[SLOF] [PATCH v2 11/19] virtio: add virtio 1.0 related struct and defines

Alexey Kardashevskiy aik at ozlabs.ru
Fri Jan 22 15:30:10 AEDT 2016


On 01/20/2016 11:10 PM, Nikunj A Dadhania wrote:
> 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>
> ---
>   board-qemu/slof/virtio.fs | 17 +++++++++++++++++
>   include/byteorder.h       |  4 ++++
>   lib/libvirtio/virtio.c    | 19 +++++++++++++++++++
>   lib/libvirtio/virtio.h    | 29 ++++++++++++++++++++++++++++-
>   4 files changed, 68 insertions(+), 1 deletion(-)
>
> diff --git a/board-qemu/slof/virtio.fs b/board-qemu/slof/virtio.fs
> index 818c132..64381b1 100644
> --- a/board-qemu/slof/virtio.fs
> +++ b/board-qemu/slof/virtio.fs
> @@ -10,10 +10,27 @@
>   \ *     IBM Corporation - initial implementation
>   \ ****************************************************************************/
>
> +\ This struct must match "struct virtio_cap" in virtio.h !
> +STRUCT
> +   /n FIELD vd>cap>address
> +   /c FIELD vd>cap>bar
> +   /c FIELD vd>cap>is_io
> +   /c FIELD vd>cap>cap_id
> +   5  FIELD vd>cap>pad
> +CONSTANT /vd-cap-len
> +
>   \ This struct must match "struct virtio_device" in virtio.h!
>   STRUCT
>      /n FIELD vd>base
>      /l FIELD vd>type
> +   /l FIELD vd>is-modern
> +   /vd-cap-len FIELD vd>legacy
> +   /vd-cap-len FIELD vd>common
> +   /vd-cap-len FIELD vd>notify
> +   /vd-cap-len FIELD vd>isr
> +   /vd-cap-len FIELD vd>device
> +   /vd-cap-len 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 3a75e44..3f6859b 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 c26282f..4bb9619 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 */
> @@ -62,10 +71,28 @@ struct vring_used {
>   };
>
>   #define VIRTIO_TYPE_PCI 0	/* For virtio-pci interface */
> +
> +/* 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 */
>   	int type;		/* VIRTIO_TYPE_PCI or VIRTIO_TYPE_VIO */
> -};
> +	int is_modern;     /* Indicates whether to use virtio 1.0 */

Make it uint8_t (plug padding or uint32_t) as the rest of the struct uses 
strict binary types (except type which this will go in the next respin if I 
am not mistaken, right?).


> +	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 */
>


-- 
Alexey


More information about the SLOF mailing list