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

Driver-side implementation of a Virtqueue. More...

#include <virtqueue>

+ Inheritance diagram for L4virtio::Driver::Virtqueue:
+ Collaboration diagram for L4virtio::Driver::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.
 
Descdesc (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.
 

Detailed Description

Driver-side implementation of a Virtqueue.

Adds function for managing the descriptor list, enqueueing new and dequeueing finished requests.

Note
The Virtqueue implementation is not thread-safe.

Definition at line 476 of file virtqueue.

Member Function Documentation

◆ alloc_descriptor()

l4_uint16_t L4virtio::Driver::Virtqueue::alloc_descriptor ( )
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().

Returns
The index of the reserved descriptor or Virtqueue::Eoq if no free descriptor is available.

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().

+ Here is the caller graph for this function:

◆ desc()

Desc & L4virtio::Driver::Virtqueue::desc ( l4_uint16_t  descno)
inline

Return a reference to a descriptor in the descriptor table.

Parameters
descnoIndex 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().

+ Here is the caller graph for this function:

◆ enqueue_descriptor()

void L4virtio::Driver::Virtqueue::enqueue_descriptor ( l4_uint16_t  descno)
inline

Enqueue a descriptor in the available ring.

Parameters
descnoIndex 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().

+ Here is the caller graph for this function:

◆ find_next_used()

l4_uint16_t L4virtio::Driver::Virtqueue::find_next_used ( l4_uint32_t len = nullptr)
inline

Return the next finished block.

Parameters
[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.
Returns
Index of the head or Virtqueue::Eoq if no used element is currently available.

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().

+ Here is the caller graph for this function:

◆ free_descriptor()

void L4virtio::Driver::Virtqueue::free_descriptor ( l4_uint16_t  head,
l4_uint16_t  tail 
)
inline

Free a chained list of descriptors in the descriptor queue.

Parameters
headIndex of the first element in the descriptor chain.
tailIndex 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().

+ Here is the caller graph for this function:

◆ init_queue() [1/2]

void L4virtio::Driver::Virtqueue::init_queue ( unsigned  num,
void *  base 
)
inline

Initialize this virtqueue.

Parameters
numThe number of entries in the descriptor table, the available ring, and the used ring (must be a power of 2).
baseThe 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().

+ Here is the call graph for this function:

◆ init_queue() [2/2]

void L4virtio::Driver::Virtqueue::init_queue ( unsigned  num,
void *  desc,
void *  avail,
void *  used 
)
inline

Initialize this virtqueue.

Parameters
numThe number of entries in the descriptor table, the available ring, and the used ring (must be a power of 2).
descThe address of the descriptor table. (Must be Desc_align aligned and at least desc_size(num) bytes in size.)
availThe address of the available ring. (Must be Avail_align aligned and at least avail_size(num) bytes in size.)
usedThe 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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initialize_rings()

void L4virtio::Driver::Virtqueue::initialize_rings ( unsigned  num)
inline

Initialize the descriptor table and the index structures of this queue.

Parameters
numThe number of entries in the descriptor table, the available ring, and the used ring (must be a power of 2).
Precondition
The queue must be set up correctly with setup() or setup_simple().

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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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