[23] | 1 | /* |
---|
| 2 | * devfs.c - DEVFS File system API implementation. |
---|
| 3 | * |
---|
| 4 | * Author Mohamed Lamine Karaoui (2014,2015) |
---|
| 5 | * Alain Greiner (2016,2017) |
---|
| 6 | * |
---|
| 7 | * Copyright (c) Sorbonne Universites |
---|
| 8 | * |
---|
| 9 | * This file is part of ALMOS-MKH. |
---|
| 10 | * |
---|
| 11 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
| 12 | * under the terms of the GNU General Public License as published by |
---|
| 13 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 14 | * |
---|
| 15 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 18 | * General Public License for more details. |
---|
| 19 | * |
---|
| 20 | * You should have received a copy of the GNU General Public License |
---|
| 21 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
| 22 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 23 | */ |
---|
| 24 | |
---|
[457] | 25 | #include <hal_kernel_types.h> |
---|
[23] | 26 | #include <hal_special.h> |
---|
[407] | 27 | #include <hal_uspace.h> |
---|
[23] | 28 | #include <printk.h> |
---|
| 29 | #include <chdev.h> |
---|
[433] | 30 | #include <thread.h> |
---|
[407] | 31 | #include <dev_txt.h> |
---|
[188] | 32 | #include <cluster.h> |
---|
[23] | 33 | #include <vfs.h> |
---|
[188] | 34 | #include <kmem.h> |
---|
[23] | 35 | #include <devfs.h> |
---|
| 36 | |
---|
[188] | 37 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 38 | // Extern variables |
---|
| 39 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
[23] | 40 | |
---|
[188] | 41 | extern vfs_ctx_t fs_context[]; // allocated in kernel_init.c |
---|
| 42 | extern chdev_directory_t chdev_dir; // allocated in kernel_init.c |
---|
[23] | 43 | |
---|
[438] | 44 | #if (DEBUG_SYS_READ & 1) |
---|
[435] | 45 | extern uint32_t enter_devfs_read; |
---|
| 46 | extern uint32_t exit_devfs_read; |
---|
[407] | 47 | #endif |
---|
| 48 | |
---|
[438] | 49 | #if (DEBUG_SYS_WRITE & 1) |
---|
[435] | 50 | extern uint32_t enter_devfs_write; |
---|
| 51 | extern uint32_t exit_devfs_write; |
---|
| 52 | #endif |
---|
| 53 | |
---|
[568] | 54 | ///////////////////////////////////// |
---|
[484] | 55 | devfs_ctx_t * devfs_ctx_alloc( void ) |
---|
[188] | 56 | { |
---|
| 57 | kmem_req_t req; |
---|
[23] | 58 | |
---|
[188] | 59 | req.type = KMEM_DEVFS_CTX; |
---|
| 60 | req.size = sizeof(devfs_ctx_t); |
---|
| 61 | req.flags = AF_KERNEL | AF_ZERO; |
---|
[23] | 62 | |
---|
[188] | 63 | return (devfs_ctx_t *)kmem_alloc( &req ); |
---|
| 64 | } |
---|
[23] | 65 | |
---|
[188] | 66 | ///////////////////////////////////////////// |
---|
| 67 | void devfs_ctx_init( devfs_ctx_t * devfs_ctx, |
---|
[204] | 68 | xptr_t devfs_dev_inode_xp, |
---|
[188] | 69 | xptr_t devfs_external_inode_xp ) |
---|
[23] | 70 | { |
---|
[204] | 71 | devfs_ctx->dev_inode_xp = devfs_dev_inode_xp; |
---|
[188] | 72 | devfs_ctx->external_inode_xp = devfs_external_inode_xp; |
---|
[23] | 73 | |
---|
[188] | 74 | fs_context[FS_TYPE_DEVFS].extend = devfs_ctx; |
---|
| 75 | } |
---|
[23] | 76 | |
---|
[188] | 77 | ///////////////////////////////////////////////// |
---|
| 78 | void devfs_ctx_destroy( devfs_ctx_t * devfs_ctx ) |
---|
| 79 | { |
---|
| 80 | kmem_req_t req; |
---|
[23] | 81 | |
---|
[188] | 82 | req.type = KMEM_DEVFS_CTX; |
---|
| 83 | req.ptr = devfs_ctx; |
---|
| 84 | kmem_free( &req ); |
---|
| 85 | } |
---|
[23] | 86 | |
---|
[437] | 87 | ///////////////////////////////////////////////// |
---|
[602] | 88 | void devfs_global_init( xptr_t root_inode_xp, |
---|
[204] | 89 | xptr_t * devfs_dev_inode_xp, |
---|
[188] | 90 | xptr_t * devfs_external_inode_xp ) |
---|
[23] | 91 | { |
---|
| 92 | error_t error; |
---|
[602] | 93 | xptr_t unused_xp; // required by vfs_add_child_in_parent() |
---|
[23] | 94 | |
---|
[457] | 95 | // creates DEVFS "dev" inode in cluster 0 |
---|
| 96 | error = vfs_add_child_in_parent( 0, // cxy |
---|
[188] | 97 | INODE_TYPE_DIR, |
---|
| 98 | FS_TYPE_DEVFS, |
---|
[602] | 99 | root_inode_xp, |
---|
[188] | 100 | "dev", |
---|
[602] | 101 | &unused_xp, |
---|
| 102 | devfs_dev_inode_xp ); |
---|
[23] | 103 | |
---|
[492] | 104 | assert( (error == 0) , "cannot create <dev>\n" ); |
---|
[23] | 105 | |
---|
[568] | 106 | #if DEBUG_DEVFS_INIT |
---|
[598] | 107 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
---|
| 108 | thread_t * this = CURRENT_THREAD; |
---|
[438] | 109 | if( DEBUG_DEVFS_INIT < cycle ) |
---|
[598] | 110 | printk("\n[%s] thread[%x,%x] created <dev> inode / cycle %d\n", |
---|
| 111 | __FUNCTION__, this->process->pid, this->trdid, cycle ); |
---|
[437] | 112 | #endif |
---|
| 113 | |
---|
[457] | 114 | // create DEVFS "external" inode in cluster 0 |
---|
| 115 | error = vfs_add_child_in_parent( 0, // cxy |
---|
[188] | 116 | INODE_TYPE_DIR, |
---|
| 117 | FS_TYPE_DEVFS, |
---|
[204] | 118 | *devfs_dev_inode_xp, |
---|
| 119 | "external", |
---|
[602] | 120 | &unused_xp, |
---|
| 121 | devfs_external_inode_xp ); |
---|
[23] | 122 | |
---|
[492] | 123 | assert( (error == 0) , "cannot create <external>\n" ); |
---|
[279] | 124 | |
---|
[438] | 125 | #if DEBUG_DEVFS_INIT |
---|
[433] | 126 | cycle = (uint32_t)hal_get_cycles(); |
---|
[438] | 127 | if( DEBUG_DEVFS_INIT < cycle ) |
---|
[598] | 128 | printk("\n[%s] thread[%x,%x] created <external> inode / cycle %d\n", |
---|
| 129 | __FUNCTION__, this->process->pid, this->trdid, cycle ); |
---|
[433] | 130 | #endif |
---|
| 131 | |
---|
[602] | 132 | } // end devfs_global_init() |
---|
[23] | 133 | |
---|
[204] | 134 | /////////////////////////////////////////////////// |
---|
| 135 | void devfs_local_init( xptr_t devfs_dev_inode_xp, |
---|
| 136 | xptr_t devfs_external_inode_xp, |
---|
| 137 | xptr_t * devfs_internal_inode_xp ) |
---|
[23] | 138 | { |
---|
| 139 | char node_name[16]; |
---|
[188] | 140 | xptr_t chdev_xp; |
---|
| 141 | cxy_t chdev_cxy; |
---|
[407] | 142 | chdev_t * chdev_ptr; |
---|
[188] | 143 | xptr_t inode_xp; |
---|
[602] | 144 | cxy_t inode_cxy; |
---|
| 145 | vfs_inode_t * inode_ptr; |
---|
[23] | 146 | uint32_t channel; |
---|
[602] | 147 | xptr_t unused_xp; // required by add_child_in_parent() |
---|
[23] | 148 | |
---|
[568] | 149 | // create "internal" directory |
---|
[188] | 150 | snprintf( node_name , 16 , "internal_%x" , local_cxy ); |
---|
| 151 | vfs_add_child_in_parent( local_cxy, |
---|
| 152 | INODE_TYPE_DIR, |
---|
| 153 | FS_TYPE_DEVFS, |
---|
[204] | 154 | devfs_dev_inode_xp, |
---|
[188] | 155 | node_name, |
---|
[602] | 156 | &unused_xp, |
---|
[204] | 157 | devfs_internal_inode_xp ); |
---|
[568] | 158 | #if DEBUG_DEVFS_INIT |
---|
[598] | 159 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
---|
| 160 | thread_t * this = CURRENT_THREAD; |
---|
[568] | 161 | if( DEBUG_DEVFS_INIT < cycle ) |
---|
[598] | 162 | printk("\n[%s] thread[%x,%x] created <%s> inode in cluster %x / cycle %d\n", |
---|
| 163 | __FUNCTION__, this->process->pid, this->trdid, node_name, local_cxy, cycle ); |
---|
[568] | 164 | #endif |
---|
[23] | 165 | |
---|
| 166 | // create MMC chdev inode |
---|
[407] | 167 | chdev_xp = chdev_dir.mmc[local_cxy]; |
---|
[188] | 168 | if( chdev_xp != XPTR_NULL) |
---|
| 169 | { |
---|
[602] | 170 | chdev_ptr = GET_PTR( chdev_xp ); |
---|
[188] | 171 | vfs_add_child_in_parent( local_cxy, |
---|
| 172 | INODE_TYPE_DEV, |
---|
| 173 | FS_TYPE_DEVFS, |
---|
[204] | 174 | *devfs_internal_inode_xp, |
---|
[407] | 175 | chdev_ptr->name, |
---|
[602] | 176 | &unused_xp, |
---|
[188] | 177 | &inode_xp ); |
---|
[602] | 178 | |
---|
| 179 | // update child inode "extend" field |
---|
| 180 | inode_cxy = GET_CXY( inode_xp ); |
---|
| 181 | inode_ptr = GET_PTR( inode_xp ); |
---|
| 182 | hal_remote_spt( XPTR( inode_cxy , &inode_ptr->extend ) , chdev_ptr ); |
---|
| 183 | |
---|
[568] | 184 | #if DEBUG_DEVFS_INIT |
---|
| 185 | cycle = (uint32_t)hal_get_cycles(); |
---|
| 186 | if( DEBUG_DEVFS_INIT < cycle ) |
---|
[598] | 187 | printk("\n[%s] thread[%x,%x] created <mmc> inode in cluster %x\n", |
---|
| 188 | __FUNCTION__, this->process->pid, this->trdid, local_cxy, cycle ); |
---|
[568] | 189 | #endif |
---|
| 190 | |
---|
[188] | 191 | } |
---|
[23] | 192 | |
---|
| 193 | // create DMA chdev inodes (one DMA channel per core) |
---|
[188] | 194 | for( channel = 0 ; channel < LOCAL_CLUSTER->cores_nr ; channel++ ) |
---|
[23] | 195 | { |
---|
[602] | 196 | chdev_xp = chdev_dir.dma[channel]; |
---|
[188] | 197 | if( chdev_xp != XPTR_NULL) |
---|
| 198 | { |
---|
[602] | 199 | chdev_ptr = GET_PTR( chdev_xp ); |
---|
[188] | 200 | vfs_add_child_in_parent( local_cxy, |
---|
| 201 | INODE_TYPE_DEV, |
---|
| 202 | FS_TYPE_DEVFS, |
---|
[204] | 203 | *devfs_internal_inode_xp, |
---|
[407] | 204 | chdev_ptr->name, |
---|
[602] | 205 | &unused_xp, |
---|
[188] | 206 | &inode_xp ); |
---|
[602] | 207 | |
---|
| 208 | // update child inode "extend" field |
---|
| 209 | inode_cxy = GET_CXY( inode_xp ); |
---|
| 210 | inode_ptr = GET_PTR( inode_xp ); |
---|
| 211 | hal_remote_spt( XPTR( inode_cxy , &inode_ptr->extend ) , chdev_ptr ); |
---|
| 212 | |
---|
[568] | 213 | #if DEBUG_DEVFS_INIT |
---|
| 214 | cycle = (uint32_t)hal_get_cycles(); |
---|
| 215 | if( DEBUG_DEVFS_INIT < cycle ) |
---|
[598] | 216 | printk("\n[%s] thread [%x,%x] created <dma[%d]> inode in cluster %x\n", |
---|
| 217 | __FUNCTION__, this->process->pid, this->trdid, channel, local_cxy, cycle ); |
---|
[568] | 218 | #endif |
---|
[188] | 219 | } |
---|
[23] | 220 | } |
---|
| 221 | |
---|
[188] | 222 | // create an IOB inode in cluster containing IOB chdev |
---|
| 223 | chdev_xp = chdev_dir.iob; |
---|
| 224 | if( chdev_xp != XPTR_NULL ) |
---|
[23] | 225 | { |
---|
[188] | 226 | chdev_cxy = GET_CXY( chdev_xp ); |
---|
[602] | 227 | chdev_ptr = GET_PTR( chdev_xp ); |
---|
[188] | 228 | if( chdev_cxy == local_cxy ) |
---|
| 229 | { |
---|
| 230 | vfs_add_child_in_parent( local_cxy, |
---|
| 231 | INODE_TYPE_DEV, |
---|
| 232 | FS_TYPE_DEVFS, |
---|
| 233 | devfs_external_inode_xp, |
---|
[407] | 234 | chdev_ptr->name, |
---|
[602] | 235 | &unused_xp, |
---|
[188] | 236 | &inode_xp ); |
---|
[602] | 237 | |
---|
| 238 | // update child inode "extend" field |
---|
| 239 | inode_cxy = GET_CXY( inode_xp ); |
---|
| 240 | inode_ptr = GET_PTR( inode_xp ); |
---|
| 241 | hal_remote_spt( XPTR( inode_cxy , &inode_ptr->extend ) , chdev_ptr ); |
---|
| 242 | |
---|
[568] | 243 | #if DEBUG_DEVFS_INIT |
---|
| 244 | cycle = (uint32_t)hal_get_cycles(); |
---|
| 245 | if( DEBUG_DEVFS_INIT < cycle ) |
---|
[598] | 246 | printk("\n[%s] thread[%x,%x] created <iob> inode in cluster %x\n", |
---|
| 247 | __FUNCTION__, this->process->pid, this->trdid, local_cxy, cycle ); |
---|
[568] | 248 | #endif |
---|
[188] | 249 | } |
---|
| 250 | } |
---|
[23] | 251 | |
---|
[188] | 252 | // create a PIC inode in cluster containing PIC chdev |
---|
| 253 | chdev_xp = chdev_dir.pic; |
---|
| 254 | if( chdev_xp != XPTR_NULL ) |
---|
| 255 | { |
---|
| 256 | chdev_cxy = GET_CXY( chdev_xp ); |
---|
[602] | 257 | chdev_ptr = GET_PTR( chdev_xp ); |
---|
[188] | 258 | if( chdev_cxy == local_cxy ) |
---|
[23] | 259 | { |
---|
[188] | 260 | vfs_add_child_in_parent( local_cxy, |
---|
| 261 | INODE_TYPE_DEV, |
---|
| 262 | FS_TYPE_DEVFS, |
---|
| 263 | devfs_external_inode_xp, |
---|
[407] | 264 | chdev_ptr->name, |
---|
[602] | 265 | &unused_xp, |
---|
[188] | 266 | &inode_xp ); |
---|
[602] | 267 | |
---|
| 268 | // update child inode "extend" field |
---|
| 269 | inode_cxy = GET_CXY( inode_xp ); |
---|
| 270 | inode_ptr = GET_PTR( inode_xp ); |
---|
| 271 | hal_remote_spt( XPTR( inode_cxy , &inode_ptr->extend ) , chdev_ptr ); |
---|
| 272 | |
---|
[568] | 273 | #if DEBUG_DEVFS_INIT |
---|
| 274 | cycle = (uint32_t)hal_get_cycles(); |
---|
| 275 | if( DEBUG_DEVFS_INIT < cycle ) |
---|
[598] | 276 | printk("\n[%s] thread[%x,%x] created <pic> inode in cluster %x\n", |
---|
| 277 | __FUNCTION__, this->process->pid, this->trdid, local_cxy, cycle ); |
---|
[568] | 278 | #endif |
---|
[23] | 279 | } |
---|
[188] | 280 | } |
---|
[23] | 281 | |
---|
[407] | 282 | // create a TXT_RX inode in each cluster containing a TXT_RX chdev |
---|
[188] | 283 | for( channel = 0 ; channel < CONFIG_MAX_TXT_CHANNELS ; channel++ ) |
---|
| 284 | { |
---|
[407] | 285 | chdev_xp = chdev_dir.txt_rx[channel]; |
---|
[188] | 286 | if( chdev_xp != XPTR_NULL ) |
---|
[23] | 287 | { |
---|
[188] | 288 | chdev_cxy = GET_CXY( chdev_xp ); |
---|
[602] | 289 | chdev_ptr = GET_PTR( chdev_xp ); |
---|
[188] | 290 | if( chdev_cxy == local_cxy ) |
---|
| 291 | { |
---|
| 292 | vfs_add_child_in_parent( local_cxy, |
---|
| 293 | INODE_TYPE_DEV, |
---|
| 294 | FS_TYPE_DEVFS, |
---|
| 295 | devfs_external_inode_xp, |
---|
[407] | 296 | chdev_ptr->name, |
---|
[602] | 297 | &unused_xp, |
---|
[188] | 298 | &inode_xp ); |
---|
[602] | 299 | |
---|
| 300 | // update child inode "extend" field |
---|
| 301 | inode_cxy = GET_CXY( inode_xp ); |
---|
| 302 | inode_ptr = GET_PTR( inode_xp ); |
---|
| 303 | hal_remote_spt( XPTR( inode_cxy , &inode_ptr->extend ) , chdev_ptr ); |
---|
| 304 | |
---|
[568] | 305 | #if DEBUG_DEVFS_INIT |
---|
| 306 | cycle = (uint32_t)hal_get_cycles(); |
---|
| 307 | if( DEBUG_DEVFS_INIT < cycle ) |
---|
[598] | 308 | printk("\n[%s] thread[%x,%x] created <txt_rx[%d]> inode in cluster %x\n", |
---|
| 309 | __FUNCTION__, this->process->pid, this->trdid, channel, local_cxy, cycle ); |
---|
[568] | 310 | #endif |
---|
[188] | 311 | } |
---|
[23] | 312 | } |
---|
[188] | 313 | } |
---|
[23] | 314 | |
---|
[407] | 315 | // create a TXT_TX inode in each cluster containing a TXT_TX chdev |
---|
| 316 | for( channel = 0 ; channel < CONFIG_MAX_TXT_CHANNELS ; channel++ ) |
---|
| 317 | { |
---|
| 318 | chdev_xp = chdev_dir.txt_tx[channel]; |
---|
| 319 | if( chdev_xp != XPTR_NULL ) |
---|
| 320 | { |
---|
| 321 | chdev_cxy = GET_CXY( chdev_xp ); |
---|
[602] | 322 | chdev_ptr = GET_PTR( chdev_xp ); |
---|
[407] | 323 | if( chdev_cxy == local_cxy ) |
---|
| 324 | { |
---|
| 325 | vfs_add_child_in_parent( local_cxy, |
---|
| 326 | INODE_TYPE_DEV, |
---|
| 327 | FS_TYPE_DEVFS, |
---|
| 328 | devfs_external_inode_xp, |
---|
| 329 | chdev_ptr->name, |
---|
[602] | 330 | &unused_xp, |
---|
[407] | 331 | &inode_xp ); |
---|
[602] | 332 | |
---|
| 333 | // update child inode "extend" field |
---|
| 334 | inode_cxy = GET_CXY( inode_xp ); |
---|
| 335 | inode_ptr = GET_PTR( inode_xp ); |
---|
| 336 | hal_remote_spt( XPTR( inode_cxy , &inode_ptr->extend ) , chdev_ptr ); |
---|
| 337 | |
---|
[568] | 338 | #if DEBUG_DEVFS_INIT |
---|
| 339 | cycle = (uint32_t)hal_get_cycles(); |
---|
| 340 | if( DEBUG_DEVFS_INIT < cycle ) |
---|
[598] | 341 | printk("\n[%s] thread[%x,%x] created <txt_tx[%d]> inode in cluster %x\n", |
---|
| 342 | __FUNCTION__, this->process->pid, this->trdid, channel, local_cxy, cycle ); |
---|
[568] | 343 | #endif |
---|
[407] | 344 | } |
---|
| 345 | } |
---|
| 346 | } |
---|
| 347 | |
---|
[188] | 348 | // create an IOC inode in each cluster containing an IOC chdev |
---|
| 349 | for( channel = 0 ; channel < CONFIG_MAX_IOC_CHANNELS ; channel++ ) |
---|
| 350 | { |
---|
| 351 | chdev_xp = chdev_dir.ioc[channel]; |
---|
| 352 | if( chdev_xp != XPTR_NULL ) |
---|
[23] | 353 | { |
---|
[188] | 354 | chdev_cxy = GET_CXY( chdev_xp ); |
---|
[602] | 355 | chdev_ptr = GET_PTR( chdev_xp ); |
---|
[188] | 356 | if( chdev_cxy == local_cxy ) |
---|
| 357 | { |
---|
| 358 | vfs_add_child_in_parent( local_cxy, |
---|
| 359 | INODE_TYPE_DEV, |
---|
| 360 | FS_TYPE_DEVFS, |
---|
| 361 | devfs_external_inode_xp, |
---|
[407] | 362 | chdev_ptr->name, |
---|
[602] | 363 | &unused_xp, |
---|
[188] | 364 | &inode_xp ); |
---|
[602] | 365 | |
---|
| 366 | // update child inode "extend" field |
---|
| 367 | inode_cxy = GET_CXY( inode_xp ); |
---|
| 368 | inode_ptr = GET_PTR( inode_xp ); |
---|
| 369 | hal_remote_spt( XPTR( inode_cxy , &inode_ptr->extend ) , chdev_ptr ); |
---|
| 370 | |
---|
[568] | 371 | #if DEBUG_DEVFS_INIT |
---|
| 372 | cycle = (uint32_t)hal_get_cycles(); |
---|
| 373 | if( DEBUG_DEVFS_INIT < cycle ) |
---|
[598] | 374 | printk("\n[%s] thread[%x,%x] created <ioc[%d]> inode in cluster %x\n", |
---|
| 375 | __FUNCTION__, this->process->pid, this->trdid, channel, local_cxy, cycle ); |
---|
[568] | 376 | #endif |
---|
[188] | 377 | } |
---|
[23] | 378 | } |
---|
[188] | 379 | } |
---|
[23] | 380 | |
---|
[188] | 381 | // create a FBF inode in each cluster containing a FBF chdev |
---|
[568] | 382 | for( channel = 0 ; channel < CONFIG_MAX_FBF_CHANNELS ; channel++ ) |
---|
[188] | 383 | { |
---|
| 384 | chdev_xp = chdev_dir.fbf[channel]; |
---|
| 385 | if( chdev_xp != XPTR_NULL ) |
---|
[23] | 386 | { |
---|
[188] | 387 | chdev_cxy = GET_CXY( chdev_xp ); |
---|
[602] | 388 | chdev_ptr = GET_PTR( chdev_xp ); |
---|
[188] | 389 | if( chdev_cxy == local_cxy ) |
---|
| 390 | { |
---|
| 391 | vfs_add_child_in_parent( local_cxy, |
---|
| 392 | INODE_TYPE_DEV, |
---|
| 393 | FS_TYPE_DEVFS, |
---|
| 394 | devfs_external_inode_xp, |
---|
[407] | 395 | chdev_ptr->name, |
---|
[602] | 396 | &unused_xp, |
---|
[188] | 397 | &inode_xp ); |
---|
[602] | 398 | |
---|
| 399 | // update child inode "extend" field |
---|
| 400 | inode_cxy = GET_CXY( inode_xp ); |
---|
| 401 | inode_ptr = GET_PTR( inode_xp ); |
---|
| 402 | hal_remote_spt( XPTR( inode_cxy , &inode_ptr->extend ) , chdev_ptr ); |
---|
| 403 | |
---|
[568] | 404 | #if DEBUG_DEVFS_INIT |
---|
| 405 | cycle = (uint32_t)hal_get_cycles(); |
---|
| 406 | if( DEBUG_DEVFS_INIT < cycle ) |
---|
[598] | 407 | printk("\n[%s] thread[%x,%x] created <fbf[%d]> inode in cluster %x\n", |
---|
| 408 | __FUNCTION__, this->process->pid, this->trdid, channel, local_cxy, cycle ); |
---|
[568] | 409 | #endif |
---|
[188] | 410 | } |
---|
[23] | 411 | } |
---|
[188] | 412 | } |
---|
[23] | 413 | |
---|
[188] | 414 | // create a NIC_RX inode in each cluster containing a NIC_RX chdev |
---|
| 415 | for( channel = 0 ; channel < CONFIG_MAX_NIC_CHANNELS ; channel++ ) |
---|
| 416 | { |
---|
| 417 | chdev_xp = chdev_dir.nic_rx[channel]; |
---|
| 418 | if( chdev_xp != XPTR_NULL ) |
---|
[23] | 419 | { |
---|
[188] | 420 | chdev_cxy = GET_CXY( chdev_xp ); |
---|
[407] | 421 | chdev_ptr = (chdev_t *)GET_PTR( chdev_xp ); |
---|
[188] | 422 | if( chdev_cxy == local_cxy ) |
---|
| 423 | { |
---|
| 424 | vfs_add_child_in_parent( local_cxy, |
---|
| 425 | INODE_TYPE_DEV, |
---|
| 426 | FS_TYPE_DEVFS, |
---|
| 427 | devfs_external_inode_xp, |
---|
[407] | 428 | chdev_ptr->name, |
---|
[602] | 429 | &unused_xp, |
---|
[188] | 430 | &inode_xp ); |
---|
[568] | 431 | #if DEBUG_DEVFS_INIT |
---|
| 432 | cycle = (uint32_t)hal_get_cycles(); |
---|
| 433 | if( DEBUG_DEVFS_INIT < cycle ) |
---|
[598] | 434 | printk("\n[%s] thread[%x,%x] created <nic_rx[%d]> inode in cluster %x\n", |
---|
| 435 | __FUNCTION__, this->process->pid, this->trdid, channel, local_cxy, cycle ); |
---|
[568] | 436 | #endif |
---|
[188] | 437 | } |
---|
[23] | 438 | } |
---|
| 439 | } |
---|
| 440 | |
---|
[188] | 441 | // create a NIC_TX inode in each cluster containing a NIC_TX chdev |
---|
| 442 | for( channel = 0 ; channel < CONFIG_MAX_NIC_CHANNELS ; channel++ ) |
---|
[23] | 443 | { |
---|
[188] | 444 | chdev_xp = chdev_dir.nic_tx[channel]; |
---|
| 445 | if( chdev_xp != XPTR_NULL ) |
---|
| 446 | { |
---|
| 447 | chdev_cxy = GET_CXY( chdev_xp ); |
---|
[602] | 448 | chdev_ptr = GET_PTR( chdev_xp ); |
---|
[188] | 449 | if( chdev_cxy == local_cxy ) |
---|
| 450 | { |
---|
| 451 | vfs_add_child_in_parent( local_cxy, |
---|
| 452 | INODE_TYPE_DEV, |
---|
| 453 | FS_TYPE_DEVFS, |
---|
| 454 | devfs_external_inode_xp, |
---|
[407] | 455 | chdev_ptr->name, |
---|
[602] | 456 | &unused_xp, |
---|
[188] | 457 | &inode_xp ); |
---|
[602] | 458 | |
---|
| 459 | // update child inode "extend" field |
---|
| 460 | inode_cxy = GET_CXY( inode_xp ); |
---|
| 461 | inode_ptr = GET_PTR( inode_xp ); |
---|
| 462 | hal_remote_spt( XPTR( inode_cxy , &inode_ptr->extend ) , chdev_ptr ); |
---|
| 463 | |
---|
[438] | 464 | #if DEBUG_DEVFS_INIT |
---|
[433] | 465 | cycle = (uint32_t)hal_get_cycles(); |
---|
[438] | 466 | if( DEBUG_DEVFS_INIT < cycle ) |
---|
[598] | 467 | printk("\n[%s] thread[%x,%x] created <nic_tx[%d]> inode in cluster %x\n", |
---|
| 468 | __FUNCTION__, this->process->pid, this->trdid, channel, local_cxy, cycle ); |
---|
[433] | 469 | #endif |
---|
[568] | 470 | } |
---|
| 471 | } |
---|
| 472 | } |
---|
[188] | 473 | } // end devfs_local_init() |
---|
[23] | 474 | |
---|
[407] | 475 | ////////////////////////////////////////// |
---|
| 476 | int devfs_user_move( bool_t to_buffer, |
---|
| 477 | xptr_t file_xp, |
---|
[598] | 478 | char * u_buf, |
---|
[407] | 479 | uint32_t size ) |
---|
| 480 | { |
---|
[598] | 481 | xptr_t chdev_xp; |
---|
| 482 | cxy_t chdev_cxy; |
---|
| 483 | chdev_t * chdev_ptr; // associated chdev type |
---|
| 484 | uint32_t func; // chdev functionnal type |
---|
| 485 | uint32_t channel; // chdev channel index |
---|
| 486 | uint32_t burst; // number of bytes in a burst |
---|
| 487 | uint32_t todo; // number of bytes not yet moved |
---|
| 488 | error_t error; |
---|
| 489 | uint32_t i; |
---|
[407] | 490 | |
---|
[598] | 491 | char k_buf[CONFIG_TXT_KBUF_SIZE]; // local kernel buffer |
---|
[407] | 492 | |
---|
[598] | 493 | assert( ( file_xp != XPTR_NULL ) , "file_xp == XPTR_NULL" ); |
---|
[407] | 494 | |
---|
[438] | 495 | #if (DEBUG_SYS_READ & 1) |
---|
[435] | 496 | enter_devfs_read = hal_time_stamp(); |
---|
| 497 | #endif |
---|
| 498 | |
---|
[438] | 499 | #if (DEBUG_SYS_WRITE & 1) |
---|
[435] | 500 | enter_devfs_write = hal_time_stamp(); |
---|
| 501 | #endif |
---|
| 502 | |
---|
[438] | 503 | #if DEBUG_DEVFS_MOVE |
---|
[598] | 504 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
---|
| 505 | thread_t * this = CURRENT_THREAD; |
---|
[438] | 506 | if( DEBUG_DEVFS_MOVE < cycle ) |
---|
[598] | 507 | printk("\n[%s] thread[%x,%x] enter / to_mem %d / cycle %d\n", |
---|
| 508 | __FUNCTION__, this->process->pid, this->trdid, to_buffer, cycle ); |
---|
[433] | 509 | #endif |
---|
[407] | 510 | |
---|
[430] | 511 | // get extended pointer on chdev_xp |
---|
| 512 | chdev_xp = chdev_from_file( file_xp ); |
---|
[407] | 513 | |
---|
[430] | 514 | // get cluster and local pointer on chdev |
---|
| 515 | chdev_cxy = GET_CXY( chdev_xp ); |
---|
| 516 | chdev_ptr = (chdev_t *)GET_PTR( chdev_xp ); |
---|
[407] | 517 | |
---|
| 518 | // get chdev functionnal type and channel |
---|
[568] | 519 | func = hal_remote_l32( XPTR( chdev_cxy , &chdev_ptr->func ) ); |
---|
| 520 | channel = hal_remote_l32( XPTR( chdev_cxy , &chdev_ptr->channel ) ); |
---|
[407] | 521 | |
---|
[602] | 522 | // Only TXT devices are associated to a pseudo-file |
---|
[598] | 523 | assert( ( func == DEV_FUNC_TXT ) , __FUNCTION__, "illegal device func_type"); |
---|
| 524 | |
---|
| 525 | // initialise number of bytes to move |
---|
| 526 | todo = size; |
---|
| 527 | |
---|
| 528 | /////////////// TXT read |
---|
| 529 | if( to_buffer ) |
---|
| 530 | { |
---|
| 531 | while( todo ) |
---|
| 532 | { |
---|
| 533 | // set burst size |
---|
| 534 | if( todo > CONFIG_TXT_KBUF_SIZE ) burst = CONFIG_TXT_KBUF_SIZE; |
---|
| 535 | else burst = todo; |
---|
| 536 | |
---|
| 537 | // read burst bytes from TXT device to kernel buffer |
---|
| 538 | for( i = 0 ; i < burst ; i++ ) |
---|
[407] | 539 | { |
---|
| 540 | error = dev_txt_read( channel , &k_buf[i] ); |
---|
| 541 | |
---|
[598] | 542 | if( error ) return -1; |
---|
| 543 | } |
---|
[407] | 544 | |
---|
[598] | 545 | // move burst bytes from k_buf to u_buf |
---|
| 546 | hal_strcpy_to_uspace( u_buf , k_buf , burst ); |
---|
| 547 | |
---|
| 548 | // update loop variables |
---|
| 549 | todo -= burst; |
---|
| 550 | u_buf += burst; |
---|
| 551 | } |
---|
| 552 | |
---|
[438] | 553 | #if DEBUG_DEVFS_MOVE |
---|
[433] | 554 | cycle = (uint32_t)hal_get_cycles(); |
---|
[438] | 555 | if( DEBUG_DEVFS_MOVE < cycle ) |
---|
[598] | 556 | printk("\n[%s] thread[%x,%x] exit / to_mem %d / cycle %d\n", |
---|
| 557 | __FUNCTION__, this->process->pid, this->trdid, to_buffer, cycle ); |
---|
[433] | 558 | #endif |
---|
| 559 | |
---|
[438] | 560 | #if (DEBUG_SYS_READ & 1) |
---|
[435] | 561 | exit_devfs_read = hal_time_stamp(); |
---|
[407] | 562 | #endif |
---|
| 563 | return size; |
---|
[598] | 564 | } |
---|
| 565 | ///////////// TXT write |
---|
| 566 | else |
---|
| 567 | { |
---|
| 568 | while( todo ) |
---|
[407] | 569 | { |
---|
[598] | 570 | // set burst size |
---|
| 571 | if( todo > CONFIG_TXT_KBUF_SIZE ) burst = CONFIG_TXT_KBUF_SIZE; |
---|
| 572 | else burst = todo; |
---|
[407] | 573 | |
---|
[598] | 574 | // move burst bytes from u_buf to k_buf |
---|
| 575 | hal_strcpy_from_uspace( k_buf , u_buf , burst ); |
---|
[407] | 576 | |
---|
[598] | 577 | // write burst bytes from kernel buffer to TXT device |
---|
| 578 | error = dev_txt_write( channel , k_buf , burst ); |
---|
| 579 | |
---|
| 580 | if( error ) return -1; |
---|
| 581 | |
---|
| 582 | // update loop variables |
---|
| 583 | todo -= burst; |
---|
| 584 | u_buf += burst; |
---|
| 585 | } |
---|
| 586 | |
---|
[438] | 587 | #if DEBUG_DEVFS_MOVE |
---|
[433] | 588 | cycle = (uint32_t)hal_get_cycles(); |
---|
[438] | 589 | if( DEBUG_DEVFS_MOVE < cycle ) |
---|
[598] | 590 | printk("\n[%s] thread[%x,%x] exit / to_mem %d / cycle %d\n", |
---|
| 591 | __FUNCTION__, this->process->pid, this->trdid, to_buffer, cycle ); |
---|
[433] | 592 | #endif |
---|
[407] | 593 | |
---|
[438] | 594 | #if (DEBUG_SYS_WRITE & 1) |
---|
[435] | 595 | exit_devfs_write = hal_time_stamp(); |
---|
| 596 | #endif |
---|
[598] | 597 | return size; |
---|
[407] | 598 | } |
---|
| 599 | |
---|
| 600 | } // end devfs_user_move() |
---|
| 601 | |
---|
| 602 | |
---|