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