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

Last change on this file since 285 was 285, checked in by max@…, 7 years ago

Must be reg_t.

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