All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luigi Leonardi <leonardi@redhat.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	 "Michael S. Tsirkin" <mst@redhat.com>,
	 Richard Henderson <richard.henderson@linaro.org>,
	 Sergio Lopez <slp@redhat.com>, Gerd Hoffmann <kraxel@redhat.com>,
	 Luigi Leonardi <leonardi@redhat.com>
Subject: [PATCH 2/3] hw/i386/microvm: add platform bus support
Date: Wed, 01 Jul 2026 16:16:18 +0200	[thread overview]
Message-ID: <20260701-microvm_uefi_var-v1-2-0652cae6a152@redhat.com> (raw)
In-Reply-To: <20260701-microvm_uefi_var-v1-0-0652cae6a152@redhat.com>

Add a platform bus to microvm to support dynamic sysbus devices with
automatic MMIO address allocation. The bus is mapped at 0xfec20000
with a 1 MB window, placed after the IOAPICs.

This is necessary to support the uefi-vars-sysbus device, which
will be attached to microvm using the platform bus.

The platform bus is created without IRQ lines for now; IRQ support can
be added later as needed.

Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
---
 hw/i386/Kconfig           |  1 +
 hw/i386/microvm-dt.c      |  9 +++++++++
 hw/i386/microvm.c         | 36 ++++++++++++++++++++++++++++++++++++
 include/hw/i386/microvm.h |  4 ++++
 4 files changed, 50 insertions(+)

diff --git a/hw/i386/Kconfig b/hw/i386/Kconfig
index 12473acaa7..e5f5e11980 100644
--- a/hw/i386/Kconfig
+++ b/hw/i386/Kconfig
@@ -133,6 +133,7 @@ config MICROVM
     select PCI_EXPRESS_GENERIC_BRIDGE
     select USB_XHCI_SYSBUS
     select I8254
+    select PLATFORM_BUS
 
 config NITRO_ENCLAVE
     default y
diff --git a/hw/i386/microvm-dt.c b/hw/i386/microvm-dt.c
index 45fbb5bbd1..69feddc715 100644
--- a/hw/i386/microvm-dt.c
+++ b/hw/i386/microvm-dt.c
@@ -38,6 +38,7 @@
 #include "hw/i386/fw_cfg.h"
 #include "hw/rtc/mc146818rtc.h"
 #include "hw/core/sysbus.h"
+#include "hw/core/sysbus-fdt.h"
 #include "hw/virtio/virtio-mmio.h"
 #include "hw/usb/xhci.h"
 
@@ -337,6 +338,14 @@ void dt_setup_microvm(MicrovmMachineState *mms)
     qemu_fdt_add_subnode(ms->fdt, "/chosen");
     dt_setup_sys_bus(mms);
 
+    if (mms->platform_bus_dev) {
+        /* Platform bus IRQs are not supported, intc is required but unused */
+        platform_bus_add_all_fdt_nodes(ms->fdt, "/ioapic1",
+                                       MICROVM_PLATFORM_BUS_BASE,
+                                       MICROVM_PLATFORM_BUS_SIZE,
+                                       0);
+    }
+
     /* add to fw_cfg */
     if (debug) {
         fprintf(stderr, "%s: add etc/fdt to fw_cfg\n", __func__);
diff --git a/hw/i386/microvm.c b/hw/i386/microvm.c
index 779741ec76..d4836b5e12 100644
--- a/hw/i386/microvm.c
+++ b/hw/i386/microvm.c
@@ -47,6 +47,7 @@
 #include "hw/virtio/virtio-mmio.h"
 #include "hw/acpi/acpi.h"
 #include "hw/acpi/generic_event_device.h"
+#include "hw/core/platform-bus.h"
 #include "hw/pci-host/gpex.h"
 #include "hw/usb/xhci.h"
 #include "hw/vfio/types.h"
@@ -146,6 +147,24 @@ static void create_gpex(MicrovmMachineState *mms)
     }
 }
 
+static void create_platform_bus(MicrovmMachineState *mms)
+{
+    DeviceState *dev;
+    SysBusDevice *s;
+
+    dev = qdev_new(TYPE_PLATFORM_BUS_DEVICE);
+    dev->id = g_strdup(TYPE_PLATFORM_BUS_DEVICE);
+    qdev_prop_set_uint32(dev, "num_irqs", 0);
+    qdev_prop_set_uint32(dev, "mmio_size", MICROVM_PLATFORM_BUS_SIZE);
+    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+    mms->platform_bus_dev = dev;
+
+    s = SYS_BUS_DEVICE(dev);
+    memory_region_add_subregion(get_system_memory(),
+                                MICROVM_PLATFORM_BUS_BASE,
+                                sysbus_mmio_get_region(s, 0));
+}
+
 static int microvm_ioapics(MicrovmMachineState *mms)
 {
     if (!x86_machine_is_acpi_enabled(X86_MACHINE(mms))) {
@@ -248,6 +267,8 @@ static void microvm_devices_init(MicrovmMachineState *mms)
         x86ms->pci_irq_mask = 0;
     }
 
+    create_platform_bus(mms);
+
     if (x86ms->pic == ON_OFF_AUTO_ON || x86ms->pic == ON_OFF_AUTO_AUTO) {
         qemu_irq *i8259;
 
@@ -453,12 +474,27 @@ static HotplugHandler *microvm_get_hotplug_handler(MachineState *machine,
     return NULL;
 }
 
+static void link_one_device(SysBusDevice *sbdev, void *opaque)
+{
+    platform_bus_link_device(PLATFORM_BUS_DEVICE(opaque), sbdev);
+}
+
+static void microvm_link_platform_bus_devices(MicrovmMachineState *mms)
+{
+    if (!mms->platform_bus_dev) {
+        return;
+    }
+
+    foreach_dynamic_sysbus_device(link_one_device, mms->platform_bus_dev);
+}
+
 static void microvm_machine_done(Notifier *notifier, void *data)
 {
     MicrovmMachineState *mms = container_of(notifier, MicrovmMachineState,
                                             machine_done);
     X86MachineState *x86ms = X86_MACHINE(mms);
 
+    microvm_link_platform_bus_devices(mms);
     acpi_setup_microvm(mms);
     dt_setup_microvm(mms);
     fw_cfg_add_e820(x86ms->fw_cfg);
diff --git a/include/hw/i386/microvm.h b/include/hw/i386/microvm.h
index 184b7a8c09..bd2897aa78 100644
--- a/include/hw/i386/microvm.h
+++ b/include/hw/i386/microvm.h
@@ -61,6 +61,9 @@
 #define MICROVM_XHCI_BASE     0xfe900000
 #define MICROVM_XHCI_IRQ      10
 
+#define MICROVM_PLATFORM_BUS_BASE 0xfec20000
+#define MICROVM_PLATFORM_BUS_SIZE 0x00100000
+
 #define PCIE_MMIO_BASE        0xc0000000
 #define PCIE_MMIO_SIZE        0x20000000
 #define PCIE_ECAM_BASE        0xe0000000
@@ -101,6 +104,7 @@ struct MicrovmMachineState {
     Notifier machine_done;
     Notifier powerdown_req;
     struct GPEXConfig gpex;
+    DeviceState *platform_bus_dev;
 
     uint32_t ioapic_phandle[2];
 };

-- 
2.54.0



  parent reply	other threads:[~2026-07-01 14:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-01 14:16 [PATCH 0/3] hw/i386/microvm: add uefi-vars-sysbus support via platform bus Luigi Leonardi
2026-07-01 14:16 ` [PATCH 1/3] hw/core/platform-bus: fix crash when num_irqs is zero Luigi Leonardi
2026-07-01 14:16 ` Luigi Leonardi [this message]
2026-07-01 14:16 ` [PATCH 3/3] hw/i386/microvm: add uefi-vars-sysbus support Luigi Leonardi

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=20260701-microvm_uefi_var-v1-2-0652cae6a152@redhat.com \
    --to=leonardi@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=slp@redhat.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 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.