OpenAMP Library  353
virtqueue.h File Reference
#include <stdbool.h>
#include <stdint.h>
#include <openamp/virtio_ring.h>
#include <metal/alloc.h>
#include <metal/io.h>
#include <metal/cache.h>

Go to the source code of this file.

Data Structures

struct  virtqueue_buf
 Buffer descriptor. More...
 
struct  vq_desc_extra
 Vring descriptor extra information for buffer list management. More...
 
struct  virtqueue
 Local virtio queue to manage a virtio ring for sending or receiving. More...
 
struct  vring_alloc_info
 Virtio ring specific information. More...
 

Macros

#define VQ_ERROR_BASE   -3000
 
#define ERROR_VRING_FULL   (VQ_ERROR_BASE - 1)
 
#define ERROR_INVLD_DESC_IDX   (VQ_ERROR_BASE - 2)
 
#define ERROR_EMPTY_RING   (VQ_ERROR_BASE - 3)
 
#define ERROR_NO_MEM   (VQ_ERROR_BASE - 4)
 
#define ERROR_VRING_MAX_DESC   (VQ_ERROR_BASE - 5)
 
#define ERROR_VRING_ALIGN   (VQ_ERROR_BASE - 6)
 
#define ERROR_VRING_NO_BUFF   (VQ_ERROR_BASE - 7)
 
#define ERROR_VQUEUE_INVLD_PARAM   (VQ_ERROR_BASE - 8)
 
#define VQUEUE_SUCCESS   0
 
#define VQ_RING_DESC_CHAIN_END   32768
 
#define VIRTIO_RING_F_INDIRECT_DESC   (1 << 28)
 
#define VIRTIO_RING_F_EVENT_IDX   (1 << 29)
 
#define VRING_FLUSH(x, s)   do { } while (0)
 
#define VRING_INVALIDATE(x, s)   do { } while (0)
 
#define VQASSERT(_vq, _exp, _msg)
 
#define VQ_RING_ASSERT_VALID_IDX(_vq, _idx)
 
#define VQ_RING_ASSERT_CHAIN_TERM(_vq)
 
#define VQ_PARAM_CHK(condition, status_var, status_err)
 
#define VQUEUE_BUSY(vq)
 
#define VQUEUE_IDLE(vq)
 

Typedefs

typedef void(* vq_callback) (struct virtqueue *)
 
typedef void(* vq_notify) (struct virtqueue *)
 

Functions

int virtqueue_create (struct virtio_device *device, unsigned short id, const char *name, struct vring_alloc_info *ring, void(*callback)(struct virtqueue *vq), void(*notify)(struct virtqueue *vq), struct virtqueue *vq)
 
static void virtqueue_set_shmem_io (struct virtqueue *vq, struct metal_io_region *io)
 
int virtqueue_add_buffer (struct virtqueue *vq, struct virtqueue_buf *buf_list, int readable, int writable, void *cookie)
 
void * virtqueue_get_buffer (struct virtqueue *vq, uint32_t *len, uint16_t *idx)
 
void * virtqueue_get_first_avail_buffer (struct virtqueue *vq, uint16_t *avail_idx, uint32_t *len)
 
void * virtqueue_get_next_avail_buffer (struct virtqueue *vq, uint16_t idx, uint16_t *next_idx, uint32_t *next_len)
 
int virtqueue_add_consumed_buffer (struct virtqueue *vq, uint16_t head_idx, uint32_t len)
 
void virtqueue_disable_cb (struct virtqueue *vq)
 
int virtqueue_enable_cb (struct virtqueue *vq)
 
void virtqueue_kick (struct virtqueue *vq)
 
static struct virtqueuevirtqueue_allocate (unsigned int num_desc_extra)
 
void virtqueue_free (struct virtqueue *vq)
 
void virtqueue_dump (struct virtqueue *vq)
 
void virtqueue_notification (struct virtqueue *vq)
 
uint32_t virtqueue_get_desc_size (struct virtqueue *vq)
 
uint32_t virtqueue_get_buffer_length (struct virtqueue *vq, uint16_t idx)
 
void * virtqueue_get_buffer_addr (struct virtqueue *vq, uint16_t idx)
 
static int virtqueue_empty (struct virtqueue *vq)
 Test if virtqueue is empty. More...
 
static int virtqueue_full (struct virtqueue *vq)
 Test if virtqueue is full. More...
 

Macro Definition Documentation

◆ ERROR_EMPTY_RING

#define ERROR_EMPTY_RING   (VQ_ERROR_BASE - 3)

◆ ERROR_INVLD_DESC_IDX

#define ERROR_INVLD_DESC_IDX   (VQ_ERROR_BASE - 2)

◆ ERROR_NO_MEM

#define ERROR_NO_MEM   (VQ_ERROR_BASE - 4)

◆ ERROR_VQUEUE_INVLD_PARAM

#define ERROR_VQUEUE_INVLD_PARAM   (VQ_ERROR_BASE - 8)

◆ ERROR_VRING_ALIGN

#define ERROR_VRING_ALIGN   (VQ_ERROR_BASE - 6)

◆ ERROR_VRING_FULL

#define ERROR_VRING_FULL   (VQ_ERROR_BASE - 1)

◆ ERROR_VRING_MAX_DESC

#define ERROR_VRING_MAX_DESC   (VQ_ERROR_BASE - 5)

◆ ERROR_VRING_NO_BUFF

#define ERROR_VRING_NO_BUFF   (VQ_ERROR_BASE - 7)

◆ VIRTIO_RING_F_EVENT_IDX

#define VIRTIO_RING_F_EVENT_IDX   (1 << 29)

◆ VIRTIO_RING_F_INDIRECT_DESC

#define VIRTIO_RING_F_INDIRECT_DESC   (1 << 28)

◆ VQ_ERROR_BASE

#define VQ_ERROR_BASE   -3000

◆ VQ_PARAM_CHK

#define VQ_PARAM_CHK (   condition,
  status_var,
  status_err 
)

◆ VQ_RING_ASSERT_CHAIN_TERM

#define VQ_RING_ASSERT_CHAIN_TERM (   _vq)

◆ VQ_RING_ASSERT_VALID_IDX

#define VQ_RING_ASSERT_VALID_IDX (   _vq,
  _idx 
)

◆ VQ_RING_DESC_CHAIN_END

#define VQ_RING_DESC_CHAIN_END   32768

◆ VQASSERT

#define VQASSERT (   _vq,
  _exp,
  _msg 
)

◆ VQUEUE_BUSY

#define VQUEUE_BUSY (   vq)

◆ VQUEUE_IDLE

#define VQUEUE_IDLE (   vq)

◆ VQUEUE_SUCCESS

#define VQUEUE_SUCCESS   0

◆ VRING_FLUSH

#define VRING_FLUSH (   x,
 
)    do { } while (0)

◆ VRING_INVALIDATE

#define VRING_INVALIDATE (   x,
 
)    do { } while (0)

Typedef Documentation

◆ vq_callback

typedef void(* vq_callback) (struct virtqueue *)

◆ vq_notify

typedef void(* vq_notify) (struct virtqueue *)

Function Documentation

◆ virtqueue_add_buffer()

int virtqueue_add_buffer ( struct virtqueue vq,
struct virtqueue_buf buf_list,
int  readable,
int  writable,
void *  cookie 
)

◆ virtqueue_add_consumed_buffer()

int virtqueue_add_consumed_buffer ( struct virtqueue vq,
uint16_t  head_idx,
uint32_t  len 
)

◆ virtqueue_allocate()

static struct virtqueue* virtqueue_allocate ( unsigned int  num_desc_extra)
inlinestatic

◆ virtqueue_create()

int virtqueue_create ( struct virtio_device device,
unsigned short  id,
const char *  name,
struct vring_alloc_info ring,
void(*)(struct virtqueue *vq)  callback,
void(*)(struct virtqueue *vq)  notify,
struct virtqueue vq 
)

◆ virtqueue_disable_cb()

void virtqueue_disable_cb ( struct virtqueue vq)

◆ virtqueue_dump()

void virtqueue_dump ( struct virtqueue vq)

◆ virtqueue_empty()

static int virtqueue_empty ( struct virtqueue vq)
inlinestatic

Test if virtqueue is empty.

Parameters
vqPointer to VirtIO queue control block
Returns
1 if virtqueue is empty, 0 otherwise

◆ virtqueue_enable_cb()

int virtqueue_enable_cb ( struct virtqueue vq)

◆ virtqueue_free()

void virtqueue_free ( struct virtqueue vq)

◆ virtqueue_full()

static int virtqueue_full ( struct virtqueue vq)
inlinestatic

Test if virtqueue is full.

Parameters
vqPointer to VirtIO queue control block
Returns
1 if virtqueue is full, 0 otherwise

◆ virtqueue_get_buffer()

void* virtqueue_get_buffer ( struct virtqueue vq,
uint32_t *  len,
uint16_t *  idx 
)

◆ virtqueue_get_buffer_addr()

void* virtqueue_get_buffer_addr ( struct virtqueue vq,
uint16_t  idx 
)

◆ virtqueue_get_buffer_length()

uint32_t virtqueue_get_buffer_length ( struct virtqueue vq,
uint16_t  idx 
)

◆ virtqueue_get_desc_size()

uint32_t virtqueue_get_desc_size ( struct virtqueue vq)

◆ virtqueue_get_first_avail_buffer()

void* virtqueue_get_first_avail_buffer ( struct virtqueue vq,
uint16_t *  avail_idx,
uint32_t *  len 
)

◆ virtqueue_get_next_avail_buffer()

void* virtqueue_get_next_avail_buffer ( struct virtqueue vq,
uint16_t  idx,
uint16_t *  next_idx,
uint32_t *  next_len 
)

◆ virtqueue_kick()

void virtqueue_kick ( struct virtqueue vq)

◆ virtqueue_notification()

void virtqueue_notification ( struct virtqueue vq)

◆ virtqueue_set_shmem_io()

static void virtqueue_set_shmem_io ( struct virtqueue vq,
struct metal_io_region *  io 
)
inlinestatic