]> www.infradead.org Git - users/dwmw2/qemu.git/commitdiff
hw/acpi: Remove legacy reset handling from vmclock vmclock
authorDavid Woodhouse <dwmw@amazon.co.uk>
Fri, 7 Feb 2025 14:12:58 +0000 (14:12 +0000)
committerDavid Woodhouse <dwmw@amazon.co.uk>
Fri, 7 Feb 2025 14:19:27 +0000 (14:19 +0000)
The vmclock device only has a reset method in order to plug its memory
region into the system memory. It was originally done this way in order
to defer the memory_region_add_subregion_overlap() from vmclock_realize(),
but that doesn't seem to be necessary (any longer?).

Still, allowing the platform code to do this is cleaner because it lets
the address be specified by the platform, easing the port to Arm and
other platforms in future. And the platform has to be involved anyway
because of the need to include the device in the ACPI tables (or DT).

So drop the reset method and provide a vmclock_mmio_map() function
instead, called from pc_machine_done().

Shift the ACPI table build into #ifdef CONFIG_ACPI_VMCLOCK too while
we're at it, since it looks like that wouldn't have built when vmclock
wasn't enabled.

Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
hw/acpi/vmclock.c
hw/i386/acpi-build.c
hw/i386/pc.c
include/hw/acpi/vmclock.h

index 7387e5c9cad24ea05362b51db61a6599d560af15..36edfae0ed5fb6350d13e756929c5509f25e97ad 100644 (file)
@@ -20,7 +20,6 @@
 #include "hw/qdev-properties.h"
 #include "hw/qdev-properties-system.h"
 #include "migration/vmstate.h"
-#include "system/reset.h"
 
 #include "standard-headers/linux/vmclock-abi.h"
 
@@ -107,15 +106,14 @@ static const VMStateDescription vmstate_vmclock = {
     },
 };
 
-static void vmclock_handle_reset(void *opaque)
+void vmclock_mmio_map(Object *dev, hwaddr addr)
 {
-    VmclockState *vms = VMCLOCK(opaque);
+    VmclockState *vms = VMCLOCK(dev);
 
-    if (!memory_region_is_mapped(&vms->clk_page)) {
-        memory_region_add_subregion_overlap(get_system_memory(),
-                                            vms->physaddr,
-                                            &vms->clk_page, 0);
-    }
+    vms->physaddr = addr;
+    memory_region_add_subregion_overlap(get_system_memory(),
+                                        vms->physaddr,
+                                        &vms->clk_page, 0);
 }
 
 static void vmclock_realize(DeviceState *dev, Error **errp)
@@ -131,8 +129,6 @@ static void vmclock_realize(DeviceState *dev, Error **errp)
         return;
     }
 
-    vms->physaddr = VMCLOCK_ADDR;
-
     e820_add_entry(vms->physaddr, VMCLOCK_SIZE, E820_RESERVED);
 
     memory_region_init_ram(&vms->clk_page, OBJECT(dev), "vmclock_page",
@@ -149,8 +145,6 @@ static void vmclock_realize(DeviceState *dev, Error **errp)
     vms->clk->clock_status = VMCLOCK_STATUS_UNKNOWN;
     vms->clk->counter_id = VMCLOCK_COUNTER_INVALID;
 
-    qemu_register_reset(vmclock_handle_reset, vms);
-
     vmclock_update_guest(vms);
 }
 
index 53b7306b43ec98e25d8d26ec015c6fc064a56582..9db7b1f94ef8349fb9d50693987f90fbc430e37e 100644 (file)
@@ -2446,7 +2446,7 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)
     uint8_t *u;
     GArray *tables_blob = tables->table_data;
     AcpiSlicOem slic_oem = { .id = NULL, .table_id = NULL };
-    Object *vmgenid_dev, *vmclock_dev;
+    Object *vmgenid_dev;
     char *oem_id;
     char *oem_table_id;
 
@@ -2519,12 +2519,16 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)
                            tables->vmgenid, tables->linker, x86ms->oem_id);
     }
 
-    vmclock_dev = find_vmclock_dev();
-    if (vmclock_dev) {
-        acpi_add_table(table_offsets, tables_blob);
-        vmclock_build_acpi(VMCLOCK(vmclock_dev), tables_blob, tables->linker,
-                           x86ms->oem_id);
+#ifdef CONFIG_ACPI_VMCLOCK
+    {
+        Object *vmclock_dev = find_vmclock_dev();
+        if (vmclock_dev) {
+            acpi_add_table(table_offsets, tables_blob);
+            vmclock_build_acpi(VMCLOCK(vmclock_dev), tables_blob, tables->linker,
+                               x86ms->oem_id);
+        }
     }
+#endif
 
     if (misc.has_hpet) {
         acpi_add_table(table_offsets, tables_blob);
index b46975c8a4db8f240a1550afe028912e54b51896..776c2c8a37cf8d3a6cd4c27e43d541d69bca8ec4 100644 (file)
@@ -60,6 +60,7 @@
 #include "hw/i386/kvm/xen_gnttab.h"
 #include "hw/i386/kvm/xen_xenstore.h"
 #include "hw/mem/memory-device.h"
+#include "hw/acpi/vmclock.h"
 #include "e820_memory_layout.h"
 #include "trace.h"
 #include "sev.h"
@@ -635,6 +636,15 @@ void pc_machine_done(Notifier *notifier, void *data)
     pci_bus_add_fw_cfg_extra_pci_roots(x86ms->fw_cfg, pcms->pcibus,
                                        &error_abort);
 
+#ifdef CONFIG_ACPI_VMCLOCK
+    {
+        Object *vmclock = find_vmclock_dev();
+        if (vmclock) {
+            vmclock_mmio_map(vmclock, VMCLOCK_ADDR);
+        }
+    }
+#endif
+
     acpi_setup();
     if (x86ms->fw_cfg) {
         fw_cfg_build_smbios(pcms, x86ms->fw_cfg, pcms->smbios_entry_point_type);
index 5605605812c1f3b4d1976cbf034bd2ce6736f4c7..97f8a30c0eb33e349390e288989bbaa067f5f238 100644 (file)
@@ -30,5 +30,6 @@ static inline Object *find_vmclock_dev(void)
 
 void vmclock_build_acpi(VmclockState *vms, GArray *table_data,
                         BIOSLinker *linker, const char *oem_id);
+void vmclock_mmio_map(Object *dev, hwaddr addr);
 
 #endif