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: 749906 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3w2zmP1qr6z9rxm for ; Wed, 12 Apr 2017 19:54:45 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="qRTA+MKr"; dkim-atps=neutral Received: from localhost ([::1]:43240 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cyEz4-0007EY-Jb for incoming@patchwork.ozlabs.org; Wed, 12 Apr 2017 05:54:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51367) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cyEwX-0005aP-VG for qemu-devel@nongnu.org; Wed, 12 Apr 2017 05:52:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cyEwW-0004oI-Ij for qemu-devel@nongnu.org; Wed, 12 Apr 2017 05:52:06 -0400 Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]:35286) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cyEwW-0004nf-As for qemu-devel@nongnu.org; Wed, 12 Apr 2017 05:52:04 -0400 Received: by mail-pf0-x243.google.com with SMTP id a188so4059452pfa.2 for ; Wed, 12 Apr 2017 02:52:04 -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=GGcP2s8KnmDUuetfPWXr3VXLNKl2JCnlHKk3gyCKQllWuJOiTyJ2IborfiPGd2/WxP TgPLZMqcfiEz9a1p972cUiOxwPD1hc+6hyIvqA3SrYmwEMip1gzRG3AZw7lek95NQOXC BgqHzZ6g/vHhp4nrQDYAawSwtoR02/WijbbbWcO+p5FkSwhZ9n5OY5JUA9Jx49Y2twKR EOfCC+D+qhNi7tqRltSr+g3rf8GNqKfQVt+t5gx+vSivWg1+MWuvCqwMMLKnnKEKazbR PJ5PXY63J2IdB833fEbL9ioz/0v0X8Yx/Radu5q2amo9UPpA/aA51mJCQlKDCKaX8wP3 D2XA== X-Gm-Message-State: AFeK/H1IqMi9wGh7aN1GvZSJpmfzw/dRaA6kcwWMRY+AEgBYkhZKa1Iw+rXgCSmckgebow== 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 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> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::243 Subject: [Qemu-devel] [PATCH 5/5] mc146818rtc: embrace all x86 specific code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Xiao Guangrong , yunfangtai@tencent.com, qemu-devel@nongnu.org, kvm@vger.kernel.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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);