Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions lib/include/openamp/rpmsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,23 @@ extern "C" {
#endif

/* Configurable parameters */
#define RPMSG_NAME_SIZE (32)
#define RPMSG_ADDR_BMP_SIZE (128)
#define RPMSG_NAME_SIZE (32)
#define RPMSG_ADDR_BMP_SIZE (128)

#define RPMSG_NS_EPT_ADDR (0x35)
#define RPMSG_ADDR_ANY 0xFFFFFFFF
#define RPMSG_NS_EPT_ADDR (0x35)
#define RPMSG_RESERVED_ADDRESSES (1024)
#define RPMSG_ADDR_ANY 0xFFFFFFFF

/* Error macros. */
#define RPMSG_SUCCESS 0
#define RPMSG_ERROR_BASE -2000
#define RPMSG_ERR_NO_MEM (RPMSG_ERROR_BASE - 1)
#define RPMSG_ERR_NO_BUFF (RPMSG_ERROR_BASE - 2)
#define RPMSG_ERR_PARAM (RPMSG_ERROR_BASE - 3)
#define RPMSG_ERR_DEV_STATE (RPMSG_ERROR_BASE - 4)
#define RPMSG_ERR_BUFF_SIZE (RPMSG_ERROR_BASE - 5)
#define RPMSG_ERR_INIT (RPMSG_ERROR_BASE - 6)
#define RPMSG_ERR_ADDR (RPMSG_ERROR_BASE - 7)
#define RPMSG_SUCCESS 0
#define RPMSG_ERROR_BASE -2000
#define RPMSG_ERR_NO_MEM (RPMSG_ERROR_BASE - 1)
#define RPMSG_ERR_NO_BUFF (RPMSG_ERROR_BASE - 2)
#define RPMSG_ERR_PARAM (RPMSG_ERROR_BASE - 3)
#define RPMSG_ERR_DEV_STATE (RPMSG_ERROR_BASE - 4)
#define RPMSG_ERR_BUFF_SIZE (RPMSG_ERROR_BASE - 5)
#define RPMSG_ERR_INIT (RPMSG_ERROR_BASE - 6)
#define RPMSG_ERR_ADDR (RPMSG_ERROR_BASE - 7)
Comment thread
edmooring marked this conversation as resolved.

struct rpmsg_endpoint;
struct rpmsg_device;
Expand Down
28 changes: 18 additions & 10 deletions lib/rpmsg/rpmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static uint32_t rpmsg_get_address(unsigned long *bitmap, int size)

nextbit = metal_bitmap_next_clear_bit(bitmap, 0, size);
Comment thread
edmooring marked this conversation as resolved.
if (nextbit < (uint32_t)size) {
addr = nextbit;
addr = RPMSG_RESERVED_ADDRESSES + nextbit;
metal_bitmap_set_bit(bitmap, nextbit);
}

Expand All @@ -48,7 +48,8 @@ static uint32_t rpmsg_get_address(unsigned long *bitmap, int size)
static void rpmsg_release_address(unsigned long *bitmap, int size,
int addr)
{
if (addr < size)
addr -= RPMSG_RESERVED_ADDRESSES;
if (addr >= 0 && addr < size)
metal_bitmap_clear_bit(bitmap, addr);
}

Expand All @@ -65,7 +66,8 @@ static void rpmsg_release_address(unsigned long *bitmap, int size,
*/
static int rpmsg_is_address_set(unsigned long *bitmap, int size, int addr)
{
if (addr < size)
addr -= RPMSG_RESERVED_ADDRESSES;
if (addr >= 0 && addr < size)
return metal_bitmap_is_bit_set(bitmap, addr);
else
return RPMSG_ERR_PARAM;
Expand All @@ -84,7 +86,8 @@ 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)
{
if (addr < size) {
addr -= RPMSG_RESERVED_ADDRESSES;
if (addr >= 0 && addr < size) {
metal_bitmap_set_bit(bitmap, addr);
return RPMSG_SUCCESS;
} else {
Expand Down Expand Up @@ -207,7 +210,13 @@ int rpmsg_create_ept(struct rpmsg_endpoint *ept, struct rpmsg_device *rdev,
return RPMSG_ERR_PARAM;

metal_mutex_acquire(&rdev->lock);
if (src != RPMSG_ADDR_ANY) {
if (src == RPMSG_ADDR_ANY) {
addr = rpmsg_get_address(rdev->bitmap, RPMSG_ADDR_BMP_SIZE);
if (addr == RPMSG_ADDR_ANY) {
status = RPMSG_ERR_ADDR;
goto ret_status;
}
} else if (src >= RPMSG_RESERVED_ADDRESSES) {
status = rpmsg_is_address_set(rdev->bitmap,
RPMSG_ADDR_BMP_SIZE, src);
if (!status) {
Expand All @@ -221,11 +230,10 @@ int rpmsg_create_ept(struct rpmsg_endpoint *ept, struct rpmsg_device *rdev,
goto ret_status;
}
} else {
addr = rpmsg_get_address(rdev->bitmap, RPMSG_ADDR_BMP_SIZE);
if (addr == RPMSG_ADDR_ANY) {
status = RPMSG_ERR_ADDR;
goto ret_status;
}
/* Skip check the address duplication in 0-1023:
* 1.Trust the author of predefined service
* 2.Simplify the tracking implementation
*/
}

rpmsg_init_ept(ept, name, addr, dest, cb, unbind_cb);
Expand Down