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