| 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>
|
|---|
| 29 | #include <cluster.h>
|
|---|
| 30 | #include <vfs.h>
|
|---|
| 31 | #include <kmem.h>
|
|---|
| 32 | #include <devfs.h>
|
|---|
| 33 |
|
|---|
| 34 | /////////////////////////////////////////////////////////////////////////////////////////
|
|---|
| 35 | // Extern variables
|
|---|
| 36 | /////////////////////////////////////////////////////////////////////////////////////////
|
|---|
| 37 |
|
|---|
| 38 | extern vfs_ctx_t fs_context[]; // allocated in kernel_init.c
|
|---|
| 39 | extern chdev_directory_t chdev_dir; // allocated in kernel_init.c
|
|---|
| 40 |
|
|---|
| 41 | ///////////////////////////////
|
|---|
| 42 | devfs_ctx_t * devfs_ctx_alloc()
|
|---|
| 43 | {
|
|---|
| 44 | kmem_req_t req;
|
|---|
| 45 |
|
|---|
| 46 | req.type = KMEM_DEVFS_CTX;
|
|---|
| 47 | req.size = sizeof(devfs_ctx_t);
|
|---|
| 48 | req.flags = AF_KERNEL | AF_ZERO;
|
|---|
| 49 |
|
|---|
| 50 | return (devfs_ctx_t *)kmem_alloc( &req );
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | /////////////////////////////////////////////
|
|---|
| 54 | void devfs_ctx_init( devfs_ctx_t * devfs_ctx,
|
|---|
| 55 | xptr_t devfs_dev_inode_xp,
|
|---|
| 56 | xptr_t devfs_external_inode_xp )
|
|---|
| 57 | {
|
|---|
| 58 | devfs_ctx->dev_inode_xp = devfs_dev_inode_xp;
|
|---|
| 59 | devfs_ctx->external_inode_xp = devfs_external_inode_xp;
|
|---|
| 60 |
|
|---|
| 61 | fs_context[FS_TYPE_DEVFS].extend = devfs_ctx;
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | /////////////////////////////////////////////////
|
|---|
| 65 | void devfs_ctx_destroy( devfs_ctx_t * devfs_ctx )
|
|---|
| 66 | {
|
|---|
| 67 | kmem_req_t req;
|
|---|
| 68 |
|
|---|
| 69 | req.type = KMEM_DEVFS_CTX;
|
|---|
| 70 | req.ptr = devfs_ctx;
|
|---|
| 71 | kmem_free( &req );
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | ///////////////////////////////////////////////////
|
|---|
| 75 | void devfs_global_init( xptr_t parent_inode_xp,
|
|---|
| 76 | xptr_t * devfs_dev_inode_xp,
|
|---|
| 77 | xptr_t * devfs_external_inode_xp )
|
|---|
| 78 | {
|
|---|
| 79 | error_t error;
|
|---|
| 80 |
|
|---|
| 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,
|
|---|
| 88 | devfs_dev_inode_xp );
|
|---|
| 89 |
|
|---|
| 90 | nolock_assert( (error == 0) , __FUNCTION__ , "cannot create <dev>\n" );
|
|---|
| 91 |
|
|---|
| 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,
|
|---|
| 96 | *devfs_dev_inode_xp,
|
|---|
| 97 | "external",
|
|---|
| 98 | NULL,
|
|---|
| 99 | devfs_external_inode_xp );
|
|---|
| 100 |
|
|---|
| 101 | nolock_assert( (error == 0) , __FUNCTION__ , "cannot create <external>\n" );
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 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 )
|
|---|
| 108 | {
|
|---|
| 109 | char node_name[16];
|
|---|
| 110 | xptr_t chdev_xp;
|
|---|
| 111 | cxy_t chdev_cxy;
|
|---|
| 112 | xptr_t inode_xp;
|
|---|
| 113 | uint32_t channel;
|
|---|
| 114 |
|
|---|
| 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,
|
|---|
| 120 | devfs_dev_inode_xp,
|
|---|
| 121 | node_name,
|
|---|
| 122 | NULL,
|
|---|
| 123 | devfs_internal_inode_xp );
|
|---|
| 124 |
|
|---|
| 125 | // create MMC chdev inode
|
|---|
| 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,
|
|---|
| 132 | *devfs_internal_inode_xp,
|
|---|
| 133 | "mmc",
|
|---|
| 134 | GET_PTR( chdev_xp ),
|
|---|
| 135 | &inode_xp );
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | // create DMA chdev inodes (one DMA channel per core)
|
|---|
| 139 | for( channel = 0 ; channel < LOCAL_CLUSTER->cores_nr ; channel++ )
|
|---|
| 140 | {
|
|---|
| 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,
|
|---|
| 148 | *devfs_internal_inode_xp,
|
|---|
| 149 | node_name,
|
|---|
| 150 | GET_PTR( chdev_xp ),
|
|---|
| 151 | &inode_xp );
|
|---|
| 152 | }
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | // create an IOB inode in cluster containing IOB chdev
|
|---|
| 156 | chdev_xp = chdev_dir.iob;
|
|---|
| 157 | if( chdev_xp != XPTR_NULL )
|
|---|
| 158 | {
|
|---|
| 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 | }
|
|---|
| 171 |
|
|---|
| 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 )
|
|---|
| 178 | {
|
|---|
| 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 );
|
|---|
| 186 | }
|
|---|
| 187 | }
|
|---|
| 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 )
|
|---|
| 194 | {
|
|---|
| 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 | }
|
|---|
| 207 | }
|
|---|
| 208 | }
|
|---|
| 209 |
|
|---|
| 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 )
|
|---|
| 215 | {
|
|---|
| 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 | }
|
|---|
| 228 | }
|
|---|
| 229 | }
|
|---|
| 230 |
|
|---|
| 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 )
|
|---|
| 236 | {
|
|---|
| 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 | }
|
|---|
| 249 | }
|
|---|
| 250 | }
|
|---|
| 251 |
|
|---|
| 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 )
|
|---|
| 257 | {
|
|---|
| 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 | }
|
|---|
| 270 | }
|
|---|
| 271 | }
|
|---|
| 272 |
|
|---|
| 273 | // create a NIC_TX inode in each cluster containing a NIC_TX chdev
|
|---|
| 274 | for( channel = 0 ; channel < CONFIG_MAX_NIC_CHANNELS ; channel++ )
|
|---|
| 275 | {
|
|---|
| 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 | }
|
|---|
| 292 | }
|
|---|
| 293 | } // end devfs_local_init()
|
|---|
| 294 |
|
|---|