Ignore:
Timestamp:
Nov 3, 2014, 11:03:55 AM (10 years ago)
Author:
alain
Message:

Introducing dynamic allocation of peripheral channels (NIC, TTY, CMA, TIM)
Intoducing a kernel function for all system calls: No more direct call
to the peripheral drivers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/giet_kernel/kernel_init.c

    r428 r440  
    55// Copyright (c) UPMC-LIP6
    66////////////////////////////////////////////////////////////////////////////////////
    7 // The kernel_init.c file is part of the GIET-VM nano-kernel.
    8 //
    9 // This nano-kernel has been written for the MIPS32 processor.
    10 // The virtual adresses are on 32 bits and use the (unsigned int) type, but the
    11 // physicals addresses can have up to 40 bits, and use the (unsigned long long) type.
    12 // It natively supports clusterised shared mmemory multi-processors architectures,
    13 // where each processor is identified by a composite index [x,y,lpid],
    14 // and where there is one physical memory bank per cluster.
    15 //
    16 // The kernel_init() function is executed sequencially by all procesors.
    17 // It completes the system initialisation that has been started by processor[0,0,0]
    18 // in the boot_init() function. It makes the following assuptions, regarding the work
    19 // bone by the boot code:
    20 //
    21 // 1) The page tables associated to the various vspaces have been build
    22 //    in physical memory, and can be used by the kernel code.
    23 //
    24 // 2) All schedulers (this include all task contexts) have been initialised,
    25 //    Both the virtual and the physical base addresses of the page tables
    26 //    are available in the CTX_PTAB and CTX_PTPR slots.
    27 //
    28 // 3) The CP0_SCHED register of each processor contains a pointer on its
    29 //    private scheduler (virtual address).
    30 //
    31 // 4) The CP2_PTPR register of each processor contains a pointer on
    32 //    the vspace_0 page table (physical address>>13).
    33 //
    34 // 5) For all processors, the MMU is activated (CP2_MODE contains 0xF).
    35 //
    36 // This code must be loaded in .kinit section, in order to control seg_kinit_base,
    37 // as this address is used by the boot code to jump into kernel code.
    38 //
    39 // Each processor performs the following actions:
    40 // 1/ contribute to _schedulers_paddr[] array initialisation.
    41 // 2/ contribute to _ptabs_paddr[] and _ptabs_vaddr arrays initialisation
    42 // 3/ completes task context initialisation for ech allocated task
    43 // 4/ compute and set the ICU mask for its private ICU channel
    44 // 5/ initialise its private TICK timer (if tasks > 0)
    45 // 6/ initialise the "idle" task context in its private scheduler
    46 // 7/ initialise SP, SR, PTPR, EPC registers and jump to user code with an eret.
     7// This kernel_init.c file is part of the GIET-VM nano-kernel.
    478////////////////////////////////////////////////////////////////////////////////////
    489
    4910#include <giet_config.h>
    50 
    51 // kernel libraries
     11#include <hard_config.h>
    5212#include <utils.h>
     13#include <kernel_utils.h>
    5314#include <fat32.h>
    54 
    55 //for peripheral initialisation
    56 #include <dma_driver.h>
    57 #include <fbf_driver.h>
    58 #include <tty_driver.h>
    59 #include <icu_driver.h>
    6015#include <xcu_driver.h>
    61 #include <ioc_driver.h>
    62 #include <mmc_driver.h>
    63 #include <mwr_driver.h>
    64 #include <nic_driver.h>
    65 #include <tim_driver.h>
    66 
    6716#include <ctx_handler.h>
    6817#include <irq_handler.h>
    69 
    7018#include <mapping_info.h>
    7119#include <mips32_registers.h>
     
    14694{
    14795    // gpid : hardware processor index (fixed format: X_WIDTH|Y_WIDTH|P_WIDTH)
    148     // lpid : local processor id in a cluster ( lpid < NB_PROCS_MAX)
     96    // p : local processor id in a cluster ( p < NB_PROCS_MAX)
    14997    // cpid : "continuous" processor index = (((x * Y_SIZE + y) * NB_PROCS_MAX) + p
    15098
     
    153101    unsigned int x          = cluster_xy >> Y_WIDTH & ((1<<X_WIDTH)-1);
    154102    unsigned int y          = cluster_xy & ((1<<Y_WIDTH)-1);
    155     unsigned int lpid       = gpid & ((1<<P_WIDTH)-1);
    156     unsigned int cpid       = ((( x * Y_SIZE) + y) * NB_PROCS_MAX) + lpid;
     103    unsigned int p          = gpid & ((1<<P_WIDTH)-1);
     104    unsigned int cpid       = ((( x * Y_SIZE) + y) * NB_PROCS_MAX) + p;
    157105
    158106
     
    160108    while( cpid != kernel_init_barrier ) asm volatile ( "nop" );
    161109
    162     // Step 1 : each processor get its scheduler virtual address from CP0 register
    163     //          and contribute to initialise the _schedulers[] array
     110    // Step 1 : each processor get its scheduler virtual address from CP0_SCHED register
     111    //          and contributes to _schedulers[] array initialisation
    164112
    165113    static_scheduler_t* psched     = (static_scheduler_t*)_get_sched();
    166114    unsigned int        tasks      = psched->tasks;
    167115
    168     _schedulers[x][y][lpid] = psched;
     116    _schedulers[x][y][p] = psched;
    169117
    170118#if GIET_DEBUG_INIT
     
    172120        " - scheduler vbase = %x\n"
    173121        " - tasks           = %d\n",
    174         x, y, lpid, (unsigned int)psched, tasks );
     122        x, y, p, (unsigned int)psched, tasks );
    175123#endif
    176124
     
    181129    //          - set CTX_EPC slot that must contain the task entry point,
    182130    //            and contain only at this point the virtual address of the memory
    183     //            location containing this entry point. We must switch the PTPR
    184     //            to use the page table corresponding to the task.
     131    //            location containing this entry point.
    185132
    186133    unsigned int ltid;
     
    188135    for (ltid = 0; ltid < tasks; ltid++)
    189136    {
    190         unsigned int vsid = _get_task_slot( x, y, lpid, ltid , CTX_VSID_ID );
    191         unsigned int ptab = _get_task_slot( x, y, lpid, ltid , CTX_PTAB_ID );
    192         unsigned int ptpr = _get_task_slot( x, y, lpid, ltid , CTX_PTPR_ID );
     137        unsigned int vsid = _get_task_slot( x, y, p, ltid , CTX_VSID_ID );
     138        unsigned int ptab = _get_task_slot( x, y, p, ltid , CTX_PTAB_ID );
     139        unsigned int ptpr = _get_task_slot( x, y, p, ltid , CTX_PTPR_ID );
    193140
    194141        // initialize PTABS arrays
     
    199146_printf("\n[GIET DEBUG INIT] Processor[%d,%d,%d] contributes to PTABS arrays\n"
    200147        " - ptabs_vaddr[%d] = %x / ptpr_paddr[%d] = %l\n",
    201         x, y, lpid
     148        x, y, p
    202149        vsid, ptab, vsid, ((unsigned long long)ptpr)<<13 );
    203150#endif
     
    209156        // compute ctx_ra
    210157        unsigned int ctx_ra = (unsigned int)(&_ctx_eret);
    211         _set_task_slot( x, y, lpid, ltid, CTX_RA_ID, ctx_ra );
     158        _set_task_slot( x, y, p, ltid, CTX_RA_ID, ctx_ra );
    212159
    213160        // compute ctx_epc
    214         unsigned int* ptr = (unsigned int*)_get_task_slot( x, y, lpid, ltid, CTX_EPC_ID );
    215         _set_task_slot( x, y, lpid, ltid, CTX_EPC_ID, *ptr );
     161        unsigned int* ptr = (unsigned int*)_get_task_slot( x, y, p, ltid, CTX_EPC_ID );
     162        _set_task_slot( x, y, p, ltid, CTX_EPC_ID, *ptr );
    216163
    217164#if GIET_DEBUG_INIT
     
    219166        " - ctx_epc   = %x\n"
    220167        " - ctx_ra    = %x\n",
    221         x, y, lpid, ltid,
    222         _get_task_slot( x, y, lpid, ltid, CTX_EPC_ID ),
    223         _get_task_slot( x, y, lpid, ltid, CTX_RA_ID ) );
     168        x, y, p, ltid,
     169        _get_task_slot( x, y, p, ltid, CTX_EPC_ID ),
     170        _get_task_slot( x, y, p, ltid, CTX_RA_ID ) );
    224171#endif
    225172
    226173    }  // end for tasks
    227174
    228     // step 4 : compute and set ICU or XCU masks
     175    // step 4 : compute and set XCU masks
    229176
    230177    unsigned int isr_switch_index = 0xFFFFFFFF;
     
    252199#if GIET_DEBUG_INIT
    253200_printf("\n[GIET DEBUG INIT] Processor[%d,%d,%d] sets XCU masks\n"
    254         " - ICU HWI_MASK = %x\n"
    255         " - ICU WTI_MASK = %x\n"
    256         " - ICU PTI_MASK = %x\n",
    257         x, y, lpid, hwi_mask, wti_mask, pti_mask );
    258 #endif
    259 
    260     unsigned int channel = lpid * IRQ_PER_PROCESSOR;
    261 
    262 #if USE_XCU
     201        " - XCU HWI_MASK = %x\n"
     202        " - XCU WTI_MASK = %x\n"
     203        " - XCU PTI_MASK = %x\n",
     204        x, y, p, hwi_mask, wti_mask, pti_mask );
     205#endif
     206
     207    unsigned int channel = p * IRQ_PER_PROCESSOR;
     208
    263209    _xcu_set_mask( cluster_xy, channel, hwi_mask, IRQ_TYPE_HWI );
    264210    _xcu_set_mask( cluster_xy, channel, wti_mask, IRQ_TYPE_WTI );
    265211    _xcu_set_mask( cluster_xy, channel, pti_mask, IRQ_TYPE_PTI );
    266 #else
    267     _icu_set_mask( cluster_xy, channel, hwi_mask );   
    268 #endif
    269212
    270213    // step 5 : start TICK timer if at least one task
     
    275218        {
    276219            _printf("\n[GIET ERROR] ISR_TICK not found for processor[%d,%d,%d]\n",
    277                     x, y, lpid );
     220                    x, y, p );
    278221            _exit();
    279222        }
    280223
    281224        // start system timer
    282 
    283 #if USE_XCU
    284225        _xcu_timer_start( cluster_xy, isr_switch_index, GIET_TICK_VALUE );
    285 #else
    286         _timer_start( cluster_xy, isr_switch_index, GIET_TICK_VALUE );
    287 #endif
    288226
    289227    }
     
    291229#if GIET_DEBUG_INIT
    292230_printf("\n[GIET DEBUG INIT] Processor[%d,%d,%d] starts TICK timer\n",
    293         x, y, lpid );
     231        x, y, p );
    294232#endif
    295233
     
    302240    unsigned int pstack = ((unsigned int)psched) + 0x2000;
    303241
    304     _set_task_slot( x, y, lpid, IDLE_TASK_INDEX, CTX_SP_ID,  pstack);
    305     _set_task_slot( x, y, lpid, IDLE_TASK_INDEX, CTX_RA_ID,  (unsigned int) &_ctx_eret);
    306     _set_task_slot( x, y, lpid, IDLE_TASK_INDEX, CTX_EPC_ID, (unsigned int) &_idle_task);
     242    _set_task_slot( x, y, p, IDLE_TASK_INDEX, CTX_SP_ID,  pstack);
     243    _set_task_slot( x, y, p, IDLE_TASK_INDEX, CTX_RA_ID,  (unsigned int) &_ctx_eret);
     244    _set_task_slot( x, y, p, IDLE_TASK_INDEX, CTX_EPC_ID, (unsigned int) &_idle_task);
    307245
    308246#if GIET_DEBUG_INIT
     
    310248        " - stack_base = %x\n"
    311249        " - stack_size = 0x1000\n",
    312         x, y, lpid, pstack - 0x1000 );
     250        x, y, p, pstack - 0x1000 );
    313251#endif
    314252
     
    324262
    325263        _printf("\n[GIET WARNING] No task allocated to processor[%d,%d,%d]\n",
    326                 x, y, lpid );
     264                x, y, p );
    327265    }
    328266    else
     
    331269    }
    332270
    333     unsigned int sp_value   = _get_task_slot( x, y, lpid, ltid, CTX_SP_ID);
    334     unsigned int sr_value   = _get_task_slot( x, y, lpid, ltid, CTX_SR_ID);
    335     unsigned int ptpr_value = _get_task_slot( x, y, lpid, ltid, CTX_PTPR_ID);
    336     unsigned int epc_value  = _get_task_slot( x, y, lpid, ltid, CTX_EPC_ID);
     271    unsigned int sp_value   = _get_task_slot( x, y, p, ltid, CTX_SP_ID);
     272    unsigned int sr_value   = _get_task_slot( x, y, p, ltid, CTX_SR_ID);
     273    unsigned int ptpr_value = _get_task_slot( x, y, p, ltid, CTX_PTPR_ID);
     274    unsigned int epc_value  = _get_task_slot( x, y, p, ltid, CTX_EPC_ID);
    337275
    338276#if GIET_DEBUG_INIT
    339277_printf("\n[GIET DEBUG INIT] Processor[%d,%d,%d] reach barrier at cycle %d\n",
    340         x, y, lpid, _get_proctime() );
     278        x, y, p, _get_proctime() );
    341279#endif
    342280
     
    353291        " - ptpr = %x\n"
    354292        " - epc  = %x\n",
    355         x, y, lpid, _get_proctime(),
     293        x, y, p, _get_proctime(),
    356294        sp_value, sr_value, ptpr_value, epc_value );
    357295#endif
Note: See TracChangeset for help on using the changeset viewer.