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

Last change on this file since 448 was 443, checked in by alain, 6 years ago

Fix few bugs whike debugging the sort multi-thread application.

File size: 53.8 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///////////////////////////////////////////////////////////////////////////////////////////
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 Version 0.0 / %d cluster(s) / %d core(s) per cluster / cycle %d\n\n",
189           nclusters , ncores , hal_time_stamp() );
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    cxy_t        io_cxy = info->io_cxy;
764
765    assert( (io_cxy == ((info->x_size - 1)<<(info->y_width)) + (info->y_size - 1)) ,
766    __FUNCTION__ , "illegal IO cluter identifier\n" );
767
768    /////////////////////////////////////////////////////////////////////////////////
769    // STEP 0 : Each core get its core identifier from boot_info, and makes
770    //          a partial initialisation of its private idle thread descriptor.
771    //          CP0 initializes the "local_cxy" global variable.
772    //          CP0 in cluster IO initializes the TXT0 chdev to print log messages.
773    /////////////////////////////////////////////////////////////////////////////////
774
775    error = get_core_identifiers( info,
776                                  &core_lid,
777                                  &core_cxy,
778                                  &core_gid );
779
780    // CP0 initializes cluster identifier
781    if( core_lid == 0 ) local_cxy = info->cxy;
782
783    // each core gets a pointer on its private idle thread descriptor
784    thread = (thread_t *)( idle_threads + (core_lid * CONFIG_THREAD_DESC_SIZE) );
785
786    // each core registers this thread pointer in hardware register
787    hal_set_current_thread( thread );
788
789    // each core register core descriptor pointer in idle thread descriptor
790    thread->core = &LOCAL_CLUSTER->core_tbl[core_lid];
791
792    // each core initializes the idle thread lists of locks
793    list_root_init( &thread->locks_root );
794    xlist_root_init( XPTR( local_cxy , &thread->xlocks_root ) );
795    thread->local_locks = 0;
796    thread->remote_locks = 0;
797
798    // CP0 in I/O cluster initialises TXT0 chdev descriptor
799    if( (core_lid == 0) && (core_cxy == io_cxy) ) txt0_device_init( info );
800
801    /////////////////////////////////////////////////////////////////////////////////
802    if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ), 
803                                        (info->x_size * info->y_size) );
804    barrier_wait( &local_barrier , info->cores_nr );
805    /////////////////////////////////////////////////////////////////////////////////
806
807#if DEBUG_KERNEL_INIT
808if( (core_lid ==  0) & (local_cxy == 0) ) 
809printk("\n[DBG] %s : exit barrier 0 : TXT0 initialized / cycle %d\n",
810__FUNCTION__, (uint32_t)hal_get_cycles() );
811#endif
812
813    /////////////////////////////////////////////////////////////////////////////
814    // STEP 1 : all cores check core identifier.
815    //          CP0 initializes the local cluster manager.
816    //          This includes the memory allocators.
817    /////////////////////////////////////////////////////////////////////////////
818
819    // all cores check identifiers
820    if( error )
821    {
822        assert( false , __FUNCTION__ ,
823        "illegal core identifiers gid = %x / cxy = %x / lid = %d",
824        core_lid , core_cxy , core_lid );
825    }
826
827    // CP0 initializes cluster manager
828    if( core_lid == 0 )
829    {
830        error = cluster_init( info );
831
832        if( error )
833        {
834            assert( false , __FUNCTION__ ,
835            "cannot initialise cluster %x", local_cxy );
836        }
837    }
838
839    /////////////////////////////////////////////////////////////////////////////////
840    if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ), 
841                                        (info->x_size * info->y_size) );
842    barrier_wait( &local_barrier , info->cores_nr );
843    /////////////////////////////////////////////////////////////////////////////////
844
845#if DEBUG_KERNEL_INIT
846if( (core_lid ==  0) & (local_cxy == 0) ) 
847printk("\n[DBG] %s : exit barrier 1 : clusters initialised / cycle %d\n",
848__FUNCTION__, (uint32_t)hal_get_cycles() );
849#endif
850
851    /////////////////////////////////////////////////////////////////////////////////
852    // STEP 2 : CP0 initializes the process_zero descriptor.
853    //          CP0 in cluster 0 initializes the IOPIC device.
854    /////////////////////////////////////////////////////////////////////////////////
855
856    // all cores get pointer on local cluster manager & core descriptor
857    cluster = &cluster_manager;
858    core    = &cluster->core_tbl[core_lid];
859
860    // all CP0s initialize the process_zero descriptor
861    if( core_lid == 0 ) process_zero_create( &process_zero );
862
863    // CP0 in cluster 0 initializes the PIC chdev,
864    if( (core_lid == 0) && (local_cxy == 0) ) iopic_init( info );
865   
866    ////////////////////////////////////////////////////////////////////////////////
867    if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ), 
868                                        (info->x_size * info->y_size) );
869    barrier_wait( &local_barrier , info->cores_nr );
870    ////////////////////////////////////////////////////////////////////////////////
871
872#if DEBUG_KERNEL_INIT
873if( (core_lid ==  0) & (local_cxy == 0) ) 
874printk("\n[DBG] %s : exit barrier 2 : PIC initialised / cycle %d\n",
875__FUNCTION__, (uint32_t)hal_get_cycles() );
876#endif
877
878    ////////////////////////////////////////////////////////////////////////////////
879    // STEP 3 : CP0 initializes the distibuted LAPIC descriptor.
880    //          CP0 initializes the internal chdev descriptors
881    //          CP0 initialize the local external chdev descriptors
882    ////////////////////////////////////////////////////////////////////////////////
883
884    // all CP0s initialize their local LAPIC extension,
885    if( core_lid == 0 ) lapic_init( info );
886
887    // CP0 scan the internal (private) peripherals,
888    // and allocates memory for the corresponding chdev descriptors.
889    if( core_lid == 0 ) internal_devices_init( info );
890       
891
892    // All CP0s contribute to initialise external peripheral chdev descriptors.
893    // Each CP0[cxy] scan the set of external (shared) peripherals (but the TXT0),
894    // and allocates memory for the chdev descriptors that must be placed
895    // on the (cxy) cluster according to the global index value.
896
897    if( core_lid == 0 ) external_devices_init( info );
898
899    /////////////////////////////////////////////////////////////////////////////////
900    if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ), 
901                                        (info->x_size * info->y_size) );
902    barrier_wait( &local_barrier , info->cores_nr );
903    /////////////////////////////////////////////////////////////////////////////////
904
905#if DEBUG_KERNEL_INIT
906if( (core_lid ==  0) & (local_cxy == 0) ) 
907printk("\n[DBG] %s : exit barrier 3 : all chdev initialised / cycle %d\n",
908__FUNCTION__, (uint32_t)hal_get_cycles() );
909#endif
910
911#if( DEBUG_KERNEL_INIT & 1 )
912if( (core_lid ==  0) & (local_cxy == 0) ) 
913chdev_dir_display();
914#endif
915   
916    /////////////////////////////////////////////////////////////////////////////////
917    // STEP 4 : All cores enable IPI (Inter Procesor Interrupt),
918    //          Alh cores initialize IDLE thread.
919    //          Only CP0 in cluster 0 creates the VFS root inode.
920    //          It access the boot device to initialize the file system context.
921    /////////////////////////////////////////////////////////////////////////////////
922
923    // All cores enable the shared IPI channel
924    dev_pic_enable_ipi();
925    hal_enable_irq( &status );
926
927    // all cores initialize the idle thread descriptor
928    error = thread_idle_init( thread,
929                              THREAD_IDLE,
930                              &thread_idle_func,
931                              NULL,
932                              core_lid );
933    if( error )
934    {
935        assert( false , __FUNCTION__ ,
936        "core[%x][%d] cannot initialize idle thread", local_cxy , core_lid );
937    }
938
939    // all cores unblock idle thread, and register it in scheduler
940    thread_unblock( XPTR( local_cxy , thread ) , THREAD_BLOCKED_GLOBAL );
941    core->scheduler.idle = thread;
942
943#if( DEBUG_KERNEL_INIT & 1 )
944sched_display( core_lid );
945#endif
946
947    // CPO in cluster 0 creates the VFS root
948    if( (core_lid ==  0) && (local_cxy == 0 ) ) 
949    {
950        vfs_root_inode_xp = XPTR_NULL;
951
952        // File System must be FATFS in this implementation,
953        // but other File System can be introduced here
954        if( CONFIG_VFS_ROOT_IS_FATFS )
955        {
956            // 1. allocate memory for FATFS context in cluster 0
957            fatfs_ctx_t * fatfs_ctx = fatfs_ctx_alloc();
958
959            assert( (fatfs_ctx != NULL) , __FUNCTION__ ,
960                    "cannot create FATFS context in cluster 0\n" );
961
962            // 2. access boot device to initialize FATFS context
963            fatfs_ctx_init( fatfs_ctx );
964 
965            // 3. get various informations from FATFS context
966            uint32_t root_dir_cluster = fatfs_ctx->root_dir_cluster;
967            uint32_t cluster_size     = fatfs_ctx->bytes_per_sector * 
968                                        fatfs_ctx->sectors_per_cluster;
969            uint32_t total_clusters   = fatfs_ctx->fat_sectors_count << 7;
970 
971            // 4. create VFS root inode in cluster 0
972            error = vfs_inode_create( XPTR_NULL,                           // dentry_xp
973                                      FS_TYPE_FATFS,                       // fs_type
974                                      INODE_TYPE_DIR,                      // inode_type
975                                      (void *)(intptr_t)root_dir_cluster,  // extend
976                                      0,                                   // attr
977                                      0,                                   // rights
978                                      0,                                   // uid
979                                      0,                                   // gid
980                                      &vfs_root_inode_xp );                // return
981
982            assert( (error == 0) , __FUNCTION__ , 
983                    "cannot create VFS root inode\n" );
984
985            // 5. initialize VFS context for FAT in cluster 0
986            vfs_ctx_init( FS_TYPE_FATFS,                 // file system type
987                          0,                             // attributes
988                              total_clusters,               
989                              cluster_size,
990                              vfs_root_inode_xp,             // VFS root
991                          fatfs_ctx );                   // extend
992
993            // 6. check initialisation
994            vfs_ctx_t   * vfs_ctx = &fs_context[FS_TYPE_FATFS];
995            assert( (((fatfs_ctx_t *)vfs_ctx->extend)->sectors_per_cluster == 8),
996            __FUNCTION__ , "illegal value for FATFS context in cluster %x\n", local_cxy );
997        }
998        else
999        {
1000            assert( false , __FUNCTION__ ,
1001            "root FS must be FATFS" );
1002        }
1003
1004        // register VFS root inode in process_zero descriptor of cluster 0
1005        process_zero.vfs_root_xp = vfs_root_inode_xp;
1006        process_zero.vfs_cwd_xp  = vfs_root_inode_xp;
1007    }
1008
1009    /////////////////////////////////////////////////////////////////////////////////
1010    if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ), 
1011                                        (info->x_size * info->y_size) );
1012    barrier_wait( &local_barrier , info->cores_nr );
1013    /////////////////////////////////////////////////////////////////////////////////
1014
1015#if DEBUG_KERNEL_INIT
1016if( (core_lid ==  0) & (local_cxy == 0) ) 
1017printk("\n[DBG] %s : exit barrier 4 : VFS_root = %l in cluster 0 / cycle %d\n",
1018__FUNCTION__, vfs_root_inode_xp , (uint32_t)hal_get_cycles());
1019#endif
1020
1021    /////////////////////////////////////////////////////////////////////////////////
1022    // STEP 5 : Other CP0s allocate memory for the selected FS context,
1023    //          and initialise both the local FS context and the local VFS context
1024    //          from values stored in cluster 0.
1025    //          They get the VFS root inode extended pointer from cluster 0.
1026    /////////////////////////////////////////////////////////////////////////////////
1027
1028    if( (core_lid ==  0) && (local_cxy != 0) ) 
1029    {
1030        // File System must be FATFS in this implementation,
1031        // but other File System can be introduced here
1032        if( CONFIG_VFS_ROOT_IS_FATFS )
1033        {
1034            // 1. allocate memory for local FATFS context
1035            fatfs_ctx_t * local_fatfs_ctx = fatfs_ctx_alloc();
1036
1037            assert( (local_fatfs_ctx != NULL) , __FUNCTION__ ,
1038            "cannot create FATFS context in cluster %x\n", local_cxy );
1039
1040            // 2. get local pointer on VFS context for FATFS
1041            vfs_ctx_t   * vfs_ctx = &fs_context[FS_TYPE_FATFS];
1042
1043            // 3. get local pointer on FATFS context in cluster 0
1044            fatfs_ctx_t * remote_fatfs_ctx = hal_remote_lpt( XPTR( 0 , &vfs_ctx->extend ) );
1045
1046            // 4. copy FATFS context from cluster 0 to local cluster
1047            hal_remote_memcpy( XPTR( local_cxy , local_fatfs_ctx ), 
1048                               XPTR( 0 ,         remote_fatfs_ctx ), sizeof(fatfs_ctx_t) );
1049
1050            // 5. copy VFS context from cluster 0 to local cluster
1051            hal_remote_memcpy( XPTR( local_cxy , vfs_ctx ), 
1052                               XPTR( 0 ,         vfs_ctx ), sizeof(vfs_ctx_t) );
1053
1054            // 6. update extend field in local copy of VFS context
1055            vfs_ctx->extend = local_fatfs_ctx;
1056
1057            // 7. check initialisation
1058            assert( (((fatfs_ctx_t *)vfs_ctx->extend)->sectors_per_cluster == 8),
1059            __FUNCTION__ , "illegal value for FATFS context in cluster %x\n", local_cxy );
1060        }
1061
1062        // get extended pointer on VFS root inode from cluster 0
1063        vfs_root_inode_xp = hal_remote_lwd( XPTR( 0 , &process_zero.vfs_root_xp ) );
1064
1065        // update local process_zero descriptor
1066        process_zero.vfs_root_xp = vfs_root_inode_xp;
1067        process_zero.vfs_cwd_xp  = vfs_root_inode_xp;
1068    }
1069
1070    /////////////////////////////////////////////////////////////////////////////////
1071    if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ), 
1072                                        (info->x_size * info->y_size) );
1073    barrier_wait( &local_barrier , info->cores_nr );
1074    /////////////////////////////////////////////////////////////////////////////////
1075
1076#if DEBUG_KERNEL_INIT
1077if( (core_lid ==  0) & (local_cxy == 0) ) 
1078printk("\n[DBG] %s : exit barrier 5 : VFS_root = %l in cluster %x / cycle %d\n",
1079__FUNCTION__, vfs_root_inode_xp , io_cxy , (uint32_t)hal_get_cycles());
1080#endif
1081
1082    /////////////////////////////////////////////////////////////////////////////////
1083    // STEP 6 : CP0 in cluster IO makes the global DEVFS tree initialisation:
1084    //          It creates the DEVFS directory "dev", and the DEVFS "external"
1085    //          directory in cluster IO and mount these inodes into VFS.
1086    /////////////////////////////////////////////////////////////////////////////////
1087
1088    if( (core_lid ==  0) && (local_cxy == io_cxy) ) 
1089    {
1090        // create "dev" and "external" directories.
1091        devfs_global_init( process_zero.vfs_root_xp,
1092                           &devfs_dev_inode_xp,
1093                           &devfs_external_inode_xp );
1094
1095        // creates the DEVFS context in cluster IO
1096        devfs_ctx_t * devfs_ctx = devfs_ctx_alloc();
1097
1098        assert( (devfs_ctx != NULL) , __FUNCTION__ ,
1099                "cannot create DEVFS context in cluster IO\n");
1100
1101        // register DEVFS root and external directories
1102        devfs_ctx_init( devfs_ctx, devfs_dev_inode_xp, devfs_external_inode_xp );
1103    }   
1104
1105    /////////////////////////////////////////////////////////////////////////////////
1106    if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ), 
1107                                        (info->x_size * info->y_size) );
1108    barrier_wait( &local_barrier , info->cores_nr );
1109    /////////////////////////////////////////////////////////////////////////////////
1110
1111#if DEBUG_KERNEL_INIT
1112if( (core_lid ==  0) & (local_cxy == 0) ) 
1113printk("\n[DBG] %s : exit barrier 6 : dev_root = %l in cluster %x / cycle %d\n",
1114__FUNCTION__, devfs_dev_inode_xp , io_cxy , (uint32_t)hal_get_cycles() );
1115#endif
1116
1117    /////////////////////////////////////////////////////////////////////////////////
1118    // STEP 7 : All CP0s complete in parallel the DEVFS tree initialization.
1119    //          Each CP0 get the "dev" and "external" extended pointers from
1120    //          values stored in cluster IO.
1121    //          Then each CP0 in cluster(i) creates the DEVFS "internal directory,
1122    //          and creates the pseudo-files for all chdevs in cluster (i).
1123    /////////////////////////////////////////////////////////////////////////////////
1124
1125    if( core_lid == 0 )
1126    {
1127        // get extended pointer on "extend" field of VFS context for DEVFS in cluster IO
1128        xptr_t  extend_xp = XPTR( io_cxy , &fs_context[FS_TYPE_DEVFS].extend );
1129
1130        // get pointer on DEVFS context in cluster IO
1131        devfs_ctx_t * devfs_ctx = hal_remote_lpt( extend_xp );
1132       
1133        devfs_dev_inode_xp      = hal_remote_lwd( XPTR( io_cxy ,
1134                                                        &devfs_ctx->dev_inode_xp ) );
1135        devfs_external_inode_xp = hal_remote_lwd( XPTR( io_cxy , 
1136                                                        &devfs_ctx->external_inode_xp ) );
1137
1138        // populate DEVFS in all clusters
1139        devfs_local_init( devfs_dev_inode_xp,
1140                          devfs_external_inode_xp,
1141                          &devfs_internal_inode_xp );
1142    }
1143
1144    /////////////////////////////////////////////////////////////////////////////////
1145    if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ), 
1146                                        (info->x_size * info->y_size) );
1147    barrier_wait( &local_barrier , info->cores_nr );
1148    /////////////////////////////////////////////////////////////////////////////////
1149
1150#if DEBUG_KERNEL_INIT
1151if( (core_lid ==  0) & (local_cxy == 0) ) 
1152printk("\n[DBG] %s : exit barrier 7 : dev_root = %l in cluster 0 / cycle %d\n",
1153__FUNCTION__, devfs_dev_inode_xp , (uint32_t)hal_get_cycles() );
1154#endif
1155
1156    /////////////////////////////////////////////////////////////////////////////////
1157    // STEP 8 : CP0 in cluster 0 creates the first user process (process_init)
1158    /////////////////////////////////////////////////////////////////////////////////
1159
1160    if( (core_lid ==  0) && (local_cxy == 0) ) 
1161    {
1162
1163#if( DEBUG_KERNEL_INIT & 1 )
1164vfs_display( vfs_root_inode_xp );
1165#endif
1166
1167       process_init_create();
1168    }
1169
1170    /////////////////////////////////////////////////////////////////////////////////
1171    if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ),
1172                                        (info->x_size * info->y_size) );
1173    barrier_wait( &local_barrier , info->cores_nr );
1174    /////////////////////////////////////////////////////////////////////////////////
1175
1176#if DEBUG_KERNEL_INIT
1177if( (core_lid ==  0) & (local_cxy == 0) ) 
1178printk("\n[DBG] %s : exit barrier 8 : process init created / cycle %d\n", 
1179__FUNCTION__ , (uint32_t)hal_get_cycles() );
1180#endif
1181
1182#if (DEBUG_KERNEL_INIT & 1)
1183if( (core_lid ==  0) & (local_cxy == 0) ) 
1184sched_display( 0 );
1185#endif
1186
1187    /////////////////////////////////////////////////////////////////////////////////
1188    // STEP 9 : CP0 in cluster 0 print banner
1189    /////////////////////////////////////////////////////////////////////////////////
1190   
1191    if( (core_lid ==  0) && (local_cxy == io_cxy) ) 
1192    {
1193        print_banner( (info->x_size * info->y_size) , info->cores_nr );
1194
1195#if( DEBUG_KERNEL_INIT & 1 )
1196printk("\n\n***** memory fooprint for main kernel objects\n\n"
1197                   " - thread descriptor  : %d bytes\n"
1198                   " - process descriptor : %d bytes\n"
1199                   " - cluster manager    : %d bytes\n"
1200                   " - chdev descriptor   : %d bytes\n"
1201                   " - core descriptor    : %d bytes\n"
1202                   " - scheduler          : %d bytes\n"
1203                   " - rpc fifo           : %d bytes\n"
1204                   " - page descriptor    : %d bytes\n"
1205                   " - mapper root        : %d bytes\n"
1206                   " - ppm manager        : %d bytes\n"
1207                   " - kcm manager        : %d bytes\n"
1208                   " - khm manager        : %d bytes\n"
1209                   " - vmm manager        : %d bytes\n"
1210                   " - gpt root           : %d bytes\n"
1211                   " - list item          : %d bytes\n"
1212                   " - xlist item         : %d bytes\n"
1213                   " - spinlock           : %d bytes\n"
1214                   " - remote spinlock    : %d bytes\n"
1215                   " - rwlock             : %d bytes\n"
1216                   " - remote rwlock      : %d bytes\n",
1217                   sizeof( thread_t          ),
1218                   sizeof( process_t         ),
1219                   sizeof( cluster_t         ),
1220                   sizeof( chdev_t           ),
1221                   sizeof( core_t            ),
1222                   sizeof( scheduler_t       ),
1223                   sizeof( remote_fifo_t     ),
1224                   sizeof( page_t            ),
1225                   sizeof( mapper_t          ),
1226                   sizeof( ppm_t             ),
1227                   sizeof( kcm_t             ),
1228                   sizeof( khm_t             ),
1229                   sizeof( vmm_t             ),
1230                   sizeof( gpt_t             ),
1231                   sizeof( list_entry_t      ),
1232                   sizeof( xlist_entry_t     ),
1233                   sizeof( spinlock_t        ),
1234                   sizeof( remote_spinlock_t ),
1235                   sizeof( rwlock_t          ),
1236                   sizeof( remote_rwlock_t   ));
1237#endif
1238
1239    }
1240
1241    // each core activates its private TICK IRQ
1242    dev_pic_enable_timer( CONFIG_SCHED_TICK_MS_PERIOD );
1243
1244#if DEBUG_KERNEL_INIT
1245printk("\n[DBG] %s : thread %x on core[%x,%d] jumps to thread_idle_func() / cycle %d\n",
1246__FUNCTION__ , CURRENT_THREAD , local_cxy , core_lid , (uint32_t)hal_get_cycles() );
1247#endif
1248
1249    // each core jump to thread_idle_func
1250    thread_idle_func();
1251}
1252
Note: See TracBrowser for help on using the repository browser.