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