wiki:bdv_driver

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

--

GIET-VM / BDV Driver

The bdv_driver.c and bdv_driver.h files define the BDV driver.

This component is a single channel, block oriented, external mass storage peripheral, available in the SoCLib components library.

This driver is called by the generic FAT handler when the USE_IOC_BDV flag is set in the hard_config.h file.

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

The _bdv_read() and _bdv_write() functions are always blocking. They can be called in 2 modes:

  • In synchronous mode, these functions use a polling policy on the BDV STATUS register to detect transfer completion, as interrupts are not activated. 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, these functions use a descheduling plus IRQ strategy: The ISR executed when transfer completes should restart the calling task. This mode must be used, to handle the user system calls. The _bdv_gtid global variable register the calling task global index.

The BDV component is single channel, but can be used by several programs running in parallel, as the _bdv_lock global variable guaranties exclusive access to the device. The _bdv_read() and _bdv_write() functions use atomic LL/SC to get the lock.

The addressable registers map, the operation codes, and the status values are defined here.

unsigned int _bdv_init()

This function cheks block size == 512, and desactivates the interrupts. Return 0 for success, > 0 if error

unsigned int _bdv_access( unsigned int use_irq , unsigned int to_mem , unsigned int lba , unsigned long long buffer , unsigned int count )

This function transfer data from the block device to a memory buffer.

  • use_irq : Boolean => descheduling mode when non zero.
  • to_mem : Boolean => to memory transfer when non zero.
  • lba : first block index on the block device
  • buffer : physical base address of the memory buffer (word aligned)
  • count : number of blocks to be transfered.

Returns 0 if success, > 0 if error.

void _bdv_isr( unsigned irq_type, unsigned irq_id, unsigned channel )

This Interrupt Service Routine save the status register value in the _bdv_status global variable, acknowledge the IRQ, and activates the task waiting on IO transfer. It can be an HWI or a SWI.

  • irq_type : HWI / PTI / WTI
  • irq-id : index returned by ICU/XCU
  • channel : unused (block-device peripheral is single channel).