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

Last change on this file since 533 was 532, checked in by nicolas.van.phan@…, 6 years ago

Add message to show enabling of IPI on cores.

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