1 /* 2 * device_conf.h: device XML handling entry points 3 * 4 * Copyright (C) 2006-2012, 2014-2016 Red Hat, Inc. 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2.1 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library. If not, see 18 * <http://www.gnu.org/licenses/>. 19 */ 20 21 #pragma once 22 23 #include <libxml/parser.h> 24 #include <libxml/tree.h> 25 #include <libxml/xpath.h> 26 27 #include "internal.h" 28 #include "virthread.h" 29 #include "virbuffer.h" 30 #include "virpci.h" 31 #include "virnetdev.h" 32 #include "virenum.h" 33 34 typedef enum { 35 VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE, 36 VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI, 37 VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE, 38 VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_SERIAL, 39 VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCID, 40 VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB, 41 VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO, 42 VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390, 43 VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW, 44 VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO, 45 VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA, 46 VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM, 47 VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASSIGNED, 48 49 VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST 50 } virDomainDeviceAddressType; 51 52 VIR_ENUM_DECL(virDomainDeviceAddress); 53 54 typedef struct _virDomainDeviceDriveAddress virDomainDeviceDriveAddress; 55 struct _virDomainDeviceDriveAddress { 56 unsigned int controller; 57 unsigned int bus; 58 unsigned int target; 59 unsigned int unit; 60 61 /* internal fields for the address formatter */ 62 unsigned int diskbus; /* virDomainDiskBus */ 63 }; 64 65 typedef struct _virDomainDeviceVirtioSerialAddress virDomainDeviceVirtioSerialAddress; 66 struct _virDomainDeviceVirtioSerialAddress { 67 unsigned int controller; 68 unsigned int bus; 69 unsigned int port; 70 }; 71 72 #define VIR_DOMAIN_DEVICE_CCW_MAX_CSSID 254 73 #define VIR_DOMAIN_DEVICE_CCW_MAX_SSID 3 74 #define VIR_DOMAIN_DEVICE_CCW_MAX_DEVNO 65535 75 76 typedef struct _virDomainDeviceCCWAddress virDomainDeviceCCWAddress; 77 struct _virDomainDeviceCCWAddress { 78 unsigned int cssid; 79 unsigned int ssid; 80 unsigned int devno; 81 bool assigned; 82 }; 83 84 typedef struct _virDomainDeviceCcidAddress virDomainDeviceCcidAddress; 85 struct _virDomainDeviceCcidAddress { 86 unsigned int controller; 87 unsigned int slot; 88 }; 89 90 #define VIR_DOMAIN_DEVICE_USB_MAX_PORT_DEPTH 4 91 92 typedef struct _virDomainDeviceUSBAddress virDomainDeviceUSBAddress; 93 struct _virDomainDeviceUSBAddress { 94 unsigned int bus; 95 unsigned int port[VIR_DOMAIN_DEVICE_USB_MAX_PORT_DEPTH]; 96 }; 97 98 typedef struct _virDomainDeviceSpaprVioAddress virDomainDeviceSpaprVioAddress; 99 struct _virDomainDeviceSpaprVioAddress { 100 unsigned long long reg; 101 bool has_reg; 102 }; 103 104 typedef enum { 105 VIR_DOMAIN_CONTROLLER_MASTER_NONE, 106 VIR_DOMAIN_CONTROLLER_MASTER_USB, 107 108 VIR_DOMAIN_CONTROLLER_MASTER_LAST 109 } virDomainControllerMaster; 110 111 typedef struct _virDomainDeviceUSBMaster virDomainDeviceUSBMaster; 112 struct _virDomainDeviceUSBMaster { 113 unsigned int startport; 114 }; 115 116 typedef struct _virDomainDeviceISAAddress virDomainDeviceISAAddress; 117 struct _virDomainDeviceISAAddress { 118 unsigned int iobase; 119 unsigned int irq; 120 }; 121 122 typedef struct _virDomainDeviceDimmAddress virDomainDeviceDimmAddress; 123 struct _virDomainDeviceDimmAddress { 124 unsigned int slot; 125 unsigned long long base; 126 }; 127 128 typedef struct _virDomainDeviceInfo virDomainDeviceInfo; 129 struct _virDomainDeviceInfo { 130 char *alias; 131 int type; /* virDomainDeviceAddressType */ 132 union { 133 virPCIDeviceAddress pci; 134 virDomainDeviceDriveAddress drive; 135 virDomainDeviceVirtioSerialAddress vioserial; 136 virDomainDeviceCcidAddress ccid; 137 virDomainDeviceUSBAddress usb; 138 virDomainDeviceSpaprVioAddress spaprvio; 139 virDomainDeviceCCWAddress ccw; 140 virDomainDeviceISAAddress isa; 141 virDomainDeviceDimmAddress dimm; 142 } addr; 143 int mastertype; 144 union { 145 virDomainDeviceUSBMaster usb; 146 } master; 147 /* rombar and romfile are only used for pci hostdev and network 148 * devices. */ 149 virTristateBool romenabled; 150 virTristateSwitch rombar; 151 char *romfile; 152 /* bootIndex is only used for disk, network interface, hostdev 153 * and redirdev devices */ 154 unsigned int bootIndex; 155 /* 'effectiveBootIndex' is same as 'bootIndex' (if provided in the XML) but 156 * not formatted back. This allows HV drivers to update it if <os><boot .. 157 * is present. */ 158 unsigned int effectiveBootIndex; 159 /* Valid for any PCI device. Can be used for NIC to get 160 * stable numbering in Linux */ 161 unsigned int acpiIndex; 162 163 /* pciConnectFlags is only used internally during address 164 * assignment, never saved and never reported. 165 */ 166 int pciConnectFlags; /* enum virDomainPCIConnectFlags */ 167 /* pciAddrExtFlags is only used internally to calculate PCI 168 * address extension flags during address assignment. 169 */ 170 int pciAddrExtFlags; /* enum virDomainPCIAddressExtensionFlags */ 171 char *loadparm; 172 173 /* PCI devices will only be automatically placed on a PCI bus 174 * that shares the same isolation group */ 175 unsigned int isolationGroup; 176 177 /* Usually, PCI buses will take on the same isolation group 178 * as the first device that is plugged into them, but in some 179 * cases we might want to prevent that from happening by 180 * locking the isolation group */ 181 bool isolationGroupLocked; 182 }; 183 184 void virDomainDeviceInfoClear(virDomainDeviceInfo *info); 185 void virDomainDeviceInfoFree(virDomainDeviceInfo *info); 186 187 bool virDomainDeviceInfoAddressIsEqual(const virDomainDeviceInfo *a, 188 const virDomainDeviceInfo *b) 189 ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT; 190 191 bool virDomainDeviceAddressIsValid(virDomainDeviceInfo *info, 192 int type); 193 194 bool virDeviceInfoPCIAddressIsWanted(const virDomainDeviceInfo *info); 195 bool virDeviceInfoPCIAddressIsPresent(const virDomainDeviceInfo *info); 196 197 bool virDeviceInfoPCIAddressExtensionIsWanted(const virDomainDeviceInfo *info); 198 bool virDeviceInfoPCIAddressExtensionIsPresent(const virDomainDeviceInfo *info); 199 200 int virPCIDeviceAddressParseXML(xmlNodePtr node, 201 virPCIDeviceAddress *addr); 202 203 void virPCIDeviceAddressFormat(virBuffer *buf, 204 virPCIDeviceAddress addr, 205 bool includeTypeInAddr); 206 207 bool virDomainDeviceCCWAddressIsValid(virDomainDeviceCCWAddress *addr); 208 int virDomainDeviceCCWAddressParseXML(xmlNodePtr node, 209 virDomainDeviceCCWAddress *addr); 210 bool virDomainDeviceCCWAddressEqual(virDomainDeviceCCWAddress *addr1, 211 virDomainDeviceCCWAddress *addr2); 212 #define VIR_CCW_DEVICE_ADDRESS_FMT "%x.%x.%04x" 213 214 int virDomainDeviceDriveAddressParseXML(xmlNodePtr node, 215 virDomainDeviceDriveAddress *addr); 216 217 int virDomainDeviceVirtioSerialAddressParseXML(xmlNodePtr node, 218 virDomainDeviceVirtioSerialAddress *addr); 219 220 int virDomainDeviceCcidAddressParseXML(xmlNodePtr node, 221 virDomainDeviceCcidAddress *addr); 222 223 int virDomainDeviceUSBAddressParseXML(xmlNodePtr node, 224 virDomainDeviceUSBAddress *addr); 225 226 int virDomainDeviceSpaprVioAddressParseXML(xmlNodePtr node, 227 virDomainDeviceSpaprVioAddress *addr); 228 229 int virInterfaceLinkParseXML(xmlNodePtr node, 230 virNetDevIfLink *lnk); 231 232 int virInterfaceLinkFormat(virBuffer *buf, 233 const virNetDevIfLink *lnk); 234