L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
L4virtio::Driver::Block_device Class Reference

Simple class for accessing a virtio block device synchronously. More...

#include <virtio-block>

+ Inheritance diagram for L4virtio::Driver::Block_device:
+ Collaboration diagram for L4virtio::Driver::Block_device:

Data Structures

class  Handle
 Handle to an ongoing request. More...
 

Public Member Functions

void setup_device (L4::Cap< L4virtio::Device > srvcap, l4_size_t usermem, void **userdata, Ptr< void > &user_devaddr, L4::Cap< L4Re::Dataspace > qds=L4::Cap< L4Re::Dataspace >(), l4_uint32_t fmask0=-1U, l4_uint32_t fmask1=-1U)
 Establish a connection to the device and set up shared memory.
 
l4virtio_block_config_t const & device_config () const
 Return a reference to the device configuration.
 
Handle start_request (l4_uint64_t sector, l4_uint32_t type, Callback callback)
 Start the setup of a new request.
 
int add_block (Handle handle, Ptr< void > addr, l4_uint32_t size)
 Add a data block to a request that has already been set up.
 
int send_request (Handle handle)
 Process request asynchronously.
 
int process_request (Handle handle)
 Process request synchronously.
 
void process_used_queue ()
 Process and free all items in the used queue.
 
- Public Member Functions inherited from L4virtio::Driver::Device
void driver_connect (L4::Cap< L4virtio::Device > srvcap, bool manage_notify=true)
 Contacts the device and starts the initial handshake.
 
int bind_notification_irq (unsigned index, L4::Cap< L4::Triggerable > irq) const
 Register a triggerable to receive notifications from the device.
 
bool fail_state () const
 Return true if the device is in a fail state.
 
bool feature_negotiated (unsigned int feat) const
 Check if a particular feature bit was negotiated with the device.
 
int driver_acknowledge ()
 Finalize handshake with the device.
 
int register_ds (L4::Cap< L4Re::Dataspace > ds, l4_umword_t offset, l4_umword_t size, l4_uint64_t *devaddr)
 Share a dataspace with the device.
 
int config_queue (int num, unsigned size, l4_uint64_t desc_addr, l4_uint64_t avail_addr, l4_uint64_t used_addr)
 Send the virtqueue configuration to the device.
 
int max_queue_size (int num) const
 Maximum queue size allowed by the device.
 
int send_and_wait (Virtqueue &queue, l4_uint16_t descno)
 Send a request to the device and wait for it to be processed.
 
int wait (int index) const
 Wait for a notification from the device.
 
int wait_for_next_used (Virtqueue &queue, l4_uint32_t *len=nullptr) const
 Wait for the next item to arrive in the used queue and return it.
 
void send (Virtqueue &queue, l4_uint16_t descno)
 Send a request to the device.
 

Detailed Description

Simple class for accessing a virtio block device synchronously.

Definition at line 36 of file virtio-block.

Member Function Documentation

◆ add_block()

int L4virtio::Driver::Block_device::add_block ( Handle  handle,
Ptr< void >  addr,
l4_uint32_t  size 
)
inline

Add a data block to a request that has already been set up.

Parameters
handleHandle to request previously set up with start_request().
addrAddress of data block in device address space.
sizeSize of data block.
Return values
L4_OKBlock was successfully added.
-L4_EAGAINNo descriptors available. Try again later.

Definition at line 229 of file virtio-block.

References L4virtio::Virtqueue::Desc::addr, L4virtio::Driver::Virtqueue::alloc_descriptor(), L4virtio::Driver::Virtqueue::desc(), L4virtio::Virtqueue::Desc::flags, L4_EAGAIN, L4_EOK, L4virtio::Virtqueue::Desc::len, L4virtio::Virtqueue::Desc::Flags::next(), L4virtio::Virtqueue::Desc::next, L4virtio::Virtqueue::Desc::Flags::raw, l4virtio_block_header_t::type, and L4virtio::Virtqueue::Desc::Flags::write().

+ Here is the call graph for this function:

◆ process_request()

int L4virtio::Driver::Block_device::process_request ( Handle  handle)
inline

Process request synchronously.

Parameters
handleHandle to request to process.
Return values
L4_EOKRequest processed successfully.
-L4_EAGAINNo descriptors available. Try again later.
-L4_EIOIO error during request processing.
-L4_ENOSYSUnsupported request.
<0Another unspecified error occurred.

Sends a request to the driver that was previously set up with start_request() and add_block() and wait for it to be executed.

Definition at line 306 of file virtio-block.

References L4virtio::Virtqueue::Desc::addr, L4virtio::Driver::Virtqueue::alloc_descriptor(), L4virtio::Driver::Virtqueue::desc(), L4virtio::Virtqueue::Desc::flags, L4_EAGAIN, L4_EINVAL, L4_EIO, L4_ENOSYS, L4_EOK, L4VIRTIO_BLOCK_S_IOERR, L4VIRTIO_BLOCK_S_OK, L4VIRTIO_BLOCK_S_UNSUPP, L4virtio::Virtqueue::Desc::len, L4virtio::Virtqueue::Desc::Flags::next(), L4virtio::Virtqueue::Desc::next, L4virtio::Virtqueue::Desc::Flags::raw, L4virtio::Driver::Device::send_and_wait(), and L4virtio::Virtqueue::Desc::Flags::write().

+ Here is the call graph for this function:

◆ process_used_queue()

void L4virtio::Driver::Block_device::process_used_queue ( )
inline

Process and free all items in the used queue.

If the request has a callback registered it is called after the item has been removed from the queue.

Definition at line 357 of file virtio-block.

References L4Re::chksys(), L4virtio::Driver::Virtqueue::find_next_used(), L4_ENOSYS, and L4virtio::Virtqueue::num().

+ Here is the call graph for this function:

◆ send_request()

int L4virtio::Driver::Block_device::send_request ( Handle  handle)
inline

Process request asynchronously.

Parameters
handleHandle to request to send to the device
Return values
L4_OKRequest was successfully scheduled.
-L4_EAGAINNo descriptors available. Try again later.

Sends a request to the driver that was previously set up with start_request() and add_block() and wait for it to be executed.

Definition at line 265 of file virtio-block.

References L4virtio::Virtqueue::Desc::addr, L4virtio::Driver::Virtqueue::alloc_descriptor(), L4virtio::Driver::Virtqueue::desc(), L4virtio::Virtqueue::Desc::flags, L4_EAGAIN, L4_EOK, L4virtio::Virtqueue::Desc::len, L4virtio::Virtqueue::Desc::Flags::next(), L4virtio::Virtqueue::Desc::next, L4virtio::Virtqueue::Desc::Flags::raw, L4virtio::Driver::Device::send(), and L4virtio::Virtqueue::Desc::Flags::write().

+ Here is the call graph for this function:

◆ setup_device()

void L4virtio::Driver::Block_device::setup_device ( L4::Cap< L4virtio::Device srvcap,
l4_size_t  usermem,
void **  userdata,
Ptr< void > &  user_devaddr,
L4::Cap< L4Re::Dataspace qds = L4::Cap<L4Re::Dataspace>(),
l4_uint32_t  fmask0 = -1U,
l4_uint32_t  fmask1 = -1U 
)
inline

Establish a connection to the device and set up shared memory.

Parameters
srvcapIPC capability of the channel to the server.
usermemSize of additional memory to share with device.
[out]userdataPointer to the region of user-usable memory.
[out]user_devaddrAddress of user-usable memory in device address space.
qdsExternal queue dataspace. If this capability is invalid, the function will attempt to allocate a dataspace on its own. Note that the external queue dataspace must be large enough.
fmask0Feature bits 0..31 that the driver supports.
fmask1Feature bits 32..63 that the driver supports.

This function starts a handshake with the device and sets up the virtqueues for communication and the additional data structures for the block device. It will also allocate and share additional memory that the caller then can use freely, i.e. normally this memory would be used as a reception buffer. The caller may also decide to not make use of this convenience function and request 0 bytes in usermem. Then it has to allocate the block buffers for sending/receiving payload manually and share them using register_ds().

Definition at line 92 of file virtio-block.

References L4virtio::Virtqueue::avail_offset(), L4Re::chkcap(), L4Re::chksys(), L4virtio::Driver::Device::config_queue(), L4Re::Mem_alloc::Continuous, L4virtio::Driver::Device::driver_acknowledge(), L4virtio::Driver::Device::driver_connect(), L4Re::Env::env(), L4Re::Rm::Unique_region< T >::get(), L4virtio::Driver::Virtqueue::init_queue(), L4_EINVAL, L4_ENODEV, L4_PAGESHIFT, l4_round_page(), l4_round_size(), L4VIRTIO_ID_BLOCK, L4::Ipc::make_cap_rw(), L4virtio::Driver::Device::max_queue_size(), L4Re::Mem_alloc::Pinned, L4virtio::Driver::Device::register_ds(), L4Re::Rm::F::RW, L4Re::Rm::F::Search_addr, L4virtio::Virtqueue::total_size(), and L4virtio::Virtqueue::used_offset().

+ Here is the call graph for this function:

◆ start_request()

Handle L4virtio::Driver::Block_device::start_request ( l4_uint64_t  sector,
l4_uint32_t  type,
Callback  callback 
)
inline

Start the setup of a new request.

Parameters
sectorFirst sector to write to/read from.
typeRequest type.
callbackFunction to call, when the request is finished. May be 0 for synchronous requests.

Definition at line 191 of file virtio-block.

References L4virtio::Virtqueue::Desc::addr, L4virtio::Driver::Virtqueue::alloc_descriptor(), L4virtio::Driver::Virtqueue::desc(), L4virtio::Virtqueue::Desc::flags, l4virtio_block_header_t::ioprio, L4virtio::Virtqueue::Desc::len, L4virtio::Virtqueue::Desc::Flags::raw, l4virtio_block_header_t::sector, and l4virtio_block_header_t::type.

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: