rpmsg_lite.h
/*
* Copyright (c) 2014, Mentor Graphics Corporation
* Copyright (c) 2015 Xilinx, Inc.
* Copyright (c) 2016 Freescale Semiconductor, Inc.
* Copyright 2016-2019 NXP
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _RPMSG_LITE_H
#define _RPMSG_LITE_H
#if defined(__cplusplus)
extern "C" {
#endif
#include <stddef.h>
#include "virtqueue.h"
#include "rpmsg_env.h"
#include "llist.h"
#include "rpmsg_compiler.h"
#include "rpmsg_default_config.h"
/*******************************************************************************
* Definitions
******************************************************************************/
#define RL_VERSION "2.2.0"
/* Shared memory "allocator" parameters */
#define RL_WORD_SIZE (sizeof(unsigned long))
#define RL_WORD_ALIGN_UP(a) \
(((((unsigned long)a) & (RL_WORD_SIZE - 1)) != 0) ? ((((unsigned long)a) & (~(RL_WORD_SIZE - 1))) + 4) : \
((unsigned long)a))
#define RL_WORD_ALIGN_DOWN(a) \
(((((unsigned long)a) & (RL_WORD_SIZE - 1)) != 0) ? (((unsigned long)a) & (~(RL_WORD_SIZE - 1))) : \
((unsigned long)a))
/* Definitions for device types , null pointer, etc.*/
#define RL_SUCCESS (0)
#define RL_NULL ((void *)0)
#define RL_REMOTE (0)
#define RL_MASTER (1)
#define RL_TRUE (1)
#define RL_FALSE (0)
#define RL_ADDR_ANY (0xFFFFFFFF)
#define RL_RELEASE (0)
#define RL_HOLD (1)
#define RL_DONT_BLOCK (0)
#define RL_BLOCK (0xFFFFFFFF)
/* Error macros. */
#define RL_ERRORS_BASE (-5000)
#define RL_ERR_NO_MEM (RL_ERRORS_BASE - 1)
#define RL_ERR_BUFF_SIZE (RL_ERRORS_BASE - 2)
#define RL_ERR_PARAM (RL_ERRORS_BASE - 3)
#define RL_ERR_DEV_ID (RL_ERRORS_BASE - 4)
#define RL_ERR_MAX_VQ (RL_ERRORS_BASE - 5)
#define RL_ERR_NO_BUFF (RL_ERRORS_BASE - 6)
#define RL_NOT_READY (RL_ERRORS_BASE - 7)
#define RL_ALREADY_DONE (RL_ERRORS_BASE - 8)
/* Init flags */
#define RL_NO_FLAGS (0)
typedef int (*rl_ept_rx_cb_t)(void *payload, int payload_len, unsigned long src, void *priv);
struct rpmsg_lite_endpoint
{
unsigned long addr;
rl_ept_rx_cb_t rx_cb;
void *rx_cb_data;
void *rfu;
/* 16 bytes aligned on 32bit architecture */
};
struct rpmsg_lite_ept_static_context
{
struct rpmsg_lite_endpoint ept;
struct llist node;
};
struct rpmsg_lite_instance
{
struct virtqueue *rvq;
struct virtqueue *tvq;
struct llist *rl_endpoints;
LOCK *lock;
unsigned int link_state;
char *sh_mem_base;
unsigned int sh_mem_remaining;
unsigned int sh_mem_total;
struct virtqueue_ops const *vq_ops;
#if defined(RL_USE_ENVIRONMENT_CONTEXT) && (RL_USE_ENVIRONMENT_CONTEXT == 1)
void *env;
#endif
#if defined(RL_USE_STATIC_API) && (RL_USE_STATIC_API == 1)
struct vq_static_context vq_ctxt[2];
#endif
};
/*******************************************************************************
* API
******************************************************************************/
/* Exported API functions */
#if defined(RL_USE_STATIC_API) && (RL_USE_STATIC_API == 1)
struct rpmsg_lite_instance *rpmsg_lite_master_init(void *shmem_addr,
size_t shmem_length,
int link_id,
uint32_t init_flags,
struct rpmsg_lite_instance *static_context);
#elif defined(RL_USE_ENVIRONMENT_CONTEXT) && (RL_USE_ENVIRONMENT_CONTEXT == 1)
struct rpmsg_lite_instance *rpmsg_lite_master_init(void *shmem_addr,
size_t shmem_length,
int link_id,
uint32_t init_flags,
void *env_cfg);
#else
struct rpmsg_lite_instance *rpmsg_lite_master_init(void *shmem_addr,
size_t shmem_length,
int link_id,
uint32_t init_flags);
#endif
#if defined(RL_USE_STATIC_API) && (RL_USE_STATIC_API == 1)
struct rpmsg_lite_instance *rpmsg_lite_remote_init(void *shmem_addr,
int link_id,
uint32_t init_flags,
struct rpmsg_lite_instance *static_context);
#elif defined(RL_USE_ENVIRONMENT_CONTEXT) && (RL_USE_ENVIRONMENT_CONTEXT == 1)
struct rpmsg_lite_instance *rpmsg_lite_remote_init(void *shmem_addr, int link_id, uint32_t init_flags, void *env_cfg);
#else
struct rpmsg_lite_instance *rpmsg_lite_remote_init(void *shmem_addr, int link_id, uint32_t init_flags);
#endif
int rpmsg_lite_deinit(struct rpmsg_lite_instance *rpmsg_lite_dev);
#if defined(RL_USE_STATIC_API) && (RL_USE_STATIC_API == 1)
struct rpmsg_lite_endpoint *rpmsg_lite_create_ept(struct rpmsg_lite_instance *rpmsg_lite_dev,
unsigned long addr,
rl_ept_rx_cb_t rx_cb,
void *rx_cb_data,
struct rpmsg_lite_ept_static_context *ept_context);
#else
struct rpmsg_lite_endpoint *rpmsg_lite_create_ept(struct rpmsg_lite_instance *rpmsg_lite_dev,
unsigned long addr,
rl_ept_rx_cb_t rx_cb,
void *rx_cb_data);
#endif
int rpmsg_lite_destroy_ept(struct rpmsg_lite_instance *rpmsg_lite_dev, struct rpmsg_lite_endpoint *rl_ept);
int rpmsg_lite_send(struct rpmsg_lite_instance *rpmsg_lite_dev,
struct rpmsg_lite_endpoint *ept,
unsigned long dst,
char *data,
unsigned long size,
unsigned long timeout);
int rpmsg_lite_is_link_up(struct rpmsg_lite_instance *rpmsg_lite_dev);
#if defined(RL_API_HAS_ZEROCOPY) && (RL_API_HAS_ZEROCOPY == 1)
int rpmsg_lite_release_rx_buffer(struct rpmsg_lite_instance *rpmsg_lite_dev, void *rxbuf);
void *rpmsg_lite_alloc_tx_buffer(struct rpmsg_lite_instance *rpmsg_lite_dev,
unsigned long *size,
unsigned long timeout);
int rpmsg_lite_send_nocopy(struct rpmsg_lite_instance *rpmsg_lite_dev,
struct rpmsg_lite_endpoint *ept,
unsigned long dst,
void *data,
unsigned long size);
#endif /* RL_API_HAS_ZEROCOPY */
#if defined(__cplusplus)
}
#endif
#endif /* _RPMSG_LITE_H */
rpmsg_lite_instance::lock
LOCK * lock
Definition: rpmsg_lite.h:129
rpmsg_lite_send
int rpmsg_lite_send(struct rpmsg_lite_instance *rpmsg_lite_dev, struct rpmsg_lite_endpoint *ept, unsigned long dst, char *data, unsigned long size, unsigned long timeout)
Sends a message contained in data field of length size to the remote endpoint with address dst...
rpmsg_lite_instance
Definition: rpmsg_lite.h:124
rpmsg_lite_master_init
struct rpmsg_lite_instance * rpmsg_lite_master_init(void *shmem_addr, size_t shmem_length, int link_id, uint32_t init_flags)
Initializes the RPMsg-Lite communication stack. Must be called prior to any other RPMSG lite API...
rpmsg_lite_instance::sh_mem_base
char * sh_mem_base
Definition: rpmsg_lite.h:131
rpmsg_lite_remote_init
struct rpmsg_lite_instance * rpmsg_lite_remote_init(void *shmem_addr, int link_id, uint32_t init_flags)
Initializes the RPMsg-Lite communication stack. Must be called prior to any other RPMsg-Lite API...
rpmsg_lite_alloc_tx_buffer
void * rpmsg_lite_alloc_tx_buffer(struct rpmsg_lite_instance *rpmsg_lite_dev, unsigned long *size, unsigned long timeout)
Allocates the tx buffer for message payload.
rpmsg_lite_send_nocopy
int rpmsg_lite_send_nocopy(struct rpmsg_lite_instance *rpmsg_lite_dev, struct rpmsg_lite_endpoint *ept, unsigned long dst, void *data, unsigned long size)
Sends a message in tx buffer allocated by rpmsg_lite_alloc_tx_buffer()
rpmsg_lite_endpoint::rfu
void * rfu
Definition: rpmsg_lite.h:105
rpmsg_lite_create_ept
struct rpmsg_lite_endpoint * rpmsg_lite_create_ept(struct rpmsg_lite_instance *rpmsg_lite_dev, unsigned long addr, rl_ept_rx_cb_t rx_cb, void *rx_cb_data)
Create a new rpmsg endpoint, which can be used for communication.
rpmsg_lite_ept_static_context
Definition: rpmsg_lite.h:112
rpmsg_lite_instance::vq_ops
struct virtqueue_ops const * vq_ops
Definition: rpmsg_lite.h:134
rpmsg_lite_instance::sh_mem_remaining
unsigned int sh_mem_remaining
Definition: rpmsg_lite.h:132
rpmsg_lite_deinit
int rpmsg_lite_deinit(struct rpmsg_lite_instance *rpmsg_lite_dev)
Deinitialized the RPMsg-Lite communication stack This function always succeeds. rpmsg_lite_init() can...
rpmsg_lite_endpoint::rx_cb_data
void * rx_cb_data
Definition: rpmsg_lite.h:104
rpmsg_default_config.h
rpmsg_lite_instance::sh_mem_total
unsigned int sh_mem_total
Definition: rpmsg_lite.h:133
rpmsg_lite_instance::link_state
unsigned int link_state
Definition: rpmsg_lite.h:130
rpmsg_lite_is_link_up
int rpmsg_lite_is_link_up(struct rpmsg_lite_instance *rpmsg_lite_dev)
Function to get the link state.
rpmsg_lite_instance::rvq
struct virtqueue * rvq
Definition: rpmsg_lite.h:126
rl_ept_rx_cb_t
int(* rl_ept_rx_cb_t)(void *payload, int payload_len, unsigned long src, void *priv)
Receive callback function type.
Definition: rpmsg_lite.h:95
rpmsg_lite_release_rx_buffer
int rpmsg_lite_release_rx_buffer(struct rpmsg_lite_instance *rpmsg_lite_dev, void *rxbuf)
Releases the rx buffer for future reuse in vring. This API can be called at process context when the ...
rpmsg_lite_endpoint
Definition: rpmsg_lite.h:100
rpmsg_lite_endpoint::addr
unsigned long addr
Definition: rpmsg_lite.h:102
rpmsg_lite_instance::rl_endpoints
struct llist * rl_endpoints
Definition: rpmsg_lite.h:128
rpmsg_lite_instance::tvq
struct virtqueue * tvq
Definition: rpmsg_lite.h:127
rpmsg_lite_endpoint::rx_cb
rl_ept_rx_cb_t rx_cb
Definition: rpmsg_lite.h:103
rpmsg_lite_destroy_ept
int rpmsg_lite_destroy_ept(struct rpmsg_lite_instance *rpmsg_lite_dev, struct rpmsg_lite_endpoint *rl_ept)
This function deletes rpmsg endpoint and performs cleanup.