From 32d7784d3d754a0e8a71ccf913eab656ceb9b674 Mon Sep 17 00:00:00 2001 From: Bowen Wang Date: Mon, 3 Jul 2023 23:20:48 +0800 Subject: [PATCH] virtio: add create_virtqueues and delete_virtqueues in virtio_dispatch This is the first step to decoupling the virtio deivce and transport layer. Signed-off-by: Bowen Wang --- lib/include/openamp/virtio.h | 128 +++++++++++++++++++++++++++++++++++ lib/virtio/virtio.c | 5 ++ 2 files changed, 133 insertions(+) diff --git a/lib/include/openamp/virtio.h b/lib/include/openamp/virtio.h index 6ea031e5..3aba2cc0 100644 --- a/lib/include/openamp/virtio.h +++ b/lib/include/openamp/virtio.h @@ -176,6 +176,11 @@ void virtio_describe(struct virtio_device *dev, const char *msg, */ struct virtio_dispatch { + int (*create_virtqueues)(struct virtio_device *vdev, + unsigned int flags, + unsigned int nvqs, const char *names[], + vq_callback callbacks[]); + void (*delete_virtqueues)(struct virtio_device *vdev); uint8_t (*get_status)(struct virtio_device *dev); void (*set_status)(struct virtio_device *dev, uint8_t status); uint32_t (*get_features)(struct virtio_device *dev); @@ -196,10 +201,133 @@ struct virtio_dispatch { void (*notify)(struct virtqueue *vq); }; +/** + * @brief Create the virtio device virtqueue. + * + * @param vdev Pointer to virtio device structure. + * @param flags Create flag. + * @param nvqs The virtqueue number. + * @param names Virtqueue names. + * @param callbacks Virtqueue callback functions. + * + * @return Pointer to virtio device structure. + */ int virtio_create_virtqueues(struct virtio_device *vdev, unsigned int flags, unsigned int nvqs, const char *names[], vq_callback callbacks[]); +/** + * @brief Delete the virtio device virtqueue. + * + * @param vdev Pointer to virtio device structure. + * + * @return pointer to virtio device structure. + */ +static inline void virtio_delete_virtqueues(struct virtio_device *vdev) +{ + return vdev->func->delete_virtqueues(vdev); +} + +/** + * @brief Retrieve device status. + * + * @param dev Pointer to device structure. + * + * @return status of the device. + */ +static inline uint8_t virtio_get_status(struct virtio_device *vdev) +{ + return vdev->func->get_status(vdev); +} + +/** + * @brief Set device status. + * + * @param dev Pointer to device structure. + * @param status Value to be set as device status. + */ +static inline void virtio_set_status(struct virtio_device *vdev, + uint8_t status) +{ + vdev->func->set_status(vdev, status); +} + +/** + * @brief Retrieve configuration data from the device. + * + * @param dev Pointer to device structure. + * @param offset Offset of the data within the configuration area. + * @param dst Address of the buffer that will hold the data. + * @param len Length of the data to be retrieved. + */ +static inline void virtio_read_config(struct virtio_device *vdev, + uint32_t offset, void *dst, + int length) +{ + vdev->func->read_config(vdev, offset, dst, length); +} + +/** + * @brief Write configuration data to the device. + * + * @param dev Pointer to device structure. + * @param offset Offset of the data within the configuration area. + * @param src Address of the buffer that holds the data to write. + * @param len Length of the data to be written. + */ +static inline void virtio_write_config(struct virtio_device *vdev, + uint32_t offset, void *src, + int length) +{ + vdev->func->write_config(vdev, offset, src, length); +} + +/** + * @brief Get the virtio device features. + * + * @param[in] dev Pointer to device structure. + * + * @return Features supported by both the driver and the device as a bitfield. + */ +static inline uint32_t virtio_get_features(struct virtio_device *vdev) +{ + return vdev->func->get_features(vdev); +} + +/** + * @brief Set features supported by the VIRTIO driver. + * + * @param dev Pointer to device structure. + * @param features Features supported by the driver as a bitfield. + */ +static inline void virtio_set_features(struct virtio_device *vdev, + uint32_t features) +{ + return vdev->func->set_features(vdev, features); +} + +/** + * @brief Negotiate features between virtio device and driver. + * + * @param dev Pointer to device structure. + * @param features Supported features. + */ +static inline uint32_t virtio_negotiate_features(struct virtio_device *vdev, + uint32_t features) +{ + return vdev->func->negotiate_features(vdev, features); +} + +/** + * @brief Reset virtio device. + * + * @param vdev Pointer to virtio_device structure. + */ +static inline void virtio_reset_device(struct virtio_device *vdev) +{ + vdev->func->reset_device(vdev); +} + #if defined __cplusplus } #endif diff --git a/lib/virtio/virtio.c b/lib/virtio/virtio.c index 48f68061..da9260e4 100644 --- a/lib/virtio/virtio.c +++ b/lib/virtio/virtio.c @@ -104,6 +104,11 @@ int virtio_create_virtqueues(struct virtio_device *vdev, unsigned int flags, int ret; (void)flags; + if (vdev->func->create_virtqueues) { + return vdev->func->create_virtqueues(vdev, flags, nvqs, + names, callbacks); + } + num_vrings = vdev->vrings_num; if (nvqs > num_vrings) return ERROR_VQUEUE_INVLD_PARAM;