Ignore:
Timestamp:
Sep 29, 2014, 12:02:13 PM (10 years ago)
Author:
alain
Message:

Introducing support for the PIC_MASK register in pic_driver.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/giet_drivers/ioc_driver.c

    r350 r413  
    66// Copyright (c) UPMC-LIP6
    77///////////////////////////////////////////////////////////////////////////////////
    8 // The ioc_driver.c and ioc_driver.h files are part ot the GIET-VM kernel.
     8// Implementation note:
    99//
    10 // This abstact driver define a generic API, supporting various physical
    11 // block device controlers, including:
    12 // - vci_block_device : single channel)                    => bdv_driver
    13 // - vci_ahci         : multi channels                     => hba_driver
    14 // - sd_card          : single channel                     => sdc_driver
    15 // - ramdisk (single channel meory mapped virtual disk)    => rdk_driver
     10// 1) In order to share the code, the two _ioc_read() and _ioc_write() functions
     11// call the same _ioc_access() function.
    1612//
    17 // It can exist only one block-device type in the architecture, that must be
    18 // defined by one of the following configuration variables in hard_config.h file:
    19 // USE_IOC_BDV, USE_IOC_SDC, USE_IOC_HBA, USE_IOC_RDK.
    20 //
    21 // Any physical driver xxx must provide the following API:
    22 // - _xxx_init()
    23 // - _xxx_read()
    24 // - _xxx_write()
    25 // - _xxx_get_status()
    26 // - _xxx_get_block_size()
    27 // The "channel" parameter is no transmited to single channel devices.
    28 //
    29 // The _ioc_read() and _ioc_write() functions are always blocking for
    30 // the calling user program.
    31 //
    32 // These functions compute the physical address of the memory buffer before
    33 // calling the proper physical device. They can be called in 3 modes:
    34 //
    35 // - In BOOT mode, these functions use the buffer virtual address
    36 //   as a physical address if the MMU is not activated.
    37 //   They make a V2P translation if the MMU is activated.
    38 //   This mode is used to load the map.bin file (before memory activation),
    39 //   or to load the various .elf files (after MMU activation).
    40 //
    41 // - In KERNEL mode, these functions make a V2P translation to
    42 //   compute the buffer physical address.
    43 //   There is no checking of user access right to the memory buffer. 
    44 //   This mode must be used for an "open" system call.
    45 //
    46 // - In USER mode, these functions make a V2P translation to
    47 //   compute the buffer physical address.
    48 //   The user access right to the memory buffer are checked. 
    49 //   This mode must be used for a "read" or "write" system call.
    50 //
    51 // The IOMMU can be activated or not:
    52 //
    53 // 1) When the IOMMU is used, a fixed size 2Mbytes vseg is allocated to
    54 // the IOC peripheral, in the I/O virtual space, and the user buffer is
    55 // dynamically remapped in the IOMMU page table. The corresponding entry
    56 // in the IOMMU PT1 is defined by the kernel _ioc_iommu_ix1 variable.
    57 // The number of pages to be unmapped is stored in the _ioc_npages variable.
    58 // The number of PT2 entries is dynamically computed and stored in the
    59 // kernel _ioc_iommu_npages variable. It cannot be larger than 512.
     13// 2) The IOMMU is not supported yet, but the method is the following:
     14// A fixed size 2 Mbytes vseg is allocated to the IOC peripheral, in the I/O
     15// virtual space, and the user buffer is dynamically remapped to one single
     16// big page in the IOMMU page table.
    6017// The user buffer is unmapped by the _ioc_completed() function when
    6118// the transfer is completed.
    62 //
    63 // 2/ If the IOMMU is not used, we check that  the user buffer is mapped to a
    64 // contiguous physical buffer (this is generally true because the user space
    65 // page tables are statically constructed to use contiguous physical memory).
    66 //
    67 // Finally, the memory buffer must fulfill the following conditions:
    68 // - The buffer must be word aligned,
    69 // - The buffer must be mapped in user space for an user access,
    70 // - The buffer must be writable in case of (to_mem) access,
    71 // - The total number of physical pages occupied by the user buffer cannot
    72 //   be larger than 512 pages if the IOMMU is activated,
    73 // - All physical pages occupied by the user buffer must be contiguous
    74 //   if the IOMMU is not activated.
    75 // An error code is returned if these conditions are not verified.
    76 //
    77 // The SEG_IOC_BASE virtual base address must be defined in hard_config.h,
    78 // as it is used by the BDV, HBA and SPI drivers.
    79 //
    80 // If the RAMDISK is used, an extra memory segment with virtual base address
    81 // SEG_RDK_BASE, used by RDK driver, must be defined in hard_config.h.
    82 ///////////////////////////////////////////////////////////////////////////////////
    83 // Implementation note:
    84 // In order to share the code, the two _ioc_read() and _ioc_write() functions
    85 // call the same _ioc_access() function.
    8619///////////////////////////////////////////////////////////////////////////////////
    8720
     
    16699unsigned int y       = cid & ((1<<Y_WIDTH) - 1);
    167100
    168 _printf("\n[IOC DEBUG] Processor[%d,%d,%d] enters _ioc_access() at cycle %d\n"
     101_printf("\n[IOC DEBUG] _ioc_access() : P[%d,%d,%d] enters at cycle %d\n"
    169102        " - channel  = %d\n"
    170103        " - mode     = %d\n"
     
    177110    unsigned int error;            // return value
    178111    unsigned int pt_vbase;         // page table vbase address
    179     unsigned int vpn_min;          // first virtuel page index covering buffer
    180     unsigned int vpn_max;          // last virtual page index covering buffer
    181     unsigned int vpn;              // current virtual page index
    182     unsigned int ppn;              // physical page number
    183     unsigned int flags;            // page protection flags
    184     unsigned int ix2;              // page index in IOMMU PT1 page table
    185     unsigned int ppn_first = 0;    // first physical page number for user buffer
    186     unsigned int buf_xaddr = 0;    // user buffer virtual address in IO space (if IOMMU)
    187     paddr_t      buf_paddr = 0;    // user buffer physical address (if no IOMMU),
     112    unsigned int ppn;              // user buffer first page PPN
     113    unsigned int flags;            // user buffer protection flags
     114    paddr_t      buf_paddr;        // user buffer physical address (if no IOMMU),
    188115
    189116    // check buffer alignment
    190117    if ((unsigned int) buf_vaddr & 0x3)
    191118    {
    192         _printf("\n[GIET ERROR] in _ioc_access() : buffer not word aligned\n");
     119        _printf("\n[IOC ERROR] in _ioc_access() : buffer not word aligned\n");
    193120        _exit();
    194121    }
     
    197124    if ( (USE_IOC_HBA == 0) && (channel > 0) )
    198125    {
    199         _printf("\n[GIET ERROR] in _ioc_access() : channel must be 0 when HBA not used\n");
     126        _printf("\n[IOC ERROR] in _ioc_access() : channel must be 0 when HBA not used\n");
    200127        _exit();
    201128    }
     
    212139        // get page table virtual address
    213140        pt_vbase = _get_context_slot(CTX_PTAB_ID);
    214         vpn_min  = buf_vaddr >> 12;
    215         vpn_max  = (buf_vaddr + length - 1) >> 12;
    216 
    217         // loop on all virtual pages covering the user buffer
    218         for (vpn = vpn_min, ix2 = 0 ; vpn <= vpn_max ; vpn++, ix2++ )
     141
     142        // get user buffer first page ppn and flags
     143        unsigned int ko = _v2p_translate( (page_table_t*)pt_vbase,
     144                                           buf_vaddr >> 12,
     145                                           &ppn,
     146                                           &flags );
     147        // check access rights
     148        if ( ko )
    219149        {
    220             // get ppn and flags for each vpn
    221             unsigned int ko = _v2p_translate( (page_table_t*)pt_vbase,
    222                                               vpn,
    223                                               &ppn,
    224                                               &flags);
    225             // check access rights
    226             if ( ko )
    227             {
    228                 _printf("\n[GIET ERROR] in _ioc_access() : buffer unmapped\n");
    229                 return 1;
    230             }
    231 
    232             if ( (mode == IOC_USER_MODE) && ((flags & PTE_U) == 0) )
    233             {
    234                 _printf("\n[GIET ERROR] in _ioc_access() : buffer not user accessible\n");
    235                 return 1;
    236             }
    237 
    238             if ( ((flags & PTE_W) == 0 ) && to_mem )
    239             {
    240                 _printf("\n[GIET ERROR] in _ioc_access() : buffer not writable\n");
    241                 return 1;
    242             }
    243 
    244             // save first ppn value
    245             if (ix2 == 0) ppn_first = ppn;
    246 
    247 #if GIET_USE_IOMMU
    248  
    249             // check buffer length < 2 Mbytes
    250             if (ix2 > 511) // check buffer length < 2 Mbytes
    251             {
    252                 _printf("\n[GIET ERROR] in _ioc_access() : user buffer > 2 Mbytes\n");
    253                 return 1;
    254             }
    255             // map the physical page in IOMMU page table
    256             _iommu_add_pte2( _ioc_iommu_ix1,    // PT1 index
    257                              ix2,               // PT2 index
    258                              ppn,               // Physical page number   
    259                              flags );           // Protection flags
    260 
    261             // compute user buffer virtual adress in IO space
    262             buf_xaddr = (_ioc_iommu_ix1) << 21 | (buf_vaddr & 0xFFF);
    263 
    264 #else
    265 
    266             // check that physical pages are contiguous
    267             if ((ppn - ppn_first) != ix2)
    268             {
    269                 _printf("[GIET ERROR] in _ioc_access() : split physical buffer\n");
    270                 return 1;
    271             }
    272 
    273             // compute user buffer physical adress
    274             buf_paddr = (((paddr_t)ppn_first) << 12) | (buf_vaddr & 0xFFF);
    275 #endif           
    276 
    277         } // end for vpn
    278     }
    279 
    280 #if GIET_USE_IOMMU
    281 
    282     // register the number of pages to be unmapped in IOMMU
    283     _ioc_iommu_npages = (vpn_max - vpn_min) + 1;
    284 
    285 #endif
     150            _printf("\n[IOC ERROR] in _ioc_access() : buffer unmapped\n");
     151            _exit();
     152        }
     153
     154        if ( (mode == IOC_USER_MODE) && ((flags & PTE_U) == 0) )
     155        {
     156            _printf("\n[IOC ERROR] in _ioc_access() : buffer not user accessible\n");
     157            _exit();
     158        }
     159
     160        if ( ((flags & PTE_W) == 0 ) && to_mem )
     161        {
     162            _printf("\n[IOC ERROR] in _ioc_access() : buffer not writable\n");
     163            _exit();
     164        }
     165
     166        buf_paddr = (((paddr_t)ppn) << 12) | (buf_vaddr & 0xFFF);
     167    }
     168
     169    // cache coherence for both L1 & L2 caches
    286170
    287171    if ( to_mem ) // memory write : invalidate data caches
    288172    {
    289         // L1 cache
    290         if ( GIET_NO_HARD_CC ) _dcache_buf_invalidate((void *) buf_vaddr, length);
    291 
    292         // L2 cache (only if IOB used)
     173        // L1 cache (only if L1 cache coherence not guaranteed by hardware)
     174        if ( GIET_NO_HARD_CC ) _dcache_buf_invalidate( buf_vaddr, length );
     175
     176        // L2 cache (only if we use an IO-Bridge component in architecture))
    293177        if ( USE_IOB ) _mmc_inval( buf_paddr, length );
    294178    }
     
    297181        // L1 cache : nothing to do for L1 write-through
    298182
    299         // L2 cache (only if IOB used)
     183        // L2 cache (only if we use an IO-Bridge component in architecture))
    300184        if ( USE_IOB ) _mmc_sync( buf_paddr, length );
    301185    }
    302186
    303     if ( GIET_USE_IOMMU ) buf_paddr = (paddr_t) buf_xaddr;
    304 
    305     ///////////////////////////////////////////
    306187    // select the proper physical device
    307     ///////////////////////////////////////////
    308 
    309 #if       ( USE_IOC_BDV )
     188
     189#if   ( USE_IOC_BDV )
    310190        if (to_mem) error = _bdv_read ( mode, lba, buf_paddr, count);
    311191        else        error = _bdv_write( mode, lba, buf_paddr, count);
     
    324204} // end _ioc_access()
    325205
    326 ///////////////////////////////////////////////////////////////////////////////
    327 // This function cheks block size, and desactivates the IOC interrupts.
    328 // Return 0 for success.
    329 ///////////////////////////////////////////////////////////////////////////////
     206//////////////////////////////////////////////
    330207unsigned int _ioc_init( unsigned int channel )
    331208{
     
    351228}
    352229
    353 ///////////////////////////////////////////////////////////////////////////////
    354 // Transfer data from the block device to a memory buffer.
    355 // - mode     : BOOT_PA / BOOT_VA / KERNEL / USER
    356 // - lba      : first block index on the block device
    357 // - buffer   : base address of the memory buffer (must be word aligned)
    358 // - count    : number of blocks to be transfered.
    359 // Returns 0 if success, > 0 if error.
    360 ///////////////////////////////////////////////////////////////////////////////
     230//////////////////////////////////////////////
    361231unsigned int _ioc_read( unsigned int channel,
    362232                        unsigned int mode, 
     
    373243}
    374244
    375 ///////////////////////////////////////////////////////////////////////////////
    376 // Transfer data from a memory buffer to the block device.
    377 // - mode     : BOOT_PA / BOOT_VA / KERNEL / USER
    378 // - lba      : first block index on the block device
    379 // - buffer   : base address of the memory buffer (must be word aligned)
    380 // - count    : number of blocks to be transfered.
    381 // Returns 0 if success, > 0 if error.
    382 ///////////////////////////////////////////////////////////////////////////////
     245//////////////////////////////////////////////
    383246unsigned int _ioc_write( unsigned int channel,
    384247                         unsigned int mode, 
     
    395258}
    396259
    397 ///////////////////////////////////////////////////////////////////////////////
    398 // This function returns in the status variable, the transfert status, and
    399 // acknowledge the IRQ if the IOC controler is not busy.
    400 // Returns 0 if success, > 0 if error
    401 ///////////////////////////////////////////////////////////////////////////////
     260/////////////////////////////////////////////////////
    402261unsigned int _ioc_get_status( unsigned int  channel )
    403262{
     
    427286}
    428287
    429 ///////////////////////////////////////////////////////////////////////////////
    430 // This function returns the block_size with which the IOC has been configured.
    431 ///////////////////////////////////////////////////////////////////////////////
     288//////////////////////////////////
    432289unsigned int _ioc_get_block_size()
    433290{
Note: See TracChangeset for help on using the changeset viewer.