All of lore.kernel.org
 help / color / mirror / Atom feed
From: Igor Mammedov <imammedo@redhat.com>
To: qemu-devel@nongnu.org
Cc: mst@redhat.com, berrange@redhat.com
Subject: [PATCH v2 29/34] pci: move acpi-index uniqueness check to generic PCI device code
Date: Thu,  2 Mar 2023 17:15:38 +0100	[thread overview]
Message-ID: <20230302161543.286002-30-imammedo@redhat.com> (raw)
In-Reply-To: <20230302161543.286002-1-imammedo@redhat.com>

acpi-index is now working with non-hotpluggable buses
(pci/q35 machine hostbridge), it can be used even if
ACPI PCI hotplug is disabled and as result acpi-index
uniqueness check will be omitted (since the check is
done by ACPI PCI hotplug handler, which isn't wired
when ACPI PCI hotplug is disabled).
Move check and related code to generic PCIDevice so it
would be independent of ACPI PCI hotplug.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
PS: this also one step closer to enabling acpi-index
support for microvm and virt/arm machines.
---
 hw/acpi/pcihp.c | 56 ------------------------------------------------
 hw/pci/pci.c    | 57 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+), 56 deletions(-)

diff --git a/hw/acpi/pcihp.c b/hw/acpi/pcihp.c
index 5dc7377411..adf45e8443 100644
--- a/hw/acpi/pcihp.c
+++ b/hw/acpi/pcihp.c
@@ -54,21 +54,6 @@ typedef struct AcpiPciHpFind {
     PCIBus *bus;
 } AcpiPciHpFind;
 
-static gint g_cmp_uint32(gconstpointer a, gconstpointer b, gpointer user_data)
-{
-    return a - b;
-}
-
-static GSequence *pci_acpi_index_list(void)
-{
-    static GSequence *used_acpi_index_list;
-
-    if (!used_acpi_index_list) {
-        used_acpi_index_list = g_sequence_new(NULL);
-    }
-    return used_acpi_index_list;
-}
-
 static int acpi_pcihp_get_bsel(PCIBus *bus)
 {
     Error *local_err = NULL;
@@ -300,8 +285,6 @@ void acpi_pcihp_reset(AcpiPciHpState *s, bool acpihp_root_off)
     acpi_pcihp_update(s);
 }
 
-#define ONBOARD_INDEX_MAX (16 * 1024 - 1)
-
 void acpi_pcihp_device_pre_plug_cb(HotplugHandler *hotplug_dev,
                                    DeviceState *dev, Error **errp)
 {
@@ -314,34 +297,6 @@ void acpi_pcihp_device_pre_plug_cb(HotplugHandler *hotplug_dev,
                    ACPI_PCIHP_PROP_BSEL "' set");
         return;
     }
-
-    /*
-     * capped by systemd (see: udev-builtin-net_id.c)
-     * as it's the only known user honor it to avoid users
-     * misconfigure QEMU and then wonder why acpi-index doesn't work
-     */
-    if (pdev->acpi_index > ONBOARD_INDEX_MAX) {
-        error_setg(errp, "acpi-index should be less or equal to %u",
-                   ONBOARD_INDEX_MAX);
-        return;
-    }
-
-    /*
-     * make sure that acpi-index is unique across all present PCI devices
-     */
-    if (pdev->acpi_index) {
-        GSequence *used_indexes = pci_acpi_index_list();
-
-        if (g_sequence_lookup(used_indexes, GINT_TO_POINTER(pdev->acpi_index),
-                              g_cmp_uint32, NULL)) {
-            error_setg(errp, "a PCI device with acpi-index = %" PRIu32
-                       " already exist", pdev->acpi_index);
-            return;
-        }
-        g_sequence_insert_sorted(used_indexes,
-                                 GINT_TO_POINTER(pdev->acpi_index),
-                                 g_cmp_uint32, NULL);
-    }
 }
 
 void acpi_pcihp_device_plug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState *s,
@@ -401,17 +356,6 @@ void acpi_pcihp_device_unplug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState *s,
     trace_acpi_pci_unplug(PCI_SLOT(pdev->devfn),
                           acpi_pcihp_get_bsel(pci_get_bus(pdev)));
 
-    /*
-     * clean up acpi-index so it could reused by another device
-     */
-    if (pdev->acpi_index) {
-        GSequence *used_indexes = pci_acpi_index_list();
-
-        g_sequence_remove(g_sequence_lookup(used_indexes,
-                          GINT_TO_POINTER(pdev->acpi_index),
-                          g_cmp_uint32, NULL));
-    }
-
     qdev_unrealize(dev);
 }
 
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 08060b3e88..45ed2ce730 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -92,6 +92,21 @@ static const VMStateDescription vmstate_pcibus = {
     }
 };
 
+static gint g_cmp_uint32(gconstpointer a, gconstpointer b, gpointer user_data)
+{
+    return a - b;
+}
+
+static GSequence *pci_acpi_index_list(void)
+{
+    static GSequence *used_acpi_index_list;
+
+    if (!used_acpi_index_list) {
+        used_acpi_index_list = g_sequence_new(NULL);
+    }
+    return used_acpi_index_list;
+}
+
 static void pci_init_bus_master(PCIDevice *pci_dev)
 {
     AddressSpace *dma_as = pci_device_iommu_address_space(pci_dev);
@@ -1229,6 +1244,17 @@ static void pci_qdev_unrealize(DeviceState *dev)
     do_pci_unregister_device(pci_dev);
 
     pci_dev->msi_trigger = NULL;
+
+    /*
+     * clean up acpi-index so it could reused by another device
+     */
+    if (pci_dev->acpi_index) {
+        GSequence *used_indexes = pci_acpi_index_list();
+
+        g_sequence_remove(g_sequence_lookup(used_indexes,
+                          GINT_TO_POINTER(pci_dev->acpi_index),
+                          g_cmp_uint32, NULL));
+    }
 }
 
 void pci_register_bar(PCIDevice *pci_dev, int region_num,
@@ -1988,6 +2014,8 @@ PCIDevice *pci_find_device(PCIBus *bus, int bus_num, uint8_t devfn)
     return bus->devices[devfn];
 }
 
+#define ONBOARD_INDEX_MAX (16 * 1024 - 1)
+
 static void pci_qdev_realize(DeviceState *qdev, Error **errp)
 {
     PCIDevice *pci_dev = (PCIDevice *)qdev;
@@ -1997,6 +2025,35 @@ static void pci_qdev_realize(DeviceState *qdev, Error **errp)
     bool is_default_rom;
     uint16_t class_id;
 
+    /*
+     * capped by systemd (see: udev-builtin-net_id.c)
+     * as it's the only known user honor it to avoid users
+     * misconfigure QEMU and then wonder why acpi-index doesn't work
+     */
+    if (pci_dev->acpi_index > ONBOARD_INDEX_MAX) {
+        error_setg(errp, "acpi-index should be less or equal to %u",
+                   ONBOARD_INDEX_MAX);
+        return;
+    }
+
+    /*
+     * make sure that acpi-index is unique across all present PCI devices
+     */
+    if (pci_dev->acpi_index) {
+        GSequence *used_indexes = pci_acpi_index_list();
+
+        if (g_sequence_lookup(used_indexes,
+                              GINT_TO_POINTER(pci_dev->acpi_index),
+                              g_cmp_uint32, NULL)) {
+            error_setg(errp, "a PCI device with acpi-index = %" PRIu32
+                       " already exist", pci_dev->acpi_index);
+            return;
+        }
+        g_sequence_insert_sorted(used_indexes,
+                                 GINT_TO_POINTER(pci_dev->acpi_index),
+                                 g_cmp_uint32, NULL);
+    }
+
     if (pci_dev->romsize != -1 && !is_power_of_2(pci_dev->romsize)) {
         error_setg(errp, "ROM size %u is not a power of two", pci_dev->romsize);
         return;
-- 
2.39.1



  parent reply	other threads:[~2023-03-02 16:19 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-02 16:15 [PATCH v2 00/34] pci(pc/q35): acpi-index support on non-hotpluggable slots Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 01/34] Revert "tests/qtest: Check for devices in bios-tables-test" Igor Mammedov
2023-03-02 16:46   ` Fabiano Rosas
2023-03-02 16:15 ` [PATCH v2 02/34] tests: acpi: whitelist new q35.noacpihp test and pc.hpbrroot Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 03/34] tests: acpi: add test_acpi_q35_tcg_no_acpi_hotplug test and extend test_acpi_piix4_no_acpi_pci_hotplug Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 04/34] tests: acpi: update expected blobs Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 05/34] tests: acpi: whitelist q35/DSDT.multi-bridge before extending testcase Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 06/34] tests: acpi: extend multi-bridge case with case 'root-port, id=HOHP, hotplug=off root-port, bus=NOHP' Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 07/34] x86: pcihp: fix missing PCNT callchain when intermediate root-port has 'hotplug=off' set Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 08/34] tests: acpi: whitelist pc/DSDT.hpbrroot and pc/DSDT.hpbridge tests Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 09/34] x86: pcihp: fix missing bridge AML when intermediate root-port has 'hotplug=off' set Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 10/34] tests: acpi: update expected blobs Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 11/34] pcihp: piix4: do not redirect hotplug controller to piix4 when ACPI hotplug is disabled Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 12/34] pci: fix 'hotplugglable' property behavior Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 13/34] tests: acpi: whitelist DSDT blobs before isolating PCI _DSM func 0 prolog Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 14/34] pcihp: move PCI _DSM function 0 prolog into separate function Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 15/34] tests: acpi: update expected blobs Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 16/34] tests: acpi: whitelist DSDT before adding EDSM method Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 17/34] acpi: pci: add EDSM method to DSDT Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 18/34] tests: acpi: update expected blobs Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 19/34] tests: acpi: whitelist DSDT before adding device with acpi-index to testcases Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 20/34] tests: acpi: add device with acpi-index on non-hotpluggble bus Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 21/34] acpi: pci: support acpi-index for non-hotpluggable devices Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 22/34] tests: acpi: update expected blobs Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 23/34] tests: acpi: whitelist DSDT before exposing non zero functions Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 24/34] acpi: pci: describe all functions on populated slots Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 25/34] tests: acpi: update expected blobs Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 26/34] tests: acpi: whitelist DSDT before adding non-0 function device with acpi-index to testcases Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 27/34] tests: acpi: add non zero function device with acpi-index on non-hotpluggble bus Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 28/34] tests: acpi: update expected blobs Igor Mammedov
2023-03-02 16:15 ` Igor Mammedov [this message]
2023-03-02 16:15 ` [PATCH v2 30/34] acpi: pci: drop BSEL usage when deciding that device isn't hotpluggable Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 31/34] acpi: pci: move BSEL into build_append_pcihp_slots() Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 32/34] acpi: pci: move out ACPI PCI hotplug generator from generic slot generator build_append_pci_bus_devices() Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 33/34] pcihp: move fields enabling hotplug into AcpiPciHpState Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 34/34] pcihp: add ACPI PCI hotplug specific is_hotpluggable_bus() callback Igor Mammedov

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=20230302161543.286002-30-imammedo@redhat.com \
    --to=imammedo@redhat.com \
    --cc=berrange@redhat.com \
    --cc=mst@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.