xref: /qemu/subprojects/libvduse/standard-headers/linux/virtio_pci.h (revision 44fe383c274174405da79f5fcb028e39fe688036)
19fbe302bSMichael S. Tsirkin /*
29fbe302bSMichael S. Tsirkin  * Virtio PCI driver
39fbe302bSMichael S. Tsirkin  *
49fbe302bSMichael S. Tsirkin  * This module allows virtio devices to be used over a virtual PCI device.
59fbe302bSMichael S. Tsirkin  * This can be used with QEMU based VMMs like KVM or Xen.
69fbe302bSMichael S. Tsirkin  *
79fbe302bSMichael S. Tsirkin  * Copyright IBM Corp. 2007
89fbe302bSMichael S. Tsirkin  *
99fbe302bSMichael S. Tsirkin  * Authors:
109fbe302bSMichael S. Tsirkin  *  Anthony Liguori  <aliguori@us.ibm.com>
119fbe302bSMichael S. Tsirkin  *
129fbe302bSMichael S. Tsirkin  * This header is BSD licensed so anyone can use the definitions to implement
139fbe302bSMichael S. Tsirkin  * compatible drivers/servers.
149fbe302bSMichael S. Tsirkin  *
159fbe302bSMichael S. Tsirkin  * Redistribution and use in source and binary forms, with or without
169fbe302bSMichael S. Tsirkin  * modification, are permitted provided that the following conditions
179fbe302bSMichael S. Tsirkin  * are met:
189fbe302bSMichael S. Tsirkin  * 1. Redistributions of source code must retain the above copyright
199fbe302bSMichael S. Tsirkin  *    notice, this list of conditions and the following disclaimer.
209fbe302bSMichael S. Tsirkin  * 2. Redistributions in binary form must reproduce the above copyright
219fbe302bSMichael S. Tsirkin  *    notice, this list of conditions and the following disclaimer in the
229fbe302bSMichael S. Tsirkin  *    documentation and/or other materials provided with the distribution.
239fbe302bSMichael S. Tsirkin  * 3. Neither the name of IBM nor the names of its contributors
249fbe302bSMichael S. Tsirkin  *    may be used to endorse or promote products derived from this software
259fbe302bSMichael S. Tsirkin  *    without specific prior written permission.
269fbe302bSMichael S. Tsirkin  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
279fbe302bSMichael S. Tsirkin  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
289fbe302bSMichael S. Tsirkin  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
299fbe302bSMichael S. Tsirkin  * ARE DISCLAIMED.  IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
309fbe302bSMichael S. Tsirkin  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
319fbe302bSMichael S. Tsirkin  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
329fbe302bSMichael S. Tsirkin  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
339fbe302bSMichael S. Tsirkin  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
349fbe302bSMichael S. Tsirkin  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
359fbe302bSMichael S. Tsirkin  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
369fbe302bSMichael S. Tsirkin  * SUCH DAMAGE.
379fbe302bSMichael S. Tsirkin  */
389fbe302bSMichael S. Tsirkin 
399fbe302bSMichael S. Tsirkin #ifndef _LINUX_VIRTIO_PCI_H
409fbe302bSMichael S. Tsirkin #define _LINUX_VIRTIO_PCI_H
419fbe302bSMichael S. Tsirkin 
429fbe302bSMichael S. Tsirkin #include "standard-headers/linux/types.h"
43*44fe383cSHendrik Brueckner #include "standard-headers/linux/kernel.h"
449fbe302bSMichael S. Tsirkin 
459fbe302bSMichael S. Tsirkin #ifndef VIRTIO_PCI_NO_LEGACY
469fbe302bSMichael S. Tsirkin 
479fbe302bSMichael S. Tsirkin /* A 32-bit r/o bitmask of the features supported by the host */
489fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_HOST_FEATURES	0
499fbe302bSMichael S. Tsirkin 
509fbe302bSMichael S. Tsirkin /* A 32-bit r/w bitmask of features activated by the guest */
519fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_GUEST_FEATURES	4
529fbe302bSMichael S. Tsirkin 
539fbe302bSMichael S. Tsirkin /* A 32-bit r/w PFN for the currently selected queue */
549fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_QUEUE_PFN		8
559fbe302bSMichael S. Tsirkin 
569fbe302bSMichael S. Tsirkin /* A 16-bit r/o queue size for the currently selected queue */
579fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_QUEUE_NUM		12
589fbe302bSMichael S. Tsirkin 
599fbe302bSMichael S. Tsirkin /* A 16-bit r/w queue selector */
609fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_QUEUE_SEL		14
619fbe302bSMichael S. Tsirkin 
629fbe302bSMichael S. Tsirkin /* A 16-bit r/w queue notifier */
639fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_QUEUE_NOTIFY		16
649fbe302bSMichael S. Tsirkin 
659fbe302bSMichael S. Tsirkin /* An 8-bit device status register.  */
669fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_STATUS		18
679fbe302bSMichael S. Tsirkin 
689fbe302bSMichael S. Tsirkin /* An 8-bit r/o interrupt status register.  Reading the value will return the
699fbe302bSMichael S. Tsirkin  * current contents of the ISR and will also clear it.  This is effectively
709fbe302bSMichael S. Tsirkin  * a read-and-acknowledge. */
719fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_ISR			19
729fbe302bSMichael S. Tsirkin 
739fbe302bSMichael S. Tsirkin /* MSI-X registers: only enabled if MSI-X is enabled. */
749fbe302bSMichael S. Tsirkin /* A 16-bit vector for configuration changes. */
759fbe302bSMichael S. Tsirkin #define VIRTIO_MSI_CONFIG_VECTOR        20
769fbe302bSMichael S. Tsirkin /* A 16-bit vector for selected queue notifications. */
779fbe302bSMichael S. Tsirkin #define VIRTIO_MSI_QUEUE_VECTOR         22
789fbe302bSMichael S. Tsirkin 
799fbe302bSMichael S. Tsirkin /* The remaining space is defined by each driver as the per-driver
809fbe302bSMichael S. Tsirkin  * configuration space */
819fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_CONFIG_OFF(msix_enabled)	((msix_enabled) ? 24 : 20)
829fbe302bSMichael S. Tsirkin /* Deprecated: please use VIRTIO_PCI_CONFIG_OFF instead */
839fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_CONFIG(dev)	VIRTIO_PCI_CONFIG_OFF((dev)->msix_enabled)
849fbe302bSMichael S. Tsirkin 
859fbe302bSMichael S. Tsirkin /* Virtio ABI version, this must match exactly */
869fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_ABI_VERSION		0
879fbe302bSMichael S. Tsirkin 
889fbe302bSMichael S. Tsirkin /* How many bits to shift physical queue address written to QUEUE_PFN.
899fbe302bSMichael S. Tsirkin  * 12 is historical, and due to x86 page size. */
909fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_QUEUE_ADDR_SHIFT	12
919fbe302bSMichael S. Tsirkin 
929fbe302bSMichael S. Tsirkin /* The alignment to use between consumer and producer parts of vring.
939fbe302bSMichael S. Tsirkin  * x86 pagesize again. */
949fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_VRING_ALIGN		4096
959fbe302bSMichael S. Tsirkin 
969fbe302bSMichael S. Tsirkin #endif /* VIRTIO_PCI_NO_LEGACY */
979fbe302bSMichael S. Tsirkin 
989fbe302bSMichael S. Tsirkin /* The bit of the ISR which indicates a device configuration change. */
999fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_ISR_CONFIG		0x2
1009fbe302bSMichael S. Tsirkin /* Vector value used to disable MSI for queue */
1019fbe302bSMichael S. Tsirkin #define VIRTIO_MSI_NO_VECTOR            0xffff
1029fbe302bSMichael S. Tsirkin 
1039fbe302bSMichael S. Tsirkin #ifndef VIRTIO_PCI_NO_MODERN
1049fbe302bSMichael S. Tsirkin 
1059fbe302bSMichael S. Tsirkin /* IDs for different capabilities.  Must all exist. */
1069fbe302bSMichael S. Tsirkin 
1079fbe302bSMichael S. Tsirkin /* Common configuration */
1089fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_CAP_COMMON_CFG	1
1099fbe302bSMichael S. Tsirkin /* Notifications */
1109fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_CAP_NOTIFY_CFG	2
1119fbe302bSMichael S. Tsirkin /* ISR access */
1129fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_CAP_ISR_CFG		3
1139fbe302bSMichael S. Tsirkin /* Device specific configuration */
1149fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_CAP_DEVICE_CFG	4
1159fbe302bSMichael S. Tsirkin /* PCI configuration access */
1169fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_CAP_PCI_CFG		5
11753ba2eeeSMatthew Rosato /* Additional shared memory capability */
11853ba2eeeSMatthew Rosato #define VIRTIO_PCI_CAP_SHARED_MEMORY_CFG 8
1199fbe302bSMichael S. Tsirkin 
1209fbe302bSMichael S. Tsirkin /* This is the PCI capability header: */
1219fbe302bSMichael S. Tsirkin struct virtio_pci_cap {
1229fbe302bSMichael S. Tsirkin 	uint8_t cap_vndr;		/* Generic PCI field: PCI_CAP_ID_VNDR */
1239fbe302bSMichael S. Tsirkin 	uint8_t cap_next;		/* Generic PCI field: next ptr. */
1249fbe302bSMichael S. Tsirkin 	uint8_t cap_len;		/* Generic PCI field: capability length */
1259fbe302bSMichael S. Tsirkin 	uint8_t cfg_type;		/* Identifies the structure. */
1269fbe302bSMichael S. Tsirkin 	uint8_t bar;		/* Where to find it. */
12753ba2eeeSMatthew Rosato 	uint8_t id;		/* Multiple capabilities of the same type */
12853ba2eeeSMatthew Rosato 	uint8_t padding[2];	/* Pad to full dword. */
1299fbe302bSMichael S. Tsirkin 	uint32_t offset;		/* Offset within bar. */
1309fbe302bSMichael S. Tsirkin 	uint32_t length;		/* Length of the structure, in bytes. */
1319fbe302bSMichael S. Tsirkin };
1329fbe302bSMichael S. Tsirkin 
13353ba2eeeSMatthew Rosato struct virtio_pci_cap64 {
13453ba2eeeSMatthew Rosato 	struct virtio_pci_cap cap;
13553ba2eeeSMatthew Rosato 	uint32_t offset_hi;             /* Most sig 32 bits of offset */
13653ba2eeeSMatthew Rosato 	uint32_t length_hi;             /* Most sig 32 bits of length */
13753ba2eeeSMatthew Rosato };
13853ba2eeeSMatthew Rosato 
1399fbe302bSMichael S. Tsirkin struct virtio_pci_notify_cap {
1409fbe302bSMichael S. Tsirkin 	struct virtio_pci_cap cap;
1419fbe302bSMichael S. Tsirkin 	uint32_t notify_off_multiplier;	/* Multiplier for queue_notify_off. */
1429fbe302bSMichael S. Tsirkin };
1439fbe302bSMichael S. Tsirkin 
1449fbe302bSMichael S. Tsirkin /* Fields in VIRTIO_PCI_CAP_COMMON_CFG: */
1459fbe302bSMichael S. Tsirkin struct virtio_pci_common_cfg {
1469fbe302bSMichael S. Tsirkin 	/* About the whole device. */
1479fbe302bSMichael S. Tsirkin 	uint32_t device_feature_select;	/* read-write */
1489fbe302bSMichael S. Tsirkin 	uint32_t device_feature;		/* read-only */
1499fbe302bSMichael S. Tsirkin 	uint32_t guest_feature_select;	/* read-write */
1509fbe302bSMichael S. Tsirkin 	uint32_t guest_feature;		/* read-write */
1519fbe302bSMichael S. Tsirkin 	uint16_t msix_config;		/* read-write */
1529fbe302bSMichael S. Tsirkin 	uint16_t num_queues;		/* read-only */
1539fbe302bSMichael S. Tsirkin 	uint8_t device_status;		/* read-write */
1549fbe302bSMichael S. Tsirkin 	uint8_t config_generation;		/* read-only */
1559fbe302bSMichael S. Tsirkin 
1569fbe302bSMichael S. Tsirkin 	/* About a specific virtqueue. */
1579fbe302bSMichael S. Tsirkin 	uint16_t queue_select;		/* read-write */
1589fbe302bSMichael S. Tsirkin 	uint16_t queue_size;		/* read-write, power of 2. */
1599fbe302bSMichael S. Tsirkin 	uint16_t queue_msix_vector;	/* read-write */
1609fbe302bSMichael S. Tsirkin 	uint16_t queue_enable;		/* read-write */
1619fbe302bSMichael S. Tsirkin 	uint16_t queue_notify_off;	/* read-only */
1629fbe302bSMichael S. Tsirkin 	uint32_t queue_desc_lo;		/* read-write */
1639fbe302bSMichael S. Tsirkin 	uint32_t queue_desc_hi;		/* read-write */
1649fbe302bSMichael S. Tsirkin 	uint32_t queue_avail_lo;		/* read-write */
1659fbe302bSMichael S. Tsirkin 	uint32_t queue_avail_hi;		/* read-write */
1669fbe302bSMichael S. Tsirkin 	uint32_t queue_used_lo;		/* read-write */
1679fbe302bSMichael S. Tsirkin 	uint32_t queue_used_hi;		/* read-write */
1689fbe302bSMichael S. Tsirkin };
1699fbe302bSMichael S. Tsirkin 
170efb91426SDaniel Henrique Barboza /*
171efb91426SDaniel Henrique Barboza  * Warning: do not use sizeof on this: use offsetofend for
172efb91426SDaniel Henrique Barboza  * specific fields you need.
173efb91426SDaniel Henrique Barboza  */
174efb91426SDaniel Henrique Barboza struct virtio_pci_modern_common_cfg {
175efb91426SDaniel Henrique Barboza 	struct virtio_pci_common_cfg cfg;
176efb91426SDaniel Henrique Barboza 
177efb91426SDaniel Henrique Barboza 	uint16_t queue_notify_data;	/* read-write */
178efb91426SDaniel Henrique Barboza 	uint16_t queue_reset;		/* read-write */
1796a02465fSDaniel Henrique Barboza 
1806a02465fSDaniel Henrique Barboza 	uint16_t admin_queue_index;	/* read-only */
1816a02465fSDaniel Henrique Barboza 	uint16_t admin_queue_num;		/* read-only */
182efb91426SDaniel Henrique Barboza };
183efb91426SDaniel Henrique Barboza 
184c36f24a2SMichael S. Tsirkin /* Fields in VIRTIO_PCI_CAP_PCI_CFG: */
185c36f24a2SMichael S. Tsirkin struct virtio_pci_cfg_cap {
186c36f24a2SMichael S. Tsirkin 	struct virtio_pci_cap cap;
187c36f24a2SMichael S. Tsirkin 	uint8_t pci_cfg_data[4]; /* Data for BAR access. */
188c36f24a2SMichael S. Tsirkin };
189c36f24a2SMichael S. Tsirkin 
1909fbe302bSMichael S. Tsirkin /* Macro versions of offsets for the Old Timers! */
1919fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_CAP_VNDR		0
1929fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_CAP_NEXT		1
1939fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_CAP_LEN		2
1949fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_CAP_CFG_TYPE		3
1959fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_CAP_BAR		4
1969fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_CAP_OFFSET		8
1979fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_CAP_LENGTH		12
1989fbe302bSMichael S. Tsirkin 
1999fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_NOTIFY_CAP_MULT	16
2009fbe302bSMichael S. Tsirkin 
2019fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_DFSELECT	0
2029fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_DF		4
2039fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_GFSELECT	8
2049fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_GF		12
2059fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_MSIX		16
2069fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_NUMQ		18
2079fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_STATUS	20
2089fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_CFGGENERATION	21
2099fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_Q_SELECT	22
2109fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_Q_SIZE	24
2119fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_Q_MSIX	26
2129fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_Q_ENABLE	28
2139fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_Q_NOFF	30
2149fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_Q_DESCLO	32
2159fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_Q_DESCHI	36
2169fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_Q_AVAILLO	40
2179fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_Q_AVAILHI	44
2189fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_Q_USEDLO	48
2199fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_Q_USEDHI	52
220d525f73fSChenyi Qiang #define VIRTIO_PCI_COMMON_Q_NDATA	56
221d525f73fSChenyi Qiang #define VIRTIO_PCI_COMMON_Q_RESET	58
2226a02465fSDaniel Henrique Barboza #define VIRTIO_PCI_COMMON_ADM_Q_IDX	60
2236a02465fSDaniel Henrique Barboza #define VIRTIO_PCI_COMMON_ADM_Q_NUM	62
2249fbe302bSMichael S. Tsirkin 
2259fbe302bSMichael S. Tsirkin #endif /* VIRTIO_PCI_NO_MODERN */
2269fbe302bSMichael S. Tsirkin 
2276a02465fSDaniel Henrique Barboza /* Admin command status. */
2286a02465fSDaniel Henrique Barboza #define VIRTIO_ADMIN_STATUS_OK		0
2296a02465fSDaniel Henrique Barboza 
2306a02465fSDaniel Henrique Barboza /* Admin command opcode. */
2316a02465fSDaniel Henrique Barboza #define VIRTIO_ADMIN_CMD_LIST_QUERY	0x0
2326a02465fSDaniel Henrique Barboza #define VIRTIO_ADMIN_CMD_LIST_USE	0x1
2336a02465fSDaniel Henrique Barboza 
2346a02465fSDaniel Henrique Barboza /* Admin command group type. */
2356a02465fSDaniel Henrique Barboza #define VIRTIO_ADMIN_GROUP_TYPE_SRIOV	0x1
2366a02465fSDaniel Henrique Barboza 
2376a02465fSDaniel Henrique Barboza /* Transitional device admin command. */
2386a02465fSDaniel Henrique Barboza #define VIRTIO_ADMIN_CMD_LEGACY_COMMON_CFG_WRITE	0x2
2396a02465fSDaniel Henrique Barboza #define VIRTIO_ADMIN_CMD_LEGACY_COMMON_CFG_READ		0x3
2406a02465fSDaniel Henrique Barboza #define VIRTIO_ADMIN_CMD_LEGACY_DEV_CFG_WRITE		0x4
2416a02465fSDaniel Henrique Barboza #define VIRTIO_ADMIN_CMD_LEGACY_DEV_CFG_READ		0x5
2426a02465fSDaniel Henrique Barboza #define VIRTIO_ADMIN_CMD_LEGACY_NOTIFY_INFO		0x6
2436a02465fSDaniel Henrique Barboza 
244*44fe383cSHendrik Brueckner /* Device parts access commands. */
245*44fe383cSHendrik Brueckner #define VIRTIO_ADMIN_CMD_CAP_ID_LIST_QUERY		0x7
246*44fe383cSHendrik Brueckner #define VIRTIO_ADMIN_CMD_DEVICE_CAP_GET			0x8
247*44fe383cSHendrik Brueckner #define VIRTIO_ADMIN_CMD_DRIVER_CAP_SET			0x9
248*44fe383cSHendrik Brueckner #define VIRTIO_ADMIN_CMD_RESOURCE_OBJ_CREATE		0xa
249*44fe383cSHendrik Brueckner #define VIRTIO_ADMIN_CMD_RESOURCE_OBJ_DESTROY		0xd
250*44fe383cSHendrik Brueckner #define VIRTIO_ADMIN_CMD_DEV_PARTS_METADATA_GET		0xe
251*44fe383cSHendrik Brueckner #define VIRTIO_ADMIN_CMD_DEV_PARTS_GET			0xf
252*44fe383cSHendrik Brueckner #define VIRTIO_ADMIN_CMD_DEV_PARTS_SET			0x10
253*44fe383cSHendrik Brueckner #define VIRTIO_ADMIN_CMD_DEV_MODE_SET			0x11
254*44fe383cSHendrik Brueckner 
255ab0c7fb2SPaolo Bonzini struct virtio_admin_cmd_hdr {
2566a02465fSDaniel Henrique Barboza 	uint16_t opcode;
2576a02465fSDaniel Henrique Barboza 	/*
2586a02465fSDaniel Henrique Barboza 	 * 1 - SR-IOV
2596a02465fSDaniel Henrique Barboza 	 * 2-65535 - reserved
2606a02465fSDaniel Henrique Barboza 	 */
2616a02465fSDaniel Henrique Barboza 	uint16_t group_type;
2626a02465fSDaniel Henrique Barboza 	/* Unused, reserved for future extensions. */
2636a02465fSDaniel Henrique Barboza 	uint8_t reserved1[12];
2646a02465fSDaniel Henrique Barboza 	uint64_t group_member_id;
2656a02465fSDaniel Henrique Barboza };
2666a02465fSDaniel Henrique Barboza 
267ab0c7fb2SPaolo Bonzini struct virtio_admin_cmd_status {
2686a02465fSDaniel Henrique Barboza 	uint16_t status;
2696a02465fSDaniel Henrique Barboza 	uint16_t status_qualifier;
2706a02465fSDaniel Henrique Barboza 	/* Unused, reserved for future extensions. */
2716a02465fSDaniel Henrique Barboza 	uint8_t reserved2[4];
2726a02465fSDaniel Henrique Barboza };
2736a02465fSDaniel Henrique Barboza 
274ab0c7fb2SPaolo Bonzini struct virtio_admin_cmd_legacy_wr_data {
2756a02465fSDaniel Henrique Barboza 	uint8_t offset; /* Starting offset of the register(s) to write. */
2766a02465fSDaniel Henrique Barboza 	uint8_t reserved[7];
2776a02465fSDaniel Henrique Barboza 	uint8_t registers[];
2786a02465fSDaniel Henrique Barboza };
2796a02465fSDaniel Henrique Barboza 
280ab0c7fb2SPaolo Bonzini struct virtio_admin_cmd_legacy_rd_data {
2816a02465fSDaniel Henrique Barboza 	uint8_t offset; /* Starting offset of the register(s) to read. */
2826a02465fSDaniel Henrique Barboza };
2836a02465fSDaniel Henrique Barboza 
2846a02465fSDaniel Henrique Barboza #define VIRTIO_ADMIN_CMD_NOTIFY_INFO_FLAGS_END 0
2856a02465fSDaniel Henrique Barboza #define VIRTIO_ADMIN_CMD_NOTIFY_INFO_FLAGS_OWNER_DEV 0x1
2866a02465fSDaniel Henrique Barboza #define VIRTIO_ADMIN_CMD_NOTIFY_INFO_FLAGS_OWNER_MEM 0x2
2876a02465fSDaniel Henrique Barboza 
2886a02465fSDaniel Henrique Barboza #define VIRTIO_ADMIN_CMD_MAX_NOTIFY_INFO 4
2896a02465fSDaniel Henrique Barboza 
290ab0c7fb2SPaolo Bonzini struct virtio_admin_cmd_notify_info_data {
2916a02465fSDaniel Henrique Barboza 	uint8_t flags; /* 0 = end of list, 1 = owner device, 2 = member device */
2926a02465fSDaniel Henrique Barboza 	uint8_t bar; /* BAR of the member or the owner device */
2936a02465fSDaniel Henrique Barboza 	uint8_t padding[6];
2946a02465fSDaniel Henrique Barboza 	uint64_t offset; /* Offset within bar. */
2956a02465fSDaniel Henrique Barboza };
2966a02465fSDaniel Henrique Barboza 
2976a02465fSDaniel Henrique Barboza struct virtio_admin_cmd_notify_info_result {
2986a02465fSDaniel Henrique Barboza 	struct virtio_admin_cmd_notify_info_data entries[VIRTIO_ADMIN_CMD_MAX_NOTIFY_INFO];
2996a02465fSDaniel Henrique Barboza };
3006a02465fSDaniel Henrique Barboza 
301*44fe383cSHendrik Brueckner #define VIRTIO_DEV_PARTS_CAP 0x0000
302*44fe383cSHendrik Brueckner 
303*44fe383cSHendrik Brueckner struct virtio_dev_parts_cap {
304*44fe383cSHendrik Brueckner 	uint8_t get_parts_resource_objects_limit;
305*44fe383cSHendrik Brueckner 	uint8_t set_parts_resource_objects_limit;
306*44fe383cSHendrik Brueckner };
307*44fe383cSHendrik Brueckner 
308*44fe383cSHendrik Brueckner #define MAX_CAP_ID __KERNEL_DIV_ROUND_UP(VIRTIO_DEV_PARTS_CAP + 1, 64)
309*44fe383cSHendrik Brueckner 
310*44fe383cSHendrik Brueckner struct virtio_admin_cmd_query_cap_id_result {
311*44fe383cSHendrik Brueckner 	uint64_t supported_caps[MAX_CAP_ID];
312*44fe383cSHendrik Brueckner };
313*44fe383cSHendrik Brueckner 
314*44fe383cSHendrik Brueckner struct virtio_admin_cmd_cap_get_data {
315*44fe383cSHendrik Brueckner 	uint16_t id;
316*44fe383cSHendrik Brueckner 	uint8_t reserved[6];
317*44fe383cSHendrik Brueckner };
318*44fe383cSHendrik Brueckner 
319*44fe383cSHendrik Brueckner struct virtio_admin_cmd_cap_set_data {
320*44fe383cSHendrik Brueckner 	uint16_t id;
321*44fe383cSHendrik Brueckner 	uint8_t reserved[6];
322*44fe383cSHendrik Brueckner 	uint8_t cap_specific_data[];
323*44fe383cSHendrik Brueckner };
324*44fe383cSHendrik Brueckner 
325*44fe383cSHendrik Brueckner struct virtio_admin_cmd_resource_obj_cmd_hdr {
326*44fe383cSHendrik Brueckner 	uint16_t type;
327*44fe383cSHendrik Brueckner 	uint8_t reserved[2];
328*44fe383cSHendrik Brueckner 	uint32_t id; /* Indicates unique resource object id per resource object type */
329*44fe383cSHendrik Brueckner };
330*44fe383cSHendrik Brueckner 
331*44fe383cSHendrik Brueckner struct virtio_admin_cmd_resource_obj_create_data {
332*44fe383cSHendrik Brueckner 	struct virtio_admin_cmd_resource_obj_cmd_hdr hdr;
333*44fe383cSHendrik Brueckner 	uint64_t flags;
334*44fe383cSHendrik Brueckner 	uint8_t resource_obj_specific_data[];
335*44fe383cSHendrik Brueckner };
336*44fe383cSHendrik Brueckner 
337*44fe383cSHendrik Brueckner #define VIRTIO_RESOURCE_OBJ_DEV_PARTS 0
338*44fe383cSHendrik Brueckner 
339*44fe383cSHendrik Brueckner #define VIRTIO_RESOURCE_OBJ_DEV_PARTS_TYPE_GET 0
340*44fe383cSHendrik Brueckner #define VIRTIO_RESOURCE_OBJ_DEV_PARTS_TYPE_SET 1
341*44fe383cSHendrik Brueckner 
342*44fe383cSHendrik Brueckner struct virtio_resource_obj_dev_parts {
343*44fe383cSHendrik Brueckner 	uint8_t type;
344*44fe383cSHendrik Brueckner 	uint8_t reserved[7];
345*44fe383cSHendrik Brueckner };
346*44fe383cSHendrik Brueckner 
347*44fe383cSHendrik Brueckner #define VIRTIO_ADMIN_CMD_DEV_PARTS_METADATA_TYPE_SIZE 0
348*44fe383cSHendrik Brueckner #define VIRTIO_ADMIN_CMD_DEV_PARTS_METADATA_TYPE_COUNT 1
349*44fe383cSHendrik Brueckner #define VIRTIO_ADMIN_CMD_DEV_PARTS_METADATA_TYPE_LIST 2
350*44fe383cSHendrik Brueckner 
351*44fe383cSHendrik Brueckner struct virtio_admin_cmd_dev_parts_metadata_data {
352*44fe383cSHendrik Brueckner 	struct virtio_admin_cmd_resource_obj_cmd_hdr hdr;
353*44fe383cSHendrik Brueckner 	uint8_t type;
354*44fe383cSHendrik Brueckner 	uint8_t reserved[7];
355*44fe383cSHendrik Brueckner };
356*44fe383cSHendrik Brueckner 
357*44fe383cSHendrik Brueckner #define VIRTIO_DEV_PART_F_OPTIONAL 0
358*44fe383cSHendrik Brueckner 
359*44fe383cSHendrik Brueckner struct virtio_dev_part_hdr {
360*44fe383cSHendrik Brueckner 	uint16_t part_type;
361*44fe383cSHendrik Brueckner 	uint8_t flags;
362*44fe383cSHendrik Brueckner 	uint8_t reserved;
363*44fe383cSHendrik Brueckner 	union {
364*44fe383cSHendrik Brueckner 		struct {
365*44fe383cSHendrik Brueckner 			uint32_t offset;
366*44fe383cSHendrik Brueckner 			uint32_t reserved;
367*44fe383cSHendrik Brueckner 		} pci_common_cfg;
368*44fe383cSHendrik Brueckner 		struct {
369*44fe383cSHendrik Brueckner 			uint16_t index;
370*44fe383cSHendrik Brueckner 			uint8_t reserved[6];
371*44fe383cSHendrik Brueckner 		} vq_index;
372*44fe383cSHendrik Brueckner 	} selector;
373*44fe383cSHendrik Brueckner 	uint32_t length;
374*44fe383cSHendrik Brueckner };
375*44fe383cSHendrik Brueckner 
376*44fe383cSHendrik Brueckner struct virtio_dev_part {
377*44fe383cSHendrik Brueckner 	struct virtio_dev_part_hdr hdr;
378*44fe383cSHendrik Brueckner 	uint8_t value[];
379*44fe383cSHendrik Brueckner };
380*44fe383cSHendrik Brueckner 
381*44fe383cSHendrik Brueckner struct virtio_admin_cmd_dev_parts_metadata_result {
382*44fe383cSHendrik Brueckner 	union {
383*44fe383cSHendrik Brueckner 		struct {
384*44fe383cSHendrik Brueckner 			uint32_t size;
385*44fe383cSHendrik Brueckner 			uint32_t reserved;
386*44fe383cSHendrik Brueckner 		} parts_size;
387*44fe383cSHendrik Brueckner 		struct {
388*44fe383cSHendrik Brueckner 			uint32_t count;
389*44fe383cSHendrik Brueckner 			uint32_t reserved;
390*44fe383cSHendrik Brueckner 		} hdr_list_count;
391*44fe383cSHendrik Brueckner 		struct {
392*44fe383cSHendrik Brueckner 			uint32_t count;
393*44fe383cSHendrik Brueckner 			uint32_t reserved;
394*44fe383cSHendrik Brueckner 			struct virtio_dev_part_hdr hdrs[];
395*44fe383cSHendrik Brueckner 		} hdr_list;
396*44fe383cSHendrik Brueckner 	};
397*44fe383cSHendrik Brueckner };
398*44fe383cSHendrik Brueckner 
399*44fe383cSHendrik Brueckner #define VIRTIO_ADMIN_CMD_DEV_PARTS_GET_TYPE_SELECTED 0
400*44fe383cSHendrik Brueckner #define VIRTIO_ADMIN_CMD_DEV_PARTS_GET_TYPE_ALL 1
401*44fe383cSHendrik Brueckner 
402*44fe383cSHendrik Brueckner struct virtio_admin_cmd_dev_parts_get_data {
403*44fe383cSHendrik Brueckner 	struct virtio_admin_cmd_resource_obj_cmd_hdr hdr;
404*44fe383cSHendrik Brueckner 	uint8_t type;
405*44fe383cSHendrik Brueckner 	uint8_t reserved[7];
406*44fe383cSHendrik Brueckner 	struct virtio_dev_part_hdr hdr_list[];
407*44fe383cSHendrik Brueckner };
408*44fe383cSHendrik Brueckner 
409*44fe383cSHendrik Brueckner struct virtio_admin_cmd_dev_parts_set_data {
410*44fe383cSHendrik Brueckner 	struct virtio_admin_cmd_resource_obj_cmd_hdr hdr;
411*44fe383cSHendrik Brueckner 	struct virtio_dev_part parts[];
412*44fe383cSHendrik Brueckner };
413*44fe383cSHendrik Brueckner 
414*44fe383cSHendrik Brueckner #define VIRTIO_ADMIN_CMD_DEV_MODE_F_STOPPED 0
415*44fe383cSHendrik Brueckner 
416*44fe383cSHendrik Brueckner struct virtio_admin_cmd_dev_mode_set_data {
417*44fe383cSHendrik Brueckner 	uint8_t flags;
418*44fe383cSHendrik Brueckner };
419*44fe383cSHendrik Brueckner 
4209fbe302bSMichael S. Tsirkin #endif
421