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