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

Last change on this file since 490 was 490, checked in by viala@…, 6 years ago

Minor: Add extern prototype for kernel_init function.

Also I add documentation from where this function is called.

Gcc warning fixed:
`
kern/kernel_init.c: At top level:
kern/kernel_init.c:744:6: warning: no previous declaration for 'kernel_init'
[-Wmissing-declarations]

void kernel_init( boot_info_t * info )


`

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