[SLOF] [PATCH v6 15/23] virtio: add virtio 1.0 related struct and defines
Nikunj A Dadhania
nikunj at linux.vnet.ibm.com
Mon Feb 1 16:48:05 AEDT 2016
Traditionally, struct virtio_device is shared between SLOF and C code.
This still remains shared with the addition of virtio_cap structure as
well. Now both virtio_device and virtio_cap structures are shared.
Signed-off-by: Nikunj A Dadhania <nikunj at linux.vnet.ibm.com>
Reviewed-by: Thomas Huth <thuth at redhat.com>
---
board-qemu/slof/virtio.fs | 8 ++++++++
include/byteorder.h | 4 ++++
lib/libvirtio/virtio.c | 19 +++++++++++++++++++
lib/libvirtio/virtio.h | 28 +++++++++++++++++++++++++++-
4 files changed, 58 insertions(+), 1 deletion(-)
diff --git a/board-qemu/slof/virtio.fs b/board-qemu/slof/virtio.fs
index 1bf2e76..28700f9 100644
--- a/board-qemu/slof/virtio.fs
+++ b/board-qemu/slof/virtio.fs
@@ -13,6 +13,14 @@
\ This struct must match "struct virtio_device" in virtio.h!
STRUCT
/n FIELD vd>base
+ /l FIELD vd>is-modern
+ 10 FIELD vd>legacy
+ 10 FIELD vd>common
+ 10 FIELD vd>notify
+ 10 FIELD vd>isr
+ 10 FIELD vd>device
+ 10 FIELD vd>pci
+ /l FIELD vd>notify_off_mul
CONSTANT /vd-len
diff --git a/include/byteorder.h b/include/byteorder.h
index 8ae680f..d4a2c8c 100644
--- a/include/byteorder.h
+++ b/include/byteorder.h
@@ -19,6 +19,10 @@
#include <stdint.h>
+typedef uint16_t le16;
+typedef uint32_t le32;
+typedef uint64_t le64;
+
static inline uint16_t bswap_16 (uint16_t x)
{
return __builtin_bswap16(x);
diff --git a/lib/libvirtio/virtio.c b/lib/libvirtio/virtio.c
index edb6258..f30b69b 100644
--- a/lib/libvirtio/virtio.c
+++ b/lib/libvirtio/virtio.c
@@ -31,6 +31,25 @@
#define VIRTIOHDR_ISR_STATUS 19
#define VIRTIOHDR_DEVICE_CONFIG 20
+struct virtio_dev_common {
+ le32 dev_features_sel;
+ le32 dev_features;
+ le32 drv_features_sel;
+ le32 drv_features;
+ le16 msix_config;
+ le16 num_queues;
+ uint8_t dev_status;
+ uint8_t cfg_generation;
+
+ le16 q_select;
+ le16 q_size;
+ le16 q_msix_vec;
+ le16 q_enable;
+ le16 q_notify_off;
+ le64 q_desc;
+ le64 q_avail;
+ le64 q_used;
+} __attribute__ ((packed));
/**
* Calculate ring size according to queue size number
diff --git a/lib/libvirtio/virtio.h b/lib/libvirtio/virtio.h
index 75de5ec..ebfc726 100644
--- a/lib/libvirtio/virtio.h
+++ b/lib/libvirtio/virtio.h
@@ -20,8 +20,17 @@
#define VIRTIO_STAT_ACKNOWLEDGE 1
#define VIRTIO_STAT_DRIVER 2
#define VIRTIO_STAT_DRIVER_OK 4
+#define VIRTIO_STAT_FEATURES_OK 8
+#define VIRTIO_STAT_NEEDS_RESET 64
#define VIRTIO_STAT_FAILED 128
+#define BIT(x) (1UL << (x))
+
+/* VIRTIO 1.0 Device independent feature bits */
+#define VIRTIO_F_RING_INDIRECT_DESC BIT(28)
+#define VIRTIO_F_RING_EVENT_IDX BIT(29)
+#define VIRTIO_F_VERSION_1 BIT(32)
+
#define VIRTIO_TIMEOUT 5000 /* 5 sec timeout */
/* Definitions for vring_desc.flags */
@@ -61,9 +70,26 @@ struct vring_used {
struct vring_used_elem ring[];
};
+/* Structure shared with SLOF and is 16bytes */
+struct virtio_cap {
+ void *addr;
+ uint8_t bar;
+ uint8_t is_io;
+ uint8_t cap_id;
+ uint8_t pad[5];
+} __attribute__ ((packed));
+
struct virtio_device {
void *base; /* base address */
-};
+ uint32_t is_modern; /* Indicates whether to use virtio 1.0 */
+ struct virtio_cap legacy;
+ struct virtio_cap common;
+ struct virtio_cap notify;
+ struct virtio_cap isr;
+ struct virtio_cap device;
+ struct virtio_cap pci;
+ uint32_t notify_off_mul;
+} __attribute__ ((packed));
struct vqs {
uint64_t id; /* Queue ID */
--
2.5.0
More information about the SLOF
mailing list