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