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

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

Replace TXT0 by MTTY0 for LETI

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