Skip to content

Commit

Permalink
rpmsg: set ept address to incease num when alloc from the bitmap
Browse files Browse the repository at this point in the history
CPU0                                CPU1
create_ept1:addr1                   create_ept1
OK                       <======    msg1
OK                       <======    msg2
OK                       <======    msg3
                           msg4
                         <======    msg4 on the virtioqueue
close_ept1                          close_ept1

create_ept2:addr1                   create_ept1
(same addr with ept1)
                           msg4
ept2 recv ept1 msg ERROR <======

The msg4 which belong to ep1, error received by ept2.

For this issue, I give a resolve method:
Let the rpmsg_get_address() always return a new increased num.

Signed-off-by: Guiding Li <liguiding1@xiaomi.com>
  • Loading branch information
GUIDINGLI authored and arnopo committed Oct 31, 2023
1 parent 1904dee commit bbefedd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/include/openamp/rpmsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ struct rpmsg_device {

/** Table endpoint address allocation */
unsigned long bitmap[metal_bitmap_longs(RPMSG_ADDR_BMP_SIZE)];
unsigned int bitnext;

/** Mutex lock for RPMsg management */
metal_mutex_t lock;
Expand Down
7 changes: 4 additions & 3 deletions lib/rpmsg/rpmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
*
* @return A unique address
*/
static uint32_t rpmsg_get_address(unsigned long *bitmap, int size)
static uint32_t rpmsg_get_address(unsigned long *bitmap, unsigned int start, int size)
{
unsigned int addr = RPMSG_ADDR_ANY;
unsigned int nextbit;

nextbit = metal_bitmap_next_clear_bit(bitmap, 0, size);
nextbit = metal_bitmap_next_clear_bit(bitmap, start, size);
if (nextbit < (uint32_t)size) {
addr = RPMSG_RESERVED_ADDRESSES + nextbit;
metal_bitmap_set_bit(bitmap, nextbit);
Expand Down Expand Up @@ -277,11 +277,12 @@ int rpmsg_create_ept(struct rpmsg_endpoint *ept, struct rpmsg_device *rdev,

metal_mutex_acquire(&rdev->lock);
if (src == RPMSG_ADDR_ANY) {
addr = rpmsg_get_address(rdev->bitmap, RPMSG_ADDR_BMP_SIZE);
addr = rpmsg_get_address(rdev->bitmap, rdev->bitnext, RPMSG_ADDR_BMP_SIZE);
if (addr == RPMSG_ADDR_ANY) {
status = RPMSG_ERR_ADDR;
goto ret_status;
}
rdev->bitnext = (addr + 1) % RPMSG_ADDR_BMP_SIZE;
} else if (src >= RPMSG_RESERVED_ADDRESSES) {
status = rpmsg_is_address_set(rdev->bitmap,
RPMSG_ADDR_BMP_SIZE, src);
Expand Down

0 comments on commit bbefedd

Please sign in to comment.