Changeset 167 for soft/giet_vm/sys


Ignore:
Timestamp:
Jul 16, 2012, 10:26:27 AM (12 years ago)
Author:
alain
Message:

Fix several bugs to use the vci_block_device with MMU activated

Location:
soft/giet_vm/sys
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/sys/ctx_handler.c

    r165 r167  
    1515// It contains copies of processor registers, when the task is not running,
    1616// and some general informations associated to the task.
     17//
    1718// - It contains GPR[i], generally stored in slot (i). $0, *26 & $27 are not saved.
    1819// - It contains HI & LO registers.
    1920// - It contains CP0 registers: EPC, SR, CR.
    2021// - It contains CP2 registers : PTPR and MODE.
    21 // - It contains the TTY index for the terminal allocated to the task.
    22 // ctx[0] <- SR   ctx[8] <- $8    ctx[16]<- $16   ctx[24]<- $24   ctx[32]<- EPC
    23 // ctx[1] <- $1   ctx[9] <- $9    ctx[17]<- $17   ctx[25]<- $25   ctx[33]<- CR
    24 // ctx[2] <- $2   ctx[10]<- $10   ctx[18]<- $18   ctx[26]<- LO    ctx[34]<- TTY
    25 // ctx[3] <- $3   ctx[11]<- $11   ctx[19]<- $19   ctx[27]<- HI    ctx[35]<- PTPR
    26 // ctx[4] <- $4   ctx[12]<- $12   ctx[20]<- $20   ctx[28]<- $28   ctx[36]<- MODE
    27 // ctx[5] <- $5   ctx[13]<- $13   ctx[21]<- $21   ctx[29]<- $29   ctx[37]<- FBDMA
    28 // ctx[6] <- $6   ctx[14]<- $14   ctx[22]<- $22   ctx[30]<- $30   ctx[38]<- reserved
    29 // ctx[7] <- $7   ctx[15]<- $15   ctx[23]<- $23   ctx[31]<- $31   ctx[39]<- reserved
     22// - It contains the TTY global index, the FBDMA global index, the virtual base
     23//   address of the page table (PTAB), and the task global index (TASK).
     24//
     25// ctx[0]<- SR|ctx[8] <- $8 |ctx[16]<- $16|ctx[24]<- $24|ctx[32]<- EPC |ctx[40]<- TTY
     26// ctx[1]<- $1|ctx[9] <- $9 |ctx[17]<- $17|ctx[25]<- $25|ctx[33]<- CR  |ctx[41]<- FBDMA
     27// ctx[2]<- $2|ctx[10]<- $10|ctx[18]<- $18|ctx[26]<- LO |ctx[34]<- *** |ctx[42]<- PTAB
     28// ctx[3]<- $3|ctx[11]<- $11|ctx[19]<- $19|ctx[27]<- HI |ctx[35]<- PTPR|ctx[43]<- TASK
     29// ctx[4]<- $4|ctx[12]<- $12|ctx[20]<- $20|ctx[28]<- $28|ctx[36]<- MODE|ctx[44]<- ***
     30// ctx[5]<- $5|ctx[13]<- $13|ctx[21]<- $21|ctx[29]<- SP |ctx[37]<- *** |ctx[45]<- ***
     31// ctx[6]<- $6|ctx[14]<- $14|ctx[22]<- $22|ctx[30]<- $30|ctx[38]<- *** |ctx[46]<- ***
     32// ctx[7]<- $7|ctx[15]<- $15|ctx[23]<- $23|ctx[31]<- RA |ctx[39]<- *** |ctx[47]<- ***
    3033/////////////////////////////////////////////////////////////////////////////////////
    3134
     
    4043
    4144/////////////////////////////////////////////////////////////////////////////////
    42 //      Global variables
     45//      Global variables : array of schedulers (one scheduler per processor)
    4346/////////////////////////////////////////////////////////////////////////////////
    4447
    45 static_scheduler_t _scheduler[NB_CLUSTERS * NB_PROCS];
     48__attribute__((section (".kdata"))) static_scheduler_t _scheduler[NB_CLUSTERS * NB_PROCS];
    4649
    4750/////////////////////////////////////////////////////////////////////////////////
     
    6467    unsigned int *next_context;
    6568
    66     unsigned int pid   = _procid();
    67     unsigned int time  = _proctime();
    68     unsigned int tasks = _scheduler[pid].tasks;
     69    unsigned int proc_id   = _procid();
     70    unsigned int tasks     = _scheduler[proc_id].tasks;
    6971
    7072    // return if only one task  */
     
    7274 
    7375    // compute the task context base address for the current task
    74     curr_task_id = _scheduler[pid].current;
    75     curr_context = &(_scheduler[pid].context[curr_task_id][0]);
     76    curr_task_id = _scheduler[proc_id].current;
     77    curr_context = &(_scheduler[proc_id].context[curr_task_id][0]);
    7678   
    7779    // select the next task using a round-robin scheduling policy
     
    7981   
    8082    // compute the task context base address for the next task
    81     next_context = &(_scheduler[pid].context[next_task_id][0]);
     83    next_context = &(_scheduler[proc_id].context[next_task_id][0]);
    8284
    8385#if GIET_DEBUG_SWITCH
    8486_get_lock( &_tty_put_lock );
    8587_puts( "\n[GIET] Context switch for processor ");
    86 _putw( pid );
     88_putw( proc_id );
    8789_puts( " at cycle ");
    88 _putw( time );
     90_putw( _proctime() );
    8991_puts("\n");
    9092_puts( " - tasks        = ");
     
    101103
    102104    //  update the scheduler state, and makes the task switch
    103     _scheduler[pid].current = next_task_id;
     105    _scheduler[proc_id].current = next_task_id;
    104106    _task_switch( curr_context, next_context );
    105107
  • soft/giet_vm/sys/ctx_handler.h

    r165 r167  
    1515} static_scheduler_t;
    1616
     17/////////////////////////////////////////////////////////////////////////////////
     18//      Definition of the task context slots indexes
     19/////////////////////////////////////////////////////////////////////////////////
     20
     21#define CTX_SR_ID               0
     22#define CTX_SP_ID               29
     23#define CTX_RA_ID               31
     24
     25#define CTX_EPC_ID              32
     26#define CTX_CR_ID               33
     27#define CTX_PTPR_ID             35
     28#define CTX_MODE_ID             36
     29
     30#define CTX_TTY_ID              40
     31#define CTX_FBDMA_ID    41
     32#define CTX_PTAB_ID             42
     33#define CTX_TASK_ID             43
     34
     35
    1736//////////////////////////////////////////////////////////////////////////////////
    1837//      Prototype of the context switch function
  • soft/giet_vm/sys/drivers.c

    r166 r167  
    491491                          unsigned int  count )
    492492{
    493     unsigned int        user_vpn_min;
    494     unsigned int        user_vpn_max;
    495     unsigned int        vpn;                    // virtual page number in user space
    496     unsigned int        ppn;                    // physical page number
    497     unsigned int        flags;                  // page protection flags
    498     unsigned int        ix2;                    // Page index (for IOMMU page table)
    499     unsigned int        addr;                   // buffer address for IOC
    500     page_table_t*       user_ptp;               // user page table pointer
    501     unsigned int        ko;                             // bool returned by _v2p_translate()
    502     unsigned int        ppn_first;              // first physical page number for user buffer
     493    unsigned int                user_vpn_min;   // first virtuel page index in user space
     494    unsigned int                user_vpn_max;   // last virtual page index in user space
     495    unsigned int                vpn;                    // current virtual page index in user space
     496    unsigned int                ppn;                    // physical page number
     497    unsigned int                flags;                  // page protection flags
     498    unsigned int                ix2;                    // page index in IOMMU PT1 page table
     499    unsigned int                addr;                   // buffer address for IOC peripheral
     500    unsigned int                user_ptp;               // page table pointer in user space
     501    unsigned int                ko;                             // bool returned by _v2p_translate()
     502    unsigned int                ppn_first;              // first physical page number for user buffer
     503    unsigned int                ltid;                   // current task local index
     504    static_scheduler_t* psched;                 // pointer on the current task scheduler
    503505       
    504506    // check buffer alignment
     
    509511    unsigned int        length       = count*block_size;
    510512
    511     // get user space page table base address
    512     user_ptp     = (page_table_t*)(_get_ptpr() << 13);
     513    // get user space page table virtual address
     514    psched   = &_scheduler[_procid()];
     515    ltid     = psched->current;
     516    user_ptp = psched->context[ltid][CTX_PTAB_ID];
    513517   
    514518    user_vpn_min = user_vaddr >> 12;
     
    520524    {
    521525        // get ppn and flags for each vpn
    522         ko = _v2p_translate( user_ptp,  // user page table pointer
    523                              vpn,               // virtual page number
    524                              &ppn,              // physical page number
    525                              &flags );  // protection flags
     526        ko = _v2p_translate( (page_table_t*)user_ptp,
     527                             vpn,
     528                             &ppn,
     529                             &flags );
    526530
    527531        // check access rights
     
    543547                                                 ppn,                           // Physical page number
    544548                             flags );                   // Protection flags
    545 
    546             // buffer base address for IOC with IOMMU
    547549        }
    548550        else                    // no IOMMU : check that physical pages are contiguous
     
    563565    // compute buffer base address for IOC depending on IOMMU activation
    564566    if ( GIET_IOMMU_ACTIVE ) addr = (_ioc_iommu_ix1) << 21 | (user_vaddr & 0xFFF);
    565     else                     addr = ppn_first | (user_vaddr & 0xFFF);
     567    else                     addr = (ppn_first << 12) | (user_vaddr & 0xFFF);
    566568
    567569    // get the lock on ioc device
  • soft/giet_vm/sys/irq_handler.c

    r165 r167  
    2323///////////////////////////////////////////////////////////////////////////////////
    2424
    25 _isr_func_t _interrupt_vector[32] = { [0 ... 31] = &_isr_default };
     25__attribute__((section (".kdata"))) _isr_func_t _interrupt_vector[32] =
     26                                                  { [0 ... 31] = &_isr_default };
    2627
    2728///////////////////////////////////////////////////////////////////////////////////
  • soft/giet_vm/sys/kernel_init.c

    r166 r167  
    3131 
    3232///////////////////////////////////////////////////////////////////////////////////
     33// array of pointers on the page tables
     34// (both physical and virtual addresses)
     35///////////////////////////////////////////////////////////////////////////////////
     36
     37__attribute__((section (".kdata"))) unsigned int _kernel_ptabs_paddr[GIET_NB_VSPACE_MAX];
     38__attribute__((section (".kdata"))) unsigned int _kernel_ptabs_vaddr[GIET_NB_VSPACE_MAX];
     39
     40///////////////////////////////////////////////////////////////////////////////////
    3341// declarations required to avoid forward references
    3442///////////////////////////////////////////////////////////////////////////////////
    3543
    36 void    _kernel_vobjs_init(unsigned int*);
    37 void    _kernel_tasks_init(unsigned int*);
     44void    _kernel_vobjs_init(void);
     45void    _kernel_tasks_init(void);
    3846void    _kernel_peripherals_init(void);
    3947void    _kernel_interrupt_vector_init(void);
     
    4553in_kinit void _kernel_init()
    4654{
    47     // array of pointers on the page tables (used for task context initialisation)
    48     unsigned int        kernel_ptabs[GIET_NB_VSPACE_MAX];
    49 
    5055    // values to be written in registers
    5156    unsigned int        sp_value;
     
    5964    if ( pid == 0 )
    6065    {
    61         _kernel_vobjs_init(kernel_ptabs);
    62         _kernel_tasks_init(kernel_ptabs);
     66        _kernel_vobjs_init();
     67        _kernel_tasks_init();
    6368        _kernel_interrupt_vector_init();
    6469        _kernel_peripherals_init();
     
    163168// - ptpr   page table base address / 8K
    164169// - mode   mmu_mode = 0xF (TLBs and caches activated)
     170// - ptab   page table virtual address
    165171////////////////////////////////////////////////////////////////////////////////
    166172in_kinit void _task_map( unsigned int   task_id,    // global index
    167173                                         unsigned int   vspace_id,  // global index
    168174                         unsigned int   tty_id,         // TTY index
    169                          unsigned int   fb_id,          // FB index
    170                          unsigned int   pt_base )   // page table base adddress
     175                         unsigned int   fbdma_id )  // FBDMA index
    171176{
    172177    mapping_header_t*   header = (mapping_header_t*)&seg_mapping_base; 
     
    176181    mapping_vobj_t*     vobj   = _get_vobj_base( header );
    177182
     183   
    178184    // values to be initialised in task context
    179     unsigned int                ra = (unsigned int)&_eret;
     185    unsigned int                ra   = (unsigned int)&_eret;
    180186    unsigned int                sr   = 0x0000FF13;
    181187    unsigned int                tty  = tty_id;
    182     unsigned int                fb   = fb_id;   
    183     unsigned int                ptpr = pt_base >> 13;
     188    unsigned int                fb   = fbdma_id;         
     189    unsigned int                ptpr = _kernel_ptabs_paddr[vspace_id] >> 13;
     190    unsigned int                ptab = _kernel_ptabs_vaddr[vspace_id];
    184191    unsigned int                mode = 0xF;
    185192    unsigned int                sp;
    186193    unsigned int                epc;     
    187194
    188     // compute epc value
    189     // Get the (virtual) base address of the start_vector that
    190     // contains the start addresses for all tasks defined in a vspace.
     195    // EPC : Get the (virtual) base address of the start_vector containing
     196    // the start addresses for all tasks defined in a vspace.
    191197    mapping_vobj_t* vobj_data = &vobj[vspace[vspace_id].vobj_offset +
    192198                                      vspace[vspace_id].start_offset];
     
    194200    epc  = start_vector[task[task_id].startid];
    195201
    196     // compute sp value
    197     // Get the vobj containing the stack
     202    // SP :  Get the vobj containing the stack
    198203    unsigned int vobj_id = task[task_id].vobjlocid + vspace[vspace_id].vobj_offset;
    199204    sp = vobj[vobj_id].vaddr + vobj[vobj_id].length;
     
    220225    _scheduler[proc_id].context[ltid][CTX_RA_ID]    = ra;
    221226    _scheduler[proc_id].context[ltid][CTX_EPC_ID]   = epc;
     227    _scheduler[proc_id].context[ltid][CTX_PTPR_ID]  = ptpr;
     228    _scheduler[proc_id].context[ltid][CTX_MODE_ID]  = mode;
    222229    _scheduler[proc_id].context[ltid][CTX_TTY_ID]   = tty;
    223230        _scheduler[proc_id].context[ltid][CTX_FBDMA_ID] = fb;
    224     _scheduler[proc_id].context[ltid][CTX_PTPR_ID]  = ptpr;
    225     _scheduler[proc_id].context[ltid][CTX_MODE_ID]  = mode;
     231    _scheduler[proc_id].context[ltid][CTX_PTAB_ID]  = ptab;
    226232    _scheduler[proc_id].context[ltid][CTX_TASK_ID]  = task_id;
    227233   
    228 #if INIT_DEBUG
     234#if INIT_DEBUG_CTX
    229235_puts("Task ");
    230236_puts( task[task_id].name );
     
    259265_puts("\n");
    260266
     267_puts("  - PTPR        = ");
     268_putw( ptpr<<13 );
     269_puts("  saved at ");
     270_putw( (unsigned int)&_scheduler[proc_id].context[ltid][CTX_PTPR_ID] );
     271_puts("\n");
     272
    261273_puts("  - TTY         = ");
    262274_putw( tty );
     
    271283_puts("\n");
    272284
    273 _puts("  - PTPR        = ");
    274 _putw( ptpr<<13 );
    275 _puts("  saved at ");
    276 _putw( (unsigned int)&_scheduler[proc_id].context[ltid][CTX_PTPR_ID] );
     285_puts("  - PTAB        = ");
     286_putw( ptab );
     287_puts("  saved at ");
     288_putw( (unsigned int)&_scheduler[proc_id].context[ltid][CTX_PTAB_ID] );
    277289_puts("\n");
    278290#endif
     
    284296// such as mwmr channels, barriers and locks, depending on the vobj type.
    285297// (Most of the vobjs are not known, and not initialised by the compiler).
    286 // This function initialises the kernel_ptabs[] array indexed by the vspace_id,
    287 // and containint the base addresses of all page tables.
    288 // This kernel_ptabs[] array is used to initialise the task contexts.
     298// This function initialises the _kernel_ptabs_paddr[] array indexed by the vspace_id,
     299// and containing the base addresses of all page tables.
     300// This _kernel_ptabs_paddr[] array is used to initialise the task contexts.
    289301///////////////////////////////////////////////////////////////////////////////
    290 in_kinit void _kernel_vobjs_init( unsigned int* kernel_ptabs )
     302in_kinit void _kernel_vobjs_init()
    291303{
    292304    mapping_header_t*   header  = (mapping_header_t*)&seg_mapping_base; 
     
    302314        char ptab_found = 0;
    303315
    304 #if INIT_DEBUG
     316#if INIT_DEBUG_CTX
    305317_puts("[INIT] --- vobjs initialisation in vspace ");
    306318_puts(vspace[vspace_id].name);
     
    317329                {
    318330                    ptab_found = 1;
    319                     kernel_ptabs[vspace_id] = vobj[vobj_id].paddr;
    320 
    321 #if INIT_DEBUG
     331                    _kernel_ptabs_paddr[vspace_id] = vobj[vobj_id].paddr;
     332                    _kernel_ptabs_vaddr[vspace_id] = vobj[vobj_id].vaddr;
     333
     334#if INIT_DEBUG_CTX
    322335_puts("[INIT]   PTAB address = ");
    323 _putw(kernel_ptabs[vspace_id]);
     336_putw(_kernel_ptabs_paddr[vspace_id]);
    324337_puts("\n");
    325338#endif
     
    334347                    mwmr->depth = (vobj[vobj_id].length>>2) - 5;
    335348                    mwmr->lock  = 0;
    336 #if INIT_DEBUG
     349#if INIT_DEBUG_CTX
    337350_puts("[INIT]   MWMR channel ");
    338351_puts( vobj->name);
     
    346359                {
    347360
    348 #if INIT_DEBUG
     361#if INIT_DEBUG_CTX
    349362_puts("[INIT]   ELF section ");
    350363_puts( vobj->name);
     
    360373                    barrier->count = 0;
    361374                    barrier->init  = vobj[vobj_id].init;
    362 #if INIT_DEBUG
     375#if INIT_DEBUG_CTX
    363376_puts("   BARRIER ");
    364377_puts( vobj->name);
     
    373386                    unsigned int* lock = (unsigned int*)(vobj[vobj_id].vaddr);
    374387                    *lock = 0;
    375 #if INIT_DEBUG
     388#if INIT_DEBUG_CTX
    376389_puts("   LOCK ");
    377390_puts( vobj->name);
     
    383396                {
    384397
    385 #if INIT_DEBUG
     398#if INIT_DEBUG_CTX
    386399_puts("   BUFFER ");
    387400_puts( vobj->name);
     
    425438// TTY[0] is reserved for the kernel.
    426439///////////////////////////////////////////////////////////////////////////////
    427 in_kinit void _kernel_tasks_init(unsigned int* ptabs)
     440in_kinit void _kernel_tasks_init()
    428441{
    429442    mapping_header_t*   header  = (mapping_header_t*)&seg_mapping_base; 
     
    461474    {
    462475
    463 #if INIT_DEBUG
     476#if INIT_DEBUG_CTX
    464477_puts("\n[INIT] mapping tasks in vspace ");
    465478_puts(vspace[vspace_id].name);
     
    486499                       vspace_id,                       // vspace index
    487500                       tty_id,                          // global tty index
    488                        fb_id,                           // global fbdma index
    489                        ptabs[vspace_id] );      // page table pointer
     501                       fb_id );                         // global fbdma index
    490502        } // end loop on tasks
    491503    } // end oop on vspaces
     
    495507    _puts("\n");
    496508
    497 #if INIT_DEBUG
     509#if INIT_DEBUG_CTX
    498510for ( cluster_id = 0 ; cluster_id < header->clusters ; cluster_id++ )
    499511{
     
    540552    {
    541553        unsigned int*   iob_address = (unsigned int*)&seg_iob_base;
    542         unsigned int    icu_address = (unsigned int)&seg_icu_base;
    543554
    544555        // define IPI address mapping the IOC interrupt ...TODO...
  • soft/giet_vm/sys/mips32_registers.h

    r165 r167  
    7878#define CP2_DCACHE_INVAL_PA     $20
    7979
    80 /* Context index */
    81 
    82 #define CTX_SR_ID               0
    83 #define CTX_SP_ID               29
    84 #define CTX_RA_ID               31
    85 #define CTX_EPC_ID              32
    86 #define CTX_TTY_ID              34
    87 #define CTX_PTPR_ID             35
    88 #define CTX_MODE_ID             36
    89 #define CTX_FBDMA_ID    37
    90 #define CTX_TASK_ID             63
    91 
    92 
    9380#endif
  • soft/giet_vm/sys/sys.ld

    r166 r167  
    33*****************************************************************************/
    44
    5 /* The vsegs used by the system are replicated in all virtual spaces
     5/* The vsegs used by the system are mapped in all virtual spaces
    66   They can be identity mapping... or not */
    77
    88seg_kernel_code_base    = 0x80000000;   /* system code */
    99seg_kernel_data_base    = 0x80010000;   /* system cacheable data */
    10 seg_kernel_uncdata_base = 0x80020000;   /* system uncacheable data */
    11 seg_kernel_init_base    = 0x80030000;   /* system page table */
     10seg_kernel_uncdata_base = 0x80080000;   /* system uncacheable data */
     11seg_kernel_init_base    = 0x80090000;   /* system page table */
    1212seg_mapping_base            = 0xBFC0C000;       /* boot mapping_info */
    1313
     
    1616   must be defined, even if the peripherals are not used in the architecture */
    1717
    18 seg_tty_base            = 0x90000000;   /* TTY device */
    19 seg_timer_base          = 0x91000000;   /* Timer device */
    20 seg_ioc_base            = 0x92000000;   /* Block device */
    21 seg_dma_base            = 0x93000000;   /* DMA device */
    22 seg_gcd_base            = 0x95000000;   /* GCD device */
    23 seg_fb_base             = 0x96000000;   /* FrameBuffer device */
    24 seg_icu_base            = 0x9F000000;   /* ICU or XICU device */
    25 seg_iob_base            = 0x9E000000;   /* IOB device */
     18seg_tty_base                = 0x90000000;   /* TTY device */
     19seg_timer_base              = 0x91000000;   /* Timer device */
     20seg_ioc_base                = 0x92000000;   /* Block device */
     21seg_dma_base                = 0x93000000;   /* DMA device */
     22seg_gcd_base                = 0x95000000;   /* GCD device */
     23seg_fb_base                 = 0x96000000;   /* FrameBuffer device */
     24seg_iob_base                = 0x9E000000;   /* IOB device */
     25seg_icu_base                = 0x9F000000;   /* ICU or XICU device */
    2626
    2727/*
     
    4040    seg_kernel_data :
    4141    {
     42        *(.iommu)
     43        *(.kdata)
    4244        *(.rodata)
    43         /* . = ALIGN(4); */
    4445        *(.rodata.*)
    45         /* . = ALIGN(4); */
    4646        *(.data)
    47         /* . = ALIGN(4); */
    4847        *(.lit8)
    4948        *(.lit4)
    5049        *(.sdata)
    51         /* . = ALIGN(4); */
    5250        *(.bss)
    5351        *(COMMON)
  • soft/giet_vm/sys/sys_handler.c

    r165 r167  
    7575void _exit()
    7676{
     77    unsigned int date    = _proctime();
    7778    unsigned int proc_id = _procid();
    7879    unsigned int task_id = _scheduler[proc_id].current;
     
    8384    _puts(" on processor ");
    8485    _putw( proc_id );
     86    _puts(" at cycle ");
     87    _putw( date );
    8588    _puts("\n\n");
    8689
Note: See TracChangeset for help on using the changeset viewer.