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" 4344fe383cSHendrik 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 119*421ee1ecSDaniel Henrique Barboza /* PCI vendor data configuration */ 120*421ee1ecSDaniel Henrique Barboza #define VIRTIO_PCI_CAP_VENDOR_CFG 9 1219fbe302bSMichael S. Tsirkin 1229fbe302bSMichael S. Tsirkin /* This is the PCI capability header: */ 1239fbe302bSMichael S. Tsirkin struct virtio_pci_cap { 1249fbe302bSMichael S. Tsirkin uint8_t cap_vndr; /* Generic PCI field: PCI_CAP_ID_VNDR */ 1259fbe302bSMichael S. Tsirkin uint8_t cap_next; /* Generic PCI field: next ptr. */ 1269fbe302bSMichael S. Tsirkin uint8_t cap_len; /* Generic PCI field: capability length */ 1279fbe302bSMichael S. Tsirkin uint8_t cfg_type; /* Identifies the structure. */ 1289fbe302bSMichael S. Tsirkin uint8_t bar; /* Where to find it. */ 12953ba2eeeSMatthew Rosato uint8_t id; /* Multiple capabilities of the same type */ 13053ba2eeeSMatthew Rosato uint8_t padding[2]; /* Pad to full dword. */ 1319fbe302bSMichael S. Tsirkin uint32_t offset; /* Offset within bar. */ 1329fbe302bSMichael S. Tsirkin uint32_t length; /* Length of the structure, in bytes. */ 1339fbe302bSMichael S. Tsirkin }; 1349fbe302bSMichael S. Tsirkin 135*421ee1ecSDaniel Henrique Barboza /* This is the PCI vendor data capability header: */ 136*421ee1ecSDaniel Henrique Barboza struct virtio_pci_vndr_data { 137*421ee1ecSDaniel Henrique Barboza uint8_t cap_vndr; /* Generic PCI field: PCI_CAP_ID_VNDR */ 138*421ee1ecSDaniel Henrique Barboza uint8_t cap_next; /* Generic PCI field: next ptr. */ 139*421ee1ecSDaniel Henrique Barboza uint8_t cap_len; /* Generic PCI field: capability length */ 140*421ee1ecSDaniel Henrique Barboza uint8_t cfg_type; /* Identifies the structure. */ 141*421ee1ecSDaniel Henrique Barboza uint16_t vendor_id; /* Identifies the vendor-specific format. */ 142*421ee1ecSDaniel Henrique Barboza /* For Vendor Definition */ 143*421ee1ecSDaniel Henrique Barboza /* Pads structure to a multiple of 4 bytes */ 144*421ee1ecSDaniel Henrique Barboza /* Reads must not have side effects */ 145*421ee1ecSDaniel Henrique Barboza }; 146*421ee1ecSDaniel Henrique Barboza 14753ba2eeeSMatthew Rosato struct virtio_pci_cap64 { 14853ba2eeeSMatthew Rosato struct virtio_pci_cap cap; 14953ba2eeeSMatthew Rosato uint32_t offset_hi; /* Most sig 32 bits of offset */ 15053ba2eeeSMatthew Rosato uint32_t length_hi; /* Most sig 32 bits of length */ 15153ba2eeeSMatthew Rosato }; 15253ba2eeeSMatthew Rosato 1539fbe302bSMichael S. Tsirkin struct virtio_pci_notify_cap { 1549fbe302bSMichael S. Tsirkin struct virtio_pci_cap cap; 1559fbe302bSMichael S. Tsirkin uint32_t notify_off_multiplier; /* Multiplier for queue_notify_off. */ 1569fbe302bSMichael S. Tsirkin }; 1579fbe302bSMichael S. Tsirkin 1589fbe302bSMichael S. Tsirkin /* Fields in VIRTIO_PCI_CAP_COMMON_CFG: */ 1599fbe302bSMichael S. Tsirkin struct virtio_pci_common_cfg { 1609fbe302bSMichael S. Tsirkin /* About the whole device. */ 1619fbe302bSMichael S. Tsirkin uint32_t device_feature_select; /* read-write */ 1629fbe302bSMichael S. Tsirkin uint32_t device_feature; /* read-only */ 1639fbe302bSMichael S. Tsirkin uint32_t guest_feature_select; /* read-write */ 1649fbe302bSMichael S. Tsirkin uint32_t guest_feature; /* read-write */ 1659fbe302bSMichael S. Tsirkin uint16_t msix_config; /* read-write */ 1669fbe302bSMichael S. Tsirkin uint16_t num_queues; /* read-only */ 1679fbe302bSMichael S. Tsirkin uint8_t device_status; /* read-write */ 1689fbe302bSMichael S. Tsirkin uint8_t config_generation; /* read-only */ 1699fbe302bSMichael S. Tsirkin 1709fbe302bSMichael S. Tsirkin /* About a specific virtqueue. */ 1719fbe302bSMichael S. Tsirkin uint16_t queue_select; /* read-write */ 1729fbe302bSMichael S. Tsirkin uint16_t queue_size; /* read-write, power of 2. */ 1739fbe302bSMichael S. Tsirkin uint16_t queue_msix_vector; /* read-write */ 1749fbe302bSMichael S. Tsirkin uint16_t queue_enable; /* read-write */ 1759fbe302bSMichael S. Tsirkin uint16_t queue_notify_off; /* read-only */ 1769fbe302bSMichael S. Tsirkin uint32_t queue_desc_lo; /* read-write */ 1779fbe302bSMichael S. Tsirkin uint32_t queue_desc_hi; /* read-write */ 1789fbe302bSMichael S. Tsirkin uint32_t queue_avail_lo; /* read-write */ 1799fbe302bSMichael S. Tsirkin uint32_t queue_avail_hi; /* read-write */ 1809fbe302bSMichael S. Tsirkin uint32_t queue_used_lo; /* read-write */ 1819fbe302bSMichael S. Tsirkin uint32_t queue_used_hi; /* read-write */ 1829fbe302bSMichael S. Tsirkin }; 1839fbe302bSMichael S. Tsirkin 184efb91426SDaniel Henrique Barboza /* 185efb91426SDaniel Henrique Barboza * Warning: do not use sizeof on this: use offsetofend for 186efb91426SDaniel Henrique Barboza * specific fields you need. 187efb91426SDaniel Henrique Barboza */ 188efb91426SDaniel Henrique Barboza struct virtio_pci_modern_common_cfg { 189efb91426SDaniel Henrique Barboza struct virtio_pci_common_cfg cfg; 190efb91426SDaniel Henrique Barboza 191efb91426SDaniel Henrique Barboza uint16_t queue_notify_data; /* read-write */ 192efb91426SDaniel Henrique Barboza uint16_t queue_reset; /* read-write */ 1936a02465fSDaniel Henrique Barboza 1946a02465fSDaniel Henrique Barboza uint16_t admin_queue_index; /* read-only */ 1956a02465fSDaniel Henrique Barboza uint16_t admin_queue_num; /* read-only */ 196efb91426SDaniel Henrique Barboza }; 197efb91426SDaniel Henrique Barboza 198c36f24a2SMichael S. Tsirkin /* Fields in VIRTIO_PCI_CAP_PCI_CFG: */ 199c36f24a2SMichael S. Tsirkin struct virtio_pci_cfg_cap { 200c36f24a2SMichael S. Tsirkin struct virtio_pci_cap cap; 201c36f24a2SMichael S. Tsirkin uint8_t pci_cfg_data[4]; /* Data for BAR access. */ 202c36f24a2SMichael S. Tsirkin }; 203c36f24a2SMichael S. Tsirkin 2049fbe302bSMichael S. Tsirkin /* Macro versions of offsets for the Old Timers! */ 2059fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_CAP_VNDR 0 2069fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_CAP_NEXT 1 2079fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_CAP_LEN 2 2089fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_CAP_CFG_TYPE 3 2099fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_CAP_BAR 4 2109fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_CAP_OFFSET 8 2119fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_CAP_LENGTH 12 2129fbe302bSMichael S. Tsirkin 2139fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_NOTIFY_CAP_MULT 16 2149fbe302bSMichael S. Tsirkin 2159fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_DFSELECT 0 2169fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_DF 4 2179fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_GFSELECT 8 2189fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_GF 12 2199fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_MSIX 16 2209fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_NUMQ 18 2219fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_STATUS 20 2229fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_CFGGENERATION 21 2239fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_Q_SELECT 22 2249fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_Q_SIZE 24 2259fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_Q_MSIX 26 2269fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_Q_ENABLE 28 2279fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_Q_NOFF 30 2289fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_Q_DESCLO 32 2299fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_Q_DESCHI 36 2309fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_Q_AVAILLO 40 2319fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_Q_AVAILHI 44 2329fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_Q_USEDLO 48 2339fbe302bSMichael S. Tsirkin #define VIRTIO_PCI_COMMON_Q_USEDHI 52 234d525f73fSChenyi Qiang #define VIRTIO_PCI_COMMON_Q_NDATA 56 235d525f73fSChenyi Qiang #define VIRTIO_PCI_COMMON_Q_RESET 58 2366a02465fSDaniel Henrique Barboza #define VIRTIO_PCI_COMMON_ADM_Q_IDX 60 2376a02465fSDaniel Henrique Barboza #define VIRTIO_PCI_COMMON_ADM_Q_NUM 62 2389fbe302bSMichael S. Tsirkin 2399fbe302bSMichael S. Tsirkin #endif /* VIRTIO_PCI_NO_MODERN */ 2409fbe302bSMichael S. Tsirkin 2416a02465fSDaniel Henrique Barboza /* Admin command status. */ 2426a02465fSDaniel Henrique Barboza #define VIRTIO_ADMIN_STATUS_OK 0 2436a02465fSDaniel Henrique Barboza 2446a02465fSDaniel Henrique Barboza /* Admin command opcode. */ 2456a02465fSDaniel Henrique Barboza #define VIRTIO_ADMIN_CMD_LIST_QUERY 0x0 2466a02465fSDaniel Henrique Barboza #define VIRTIO_ADMIN_CMD_LIST_USE 0x1 2476a02465fSDaniel Henrique Barboza 2486a02465fSDaniel Henrique Barboza /* Admin command group type. */ 2496a02465fSDaniel Henrique Barboza #define VIRTIO_ADMIN_GROUP_TYPE_SRIOV 0x1 2506a02465fSDaniel Henrique Barboza 2516a02465fSDaniel Henrique Barboza /* Transitional device admin command. */ 2526a02465fSDaniel Henrique Barboza #define VIRTIO_ADMIN_CMD_LEGACY_COMMON_CFG_WRITE 0x2 2536a02465fSDaniel Henrique Barboza #define VIRTIO_ADMIN_CMD_LEGACY_COMMON_CFG_READ 0x3 2546a02465fSDaniel Henrique Barboza #define VIRTIO_ADMIN_CMD_LEGACY_DEV_CFG_WRITE 0x4 2556a02465fSDaniel Henrique Barboza #define VIRTIO_ADMIN_CMD_LEGACY_DEV_CFG_READ 0x5 2566a02465fSDaniel Henrique Barboza #define VIRTIO_ADMIN_CMD_LEGACY_NOTIFY_INFO 0x6 2576a02465fSDaniel Henrique Barboza 25844fe383cSHendrik Brueckner /* Device parts access commands. */ 25944fe383cSHendrik Brueckner #define VIRTIO_ADMIN_CMD_CAP_ID_LIST_QUERY 0x7 26044fe383cSHendrik Brueckner #define VIRTIO_ADMIN_CMD_DEVICE_CAP_GET 0x8 26144fe383cSHendrik Brueckner #define VIRTIO_ADMIN_CMD_DRIVER_CAP_SET 0x9 26244fe383cSHendrik Brueckner #define VIRTIO_ADMIN_CMD_RESOURCE_OBJ_CREATE 0xa 26344fe383cSHendrik Brueckner #define VIRTIO_ADMIN_CMD_RESOURCE_OBJ_DESTROY 0xd 26444fe383cSHendrik Brueckner #define VIRTIO_ADMIN_CMD_DEV_PARTS_METADATA_GET 0xe 26544fe383cSHendrik Brueckner #define VIRTIO_ADMIN_CMD_DEV_PARTS_GET 0xf 26644fe383cSHendrik Brueckner #define VIRTIO_ADMIN_CMD_DEV_PARTS_SET 0x10 26744fe383cSHendrik Brueckner #define VIRTIO_ADMIN_CMD_DEV_MODE_SET 0x11 26844fe383cSHendrik Brueckner 269ab0c7fb2SPaolo Bonzini struct virtio_admin_cmd_hdr { 2706a02465fSDaniel Henrique Barboza uint16_t opcode; 2716a02465fSDaniel Henrique Barboza /* 2726a02465fSDaniel Henrique Barboza * 1 - SR-IOV 2736a02465fSDaniel Henrique Barboza * 2-65535 - reserved 2746a02465fSDaniel Henrique Barboza */ 2756a02465fSDaniel Henrique Barboza uint16_t group_type; 2766a02465fSDaniel Henrique Barboza /* Unused, reserved for future extensions. */ 2776a02465fSDaniel Henrique Barboza uint8_t reserved1[12]; 2786a02465fSDaniel Henrique Barboza uint64_t group_member_id; 2796a02465fSDaniel Henrique Barboza }; 2806a02465fSDaniel Henrique Barboza 281ab0c7fb2SPaolo Bonzini struct virtio_admin_cmd_status { 2826a02465fSDaniel Henrique Barboza uint16_t status; 2836a02465fSDaniel Henrique Barboza uint16_t status_qualifier; 2846a02465fSDaniel Henrique Barboza /* Unused, reserved for future extensions. */ 2856a02465fSDaniel Henrique Barboza uint8_t reserved2[4]; 2866a02465fSDaniel Henrique Barboza }; 2876a02465fSDaniel Henrique Barboza 288ab0c7fb2SPaolo Bonzini struct virtio_admin_cmd_legacy_wr_data { 2896a02465fSDaniel Henrique Barboza uint8_t offset; /* Starting offset of the register(s) to write. */ 2906a02465fSDaniel Henrique Barboza uint8_t reserved[7]; 2916a02465fSDaniel Henrique Barboza uint8_t registers[]; 2926a02465fSDaniel Henrique Barboza }; 2936a02465fSDaniel Henrique Barboza 294ab0c7fb2SPaolo Bonzini struct virtio_admin_cmd_legacy_rd_data { 2956a02465fSDaniel Henrique Barboza uint8_t offset; /* Starting offset of the register(s) to read. */ 2966a02465fSDaniel Henrique Barboza }; 2976a02465fSDaniel Henrique Barboza 2986a02465fSDaniel Henrique Barboza #define VIRTIO_ADMIN_CMD_NOTIFY_INFO_FLAGS_END 0 2996a02465fSDaniel Henrique Barboza #define VIRTIO_ADMIN_CMD_NOTIFY_INFO_FLAGS_OWNER_DEV 0x1 3006a02465fSDaniel Henrique Barboza #define VIRTIO_ADMIN_CMD_NOTIFY_INFO_FLAGS_OWNER_MEM 0x2 3016a02465fSDaniel Henrique Barboza 3026a02465fSDaniel Henrique Barboza #define VIRTIO_ADMIN_CMD_MAX_NOTIFY_INFO 4 3036a02465fSDaniel Henrique Barboza 304ab0c7fb2SPaolo Bonzini struct virtio_admin_cmd_notify_info_data { 3056a02465fSDaniel Henrique Barboza uint8_t flags; /* 0 = end of list, 1 = owner device, 2 = member device */ 3066a02465fSDaniel Henrique Barboza uint8_t bar; /* BAR of the member or the owner device */ 3076a02465fSDaniel Henrique Barboza uint8_t padding[6]; 3086a02465fSDaniel Henrique Barboza uint64_t offset; /* Offset within bar. */ 3096a02465fSDaniel Henrique Barboza }; 3106a02465fSDaniel Henrique Barboza 3116a02465fSDaniel Henrique Barboza struct virtio_admin_cmd_notify_info_result { 3126a02465fSDaniel Henrique Barboza struct virtio_admin_cmd_notify_info_data entries[VIRTIO_ADMIN_CMD_MAX_NOTIFY_INFO]; 3136a02465fSDaniel Henrique Barboza }; 3146a02465fSDaniel Henrique Barboza 31544fe383cSHendrik Brueckner #define VIRTIO_DEV_PARTS_CAP 0x0000 31644fe383cSHendrik Brueckner 31744fe383cSHendrik Brueckner struct virtio_dev_parts_cap { 31844fe383cSHendrik Brueckner uint8_t get_parts_resource_objects_limit; 31944fe383cSHendrik Brueckner uint8_t set_parts_resource_objects_limit; 32044fe383cSHendrik Brueckner }; 32144fe383cSHendrik Brueckner 32244fe383cSHendrik Brueckner #define MAX_CAP_ID __KERNEL_DIV_ROUND_UP(VIRTIO_DEV_PARTS_CAP + 1, 64) 32344fe383cSHendrik Brueckner 32444fe383cSHendrik Brueckner struct virtio_admin_cmd_query_cap_id_result { 32544fe383cSHendrik Brueckner uint64_t supported_caps[MAX_CAP_ID]; 32644fe383cSHendrik Brueckner }; 32744fe383cSHendrik Brueckner 32844fe383cSHendrik Brueckner struct virtio_admin_cmd_cap_get_data { 32944fe383cSHendrik Brueckner uint16_t id; 33044fe383cSHendrik Brueckner uint8_t reserved[6]; 33144fe383cSHendrik Brueckner }; 33244fe383cSHendrik Brueckner 33344fe383cSHendrik Brueckner struct virtio_admin_cmd_cap_set_data { 33444fe383cSHendrik Brueckner uint16_t id; 33544fe383cSHendrik Brueckner uint8_t reserved[6]; 33644fe383cSHendrik Brueckner uint8_t cap_specific_data[]; 33744fe383cSHendrik Brueckner }; 33844fe383cSHendrik Brueckner 33944fe383cSHendrik Brueckner struct virtio_admin_cmd_resource_obj_cmd_hdr { 34044fe383cSHendrik Brueckner uint16_t type; 34144fe383cSHendrik Brueckner uint8_t reserved[2]; 34244fe383cSHendrik Brueckner uint32_t id; /* Indicates unique resource object id per resource object type */ 34344fe383cSHendrik Brueckner }; 34444fe383cSHendrik Brueckner 34544fe383cSHendrik Brueckner struct virtio_admin_cmd_resource_obj_create_data { 34644fe383cSHendrik Brueckner struct virtio_admin_cmd_resource_obj_cmd_hdr hdr; 34744fe383cSHendrik Brueckner uint64_t flags; 34844fe383cSHendrik Brueckner uint8_t resource_obj_specific_data[]; 34944fe383cSHendrik Brueckner }; 35044fe383cSHendrik Brueckner 35144fe383cSHendrik Brueckner #define VIRTIO_RESOURCE_OBJ_DEV_PARTS 0 35244fe383cSHendrik Brueckner 35344fe383cSHendrik Brueckner #define VIRTIO_RESOURCE_OBJ_DEV_PARTS_TYPE_GET 0 35444fe383cSHendrik Brueckner #define VIRTIO_RESOURCE_OBJ_DEV_PARTS_TYPE_SET 1 35544fe383cSHendrik Brueckner 35644fe383cSHendrik Brueckner struct virtio_resource_obj_dev_parts { 35744fe383cSHendrik Brueckner uint8_t type; 35844fe383cSHendrik Brueckner uint8_t reserved[7]; 35944fe383cSHendrik Brueckner }; 36044fe383cSHendrik Brueckner 36144fe383cSHendrik Brueckner #define VIRTIO_ADMIN_CMD_DEV_PARTS_METADATA_TYPE_SIZE 0 36244fe383cSHendrik Brueckner #define VIRTIO_ADMIN_CMD_DEV_PARTS_METADATA_TYPE_COUNT 1 36344fe383cSHendrik Brueckner #define VIRTIO_ADMIN_CMD_DEV_PARTS_METADATA_TYPE_LIST 2 36444fe383cSHendrik Brueckner 36544fe383cSHendrik Brueckner struct virtio_admin_cmd_dev_parts_metadata_data { 36644fe383cSHendrik Brueckner struct virtio_admin_cmd_resource_obj_cmd_hdr hdr; 36744fe383cSHendrik Brueckner uint8_t type; 36844fe383cSHendrik Brueckner uint8_t reserved[7]; 36944fe383cSHendrik Brueckner }; 37044fe383cSHendrik Brueckner 37144fe383cSHendrik Brueckner #define VIRTIO_DEV_PART_F_OPTIONAL 0 37244fe383cSHendrik Brueckner 37344fe383cSHendrik Brueckner struct virtio_dev_part_hdr { 37444fe383cSHendrik Brueckner uint16_t part_type; 37544fe383cSHendrik Brueckner uint8_t flags; 37644fe383cSHendrik Brueckner uint8_t reserved; 37744fe383cSHendrik Brueckner union { 37844fe383cSHendrik Brueckner struct { 37944fe383cSHendrik Brueckner uint32_t offset; 38044fe383cSHendrik Brueckner uint32_t reserved; 38144fe383cSHendrik Brueckner } pci_common_cfg; 38244fe383cSHendrik Brueckner struct { 38344fe383cSHendrik Brueckner uint16_t index; 38444fe383cSHendrik Brueckner uint8_t reserved[6]; 38544fe383cSHendrik Brueckner } vq_index; 38644fe383cSHendrik Brueckner } selector; 38744fe383cSHendrik Brueckner uint32_t length; 38844fe383cSHendrik Brueckner }; 38944fe383cSHendrik Brueckner 39044fe383cSHendrik Brueckner struct virtio_dev_part { 39144fe383cSHendrik Brueckner struct virtio_dev_part_hdr hdr; 39244fe383cSHendrik Brueckner uint8_t value[]; 39344fe383cSHendrik Brueckner }; 39444fe383cSHendrik Brueckner 39544fe383cSHendrik Brueckner struct virtio_admin_cmd_dev_parts_metadata_result { 39644fe383cSHendrik Brueckner union { 39744fe383cSHendrik Brueckner struct { 39844fe383cSHendrik Brueckner uint32_t size; 39944fe383cSHendrik Brueckner uint32_t reserved; 40044fe383cSHendrik Brueckner } parts_size; 40144fe383cSHendrik Brueckner struct { 40244fe383cSHendrik Brueckner uint32_t count; 40344fe383cSHendrik Brueckner uint32_t reserved; 40444fe383cSHendrik Brueckner } hdr_list_count; 40544fe383cSHendrik Brueckner struct { 40644fe383cSHendrik Brueckner uint32_t count; 40744fe383cSHendrik Brueckner uint32_t reserved; 40844fe383cSHendrik Brueckner struct virtio_dev_part_hdr hdrs[]; 40944fe383cSHendrik Brueckner } hdr_list; 41044fe383cSHendrik Brueckner }; 41144fe383cSHendrik Brueckner }; 41244fe383cSHendrik Brueckner 41344fe383cSHendrik Brueckner #define VIRTIO_ADMIN_CMD_DEV_PARTS_GET_TYPE_SELECTED 0 41444fe383cSHendrik Brueckner #define VIRTIO_ADMIN_CMD_DEV_PARTS_GET_TYPE_ALL 1 41544fe383cSHendrik Brueckner 41644fe383cSHendrik Brueckner struct virtio_admin_cmd_dev_parts_get_data { 41744fe383cSHendrik Brueckner struct virtio_admin_cmd_resource_obj_cmd_hdr hdr; 41844fe383cSHendrik Brueckner uint8_t type; 41944fe383cSHendrik Brueckner uint8_t reserved[7]; 42044fe383cSHendrik Brueckner struct virtio_dev_part_hdr hdr_list[]; 42144fe383cSHendrik Brueckner }; 42244fe383cSHendrik Brueckner 42344fe383cSHendrik Brueckner struct virtio_admin_cmd_dev_parts_set_data { 42444fe383cSHendrik Brueckner struct virtio_admin_cmd_resource_obj_cmd_hdr hdr; 42544fe383cSHendrik Brueckner struct virtio_dev_part parts[]; 42644fe383cSHendrik Brueckner }; 42744fe383cSHendrik Brueckner 42844fe383cSHendrik Brueckner #define VIRTIO_ADMIN_CMD_DEV_MODE_F_STOPPED 0 42944fe383cSHendrik Brueckner 43044fe383cSHendrik Brueckner struct virtio_admin_cmd_dev_mode_set_data { 43144fe383cSHendrik Brueckner uint8_t flags; 43244fe383cSHendrik Brueckner }; 43344fe383cSHendrik Brueckner 4349fbe302bSMichael S. Tsirkin #endif 435