qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Tomita Moeko <tomitamoeko@gmail.com>
To: "Alex Williamson" <alex.williamson@redhat.com>,
	"Cédric Le Goater" <clg@redhat.com>
Cc: qemu-devel@nongnu.org, Tomita Moeko <tomitamoeko@gmail.com>
Subject: [PATCH 10/10] vfio/igd: Replace legacy mode with options
Date: Tue, 25 Feb 2025 02:29:27 +0800	[thread overview]
Message-ID: <20250224182927.31519-11-tomitamoeko@gmail.com> (raw)
In-Reply-To: <20250224182927.31519-1-tomitamoeko@gmail.com>

IGD-specific quirks are implicitly enabled by legacy mode, which is
toggled by assigning IGD to 00:02.0. This patch replaces legacy mode
with explicit options for these quirks. The OpRegion quirk is merged to
the exisiting x-igd-opregion option, while a new option x-igd-lpc is
defined for the LPC bridge / Host bridge ID quirk.

The BDSM and GGC register quirks is applied to all known IGD devices.
BDSM register, which contains HPA (meaningless to guest), is initialized
to 0. GGC register is just a copy if x-igd-gms is not specified.

Unlike legacy mode, these options do not require IGD BDF being 00:02.0,
but guest drivers like EFI GOP driver still hardcodes the BDF. It is
highly recommended to assign IGD to 00:02.0.

Signed-off-by: Tomita Moeko <tomitamoeko@gmail.com>
---
 hw/vfio/igd.c | 38 +++++++++-----------------------------
 hw/vfio/pci.c | 11 ++---------
 hw/vfio/pci.h |  3 +++
 3 files changed, 14 insertions(+), 38 deletions(-)

diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c
index 1ed364b497..54a6a7b97f 100644
--- a/hw/vfio/igd.c
+++ b/hw/vfio/igd.c
@@ -426,15 +426,8 @@ void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr)
     VFIOConfigMirrorQuirk *ggc_mirror, *bdsm_mirror;
     int gen;
 
-    /*
-     * This must be an Intel VGA device at address 00:02.0 for us to even
-     * consider enabling legacy mode. Some driver have dependencies on the PCI
-     * bus address.
-     */
     if (!vfio_pci_is(vdev, PCI_VENDOR_ID_INTEL, PCI_ANY_ID) ||
-        !vfio_is_vga(vdev) || nr != 0 ||
-        &vdev->pdev != pci_find_device(pci_device_root_bus(&vdev->pdev),
-                                       0, PCI_DEVFN(0x2, 0))) {
+        !vfio_is_vga(vdev) || nr != 0) {
         return;
     }
 
@@ -482,24 +475,15 @@ void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr)
     QLIST_INSERT_HEAD(&vdev->bars[nr].quirks, bdsm_quirk, next);
 }
 
-bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev,
-                                 Error **errp G_GNUC_UNUSED)
+bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
 {
     int gen;
     uint64_t gms_size;
     uint64_t *bdsm_size;
     uint32_t gmch;
-    Error *err = NULL;
 
-    /*
-     * This must be an Intel VGA device at address 00:02.0 for us to even
-     * consider enabling legacy mode.  The vBIOS has dependencies on the
-     * PCI bus address.
-     */
     if (!vfio_pci_is(vdev, PCI_VENDOR_ID_INTEL, PCI_ANY_ID) ||
-        !vfio_is_vga(vdev) ||
-        &vdev->pdev != pci_find_device(pci_device_root_bus(&vdev->pdev),
-                                       0, PCI_DEVFN(0x2, 0))) {
+        !vfio_is_vga(vdev)) {
         return true;
     }
 
@@ -510,23 +494,19 @@ bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev,
      */
     gen = igd_gen(vdev);
     if (gen == -1) {
-        error_report("IGD device %s is unsupported in legacy mode, "
-                     "try SandyBridge or newer", vdev->vbasedev.name);
         return true;
     }
 
     /* Setup OpRegion access */
-    if (!vfio_pci_igd_setup_opregion(vdev, &err)) {
-        error_append_hint(&err, "IGD legacy mode disabled\n");
-        error_report_err(err);
-        return true;
+    if ((vdev->features & VFIO_FEATURE_ENABLE_IGD_OPREGION) &&
+        !vfio_pci_igd_setup_opregion(vdev, errp)) {
+        return false;
     }
 
     /* Setup LPC bridge / Host bridge PCI IDs */
-    if (!vfio_pci_igd_setup_lpc_bridge(vdev, &err)) {
-        error_append_hint(&err, "IGD legacy mode disabled\n");
-        error_report_err(err);
-        return true;
+    if ((vdev->features & VFIO_FEATURE_ENABLE_IGD_LPC) &&
+        !vfio_pci_igd_setup_lpc_bridge(vdev, errp)) {
+        return false;
     }
 
     gmch = vfio_pci_read_config(&vdev->pdev, IGD_GMCH, 4);
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index 10f63d4589..dde2b34d9d 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -3136,15 +3136,6 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
         vfio_bar_quirk_setup(vdev, i);
     }
 
-#ifdef CONFIG_VFIO_IGD
-    if (!vdev->igd_opregion &&
-        vdev->features & VFIO_FEATURE_ENABLE_IGD_OPREGION) {
-        if (!vfio_pci_igd_setup_opregion(vdev, errp)) {
-            goto out_unset_idev;
-        }
-    }
-#endif
-
     /* QEMU emulates all of MSI & MSIX */
     if (pdev->cap_present & QEMU_PCI_CAP_MSIX) {
         memset(vdev->emulated_config_bits + pdev->msix_cap, 0xff,
@@ -3363,6 +3354,8 @@ static const Property vfio_pci_dev_properties[] = {
                     VFIO_FEATURE_ENABLE_REQ_BIT, true),
     DEFINE_PROP_BIT("x-igd-opregion", VFIOPCIDevice, features,
                     VFIO_FEATURE_ENABLE_IGD_OPREGION_BIT, false),
+    DEFINE_PROP_BIT("x-igd-lpc", VFIOPCIDevice, features,
+                    VFIO_FEATURE_ENABLE_IGD_LPC_BIT, false),
     DEFINE_PROP_ON_OFF_AUTO("enable-migration", VFIOPCIDevice,
                             vbasedev.enable_migration, ON_OFF_AUTO_AUTO),
     DEFINE_PROP_BOOL("migration-events", VFIOPCIDevice,
diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h
index 6fe25c9701..596c78e99e 100644
--- a/hw/vfio/pci.h
+++ b/hw/vfio/pci.h
@@ -154,6 +154,9 @@ struct VFIOPCIDevice {
 #define VFIO_FEATURE_ENABLE_IGD_OPREGION_BIT 2
 #define VFIO_FEATURE_ENABLE_IGD_OPREGION \
                                 (1 << VFIO_FEATURE_ENABLE_IGD_OPREGION_BIT)
+#define VFIO_FEATURE_ENABLE_IGD_LPC_BIT 3
+#define VFIO_FEATURE_ENABLE_IGD_LPC \
+                                (1 << VFIO_FEATURE_ENABLE_IGD_LPC_BIT)
     OnOffAuto display;
     uint32_t display_xres;
     uint32_t display_yres;
-- 
2.47.2



  parent reply	other threads:[~2025-02-24 18:35 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-24 18:29 [PATCH 00/10] vfio/igd: Remove legacy mode Tomita Moeko
2025-02-24 18:29 ` [PATCH 01/10] vfio/igd: Remove GTT write quirk in IO BAR 4 Tomita Moeko
2025-02-24 18:29 ` [PATCH 02/10] vfio/igd: Do not include GTT stolen size in etc/igd-bdsm-size Tomita Moeko
2025-02-24 18:29 ` [PATCH 03/10] vfio/igd: Remove rombar check for legacy mode Tomita Moeko
2025-02-24 18:29 ` [PATCH 04/10] vfio/igd: Remove implicit VGA access enabled by " Tomita Moeko
2025-02-24 18:29 ` [PATCH 05/10] vfio/pci: Make vfio_populate_vga static Tomita Moeko
2025-02-24 18:29 ` [PATCH 06/10] vfio/igd: Consolidate OpRegion initialization into a single function Tomita Moeko
2025-02-24 18:29 ` [PATCH 07/10] vfio/igd: Move LPC bridge initialization to a separate function Tomita Moeko
2025-02-24 18:29 ` [PATCH 08/10] vfio/pci: Add placeholder for device-specific config space quirks Tomita Moeko
2025-02-24 18:29 ` [PATCH 09/10] vfio/igd: Refactor vfio_probe_igd_bar4_quirk into pci config quirk Tomita Moeko
2025-02-24 18:29 ` Tomita Moeko [this message]
2025-02-27  8:28 ` [PATCH 00/10] vfio/igd: Remove legacy mode Cédric Le Goater
2025-02-27 16:03   ` Tomita Moeko
2025-02-27 21:55 ` Alex Williamson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250224182927.31519-11-tomitamoeko@gmail.com \
    --to=tomitamoeko@gmail.com \
    --cc=alex.williamson@redhat.com \
    --cc=clg@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).