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 Jul 25, 2022
1 parent afed3bd commit f4d445f
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 @@ -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 wait 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
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_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 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_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 @@ -162,6 +162,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 @@ -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->wait_notified = remoteproc_virtio_wait_notified;
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_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_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_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 f4d445f

Please sign in to comment.