Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove layer breaking functions from rpmsg_virtio #561

Merged
merged 5 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions lib/include/openamp/rpmsg_virtio.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,12 @@ rpmsg_virtio_get_role(struct rpmsg_virtio_device *rvdev)
/**
* @brief Set rpmsg virtio device status.
*
* Deprecated: Use virtio_set_status() instead
*
* @param rvdev Pointer to rpmsg virtio device.
* @param status Value to be set as rpmsg virtio device status.
*/
__deprecated
static inline void rpmsg_virtio_set_status(struct rpmsg_virtio_device *rvdev,
uint8_t status)
{
Expand All @@ -155,10 +158,13 @@ static inline void rpmsg_virtio_set_status(struct rpmsg_virtio_device *rvdev,
/**
* @brief Retrieve rpmsg virtio device status.
*
* Deprecated: Use virtio_get_status() instead
*
* @param rvdev Pointer to rpmsg virtio device.
*
* @return The rpmsg virtio device status.
*/
__deprecated
static inline uint8_t rpmsg_virtio_get_status(struct rpmsg_virtio_device *rvdev)
{
return rvdev->vdev->func->get_status(rvdev->vdev);
Expand All @@ -167,10 +173,13 @@ static inline uint8_t rpmsg_virtio_get_status(struct rpmsg_virtio_device *rvdev)
/**
* @brief Get the rpmsg virtio device features.
*
* Deprecated: Use virtio_get_features() instead
*
* @param rvdev Pointer to the rpmsg virtio device.
*
* @return The features supported by both the rpmsg driver and rpmsg device.
*/
__deprecated
static inline uint32_t
rpmsg_virtio_get_features(struct rpmsg_virtio_device *rvdev)
{
Expand All @@ -180,11 +189,14 @@ rpmsg_virtio_get_features(struct rpmsg_virtio_device *rvdev)
/**
* @brief Retrieve configuration data from the rpmsg virtio device.
*
* Deprecated: Use virtio_read_config() instead
*
* @param rvdev Pointer to the rpmsg virtio device.
* @param offset Offset of the data within the configuration area.
* @param dst Address of the buffer that will hold the data.
* @param length Length of the data to be retrieved.
*/
__deprecated
static inline void
rpmsg_virtio_read_config(struct rpmsg_virtio_device *rvdev,
uint32_t offset, void *dst, int length)
Expand All @@ -195,13 +207,16 @@ rpmsg_virtio_read_config(struct rpmsg_virtio_device *rvdev,
/**
* @brief Write configuration data to the rpmsg virtio device.
*
* Deprecated: Use virtio_write_config() instead
*
* @param rvdev Pointer to the rpmsg virtio device.
* @param offset Offset of the data within the configuration area.
* @param src Address of the buffer that holds the data to write.
* @param length Length of the data to be written.
*
* @return 0 on success, otherwise error code.
*/
__deprecated
static inline void
rpmsg_virtio_write_config(struct rpmsg_virtio_device *rvdev,
uint32_t offset, void *src, int length)
Expand All @@ -212,6 +227,8 @@ rpmsg_virtio_write_config(struct rpmsg_virtio_device *rvdev,
/**
* @brief Create the rpmsg virtio device virtqueue.
*
* Deprecated: Use virtio_create_virtqueues() instead
*
* @param rvdev Pointer to the rpmsg virtio device.
* @param flags Create flag.
* @param nvqs The virtqueue number.
Expand All @@ -220,6 +237,7 @@ rpmsg_virtio_write_config(struct rpmsg_virtio_device *rvdev,
*
* @return 0 on success, otherwise error code.
*/
__deprecated
static inline int
rpmsg_virtio_create_virtqueues(struct rpmsg_virtio_device *rvdev,
int flags, unsigned int nvqs,
Expand All @@ -233,8 +251,11 @@ rpmsg_virtio_create_virtqueues(struct rpmsg_virtio_device *rvdev,
/**
* @brief Delete the virtqueues created in rpmsg_virtio_create_virtqueues()
*
* Deprecated: Use virtio_delete_virtqueues() instead
*
* @param rvdev Pointer to the rpmsg virtio device
*/
__deprecated
static inline void
rpmsg_virtio_delete_virtqueues(struct rpmsg_virtio_device *rvdev)
{
Expand Down
52 changes: 36 additions & 16 deletions lib/rpmsg/rpmsg_virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,21 +269,32 @@ static void *rpmsg_virtio_get_rx_buffer(struct rpmsg_virtio_device *rvdev,
}

#ifndef VIRTIO_DRIVER_ONLY
/*
* check if the remote is ready to start RPMsg communication
/**
* @internal
*
* @brief Check if the remote is ready to start RPMsg communication
*
* @param rvdev Pointer to rpmsg_virtio device
*
* @return 0 on success, otherwise error code.
*/
static int rpmsg_virtio_wait_remote_ready(struct rpmsg_virtio_device *rvdev)
{
uint8_t status;
int ret;

while (1) {
status = rpmsg_virtio_get_status(rvdev);
ret = virtio_get_status(rvdev->vdev, &status);
if (ret)
return ret;
/* Busy wait until the remote is ready */
if (status & VIRTIO_CONFIG_STATUS_NEEDS_RESET) {
rpmsg_virtio_set_status(rvdev, 0);
ret = virtio_set_status(rvdev->vdev, 0);
if (ret)
return ret;
/* TODO notify remote processor */
} else if (status & VIRTIO_CONFIG_STATUS_DRIVER_OK) {
return true;
return 0;
}
/* TODO: clarify metal_cpu_yield usage*/
metal_cpu_yield();
Expand Down Expand Up @@ -375,6 +386,7 @@ static void *rpmsg_virtio_get_tx_payload_buffer(struct rpmsg_device *rdev,
{
struct rpmsg_virtio_device *rvdev;
struct rpmsg_hdr *rp_hdr;
uint8_t virtio_status;
glneo marked this conversation as resolved.
Show resolved Hide resolved
uint16_t idx;
int tick_count;
int status;
Expand All @@ -383,8 +395,8 @@ static void *rpmsg_virtio_get_tx_payload_buffer(struct rpmsg_device *rdev,
rvdev = metal_container_of(rdev, struct rpmsg_virtio_device, rdev);

/* Validate device state */
status = rpmsg_virtio_get_status(rvdev);
if (!(status & VIRTIO_CONFIG_STATUS_DRIVER_OK))
status = virtio_get_status(rvdev->vdev, &virtio_status);
if (status || !(virtio_status & VIRTIO_CONFIG_STATUS_DRIVER_OK))
return NULL;

if (wait)
Expand Down Expand Up @@ -814,6 +826,7 @@ int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev,
struct rpmsg_device *rdev;
const char *vq_names[RPMSG_NUM_VRINGS];
vq_callback callback[RPMSG_NUM_VRINGS];
uint32_t features;
int status;
unsigned int i, role;

Expand Down Expand Up @@ -854,11 +867,15 @@ int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev,
#ifndef VIRTIO_DRIVER_ONLY
if (role == RPMSG_REMOTE) {
/* wait synchro with the host */
rpmsg_virtio_wait_remote_ready(rvdev);
status = rpmsg_virtio_wait_remote_ready(rvdev);
if (status)
return status;
}
#endif /*!VIRTIO_DRIVER_ONLY*/
vdev->features = rpmsg_virtio_get_features(rvdev);
rdev->support_ns = !!(vdev->features & (1 << VIRTIO_RPMSG_F_NS));
status = virtio_get_features(rvdev->vdev, &features);
if (status)
return status;
rdev->support_ns = !!(features & (1 << VIRTIO_RPMSG_F_NS));

#ifndef VIRTIO_DEVICE_ONLY
if (role == RPMSG_HOST) {
Expand Down Expand Up @@ -892,8 +909,8 @@ int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev,
metal_list_init(&rvdev->reclaimer);

/* Create virtqueues for remote device */
status = rpmsg_virtio_create_virtqueues(rvdev, 0, RPMSG_NUM_VRINGS,
vq_names, callback);
status = virtio_create_virtqueues(rvdev->vdev, 0, RPMSG_NUM_VRINGS,
vq_names, callback, NULL);
if (status != RPMSG_SUCCESS)
return status;

Expand Down Expand Up @@ -974,15 +991,18 @@ int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev,
}

#ifndef VIRTIO_DEVICE_ONLY
if (role == RPMSG_HOST)
rpmsg_virtio_set_status(rvdev, VIRTIO_CONFIG_STATUS_DRIVER_OK);
if (role == RPMSG_HOST) {
status = virtio_set_status(rvdev->vdev, VIRTIO_CONFIG_STATUS_DRIVER_OK);
if (status)
goto err;
}
#endif /*!VIRTIO_DEVICE_ONLY*/

return RPMSG_SUCCESS;

#ifndef VIRTIO_DEVICE_ONLY
err:
rpmsg_virtio_delete_virtqueues(rvdev);
virtio_delete_virtqueues(rvdev->vdev);
return status;
#endif /*!VIRTIO_DEVICE_ONLY*/
}
Expand All @@ -1004,7 +1024,7 @@ void rpmsg_deinit_vdev(struct rpmsg_virtio_device *rvdev)
rvdev->rvq = 0;
rvdev->svq = 0;

rpmsg_virtio_delete_virtqueues(rvdev);
virtio_delete_virtqueues(rvdev->vdev);
metal_mutex_deinit(&rdev->lock);
}
}
Loading