[1] | 1 | /* |
---|
| 2 | * kernel_init.c - kernel parallel initialization |
---|
[127] | 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> |
---|
[279] | 30 | #include <hal_irqmask.h> |
---|
[296] | 31 | #include <hal_ppm.h> |
---|
[14] | 32 | #include <barrier.h> |
---|
[1] | 33 | #include <remote_barrier.h> |
---|
[407] | 34 | #include <remote_fifo.h> |
---|
[1] | 35 | #include <core.h> |
---|
| 36 | #include <list.h> |
---|
[68] | 37 | #include <xlist.h> |
---|
[204] | 38 | #include <xhtab.h> |
---|
[1] | 39 | #include <thread.h> |
---|
| 40 | #include <scheduler.h> |
---|
| 41 | #include <kmem.h> |
---|
| 42 | #include <cluster.h> |
---|
| 43 | #include <string.h> |
---|
| 44 | #include <memcpy.h> |
---|
| 45 | #include <ppm.h> |
---|
| 46 | #include <page.h> |
---|
[5] | 47 | #include <chdev.h> |
---|
[1] | 48 | #include <boot_info.h> |
---|
| 49 | #include <dqdt.h> |
---|
| 50 | #include <dev_mmc.h> |
---|
[5] | 51 | #include <dev_dma.h> |
---|
| 52 | #include <dev_iob.h> |
---|
[1] | 53 | #include <dev_ioc.h> |
---|
[5] | 54 | #include <dev_txt.h> |
---|
[1] | 55 | #include <dev_pic.h> |
---|
| 56 | #include <printk.h> |
---|
| 57 | #include <vfs.h> |
---|
[23] | 58 | #include <devfs.h> |
---|
[68] | 59 | #include <mapper.h> |
---|
[1] | 60 | |
---|
[5] | 61 | #define KERNEL_INIT_SYNCHRO 0xA5A5B5B5 |
---|
[1] | 62 | |
---|
| 63 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[279] | 64 | // All the following global variables are replicated in all clusters. |
---|
[1] | 65 | // They are initialised by the kernel_init() function. |
---|
[14] | 66 | // |
---|
[127] | 67 | // WARNING : The section names have been defined to control the base addresses of the |
---|
[14] | 68 | // boot_info structure and the idle thread descriptors, through the kernel.ld script: |
---|
[127] | 69 | // - the boot_info structure is built by the bootloader, and used by kernel_init. |
---|
| 70 | // it must be the first object in the kdata segment. |
---|
[14] | 71 | // - the array of idle threads descriptors must be placed on the first page boundary after |
---|
| 72 | // the boot_info structure in the kdata segment. |
---|
[1] | 73 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 74 | |
---|
[5] | 75 | // This variable defines the local boot_info structure |
---|
| 76 | __attribute__((section(".kinfo"))) |
---|
[14] | 77 | boot_info_t boot_info; |
---|
[5] | 78 | |
---|
[14] | 79 | // This variable defines the "idle" threads descriptors array |
---|
| 80 | __attribute__((section(".kidle"))) |
---|
[381] | 81 | char idle_threads[CONFIG_THREAD_DESC_SIZE * |
---|
[14] | 82 | CONFIG_MAX_LOCAL_CORES] CONFIG_PPM_PAGE_ALIGNED; |
---|
| 83 | |
---|
[127] | 84 | // This variable defines the local cluster manager |
---|
[5] | 85 | __attribute__((section(".kdata"))) |
---|
[19] | 86 | cluster_t cluster_manager CONFIG_CACHE_LINE_ALIGNED; |
---|
[1] | 87 | |
---|
[407] | 88 | // This variable defines the TXT0 kernel terminal (TX only) |
---|
[188] | 89 | __attribute__((section(".kdata"))) |
---|
| 90 | chdev_t txt0_chdev CONFIG_CACHE_LINE_ALIGNED; |
---|
| 91 | |
---|
[14] | 92 | // This variables define the kernel process0 descriptor |
---|
[5] | 93 | __attribute__((section(".kdata"))) |
---|
[19] | 94 | process_t process_zero CONFIG_CACHE_LINE_ALIGNED; |
---|
[1] | 95 | |
---|
[14] | 96 | // This variable defines extended pointers on the distributed chdevs |
---|
[5] | 97 | __attribute__((section(".kdata"))) |
---|
[14] | 98 | chdev_directory_t chdev_dir CONFIG_CACHE_LINE_ALIGNED; |
---|
[1] | 99 | |
---|
[188] | 100 | // This variable contains the input IRQ indexes for the IOPIC controller |
---|
[5] | 101 | __attribute__((section(".kdata"))) |
---|
[246] | 102 | iopic_input_t iopic_input CONFIG_CACHE_LINE_ALIGNED; |
---|
[1] | 103 | |
---|
[188] | 104 | // This variable contains the input IRQ indexes for the LAPIC controller |
---|
[5] | 105 | __attribute__((section(".kdata"))) |
---|
[188] | 106 | lapic_input_t lapic_input CONFIG_CACHE_LINE_ALIGNED; |
---|
[1] | 107 | |
---|
[14] | 108 | // This variable defines the local cluster identifier |
---|
[5] | 109 | __attribute__((section(".kdata"))) |
---|
[14] | 110 | cxy_t local_cxy CONFIG_CACHE_LINE_ALIGNED; |
---|
[5] | 111 | |
---|
[127] | 112 | // This variable is used for CP0 cores synchronisation in kernel_init() |
---|
[5] | 113 | __attribute__((section(".kdata"))) |
---|
[14] | 114 | remote_barrier_t global_barrier CONFIG_CACHE_LINE_ALIGNED; |
---|
[1] | 115 | |
---|
[127] | 116 | // This variable is used for local cores synchronisation in kernel_init() |
---|
[14] | 117 | __attribute__((section(".kdata"))) |
---|
| 118 | barrier_t local_barrier CONFIG_CACHE_LINE_ALIGNED; |
---|
| 119 | |
---|
[127] | 120 | // This variable defines the array of supported File System contexts |
---|
[50] | 121 | __attribute__((section(".kdata"))) |
---|
| 122 | vfs_ctx_t fs_context[FS_TYPES_NR] CONFIG_CACHE_LINE_ALIGNED; |
---|
| 123 | |
---|
| 124 | |
---|
[435] | 125 | // these debug variables are used to analyse the sys_read() syscall timing |
---|
[408] | 126 | |
---|
[438] | 127 | #if DEBUG_SYS_READ |
---|
[407] | 128 | uint32_t enter_sys_read; |
---|
| 129 | uint32_t exit_sys_read; |
---|
| 130 | |
---|
[435] | 131 | uint32_t enter_devfs_read; |
---|
| 132 | uint32_t exit_devfs_read; |
---|
[407] | 133 | |
---|
| 134 | uint32_t enter_txt_read; |
---|
| 135 | uint32_t exit_txt_read; |
---|
| 136 | |
---|
[435] | 137 | uint32_t enter_chdev_cmd_read; |
---|
| 138 | uint32_t exit_chdev_cmd_read; |
---|
[407] | 139 | |
---|
[435] | 140 | uint32_t enter_chdev_server_read; |
---|
| 141 | uint32_t exit_chdev_server_read; |
---|
[407] | 142 | |
---|
[435] | 143 | uint32_t enter_tty_cmd_read; |
---|
| 144 | uint32_t exit_tty_cmd_read; |
---|
[407] | 145 | |
---|
[435] | 146 | uint32_t enter_tty_isr_read; |
---|
| 147 | uint32_t exit_tty_isr_read; |
---|
[407] | 148 | #endif |
---|
| 149 | |
---|
[435] | 150 | // these debug variables are used to analyse the sys_write() syscall timing |
---|
| 151 | |
---|
[438] | 152 | #if DEBUG_SYS_WRITE |
---|
[435] | 153 | uint32_t enter_sys_write; |
---|
| 154 | uint32_t exit_sys_write; |
---|
| 155 | |
---|
| 156 | uint32_t enter_devfs_write; |
---|
| 157 | uint32_t exit_devfs_write; |
---|
| 158 | |
---|
| 159 | uint32_t enter_txt_write; |
---|
| 160 | uint32_t exit_txt_write; |
---|
| 161 | |
---|
| 162 | uint32_t enter_chdev_cmd_write; |
---|
| 163 | uint32_t exit_chdev_cmd_write; |
---|
| 164 | |
---|
| 165 | uint32_t enter_chdev_server_write; |
---|
| 166 | uint32_t exit_chdev_server_write; |
---|
| 167 | |
---|
| 168 | uint32_t enter_tty_cmd_write; |
---|
| 169 | uint32_t exit_tty_cmd_write; |
---|
| 170 | |
---|
| 171 | uint32_t enter_tty_isr_write; |
---|
| 172 | uint32_t exit_tty_isr_write; |
---|
| 173 | #endif |
---|
| 174 | |
---|
[1] | 175 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[5] | 176 | // This function displays the ALMOS_MKH banner. |
---|
[1] | 177 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[5] | 178 | static void print_banner( uint32_t nclusters , uint32_t ncores ) |
---|
[127] | 179 | { |
---|
[5] | 180 | printk("\n" |
---|
| 181 | " _ __ __ _____ ______ __ __ _ __ _ _ \n" |
---|
| 182 | " /\\ | | | \\ / | / ___ \\ / _____| | \\ / | | | / / | | | | \n" |
---|
| 183 | " / \\ | | | \\/ | | / \\ | | / | \\/ | | |/ / | | | | \n" |
---|
| 184 | " / /\\ \\ | | | |\\ /| | | | | | | |_____ ___ | |\\ /| | | / | |___| | \n" |
---|
| 185 | " / /__\\ \\ | | | | \\/ | | | | | | \\_____ \\ |___| | | \\/ | | | \\ | ___ | \n" |
---|
| 186 | " / ______ \\ | | | | | | | | | | | | | | | | | |\\ \\ | | | | \n" |
---|
| 187 | " / / \\ \\ | |____ | | | | | \\___/ | _____/ | | | | | | | \\ \\ | | | | \n" |
---|
| 188 | " /_/ \\_\\ |______| |_| |_| \\_____/ |______/ |_| |_| |_| \\_\\ |_| |_| \n" |
---|
| 189 | "\n\n\t\t Advanced Locality Management Operating System / Multi Kernel Hybrid\n" |
---|
[407] | 190 | "\n\n\t\t Version 0.0 / %d cluster(s) / %d core(s) per cluster / cycle %d\n\n", |
---|
| 191 | nclusters , ncores , hal_time_stamp() ); |
---|
[5] | 192 | } |
---|
[1] | 193 | |
---|
| 194 | |
---|
[5] | 195 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[188] | 196 | // This function initializes the TXT0 chdev descriptor, that is the "kernel terminal", |
---|
| 197 | // shared by all kernel instances for debug messages. |
---|
| 198 | // It is a global variable (replicated in all clusters), because this terminal is used |
---|
| 199 | // before the kmem allocator initialisation, but only the instance in cluster containing |
---|
| 200 | // the calling core is registered in the "chdev_dir" directory. |
---|
[127] | 201 | // As this TXT0 chdev supports only the TXT_SYNC_WRITE command, we don't create |
---|
| 202 | // a server thread, we don't allocate a WTI, and we don't initialize the waiting queue. |
---|
[5] | 203 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 204 | // @ info : pointer on the local boot-info structure. |
---|
| 205 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 206 | static void txt0_device_init( boot_info_t * info ) |
---|
| 207 | { |
---|
| 208 | boot_device_t * dev_tbl; // pointer on array of devices in boot_info |
---|
[127] | 209 | uint32_t dev_nr; // actual number of devices in this cluster |
---|
| 210 | xptr_t base; // remote pointer on segment base |
---|
| 211 | uint32_t func; // device functional index |
---|
[5] | 212 | uint32_t impl; // device implementation index |
---|
[127] | 213 | uint32_t i; // device index in dev_tbl |
---|
| 214 | uint32_t x; // X cluster coordinate |
---|
| 215 | uint32_t y; // Y cluster coordinate |
---|
[188] | 216 | uint32_t channels; // number of channels |
---|
[1] | 217 | |
---|
[5] | 218 | // get number of peripherals and base of devices array from boot_info |
---|
[127] | 219 | dev_nr = info->ext_dev_nr; |
---|
[5] | 220 | dev_tbl = info->ext_dev; |
---|
[1] | 221 | |
---|
[14] | 222 | // loop on external peripherals to find TXT device |
---|
[127] | 223 | for( i = 0 ; i < dev_nr ; i++ ) |
---|
| 224 | { |
---|
[5] | 225 | base = dev_tbl[i].base; |
---|
[188] | 226 | func = FUNC_FROM_TYPE( dev_tbl[i].type ); |
---|
| 227 | impl = IMPL_FROM_TYPE( dev_tbl[i].type ); |
---|
| 228 | channels = dev_tbl[i].channels; |
---|
[5] | 229 | |
---|
[127] | 230 | if (func == DEV_FUNC_TXT ) |
---|
[5] | 231 | { |
---|
[428] | 232 | assert( (channels > 0) , __FUNCTION__ , "number of TXT channels cannot be 0\n"); |
---|
[5] | 233 | |
---|
[428] | 234 | // initializes TXT_TX[0] chdev |
---|
[188] | 235 | txt0_chdev.func = func; |
---|
| 236 | txt0_chdev.impl = impl; |
---|
| 237 | txt0_chdev.channel = 0; |
---|
| 238 | txt0_chdev.base = base; |
---|
| 239 | txt0_chdev.is_rx = false; |
---|
| 240 | |
---|
| 241 | // initializes lock |
---|
[14] | 242 | remote_spinlock_init( XPTR( local_cxy , &txt0_chdev.wait_lock ) ); |
---|
[188] | 243 | |
---|
| 244 | // TXT specific initialisation: |
---|
| 245 | // no server thread & no IRQ routing for channel 0 |
---|
| 246 | dev_txt_init( &txt0_chdev ); |
---|
[14] | 247 | |
---|
[188] | 248 | // register the TXT0 in all chdev_dir[x][y] structures |
---|
[5] | 249 | for( x = 0 ; x < info->x_size ; x++ ) |
---|
| 250 | { |
---|
| 251 | for( y = 0 ; y < info->y_size ; y++ ) |
---|
| 252 | { |
---|
| 253 | cxy_t cxy = (x<<info->y_width) + y; |
---|
[407] | 254 | hal_remote_swd( XPTR( cxy , &chdev_dir.txt_tx[0] ) , |
---|
[14] | 255 | XPTR( local_cxy , &txt0_chdev ) ); |
---|
[5] | 256 | } |
---|
| 257 | } |
---|
| 258 | } |
---|
[188] | 259 | } // end loop on devices |
---|
| 260 | } // end txt0_device_init() |
---|
[5] | 261 | |
---|
[1] | 262 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[188] | 263 | // This function allocates memory and initializes the chdev descriptors for the internal |
---|
| 264 | // peripherals contained in the local cluster, other than the LAPIC, as specified by |
---|
| 265 | // the boot_info, including the linking with the driver for the specified implementation. |
---|
| 266 | // The relevant entries in all copies of the devices directory are initialised. |
---|
[1] | 267 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 268 | // @ info : pointer on the local boot-info structure. |
---|
| 269 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[5] | 270 | static void internal_devices_init( boot_info_t * info ) |
---|
[1] | 271 | { |
---|
[188] | 272 | boot_device_t * dev_tbl; // pointer on array of internaldevices in boot_info |
---|
| 273 | uint32_t dev_nr; // actual number of devices in this cluster |
---|
| 274 | xptr_t base; // remote pointer on segment base |
---|
| 275 | uint32_t func; // device functionnal index |
---|
| 276 | uint32_t impl; // device implementation index |
---|
| 277 | uint32_t i; // device index in dev_tbl |
---|
| 278 | uint32_t x; // X cluster coordinate |
---|
| 279 | uint32_t y; // Y cluster coordinate |
---|
| 280 | uint32_t channels; // number of channels |
---|
| 281 | uint32_t channel; // channel index |
---|
| 282 | chdev_t * chdev_ptr; // local pointer on created chdev |
---|
[1] | 283 | |
---|
[188] | 284 | // get number of internal peripherals and base from boot_info |
---|
| 285 | dev_nr = info->int_dev_nr; |
---|
| 286 | dev_tbl = info->int_dev; |
---|
[1] | 287 | |
---|
[188] | 288 | // loop on internal peripherals |
---|
| 289 | for( i = 0 ; i < dev_nr ; i++ ) |
---|
| 290 | { |
---|
| 291 | base = dev_tbl[i].base; |
---|
| 292 | channels = dev_tbl[i].channels; |
---|
| 293 | func = FUNC_FROM_TYPE( dev_tbl[i].type ); |
---|
| 294 | impl = IMPL_FROM_TYPE( dev_tbl[i].type ); |
---|
[204] | 295 | |
---|
[188] | 296 | ////////////////////////// |
---|
| 297 | if( func == DEV_FUNC_MMC ) |
---|
[5] | 298 | { |
---|
[188] | 299 | assert( (channels == 1) , __FUNCTION__ , |
---|
| 300 | "MMC device must be single channel\n" ); |
---|
[1] | 301 | |
---|
[188] | 302 | // create chdev in local cluster |
---|
| 303 | chdev_ptr = chdev_create( func, |
---|
| 304 | impl, |
---|
| 305 | 0, // channel |
---|
| 306 | false, // direction |
---|
| 307 | base ); |
---|
[14] | 308 | |
---|
[188] | 309 | assert( (chdev_ptr != NULL) , __FUNCTION__ , |
---|
| 310 | "cannot allocate memory for MMC chdev\n" ); |
---|
| 311 | |
---|
| 312 | // make MMC specific initialisation |
---|
| 313 | dev_mmc_init( chdev_ptr ); |
---|
[1] | 314 | |
---|
[188] | 315 | // set the MMC field in all chdev_dir[x][y] structures |
---|
| 316 | for( x = 0 ; x < info->x_size ; x++ ) |
---|
[1] | 317 | { |
---|
[188] | 318 | for( y = 0 ; y < info->y_size ; y++ ) |
---|
| 319 | { |
---|
| 320 | cxy_t cxy = (x<<info->y_width) + y; |
---|
| 321 | hal_remote_swd( XPTR( cxy , &chdev_dir.mmc[local_cxy] ), |
---|
| 322 | XPTR( local_cxy , chdev_ptr ) ); |
---|
| 323 | } |
---|
[1] | 324 | } |
---|
[188] | 325 | |
---|
[438] | 326 | #if( DEBUG_KERNEL_INIT & 0x1 ) |
---|
| 327 | if( hal_time_stamp() > DEBUG_KERNEL_INIT ) |
---|
[407] | 328 | printk("\n[DBG] %s : created MMC in cluster %x / chdev = %x\n", |
---|
| 329 | __FUNCTION__ , local_cxy , chdev_ptr ); |
---|
[389] | 330 | #endif |
---|
[14] | 331 | } |
---|
[188] | 332 | /////////////////////////////// |
---|
| 333 | else if( func == DEV_FUNC_DMA ) |
---|
[127] | 334 | { |
---|
[188] | 335 | // create one chdev per channel in local cluster |
---|
| 336 | for( channel = 0 ; channel < channels ; channel++ ) |
---|
| 337 | { |
---|
| 338 | // create chdev[channel] in local cluster |
---|
| 339 | chdev_ptr = chdev_create( func, |
---|
| 340 | impl, |
---|
| 341 | channel, |
---|
| 342 | false, // direction |
---|
| 343 | base ); |
---|
[5] | 344 | |
---|
[188] | 345 | assert( (chdev_ptr != NULL) , __FUNCTION__ , |
---|
| 346 | "cannot allocate memory for DMA chdev" ); |
---|
| 347 | |
---|
| 348 | // make DMA specific initialisation |
---|
| 349 | dev_dma_init( chdev_ptr ); |
---|
[127] | 350 | |
---|
[188] | 351 | // initialize only the DMA[channel] field in the local chdev_dir[x][y] |
---|
| 352 | // structure because the DMA device is not remotely accessible. |
---|
| 353 | chdev_dir.dma[channel] = XPTR( local_cxy , chdev_ptr ); |
---|
[5] | 354 | |
---|
[438] | 355 | #if( DEBUG_KERNEL_INIT & 0x1 ) |
---|
| 356 | if( hal_time_stamp() > DEBUG_KERNEL_INIT ) |
---|
[407] | 357 | printk("\n[DBG] %s : created DMA[%d] in cluster %x / chdev = %x\n", |
---|
[389] | 358 | __FUNCTION__ , channel , local_cxy , chdev_ptr ); |
---|
| 359 | #endif |
---|
[188] | 360 | } |
---|
[14] | 361 | } |
---|
[127] | 362 | } |
---|
[5] | 363 | } // end internal_devices_init() |
---|
| 364 | |
---|
| 365 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[188] | 366 | // This function allocates memory and initializes the chdev descriptors for the |
---|
[408] | 367 | // external (shared) peripherals other than the IOPIC, as specified by the boot_info. |
---|
| 368 | // This includes the dynamic linking with the driver for the specified implementation. |
---|
[188] | 369 | // These chdev descriptors are distributed on all clusters, using a modulo on a global |
---|
[408] | 370 | // index, identically computed in all clusters. |
---|
| 371 | // This function is executed in all clusters by the CP0 core, that computes a global index |
---|
| 372 | // for all external chdevs. Each CP0 core creates only the chdevs that must be placed in |
---|
| 373 | // the local cluster, because the global index matches the local index. |
---|
[188] | 374 | // The relevant entries in all copies of the devices directory are initialised. |
---|
[5] | 375 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 376 | // @ info : pointer on the local boot-info structure. |
---|
| 377 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 378 | static void external_devices_init( boot_info_t * info ) |
---|
| 379 | { |
---|
[188] | 380 | boot_device_t * dev_tbl; // pointer on array of external devices in boot_info |
---|
| 381 | uint32_t dev_nr; // actual number of external devices |
---|
| 382 | xptr_t base; // remote pointer on segment base |
---|
[5] | 383 | uint32_t func; // device functionnal index |
---|
| 384 | uint32_t impl; // device implementation index |
---|
[188] | 385 | uint32_t i; // device index in dev_tbl |
---|
| 386 | uint32_t x; // X cluster coordinate |
---|
| 387 | uint32_t y; // Y cluster coordinate |
---|
| 388 | uint32_t channels; // number of channels |
---|
| 389 | uint32_t channel; // channel index |
---|
| 390 | uint32_t directions; // number of directions (1 or 2) |
---|
| 391 | uint32_t rx; // direction index (0 or 1) |
---|
[127] | 392 | chdev_t * chdev; // local pointer on one channel_device descriptor |
---|
[188] | 393 | uint32_t ext_chdev_gid; // global index of external chdev |
---|
[5] | 394 | |
---|
| 395 | // get number of peripherals and base of devices array from boot_info |
---|
[127] | 396 | dev_nr = info->ext_dev_nr; |
---|
[5] | 397 | dev_tbl = info->ext_dev; |
---|
| 398 | |
---|
[188] | 399 | // initializes global index (PIC is already placed in cluster 0 |
---|
| 400 | ext_chdev_gid = 1; |
---|
| 401 | |
---|
[5] | 402 | // loop on external peripherals |
---|
[127] | 403 | for( i = 0 ; i < dev_nr ; i++ ) |
---|
| 404 | { |
---|
[188] | 405 | base = dev_tbl[i].base; |
---|
| 406 | channels = dev_tbl[i].channels; |
---|
| 407 | func = FUNC_FROM_TYPE( dev_tbl[i].type ); |
---|
| 408 | impl = IMPL_FROM_TYPE( dev_tbl[i].type ); |
---|
[5] | 409 | |
---|
[407] | 410 | // There is one chdev per direction for NIC and for TXT |
---|
| 411 | if((func == DEV_FUNC_NIC) || (func == DEV_FUNC_TXT)) directions = 2; |
---|
| 412 | else directions = 1; |
---|
[5] | 413 | |
---|
[407] | 414 | // do nothing for ROM, that does not require a device descriptor. |
---|
[5] | 415 | if( func == DEV_FUNC_ROM ) continue; |
---|
| 416 | |
---|
[188] | 417 | // do nothing for PIC, that is already initialized |
---|
| 418 | if( func == DEV_FUNC_PIC ) continue; |
---|
[5] | 419 | |
---|
[188] | 420 | // check PIC device initialized |
---|
| 421 | assert( (chdev_dir.pic != XPTR_NULL ) , __FUNCTION__ , |
---|
| 422 | "PIC device must be initialized before other devices\n" ); |
---|
| 423 | |
---|
| 424 | // check external device functionnal type |
---|
| 425 | assert( ( (func == DEV_FUNC_IOB) || |
---|
| 426 | (func == DEV_FUNC_IOC) || |
---|
| 427 | (func == DEV_FUNC_TXT) || |
---|
| 428 | (func == DEV_FUNC_NIC) || |
---|
| 429 | (func == DEV_FUNC_FBF) ) , __FUNCTION__ , |
---|
| 430 | "undefined external peripheral type\n" ); |
---|
| 431 | |
---|
[127] | 432 | // loops on channels |
---|
[428] | 433 | for( channel = 0 ; channel < channels ; channel++ ) |
---|
[127] | 434 | { |
---|
[5] | 435 | // loop on directions |
---|
[188] | 436 | for( rx = 0 ; rx < directions ; rx++ ) |
---|
[1] | 437 | { |
---|
[428] | 438 | // skip TXT_TX[0] chdev that has already been created & registered |
---|
| 439 | if( (func == DEV_FUNC_TXT) && (channel == 0) && (rx == 0) ) continue; |
---|
| 440 | |
---|
[188] | 441 | // compute target cluster for chdev[func,channel,direction] |
---|
| 442 | uint32_t offset = ext_chdev_gid % ( info->x_size * info->y_size ); |
---|
[5] | 443 | uint32_t cx = offset / info->y_size; |
---|
| 444 | uint32_t cy = offset % info->y_size; |
---|
| 445 | uint32_t target_cxy = (cx<<info->y_width) + cy; |
---|
[1] | 446 | |
---|
[5] | 447 | // allocate and initialize a local chdev |
---|
[407] | 448 | // when local cluster matches target cluster |
---|
[5] | 449 | if( target_cxy == local_cxy ) |
---|
[1] | 450 | { |
---|
[5] | 451 | chdev = chdev_create( func, |
---|
| 452 | impl, |
---|
| 453 | channel, |
---|
[188] | 454 | rx, // direction |
---|
[5] | 455 | base ); |
---|
| 456 | |
---|
[127] | 457 | assert( (chdev != NULL), __FUNCTION__ , |
---|
[5] | 458 | "cannot allocate external device" ); |
---|
| 459 | |
---|
| 460 | // make device type specific initialisation |
---|
| 461 | if ( func == DEV_FUNC_IOB ) dev_iob_init( chdev ); |
---|
| 462 | else if( func == DEV_FUNC_IOC ) dev_ioc_init( chdev ); |
---|
| 463 | else if( func == DEV_FUNC_TXT ) dev_txt_init( chdev ); |
---|
| 464 | else if( func == DEV_FUNC_NIC ) dev_nic_init( chdev ); |
---|
[188] | 465 | else if( func == DEV_FUNC_FBF ) dev_fbf_init( chdev ); |
---|
[5] | 466 | |
---|
[127] | 467 | // all external (shared) devices are remotely accessible |
---|
[5] | 468 | // initialize the replicated chdev_dir[x][y] structures |
---|
[127] | 469 | // defining the extended pointers on chdev descriptors |
---|
| 470 | xptr_t * entry; |
---|
| 471 | |
---|
[188] | 472 | if(func==DEV_FUNC_IOB ) entry = &chdev_dir.iob; |
---|
| 473 | if(func==DEV_FUNC_IOC ) entry = &chdev_dir.ioc[channel]; |
---|
| 474 | if(func==DEV_FUNC_FBF ) entry = &chdev_dir.fbf[channel]; |
---|
[407] | 475 | if((func==DEV_FUNC_TXT) && (rx==0)) entry = &chdev_dir.txt_tx[channel]; |
---|
| 476 | if((func==DEV_FUNC_TXT) && (rx==1)) entry = &chdev_dir.txt_rx[channel]; |
---|
[188] | 477 | if((func==DEV_FUNC_NIC) && (rx==0)) entry = &chdev_dir.nic_tx[channel]; |
---|
| 478 | if((func==DEV_FUNC_NIC) && (rx==1)) entry = &chdev_dir.nic_rx[channel]; |
---|
[127] | 479 | |
---|
[1] | 480 | for( x = 0 ; x < info->x_size ; x++ ) |
---|
| 481 | { |
---|
| 482 | for( y = 0 ; y < info->y_size ; y++ ) |
---|
| 483 | { |
---|
| 484 | cxy_t cxy = (x<<info->y_width) + y; |
---|
[188] | 485 | hal_remote_swd( XPTR( cxy , entry ), |
---|
| 486 | XPTR( local_cxy , chdev ) ); |
---|
[5] | 487 | } |
---|
[1] | 488 | } |
---|
| 489 | |
---|
[438] | 490 | #if( DEBUG_KERNEL_INIT & 0x1 ) |
---|
| 491 | if( hal_time_stamp() > DEBUG_KERNEL_INIT ) |
---|
[407] | 492 | printk("\n[DBG] %s : create chdev %s / channel = %d / rx = %d / cluster %x / chdev = %x\n", |
---|
| 493 | __FUNCTION__ , chdev_func_str( func ), channel , rx , local_cxy , chdev ); |
---|
[389] | 494 | #endif |
---|
[5] | 495 | } // end if match |
---|
| 496 | |
---|
[19] | 497 | // increment chdev global index (matching or not) |
---|
[188] | 498 | ext_chdev_gid++; |
---|
[5] | 499 | |
---|
| 500 | } // end loop on directions |
---|
| 501 | } // end loop on channels |
---|
[188] | 502 | } // end loop on devices |
---|
| 503 | } // end external_devices_init() |
---|
[5] | 504 | |
---|
[188] | 505 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 506 | // This function is called by CP0 in cluster 0 to allocate memory and initialize the PIC |
---|
[407] | 507 | // device, namely the informations attached to the external IOPIC controller, that |
---|
| 508 | // must be replicated in all clusters (struct iopic_input). |
---|
[188] | 509 | // This initialisation must be done before other devices initialisation because the IRQ |
---|
[407] | 510 | // routing infrastructure is required for both internal and external devices init. |
---|
[188] | 511 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 512 | // @ info : pointer on the local boot-info structure. |
---|
| 513 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 514 | static void iopic_init( boot_info_t * info ) |
---|
| 515 | { |
---|
| 516 | boot_device_t * dev_tbl; // pointer on boot_info external devices array |
---|
| 517 | uint32_t dev_nr; // actual number of external devices |
---|
| 518 | xptr_t base; // remote pointer on segment base |
---|
| 519 | uint32_t func; // device functionnal index |
---|
| 520 | uint32_t impl; // device implementation index |
---|
| 521 | uint32_t i; // device index in dev_tbl |
---|
| 522 | uint32_t x; // cluster X coordinate |
---|
| 523 | uint32_t y; // cluster Y coordinate |
---|
| 524 | bool_t found; // IOPIC found |
---|
| 525 | chdev_t * chdev; // pointer on PIC chdev descriptor |
---|
| 526 | |
---|
| 527 | // get number of external peripherals and base of array from boot_info |
---|
| 528 | dev_nr = info->ext_dev_nr; |
---|
| 529 | dev_tbl = info->ext_dev; |
---|
| 530 | |
---|
| 531 | // loop on external peripherals to get the IOPIC |
---|
| 532 | for( i = 0 , found = false ; i < dev_nr ; i++ ) |
---|
| 533 | { |
---|
| 534 | func = FUNC_FROM_TYPE( dev_tbl[i].type ); |
---|
| 535 | |
---|
[127] | 536 | if( func == DEV_FUNC_PIC ) |
---|
[1] | 537 | { |
---|
[188] | 538 | base = dev_tbl[i].base; |
---|
| 539 | impl = IMPL_FROM_TYPE( dev_tbl[i].type ); |
---|
| 540 | found = true; |
---|
| 541 | break; |
---|
| 542 | } |
---|
| 543 | } |
---|
[5] | 544 | |
---|
[188] | 545 | assert( found , __FUNCTION__ , "PIC device not found\n" ); |
---|
[1] | 546 | |
---|
[407] | 547 | // allocate and initialize the PIC chdev in cluster 0 |
---|
| 548 | chdev = chdev_create( DEV_FUNC_PIC, |
---|
[188] | 549 | impl, |
---|
| 550 | 0, // channel |
---|
| 551 | 0, // direction, |
---|
| 552 | base ); |
---|
[5] | 553 | |
---|
[188] | 554 | assert( (chdev != NULL), __FUNCTION__ , "no memory for PIC chdev\n" ); |
---|
[5] | 555 | |
---|
[188] | 556 | // make PIC device type specific initialisation |
---|
| 557 | dev_pic_init( chdev ); |
---|
[1] | 558 | |
---|
[407] | 559 | // register, in all clusters, the extended pointer |
---|
| 560 | // on PIC chdev in "chdev_dir" array |
---|
[188] | 561 | xptr_t * entry = &chdev_dir.pic; |
---|
| 562 | |
---|
| 563 | for( x = 0 ; x < info->x_size ; x++ ) |
---|
| 564 | { |
---|
| 565 | for( y = 0 ; y < info->y_size ; y++ ) |
---|
| 566 | { |
---|
| 567 | cxy_t cxy = (x<<info->y_width) + y; |
---|
| 568 | hal_remote_swd( XPTR( cxy , entry ) , |
---|
| 569 | XPTR( local_cxy , chdev ) ); |
---|
| 570 | } |
---|
| 571 | } |
---|
[1] | 572 | |
---|
[407] | 573 | // initialize, in all clusters, the "iopic_input" structure |
---|
[188] | 574 | // defining how external IRQs are connected to IOPIC |
---|
| 575 | |
---|
[407] | 576 | // register default value for unused inputs |
---|
| 577 | for( x = 0 ; x < info->x_size ; x++ ) |
---|
| 578 | { |
---|
| 579 | for( y = 0 ; y < info->y_size ; y++ ) |
---|
| 580 | { |
---|
| 581 | cxy_t cxy = (x<<info->y_width) + y; |
---|
| 582 | hal_remote_memset( XPTR( cxy , &iopic_input ) , 0xFF , sizeof(iopic_input_t) ); |
---|
| 583 | } |
---|
| 584 | } |
---|
| 585 | |
---|
| 586 | // register input IRQ index for valid inputs |
---|
| 587 | uint32_t id; // input IRQ index |
---|
| 588 | uint8_t valid; // input IRQ is connected |
---|
| 589 | uint32_t type; // source device type |
---|
| 590 | uint8_t channel; // source device channel |
---|
| 591 | uint8_t is_rx; // source device direction |
---|
| 592 | uint32_t * ptr; // local pointer on one field in iopic_input stucture |
---|
| 593 | |
---|
[188] | 594 | for( id = 0 ; id < CONFIG_MAX_EXTERNAL_IRQS ; id++ ) |
---|
| 595 | { |
---|
| 596 | valid = dev_tbl[i].irq[id].valid; |
---|
| 597 | type = dev_tbl[i].irq[id].dev_type; |
---|
| 598 | channel = dev_tbl[i].irq[id].channel; |
---|
| 599 | is_rx = dev_tbl[i].irq[id].is_rx; |
---|
[407] | 600 | func = FUNC_FROM_TYPE( type ); |
---|
[188] | 601 | |
---|
[407] | 602 | // get pointer on relevant field in iopic_input |
---|
| 603 | if( valid ) |
---|
[188] | 604 | { |
---|
[407] | 605 | if ( func == DEV_FUNC_IOC ) ptr = &iopic_input.ioc[channel]; |
---|
| 606 | else if((func == DEV_FUNC_TXT) && (is_rx == 0)) ptr = &iopic_input.txt_tx[channel]; |
---|
| 607 | else if((func == DEV_FUNC_TXT) && (is_rx != 0)) ptr = &iopic_input.txt_rx[channel]; |
---|
| 608 | else if((func == DEV_FUNC_NIC) && (is_rx == 0)) ptr = &iopic_input.nic_tx[channel]; |
---|
| 609 | else if((func == DEV_FUNC_NIC) && (is_rx != 0)) ptr = &iopic_input.nic_rx[channel]; |
---|
| 610 | else if( func == DEV_FUNC_IOB ) ptr = &iopic_input.iob; |
---|
[428] | 611 | else assert( false , __FUNCTION__ , "illegal source device for IOPIC input" ); |
---|
[188] | 612 | |
---|
[407] | 613 | // set one entry in all "iopic_input" structures |
---|
| 614 | for( x = 0 ; x < info->x_size ; x++ ) |
---|
| 615 | { |
---|
| 616 | for( y = 0 ; y < info->y_size ; y++ ) |
---|
| 617 | { |
---|
| 618 | cxy_t cxy = (x<<info->y_width) + y; |
---|
| 619 | hal_remote_swd( XPTR( cxy , ptr ) , id ); |
---|
| 620 | } |
---|
| 621 | } |
---|
[188] | 622 | } |
---|
| 623 | } |
---|
| 624 | |
---|
[438] | 625 | #if( DEBUG_KERNEL_INIT & 0x1 ) |
---|
| 626 | if( hal_time_stamp() > DEBUG_KERNEL_INIT ) |
---|
[407] | 627 | { |
---|
| 628 | printk("\n[DBG] %s created PIC chdev in cluster %x at cycle %d\n", |
---|
| 629 | __FUNCTION__ , local_cxy , (uint32_t)hal_time_stamp() ); |
---|
| 630 | dev_pic_inputs_display(); |
---|
| 631 | } |
---|
[389] | 632 | #endif |
---|
[188] | 633 | |
---|
| 634 | } // end iopic_init() |
---|
| 635 | |
---|
[1] | 636 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[188] | 637 | // This function is called by all CP0s in all cluster to complete the PIC device |
---|
| 638 | // initialisation, namely the informations attached to the LAPIC controller. |
---|
| 639 | // This initialisation must be done after the IOPIC initialisation, but before other |
---|
| 640 | // devices initialisation because the IRQ routing infrastructure is required for both |
---|
| 641 | // internal and external devices initialisation. |
---|
| 642 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 643 | // @ info : pointer on the local boot-info structure. |
---|
| 644 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 645 | static void lapic_init( boot_info_t * info ) |
---|
| 646 | { |
---|
| 647 | boot_device_t * dev_tbl; // pointer on boot_info internal devices array |
---|
| 648 | uint32_t dev_nr; // number of internal devices |
---|
| 649 | uint32_t i; // device index in dev_tbl |
---|
| 650 | xptr_t base; // remote pointer on segment base |
---|
| 651 | uint32_t func; // device functionnal type in boot_info |
---|
| 652 | bool_t found; // LAPIC found |
---|
| 653 | |
---|
| 654 | // get number of internal peripherals and base |
---|
| 655 | dev_nr = info->int_dev_nr; |
---|
| 656 | dev_tbl = info->int_dev; |
---|
| 657 | |
---|
| 658 | // loop on internal peripherals to get the lapic device |
---|
| 659 | for( i = 0 , found = false ; i < dev_nr ; i++ ) |
---|
| 660 | { |
---|
| 661 | func = FUNC_FROM_TYPE( dev_tbl[i].type ); |
---|
| 662 | |
---|
| 663 | if( func == DEV_FUNC_ICU ) |
---|
| 664 | { |
---|
| 665 | base = dev_tbl[i].base; |
---|
| 666 | found = true; |
---|
| 667 | break; |
---|
| 668 | } |
---|
| 669 | } |
---|
| 670 | |
---|
| 671 | // if the LAPIC controller is not defined in the boot_info, |
---|
| 672 | // we simply don't initialize the PIC extensions in the kernel, |
---|
| 673 | // making the assumption that the LAPIC related informations |
---|
| 674 | // are hidden in the hardware specific PIC driver. |
---|
| 675 | if( found ) |
---|
| 676 | { |
---|
| 677 | // initialise the PIC extensions for |
---|
| 678 | // the core descriptor and core manager extensions |
---|
| 679 | dev_pic_extend_init( (uint32_t *)GET_PTR( base ) ); |
---|
| 680 | |
---|
| 681 | // initialize the "lapic_input" structure |
---|
| 682 | // defining how internal IRQs are connected to LAPIC |
---|
| 683 | uint32_t id; |
---|
| 684 | uint8_t valid; |
---|
| 685 | uint8_t channel; |
---|
| 686 | uint32_t func; |
---|
| 687 | |
---|
| 688 | for( id = 0 ; id < CONFIG_MAX_INTERNAL_IRQS ; id++ ) |
---|
| 689 | { |
---|
| 690 | valid = dev_tbl[i].irq[id].valid; |
---|
| 691 | func = FUNC_FROM_TYPE( dev_tbl[i].irq[id].dev_type ); |
---|
| 692 | channel = dev_tbl[i].irq[id].channel; |
---|
| 693 | |
---|
| 694 | if( valid ) // only valid local IRQs are registered |
---|
| 695 | { |
---|
| 696 | if ( func == DEV_FUNC_MMC ) lapic_input.mmc = id; |
---|
| 697 | else if( func == DEV_FUNC_DMA ) lapic_input.dma[channel] = id; |
---|
| 698 | else assert( false , __FUNCTION__ , "illegal source device for LAPIC input" ); |
---|
| 699 | } |
---|
| 700 | } |
---|
| 701 | } |
---|
| 702 | } // end lapic_init() |
---|
| 703 | |
---|
| 704 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[14] | 705 | // This static function returns the identifiers of the calling core. |
---|
| 706 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 707 | // @ info : pointer on boot_info structure. |
---|
| 708 | // @ lid : [out] core local index in cluster. |
---|
| 709 | // @ cxy : [out] cluster identifier. |
---|
| 710 | // @ lid : [out] core global identifier (hardware). |
---|
| 711 | // @ return 0 if success / return EINVAL if not found. |
---|
| 712 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[23] | 713 | static error_t get_core_identifiers( boot_info_t * info, |
---|
| 714 | lid_t * lid, |
---|
[14] | 715 | cxy_t * cxy, |
---|
| 716 | gid_t * gid ) |
---|
| 717 | { |
---|
[127] | 718 | uint32_t i; |
---|
[14] | 719 | gid_t global_id; |
---|
[19] | 720 | |
---|
[14] | 721 | // get global identifier from hardware register |
---|
[127] | 722 | global_id = hal_get_gid(); |
---|
[14] | 723 | |
---|
| 724 | // makes an associative search in boot_info to get (cxy,lid) from global_id |
---|
| 725 | for( i = 0 ; i < info->cores_nr ; i++ ) |
---|
| 726 | { |
---|
| 727 | if( global_id == info->core[i].gid ) |
---|
| 728 | { |
---|
| 729 | *lid = info->core[i].lid; |
---|
| 730 | *cxy = info->core[i].cxy; |
---|
| 731 | *gid = global_id; |
---|
| 732 | return 0; |
---|
| 733 | } |
---|
| 734 | } |
---|
| 735 | return EINVAL; |
---|
[19] | 736 | } |
---|
[14] | 737 | |
---|
| 738 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[1] | 739 | // This function is the entry point for the kernel initialisation. |
---|
[19] | 740 | // It is executed by all cores in all clusters, but only core[0], called CP0, |
---|
[14] | 741 | // initializes the shared resources such as the cluster manager, or the local peripherals. |
---|
[19] | 742 | // To comply with the multi-kernels paradigm, it accesses only local cluster memory, using |
---|
| 743 | // only information contained in the local boot_info_t structure, set by the bootloader. |
---|
[103] | 744 | // Only CP0 in cluster 0 print the log messages. |
---|
[1] | 745 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 746 | // @ info : pointer on the local boot-info structure. |
---|
| 747 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 748 | void kernel_init( boot_info_t * info ) |
---|
| 749 | { |
---|
[204] | 750 | lid_t core_lid = -1; // running core local index |
---|
| 751 | cxy_t core_cxy = -1; // running core cluster identifier |
---|
| 752 | gid_t core_gid; // running core hardware identifier |
---|
| 753 | cluster_t * cluster; // pointer on local cluster manager |
---|
| 754 | core_t * core; // pointer on running core descriptor |
---|
| 755 | thread_t * thread; // pointer on idle thread descriptor |
---|
| 756 | |
---|
| 757 | xptr_t vfs_root_inode_xp; // extended pointer on VFS root inode |
---|
| 758 | xptr_t devfs_dev_inode_xp; // extended pointer on DEVFS dev inode |
---|
| 759 | xptr_t devfs_external_inode_xp; // extended pointer on DEVFS external inode |
---|
| 760 | xptr_t devfs_internal_inode_xp; // extended pointer on DEVFS internal inode |
---|
| 761 | |
---|
[1] | 762 | error_t error; |
---|
[285] | 763 | reg_t status; // running core status register |
---|
[1] | 764 | |
---|
[188] | 765 | cxy_t io_cxy = info->io_cxy; |
---|
| 766 | |
---|
[381] | 767 | assert( (io_cxy == ((info->x_size - 1)<<(info->y_width)) + (info->y_size - 1)) , |
---|
| 768 | __FUNCTION__ , "illegal IO cluter identifier\n" ); |
---|
| 769 | |
---|
[188] | 770 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 771 | // STEP 0 : Each core get its core identifier from boot_info, and makes |
---|
| 772 | // a partial initialisation of its private idle thread descriptor. |
---|
| 773 | // CP0 initializes the "local_cxy" global variable. |
---|
| 774 | // CP0 in cluster IO initializes the TXT0 chdev to print log messages. |
---|
| 775 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 776 | |
---|
[23] | 777 | error = get_core_identifiers( info, |
---|
[14] | 778 | &core_lid, |
---|
| 779 | &core_cxy, |
---|
| 780 | &core_gid ); |
---|
[1] | 781 | |
---|
[127] | 782 | // CP0 initializes cluster identifier |
---|
[14] | 783 | if( core_lid == 0 ) local_cxy = info->cxy; |
---|
[1] | 784 | |
---|
[127] | 785 | // each core gets a pointer on its private idle thread descriptor |
---|
| 786 | thread = (thread_t *)( idle_threads + (core_lid * CONFIG_THREAD_DESC_SIZE) ); |
---|
[68] | 787 | |
---|
[127] | 788 | // each core registers this thread pointer in hardware register |
---|
[68] | 789 | hal_set_current_thread( thread ); |
---|
[71] | 790 | |
---|
[407] | 791 | // each core register core descriptor pointer in idle thread descriptor |
---|
| 792 | thread->core = &LOCAL_CLUSTER->core_tbl[core_lid]; |
---|
| 793 | |
---|
[437] | 794 | // each core initializes the idle thread lists of locks |
---|
[124] | 795 | list_root_init( &thread->locks_root ); |
---|
[188] | 796 | xlist_root_init( XPTR( local_cxy , &thread->xlocks_root ) ); |
---|
[437] | 797 | thread->local_locks = 0; |
---|
| 798 | thread->remote_locks = 0; |
---|
[124] | 799 | |
---|
[188] | 800 | // CP0 in I/O cluster initialises TXT0 chdev descriptor |
---|
| 801 | if( (core_lid == 0) && (core_cxy == io_cxy) ) txt0_device_init( info ); |
---|
[14] | 802 | |
---|
| 803 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[188] | 804 | if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ), |
---|
[14] | 805 | (info->x_size * info->y_size) ); |
---|
| 806 | barrier_wait( &local_barrier , info->cores_nr ); |
---|
[437] | 807 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[14] | 808 | |
---|
[438] | 809 | #if DEBUG_KERNEL_INIT |
---|
| 810 | if( (core_lid == 0) & (local_cxy == 0) ) |
---|
[437] | 811 | printk("\n[DBG] %s : exit barrier 0 : TXT0 initialized / cycle %d\n", |
---|
| 812 | __FUNCTION__, (uint32_t)hal_get_cycles() ); |
---|
| 813 | #endif |
---|
[14] | 814 | |
---|
[188] | 815 | ///////////////////////////////////////////////////////////////////////////// |
---|
[407] | 816 | // STEP 1 : all cores check core identifier. |
---|
[188] | 817 | // CP0 initializes the local cluster manager. |
---|
| 818 | // This includes the memory allocators. |
---|
| 819 | ///////////////////////////////////////////////////////////////////////////// |
---|
| 820 | |
---|
| 821 | // all cores check identifiers |
---|
[14] | 822 | if( error ) |
---|
[1] | 823 | { |
---|
[428] | 824 | assert( false , __FUNCTION__ , |
---|
| 825 | "illegal core identifiers gid = %x / cxy = %x / lid = %d", |
---|
| 826 | core_lid , core_cxy , core_lid ); |
---|
[1] | 827 | } |
---|
| 828 | |
---|
[188] | 829 | // CP0 initializes cluster manager |
---|
[14] | 830 | if( core_lid == 0 ) |
---|
[1] | 831 | { |
---|
| 832 | error = cluster_init( info ); |
---|
| 833 | |
---|
[14] | 834 | if( error ) |
---|
| 835 | { |
---|
[428] | 836 | assert( false , __FUNCTION__ , |
---|
| 837 | "cannot initialise cluster %x", local_cxy ); |
---|
[14] | 838 | } |
---|
| 839 | } |
---|
[5] | 840 | |
---|
[14] | 841 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[188] | 842 | if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ), |
---|
[14] | 843 | (info->x_size * info->y_size) ); |
---|
| 844 | barrier_wait( &local_barrier , info->cores_nr ); |
---|
| 845 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[1] | 846 | |
---|
[438] | 847 | #if DEBUG_KERNEL_INIT |
---|
| 848 | if( (core_lid == 0) & (local_cxy == 0) ) |
---|
[437] | 849 | printk("\n[DBG] %s : exit barrier 1 : clusters initialised / cycle %d\n", |
---|
| 850 | __FUNCTION__, (uint32_t)hal_get_cycles() ); |
---|
| 851 | #endif |
---|
[1] | 852 | |
---|
[188] | 853 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[407] | 854 | // STEP 2 : CP0 initializes the process_zero descriptor. |
---|
[296] | 855 | // CP0 in cluster 0 initializes the IOPIC device. |
---|
[188] | 856 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 857 | |
---|
| 858 | // all cores get pointer on local cluster manager & core descriptor |
---|
[14] | 859 | cluster = &cluster_manager; |
---|
[127] | 860 | core = &cluster->core_tbl[core_lid]; |
---|
[1] | 861 | |
---|
[188] | 862 | // all CP0s initialize the process_zero descriptor |
---|
[428] | 863 | if( core_lid == 0 ) process_zero_create( &process_zero ); |
---|
[5] | 864 | |
---|
[188] | 865 | // CP0 in cluster 0 initializes the PIC chdev, |
---|
| 866 | if( (core_lid == 0) && (local_cxy == 0) ) iopic_init( info ); |
---|
| 867 | |
---|
| 868 | //////////////////////////////////////////////////////////////////////////////// |
---|
| 869 | if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ), |
---|
| 870 | (info->x_size * info->y_size) ); |
---|
| 871 | barrier_wait( &local_barrier , info->cores_nr ); |
---|
| 872 | //////////////////////////////////////////////////////////////////////////////// |
---|
[127] | 873 | |
---|
[438] | 874 | #if DEBUG_KERNEL_INIT |
---|
| 875 | if( (core_lid == 0) & (local_cxy == 0) ) |
---|
[437] | 876 | printk("\n[DBG] %s : exit barrier 2 : PIC initialised / cycle %d\n", |
---|
| 877 | __FUNCTION__, (uint32_t)hal_get_cycles() ); |
---|
| 878 | #endif |
---|
[1] | 879 | |
---|
[188] | 880 | //////////////////////////////////////////////////////////////////////////////// |
---|
[407] | 881 | // STEP 3 : CP0 initializes the distibuted LAPIC descriptor. |
---|
| 882 | // CP0 initializes the internal chdev descriptors |
---|
| 883 | // CP0 initialize the local external chdev descriptors |
---|
[188] | 884 | //////////////////////////////////////////////////////////////////////////////// |
---|
[5] | 885 | |
---|
[279] | 886 | // all CP0s initialize their local LAPIC extension, |
---|
| 887 | if( core_lid == 0 ) lapic_init( info ); |
---|
| 888 | |
---|
[188] | 889 | // CP0 scan the internal (private) peripherals, |
---|
| 890 | // and allocates memory for the corresponding chdev descriptors. |
---|
| 891 | if( core_lid == 0 ) internal_devices_init( info ); |
---|
| 892 | |
---|
[1] | 893 | |
---|
[50] | 894 | // All CP0s contribute to initialise external peripheral chdev descriptors. |
---|
[14] | 895 | // Each CP0[cxy] scan the set of external (shared) peripherals (but the TXT0), |
---|
| 896 | // and allocates memory for the chdev descriptors that must be placed |
---|
[127] | 897 | // on the (cxy) cluster according to the global index value. |
---|
[188] | 898 | |
---|
[14] | 899 | if( core_lid == 0 ) external_devices_init( info ); |
---|
[1] | 900 | |
---|
[14] | 901 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[188] | 902 | if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ), |
---|
[14] | 903 | (info->x_size * info->y_size) ); |
---|
| 904 | barrier_wait( &local_barrier , info->cores_nr ); |
---|
| 905 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[5] | 906 | |
---|
[438] | 907 | #if DEBUG_KERNEL_INIT |
---|
| 908 | if( (core_lid == 0) & (local_cxy == 0) ) |
---|
[437] | 909 | printk("\n[DBG] %s : exit barrier 3 : all chdev initialised / cycle %d\n", |
---|
| 910 | __FUNCTION__, (uint32_t)hal_get_cycles() ); |
---|
| 911 | #endif |
---|
[1] | 912 | |
---|
[438] | 913 | #if( DEBUG_KERNEL_INIT & 1 ) |
---|
[437] | 914 | chdev_dir_display(); |
---|
| 915 | #endif |
---|
| 916 | |
---|
[188] | 917 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[279] | 918 | // STEP 4 : All cores enable IPI (Inter Procesor Interrupt), |
---|
| 919 | // Alh cores initialize IDLE thread. |
---|
[188] | 920 | // Only CP0 in cluster 0 creates the VFS root inode. |
---|
| 921 | // It access the boot device to initialize the file system context. |
---|
| 922 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 923 | |
---|
[279] | 924 | // All cores enable the shared IPI channel |
---|
| 925 | dev_pic_enable_ipi(); |
---|
| 926 | hal_enable_irq( &status ); |
---|
| 927 | |
---|
[296] | 928 | // all cores initialize the idle thread descriptor |
---|
[438] | 929 | error = thread_idle_init( thread, |
---|
| 930 | THREAD_IDLE, |
---|
| 931 | &thread_idle_func, |
---|
| 932 | NULL, |
---|
| 933 | core_lid ); |
---|
[14] | 934 | if( error ) |
---|
[1] | 935 | { |
---|
[428] | 936 | assert( false , __FUNCTION__ , |
---|
| 937 | "core[%x][%d] cannot initialize idle thread", local_cxy , core_lid ); |
---|
[1] | 938 | } |
---|
| 939 | |
---|
[296] | 940 | // all cores unblock idle thread, and register it in scheduler |
---|
| 941 | thread_unblock( XPTR( local_cxy , thread ) , THREAD_BLOCKED_GLOBAL ); |
---|
[103] | 942 | core->scheduler.idle = thread; |
---|
[1] | 943 | |
---|
[438] | 944 | #if( DEBUG_KERNEL_INIT & 1 ) |
---|
[407] | 945 | sched_display( core_lid ); |
---|
[389] | 946 | #endif |
---|
[14] | 947 | |
---|
[188] | 948 | // CPO in cluster 0 creates the VFS root |
---|
| 949 | if( (core_lid == 0) && (local_cxy == 0 ) ) |
---|
[14] | 950 | { |
---|
[188] | 951 | vfs_root_inode_xp = XPTR_NULL; |
---|
[23] | 952 | |
---|
[188] | 953 | // File System must be FATFS in this implementation, |
---|
| 954 | // but other File System can be introduced here |
---|
[23] | 955 | if( CONFIG_VFS_ROOT_IS_FATFS ) |
---|
| 956 | { |
---|
[389] | 957 | // 1. allocate memory for FATFS context in cluster 0 |
---|
[188] | 958 | fatfs_ctx_t * fatfs_ctx = fatfs_ctx_alloc(); |
---|
| 959 | |
---|
[279] | 960 | assert( (fatfs_ctx != NULL) , __FUNCTION__ , |
---|
| 961 | "cannot create FATFS context in cluster 0\n" ); |
---|
[188] | 962 | |
---|
| 963 | // 2. access boot device to initialize FATFS context |
---|
| 964 | fatfs_ctx_init( fatfs_ctx ); |
---|
| 965 | |
---|
| 966 | // 3. get various informations from FATFS context |
---|
| 967 | uint32_t root_dir_cluster = fatfs_ctx->root_dir_cluster; |
---|
| 968 | uint32_t cluster_size = fatfs_ctx->bytes_per_sector * |
---|
| 969 | fatfs_ctx->sectors_per_cluster; |
---|
| 970 | uint32_t total_clusters = fatfs_ctx->fat_sectors_count << 7; |
---|
| 971 | |
---|
| 972 | // 4. create VFS root inode in cluster 0 |
---|
| 973 | error = vfs_inode_create( XPTR_NULL, // dentry_xp |
---|
| 974 | FS_TYPE_FATFS, // fs_type |
---|
| 975 | INODE_TYPE_DIR, // inode_type |
---|
| 976 | (void *)(intptr_t)root_dir_cluster, // extend |
---|
| 977 | 0, // attr |
---|
| 978 | 0, // rights |
---|
| 979 | 0, // uid |
---|
| 980 | 0, // gid |
---|
| 981 | &vfs_root_inode_xp ); // return |
---|
| 982 | |
---|
[279] | 983 | assert( (error == 0) , __FUNCTION__ , |
---|
| 984 | "cannot create VFS root inode\n" ); |
---|
[188] | 985 | |
---|
| 986 | // 5. initialize VFS context for FAT in cluster 0 |
---|
| 987 | vfs_ctx_init( FS_TYPE_FATFS, // file system type |
---|
| 988 | 0, // attributes |
---|
| 989 | total_clusters, |
---|
| 990 | cluster_size, |
---|
| 991 | vfs_root_inode_xp, // VFS root |
---|
| 992 | fatfs_ctx ); // extend |
---|
[389] | 993 | |
---|
| 994 | // 6. check initialisation |
---|
| 995 | vfs_ctx_t * vfs_ctx = &fs_context[FS_TYPE_FATFS]; |
---|
| 996 | assert( (((fatfs_ctx_t *)vfs_ctx->extend)->sectors_per_cluster == 8), |
---|
| 997 | __FUNCTION__ , "illegal value for FATFS context in cluster %x\n", local_cxy ); |
---|
[23] | 998 | } |
---|
| 999 | else |
---|
| 1000 | { |
---|
[428] | 1001 | assert( false , __FUNCTION__ , |
---|
| 1002 | "root FS must be FATFS" ); |
---|
[23] | 1003 | } |
---|
| 1004 | |
---|
[389] | 1005 | // register VFS root inode in process_zero descriptor of cluster 0 |
---|
[188] | 1006 | process_zero.vfs_root_xp = vfs_root_inode_xp; |
---|
| 1007 | process_zero.vfs_cwd_xp = vfs_root_inode_xp; |
---|
| 1008 | } |
---|
| 1009 | |
---|
| 1010 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 1011 | if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ), |
---|
| 1012 | (info->x_size * info->y_size) ); |
---|
| 1013 | barrier_wait( &local_barrier , info->cores_nr ); |
---|
| 1014 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 1015 | |
---|
[438] | 1016 | #if DEBUG_KERNEL_INIT |
---|
| 1017 | if( (core_lid == 0) & (local_cxy == 0) ) |
---|
[437] | 1018 | printk("\n[DBG] %s : exit barrier 4 : VFS_root = %l in cluster 0 / cycle %d\n", |
---|
| 1019 | __FUNCTION__, vfs_root_inode_xp , (uint32_t)hal_get_cycles()); |
---|
| 1020 | #endif |
---|
[188] | 1021 | |
---|
| 1022 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 1023 | // STEP 5 : Other CP0s allocate memory for the selected FS context, |
---|
| 1024 | // and initialise both the local FS context and the local VFS context |
---|
| 1025 | // from values stored in cluster 0. |
---|
| 1026 | // They get the VFS root inode extended pointer from cluster 0. |
---|
| 1027 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 1028 | |
---|
| 1029 | if( (core_lid == 0) && (local_cxy != 0) ) |
---|
| 1030 | { |
---|
| 1031 | // File System must be FATFS in this implementation, |
---|
| 1032 | // but other File System can be introduced here |
---|
| 1033 | if( CONFIG_VFS_ROOT_IS_FATFS ) |
---|
[23] | 1034 | { |
---|
[389] | 1035 | // 1. allocate memory for local FATFS context |
---|
| 1036 | fatfs_ctx_t * local_fatfs_ctx = fatfs_ctx_alloc(); |
---|
[188] | 1037 | |
---|
[389] | 1038 | assert( (local_fatfs_ctx != NULL) , __FUNCTION__ , |
---|
| 1039 | "cannot create FATFS context in cluster %x\n", local_cxy ); |
---|
[188] | 1040 | |
---|
[389] | 1041 | // 2. get local pointer on VFS context for FATFS |
---|
[188] | 1042 | vfs_ctx_t * vfs_ctx = &fs_context[FS_TYPE_FATFS]; |
---|
| 1043 | |
---|
[389] | 1044 | // 3. get local pointer on FATFS context in cluster 0 |
---|
| 1045 | fatfs_ctx_t * remote_fatfs_ctx = hal_remote_lpt( XPTR( 0 , &vfs_ctx->extend ) ); |
---|
| 1046 | |
---|
| 1047 | // 4. copy FATFS context from cluster 0 to local cluster |
---|
| 1048 | hal_remote_memcpy( XPTR( local_cxy , local_fatfs_ctx ), |
---|
| 1049 | XPTR( 0 , remote_fatfs_ctx ), sizeof(fatfs_ctx_t) ); |
---|
| 1050 | |
---|
| 1051 | // 5. copy VFS context from cluster 0 to local cluster |
---|
[188] | 1052 | hal_remote_memcpy( XPTR( local_cxy , vfs_ctx ), |
---|
[389] | 1053 | XPTR( 0 , vfs_ctx ), sizeof(vfs_ctx_t) ); |
---|
[188] | 1054 | |
---|
[389] | 1055 | // 6. update extend field in local copy of VFS context |
---|
| 1056 | vfs_ctx->extend = local_fatfs_ctx; |
---|
[188] | 1057 | |
---|
[389] | 1058 | // 7. check initialisation |
---|
| 1059 | assert( (((fatfs_ctx_t *)vfs_ctx->extend)->sectors_per_cluster == 8), |
---|
| 1060 | __FUNCTION__ , "illegal value for FATFS context in cluster %x\n", local_cxy ); |
---|
[23] | 1061 | } |
---|
| 1062 | |
---|
[188] | 1063 | // get extended pointer on VFS root inode from cluster 0 |
---|
[296] | 1064 | vfs_root_inode_xp = hal_remote_lwd( XPTR( 0 , &process_zero.vfs_root_xp ) ); |
---|
[101] | 1065 | |
---|
[188] | 1066 | // update local process_zero descriptor |
---|
| 1067 | process_zero.vfs_root_xp = vfs_root_inode_xp; |
---|
| 1068 | process_zero.vfs_cwd_xp = vfs_root_inode_xp; |
---|
[14] | 1069 | } |
---|
| 1070 | |
---|
[188] | 1071 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 1072 | if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ), |
---|
| 1073 | (info->x_size * info->y_size) ); |
---|
| 1074 | barrier_wait( &local_barrier , info->cores_nr ); |
---|
[204] | 1075 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[101] | 1076 | |
---|
[438] | 1077 | #if DEBUG_KERNEL_INIT |
---|
| 1078 | if( (core_lid == 0) & (local_cxy == 0) ) |
---|
[437] | 1079 | printk("\n[DBG] %s : exit barrier 5 : VFS_root = %l in cluster %x / cycle %d\n", |
---|
| 1080 | __FUNCTION__, vfs_root_inode_xp , io_cxy , (uint32_t)hal_get_cycles()); |
---|
| 1081 | #endif |
---|
[188] | 1082 | |
---|
| 1083 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 1084 | // STEP 6 : CP0 in cluster IO makes the global DEVFS tree initialisation: |
---|
[204] | 1085 | // It creates the DEVFS directory "dev", and the DEVFS "external" |
---|
| 1086 | // directory in cluster IO and mount these inodes into VFS. |
---|
[188] | 1087 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 1088 | |
---|
| 1089 | if( (core_lid == 0) && (local_cxy == io_cxy) ) |
---|
[1] | 1090 | { |
---|
[188] | 1091 | // create "dev" and "external" directories. |
---|
| 1092 | devfs_global_init( process_zero.vfs_root_xp, |
---|
[204] | 1093 | &devfs_dev_inode_xp, |
---|
[188] | 1094 | &devfs_external_inode_xp ); |
---|
| 1095 | |
---|
| 1096 | // creates the DEVFS context in cluster IO |
---|
| 1097 | devfs_ctx_t * devfs_ctx = devfs_ctx_alloc(); |
---|
| 1098 | |
---|
[279] | 1099 | assert( (devfs_ctx != NULL) , __FUNCTION__ , |
---|
| 1100 | "cannot create DEVFS context in cluster IO\n"); |
---|
[188] | 1101 | |
---|
| 1102 | // register DEVFS root and external directories |
---|
[204] | 1103 | devfs_ctx_init( devfs_ctx, devfs_dev_inode_xp, devfs_external_inode_xp ); |
---|
[188] | 1104 | } |
---|
| 1105 | |
---|
| 1106 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 1107 | if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ), |
---|
| 1108 | (info->x_size * info->y_size) ); |
---|
| 1109 | barrier_wait( &local_barrier , info->cores_nr ); |
---|
[204] | 1110 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[188] | 1111 | |
---|
[438] | 1112 | #if DEBUG_KERNEL_INIT |
---|
| 1113 | if( (core_lid == 0) & (local_cxy == 0) ) |
---|
[437] | 1114 | printk("\n[DBG] %s : exit barrier 6 : dev_root = %l in cluster %x / cycle %d\n", |
---|
| 1115 | __FUNCTION__, devfs_dev_inode_xp , io_cxy , (uint32_t)hal_get_cycles() ); |
---|
| 1116 | #endif |
---|
[188] | 1117 | |
---|
| 1118 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 1119 | // STEP 7 : All CP0s complete in parallel the DEVFS tree initialization. |
---|
| 1120 | // Each CP0 get the "dev" and "external" extended pointers from |
---|
[204] | 1121 | // values stored in cluster IO. |
---|
[337] | 1122 | // Then each CP0 in cluster(i) creates the DEVFS "internal directory, |
---|
[204] | 1123 | // and creates the pseudo-files for all chdevs in cluster (i). |
---|
[188] | 1124 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 1125 | |
---|
| 1126 | if( core_lid == 0 ) |
---|
| 1127 | { |
---|
| 1128 | // get extended pointer on "extend" field of VFS context for DEVFS in cluster IO |
---|
| 1129 | xptr_t extend_xp = XPTR( io_cxy , &fs_context[FS_TYPE_DEVFS].extend ); |
---|
| 1130 | |
---|
| 1131 | // get pointer on DEVFS context in cluster IO |
---|
| 1132 | devfs_ctx_t * devfs_ctx = hal_remote_lpt( extend_xp ); |
---|
| 1133 | |
---|
[204] | 1134 | devfs_dev_inode_xp = hal_remote_lwd( XPTR( io_cxy , |
---|
| 1135 | &devfs_ctx->dev_inode_xp ) ); |
---|
| 1136 | devfs_external_inode_xp = hal_remote_lwd( XPTR( io_cxy , |
---|
| 1137 | &devfs_ctx->external_inode_xp ) ); |
---|
[188] | 1138 | |
---|
[204] | 1139 | // populate DEVFS in all clusters |
---|
| 1140 | devfs_local_init( devfs_dev_inode_xp, |
---|
| 1141 | devfs_external_inode_xp, |
---|
| 1142 | &devfs_internal_inode_xp ); |
---|
[188] | 1143 | } |
---|
| 1144 | |
---|
| 1145 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 1146 | if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ), |
---|
| 1147 | (info->x_size * info->y_size) ); |
---|
| 1148 | barrier_wait( &local_barrier , info->cores_nr ); |
---|
[204] | 1149 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[188] | 1150 | |
---|
[438] | 1151 | #if DEBUG_KERNEL_INIT |
---|
| 1152 | if( (core_lid == 0) & (local_cxy == 0) ) |
---|
[437] | 1153 | printk("\n[DBG] %s : exit barrier 7 : dev_root = %l in cluster 0 / cycle %d\n", |
---|
| 1154 | __FUNCTION__, devfs_dev_inode_xp , (uint32_t)hal_get_cycles() ); |
---|
| 1155 | #endif |
---|
[188] | 1156 | |
---|
| 1157 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[428] | 1158 | // STEP 8 : CP0 in cluster 0 creates the first user process (process_init) |
---|
[188] | 1159 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 1160 | |
---|
[428] | 1161 | if( (core_lid == 0) && (local_cxy == 0) ) |
---|
[188] | 1162 | { |
---|
[428] | 1163 | |
---|
[438] | 1164 | #if( DEBUG_KERNEL_INIT & 1 ) |
---|
[428] | 1165 | vfs_display( vfs_root_inode_xp ); |
---|
| 1166 | #endif |
---|
| 1167 | |
---|
| 1168 | process_init_create(); |
---|
[188] | 1169 | } |
---|
[101] | 1170 | |
---|
[188] | 1171 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[381] | 1172 | if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ), |
---|
[188] | 1173 | (info->x_size * info->y_size) ); |
---|
| 1174 | barrier_wait( &local_barrier , info->cores_nr ); |
---|
[204] | 1175 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[188] | 1176 | |
---|
[438] | 1177 | #if DEBUG_KERNEL_INIT |
---|
| 1178 | if( (core_lid == 0) & (local_cxy == 0) ) |
---|
[437] | 1179 | printk("\n[DBG] %s : exit barrier 8 : process init created / cycle %d\n", |
---|
| 1180 | __FUNCTION__ , (uint32_t)hal_get_cycles() ); |
---|
| 1181 | #endif |
---|
[188] | 1182 | |
---|
| 1183 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 1184 | // STEP 9 : CP0 in cluster 0 print banner |
---|
| 1185 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 1186 | |
---|
| 1187 | if( (core_lid == 0) && (local_cxy == io_cxy) ) |
---|
| 1188 | { |
---|
[5] | 1189 | print_banner( (info->x_size * info->y_size) , info->cores_nr ); |
---|
[68] | 1190 | |
---|
[438] | 1191 | #if( DEBUG_KERNEL_INIT & 1 ) |
---|
[437] | 1192 | printk("\n\n***** memory fooprint for main kernel objects\n\n" |
---|
[68] | 1193 | " - thread descriptor : %d bytes\n" |
---|
| 1194 | " - process descriptor : %d bytes\n" |
---|
| 1195 | " - cluster manager : %d bytes\n" |
---|
| 1196 | " - chdev descriptor : %d bytes\n" |
---|
| 1197 | " - core descriptor : %d bytes\n" |
---|
| 1198 | " - scheduler : %d bytes\n" |
---|
| 1199 | " - rpc fifo : %d bytes\n" |
---|
| 1200 | " - page descriptor : %d bytes\n" |
---|
| 1201 | " - mapper root : %d bytes\n" |
---|
| 1202 | " - ppm manager : %d bytes\n" |
---|
| 1203 | " - kcm manager : %d bytes\n" |
---|
| 1204 | " - khm manager : %d bytes\n" |
---|
| 1205 | " - vmm manager : %d bytes\n" |
---|
| 1206 | " - gpt root : %d bytes\n" |
---|
| 1207 | " - list item : %d bytes\n" |
---|
| 1208 | " - xlist item : %d bytes\n" |
---|
| 1209 | " - spinlock : %d bytes\n" |
---|
| 1210 | " - remote spinlock : %d bytes\n" |
---|
| 1211 | " - rwlock : %d bytes\n" |
---|
| 1212 | " - remote rwlock : %d bytes\n", |
---|
[127] | 1213 | sizeof( thread_t ), |
---|
[68] | 1214 | sizeof( process_t ), |
---|
| 1215 | sizeof( cluster_t ), |
---|
| 1216 | sizeof( chdev_t ), |
---|
| 1217 | sizeof( core_t ), |
---|
| 1218 | sizeof( scheduler_t ), |
---|
[407] | 1219 | sizeof( remote_fifo_t ), |
---|
[68] | 1220 | sizeof( page_t ), |
---|
| 1221 | sizeof( mapper_t ), |
---|
| 1222 | sizeof( ppm_t ), |
---|
| 1223 | sizeof( kcm_t ), |
---|
| 1224 | sizeof( khm_t ), |
---|
| 1225 | sizeof( vmm_t ), |
---|
| 1226 | sizeof( gpt_t ), |
---|
| 1227 | sizeof( list_entry_t ), |
---|
| 1228 | sizeof( xlist_entry_t ), |
---|
| 1229 | sizeof( spinlock_t ), |
---|
| 1230 | sizeof( remote_spinlock_t ), |
---|
| 1231 | sizeof( rwlock_t ), |
---|
| 1232 | sizeof( remote_rwlock_t )); |
---|
[406] | 1233 | #endif |
---|
| 1234 | |
---|
[1] | 1235 | } |
---|
| 1236 | |
---|
[398] | 1237 | // each core activates its private TICK IRQ |
---|
| 1238 | dev_pic_enable_timer( CONFIG_SCHED_TICK_MS_PERIOD ); |
---|
[14] | 1239 | |
---|
[407] | 1240 | // each core jump to thread_idle_func |
---|
[50] | 1241 | thread_idle_func(); |
---|
[127] | 1242 | } |
---|
[14] | 1243 | |
---|