qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jean-Philippe Brucker <jean-philippe@linaro.org>
To: mst@redhat.com, imammedo@redhat.com, peter.maydell@linaro.org
Cc: Jean-Philippe Brucker <jean-philippe@linaro.org>,
	ehabkost@redhat.com, eric.auger@redhat.com, jasowang@redhat.com,
	richard.henderson@linaro.org, qemu-devel@nongnu.org,
	peterx@redhat.com, shannon.zhaosl@gmail.com, qemu-arm@nongnu.org,
	ani@anisinha.ca, pbonzini@redhat.com
Subject: [PATCH v5 03/12] hw/i386/pc: Move IOMMU singleton into PCMachineState
Date: Wed, 20 Oct 2021 18:27:37 +0100	[thread overview]
Message-ID: <20211020172745.620101-4-jean-philippe@linaro.org> (raw)
In-Reply-To: <20211020172745.620101-1-jean-philippe@linaro.org>

We're about to support a third vIOMMU for x86, virtio-iommu which
doesn't inherit X86IOMMUState. Move the IOMMU singleton into
PCMachineState, so it can be shared between all three vIOMMUs.

The x86_iommu_get_default() helper is still needed by KVM and IOAPIC to
fetch the default IRQ-remapping IOMMU. Since virtio-iommu doesn't
support IRQ remapping, this interface doesn't need to change for the
moment. We could later replace X86IOMMUState with an "IRQ remapping
IOMMU" interface if necessary.

Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
---
 include/hw/i386/pc.h |  1 +
 hw/i386/pc.c         | 12 +++++++++++-
 hw/i386/x86-iommu.c  | 26 ++++++++------------------
 3 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 11426e26dc..b72e5bf9d1 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -35,6 +35,7 @@ typedef struct PCMachineState {
     I2CBus *smbus;
     PFlashCFI01 *flash[2];
     ISADevice *pcspk;
+    DeviceState *iommu;
 
     /* Configuration options: */
     uint64_t max_ram_below_4g;
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 54e4c00dce..fcbf328e8d 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1330,6 +1330,15 @@ static void pc_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev,
     } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PMEM_PCI) ||
                object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MEM_PCI)) {
         pc_virtio_md_pci_pre_plug(hotplug_dev, dev, errp);
+    } else if (object_dynamic_cast(OBJECT(dev), TYPE_X86_IOMMU_DEVICE)) {
+        PCMachineState *pcms = PC_MACHINE(hotplug_dev);
+
+        if (pcms->iommu) {
+            error_setg(errp, "QEMU does not support multiple vIOMMUs "
+                       "for x86 yet.");
+            return;
+        }
+        pcms->iommu = dev;
     }
 }
 
@@ -1384,7 +1393,8 @@ static HotplugHandler *pc_get_hotplug_handler(MachineState *machine,
     if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM) ||
         object_dynamic_cast(OBJECT(dev), TYPE_CPU) ||
         object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PMEM_PCI) ||
-        object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MEM_PCI)) {
+        object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MEM_PCI) ||
+        object_dynamic_cast(OBJECT(dev), TYPE_X86_IOMMU_DEVICE)) {
         return HOTPLUG_HANDLER(machine);
     }
 
diff --git a/hw/i386/x86-iommu.c b/hw/i386/x86-iommu.c
index dc968c7a53..01d11325a6 100644
--- a/hw/i386/x86-iommu.c
+++ b/hw/i386/x86-iommu.c
@@ -77,25 +77,17 @@ void x86_iommu_irq_to_msi_message(X86IOMMUIrq *irq, MSIMessage *msg_out)
     msg_out->data = msg.msi_data;
 }
 
-/* Default X86 IOMMU device */
-static X86IOMMUState *x86_iommu_default = NULL;
-
-static void x86_iommu_set_default(X86IOMMUState *x86_iommu)
+X86IOMMUState *x86_iommu_get_default(void)
 {
-    assert(x86_iommu);
+    MachineState *ms = MACHINE(qdev_get_machine());
+    PCMachineState *pcms =
+        PC_MACHINE(object_dynamic_cast(OBJECT(ms), TYPE_PC_MACHINE));
 
-    if (x86_iommu_default) {
-        error_report("QEMU does not support multiple vIOMMUs "
-                     "for x86 yet.");
-        exit(1);
+    if (pcms &&
+        object_dynamic_cast(OBJECT(pcms->iommu), TYPE_X86_IOMMU_DEVICE)) {
+        return X86_IOMMU_DEVICE(pcms->iommu);
     }
-
-    x86_iommu_default = x86_iommu;
-}
-
-X86IOMMUState *x86_iommu_get_default(void)
-{
-    return x86_iommu_default;
+    return NULL;
 }
 
 static void x86_iommu_realize(DeviceState *dev, Error **errp)
@@ -131,8 +123,6 @@ static void x86_iommu_realize(DeviceState *dev, Error **errp)
     if (x86_class->realize) {
         x86_class->realize(dev, errp);
     }
-
-    x86_iommu_set_default(X86_IOMMU_DEVICE(dev));
 }
 
 static Property x86_iommu_properties[] = {
-- 
2.33.0



  parent reply	other threads:[~2021-10-20 17:39 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-20 17:27 [PATCH v5 00/12] virtio-iommu: Add ACPI support Jean-Philippe Brucker
2021-10-20 17:27 ` [PATCH v5 01/12] hw/acpi: Add VIOT table Jean-Philippe Brucker
2021-10-20 17:27 ` [PATCH v5 02/12] hw/i386/pc: Remove x86_iommu_get_type() Jean-Philippe Brucker
2021-10-21  9:02   ` Eric Auger
2021-10-21 13:29   ` Igor Mammedov
2021-10-20 17:27 ` Jean-Philippe Brucker [this message]
2021-10-21  9:02   ` [PATCH v5 03/12] hw/i386/pc: Move IOMMU singleton into PCMachineState Eric Auger
2021-10-21 13:34   ` Igor Mammedov
2021-10-20 17:27 ` [PATCH v5 04/12] hw/i386/pc: Allow instantiating a virtio-iommu device Jean-Philippe Brucker
2021-10-21 13:47   ` Igor Mammedov
2021-10-25 11:23     ` Jean-Philippe Brucker
2021-10-20 17:27 ` [PATCH v5 05/12] hw/arm/virt-acpi-build: Add VIOT table for virtio-iommu Jean-Philippe Brucker
2021-10-21 13:49   ` Igor Mammedov
2021-10-20 17:27 ` [PATCH v5 06/12] hw/arm/virt: Remove device tree restriction " Jean-Philippe Brucker
2021-10-21 13:53   ` Igor Mammedov
2021-10-20 17:27 ` [PATCH v5 07/12] hw/arm/virt: Reject instantiation of multiple IOMMUs Jean-Philippe Brucker
2021-10-21 13:54   ` Igor Mammedov
2021-10-20 17:27 ` [PATCH v5 08/12] hw/arm/virt: Use object_property_set instead of qdev_prop_set Jean-Philippe Brucker
2021-10-20 17:27 ` [PATCH v5 09/12] tests/acpi: allow updates of VIOT expected data files Jean-Philippe Brucker
2021-10-21  9:02   ` Eric Auger
2021-10-21 14:00   ` Igor Mammedov
2021-10-20 17:27 ` [PATCH v5 10/12] tests/acpi: add test cases for VIOT Jean-Philippe Brucker
2021-10-21  9:02   ` Eric Auger
2021-10-26  9:47     ` Jean-Philippe Brucker
2021-10-21  9:02   ` Eric Auger
2021-10-20 17:27 ` [PATCH v5 11/12] tests/acpi: add expected blob for VIOT test on virt machine Jean-Philippe Brucker
2021-10-20 17:27 ` [PATCH v5 12/12] tests/acpi: add expected blobs for VIOT test on q35 machine Jean-Philippe Brucker

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=20211020172745.620101-4-jean-philippe@linaro.org \
    --to=jean-philippe@linaro.org \
    --cc=ani@anisinha.ca \
    --cc=ehabkost@redhat.com \
    --cc=eric.auger@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=peterx@redhat.com \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=shannon.zhaosl@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).