4 * Copyright Red Hat, Inc. 2016
7 * Alex Williamson <alex.williamson@redhat.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
13 #include "qemu/osdep.h"
14 #include "qemu/units.h"
15 #include "qemu/error-report.h"
16 #include "qapi/error.h"
18 #include "hw/nvram/fw_cfg.h"
25 * Obviously IGD is not a discrete device, this is evidenced not only by it
26 * being integrated into the CPU, but by the various chipset and BIOS
27 * dependencies that it brings along with it. Intel is trying to move away
28 * from this and Broadwell and newer devices can run in what Intel calls
29 * "Universal Pass-Through" mode, or UPT. Theoretically in UPT mode, nothing
30 * more is required beyond assigning the IGD device to a VM. There are
31 * however support limitations to this mode. It only supports IGD as a
32 * secondary graphics device in the VM and it doesn't officially support any
35 * The code here attempts to enable what we'll call legacy mode assignment,
36 * IGD retains most of the capabilities we expect for it to have on bare
37 * metal. To enable this mode, the IGD device must be assigned to the VM
38 * at PCI address 00:02.0, it must have a ROM, it very likely needs VGA
39 * support, we must have VM BIOS support for reserving and populating some
40 * of the required tables, and we need to tweak the chipset with revisions
41 * and IDs and an LPC/ISA bridge device. The intention is to make all of
42 * this happen automatically by installing the device at the correct VM PCI
43 * bus address. If any of the conditions are not met, we cross our fingers
44 * and hope the user knows better.
46 * NB - It is possible to enable physical outputs in UPT mode by supplying
47 * an OpRegion table. We don't do this by default because the guest driver
48 * behaves differently if an OpRegion is provided and no monitor is attached
49 * vs no OpRegion and a monitor being attached or not. Effectively, if a
50 * headless setup is desired, the OpRegion gets in the way of that.
54 * This presumes the device is already known to be an Intel VGA device, so we
55 * take liberties in which device ID bits match which generation. This should
56 * not be taken as an indication that all the devices are supported, or even
57 * supportable, some of them don't even support VT-d.
58 * See linux:include/drm/i915_pciids.h for IDs.
60 static int igd_gen(VFIOPCIDevice
*vdev
)
62 if ((vdev
->device_id
& 0xfff) == 0xa84) {
63 return 8; /* Broxton */
66 switch (vdev
->device_id
& 0xff00) {
67 /* Old, untested, unavailable, unknown */
77 /* SandyBridge, IvyBridge, ValleyView, Haswell */
85 /* BroadWell, CherryView, SkyLake, KabyLake */
100 * Unfortunately, Intel changes it's specification quite often. This makes
101 * it impossible to use a suitable default value for unknown devices.
106 typedef struct VFIOIGDQuirk
{
107 struct VFIOPCIDevice
*vdev
;
112 #define IGD_GMCH 0x50 /* Graphics Control Register */
113 #define IGD_BDSM 0x5c /* Base Data of Stolen Memory */
114 #define IGD_BDSM_GEN11 0xc0 /* Base Data of Stolen Memory of gen 11 and later */
118 * The rather short list of registers that we copy from the host devices.
119 * The LPC/ISA bridge values are definitely needed to support the vBIOS, the
120 * host bridge values may or may not be needed depending on the guest OS.
121 * Since we're only munging revision and subsystem values on the host bridge,
122 * we don't require our own device. The LPC/ISA bridge needs to be our very
130 static const IGDHostInfo igd_host_bridge_infos
[] = {
131 {PCI_REVISION_ID
, 2},
132 {PCI_SUBSYSTEM_VENDOR_ID
, 2},
133 {PCI_SUBSYSTEM_ID
, 2},
136 static const IGDHostInfo igd_lpc_bridge_infos
[] = {
139 {PCI_REVISION_ID
, 2},
140 {PCI_SUBSYSTEM_VENDOR_ID
, 2},
141 {PCI_SUBSYSTEM_ID
, 2},
144 static int vfio_pci_igd_copy(VFIOPCIDevice
*vdev
, PCIDevice
*pdev
,
145 struct vfio_region_info
*info
,
146 const IGDHostInfo
*list
, int len
)
150 for (i
= 0; i
< len
; i
++) {
151 ret
= pread(vdev
->vbasedev
.fd
, pdev
->config
+ list
[i
].offset
,
152 list
[i
].len
, info
->offset
+ list
[i
].offset
);
153 if (ret
!= list
[i
].len
) {
154 error_report("IGD copy failed: %m");
163 * Stuff a few values into the host bridge.
165 static int vfio_pci_igd_host_init(VFIOPCIDevice
*vdev
,
166 struct vfio_region_info
*info
)
169 PCIDevice
*host_bridge
;
172 bus
= pci_device_root_bus(&vdev
->pdev
);
173 host_bridge
= pci_find_device(bus
, 0, PCI_DEVFN(0, 0));
176 error_report("Can't find host bridge");
180 ret
= vfio_pci_igd_copy(vdev
, host_bridge
, info
, igd_host_bridge_infos
,
181 ARRAY_SIZE(igd_host_bridge_infos
));
183 trace_vfio_pci_igd_host_bridge_enabled(vdev
->vbasedev
.name
);
190 * IGD LPC/ISA bridge support code. The vBIOS needs this, but we can't write
191 * arbitrary values into just any bridge, so we must create our own. We try
192 * to handle if the user has created it for us, which they might want to do
193 * to enable multifunction so we don't occupy the whole PCI slot.
195 static void vfio_pci_igd_lpc_bridge_realize(PCIDevice
*pdev
, Error
**errp
)
197 if (pdev
->devfn
!= PCI_DEVFN(0x1f, 0)) {
198 error_setg(errp
, "VFIO dummy ISA/LPC bridge must have address 1f.0");
202 static void vfio_pci_igd_lpc_bridge_class_init(ObjectClass
*klass
, void *data
)
204 DeviceClass
*dc
= DEVICE_CLASS(klass
);
205 PCIDeviceClass
*k
= PCI_DEVICE_CLASS(klass
);
207 set_bit(DEVICE_CATEGORY_BRIDGE
, dc
->categories
);
208 dc
->desc
= "VFIO dummy ISA/LPC bridge for IGD assignment";
209 dc
->hotpluggable
= false;
210 k
->realize
= vfio_pci_igd_lpc_bridge_realize
;
211 k
->class_id
= PCI_CLASS_BRIDGE_ISA
;
214 static const TypeInfo vfio_pci_igd_lpc_bridge_info
= {
215 .name
= "vfio-pci-igd-lpc-bridge",
216 .parent
= TYPE_PCI_DEVICE
,
217 .class_init
= vfio_pci_igd_lpc_bridge_class_init
,
218 .interfaces
= (InterfaceInfo
[]) {
219 { INTERFACE_CONVENTIONAL_PCI_DEVICE
},
224 static void vfio_pci_igd_register_types(void)
226 type_register_static(&vfio_pci_igd_lpc_bridge_info
);
229 type_init(vfio_pci_igd_register_types
)
231 static int vfio_pci_igd_lpc_init(VFIOPCIDevice
*vdev
,
232 struct vfio_region_info
*info
)
234 PCIDevice
*lpc_bridge
;
237 lpc_bridge
= pci_find_device(pci_device_root_bus(&vdev
->pdev
),
238 0, PCI_DEVFN(0x1f, 0));
240 lpc_bridge
= pci_create_simple(pci_device_root_bus(&vdev
->pdev
),
241 PCI_DEVFN(0x1f, 0), "vfio-pci-igd-lpc-bridge");
244 ret
= vfio_pci_igd_copy(vdev
, lpc_bridge
, info
, igd_lpc_bridge_infos
,
245 ARRAY_SIZE(igd_lpc_bridge_infos
));
247 trace_vfio_pci_igd_lpc_bridge_enabled(vdev
->vbasedev
.name
);
254 * IGD Gen8 and newer support up to 8MB for the GTT and use a 64bit PTE
255 * entry, older IGDs use 2MB and 32bit. Each PTE maps a 4k page. Therefore
256 * we either have 2M/4k * 4 = 2k or 8M/4k * 8 = 16k as the maximum iobar index
257 * for programming the GTT.
259 * See linux:include/drm/i915_drm.h for shift and mask values.
261 static int vfio_igd_gtt_max(VFIOPCIDevice
*vdev
)
263 uint32_t gmch
= vfio_pci_read_config(&vdev
->pdev
, IGD_GMCH
, sizeof(gmch
));
264 int ggms
, gen
= igd_gen(vdev
);
266 gmch
= vfio_pci_read_config(&vdev
->pdev
, IGD_GMCH
, sizeof(gmch
));
267 ggms
= (gmch
>> (gen
< 8 ? 8 : 6)) & 0x3;
274 return (ggms
/ (4 * KiB
)) * (gen
< 8 ? 4 : 8);
278 * The IGD ROM will make use of stolen memory (GGMS) for support of VESA modes.
279 * Somehow the host stolen memory range is used for this, but how the ROM gets
280 * it is a mystery, perhaps it's hardcoded into the ROM. Thankfully though, it
281 * reprograms the GTT through the IOBAR where we can trap it and transpose the
282 * programming to the VM allocated buffer. That buffer gets reserved by the VM
283 * firmware via the fw_cfg entry added below. Here we're just monitoring the
284 * IOBAR address and data registers to detect a write sequence targeting the
285 * GTTADR. This code is developed by observed behavior and doesn't have a
286 * direct spec reference, unfortunately.
288 static uint64_t vfio_igd_quirk_data_read(void *opaque
,
289 hwaddr addr
, unsigned size
)
291 VFIOIGDQuirk
*igd
= opaque
;
292 VFIOPCIDevice
*vdev
= igd
->vdev
;
296 return vfio_region_read(&vdev
->bars
[4].region
, addr
+ 4, size
);
299 static void vfio_igd_quirk_data_write(void *opaque
, hwaddr addr
,
300 uint64_t data
, unsigned size
)
302 VFIOIGDQuirk
*igd
= opaque
;
303 VFIOPCIDevice
*vdev
= igd
->vdev
;
305 int gen
= igd_gen(vdev
);
308 * Programming the GGMS starts at index 0x1 and uses every 4th index (ie.
309 * 0x1, 0x5, 0x9, 0xd,...). For pre-Gen8 each 4-byte write is a whole PTE
310 * entry, with 0th bit enable set. For Gen8 and up, PTEs are 64bit, so
311 * entries 0x5 & 0xd are the high dword, in our case zero. Each PTE points
312 * to a 4k page, which we translate to a page from the VM allocated region,
313 * pointed to by the BDSM register. If this is not set, we fail.
315 * We trap writes to the full configured GTT size, but we typically only
316 * see the vBIOS writing up to (nearly) the 1MB barrier. In fact it often
317 * seems to miss the last entry for an even 1MB GTT. Doing a gratuitous
318 * write of that last entry does work, but is hopefully unnecessary since
319 * we clear the previous GTT on initialization.
321 if ((igd
->index
% 4 == 1) && igd
->index
< vfio_igd_gtt_max(vdev
)) {
322 if (gen
< 8 || (igd
->index
% 8 == 1)) {
326 base
= pci_get_long(vdev
->pdev
.config
+ IGD_BDSM
);
328 base
= pci_get_quad(vdev
->pdev
.config
+ IGD_BDSM_GEN11
);
331 hw_error("vfio-igd: Guest attempted to program IGD GTT before "
332 "BIOS reserved stolen memory. Unsupported BIOS?");
335 val
= data
- igd
->bdsm
+ base
;
337 val
= 0; /* upper 32bits of pte, we only enable below 4G PTEs */
340 trace_vfio_pci_igd_bar4_write(vdev
->vbasedev
.name
,
341 igd
->index
, data
, val
);
344 vfio_region_write(&vdev
->bars
[4].region
, addr
+ 4, val
, size
);
349 static const MemoryRegionOps vfio_igd_data_quirk
= {
350 .read
= vfio_igd_quirk_data_read
,
351 .write
= vfio_igd_quirk_data_write
,
352 .endianness
= DEVICE_LITTLE_ENDIAN
,
355 static uint64_t vfio_igd_quirk_index_read(void *opaque
,
356 hwaddr addr
, unsigned size
)
358 VFIOIGDQuirk
*igd
= opaque
;
359 VFIOPCIDevice
*vdev
= igd
->vdev
;
363 return vfio_region_read(&vdev
->bars
[4].region
, addr
, size
);
366 static void vfio_igd_quirk_index_write(void *opaque
, hwaddr addr
,
367 uint64_t data
, unsigned size
)
369 VFIOIGDQuirk
*igd
= opaque
;
370 VFIOPCIDevice
*vdev
= igd
->vdev
;
374 vfio_region_write(&vdev
->bars
[4].region
, addr
, data
, size
);
377 static const MemoryRegionOps vfio_igd_index_quirk
= {
378 .read
= vfio_igd_quirk_index_read
,
379 .write
= vfio_igd_quirk_index_write
,
380 .endianness
= DEVICE_LITTLE_ENDIAN
,
383 #define IGD_BDSM_MMIO_OFFSET 0x1080C0
385 static uint64_t vfio_igd_quirk_bdsm_read(void *opaque
,
386 hwaddr addr
, unsigned size
)
388 VFIOPCIDevice
*vdev
= opaque
;
391 offset
= IGD_BDSM_GEN11
+ addr
;
395 return pci_get_byte(vdev
->pdev
.config
+ offset
);
397 return pci_get_word(vdev
->pdev
.config
+ offset
);
399 return pci_get_long(vdev
->pdev
.config
+ offset
);
401 return pci_get_quad(vdev
->pdev
.config
+ offset
);
403 hw_error("igd: unsupported read size, %u bytes", size
);
410 static void vfio_igd_quirk_bdsm_write(void *opaque
, hwaddr addr
,
411 uint64_t data
, unsigned size
)
413 VFIOPCIDevice
*vdev
= opaque
;
416 offset
= IGD_BDSM_GEN11
+ addr
;
420 pci_set_byte(vdev
->pdev
.config
+ offset
, data
);
423 pci_set_word(vdev
->pdev
.config
+ offset
, data
);
426 pci_set_long(vdev
->pdev
.config
+ offset
, data
);
429 pci_set_quad(vdev
->pdev
.config
+ offset
, data
);
432 hw_error("igd: unsupported read size, %u bytes", size
);
437 static const MemoryRegionOps vfio_igd_bdsm_quirk
= {
438 .read
= vfio_igd_quirk_bdsm_read
,
439 .write
= vfio_igd_quirk_bdsm_write
,
440 .endianness
= DEVICE_LITTLE_ENDIAN
,
443 void vfio_probe_igd_bar0_quirk(VFIOPCIDevice
*vdev
, int nr
)
449 * This must be an Intel VGA device at address 00:02.0 for us to even
450 * consider enabling legacy mode. Some driver have dependencies on the PCI
453 if (!vfio_pci_is(vdev
, PCI_VENDOR_ID_INTEL
, PCI_ANY_ID
) ||
454 !vfio_is_vga(vdev
) || nr
!= 0 ||
455 &vdev
->pdev
!= pci_find_device(pci_device_root_bus(&vdev
->pdev
),
456 0, PCI_DEVFN(0x2, 0))) {
461 * Only on IGD devices of gen 11 and above, the BDSM register is mirrored
462 * into MMIO space and read from MMIO space by the Windows driver.
469 quirk
= vfio_quirk_alloc(1);
472 memory_region_init_io(&quirk
->mem
[0], OBJECT(vdev
), &vfio_igd_bdsm_quirk
,
473 vdev
, "vfio-igd-bdsm-quirk", 8);
474 memory_region_add_subregion_overlap(vdev
->bars
[0].region
.mem
,
475 IGD_BDSM_MMIO_OFFSET
, &quirk
->mem
[0],
478 QLIST_INSERT_HEAD(&vdev
->bars
[nr
].quirks
, quirk
, next
);
481 static int igd_get_stolen_mb(int gen
, uint32_t gmch
)
486 gms
= (gmch
>> 3) & 0x1f;
488 gms
= (gmch
>> 8) & 0xff;
493 error_report("Unsupported IGD GMS value 0x%x", gms
);
505 void vfio_probe_igd_bar4_quirk(VFIOPCIDevice
*vdev
, int nr
)
507 g_autofree
struct vfio_region_info
*rom
= NULL
;
508 g_autofree
struct vfio_region_info
*opregion
= NULL
;
509 g_autofree
struct vfio_region_info
*host
= NULL
;
510 g_autofree
struct vfio_region_info
*lpc
= NULL
;
513 PCIDevice
*lpc_bridge
;
514 int i
, ret
, ggms_mb
, gms_mb
= 0, gen
;
517 uint16_t cmd_orig
, cmd
;
521 * This must be an Intel VGA device at address 00:02.0 for us to even
522 * consider enabling legacy mode. The vBIOS has dependencies on the
525 if (!vfio_pci_is(vdev
, PCI_VENDOR_ID_INTEL
, PCI_ANY_ID
) ||
526 !vfio_is_vga(vdev
) || nr
!= 4 ||
527 &vdev
->pdev
!= pci_find_device(pci_device_root_bus(&vdev
->pdev
),
528 0, PCI_DEVFN(0x2, 0))) {
533 * We need to create an LPC/ISA bridge at PCI bus address 00:1f.0 that we
534 * can stuff host values into, so if there's already one there and it's not
535 * one we can hack on, legacy mode is no-go. Sorry Q35.
537 lpc_bridge
= pci_find_device(pci_device_root_bus(&vdev
->pdev
),
538 0, PCI_DEVFN(0x1f, 0));
539 if (lpc_bridge
&& !object_dynamic_cast(OBJECT(lpc_bridge
),
540 "vfio-pci-igd-lpc-bridge")) {
541 error_report("IGD device %s cannot support legacy mode due to existing "
542 "devices at address 1f.0", vdev
->vbasedev
.name
);
547 * IGD is not a standard, they like to change their specs often. We
548 * only attempt to support back to SandBridge and we hope that newer
549 * devices maintain compatibility with generation 8.
553 error_report("IGD device %s is unsupported in legacy mode, "
554 "try SandyBridge or newer", vdev
->vbasedev
.name
);
559 * Most of what we're doing here is to enable the ROM to run, so if
560 * there's no ROM, there's no point in setting up this quirk.
561 * NB. We only seem to get BIOS ROMs, so a UEFI VM would need CSM support.
563 ret
= vfio_get_region_info(&vdev
->vbasedev
,
564 VFIO_PCI_ROM_REGION_INDEX
, &rom
);
565 if ((ret
|| !rom
->size
) && !vdev
->pdev
.romfile
) {
566 error_report("IGD device %s has no ROM, legacy mode disabled",
567 vdev
->vbasedev
.name
);
572 * Ignore the hotplug corner case, mark the ROM failed, we can't
573 * create the devices we need for legacy mode in the hotplug scenario.
575 if (vdev
->pdev
.qdev
.hotplugged
) {
576 error_report("IGD device %s hotplugged, ROM disabled, "
577 "legacy mode disabled", vdev
->vbasedev
.name
);
578 vdev
->rom_read_failed
= true;
583 * Check whether we have all the vfio device specific regions to
584 * support legacy mode (added in Linux v4.6). If not, bail.
586 ret
= vfio_get_dev_region_info(&vdev
->vbasedev
,
587 VFIO_REGION_TYPE_PCI_VENDOR_TYPE
| PCI_VENDOR_ID_INTEL
,
588 VFIO_REGION_SUBTYPE_INTEL_IGD_OPREGION
, &opregion
);
590 error_report("IGD device %s does not support OpRegion access,"
591 "legacy mode disabled", vdev
->vbasedev
.name
);
595 ret
= vfio_get_dev_region_info(&vdev
->vbasedev
,
596 VFIO_REGION_TYPE_PCI_VENDOR_TYPE
| PCI_VENDOR_ID_INTEL
,
597 VFIO_REGION_SUBTYPE_INTEL_IGD_HOST_CFG
, &host
);
599 error_report("IGD device %s does not support host bridge access,"
600 "legacy mode disabled", vdev
->vbasedev
.name
);
604 ret
= vfio_get_dev_region_info(&vdev
->vbasedev
,
605 VFIO_REGION_TYPE_PCI_VENDOR_TYPE
| PCI_VENDOR_ID_INTEL
,
606 VFIO_REGION_SUBTYPE_INTEL_IGD_LPC_CFG
, &lpc
);
608 error_report("IGD device %s does not support LPC bridge access,"
609 "legacy mode disabled", vdev
->vbasedev
.name
);
613 gmch
= vfio_pci_read_config(&vdev
->pdev
, IGD_GMCH
, 4);
616 * If IGD VGA Disable is clear (expected) and VGA is not already enabled,
617 * try to enable it. Probably shouldn't be using legacy mode without VGA,
618 * but also no point in us enabling VGA if disabled in hardware.
620 if (!(gmch
& 0x2) && !vdev
->vga
&& !vfio_populate_vga(vdev
, &err
)) {
621 error_reportf_err(err
, VFIO_MSG_PREFIX
, vdev
->vbasedev
.name
);
622 error_report("IGD device %s failed to enable VGA access, "
623 "legacy mode disabled", vdev
->vbasedev
.name
);
627 /* Create our LPC/ISA bridge */
628 ret
= vfio_pci_igd_lpc_init(vdev
, lpc
);
630 error_report("IGD device %s failed to create LPC bridge, "
631 "legacy mode disabled", vdev
->vbasedev
.name
);
635 /* Stuff some host values into the VM PCI host bridge */
636 ret
= vfio_pci_igd_host_init(vdev
, host
);
638 error_report("IGD device %s failed to modify host bridge, "
639 "legacy mode disabled", vdev
->vbasedev
.name
);
643 /* Setup OpRegion access */
644 if (!vfio_pci_igd_opregion_init(vdev
, opregion
, &err
)) {
645 error_append_hint(&err
, "IGD legacy mode disabled\n");
646 error_reportf_err(err
, VFIO_MSG_PREFIX
, vdev
->vbasedev
.name
);
650 /* Setup our quirk to munge GTT addresses to the VM allocated buffer */
651 quirk
= vfio_quirk_alloc(2);
652 igd
= quirk
->data
= g_malloc0(sizeof(*igd
));
656 igd
->bdsm
= vfio_pci_read_config(&vdev
->pdev
, IGD_BDSM
, 4);
658 igd
->bdsm
= vfio_pci_read_config(&vdev
->pdev
, IGD_BDSM_GEN11
, 4);
660 (uint64_t)vfio_pci_read_config(&vdev
->pdev
, IGD_BDSM_GEN11
+ 4, 4) << 32;
662 igd
->bdsm
&= ~((1 * MiB
) - 1); /* 1MB aligned */
664 memory_region_init_io(&quirk
->mem
[0], OBJECT(vdev
), &vfio_igd_index_quirk
,
665 igd
, "vfio-igd-index-quirk", 4);
666 memory_region_add_subregion_overlap(vdev
->bars
[nr
].region
.mem
,
667 0, &quirk
->mem
[0], 1);
669 memory_region_init_io(&quirk
->mem
[1], OBJECT(vdev
), &vfio_igd_data_quirk
,
670 igd
, "vfio-igd-data-quirk", 4);
671 memory_region_add_subregion_overlap(vdev
->bars
[nr
].region
.mem
,
672 4, &quirk
->mem
[1], 1);
674 QLIST_INSERT_HEAD(&vdev
->bars
[nr
].quirks
, quirk
, next
);
676 /* Determine the size of stolen memory needed for GTT */
677 ggms_mb
= (gmch
>> (gen
< 8 ? 8 : 6)) & 0x3;
679 ggms_mb
= 1 << ggms_mb
;
682 gms_mb
= igd_get_stolen_mb(gen
, gmch
);
685 * Request reserved memory for stolen memory via fw_cfg. VM firmware
686 * must allocate a 1MB aligned reserved memory region below 4GB with
687 * the requested size (in bytes) for use by the Intel PCI class VGA
688 * device at VM address 00:02.0. The base address of this reserved
689 * memory region must be written to the device BDSM register at PCI
690 * config offset 0x5C.
692 bdsm_size
= g_malloc(sizeof(*bdsm_size
));
693 *bdsm_size
= cpu_to_le64((ggms_mb
+ gms_mb
) * MiB
);
694 fw_cfg_add_file(fw_cfg_find(), "etc/igd-bdsm-size",
695 bdsm_size
, sizeof(*bdsm_size
));
697 /* GMCH is read-only, emulated */
698 pci_set_long(vdev
->pdev
.config
+ IGD_GMCH
, gmch
);
699 pci_set_long(vdev
->pdev
.wmask
+ IGD_GMCH
, 0);
700 pci_set_long(vdev
->emulated_config_bits
+ IGD_GMCH
, ~0);
702 /* BDSM is read-write, emulated. The BIOS needs to be able to write it */
704 pci_set_long(vdev
->pdev
.config
+ IGD_BDSM
, 0);
705 pci_set_long(vdev
->pdev
.wmask
+ IGD_BDSM
, ~0);
706 pci_set_long(vdev
->emulated_config_bits
+ IGD_BDSM
, ~0);
708 pci_set_quad(vdev
->pdev
.config
+ IGD_BDSM_GEN11
, 0);
709 pci_set_quad(vdev
->pdev
.wmask
+ IGD_BDSM_GEN11
, ~0);
710 pci_set_quad(vdev
->emulated_config_bits
+ IGD_BDSM_GEN11
, ~0);
714 * This IOBAR gives us access to GTTADR, which allows us to write to
715 * the GTT itself. So let's go ahead and write zero to all the GTT
716 * entries to avoid spurious DMA faults. Be sure I/O access is enabled
717 * before talking to the device.
719 if (pread(vdev
->vbasedev
.fd
, &cmd_orig
, sizeof(cmd_orig
),
720 vdev
->config_offset
+ PCI_COMMAND
) != sizeof(cmd_orig
)) {
721 error_report("IGD device %s - failed to read PCI command register",
722 vdev
->vbasedev
.name
);
725 cmd
= cmd_orig
| PCI_COMMAND_IO
;
727 if (pwrite(vdev
->vbasedev
.fd
, &cmd
, sizeof(cmd
),
728 vdev
->config_offset
+ PCI_COMMAND
) != sizeof(cmd
)) {
729 error_report("IGD device %s - failed to write PCI command register",
730 vdev
->vbasedev
.name
);
733 for (i
= 1; i
< vfio_igd_gtt_max(vdev
); i
+= 4) {
734 vfio_region_write(&vdev
->bars
[4].region
, 0, i
, 4);
735 vfio_region_write(&vdev
->bars
[4].region
, 4, 0, 4);
738 if (pwrite(vdev
->vbasedev
.fd
, &cmd_orig
, sizeof(cmd_orig
),
739 vdev
->config_offset
+ PCI_COMMAND
) != sizeof(cmd_orig
)) {
740 error_report("IGD device %s - failed to restore PCI command register",
741 vdev
->vbasedev
.name
);
744 trace_vfio_pci_igd_bdsm_enabled(vdev
->vbasedev
.name
, ggms_mb
+ gms_mb
);