[1] | 1 | /* |
---|
| 2 | * kernel_init.c - kernel parallel initialization |
---|
| 3 | * |
---|
[23] | 4 | * Authors : Mohamed Lamine Karaoui (2015) |
---|
| 5 | * Alain Greiner (2016,2017) |
---|
[1] | 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 | |
---|
[14] | 25 | #include <kernel_config.h> |
---|
[1] | 26 | #include <errno.h> |
---|
| 27 | #include <hal_types.h> |
---|
| 28 | #include <hal_special.h> |
---|
| 29 | #include <hal_context.h> |
---|
[14] | 30 | #include <barrier.h> |
---|
[1] | 31 | #include <remote_barrier.h> |
---|
| 32 | #include <core.h> |
---|
| 33 | #include <list.h> |
---|
[68] | 34 | #include <xlist.h> |
---|
[1] | 35 | #include <thread.h> |
---|
| 36 | #include <scheduler.h> |
---|
| 37 | #include <kmem.h> |
---|
| 38 | #include <cluster.h> |
---|
| 39 | #include <string.h> |
---|
| 40 | #include <memcpy.h> |
---|
| 41 | #include <ppm.h> |
---|
| 42 | #include <page.h> |
---|
[5] | 43 | #include <chdev.h> |
---|
[1] | 44 | #include <boot_info.h> |
---|
| 45 | #include <dqdt.h> |
---|
| 46 | #include <dev_icu.h> |
---|
| 47 | #include <dev_mmc.h> |
---|
[5] | 48 | #include <dev_dma.h> |
---|
| 49 | #include <dev_iob.h> |
---|
[1] | 50 | #include <dev_ioc.h> |
---|
[5] | 51 | #include <dev_txt.h> |
---|
[1] | 52 | #include <dev_pic.h> |
---|
| 53 | #include <printk.h> |
---|
| 54 | #include <vfs.h> |
---|
[5] | 55 | #include <soclib_tty.h> |
---|
[23] | 56 | #include <devfs.h> |
---|
[68] | 57 | #include <mapper.h> |
---|
[1] | 58 | |
---|
| 59 | |
---|
[5] | 60 | #define KERNEL_INIT_SYNCHRO 0xA5A5B5B5 |
---|
[1] | 61 | |
---|
| 62 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 63 | // All these global variables are replicated in all clusters. |
---|
| 64 | // They are initialised by the kernel_init() function. |
---|
[14] | 65 | // |
---|
| 66 | // WARNING : The section names have been defined to control the base addresses of the |
---|
| 67 | // boot_info structure and the idle thread descriptors, through the kernel.ld script: |
---|
| 68 | // - the boot_info structure is build by the bootloader, and used by kernel_init. |
---|
| 69 | // it must be first object in the kdata segment. |
---|
| 70 | // - the array of idle threads descriptors must be placed on the first page boundary after |
---|
| 71 | // the boot_info structure in the kdata segment. |
---|
[1] | 72 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 73 | |
---|
[5] | 74 | // This variable defines the local boot_info structure |
---|
| 75 | __attribute__((section(".kinfo"))) |
---|
[14] | 76 | boot_info_t boot_info; |
---|
[5] | 77 | |
---|
[14] | 78 | // This variable defines the "idle" threads descriptors array |
---|
| 79 | __attribute__((section(".kidle"))) |
---|
| 80 | char idle_threads[CONFIG_THREAD_DESC_SIZE * |
---|
| 81 | CONFIG_MAX_LOCAL_CORES] CONFIG_PPM_PAGE_ALIGNED; |
---|
| 82 | |
---|
[1] | 83 | // This variable defines the local cluster manager |
---|
[5] | 84 | __attribute__((section(".kdata"))) |
---|
[19] | 85 | cluster_t cluster_manager CONFIG_CACHE_LINE_ALIGNED; |
---|
[1] | 86 | |
---|
[14] | 87 | // This variables define the kernel process0 descriptor |
---|
[5] | 88 | __attribute__((section(".kdata"))) |
---|
[19] | 89 | process_t process_zero CONFIG_CACHE_LINE_ALIGNED; |
---|
[1] | 90 | |
---|
[14] | 91 | // This variable defines extended pointers on the distributed chdevs |
---|
[5] | 92 | __attribute__((section(".kdata"))) |
---|
[14] | 93 | chdev_directory_t chdev_dir CONFIG_CACHE_LINE_ALIGNED; |
---|
[1] | 94 | |
---|
[5] | 95 | // This variable contains the input IRQ indexes for the PIC device |
---|
| 96 | __attribute__((section(".kdata"))) |
---|
[14] | 97 | chdev_pic_input_t chdev_pic_input CONFIG_CACHE_LINE_ALIGNED; |
---|
[1] | 98 | |
---|
[5] | 99 | // This variable contains the input IRQ indexes for the ICU device |
---|
| 100 | __attribute__((section(".kdata"))) |
---|
[14] | 101 | chdev_icu_input_t chdev_icu_input CONFIG_CACHE_LINE_ALIGNED; |
---|
[1] | 102 | |
---|
[14] | 103 | // This variable defines the local cluster identifier |
---|
[5] | 104 | __attribute__((section(".kdata"))) |
---|
[14] | 105 | cxy_t local_cxy CONFIG_CACHE_LINE_ALIGNED; |
---|
[5] | 106 | |
---|
[14] | 107 | // This variable defines the TXT0 chdev descriptor |
---|
[5] | 108 | __attribute__((section(".kdata"))) |
---|
[14] | 109 | chdev_t txt0_chdev CONFIG_CACHE_LINE_ALIGNED; |
---|
[1] | 110 | |
---|
[14] | 111 | // This variable is used for CP0 cores sychronisation in kernel_init() |
---|
[5] | 112 | __attribute__((section(".kdata"))) |
---|
[14] | 113 | remote_barrier_t global_barrier CONFIG_CACHE_LINE_ALIGNED; |
---|
[1] | 114 | |
---|
[14] | 115 | // This variable is used for local cores sychronisation in kernel_init() |
---|
| 116 | __attribute__((section(".kdata"))) |
---|
| 117 | barrier_t local_barrier CONFIG_CACHE_LINE_ALIGNED; |
---|
| 118 | |
---|
[50] | 119 | // This variable defines the array of supported File System contexts |
---|
| 120 | __attribute__((section(".kdata"))) |
---|
| 121 | vfs_ctx_t fs_context[FS_TYPES_NR] CONFIG_CACHE_LINE_ALIGNED; |
---|
| 122 | |
---|
| 123 | |
---|
[1] | 124 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[5] | 125 | // This function displays the ALMOS_MKH banner. |
---|
[1] | 126 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[5] | 127 | static void print_banner( uint32_t nclusters , uint32_t ncores ) |
---|
[1] | 128 | { |
---|
[5] | 129 | printk("\n" |
---|
| 130 | " _ __ __ _____ ______ __ __ _ __ _ _ \n" |
---|
| 131 | " /\\ | | | \\ / | / ___ \\ / _____| | \\ / | | | / / | | | | \n" |
---|
| 132 | " / \\ | | | \\/ | | / \\ | | / | \\/ | | |/ / | | | | \n" |
---|
| 133 | " / /\\ \\ | | | |\\ /| | | | | | | |_____ ___ | |\\ /| | | / | |___| | \n" |
---|
| 134 | " / /__\\ \\ | | | | \\/ | | | | | | \\_____ \\ |___| | | \\/ | | | \\ | ___ | \n" |
---|
| 135 | " / ______ \\ | | | | | | | | | | | | | | | | | |\\ \\ | | | | \n" |
---|
| 136 | " / / \\ \\ | |____ | | | | | \\___/ | _____/ | | | | | | | \\ \\ | | | | \n" |
---|
| 137 | " /_/ \\_\\ |______| |_| |_| \\_____/ |______/ |_| |_| |_| \\_\\ |_| |_| \n" |
---|
| 138 | "\n\n\t\t Advanced Locality Management Operating System / Multi Kernel Hybrid\n" |
---|
| 139 | "\n\n\t\t\t Version 0.0 : %d clusters / %d cores per cluster\n\n", nclusters , ncores ); |
---|
| 140 | } |
---|
[1] | 141 | |
---|
| 142 | |
---|
[5] | 143 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[14] | 144 | // This static function initializes the TXT0 chdev descriptor, associated to the "kernel |
---|
| 145 | // terminal", and shared by all kernel instances for debug messages. It also register it |
---|
| 146 | // in the chdev directory, containing extended pointers on all chdevs. |
---|
| 147 | // The global variable txt0_chdev is replicated in all clusters, but only the chdev |
---|
| 148 | // allocated in I/O cluster is used by ALMOS-MKH. |
---|
| 149 | // Therefore, this function must be called by a thread running in the I/O cluster. |
---|
| 150 | // As this TXT0 chdev supports only the TXT_SYNC_WRITE command, we don't create |
---|
| 151 | // a server thread, we don't allocate a WTI, and we don't initialize the waiting queue. |
---|
[5] | 152 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 153 | // @ info : pointer on the local boot-info structure. |
---|
| 154 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 155 | static void txt0_device_init( boot_info_t * info ) |
---|
| 156 | { |
---|
| 157 | boot_device_t * dev_tbl; // pointer on array of devices in boot_info |
---|
| 158 | uint32_t dev_nr; // actual number of devices in this cluster |
---|
| 159 | xptr_t base; // remote pointer on segment base |
---|
| 160 | uint32_t type; // peripheral type |
---|
| 161 | uint32_t func; // device functionnal index |
---|
| 162 | uint32_t impl; // device implementation index |
---|
| 163 | uint32_t i; // device index in dev_tbl |
---|
| 164 | uint32_t x; // X cluster coordinate |
---|
| 165 | uint32_t y; // Y cluster coordinate |
---|
[1] | 166 | |
---|
[5] | 167 | // get number of peripherals and base of devices array from boot_info |
---|
| 168 | dev_nr = info->ext_dev_nr; |
---|
| 169 | dev_tbl = info->ext_dev; |
---|
[1] | 170 | |
---|
[14] | 171 | // loop on external peripherals to find TXT device |
---|
[5] | 172 | for( i = 0 ; i < dev_nr ; i++ ) |
---|
| 173 | { |
---|
| 174 | base = dev_tbl[i].base; |
---|
| 175 | type = dev_tbl[i].type; |
---|
| 176 | func = FUNC_FROM_TYPE( type ); |
---|
| 177 | impl = IMPL_FROM_TYPE( type ); |
---|
| 178 | |
---|
| 179 | if (func == DEV_FUNC_TXT ) |
---|
| 180 | { |
---|
[14] | 181 | // initialize basic fields |
---|
| 182 | txt0_chdev.func = func; |
---|
| 183 | txt0_chdev.impl = impl; |
---|
| 184 | txt0_chdev.channel = 0; |
---|
| 185 | txt0_chdev.is_rx = 0; |
---|
| 186 | txt0_chdev.base = base; |
---|
[5] | 187 | |
---|
[14] | 188 | // initialize lock |
---|
| 189 | remote_spinlock_init( XPTR( local_cxy , &txt0_chdev.wait_lock ) ); |
---|
| 190 | |
---|
[5] | 191 | // Complete TXT specific initialisation |
---|
| 192 | if( impl == IMPL_TXT_TTY ) |
---|
| 193 | { |
---|
[14] | 194 | txt0_chdev.cmd = &soclib_tty_cmd; |
---|
| 195 | txt0_chdev.isr = &soclib_tty_isr; |
---|
| 196 | soclib_tty_init( &txt0_chdev ); |
---|
[5] | 197 | } |
---|
| 198 | |
---|
| 199 | // initialize the replicated chdev_dir[x][y] structures |
---|
| 200 | for( x = 0 ; x < info->x_size ; x++ ) |
---|
| 201 | { |
---|
| 202 | for( y = 0 ; y < info->y_size ; y++ ) |
---|
| 203 | { |
---|
| 204 | cxy_t cxy = (x<<info->y_width) + y; |
---|
[19] | 205 | hal_remote_swd( XPTR( cxy , &chdev_dir.txt[0] ) , |
---|
[14] | 206 | XPTR( local_cxy , &txt0_chdev ) ); |
---|
[5] | 207 | } |
---|
| 208 | } |
---|
| 209 | |
---|
[14] | 210 | kinit_dmsg("\n[INFO] %s : core[%x][0] created TXT0 chdev" |
---|
| 211 | " / paddr = %l at cycle %d\n", |
---|
[19] | 212 | __FUNCTION__ , local_cxy , chdev_func_str( func ), |
---|
[14] | 213 | XPTR(local_cxy , &txt0_chdev) , hal_time_stamp() ); |
---|
[5] | 214 | } |
---|
| 215 | |
---|
| 216 | } // end loop on devices |
---|
| 217 | |
---|
| 218 | } // end txt0_device_init() |
---|
| 219 | |
---|
[1] | 220 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[5] | 221 | // This static function allocates memory for the chdev (channel_device) descriptors |
---|
| 222 | // associated to the internal peripherals contained in the local cluster. These internal |
---|
| 223 | // devices (ICU, MMC, DMA) chdev descriptors are placed in the local cluster. |
---|
[1] | 224 | // It initialises these device descriptors as specified by the boot_info_t structure, |
---|
| 225 | // including the dynamic linking with the driver for the specified implementation. |
---|
| 226 | // Finally, all copies of the devices directory are initialised. |
---|
| 227 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 228 | // @ info : pointer on the local boot-info structure. |
---|
| 229 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[5] | 230 | static void internal_devices_init( boot_info_t * info ) |
---|
[1] | 231 | { |
---|
[14] | 232 | boot_device_t * dev; // pointer on boot_info device (ICU/MMC/DMA) |
---|
[1] | 233 | uint32_t x; // X cluster coordinate |
---|
| 234 | uint32_t y; // Y cluster coordinate |
---|
[14] | 235 | chdev_t * chdev_ptr; // local pointer on chdev descriptor |
---|
| 236 | xptr_t chdev_xp; // extended pointer on chdev descriptor |
---|
[1] | 237 | |
---|
[14] | 238 | /////////// ICU ////////// |
---|
[1] | 239 | |
---|
[14] | 240 | dev = &info->dev_icu; |
---|
[5] | 241 | |
---|
[14] | 242 | assert( ((info->cores_nr == 0) || (dev->channels != 0)) , __FUNCTION__ , |
---|
| 243 | "ICU device must exist in cluster containing cores" ); |
---|
| 244 | |
---|
| 245 | assert( (dev->channels == 1) , __FUNCTION__ , |
---|
| 246 | "channels number must be 1 for ICU device" ); |
---|
[1] | 247 | |
---|
[14] | 248 | assert( (FUNC_FROM_TYPE( dev->type ) == DEV_FUNC_ICU ) , __FUNCTION__ , |
---|
| 249 | " inconsistent ICU device type"); |
---|
[1] | 250 | |
---|
[14] | 251 | // create one chdev in local cluster |
---|
| 252 | chdev_ptr = chdev_create( FUNC_FROM_TYPE( dev->type ), |
---|
| 253 | IMPL_FROM_TYPE( dev->type ), |
---|
| 254 | 0, // channel |
---|
| 255 | false, // TX |
---|
| 256 | dev->base ); |
---|
[1] | 257 | |
---|
[14] | 258 | assert( (chdev_ptr != NULL) , __FUNCTION__ , "cannot allocate ICU chdev" ); |
---|
| 259 | |
---|
| 260 | // get extended pointer on chdev descriptor |
---|
| 261 | chdev_xp = XPTR( local_cxy , chdev_ptr ); |
---|
| 262 | |
---|
| 263 | // make ICU specific initialisation |
---|
| 264 | // TODO remove these three parameters |
---|
[19] | 265 | dev_icu_init( chdev_ptr , dev->param0 , dev->param1 , dev->param2 ); |
---|
[14] | 266 | |
---|
| 267 | // initialize the ICU field in the chdev_dir[x][y] structures |
---|
| 268 | // replicated in all clusters, and containing extended pointers |
---|
| 269 | // on all remotely accessible devices |
---|
| 270 | for( x = 0 ; x < info->x_size ; x++ ) |
---|
| 271 | { |
---|
| 272 | for( y = 0 ; y < info->y_size ; y++ ) |
---|
[5] | 273 | { |
---|
[14] | 274 | cxy_t cxy = (x<<info->y_width) + y; |
---|
| 275 | hal_remote_swd( XPTR( cxy , &chdev_dir.icu[local_cxy] ) , chdev_xp ); |
---|
[5] | 276 | } |
---|
[14] | 277 | } |
---|
[1] | 278 | |
---|
[14] | 279 | // initialize the entries of the local chdev_icu_input structure |
---|
| 280 | // defining how internal peripherals are connected to ICU |
---|
| 281 | uint32_t id; |
---|
| 282 | uint8_t valid; |
---|
| 283 | uint32_t src_type; |
---|
| 284 | uint8_t src_ch; |
---|
| 285 | uint32_t src_func; |
---|
| 286 | for( id = 0 ; id < CONFIG_MAX_HWIS_PER_ICU ; id++ ) |
---|
| 287 | { |
---|
| 288 | valid = dev->irq[id].valid; |
---|
| 289 | src_type = dev->irq[id].dev_type; |
---|
| 290 | src_ch = dev->irq[id].channel; |
---|
| 291 | src_func = FUNC_FROM_TYPE( src_type ); |
---|
| 292 | |
---|
| 293 | if( valid ) // only valid local IRQs are registered |
---|
[5] | 294 | { |
---|
[14] | 295 | if ( src_func == DEV_FUNC_MMC ) chdev_icu_input.mmc = id; |
---|
| 296 | else if( src_func == DEV_FUNC_DMA ) chdev_icu_input.dma[src_ch] = id; |
---|
| 297 | else assert( false , __FUNCTION__ , "illegal source device for ICU input" ); |
---|
| 298 | } |
---|
| 299 | } |
---|
[1] | 300 | |
---|
[50] | 301 | kinit_dmsg("\n[INFO] %s : core[%x][0] created ICU chdev at cycle %d\n", |
---|
[14] | 302 | __FUNCTION__ , local_cxy , hal_time_stamp() ); |
---|
[1] | 303 | |
---|
[14] | 304 | /////////// MMC internal chdev /////////// |
---|
[1] | 305 | |
---|
[14] | 306 | dev = &info->dev_mmc; |
---|
[1] | 307 | |
---|
[14] | 308 | if( dev->channels != 0 ) // MMC device is defined |
---|
| 309 | { |
---|
| 310 | assert( (dev->channels == 1) , __FUNCTION__ , |
---|
| 311 | "channels number must be 1 for MMC device" ); |
---|
[1] | 312 | |
---|
[14] | 313 | assert( (FUNC_FROM_TYPE( dev->type ) == DEV_FUNC_MMC ) , __FUNCTION__ , |
---|
| 314 | " inconsistent MMC device type"); |
---|
| 315 | |
---|
| 316 | // create one chdev in local cluster |
---|
| 317 | chdev_ptr = chdev_create( FUNC_FROM_TYPE( dev->type ), |
---|
| 318 | IMPL_FROM_TYPE( dev->type ), |
---|
| 319 | 0, // channel |
---|
| 320 | false, // TX |
---|
| 321 | dev->base ); |
---|
| 322 | |
---|
| 323 | assert( (chdev_ptr != NULL) , __FUNCTION__ , "cannot allocate MMC chdev" ); |
---|
| 324 | |
---|
| 325 | // get extended pointer on chdev descriptor |
---|
| 326 | chdev_xp = XPTR( local_cxy , chdev_ptr ); |
---|
| 327 | |
---|
| 328 | // make MMC specific initialisation |
---|
| 329 | dev_mmc_init( chdev_ptr ); |
---|
| 330 | |
---|
| 331 | // initialize the MMC field in the chdev_dir[x][y] structures |
---|
| 332 | // replicated in all clusters, and containing extended pointers |
---|
| 333 | // on all remotely accessible devices |
---|
| 334 | for( x = 0 ; x < info->x_size ; x++ ) |
---|
| 335 | { |
---|
| 336 | for( y = 0 ; y < info->y_size ; y++ ) |
---|
[1] | 337 | { |
---|
[14] | 338 | cxy_t cxy = (x<<info->y_width) + y; |
---|
| 339 | hal_remote_swd( XPTR( cxy , &chdev_dir.mmc[local_cxy] ) , chdev_xp ); |
---|
[1] | 340 | } |
---|
[14] | 341 | } |
---|
[1] | 342 | |
---|
[50] | 343 | kinit_dmsg("\n[INFO] %s : core[%x][0] created MMC chdev at cycle %d\n", |
---|
[14] | 344 | __FUNCTION__ , local_cxy , hal_time_stamp() ); |
---|
| 345 | } |
---|
[5] | 346 | |
---|
[14] | 347 | /////////// DMA internal chdevs ////////// |
---|
[1] | 348 | |
---|
[14] | 349 | dev = &info->dev_dma; |
---|
[1] | 350 | |
---|
[14] | 351 | if( dev->channels != 0 ) // DMA device is defined |
---|
| 352 | { |
---|
| 353 | assert( (FUNC_FROM_TYPE( dev->type ) == DEV_FUNC_DMA ) , __FUNCTION__ , |
---|
| 354 | " inconsistent DMA device type"); |
---|
[5] | 355 | |
---|
[14] | 356 | // create one chdev per channel in local cluster |
---|
| 357 | uint32_t channel; |
---|
| 358 | for( channel = 0 ; channel < dev->channels ; channel++ ) |
---|
| 359 | { |
---|
| 360 | chdev_ptr = chdev_create( FUNC_FROM_TYPE( dev->type ), |
---|
| 361 | IMPL_FROM_TYPE( dev->type ), |
---|
| 362 | channel, // channel |
---|
| 363 | false, // TX |
---|
| 364 | dev->base ); |
---|
[5] | 365 | |
---|
[14] | 366 | assert( (chdev_ptr != NULL) , __FUNCTION__ , "cannot allocate DMA chdev" ); |
---|
| 367 | |
---|
| 368 | // get extended pointer on channel descriptor |
---|
| 369 | chdev_xp = XPTR( local_cxy , chdev_ptr ); |
---|
[5] | 370 | |
---|
[14] | 371 | // make DMA specific initialisation |
---|
| 372 | dev_dma_init( chdev_ptr ); |
---|
| 373 | |
---|
| 374 | // initialize only the DMA[channel] field in the local chdev_dir[x][y] |
---|
| 375 | // structure because the DMA device is not remotely accessible. |
---|
| 376 | chdev_dir.dma[channel] = chdev_xp; |
---|
| 377 | |
---|
[50] | 378 | kinit_dmsg("\n[INFO] %s : core[%x][0] created DMA[%d] chdev at cycle %d\n", |
---|
[14] | 379 | __FUNCTION__ , local_cxy , channel , hal_time_stamp() ); |
---|
| 380 | } |
---|
| 381 | } |
---|
[5] | 382 | } // end internal_devices_init() |
---|
| 383 | |
---|
| 384 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 385 | // This static function allocates memory for the chdev descriptors associated |
---|
| 386 | // to the external (shared) peripherals contained in the local cluster. These external |
---|
| 387 | // devices (IOB, IOC, TXT, NIC, etc ) are distributed on all clusters. |
---|
| 388 | // It initialises these device descriptors as specified by the boot_info_t structure, |
---|
| 389 | // including the dynamic linking with the driver for the specified implementation. |
---|
| 390 | // Finally, all copies of the devices directory are initialised. |
---|
| 391 | // |
---|
| 392 | // The number of channel_devices depends on the device functionnal type. |
---|
[14] | 393 | // There is three nested loops to build the full set of external channel_devices: |
---|
[5] | 394 | // - loop on external devices. |
---|
| 395 | // - loop on channels for multi-channels devices. |
---|
| 396 | // - loop on directions (RX/TX) for NIC device. |
---|
| 397 | // The set of channel_devices is indexed by the chdev_gid global index, that is used |
---|
| 398 | // to select the cluster containing a given chdev[func,channel,direction]. |
---|
| 399 | // All clusters scan the full set of chdevs, but only the cluster matching |
---|
| 400 | // (chdev_gid % (x_size*y_size)) create the corresponding chdev. |
---|
| 401 | // |
---|
| 402 | // TODO check that cluster IO contains a PIC [AG] |
---|
[50] | 403 | // TODO make a default initialisation for the chdev_dir structure (XPTR_NULL ) [AG] |
---|
[5] | 404 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 405 | // @ info : pointer on the local boot-info structure. |
---|
| 406 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 407 | static void external_devices_init( boot_info_t * info ) |
---|
| 408 | { |
---|
| 409 | boot_device_t * dev_tbl; // pointer on array of devices in boot_info |
---|
| 410 | uint32_t dev_nr; // actual number of devices in this cluster |
---|
| 411 | xptr_t base; // remote pointer on segment base |
---|
| 412 | uint32_t type; // peripheral type |
---|
| 413 | uint32_t func; // device functionnal index |
---|
| 414 | uint32_t impl; // device implementation index |
---|
| 415 | uint32_t i; // device index in dev_tbl |
---|
| 416 | uint32_t x; // X cluster coordinate |
---|
| 417 | uint32_t y; // Y cluster coordinate |
---|
| 418 | uint32_t channels_nr; // number of channels |
---|
| 419 | uint32_t channel; // channel index |
---|
| 420 | uint32_t directions_nr; // number of directions |
---|
| 421 | uint32_t direction; // direction index |
---|
| 422 | uint32_t p0; // device parameter 0 |
---|
| 423 | uint32_t p1; // device parameter 1 |
---|
| 424 | uint32_t p2; // device parameter 2 |
---|
| 425 | uint32_t p3; // device parameter 3 |
---|
| 426 | uint32_t first_channel; // used in loop on channels |
---|
| 427 | |
---|
| 428 | chdev_t * chdev; // local pointer on one channel_device descriptor |
---|
| 429 | xptr_t chdev_xp; // extended pointer on channel_device descriptor |
---|
| 430 | uint32_t chdev_gid = 0; // global index of channel_device descriptor |
---|
| 431 | |
---|
| 432 | // get number of peripherals and base of devices array from boot_info |
---|
| 433 | dev_nr = info->ext_dev_nr; |
---|
| 434 | dev_tbl = info->ext_dev; |
---|
| 435 | |
---|
| 436 | // loop on external peripherals |
---|
| 437 | for( i = 0 ; i < dev_nr ; i++ ) |
---|
| 438 | { |
---|
| 439 | base = dev_tbl[i].base; |
---|
| 440 | type = dev_tbl[i].type; |
---|
| 441 | channels_nr = dev_tbl[i].channels; |
---|
| 442 | p0 = dev_tbl[i].param0; |
---|
| 443 | p1 = dev_tbl[i].param1; |
---|
| 444 | p2 = dev_tbl[i].param2; |
---|
| 445 | p3 = dev_tbl[i].param3; |
---|
| 446 | |
---|
| 447 | func = FUNC_FROM_TYPE( type ); |
---|
| 448 | impl = IMPL_FROM_TYPE( type ); |
---|
| 449 | |
---|
| 450 | // There is one chdev per direction for NIC |
---|
| 451 | if (func == DEV_FUNC_NIC) directions_nr = 2; |
---|
| 452 | else directions_nr = 1; |
---|
| 453 | |
---|
| 454 | // The TXT0 chdev has already been created |
---|
| 455 | if (func == DEV_FUNC_TXT) first_channel = 1; |
---|
| 456 | else first_channel = 0; |
---|
| 457 | |
---|
| 458 | // do nothing for ROM, that does not require a device descriptor. |
---|
| 459 | if( func == DEV_FUNC_ROM ) continue; |
---|
| 460 | |
---|
| 461 | // check external device functionnal type |
---|
| 462 | if( (func != DEV_FUNC_IOB) && |
---|
| 463 | (func != DEV_FUNC_PIC) && |
---|
| 464 | (func != DEV_FUNC_IOC) && |
---|
| 465 | (func != DEV_FUNC_TXT) && |
---|
| 466 | (func != DEV_FUNC_NIC) && |
---|
| 467 | (func != DEV_FUNC_FBF) ) |
---|
[1] | 468 | { |
---|
[5] | 469 | assert( false , __FUNCTION__ , "undefined external peripheral type" ); |
---|
| 470 | } |
---|
| 471 | |
---|
| 472 | // loops on channels |
---|
| 473 | for( channel = first_channel ; channel < channels_nr ; channel++ ) |
---|
| 474 | { |
---|
| 475 | // loop on directions |
---|
| 476 | for( direction = 0 ; direction < directions_nr ; direction++ ) |
---|
[1] | 477 | { |
---|
[5] | 478 | // get target cluster for chdev[func,channel,direction] |
---|
| 479 | uint32_t offset = chdev_gid % ( info->x_size * info->y_size ); |
---|
| 480 | uint32_t cx = offset / info->y_size; |
---|
| 481 | uint32_t cy = offset % info->y_size; |
---|
| 482 | uint32_t target_cxy = (cx<<info->y_width) + cy; |
---|
[1] | 483 | |
---|
[5] | 484 | // allocate and initialize a local chdev |
---|
| 485 | // if local cluster matches target cluster |
---|
| 486 | if( target_cxy == local_cxy ) |
---|
[1] | 487 | { |
---|
[5] | 488 | chdev = chdev_create( func, |
---|
| 489 | impl, |
---|
| 490 | channel, |
---|
| 491 | direction, |
---|
| 492 | base ); |
---|
| 493 | |
---|
| 494 | assert( (chdev != NULL), __FUNCTION__ , |
---|
| 495 | "cannot allocate external device" ); |
---|
| 496 | |
---|
| 497 | // get extended pointer on chdev |
---|
| 498 | chdev_xp = XPTR( local_cxy , chdev ); |
---|
| 499 | |
---|
| 500 | // make device type specific initialisation |
---|
| 501 | // the number of parameters depends on the device type |
---|
| 502 | // TODO : remove the parameters that must be provided by the drivers |
---|
| 503 | if ( func == DEV_FUNC_IOB ) dev_iob_init( chdev ); |
---|
| 504 | else if( func == DEV_FUNC_IOC ) dev_ioc_init( chdev ); |
---|
| 505 | else if( func == DEV_FUNC_TXT ) dev_txt_init( chdev ); |
---|
| 506 | else if( func == DEV_FUNC_NIC ) dev_nic_init( chdev ); |
---|
| 507 | else if( func == DEV_FUNC_PIC ) dev_pic_init( chdev , p0 ); |
---|
| 508 | else if( func == DEV_FUNC_FBF ) dev_fbf_init( chdev , p0 , p1 ); |
---|
| 509 | else |
---|
| 510 | { |
---|
| 511 | assert( false , __FUNCTION__ , "undefined device type" ); |
---|
| 512 | } |
---|
| 513 | |
---|
| 514 | // all external (shared) devices are remotely accessible |
---|
| 515 | // initialize the replicated chdev_dir[x][y] structures |
---|
| 516 | // defining the extended pointers on chdev descriptors |
---|
| 517 | xptr_t * entry; |
---|
| 518 | |
---|
| 519 | if( func == DEV_FUNC_IOB ) entry = &chdev_dir.iob; |
---|
| 520 | if( func == DEV_FUNC_PIC ) entry = &chdev_dir.pic; |
---|
| 521 | if( func == DEV_FUNC_TXT ) entry = &chdev_dir.txt[channel]; |
---|
| 522 | if( func == DEV_FUNC_IOC ) entry = &chdev_dir.ioc[channel]; |
---|
| 523 | if( func == DEV_FUNC_FBF ) entry = &chdev_dir.fbf[channel]; |
---|
| 524 | if( func == DEV_FUNC_NIC ) entry = &chdev_dir.nic_tx[channel]; |
---|
| 525 | |
---|
[1] | 526 | for( x = 0 ; x < info->x_size ; x++ ) |
---|
| 527 | { |
---|
| 528 | for( y = 0 ; y < info->y_size ; y++ ) |
---|
| 529 | { |
---|
| 530 | cxy_t cxy = (x<<info->y_width) + y; |
---|
[5] | 531 | hal_remote_swd( XPTR( cxy , entry ) , chdev_xp ); |
---|
| 532 | } |
---|
[1] | 533 | } |
---|
| 534 | |
---|
[14] | 535 | kinit_dmsg("\n[INFO] %s : core[%x][0] create chdev %s[%d] at cycle %d\n", |
---|
[5] | 536 | __FUNCTION__ , local_cxy , chdev_func_str( func ), |
---|
[14] | 537 | channel , hal_time_stamp() ); |
---|
[5] | 538 | |
---|
| 539 | } // end if match |
---|
| 540 | |
---|
[19] | 541 | // increment chdev global index (matching or not) |
---|
[5] | 542 | chdev_gid++; |
---|
| 543 | |
---|
| 544 | } // end loop on directions |
---|
| 545 | |
---|
| 546 | } // end loop on channels |
---|
| 547 | |
---|
| 548 | // initialize the entries of the local chdev_pic_input structure |
---|
| 549 | // defining how external peripherals are connected to PIC |
---|
| 550 | if( func == DEV_FUNC_PIC ) |
---|
[1] | 551 | { |
---|
[5] | 552 | uint32_t id; |
---|
| 553 | uint8_t valid; |
---|
| 554 | uint32_t dev_type; |
---|
| 555 | uint8_t channel; |
---|
| 556 | uint8_t is_rx; |
---|
| 557 | |
---|
| 558 | // loop on PIC inputs |
---|
| 559 | for( id = 0 ; id < CONFIG_MAX_IRQS_PER_PIC ; id++ ) |
---|
[1] | 560 | { |
---|
[5] | 561 | valid = dev_tbl[i].irq[id].valid; |
---|
| 562 | dev_type = dev_tbl[i].irq[id].dev_type; |
---|
| 563 | channel = dev_tbl[i].irq[id].channel; |
---|
| 564 | is_rx = dev_tbl[i].irq[id].is_rx; |
---|
[1] | 565 | |
---|
[5] | 566 | if( valid ) // only valid inputs are registered |
---|
[1] | 567 | { |
---|
[5] | 568 | uint32_t * index; // local pointer on one entry |
---|
[1] | 569 | uint16_t dev_func = FUNC_FROM_TYPE( dev_type ); |
---|
[5] | 570 | |
---|
| 571 | if( dev_func == DEV_FUNC_TXT ) |
---|
[1] | 572 | { |
---|
[5] | 573 | index = &chdev_pic_input.txt[channel]; |
---|
[1] | 574 | } |
---|
[5] | 575 | else if( dev_func == DEV_FUNC_IOC ) |
---|
| 576 | { |
---|
| 577 | index = &chdev_pic_input.ioc[channel]; |
---|
| 578 | } |
---|
| 579 | else if( (dev_func == DEV_FUNC_NIC) && (is_rx == 0) ) |
---|
| 580 | { |
---|
| 581 | index = &chdev_pic_input.nic_tx[channel]; |
---|
| 582 | } |
---|
| 583 | else if( (dev_func == DEV_FUNC_NIC) && (is_rx != 0) ) |
---|
| 584 | { |
---|
| 585 | index = &chdev_pic_input.nic_rx[channel]; |
---|
| 586 | } |
---|
| 587 | else |
---|
| 588 | { |
---|
| 589 | assert( false , __FUNCTION__ , "illegal source device for PIC input" ); |
---|
| 590 | } |
---|
| 591 | |
---|
| 592 | // set entry in local structure |
---|
| 593 | *index = id; |
---|
[1] | 594 | } |
---|
[5] | 595 | } // end loop on PIC inputs |
---|
| 596 | } // end PIC |
---|
| 597 | } // end loop on devices |
---|
| 598 | } // end external_devices_init() |
---|
[1] | 599 | |
---|
| 600 | |
---|
| 601 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[14] | 602 | // This static function returns the identifiers of the calling core. |
---|
| 603 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 604 | // @ info : pointer on boot_info structure. |
---|
| 605 | // @ lid : [out] core local index in cluster. |
---|
| 606 | // @ cxy : [out] cluster identifier. |
---|
| 607 | // @ lid : [out] core global identifier (hardware). |
---|
| 608 | // @ return 0 if success / return EINVAL if not found. |
---|
| 609 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[23] | 610 | static error_t get_core_identifiers( boot_info_t * info, |
---|
| 611 | lid_t * lid, |
---|
[14] | 612 | cxy_t * cxy, |
---|
| 613 | gid_t * gid ) |
---|
| 614 | { |
---|
| 615 | uint32_t i; |
---|
| 616 | gid_t global_id; |
---|
[19] | 617 | |
---|
[14] | 618 | // get global identifier from hardware register |
---|
| 619 | global_id = hal_get_gid(); |
---|
| 620 | |
---|
| 621 | // makes an associative search in boot_info to get (cxy,lid) from global_id |
---|
| 622 | for( i = 0 ; i < info->cores_nr ; i++ ) |
---|
| 623 | { |
---|
| 624 | if( global_id == info->core[i].gid ) |
---|
| 625 | { |
---|
| 626 | *lid = info->core[i].lid; |
---|
| 627 | *cxy = info->core[i].cxy; |
---|
| 628 | *gid = global_id; |
---|
| 629 | return 0; |
---|
| 630 | } |
---|
| 631 | } |
---|
| 632 | return EINVAL; |
---|
[19] | 633 | } |
---|
[14] | 634 | |
---|
| 635 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[1] | 636 | // This function is the entry point for the kernel initialisation. |
---|
[19] | 637 | // It is executed by all cores in all clusters, but only core[0], called CP0, |
---|
[14] | 638 | // initializes the shared resources such as the cluster manager, or the local peripherals. |
---|
[19] | 639 | // To comply with the multi-kernels paradigm, it accesses only local cluster memory, using |
---|
| 640 | // only information contained in the local boot_info_t structure, set by the bootloader. |
---|
[1] | 641 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 642 | // @ info : pointer on the local boot-info structure. |
---|
| 643 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 644 | void kernel_init( boot_info_t * info ) |
---|
| 645 | { |
---|
[23] | 646 | lid_t core_lid = -1; // running core local index |
---|
[14] | 647 | cxy_t core_cxy = -1; // running core cluster identifier |
---|
| 648 | gid_t core_gid; // running core hardware identifier |
---|
| 649 | cluster_t * cluster; // pointer on local cluster manager |
---|
| 650 | core_t * core; // pointer on running core descriptor |
---|
| 651 | thread_t * thread; // pointer on idle thread descriptor |
---|
[1] | 652 | error_t error; |
---|
| 653 | |
---|
[14] | 654 | // all cores get core identifiers |
---|
[23] | 655 | error = get_core_identifiers( info, |
---|
[14] | 656 | &core_lid, |
---|
| 657 | &core_cxy, |
---|
| 658 | &core_gid ); |
---|
[1] | 659 | |
---|
[14] | 660 | // CP0 initialise cluster identifier |
---|
| 661 | if( core_lid == 0 ) local_cxy = info->cxy; |
---|
[1] | 662 | |
---|
[68] | 663 | // each core get pointer on its private idle thread descriptor |
---|
| 664 | thread = (thread_t *)( idle_threads + (core_lid * CONFIG_THREAD_DESC_SIZE) ); |
---|
| 665 | |
---|
[71] | 666 | // each core registers this thread pointer in hardware register |
---|
[68] | 667 | hal_set_current_thread( thread ); |
---|
[71] | 668 | |
---|
| 669 | #ifdef __HAL_x86_64__ |
---|
| 670 | return; |
---|
| 671 | #endif |
---|
| 672 | |
---|
[14] | 673 | // CP0 in I/O cluster initialises TXT0 chdev descriptor |
---|
| 674 | if( (core_lid == 0) && (core_cxy == info->io_cxy) ) txt0_device_init( info ); |
---|
| 675 | |
---|
| 676 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 677 | // global & local synchro to protect access to TXT0 terminal |
---|
| 678 | if( core_lid == 0 ) remote_barrier( XPTR( info->io_cxy , &global_barrier ), |
---|
| 679 | (info->x_size * info->y_size) ); |
---|
| 680 | barrier_wait( &local_barrier , info->cores_nr ); |
---|
| 681 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 682 | |
---|
[23] | 683 | kinit_dmsg("\n[INFO] %s : core[%x][%d] exit barrier 0 at cycle %d\n", |
---|
| 684 | __FUNCTION__ , core_cxy , core_lid , hal_time_stamp() ); |
---|
[14] | 685 | |
---|
| 686 | // all cores check core identifiers |
---|
| 687 | if( error ) |
---|
[1] | 688 | { |
---|
[14] | 689 | printk("\n[PANIC] in %s : illegal core identifiers" |
---|
| 690 | " gid = %x / cxy = %x / lid = %d\n", |
---|
| 691 | __FUNCTION__ , core_lid , core_cxy , core_lid ); |
---|
| 692 | hal_core_sleep(); |
---|
[1] | 693 | } |
---|
| 694 | |
---|
[19] | 695 | // CP0 initializes the local cluster manager (cores and memory allocators) |
---|
[14] | 696 | if( core_lid == 0 ) |
---|
[1] | 697 | { |
---|
| 698 | error = cluster_init( info ); |
---|
| 699 | |
---|
[14] | 700 | if( error ) |
---|
| 701 | { |
---|
| 702 | printk("\n[PANIC] in %s : cannot initialise cluster manager in cluster %x", |
---|
| 703 | __FUNCTION__ , local_cxy ); |
---|
| 704 | hal_core_sleep(); |
---|
| 705 | } |
---|
| 706 | } |
---|
[5] | 707 | |
---|
[14] | 708 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 709 | // global & local synchro, to protect access to cluster manager |
---|
| 710 | if( core_lid == 0 ) remote_barrier( XPTR( info->io_cxy , &global_barrier ), |
---|
| 711 | (info->x_size * info->y_size) ); |
---|
| 712 | barrier_wait( &local_barrier , info->cores_nr ); |
---|
| 713 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[1] | 714 | |
---|
[23] | 715 | kinit_dmsg("\n[INFO] %s : core[%x][%d] exit barrier 1 at cycle %d\n", |
---|
| 716 | __FUNCTION__ , core_cxy , core_lid , hal_time_stamp() ); |
---|
[1] | 717 | |
---|
[14] | 718 | // all cores get pointer on local cluster manager and on core descriptor |
---|
| 719 | cluster = &cluster_manager; |
---|
| 720 | core = &cluster->core_tbl[core_lid]; |
---|
[1] | 721 | |
---|
[19] | 722 | // CP0 initializes the process_zero descriptor |
---|
[14] | 723 | if( core_lid == 0 ) process_zero_init( info ); |
---|
[5] | 724 | |
---|
[19] | 725 | // CP0 allocates and initialises the internal peripheral chdev descriptors. |
---|
[14] | 726 | // Each CP0[cxy] scan the set of its internal (private) peripherals, |
---|
| 727 | // and allocate memory for the corresponding chdev descriptors. |
---|
| 728 | if( core_lid == 0 ) internal_devices_init( info ); |
---|
[5] | 729 | |
---|
[14] | 730 | // CP0 allocates one WTI mailbbox per core for Inter Processor Interrupt |
---|
| 731 | // this must be done after ICU chdev initialisation, by CP0 only, and before |
---|
[50] | 732 | // external devices initialisation to enforce the rule : |
---|
| 733 | // "The WTI index for the IPI routed to core[lid] is lid" |
---|
[14] | 734 | if( core_lid == 0 ) |
---|
[1] | 735 | { |
---|
[14] | 736 | uint32_t wti_id; |
---|
| 737 | uint32_t lid; |
---|
| 738 | for( lid = 0 ; lid < LOCAL_CLUSTER->cores_nr ; lid++ ) |
---|
[1] | 739 | { |
---|
[14] | 740 | wti_id = dev_icu_wti_alloc(); |
---|
[1] | 741 | |
---|
[14] | 742 | if( wti_id != lid ) |
---|
| 743 | { |
---|
| 744 | printk("\n[PANIC] in %s : WTI index for IPI = %d / core_lid = %d", |
---|
| 745 | __FUNCTION__ , wti_id , lid ); |
---|
| 746 | hal_core_sleep(); |
---|
| 747 | } |
---|
[5] | 748 | |
---|
[14] | 749 | dev_icu_enable_irq( lid , WTI_TYPE , wti_id , NULL ); |
---|
| 750 | } |
---|
[1] | 751 | } |
---|
| 752 | |
---|
[50] | 753 | // All CP0s contribute to initialise external peripheral chdev descriptors. |
---|
[14] | 754 | // Each CP0[cxy] scan the set of external (shared) peripherals (but the TXT0), |
---|
| 755 | // and allocates memory for the chdev descriptors that must be placed |
---|
| 756 | // on the (cxy) cluster according to the global index value. |
---|
| 757 | if( core_lid == 0 ) external_devices_init( info ); |
---|
[1] | 758 | |
---|
[14] | 759 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 760 | // global &local synchro to protect access to peripherals |
---|
| 761 | if( core_lid == 0 ) remote_barrier( XPTR( info->io_cxy , &global_barrier ), |
---|
| 762 | (info->x_size * info->y_size) ); |
---|
| 763 | barrier_wait( &local_barrier , info->cores_nr ); |
---|
| 764 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[5] | 765 | |
---|
[23] | 766 | kinit_dmsg("\n[INFO] %s : core[%x][%d] exit barrier 2 at cycle %d\n", |
---|
| 767 | __FUNCTION__ , core_cxy , core_lid , hal_time_stamp() ); |
---|
[1] | 768 | |
---|
| 769 | |
---|
[14] | 770 | error = thread_kernel_init( thread, |
---|
| 771 | THREAD_IDLE, |
---|
| 772 | &thread_idle_func, |
---|
| 773 | NULL, |
---|
| 774 | core_lid ); |
---|
| 775 | if( error ) |
---|
[1] | 776 | { |
---|
[14] | 777 | printk("\n[PANIC] in %s : core[%x][%d] cannot initialize idle thread\n", |
---|
| 778 | __FUNCTION__ , local_cxy , core_lid ); |
---|
| 779 | hal_core_sleep(); |
---|
[1] | 780 | } |
---|
[14] | 781 | else |
---|
| 782 | { |
---|
| 783 | // register idle thread in scheduler |
---|
| 784 | core->scheduler.idle = thread; |
---|
[1] | 785 | |
---|
[14] | 786 | // activate the idle thread |
---|
| 787 | thread_unblock( XPTR( local_cxy , thread ) , THREAD_BLOCKED_GLOBAL ); |
---|
[1] | 788 | |
---|
[14] | 789 | kinit_dmsg("\n[INFO] %s : core[%x][%d] created idle thread %x at cycle %d\n", |
---|
| 790 | __FUNCTION__ , core_cxy , core_lid , thread , hal_time_stamp()); |
---|
| 791 | } |
---|
| 792 | |
---|
[23] | 793 | // CP0 in all clusters initializes cooperatively VFS and DEVFS |
---|
| 794 | if( (core_lid == 0) ) |
---|
[14] | 795 | { |
---|
[23] | 796 | xptr_t root_inode_xp; |
---|
| 797 | |
---|
[50] | 798 | // initialize root File System (must be FATFS in this implementation) |
---|
[23] | 799 | if( CONFIG_VFS_ROOT_IS_FATFS ) |
---|
| 800 | { |
---|
| 801 | root_inode_xp = fatfs_init(); |
---|
| 802 | } |
---|
| 803 | else |
---|
| 804 | { |
---|
| 805 | printk("\n[PANIC] in %s : root FS must be FATFS\n", __FUNCTION__ ); |
---|
| 806 | hal_core_sleep(); |
---|
| 807 | } |
---|
| 808 | |
---|
| 809 | if( root_inode_xp == XPTR_NULL ) |
---|
| 810 | { |
---|
| 811 | printk("\n[PANIC] in %s : core[%x][%d] cannot initialize file system\n", |
---|
| 812 | __FUNCTION__ , local_cxy , core_lid ); |
---|
| 813 | hal_core_sleep(); |
---|
| 814 | } |
---|
| 815 | |
---|
| 816 | // mount the DEVFS File system |
---|
| 817 | devfs_mount( root_inode_xp , "dev" ); |
---|
[14] | 818 | } |
---|
| 819 | |
---|
| 820 | // CP0 in I/O cluster print banner |
---|
[5] | 821 | if( (core_lid == 0) && (local_cxy == info->io_cxy) ) |
---|
[1] | 822 | { |
---|
[5] | 823 | print_banner( (info->x_size * info->y_size) , info->cores_nr ); |
---|
[68] | 824 | |
---|
| 825 | kinit_dmsg("\n\n*** memory fooprint of main kernet objects ***\n" |
---|
| 826 | " - thread descriptor : %d bytes\n" |
---|
| 827 | " - process descriptor : %d bytes\n" |
---|
| 828 | " - cluster manager : %d bytes\n" |
---|
| 829 | " - chdev descriptor : %d bytes\n" |
---|
| 830 | " - core descriptor : %d bytes\n" |
---|
| 831 | " - scheduler : %d bytes\n" |
---|
| 832 | " - rpc fifo : %d bytes\n" |
---|
| 833 | " - page descriptor : %d bytes\n" |
---|
| 834 | " - mapper root : %d bytes\n" |
---|
| 835 | " - ppm manager : %d bytes\n" |
---|
| 836 | " - kcm manager : %d bytes\n" |
---|
| 837 | " - khm manager : %d bytes\n" |
---|
| 838 | " - vmm manager : %d bytes\n" |
---|
| 839 | " - gpt root : %d bytes\n" |
---|
| 840 | " - list item : %d bytes\n" |
---|
| 841 | " - xlist item : %d bytes\n" |
---|
| 842 | " - spinlock : %d bytes\n" |
---|
| 843 | " - remote spinlock : %d bytes\n" |
---|
| 844 | " - rwlock : %d bytes\n" |
---|
| 845 | " - remote rwlock : %d bytes\n", |
---|
| 846 | sizeof( thread_t ), |
---|
| 847 | sizeof( process_t ), |
---|
| 848 | sizeof( cluster_t ), |
---|
| 849 | sizeof( chdev_t ), |
---|
| 850 | sizeof( core_t ), |
---|
| 851 | sizeof( scheduler_t ), |
---|
| 852 | sizeof( rpc_fifo_t ), |
---|
| 853 | sizeof( page_t ), |
---|
| 854 | sizeof( mapper_t ), |
---|
| 855 | sizeof( ppm_t ), |
---|
| 856 | sizeof( kcm_t ), |
---|
| 857 | sizeof( khm_t ), |
---|
| 858 | sizeof( vmm_t ), |
---|
| 859 | sizeof( gpt_t ), |
---|
| 860 | sizeof( list_entry_t ), |
---|
| 861 | sizeof( xlist_entry_t ), |
---|
| 862 | sizeof( spinlock_t ), |
---|
| 863 | sizeof( remote_spinlock_t ), |
---|
| 864 | sizeof( rwlock_t ), |
---|
| 865 | sizeof( remote_rwlock_t )); |
---|
[1] | 866 | } |
---|
| 867 | |
---|
[14] | 868 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 869 | // global syncho to protect access to File System |
---|
| 870 | if( core_lid == 0 ) remote_barrier( XPTR( info->io_cxy , &global_barrier ), |
---|
| 871 | (info->x_size * info->y_size) ); |
---|
| 872 | barrier_wait( &local_barrier , info->cores_nr ); |
---|
| 873 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[1] | 874 | |
---|
[23] | 875 | kinit_dmsg("\n[INFO] %s : core[%x][%d] exit barrier 3 at cycle %d\n", |
---|
| 876 | __FUNCTION__ , core_cxy , core_lid , hal_time_stamp() ); |
---|
[14] | 877 | |
---|
| 878 | // each core activates its private PTI IRQ |
---|
| 879 | dev_icu_set_period( core_lid , CONFIG_SCHED_TICK_PERIOD ); |
---|
| 880 | dev_icu_enable_irq( core_lid , PTI_TYPE , core_lid , NULL ); |
---|
| 881 | |
---|
| 882 | // each core get its private IRQ masks values and |
---|
| 883 | uint32_t hwi_mask; |
---|
| 884 | uint32_t wti_mask; |
---|
| 885 | uint32_t pti_mask; |
---|
| 886 | dev_icu_get_masks( core_lid , &hwi_mask , &wti_mask , &pti_mask ); |
---|
| 887 | |
---|
| 888 | thread_dmsg("\n[INFO] %s : core[%x][%d] activates scheduler at cycle %d\n" |
---|
| 889 | " hwi_mask = %x / wti_mask = %x / pti_mask = %x\n", |
---|
| 890 | __FUNCTION__ , local_cxy , core_lid , hal_time_stamp() , |
---|
| 891 | hwi_mask , wti_mask , pti_mask ); |
---|
| 892 | |
---|
| 893 | // each core jump to idle thread |
---|
[50] | 894 | thread_idle_func(); |
---|
[14] | 895 | |
---|
[1] | 896 | } // end kernel_init() |
---|
| 897 | |
---|