[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 | |
---|
[188] | 81 | // creates DEVFS "dev" inode in cluster IO |
---|
| 82 | error = vfs_add_child_in_parent( LOCAL_CLUSTER->io_cxy, |
---|
| 83 | INODE_TYPE_DIR, |
---|
| 84 | FS_TYPE_DEVFS, |
---|
| 85 | parent_inode_xp, |
---|
| 86 | "dev", |
---|
| 87 | NULL, |
---|
[204] | 88 | devfs_dev_inode_xp ); |
---|
[23] | 89 | |
---|
[188] | 90 | nolock_assert( (error == 0) , __FUNCTION__ , "cannot create <dev>\n" ); |
---|
[23] | 91 | |
---|
[188] | 92 | // create DEVFS "external" inode in cluster IO |
---|
| 93 | error = vfs_add_child_in_parent( LOCAL_CLUSTER->io_cxy, |
---|
| 94 | INODE_TYPE_DIR, |
---|
| 95 | FS_TYPE_DEVFS, |
---|
[204] | 96 | *devfs_dev_inode_xp, |
---|
| 97 | "external", |
---|
[188] | 98 | NULL, |
---|
| 99 | devfs_external_inode_xp ); |
---|
[23] | 100 | |
---|
[188] | 101 | nolock_assert( (error == 0) , __FUNCTION__ , "cannot create <external>\n" ); |
---|
| 102 | } |
---|
[23] | 103 | |
---|
[204] | 104 | /////////////////////////////////////////////////// |
---|
| 105 | void devfs_local_init( xptr_t devfs_dev_inode_xp, |
---|
| 106 | xptr_t devfs_external_inode_xp, |
---|
| 107 | xptr_t * devfs_internal_inode_xp ) |
---|
[23] | 108 | { |
---|
| 109 | char node_name[16]; |
---|
[188] | 110 | xptr_t chdev_xp; |
---|
| 111 | cxy_t chdev_cxy; |
---|
| 112 | xptr_t inode_xp; |
---|
[23] | 113 | uint32_t channel; |
---|
| 114 | |
---|
[188] | 115 | // create "internal" directory linked to "dev" |
---|
| 116 | snprintf( node_name , 16 , "internal_%x" , local_cxy ); |
---|
| 117 | vfs_add_child_in_parent( local_cxy, |
---|
| 118 | INODE_TYPE_DIR, |
---|
| 119 | FS_TYPE_DEVFS, |
---|
[204] | 120 | devfs_dev_inode_xp, |
---|
[188] | 121 | node_name, |
---|
| 122 | NULL, |
---|
[204] | 123 | devfs_internal_inode_xp ); |
---|
[23] | 124 | |
---|
| 125 | // create MMC chdev inode |
---|
[188] | 126 | chdev_xp = chdev_dir.mmc[local_cxy]; |
---|
| 127 | if( chdev_xp != XPTR_NULL) |
---|
| 128 | { |
---|
| 129 | vfs_add_child_in_parent( local_cxy, |
---|
| 130 | INODE_TYPE_DEV, |
---|
| 131 | FS_TYPE_DEVFS, |
---|
[204] | 132 | *devfs_internal_inode_xp, |
---|
[188] | 133 | "mmc", |
---|
| 134 | GET_PTR( chdev_xp ), |
---|
| 135 | &inode_xp ); |
---|
| 136 | } |
---|
[23] | 137 | |
---|
| 138 | // create DMA chdev inodes (one DMA channel per core) |
---|
[188] | 139 | for( channel = 0 ; channel < LOCAL_CLUSTER->cores_nr ; channel++ ) |
---|
[23] | 140 | { |
---|
[188] | 141 | chdev_xp = chdev_dir.dma[channel]; |
---|
| 142 | if( chdev_xp != XPTR_NULL) |
---|
| 143 | { |
---|
| 144 | snprintf( node_name , 16 , "dma_%d" , channel ); |
---|
| 145 | vfs_add_child_in_parent( local_cxy, |
---|
| 146 | INODE_TYPE_DEV, |
---|
| 147 | FS_TYPE_DEVFS, |
---|
[204] | 148 | *devfs_internal_inode_xp, |
---|
[188] | 149 | node_name, |
---|
| 150 | GET_PTR( chdev_xp ), |
---|
| 151 | &inode_xp ); |
---|
| 152 | } |
---|
[23] | 153 | } |
---|
| 154 | |
---|
[188] | 155 | // create an IOB inode in cluster containing IOB chdev |
---|
| 156 | chdev_xp = chdev_dir.iob; |
---|
| 157 | if( chdev_xp != XPTR_NULL ) |
---|
[23] | 158 | { |
---|
[188] | 159 | chdev_cxy = GET_CXY( chdev_xp ); |
---|
| 160 | if( chdev_cxy == local_cxy ) |
---|
| 161 | { |
---|
| 162 | vfs_add_child_in_parent( local_cxy, |
---|
| 163 | INODE_TYPE_DEV, |
---|
| 164 | FS_TYPE_DEVFS, |
---|
| 165 | devfs_external_inode_xp, |
---|
| 166 | "iob", |
---|
| 167 | GET_PTR( chdev_xp ), |
---|
| 168 | &inode_xp ); |
---|
| 169 | } |
---|
| 170 | } |
---|
[23] | 171 | |
---|
[188] | 172 | // create a PIC inode in cluster containing PIC chdev |
---|
| 173 | chdev_xp = chdev_dir.pic; |
---|
| 174 | if( chdev_xp != XPTR_NULL ) |
---|
| 175 | { |
---|
| 176 | chdev_cxy = GET_CXY( chdev_xp ); |
---|
| 177 | if( chdev_cxy == local_cxy ) |
---|
[23] | 178 | { |
---|
[188] | 179 | vfs_add_child_in_parent( local_cxy, |
---|
| 180 | INODE_TYPE_DEV, |
---|
| 181 | FS_TYPE_DEVFS, |
---|
| 182 | devfs_external_inode_xp, |
---|
| 183 | "pic", |
---|
| 184 | GET_PTR( chdev_xp ), |
---|
| 185 | &inode_xp ); |
---|
[23] | 186 | } |
---|
[188] | 187 | } |
---|
[23] | 188 | |
---|
[188] | 189 | // create a TXT inode in each cluster containing a TXT chdev |
---|
| 190 | for( channel = 0 ; channel < CONFIG_MAX_TXT_CHANNELS ; channel++ ) |
---|
| 191 | { |
---|
| 192 | chdev_xp = chdev_dir.txt[channel]; |
---|
| 193 | if( chdev_xp != XPTR_NULL ) |
---|
[23] | 194 | { |
---|
[188] | 195 | chdev_cxy = GET_CXY( chdev_xp ); |
---|
| 196 | if( chdev_cxy == local_cxy ) |
---|
| 197 | { |
---|
| 198 | snprintf( node_name , 16 , "txt_%d" , channel ); |
---|
| 199 | vfs_add_child_in_parent( local_cxy, |
---|
| 200 | INODE_TYPE_DEV, |
---|
| 201 | FS_TYPE_DEVFS, |
---|
| 202 | devfs_external_inode_xp, |
---|
| 203 | node_name, |
---|
| 204 | GET_PTR( chdev_xp ), |
---|
| 205 | &inode_xp ); |
---|
| 206 | } |
---|
[23] | 207 | } |
---|
[188] | 208 | } |
---|
[23] | 209 | |
---|
[188] | 210 | // create an IOC inode in each cluster containing an IOC chdev |
---|
| 211 | for( channel = 0 ; channel < CONFIG_MAX_IOC_CHANNELS ; channel++ ) |
---|
| 212 | { |
---|
| 213 | chdev_xp = chdev_dir.ioc[channel]; |
---|
| 214 | if( chdev_xp != XPTR_NULL ) |
---|
[23] | 215 | { |
---|
[188] | 216 | chdev_cxy = GET_CXY( chdev_xp ); |
---|
| 217 | if( chdev_cxy == local_cxy ) |
---|
| 218 | { |
---|
| 219 | snprintf( node_name , 16 , "ioc_%d" , channel ); |
---|
| 220 | vfs_add_child_in_parent( local_cxy, |
---|
| 221 | INODE_TYPE_DEV, |
---|
| 222 | FS_TYPE_DEVFS, |
---|
| 223 | devfs_external_inode_xp, |
---|
| 224 | node_name, |
---|
| 225 | GET_PTR( chdev_xp ), |
---|
| 226 | &inode_xp ); |
---|
| 227 | } |
---|
[23] | 228 | } |
---|
[188] | 229 | } |
---|
[23] | 230 | |
---|
[188] | 231 | // create a FBF inode in each cluster containing a FBF chdev |
---|
| 232 | for( channel = 0 ; channel < CONFIG_MAX_IOC_CHANNELS ; channel++ ) |
---|
| 233 | { |
---|
| 234 | chdev_xp = chdev_dir.fbf[channel]; |
---|
| 235 | if( chdev_xp != XPTR_NULL ) |
---|
[23] | 236 | { |
---|
[188] | 237 | chdev_cxy = GET_CXY( chdev_xp ); |
---|
| 238 | if( chdev_cxy == local_cxy ) |
---|
| 239 | { |
---|
| 240 | snprintf( node_name , 16 , "fbf_%d" , channel ); |
---|
| 241 | vfs_add_child_in_parent( local_cxy, |
---|
| 242 | INODE_TYPE_DEV, |
---|
| 243 | FS_TYPE_DEVFS, |
---|
| 244 | devfs_external_inode_xp, |
---|
| 245 | node_name, |
---|
| 246 | GET_PTR( chdev_xp ), |
---|
| 247 | &inode_xp ); |
---|
| 248 | } |
---|
[23] | 249 | } |
---|
[188] | 250 | } |
---|
[23] | 251 | |
---|
[188] | 252 | // create a NIC_RX inode in each cluster containing a NIC_RX chdev |
---|
| 253 | for( channel = 0 ; channel < CONFIG_MAX_NIC_CHANNELS ; channel++ ) |
---|
| 254 | { |
---|
| 255 | chdev_xp = chdev_dir.nic_rx[channel]; |
---|
| 256 | if( chdev_xp != XPTR_NULL ) |
---|
[23] | 257 | { |
---|
[188] | 258 | chdev_cxy = GET_CXY( chdev_xp ); |
---|
| 259 | if( chdev_cxy == local_cxy ) |
---|
| 260 | { |
---|
| 261 | snprintf( node_name , 16 , "nic_rx_%d" , channel ); |
---|
| 262 | vfs_add_child_in_parent( local_cxy, |
---|
| 263 | INODE_TYPE_DEV, |
---|
| 264 | FS_TYPE_DEVFS, |
---|
| 265 | devfs_external_inode_xp, |
---|
| 266 | node_name, |
---|
| 267 | GET_PTR( chdev_xp ), |
---|
| 268 | &inode_xp ); |
---|
| 269 | } |
---|
[23] | 270 | } |
---|
| 271 | } |
---|
| 272 | |
---|
[188] | 273 | // create a NIC_TX inode in each cluster containing a NIC_TX chdev |
---|
| 274 | for( channel = 0 ; channel < CONFIG_MAX_NIC_CHANNELS ; channel++ ) |
---|
[23] | 275 | { |
---|
[188] | 276 | chdev_xp = chdev_dir.nic_tx[channel]; |
---|
| 277 | if( chdev_xp != XPTR_NULL ) |
---|
| 278 | { |
---|
| 279 | chdev_cxy = GET_CXY( chdev_xp ); |
---|
| 280 | if( chdev_cxy == local_cxy ) |
---|
| 281 | { |
---|
| 282 | snprintf( node_name , 16 , "nic_tx_%d" , channel ); |
---|
| 283 | vfs_add_child_in_parent( local_cxy, |
---|
| 284 | INODE_TYPE_DEV, |
---|
| 285 | FS_TYPE_DEVFS, |
---|
| 286 | devfs_external_inode_xp, |
---|
| 287 | node_name, |
---|
| 288 | GET_PTR( chdev_xp ), |
---|
| 289 | &inode_xp ); |
---|
| 290 | } |
---|
| 291 | } |
---|
[23] | 292 | } |
---|
[188] | 293 | } // end devfs_local_init() |
---|
[23] | 294 | |
---|