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