Changeset 647 for trunk/kernel/devices/dev_fbf.c
- Timestamp:
- Oct 22, 2019, 1:48:51 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/devices/dev_fbf.c
r565 r647 1 1 /* 2 * dev_fbf.c - FBF ( Block Device Controler) generic device API implementation.2 * dev_fbf.c - FBF (Frame Buffer) generic device API implementation. 3 3 * 4 * Author Alain Greiner (2016,2017,2018 )4 * Author Alain Greiner (2016,2017,2018,2019) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 25 25 #include <hal_kernel_types.h> 26 26 #include <hal_gpt.h> 27 #include <hal_drivers.h> 27 28 #include <thread.h> 28 29 #include <printk.h> … … 37 38 extern chdev_directory_t chdev_dir; // allocated in kernel_init.c 38 39 40 /////////////////////////////////////////// 41 char * dev_fbf_cmd_str( uint32_t cmd_type ) 42 { 43 if ( cmd_type == FBF_READ ) return "READ"; 44 else if( cmd_type == FBF_WRITE ) return "WRITE"; 45 else if( cmd_type == FBF_GET_CONFIG ) return "GET_CONFIG"; 46 else return "undefined"; 47 } 48 39 49 //////////////////////////////////// 40 void dev_fbf_init( chdev_t * chdev)50 void dev_fbf_init( chdev_t * fbf ) 41 51 { 42 // set FBF chdev extension fields43 // TODO this should be done in the implementation44 // TODO specific part, as these parameters must be obtained from the hardware.45 chdev->ext.fbf.width = CONFIG_FBF_WIDTH;46 chdev->ext.fbf.height = CONFIG_FBF_HEIGHT;47 48 // get implementation49 uint32_t impl = chdev->impl;50 51 52 // set chdev name 52 strcpy( chdev->name, "fbf" );53 strcpy( fbf->name, "fbf" ); 53 54 54 55 // call driver init function 55 if( impl == IMPL_FBF_SCL ) 56 { 57 printk("\n[WARNING] Soclib FBF driver not implemented yet\n"); 58 } 59 else 60 { 61 assert( false , "undefined FBF device implementation" ); 62 } 56 hal_drivers_fbf_init( fbf ); 63 57 64 58 } // end dev_fbf_init() 65 59 66 ///////////////////////////////////////// 67 void dev_fbf_get_size( uint32_t * width, 68 uint32_t * height ) 60 ////////////////////////////////////////// 61 void dev_fbf_get_config( uint32_t * width, 62 uint32_t * height, 63 uint32_t * type ) 69 64 { 70 65 // get extended pointer on FBF chdev descriptor … … 80 75 *width = hal_remote_l32( XPTR( dev_cxy , &dev_ptr->ext.fbf.width ) ); 81 76 *height = hal_remote_l32( XPTR( dev_cxy , &dev_ptr->ext.fbf.height ) ); 77 *type = hal_remote_l32( XPTR( dev_cxy , &dev_ptr->ext.fbf.subsampling ) ); 82 78 83 } // end dev_fbf_get_ size()79 } // end dev_fbf_get_config() 84 80 85 ///////////////////////////// 86 error_t dev_fbf_alloc( void ) 81 ///////////////////////////////////////////////////// 82 error_t dev_fbf_move_data( uint32_t cmd_type, 83 void * user_buffer, 84 uint32_t length, 85 uint32_t offset ) 87 86 { 88 // get extended pointer on FBF chdev descriptor89 // xptr_t dev_xp = chdev_dir.fbf[0];87 // get pointer on calling thread 88 thread_t * this = CURRENT_THREAD; 90 89 91 // assert( (dev_xp != XPTR_NULL) , "undefined FBF chdev descriptor" ); 90 #if DEBUG_DEV_FBF 91 uint32_t cycle = (uint32_t)hal_get_cycles(); 92 if( DEBUG_DEV_FBF < cycle ) 93 printk("\n[%s] thread[%x,%x] : %s / buffer %x / length %d / offset %x / cycle %d\n", 94 __FUNCTION__ , this->process->pid, this->trdid, 95 dev_fbf_cmd_str(cmd_type), user_buffer, length, offset, cycle ); 96 #endif 92 97 93 // get FBF chdev cluster and local pointer 94 // cxy_t dev_cxy = GET_CXY( dev_xp ); 95 // chdev_t * dev_ptr = GET_PTR( dev_xp ); 98 // get pointers on FBF chdev 99 xptr_t fbf_xp = chdev_dir.fbf[0]; 100 cxy_t fbf_cxy = GET_CXY( fbf_xp ); 101 chdev_t * fbf_ptr = GET_PTR( fbf_xp ); 96 102 97 // try to get FBF ownership 103 // check fbf_xp definition 104 assert( (fbf_xp != XPTR_NULL) , "undefined FBF chdev descriptor" ); 98 105 99 assert( false , "not implemented yet" ); 100 101 } // end dev_fbf_alloc() 102 103 ///////////////////////// 104 void dev_fbf_free( void ) 105 { 106 // get extended pointer on FBF chdev descriptor 107 // xptr_t dev_xp = chdev_dir.fbf[0]; 108 109 // assert( (dev_xp != XPTR_NULL) , "undefined FBF chdev descriptor" ); 110 111 // get FBF chdev cluster and local pointer 112 // cxy_t dev_cxy = GET_CXY( dev_xp ); 113 // chdev_t * dev_ptr = (GET_PTR( dev_xp ); 114 115 // release FBF ownership 116 117 assert( false , "not implemented yet" ); 118 119 } // end dev_fbf_free() 120 121 ////////////////////////////////////////////////////////////////////////////////// 122 // This static function is called by dev_fbf_read() & dev_fbf_write() functions. 123 // It builds and registers the command in the calling thread descriptor. 124 // Then, it registers the calling thread in the relevant DMA chdev waiting queue. 125 // Finally it blocks on the THREAD_BLOCKED_DEV condition and deschedule. 126 ////////////////////////////////////i///////////////////////////////////////////// 127 static error_t dev_fbf_access( bool_t to_fbf, 128 char * buffer, 129 uint32_t length, 130 uint32_t offset ) 131 { 132 133 // get extended pointer on FBF chdev descriptor 134 xptr_t fbf_xp = chdev_dir.fbf[0]; 135 136 assert( (fbf_xp != XPTR_NULL) , "undefined FBF chdev descriptor" ); 137 138 // get FBF chdev cluster and local pointer 139 cxy_t fbf_cxy = GET_CXY( fbf_xp ); 140 chdev_t * fbf_ptr = (chdev_t *)GET_PTR( fbf_xp ); 141 142 // get frame buffer base address, width and height 143 xptr_t base = hal_remote_l64( XPTR( fbf_cxy , &fbf_ptr->base ) ); 106 // get frame buffer width and height 144 107 uint32_t width = hal_remote_l32 ( XPTR( fbf_cxy , &fbf_ptr->ext.fbf.width ) ); 145 108 uint32_t height = hal_remote_l32 ( XPTR( fbf_cxy , &fbf_ptr->ext.fbf.height ) ); 146 109 147 148 149 110 // check offset and length versus FBF size 111 assert( ((offset + length) <= (width * height)) , 112 "offset %d / length %d / width %d / height %d\n", offset, length, width, height ); 150 113 151 // compute extended pointers on frame buffer and memory buffer 152 xptr_t mem_buf_xp = XPTR( local_cxy , buffer ); 153 xptr_t fbf_buf_xp = base + offset; 114 // register command in calling thread descriptor 115 this->fbf_cmd.dev_xp = fbf_xp; 116 this->fbf_cmd.type = cmd_type; 117 this->fbf_cmd.buffer = user_buffer; 118 this->fbf_cmd.offset = offset; 119 this->fbf_cmd.length = length; 154 120 155 // register command in DMA chdev 156 if( to_fbf ) dev_dma_remote_memcpy( fbf_buf_xp , mem_buf_xp , length ); 157 else dev_dma_remote_memcpy( mem_buf_xp , fbf_buf_xp , length ); 121 // get driver command function 122 dev_cmd_t * cmd = (dev_cmd_t *)hal_remote_lpt( XPTR( fbf_cxy , &fbf_ptr->cmd ) ); 158 123 159 return 0; 124 // call driver 125 cmd( XPTR( local_cxy , this ) ); 160 126 161 } // end dev_fbf_access() 127 error_t error = this->fbf_cmd.error; 162 128 163 //////////////////////////////////////////// 164 error_t dev_fbf_read( char * buffer, 165 uint32_t length, 166 uint32_t offset ) 167 { 168 169 #if DEBUG_DEV_FBF_RX 170 uint32_t cycle = (uint32_t)hal_get_cycles(); 171 if( DEBUG_DEV_FBF_RX < cycle ) 172 printk("\n[DBG] %s : thread %x enter / process %x / vaddr %x / size %x\n", 173 __FUNCTION__ , this, this->process->pid , buffer , buf_paddr ); 129 #if DEBUG_DEV_FBF 130 cycle = (uint32_t)hal_get_cycles(); 131 if( DEBUG_DEV_FBF < cycle ) 132 printk("\n[%s] thread[%x,%x] completes %s / error = %d / cycle %d\n", 133 __FUNCTION__ , this->process->pid, this->trdid, 134 dev_fbf_cmd_str(cmd_type), error , cycle ); 174 135 #endif 175 136 176 return dev_fbf_access( false , buffer , length , offset ); 137 // return I/O operation status 138 return error; 177 139 178 #if DEBUG_DEV_FBF_RX 179 cycle = (uint32_t)hal_get_cycles(); 180 if( DEBUG_DEV_FBF_RX < cycle ) 181 printk("\n[DBG] %s : thread %x exit / process %x / vaddr %x / size %x\n", 182 __FUNCTION__ , this, this->process->pid , buffer , buf_paddr ); 183 #endif 184 185 } 186 187 //////////////////////////////////////////// 188 error_t dev_fbf_write( char * buffer, 189 uint32_t length, 190 uint32_t offset ) 191 { 192 193 #if DEBUG_DEV_FBF_TX 194 uint32_t cycle = (uint32_t)hal_get_cycles(); 195 if( DEBUG_DEV_FBF_TX < cycle ) 196 printk("\n[DBG] %s : thread %x enter / process %x / vaddr %x / size %x\n", 197 __FUNCTION__ , this, this->process->pid , buffer , buf_paddr ); 198 #endif 199 200 return dev_fbf_access( true , buffer , length , offset ); 201 202 #if DEBUG_DEV_FBF_RX 203 cycle = (uint32_t)hal_get_cycles(); 204 if( DEBUG_DEV_FBF_RX < cycle ) 205 printk("\n[DBG] %s : thread %x exit / process %x / vaddr %x / size %x\n", 206 __FUNCTION__ , this, this->process->pid , buffer , buf_paddr ); 207 #endif 208 209 } 140 } // end dev_fbf_move_data()
Note: See TracChangeset
for help on using the changeset viewer.