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, "Corvin Köhne" <corvin.koehne@gmail.com>,
	"Tomita Moeko" <tomitamoeko@gmail.com>
Subject: [PATCH v2 2/9] vfio/igd: Do not include GTT stolen size in etc/igd-bdsm-size
Date: Tue,  4 Mar 2025 01:52:12 +0800	[thread overview]
Message-ID: <20250303175220.74917-3-tomitamoeko@gmail.com> (raw)
In-Reply-To: <20250303175220.74917-1-tomitamoeko@gmail.com>

Though GTT Stolen Memory (GSM) is right below Data Stolen Memory (DSM)
in host address space, direct access to GSM is prohibited, and it is
not mapped to guest address space. Both host and guest accesses GSM
indirectly through the second half of MMIO BAR0 (GTTMMADR).

Guest firmware only need to reserve a memory region for DSM and program
the BDSM register with the base address of that region, that's actually
what both SeaBIOS[1] and OVMF does now.

[1] https://gitlab.com/qemu-project/seabios/-/blob/1.12-stable/src/fw/pciinit.c#L319-332

Signed-off-by: Tomita Moeko <tomitamoeko@gmail.com>
---
 hw/vfio/igd.c | 28 +++-------------------------
 1 file changed, 3 insertions(+), 25 deletions(-)

diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c
index ca3a32f4f2..dda4c7bb5d 100644
--- a/hw/vfio/igd.c
+++ b/hw/vfio/igd.c
@@ -112,28 +112,8 @@ static int igd_gen(VFIOPCIDevice *vdev)
 
 #define IGD_GMCH_GEN6_GMS_SHIFT     3       /* SNB_GMCH in i915 */
 #define IGD_GMCH_GEN6_GMS_MASK      0x1f
-#define IGD_GMCH_GEN6_GGMS_SHIFT    8
-#define IGD_GMCH_GEN6_GGMS_MASK     0x3
 #define IGD_GMCH_GEN8_GMS_SHIFT     8       /* BDW_GMCH in i915 */
 #define IGD_GMCH_GEN8_GMS_MASK      0xff
-#define IGD_GMCH_GEN8_GGMS_SHIFT    6
-#define IGD_GMCH_GEN8_GGMS_MASK     0x3
-
-static uint64_t igd_gtt_memory_size(int gen, uint16_t gmch)
-{
-    uint64_t ggms;
-
-    if (gen < 8) {
-        ggms = (gmch >> IGD_GMCH_GEN6_GGMS_SHIFT) & IGD_GMCH_GEN6_GGMS_MASK;
-    } else {
-        ggms = (gmch >> IGD_GMCH_GEN8_GGMS_SHIFT) & IGD_GMCH_GEN8_GGMS_MASK;
-        if (ggms != 0) {
-            ggms = 1ULL << ggms;
-        }
-    }
-
-    return ggms * MiB;
-}
 
 static uint64_t igd_stolen_memory_size(int gen, uint32_t gmch)
 {
@@ -367,7 +347,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
     g_autofree struct vfio_region_info *lpc = NULL;
     PCIDevice *lpc_bridge;
     int ret, gen;
-    uint64_t ggms_size, gms_size;
+    uint64_t gms_size;
     uint64_t *bdsm_size;
     uint32_t gmch;
     Error *err = NULL;
@@ -527,7 +507,6 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
         }
     }
 
-    ggms_size = igd_gtt_memory_size(gen, gmch);
     gms_size = igd_stolen_memory_size(gen, gmch);
 
     /*
@@ -539,7 +518,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
      * config offset 0x5C.
      */
     bdsm_size = g_malloc(sizeof(*bdsm_size));
-    *bdsm_size = cpu_to_le64(ggms_size + gms_size);
+    *bdsm_size = cpu_to_le64(gms_size);
     fw_cfg_add_file(fw_cfg_find(), "etc/igd-bdsm-size",
                     bdsm_size, sizeof(*bdsm_size));
 
@@ -559,6 +538,5 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
         pci_set_quad(vdev->emulated_config_bits + IGD_BDSM_GEN11, ~0);
     }
 
-    trace_vfio_pci_igd_bdsm_enabled(vdev->vbasedev.name,
-                                    (ggms_size + gms_size) / MiB);
+    trace_vfio_pci_igd_bdsm_enabled(vdev->vbasedev.name, (gms_size / MiB));
 }
-- 
2.47.2



  parent reply	other threads:[~2025-03-03 17:53 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-03 17:52 [PATCH v2 0/9] vfio/igd: Decoupling quirks with legacy mode Tomita Moeko
2025-03-03 17:52 ` [PATCH v2 1/9] vfio/igd: Remove GTT write quirk in IO BAR 4 Tomita Moeko
2025-03-03 17:52 ` Tomita Moeko [this message]
2025-03-04  7:17   ` [PATCH v2 2/9] vfio/igd: Do not include GTT stolen size in etc/igd-bdsm-size Corvin Köhne
2025-03-04 17:09     ` Tomita Moeko
2025-03-03 17:52 ` [PATCH v2 3/9] vfio/igd: Consolidate OpRegion initialization into a single function Tomita Moeko
2025-03-03 17:52 ` [PATCH v2 4/9] vfio/igd: Move LPC bridge initialization to a separate function Tomita Moeko
2025-03-03 17:52 ` [PATCH v2 5/9] vfio/pci: Add placeholder for device-specific config space quirks Tomita Moeko
2025-03-03 17:52 ` [PATCH v2 6/9] vfio/igd: Refactor vfio_probe_igd_bar4_quirk into pci config quirk Tomita Moeko
2025-03-03 17:52 ` [PATCH v2 7/9] vfio/igd: Decouple common quirks from legacy mode Tomita Moeko
2025-03-04  2:33   ` Alex Williamson
2025-03-04  8:07   ` Corvin Köhne
2025-03-04  8:15     ` Corvin Köhne
2025-03-03 17:52 ` [PATCH v2 8/9] vfio/igd: Handle x-igd-opregion option in config quirk Tomita Moeko
2025-03-03 17:52 ` [PATCH v2 9/9] vfio/igd: Introduce x-igd-lpc option for LPC bridge ID quirk Tomita Moeko
2025-03-06  5:50 ` [PATCH v2 0/9] vfio/igd: Decoupling quirks with legacy mode Cédric Le Goater

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=20250303175220.74917-3-tomitamoeko@gmail.com \
    --to=tomitamoeko@gmail.com \
    --cc=alex.williamson@redhat.com \
    --cc=clg@redhat.com \
    --cc=corvin.koehne@gmail.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).