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