qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Cédric Le Goater" <clg@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Alex Williamson" <alex.williamson@redhat.com>,
	"Tomita Moeko" <tomitamoeko@gmail.com>,
	"Corvin Köhne" <c.koehne@beckhoff.com>,
	"Cédric Le Goater" <clg@redhat.com>
Subject: [PULL 10/28] vfio/igd: Allow overriding GMS with 0xf0 to 0xfe on Gen9+
Date: Fri,  9 May 2025 15:12:59 +0200	[thread overview]
Message-ID: <20250509131317.164235-11-clg@redhat.com> (raw)
In-Reply-To: <20250509131317.164235-1-clg@redhat.com>

From: Tomita Moeko <tomitamoeko@gmail.com>

On Gen9 and later IGD devices, GMS 0xf0 to 0xfe represents 4MB to 60MB
pre-allocated memory size in 4MB increments. Allow users overriding
GMS with these values.

Signed-off-by: Tomita Moeko <tomitamoeko@gmail.com>
Reviewed-by: Corvin Köhne <c.koehne@beckhoff.com>
Reviewed-by: Alex Williamson <alex.williamson@redhat.com>
Tested-by: Alex Williamson <alex.williamson@redhat.com>
Link: https://lore.kernel.org/qemu-devel/20250505170305.23622-8-tomitamoeko@gmail.com
Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 hw/vfio/igd.c | 59 +++++++++++++++++++++++++++++++++++----------------
 1 file changed, 41 insertions(+), 18 deletions(-)

diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c
index 9dec32818c91f2021f6dc0c4bbe1fc0682df1a55..8ad9d723e29cd4d63e12346b6e40604ac020e747 100644
--- a/hw/vfio/igd.c
+++ b/hw/vfio/igd.c
@@ -412,6 +412,44 @@ static bool vfio_pci_igd_setup_lpc_bridge(VFIOPCIDevice *vdev, Error **errp)
     return true;
 }
 
+static bool vfio_pci_igd_override_gms(int gen, uint32_t gms, uint32_t *gmch)
+{
+    bool ret = false;
+
+    if (gen == -1) {
+        error_report("x-igd-gms is not supported on this device");
+    } else if (gen < 8) {
+        if (gms <= 0x10) {
+            *gmch &= ~(IGD_GMCH_GEN6_GMS_MASK << IGD_GMCH_GEN6_GMS_SHIFT);
+            *gmch |= gms << IGD_GMCH_GEN6_GMS_SHIFT;
+            ret = true;
+        } else {
+            error_report(QERR_INVALID_PARAMETER_VALUE, "x-igd-gms", "0~0x10");
+        }
+    } else if (gen == 8) {
+        if (gms <= 0x40) {
+            *gmch &= ~(IGD_GMCH_GEN8_GMS_MASK << IGD_GMCH_GEN8_GMS_SHIFT);
+            *gmch |= gms << IGD_GMCH_GEN8_GMS_SHIFT;
+            ret = true;
+        } else {
+            error_report(QERR_INVALID_PARAMETER_VALUE, "x-igd-gms", "0~0x40");
+        }
+    } else {
+        /* 0x0  to 0x40: 32MB increments starting at 0MB */
+        /* 0xf0 to 0xfe: 4MB increments starting at 4MB */
+        if ((gms <= 0x40) || (gms >= 0xf0 && gms <= 0xfe)) {
+            *gmch &= ~(IGD_GMCH_GEN8_GMS_MASK << IGD_GMCH_GEN8_GMS_SHIFT);
+            *gmch |= gms << IGD_GMCH_GEN8_GMS_SHIFT;
+            ret = true;
+        } else {
+            error_report(QERR_INVALID_PARAMETER_VALUE,
+                         "x-igd-gms", "0~0x40 or 0xf0~0xfe");
+        }
+    }
+
+    return ret;
+}
+
 #define IGD_GGC_MMIO_OFFSET     0x108040
 #define IGD_BDSM_MMIO_OFFSET    0x1080C0
 
@@ -594,24 +632,9 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
      * 32MiB. This option should only be used when the desired size cannot be
      * set from DVMT Pre-Allocated option in host BIOS.
      */
-    if (vdev->igd_gms) {
-        if (gen < 8) {
-            if (vdev->igd_gms <= 0x10) {
-                gmch &= ~(IGD_GMCH_GEN6_GMS_MASK << IGD_GMCH_GEN6_GMS_SHIFT);
-                gmch |= vdev->igd_gms << IGD_GMCH_GEN6_GMS_SHIFT;
-            } else {
-                error_report(QERR_INVALID_PARAMETER_VALUE,
-                             "x-igd-gms", "0~0x10");
-            }
-        } else {
-            if (vdev->igd_gms <= 0x40) {
-                gmch &= ~(IGD_GMCH_GEN8_GMS_MASK << IGD_GMCH_GEN8_GMS_SHIFT);
-                gmch |= vdev->igd_gms << IGD_GMCH_GEN8_GMS_SHIFT;
-            } else {
-                error_report(QERR_INVALID_PARAMETER_VALUE,
-                             "x-igd-gms", "0~0x40");
-            }
-        }
+    if (vdev->igd_gms &&
+        !vfio_pci_igd_override_gms(gen, vdev->igd_gms, &gmch)) {
+        return false;
     }
 
     gms_size = igd_stolen_memory_size(gen, gmch);
-- 
2.49.0



  parent reply	other threads:[~2025-05-09 13:21 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-09 13:12 [PULL 00/28] vfio queue Cédric Le Goater
2025-05-09 13:12 ` [PULL 01/28] vfio/container: ram discard disable helper Cédric Le Goater
2025-05-09 13:12 ` [PULL 02/28] vfio/container: reform vfio_container_connect cleanup Cédric Le Goater
2025-05-09 13:12 ` [PULL 03/28] vfio/container: vfio_container_group_add Cédric Le Goater
2025-05-09 13:12 ` [PULL 04/28] vfio/igd: Restrict legacy mode to Gen6-9 devices Cédric Le Goater
2025-05-09 13:12 ` [PULL 05/28] vfio/igd: Always emulate ASLS (OpRegion) register Cédric Le Goater
2025-05-09 13:12 ` [PULL 06/28] vfio/igd: Detect IGD device by OpRegion Cédric Le Goater
2025-05-09 13:12 ` [PULL 07/28] vfio/igd: Check vendor and device ID on GVT-g mdev Cédric Le Goater
2025-05-09 13:12 ` [PULL 08/28] vfio/igd: Check OpRegion support " Cédric Le Goater
2025-05-09 13:12 ` [PULL 09/28] vfio/igd: Enable OpRegion by default Cédric Le Goater
2025-05-09 13:12 ` Cédric Le Goater [this message]
2025-05-09 13:13 ` [PULL 11/28] vfio/igd: Only emulate GGC register when x-igd-gms is set Cédric Le Goater
2025-05-09 13:13 ` [PULL 12/28] vfio/igd: Remove generation limitation for IGD passthrough Cédric Le Goater
2025-05-09 13:13 ` [PULL 13/28] linux-header: update-linux-header script changes Cédric Le Goater
2025-05-09 13:13 ` [PULL 14/28] linux-headers: Update to Linux v6.15-rc3 Cédric Le Goater
2025-05-09 13:13 ` [PULL 15/28] vfio: add vfio_device_prepare() Cédric Le Goater
2025-05-09 13:13 ` [PULL 16/28] vfio: add vfio_device_unprepare() Cédric Le Goater
2025-05-09 13:13 ` [PULL 17/28] vfio: add vfio_attach_device_by_iommu_type() Cédric Le Goater
2025-05-09 13:13 ` [PULL 18/28] vfio: add vfio_device_get_irq_info() helper Cédric Le Goater
2025-05-09 13:13 ` [PULL 19/28] vfio: consistently handle return value for helpers Cédric Le Goater
2025-05-09 13:13 ` [PULL 20/28] vfio: add strread/writeerror() Cédric Le Goater
2025-05-09 13:13 ` [PULL 21/28] vfio: add vfio_pci_config_space_read/write() Cédric Le Goater
2025-05-09 13:13 ` [PULL 22/28] vfio: add unmap_all flag to DMA unmap callback Cédric Le Goater
2025-05-09 13:13 ` [PULL 23/28] vfio: implement unmap all for DMA unmap callbacks Cédric Le Goater
2025-05-09 13:13 ` [PULL 24/28] vfio: add device IO ops vector Cédric Le Goater
2025-05-09 13:13 ` [PULL 25/28] vfio: add region info cache Cédric Le Goater
2025-10-14 13:16   ` Cédric Le Goater
2025-10-14 13:32     ` John Levon
2025-10-14 13:49       ` Alex Williamson
2025-10-14 13:58         ` Cédric Le Goater
2025-10-14 14:01           ` John Levon
2025-10-14 14:00         ` John Levon
2025-10-14 14:29           ` Alex Williamson
2025-10-14 14:36             ` John Levon
2025-05-09 13:13 ` [PULL 26/28] vfio: add read/write to device IO ops vector Cédric Le Goater
2025-05-09 13:13 ` [PULL 27/28] vfio: add vfio-pci-base class Cédric Le Goater
2025-05-09 13:13 ` [PULL 28/28] vfio/container: pass listener_begin/commit callbacks Cédric Le Goater
2025-05-10 18:36 ` [PULL 00/28] vfio queue Stefan Hajnoczi

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=20250509131317.164235-11-clg@redhat.com \
    --to=clg@redhat.com \
    --cc=alex.williamson@redhat.com \
    --cc=c.koehne@beckhoff.com \
    --cc=qemu-devel@nongnu.org \
    --cc=tomitamoeko@gmail.com \
    /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).