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