[3] | 1 | /* |
---|
| 2 | * dev_fbf.c - FBF (Block Device Controler) generic device API implementation. |
---|
| 3 | * |
---|
[437] | 4 | * Author Alain Greiner (2016,2017,2018) |
---|
[3] | 5 | * |
---|
| 6 | * Copyright (c) UPMC Sorbonne Universites |
---|
| 7 | * |
---|
| 8 | * This file is part of ALMOS-MK |
---|
| 9 | * |
---|
| 10 | * ALMOS-MKH.is free software; you can redistribute it and/or modify it |
---|
| 11 | * under the terms of the GNU General Public License as published by |
---|
| 12 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 13 | * |
---|
| 14 | * ALMOS-MKH.is distributed in the hope that it will be useful, but |
---|
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 17 | * General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with ALMOS-kernel; if not, write to the Free Software Foundation, |
---|
| 21 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 22 | */ |
---|
| 23 | |
---|
[14] | 24 | #include <kernel_config.h> |
---|
[457] | 25 | #include <hal_kernel_types.h> |
---|
[3] | 26 | #include <hal_gpt.h> |
---|
| 27 | #include <thread.h> |
---|
| 28 | #include <printk.h> |
---|
[422] | 29 | #include <string.h> |
---|
[3] | 30 | #include <chdev.h> |
---|
| 31 | #include <dev_fbf.h> |
---|
| 32 | |
---|
| 33 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 34 | // Extern global variables |
---|
| 35 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 36 | |
---|
| 37 | extern chdev_directory_t chdev_dir; // allocated in kernel_init.c |
---|
| 38 | |
---|
| 39 | //////////////////////////////////// |
---|
[188] | 40 | void dev_fbf_init( chdev_t * chdev ) |
---|
[3] | 41 | { |
---|
| 42 | // set FBF chdev extension fields |
---|
[408] | 43 | // TODO this should be done in the implementation |
---|
[3] | 44 | // TODO specific part, as these parameters must be obtained from the hardware. |
---|
[188] | 45 | chdev->ext.fbf.width = CONFIG_FBF_WIDTH; |
---|
| 46 | chdev->ext.fbf.height = CONFIG_FBF_HEIGHT; |
---|
[3] | 47 | |
---|
| 48 | // get implementation |
---|
| 49 | uint32_t impl = chdev->impl; |
---|
| 50 | |
---|
[23] | 51 | // set chdev name |
---|
| 52 | strcpy( chdev->name, "fbf" ); |
---|
[188] | 53 | |
---|
[3] | 54 | // call driver init function |
---|
| 55 | if( impl == IMPL_FBF_SCL ) |
---|
| 56 | { |
---|
[565] | 57 | printk("\n[WARNING] Soclib FBF driver not implemented yet\n"); |
---|
[3] | 58 | } |
---|
| 59 | else |
---|
| 60 | { |
---|
[492] | 61 | assert( false , "undefined FBF device implementation" ); |
---|
[3] | 62 | } |
---|
| 63 | |
---|
| 64 | } // end dev_fbf_init() |
---|
| 65 | |
---|
| 66 | ///////////////////////////////////////// |
---|
| 67 | void dev_fbf_get_size( uint32_t * width, |
---|
| 68 | uint32_t * height ) |
---|
| 69 | { |
---|
| 70 | // get extended pointer on FBF chdev descriptor |
---|
| 71 | xptr_t dev_xp = chdev_dir.fbf[0]; |
---|
| 72 | |
---|
[492] | 73 | assert( (dev_xp != XPTR_NULL) , "undefined FBF chdev descriptor" ); |
---|
[3] | 74 | |
---|
| 75 | // get FBF chdev cluster and local pointer |
---|
| 76 | cxy_t dev_cxy = GET_CXY( dev_xp ); |
---|
| 77 | chdev_t * dev_ptr = (chdev_t *)GET_PTR( dev_xp ); |
---|
| 78 | |
---|
| 79 | // return values |
---|
[565] | 80 | *width = hal_remote_l32( XPTR( dev_cxy , &dev_ptr->ext.fbf.width ) ); |
---|
| 81 | *height = hal_remote_l32( XPTR( dev_cxy , &dev_ptr->ext.fbf.height ) ); |
---|
[3] | 82 | |
---|
| 83 | } // end dev_fbf_get_size() |
---|
| 84 | |
---|
[565] | 85 | ///////////////////////////// |
---|
[483] | 86 | error_t dev_fbf_alloc( void ) |
---|
[3] | 87 | { |
---|
| 88 | // get extended pointer on FBF chdev descriptor |
---|
[565] | 89 | // xptr_t dev_xp = chdev_dir.fbf[0]; |
---|
[3] | 90 | |
---|
[565] | 91 | // assert( (dev_xp != XPTR_NULL) , "undefined FBF chdev descriptor" ); |
---|
[3] | 92 | |
---|
| 93 | // get FBF chdev cluster and local pointer |
---|
[565] | 94 | // cxy_t dev_cxy = GET_CXY( dev_xp ); |
---|
| 95 | // chdev_t * dev_ptr = GET_PTR( dev_xp ); |
---|
[3] | 96 | |
---|
| 97 | // try to get FBF ownership |
---|
| 98 | |
---|
[565] | 99 | assert( false , "not implemented yet" ); |
---|
| 100 | |
---|
[3] | 101 | } // end dev_fbf_alloc() |
---|
| 102 | |
---|
[565] | 103 | ///////////////////////// |
---|
[483] | 104 | void dev_fbf_free( void ) |
---|
[3] | 105 | { |
---|
| 106 | // get extended pointer on FBF chdev descriptor |
---|
[565] | 107 | // xptr_t dev_xp = chdev_dir.fbf[0]; |
---|
[3] | 108 | |
---|
[565] | 109 | // assert( (dev_xp != XPTR_NULL) , "undefined FBF chdev descriptor" ); |
---|
[3] | 110 | |
---|
| 111 | // get FBF chdev cluster and local pointer |
---|
[565] | 112 | // cxy_t dev_cxy = GET_CXY( dev_xp ); |
---|
| 113 | // chdev_t * dev_ptr = (GET_PTR( dev_xp ); |
---|
[3] | 114 | |
---|
| 115 | // release FBF ownership |
---|
| 116 | |
---|
[565] | 117 | assert( false , "not implemented yet" ); |
---|
| 118 | |
---|
[3] | 119 | } // end dev_fbf_free() |
---|
| 120 | |
---|
| 121 | ////////////////////////////////////////////////////////////////////////////////// |
---|
| 122 | // This static function is called by dev_fbf_read() & dev_fbf_write() functions. |
---|
[440] | 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. |
---|
[3] | 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 | |
---|
[492] | 136 | assert( (fbf_xp != XPTR_NULL) , "undefined FBF chdev descriptor" ); |
---|
[3] | 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 |
---|
[565] | 143 | xptr_t base = hal_remote_l64( XPTR( fbf_cxy , &fbf_ptr->base ) ); |
---|
| 144 | uint32_t width = hal_remote_l32 ( XPTR( fbf_cxy , &fbf_ptr->ext.fbf.width ) ); |
---|
| 145 | uint32_t height = hal_remote_l32 ( XPTR( fbf_cxy , &fbf_ptr->ext.fbf.height ) ); |
---|
[3] | 146 | |
---|
| 147 | // check offset and length versus FBF size |
---|
[492] | 148 | assert( ((offset + length) <= (width * height)) , |
---|
[437] | 149 | "offset %d / length %d / width %d / height %d\n", offset, length, width, height ); |
---|
[3] | 150 | |
---|
| 151 | // compute extended pointers on frame buffer and memory buffer |
---|
[440] | 152 | xptr_t mem_buf_xp = XPTR( local_cxy , buffer ); |
---|
[3] | 153 | xptr_t fbf_buf_xp = base + offset; |
---|
| 154 | |
---|
| 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 ); |
---|
| 158 | |
---|
| 159 | return 0; |
---|
| 160 | |
---|
| 161 | } // end dev_fbf_access() |
---|
| 162 | |
---|
| 163 | //////////////////////////////////////////// |
---|
| 164 | error_t dev_fbf_read( char * buffer, |
---|
| 165 | uint32_t length, |
---|
| 166 | uint32_t offset ) |
---|
| 167 | { |
---|
[437] | 168 | |
---|
[438] | 169 | #if DEBUG_DEV_FBF_RX |
---|
[471] | 170 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
---|
[438] | 171 | if( DEBUG_DEV_FBF_RX < cycle ) |
---|
[437] | 172 | printk("\n[DBG] %s : thread %x enter / process %x / vaddr %x / size %x\n", |
---|
| 173 | __FUNCTION__ , this, this->process->pid , buffer , buf_paddr ); |
---|
| 174 | #endif |
---|
| 175 | |
---|
[3] | 176 | return dev_fbf_access( false , buffer , length , offset ); |
---|
[437] | 177 | |
---|
[438] | 178 | #if DEBUG_DEV_FBF_RX |
---|
[471] | 179 | cycle = (uint32_t)hal_get_cycles(); |
---|
[438] | 180 | if( DEBUG_DEV_FBF_RX < cycle ) |
---|
[437] | 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 | |
---|
[3] | 185 | } |
---|
| 186 | |
---|
| 187 | //////////////////////////////////////////// |
---|
| 188 | error_t dev_fbf_write( char * buffer, |
---|
| 189 | uint32_t length, |
---|
| 190 | uint32_t offset ) |
---|
| 191 | { |
---|
[437] | 192 | |
---|
[438] | 193 | #if DEBUG_DEV_FBF_TX |
---|
[471] | 194 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
---|
[438] | 195 | if( DEBUG_DEV_FBF_TX < cycle ) |
---|
[437] | 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 | |
---|
[3] | 200 | return dev_fbf_access( true , buffer , length , offset ); |
---|
[437] | 201 | |
---|
[438] | 202 | #if DEBUG_DEV_FBF_RX |
---|
[471] | 203 | cycle = (uint32_t)hal_get_cycles(); |
---|
[438] | 204 | if( DEBUG_DEV_FBF_RX < cycle ) |
---|
[437] | 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 | |
---|
[3] | 209 | } |
---|