[PULL 20/24] hw/uefi-vars-sysbus: add x64 variant

Gerd Hoffmann posted 24 patches 11 months, 1 week ago
[PULL 20/24] hw/uefi-vars-sysbus: add x64 variant
Posted by Gerd Hoffmann 11 months, 1 week ago
The x86 variant of the device is mapped on the fixed address 0xfef10000
and uses etc/hardware-info instead of FDT to pass the mapping location
to the edk2 firmware.  The latter allows to move the device to a
different location should that turn out to be necessary in the future.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Message-ID: <20250225163031.1409078-21-kraxel@redhat.com>
---
 hw/uefi/var-service-sysbus.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/hw/uefi/var-service-sysbus.c b/hw/uefi/var-service-sysbus.c
index 28572981c2af..97da8672ee95 100644
--- a/hw/uefi/var-service-sysbus.c
+++ b/hw/uefi/var-service-sysbus.c
@@ -9,6 +9,7 @@
 #include "hw/qdev-properties.h"
 #include "hw/sysbus.h"
 
+#include "hw/uefi/hardware-info.h"
 #include "hw/uefi/var-service.h"
 #include "hw/uefi/var-service-api.h"
 
@@ -75,6 +76,7 @@ static void uefi_vars_sysbus_class_init(ObjectClass *klass, void *data)
     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
 }
 
+/* generic: hardware discovery via FDT */
 static const TypeInfo uefi_vars_sysbus_info = {
     .name          = TYPE_UEFI_VARS_SYSBUS,
     .parent        = TYPE_SYS_BUS_DEVICE,
@@ -84,9 +86,39 @@ static const TypeInfo uefi_vars_sysbus_info = {
 };
 module_obj(TYPE_UEFI_VARS_SYSBUS);
 
+static void uefi_vars_x64_realize(DeviceState *dev, Error **errp)
+{
+    HARDWARE_INFO_SIMPLE_DEVICE hwinfo = {
+        .mmio_address = cpu_to_le64(0xfef10000),
+    };
+    SysBusDevice *sysbus = SYS_BUS_DEVICE(dev);
+
+    uefi_vars_sysbus_realize(dev, errp);
+
+    hardware_info_register(HardwareInfoQemuUefiVars,
+                           &hwinfo, sizeof(hwinfo));
+    sysbus_mmio_map(sysbus, 0, hwinfo.mmio_address);
+}
+
+static void uefi_vars_x64_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->realize = uefi_vars_x64_realize;
+}
+
+/* x64: hardware discovery via etc/hardware-info fw_cfg */
+static const TypeInfo uefi_vars_x64_info = {
+    .name          = TYPE_UEFI_VARS_X64,
+    .parent        = TYPE_UEFI_VARS_SYSBUS,
+    .class_init    = uefi_vars_x64_class_init,
+};
+module_obj(TYPE_UEFI_VARS_X64);
+
 static void uefi_vars_sysbus_register_types(void)
 {
     type_register_static(&uefi_vars_sysbus_info);
+    type_register_static(&uefi_vars_x64_info);
 }
 
 type_init(uefi_vars_sysbus_register_types)
-- 
2.48.1
Re: [PULL 20/24] hw/uefi-vars-sysbus: add x64 variant
Posted by Peter Maydell 4 months, 3 weeks ago
On Tue, 4 Mar 2025 at 12:49, Gerd Hoffmann <kraxel@redhat.com> wrote:
>
> The x86 variant of the device is mapped on the fixed address 0xfef10000
> and uses etc/hardware-info instead of FDT to pass the mapping location
> to the edk2 firmware.  The latter allows to move the device to a
> different location should that turn out to be necessary in the future.
>
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> Message-ID: <20250225163031.1409078-21-kraxel@redhat.com>

Hi; apologies for this very late comment, but I just
noticed this reading through the code:

> +static void uefi_vars_x64_realize(DeviceState *dev, Error **errp)
> +{
> +    HARDWARE_INFO_SIMPLE_DEVICE hwinfo = {
> +        .mmio_address = cpu_to_le64(0xfef10000),
> +    };
> +    SysBusDevice *sysbus = SYS_BUS_DEVICE(dev);
> +
> +    uefi_vars_sysbus_realize(dev, errp);
> +
> +    hardware_info_register(HardwareInfoQemuUefiVars,
> +                           &hwinfo, sizeof(hwinfo));
> +    sysbus_mmio_map(sysbus, 0, hwinfo.mmio_address);
> +}

Device realize methods should generally not map things into
the system address space. Can we refactor this so
that the board/SoC/whatever devices that create the
device do the mapping ?

thanks
-- PMM