source: trunk/kernel/kern/kernel_init.c@ 437

Last change on this file since 437 was 437, checked in by alain, 9 years ago

Fix various bugs

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