| 1 | [wiki:Component SocLib Components General Index] |
| 2 | |
| 3 | = !VciBlockDevice = |
| 4 | |
| 5 | == 1) Functional Description == |
| 6 | |
| 7 | This VCI component is both a target and an initiator. |
| 8 | * It is addressed as a target to be configured for a transfer. |
| 9 | * It is acting as an initiator to do the transfer |
| 10 | |
| 11 | There is only one block device handled by this component, limited to 2^41 bytes. |
| 12 | An IRQ is optionally asserted when transfer is finished. |
| 13 | |
| 14 | This hardware component checks for segmentation violation, and can be used |
| 15 | as a default target. |
| 16 | |
| 17 | It contains the following memory-mapped registers: |
| 18 | |
| 19 | * `BLOCK_DEVICE_BUFFER` Physical address of the buffer in SoC memory |
| 20 | |
| 21 | * `BLOCK_DEVICE_COUNT` Count of blocks to transfer |
| 22 | |
| 23 | * `BLOCK_DEVICE_LBA` Base sector for transfer |
| 24 | |
| 25 | * `BLOCK_DEVICE_OP` Type of operation, writing here initiates the operation.[[BR]] |
| 26 | This register goes back to BLOCK_DEVICE_NOOP when operation is finished. |
| 27 | |
| 28 | * `BLOCK_DEVICE_STATUS` State of the transfer, -1 on failure |
| 29 | |
| 30 | * `BLOCK_DEVICE_IRQ_ENABLE` Boolean enabling the IRQ line |
| 31 | |
| 32 | * `BLOCK_DEVICE_SIZE` Number of blocks addressable in the controller (read-only) |
| 33 | |
| 34 | The following operations codes are defined: |
| 35 | |
| 36 | * `BLOCK_DEVICE_NOOP` Nothing |
| 37 | |
| 38 | * `BLOCK_DEVICE_READ` read() |
| 39 | |
| 40 | * `BLOCK_DEVICE_WRITE` write() |
| 41 | |
| 42 | For extensibility issues, you should access this component using globally-defined offsets. |
| 43 | You should include file `soclib/block_device.h` from your software, it |
| 44 | defines `BLOCK_DEVICE_COUNT`, `BLOCK_DEVICE_READ`, ... |
| 45 | |
| 46 | Sample code: |
| 47 | {{{ |
| 48 | #include "soclib/block_device.h" |
| 49 | |
| 50 | static const void* bd_base = 0xc0000000; |
| 51 | |
| 52 | |
| 53 | int block_read( const size_t lba, void *buffer, const size_t len ) |
| 54 | { |
| 55 | soclib_io_set(bd_base, BLOCK_DEVICE_LBA, lba); |
| 56 | soclib_io_set(bd_base, BLOCK_DEVICE_BUFFER, (uint32_t)buffer); |
| 57 | soclib_io_set(bd_base, BLOCK_DEVICE_COUNT, len); |
| 58 | soclib_io_set(bd_base, BLOCK_DEVICE_OP, BLOCK_DEVICE_READ); |
| 59 | while (soclib_io_get(bd_base, BLOCK_DEVICE_OP)) |
| 60 | ; |
| 61 | return soclib_io_get(bd_base, BLOCK_DEVICE_STATUS); |
| 62 | } |
| 63 | |
| 64 | int block_write( const size_t lba, const void *buffer, const size_t len ) |
| 65 | { |
| 66 | soclib_io_set(bd_base, BLOCK_DEVICE_LBA, lba); |
| 67 | soclib_io_set(bd_base, BLOCK_DEVICE_BUFFER, (uint32_t)buffer); |
| 68 | soclib_io_set(bd_base, BLOCK_DEVICE_COUNT, len); |
| 69 | soclib_io_set(bd_base, BLOCK_DEVICE_OP, BLOCK_DEVICE_WRITE); |
| 70 | while (soclib_io_get(bd_base, BLOCK_DEVICE_OP)) |
| 71 | ; |
| 72 | return soclib_io_get(bd_base, BLOCK_DEVICE_STATUS); |
| 73 | } |
| 74 | |
| 75 | uint32_t block_size() |
| 76 | { |
| 77 | return soclib_io_get(bd_base, BLOCK_DEVICE_SIZE); |
| 78 | } |
| 79 | |
| 80 | }}} |
| 81 | |
| 82 | (add -I/path/to/soclib/include to your compilation command-line) |
| 83 | |
| 84 | == 2) Component definition & usage == |
| 85 | |
| 86 | source:trunk/soclib/module/connectivity_component/vci_block_device/caba/metadata/vci_block_device.sd |
| 87 | |
| 88 | See [wiki:SoclibCc/VciParameters SoclibCc/VciParameters] |
| 89 | {{{ |
| 90 | Uses( 'vci_block_device', **vci_parameters ) |
| 91 | }}} |
| 92 | |
| 93 | == 3) CABA Implementation == |
| 94 | |
| 95 | === CABA sources === |
| 96 | |
| 97 | * interface : source:trunk/soclib/soclib/module/connectivity_component/vci_block_device/caba/source/include/vci_block_device.h |
| 98 | * implementation : source:trunk/soclib/soclib/module/connectivity_component/vci_block_device/caba/source/src/vci_block_device.cpp |
| 99 | |
| 100 | === CABA Constructor parameters === |
| 101 | |
| 102 | {{{ |
| 103 | VciBlockDevice( |
| 104 | sc_module_name name, // Component Name |
| 105 | const soclib::common::IntTab & index, // Target index |
| 106 | const soclib::common::MappingTable &mt, // MappingTable |
| 107 | const std::string &filename ) // mapped file, may be a host block device |
| 108 | }}} |
| 109 | |
| 110 | === CABA Ports === |
| 111 | |
| 112 | * sc_in<bool> '''p_resetn''' : Global system reset |
| 113 | * sc_in<bool> '''p_clk''' : Global system clock |
| 114 | * soclib::caba::!VciTarget<vci_param> '''p_vci_target''' : The VCI target port |
| 115 | * soclib::caba::!VciInitiator<vci_param> '''p_vci_initiator''' : The VCI initiator port |
| 116 | * sc_out<bool> '''p_irq''' : Interrupt port |
| 117 | |
| 118 | == 4) TLM-T Implementation == |
| 119 | |
| 120 | The TLM-T implementation is not yet available. |