Skip to content

Commit

Permalink
virtio: decoupling the transport layer and virtio device layer
Browse files Browse the repository at this point in the history
1. Add virtio device api to decouple the transport layer and virtio
   device layer.
2. Move the vrings info and virtqueue allocation/free  to the
   remoteproc transport layer;
3. Because 2, modify the rpmsg device also;

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
  • Loading branch information
CV-Bowen committed Jun 17, 2023
1 parent fe5ac7a commit 4161017
Show file tree
Hide file tree
Showing 5 changed files with 266 additions and 91 deletions.
10 changes: 8 additions & 2 deletions lib/include/openamp/rpmsg_virtio.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,14 @@ rpmsg_virtio_create_virtqueues(struct rpmsg_virtio_device *rvdev,
const char *names[],
vq_callback *callbacks)
{
return virtio_create_virtqueues(rvdev->vdev, flags, nvqs, names,
callbacks);
return rvdev->vdev->func->create_virtqueues(rvdev->vdev, flags, nvqs,
names, callbacks);
}

static inline void
rpmsg_virtio_delete_virtqueues(struct rpmsg_virtio_device *rvdev)
{
rvdev->vdev->func->delete_virtqueues(rvdev->vdev);
}

/**
Expand Down
97 changes: 97 additions & 0 deletions lib/include/openamp/virtio.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,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);
Expand All @@ -168,6 +173,98 @@ int virtio_create_virtqueues(struct virtio_device *vdev, unsigned int flags,
unsigned int nvqs, const char *names[],
vq_callback callbacks[]);

/**
* @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.
*/
#define virtio_dispatch_create_virtqueues(vdev, flags, nvqs, names, callbacks) \
vdev->func->create_virtqueues(vdev, flags, nvqs, names, callbacks)

/**
* @brief Delete the virtio device virtqueue.
*
* @param vdev Pointer to virtio device structure.
*
* @return pointer to virtio device structure.
*/
#define virtio_dispatch_delete_virtqueues(vdev) \
vdev->func->delete_virtqueues(vdev)

/**
* @brief Retrieve device status.
*
* @param dev Pointer to device structure.
*
* @return status of the device.
*/
#define virtio_dispatch_get_status(vdev) \
vdev->func->get_status(vdev)

/**
* @brief Set device status.
*
* @param dev Pointer to device structure.
* @param status Value to be set as device status.
*/
#define virtio_dispatch_set_status(vdev) \
vdev->func->set_status(vdev)

/**
* @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.
*/
#define virtio_dispatch_read_config(vdev, offset, dst, 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.
*/
#define virtio_dispatch_write_config(vdev, offset, src, 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.
*/
#define virtio_dispatch_get_features(vdev) \
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.
*/
#define virtio_dispatch_set_feature(vdev, features) \
vdev->func->set_features(vdev, features)

/**
* @brief Reset virtio device.
*
* @param vdev Pointer to virtio_device structure.
*/
#define virtio_dispatch_reset_device(vdev) \
vdev->func->reset_device(vdev)

#if defined __cplusplus
}
#endif
Expand Down
32 changes: 0 additions & 32 deletions lib/remoteproc/remoteproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,6 @@ remoteproc_create_virtio(struct remoteproc *rproc,
struct remoteproc_virtio *rpvdev;
size_t vdev_rsc_offset;
unsigned int notifyid;
unsigned int num_vrings, i;
struct metal_list *node;

#ifdef VIRTIO_DRIVER_ONLY
Expand Down Expand Up @@ -959,39 +958,8 @@ remoteproc_create_virtio(struct remoteproc *rproc,

rpvdev = metal_container_of(vdev, struct remoteproc_virtio, vdev);
metal_list_add_tail(&rproc->vdevs, &rpvdev->node);
num_vrings = vdev_rsc->num_of_vrings;

/* set the notification id for vrings */
for (i = 0; i < num_vrings; i++) {
struct fw_rsc_vdev_vring *vring_rsc;
metal_phys_addr_t da;
unsigned int num_descs, align;
struct metal_io_region *io;
void *va;
size_t size;
int ret;

vring_rsc = &vdev_rsc->vring[i];
notifyid = vring_rsc->notifyid;
da = vring_rsc->da;
num_descs = vring_rsc->num;
align = vring_rsc->align;
size = vring_size(num_descs, align);
va = remoteproc_mmap(rproc, NULL, &da, size, 0, &io);
if (!va)
goto err1;
ret = rproc_virtio_init_vring(vdev, i, notifyid,
va, io, num_descs, align);
if (ret)
goto err1;
}
metal_mutex_release(&rproc->lock);
return vdev;

err1:
remoteproc_remove_virtio(rproc, vdev);
metal_mutex_release(&rproc->lock);
return NULL;
}

void remoteproc_remove_virtio(struct remoteproc *rproc,
Expand Down

0 comments on commit 4161017

Please sign in to comment.