[1] | 1 | /* |
---|
| 2 | * kernel_init.c - kernel parallel initialization |
---|
[127] | 3 | * |
---|
[23] | 4 | * Authors : Mohamed Lamine Karaoui (2015) |
---|
[623] | 5 | * Alain Greiner (2016,2017,2018,2019) |
---|
[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> |
---|
[457] | 27 | #include <hal_kernel_types.h> |
---|
[1] | 28 | #include <hal_special.h> |
---|
| 29 | #include <hal_context.h> |
---|
[279] | 30 | #include <hal_irqmask.h> |
---|
[564] | 31 | #include <hal_macros.h> |
---|
[296] | 32 | #include <hal_ppm.h> |
---|
[14] | 33 | #include <barrier.h> |
---|
[564] | 34 | #include <xbarrier.h> |
---|
[407] | 35 | #include <remote_fifo.h> |
---|
[1] | 36 | #include <core.h> |
---|
| 37 | #include <list.h> |
---|
[68] | 38 | #include <xlist.h> |
---|
[204] | 39 | #include <xhtab.h> |
---|
[1] | 40 | #include <thread.h> |
---|
| 41 | #include <scheduler.h> |
---|
| 42 | #include <kmem.h> |
---|
| 43 | #include <cluster.h> |
---|
| 44 | #include <string.h> |
---|
| 45 | #include <memcpy.h> |
---|
| 46 | #include <ppm.h> |
---|
| 47 | #include <page.h> |
---|
[5] | 48 | #include <chdev.h> |
---|
[1] | 49 | #include <boot_info.h> |
---|
| 50 | #include <dqdt.h> |
---|
| 51 | #include <dev_mmc.h> |
---|
[5] | 52 | #include <dev_dma.h> |
---|
| 53 | #include <dev_iob.h> |
---|
[1] | 54 | #include <dev_ioc.h> |
---|
[5] | 55 | #include <dev_txt.h> |
---|
[1] | 56 | #include <dev_pic.h> |
---|
| 57 | #include <printk.h> |
---|
| 58 | #include <vfs.h> |
---|
[23] | 59 | #include <devfs.h> |
---|
[68] | 60 | #include <mapper.h> |
---|
[1] | 61 | |
---|
| 62 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[279] | 63 | // All the following global variables are replicated in all clusters. |
---|
[1] | 64 | // They are initialised by the kernel_init() function. |
---|
[14] | 65 | // |
---|
[127] | 66 | // WARNING : The section names have been defined to control the base addresses of the |
---|
[14] | 67 | // boot_info structure and the idle thread descriptors, through the kernel.ld script: |
---|
[127] | 68 | // - the boot_info structure is built by the bootloader, and used by kernel_init. |
---|
| 69 | // it must be the first object in the kdata segment. |
---|
[14] | 70 | // - the array of idle threads descriptors must be placed on the first page boundary after |
---|
| 71 | // the boot_info structure in the kdata segment. |
---|
[1] | 72 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 73 | |
---|
[5] | 74 | // This variable defines the local boot_info structure |
---|
| 75 | __attribute__((section(".kinfo"))) |
---|
[14] | 76 | boot_info_t boot_info; |
---|
[5] | 77 | |
---|
[14] | 78 | // This variable defines the "idle" threads descriptors array |
---|
| 79 | __attribute__((section(".kidle"))) |
---|
[381] | 80 | char idle_threads[CONFIG_THREAD_DESC_SIZE * |
---|
[14] | 81 | CONFIG_MAX_LOCAL_CORES] CONFIG_PPM_PAGE_ALIGNED; |
---|
| 82 | |
---|
[127] | 83 | // This variable defines the local cluster manager |
---|
[5] | 84 | __attribute__((section(".kdata"))) |
---|
[19] | 85 | cluster_t cluster_manager CONFIG_CACHE_LINE_ALIGNED; |
---|
[1] | 86 | |
---|
[564] | 87 | // This variable defines the TXT_TX[0] chdev |
---|
[188] | 88 | __attribute__((section(".kdata"))) |
---|
[564] | 89 | chdev_t txt0_tx_chdev CONFIG_CACHE_LINE_ALIGNED; |
---|
[188] | 90 | |
---|
[564] | 91 | // This variable defines the TXT_RX[0] chdev |
---|
[539] | 92 | __attribute__((section(".kdata"))) |
---|
[564] | 93 | chdev_t txt0_rx_chdev CONFIG_CACHE_LINE_ALIGNED; |
---|
[539] | 94 | |
---|
[14] | 95 | // This variables define the kernel process0 descriptor |
---|
[5] | 96 | __attribute__((section(".kdata"))) |
---|
[19] | 97 | process_t process_zero CONFIG_CACHE_LINE_ALIGNED; |
---|
[1] | 98 | |
---|
[624] | 99 | // This variable defines a set of extended pointers on the distributed chdevs |
---|
[5] | 100 | __attribute__((section(".kdata"))) |
---|
[14] | 101 | chdev_directory_t chdev_dir CONFIG_CACHE_LINE_ALIGNED; |
---|
[1] | 102 | |
---|
[188] | 103 | // This variable contains the input IRQ indexes for the IOPIC controller |
---|
[5] | 104 | __attribute__((section(".kdata"))) |
---|
[246] | 105 | iopic_input_t iopic_input CONFIG_CACHE_LINE_ALIGNED; |
---|
[1] | 106 | |
---|
[188] | 107 | // This variable contains the input IRQ indexes for the LAPIC controller |
---|
[5] | 108 | __attribute__((section(".kdata"))) |
---|
[188] | 109 | lapic_input_t lapic_input CONFIG_CACHE_LINE_ALIGNED; |
---|
[1] | 110 | |
---|
[14] | 111 | // This variable defines the local cluster identifier |
---|
[5] | 112 | __attribute__((section(".kdata"))) |
---|
[14] | 113 | cxy_t local_cxy CONFIG_CACHE_LINE_ALIGNED; |
---|
[5] | 114 | |
---|
[623] | 115 | // This variable is used for core[0] cores synchronisation in kernel_init() |
---|
[5] | 116 | __attribute__((section(".kdata"))) |
---|
[564] | 117 | xbarrier_t global_barrier CONFIG_CACHE_LINE_ALIGNED; |
---|
[1] | 118 | |
---|
[127] | 119 | // This variable is used for local cores synchronisation in kernel_init() |
---|
[14] | 120 | __attribute__((section(".kdata"))) |
---|
| 121 | barrier_t local_barrier CONFIG_CACHE_LINE_ALIGNED; |
---|
| 122 | |
---|
[127] | 123 | // This variable defines the array of supported File System contexts |
---|
[50] | 124 | __attribute__((section(".kdata"))) |
---|
| 125 | vfs_ctx_t fs_context[FS_TYPES_NR] CONFIG_CACHE_LINE_ALIGNED; |
---|
| 126 | |
---|
[564] | 127 | // This array is used for debug, and describes the kernel locks usage, |
---|
| 128 | // It must be kept consistent with the defines in kernel_config.h file. |
---|
[624] | 129 | __attribute__((section(".kdata"))) |
---|
[564] | 130 | char * lock_type_str[] = |
---|
| 131 | { |
---|
| 132 | "unused_0", // 0 |
---|
[408] | 133 | |
---|
[564] | 134 | "CLUSTER_KCM", // 1 |
---|
| 135 | "PPM_FREE", // 2 |
---|
| 136 | "SCHED_STATE", // 3 |
---|
| 137 | "VMM_STACK", // 4 |
---|
| 138 | "VMM_MMAP", // 5 |
---|
| 139 | "VFS_CTX", // 6 |
---|
| 140 | "KCM_STATE", // 7 |
---|
| 141 | "KHM_STATE", // 8 |
---|
| 142 | "HTAB_STATE", // 9 |
---|
| 143 | |
---|
| 144 | "THREAD_JOIN", // 10 |
---|
[610] | 145 | "XHTAB_STATE", // 11 |
---|
[564] | 146 | "CHDEV_QUEUE", // 12 |
---|
| 147 | "CHDEV_TXT0", // 13 |
---|
| 148 | "CHDEV_TXTLIST", // 14 |
---|
| 149 | "PAGE_STATE", // 15 |
---|
| 150 | "MUTEX_STATE", // 16 |
---|
| 151 | "CONDVAR_STATE", // 17 |
---|
| 152 | "SEM_STATE", // 18 |
---|
[619] | 153 | "PROCESS_CWD", // 19 |
---|
| 154 | "BARRIER_STATE", // 20 |
---|
[564] | 155 | |
---|
| 156 | "CLUSTER_PREFTBL", // 21 |
---|
[601] | 157 | |
---|
[564] | 158 | "PPM_DIRTY", // 22 |
---|
| 159 | "CLUSTER_LOCALS", // 23 |
---|
| 160 | "CLUSTER_COPIES", // 24 |
---|
| 161 | "PROCESS_CHILDREN", // 25 |
---|
| 162 | "PROCESS_USERSYNC", // 26 |
---|
| 163 | "PROCESS_FDARRAY", // 27 |
---|
[628] | 164 | "PROCESS_DIR", // 28 |
---|
| 165 | "unused_29", // 29 |
---|
[564] | 166 | |
---|
[611] | 167 | "PROCESS_THTBL", // 30 |
---|
[564] | 168 | |
---|
[611] | 169 | "MAPPER_STATE", // 31 |
---|
| 170 | "VFS_SIZE", // 32 |
---|
| 171 | "VFS_FILE", // 33 |
---|
| 172 | "VMM_VSL", // 34 |
---|
[629] | 173 | "VFS_MAIN", // 35 |
---|
| 174 | "FATFS_FAT", // 36 |
---|
[564] | 175 | }; |
---|
| 176 | |
---|
[601] | 177 | // debug variables to analyse the sys_read() and sys_write() syscalls timing |
---|
[564] | 178 | |
---|
[438] | 179 | #if DEBUG_SYS_READ |
---|
[407] | 180 | uint32_t enter_sys_read; |
---|
| 181 | uint32_t exit_sys_read; |
---|
| 182 | |
---|
[435] | 183 | uint32_t enter_devfs_read; |
---|
| 184 | uint32_t exit_devfs_read; |
---|
[407] | 185 | |
---|
| 186 | uint32_t enter_txt_read; |
---|
| 187 | uint32_t exit_txt_read; |
---|
| 188 | |
---|
[435] | 189 | uint32_t enter_chdev_cmd_read; |
---|
| 190 | uint32_t exit_chdev_cmd_read; |
---|
[407] | 191 | |
---|
[435] | 192 | uint32_t enter_chdev_server_read; |
---|
| 193 | uint32_t exit_chdev_server_read; |
---|
[407] | 194 | |
---|
[435] | 195 | uint32_t enter_tty_cmd_read; |
---|
| 196 | uint32_t exit_tty_cmd_read; |
---|
[407] | 197 | |
---|
[435] | 198 | uint32_t enter_tty_isr_read; |
---|
| 199 | uint32_t exit_tty_isr_read; |
---|
[407] | 200 | #endif |
---|
| 201 | |
---|
[435] | 202 | // these debug variables are used to analyse the sys_write() syscall timing |
---|
| 203 | |
---|
[438] | 204 | #if DEBUG_SYS_WRITE |
---|
[435] | 205 | uint32_t enter_sys_write; |
---|
| 206 | uint32_t exit_sys_write; |
---|
| 207 | |
---|
| 208 | uint32_t enter_devfs_write; |
---|
| 209 | uint32_t exit_devfs_write; |
---|
| 210 | |
---|
| 211 | uint32_t enter_txt_write; |
---|
| 212 | uint32_t exit_txt_write; |
---|
| 213 | |
---|
| 214 | uint32_t enter_chdev_cmd_write; |
---|
| 215 | uint32_t exit_chdev_cmd_write; |
---|
| 216 | |
---|
| 217 | uint32_t enter_chdev_server_write; |
---|
| 218 | uint32_t exit_chdev_server_write; |
---|
| 219 | |
---|
| 220 | uint32_t enter_tty_cmd_write; |
---|
| 221 | uint32_t exit_tty_cmd_write; |
---|
| 222 | |
---|
| 223 | uint32_t enter_tty_isr_write; |
---|
| 224 | uint32_t exit_tty_isr_write; |
---|
| 225 | #endif |
---|
| 226 | |
---|
[564] | 227 | // intrumentation variables : cumulated costs per syscall type in cluster |
---|
[624] | 228 | |
---|
| 229 | #if CONFIG_INSTRUMENTATION_SYSCALLS |
---|
| 230 | __attribute__((section(".kdata"))) |
---|
[564] | 231 | uint32_t syscalls_cumul_cost[SYSCALLS_NR]; |
---|
| 232 | |
---|
[624] | 233 | __attribute__((section(".kdata"))) |
---|
[564] | 234 | uint32_t syscalls_occurences[SYSCALLS_NR]; |
---|
[624] | 235 | #endif |
---|
[564] | 236 | |
---|
[1] | 237 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[5] | 238 | // This function displays the ALMOS_MKH banner. |
---|
[1] | 239 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[5] | 240 | static void print_banner( uint32_t nclusters , uint32_t ncores ) |
---|
[127] | 241 | { |
---|
[5] | 242 | printk("\n" |
---|
| 243 | " _ __ __ _____ ______ __ __ _ __ _ _ \n" |
---|
| 244 | " /\\ | | | \\ / | / ___ \\ / _____| | \\ / | | | / / | | | | \n" |
---|
| 245 | " / \\ | | | \\/ | | / \\ | | / | \\/ | | |/ / | | | | \n" |
---|
| 246 | " / /\\ \\ | | | |\\ /| | | | | | | |_____ ___ | |\\ /| | | / | |___| | \n" |
---|
| 247 | " / /__\\ \\ | | | | \\/ | | | | | | \\_____ \\ |___| | | \\/ | | | \\ | ___ | \n" |
---|
| 248 | " / ______ \\ | | | | | | | | | | | | | | | | | |\\ \\ | | | | \n" |
---|
| 249 | " / / \\ \\ | |____ | | | | | \\___/ | _____/ | | | | | | | \\ \\ | | | | \n" |
---|
| 250 | " /_/ \\_\\ |______| |_| |_| \\_____/ |______/ |_| |_| |_| \\_\\ |_| |_| \n" |
---|
| 251 | "\n\n\t\t Advanced Locality Management Operating System / Multi Kernel Hybrid\n" |
---|
[457] | 252 | "\n\n\t\t %s / %d cluster(s) / %d core(s) per cluster\n\n", |
---|
| 253 | CONFIG_ALMOS_VERSION , nclusters , ncores ); |
---|
[5] | 254 | } |
---|
[1] | 255 | |
---|
| 256 | |
---|
[5] | 257 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[564] | 258 | // This function initializes the TXT_TX[0] and TXT_RX[0] chdev descriptors, implementing |
---|
| 259 | // the "kernel terminal", shared by all kernel instances for debug messages. |
---|
| 260 | // These chdev are implemented as global variables (replicated in all clusters), |
---|
| 261 | // because this terminal is used before the kmem allocator initialisation, but only |
---|
| 262 | // the chdevs in cluster 0 are registered in the "chdev_dir" directory. |
---|
[127] | 263 | // As this TXT0 chdev supports only the TXT_SYNC_WRITE command, we don't create |
---|
| 264 | // a server thread, we don't allocate a WTI, and we don't initialize the waiting queue. |
---|
[564] | 265 | // Note: The TXT_RX[0] chdev is created, but is not used by ALMOS-MKH (september 2018). |
---|
[5] | 266 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 267 | // @ info : pointer on the local boot-info structure. |
---|
| 268 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[564] | 269 | static void __attribute__ ((noinline)) txt0_device_init( boot_info_t * info ) |
---|
[5] | 270 | { |
---|
| 271 | boot_device_t * dev_tbl; // pointer on array of devices in boot_info |
---|
[127] | 272 | uint32_t dev_nr; // actual number of devices in this cluster |
---|
| 273 | xptr_t base; // remote pointer on segment base |
---|
| 274 | uint32_t func; // device functional index |
---|
[5] | 275 | uint32_t impl; // device implementation index |
---|
[127] | 276 | uint32_t i; // device index in dev_tbl |
---|
| 277 | uint32_t x; // X cluster coordinate |
---|
| 278 | uint32_t y; // Y cluster coordinate |
---|
[188] | 279 | uint32_t channels; // number of channels |
---|
[1] | 280 | |
---|
[5] | 281 | // get number of peripherals and base of devices array from boot_info |
---|
[127] | 282 | dev_nr = info->ext_dev_nr; |
---|
[5] | 283 | dev_tbl = info->ext_dev; |
---|
[1] | 284 | |
---|
[14] | 285 | // loop on external peripherals to find TXT device |
---|
[127] | 286 | for( i = 0 ; i < dev_nr ; i++ ) |
---|
| 287 | { |
---|
[5] | 288 | base = dev_tbl[i].base; |
---|
[188] | 289 | func = FUNC_FROM_TYPE( dev_tbl[i].type ); |
---|
| 290 | impl = IMPL_FROM_TYPE( dev_tbl[i].type ); |
---|
| 291 | channels = dev_tbl[i].channels; |
---|
[5] | 292 | |
---|
[127] | 293 | if (func == DEV_FUNC_TXT ) |
---|
[5] | 294 | { |
---|
[564] | 295 | // initialize TXT_TX[0] chdev |
---|
| 296 | txt0_tx_chdev.func = func; |
---|
| 297 | txt0_tx_chdev.impl = impl; |
---|
| 298 | txt0_tx_chdev.channel = 0; |
---|
| 299 | txt0_tx_chdev.base = base; |
---|
| 300 | txt0_tx_chdev.is_rx = false; |
---|
| 301 | remote_busylock_init( XPTR( local_cxy , &txt0_tx_chdev.wait_lock ), |
---|
| 302 | LOCK_CHDEV_TXT0 ); |
---|
[188] | 303 | |
---|
[564] | 304 | // initialize TXT_RX[0] chdev |
---|
| 305 | txt0_rx_chdev.func = func; |
---|
| 306 | txt0_rx_chdev.impl = impl; |
---|
| 307 | txt0_rx_chdev.channel = 0; |
---|
| 308 | txt0_rx_chdev.base = base; |
---|
| 309 | txt0_rx_chdev.is_rx = true; |
---|
| 310 | remote_busylock_init( XPTR( local_cxy , &txt0_rx_chdev.wait_lock ), |
---|
| 311 | LOCK_CHDEV_TXT0 ); |
---|
| 312 | |
---|
| 313 | // make TXT specific initialisations |
---|
| 314 | dev_txt_init( &txt0_tx_chdev ); |
---|
| 315 | dev_txt_init( &txt0_rx_chdev ); |
---|
[14] | 316 | |
---|
[564] | 317 | // register TXT_TX[0] & TXT_RX[0] in chdev_dir[x][y] |
---|
| 318 | // for all valid clusters |
---|
[5] | 319 | for( x = 0 ; x < info->x_size ; x++ ) |
---|
| 320 | { |
---|
[564] | 321 | for( y = 0 ; y < info->y_size ; y++ ) |
---|
[5] | 322 | { |
---|
[564] | 323 | cxy_t cxy = HAL_CXY_FROM_XY( x , y ); |
---|
| 324 | |
---|
| 325 | if( cluster_is_active( cxy ) ) |
---|
| 326 | { |
---|
| 327 | hal_remote_s64( XPTR( cxy , &chdev_dir.txt_tx[0] ) , |
---|
| 328 | XPTR( local_cxy , &txt0_tx_chdev ) ); |
---|
| 329 | hal_remote_s64( XPTR( cxy , &chdev_dir.txt_rx[0] ) , |
---|
| 330 | XPTR( local_cxy , &txt0_rx_chdev ) ); |
---|
[559] | 331 | } |
---|
[5] | 332 | } |
---|
| 333 | } |
---|
[564] | 334 | |
---|
| 335 | hal_fence(); |
---|
[5] | 336 | } |
---|
[188] | 337 | } // end loop on devices |
---|
| 338 | } // end txt0_device_init() |
---|
[5] | 339 | |
---|
[1] | 340 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[188] | 341 | // This function allocates memory and initializes the chdev descriptors for the internal |
---|
| 342 | // peripherals contained in the local cluster, other than the LAPIC, as specified by |
---|
| 343 | // the boot_info, including the linking with the driver for the specified implementation. |
---|
| 344 | // The relevant entries in all copies of the devices directory are initialised. |
---|
[1] | 345 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 346 | // @ info : pointer on the local boot-info structure. |
---|
| 347 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[564] | 348 | static void __attribute__ ((noinline)) internal_devices_init( boot_info_t * info ) |
---|
[1] | 349 | { |
---|
[188] | 350 | boot_device_t * dev_tbl; // pointer on array of internaldevices in boot_info |
---|
| 351 | uint32_t dev_nr; // actual number of devices in this cluster |
---|
| 352 | xptr_t base; // remote pointer on segment base |
---|
| 353 | uint32_t func; // device functionnal index |
---|
| 354 | uint32_t impl; // device implementation index |
---|
| 355 | uint32_t i; // device index in dev_tbl |
---|
| 356 | uint32_t x; // X cluster coordinate |
---|
| 357 | uint32_t y; // Y cluster coordinate |
---|
| 358 | uint32_t channels; // number of channels |
---|
| 359 | uint32_t channel; // channel index |
---|
| 360 | chdev_t * chdev_ptr; // local pointer on created chdev |
---|
[1] | 361 | |
---|
[188] | 362 | // get number of internal peripherals and base from boot_info |
---|
| 363 | dev_nr = info->int_dev_nr; |
---|
| 364 | dev_tbl = info->int_dev; |
---|
[1] | 365 | |
---|
[188] | 366 | // loop on internal peripherals |
---|
| 367 | for( i = 0 ; i < dev_nr ; i++ ) |
---|
| 368 | { |
---|
| 369 | base = dev_tbl[i].base; |
---|
| 370 | channels = dev_tbl[i].channels; |
---|
| 371 | func = FUNC_FROM_TYPE( dev_tbl[i].type ); |
---|
| 372 | impl = IMPL_FROM_TYPE( dev_tbl[i].type ); |
---|
[204] | 373 | |
---|
[188] | 374 | ////////////////////////// |
---|
| 375 | if( func == DEV_FUNC_MMC ) |
---|
[5] | 376 | { |
---|
[1] | 377 | |
---|
[564] | 378 | // check channels |
---|
| 379 | if( channels != 1 ) |
---|
[580] | 380 | { |
---|
| 381 | printk("\n[PANIC] in %s : MMC device must be single channel\n", |
---|
| 382 | __FUNCTION__ ); |
---|
| 383 | hal_core_sleep(); |
---|
| 384 | } |
---|
[564] | 385 | |
---|
[188] | 386 | // create chdev in local cluster |
---|
| 387 | chdev_ptr = chdev_create( func, |
---|
| 388 | impl, |
---|
| 389 | 0, // channel |
---|
| 390 | false, // direction |
---|
| 391 | base ); |
---|
[14] | 392 | |
---|
[564] | 393 | // check memory |
---|
| 394 | if( chdev_ptr == NULL ) |
---|
[580] | 395 | { |
---|
| 396 | printk("\n[PANIC] in %s : cannot create MMC chdev\n", |
---|
| 397 | __FUNCTION__ ); |
---|
| 398 | hal_core_sleep(); |
---|
| 399 | } |
---|
[188] | 400 | |
---|
| 401 | // make MMC specific initialisation |
---|
| 402 | dev_mmc_init( chdev_ptr ); |
---|
[1] | 403 | |
---|
[188] | 404 | // set the MMC field in all chdev_dir[x][y] structures |
---|
| 405 | for( x = 0 ; x < info->x_size ; x++ ) |
---|
[1] | 406 | { |
---|
[564] | 407 | for( y = 0 ; y < info->y_size ; y++ ) |
---|
[188] | 408 | { |
---|
[564] | 409 | cxy_t cxy = HAL_CXY_FROM_XY( x , y ); |
---|
| 410 | |
---|
| 411 | if( cluster_is_active( cxy ) ) |
---|
| 412 | { |
---|
| 413 | hal_remote_s64( XPTR( cxy , &chdev_dir.mmc[local_cxy] ), |
---|
[559] | 414 | XPTR( local_cxy , chdev_ptr ) ); |
---|
| 415 | } |
---|
[188] | 416 | } |
---|
[1] | 417 | } |
---|
[188] | 418 | |
---|
[438] | 419 | #if( DEBUG_KERNEL_INIT & 0x1 ) |
---|
| 420 | if( hal_time_stamp() > DEBUG_KERNEL_INIT ) |
---|
[601] | 421 | printk("\n[%s] : created MMC in cluster %x / chdev = %x\n", |
---|
[407] | 422 | __FUNCTION__ , local_cxy , chdev_ptr ); |
---|
[389] | 423 | #endif |
---|
[14] | 424 | } |
---|
[188] | 425 | /////////////////////////////// |
---|
| 426 | else if( func == DEV_FUNC_DMA ) |
---|
[127] | 427 | { |
---|
[188] | 428 | // create one chdev per channel in local cluster |
---|
| 429 | for( channel = 0 ; channel < channels ; channel++ ) |
---|
| 430 | { |
---|
| 431 | // create chdev[channel] in local cluster |
---|
| 432 | chdev_ptr = chdev_create( func, |
---|
| 433 | impl, |
---|
| 434 | channel, |
---|
| 435 | false, // direction |
---|
| 436 | base ); |
---|
[5] | 437 | |
---|
[564] | 438 | // check memory |
---|
| 439 | if( chdev_ptr == NULL ) |
---|
[580] | 440 | { |
---|
| 441 | printk("\n[PANIC] in %s : cannot create DMA chdev\n", |
---|
| 442 | __FUNCTION__ ); |
---|
| 443 | hal_core_sleep(); |
---|
| 444 | } |
---|
[564] | 445 | |
---|
[188] | 446 | // make DMA specific initialisation |
---|
| 447 | dev_dma_init( chdev_ptr ); |
---|
[127] | 448 | |
---|
[188] | 449 | // initialize only the DMA[channel] field in the local chdev_dir[x][y] |
---|
| 450 | // structure because the DMA device is not remotely accessible. |
---|
| 451 | chdev_dir.dma[channel] = XPTR( local_cxy , chdev_ptr ); |
---|
[5] | 452 | |
---|
[438] | 453 | #if( DEBUG_KERNEL_INIT & 0x1 ) |
---|
| 454 | if( hal_time_stamp() > DEBUG_KERNEL_INIT ) |
---|
[601] | 455 | printk("\n[%s] : created DMA[%d] in cluster %x / chdev = %x\n", |
---|
[389] | 456 | __FUNCTION__ , channel , local_cxy , chdev_ptr ); |
---|
| 457 | #endif |
---|
[188] | 458 | } |
---|
[14] | 459 | } |
---|
[127] | 460 | } |
---|
[5] | 461 | } // end internal_devices_init() |
---|
| 462 | |
---|
| 463 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[188] | 464 | // This function allocates memory and initializes the chdev descriptors for the |
---|
[408] | 465 | // external (shared) peripherals other than the IOPIC, as specified by the boot_info. |
---|
| 466 | // This includes the dynamic linking with the driver for the specified implementation. |
---|
[188] | 467 | // These chdev descriptors are distributed on all clusters, using a modulo on a global |
---|
[408] | 468 | // index, identically computed in all clusters. |
---|
[623] | 469 | // This function is executed in all clusters by the core[0] core, that computes a global index |
---|
| 470 | // for all external chdevs. Each core[0] core creates only the chdevs that must be placed in |
---|
[408] | 471 | // the local cluster, because the global index matches the local index. |
---|
[188] | 472 | // The relevant entries in all copies of the devices directory are initialised. |
---|
[5] | 473 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 474 | // @ info : pointer on the local boot-info structure. |
---|
| 475 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 476 | static void external_devices_init( boot_info_t * info ) |
---|
| 477 | { |
---|
[188] | 478 | boot_device_t * dev_tbl; // pointer on array of external devices in boot_info |
---|
| 479 | uint32_t dev_nr; // actual number of external devices |
---|
| 480 | xptr_t base; // remote pointer on segment base |
---|
[5] | 481 | uint32_t func; // device functionnal index |
---|
| 482 | uint32_t impl; // device implementation index |
---|
[188] | 483 | uint32_t i; // device index in dev_tbl |
---|
| 484 | uint32_t x; // X cluster coordinate |
---|
| 485 | uint32_t y; // Y cluster coordinate |
---|
| 486 | uint32_t channels; // number of channels |
---|
| 487 | uint32_t channel; // channel index |
---|
| 488 | uint32_t directions; // number of directions (1 or 2) |
---|
| 489 | uint32_t rx; // direction index (0 or 1) |
---|
[127] | 490 | chdev_t * chdev; // local pointer on one channel_device descriptor |
---|
[188] | 491 | uint32_t ext_chdev_gid; // global index of external chdev |
---|
[5] | 492 | |
---|
| 493 | // get number of peripherals and base of devices array from boot_info |
---|
[127] | 494 | dev_nr = info->ext_dev_nr; |
---|
[5] | 495 | dev_tbl = info->ext_dev; |
---|
| 496 | |
---|
[188] | 497 | // initializes global index (PIC is already placed in cluster 0 |
---|
| 498 | ext_chdev_gid = 1; |
---|
| 499 | |
---|
[5] | 500 | // loop on external peripherals |
---|
[127] | 501 | for( i = 0 ; i < dev_nr ; i++ ) |
---|
| 502 | { |
---|
[188] | 503 | base = dev_tbl[i].base; |
---|
| 504 | channels = dev_tbl[i].channels; |
---|
| 505 | func = FUNC_FROM_TYPE( dev_tbl[i].type ); |
---|
| 506 | impl = IMPL_FROM_TYPE( dev_tbl[i].type ); |
---|
[5] | 507 | |
---|
[407] | 508 | // There is one chdev per direction for NIC and for TXT |
---|
| 509 | if((func == DEV_FUNC_NIC) || (func == DEV_FUNC_TXT)) directions = 2; |
---|
| 510 | else directions = 1; |
---|
[5] | 511 | |
---|
[407] | 512 | // do nothing for ROM, that does not require a device descriptor. |
---|
[5] | 513 | if( func == DEV_FUNC_ROM ) continue; |
---|
| 514 | |
---|
[188] | 515 | // do nothing for PIC, that is already initialized |
---|
| 516 | if( func == DEV_FUNC_PIC ) continue; |
---|
[5] | 517 | |
---|
[188] | 518 | // check PIC device initialized |
---|
[564] | 519 | if( chdev_dir.pic == XPTR_NULL ) |
---|
[580] | 520 | { |
---|
| 521 | printk("\n[PANIC] in %s : PIC device must be initialized first\n", |
---|
| 522 | __FUNCTION__ ); |
---|
| 523 | hal_core_sleep(); |
---|
| 524 | } |
---|
[188] | 525 | |
---|
| 526 | // check external device functionnal type |
---|
[564] | 527 | if( (func != DEV_FUNC_IOB) && (func != DEV_FUNC_IOC) && (func != DEV_FUNC_TXT) && |
---|
| 528 | (func != DEV_FUNC_NIC) && (func != DEV_FUNC_FBF) ) |
---|
[580] | 529 | { |
---|
| 530 | printk("\n[PANIC] in %s : undefined peripheral type\n", |
---|
| 531 | __FUNCTION__ ); |
---|
| 532 | hal_core_sleep(); |
---|
| 533 | } |
---|
[188] | 534 | |
---|
[127] | 535 | // loops on channels |
---|
[428] | 536 | for( channel = 0 ; channel < channels ; channel++ ) |
---|
[127] | 537 | { |
---|
[5] | 538 | // loop on directions |
---|
[188] | 539 | for( rx = 0 ; rx < directions ; rx++ ) |
---|
[1] | 540 | { |
---|
[564] | 541 | // skip TXT0 that has already been initialized |
---|
| 542 | if( (func == DEV_FUNC_TXT) && (channel == 0) ) continue; |
---|
[428] | 543 | |
---|
[564] | 544 | // all kernel instances compute the target cluster for all chdevs, |
---|
| 545 | // computing the global index ext_chdev_gid[func,channel,direction] |
---|
| 546 | cxy_t target_cxy; |
---|
| 547 | while( 1 ) |
---|
[536] | 548 | { |
---|
[564] | 549 | uint32_t offset = ext_chdev_gid % ( info->x_size * info->y_size ); |
---|
| 550 | uint32_t x = offset / info->y_size; |
---|
| 551 | uint32_t y = offset % info->y_size; |
---|
[536] | 552 | |
---|
[564] | 553 | target_cxy = HAL_CXY_FROM_XY( x , y ); |
---|
| 554 | |
---|
| 555 | // exit loop if target cluster is active |
---|
| 556 | if( cluster_is_active( target_cxy ) ) break; |
---|
| 557 | |
---|
| 558 | // increment global index otherwise |
---|
| 559 | ext_chdev_gid++; |
---|
[550] | 560 | } |
---|
| 561 | |
---|
[5] | 562 | // allocate and initialize a local chdev |
---|
[407] | 563 | // when local cluster matches target cluster |
---|
[5] | 564 | if( target_cxy == local_cxy ) |
---|
[1] | 565 | { |
---|
[5] | 566 | chdev = chdev_create( func, |
---|
| 567 | impl, |
---|
| 568 | channel, |
---|
[188] | 569 | rx, // direction |
---|
[5] | 570 | base ); |
---|
| 571 | |
---|
[564] | 572 | if( chdev == NULL ) |
---|
[580] | 573 | { |
---|
| 574 | printk("\n[PANIC] in %s : cannot allocate chdev\n", |
---|
| 575 | __FUNCTION__ ); |
---|
| 576 | hal_core_sleep(); |
---|
| 577 | } |
---|
[5] | 578 | |
---|
| 579 | // make device type specific initialisation |
---|
| 580 | if ( func == DEV_FUNC_IOB ) dev_iob_init( chdev ); |
---|
| 581 | else if( func == DEV_FUNC_IOC ) dev_ioc_init( chdev ); |
---|
| 582 | else if( func == DEV_FUNC_TXT ) dev_txt_init( chdev ); |
---|
| 583 | else if( func == DEV_FUNC_NIC ) dev_nic_init( chdev ); |
---|
[188] | 584 | else if( func == DEV_FUNC_FBF ) dev_fbf_init( chdev ); |
---|
[5] | 585 | |
---|
[127] | 586 | // all external (shared) devices are remotely accessible |
---|
[5] | 587 | // initialize the replicated chdev_dir[x][y] structures |
---|
[127] | 588 | // defining the extended pointers on chdev descriptors |
---|
| 589 | xptr_t * entry; |
---|
| 590 | |
---|
[188] | 591 | if(func==DEV_FUNC_IOB ) entry = &chdev_dir.iob; |
---|
| 592 | if(func==DEV_FUNC_IOC ) entry = &chdev_dir.ioc[channel]; |
---|
| 593 | if(func==DEV_FUNC_FBF ) entry = &chdev_dir.fbf[channel]; |
---|
[407] | 594 | if((func==DEV_FUNC_TXT) && (rx==0)) entry = &chdev_dir.txt_tx[channel]; |
---|
| 595 | if((func==DEV_FUNC_TXT) && (rx==1)) entry = &chdev_dir.txt_rx[channel]; |
---|
[188] | 596 | if((func==DEV_FUNC_NIC) && (rx==0)) entry = &chdev_dir.nic_tx[channel]; |
---|
| 597 | if((func==DEV_FUNC_NIC) && (rx==1)) entry = &chdev_dir.nic_rx[channel]; |
---|
[127] | 598 | |
---|
[1] | 599 | for( x = 0 ; x < info->x_size ; x++ ) |
---|
| 600 | { |
---|
[564] | 601 | for( y = 0 ; y < info->y_size ; y++ ) |
---|
[1] | 602 | { |
---|
[564] | 603 | cxy_t cxy = HAL_CXY_FROM_XY( x , y ); |
---|
| 604 | |
---|
| 605 | if( cluster_is_active( cxy ) ) |
---|
| 606 | { |
---|
| 607 | hal_remote_s64( XPTR( cxy , entry ), |
---|
[559] | 608 | XPTR( local_cxy , chdev ) ); |
---|
| 609 | } |
---|
[5] | 610 | } |
---|
[1] | 611 | } |
---|
| 612 | |
---|
[438] | 613 | #if( DEBUG_KERNEL_INIT & 0x1 ) |
---|
| 614 | if( hal_time_stamp() > DEBUG_KERNEL_INIT ) |
---|
[601] | 615 | printk("\n[%s] : create chdev %s / channel = %d / rx = %d / cluster %x / chdev = %x\n", |
---|
[407] | 616 | __FUNCTION__ , chdev_func_str( func ), channel , rx , local_cxy , chdev ); |
---|
[389] | 617 | #endif |
---|
[5] | 618 | } // end if match |
---|
| 619 | |
---|
[19] | 620 | // increment chdev global index (matching or not) |
---|
[188] | 621 | ext_chdev_gid++; |
---|
[5] | 622 | |
---|
| 623 | } // end loop on directions |
---|
| 624 | } // end loop on channels |
---|
[188] | 625 | } // end loop on devices |
---|
| 626 | } // end external_devices_init() |
---|
[5] | 627 | |
---|
[188] | 628 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[623] | 629 | // This function is called by core[0] in cluster 0 to allocate memory and initialize the PIC |
---|
[407] | 630 | // device, namely the informations attached to the external IOPIC controller, that |
---|
| 631 | // must be replicated in all clusters (struct iopic_input). |
---|
[188] | 632 | // This initialisation must be done before other devices initialisation because the IRQ |
---|
[407] | 633 | // routing infrastructure is required for both internal and external devices init. |
---|
[188] | 634 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 635 | // @ info : pointer on the local boot-info structure. |
---|
| 636 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[564] | 637 | static void __attribute__ ((noinline)) iopic_init( boot_info_t * info ) |
---|
[188] | 638 | { |
---|
| 639 | boot_device_t * dev_tbl; // pointer on boot_info external devices array |
---|
| 640 | uint32_t dev_nr; // actual number of external devices |
---|
| 641 | xptr_t base; // remote pointer on segment base |
---|
| 642 | uint32_t func; // device functionnal index |
---|
| 643 | uint32_t impl; // device implementation index |
---|
| 644 | uint32_t i; // device index in dev_tbl |
---|
| 645 | uint32_t x; // cluster X coordinate |
---|
| 646 | uint32_t y; // cluster Y coordinate |
---|
| 647 | bool_t found; // IOPIC found |
---|
| 648 | chdev_t * chdev; // pointer on PIC chdev descriptor |
---|
| 649 | |
---|
| 650 | // get number of external peripherals and base of array from boot_info |
---|
| 651 | dev_nr = info->ext_dev_nr; |
---|
| 652 | dev_tbl = info->ext_dev; |
---|
| 653 | |
---|
[564] | 654 | // avoid GCC warning |
---|
| 655 | base = XPTR_NULL; |
---|
| 656 | impl = 0; |
---|
| 657 | |
---|
[188] | 658 | // loop on external peripherals to get the IOPIC |
---|
| 659 | for( i = 0 , found = false ; i < dev_nr ; i++ ) |
---|
| 660 | { |
---|
| 661 | func = FUNC_FROM_TYPE( dev_tbl[i].type ); |
---|
| 662 | |
---|
[127] | 663 | if( func == DEV_FUNC_PIC ) |
---|
[1] | 664 | { |
---|
[188] | 665 | base = dev_tbl[i].base; |
---|
| 666 | impl = IMPL_FROM_TYPE( dev_tbl[i].type ); |
---|
| 667 | found = true; |
---|
| 668 | break; |
---|
| 669 | } |
---|
| 670 | } |
---|
[5] | 671 | |
---|
[564] | 672 | // check PIC existence |
---|
| 673 | if( found == false ) |
---|
[580] | 674 | { |
---|
| 675 | printk("\n[PANIC] in %s : PIC device not found\n", |
---|
| 676 | __FUNCTION__ ); |
---|
| 677 | hal_core_sleep(); |
---|
| 678 | } |
---|
[1] | 679 | |
---|
[407] | 680 | // allocate and initialize the PIC chdev in cluster 0 |
---|
| 681 | chdev = chdev_create( DEV_FUNC_PIC, |
---|
[188] | 682 | impl, |
---|
| 683 | 0, // channel |
---|
| 684 | 0, // direction, |
---|
| 685 | base ); |
---|
[5] | 686 | |
---|
[564] | 687 | // check memory |
---|
| 688 | if( chdev == NULL ) |
---|
[580] | 689 | { |
---|
| 690 | printk("\n[PANIC] in %s : no memory for PIC chdev\n", |
---|
| 691 | __FUNCTION__ ); |
---|
| 692 | hal_core_sleep(); |
---|
| 693 | } |
---|
[5] | 694 | |
---|
[188] | 695 | // make PIC device type specific initialisation |
---|
| 696 | dev_pic_init( chdev ); |
---|
[1] | 697 | |
---|
[407] | 698 | // register, in all clusters, the extended pointer |
---|
| 699 | // on PIC chdev in "chdev_dir" array |
---|
[188] | 700 | xptr_t * entry = &chdev_dir.pic; |
---|
| 701 | |
---|
| 702 | for( x = 0 ; x < info->x_size ; x++ ) |
---|
| 703 | { |
---|
[564] | 704 | for( y = 0 ; y < info->y_size ; y++ ) |
---|
[188] | 705 | { |
---|
[564] | 706 | cxy_t cxy = HAL_CXY_FROM_XY( x , y ); |
---|
| 707 | |
---|
| 708 | if( cluster_is_active( cxy ) ) |
---|
| 709 | { |
---|
| 710 | hal_remote_s64( XPTR( cxy , entry ) , |
---|
[559] | 711 | XPTR( local_cxy , chdev ) ); |
---|
| 712 | } |
---|
[188] | 713 | } |
---|
| 714 | } |
---|
[1] | 715 | |
---|
[407] | 716 | // initialize, in all clusters, the "iopic_input" structure |
---|
[188] | 717 | // defining how external IRQs are connected to IOPIC |
---|
| 718 | |
---|
[407] | 719 | // register default value for unused inputs |
---|
| 720 | for( x = 0 ; x < info->x_size ; x++ ) |
---|
| 721 | { |
---|
[564] | 722 | for( y = 0 ; y < info->y_size ; y++ ) |
---|
[407] | 723 | { |
---|
[564] | 724 | cxy_t cxy = HAL_CXY_FROM_XY( x , y ); |
---|
| 725 | |
---|
| 726 | if( cluster_is_active( cxy ) ) |
---|
| 727 | { |
---|
| 728 | hal_remote_memset( XPTR( cxy , &iopic_input ), |
---|
| 729 | 0xFF , sizeof(iopic_input_t) ); |
---|
[559] | 730 | } |
---|
[407] | 731 | } |
---|
| 732 | } |
---|
| 733 | |
---|
| 734 | // register input IRQ index for valid inputs |
---|
[577] | 735 | uint32_t id; // input IRQ index |
---|
| 736 | uint8_t valid; // input IRQ is connected |
---|
| 737 | uint32_t type; // source device type |
---|
| 738 | uint8_t channel; // source device channel |
---|
| 739 | uint8_t is_rx; // source device direction |
---|
| 740 | uint32_t * ptr = NULL; // local pointer on one field in iopic_input stucture |
---|
[407] | 741 | |
---|
[188] | 742 | for( id = 0 ; id < CONFIG_MAX_EXTERNAL_IRQS ; id++ ) |
---|
| 743 | { |
---|
| 744 | valid = dev_tbl[i].irq[id].valid; |
---|
| 745 | type = dev_tbl[i].irq[id].dev_type; |
---|
| 746 | channel = dev_tbl[i].irq[id].channel; |
---|
| 747 | is_rx = dev_tbl[i].irq[id].is_rx; |
---|
[407] | 748 | func = FUNC_FROM_TYPE( type ); |
---|
[188] | 749 | |
---|
[407] | 750 | // get pointer on relevant field in iopic_input |
---|
| 751 | if( valid ) |
---|
[188] | 752 | { |
---|
[407] | 753 | if ( func == DEV_FUNC_IOC ) ptr = &iopic_input.ioc[channel]; |
---|
| 754 | else if((func == DEV_FUNC_TXT) && (is_rx == 0)) ptr = &iopic_input.txt_tx[channel]; |
---|
| 755 | else if((func == DEV_FUNC_TXT) && (is_rx != 0)) ptr = &iopic_input.txt_rx[channel]; |
---|
[492] | 756 | else if((func == DEV_FUNC_NIC) && (is_rx == 0)) ptr = &iopic_input.nic_tx[channel]; |
---|
| 757 | else if((func == DEV_FUNC_NIC) && (is_rx != 0)) ptr = &iopic_input.nic_rx[channel]; |
---|
| 758 | else if( func == DEV_FUNC_IOB ) ptr = &iopic_input.iob; |
---|
[580] | 759 | else |
---|
| 760 | { |
---|
| 761 | printk("\n[PANIC] in %s : illegal source device for IOPIC input\n", |
---|
| 762 | __FUNCTION__ ); |
---|
| 763 | hal_core_sleep(); |
---|
| 764 | } |
---|
[188] | 765 | |
---|
[407] | 766 | // set one entry in all "iopic_input" structures |
---|
| 767 | for( x = 0 ; x < info->x_size ; x++ ) |
---|
| 768 | { |
---|
[564] | 769 | for( y = 0 ; y < info->y_size ; y++ ) |
---|
[407] | 770 | { |
---|
[564] | 771 | cxy_t cxy = HAL_CXY_FROM_XY( x , y ); |
---|
| 772 | |
---|
| 773 | if( cluster_is_active( cxy ) ) |
---|
| 774 | { |
---|
| 775 | hal_remote_s64( XPTR( cxy , ptr ) , id ); |
---|
[559] | 776 | } |
---|
[407] | 777 | } |
---|
| 778 | } |
---|
[188] | 779 | } |
---|
| 780 | } |
---|
| 781 | |
---|
[438] | 782 | #if( DEBUG_KERNEL_INIT & 0x1 ) |
---|
[601] | 783 | if( hal_time_stamp() > DEBUG_KERNEL_INIT ) |
---|
[407] | 784 | { |
---|
[601] | 785 | printk("\n[%s] created PIC chdev in cluster %x at cycle %d\n", |
---|
[407] | 786 | __FUNCTION__ , local_cxy , (uint32_t)hal_time_stamp() ); |
---|
| 787 | dev_pic_inputs_display(); |
---|
| 788 | } |
---|
[389] | 789 | #endif |
---|
[188] | 790 | |
---|
| 791 | } // end iopic_init() |
---|
| 792 | |
---|
[1] | 793 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[623] | 794 | // This function is called by all core[0]s in all cluster to complete the PIC device |
---|
[188] | 795 | // initialisation, namely the informations attached to the LAPIC controller. |
---|
| 796 | // This initialisation must be done after the IOPIC initialisation, but before other |
---|
| 797 | // devices initialisation because the IRQ routing infrastructure is required for both |
---|
| 798 | // internal and external devices initialisation. |
---|
| 799 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 800 | // @ info : pointer on the local boot-info structure. |
---|
| 801 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[564] | 802 | static void __attribute__ ((noinline)) lapic_init( boot_info_t * info ) |
---|
[188] | 803 | { |
---|
| 804 | boot_device_t * dev_tbl; // pointer on boot_info internal devices array |
---|
| 805 | uint32_t dev_nr; // number of internal devices |
---|
| 806 | uint32_t i; // device index in dev_tbl |
---|
| 807 | xptr_t base; // remote pointer on segment base |
---|
| 808 | uint32_t func; // device functionnal type in boot_info |
---|
| 809 | bool_t found; // LAPIC found |
---|
| 810 | |
---|
| 811 | // get number of internal peripherals and base |
---|
| 812 | dev_nr = info->int_dev_nr; |
---|
| 813 | dev_tbl = info->int_dev; |
---|
| 814 | |
---|
| 815 | // loop on internal peripherals to get the lapic device |
---|
| 816 | for( i = 0 , found = false ; i < dev_nr ; i++ ) |
---|
| 817 | { |
---|
| 818 | func = FUNC_FROM_TYPE( dev_tbl[i].type ); |
---|
| 819 | |
---|
| 820 | if( func == DEV_FUNC_ICU ) |
---|
| 821 | { |
---|
| 822 | base = dev_tbl[i].base; |
---|
| 823 | found = true; |
---|
| 824 | break; |
---|
| 825 | } |
---|
| 826 | } |
---|
| 827 | |
---|
| 828 | // if the LAPIC controller is not defined in the boot_info, |
---|
| 829 | // we simply don't initialize the PIC extensions in the kernel, |
---|
| 830 | // making the assumption that the LAPIC related informations |
---|
| 831 | // are hidden in the hardware specific PIC driver. |
---|
| 832 | if( found ) |
---|
| 833 | { |
---|
| 834 | // initialise the PIC extensions for |
---|
| 835 | // the core descriptor and core manager extensions |
---|
| 836 | dev_pic_extend_init( (uint32_t *)GET_PTR( base ) ); |
---|
| 837 | |
---|
| 838 | // initialize the "lapic_input" structure |
---|
| 839 | // defining how internal IRQs are connected to LAPIC |
---|
| 840 | uint32_t id; |
---|
| 841 | uint8_t valid; |
---|
| 842 | uint8_t channel; |
---|
| 843 | uint32_t func; |
---|
| 844 | |
---|
| 845 | for( id = 0 ; id < CONFIG_MAX_INTERNAL_IRQS ; id++ ) |
---|
| 846 | { |
---|
| 847 | valid = dev_tbl[i].irq[id].valid; |
---|
| 848 | func = FUNC_FROM_TYPE( dev_tbl[i].irq[id].dev_type ); |
---|
| 849 | channel = dev_tbl[i].irq[id].channel; |
---|
| 850 | |
---|
| 851 | if( valid ) // only valid local IRQs are registered |
---|
| 852 | { |
---|
| 853 | if ( func == DEV_FUNC_MMC ) lapic_input.mmc = id; |
---|
| 854 | else if( func == DEV_FUNC_DMA ) lapic_input.dma[channel] = id; |
---|
[580] | 855 | else |
---|
| 856 | { |
---|
| 857 | printk("\n[PANIC] in %s : illegal source device for LAPIC input\n", |
---|
| 858 | __FUNCTION__ ); |
---|
| 859 | hal_core_sleep(); |
---|
| 860 | } |
---|
[188] | 861 | } |
---|
| 862 | } |
---|
| 863 | } |
---|
| 864 | } // end lapic_init() |
---|
| 865 | |
---|
| 866 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[14] | 867 | // This static function returns the identifiers of the calling core. |
---|
| 868 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 869 | // @ info : pointer on boot_info structure. |
---|
| 870 | // @ lid : [out] core local index in cluster. |
---|
| 871 | // @ cxy : [out] cluster identifier. |
---|
| 872 | // @ lid : [out] core global identifier (hardware). |
---|
| 873 | // @ return 0 if success / return EINVAL if not found. |
---|
| 874 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[564] | 875 | static error_t __attribute__ ((noinline)) get_core_identifiers( boot_info_t * info, |
---|
| 876 | lid_t * lid, |
---|
| 877 | cxy_t * cxy, |
---|
| 878 | gid_t * gid ) |
---|
[14] | 879 | { |
---|
[127] | 880 | uint32_t i; |
---|
[14] | 881 | gid_t global_id; |
---|
[19] | 882 | |
---|
[14] | 883 | // get global identifier from hardware register |
---|
[127] | 884 | global_id = hal_get_gid(); |
---|
[14] | 885 | |
---|
| 886 | // makes an associative search in boot_info to get (cxy,lid) from global_id |
---|
| 887 | for( i = 0 ; i < info->cores_nr ; i++ ) |
---|
| 888 | { |
---|
| 889 | if( global_id == info->core[i].gid ) |
---|
| 890 | { |
---|
| 891 | *lid = info->core[i].lid; |
---|
| 892 | *cxy = info->core[i].cxy; |
---|
| 893 | *gid = global_id; |
---|
| 894 | return 0; |
---|
| 895 | } |
---|
| 896 | } |
---|
| 897 | return EINVAL; |
---|
[19] | 898 | } |
---|
[14] | 899 | |
---|
[626] | 900 | |
---|
| 901 | |
---|
| 902 | |
---|
| 903 | |
---|
| 904 | ///////////////////////////////// |
---|
| 905 | // kleenex debug function |
---|
| 906 | ///////////////////////////////// |
---|
| 907 | void display_fat( uint32_t step ) |
---|
| 908 | { |
---|
| 909 | fatfs_ctx_t * fatfs_ctx = fs_context[FS_TYPE_FATFS].extend; |
---|
| 910 | if( fatfs_ctx != NULL ) |
---|
| 911 | { |
---|
| 912 | printk("\n[%s] step %d at cycle %d\n", __FUNCTION__, step, (uint32_t)hal_get_cycles() ); |
---|
| 913 | xptr_t mapper_xp = fatfs_ctx->fat_mapper_xp; |
---|
| 914 | mapper_display_page( mapper_xp , 0 , 128 ); |
---|
| 915 | } |
---|
| 916 | else |
---|
| 917 | { |
---|
| 918 | printk("\n[%s] step %d : fatfs context not initialized\n", __FUNCTION__, step ); |
---|
| 919 | } |
---|
| 920 | } |
---|
| 921 | |
---|
| 922 | |
---|
| 923 | |
---|
| 924 | |
---|
| 925 | |
---|
[14] | 926 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[1] | 927 | // This function is the entry point for the kernel initialisation. |
---|
[623] | 928 | // It is executed by all cores in all clusters, but only core[0] initializes |
---|
| 929 | // the shared resources such as the cluster manager, or the local peripherals. |
---|
[19] | 930 | // To comply with the multi-kernels paradigm, it accesses only local cluster memory, using |
---|
| 931 | // only information contained in the local boot_info_t structure, set by the bootloader. |
---|
[623] | 932 | // Only core[0] in cluster 0 print the log messages. |
---|
[1] | 933 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 934 | // @ info : pointer on the local boot-info structure. |
---|
| 935 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 936 | void kernel_init( boot_info_t * info ) |
---|
| 937 | { |
---|
[204] | 938 | lid_t core_lid = -1; // running core local index |
---|
| 939 | cxy_t core_cxy = -1; // running core cluster identifier |
---|
| 940 | gid_t core_gid; // running core hardware identifier |
---|
| 941 | cluster_t * cluster; // pointer on local cluster manager |
---|
| 942 | core_t * core; // pointer on running core descriptor |
---|
| 943 | thread_t * thread; // pointer on idle thread descriptor |
---|
| 944 | |
---|
| 945 | xptr_t vfs_root_inode_xp; // extended pointer on VFS root inode |
---|
| 946 | xptr_t devfs_dev_inode_xp; // extended pointer on DEVFS dev inode |
---|
| 947 | xptr_t devfs_external_inode_xp; // extended pointer on DEVFS external inode |
---|
| 948 | xptr_t devfs_internal_inode_xp; // extended pointer on DEVFS internal inode |
---|
| 949 | |
---|
[1] | 950 | error_t error; |
---|
[285] | 951 | reg_t status; // running core status register |
---|
[1] | 952 | |
---|
[188] | 953 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[623] | 954 | // STEP 1 : Each core get its core identifier from boot_info, and makes |
---|
[188] | 955 | // a partial initialisation of its private idle thread descriptor. |
---|
[623] | 956 | // core[0] initializes the "local_cxy" global variable. |
---|
| 957 | // core[0] in cluster[0] initializes the TXT0 chdev for log messages. |
---|
[188] | 958 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 959 | |
---|
[23] | 960 | error = get_core_identifiers( info, |
---|
[14] | 961 | &core_lid, |
---|
| 962 | &core_cxy, |
---|
| 963 | &core_gid ); |
---|
[1] | 964 | |
---|
[623] | 965 | // core[0] initialize cluster identifier |
---|
[14] | 966 | if( core_lid == 0 ) local_cxy = info->cxy; |
---|
[1] | 967 | |
---|
[127] | 968 | // each core gets a pointer on its private idle thread descriptor |
---|
| 969 | thread = (thread_t *)( idle_threads + (core_lid * CONFIG_THREAD_DESC_SIZE) ); |
---|
[68] | 970 | |
---|
[127] | 971 | // each core registers this thread pointer in hardware register |
---|
[68] | 972 | hal_set_current_thread( thread ); |
---|
[71] | 973 | |
---|
[407] | 974 | // each core register core descriptor pointer in idle thread descriptor |
---|
| 975 | thread->core = &LOCAL_CLUSTER->core_tbl[core_lid]; |
---|
| 976 | |
---|
[564] | 977 | // each core initializes the idle thread locks counters |
---|
| 978 | thread->busylocks = 0; |
---|
[124] | 979 | |
---|
[564] | 980 | #if DEBUG_BUSYLOCK |
---|
| 981 | // each core initialise the idle thread list of busylocks |
---|
| 982 | xlist_root_init( XPTR( local_cxy , &thread->busylocks_root ) ); |
---|
| 983 | #endif |
---|
[14] | 984 | |
---|
[623] | 985 | // core[0] initializes cluster info |
---|
[564] | 986 | if( core_lid == 0 ) cluster_info_init( info ); |
---|
| 987 | |
---|
[623] | 988 | // core[0] in cluster[0] initialises TXT0 chdev descriptor |
---|
[564] | 989 | if( (core_lid == 0) && (core_cxy == 0) ) txt0_device_init( info ); |
---|
| 990 | |
---|
[623] | 991 | // all cores check identifiers |
---|
| 992 | if( error ) |
---|
| 993 | { |
---|
| 994 | printk("\n[PANIC] in %s : illegal core : gid %x / cxy %x / lid %d", |
---|
| 995 | __FUNCTION__, core_lid, core_cxy, core_lid ); |
---|
| 996 | hal_core_sleep(); |
---|
| 997 | } |
---|
| 998 | |
---|
[14] | 999 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[564] | 1000 | if( core_lid == 0 ) xbarrier_wait( XPTR( 0 , &global_barrier ), |
---|
| 1001 | (info->x_size * info->y_size) ); |
---|
[14] | 1002 | barrier_wait( &local_barrier , info->cores_nr ); |
---|
[437] | 1003 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[14] | 1004 | |
---|
[438] | 1005 | #if DEBUG_KERNEL_INIT |
---|
[583] | 1006 | if( (core_lid == 0) & (local_cxy == 0) ) |
---|
[624] | 1007 | printk("\n[%s] exit barrier 1 : TXT0 initialized / cycle %d\n", |
---|
[610] | 1008 | __FUNCTION__, (uint32_t)hal_get_cycles() ); |
---|
[437] | 1009 | #endif |
---|
[14] | 1010 | |
---|
[623] | 1011 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 1012 | // STEP 2 : core[0] initializes the cluter manager, |
---|
| 1013 | // including the physical memory allocator. |
---|
| 1014 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[188] | 1015 | |
---|
[623] | 1016 | // core[0] initialises DQDT (only core[0] in cluster 0 build the quad-tree) |
---|
[582] | 1017 | if( core_lid == 0 ) dqdt_init(); |
---|
| 1018 | |
---|
[623] | 1019 | // core[0] initialize other cluster manager complex structures |
---|
[14] | 1020 | if( core_lid == 0 ) |
---|
[1] | 1021 | { |
---|
[564] | 1022 | error = cluster_manager_init( info ); |
---|
[1] | 1023 | |
---|
[14] | 1024 | if( error ) |
---|
[580] | 1025 | { |
---|
| 1026 | printk("\n[PANIC] in %s : cannot initialize cluster manager in cluster %x\n", |
---|
| 1027 | __FUNCTION__, local_cxy ); |
---|
| 1028 | hal_core_sleep(); |
---|
| 1029 | } |
---|
[14] | 1030 | } |
---|
[5] | 1031 | |
---|
[14] | 1032 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[564] | 1033 | if( core_lid == 0 ) xbarrier_wait( XPTR( 0 , &global_barrier ), |
---|
| 1034 | (info->x_size * info->y_size) ); |
---|
[14] | 1035 | barrier_wait( &local_barrier , info->cores_nr ); |
---|
| 1036 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[1] | 1037 | |
---|
[438] | 1038 | #if DEBUG_KERNEL_INIT |
---|
| 1039 | if( (core_lid == 0) & (local_cxy == 0) ) |
---|
[624] | 1040 | printk("\n[%s] exit barrier 2 : cluster manager initialized / cycle %d\n", |
---|
[610] | 1041 | __FUNCTION__, (uint32_t)hal_get_cycles() ); |
---|
[437] | 1042 | #endif |
---|
[1] | 1043 | |
---|
[188] | 1044 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[624] | 1045 | // STEP 3 : all cores initialize the idle thread descriptor. |
---|
| 1046 | // core[0] initializes the process_zero descriptor, |
---|
[623] | 1047 | // including the kernel VMM (both GPT and VSL) |
---|
[188] | 1048 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 1049 | |
---|
| 1050 | // all cores get pointer on local cluster manager & core descriptor |
---|
[14] | 1051 | cluster = &cluster_manager; |
---|
[127] | 1052 | core = &cluster->core_tbl[core_lid]; |
---|
[1] | 1053 | |
---|
[624] | 1054 | // all cores update the register(s) defining the kernel |
---|
| 1055 | // entry points for interrupts, exceptions and syscalls, |
---|
| 1056 | // this must be done before VFS initialisation, because |
---|
| 1057 | // kernel_init() uses RPCs requiring IPIs... |
---|
| 1058 | hal_set_kentry(); |
---|
| 1059 | |
---|
| 1060 | // all cores initialize the idle thread descriptor |
---|
| 1061 | thread_idle_init( thread, |
---|
| 1062 | THREAD_IDLE, |
---|
| 1063 | &thread_idle_func, |
---|
| 1064 | NULL, |
---|
| 1065 | core_lid ); |
---|
| 1066 | |
---|
[623] | 1067 | // core[0] initializes the process_zero descriptor, |
---|
| 1068 | if( core_lid == 0 ) process_zero_create( &process_zero , info ); |
---|
[5] | 1069 | |
---|
[623] | 1070 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 1071 | if( core_lid == 0 ) xbarrier_wait( XPTR( 0 , &global_barrier ), |
---|
| 1072 | (info->x_size * info->y_size) ); |
---|
| 1073 | barrier_wait( &local_barrier , info->cores_nr ); |
---|
| 1074 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 1075 | |
---|
| 1076 | #if DEBUG_KERNEL_INIT |
---|
| 1077 | if( (core_lid == 0) & (local_cxy == 0) ) |
---|
[624] | 1078 | printk("\n[%s] exit barrier 3 : kernel processs initialized / cycle %d\n", |
---|
[623] | 1079 | __FUNCTION__, (uint32_t)hal_get_cycles() ); |
---|
| 1080 | #endif |
---|
| 1081 | |
---|
| 1082 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 1083 | // STEP 4 : all cores initialize their private MMU |
---|
| 1084 | // core[0] in cluster 0 initializes the IOPIC device. |
---|
| 1085 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 1086 | |
---|
| 1087 | // all cores initialise their MMU |
---|
| 1088 | hal_mmu_init( &process_zero.vmm.gpt ); |
---|
| 1089 | |
---|
| 1090 | // core[0] in cluster[0] initializes the PIC chdev, |
---|
[188] | 1091 | if( (core_lid == 0) && (local_cxy == 0) ) iopic_init( info ); |
---|
| 1092 | |
---|
| 1093 | //////////////////////////////////////////////////////////////////////////////// |
---|
[564] | 1094 | if( core_lid == 0 ) xbarrier_wait( XPTR( 0 , &global_barrier ), |
---|
| 1095 | (info->x_size * info->y_size) ); |
---|
[188] | 1096 | barrier_wait( &local_barrier , info->cores_nr ); |
---|
| 1097 | //////////////////////////////////////////////////////////////////////////////// |
---|
[127] | 1098 | |
---|
[438] | 1099 | #if DEBUG_KERNEL_INIT |
---|
| 1100 | if( (core_lid == 0) & (local_cxy == 0) ) |
---|
[624] | 1101 | printk("\n[%s] exit barrier 4 : MMU and IOPIC initialized / cycle %d\n", |
---|
[610] | 1102 | __FUNCTION__, (uint32_t)hal_get_cycles() ); |
---|
[437] | 1103 | #endif |
---|
[1] | 1104 | |
---|
[188] | 1105 | //////////////////////////////////////////////////////////////////////////////// |
---|
[623] | 1106 | // STEP 5 : core[0] initializes the distibuted LAPIC descriptor. |
---|
| 1107 | // core[0] initializes the internal chdev descriptors |
---|
| 1108 | // core[0] initialize the local external chdev descriptors |
---|
[188] | 1109 | //////////////////////////////////////////////////////////////////////////////// |
---|
[5] | 1110 | |
---|
[623] | 1111 | // all core[0]s initialize their local LAPIC extension, |
---|
[279] | 1112 | if( core_lid == 0 ) lapic_init( info ); |
---|
| 1113 | |
---|
[623] | 1114 | // core[0] scan the internal (private) peripherals, |
---|
[188] | 1115 | // and allocates memory for the corresponding chdev descriptors. |
---|
| 1116 | if( core_lid == 0 ) internal_devices_init( info ); |
---|
| 1117 | |
---|
[1] | 1118 | |
---|
[623] | 1119 | // All core[0]s contribute to initialise external peripheral chdev descriptors. |
---|
| 1120 | // Each core[0][cxy] scan the set of external (shared) peripherals (but the TXT0), |
---|
[14] | 1121 | // and allocates memory for the chdev descriptors that must be placed |
---|
[127] | 1122 | // on the (cxy) cluster according to the global index value. |
---|
[188] | 1123 | |
---|
[14] | 1124 | if( core_lid == 0 ) external_devices_init( info ); |
---|
[1] | 1125 | |
---|
[14] | 1126 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[564] | 1127 | if( core_lid == 0 ) xbarrier_wait( XPTR( 0 , &global_barrier ), |
---|
| 1128 | (info->x_size * info->y_size) ); |
---|
[14] | 1129 | barrier_wait( &local_barrier , info->cores_nr ); |
---|
| 1130 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[5] | 1131 | |
---|
[438] | 1132 | #if DEBUG_KERNEL_INIT |
---|
| 1133 | if( (core_lid == 0) & (local_cxy == 0) ) |
---|
[624] | 1134 | printk("\n[%s] exit barrier 5 : chdevs initialised / cycle %d\n", |
---|
[610] | 1135 | __FUNCTION__, (uint32_t)hal_get_cycles() ); |
---|
[437] | 1136 | #endif |
---|
[1] | 1137 | |
---|
[438] | 1138 | #if( DEBUG_KERNEL_INIT & 1 ) |
---|
[443] | 1139 | if( (core_lid == 0) & (local_cxy == 0) ) |
---|
[437] | 1140 | chdev_dir_display(); |
---|
| 1141 | #endif |
---|
| 1142 | |
---|
[188] | 1143 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[624] | 1144 | // STEP 6 : all cores enable IPI (Inter Procesor Interrupt), |
---|
| 1145 | // all cores unblock the idle thread, and register it in scheduler. |
---|
| 1146 | // core[0] in cluster[0] creates the VFS root inode. |
---|
[188] | 1147 | // It access the boot device to initialize the file system context. |
---|
| 1148 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 1149 | |
---|
[564] | 1150 | // All cores enable IPI |
---|
[279] | 1151 | dev_pic_enable_ipi(); |
---|
| 1152 | hal_enable_irq( &status ); |
---|
| 1153 | |
---|
[624] | 1154 | // all cores unblock the idle thread, and register it in scheduler |
---|
[296] | 1155 | thread_unblock( XPTR( local_cxy , thread ) , THREAD_BLOCKED_GLOBAL ); |
---|
[103] | 1156 | core->scheduler.idle = thread; |
---|
[1] | 1157 | |
---|
[623] | 1158 | // core[O] in cluster[0] creates the VFS root |
---|
[188] | 1159 | if( (core_lid == 0) && (local_cxy == 0 ) ) |
---|
[14] | 1160 | { |
---|
[188] | 1161 | vfs_root_inode_xp = XPTR_NULL; |
---|
[23] | 1162 | |
---|
[614] | 1163 | // Only FATFS is supported yet, |
---|
| 1164 | // other File System can be introduced here |
---|
[23] | 1165 | if( CONFIG_VFS_ROOT_IS_FATFS ) |
---|
| 1166 | { |
---|
[626] | 1167 | // 1. allocate memory for FATFS context in cluster 0 |
---|
[188] | 1168 | fatfs_ctx_t * fatfs_ctx = fatfs_ctx_alloc(); |
---|
| 1169 | |
---|
[564] | 1170 | if( fatfs_ctx == NULL ) |
---|
[580] | 1171 | { |
---|
| 1172 | printk("\n[PANIC] in %s : cannot create FATFS context in cluster 0\n", |
---|
| 1173 | __FUNCTION__ ); |
---|
| 1174 | hal_core_sleep(); |
---|
| 1175 | } |
---|
[188] | 1176 | |
---|
| 1177 | // 2. access boot device to initialize FATFS context |
---|
| 1178 | fatfs_ctx_init( fatfs_ctx ); |
---|
[626] | 1179 | |
---|
[188] | 1180 | // 3. get various informations from FATFS context |
---|
| 1181 | uint32_t root_dir_cluster = fatfs_ctx->root_dir_cluster; |
---|
| 1182 | uint32_t cluster_size = fatfs_ctx->bytes_per_sector * |
---|
| 1183 | fatfs_ctx->sectors_per_cluster; |
---|
| 1184 | uint32_t total_clusters = fatfs_ctx->fat_sectors_count << 7; |
---|
| 1185 | |
---|
[601] | 1186 | // 4. create VFS root inode in cluster 0 |
---|
[610] | 1187 | error = vfs_inode_create( FS_TYPE_FATFS, // fs_type |
---|
[188] | 1188 | 0, // attr |
---|
| 1189 | 0, // rights |
---|
| 1190 | 0, // uid |
---|
| 1191 | 0, // gid |
---|
| 1192 | &vfs_root_inode_xp ); // return |
---|
[564] | 1193 | if( error ) |
---|
[580] | 1194 | { |
---|
| 1195 | printk("\n[PANIC] in %s : cannot create VFS root inode in cluster 0\n", |
---|
| 1196 | __FUNCTION__ ); |
---|
| 1197 | hal_core_sleep(); |
---|
| 1198 | } |
---|
[188] | 1199 | |
---|
[623] | 1200 | // 5. update FATFS root inode "type" and "extend" fields |
---|
[601] | 1201 | cxy_t vfs_root_cxy = GET_CXY( vfs_root_inode_xp ); |
---|
| 1202 | vfs_inode_t * vfs_root_ptr = GET_PTR( vfs_root_inode_xp ); |
---|
[624] | 1203 | hal_remote_s32( XPTR( vfs_root_cxy , &vfs_root_ptr->type ), INODE_TYPE_DIR ); |
---|
[601] | 1204 | hal_remote_spt( XPTR( vfs_root_cxy , &vfs_root_ptr->extend ), |
---|
| 1205 | (void*)(intptr_t)root_dir_cluster ); |
---|
[188] | 1206 | |
---|
[601] | 1207 | // 6. initialize the generic VFS context for FATFS |
---|
| 1208 | vfs_ctx_init( FS_TYPE_FATFS, // fs type |
---|
| 1209 | 0, // attributes: unused |
---|
| 1210 | total_clusters, // number of clusters |
---|
| 1211 | cluster_size, // bytes |
---|
| 1212 | vfs_root_inode_xp, // VFS root |
---|
| 1213 | fatfs_ctx ); // extend |
---|
[23] | 1214 | } |
---|
| 1215 | else |
---|
| 1216 | { |
---|
[564] | 1217 | printk("\n[PANIC] in %s : unsupported VFS type in cluster 0\n", |
---|
| 1218 | __FUNCTION__ ); |
---|
[580] | 1219 | hal_core_sleep(); |
---|
[23] | 1220 | } |
---|
| 1221 | |
---|
[614] | 1222 | // create the <.> and <..> dentries in VFS root directory |
---|
| 1223 | // the VFS root parent inode is the VFS root inode itself |
---|
| 1224 | vfs_add_special_dentries( vfs_root_inode_xp, |
---|
| 1225 | vfs_root_inode_xp ); |
---|
| 1226 | |
---|
[389] | 1227 | // register VFS root inode in process_zero descriptor of cluster 0 |
---|
[188] | 1228 | process_zero.vfs_root_xp = vfs_root_inode_xp; |
---|
[610] | 1229 | process_zero.cwd_xp = vfs_root_inode_xp; |
---|
[188] | 1230 | } |
---|
| 1231 | |
---|
| 1232 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[564] | 1233 | if( core_lid == 0 ) xbarrier_wait( XPTR( 0 , &global_barrier ), |
---|
| 1234 | (info->x_size * info->y_size) ); |
---|
[188] | 1235 | barrier_wait( &local_barrier , info->cores_nr ); |
---|
| 1236 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 1237 | |
---|
[438] | 1238 | #if DEBUG_KERNEL_INIT |
---|
| 1239 | if( (core_lid == 0) & (local_cxy == 0) ) |
---|
[624] | 1240 | printk("\n[%s] exit barrier 6 : VFS root (%x,%x) in cluster 0 / cycle %d\n", |
---|
[610] | 1241 | __FUNCTION__, GET_CXY(process_zero.vfs_root_xp), |
---|
| 1242 | GET_PTR(process_zero.vfs_root_xp), (uint32_t)hal_get_cycles() ); |
---|
[437] | 1243 | #endif |
---|
[188] | 1244 | |
---|
| 1245 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[623] | 1246 | // STEP 7 : In all other clusters than cluster[0], the core[0] allocates memory |
---|
| 1247 | // for the selected FS context, and initialise the local FS context and |
---|
| 1248 | // the local VFS context from values stored in cluster 0. |
---|
[188] | 1249 | // They get the VFS root inode extended pointer from cluster 0. |
---|
| 1250 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 1251 | |
---|
| 1252 | if( (core_lid == 0) && (local_cxy != 0) ) |
---|
| 1253 | { |
---|
| 1254 | // File System must be FATFS in this implementation, |
---|
| 1255 | // but other File System can be introduced here |
---|
| 1256 | if( CONFIG_VFS_ROOT_IS_FATFS ) |
---|
[23] | 1257 | { |
---|
[389] | 1258 | // 1. allocate memory for local FATFS context |
---|
| 1259 | fatfs_ctx_t * local_fatfs_ctx = fatfs_ctx_alloc(); |
---|
[188] | 1260 | |
---|
[564] | 1261 | // check memory |
---|
| 1262 | if( local_fatfs_ctx == NULL ) |
---|
[580] | 1263 | { |
---|
| 1264 | printk("\n[PANIC] in %s : cannot create FATFS context in cluster %x\n", |
---|
| 1265 | __FUNCTION__ , local_cxy ); |
---|
| 1266 | hal_core_sleep(); |
---|
| 1267 | } |
---|
[188] | 1268 | |
---|
[389] | 1269 | // 2. get local pointer on VFS context for FATFS |
---|
[188] | 1270 | vfs_ctx_t * vfs_ctx = &fs_context[FS_TYPE_FATFS]; |
---|
| 1271 | |
---|
[389] | 1272 | // 3. get local pointer on FATFS context in cluster 0 |
---|
| 1273 | fatfs_ctx_t * remote_fatfs_ctx = hal_remote_lpt( XPTR( 0 , &vfs_ctx->extend ) ); |
---|
| 1274 | |
---|
| 1275 | // 4. copy FATFS context from cluster 0 to local cluster |
---|
| 1276 | hal_remote_memcpy( XPTR( local_cxy , local_fatfs_ctx ), |
---|
| 1277 | XPTR( 0 , remote_fatfs_ctx ), sizeof(fatfs_ctx_t) ); |
---|
| 1278 | |
---|
| 1279 | // 5. copy VFS context from cluster 0 to local cluster |
---|
[188] | 1280 | hal_remote_memcpy( XPTR( local_cxy , vfs_ctx ), |
---|
[389] | 1281 | XPTR( 0 , vfs_ctx ), sizeof(vfs_ctx_t) ); |
---|
[188] | 1282 | |
---|
[389] | 1283 | // 6. update extend field in local copy of VFS context |
---|
| 1284 | vfs_ctx->extend = local_fatfs_ctx; |
---|
[188] | 1285 | |
---|
[564] | 1286 | if( ((fatfs_ctx_t *)vfs_ctx->extend)->sectors_per_cluster != 8 ) |
---|
[580] | 1287 | { |
---|
| 1288 | printk("\n[PANIC] in %s : illegal FATFS context in cluster %x\n", |
---|
| 1289 | __FUNCTION__ , local_cxy ); |
---|
| 1290 | hal_core_sleep(); |
---|
| 1291 | } |
---|
[23] | 1292 | } |
---|
| 1293 | |
---|
[188] | 1294 | // get extended pointer on VFS root inode from cluster 0 |
---|
[564] | 1295 | vfs_root_inode_xp = hal_remote_l64( XPTR( 0 , &process_zero.vfs_root_xp ) ); |
---|
[101] | 1296 | |
---|
[188] | 1297 | // update local process_zero descriptor |
---|
| 1298 | process_zero.vfs_root_xp = vfs_root_inode_xp; |
---|
[610] | 1299 | process_zero.cwd_xp = vfs_root_inode_xp; |
---|
[14] | 1300 | } |
---|
| 1301 | |
---|
[188] | 1302 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[564] | 1303 | if( core_lid == 0 ) xbarrier_wait( XPTR( 0 , &global_barrier ), |
---|
| 1304 | (info->x_size * info->y_size) ); |
---|
[188] | 1305 | barrier_wait( &local_barrier , info->cores_nr ); |
---|
[204] | 1306 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[101] | 1307 | |
---|
[438] | 1308 | #if DEBUG_KERNEL_INIT |
---|
[564] | 1309 | if( (core_lid == 0) & (local_cxy == 1) ) |
---|
[624] | 1310 | printk("\n[%s] exit barrier 7 : VFS root (%x,%x) in cluster 1 / cycle %d\n", |
---|
[610] | 1311 | __FUNCTION__, GET_CXY(process_zero.vfs_root_xp), |
---|
| 1312 | GET_PTR(process_zero.vfs_root_xp), (uint32_t)hal_get_cycles() ); |
---|
[437] | 1313 | #endif |
---|
[188] | 1314 | |
---|
| 1315 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[623] | 1316 | // STEP 8 : core[0] in cluster 0 makes the global DEVFS initialisation: |
---|
[564] | 1317 | // It initializes the DEVFS context, and creates the DEVFS |
---|
| 1318 | // "dev" and "external" inodes in cluster 0. |
---|
[188] | 1319 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 1320 | |
---|
[564] | 1321 | if( (core_lid == 0) && (local_cxy == 0) ) |
---|
[1] | 1322 | { |
---|
[564] | 1323 | // 1. allocate memory for DEVFS context extension in cluster 0 |
---|
| 1324 | devfs_ctx_t * devfs_ctx = devfs_ctx_alloc(); |
---|
| 1325 | |
---|
| 1326 | if( devfs_ctx == NULL ) |
---|
[580] | 1327 | { |
---|
| 1328 | printk("\n[PANIC] in %s : cannot create DEVFS context in cluster 0\n", |
---|
| 1329 | __FUNCTION__ , local_cxy ); |
---|
| 1330 | hal_core_sleep(); |
---|
| 1331 | } |
---|
[564] | 1332 | |
---|
| 1333 | // 2. initialize the DEVFS entry in the vfs_context[] array |
---|
| 1334 | vfs_ctx_init( FS_TYPE_DEVFS, // fs type |
---|
| 1335 | 0, // attributes: unused |
---|
| 1336 | 0, // total_clusters: unused |
---|
| 1337 | 0, // cluster_size: unused |
---|
| 1338 | vfs_root_inode_xp, // VFS root |
---|
| 1339 | devfs_ctx ); // extend |
---|
| 1340 | |
---|
| 1341 | // 3. create "dev" and "external" inodes (directories) |
---|
[188] | 1342 | devfs_global_init( process_zero.vfs_root_xp, |
---|
[204] | 1343 | &devfs_dev_inode_xp, |
---|
[188] | 1344 | &devfs_external_inode_xp ); |
---|
| 1345 | |
---|
[564] | 1346 | // 4. initializes DEVFS context extension |
---|
| 1347 | devfs_ctx_init( devfs_ctx, |
---|
| 1348 | devfs_dev_inode_xp, |
---|
| 1349 | devfs_external_inode_xp ); |
---|
[188] | 1350 | } |
---|
| 1351 | |
---|
| 1352 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[564] | 1353 | if( core_lid == 0 ) xbarrier_wait( XPTR( 0 , &global_barrier ), |
---|
| 1354 | (info->x_size * info->y_size) ); |
---|
[188] | 1355 | barrier_wait( &local_barrier , info->cores_nr ); |
---|
[204] | 1356 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[188] | 1357 | |
---|
[438] | 1358 | #if DEBUG_KERNEL_INIT |
---|
| 1359 | if( (core_lid == 0) & (local_cxy == 0) ) |
---|
[624] | 1360 | printk("\n[%s] exit barrier 8 : DEVFS root initialized in cluster 0 / cycle %d\n", |
---|
[610] | 1361 | __FUNCTION__, (uint32_t)hal_get_cycles() ); |
---|
[437] | 1362 | #endif |
---|
[188] | 1363 | |
---|
| 1364 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[624] | 1365 | // STEP 9 : In all clusters in parallel, core[0] completes DEVFS initialization. |
---|
[623] | 1366 | // Each core[0] get the "dev" and "external" extended pointers from |
---|
[624] | 1367 | // values stored in cluster(0), creates the DEVFS "internal" directory, |
---|
| 1368 | // and creates the pseudo-files for all chdevs in local cluster. |
---|
[188] | 1369 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 1370 | |
---|
| 1371 | if( core_lid == 0 ) |
---|
| 1372 | { |
---|
[564] | 1373 | // get extended pointer on "extend" field of VFS context for DEVFS in cluster 0 |
---|
| 1374 | xptr_t extend_xp = XPTR( 0 , &fs_context[FS_TYPE_DEVFS].extend ); |
---|
[188] | 1375 | |
---|
[457] | 1376 | // get pointer on DEVFS context in cluster 0 |
---|
[188] | 1377 | devfs_ctx_t * devfs_ctx = hal_remote_lpt( extend_xp ); |
---|
| 1378 | |
---|
[564] | 1379 | devfs_dev_inode_xp = hal_remote_l64( XPTR( 0 , &devfs_ctx->dev_inode_xp ) ); |
---|
| 1380 | devfs_external_inode_xp = hal_remote_l64( XPTR( 0 , &devfs_ctx->external_inode_xp ) ); |
---|
[188] | 1381 | |
---|
[204] | 1382 | // populate DEVFS in all clusters |
---|
| 1383 | devfs_local_init( devfs_dev_inode_xp, |
---|
| 1384 | devfs_external_inode_xp, |
---|
| 1385 | &devfs_internal_inode_xp ); |
---|
[188] | 1386 | } |
---|
| 1387 | |
---|
| 1388 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[564] | 1389 | if( core_lid == 0 ) xbarrier_wait( XPTR( 0 , &global_barrier ), |
---|
| 1390 | (info->x_size * info->y_size) ); |
---|
[188] | 1391 | barrier_wait( &local_barrier , info->cores_nr ); |
---|
[204] | 1392 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[188] | 1393 | |
---|
[438] | 1394 | #if DEBUG_KERNEL_INIT |
---|
| 1395 | if( (core_lid == 0) & (local_cxy == 0) ) |
---|
[624] | 1396 | printk("\n[%s] exit barrier 9 : DEVFS initialized in cluster 0 / cycle %d\n", |
---|
[610] | 1397 | __FUNCTION__, (uint32_t)hal_get_cycles() ); |
---|
[437] | 1398 | #endif |
---|
[188] | 1399 | |
---|
[623] | 1400 | #if( DEBUG_KERNEL_INIT & 1 ) |
---|
| 1401 | if( (core_lid == 0) & (local_cxy == 0) ) |
---|
| 1402 | vfs_display( vfs_root_inode_xp ); |
---|
| 1403 | #endif |
---|
| 1404 | |
---|
[188] | 1405 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[623] | 1406 | // STEP 10 : core[0] in cluster 0 creates the first user process (process_init). |
---|
| 1407 | // This include the first user process VMM (GPT and VSL) creation. |
---|
| 1408 | // Finally, it prints the ALMOS-MKH banner. |
---|
[188] | 1409 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 1410 | |
---|
[457] | 1411 | if( (core_lid == 0) && (local_cxy == 0) ) |
---|
[188] | 1412 | { |
---|
[428] | 1413 | process_init_create(); |
---|
[188] | 1414 | } |
---|
[101] | 1415 | |
---|
[624] | 1416 | #if DEBUG_KERNEL_INIT |
---|
| 1417 | if( (core_lid == 0) & (local_cxy == 0) ) |
---|
| 1418 | printk("\n[%s] exit barrier 10 : process_init created in cluster 0 / cycle %d\n", |
---|
| 1419 | __FUNCTION__, (uint32_t)hal_get_cycles() ); |
---|
| 1420 | #endif |
---|
| 1421 | |
---|
[443] | 1422 | #if (DEBUG_KERNEL_INIT & 1) |
---|
[564] | 1423 | if( (core_lid == 0) & (local_cxy == 0) ) |
---|
[443] | 1424 | sched_display( 0 ); |
---|
| 1425 | #endif |
---|
| 1426 | |
---|
[564] | 1427 | if( (core_lid == 0) && (local_cxy == 0) ) |
---|
[188] | 1428 | { |
---|
[5] | 1429 | print_banner( (info->x_size * info->y_size) , info->cores_nr ); |
---|
[623] | 1430 | } |
---|
[68] | 1431 | |
---|
[438] | 1432 | #if( DEBUG_KERNEL_INIT & 1 ) |
---|
[623] | 1433 | if( (core_lid == 0) & (local_cxy == 0) ) |
---|
[437] | 1434 | printk("\n\n***** memory fooprint for main kernel objects\n\n" |
---|
[68] | 1435 | " - thread descriptor : %d bytes\n" |
---|
| 1436 | " - process descriptor : %d bytes\n" |
---|
| 1437 | " - cluster manager : %d bytes\n" |
---|
| 1438 | " - chdev descriptor : %d bytes\n" |
---|
| 1439 | " - core descriptor : %d bytes\n" |
---|
| 1440 | " - scheduler : %d bytes\n" |
---|
| 1441 | " - rpc fifo : %d bytes\n" |
---|
| 1442 | " - page descriptor : %d bytes\n" |
---|
| 1443 | " - mapper root : %d bytes\n" |
---|
| 1444 | " - ppm manager : %d bytes\n" |
---|
| 1445 | " - kcm manager : %d bytes\n" |
---|
| 1446 | " - khm manager : %d bytes\n" |
---|
| 1447 | " - vmm manager : %d bytes\n" |
---|
| 1448 | " - gpt root : %d bytes\n" |
---|
| 1449 | " - list item : %d bytes\n" |
---|
| 1450 | " - xlist item : %d bytes\n" |
---|
[564] | 1451 | " - busylock : %d bytes\n" |
---|
| 1452 | " - remote busylock : %d bytes\n" |
---|
| 1453 | " - queuelock : %d bytes\n" |
---|
| 1454 | " - remote queuelock : %d bytes\n" |
---|
[68] | 1455 | " - rwlock : %d bytes\n" |
---|
| 1456 | " - remote rwlock : %d bytes\n", |
---|
[564] | 1457 | sizeof( thread_t ), |
---|
| 1458 | sizeof( process_t ), |
---|
| 1459 | sizeof( cluster_t ), |
---|
| 1460 | sizeof( chdev_t ), |
---|
| 1461 | sizeof( core_t ), |
---|
| 1462 | sizeof( scheduler_t ), |
---|
| 1463 | sizeof( remote_fifo_t ), |
---|
| 1464 | sizeof( page_t ), |
---|
| 1465 | sizeof( mapper_t ), |
---|
| 1466 | sizeof( ppm_t ), |
---|
| 1467 | sizeof( kcm_t ), |
---|
| 1468 | sizeof( khm_t ), |
---|
| 1469 | sizeof( vmm_t ), |
---|
| 1470 | sizeof( gpt_t ), |
---|
| 1471 | sizeof( list_entry_t ), |
---|
| 1472 | sizeof( xlist_entry_t ), |
---|
| 1473 | sizeof( busylock_t ), |
---|
| 1474 | sizeof( remote_busylock_t ), |
---|
| 1475 | sizeof( queuelock_t ), |
---|
| 1476 | sizeof( remote_queuelock_t ), |
---|
| 1477 | sizeof( rwlock_t ), |
---|
| 1478 | sizeof( remote_rwlock_t )); |
---|
[406] | 1479 | #endif |
---|
| 1480 | |
---|
[398] | 1481 | // each core activates its private TICK IRQ |
---|
| 1482 | dev_pic_enable_timer( CONFIG_SCHED_TICK_MS_PERIOD ); |
---|
[14] | 1483 | |
---|
[610] | 1484 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 1485 | if( core_lid == 0 ) xbarrier_wait( XPTR( 0 , &global_barrier ), |
---|
| 1486 | (info->x_size * info->y_size) ); |
---|
| 1487 | barrier_wait( &local_barrier , info->cores_nr ); |
---|
| 1488 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 1489 | |
---|
[623] | 1490 | #if( DEBUG_KERNEL_INIT & 1 ) |
---|
[610] | 1491 | thread_t * this = CURRENT_THREAD; |
---|
| 1492 | printk("\n[%s] : thread[%x,%x] on core[%x,%d] jumps to thread_idle_func() / cycle %d\n", |
---|
| 1493 | __FUNCTION__ , this->process->pid, this->trdid, |
---|
| 1494 | local_cxy, core_lid, (uint32_t)hal_get_cycles() ); |
---|
[440] | 1495 | #endif |
---|
| 1496 | |
---|
[407] | 1497 | // each core jump to thread_idle_func |
---|
[50] | 1498 | thread_idle_func(); |
---|
[14] | 1499 | |
---|
[610] | 1500 | } // end kernel_init() |
---|
| 1501 | |
---|