diff options
Diffstat (limited to 'tests/libqos/virtio.h')
-rw-r--r-- | tests/libqos/virtio.h | 78 |
1 files changed, 12 insertions, 66 deletions
diff --git a/tests/libqos/virtio.h b/tests/libqos/virtio.h index 01012787b8..0250842bf2 100644 --- a/tests/libqos/virtio.h +++ b/tests/libqos/virtio.h @@ -11,78 +11,19 @@ #define LIBQOS_VIRTIO_H #include "libqos/malloc.h" +#include "standard-headers/linux/virtio_ring.h" -#define QVIRTIO_VENDOR_ID 0x1AF4 - -#define QVIRTIO_RESET 0x0 -#define QVIRTIO_ACKNOWLEDGE 0x1 -#define QVIRTIO_DRIVER 0x2 -#define QVIRTIO_DRIVER_OK 0x4 - -#define QVIRTIO_NET_DEVICE_ID 0x1 -#define QVIRTIO_BLK_DEVICE_ID 0x2 -#define QVIRTIO_CONSOLE_DEVICE_ID 0x3 -#define QVIRTIO_RNG_DEVICE_ID 0x4 -#define QVIRTIO_BALLOON_DEVICE_ID 0x5 -#define QVIRTIO_RPMSG_DEVICE_ID 0x7 -#define QVIRTIO_SCSI_DEVICE_ID 0x8 -#define QVIRTIO_9P_DEVICE_ID 0x9 - -#define QVIRTIO_F_NOTIFY_ON_EMPTY 0x01000000 -#define QVIRTIO_F_ANY_LAYOUT 0x08000000 -#define QVIRTIO_F_RING_INDIRECT_DESC 0x10000000 -#define QVIRTIO_F_RING_EVENT_IDX 0x20000000 #define QVIRTIO_F_BAD_FEATURE 0x40000000 -#define QVRING_DESC_F_NEXT 0x1 -#define QVRING_DESC_F_WRITE 0x2 -#define QVRING_DESC_F_INDIRECT 0x4 - -#define QVIRTIO_F_NOTIFY_ON_EMPTY 0x01000000 -#define QVIRTIO_F_ANY_LAYOUT 0x08000000 -#define QVIRTIO_F_RING_INDIRECT_DESC 0x10000000 -#define QVIRTIO_F_RING_EVENT_IDX 0x20000000 -#define QVIRTIO_F_BAD_FEATURE 0x40000000 - -#define QVRING_AVAIL_F_NO_INTERRUPT 1 - -#define QVRING_USED_F_NO_NOTIFY 1 - typedef struct QVirtioDevice { /* Device type */ uint16_t device_type; } QVirtioDevice; -typedef struct QVRingDesc { - uint64_t addr; - uint32_t len; - uint16_t flags; - uint16_t next; -} QVRingDesc; - -typedef struct QVRingAvail { - uint16_t flags; - uint16_t idx; - uint16_t ring[0]; /* This is an array of uint16_t */ - uint16_t used_event; -} QVRingAvail; - -typedef struct QVRingUsedElem { - uint32_t id; - uint32_t len; -} QVRingUsedElem; - -typedef struct QVRingUsed { - uint16_t flags; - uint16_t idx; - QVRingUsedElem ring[0]; /* This is an array of QVRingUsedElem structs */ - uint16_t avail_event; -} QVRingUsed; - typedef struct QVirtQueue { - uint64_t desc; /* This points to an array of QVRingDesc */ - uint64_t avail; /* This points to a QVRingAvail */ - uint64_t used; /* This points to a QVRingDesc */ + uint64_t desc; /* This points to an array of struct vring_desc */ + uint64_t avail; /* This points to a struct vring_avail */ + uint64_t used; /* This points to a struct vring_desc */ uint16_t index; uint32_t size; uint32_t free_head; @@ -93,7 +34,7 @@ typedef struct QVirtQueue { } QVirtQueue; typedef struct QVRingIndirectDesc { - uint64_t desc; /* This points to an array fo QVRingDesc */ + uint64_t desc; /* This points to an array fo struct vring_desc */ uint16_t index; uint16_t elem; } QVRingIndirectDesc; @@ -138,15 +79,18 @@ typedef struct QVirtioBus { QVirtQueue *(*virtqueue_setup)(QVirtioDevice *d, QGuestAllocator *alloc, uint16_t index); + /* Free virtqueue resources */ + void (*virtqueue_cleanup)(QVirtQueue *vq, QGuestAllocator *alloc); + /* Notify changes in virtqueue */ void (*virtqueue_kick)(QVirtioDevice *d, QVirtQueue *vq); } QVirtioBus; static inline uint32_t qvring_size(uint32_t num, uint32_t align) { - return ((sizeof(struct QVRingDesc) * num + sizeof(uint16_t) * (3 + num) + return ((sizeof(struct vring_desc) * num + sizeof(uint16_t) * (3 + num) + align - 1) & ~(align - 1)) - + sizeof(uint16_t) * 3 + sizeof(struct QVRingUsedElem) * num; + + sizeof(uint16_t) * 3 + sizeof(struct vring_used_elem) * num; } uint8_t qvirtio_config_readb(const QVirtioBus *bus, QVirtioDevice *d, @@ -177,6 +121,8 @@ void qvirtio_wait_config_isr(const QVirtioBus *bus, QVirtioDevice *d, gint64 timeout_us); QVirtQueue *qvirtqueue_setup(const QVirtioBus *bus, QVirtioDevice *d, QGuestAllocator *alloc, uint16_t index); +void qvirtqueue_cleanup(const QVirtioBus *bus, QVirtQueue *vq, + QGuestAllocator *alloc); void qvring_init(const QGuestAllocator *alloc, QVirtQueue *vq, uint64_t addr); QVRingIndirectDesc *qvring_indirect_desc_setup(QVirtioDevice *d, |