Skip to content

Commit

Permalink
virtio: virtio-mmio framework
Browse files Browse the repository at this point in the history
VIRTIO MMIO transport for OpenAMP.

Signed-off-by: Dan Milea <dan.milea@windriver.com>
  • Loading branch information
Dan Milea committed Jul 19, 2023
1 parent 5891cb4 commit 866060a
Show file tree
Hide file tree
Showing 9 changed files with 770 additions and 10 deletions.
6 changes: 6 additions & 0 deletions cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ if (NOT WITH_VIRTIO_DEVICE AND NOT WITH_VIRTIO_SLAVE)
add_definitions(-DVIRTIO_DRIVER_ONLY)
endif (NOT WITH_VIRTIO_DEVICE AND NOT WITH_VIRTIO_SLAVE)

option (WITH_VIRTIO_MMIO_DRV "Build with virtio mmio driver support enabled" OFF)

if (WITH_VIRTIO_MMIO_DRV)
add_definitions(-DWITH_VIRTIO_MMIO_DRV)
endif (WITH_VIRTIO_MMIO_DRV)

option (WITH_DCACHE_VRINGS "Build with vrings cache operations enabled" OFF)

if (WITH_DCACHE_VRINGS)
Expand Down
3 changes: 3 additions & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ collect (PROJECT_LIB_SOURCES version.c)
add_subdirectory (virtio)
add_subdirectory (rpmsg)
add_subdirectory (remoteproc)
if (WITH_VIRTIO_MMIO_DRV)
add_subdirectory (virtio_mmio)
endif (WITH_VIRTIO_MMIO_DRV)

if (WITH_PROXY)
add_subdirectory (proxy)
Expand Down
2 changes: 1 addition & 1 deletion lib/include/openamp/rpmsg_virtio.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ rpmsg_virtio_create_virtqueues(struct rpmsg_virtio_device *rvdev,
vq_callback *callbacks)
{
return virtio_create_virtqueues(rvdev->vdev, flags, nvqs, names,
callbacks);
callbacks, NULL);
}

/**
Expand Down
70 changes: 63 additions & 7 deletions lib/include/openamp/virtio.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ __deprecated static inline int deprecated_virtio_dev_slave(void)
struct virtio_device_id {
uint32_t device;
uint32_t vendor;
uint32_t version;
};

/*
Expand All @@ -120,6 +121,44 @@ struct virtio_device_id {
#define VIRTIO_TRANSPORT_F_START 28
#define VIRTIO_TRANSPORT_F_END 32

#ifdef VIRTIO_DEBUG
#include <metal/log.h>

#define VIRTIO_ASSERT(_exp, _msg) do { \
if (!(_exp)) { \
metal_log(METAL_LOG_EMERGENCY, \
"FATAL: %s - " _msg, __func__); \
metal_assert(_exp); \
} \
} while (0)
#else
#define VIRTIO_ASSERT(_exp, _msg) metal_assert(_exp)
#endif /* VIRTIO_DEBUG */

#define VRING_ALIGNMENT 4096

#define VIRTIO_RING_SIZE(n, align) \
(( \
( \
sizeof(struct vring_desc) * n + \
sizeof(struct vring_avail) + \
sizeof(uint16_t) * (n + 1) + \
align - 1 \
) \
& ~(align - 1) \
) + \
sizeof(struct vring_used) + \
sizeof(struct vring_used_elem) * n + sizeof(uint16_t))

#define VRING_DECLARE(name, n, align) \
static char __vrbuf_##name[VIRTIO_RING_SIZE(n, align)] __aligned(VRING_ALIGNMENT); \
static struct vring __vring_##name = { \
.desc = (void *)__vrbuf_##name, \
.avail = (void *)((unsigned long)__vrbuf_##name + n * sizeof(struct vring_desc)), \
.used = (void *)((unsigned long)__vrbuf_##name + ((n * sizeof(struct vring_desc) + \
(n + 1) * sizeof(uint16_t) + align - 1) & ~(align - 1))), \
}

typedef void (*virtio_dev_reset_cb)(struct virtio_device *vdev);

struct virtio_dispatch;
Expand Down Expand Up @@ -180,7 +219,8 @@ struct virtio_dispatch {
int (*create_virtqueues)(struct virtio_device *vdev,
unsigned int flags,
unsigned int nvqs, const char *names[],
vq_callback callbacks[]);
vq_callback callbacks[],
void *callback_args[]);
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);
Expand All @@ -205,17 +245,18 @@ struct virtio_dispatch {
/**
* @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.
* @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.
* @param callback_args Virtqueue callback function arguments.
*
* @return 0 on success, otherwise error code.
*/
int virtio_create_virtqueues(struct virtio_device *vdev, unsigned int flags,
unsigned int nvqs, const char *names[],
vq_callback callbacks[]);
vq_callback callbacks[], void *callback_args[]);

/**
* @brief Delete the virtio device virtqueue.
Expand All @@ -236,6 +277,21 @@ static inline int virtio_delete_virtqueues(struct virtio_device *vdev)
return 0;
}

/**
* @brief Get device ID.
*
* @param dev Pointer to device structure.
*
* @return Device ID value.
*/

static inline uint32_t virtio_get_devid(const struct virtio_device *vdev)
{
if (!vdev)
return 0;
return vdev->id.device;
}

/**
* @brief Retrieve device status.
*
Expand Down
Loading

0 comments on commit 866060a

Please sign in to comment.