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