diff --git a/lib/include/openamp/rpmsg_virtio.h b/lib/include/openamp/rpmsg_virtio.h index 752be7762..678675c84 100644 --- a/lib/include/openamp/rpmsg_virtio.h +++ b/lib/include/openamp/rpmsg_virtio.h @@ -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) { @@ -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); @@ -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) { @@ -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) @@ -195,6 +207,8 @@ 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. @@ -202,6 +216,7 @@ rpmsg_virtio_read_config(struct rpmsg_virtio_device *rvdev, * * @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) @@ -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. @@ -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, @@ -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) { diff --git a/lib/rpmsg/rpmsg_virtio.c b/lib/rpmsg/rpmsg_virtio.c index 1a9d0bfaa..6ddfb1af2 100644 --- a/lib/rpmsg/rpmsg_virtio.c +++ b/lib/rpmsg/rpmsg_virtio.c @@ -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(); @@ -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; uint16_t idx; int tick_count; int status; @@ -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) @@ -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; @@ -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) { @@ -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; @@ -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*/ } @@ -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); } }