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