Skip to content

Commit

Permalink
openamp: add new ops wait_notified() 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 Apr 18, 2022
1 parent e4307e1 commit 05f138e
Show file tree
Hide file tree
Showing 8 changed files with 60 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 @@ -433,6 +433,18 @@ struct remoteproc_ops {
metal_phys_addr_t da,
void *va, size_t size,
struct remoteproc_mem *buf);
/**
* wait_notified
*
* Wait for remote notified, when there is no TX buffer anymore.
* Set to NULL means use usleep to TX buffer available.
*
* @rproc - pointer to remoteproc instance
* @id - the notifyid
*
* return 0 means there is notify available, otherwise negative value.
*/
int (*wait_notified)(struct remoteproc *rproc, uint32_t id);
};

/* Remoteproc error codes */
Expand Down
3 changes: 3 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_wait_notified_func)(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_wait_notified_func wait_notified;
struct virtio_device vdev;
struct metal_list node;
};
Expand All @@ -62,6 +64,7 @@ rproc_virtio_create_vdev(unsigned int role, unsigned int notifyid,
void *rsc, struct metal_io_region *rsc_io,
void *priv,
rpvdev_notify_func notify,
rpvdev_wait_notified_func wait_notified,
virtio_dev_reset_cb rst_cb);

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

static inline int
rpmsg_virtio_wait_notified(struct rpmsg_virtio_device *rvdev,
struct virtqueue *vq)
{
return rvdev->vdev->func->wait_notified ?
rvdev->vdev->func->wait_notified(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 @@ -137,6 +137,7 @@ struct virtio_dispatch {
void *src, int length);
void (*reset_device)(struct virtio_device *dev);
void (*notify)(struct virtqueue *vq);
int (*wait_notified)(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_wait_notified(void *priv, uint32_t id)
{
struct remoteproc *rproc = priv;

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

return 0;
}

struct virtio_device *
remoteproc_create_virtio(struct remoteproc *rproc,
int vdev_id, unsigned int role,
Expand Down Expand Up @@ -918,6 +928,7 @@ remoteproc_create_virtio(struct remoteproc *rproc,
vdev = rproc_virtio_create_vdev(role, notifyid,
vdev_rsc, vdev_rsc_io, rproc,
remoteproc_virtio_notify,
remoteproc_virtio_wait_notified,
rst_cb);
if (!vdev) {
metal_mutex_release(&rproc->lock);
Expand Down
16 changes: 16 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_wait_notified(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->wait_notified(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,
.wait_notified = rproc_virtio_wait_notified,
#ifndef VIRTIO_SLAVE_ONLY
/*
* We suppose here that the vdev is in a shared memory so that can
Expand All @@ -198,6 +212,7 @@ rproc_virtio_create_vdev(unsigned int role, unsigned int notifyid,
void *rsc, struct metal_io_region *rsc_io,
void *priv,
rpvdev_notify_func notify,
rpvdev_wait_notified_func wait_notified,
virtio_dev_reset_cb rst_cb)
{
struct remoteproc_virtio *rpvdev;
Expand Down Expand Up @@ -233,6 +248,7 @@ rproc_virtio_create_vdev(unsigned int role, unsigned int notifyid,
}

rpvdev->notify = notify;
rpvdev->wait_notified = wait_notified;
rpvdev->priv = priv;
vdev->vrings_info = vrings_info;
/* Assuming the shared memory has been mapped and registered if
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 @@ -346,6 +346,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_wait_notified(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 05f138e

Please sign in to comment.