From patchwork Wed Apr 12 09:51:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 9676927 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9F73A60382 for ; Wed, 12 Apr 2017 09:52:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F42A2855A for ; Wed, 12 Apr 2017 09:52:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 83E19285D3; Wed, 12 Apr 2017 09:52:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E9C642855A for ; Wed, 12 Apr 2017 09:52:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753002AbdDLJwK (ORCPT ); Wed, 12 Apr 2017 05:52:10 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:36399 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752852AbdDLJwE (ORCPT ); Wed, 12 Apr 2017 05:52:04 -0400 Received: by mail-pf0-f196.google.com with SMTP id i5so4042722pfc.3 for ; Wed, 12 Apr 2017 02:52:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=CUt7N+WQwV29GnvX3YwvHLD7J/l2NBkYag8VuOslczw=; b=qRTA+MKr3ks6bJDNdySlIQhYDs49clEnIOfsttZK8ozJaiLOk6ouY/aDTYJS4TEhHH y5uaNi6KhhbY+OEjuN1kLym0Z9VbSlliuVgzbjCJbeoi0pthJIlTCT9GfISYdxUq9Wik ky70wm0JjUXqh3H4CXl2U7POeIhrDozeM8bE5XzbcJPPRnaNFnRwTdz5ymjS+YObCnYF ngRNOLeYKUmGBt7BgTRnewjp061MJIZOke0OMlUTGitNslGxczkfsKjVhoHDtLvM7wAh YNMjTBegDWbRf1gbIfyxVloIgWWf8VrnYr3aoytUQ6zpQhFiIfbZiktnx3DDcXfe+LVs 8/6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=CUt7N+WQwV29GnvX3YwvHLD7J/l2NBkYag8VuOslczw=; b=uf9ThOetf9Cf/be/bFmvmmEdRIC9KCCbEIWBbfztgmBVcLsZzJer3/xVYDLr7ExRNZ AN6csBkx8GQxrKCnbHW3ZFzZcxWB2B+/0hfPTnBWDBJvC+gTAeQ3xpX3y9B3eNJjREbK LOBcPv1uHq45u8IbeNh3qQadBN4CRMJv8OGhrMyojn6KuZEdpcSsm+SrgXvW153W81lh 1aBG/sRVsHG+TI2s9mCDSUDvnYcWD3B7ffXQsOILzDZKUGHoAuSLj8HkbS/OvzN6aKFN IBEjhsr5y208FYJtVfPNuCEDj4G87l9Egqdwfv5x/HHZ7xiRsqEywiGBbydh4qpqkRaI OB+w== X-Gm-Message-State: AFeK/H3U6PKZ1DMvWbeV7KPF038B0pxjTpp4+WdQGVd3OEaLUbIFTNNVwlf6UtnE1MxLhQ== X-Received: by 10.98.156.23 with SMTP id f23mr64892370pfe.3.1491990723339; Wed, 12 Apr 2017 02:52:03 -0700 (PDT) Received: from eric.tencent.com ([103.7.29.8]) by smtp.gmail.com with ESMTPSA id 4sm35445749pff.17.2017.04.12.02.52.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Apr 2017 02:52:02 -0700 (PDT) From: guangrong.xiao@gmail.com X-Google-Original-From: xiaoguangrong@tencent.com To: pbonzini@redhat.com, mst@redhat.com, mtosatti@redhat.com Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, yunfangtai@tencent.com, Xiao Guangrong Subject: [PATCH 5/5] mc146818rtc: embrace all x86 specific code Date: Wed, 12 Apr 2017 17:51:11 +0800 Message-Id: <20170412095111.11728-6-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170412095111.11728-1-xiaoguangrong@tencent.com> References: <20170412095111.11728-1-xiaoguangrong@tencent.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Xiao Guangrong This patch introduces proper hooks in the common code then moves x86 specific code into a single '#ifdef TARGET_I386' The real logic is not touched Signed-off-by: Xiao Guangrong --- hw/timer/mc146818rtc.c | 197 ++++++++++++++++++++++++++++++------------------- 1 file changed, 122 insertions(+), 75 deletions(-) diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c index d7b7c56..5cb4621 100644 --- a/hw/timer/mc146818rtc.c +++ b/hw/timer/mc146818rtc.c @@ -112,6 +112,9 @@ static uint64_t get_guest_rtc_ns(RTCState *s) guest_clock - s->last_update + s->offset; } +static QLIST_HEAD(, RTCState) rtc_devices = + QLIST_HEAD_INITIALIZER(rtc_devices); + #ifdef TARGET_I386 static void rtc_coalesced_timer_update(RTCState *s) { @@ -145,6 +148,15 @@ static void rtc_coalesced_timer(void *opaque) rtc_coalesced_timer_update(s); } +void qmp_rtc_reset_reinjection(Error **errp) +{ + RTCState *s; + + QLIST_FOREACH(s, &rtc_devices, link) { + s->irq_coalesced = 0; + } +} + static int64_t arch_periodic_timer_update(RTCState *s, int period, int64_t lost_clock) { @@ -191,6 +203,83 @@ static void arch_periodic_timer_disable(RTCState *s) { s->irq_coalesced = 0; } + +static void arch_rtc_periodic_timer(RTCState *s) +{ + if (s->lost_tick_policy == LOST_TICK_POLICY_SLEW) { + if (s->irq_reinject_on_ack_count >= RTC_REINJECT_ON_ACK_COUNT) { + s->irq_reinject_on_ack_count = 0; + } + apic_reset_irq_delivered(); + qemu_irq_raise(s->irq); + if (!apic_get_irq_delivered()) { + s->irq_coalesced++; + rtc_coalesced_timer_update(s); + DPRINTF_C("cmos: coalesced irqs increased to %d\n", + s->irq_coalesced); + } + } else { + qemu_irq_raise(s->irq); + } +} + +static void arch_read_regC(RTCState *s) +{ + if (s->irq_coalesced && (s->cmos_data[RTC_REG_B] & REG_B_PIE) && + s->irq_reinject_on_ack_count < RTC_REINJECT_ON_ACK_COUNT) { + s->irq_reinject_on_ack_count++; + s->cmos_data[RTC_REG_C] |= REG_C_IRQF | REG_C_PF; + apic_reset_irq_delivered(); + DPRINTF_C("cmos: injecting on ack\n"); + qemu_irq_raise(s->irq); + if (apic_get_irq_delivered()) { + s->irq_coalesced--; + DPRINTF_C("cmos: coalesced irqs decreased to %d\n", + s->irq_coalesced); + } + } +} + +static void arch_rtc_post_load(RTCState *s, int version_id) +{ + if (version_id >= 2) { + if (s->lost_tick_policy == LOST_TICK_POLICY_SLEW) { + rtc_coalesced_timer_update(s); + } + } +} + +static void arch_rtc_notify_clock_reset(RTCState *s) +{ + if (s->lost_tick_policy == LOST_TICK_POLICY_SLEW) { + rtc_coalesced_timer_update(s); + } +} + +static void arch_rtc_reset(RTCState *s) +{ + if (s->lost_tick_policy == LOST_TICK_POLICY_SLEW) { + s->irq_coalesced = 0; + s->irq_reinject_on_ack_count = 0; + } +} + +static bool arch_rtc_realizefn(RTCState *s, Error **errp) +{ + switch (s->lost_tick_policy) { + case LOST_TICK_POLICY_SLEW: + s->coalesced_timer = + timer_new_ns(rtc_clock, rtc_coalesced_timer, s); + break; + case LOST_TICK_POLICY_DISCARD: + break; + default: + error_setg(errp, "Invalid lost tick policy."); + return false; + } + + return true; +} #else static int64_t arch_periodic_timer_update(RTCState *s, int period, int64_t lost_clock) @@ -201,6 +290,32 @@ arch_periodic_timer_update(RTCState *s, int period, int64_t lost_clock) static void arch_periodic_timer_disable(RTCState *s) { } + +static void arch_rtc_periodic_timer(RTCState *s) +{ + qemu_irq_raise(s->irq); +} + +static void arch_read_regC(RTCState *s) +{ +} + +static void arch_rtc_post_load(RTCState *s, int version_id) +{ +} + +static void arch_rtc_notify_clock_reset(RTCState *s) +{ +} + +static void arch_rtc_reset(RTCState *s) +{ +} + +static bool arch_rtc_realizefn(RTCState *s, Error **errp) +{ + return true; +} #endif static int period_code_to_clock(int period_code) @@ -287,21 +402,7 @@ static void rtc_periodic_timer(void *opaque) s->cmos_data[RTC_REG_C] |= REG_C_PF; if (s->cmos_data[RTC_REG_B] & REG_B_PIE) { s->cmos_data[RTC_REG_C] |= REG_C_IRQF; -#ifdef TARGET_I386 - if (s->lost_tick_policy == LOST_TICK_POLICY_SLEW) { - if (s->irq_reinject_on_ack_count >= RTC_REINJECT_ON_ACK_COUNT) - s->irq_reinject_on_ack_count = 0; - apic_reset_irq_delivered(); - qemu_irq_raise(s->irq); - if (!apic_get_irq_delivered()) { - s->irq_coalesced++; - rtc_coalesced_timer_update(s); - DPRINTF_C("cmos: coalesced irqs increased to %d\n", - s->irq_coalesced); - } - } else -#endif - qemu_irq_raise(s->irq); + arch_rtc_periodic_timer(s); } } @@ -656,20 +757,6 @@ static void rtc_get_time(RTCState *s, struct tm *tm) rtc_from_bcd(s, s->cmos_data[RTC_CENTURY]) * 100 - 1900; } -static QLIST_HEAD(, RTCState) rtc_devices = - QLIST_HEAD_INITIALIZER(rtc_devices); - -#ifdef TARGET_I386 -void qmp_rtc_reset_reinjection(Error **errp) -{ - RTCState *s; - - QLIST_FOREACH(s, &rtc_devices, link) { - s->irq_coalesced = 0; - } -} -#endif - static void rtc_set_time(RTCState *s) { struct tm tm; @@ -789,22 +876,8 @@ static uint64_t cmos_ioport_read(void *opaque, hwaddr addr, if (ret & (REG_C_UF | REG_C_AF)) { check_update_timer(s); } -#ifdef TARGET_I386 - if(s->irq_coalesced && - (s->cmos_data[RTC_REG_B] & REG_B_PIE) && - s->irq_reinject_on_ack_count < RTC_REINJECT_ON_ACK_COUNT) { - s->irq_reinject_on_ack_count++; - s->cmos_data[RTC_REG_C] |= REG_C_IRQF | REG_C_PF; - apic_reset_irq_delivered(); - DPRINTF_C("cmos: injecting on ack\n"); - qemu_irq_raise(s->irq); - if (apic_get_irq_delivered()) { - s->irq_coalesced--; - DPRINTF_C("cmos: coalesced irqs decreased to %d\n", - s->irq_coalesced); - } - } -#endif + + arch_read_regC(s); break; default: ret = s->cmos_data[s->cmos_index]; @@ -874,13 +947,7 @@ static int rtc_post_load(void *opaque, int version_id) } } -#ifdef TARGET_I386 - if (version_id >= 2) { - if (s->lost_tick_policy == LOST_TICK_POLICY_SLEW) { - rtc_coalesced_timer_update(s); - } - } -#endif + arch_rtc_post_load(s, version_id); return 0; } @@ -937,11 +1004,7 @@ static void rtc_notify_clock_reset(Notifier *notifier, void *data) rtc_set_date_from_host(ISA_DEVICE(s)); periodic_timer_update(s, now, 0); check_update_timer(s); -#ifdef TARGET_I386 - if (s->lost_tick_policy == LOST_TICK_POLICY_SLEW) { - rtc_coalesced_timer_update(s); - } -#endif + arch_rtc_notify_clock_reset(s); } /* set CMOS shutdown status register (index 0xF) as S3_resume(0xFE) @@ -961,13 +1024,7 @@ static void rtc_reset(void *opaque) check_update_timer(s); qemu_irq_lower(s->irq); - -#ifdef TARGET_I386 - if (s->lost_tick_policy == LOST_TICK_POLICY_SLEW) { - s->irq_coalesced = 0; - s->irq_reinject_on_ack_count = 0; - } -#endif + arch_rtc_reset(s); } static const MemoryRegionOps cmos_ops = { @@ -1013,19 +1070,9 @@ static void rtc_realizefn(DeviceState *dev, Error **errp) rtc_set_date_from_host(isadev); -#ifdef TARGET_I386 - switch (s->lost_tick_policy) { - case LOST_TICK_POLICY_SLEW: - s->coalesced_timer = - timer_new_ns(rtc_clock, rtc_coalesced_timer, s); - break; - case LOST_TICK_POLICY_DISCARD: - break; - default: - error_setg(errp, "Invalid lost tick policy."); + if (!arch_rtc_realizefn(s, errp)) { return; } -#endif s->periodic_timer = timer_new_ns(rtc_clock, rtc_periodic_timer, s); s->update_timer = timer_new_ns(rtc_clock, rtc_update_timer, s);