Zephyr Project API 4.1.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
Virtqueue Interface

Virtqueue Interface. More...

Data Structures

struct  virtq_desc
 virtqueue descriptor More...
 
struct  virtq_avail
 virtqueue available ring More...
 
struct  virtq_used_elem
 used descriptor chain More...
 
struct  virtq_used
 virtqueue used ring More...
 
struct  virtq_receive_callback_entry
 callback descriptor More...
 
struct  virtq
 virtqueue More...
 
struct  virtq_buf
 single buffer passed to virtq_add_buffer_chain More...
 

Macros

#define VIRTQ_DESC_F_NEXT   1
 used in virtq_desc::flags, enables chaining descriptor via virtq_desc::next
 
#define VIRTQ_DESC_F_WRITE   2
 used in virtq_desc::flags, makes descriptor device writeable
 

Typedefs

typedef void(* virtq_receive_callback) (void *opaque, uint32_t used_len)
 receive callback function type
 

Functions

int virtq_create (struct virtq *v, size_t size)
 creates virtqueue
 
void virtq_free (struct virtq *v)
 frees virtqueue
 
int virtq_add_buffer_chain (struct virtq *v, struct virtq_buf *bufs, uint16_t bufs_size, uint16_t device_readable_count, virtq_receive_callback cb, void *cb_opaque, k_timeout_t timeout)
 adds chain of buffers to the virtqueue
 
void virtq_add_free_desc (struct virtq *v, uint16_t desc_idx)
 adds free descriptor back
 
int virtq_get_free_desc (struct virtq *v, uint16_t *desc_idx, k_timeout_t timeout)
 gets next free descriptor
 

Detailed Description

Virtqueue Interface.

Macro Definition Documentation

◆ VIRTQ_DESC_F_NEXT

#define VIRTQ_DESC_F_NEXT   1

#include <include/zephyr/virtio/virtqueue.h>

used in virtq_desc::flags, enables chaining descriptor via virtq_desc::next

◆ VIRTQ_DESC_F_WRITE

#define VIRTQ_DESC_F_WRITE   2

#include <include/zephyr/virtio/virtqueue.h>

used in virtq_desc::flags, makes descriptor device writeable

Typedef Documentation

◆ virtq_receive_callback

typedef void(* virtq_receive_callback) (void *opaque, uint32_t used_len)

#include <include/zephyr/virtio/virtqueue.h>

receive callback function type

Parameters
opaqueargument passed to the callback
used_lentotal amount of bytes written to the descriptor chain by the virtio device

Function Documentation

◆ virtq_add_buffer_chain()

int virtq_add_buffer_chain ( struct virtq v,
struct virtq_buf bufs,
uint16_t  bufs_size,
uint16_t  device_readable_count,
virtq_receive_callback  cb,
void *  cb_opaque,
k_timeout_t  timeout 
)

#include <include/zephyr/virtio/virtqueue.h>

adds chain of buffers to the virtqueue

Note that according to spec 2.7.13.3 the device may access the buffers as soon as the avail->idx is increased, which is done at the end of this function, so the device may access the buffers without notifying it with virtio_notify_virtqueue

Parameters
vvirtqueue it operates on
bufsarray of buffers to be added to the virtqueue
bufs_sizeamount of buffers
device_readable_countamount of bufferes readable by the device, the first device_readable_count buffers will be set as device readable
cbcallback to be invoked after device returns the buffer chain, can be NULL
cb_opaqueopaque value that will be passed to the cb
timeoutamount of time it will wait for free descriptors, with K_NO_WAIT it can be called from isr
Returns
0 or error code on failure

◆ virtq_add_free_desc()

void virtq_add_free_desc ( struct virtq v,
uint16_t  desc_idx 
)

#include <include/zephyr/virtio/virtqueue.h>

adds free descriptor back

Parameters
vvirtqueue it operates on
desc_idxindex of returned descriptor

◆ virtq_create()

int virtq_create ( struct virtq v,
size_t  size 
)

#include <include/zephyr/virtio/virtqueue.h>

creates virtqueue

Parameters
vvirtqueue to be created
sizesize of the virtqueue
Returns
0 or error code on failure

◆ virtq_free()

void virtq_free ( struct virtq v)

#include <include/zephyr/virtio/virtqueue.h>

frees virtqueue

Parameters
vvirtqueue to be freed

◆ virtq_get_free_desc()

int virtq_get_free_desc ( struct virtq v,
uint16_t desc_idx,
k_timeout_t  timeout 
)

#include <include/zephyr/virtio/virtqueue.h>

gets next free descriptor

Parameters
vvirtqueue it operates on
desc_idxaddress where index of descriptor will be stored
timeoutamount of time it will wait for free descriptor, with K_NO_WAIT it can be called from isr
Returns
0 or error code on failure