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

Last change on this file since 433 was 428, checked in by alain, 6 years ago

blip

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