From 56f63b7364c08b75eaf2b8e6b5f7e96dd104fdb3 Mon Sep 17 00:00:00 2001 From: Bryan Venteicher Date: Sun, 17 Jun 2018 20:45:48 +0000 Subject: [PATCH] Update VirtIO definitions from Linux virtio_config.h and virtio_ring.h headers --- sys/dev/virtio/virtio_config.h | 37 +++++++++++++++++++++++++++------- sys/dev/virtio/virtio_ring.h | 7 +++++++ 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/sys/dev/virtio/virtio_config.h b/sys/dev/virtio/virtio_config.h index 88cdb8b83a9a..c16516f86f5a 100644 --- a/sys/dev/virtio/virtio_config.h +++ b/sys/dev/virtio/virtio_config.h @@ -33,35 +33,58 @@ /* Status byte for guest to report progress. */ #define VIRTIO_CONFIG_STATUS_RESET 0x00 +/* We have seen device and processed generic fields. */ #define VIRTIO_CONFIG_STATUS_ACK 0x01 -#define VIRTIO_CONFIG_STATUS_DRIVER 0x03 +/* We have found a driver for the device. */ +#define VIRTIO_CONFIG_STATUS_DRIVER 0x02 +/* Driver has used its parts of the config, and is happy. */ #define VIRTIO_CONFIG_STATUS_DRIVER_OK 0x04 +/* Driver has finished configuring features (modern only). */ +#define VIRTIO_CONFIG_S_FEATURES_OK 0x08 +/* Device entered invalid state, driver must reset it. */ +#define VIRTIO_CONFIG_S_NEEDS_RESET 0x40 +/* We've given up on this device. */ #define VIRTIO_CONFIG_STATUS_FAILED 0x80 /* * Generate interrupt when the virtqueue ring is * completely used, even if we've suppressed them. */ -#define VIRTIO_F_NOTIFY_ON_EMPTY (1 << 24) +#define VIRTIO_F_NOTIFY_ON_EMPTY (1UL << 24) + +/* Can the device handle any descriptor layout? */ +#define VIRTIO_F_ANY_LAYOUT (1UL << 27) /* Support for indirect buffer descriptors. */ -#define VIRTIO_RING_F_INDIRECT_DESC (1 << 28) +#define VIRTIO_RING_F_INDIRECT_DESC (1UL << 28) /* Support to suppress interrupt until specific index is reached. */ -#define VIRTIO_RING_F_EVENT_IDX (1 << 29) +#define VIRTIO_RING_F_EVENT_IDX (1UL << 29) /* * The guest should never negotiate this feature; it * is used to detect faulty drivers. */ -#define VIRTIO_F_BAD_FEATURE (1 << 30) +#define VIRTIO_F_BAD_FEATURE (1UL << 30) + +/* v1.0 compliant. */ +#define VIRTIO_F_VERSION_1 (1ULL << 32) /* - * Some VirtIO feature bits (currently bits 28 through 31) are + * If clear - device has the IOMMU bypass quirk feature. + * If set - use platform tools to detect the IOMMU. + * + * Note the reverse polarity (compared to most other features), + * this is for compatibility with legacy systems. + */ +#define VIRTIO_F_IOMMU_PLATFORM (1ULL << 33) + +/* + * Some VirtIO feature bits (currently bits 28 through 34) are * reserved for the transport being used (eg. virtio_ring), the * rest are per-device feature bits. */ #define VIRTIO_TRANSPORT_F_START 28 -#define VIRTIO_TRANSPORT_F_END 32 +#define VIRTIO_TRANSPORT_F_END 34 #endif /* _VIRTIO_CONFIG_H_ */ diff --git a/sys/dev/virtio/virtio_ring.h b/sys/dev/virtio/virtio_ring.h index ee2609685d06..816c24d6d5ca 100644 --- a/sys/dev/virtio/virtio_ring.h +++ b/sys/dev/virtio/virtio_ring.h @@ -92,6 +92,13 @@ struct vring { struct vring_used *used; }; +/* Alignment requirements for vring elements. + * When using pre-virtio 1.0 layout, these fall out naturally. + */ +#define VRING_AVAIL_ALIGN_SIZE 2 +#define VRING_USED_ALIGN_SIZE 4 +#define VRING_DESC_ALIGN_SIZE 16 + /* The standard layout for the ring is a continuous chunk of memory which * looks like this. We assume num is a power of 2. *