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