OpenAMP Library  353
rpmsg_virtio.c File Reference
#include <metal/alloc.h>
#include <metal/sleep.h>
#include <metal/sys.h>
#include <metal/utilities.h>
#include <openamp/rpmsg_virtio.h>
#include <openamp/virtqueue.h>
#include "rpmsg_internal.h"

Data Structures

struct  vbuff_reclaimer_t
 struct vbuff_reclaimer_t - vring buffer recycler More...
 

Macros

#define RPMSG_NUM_VRINGS   2
 
#define RPMSG_TICK_COUNT   15000000
 
#define RPMSG_TICKS_PER_INTERVAL   1000
 
#define RPMSG_BUF_HELD_COUNTER(rp_hdr)    (((rp_hdr)->reserved & RPMSG_BUF_HELD_MASK) >> RPMSG_BUF_HELD_SHIFT)
 
#define RPMSG_BUF_HELD_INC(rp_hdr)    ((rp_hdr)->reserved += 1 << RPMSG_BUF_HELD_SHIFT)
 
#define RPMSG_BUF_HELD_DEC(rp_hdr)    ((rp_hdr)->reserved -= 1 << RPMSG_BUF_HELD_SHIFT)
 
#define RPMSG_BUF_INDEX(rphdr)    ((uint16_t)((rp_hdr)->reserved & ~RPMSG_BUF_HELD_MASK))
 
#define RPMSG_VIRTIO_DEFAULT_CONFIG   NULL
 

Functions

void rpmsg_virtio_init_shm_pool (struct rpmsg_virtio_shm_pool *shpool, void *shb, size_t size)
 Initialize default shared buffers pool. More...
 
static void rpmsg_virtio_return_buffer (struct rpmsg_virtio_device *rvdev, void *buffer, uint32_t len, uint16_t idx)
 
static int rpmsg_virtio_enqueue_buffer (struct rpmsg_virtio_device *rvdev, void *buffer, uint32_t len, uint16_t idx)
 
static void * rpmsg_virtio_get_tx_buffer (struct rpmsg_virtio_device *rvdev, uint32_t *len, uint16_t *idx)
 
static void * rpmsg_virtio_get_rx_buffer (struct rpmsg_virtio_device *rvdev, uint32_t *len, uint16_t *idx)
 
static int rpmsg_virtio_wait_remote_ready (struct rpmsg_virtio_device *rvdev)
 
static bool rpmsg_virtio_buf_held_dec_test (struct rpmsg_hdr *rp_hdr)
 
static void rpmsg_virtio_hold_rx_buffer (struct rpmsg_device *rdev, void *rxbuf)
 
static bool rpmsg_virtio_release_rx_buffer_nolock (struct rpmsg_virtio_device *rvdev, struct rpmsg_hdr *rp_hdr)
 
static void rpmsg_virtio_release_rx_buffer (struct rpmsg_device *rdev, void *rxbuf)
 
static int rpmsg_virtio_notify_wait (struct rpmsg_virtio_device *rvdev, struct virtqueue *vq)
 
static void * rpmsg_virtio_get_tx_payload_buffer (struct rpmsg_device *rdev, uint32_t *len, int wait)
 
static int rpmsg_virtio_send_offchannel_nocopy (struct rpmsg_device *rdev, uint32_t src, uint32_t dst, const void *data, int len)
 
static int rpmsg_virtio_release_tx_buffer (struct rpmsg_device *rdev, void *txbuf)
 
static int rpmsg_virtio_send_offchannel_raw (struct rpmsg_device *rdev, uint32_t src, uint32_t dst, const void *data, int len, int wait)
 
static void rpmsg_virtio_tx_callback (struct virtqueue *vq)
 
static void rpmsg_virtio_rx_callback (struct virtqueue *vq)
 
static int rpmsg_virtio_ns_callback (struct rpmsg_endpoint *ept, void *data, size_t len, uint32_t src, void *priv)
 
int rpmsg_virtio_get_tx_buffer_size (struct rpmsg_device *rdev)
 Get rpmsg virtio buffer size. More...
 
int rpmsg_virtio_get_rx_buffer_size (struct rpmsg_device *rdev)
 Get rpmsg virtio Rx buffer size. More...
 
int rpmsg_init_vdev (struct rpmsg_virtio_device *rvdev, struct virtio_device *vdev, rpmsg_ns_bind_cb ns_bind_cb, struct metal_io_region *shm_io, struct rpmsg_virtio_shm_pool *shpool)
 Initialize rpmsg virtio device. More...
 
int rpmsg_init_vdev_with_config (struct rpmsg_virtio_device *rvdev, struct virtio_device *vdev, rpmsg_ns_bind_cb ns_bind_cb, struct metal_io_region *shm_io, struct rpmsg_virtio_shm_pool *shpool, const struct rpmsg_virtio_config *config)
 Initialize rpmsg virtio device with config. More...
 
void rpmsg_deinit_vdev (struct rpmsg_virtio_device *rvdev)
 Deinitialize rpmsg virtio device. More...
 

Macro Definition Documentation

◆ RPMSG_BUF_HELD_COUNTER

#define RPMSG_BUF_HELD_COUNTER (   rp_hdr)     (((rp_hdr)->reserved & RPMSG_BUF_HELD_MASK) >> RPMSG_BUF_HELD_SHIFT)

◆ RPMSG_BUF_HELD_DEC

#define RPMSG_BUF_HELD_DEC (   rp_hdr)     ((rp_hdr)->reserved -= 1 << RPMSG_BUF_HELD_SHIFT)

◆ RPMSG_BUF_HELD_INC

#define RPMSG_BUF_HELD_INC (   rp_hdr)     ((rp_hdr)->reserved += 1 << RPMSG_BUF_HELD_SHIFT)

◆ RPMSG_BUF_INDEX

#define RPMSG_BUF_INDEX (   rphdr)     ((uint16_t)((rp_hdr)->reserved & ~RPMSG_BUF_HELD_MASK))

◆ RPMSG_NUM_VRINGS

#define RPMSG_NUM_VRINGS   2

◆ RPMSG_TICK_COUNT

#define RPMSG_TICK_COUNT   15000000

◆ RPMSG_TICKS_PER_INTERVAL

#define RPMSG_TICKS_PER_INTERVAL   1000

◆ RPMSG_VIRTIO_DEFAULT_CONFIG

#define RPMSG_VIRTIO_DEFAULT_CONFIG   NULL

Function Documentation

◆ rpmsg_deinit_vdev()

void rpmsg_deinit_vdev ( struct rpmsg_virtio_device rvdev)

Deinitialize rpmsg virtio device.

Parameters
rvdevPointer to the rpmsg virtio device

◆ rpmsg_init_vdev()

int rpmsg_init_vdev ( struct rpmsg_virtio_device rvdev,
struct virtio_device vdev,
rpmsg_ns_bind_cb  ns_bind_cb,
struct metal_io_region *  shm_io,
struct rpmsg_virtio_shm_pool shpool 
)

Initialize rpmsg virtio device.

Host side: Initialize RPMsg virtio queues and shared buffers, the address of shm can be ANY. In this case, function will get shared memory from system shared memory pools. If the vdev has the RPMsg name service feature, this API will create a name service endpoint.

Remote side: This API will not return until the driver ready is set by the host side.

Parameters
rvdevPointer to the rpmsg virtio device
vdevPointer to the virtio device
ns_bind_cbCallback handler for name service announcement without local endpoints waiting to bind.
shm_ioPointer to the share memory I/O region.
shpoolPointer to shared memory pool. rpmsg_virtio_init_shm_pool has to be called first to fill this structure.
Returns
Status of function execution

◆ rpmsg_init_vdev_with_config()

int rpmsg_init_vdev_with_config ( struct rpmsg_virtio_device rvdev,
struct virtio_device vdev,
rpmsg_ns_bind_cb  ns_bind_cb,
struct metal_io_region *  shm_io,
struct rpmsg_virtio_shm_pool shpool,
const struct rpmsg_virtio_config config 
)

Initialize rpmsg virtio device with config.

Host side: Initialize RPMsg virtio queues and shared buffers, the address of shm can be ANY. In this case, function will get shared memory from system shared memory pools. If the vdev has the RPMsg name service feature, this API will create a name service endpoint. Sizes of virtio data buffers used by the initialized RPMsg instance are set to values read from the passed configuration structure.

Remote side: This API will not return until the driver ready is set by the host side. Sizes of virtio data buffers are set by the host side. Values passed in the configuration structure have no effect.

Parameters
rvdevPointer to the rpmsg virtio device
vdevPointer to the virtio device
ns_bind_cbCallback handler for name service announcement without local endpoints waiting to bind.
shm_ioPointer to the share memory I/O region.
shpoolPointer to shared memory pool array. If the config->split_shpool is turn on, the array will contain two elements, the shpool of txshpool and rxshpool, Otherwise, the array has only one element, and txshpool rxshpool shares a shpool. And rpmsg_virtio_init_shm_pool has to be called first to fill each shpool in this array.
configPointer to configuration structure
Returns
Status of function execution

◆ rpmsg_virtio_buf_held_dec_test()

static bool rpmsg_virtio_buf_held_dec_test ( struct rpmsg_hdr rp_hdr)
static

◆ rpmsg_virtio_enqueue_buffer()

static int rpmsg_virtio_enqueue_buffer ( struct rpmsg_virtio_device rvdev,
void *  buffer,
uint32_t  len,
uint16_t  idx 
)
static

◆ rpmsg_virtio_get_rx_buffer()

static void* rpmsg_virtio_get_rx_buffer ( struct rpmsg_virtio_device rvdev,
uint32_t *  len,
uint16_t *  idx 
)
static

◆ rpmsg_virtio_get_rx_buffer_size()

int rpmsg_virtio_get_rx_buffer_size ( struct rpmsg_device rdev)

Get rpmsg virtio Rx buffer size.

Parameters
rdevPointer to the rpmsg device
Returns
Next available buffer size for text, negative value for failure

◆ rpmsg_virtio_get_tx_buffer()

static void* rpmsg_virtio_get_tx_buffer ( struct rpmsg_virtio_device rvdev,
uint32_t *  len,
uint16_t *  idx 
)
static

◆ rpmsg_virtio_get_tx_buffer_size()

int rpmsg_virtio_get_tx_buffer_size ( struct rpmsg_device rdev)

Get rpmsg virtio buffer size.

Parameters
rdevPointer to the rpmsg device
Returns
Next available buffer size for text, negative value for failure

◆ rpmsg_virtio_get_tx_payload_buffer()

static void* rpmsg_virtio_get_tx_payload_buffer ( struct rpmsg_device rdev,
uint32_t *  len,
int  wait 
)
static

◆ rpmsg_virtio_hold_rx_buffer()

static void rpmsg_virtio_hold_rx_buffer ( struct rpmsg_device rdev,
void *  rxbuf 
)
static

◆ rpmsg_virtio_init_shm_pool()

void rpmsg_virtio_init_shm_pool ( struct rpmsg_virtio_shm_pool shpool,
void *  shbuf,
size_t  size 
)

Initialize default shared buffers pool.

RPMsg virtio has default shared buffers pool implementation. The memory assigned to this pool will be dedicated to the RPMsg virtio. This function has to be called before calling rpmsg_init_vdev, to initialize the rpmsg_virtio_shm_pool structure.

Parameters
shpoolPointer to the shared buffers pool structure
shbufPointer to the beginning of shared buffers
sizeShared buffers total size

◆ rpmsg_virtio_notify_wait()

static int rpmsg_virtio_notify_wait ( struct rpmsg_virtio_device rvdev,
struct virtqueue vq 
)
static

◆ rpmsg_virtio_ns_callback()

static int rpmsg_virtio_ns_callback ( struct rpmsg_endpoint ept,
void *  data,
size_t  len,
uint32_t  src,
void *  priv 
)
static

◆ rpmsg_virtio_release_rx_buffer()

static void rpmsg_virtio_release_rx_buffer ( struct rpmsg_device rdev,
void *  rxbuf 
)
static

◆ rpmsg_virtio_release_rx_buffer_nolock()

static bool rpmsg_virtio_release_rx_buffer_nolock ( struct rpmsg_virtio_device rvdev,
struct rpmsg_hdr rp_hdr 
)
static

◆ rpmsg_virtio_release_tx_buffer()

static int rpmsg_virtio_release_tx_buffer ( struct rpmsg_device rdev,
void *  txbuf 
)
static

◆ rpmsg_virtio_return_buffer()

static void rpmsg_virtio_return_buffer ( struct rpmsg_virtio_device rvdev,
void *  buffer,
uint32_t  len,
uint16_t  idx 
)
static

◆ rpmsg_virtio_rx_callback()

static void rpmsg_virtio_rx_callback ( struct virtqueue vq)
static

◆ rpmsg_virtio_send_offchannel_nocopy()

static int rpmsg_virtio_send_offchannel_nocopy ( struct rpmsg_device rdev,
uint32_t  src,
uint32_t  dst,
const void *  data,
int  len 
)
static

◆ rpmsg_virtio_send_offchannel_raw()

static int rpmsg_virtio_send_offchannel_raw ( struct rpmsg_device rdev,
uint32_t  src,
uint32_t  dst,
const void *  data,
int  len,
int  wait 
)
static

◆ rpmsg_virtio_tx_callback()

static void rpmsg_virtio_tx_callback ( struct virtqueue vq)
static

◆ rpmsg_virtio_wait_remote_ready()

static int rpmsg_virtio_wait_remote_ready ( struct rpmsg_virtio_device rvdev)
static