wiki:hba_driver

Version 11 (modified by alain, 10 years ago) (diff)

--

GIET-VM / HBA Driver

The hba_driver.c and hba_driver.h files define the HBA driver.

The vci_multi_ahci component is a multi-channels, block oriented, external mass storage controller respecting the AHCI standard. Each channel define an independant physical disk, but this driver supports only one channel, because the GIET-VM uses only one physical disk.

The Command List is a software FIFO that can contain up to 32 independant commands, posted by different user tasks. These independant transfers are handled by the HBA device in the same order as they have been written in the command list. There is no global lock protecting the the HBA device, but the command list being a shared structure, the driver uses a ptw pointer on the next free slot in the command list, and uses an _atomic_increment() to increment this ptw pointer.

This driver implements two operating mode:

  • In synchronous mode, the calling task uses a polling strategy on the HBA_PXCI register to detect the command completion (busy waiting). It does not use interrupt. This mode is used by the boot code to load the map.bin file into memory (before MMU activation), or to load the .elf files (after MMU activation).
  • In descheduling mode, the calling task is descheduled, and the calling task global index is saved in the _hba_gtid[32] array, indexed by the command index. The task must be reactivated when the command is completed. This mode is used, to handle the user system calls.

As several user tasks can concurrently register commands in the command list, and there is only one HBA interrupt per channel, this interrupt is not linked to a specific command. In descheduling mode, the HBA IRQ is a "global" IRQ that is statically routed to processor P[0,0,0]. The associated global HBA_ISR send a WAKUP WTI to all tasks that have a completed command. This HBA_ISR uses a ptr pointer on the first active command in the Command List to identify the completed commands. The incrementation of this ptr pointer does not require _atomic_increment() as there is no concurrent access on this pointer.

The SEG_IOC_BASE address must be defined in the hard_config.h file.

The addressable registers map is defined here.

Software data structures

The HBA component support split memory buffers (several physical buffers for one single command), but this driver supports only one single buffer commands, because a contiguous buffer in virtual space is also contiguous in physical space. This is a nice property of the the static memory allocation policy implemented by the GIET_VM.

There exist 32 command tables associated to the 32 commands in the command list, and each command table occupies only 32 bytes.

Command List

The command List is an array of 32 Command Descriptors. Each Command Descriptor occupies 16 bytes, and is aligned on a 16 bytes boundary.

typedef struct hba_cmd_desc_s  // size = 16 bytes
{
    unsigned char       flag[2];            // W in bit 6 of flag[0]
    unsigned char       prdtl[2];           // Number of buffers
    unsigned int        prdbc;              // Number of bytes actually transfered
    unsigned int        ctba;               // Command Table base address 32 LSB bits
    unsigned int        ctbau;              // Command Table base address 32 MSB bits
} hba_cmd_desc_t;

Command Table

The GIET_VM define an array of 32 Command Tables. A Command Table contains one header, and one Buffer Descriptor. Each Command Table occupies 32 bytes, and is aligned on a 32 bytes boundary.

typedef struct hba_cmd_header_s // size = 16 bytes
{
    unsigned int           res0;       // reserved	
    unsigned char          lba0;       // LBA 7:0
    unsigned char          lba1;       // LBA 15:8
    unsigned char          lba2;       // LBA 23:16
    unsigned char          res1;       // reserved
    unsigned char          lba3;       // LBA 31:24
    unsigned char          lba4;       // LBA 39:32
    unsigned char          lba5;       // LBA 47:40
    unsigned char          res2;       // reserved
    unsigned int           res3;       // reserved	
} hba_cmd_header_t;

typedef struct hba_cmd_buffer_s  // size = 16 bytes
{
    unsigned int        dba;	      // Buffer base address 32 LSB bits
    unsigned int        dbau;         // Buffer base address 32 MSB bits
    unsigned int        res0;	      // reserved
    unsigned int        dbc;	      // Buffer byte count
} hba_cmd_buffer_t;

typedef struct hba_cmd_table_s  // size = 32 bytes
{
    hba_cmd_header_t   header;     // contains LBA
    hba_cmd_buffer_t   buffer;     // only one physical buffer
} hba_cmd_table_t;

Access Functions

unsigned int _hba_init ( )

This function checks the block size and desactivates interrupts. It initializes the HBA hardware registers, and the Command List.that is statically routed to processor P[x_io,y_io,0] in cluster_io. The associated global HBA_ISR send a WAKUP WTI to all tasks that have a completed command. This HBA_ISR uses a read pointer on the command to identify the first expected command completion. The incrementation of this read pointer does

Access Functions

unsigned int _hba_init ( )

This function checks the block size and desactivates interrupts. It initializes the HBA hardware registers, and the Command List. Return 0 for success, > 0 if error.

unsigned int _hba_access( unsigned int use_irq , unsigned int to_mem , unsigned int lba , unsigned long long paddr, unsigned int count )

This function register a command in the Command List (and associated Command Table) for a single physical buffer, and updates the HBA_PXCI register.

  • use_irq: Boolean => request to use the descheduling mode if non zero
  • to_mem : Boolean => to memory transfer if non zero
  • lba : logic bloc address on device
  • paddr : memory buffer physical base address
  • count : number of blocs

Returns 0 if success, > 0 if error.

void _hba_isr( unsigned int irq_type , unsigned int irq_id , unsigned int channel )

This Interrupt Service routine is only used in the descheduling mode. It analyses the HBA_PXCI register, and for all completed commands, it saves the status value in the _hba_status[32] array, indexed by the command index, and activates the task waiting completion of this command.

  • irq_type : HWI / PTI / WTI
  • irq-id : index returned by XCU
  • channel : unused (only one HBA channel is supported).