1 /* 2 * capabilities.h: hypervisor capabilities 3 * 4 * Copyright (C) 2006-2019 Red Hat, Inc. 5 * Copyright (C) 2006-2008 Daniel P. Berrange 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library. If not, see 19 * <http://www.gnu.org/licenses/>. 20 */ 21 22 #pragma once 23 24 #include "internal.h" 25 #include "virconftypes.h" 26 #include "virbuffer.h" 27 #include "cpu_conf.h" 28 #include "virarch.h" 29 #include "virmacaddr.h" 30 #include "virobject.h" 31 #include "virresctrl.h" 32 33 #include <libxml/xpath.h> 34 35 typedef enum { 36 VIR_CAPS_GUEST_FEATURE_TYPE_PAE = 0, 37 VIR_CAPS_GUEST_FEATURE_TYPE_NONPAE, 38 VIR_CAPS_GUEST_FEATURE_TYPE_IA64_BE, 39 VIR_CAPS_GUEST_FEATURE_TYPE_ACPI, 40 VIR_CAPS_GUEST_FEATURE_TYPE_APIC, 41 VIR_CAPS_GUEST_FEATURE_TYPE_CPUSELECTION, 42 VIR_CAPS_GUEST_FEATURE_TYPE_DEVICEBOOT, 43 VIR_CAPS_GUEST_FEATURE_TYPE_DISKSNAPSHOT, 44 VIR_CAPS_GUEST_FEATURE_TYPE_HAP, 45 46 VIR_CAPS_GUEST_FEATURE_TYPE_LAST 47 } virCapsGuestFeatureType; 48 49 struct _virCapsGuestFeature { 50 bool present; 51 virTristateSwitch defaultOn; 52 virTristateBool toggle; 53 }; 54 55 struct _virCapsGuestMachine { 56 char *name; 57 char *canonical; 58 unsigned int maxCpus; 59 bool deprecated; 60 }; 61 62 struct _virCapsGuestDomainInfo { 63 char *emulator; 64 char *loader; 65 int nmachines; 66 virCapsGuestMachine **machines; 67 }; 68 69 struct _virCapsGuestDomain { 70 int type; /* virDomainVirtType */ 71 virCapsGuestDomainInfo info; 72 }; 73 74 struct _virCapsGuestArch { 75 virArch id; 76 unsigned int wordsize; 77 virCapsGuestDomainInfo defaultInfo; 78 size_t ndomains; 79 size_t ndomains_max; 80 virCapsGuestDomain **domains; 81 }; 82 83 struct _virCapsGuest { 84 int ostype; 85 virCapsGuestArch arch; 86 virCapsGuestFeature features[VIR_CAPS_GUEST_FEATURE_TYPE_LAST]; 87 }; 88 89 struct _virCapsHostNUMACellCPU { 90 unsigned int id; 91 unsigned int socket_id; 92 unsigned int die_id; 93 unsigned int core_id; 94 virBitmap *siblings; 95 }; 96 97 struct _virCapsHostNUMACellPageInfo { 98 unsigned int size; /* page size in kibibytes */ 99 unsigned long long avail; /* the size of pool */ 100 }; 101 102 struct _virCapsHostNUMACell { 103 int num; 104 int ncpus; 105 unsigned long long mem; /* in kibibytes */ 106 virCapsHostNUMACellCPU *cpus; 107 size_t ndistances; 108 virNumaDistance *distances; 109 int npageinfo; 110 virCapsHostNUMACellPageInfo *pageinfo; 111 GArray *caches; /* virNumaCache */ 112 }; 113 114 struct _virCapsHostNUMA { 115 gint refs; 116 GPtrArray *cells; 117 GArray *interconnects; /* virNumaInterconnect */ 118 }; 119 120 struct _virCapsHostSecModelLabel { 121 char *type; 122 char *label; 123 }; 124 125 struct _virCapsHostSecModel { 126 char *model; 127 char *doi; 128 size_t nlabels; 129 virCapsHostSecModelLabel *labels; 130 }; 131 132 struct _virCapsHostCacheBank { 133 unsigned int id; 134 unsigned int level; /* 1=L1, 2=L2, 3=L3, etc. */ 135 unsigned long long size; /* B */ 136 virCacheType type; /* Data, Instruction or Unified */ 137 virBitmap *cpus; /* All CPUs that share this bank */ 138 size_t ncontrols; 139 virResctrlInfoPerCache **controls; 140 }; 141 142 struct _virCapsHostCache { 143 size_t nbanks; 144 virCapsHostCacheBank **banks; 145 146 virResctrlInfoMon *monitor; 147 }; 148 149 struct _virCapsHostMemBWNode { 150 unsigned int id; 151 virBitmap *cpus; /* All CPUs that belong to this node */ 152 virResctrlInfoMemBWPerNode control; 153 }; 154 155 struct _virCapsHostMemBW { 156 size_t nnodes; 157 virCapsHostMemBWNode **nodes; 158 159 virResctrlInfoMon *monitor; 160 }; 161 162 struct _virCapsHost { 163 virArch arch; 164 size_t nfeatures; 165 size_t nfeatures_max; 166 char **features; 167 unsigned int powerMgmt; /* Bitmask of the PM capabilities. 168 * See enum virHostPMCapability. 169 */ 170 bool offlineMigrate; 171 bool liveMigrate; 172 size_t nmigrateTrans; 173 size_t nmigrateTrans_max; 174 char **migrateTrans; 175 176 virCapsHostNUMA *numa; 177 178 virResctrlInfo *resctrl; 179 180 virCapsHostCache cache; 181 182 virCapsHostMemBW memBW; 183 184 size_t nsecModels; 185 virCapsHostSecModel *secModels; 186 187 char *netprefix; 188 virCPUDef *cpu; 189 int nPagesSize; /* size of pagesSize array */ 190 unsigned int *pagesSize; /* page sizes support on the system */ 191 unsigned char host_uuid[VIR_UUID_BUFLEN]; 192 bool iommu; 193 }; 194 195 struct _virCapsStoragePool { 196 int type; 197 }; 198 199 200 struct _virCaps { 201 virObject parent; 202 203 virCapsHost host; 204 size_t nguests; 205 size_t nguests_max; 206 virCapsGuest **guests; 207 208 size_t npools; 209 size_t npools_max; 210 virCapsStoragePool **pools; 211 }; 212 213 G_DEFINE_AUTOPTR_CLEANUP_FUNC(virCaps, virObjectUnref); 214 215 216 struct _virCapsDomainData { 217 int ostype; 218 int arch; 219 int domaintype; /* virDomainVirtType */ 220 const char *emulator; 221 const char *machinetype; 222 }; 223 224 225 virCaps * 226 virCapabilitiesNew(virArch hostarch, 227 bool offlineMigrate, 228 bool liveMigrate); 229 230 void 231 virCapabilitiesHostNUMAUnref(virCapsHostNUMA *caps); 232 void 233 virCapabilitiesHostNUMARef(virCapsHostNUMA *caps); 234 235 G_DEFINE_AUTOPTR_CLEANUP_FUNC(virCapsHostNUMA, virCapabilitiesHostNUMAUnref); 236 237 int 238 virCapabilitiesAddHostFeature(virCaps *caps, 239 const char *name); 240 241 int 242 virCapabilitiesAddHostMigrateTransport(virCaps *caps, 243 const char *name); 244 245 int 246 virCapabilitiesSetNetPrefix(virCaps *caps, 247 const char *prefix); 248 249 void 250 virCapabilitiesHostNUMAAddCell(virCapsHostNUMA *caps, 251 int num, 252 unsigned long long mem, 253 int ncpus, 254 virCapsHostNUMACellCPU **cpus, 255 int ndistances, 256 virNumaDistance **distances, 257 int npageinfo, 258 virCapsHostNUMACellPageInfo **pageinfo, 259 GArray **caches); 260 261 virCapsGuestMachine ** 262 virCapabilitiesAllocMachines(const char *const *names, 263 int nnames); 264 void 265 virCapabilitiesFreeMachines(virCapsGuestMachine **machines, 266 int nmachines); 267 268 void 269 virCapabilitiesFreeGuest(virCapsGuest *guest); 270 271 virCapsGuest * 272 virCapabilitiesAddGuest(virCaps *caps, 273 int ostype, 274 virArch arch, 275 const char *emulator, 276 const char *loader, 277 int nmachines, 278 virCapsGuestMachine **machines); 279 280 virCapsGuestDomain * 281 virCapabilitiesAddGuestDomain(virCapsGuest *guest, 282 int hvtype, 283 const char *emulator, 284 const char *loader, 285 int nmachines, 286 virCapsGuestMachine **machines); 287 288 void 289 virCapabilitiesAddGuestFeature(virCapsGuest *guest, 290 virCapsGuestFeatureType feature); 291 void 292 virCapabilitiesAddGuestFeatureWithToggle(virCapsGuest *guest, 293 virCapsGuestFeatureType feature, 294 bool defaultOn, 295 bool toggle); 296 297 int 298 virCapabilitiesAddStoragePool(virCaps *caps, 299 int poolType); 300 301 int 302 virCapabilitiesHostSecModelAddBaseLabel(virCapsHostSecModel *secmodel, 303 const char *type, 304 const char *label); 305 306 virCapsDomainData * 307 virCapabilitiesDomainDataLookup(virCaps *caps, 308 int ostype, 309 virArch arch, 310 int domaintype, 311 const char *emulator, 312 const char *machinetype); 313 314 bool 315 virCapabilitiesDomainSupported(virCaps *caps, 316 int ostype, 317 virArch arch, 318 int domaintype); 319 320 321 void 322 virCapabilitiesClearHostNUMACellCPUTopology(virCapsHostNUMACellCPU *cpu, 323 size_t ncpus); 324 325 char * 326 virCapabilitiesFormatXML(virCaps *caps); 327 328 virBitmap *virCapabilitiesHostNUMAGetCpus(virCapsHostNUMA *caps, 329 virBitmap *nodemask); 330 331 int virCapabilitiesHostNUMAGetMaxNode(virCapsHostNUMA *caps); 332 333 int virCapabilitiesGetNodeInfo(virNodeInfoPtr nodeinfo); 334 335 int virCapabilitiesInitPages(virCaps *caps); 336 337 virCapsHostNUMA *virCapabilitiesHostNUMANew(void); 338 virCapsHostNUMA *virCapabilitiesHostNUMANewHost(void); 339 340 bool virCapsHostCacheBankEquals(virCapsHostCacheBank *a, 341 virCapsHostCacheBank *b); 342 void virCapsHostCacheBankFree(virCapsHostCacheBank *ptr); 343 344 int virCapabilitiesInitCaches(virCaps *caps); 345 346 void virCapabilitiesHostInitIOMMU(virCaps *caps); 347