[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 | |
---|
| 25 | #include <hal_types.h> |
---|
| 26 | #include <hal_special.h> |
---|
| 27 | #include <printk.h> |
---|
| 28 | #include <chdev.h> |
---|
[188] | 29 | #include <cluster.h> |
---|
[23] | 30 | #include <vfs.h> |
---|
[188] | 31 | #include <kmem.h> |
---|
[23] | 32 | #include <devfs.h> |
---|
| 33 | |
---|
[188] | 34 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 35 | // Extern variables |
---|
| 36 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
[23] | 37 | |
---|
[188] | 38 | extern vfs_ctx_t fs_context[]; // allocated in kernel_init.c |
---|
| 39 | extern chdev_directory_t chdev_dir; // allocated in kernel_init.c |
---|
[23] | 40 | |
---|
[188] | 41 | /////////////////////////////// |
---|
| 42 | devfs_ctx_t * devfs_ctx_alloc() |
---|
| 43 | { |
---|
| 44 | kmem_req_t req; |
---|
[23] | 45 | |
---|
[188] | 46 | req.type = KMEM_DEVFS_CTX; |
---|
| 47 | req.size = sizeof(devfs_ctx_t); |
---|
| 48 | req.flags = AF_KERNEL | AF_ZERO; |
---|
[23] | 49 | |
---|
[188] | 50 | return (devfs_ctx_t *)kmem_alloc( &req ); |
---|
| 51 | } |
---|
[23] | 52 | |
---|
[188] | 53 | ///////////////////////////////////////////// |
---|
| 54 | void devfs_ctx_init( devfs_ctx_t * devfs_ctx, |
---|
[204] | 55 | xptr_t devfs_dev_inode_xp, |
---|
[188] | 56 | xptr_t devfs_external_inode_xp ) |
---|
[23] | 57 | { |
---|
[204] | 58 | devfs_ctx->dev_inode_xp = devfs_dev_inode_xp; |
---|
[188] | 59 | devfs_ctx->external_inode_xp = devfs_external_inode_xp; |
---|
[23] | 60 | |
---|
[188] | 61 | fs_context[FS_TYPE_DEVFS].extend = devfs_ctx; |
---|
| 62 | } |
---|
[23] | 63 | |
---|
[188] | 64 | ///////////////////////////////////////////////// |
---|
| 65 | void devfs_ctx_destroy( devfs_ctx_t * devfs_ctx ) |
---|
| 66 | { |
---|
| 67 | kmem_req_t req; |
---|
[23] | 68 | |
---|
[188] | 69 | req.type = KMEM_DEVFS_CTX; |
---|
| 70 | req.ptr = devfs_ctx; |
---|
| 71 | kmem_free( &req ); |
---|
| 72 | } |
---|
[23] | 73 | |
---|
[188] | 74 | /////////////////////////////////////////////////// |
---|
| 75 | void devfs_global_init( xptr_t parent_inode_xp, |
---|
[204] | 76 | xptr_t * devfs_dev_inode_xp, |
---|
[188] | 77 | xptr_t * devfs_external_inode_xp ) |
---|
[23] | 78 | { |
---|
| 79 | error_t error; |
---|
| 80 | |
---|
[279] | 81 | devfs_dmsg("\n[INFO] %s : enter in cluster %x\n", |
---|
| 82 | __FUNCTION__ , local_cxy ); |
---|
| 83 | |
---|
[188] | 84 | // creates DEVFS "dev" inode in cluster IO |
---|
| 85 | error = vfs_add_child_in_parent( LOCAL_CLUSTER->io_cxy, |
---|
| 86 | INODE_TYPE_DIR, |
---|
| 87 | FS_TYPE_DEVFS, |
---|
| 88 | parent_inode_xp, |
---|
| 89 | "dev", |
---|
| 90 | NULL, |
---|
[204] | 91 | devfs_dev_inode_xp ); |
---|
[23] | 92 | |
---|
[279] | 93 | assert( (error == 0) , __FUNCTION__ , "cannot create <dev>\n" ); |
---|
[23] | 94 | |
---|
[279] | 95 | devfs_dmsg("\n[INFO] %s : <dev> created in cluster %x\n", |
---|
| 96 | __FUNCTION__ , local_cxy ); |
---|
| 97 | |
---|
[188] | 98 | // create DEVFS "external" inode in cluster IO |
---|
| 99 | error = vfs_add_child_in_parent( LOCAL_CLUSTER->io_cxy, |
---|
| 100 | INODE_TYPE_DIR, |
---|
| 101 | FS_TYPE_DEVFS, |
---|
[204] | 102 | *devfs_dev_inode_xp, |
---|
| 103 | "external", |
---|
[188] | 104 | NULL, |
---|
| 105 | devfs_external_inode_xp ); |
---|
[23] | 106 | |
---|
[279] | 107 | assert( (error == 0) , __FUNCTION__ , "cannot create <external>\n" ); |
---|
| 108 | |
---|
| 109 | devfs_dmsg("\n[INFO] %s : <external> created in cluster %x\n", |
---|
| 110 | __FUNCTION__ , local_cxy ); |
---|
[188] | 111 | } |
---|
[23] | 112 | |
---|
[204] | 113 | /////////////////////////////////////////////////// |
---|
| 114 | void devfs_local_init( xptr_t devfs_dev_inode_xp, |
---|
| 115 | xptr_t devfs_external_inode_xp, |
---|
| 116 | xptr_t * devfs_internal_inode_xp ) |
---|
[23] | 117 | { |
---|
| 118 | char node_name[16]; |
---|
[188] | 119 | xptr_t chdev_xp; |
---|
| 120 | cxy_t chdev_cxy; |
---|
| 121 | xptr_t inode_xp; |
---|
[23] | 122 | uint32_t channel; |
---|
| 123 | |
---|
[188] | 124 | // create "internal" directory linked to "dev" |
---|
| 125 | snprintf( node_name , 16 , "internal_%x" , local_cxy ); |
---|
| 126 | vfs_add_child_in_parent( local_cxy, |
---|
| 127 | INODE_TYPE_DIR, |
---|
| 128 | FS_TYPE_DEVFS, |
---|
[204] | 129 | devfs_dev_inode_xp, |
---|
[188] | 130 | node_name, |
---|
| 131 | NULL, |
---|
[204] | 132 | devfs_internal_inode_xp ); |
---|
[23] | 133 | |
---|
| 134 | // create MMC chdev inode |
---|
[188] | 135 | chdev_xp = chdev_dir.mmc[local_cxy]; |
---|
| 136 | if( chdev_xp != XPTR_NULL) |
---|
| 137 | { |
---|
| 138 | vfs_add_child_in_parent( local_cxy, |
---|
| 139 | INODE_TYPE_DEV, |
---|
| 140 | FS_TYPE_DEVFS, |
---|
[204] | 141 | *devfs_internal_inode_xp, |
---|
[188] | 142 | "mmc", |
---|
| 143 | GET_PTR( chdev_xp ), |
---|
| 144 | &inode_xp ); |
---|
| 145 | } |
---|
[23] | 146 | |
---|
| 147 | // create DMA chdev inodes (one DMA channel per core) |
---|
[188] | 148 | for( channel = 0 ; channel < LOCAL_CLUSTER->cores_nr ; channel++ ) |
---|
[23] | 149 | { |
---|
[188] | 150 | chdev_xp = chdev_dir.dma[channel]; |
---|
| 151 | if( chdev_xp != XPTR_NULL) |
---|
| 152 | { |
---|
| 153 | snprintf( node_name , 16 , "dma_%d" , channel ); |
---|
| 154 | vfs_add_child_in_parent( local_cxy, |
---|
| 155 | INODE_TYPE_DEV, |
---|
| 156 | FS_TYPE_DEVFS, |
---|
[204] | 157 | *devfs_internal_inode_xp, |
---|
[188] | 158 | node_name, |
---|
| 159 | GET_PTR( chdev_xp ), |
---|
| 160 | &inode_xp ); |
---|
| 161 | } |
---|
[23] | 162 | } |
---|
| 163 | |
---|
[188] | 164 | // create an IOB inode in cluster containing IOB chdev |
---|
| 165 | chdev_xp = chdev_dir.iob; |
---|
| 166 | if( chdev_xp != XPTR_NULL ) |
---|
[23] | 167 | { |
---|
[188] | 168 | chdev_cxy = GET_CXY( chdev_xp ); |
---|
| 169 | if( chdev_cxy == local_cxy ) |
---|
| 170 | { |
---|
| 171 | vfs_add_child_in_parent( local_cxy, |
---|
| 172 | INODE_TYPE_DEV, |
---|
| 173 | FS_TYPE_DEVFS, |
---|
| 174 | devfs_external_inode_xp, |
---|
| 175 | "iob", |
---|
| 176 | GET_PTR( chdev_xp ), |
---|
| 177 | &inode_xp ); |
---|
| 178 | } |
---|
| 179 | } |
---|
[23] | 180 | |
---|
[188] | 181 | // create a PIC inode in cluster containing PIC chdev |
---|
| 182 | chdev_xp = chdev_dir.pic; |
---|
| 183 | if( chdev_xp != XPTR_NULL ) |
---|
| 184 | { |
---|
| 185 | chdev_cxy = GET_CXY( chdev_xp ); |
---|
| 186 | if( chdev_cxy == local_cxy ) |
---|
[23] | 187 | { |
---|
[188] | 188 | vfs_add_child_in_parent( local_cxy, |
---|
| 189 | INODE_TYPE_DEV, |
---|
| 190 | FS_TYPE_DEVFS, |
---|
| 191 | devfs_external_inode_xp, |
---|
| 192 | "pic", |
---|
| 193 | GET_PTR( chdev_xp ), |
---|
| 194 | &inode_xp ); |
---|
[23] | 195 | } |
---|
[188] | 196 | } |
---|
[23] | 197 | |
---|
[188] | 198 | // create a TXT inode in each cluster containing a TXT chdev |
---|
| 199 | for( channel = 0 ; channel < CONFIG_MAX_TXT_CHANNELS ; channel++ ) |
---|
| 200 | { |
---|
| 201 | chdev_xp = chdev_dir.txt[channel]; |
---|
| 202 | if( chdev_xp != XPTR_NULL ) |
---|
[23] | 203 | { |
---|
[188] | 204 | chdev_cxy = GET_CXY( chdev_xp ); |
---|
| 205 | if( chdev_cxy == local_cxy ) |
---|
| 206 | { |
---|
| 207 | snprintf( node_name , 16 , "txt_%d" , channel ); |
---|
| 208 | vfs_add_child_in_parent( local_cxy, |
---|
| 209 | INODE_TYPE_DEV, |
---|
| 210 | FS_TYPE_DEVFS, |
---|
| 211 | devfs_external_inode_xp, |
---|
| 212 | node_name, |
---|
| 213 | GET_PTR( chdev_xp ), |
---|
| 214 | &inode_xp ); |
---|
| 215 | } |
---|
[23] | 216 | } |
---|
[188] | 217 | } |
---|
[23] | 218 | |
---|
[188] | 219 | // create an IOC inode in each cluster containing an IOC chdev |
---|
| 220 | for( channel = 0 ; channel < CONFIG_MAX_IOC_CHANNELS ; channel++ ) |
---|
| 221 | { |
---|
| 222 | chdev_xp = chdev_dir.ioc[channel]; |
---|
| 223 | if( chdev_xp != XPTR_NULL ) |
---|
[23] | 224 | { |
---|
[188] | 225 | chdev_cxy = GET_CXY( chdev_xp ); |
---|
| 226 | if( chdev_cxy == local_cxy ) |
---|
| 227 | { |
---|
| 228 | snprintf( node_name , 16 , "ioc_%d" , channel ); |
---|
| 229 | vfs_add_child_in_parent( local_cxy, |
---|
| 230 | INODE_TYPE_DEV, |
---|
| 231 | FS_TYPE_DEVFS, |
---|
| 232 | devfs_external_inode_xp, |
---|
| 233 | node_name, |
---|
| 234 | GET_PTR( chdev_xp ), |
---|
| 235 | &inode_xp ); |
---|
| 236 | } |
---|
[23] | 237 | } |
---|
[188] | 238 | } |
---|
[23] | 239 | |
---|
[188] | 240 | // create a FBF inode in each cluster containing a FBF chdev |
---|
| 241 | for( channel = 0 ; channel < CONFIG_MAX_IOC_CHANNELS ; channel++ ) |
---|
| 242 | { |
---|
| 243 | chdev_xp = chdev_dir.fbf[channel]; |
---|
| 244 | if( chdev_xp != XPTR_NULL ) |
---|
[23] | 245 | { |
---|
[188] | 246 | chdev_cxy = GET_CXY( chdev_xp ); |
---|
| 247 | if( chdev_cxy == local_cxy ) |
---|
| 248 | { |
---|
| 249 | snprintf( node_name , 16 , "fbf_%d" , channel ); |
---|
| 250 | vfs_add_child_in_parent( local_cxy, |
---|
| 251 | INODE_TYPE_DEV, |
---|
| 252 | FS_TYPE_DEVFS, |
---|
| 253 | devfs_external_inode_xp, |
---|
| 254 | node_name, |
---|
| 255 | GET_PTR( chdev_xp ), |
---|
| 256 | &inode_xp ); |
---|
| 257 | } |
---|
[23] | 258 | } |
---|
[188] | 259 | } |
---|
[23] | 260 | |
---|
[188] | 261 | // create a NIC_RX inode in each cluster containing a NIC_RX chdev |
---|
| 262 | for( channel = 0 ; channel < CONFIG_MAX_NIC_CHANNELS ; channel++ ) |
---|
| 263 | { |
---|
| 264 | chdev_xp = chdev_dir.nic_rx[channel]; |
---|
| 265 | if( chdev_xp != XPTR_NULL ) |
---|
[23] | 266 | { |
---|
[188] | 267 | chdev_cxy = GET_CXY( chdev_xp ); |
---|
| 268 | if( chdev_cxy == local_cxy ) |
---|
| 269 | { |
---|
| 270 | snprintf( node_name , 16 , "nic_rx_%d" , channel ); |
---|
| 271 | vfs_add_child_in_parent( local_cxy, |
---|
| 272 | INODE_TYPE_DEV, |
---|
| 273 | FS_TYPE_DEVFS, |
---|
| 274 | devfs_external_inode_xp, |
---|
| 275 | node_name, |
---|
| 276 | GET_PTR( chdev_xp ), |
---|
| 277 | &inode_xp ); |
---|
| 278 | } |
---|
[23] | 279 | } |
---|
| 280 | } |
---|
| 281 | |
---|
[188] | 282 | // create a NIC_TX inode in each cluster containing a NIC_TX chdev |
---|
| 283 | for( channel = 0 ; channel < CONFIG_MAX_NIC_CHANNELS ; channel++ ) |
---|
[23] | 284 | { |
---|
[188] | 285 | chdev_xp = chdev_dir.nic_tx[channel]; |
---|
| 286 | if( chdev_xp != XPTR_NULL ) |
---|
| 287 | { |
---|
| 288 | chdev_cxy = GET_CXY( chdev_xp ); |
---|
| 289 | if( chdev_cxy == local_cxy ) |
---|
| 290 | { |
---|
| 291 | snprintf( node_name , 16 , "nic_tx_%d" , channel ); |
---|
| 292 | vfs_add_child_in_parent( local_cxy, |
---|
| 293 | INODE_TYPE_DEV, |
---|
| 294 | FS_TYPE_DEVFS, |
---|
| 295 | devfs_external_inode_xp, |
---|
| 296 | node_name, |
---|
| 297 | GET_PTR( chdev_xp ), |
---|
| 298 | &inode_xp ); |
---|
| 299 | } |
---|
| 300 | } |
---|
[23] | 301 | } |
---|
[188] | 302 | } // end devfs_local_init() |
---|
[23] | 303 | |
---|