Skip to content

Commit 518e507

Browse files
rpmsg: shouldn't allocate 0-1023 address in rpmsg_create_ept
since this region is reserved for predefined services(e.g. NS use 0x35) Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
1 parent 20292c5 commit 518e507

2 files changed

Lines changed: 28 additions & 24 deletions

File tree

lib/include/openamp/rpmsg.h

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,23 @@ extern "C" {
2525
#endif
2626

2727
/* Configurable parameters */
28-
#define RPMSG_NAME_SIZE (32)
29-
#define RPMSG_ADDR_BMP_SIZE (128)
28+
#define RPMSG_NAME_SIZE (32)
29+
#define RPMSG_ADDR_BMP_SIZE (128)
3030

31-
#define RPMSG_NS_EPT_ADDR (0x35)
32-
#define RPMSG_ADDR_ANY 0xFFFFFFFF
31+
#define RPMSG_NS_EPT_ADDR (0x35)
32+
#define RPMSG_RESERVED_ADDRESSES (1024)
33+
#define RPMSG_ADDR_ANY 0xFFFFFFFF
3334

3435
/* Error macros. */
35-
#define RPMSG_SUCCESS 0
36-
#define RPMSG_ERROR_BASE -2000
37-
#define RPMSG_ERR_NO_MEM (RPMSG_ERROR_BASE - 1)
38-
#define RPMSG_ERR_NO_BUFF (RPMSG_ERROR_BASE - 2)
39-
#define RPMSG_ERR_PARAM (RPMSG_ERROR_BASE - 3)
40-
#define RPMSG_ERR_DEV_STATE (RPMSG_ERROR_BASE - 4)
41-
#define RPMSG_ERR_BUFF_SIZE (RPMSG_ERROR_BASE - 5)
42-
#define RPMSG_ERR_INIT (RPMSG_ERROR_BASE - 6)
43-
#define RPMSG_ERR_ADDR (RPMSG_ERROR_BASE - 7)
36+
#define RPMSG_SUCCESS 0
37+
#define RPMSG_ERROR_BASE -2000
38+
#define RPMSG_ERR_NO_MEM (RPMSG_ERROR_BASE - 1)
39+
#define RPMSG_ERR_NO_BUFF (RPMSG_ERROR_BASE - 2)
40+
#define RPMSG_ERR_PARAM (RPMSG_ERROR_BASE - 3)
41+
#define RPMSG_ERR_DEV_STATE (RPMSG_ERROR_BASE - 4)
42+
#define RPMSG_ERR_BUFF_SIZE (RPMSG_ERROR_BASE - 5)
43+
#define RPMSG_ERR_INIT (RPMSG_ERROR_BASE - 6)
44+
#define RPMSG_ERR_ADDR (RPMSG_ERROR_BASE - 7)
4445

4546
struct rpmsg_endpoint;
4647
struct rpmsg_device;

lib/rpmsg/rpmsg.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static uint32_t rpmsg_get_address(unsigned long *bitmap, int size)
2929

3030
nextbit = metal_bitmap_next_clear_bit(bitmap, 0, size);
3131
if (nextbit < (uint32_t)size) {
32-
addr = nextbit;
32+
addr = RPMSG_RESERVED_ADDRESSES + nextbit;
3333
metal_bitmap_set_bit(bitmap, nextbit);
3434
}
3535

@@ -48,7 +48,8 @@ static uint32_t rpmsg_get_address(unsigned long *bitmap, int size)
4848
static void rpmsg_release_address(unsigned long *bitmap, int size,
4949
int addr)
5050
{
51-
if (addr < size)
51+
addr -= RPMSG_RESERVED_ADDRESSES;
52+
if (addr >= 0 && addr < size)
5253
metal_bitmap_clear_bit(bitmap, addr);
5354
}
5455

@@ -65,7 +66,8 @@ static void rpmsg_release_address(unsigned long *bitmap, int size,
6566
*/
6667
static int rpmsg_is_address_set(unsigned long *bitmap, int size, int addr)
6768
{
68-
if (addr < size)
69+
addr -= RPMSG_RESERVED_ADDRESSES;
70+
if (addr >= 0 && addr < size)
6971
return metal_bitmap_is_bit_set(bitmap, addr);
7072
else
7173
return RPMSG_ERR_PARAM;
@@ -84,7 +86,8 @@ static int rpmsg_is_address_set(unsigned long *bitmap, int size, int addr)
8486
*/
8587
static int rpmsg_set_address(unsigned long *bitmap, int size, int addr)
8688
{
87-
if (addr < size) {
89+
addr -= RPMSG_RESERVED_ADDRESSES;
90+
if (addr >= 0 && addr < size) {
8891
metal_bitmap_set_bit(bitmap, addr);
8992
return RPMSG_SUCCESS;
9093
} else {
@@ -207,7 +210,13 @@ int rpmsg_create_ept(struct rpmsg_endpoint *ept, struct rpmsg_device *rdev,
207210
return RPMSG_ERR_PARAM;
208211

209212
metal_mutex_acquire(&rdev->lock);
210-
if (src != RPMSG_ADDR_ANY) {
213+
if (src == RPMSG_ADDR_ANY) {
214+
addr = rpmsg_get_address(rdev->bitmap, RPMSG_ADDR_BMP_SIZE);
215+
if (addr == RPMSG_ADDR_ANY) {
216+
status = RPMSG_ERR_ADDR;
217+
goto ret_status;
218+
}
219+
} else if (src >= RPMSG_RESERVED_ADDRESSES) {
211220
status = rpmsg_is_address_set(rdev->bitmap,
212221
RPMSG_ADDR_BMP_SIZE, src);
213222
if (!status) {
@@ -220,12 +229,6 @@ int rpmsg_create_ept(struct rpmsg_endpoint *ept, struct rpmsg_device *rdev,
220229
} else {
221230
goto ret_status;
222231
}
223-
} else {
224-
addr = rpmsg_get_address(rdev->bitmap, RPMSG_ADDR_BMP_SIZE);
225-
if (addr == RPMSG_ADDR_ANY) {
226-
status = RPMSG_ERR_ADDR;
227-
goto ret_status;
228-
}
229232
}
230233

231234
rpmsg_init_ept(ept, name, addr, dest, cb, unbind_cb);

0 commit comments

Comments
 (0)