OpenAMP Library  353
rpmsg.c File Reference
#include <internal/utilities.h>
#include <openamp/rpmsg.h>
#include <metal/alloc.h>
#include "rpmsg_internal.h"

Functions

static uint32_t rpmsg_get_address (unsigned long *bitmap, unsigned int start, int size)
 
static void rpmsg_release_address (unsigned long *bitmap, int size, int addr)
 
static int rpmsg_is_address_set (unsigned long *bitmap, int size, int addr)
 
static int rpmsg_set_address (unsigned long *bitmap, int size, int addr)
 
void rpmsg_ept_incref (struct rpmsg_endpoint *ept)
 
void rpmsg_ept_decref (struct rpmsg_endpoint *ept)
 
int rpmsg_send_offchannel_raw (struct rpmsg_endpoint *ept, uint32_t src, uint32_t dst, const void *data, int len, int wait)
 Send a message across to the remote processor, specifying source and destination address. More...
 
int rpmsg_send_ns_message (struct rpmsg_endpoint *ept, unsigned long flags)
 
void rpmsg_hold_rx_buffer (struct rpmsg_endpoint *ept, void *rxbuf)
 Holds the rx buffer for usage outside the receive callback. More...
 
void rpmsg_release_rx_buffer (struct rpmsg_endpoint *ept, void *rxbuf)
 Releases the rx buffer for future reuse in vring. More...
 
int rpmsg_release_tx_buffer (struct rpmsg_endpoint *ept, void *buf)
 Releases unused buffer. More...
 
void * rpmsg_get_tx_payload_buffer (struct rpmsg_endpoint *ept, uint32_t *len, int wait)
 Gets the tx buffer for message payload. More...
 
int rpmsg_get_tx_buffer_size (struct rpmsg_endpoint *ept)
 Get RPMsg Tx buffer size. More...
 
int rpmsg_get_rx_buffer_size (struct rpmsg_endpoint *ept)
 Get RPMsg Rx buffer size. More...
 
int rpmsg_send_offchannel_nocopy (struct rpmsg_endpoint *ept, uint32_t src, uint32_t dst, const void *data, int len)
 Send a message in tx buffer reserved by rpmsg_get_tx_payload_buffer() across to the remote processor. More...
 
struct rpmsg_endpointrpmsg_get_endpoint (struct rpmsg_device *rdev, const char *name, uint32_t addr, uint32_t dest_addr)
 
static void rpmsg_unregister_endpoint (struct rpmsg_endpoint *ept)
 
void rpmsg_register_endpoint (struct rpmsg_device *rdev, struct rpmsg_endpoint *ept, const char *name, uint32_t src, uint32_t dest, rpmsg_ept_cb cb, rpmsg_ns_unbind_cb ns_unbind_cb, void *priv)
 
int rpmsg_create_ept (struct rpmsg_endpoint *ept, struct rpmsg_device *rdev, const char *name, uint32_t src, uint32_t dest, rpmsg_ept_cb cb, rpmsg_ns_unbind_cb unbind_cb)
 Create rpmsg endpoint and register it to rpmsg device. More...
 
void rpmsg_destroy_ept (struct rpmsg_endpoint *ept)
 Destroy rpmsg endpoint and unregister it from rpmsg device. More...
 

Function Documentation

◆ rpmsg_create_ept()

int rpmsg_create_ept ( struct rpmsg_endpoint ept,
struct rpmsg_device rdev,
const char *  name,
uint32_t  src,
uint32_t  dest,
rpmsg_ept_cb  cb,
rpmsg_ns_unbind_cb  ns_unbind_cb 
)

Create rpmsg endpoint and register it to rpmsg device.

Create a RPMsg endpoint, initialize it with a name, source address, remoteproc address, endpoint callback, and destroy endpoint callback, and register it to the RPMsg device.

In essence, an rpmsg endpoint represents a listener on the rpmsg bus, as it binds an rpmsg address with an rx callback handler.

Rpmsg client should create an endpoint to discuss with remote. rpmsg client provide at least a channel name, a callback for message notification and by default endpoint source address should be set to RPMSG_ADDR_ANY.

As an option Some rpmsg clients can specify an endpoint with a specific source address.

Parameters
eptPointer to rpmsg endpoint
rdevRPMsg device associated with the endpoint
nameService name associated to the endpoint (maximum size RPMSG_NAME_SIZE)
srcLocal address of the endpoint
destTarget address of the endpoint
cbEndpoint callback
ns_unbind_cbEndpoint service unbind callback, called when remote ept is destroyed.
Returns
0 on success, or negative error value on failure.

◆ rpmsg_destroy_ept()

void rpmsg_destroy_ept ( struct rpmsg_endpoint ept)

Destroy rpmsg endpoint and unregister it from rpmsg device.

It unregisters the rpmsg endpoint from the rpmsg device and calls the destroy endpoint callback if it is provided.

Parameters
eptPointer to the rpmsg endpoint

◆ rpmsg_ept_decref()

void rpmsg_ept_decref ( struct rpmsg_endpoint ept)

◆ rpmsg_ept_incref()

void rpmsg_ept_incref ( struct rpmsg_endpoint ept)

◆ rpmsg_get_address()

static uint32_t rpmsg_get_address ( unsigned long *  bitmap,
unsigned int  start,
int  size 
)
static

◆ rpmsg_get_endpoint()

struct rpmsg_endpoint* rpmsg_get_endpoint ( struct rpmsg_device rdev,
const char *  name,
uint32_t  addr,
uint32_t  dest_addr 
)

◆ rpmsg_get_rx_buffer_size()

int rpmsg_get_rx_buffer_size ( struct rpmsg_endpoint ept)

Get RPMsg Rx buffer size.

Parameters
eptThe rpmsg endpoint
Returns
  • Next available Rx buffer size on success
  • RPMSG_ERR_PARAM on invalid parameter
  • RPMSG_ERR_PERM if service not implemented

◆ rpmsg_get_tx_buffer_size()

int rpmsg_get_tx_buffer_size ( struct rpmsg_endpoint ept)

Get RPMsg Tx buffer size.

Parameters
eptThe rpmsg endpoint
Returns
  • Next available Tx buffer size on success
  • RPMSG_ERR_PARAM on invalid parameter
  • RPMSG_ERR_PERM if service not implemented

◆ rpmsg_get_tx_payload_buffer()

void* rpmsg_get_tx_payload_buffer ( struct rpmsg_endpoint ept,
uint32_t *  len,
int  wait 
)

Gets the tx buffer for message payload.

This API can only be called at process context to get the tx buffer in vring. By this way, the application can directly put its message into the vring tx buffer without copy from an application buffer. It is the application responsibility to correctly fill the allocated tx buffer by data and passing correct parameters to the rpmsg_send_nocopy() or rpmsg_sendto_nocopy() function to perform data no-copy-send mechanism.

Parameters
eptPointer to rpmsg endpoint
lenPointer to store tx buffer size
waitBoolean, wait or not for buffer to become available
Returns
The tx buffer address on success and NULL on failure
See also
rpmsg_send_offchannel_nocopy
rpmsg_sendto_nocopy
rpmsg_send_nocopy

◆ rpmsg_hold_rx_buffer()

void rpmsg_hold_rx_buffer ( struct rpmsg_endpoint ept,
void *  rxbuf 
)

Holds the rx buffer for usage outside the receive callback.

Calling this function prevents the RPMsg receive buffer from being released back to the pool of shmem buffers. This API can only be called at rx callback context (rpmsg_rx_cb_t). With this API, the application doesn't need to copy the message in rx callback. Instead, the rx buffer base address is saved in application context and further processed in application process. After the message is processed, the application can release the rx buffer for future reuse in vring by calling the rpmsg_release_rx_buffer() function.

Parameters
eptThe rpmsg endpoint
rxbufRX buffer with message payload
See also
rpmsg_release_rx_buffer

◆ rpmsg_is_address_set()

static int rpmsg_is_address_set ( unsigned long *  bitmap,
int  size,
int  addr 
)
static

◆ rpmsg_register_endpoint()

void rpmsg_register_endpoint ( struct rpmsg_device rdev,
struct rpmsg_endpoint ept,
const char *  name,
uint32_t  src,
uint32_t  dest,
rpmsg_ept_cb  cb,
rpmsg_ns_unbind_cb  ns_unbind_cb,
void *  priv 
)

◆ rpmsg_release_address()

static void rpmsg_release_address ( unsigned long *  bitmap,
int  size,
int  addr 
)
static

◆ rpmsg_release_rx_buffer()

void rpmsg_release_rx_buffer ( struct rpmsg_endpoint ept,
void *  rxbuf 
)

Releases the rx buffer for future reuse in vring.

This API can be called at process context when the message in rx buffer is processed.

Parameters
eptThe rpmsg endpoint
rxbufrx buffer with message payload
See also
rpmsg_hold_rx_buffer

◆ rpmsg_release_tx_buffer()

int rpmsg_release_tx_buffer ( struct rpmsg_endpoint ept,
void *  txbuf 
)

Releases unused buffer.

This API can be called when the Tx buffer reserved by rpmsg_get_tx_payload_buffer needs to be released without having been sent to the remote side.

Note that the rpmsg virtio is not able to detect if a buffer has already been released. The user must prevent a double release (e.g. by resetting its buffer pointer to zero after the release).

Parameters
eptThe rpmsg endpoint
txbuftx buffer with message payload
Returns
  • RPMSG_SUCCESS on success
  • RPMSG_ERR_PARAM on invalid parameter
  • RPMSG_ERR_PERM if service not implemented
See also
rpmsg_get_tx_payload_buffer

◆ rpmsg_send_ns_message()

int rpmsg_send_ns_message ( struct rpmsg_endpoint ept,
unsigned long  flags 
)

◆ rpmsg_send_offchannel_nocopy()

int rpmsg_send_offchannel_nocopy ( struct rpmsg_endpoint ept,
uint32_t  src,
uint32_t  dst,
const void *  data,
int  len 
)

Send a message in tx buffer reserved by rpmsg_get_tx_payload_buffer() across to the remote processor.

This function sends buf of length len to the remote dst address, and uses src as the source address. The message will be sent to the remote processor which the ept endpoint belongs to. The application has to take the responsibility for:

  1. tx buffer reserved (rpmsg_get_tx_payload_buffer() )
  2. filling the data to be sent into the pre-allocated tx buffer
  3. not exceeding the buffer size when filling the data
  4. data cache coherency

After the rpmsg_send_offchannel_nocopy() function is issued the tx buffer is no more owned by the sending task and must not be touched anymore unless the rpmsg_send_offchannel_nocopy() function fails and returns an error. In that case application should try to re-issue the rpmsg_send_offchannel_nocopy() again.

Parameters
eptThe rpmsg endpoint
srcThe rpmsg endpoint local address
dstThe rpmsg endpoint remote address
dataTX buffer with message filled
lenLength of payload
Returns
Number of bytes it has sent or negative error value on failure.
See also
rpmsg_get_tx_payload_buffer
rpmsg_sendto_nocopy
rpmsg_send_nocopy

◆ rpmsg_send_offchannel_raw()

int rpmsg_send_offchannel_raw ( struct rpmsg_endpoint ept,
uint32_t  src,
uint32_t  dst,
const void *  data,
int  len,
int  wait 
)

Send a message across to the remote processor, specifying source and destination address.

This function sends data of length len to the remote dst address from the source src address. The message will be sent to the remote processor which the channel belongs to.

Parameters
eptThe rpmsg endpoint
srcSource endpoint address of the message
dstDestination endpoint address of the message
dataPayload of the message
lenLength of the payload
waitBoolean value indicating whether to wait on buffers
Returns
Number of bytes it has sent or negative error value on failure.

◆ rpmsg_set_address()

static int rpmsg_set_address ( unsigned long *  bitmap,
int  size,
int  addr 
)
static

◆ rpmsg_unregister_endpoint()

static void rpmsg_unregister_endpoint ( struct rpmsg_endpoint ept)
static