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