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