OpenAMP Library  353
vring Struct Reference

The virtqueue layout structure. More...

#include <virtio_ring.h>

Data Fields

unsigned int num
 The maximum number of buffer descriptors in the virtqueue. More...
 
struct vring_descdesc
 The actual buffer descriptors, 16 bytes each. More...
 
struct vring_availavail
 A ring of available descriptor heads with free-running index. More...
 
struct vring_usedused
 A ring of used descriptor heads with free-running index. More...
 

Detailed Description

The virtqueue layout structure.

Each virtqueue consists of; descriptor table, available ring, used ring, where each part is physically contiguous in guest memory, referenced by the pointers in this structure.

When the driver wants to send a buffer to the device, it fills in a slot in the descriptor table (or chains several together), and writes the descriptor index into the available ring. It then notifies the device. When the device has finished a buffer, it writes the descriptor index into the used ring, and sends an interrupt.

The standard layout for the ring, referenced by this structure, is a continuous chunk of memory exemplified by this table. The maximum number of buffer descriptors, num, is a power of 2.

vring definition description
desc struct vring_desc desc[num] All num descriptors
avail uint16_t avail_flags Device notification flags
uint16_t avail_idx Driver's next descriptor location
uint16_t available[num] The ring of descriptors
uint16_t used_event_idx Free running index
pad char pad[] Padding for memory alignment
used uint16_t used_flags Device notification flags
uint16_t used_idx Driver's next descriptor location
struct vring_used_elem used[num] The ring of descriptors
uint16_t avail_event_idx Free running index

Padding for alignment requirements:

Some architectures require strict alignment for atomic operations or DMA transfer. The pad item should be inserted between avail and used memory sections to ensure that the used ring is aligned, as the available ring size is not necessarily a multiple of 4 or 8 bytes.

The alignment may also be necessary for CPU cache line utilization, as padding can avoid crossing cache lines or memory pages in the shared memory.

NOTE: for VirtIO PCI, align is 4096.

Field Documentation

◆ avail

struct vring_avail* vring::avail

A ring of available descriptor heads with free-running index.

◆ desc

struct vring_desc* vring::desc

The actual buffer descriptors, 16 bytes each.

◆ num

unsigned int vring::num

The maximum number of buffer descriptors in the virtqueue.

The value is always a power of 2.

◆ used

struct vring_used* vring::used

A ring of used descriptor heads with free-running index.


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