From nobody Fri May 17 23:25:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1670584631; cv=none; d=zohomail.com; s=zohoarc; b=h58grfWM6sureH/goQ1HELy/O9sybr5X5YDBVCMg6QXDPPqWQIAELFRbQ2Ud+PiG2pSEBIDzEIlwVGwU23MKYiC96HjLTYpbuY9X+viIONa5ix1D1zV8soEf8VrQpC+mjFSQQWSQCXc+dISZ++G39HUig+34eGX5KxRZweqqF7M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670584631; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=lYVzZ2wyr/Q89Z/+19+QWonnkA2baWNbz0EhqNReKVA=; b=Rzbeu6FNiI1u4RiX3i/XIADsp+S9YH3caB79GXJwHN793bhAupM7QvZdMP+pbj32xq8vFKigjEEXWysFmXZ9snYWUGzVSGJO0rJ2g6QRhBlnlnwrlRalhLYnJsBNopqKvUGZcBIAUaIdBgE+o1A3iPrf9kOxXjSgTHhlxtyFyrw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1670584631260952.5403347043053; Fri, 9 Dec 2022 03:17:11 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p3bMX-0001MZ-Ni; Fri, 09 Dec 2022 06:16:17 -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 1p3bMP-0001Lt-M5 for qemu-devel@nongnu.org; Fri, 09 Dec 2022 06:16:10 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p3bML-0005Cl-Bm for qemu-devel@nongnu.org; Fri, 09 Dec 2022 06:16:09 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-486-5j8LNd1MNIaC-A_EnhIlPA-1; Fri, 09 Dec 2022 06:16:02 -0500 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A7780185A78B; Fri, 9 Dec 2022 11:16:01 +0000 (UTC) Received: from thuth.com (unknown [10.39.193.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0DE414B3FC6; Fri, 9 Dec 2022 11:15:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670584563; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=lYVzZ2wyr/Q89Z/+19+QWonnkA2baWNbz0EhqNReKVA=; b=d96Jgb5McPey/SiOYGp/E0C/1gkxNrNMKhf96nnKAOMNVqe0tjVVeXUY6TYHt4WwhOkJb2 ureOupe+7oejZYSBmMxPCySM5ksw99BnRk8EOwk5CgEr0D8YFT1G673camyYEDoVWRjtb2 lj0W1+93ArWTpMmbbBoNZQfmZxFItl0= X-MC-Unique: 5j8LNd1MNIaC-A_EnhIlPA-1 From: Thomas Huth To: Paolo Bonzini , qemu-devel@nongnu.org, Bernhard Beschow , Mark Cave-Ayland Cc: Michael S Tsirkin , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , BALATON Zoltan Subject: [PATCH v2 for-8.0] hw/rtc/mc146818rtc: Make this rtc device target independent Date: Fri, 9 Dec 2022 12:15:56 +0100 Message-Id: <20221209111556.110757-1-thuth@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1670584633481100003 Content-Type: text/plain; charset="utf-8" The only reason for this code being target dependent is the apic-related code in rtc_policy_slew_deliver_irq(). Since these apic functions are rather simple, we can easily move them into a new, separate file (apic_irqcount.c) which will always be compiled and linked if either APIC or the mc146818 dev= ice are required. This way we can get rid of the #ifdef TARGET_I386 switches in mc146818rtc.c and declare it in the softmmu_ss instead of specific_ss, so that the code only gets compiled once for all targets. Signed-off-by: Thomas Huth Reviewed-by: Mark Cave-Ayland Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- v2: Move the apic functions into a separate file instead of using an ugly function pointer include/hw/i386/apic.h | 1 + include/hw/i386/apic_internal.h | 1 - include/hw/rtc/mc146818rtc.h | 1 + hw/intc/apic_common.c | 27 ----------------- hw/intc/apic_irqcount.c | 53 +++++++++++++++++++++++++++++++++ hw/rtc/mc146818rtc.c | 25 +++++----------- hw/intc/meson.build | 6 +++- hw/rtc/meson.build | 3 +- 8 files changed, 68 insertions(+), 49 deletions(-) create mode 100644 hw/intc/apic_irqcount.c diff --git a/include/hw/i386/apic.h b/include/hw/i386/apic.h index da1d2fe155..96b9939425 100644 --- a/include/hw/i386/apic.h +++ b/include/hw/i386/apic.h @@ -9,6 +9,7 @@ int apic_accept_pic_intr(DeviceState *s); void apic_deliver_pic_intr(DeviceState *s, int level); void apic_deliver_nmi(DeviceState *d); int apic_get_interrupt(DeviceState *s); +void apic_report_irq_delivered(int delivered); void apic_reset_irq_delivered(void); int apic_get_irq_delivered(void); void cpu_set_apic_base(DeviceState *s, uint64_t val); diff --git a/include/hw/i386/apic_internal.h b/include/hw/i386/apic_interna= l.h index c175e7e718..e61ad04769 100644 --- a/include/hw/i386/apic_internal.h +++ b/include/hw/i386/apic_internal.h @@ -199,7 +199,6 @@ typedef struct VAPICState { =20 extern bool apic_report_tpr_access; =20 -void apic_report_irq_delivered(int delivered); bool apic_next_timer(APICCommonState *s, int64_t current_time); void apic_enable_tpr_access_reporting(DeviceState *d, bool enable); void apic_enable_vapic(DeviceState *d, hwaddr paddr); diff --git a/include/hw/rtc/mc146818rtc.h b/include/hw/rtc/mc146818rtc.h index 1db0fcee92..45bcd6f040 100644 --- a/include/hw/rtc/mc146818rtc.h +++ b/include/hw/rtc/mc146818rtc.h @@ -55,5 +55,6 @@ ISADevice *mc146818_rtc_init(ISABus *bus, int base_year, qemu_irq intercept_irq); void rtc_set_memory(ISADevice *dev, int addr, int val); int rtc_get_memory(ISADevice *dev, int addr); +void qmp_rtc_reset_reinjection(Error **errp); =20 #endif /* HW_RTC_MC146818RTC_H */ diff --git a/hw/intc/apic_common.c b/hw/intc/apic_common.c index 2a20982066..b0f85f9384 100644 --- a/hw/intc/apic_common.c +++ b/hw/intc/apic_common.c @@ -33,7 +33,6 @@ #include "hw/sysbus.h" #include "migration/vmstate.h" =20 -static int apic_irq_delivered; bool apic_report_tpr_access; =20 void cpu_set_apic_base(DeviceState *dev, uint64_t val) @@ -122,32 +121,6 @@ void apic_handle_tpr_access_report(DeviceState *dev, t= arget_ulong ip, vapic_report_tpr_access(s->vapic, CPU(s->cpu), ip, access); } =20 -void apic_report_irq_delivered(int delivered) -{ - apic_irq_delivered +=3D delivered; - - trace_apic_report_irq_delivered(apic_irq_delivered); -} - -void apic_reset_irq_delivered(void) -{ - /* Copy this into a local variable to encourage gcc to emit a plain - * register for a sys/sdt.h marker. For details on this workaround, s= ee: - * https://sourceware.org/bugzilla/show_bug.cgi?id=3D13296 - */ - volatile int a_i_d =3D apic_irq_delivered; - trace_apic_reset_irq_delivered(a_i_d); - - apic_irq_delivered =3D 0; -} - -int apic_get_irq_delivered(void) -{ - trace_apic_get_irq_delivered(apic_irq_delivered); - - return apic_irq_delivered; -} - void apic_deliver_nmi(DeviceState *dev) { APICCommonState *s =3D APIC_COMMON(dev); diff --git a/hw/intc/apic_irqcount.c b/hw/intc/apic_irqcount.c new file mode 100644 index 0000000000..0aadef1cb5 --- /dev/null +++ b/hw/intc/apic_irqcount.c @@ -0,0 +1,53 @@ +/* + * APIC support - functions for counting the delivered IRQs. + * (this code is in a separate file since it is used from the + * mc146818rtc code on targets without APIC, too) + * + * Copyright (c) 2011 Jan Kiszka, Siemens AG + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "qemu/osdep.h" +#include "hw/i386/apic.h" +#include "trace.h" + +static int apic_irq_delivered; + +void apic_report_irq_delivered(int delivered) +{ + apic_irq_delivered +=3D delivered; + + trace_apic_report_irq_delivered(apic_irq_delivered); +} + +void apic_reset_irq_delivered(void) +{ + /* + * Copy this into a local variable to encourage gcc to emit a plain + * register for a sys/sdt.h marker. For details on this workaround, s= ee: + * https://sourceware.org/bugzilla/show_bug.cgi?id=3D13296 + */ + volatile int a_i_d =3D apic_irq_delivered; + trace_apic_reset_irq_delivered(a_i_d); + + apic_irq_delivered =3D 0; +} + +int apic_get_irq_delivered(void) +{ + trace_apic_get_irq_delivered(apic_irq_delivered); + + return apic_irq_delivered; +} diff --git a/hw/rtc/mc146818rtc.c b/hw/rtc/mc146818rtc.c index 1ebb412479..afb1f385a3 100644 --- a/hw/rtc/mc146818rtc.c +++ b/hw/rtc/mc146818rtc.c @@ -43,11 +43,7 @@ #include "qapi/qapi-events-misc.h" #include "qapi/visitor.h" #include "hw/rtc/mc146818rtc_regs.h" - -#ifdef TARGET_I386 -#include "qapi/qapi-commands-misc-target.h" #include "hw/i386/apic.h" -#endif =20 //#define DEBUG_CMOS //#define DEBUG_COALESCED @@ -112,7 +108,6 @@ static void rtc_coalesced_timer_update(RTCState *s) static QLIST_HEAD(, RTCState) rtc_devices =3D QLIST_HEAD_INITIALIZER(rtc_devices); =20 -#ifdef TARGET_I386 void qmp_rtc_reset_reinjection(Error **errp) { RTCState *s; @@ -145,13 +140,6 @@ static void rtc_coalesced_timer(void *opaque) =20 rtc_coalesced_timer_update(s); } -#else -static bool rtc_policy_slew_deliver_irq(RTCState *s) -{ - assert(0); - return false; -} -#endif =20 static uint32_t rtc_periodic_clock_ticks(RTCState *s) { @@ -922,14 +910,15 @@ static void rtc_realizefn(DeviceState *dev, Error **e= rrp) rtc_set_date_from_host(isadev); =20 switch (s->lost_tick_policy) { -#ifdef TARGET_I386 - case LOST_TICK_POLICY_SLEW: - s->coalesced_timer =3D - timer_new_ns(rtc_clock, rtc_coalesced_timer, s); - break; -#endif case LOST_TICK_POLICY_DISCARD: break; + case LOST_TICK_POLICY_SLEW: + /* Slew tick policy is only available if the machine has an APIC */ + if (object_resolve_path_type("", "apic-common", NULL) !=3D NULL) { + s->coalesced_timer =3D timer_new_ns(rtc_clock, rtc_coalesced_t= imer, s); + break; + } + /* fallthrough */ default: error_setg(errp, "Invalid lost tick policy."); return; diff --git a/hw/intc/meson.build b/hw/intc/meson.build index bcbf22ff51..036ad1936b 100644 --- a/hw/intc/meson.build +++ b/hw/intc/meson.build @@ -25,8 +25,12 @@ softmmu_ss.add(when: 'CONFIG_XILINX', if_true: files('xi= linx_intc.c')) softmmu_ss.add(when: 'CONFIG_XLNX_ZYNQMP', if_true: files('xlnx-zynqmp-ipi= .c')) softmmu_ss.add(when: 'CONFIG_XLNX_ZYNQMP_PMU', if_true: files('xlnx-pmu-io= mod-intc.c')) =20 -specific_ss.add(when: 'CONFIG_ALLWINNER_A10_PIC', if_true: files('allwinne= r-a10-pic.c')) +if config_all_devices.has_key('CONFIG_APIC') or config_all_devices.has_key= ('CONFIG_MC146818RTC') + softmmu_ss.add(files('apic_irqcount.c')) +endif specific_ss.add(when: 'CONFIG_APIC', if_true: files('apic.c', 'apic_common= .c')) + +specific_ss.add(when: 'CONFIG_ALLWINNER_A10_PIC', if_true: files('allwinne= r-a10-pic.c')) specific_ss.add(when: 'CONFIG_ARM_GIC', if_true: files('arm_gicv3_cpuif_co= mmon.c')) specific_ss.add(when: 'CONFIG_ARM_GICV3_TCG', if_true: files('arm_gicv3_cp= uif.c')) specific_ss.add(when: 'CONFIG_ARM_GIC_KVM', if_true: files('arm_gic_kvm.c'= )) diff --git a/hw/rtc/meson.build b/hw/rtc/meson.build index dc33973384..34a4d316fa 100644 --- a/hw/rtc/meson.build +++ b/hw/rtc/meson.build @@ -13,5 +13,4 @@ softmmu_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files(= 'aspeed_rtc.c')) softmmu_ss.add(when: 'CONFIG_GOLDFISH_RTC', if_true: files('goldfish_rtc.c= ')) softmmu_ss.add(when: 'CONFIG_LS7A_RTC', if_true: files('ls7a_rtc.c')) softmmu_ss.add(when: 'CONFIG_ALLWINNER_H3', if_true: files('allwinner-rtc.= c')) - -specific_ss.add(when: 'CONFIG_MC146818RTC', if_true: files('mc146818rtc.c'= )) +softmmu_ss.add(when: 'CONFIG_MC146818RTC', if_true: files('mc146818rtc.c')) --=20 2.31.1