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