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