From patchwork Fri Feb 7 14:34:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Woodhouse X-Patchwork-Id: 13965151 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 04DE9C02199 for ; Fri, 7 Feb 2025 14:34:55 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tgPRH-0000AB-8W; Fri, 07 Feb 2025 09:34:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tgPRF-00009L-1N for qemu-devel@nongnu.org; Fri, 07 Feb 2025 09:34:37 -0500 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tgPRB-0003B5-Iv for qemu-devel@nongnu.org; Fri, 07 Feb 2025 09:34:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=MIME-Version:Content-Type:References: In-Reply-To:Date:Cc:To:From:Subject:Message-ID:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=KsJHKxDHuvghxCrCBP8FS4KOaHx66s/HjPvNG85AHEo=; b=komzWrBN+ho1CDV2waUI6XON3s tSFth5SUKbYehFn3AAg/1KmNW1qU5lIAlqjae7ilWtVrCvM+oIdtGP1j2oyDKmYoXDpO1q0TR9A6I Qjq/5pE/LRbh+WEsb7/sxwtOLwWKNwmfdLUxQ0YUsPG4mg+mv/qp5DNqMMPNzo0DirUmOWpC1XwsJ p1WgKTa3qFJgGQ76WAJF0fk37TiPraM0v12kbCfmDXFlCy/gh06+mDwdAqfPY2VF0IFymHyNu0A1L Fq1C4gIWO6QrWiU7yRknrmmqLInvsRtrS5JMJByBCMGASJxwb5kFTEN6IS6mzYf98CIIBqW8KNwKV 33Eo+ayw==; Received: from 54-240-197-238.amazon.com ([54.240.197.238] helo=freeip.amazon.com) by casper.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tgPR2-00000007xuv-0hs2; Fri, 07 Feb 2025 14:34:24 +0000 Message-ID: <3d1b617f001b4ee989101748d120992c81a63a63.camel@infradead.org> Subject: [PATCH] hw/acpi: Remove legacy reset handling from vmclock From: David Woodhouse To: Peter Maydell Cc: qemu-devel@nongnu.org, Paolo Bonzini , "Michael S. Tsirkin" , Igor Mammedov , Ani Sinha , Marcel Apfelbaum , Richard Henderson , Eduardo Habkost , Cornelia Huck , Peter Hilber , "Mohamed Abuelfotoh, Hazem" , paul Date: Fri, 07 Feb 2025 14:34:22 +0000 In-Reply-To: <9097119d6e4c6a1f0a9c8fd3516b02008a1d8ffd.camel@infradead.org> References: <20250116140315.2455143-1-dwmw2@infradead.org> <20250116140315.2455143-4-dwmw2@infradead.org> <2498d8fa34f6503879f99f671b58055bb6a63fdc.camel@infradead.org> <9097119d6e4c6a1f0a9c8fd3516b02008a1d8ffd.camel@infradead.org> User-Agent: Evolution 3.52.3-0ubuntu1 MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Received-SPF: none client-ip=2001:8b0:10b:1236::1; envelope-from=BATV+d214d3087cba0d0cd96e+7838+infradead.org+dwmw2@casper.srs.infradead.org; helo=casper.infradead.org X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: David Woodhouse 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 --- hw/acpi/vmclock.c | 18 ++++++------------ hw/i386/acpi-build.c | 16 ++++++++++------ hw/i386/pc.c | 10 ++++++++++ include/hw/acpi/vmclock.h | 1 + 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/hw/acpi/vmclock.c b/hw/acpi/vmclock.c index 7387e5c9ca..36edfae0ed 100644 --- a/hw/acpi/vmclock.c +++ b/hw/acpi/vmclock.c @@ -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); } diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 53b7306b43..9db7b1f94e 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -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); diff --git a/hw/i386/pc.c b/hw/i386/pc.c index b46975c8a4..776c2c8a37 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -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); diff --git a/include/hw/acpi/vmclock.h b/include/hw/acpi/vmclock.h index 5605605812..97f8a30c0e 100644 --- a/include/hw/acpi/vmclock.h +++ b/include/hw/acpi/vmclock.h @@ -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