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

Last change on this file since 406 was 406, checked in by alain, 7 years ago

This version executed successfully the user "init" process on a mono-processor TSAR architecture.

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