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

Last change on this file since 457 was 457, checked in by alain, 8 years ago

This version modifies the exec syscall and fixes a large number of small bugs.
The version number has been updated (0.1)

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