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

Last change on this file since 459 was 457, checked in by alain, 3 years ago

This version modifies the exec syscall and fixes a large number of small bugs.
The version number has been updated (0.1)

File size: 53.2 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
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"
[457]188           "\n\n\t\t %s / %d cluster(s) / %d core(s) per cluster\n\n",
189           CONFIG_ALMOS_VERSION , nclusters , ncores );
[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    /////////////////////////////////////////////////////////////////////////////////
764    // STEP 0 : Each core get its core identifier from boot_info, and makes
765    //          a partial initialisation of its private idle thread descriptor.
766    //          CP0 initializes the "local_cxy" global variable.
767    //          CP0 in cluster IO initializes the TXT0 chdev to print log messages.
768    /////////////////////////////////////////////////////////////////////////////////
769
[23]770    error = get_core_identifiers( info,
[14]771                                  &core_lid,
772                                  &core_cxy,
773                                  &core_gid );
[1]774
[127]775    // CP0 initializes cluster identifier
[14]776    if( core_lid == 0 ) local_cxy = info->cxy;
[1]777
[127]778    // each core gets a pointer on its private idle thread descriptor
779    thread = (thread_t *)( idle_threads + (core_lid * CONFIG_THREAD_DESC_SIZE) );
[68]780
[127]781    // each core registers this thread pointer in hardware register
[68]782    hal_set_current_thread( thread );
[71]783
[407]784    // each core register core descriptor pointer in idle thread descriptor
785    thread->core = &LOCAL_CLUSTER->core_tbl[core_lid];
786
[437]787    // each core initializes the idle thread lists of locks
[124]788    list_root_init( &thread->locks_root );
[188]789    xlist_root_init( XPTR( local_cxy , &thread->xlocks_root ) );
[437]790    thread->local_locks = 0;
791    thread->remote_locks = 0;
[124]792
[457]793    // CP0 in cluster 0 initialises TXT0 chdev descriptor
794    if( (core_lid == 0) && (core_cxy == 0) ) txt0_device_init( info );
[14]795
796    /////////////////////////////////////////////////////////////////////////////////
[457]797    if( core_lid == 0 ) remote_barrier( XPTR( 0 , &global_barrier ), 
[14]798                                        (info->x_size * info->y_size) );
799    barrier_wait( &local_barrier , info->cores_nr );
[437]800    /////////////////////////////////////////////////////////////////////////////////
[14]801
[438]802#if DEBUG_KERNEL_INIT
803if( (core_lid ==  0) & (local_cxy == 0) ) 
[437]804printk("\n[DBG] %s : exit barrier 0 : TXT0 initialized / cycle %d\n",
805__FUNCTION__, (uint32_t)hal_get_cycles() );
806#endif
[14]807
[188]808    /////////////////////////////////////////////////////////////////////////////
[407]809    // STEP 1 : all cores check core identifier.
[188]810    //          CP0 initializes the local cluster manager.
811    //          This includes the memory allocators.
812    /////////////////////////////////////////////////////////////////////////////
813
814    // all cores check identifiers
[14]815    if( error )
[1]816    {
[428]817        assert( false , __FUNCTION__ ,
818        "illegal core identifiers gid = %x / cxy = %x / lid = %d",
819        core_lid , core_cxy , core_lid );
[1]820    }
821
[188]822    // CP0 initializes cluster manager
[14]823    if( core_lid == 0 )
[1]824    {
825        error = cluster_init( info );
826
[14]827        if( error )
828        {
[428]829            assert( false , __FUNCTION__ ,
830            "cannot initialise cluster %x", local_cxy );
[14]831        }
832    }
[5]833
[14]834    /////////////////////////////////////////////////////////////////////////////////
[457]835    if( core_lid == 0 ) remote_barrier( XPTR( 0 , &global_barrier ), 
[14]836                                        (info->x_size * info->y_size) );
837    barrier_wait( &local_barrier , info->cores_nr );
838    /////////////////////////////////////////////////////////////////////////////////
[1]839
[438]840#if DEBUG_KERNEL_INIT
841if( (core_lid ==  0) & (local_cxy == 0) ) 
[437]842printk("\n[DBG] %s : exit barrier 1 : clusters initialised / cycle %d\n",
843__FUNCTION__, (uint32_t)hal_get_cycles() );
844#endif
[1]845
[188]846    /////////////////////////////////////////////////////////////////////////////////
[407]847    // STEP 2 : CP0 initializes the process_zero descriptor.
[296]848    //          CP0 in cluster 0 initializes the IOPIC device.
[188]849    /////////////////////////////////////////////////////////////////////////////////
850
851    // all cores get pointer on local cluster manager & core descriptor
[14]852    cluster = &cluster_manager;
[127]853    core    = &cluster->core_tbl[core_lid];
[1]854
[188]855    // all CP0s initialize the process_zero descriptor
[428]856    if( core_lid == 0 ) process_zero_create( &process_zero );
[5]857
[188]858    // CP0 in cluster 0 initializes the PIC chdev,
859    if( (core_lid == 0) && (local_cxy == 0) ) iopic_init( info );
860   
861    ////////////////////////////////////////////////////////////////////////////////
[457]862    if( core_lid == 0 ) remote_barrier( XPTR( 0 , &global_barrier ), 
[188]863                                        (info->x_size * info->y_size) );
864    barrier_wait( &local_barrier , info->cores_nr );
865    ////////////////////////////////////////////////////////////////////////////////
[127]866
[438]867#if DEBUG_KERNEL_INIT
868if( (core_lid ==  0) & (local_cxy == 0) ) 
[437]869printk("\n[DBG] %s : exit barrier 2 : PIC initialised / cycle %d\n",
870__FUNCTION__, (uint32_t)hal_get_cycles() );
871#endif
[1]872
[188]873    ////////////////////////////////////////////////////////////////////////////////
[407]874    // STEP 3 : CP0 initializes the distibuted LAPIC descriptor.
875    //          CP0 initializes the internal chdev descriptors
876    //          CP0 initialize the local external chdev descriptors
[188]877    ////////////////////////////////////////////////////////////////////////////////
[5]878
[279]879    // all CP0s initialize their local LAPIC extension,
880    if( core_lid == 0 ) lapic_init( info );
881
[188]882    // CP0 scan the internal (private) peripherals,
883    // and allocates memory for the corresponding chdev descriptors.
884    if( core_lid == 0 ) internal_devices_init( info );
885       
[1]886
[50]887    // All CP0s contribute to initialise external peripheral chdev descriptors.
[14]888    // Each CP0[cxy] scan the set of external (shared) peripherals (but the TXT0),
889    // and allocates memory for the chdev descriptors that must be placed
[127]890    // on the (cxy) cluster according to the global index value.
[188]891
[14]892    if( core_lid == 0 ) external_devices_init( info );
[1]893
[14]894    /////////////////////////////////////////////////////////////////////////////////
[457]895    if( core_lid == 0 ) remote_barrier( XPTR( 0 , &global_barrier ), 
[14]896                                        (info->x_size * info->y_size) );
897    barrier_wait( &local_barrier , info->cores_nr );
898    /////////////////////////////////////////////////////////////////////////////////
[5]899
[438]900#if DEBUG_KERNEL_INIT
901if( (core_lid ==  0) & (local_cxy == 0) ) 
[437]902printk("\n[DBG] %s : exit barrier 3 : all chdev initialised / cycle %d\n",
903__FUNCTION__, (uint32_t)hal_get_cycles() );
904#endif
[1]905
[438]906#if( DEBUG_KERNEL_INIT & 1 )
[443]907if( (core_lid ==  0) & (local_cxy == 0) ) 
[437]908chdev_dir_display();
909#endif
910   
[188]911    /////////////////////////////////////////////////////////////////////////////////
[279]912    // STEP 4 : All cores enable IPI (Inter Procesor Interrupt),
913    //          Alh cores initialize IDLE thread.
[188]914    //          Only CP0 in cluster 0 creates the VFS root inode.
915    //          It access the boot device to initialize the file system context.
916    /////////////////////////////////////////////////////////////////////////////////
917
[279]918    // All cores enable the shared IPI channel
919    dev_pic_enable_ipi();
920    hal_enable_irq( &status );
921
[296]922    // all cores initialize the idle thread descriptor
[457]923    thread_idle_init( thread,
924                      THREAD_IDLE,
925                      &thread_idle_func,
926                      NULL,
927                      core_lid );
[1]928
[296]929    // all cores unblock idle thread, and register it in scheduler
930    thread_unblock( XPTR( local_cxy , thread ) , THREAD_BLOCKED_GLOBAL );
[103]931    core->scheduler.idle = thread;
[1]932
[438]933#if( DEBUG_KERNEL_INIT & 1 )
[407]934sched_display( core_lid );
[389]935#endif
[14]936
[188]937    // CPO in cluster 0 creates the VFS root
938    if( (core_lid ==  0) && (local_cxy == 0 ) ) 
[14]939    {
[188]940        vfs_root_inode_xp = XPTR_NULL;
[23]941
[188]942        // File System must be FATFS in this implementation,
943        // but other File System can be introduced here
[23]944        if( CONFIG_VFS_ROOT_IS_FATFS )
945        {
[389]946            // 1. allocate memory for FATFS context in cluster 0
[188]947            fatfs_ctx_t * fatfs_ctx = fatfs_ctx_alloc();
948
[279]949            assert( (fatfs_ctx != NULL) , __FUNCTION__ ,
950                    "cannot create FATFS context in cluster 0\n" );
[188]951
952            // 2. access boot device to initialize FATFS context
953            fatfs_ctx_init( fatfs_ctx );
954 
955            // 3. get various informations from FATFS context
956            uint32_t root_dir_cluster = fatfs_ctx->root_dir_cluster;
957            uint32_t cluster_size     = fatfs_ctx->bytes_per_sector * 
958                                        fatfs_ctx->sectors_per_cluster;
959            uint32_t total_clusters   = fatfs_ctx->fat_sectors_count << 7;
960 
961            // 4. create VFS root inode in cluster 0
962            error = vfs_inode_create( XPTR_NULL,                           // dentry_xp
963                                      FS_TYPE_FATFS,                       // fs_type
964                                      INODE_TYPE_DIR,                      // inode_type
965                                      (void *)(intptr_t)root_dir_cluster,  // extend
966                                      0,                                   // attr
967                                      0,                                   // rights
968                                      0,                                   // uid
969                                      0,                                   // gid
970                                      &vfs_root_inode_xp );                // return
971
[279]972            assert( (error == 0) , __FUNCTION__ , 
973                    "cannot create VFS root inode\n" );
[188]974
975            // 5. initialize VFS context for FAT in cluster 0
976            vfs_ctx_init( FS_TYPE_FATFS,                 // file system type
977                          0,                             // attributes
978                              total_clusters,               
979                              cluster_size,
980                              vfs_root_inode_xp,             // VFS root
981                          fatfs_ctx );                   // extend
[389]982
983            // 6. check initialisation
984            vfs_ctx_t   * vfs_ctx = &fs_context[FS_TYPE_FATFS];
985            assert( (((fatfs_ctx_t *)vfs_ctx->extend)->sectors_per_cluster == 8),
986            __FUNCTION__ , "illegal value for FATFS context in cluster %x\n", local_cxy );
[23]987        }
988        else
989        {
[428]990            assert( false , __FUNCTION__ ,
991            "root FS must be FATFS" );
[23]992        }
993
[389]994        // register VFS root inode in process_zero descriptor of cluster 0
[188]995        process_zero.vfs_root_xp = vfs_root_inode_xp;
996        process_zero.vfs_cwd_xp  = vfs_root_inode_xp;
997    }
998
999    /////////////////////////////////////////////////////////////////////////////////
[457]1000    if( core_lid == 0 ) remote_barrier( XPTR( 0 , &global_barrier ), 
[188]1001                                        (info->x_size * info->y_size) );
1002    barrier_wait( &local_barrier , info->cores_nr );
1003    /////////////////////////////////////////////////////////////////////////////////
1004
[438]1005#if DEBUG_KERNEL_INIT
1006if( (core_lid ==  0) & (local_cxy == 0) ) 
[437]1007printk("\n[DBG] %s : exit barrier 4 : VFS_root = %l in cluster 0 / cycle %d\n",
1008__FUNCTION__, vfs_root_inode_xp , (uint32_t)hal_get_cycles());
1009#endif
[188]1010
1011    /////////////////////////////////////////////////////////////////////////////////
1012    // STEP 5 : Other CP0s allocate memory for the selected FS context,
1013    //          and initialise both the local FS context and the local VFS context
1014    //          from values stored in cluster 0.
1015    //          They get the VFS root inode extended pointer from cluster 0.
1016    /////////////////////////////////////////////////////////////////////////////////
1017
1018    if( (core_lid ==  0) && (local_cxy != 0) ) 
1019    {
1020        // File System must be FATFS in this implementation,
1021        // but other File System can be introduced here
1022        if( CONFIG_VFS_ROOT_IS_FATFS )
[23]1023        {
[389]1024            // 1. allocate memory for local FATFS context
1025            fatfs_ctx_t * local_fatfs_ctx = fatfs_ctx_alloc();
[188]1026
[389]1027            assert( (local_fatfs_ctx != NULL) , __FUNCTION__ ,
1028            "cannot create FATFS context in cluster %x\n", local_cxy );
[188]1029
[389]1030            // 2. get local pointer on VFS context for FATFS
[188]1031            vfs_ctx_t   * vfs_ctx = &fs_context[FS_TYPE_FATFS];
1032
[389]1033            // 3. get local pointer on FATFS context in cluster 0
1034            fatfs_ctx_t * remote_fatfs_ctx = hal_remote_lpt( XPTR( 0 , &vfs_ctx->extend ) );
1035
1036            // 4. copy FATFS context from cluster 0 to local cluster
1037            hal_remote_memcpy( XPTR( local_cxy , local_fatfs_ctx ), 
1038                               XPTR( 0 ,         remote_fatfs_ctx ), sizeof(fatfs_ctx_t) );
1039
1040            // 5. copy VFS context from cluster 0 to local cluster
[188]1041            hal_remote_memcpy( XPTR( local_cxy , vfs_ctx ), 
[389]1042                               XPTR( 0 ,         vfs_ctx ), sizeof(vfs_ctx_t) );
[188]1043
[389]1044            // 6. update extend field in local copy of VFS context
1045            vfs_ctx->extend = local_fatfs_ctx;
[188]1046
[389]1047            // 7. check initialisation
1048            assert( (((fatfs_ctx_t *)vfs_ctx->extend)->sectors_per_cluster == 8),
1049            __FUNCTION__ , "illegal value for FATFS context in cluster %x\n", local_cxy );
[23]1050        }
1051
[188]1052        // get extended pointer on VFS root inode from cluster 0
[296]1053        vfs_root_inode_xp = hal_remote_lwd( XPTR( 0 , &process_zero.vfs_root_xp ) );
[101]1054
[188]1055        // update local process_zero descriptor
1056        process_zero.vfs_root_xp = vfs_root_inode_xp;
1057        process_zero.vfs_cwd_xp  = vfs_root_inode_xp;
[14]1058    }
1059
[188]1060    /////////////////////////////////////////////////////////////////////////////////
[457]1061    if( core_lid == 0 ) remote_barrier( XPTR( 0 , &global_barrier ), 
[188]1062                                        (info->x_size * info->y_size) );
1063    barrier_wait( &local_barrier , info->cores_nr );
[204]1064    /////////////////////////////////////////////////////////////////////////////////
[101]1065
[438]1066#if DEBUG_KERNEL_INIT
1067if( (core_lid ==  0) & (local_cxy == 0) ) 
[457]1068printk("\n[DBG] %s : exit barrier 5 : VFS_root = %l in cluster 0 / cycle %d\n",
1069__FUNCTION__, vfs_root_inode_xp , (uint32_t)hal_get_cycles());
[437]1070#endif
[188]1071
1072    /////////////////////////////////////////////////////////////////////////////////
1073    // STEP 6 : CP0 in cluster IO makes the global DEVFS tree initialisation:
[204]1074    //          It creates the DEVFS directory "dev", and the DEVFS "external"
1075    //          directory in cluster IO and mount these inodes into VFS.
[188]1076    /////////////////////////////////////////////////////////////////////////////////
1077
[457]1078    if( (core_lid ==  0) && (local_cxy == 0) ) 
[1]1079    {
[188]1080        // create "dev" and "external" directories.
1081        devfs_global_init( process_zero.vfs_root_xp,
[204]1082                           &devfs_dev_inode_xp,
[188]1083                           &devfs_external_inode_xp );
1084
1085        // creates the DEVFS context in cluster IO
1086        devfs_ctx_t * devfs_ctx = devfs_ctx_alloc();
1087
[279]1088        assert( (devfs_ctx != NULL) , __FUNCTION__ ,
1089                "cannot create DEVFS context in cluster IO\n");
[188]1090
1091        // register DEVFS root and external directories
[204]1092        devfs_ctx_init( devfs_ctx, devfs_dev_inode_xp, devfs_external_inode_xp );
[188]1093    }   
1094
1095    /////////////////////////////////////////////////////////////////////////////////
[457]1096    if( core_lid == 0 ) remote_barrier( XPTR( 0 , &global_barrier ), 
[188]1097                                        (info->x_size * info->y_size) );
1098    barrier_wait( &local_barrier , info->cores_nr );
[204]1099    /////////////////////////////////////////////////////////////////////////////////
[188]1100
[438]1101#if DEBUG_KERNEL_INIT
1102if( (core_lid ==  0) & (local_cxy == 0) ) 
[457]1103printk("\n[DBG] %s : exit barrier 6 : dev_root = %l in cluster 0 / cycle %d\n",
1104__FUNCTION__, devfs_dev_inode_xp , (uint32_t)hal_get_cycles() );
[437]1105#endif
[188]1106
1107    /////////////////////////////////////////////////////////////////////////////////
1108    // STEP 7 : All CP0s complete in parallel the DEVFS tree initialization.
1109    //          Each CP0 get the "dev" and "external" extended pointers from
[204]1110    //          values stored in cluster IO.
[337]1111    //          Then each CP0 in cluster(i) creates the DEVFS "internal directory,
[204]1112    //          and creates the pseudo-files for all chdevs in cluster (i).
[188]1113    /////////////////////////////////////////////////////////////////////////////////
1114
1115    if( core_lid == 0 )
1116    {
[457]1117        // get extended pointer on "extend" field of VFS context for DEVFS in cluster 0
1118        xptr_t  extend_xp = XPTR( 0 , &fs_context[FS_TYPE_DEVFS].extend );
[188]1119
[457]1120        // get pointer on DEVFS context in cluster 0
[188]1121        devfs_ctx_t * devfs_ctx = hal_remote_lpt( extend_xp );
1122       
[457]1123        devfs_dev_inode_xp      = hal_remote_lwd( XPTR( 0 , &devfs_ctx->dev_inode_xp ) );
1124        devfs_external_inode_xp = hal_remote_lwd( XPTR( 0 , &devfs_ctx->external_inode_xp ) );
[188]1125
[204]1126        // populate DEVFS in all clusters
1127        devfs_local_init( devfs_dev_inode_xp,
1128                          devfs_external_inode_xp,
1129                          &devfs_internal_inode_xp );
[188]1130    }
1131
1132    /////////////////////////////////////////////////////////////////////////////////
[457]1133    if( core_lid == 0 ) remote_barrier( XPTR( 0 , &global_barrier ), 
[188]1134                                        (info->x_size * info->y_size) );
1135    barrier_wait( &local_barrier , info->cores_nr );
[204]1136    /////////////////////////////////////////////////////////////////////////////////
[188]1137
[438]1138#if DEBUG_KERNEL_INIT
1139if( (core_lid ==  0) & (local_cxy == 0) ) 
[437]1140printk("\n[DBG] %s : exit barrier 7 : dev_root = %l in cluster 0 / cycle %d\n",
1141__FUNCTION__, devfs_dev_inode_xp , (uint32_t)hal_get_cycles() );
1142#endif
[188]1143
1144    /////////////////////////////////////////////////////////////////////////////////
[428]1145    // STEP 8 : CP0 in cluster 0 creates the first user process (process_init)
[188]1146    /////////////////////////////////////////////////////////////////////////////////
1147
[457]1148    if( (core_lid == 0) && (local_cxy == 0) ) 
[188]1149    {
[428]1150
[438]1151#if( DEBUG_KERNEL_INIT & 1 )
[428]1152vfs_display( vfs_root_inode_xp );
1153#endif
1154
1155       process_init_create();
[188]1156    }
[101]1157
[188]1158    /////////////////////////////////////////////////////////////////////////////////
[457]1159    if( core_lid == 0 ) remote_barrier( XPTR( 0 , &global_barrier ),
[188]1160                                        (info->x_size * info->y_size) );
1161    barrier_wait( &local_barrier , info->cores_nr );
[204]1162    /////////////////////////////////////////////////////////////////////////////////
[188]1163
[438]1164#if DEBUG_KERNEL_INIT
1165if( (core_lid ==  0) & (local_cxy == 0) ) 
[437]1166printk("\n[DBG] %s : exit barrier 8 : process init created / cycle %d\n", 
1167__FUNCTION__ , (uint32_t)hal_get_cycles() );
1168#endif
[188]1169
[443]1170#if (DEBUG_KERNEL_INIT & 1)
1171if( (core_lid ==  0) & (local_cxy == 0) ) 
1172sched_display( 0 );
1173#endif
1174
[188]1175    /////////////////////////////////////////////////////////////////////////////////
1176    // STEP 9 : CP0 in cluster 0 print banner
1177    /////////////////////////////////////////////////////////////////////////////////
1178   
[457]1179    if( (core_lid == 0) && (local_cxy == 0) ) 
[188]1180    {
[5]1181        print_banner( (info->x_size * info->y_size) , info->cores_nr );
[68]1182
[438]1183#if( DEBUG_KERNEL_INIT & 1 )
[437]1184printk("\n\n***** memory fooprint for main kernel objects\n\n"
[68]1185                   " - thread descriptor  : %d bytes\n"
1186                   " - process descriptor : %d bytes\n"
1187                   " - cluster manager    : %d bytes\n"
1188                   " - chdev descriptor   : %d bytes\n"
1189                   " - core descriptor    : %d bytes\n"
1190                   " - scheduler          : %d bytes\n"
1191                   " - rpc fifo           : %d bytes\n"
1192                   " - page descriptor    : %d bytes\n"
1193                   " - mapper root        : %d bytes\n"
1194                   " - ppm manager        : %d bytes\n"
1195                   " - kcm manager        : %d bytes\n"
1196                   " - khm manager        : %d bytes\n"
1197                   " - vmm manager        : %d bytes\n"
1198                   " - gpt root           : %d bytes\n"
1199                   " - list item          : %d bytes\n"
1200                   " - xlist item         : %d bytes\n"
1201                   " - spinlock           : %d bytes\n"
1202                   " - remote spinlock    : %d bytes\n"
1203                   " - rwlock             : %d bytes\n"
1204                   " - remote rwlock      : %d bytes\n",
[127]1205                   sizeof( thread_t          ),
[68]1206                   sizeof( process_t         ),
1207                   sizeof( cluster_t         ),
1208                   sizeof( chdev_t           ),
1209                   sizeof( core_t            ),
1210                   sizeof( scheduler_t       ),
[407]1211                   sizeof( remote_fifo_t     ),
[68]1212                   sizeof( page_t            ),
1213                   sizeof( mapper_t          ),
1214                   sizeof( ppm_t             ),
1215                   sizeof( kcm_t             ),
1216                   sizeof( khm_t             ),
1217                   sizeof( vmm_t             ),
1218                   sizeof( gpt_t             ),
1219                   sizeof( list_entry_t      ),
1220                   sizeof( xlist_entry_t     ),
1221                   sizeof( spinlock_t        ),
1222                   sizeof( remote_spinlock_t ),
1223                   sizeof( rwlock_t          ),
1224                   sizeof( remote_rwlock_t   ));
[406]1225#endif
1226
[1]1227    }
1228
[398]1229    // each core activates its private TICK IRQ
1230    dev_pic_enable_timer( CONFIG_SCHED_TICK_MS_PERIOD );
[14]1231
[440]1232#if DEBUG_KERNEL_INIT
1233printk("\n[DBG] %s : thread %x on core[%x,%d] jumps to thread_idle_func() / cycle %d\n",
1234__FUNCTION__ , CURRENT_THREAD , local_cxy , core_lid , (uint32_t)hal_get_cycles() );
1235#endif
1236
[407]1237    // each core jump to thread_idle_func
[50]1238    thread_idle_func();
[127]1239}
[14]1240
Note: See TracBrowser for help on using the repository browser.