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

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

Introduce the delayed context switch if current thread has a lock.

File size: 50.4 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")))
80char                  idle_threads[CONFIG_THREAD_DESC_SIZE *
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"
[279]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
[337]275            kinit_dmsg("\n[INFO] %s : created MMC in cluster %x / chdev = %x\n",
[279]276                       __FUNCTION__ , channel , local_cxy , chdev_ptr );
[14]277        }
[188]278        ///////////////////////////////
279        else if( func == DEV_FUNC_DMA )
[127]280        {
[188]281            // create one chdev per channel in local cluster
282            for( channel = 0 ; channel < channels ; channel++ )
283            {   
284                // create chdev[channel] in local cluster
285                chdev_ptr = chdev_create( func,
286                                          impl,
287                                          channel,
288                                          false,     // direction
289                                          base );
[5]290
[188]291                assert( (chdev_ptr != NULL) , __FUNCTION__ , 
292                        "cannot allocate memory for DMA chdev" );
293           
294                // make DMA specific initialisation
295                dev_dma_init( chdev_ptr );     
[127]296
[188]297                // initialize only the DMA[channel] field in the local chdev_dir[x][y]
298                // structure because the DMA device is not remotely accessible.
299                chdev_dir.dma[channel] = XPTR( local_cxy , chdev_ptr );
[5]300
[337]301                kinit_dmsg("\n[INFO] %s : created DMA[%d] in cluster %x / chdev = %x\n",
[279]302                           __FUNCTION__ , channel , local_cxy , chdev_ptr );
[188]303            }
[14]304        }
[127]305    }
[5]306}  // end internal_devices_init()
307
308///////////////////////////////////////////////////////////////////////////////////////////
[188]309// This function allocates memory and initializes the chdev descriptors for the 
310// external (shared) peripherals other than the IOPIC, as specified by the boot_info,
[5]311// including the dynamic linking with the driver for the specified implementation.
[188]312// These chdev descriptors are distributed on all clusters, using a modulo on a global
313// index, identically computed in all clusters: In each cluster, the local CP0 core
314// computes the global index for all external chdevs, and creates only the chdevs that
315// must be placed in the local cluster.
316// The relevant entries in all copies of the devices directory are initialised.
[5]317///////////////////////////////////////////////////////////////////////////////////////////
318// @ info    : pointer on the local boot-info structure.
319///////////////////////////////////////////////////////////////////////////////////////////
320static void external_devices_init( boot_info_t * info )
321{
[188]322    boot_device_t * dev_tbl;         // pointer on array of external devices in boot_info
323        uint32_t        dev_nr;          // actual number of external devices
324        xptr_t          base;            // remote pointer on segment base
[5]325    uint32_t        func;            // device functionnal index
326    uint32_t        impl;            // device implementation index
[188]327        uint32_t        i;               // device index in dev_tbl
328        uint32_t        x;               // X cluster coordinate
329        uint32_t        y;               // Y cluster coordinate
330        uint32_t        channels;        // number of channels
331        uint32_t        channel;         // channel index
332        uint32_t        directions;      // number of directions (1 or 2)
333        uint32_t        rx;              // direction index (0 or 1)
334    uint32_t        first_channel;   // used in loop on channels for TXT
[127]335    chdev_t       * chdev;           // local pointer on one channel_device descriptor
[188]336    uint32_t        ext_chdev_gid;   // global index of external chdev
[5]337
338    // get number of peripherals and base of devices array from boot_info
[127]339    dev_nr      = info->ext_dev_nr;
[5]340    dev_tbl     = info->ext_dev;
341
[188]342    // initializes global index (PIC is already placed in cluster 0
343    ext_chdev_gid = 1;
344
[5]345    // loop on external peripherals
[127]346    for( i = 0 ; i < dev_nr ; i++ )
347    {
[188]348        base     = dev_tbl[i].base;
349        channels = dev_tbl[i].channels;
350        func     = FUNC_FROM_TYPE( dev_tbl[i].type );
351        impl     = IMPL_FROM_TYPE( dev_tbl[i].type );
[5]352
353        // There is one chdev per direction for NIC
[188]354        if (func == DEV_FUNC_NIC) directions = 2;
355        else                      directions = 1;
[5]356
357        // The TXT0 chdev has already been created
358        if (func == DEV_FUNC_TXT) first_channel = 1;
359        else                      first_channel = 0;
360
[188]361        // do nothing for RO, that does not require a device descriptor.
[5]362        if( func == DEV_FUNC_ROM ) continue;
363
[188]364        // do nothing for PIC, that is already initialized
365        if( func == DEV_FUNC_PIC ) continue;
[5]366
[188]367        // check PIC device initialized
368        assert( (chdev_dir.pic != XPTR_NULL ) , __FUNCTION__ ,
369              "PIC device must be initialized before other devices\n" );
370
371        // check external device functionnal type
372        assert( ( (func == DEV_FUNC_IOB) ||
373                  (func == DEV_FUNC_IOC) ||
374                  (func == DEV_FUNC_TXT) ||
375                  (func == DEV_FUNC_NIC) ||
376                  (func == DEV_FUNC_FBF) ) , __FUNCTION__ ,
377                  "undefined external peripheral type\n" );
378
[127]379        // loops on channels
[188]380        for( channel = first_channel ; channel < channels ; channel++ )
[127]381        {
[5]382            // loop on directions
[188]383            for( rx = 0 ; rx < directions ; rx++ )
[1]384            {
[188]385                // compute target cluster for chdev[func,channel,direction]
386                uint32_t offset     = ext_chdev_gid % ( info->x_size * info->y_size );
[5]387                uint32_t cx         = offset / info->y_size;
388                uint32_t cy         = offset % info->y_size;
389                uint32_t target_cxy = (cx<<info->y_width) + cy;
[1]390
[5]391                // allocate and initialize a local chdev
392                // if local cluster matches target cluster
393                if( target_cxy == local_cxy )
[1]394                {
[5]395                    chdev = chdev_create( func,
396                                          impl,
397                                          channel,
[188]398                                          rx,          // direction
[5]399                                          base );
400
[127]401                    assert( (chdev != NULL), __FUNCTION__ ,
[5]402                            "cannot allocate external device" );
403
404                    // make device type specific initialisation
405                    if     ( func == DEV_FUNC_IOB ) dev_iob_init( chdev );
406                    else if( func == DEV_FUNC_IOC ) dev_ioc_init( chdev );
407                    else if( func == DEV_FUNC_TXT ) dev_txt_init( chdev );
408                    else if( func == DEV_FUNC_NIC ) dev_nic_init( chdev );
[188]409                    else if( func == DEV_FUNC_FBF ) dev_fbf_init( chdev );
[5]410
[127]411                    // all external (shared) devices are remotely accessible
[5]412                    // initialize the replicated chdev_dir[x][y] structures
[127]413                    // defining the extended pointers on chdev descriptors
414                    xptr_t * entry;
415
[188]416                    if(func==DEV_FUNC_IOB             ) entry  = &chdev_dir.iob;
417                    if(func==DEV_FUNC_IOC             ) entry  = &chdev_dir.ioc[channel];
418                    if(func==DEV_FUNC_TXT             ) entry  = &chdev_dir.txt[channel];
419                    if(func==DEV_FUNC_FBF             ) entry  = &chdev_dir.fbf[channel];
420                    if((func==DEV_FUNC_NIC) && (rx==0)) entry  = &chdev_dir.nic_tx[channel];
421                    if((func==DEV_FUNC_NIC) && (rx==1)) entry  = &chdev_dir.nic_rx[channel];
[127]422
[1]423                    for( x = 0 ; x < info->x_size ; x++ )
424                    {
425                        for( y = 0 ; y < info->y_size ; y++ )
426                        {
427                            cxy_t  cxy = (x<<info->y_width) + y;
[188]428                            hal_remote_swd( XPTR( cxy , entry ),
429                                            XPTR( local_cxy , chdev ) );
[5]430                        }
[1]431                    }
432
[337]433                            kinit_dmsg("\n[INFO] %s : create chdev %s[%d] in cluster %x / chdev = %x\n",
[279]434                    __FUNCTION__ , chdev_func_str( func ), channel , local_cxy , chdev );
[5]435
436                }  // end if match
437
[19]438                // increment chdev global index (matching or not)
[188]439                ext_chdev_gid++;
[5]440
441            } // end loop on directions
442        }  // end loop on channels
[188]443        } // end loop on devices
444}  // end external_devices_init()
[5]445
[188]446///////////////////////////////////////////////////////////////////////////////////////////
447// This function is called by CP0 in cluster 0 to allocate memory and initialize the PIC
448// device, namely the informations attached to the external IOPIC controller.
449// This initialisation must be done before other devices initialisation because the IRQ
450// routing infrastructure is required for internal and external devices initialisation.
451///////////////////////////////////////////////////////////////////////////////////////////
452// @ info    : pointer on the local boot-info structure.
453///////////////////////////////////////////////////////////////////////////////////////////
454static void iopic_init( boot_info_t * info )
455{
456    boot_device_t * dev_tbl;         // pointer on boot_info external devices array
457        uint32_t        dev_nr;          // actual number of external devices
458        xptr_t          base;            // remote pointer on segment base
459    uint32_t        func;            // device functionnal index
460    uint32_t        impl;            // device implementation index
461        uint32_t        i;               // device index in dev_tbl
462    uint32_t        x;               // cluster X coordinate
463    uint32_t        y;               // cluster Y coordinate
464    bool_t          found;           // IOPIC found
465        chdev_t       * chdev;           // pointer on PIC chdev descriptor
466
467    // get number of external peripherals and base of array from boot_info
468        dev_nr      = info->ext_dev_nr;
469    dev_tbl     = info->ext_dev;
470
471    // loop on external peripherals to get the IOPIC 
472        for( i = 0 , found = false ; i < dev_nr ; i++ )
473        {
474        func = FUNC_FROM_TYPE( dev_tbl[i].type );
475
[127]476        if( func == DEV_FUNC_PIC )
[1]477        {
[188]478            base     = dev_tbl[i].base;
479            impl     = IMPL_FROM_TYPE( dev_tbl[i].type );
480            found    = true;
481            break;
482        }
483    }
[5]484
[188]485    assert( found , __FUNCTION__ , "PIC device not found\n" );
[1]486
[188]487    // allocate and initialize the PIC chdev in local cluster
488    chdev = chdev_create( func,
489                          impl,
490                          0,      // channel
491                          0,      // direction,
492                          base );
[5]493
[188]494    assert( (chdev != NULL), __FUNCTION__ , "no memory for PIC chdev\n" );
[5]495
[188]496    // make PIC device type specific initialisation
497    dev_pic_init( chdev );
[1]498
[188]499    // register extended pointer on PIC chdev in "chdev_dir" array in all clusters
500    xptr_t * entry = &chdev_dir.pic;   
501               
502    for( x = 0 ; x < info->x_size ; x++ )
503    {
504        for( y = 0 ; y < info->y_size ; y++ )
505        {
506            cxy_t  cxy = (x<<info->y_width) + y;
507            hal_remote_swd( XPTR( cxy , entry ) , 
508                            XPTR( local_cxy , chdev ) );
509        }
510    }
[1]511
[188]512    // initialize the "iopic_input" structure
513    // defining how external IRQs are connected to IOPIC
514    uint32_t   id;
515    uint8_t    valid;
516    uint32_t   type;
517    uint8_t    channel;
518    uint8_t    is_rx;
519
520    for( id = 0 ; id < CONFIG_MAX_EXTERNAL_IRQS ; id++ )
521    {
522        valid   = dev_tbl[i].irq[id].valid;
523        type    = dev_tbl[i].irq[id].dev_type;
524        channel = dev_tbl[i].irq[id].channel;
525        is_rx   = dev_tbl[i].irq[id].is_rx;
526
527        if( valid )  // only valid inputs are registered
528        {
529            uint32_t * index;  // local pointer on one entry
530            uint16_t func = FUNC_FROM_TYPE( type );
531
532            if     ( func == DEV_FUNC_TXT ) 
533            index = &iopic_input.txt[channel];
534            else if( func == DEV_FUNC_IOC ) 
535            index = &iopic_input.ioc[channel]; 
536            else if( (func == DEV_FUNC_NIC) && (is_rx == 0) )
537            index = &iopic_input.nic_tx[channel]; 
538            else if( (func == DEV_FUNC_NIC) && (is_rx != 0) )
539            index = &iopic_input.nic_rx[channel]; 
540            else if( func == DEV_FUNC_IOB )
541            index = &iopic_input.iob; 
542            else
543            assert( false , __FUNCTION__ , "illegal source device for IOPIC input" );
544
545            // set entry in local structure
546            *index = id; 
547        }
548    } 
549
[204]550    kinit_dmsg("\n[INFO] %s created PIC chdev in cluster %x at cycle %d\n",
[188]551               __FUNCTION__ , local_cxy , (uint32_t)hal_time_stamp() );
552   
553}  // end iopic_init()
554
[1]555///////////////////////////////////////////////////////////////////////////////////////////
[188]556// This function is called by all CP0s in all cluster to complete the PIC device
557// initialisation, namely the informations attached to the LAPIC controller.
558// This initialisation must be done after the IOPIC initialisation, but before other
559// devices initialisation because the IRQ routing infrastructure is required for both
560// internal and external devices initialisation.
561///////////////////////////////////////////////////////////////////////////////////////////
562// @ info    : pointer on the local boot-info structure.
563///////////////////////////////////////////////////////////////////////////////////////////
564static void lapic_init( boot_info_t * info )
565{
566    boot_device_t * dev_tbl;      // pointer on boot_info internal devices array
567    uint32_t        dev_nr;       // number of internal devices
568    uint32_t        i;            // device index in dev_tbl
569        xptr_t          base;         // remote pointer on segment base
570    uint32_t        func;         // device functionnal type in boot_info
571    bool_t          found;        // LAPIC found
572
573    // get number of internal peripherals and base
574        dev_nr      = info->int_dev_nr;
575    dev_tbl     = info->int_dev;
576
577    // loop on internal peripherals to get the lapic device
578        for( i = 0 , found = false ; i < dev_nr ; i++ )
579        {
580        func = FUNC_FROM_TYPE( dev_tbl[i].type );
581
582        if( func == DEV_FUNC_ICU )
583        {
584            base     = dev_tbl[i].base;
585            found    = true;
586            break;
587        }
588    }
589
590    // if the LAPIC controller is not defined in the boot_info,
591    // we simply don't initialize the PIC extensions in the kernel,
592    // making the assumption that the LAPIC related informations
593    // are hidden in the hardware specific PIC driver.
594    if( found )
595    {
596        // initialise the PIC extensions for
597        // the core descriptor and core manager extensions
598        dev_pic_extend_init( (uint32_t *)GET_PTR( base ) );
599
600        // initialize the "lapic_input" structure
601        // defining how internal IRQs are connected to LAPIC
602        uint32_t        id;
603        uint8_t         valid;
604        uint8_t         channel;
605        uint32_t        func;
606
607        for( id = 0 ; id < CONFIG_MAX_INTERNAL_IRQS ; id++ )
608        {
609            valid    = dev_tbl[i].irq[id].valid;
610            func     = FUNC_FROM_TYPE( dev_tbl[i].irq[id].dev_type );
611            channel  = dev_tbl[i].irq[id].channel;
612
613            if( valid ) // only valid local IRQs are registered
614            {
615                if     ( func == DEV_FUNC_MMC ) lapic_input.mmc = id;
616                else if( func == DEV_FUNC_DMA ) lapic_input.dma[channel] = id;
617                else assert( false , __FUNCTION__ , "illegal source device for LAPIC input" );
618            }
619        }
620    }
621}  // end lapic_init()
622
623///////////////////////////////////////////////////////////////////////////////////////////
[14]624// This static function returns the identifiers of the calling core.
625///////////////////////////////////////////////////////////////////////////////////////////
626// @ info    : pointer on boot_info structure.
627// @ lid     : [out] core local index in cluster.
628// @ cxy     : [out] cluster identifier.
629// @ lid     : [out] core global identifier (hardware).
630// @ return 0 if success / return EINVAL if not found.
631///////////////////////////////////////////////////////////////////////////////////////////
[23]632static error_t get_core_identifiers( boot_info_t * info,
633                                     lid_t       * lid,
[14]634                                     cxy_t       * cxy,
635                                     gid_t       * gid )
636{
[127]637    uint32_t   i;
[14]638    gid_t      global_id;
[19]639
[14]640    // get global identifier from hardware register
[127]641    global_id = hal_get_gid();
[14]642
643    // makes an associative search in boot_info to get (cxy,lid) from global_id
644    for( i = 0 ; i < info->cores_nr ; i++ )
645    {
646        if( global_id == info->core[i].gid )
647        {
648            *lid = info->core[i].lid;
649            *cxy = info->core[i].cxy;
650            *gid = global_id;
651            return 0;
652        }
653    }
654    return EINVAL;
[19]655}
[14]656
657///////////////////////////////////////////////////////////////////////////////////////////
[1]658// This function is the entry point for the kernel initialisation.
[19]659// It is executed by all cores in all clusters, but only core[0], called CP0,
[14]660// initializes the shared resources such as the cluster manager, or the local peripherals.
[19]661// To comply with the multi-kernels paradigm, it accesses only local cluster memory, using
662// only information contained in the local boot_info_t structure, set by the bootloader.
[103]663// Only CP0 in cluster 0 print the log messages.
[1]664///////////////////////////////////////////////////////////////////////////////////////////
665// @ info    : pointer on the local boot-info structure.
666///////////////////////////////////////////////////////////////////////////////////////////
667void kernel_init( boot_info_t * info )
668{
[204]669    lid_t        core_lid = -1;             // running core local index
670    cxy_t        core_cxy = -1;             // running core cluster identifier
671    gid_t        core_gid;                  // running core hardware identifier
672    cluster_t  * cluster;                   // pointer on local cluster manager
673    core_t     * core;                      // pointer on running core descriptor
674    thread_t   * thread;                    // pointer on idle thread descriptor
675
676    xptr_t       vfs_root_inode_xp;         // extended pointer on VFS root inode
677    xptr_t       devfs_dev_inode_xp;        // extended pointer on DEVFS dev inode   
678    xptr_t       devfs_external_inode_xp;   // extended pointer on DEVFS external inode       
679    xptr_t       devfs_internal_inode_xp;   // extended pointer on DEVFS internal inode       
680
[1]681    error_t      error;
[285]682    reg_t        status;                    // running core status register
[1]683
[188]684    cxy_t        io_cxy = info->io_cxy;
685
686    /////////////////////////////////////////////////////////////////////////////////
687    // STEP 0 : Each core get its core identifier from boot_info, and makes
688    //          a partial initialisation of its private idle thread descriptor.
689    //          CP0 initializes the "local_cxy" global variable.
690    //          CP0 in cluster IO initializes the TXT0 chdev to print log messages.
691    /////////////////////////////////////////////////////////////////////////////////
692
[23]693    error = get_core_identifiers( info,
[14]694                                  &core_lid,
695                                  &core_cxy,
696                                  &core_gid );
[1]697
[127]698    // CP0 initializes cluster identifier
[14]699    if( core_lid == 0 ) local_cxy = info->cxy;
[1]700
[127]701    // each core gets a pointer on its private idle thread descriptor
702    thread = (thread_t *)( idle_threads + (core_lid * CONFIG_THREAD_DESC_SIZE) );
[68]703
[127]704    // each core registers this thread pointer in hardware register
[68]705    hal_set_current_thread( thread );
[71]706
[188]707    // each core initializes the idle thread "locks_root" and "xlocks_root" fields
[124]708    list_root_init( &thread->locks_root );
[188]709    xlist_root_init( XPTR( local_cxy , &thread->xlocks_root ) );
[124]710
[188]711    // CP0 in I/O cluster initialises TXT0 chdev descriptor
712    if( (core_lid == 0) && (core_cxy == io_cxy) ) txt0_device_init( info );
[14]713
714    /////////////////////////////////////////////////////////////////////////////////
[188]715    if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ), 
[14]716                                        (info->x_size * info->y_size) );
717    barrier_wait( &local_barrier , info->cores_nr );
718
[188]719    if( (core_lid ==  0) && (local_cxy == 0) ) 
[296]720    kinit_dmsg("\n[INFO] %s : exit barrier 0 : TXT0 initialized / cycle %d\n",
721    __FUNCTION__, hal_time_stamp() );
[14]722
[188]723    /////////////////////////////////////////////////////////////////////////////
724    // STEP 1 : all cores check its core identifier.
725    //          CP0 initializes the local cluster manager.
726    //          This includes the memory allocators.
727    /////////////////////////////////////////////////////////////////////////////
728
729    // all cores check identifiers
[14]730    if( error )
[1]731    {
[279]732        printk("\n[PANIC] in %s : illegal core identifiers"
[14]733               " gid = %x / cxy = %x / lid = %d\n",
734               __FUNCTION__ , core_lid , core_cxy , core_lid );
735        hal_core_sleep();
[1]736    }
737
[188]738    // CP0 initializes cluster manager
[14]739    if( core_lid == 0 )
[1]740    {
741        error = cluster_init( info );
742
[14]743        if( error )
744        {
[279]745            printk("\n[PANIC] in %s : cannot initialise cluster %x",
[14]746                   __FUNCTION__ , local_cxy );
747            hal_core_sleep();
748        }
749    }
[5]750
[14]751    /////////////////////////////////////////////////////////////////////////////////
[188]752    if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ), 
[14]753                                        (info->x_size * info->y_size) );
754    barrier_wait( &local_barrier , info->cores_nr );
755    /////////////////////////////////////////////////////////////////////////////////
[1]756
[188]757    if( (core_lid ==  0) && (local_cxy == 0) ) 
[296]758    kinit_dmsg("\n[INFO] %s : exit barrier 1 : clusters initialised / cycle %d\n",
759    __FUNCTION__, hal_time_stamp() );
[1]760
[188]761    /////////////////////////////////////////////////////////////////////////////////
762    // STEP 2 : all CP0s initialize the process_zero descriptor.
[296]763    //          CP0 in cluster 0 initializes the IOPIC device.
[188]764    /////////////////////////////////////////////////////////////////////////////////
765
766    // all cores get pointer on local cluster manager & core descriptor
[14]767    cluster = &cluster_manager;
[127]768    core    = &cluster->core_tbl[core_lid];
[1]769
[188]770    // all CP0s initialize the process_zero descriptor
[101]771    if( core_lid == 0 ) process_reference_init( &process_zero , 0 , XPTR_NULL );
[5]772
[188]773    // CP0 in cluster 0 initializes the PIC chdev,
774    if( (core_lid == 0) && (local_cxy == 0) ) iopic_init( info );
775   
776    ////////////////////////////////////////////////////////////////////////////////
777    if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ), 
778                                        (info->x_size * info->y_size) );
779    barrier_wait( &local_barrier , info->cores_nr );
780    ////////////////////////////////////////////////////////////////////////////////
[127]781
[188]782    if( (core_lid ==  0) && (local_cxy == 0) ) 
[296]783    kinit_dmsg("\n[INFO] %s : exit barrier 2 : PIC initialised / cycle %d\n",
784    __FUNCTION__, hal_time_stamp() );
[1]785
[188]786    ////////////////////////////////////////////////////////////////////////////////
[296]787    // STEP 3 : all CP0s initialize the distibuted LAPIC descriptor.
788    //          all CP0s initialize the internal chdev descriptors
789    //          all CP0s initialize the local external chdev descriptors
[188]790    ////////////////////////////////////////////////////////////////////////////////
[5]791
[279]792    // all CP0s initialize their local LAPIC extension,
793    if( core_lid == 0 ) lapic_init( info );
794
[188]795    // CP0 scan the internal (private) peripherals,
796    // and allocates memory for the corresponding chdev descriptors.
797    if( core_lid == 0 ) internal_devices_init( info );
798       
[1]799
[50]800    // All CP0s contribute to initialise external peripheral chdev descriptors.
[14]801    // Each CP0[cxy] scan the set of external (shared) peripherals (but the TXT0),
802    // and allocates memory for the chdev descriptors that must be placed
[127]803    // on the (cxy) cluster according to the global index value.
[188]804
[14]805    if( core_lid == 0 ) external_devices_init( info );
[1]806
[14]807    /////////////////////////////////////////////////////////////////////////////////
[188]808    if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ), 
[14]809                                        (info->x_size * info->y_size) );
810    barrier_wait( &local_barrier , info->cores_nr );
811    /////////////////////////////////////////////////////////////////////////////////
[5]812
[188]813    if( (core_lid ==  0) && (local_cxy == 0) ) 
[296]814    kinit_dmsg("\n[INFO] %s : exit barrier 3 : all chdev initialised / cycle %d\n",
815               __FUNCTION__, hal_time_stamp());
[1]816
[188]817    /////////////////////////////////////////////////////////////////////////////////
[279]818    // STEP 4 : All cores enable IPI (Inter Procesor Interrupt),
[296]819    //          All cores initialise specific core registers
[279]820    //          Alh cores initialize IDLE thread.
[188]821    //          Only CP0 in cluster 0 creates the VFS root inode.
822    //          It access the boot device to initialize the file system context.
823    /////////////////////////////////////////////////////////////////////////////////
824
[279]825    if( CONFIG_KINIT_DEBUG ) chdev_dir_display();
826   
827    // All cores enable the shared IPI channel
828    dev_pic_enable_ipi();
829    hal_enable_irq( &status );
830
[296]831    // All cores initialize specific core registers
832    hal_core_init( info );
833
[279]834    kinit_dmsg("\n[INFO] %s : IRQs enabled for core[%x,%d] / SR = %x\n", 
835               __FUNCTION__ , local_cxy , core_lid , hal_get_sr() );
836
[296]837    // all cores initialize the idle thread descriptor
[14]838    error = thread_kernel_init( thread,
[127]839                                THREAD_IDLE,
840                                &thread_idle_func,
[14]841                                NULL,
842                                core_lid );
843    if( error )
[1]844    {
[279]845        printk("\n[PANIC] in %s : core[%x][%d] cannot initialize idle thread\n",
[103]846                      __FUNCTION__ , local_cxy , core_lid );
[14]847        hal_core_sleep();
[1]848    }
849
[296]850    // all cores unblock idle thread, and register it in scheduler
851    thread_unblock( XPTR( local_cxy , thread ) , THREAD_BLOCKED_GLOBAL );
[103]852    core->scheduler.idle = thread;
[1]853
[188]854    if( (core_lid ==  0) && (local_cxy == 0) ) 
[103]855    {
[296]856        kinit_dmsg("\n[INFO] %s : initialized idle thread %x on core[%x,%d] / cycle %d\n",
857        __FUNCTION__ , thread->trdid , local_cxy, core_lid, (uint32_t)hal_time_stamp());
[14]858    }
859
[296]860    #if CONFIG_KINIT_DEBUG
861    sched_display();
862    #endif
863
[188]864    // CPO in cluster 0 creates the VFS root
865    if( (core_lid ==  0) && (local_cxy == 0 ) ) 
[14]866    {
[188]867        vfs_root_inode_xp = XPTR_NULL;
[23]868
[188]869        // File System must be FATFS in this implementation,
870        // but other File System can be introduced here
[23]871        if( CONFIG_VFS_ROOT_IS_FATFS )
872        {
[188]873            // 1. create FATFS context in cluster 0
874            fatfs_ctx_t * fatfs_ctx = fatfs_ctx_alloc();
875
[279]876            assert( (fatfs_ctx != NULL) , __FUNCTION__ ,
877                    "cannot create FATFS context in cluster 0\n" );
[188]878
879            // 2. access boot device to initialize FATFS context
880            fatfs_ctx_init( fatfs_ctx );
881 
882            // 3. get various informations from FATFS context
883            uint32_t root_dir_cluster = fatfs_ctx->root_dir_cluster;
884            uint32_t cluster_size     = fatfs_ctx->bytes_per_sector * 
885                                        fatfs_ctx->sectors_per_cluster;
886            uint32_t total_clusters   = fatfs_ctx->fat_sectors_count << 7;
887 
888            // 4. create VFS root inode in cluster 0
889            error = vfs_inode_create( XPTR_NULL,                           // dentry_xp
890                                      FS_TYPE_FATFS,                       // fs_type
891                                      INODE_TYPE_DIR,                      // inode_type
892                                      (void *)(intptr_t)root_dir_cluster,  // extend
893                                      0,                                   // attr
894                                      0,                                   // rights
895                                      0,                                   // uid
896                                      0,                                   // gid
897                                      &vfs_root_inode_xp );                // return
898
[279]899            assert( (error == 0) , __FUNCTION__ , 
900                    "cannot create VFS root inode\n" );
[188]901
902            // 5. initialize VFS context for FAT in cluster 0
903            vfs_ctx_init( FS_TYPE_FATFS,                 // file system type
904                          0,                             // attributes
905                              total_clusters,               
906                              cluster_size,
907                              vfs_root_inode_xp,             // VFS root
908                          fatfs_ctx );                   // extend
[23]909        }
910        else
911        {
[279]912            printk("\n[PANIC] in %s : root FS must be FATFS\n", __FUNCTION__ );
[23]913            hal_core_sleep();
914        }
915
[188]916        // register VFS root inode in process_zero
917        process_zero.vfs_root_xp = vfs_root_inode_xp;
918        process_zero.vfs_cwd_xp  = vfs_root_inode_xp;
919    }
920
921    /////////////////////////////////////////////////////////////////////////////////
922    if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ), 
923                                        (info->x_size * info->y_size) );
924    barrier_wait( &local_barrier , info->cores_nr );
925    /////////////////////////////////////////////////////////////////////////////////
926
927    if( (core_lid ==  0) && (local_cxy == 0) ) 
[296]928    kinit_dmsg("\n[INFO] %s : exit barrier 4 : VFS_root = %l in cluster 0 / cycle %d\n",
929               __FUNCTION__, vfs_root_inode_xp , hal_time_stamp());
[188]930
931    /////////////////////////////////////////////////////////////////////////////////
932    // STEP 5 : Other CP0s allocate memory for the selected FS context,
933    //          and initialise both the local FS context and the local VFS context
934    //          from values stored in cluster 0.
935    //          They get the VFS root inode extended pointer from cluster 0.
936    /////////////////////////////////////////////////////////////////////////////////
937
938    if( (core_lid ==  0) && (local_cxy != 0) ) 
939    {
940        // File System must be FATFS in this implementation,
941        // but other File System can be introduced here
942        if( CONFIG_VFS_ROOT_IS_FATFS )
[23]943        {
[188]944            // allocate memory for FATFS context
945            fatfs_ctx_t * fatfs_ctx = fatfs_ctx_alloc();
946
[296]947            assert( (fatfs_ctx != NULL) , __FUNCTION__ , "cannot create FATFS context\n" );
[188]948
949            // get local pointer on VFS context for FATFS
950            vfs_ctx_t   * vfs_ctx = &fs_context[FS_TYPE_FATFS];
951
952            // copy VFS context from cluster 0 to local cluster
953            hal_remote_memcpy( XPTR( local_cxy , vfs_ctx ), 
954                               XPTR( 0 , vfs_ctx ),
955                               sizeof(vfs_ctx_t) );
956
957            // copy FATFS context from cluster 0 to local cluster
958            hal_remote_memcpy( XPTR( local_cxy , fatfs_ctx ), 
959                               XPTR( 0 , fatfs_ctx ),
960                               sizeof(fatfs_ctx_t) );
961
962            // update extend field in local copy of VFS context
963            vfs_ctx->extend = fatfs_ctx;
[23]964        }
965
[188]966        // get extended pointer on VFS root inode from cluster 0
[296]967        vfs_root_inode_xp = hal_remote_lwd( XPTR( 0 , &process_zero.vfs_root_xp ) );
[101]968
[188]969        // update local process_zero descriptor
970        process_zero.vfs_root_xp = vfs_root_inode_xp;
971        process_zero.vfs_cwd_xp  = vfs_root_inode_xp;
[14]972    }
973
[188]974    /////////////////////////////////////////////////////////////////////////////////
975    if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ), 
976                                        (info->x_size * info->y_size) );
977    barrier_wait( &local_barrier , info->cores_nr );
[204]978    /////////////////////////////////////////////////////////////////////////////////
[101]979
[296]980    if( (core_lid ==  0) && (local_cxy == io_cxy) ) 
981    kinit_dmsg("\n[INFO] %s : exit barrier 5 : VFS_root = %l in cluster IO / cycle %d\n",
982    __FUNCTION__, vfs_root_inode_xp , hal_time_stamp() );
[188]983
984    /////////////////////////////////////////////////////////////////////////////////
985    // STEP 6 : CP0 in cluster IO makes the global DEVFS tree initialisation:
[204]986    //          It creates the DEVFS directory "dev", and the DEVFS "external"
987    //          directory in cluster IO and mount these inodes into VFS.
[188]988    /////////////////////////////////////////////////////////////////////////////////
989
990    if( (core_lid ==  0) && (local_cxy == io_cxy) ) 
[1]991    {
[188]992        // create "dev" and "external" directories.
993        devfs_global_init( process_zero.vfs_root_xp,
[204]994                           &devfs_dev_inode_xp,
[188]995                           &devfs_external_inode_xp );
996
997        // creates the DEVFS context in cluster IO
998        devfs_ctx_t * devfs_ctx = devfs_ctx_alloc();
999
[279]1000        assert( (devfs_ctx != NULL) , __FUNCTION__ ,
1001                "cannot create DEVFS context in cluster IO\n");
[188]1002
1003        // register DEVFS root and external directories
[204]1004        devfs_ctx_init( devfs_ctx, devfs_dev_inode_xp, devfs_external_inode_xp );
[188]1005    }   
1006
1007    /////////////////////////////////////////////////////////////////////////////////
1008    if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ), 
1009                                        (info->x_size * info->y_size) );
1010    barrier_wait( &local_barrier , info->cores_nr );
[204]1011    /////////////////////////////////////////////////////////////////////////////////
[188]1012
[296]1013    if( (core_lid ==  0) && (local_cxy == io_cxy) ) 
1014    kinit_dmsg("\n[INFO] %s : exit barrier 6 : dev_root = %l in cluster IO / cycle %d\n",
1015    __FUNCTION__, devfs_dev_inode_xp , hal_time_stamp() );
[188]1016
1017    /////////////////////////////////////////////////////////////////////////////////
1018    // STEP 7 : All CP0s complete in parallel the DEVFS tree initialization.
1019    //          Each CP0 get the "dev" and "external" extended pointers from
[204]1020    //          values stored in cluster IO.
[337]1021    //          Then each CP0 in cluster(i) creates the DEVFS "internal directory,
[204]1022    //          and creates the pseudo-files for all chdevs in cluster (i).
[188]1023    /////////////////////////////////////////////////////////////////////////////////
1024
1025    if( core_lid == 0 )
1026    {
1027        // get extended pointer on "extend" field of VFS context for DEVFS in cluster IO
1028        xptr_t  extend_xp = XPTR( io_cxy , &fs_context[FS_TYPE_DEVFS].extend );
1029
1030        // get pointer on DEVFS context in cluster IO
1031        devfs_ctx_t * devfs_ctx = hal_remote_lpt( extend_xp );
1032       
[204]1033        devfs_dev_inode_xp      = hal_remote_lwd( XPTR( io_cxy ,
1034                                                        &devfs_ctx->dev_inode_xp ) );
1035        devfs_external_inode_xp = hal_remote_lwd( XPTR( io_cxy , 
1036                                                        &devfs_ctx->external_inode_xp ) );
[188]1037
[204]1038        // populate DEVFS in all clusters
1039        devfs_local_init( devfs_dev_inode_xp,
1040                          devfs_external_inode_xp,
1041                          &devfs_internal_inode_xp );
[188]1042    }
1043
1044    /////////////////////////////////////////////////////////////////////////////////
1045    if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ), 
1046                                        (info->x_size * info->y_size) );
1047    barrier_wait( &local_barrier , info->cores_nr );
[204]1048    /////////////////////////////////////////////////////////////////////////////////
[188]1049
1050    if( (core_lid ==  0) && (local_cxy == 0) ) 
[296]1051    kinit_dmsg("\n[INFO] %s : exit barrier 7 : dev_root = %l in cluster 0 / cycle %d\n",
1052    __FUNCTION__, devfs_dev_inode_xp , hal_time_stamp() );
[188]1053
1054    /////////////////////////////////////////////////////////////////////////////////
[204]1055    // STEP 8 : CP0 in I/O cluster creates the first user process (process_init)
[188]1056    /////////////////////////////////////////////////////////////////////////////////
1057
1058    if( (core_lid ==  0) && (local_cxy == io_cxy) ) 
1059    {
[101]1060        process_init_create();
[188]1061    }
[101]1062
[188]1063    /////////////////////////////////////////////////////////////////////////////////
1064    if( core_lid == 0 ) remote_barrier( XPTR( info->io_cxy , &global_barrier ),
1065                                        (info->x_size * info->y_size) );
1066    barrier_wait( &local_barrier , info->cores_nr );
[204]1067    /////////////////////////////////////////////////////////////////////////////////
[188]1068
1069    if( (core_lid ==  0) && (local_cxy == 0) ) 
[296]1070    kinit_dmsg("\n[INFO] %s : exit barrier 8 : process init created / cycle %d\n", 
1071    __FUNCTION__ , hal_time_stamp() );
[188]1072
1073    /////////////////////////////////////////////////////////////////////////////////
1074    // STEP 9 : CP0 in cluster 0 print banner
1075    /////////////////////////////////////////////////////////////////////////////////
1076   
1077    if( (core_lid ==  0) && (local_cxy == io_cxy) ) 
1078    {
[5]1079        print_banner( (info->x_size * info->y_size) , info->cores_nr );
[68]1080
[279]1081        kinit_dmsg("\n\n*** memory fooprint for main kernet objects ***\n\n"
[68]1082                   " - thread descriptor  : %d bytes\n"
1083                   " - process descriptor : %d bytes\n"
1084                   " - cluster manager    : %d bytes\n"
1085                   " - chdev descriptor   : %d bytes\n"
1086                   " - core descriptor    : %d bytes\n"
1087                   " - scheduler          : %d bytes\n"
1088                   " - rpc fifo           : %d bytes\n"
1089                   " - page descriptor    : %d bytes\n"
1090                   " - mapper root        : %d bytes\n"
1091                   " - ppm manager        : %d bytes\n"
1092                   " - kcm manager        : %d bytes\n"
1093                   " - khm manager        : %d bytes\n"
1094                   " - vmm manager        : %d bytes\n"
1095                   " - gpt root           : %d bytes\n"
1096                   " - list item          : %d bytes\n"
1097                   " - xlist item         : %d bytes\n"
1098                   " - spinlock           : %d bytes\n"
1099                   " - remote spinlock    : %d bytes\n"
1100                   " - rwlock             : %d bytes\n"
1101                   " - remote rwlock      : %d bytes\n",
[127]1102                   sizeof( thread_t          ),
[68]1103                   sizeof( process_t         ),
1104                   sizeof( cluster_t         ),
1105                   sizeof( chdev_t           ),
1106                   sizeof( core_t            ),
1107                   sizeof( scheduler_t       ),
1108                   sizeof( rpc_fifo_t        ),
1109                   sizeof( page_t            ),
1110                   sizeof( mapper_t          ),
1111                   sizeof( ppm_t             ),
1112                   sizeof( kcm_t             ),
1113                   sizeof( khm_t             ),
1114                   sizeof( vmm_t             ),
1115                   sizeof( gpt_t             ),
1116                   sizeof( list_entry_t      ),
1117                   sizeof( xlist_entry_t     ),
1118                   sizeof( spinlock_t        ),
1119                   sizeof( remote_spinlock_t ),
1120                   sizeof( rwlock_t          ),
1121                   sizeof( remote_rwlock_t   ));
[1]1122    }
1123
[279]1124    // each core activates its private TICK IRQ
[188]1125    dev_pic_enable_timer( CONFIG_SCHED_TICK_PERIOD );
[14]1126
1127    // each core jump to idle thread
[50]1128    thread_idle_func();
[127]1129}
[14]1130
Note: See TracBrowser for help on using the repository browser.