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

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

Fix few bugs whike debugging the sort multi-thread application.

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