Skip to content

Commit

Permalink
openamp: add new ops notify_wait() support
Browse files Browse the repository at this point in the history
This can avoid looping check tx buffer

Signed-off-by: Guiding Li <[email protected]>
  • Loading branch information
GUIDINGLI committed Jul 29, 2022
1 parent afed3bd commit 056bdf3
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/include/openamp/remoteproc.h
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,18 @@ struct remoteproc_ops {
int (*stop)(struct remoteproc *rproc);
int (*shutdown)(struct remoteproc *rproc);
int (*notify)(struct remoteproc *rproc, uint32_t id);
/**
* notify_wait
*
* Wait for remote notified, when there is no TX buffer anymore.
* Set to NULL means use usleep to wait TX buffer available.
*
* @rproc - pointer to remoteproc instance
* @id - the notifyid
*
* return 0 means there is notify available, otherwise negative value.
*/
int (*notify_wait)(struct remoteproc *rproc, uint32_t id);
/**
* get_mem
*
Expand Down
2 changes: 2 additions & 0 deletions lib/include/openamp/remoteproc_virtio.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ extern "C" {

/* define vdev notification function user should implement */
typedef int (*rpvdev_notify_func)(void *priv, uint32_t id);
typedef int (*rpvdev_notify_wait)(void *priv, uint32_t id);

/**
* struct remoteproc_virtio
Expand All @@ -37,6 +38,7 @@ struct remoteproc_virtio {
void *vdev_rsc;
struct metal_io_region *vdev_rsc_io;
rpvdev_notify_func notify;
rpvdev_notify_wait notify_wait;
struct virtio_device vdev;
struct metal_list node;
};
Expand Down
1 change: 1 addition & 0 deletions lib/include/openamp/rpmsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ extern "C" {
#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_ERR_NXIO (RPMSG_ERROR_BASE - 8)

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 @@ -140,6 +140,15 @@ rpmsg_virtio_create_virtqueues(struct rpmsg_virtio_device *rvdev,
callbacks);
}

static inline int
rpmsg_virtio_notify_wait(struct rpmsg_virtio_device *rvdev,
struct virtqueue *vq)
{
return rvdev->vdev->func->notify_wait ?
rvdev->vdev->func->notify_wait(rvdev->vdev, vq) :
RPMSG_ERR_NXIO;
}

/**
* rpmsg_virtio_get_buffer_size - get rpmsg virtio buffer size
*
Expand Down
1 change: 1 addition & 0 deletions lib/include/openamp/virtio.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ struct virtio_dispatch {
void *src, int length);
void (*reset_device)(struct virtio_device *dev);
void (*notify)(struct virtqueue *vq);
int (*notify_wait)(struct virtio_device *dev, struct virtqueue *vq);
};

int virtio_create_virtqueues(struct virtio_device *vdev, unsigned int flags,
Expand Down
11 changes: 11 additions & 0 deletions lib/remoteproc/remoteproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,16 @@ static int remoteproc_virtio_notify(void *priv, uint32_t id)
return 0;
}

static int remoteproc_virtio_notify_wait(void *priv, uint32_t id)
{
struct remoteproc *rproc = priv;

if (rproc->ops->notify_wait)
return rproc->ops->notify_wait(rproc, id);

return 0;
}

struct virtio_device *
remoteproc_create_virtio(struct remoteproc *rproc,
int vdev_id, unsigned int role,
Expand Down Expand Up @@ -927,6 +937,7 @@ remoteproc_create_virtio(struct remoteproc *rproc,
rproc_virtio_wait_remote_ready(vdev);

rpvdev = metal_container_of(vdev, struct remoteproc_virtio, vdev);
rpvdev->notify_wait = remoteproc_virtio_notify_wait;
metal_list_add_tail(&rproc->vdevs, &rpvdev->node);
num_vrings = vdev_rsc->num_of_vrings;

Expand Down
14 changes: 14 additions & 0 deletions lib/remoteproc/remoteproc_virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ static void rproc_virtio_virtqueue_notify(struct virtqueue *vq)
rpvdev->notify(rpvdev->priv, vring_info->notifyid);
}

static int rproc_virtio_notify_wait(struct virtio_device *vdev,
struct virtqueue *vq)
{
struct remoteproc_virtio *rpvdev;
struct virtio_vring_info *vring_info;
unsigned int vq_id = vq->vq_queue_index;

rpvdev = metal_container_of(vdev, struct remoteproc_virtio, vdev);
vring_info = &vdev->vrings_info[vq_id];

return rpvdev->notify_wait(rpvdev->priv, vring_info->notifyid);
}

static unsigned char rproc_virtio_get_status(struct virtio_device *vdev)
{
struct remoteproc_virtio *rpvdev;
Expand Down Expand Up @@ -179,6 +192,7 @@ static const struct virtio_dispatch remoteproc_virtio_dispatch_funcs = {
.get_features = rproc_virtio_get_features,
.read_config = rproc_virtio_read_config,
.notify = rproc_virtio_virtqueue_notify,
.notify_wait = rproc_virtio_notify_wait,
#ifndef VIRTIO_DEVICE_ONLY
/*
* We suppose here that the vdev is in a shared memory so that can
Expand Down
7 changes: 7 additions & 0 deletions lib/rpmsg/rpmsg_virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,13 @@ static void *rpmsg_virtio_get_tx_payload_buffer(struct rpmsg_device *rdev,
metal_mutex_release(&rdev->lock);
if (rp_hdr || !tick_count)
break;

status = rpmsg_virtio_notify_wait(rvdev, rvdev->rvq);
if (status == RPMSG_SUCCESS)
continue;
else if (status != RPMSG_ERR_NXIO)
break;

metal_sleep_usec(RPMSG_TICKS_PER_INTERVAL);
tick_count--;
}
Expand Down

0 comments on commit 056bdf3

Please sign in to comment.