L4Re Operating System Framework
Interface and Usage Documentation
|
Driver-side implementation of a Virtqueue. More...
#include <virtqueue>
Public Member Functions | |
void | initialize_rings (unsigned num) |
Initialize the descriptor table and the index structures of this queue. | |
void | init_queue (unsigned num, void *desc, void *avail, void *used) |
Initialize this virtqueue. | |
void | init_queue (unsigned num, void *base) |
Initialize this virtqueue. | |
l4_uint16_t | alloc_descriptor () |
Allocate and return an unused descriptor from the descriptor table. | |
void | enqueue_descriptor (l4_uint16_t descno) |
Enqueue a descriptor in the available ring. | |
Desc & | desc (l4_uint16_t descno) |
Return a reference to a descriptor in the descriptor table. | |
l4_uint16_t | find_next_used (l4_uint32_t *len=nullptr) |
Return the next finished block. | |
void | free_descriptor (l4_uint16_t head, l4_uint16_t tail) |
Free a chained list of descriptors in the descriptor queue. | |
Public Member Functions inherited from L4virtio::Virtqueue | |
void | disable () |
Completely disable the queue. | |
unsigned long | total_size () const |
Calculate the total size of this virtqueue. | |
unsigned long | avail_offset () const |
Get the offset of the available ring from the descriptor table. | |
unsigned long | used_offset () const |
Get the offset of the used ring from the descriptor table. | |
void | setup (unsigned num, void *desc, void *avail, void *used) |
Enable this queue. | |
void | setup_simple (unsigned num, void *ring) |
Enable this queue. | |
void | dump (Desc const *d) const |
Dump descriptors for this queue. | |
bool | ready () const |
Test if this queue is in working state. | |
unsigned | num () const |
bool | no_notify_guest () const |
Get the no IRQ flag of this queue. | |
bool | no_notify_host () const |
Get the no notify flag of this queue. | |
void | no_notify_host (bool value) |
Set the no-notify flag for this queue. | |
l4_uint16_t | get_avail_idx () const |
Get available index from available ring (for debugging). | |
l4_uint16_t | get_tail_avail_idx () const |
Get tail-available index stored in local state (for debugging). | |
Additional Inherited Members | |
Public Types inherited from L4virtio::Virtqueue | |
enum | |
Fixed alignment values for different parts of a virtqueue. | |
Static Public Member Functions inherited from L4virtio::Virtqueue | |
static unsigned long | total_size (unsigned num) |
Calculate the total size for a virtqueue of the given dimensions. | |
static unsigned long | desc_size (unsigned num) |
Calculate the size of the descriptor table for num entries. | |
static unsigned long | desc_align () |
Get the alignment in zero LSBs needed for the descriptor table. | |
static unsigned long | avail_size (unsigned num) |
Calculate the size of the available ring for num entries. | |
static unsigned long | avail_align () |
Get the alignment in zero LSBs needed for the available ring. | |
static unsigned long | used_size (unsigned num) |
Calculate the size of the used ring for num entries. | |
static unsigned long | used_align () |
Get the alignment in zero LSBs needed for the used ring. | |
Protected Member Functions inherited from L4virtio::Virtqueue | |
Virtqueue ()=default | |
Create a disabled virtqueue. | |
Protected Attributes inherited from L4virtio::Virtqueue | |
Desc * | _desc = nullptr |
pointer to descriptor table, NULL if queue is off. | |
Avail * | _avail = nullptr |
pointer to available ring. | |
Used * | _used = nullptr |
pointer to used ring. | |
l4_uint16_t | _current_avail = 0 |
The life counter for the queue. | |
l4_uint16_t | _idx_mask = 0 |
mask used for indexing into the descriptor table and the rings. | |
Driver-side implementation of a Virtqueue.
Adds function for managing the descriptor list, enqueueing new and dequeueing finished requests.
|
inline |
Allocate and return an unused descriptor from the descriptor table.
The descriptor will be removed from the free list, the content should be considered undefined. After use, it needs to be freed using free_descriptor().
Note: the implementation uses (2^16 - 1) as the end of queue marker. That means that the final entry in the queue can not be allocated iff the queue size is 2^16.
Definition at line 564 of file virtqueue.
References L4virtio::Virtqueue::_desc, and L4virtio::Virtqueue::Desc::next.
Referenced by L4virtio::Driver::Block_device::add_block(), L4virtio::Driver::Block_device::process_request(), L4virtio::Driver::Virtio_net_device::queue_rx(), L4virtio::Driver::Block_device::send_request(), L4virtio::Driver::Block_device::start_request(), and L4virtio::Driver::Virtio_net_device::tx().
|
inline |
Return a reference to a descriptor in the descriptor table.
descno | Index of the descriptor, expected to be in correct range. |
Definition at line 596 of file virtqueue.
References L4virtio::Virtqueue::_desc, and L4virtio::Virtqueue::_idx_mask.
Referenced by L4virtio::Driver::Block_device::add_block(), init_queue(), L4virtio::Driver::Block_device::process_request(), L4virtio::Driver::Block_device::send_request(), L4virtio::Driver::Virtio_net_device::setup_device(), L4virtio::Driver::Block_device::start_request(), and L4virtio::Driver::Virtio_net_device::tx().
|
inline |
Enqueue a descriptor in the available ring.
descno | Index of the head descriptor to enqueue. |
Definition at line 580 of file virtqueue.
References L4virtio::Virtqueue::_avail, L4virtio::Virtqueue::_idx_mask, L4virtio::Virtqueue::Avail::idx, and L4virtio::Virtqueue::Avail::ring.
Referenced by L4virtio::Driver::Virtio_net_device::queue_rx(), and L4virtio::Driver::Device::send().
|
inline |
Return the next finished block.
[out] | len | (optional) Size of valid data in finished block. Note that this is the value reported by the device, which may set it to a value that is larger than the original buffer size. |
Definition at line 615 of file virtqueue.
References L4virtio::Virtqueue::_current_avail, L4virtio::Virtqueue::_idx_mask, L4virtio::Virtqueue::_used, L4virtio::Virtqueue::Used::idx, L4virtio::Virtqueue::Used_elem::len, and L4virtio::Virtqueue::Used::ring.
Referenced by L4virtio::Driver::Block_device::process_used_queue(), and L4virtio::Driver::Device::wait_for_next_used().
|
inline |
Free a chained list of descriptors in the descriptor queue.
head | Index of the first element in the descriptor chain. |
tail | Index of the last element in the descriptor chain. |
Simply takes the descriptor chain and prepends it to the beginning of the free list. Assumes that the list has been correctly chained.
Definition at line 637 of file virtqueue.
References L4virtio::Virtqueue::_desc, L4virtio::Virtqueue::_idx_mask, and L4virtio::Virtqueue::Desc::next.
Referenced by L4virtio::Driver::Virtio_net_device::finish_rx().
|
inline |
Initialize this virtqueue.
num | The number of entries in the descriptor table, the available ring, and the used ring (must be a power of 2). |
base | The base address for the queue data structure. |
This function sets up the memory and initializes the freelist.
Definition at line 543 of file virtqueue.
References initialize_rings(), L4virtio::Virtqueue::num(), and L4virtio::Virtqueue::setup_simple().
|
inline |
Initialize this virtqueue.
num | The number of entries in the descriptor table, the available ring, and the used ring (must be a power of 2). |
desc | The address of the descriptor table. (Must be Desc_align aligned and at least desc_size(num) bytes in size.) |
avail | The address of the available ring. (Must be Avail_align aligned and at least avail_size(num) bytes in size.) |
used | The address of the used ring. (Must be Used_align aligned and at least used_size(num) bytes in size.) |
This function sets up the memory and initializes the freelist.
Definition at line 528 of file virtqueue.
References desc(), initialize_rings(), L4virtio::Virtqueue::num(), and L4virtio::Virtqueue::setup().
Referenced by L4virtio::Driver::Virtio_net_device::setup_device(), and L4virtio::Driver::Block_device::setup_device().
|
inline |
Initialize the descriptor table and the index structures of this queue.
num | The number of entries in the descriptor table, the available ring, and the used ring (must be a power of 2). |
Definition at line 500 of file virtqueue.
References L4virtio::Virtqueue::_avail, L4virtio::Virtqueue::_desc, L4virtio::Virtqueue::_used, L4virtio::Virtqueue::Avail::idx, L4virtio::Virtqueue::Used::idx, L4virtio::Virtqueue::Desc::next, and L4virtio::Virtqueue::num().
Referenced by init_queue(), and init_queue().