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