OpenAMP Library
Data Structures | Macros | Functions
rpmsg_virtio.c File Reference
#include <metal/alloc.h>
#include <metal/cache.h>
#include <metal/sleep.h>
#include <metal/utilities.h>
#include <openamp/rpmsg_virtio.h>
#include <openamp/virtqueue.h>
#include "rpmsg_internal.h"

Data Structures

struct  vbuff_reclaimer_t
 

Macros

#define RPMSG_NUM_VRINGS   2
 
#define RPMSG_TICK_COUNT   15000000
 
#define RPMSG_TICKS_PER_INTERVAL   1000
 
#define RPMSG_VIRTIO_DEFAULT_CONFIG
 

Functions

metal_weak void * rpmsg_virtio_shm_pool_get_buffer (struct rpmsg_virtio_shm_pool *shpool, size_t size)
 Get buffer in the shared memory pool. More...
 
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 int _rpmsg_virtio_get_buffer_size (struct rpmsg_virtio_device *rvdev)
 
static void rpmsg_virtio_hold_rx_buffer (struct rpmsg_device *rdev, void *rxbuf)
 
static void rpmsg_virtio_release_rx_buffer (struct rpmsg_device *rdev, void *rxbuf)
 
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_buffer_size (struct rpmsg_device *rdev)
 Get rpmsg virtio 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_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
Value:
(&(const struct rpmsg_virtio_config) { \
.h2r_buf_size = RPMSG_BUFFER_SIZE, \
.r2h_buf_size = RPMSG_BUFFER_SIZE, \
.split_shpool = false, \
})
#define RPMSG_BUFFER_SIZE
Definition: rpmsg_virtio.h:26
Definition: rpmsg_virtio.h:54

Function Documentation

◆ _rpmsg_virtio_get_buffer_size()

static int _rpmsg_virtio_get_buffer_size ( struct rpmsg_virtio_device rvdev)
static

VIRTIO_DRIVER_ONLY

VIRTIO_DEVICE_ONLY

VIRTIO_DRIVER_ONLY

◆ 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

VIRTIO_DEVICE_ONLY

VIRTIO_DRIVER_ONLY

VIRTIO_DEVICE_ONLY

VIRTIO_DRIVER_ONLY

VIRTIO_DEVICE_ONLY

VIRTIO_DEVICE_ONLY

◆ rpmsg_virtio_enqueue_buffer()

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

VIRTIO_DEVICE_ONLY

VIRTIO_DRIVER_ONLY

◆ rpmsg_virtio_get_buffer_size()

int rpmsg_virtio_get_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_rx_buffer()

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

VIRTIO_DEVICE_ONLY

VIRTIO_DRIVER_ONLY

◆ rpmsg_virtio_get_tx_buffer()

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

VIRTIO_DEVICE_ONLY

VIRTIO_DRIVER_ONLY

VIRTIO_DEVICE_ONLY

VIRTIO_DRIVER_ONLY

◆ 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 *  shb,
size_t  size 
)

Initialize default shared buffers pool.

VIRTIO_DEVICE_ONLY

◆ 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_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

VIRTIO_DEVICE_ONLY

◆ 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_shm_pool_get_buffer()

metal_weak void* rpmsg_virtio_shm_pool_get_buffer ( struct rpmsg_virtio_shm_pool shpool,
size_t  size 
)

Get buffer in the shared memory pool.

RPMsg virtio has default shared buffers pool implementation. The memory assigned to this pool will be dedicated to the RPMsg virtio. If you prefer to have other shared buffers allocation, you can implement your rpmsg_virtio_shm_pool_get_buffer function.

Parameters
shpoolPointer to the shared buffers pool
sizeShared buffers total size
Returns
Buffer pointer if free buffer is available, NULL otherwise.

◆ 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