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