Skip to content

Commit

Permalink
openamp: decouple rpmsg virtio and remoteproc.
Browse files Browse the repository at this point in the history
add notify_wait_cb in rpmsg virtio to call notify_wait.

Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
  • Loading branch information
wyr-7 committed Mar 8, 2024
1 parent 749d934 commit 3784214
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/include/openamp/rpmsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ extern "C" {
#define RPMSG_ERR_INIT (RPMSG_ERROR_BASE - 6)
#define RPMSG_ERR_ADDR (RPMSG_ERROR_BASE - 7)
#define RPMSG_ERR_PERM (RPMSG_ERROR_BASE - 8)
#define RPMSG_EOPNOTSUPP (RPMSG_ERROR_BASE - 9)

struct rpmsg_endpoint;
struct rpmsg_device;
Expand Down
9 changes: 9 additions & 0 deletions lib/include/openamp/rpmsg_virtio.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ extern "C" {
#define BUFFER_INVALIDATE(x, s) do { } while (0)
#endif /* VIRTIO_CACHED_BUFFERS || VIRTIO_USE_DCACHE */

/* Callback handler for rpmsg virtio service */
typedef int (*rpmsg_virtio_notify_wait_cb)(struct rpmsg_device *rdev, uint32_t id);

/** @brief Shared memory pool used for RPMsg buffers */
struct rpmsg_virtio_shm_pool {
/** Base address of the memory pool */
Expand Down Expand Up @@ -98,6 +101,12 @@ struct rpmsg_virtio_device {
* \ref rpmsg_virtio_release_tx_buffer function
*/
struct metal_list reclaimer;

/**
* Callback handler for rpmsg virtio service, called when service
* can't get tx buffer
*/
rpmsg_virtio_notify_wait_cb notify_wait_cb;
};

#define RPMSG_REMOTE VIRTIO_DEV_DEVICE
Expand Down
2 changes: 2 additions & 0 deletions lib/rpmsg/rpmsg_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ rpmsg_get_ept_from_addr(struct rpmsg_device *rdev, uint32_t addr)
return rpmsg_get_endpoint(rdev, NULL, addr, RPMSG_ADDR_ANY);
}

int rpmsg_notify_wait(struct rpmsg_device *rdev, uint32_t id);

/**
* @internal
*
Expand Down
25 changes: 23 additions & 2 deletions lib/rpmsg/rpmsg_virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,19 @@ static void rpmsg_virtio_release_rx_buffer(struct rpmsg_device *rdev,
metal_mutex_release(&rdev->lock);
}

static int rpmsg_virtio_notify_wait(struct rpmsg_virtio_device *rvdev,
struct virtqueue *vq)
{
struct virtio_vring_info *vring_info;

vring_info = &rvdev->vdev->vrings_info[vq->vq_queue_index];

if (rvdev->notify_wait_cb)
return rvdev->notify_wait_cb(&rvdev->rdev, vring_info->notifyid);

return RPMSG_EOPNOTSUPP;
}

static void *rpmsg_virtio_get_tx_payload_buffer(struct rpmsg_device *rdev,
uint32_t *len, int wait)
{
Expand Down Expand Up @@ -387,8 +400,16 @@ static void *rpmsg_virtio_get_tx_payload_buffer(struct rpmsg_device *rdev,
metal_mutex_release(&rdev->lock);
if (rp_hdr || !tick_count)
break;
metal_sleep_usec(RPMSG_TICKS_PER_INTERVAL);
tick_count--;

/*
* Try to use wait loop implemented in the virtio dispatcher and
* use metal_sleep_usec() method by default.
*/
status = rpmsg_virtio_notify_wait(rvdev, rvdev->rvq);
if (status != RPMSG_SUCCESS) {
metal_sleep_usec(RPMSG_TICKS_PER_INTERVAL);
tick_count--;
}
}

if (!rp_hdr)
Expand Down

0 comments on commit 3784214

Please sign in to comment.