xref: /linux-6.15/include/uapi/linux/virtio_pci.h (revision 1629ee10)
1607ca46eSDavid Howells /*
2607ca46eSDavid Howells  * Virtio PCI driver
3607ca46eSDavid Howells  *
4607ca46eSDavid Howells  * This module allows virtio devices to be used over a virtual PCI device.
5607ca46eSDavid Howells  * This can be used with QEMU based VMMs like KVM or Xen.
6607ca46eSDavid Howells  *
7607ca46eSDavid Howells  * Copyright IBM Corp. 2007
8607ca46eSDavid Howells  *
9607ca46eSDavid Howells  * Authors:
10607ca46eSDavid Howells  *  Anthony Liguori  <[email protected]>
11607ca46eSDavid Howells  *
12607ca46eSDavid Howells  * This header is BSD licensed so anyone can use the definitions to implement
13607ca46eSDavid Howells  * compatible drivers/servers.
14607ca46eSDavid Howells  *
15607ca46eSDavid Howells  * Redistribution and use in source and binary forms, with or without
16607ca46eSDavid Howells  * modification, are permitted provided that the following conditions
17607ca46eSDavid Howells  * are met:
18607ca46eSDavid Howells  * 1. Redistributions of source code must retain the above copyright
19607ca46eSDavid Howells  *    notice, this list of conditions and the following disclaimer.
20607ca46eSDavid Howells  * 2. Redistributions in binary form must reproduce the above copyright
21607ca46eSDavid Howells  *    notice, this list of conditions and the following disclaimer in the
22607ca46eSDavid Howells  *    documentation and/or other materials provided with the distribution.
23607ca46eSDavid Howells  * 3. Neither the name of IBM nor the names of its contributors
24607ca46eSDavid Howells  *    may be used to endorse or promote products derived from this software
25607ca46eSDavid Howells  *    without specific prior written permission.
26607ca46eSDavid Howells  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
27607ca46eSDavid Howells  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28607ca46eSDavid Howells  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29607ca46eSDavid Howells  * ARE DISCLAIMED.  IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
30607ca46eSDavid Howells  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31607ca46eSDavid Howells  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32607ca46eSDavid Howells  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33607ca46eSDavid Howells  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34607ca46eSDavid Howells  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35607ca46eSDavid Howells  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36607ca46eSDavid Howells  * SUCH DAMAGE.
37607ca46eSDavid Howells  */
38607ca46eSDavid Howells 
39607ca46eSDavid Howells #ifndef _LINUX_VIRTIO_PCI_H
40607ca46eSDavid Howells #define _LINUX_VIRTIO_PCI_H
41607ca46eSDavid Howells 
427f870c81SMichael S. Tsirkin #include <linux/types.h>
437c1ae151SYishai Hadas #include <linux/kernel.h>
44607ca46eSDavid Howells 
450dce3771SMichael S. Tsirkin #ifndef VIRTIO_PCI_NO_LEGACY
460dce3771SMichael S. Tsirkin 
47607ca46eSDavid Howells /* A 32-bit r/o bitmask of the features supported by the host */
48607ca46eSDavid Howells #define VIRTIO_PCI_HOST_FEATURES	0
49607ca46eSDavid Howells 
50607ca46eSDavid Howells /* A 32-bit r/w bitmask of features activated by the guest */
51607ca46eSDavid Howells #define VIRTIO_PCI_GUEST_FEATURES	4
52607ca46eSDavid Howells 
53607ca46eSDavid Howells /* A 32-bit r/w PFN for the currently selected queue */
54607ca46eSDavid Howells #define VIRTIO_PCI_QUEUE_PFN		8
55607ca46eSDavid Howells 
56607ca46eSDavid Howells /* A 16-bit r/o queue size for the currently selected queue */
57607ca46eSDavid Howells #define VIRTIO_PCI_QUEUE_NUM		12
58607ca46eSDavid Howells 
59607ca46eSDavid Howells /* A 16-bit r/w queue selector */
60607ca46eSDavid Howells #define VIRTIO_PCI_QUEUE_SEL		14
61607ca46eSDavid Howells 
62607ca46eSDavid Howells /* A 16-bit r/w queue notifier */
63607ca46eSDavid Howells #define VIRTIO_PCI_QUEUE_NOTIFY		16
64607ca46eSDavid Howells 
65607ca46eSDavid Howells /* An 8-bit device status register.  */
66607ca46eSDavid Howells #define VIRTIO_PCI_STATUS		18
67607ca46eSDavid Howells 
68607ca46eSDavid Howells /* An 8-bit r/o interrupt status register.  Reading the value will return the
69607ca46eSDavid Howells  * current contents of the ISR and will also clear it.  This is effectively
70607ca46eSDavid Howells  * a read-and-acknowledge. */
71607ca46eSDavid Howells #define VIRTIO_PCI_ISR			19
72607ca46eSDavid Howells 
73607ca46eSDavid Howells /* MSI-X registers: only enabled if MSI-X is enabled. */
74607ca46eSDavid Howells /* A 16-bit vector for configuration changes. */
75607ca46eSDavid Howells #define VIRTIO_MSI_CONFIG_VECTOR        20
76607ca46eSDavid Howells /* A 16-bit vector for selected queue notifications. */
77607ca46eSDavid Howells #define VIRTIO_MSI_QUEUE_VECTOR         22
78607ca46eSDavid Howells 
79607ca46eSDavid Howells /* The remaining space is defined by each driver as the per-driver
80607ca46eSDavid Howells  * configuration space */
818b21ab14SMichael S. Tsirkin #define VIRTIO_PCI_CONFIG_OFF(msix_enabled)	((msix_enabled) ? 24 : 20)
828b21ab14SMichael S. Tsirkin /* Deprecated: please use VIRTIO_PCI_CONFIG_OFF instead */
832008c154SMichael S. Tsirkin #define VIRTIO_PCI_CONFIG(dev)	VIRTIO_PCI_CONFIG_OFF((dev)->msix_enabled)
84607ca46eSDavid Howells 
85607ca46eSDavid Howells /* Virtio ABI version, this must match exactly */
86607ca46eSDavid Howells #define VIRTIO_PCI_ABI_VERSION		0
87607ca46eSDavid Howells 
88607ca46eSDavid Howells /* How many bits to shift physical queue address written to QUEUE_PFN.
89607ca46eSDavid Howells  * 12 is historical, and due to x86 page size. */
90607ca46eSDavid Howells #define VIRTIO_PCI_QUEUE_ADDR_SHIFT	12
91607ca46eSDavid Howells 
92607ca46eSDavid Howells /* The alignment to use between consumer and producer parts of vring.
93607ca46eSDavid Howells  * x86 pagesize again. */
94607ca46eSDavid Howells #define VIRTIO_PCI_VRING_ALIGN		4096
950dce3771SMichael S. Tsirkin 
960dce3771SMichael S. Tsirkin #endif /* VIRTIO_PCI_NO_LEGACY */
970dce3771SMichael S. Tsirkin 
980dce3771SMichael S. Tsirkin /* The bit of the ISR which indicates a device configuration change. */
990dce3771SMichael S. Tsirkin #define VIRTIO_PCI_ISR_CONFIG		0x2
1000dce3771SMichael S. Tsirkin /* Vector value used to disable MSI for queue */
1010dce3771SMichael S. Tsirkin #define VIRTIO_MSI_NO_VECTOR            0xffff
1020dce3771SMichael S. Tsirkin 
10371d70c26SRusty Russell #ifndef VIRTIO_PCI_NO_MODERN
10471d70c26SRusty Russell 
10571d70c26SRusty Russell /* IDs for different capabilities.  Must all exist. */
10671d70c26SRusty Russell 
10771d70c26SRusty Russell /* Common configuration */
10871d70c26SRusty Russell #define VIRTIO_PCI_CAP_COMMON_CFG	1
10971d70c26SRusty Russell /* Notifications */
11071d70c26SRusty Russell #define VIRTIO_PCI_CAP_NOTIFY_CFG	2
11171d70c26SRusty Russell /* ISR access */
11271d70c26SRusty Russell #define VIRTIO_PCI_CAP_ISR_CFG		3
113e6a02746SRusty Russell /* Device specific configuration */
11471d70c26SRusty Russell #define VIRTIO_PCI_CAP_DEVICE_CFG	4
115e6a02746SRusty Russell /* PCI configuration access */
116e6a02746SRusty Russell #define VIRTIO_PCI_CAP_PCI_CFG		5
1170dd4ff93SSebastien Boeuf /* Additional shared memory capability */
1180dd4ff93SSebastien Boeuf #define VIRTIO_PCI_CAP_SHARED_MEMORY_CFG 8
119*1629ee10SShijith Thotton /* PCI vendor data configuration */
120*1629ee10SShijith Thotton #define VIRTIO_PCI_CAP_VENDOR_CFG	9
12171d70c26SRusty Russell 
12271d70c26SRusty Russell /* This is the PCI capability header: */
12371d70c26SRusty Russell struct virtio_pci_cap {
12471d70c26SRusty Russell 	__u8 cap_vndr;		/* Generic PCI field: PCI_CAP_ID_VNDR */
12571d70c26SRusty Russell 	__u8 cap_next;		/* Generic PCI field: next ptr. */
12671d70c26SRusty Russell 	__u8 cap_len;		/* Generic PCI field: capability length */
1271fcf0512SMichael S. Tsirkin 	__u8 cfg_type;		/* Identifies the structure. */
1281fcf0512SMichael S. Tsirkin 	__u8 bar;		/* Where to find it. */
1290dd4ff93SSebastien Boeuf 	__u8 id;		/* Multiple capabilities of the same type */
1300dd4ff93SSebastien Boeuf 	__u8 padding[2];	/* Pad to full dword. */
13171d70c26SRusty Russell 	__le32 offset;		/* Offset within bar. */
1321fcf0512SMichael S. Tsirkin 	__le32 length;		/* Length of the structure, in bytes. */
13371d70c26SRusty Russell };
13471d70c26SRusty Russell 
135*1629ee10SShijith Thotton /* This is the PCI vendor data capability header: */
136*1629ee10SShijith Thotton struct virtio_pci_vndr_data {
137*1629ee10SShijith Thotton 	__u8 cap_vndr;		/* Generic PCI field: PCI_CAP_ID_VNDR */
138*1629ee10SShijith Thotton 	__u8 cap_next;		/* Generic PCI field: next ptr. */
139*1629ee10SShijith Thotton 	__u8 cap_len;		/* Generic PCI field: capability length */
140*1629ee10SShijith Thotton 	__u8 cfg_type;		/* Identifies the structure. */
141*1629ee10SShijith Thotton 	__u16 vendor_id;	/* Identifies the vendor-specific format. */
142*1629ee10SShijith Thotton 	/* For Vendor Definition */
143*1629ee10SShijith Thotton 	/* Pads structure to a multiple of 4 bytes */
144*1629ee10SShijith Thotton 	/* Reads must not have side effects */
145*1629ee10SShijith Thotton };
146*1629ee10SShijith Thotton 
1470dd4ff93SSebastien Boeuf struct virtio_pci_cap64 {
1480dd4ff93SSebastien Boeuf 	struct virtio_pci_cap cap;
1490dd4ff93SSebastien Boeuf 	__le32 offset_hi;             /* Most sig 32 bits of offset */
1500dd4ff93SSebastien Boeuf 	__le32 length_hi;             /* Most sig 32 bits of length */
1510dd4ff93SSebastien Boeuf };
1520dd4ff93SSebastien Boeuf 
15371d70c26SRusty Russell struct virtio_pci_notify_cap {
15471d70c26SRusty Russell 	struct virtio_pci_cap cap;
15571d70c26SRusty Russell 	__le32 notify_off_multiplier;	/* Multiplier for queue_notify_off. */
15671d70c26SRusty Russell };
15771d70c26SRusty Russell 
15871d70c26SRusty Russell /* Fields in VIRTIO_PCI_CAP_COMMON_CFG: */
15971d70c26SRusty Russell struct virtio_pci_common_cfg {
16071d70c26SRusty Russell 	/* About the whole device. */
16171d70c26SRusty Russell 	__le32 device_feature_select;	/* read-write */
16271d70c26SRusty Russell 	__le32 device_feature;		/* read-only */
16371d70c26SRusty Russell 	__le32 guest_feature_select;	/* read-write */
16471d70c26SRusty Russell 	__le32 guest_feature;		/* read-write */
16571d70c26SRusty Russell 	__le16 msix_config;		/* read-write */
16671d70c26SRusty Russell 	__le16 num_queues;		/* read-only */
16771d70c26SRusty Russell 	__u8 device_status;		/* read-write */
16871d70c26SRusty Russell 	__u8 config_generation;		/* read-only */
16971d70c26SRusty Russell 
17071d70c26SRusty Russell 	/* About a specific virtqueue. */
17171d70c26SRusty Russell 	__le16 queue_select;		/* read-write */
17271d70c26SRusty Russell 	__le16 queue_size;		/* read-write, power of 2. */
17371d70c26SRusty Russell 	__le16 queue_msix_vector;	/* read-write */
17471d70c26SRusty Russell 	__le16 queue_enable;		/* read-write */
17571d70c26SRusty Russell 	__le16 queue_notify_off;	/* read-only */
17671d70c26SRusty Russell 	__le32 queue_desc_lo;		/* read-write */
17771d70c26SRusty Russell 	__le32 queue_desc_hi;		/* read-write */
17871d70c26SRusty Russell 	__le32 queue_avail_lo;		/* read-write */
17971d70c26SRusty Russell 	__le32 queue_avail_hi;		/* read-write */
18071d70c26SRusty Russell 	__le32 queue_used_lo;		/* read-write */
18171d70c26SRusty Russell 	__le32 queue_used_hi;		/* read-write */
18271d70c26SRusty Russell };
18371d70c26SRusty Russell 
18435038957SMichael S. Tsirkin /*
18535038957SMichael S. Tsirkin  * Warning: do not use sizeof on this: use offsetofend for
18635038957SMichael S. Tsirkin  * specific fields you need.
18735038957SMichael S. Tsirkin  */
18835038957SMichael S. Tsirkin struct virtio_pci_modern_common_cfg {
18935038957SMichael S. Tsirkin 	struct virtio_pci_common_cfg cfg;
19035038957SMichael S. Tsirkin 
19135038957SMichael S. Tsirkin 	__le16 queue_notify_data;	/* read-write */
19235038957SMichael S. Tsirkin 	__le16 queue_reset;		/* read-write */
193fd27ef6bSFeng Liu 
194fd27ef6bSFeng Liu 	__le16 admin_queue_index;	/* read-only */
195fd27ef6bSFeng Liu 	__le16 admin_queue_num;		/* read-only */
19635038957SMichael S. Tsirkin };
19735038957SMichael S. Tsirkin 
1983121bb02SMichael S. Tsirkin /* Fields in VIRTIO_PCI_CAP_PCI_CFG: */
1993121bb02SMichael S. Tsirkin struct virtio_pci_cfg_cap {
2003121bb02SMichael S. Tsirkin 	struct virtio_pci_cap cap;
2013121bb02SMichael S. Tsirkin 	__u8 pci_cfg_data[4]; /* Data for BAR access. */
2023121bb02SMichael S. Tsirkin };
2033121bb02SMichael S. Tsirkin 
20489461c4aSRusty Russell /* Macro versions of offsets for the Old Timers! */
20589461c4aSRusty Russell #define VIRTIO_PCI_CAP_VNDR		0
20689461c4aSRusty Russell #define VIRTIO_PCI_CAP_NEXT		1
20789461c4aSRusty Russell #define VIRTIO_PCI_CAP_LEN		2
20889461c4aSRusty Russell #define VIRTIO_PCI_CAP_CFG_TYPE		3
20989461c4aSRusty Russell #define VIRTIO_PCI_CAP_BAR		4
21089461c4aSRusty Russell #define VIRTIO_PCI_CAP_OFFSET		8
21189461c4aSRusty Russell #define VIRTIO_PCI_CAP_LENGTH		12
21289461c4aSRusty Russell 
21389461c4aSRusty Russell #define VIRTIO_PCI_NOTIFY_CAP_MULT	16
21489461c4aSRusty Russell 
21589461c4aSRusty Russell #define VIRTIO_PCI_COMMON_DFSELECT	0
21689461c4aSRusty Russell #define VIRTIO_PCI_COMMON_DF		4
21789461c4aSRusty Russell #define VIRTIO_PCI_COMMON_GFSELECT	8
21889461c4aSRusty Russell #define VIRTIO_PCI_COMMON_GF		12
21989461c4aSRusty Russell #define VIRTIO_PCI_COMMON_MSIX		16
22089461c4aSRusty Russell #define VIRTIO_PCI_COMMON_NUMQ		18
22189461c4aSRusty Russell #define VIRTIO_PCI_COMMON_STATUS	20
22289461c4aSRusty Russell #define VIRTIO_PCI_COMMON_CFGGENERATION	21
22389461c4aSRusty Russell #define VIRTIO_PCI_COMMON_Q_SELECT	22
22489461c4aSRusty Russell #define VIRTIO_PCI_COMMON_Q_SIZE	24
22589461c4aSRusty Russell #define VIRTIO_PCI_COMMON_Q_MSIX	26
22689461c4aSRusty Russell #define VIRTIO_PCI_COMMON_Q_ENABLE	28
22789461c4aSRusty Russell #define VIRTIO_PCI_COMMON_Q_NOFF	30
22889461c4aSRusty Russell #define VIRTIO_PCI_COMMON_Q_DESCLO	32
22989461c4aSRusty Russell #define VIRTIO_PCI_COMMON_Q_DESCHI	36
23089461c4aSRusty Russell #define VIRTIO_PCI_COMMON_Q_AVAILLO	40
23189461c4aSRusty Russell #define VIRTIO_PCI_COMMON_Q_AVAILHI	44
23289461c4aSRusty Russell #define VIRTIO_PCI_COMMON_Q_USEDLO	48
23389461c4aSRusty Russell #define VIRTIO_PCI_COMMON_Q_USEDHI	52
234ea024594SXuan Zhuo #define VIRTIO_PCI_COMMON_Q_NDATA	56
2350cdd450eSXuan Zhuo #define VIRTIO_PCI_COMMON_Q_RESET	58
236fd27ef6bSFeng Liu #define VIRTIO_PCI_COMMON_ADM_Q_IDX	60
237fd27ef6bSFeng Liu #define VIRTIO_PCI_COMMON_ADM_Q_NUM	62
23889461c4aSRusty Russell 
23971d70c26SRusty Russell #endif /* VIRTIO_PCI_NO_MODERN */
24071d70c26SRusty Russell 
24192792ac7SFeng Liu /* Admin command status. */
24292792ac7SFeng Liu #define VIRTIO_ADMIN_STATUS_OK		0
24392792ac7SFeng Liu 
244388431b9SFeng Liu /* Admin command opcode. */
245388431b9SFeng Liu #define VIRTIO_ADMIN_CMD_LIST_QUERY	0x0
246388431b9SFeng Liu #define VIRTIO_ADMIN_CMD_LIST_USE	0x1
247388431b9SFeng Liu 
248388431b9SFeng Liu /* Admin command group type. */
249388431b9SFeng Liu #define VIRTIO_ADMIN_GROUP_TYPE_SRIOV	0x1
250388431b9SFeng Liu 
251388431b9SFeng Liu /* Transitional device admin command. */
252388431b9SFeng Liu #define VIRTIO_ADMIN_CMD_LEGACY_COMMON_CFG_WRITE	0x2
253388431b9SFeng Liu #define VIRTIO_ADMIN_CMD_LEGACY_COMMON_CFG_READ		0x3
254388431b9SFeng Liu #define VIRTIO_ADMIN_CMD_LEGACY_DEV_CFG_WRITE		0x4
255388431b9SFeng Liu #define VIRTIO_ADMIN_CMD_LEGACY_DEV_CFG_READ		0x5
256388431b9SFeng Liu #define VIRTIO_ADMIN_CMD_LEGACY_NOTIFY_INFO		0x6
257388431b9SFeng Liu 
2587c1ae151SYishai Hadas /* Device parts access commands. */
2597c1ae151SYishai Hadas #define VIRTIO_ADMIN_CMD_CAP_ID_LIST_QUERY		0x7
2607c1ae151SYishai Hadas #define VIRTIO_ADMIN_CMD_DEVICE_CAP_GET			0x8
2617c1ae151SYishai Hadas #define VIRTIO_ADMIN_CMD_DRIVER_CAP_SET			0x9
2627c1ae151SYishai Hadas #define VIRTIO_ADMIN_CMD_RESOURCE_OBJ_CREATE		0xa
2637c1ae151SYishai Hadas #define VIRTIO_ADMIN_CMD_RESOURCE_OBJ_DESTROY		0xd
2647c1ae151SYishai Hadas #define VIRTIO_ADMIN_CMD_DEV_PARTS_METADATA_GET		0xe
2657c1ae151SYishai Hadas #define VIRTIO_ADMIN_CMD_DEV_PARTS_GET			0xf
2667c1ae151SYishai Hadas #define VIRTIO_ADMIN_CMD_DEV_PARTS_SET			0x10
2677c1ae151SYishai Hadas #define VIRTIO_ADMIN_CMD_DEV_MODE_SET			0x11
2687c1ae151SYishai Hadas 
269ec6ecb84SSuzuki K Poulose struct virtio_admin_cmd_hdr {
27092792ac7SFeng Liu 	__le16 opcode;
27192792ac7SFeng Liu 	/*
27292792ac7SFeng Liu 	 * 1 - SR-IOV
27392792ac7SFeng Liu 	 * 2-65535 - reserved
27492792ac7SFeng Liu 	 */
27592792ac7SFeng Liu 	__le16 group_type;
27692792ac7SFeng Liu 	/* Unused, reserved for future extensions. */
27792792ac7SFeng Liu 	__u8 reserved1[12];
27892792ac7SFeng Liu 	__le64 group_member_id;
27992792ac7SFeng Liu };
28092792ac7SFeng Liu 
281ec6ecb84SSuzuki K Poulose struct virtio_admin_cmd_status {
28292792ac7SFeng Liu 	__le16 status;
28392792ac7SFeng Liu 	__le16 status_qualifier;
28492792ac7SFeng Liu 	/* Unused, reserved for future extensions. */
28592792ac7SFeng Liu 	__u8 reserved2[4];
28692792ac7SFeng Liu };
28792792ac7SFeng Liu 
288ec6ecb84SSuzuki K Poulose struct virtio_admin_cmd_legacy_wr_data {
289388431b9SFeng Liu 	__u8 offset; /* Starting offset of the register(s) to write. */
290388431b9SFeng Liu 	__u8 reserved[7];
291388431b9SFeng Liu 	__u8 registers[];
292388431b9SFeng Liu };
293388431b9SFeng Liu 
294ec6ecb84SSuzuki K Poulose struct virtio_admin_cmd_legacy_rd_data {
295388431b9SFeng Liu 	__u8 offset; /* Starting offset of the register(s) to read. */
296388431b9SFeng Liu };
297388431b9SFeng Liu 
298388431b9SFeng Liu #define VIRTIO_ADMIN_CMD_NOTIFY_INFO_FLAGS_END 0
299388431b9SFeng Liu #define VIRTIO_ADMIN_CMD_NOTIFY_INFO_FLAGS_OWNER_DEV 0x1
300388431b9SFeng Liu #define VIRTIO_ADMIN_CMD_NOTIFY_INFO_FLAGS_OWNER_MEM 0x2
301388431b9SFeng Liu 
302388431b9SFeng Liu #define VIRTIO_ADMIN_CMD_MAX_NOTIFY_INFO 4
303388431b9SFeng Liu 
304ec6ecb84SSuzuki K Poulose struct virtio_admin_cmd_notify_info_data {
305388431b9SFeng Liu 	__u8 flags; /* 0 = end of list, 1 = owner device, 2 = member device */
306388431b9SFeng Liu 	__u8 bar; /* BAR of the member or the owner device */
307388431b9SFeng Liu 	__u8 padding[6];
308388431b9SFeng Liu 	__le64 offset; /* Offset within bar. */
309388431b9SFeng Liu };
310388431b9SFeng Liu 
311388431b9SFeng Liu struct virtio_admin_cmd_notify_info_result {
312388431b9SFeng Liu 	struct virtio_admin_cmd_notify_info_data entries[VIRTIO_ADMIN_CMD_MAX_NOTIFY_INFO];
313388431b9SFeng Liu };
314388431b9SFeng Liu 
3157c1ae151SYishai Hadas #define VIRTIO_DEV_PARTS_CAP 0x0000
3167c1ae151SYishai Hadas 
3177c1ae151SYishai Hadas struct virtio_dev_parts_cap {
3187c1ae151SYishai Hadas 	__u8 get_parts_resource_objects_limit;
3197c1ae151SYishai Hadas 	__u8 set_parts_resource_objects_limit;
3207c1ae151SYishai Hadas };
3217c1ae151SYishai Hadas 
3227c1ae151SYishai Hadas #define MAX_CAP_ID __KERNEL_DIV_ROUND_UP(VIRTIO_DEV_PARTS_CAP + 1, 64)
3237c1ae151SYishai Hadas 
3247c1ae151SYishai Hadas struct virtio_admin_cmd_query_cap_id_result {
3257c1ae151SYishai Hadas 	__le64 supported_caps[MAX_CAP_ID];
3267c1ae151SYishai Hadas };
3277c1ae151SYishai Hadas 
3287c1ae151SYishai Hadas struct virtio_admin_cmd_cap_get_data {
3297c1ae151SYishai Hadas 	__le16 id;
3307c1ae151SYishai Hadas 	__u8 reserved[6];
3317c1ae151SYishai Hadas };
3327c1ae151SYishai Hadas 
3337c1ae151SYishai Hadas struct virtio_admin_cmd_cap_set_data {
3347c1ae151SYishai Hadas 	__le16 id;
3357c1ae151SYishai Hadas 	__u8 reserved[6];
3367c1ae151SYishai Hadas 	__u8 cap_specific_data[];
3377c1ae151SYishai Hadas };
3387c1ae151SYishai Hadas 
3397c1ae151SYishai Hadas struct virtio_admin_cmd_resource_obj_cmd_hdr {
3407c1ae151SYishai Hadas 	__le16 type;
3417c1ae151SYishai Hadas 	__u8 reserved[2];
3427c1ae151SYishai Hadas 	__le32 id; /* Indicates unique resource object id per resource object type */
3437c1ae151SYishai Hadas };
3447c1ae151SYishai Hadas 
3457c1ae151SYishai Hadas struct virtio_admin_cmd_resource_obj_create_data {
3467c1ae151SYishai Hadas 	struct virtio_admin_cmd_resource_obj_cmd_hdr hdr;
3477c1ae151SYishai Hadas 	__le64 flags;
3487c1ae151SYishai Hadas 	__u8 resource_obj_specific_data[];
3497c1ae151SYishai Hadas };
3507c1ae151SYishai Hadas 
3517c1ae151SYishai Hadas #define VIRTIO_RESOURCE_OBJ_DEV_PARTS 0
3527c1ae151SYishai Hadas 
3537c1ae151SYishai Hadas #define VIRTIO_RESOURCE_OBJ_DEV_PARTS_TYPE_GET 0
3547c1ae151SYishai Hadas #define VIRTIO_RESOURCE_OBJ_DEV_PARTS_TYPE_SET 1
3557c1ae151SYishai Hadas 
3567c1ae151SYishai Hadas struct virtio_resource_obj_dev_parts {
3577c1ae151SYishai Hadas 	__u8 type;
3587c1ae151SYishai Hadas 	__u8 reserved[7];
3597c1ae151SYishai Hadas };
3607c1ae151SYishai Hadas 
3617c1ae151SYishai Hadas #define VIRTIO_ADMIN_CMD_DEV_PARTS_METADATA_TYPE_SIZE 0
3627c1ae151SYishai Hadas #define VIRTIO_ADMIN_CMD_DEV_PARTS_METADATA_TYPE_COUNT 1
3637c1ae151SYishai Hadas #define VIRTIO_ADMIN_CMD_DEV_PARTS_METADATA_TYPE_LIST 2
3647c1ae151SYishai Hadas 
3657c1ae151SYishai Hadas struct virtio_admin_cmd_dev_parts_metadata_data {
3667c1ae151SYishai Hadas 	struct virtio_admin_cmd_resource_obj_cmd_hdr hdr;
3677c1ae151SYishai Hadas 	__u8 type;
3687c1ae151SYishai Hadas 	__u8 reserved[7];
3697c1ae151SYishai Hadas };
3707c1ae151SYishai Hadas 
3717c1ae151SYishai Hadas #define VIRTIO_DEV_PART_F_OPTIONAL 0
3727c1ae151SYishai Hadas 
3737c1ae151SYishai Hadas struct virtio_dev_part_hdr {
3747c1ae151SYishai Hadas 	__le16 part_type;
3757c1ae151SYishai Hadas 	__u8 flags;
3767c1ae151SYishai Hadas 	__u8 reserved;
3777c1ae151SYishai Hadas 	union {
3787c1ae151SYishai Hadas 		struct {
3797c1ae151SYishai Hadas 			__le32 offset;
3807c1ae151SYishai Hadas 			__le32 reserved;
3817c1ae151SYishai Hadas 		} pci_common_cfg;
3827c1ae151SYishai Hadas 		struct {
3837c1ae151SYishai Hadas 			__le16 index;
3847c1ae151SYishai Hadas 			__u8 reserved[6];
3857c1ae151SYishai Hadas 		} vq_index;
3867c1ae151SYishai Hadas 	} selector;
3877c1ae151SYishai Hadas 	__le32 length;
3887c1ae151SYishai Hadas };
3897c1ae151SYishai Hadas 
3907c1ae151SYishai Hadas struct virtio_dev_part {
3917c1ae151SYishai Hadas 	struct virtio_dev_part_hdr hdr;
3927c1ae151SYishai Hadas 	__u8 value[];
3937c1ae151SYishai Hadas };
3947c1ae151SYishai Hadas 
3957c1ae151SYishai Hadas struct virtio_admin_cmd_dev_parts_metadata_result {
3967c1ae151SYishai Hadas 	union {
3977c1ae151SYishai Hadas 		struct {
3987c1ae151SYishai Hadas 			__le32 size;
3997c1ae151SYishai Hadas 			__le32 reserved;
4007c1ae151SYishai Hadas 		} parts_size;
4017c1ae151SYishai Hadas 		struct {
4027c1ae151SYishai Hadas 			__le32 count;
4037c1ae151SYishai Hadas 			__le32 reserved;
4047c1ae151SYishai Hadas 		} hdr_list_count;
4057c1ae151SYishai Hadas 		struct {
4067c1ae151SYishai Hadas 			__le32 count;
4077c1ae151SYishai Hadas 			__le32 reserved;
4087c1ae151SYishai Hadas 			struct virtio_dev_part_hdr hdrs[];
4097c1ae151SYishai Hadas 		} hdr_list;
4107c1ae151SYishai Hadas 	};
4117c1ae151SYishai Hadas };
4127c1ae151SYishai Hadas 
4137c1ae151SYishai Hadas #define VIRTIO_ADMIN_CMD_DEV_PARTS_GET_TYPE_SELECTED 0
4147c1ae151SYishai Hadas #define VIRTIO_ADMIN_CMD_DEV_PARTS_GET_TYPE_ALL 1
4157c1ae151SYishai Hadas 
4167c1ae151SYishai Hadas struct virtio_admin_cmd_dev_parts_get_data {
4177c1ae151SYishai Hadas 	struct virtio_admin_cmd_resource_obj_cmd_hdr hdr;
4187c1ae151SYishai Hadas 	__u8 type;
4197c1ae151SYishai Hadas 	__u8 reserved[7];
4207c1ae151SYishai Hadas 	struct virtio_dev_part_hdr hdr_list[];
4217c1ae151SYishai Hadas };
4227c1ae151SYishai Hadas 
4237c1ae151SYishai Hadas struct virtio_admin_cmd_dev_parts_set_data {
4247c1ae151SYishai Hadas 	struct virtio_admin_cmd_resource_obj_cmd_hdr hdr;
4257c1ae151SYishai Hadas 	struct virtio_dev_part parts[];
4267c1ae151SYishai Hadas };
4277c1ae151SYishai Hadas 
4287c1ae151SYishai Hadas #define VIRTIO_ADMIN_CMD_DEV_MODE_F_STOPPED 0
4297c1ae151SYishai Hadas 
4307c1ae151SYishai Hadas struct virtio_admin_cmd_dev_mode_set_data {
4317c1ae151SYishai Hadas 	__u8 flags;
4327c1ae151SYishai Hadas };
4337c1ae151SYishai Hadas 
434607ca46eSDavid Howells #endif
435