Skip to content

Commit

Permalink
rpmsg_virtio: Deprecate RPMSG_HOST and RPMSG_REMOTE definitions
Browse files Browse the repository at this point in the history
For all cases when the role is checked in rpmsg_virtio, what is being
checked is the role of the underlying virtio layer. As such, we should
be matching against the role definitions for the virtio layer
(VIRTIO_DEV_DEVICE and VIRTIO_DEV_DRIVER). Fix this here.

While the underlying virtio layer may be asymmetric, the RPMSG layer
generally is symmetrical. There is no need to define a HOST or REMOTE
role specific to the RPMSG layer. And as there are now no more internal
users of these definitions, deprecate them here.

Signed-off-by: Andrew Davis <[email protected]>
  • Loading branch information
glneo committed Apr 23, 2024
1 parent bbf598f commit 6f9020a
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions lib/rpmsg/rpmsg_virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ static void rpmsg_virtio_return_buffer(struct rpmsg_virtio_device *rvdev,

BUFFER_INVALIDATE(buffer, len);

if (VIRTIO_ENABLED(VIRTIO_DRIVER_SUPPORT) && role == RPMSG_HOST) {
if (VIRTIO_ENABLED(VIRTIO_DRIVER_SUPPORT) && role == VIRTIO_DEV_DRIVER) {
struct virtqueue_buf vqbuf;

(void)idx;
Expand All @@ -125,7 +125,7 @@ static void rpmsg_virtio_return_buffer(struct rpmsg_virtio_device *rvdev,
RPMSG_ASSERT(ret == VQUEUE_SUCCESS, "add buffer failed\r\n");
}

if (VIRTIO_ENABLED(VIRTIO_DEVICE_SUPPORT) && role == RPMSG_REMOTE) {
if (VIRTIO_ENABLED(VIRTIO_DEVICE_SUPPORT) && role == VIRTIO_DEV_DEVICE) {
(void)buffer;
ret = virtqueue_add_consumed_buffer(rvdev->rvq, idx, len);
RPMSG_ASSERT(ret == VQUEUE_SUCCESS, "add consumed buffer failed\r\n");
Expand All @@ -152,7 +152,7 @@ static int rpmsg_virtio_enqueue_buffer(struct rpmsg_virtio_device *rvdev,

BUFFER_FLUSH(buffer, len);

if (VIRTIO_ENABLED(VIRTIO_DRIVER_SUPPORT) && role == RPMSG_HOST) {
if (VIRTIO_ENABLED(VIRTIO_DRIVER_SUPPORT) && role == VIRTIO_DEV_DRIVER) {
struct virtqueue_buf vqbuf;
(void)idx;

Expand All @@ -162,7 +162,7 @@ static int rpmsg_virtio_enqueue_buffer(struct rpmsg_virtio_device *rvdev,
return virtqueue_add_buffer(rvdev->svq, &vqbuf, 1, 0, buffer);
}

if (VIRTIO_ENABLED(VIRTIO_DEVICE_SUPPORT) && role == RPMSG_REMOTE) {
if (VIRTIO_ENABLED(VIRTIO_DEVICE_SUPPORT) && role == VIRTIO_DEV_DEVICE) {
(void)buffer;
return virtqueue_add_consumed_buffer(rvdev->svq, idx, len);
}
Expand Down Expand Up @@ -197,19 +197,19 @@ static void *rpmsg_virtio_get_tx_buffer(struct rpmsg_virtio_device *rvdev,
data = r_desc;
*idx = r_desc->idx;

if (VIRTIO_ENABLED(VIRTIO_DRIVER_SUPPORT) && role == RPMSG_HOST)
if (VIRTIO_ENABLED(VIRTIO_DRIVER_SUPPORT) && role == VIRTIO_DEV_DRIVER)
*len = rvdev->config.h2r_buf_size;
if (VIRTIO_ENABLED(VIRTIO_DEVICE_SUPPORT) && role == RPMSG_REMOTE)
if (VIRTIO_ENABLED(VIRTIO_DEVICE_SUPPORT) && role == VIRTIO_DEV_DEVICE)
*len = virtqueue_get_buffer_length(rvdev->svq, *idx);
} else if (VIRTIO_ENABLED(VIRTIO_DRIVER_SUPPORT) && role == RPMSG_HOST) {
} else if (VIRTIO_ENABLED(VIRTIO_DRIVER_SUPPORT) && role == VIRTIO_DEV_DRIVER) {
data = virtqueue_get_buffer(rvdev->svq, len, idx);
if (!data && rvdev->svq->vq_free_cnt) {
data = rpmsg_virtio_shm_pool_get_buffer(rvdev->shpool,
rvdev->config.h2r_buf_size);
*len = rvdev->config.h2r_buf_size;
*idx = 0;
}
} else if (VIRTIO_ENABLED(VIRTIO_DEVICE_SUPPORT) && role == RPMSG_REMOTE) {
} else if (VIRTIO_ENABLED(VIRTIO_DEVICE_SUPPORT) && role == VIRTIO_DEV_DEVICE) {
data = virtqueue_get_available_buffer(rvdev->svq, idx, len);
}

Expand All @@ -233,11 +233,11 @@ static void *rpmsg_virtio_get_rx_buffer(struct rpmsg_virtio_device *rvdev,
unsigned int role = rpmsg_virtio_get_role(rvdev);
void *data = NULL;

if (VIRTIO_ENABLED(VIRTIO_DRIVER_SUPPORT) && role == RPMSG_HOST) {
if (VIRTIO_ENABLED(VIRTIO_DRIVER_SUPPORT) && role == VIRTIO_DEV_DRIVER) {
data = virtqueue_get_buffer(rvdev->rvq, len, idx);
}

if (VIRTIO_ENABLED(VIRTIO_DEVICE_SUPPORT) && role == RPMSG_REMOTE) {
if (VIRTIO_ENABLED(VIRTIO_DEVICE_SUPPORT) && role == VIRTIO_DEV_DEVICE) {
data =
virtqueue_get_available_buffer(rvdev->rvq, idx, len);
}
Expand Down Expand Up @@ -452,7 +452,7 @@ static int rpmsg_virtio_send_offchannel_nocopy(struct rpmsg_device *rdev,

metal_mutex_acquire(&rdev->lock);

if (VIRTIO_ENABLED(VIRTIO_DRIVER_SUPPORT) && rpmsg_virtio_get_role(rvdev) == RPMSG_HOST)
if (VIRTIO_ENABLED(VIRTIO_DRIVER_SUPPORT) && rpmsg_virtio_get_role(rvdev) == VIRTIO_DEV_DRIVER)
buff_len = rvdev->config.h2r_buf_size;
else
buff_len = virtqueue_get_buffer_length(rvdev->svq, idx);
Expand Down Expand Up @@ -714,15 +714,15 @@ int rpmsg_virtio_get_tx_buffer_size(struct rpmsg_device *rdev)
rvdev = (struct rpmsg_virtio_device *)rdev;
role = rpmsg_virtio_get_role(rvdev);

if (VIRTIO_ENABLED(VIRTIO_DRIVER_SUPPORT) && role == RPMSG_HOST) {
if (VIRTIO_ENABLED(VIRTIO_DRIVER_SUPPORT) && role == VIRTIO_DEV_DRIVER) {
/*
* If device role is host then buffers are provided by us,
* so just provide the macro.
*/
size = rvdev->config.h2r_buf_size - sizeof(struct rpmsg_hdr);
}

if (VIRTIO_ENABLED(VIRTIO_DEVICE_SUPPORT) && role == RPMSG_REMOTE) {
if (VIRTIO_ENABLED(VIRTIO_DEVICE_SUPPORT) && role == VIRTIO_DEV_DEVICE) {
/*
* If other core is host then buffers are provided by it,
* so get the buffer size from the virtqueue.
Expand Down Expand Up @@ -752,15 +752,15 @@ int rpmsg_virtio_get_rx_buffer_size(struct rpmsg_device *rdev)
rvdev = (struct rpmsg_virtio_device *)rdev;
role = rpmsg_virtio_get_role(rvdev);

if (VIRTIO_ENABLED(VIRTIO_DRIVER_SUPPORT) && role == RPMSG_HOST) {
if (VIRTIO_ENABLED(VIRTIO_DRIVER_SUPPORT) && role == VIRTIO_DEV_DRIVER) {
/*
* If device role is host then buffers are provided by us,
* so just provide the macro.
*/
size = rvdev->config.r2h_buf_size - sizeof(struct rpmsg_hdr);
}

if (VIRTIO_ENABLED(VIRTIO_DEVICE_SUPPORT) && role == RPMSG_REMOTE) {
if (VIRTIO_ENABLED(VIRTIO_DEVICE_SUPPORT) && role == VIRTIO_DEV_DEVICE) {
/*
* If other core is host then buffers are provided by it,
* so get the buffer size from the virtqueue.
Expand Down Expand Up @@ -821,7 +821,7 @@ int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev,
rdev->ops.get_tx_buffer_size = rpmsg_virtio_get_tx_buffer_size;
role = rpmsg_virtio_get_role(rvdev);

if (VIRTIO_ENABLED(VIRTIO_DRIVER_SUPPORT) && role == RPMSG_HOST) {
if (VIRTIO_ENABLED(VIRTIO_DRIVER_SUPPORT) && role == VIRTIO_DEV_DRIVER) {
/*
* The virtio configuration contains only options applicable to
* a virtio driver, implying rpmsg host role.
Expand All @@ -832,7 +832,7 @@ int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev,
rvdev->config = *config;
}

if (VIRTIO_ENABLED(VIRTIO_DEVICE_SUPPORT) && role == RPMSG_REMOTE) {
if (VIRTIO_ENABLED(VIRTIO_DEVICE_SUPPORT) && role == VIRTIO_DEV_DEVICE) {
/* wait synchro with the host */
status = rpmsg_virtio_wait_remote_ready(rvdev);
if (status)
Expand All @@ -844,7 +844,7 @@ int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev,
return status;
rdev->support_ns = !!(features & (1 << VIRTIO_RPMSG_F_NS));

if (VIRTIO_ENABLED(VIRTIO_DRIVER_SUPPORT) && role == RPMSG_HOST) {
if (VIRTIO_ENABLED(VIRTIO_DRIVER_SUPPORT) && role == VIRTIO_DEV_DRIVER) {
/*
* Since device is RPMSG Remote so we need to manage the
* shared buffers. Create shared memory pool to handle buffers.
Expand All @@ -861,7 +861,7 @@ int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev,
callback[1] = rpmsg_virtio_tx_callback;
}

if (VIRTIO_ENABLED(VIRTIO_DEVICE_SUPPORT) && role == RPMSG_REMOTE) {
if (VIRTIO_ENABLED(VIRTIO_DEVICE_SUPPORT) && role == VIRTIO_DEV_DEVICE) {
vq_names[0] = "tx_vq";
vq_names[1] = "rx_vq";
callback[0] = rpmsg_virtio_tx_callback;
Expand All @@ -878,12 +878,12 @@ int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev,
return status;

/* Create virtqueue success, assign back the virtqueue */
if (VIRTIO_ENABLED(VIRTIO_DRIVER_SUPPORT) && role == RPMSG_HOST) {
if (VIRTIO_ENABLED(VIRTIO_DRIVER_SUPPORT) && role == VIRTIO_DEV_DRIVER) {
rvdev->rvq = vdev->vrings_info[0].vq;
rvdev->svq = vdev->vrings_info[1].vq;
}

if (VIRTIO_ENABLED(VIRTIO_DEVICE_SUPPORT) && role == RPMSG_REMOTE) {
if (VIRTIO_ENABLED(VIRTIO_DEVICE_SUPPORT) && role == VIRTIO_DEV_DEVICE) {
rvdev->rvq = vdev->vrings_info[1].vq;
rvdev->svq = vdev->vrings_info[0].vq;
}
Expand All @@ -902,7 +902,7 @@ int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev,
vq->shm_io = shm_io;
}

if (VIRTIO_ENABLED(VIRTIO_DRIVER_SUPPORT) && role == RPMSG_HOST) {
if (VIRTIO_ENABLED(VIRTIO_DRIVER_SUPPORT) && role == VIRTIO_DEV_DRIVER) {
struct virtqueue_buf vqbuf;
unsigned int idx;
void *buffer;
Expand Down Expand Up @@ -947,7 +947,7 @@ int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev,
rpmsg_virtio_ns_callback, NULL, rvdev);
}

if (VIRTIO_ENABLED(VIRTIO_DRIVER_SUPPORT) && role == RPMSG_HOST) {
if (VIRTIO_ENABLED(VIRTIO_DRIVER_SUPPORT) && role == VIRTIO_DEV_DRIVER) {
status = virtio_set_status(rvdev->vdev, VIRTIO_CONFIG_STATUS_DRIVER_OK);
if (status)
goto err;
Expand Down

0 comments on commit 6f9020a

Please sign in to comment.