From patchwork Mon Mar 19 06:14:03 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Yang Z" X-Patchwork-Id: 147524 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C8034B6EE7 for ; Tue, 20 Mar 2012 00:50:43 +1100 (EST) Received: from localhost ([::1]:49228 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9cyv-0004II-O4 for incoming@patchwork.ozlabs.org; Mon, 19 Mar 2012 09:50:41 -0400 Received: from eggs.gnu.org ([208.118.235.92]:54548) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9VrC-0005KV-Iw for qemu-devel@nongnu.org; Mon, 19 Mar 2012 02:14:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S9Vr5-0001T0-3W for qemu-devel@nongnu.org; Mon, 19 Mar 2012 02:14:14 -0400 Received: from mga14.intel.com ([143.182.124.37]:54987) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9Vr4-0001SF-TK for qemu-devel@nongnu.org; Mon, 19 Mar 2012 02:14:07 -0400 Received: from azsmga001.ch.intel.com ([10.2.17.19]) by azsmga102.ch.intel.com with ESMTP; 18 Mar 2012 23:14:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.71,315,1320652800"; d="scan'208";a="120496744" Received: from azsmsx603.amr.corp.intel.com ([10.2.161.23]) by azsmga001.ch.intel.com with ESMTP; 18 Mar 2012 23:14:05 -0700 Received: from chspprodmsx101.amr.corp.intel.com (10.2.67.97) by azsmsx603.amr.corp.intel.com (10.2.161.23) with Microsoft SMTP Server (TLS) id 8.2.255.0; Sun, 18 Mar 2012 23:14:05 -0700 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by CHSPPRODMSX101.amr.corp.intel.com (10.2.67.97) with Microsoft SMTP Server (TLS) id 14.1.355.2; Sun, 18 Mar 2012 23:14:05 -0700 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.142]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.91]) with mapi id 14.01.0355.002; Mon, 19 Mar 2012 14:14:04 +0800 From: "Zhang, Yang Z" To: "qemu-devel@nongnu.org" Thread-Topic: [PATCH v4 3/7] RTC: Add UIP(update in progress) check logic Thread-Index: Ac0Fl3pK4bbltCneSZCkHuDOfpR3tw== Date: Mon, 19 Mar 2012 06:14:03 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 143.182.124.37 X-Mailman-Approved-At: Mon, 19 Mar 2012 09:50:26 -0400 Cc: Paolo Bonzini , "aliguori@us.ibm.com" , "kvm@vger.kernel.org" Subject: [Qemu-devel] [PATCH v4 3/7] RTC: Add UIP(update in progress) check logic X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The UIP(update in progress) is set when RTC is updating. And the update cycle begins 244us later after UIP is set. And it is cleared when update end. Signed-off-by: Yang Zhang --- hw/mc146818rtc.c | 18 ++++++++++++++++++ 1 files changed, 18 insertions(+), 0 deletions(-) -- 1.7.1 diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c index 82a5b8a..6ebb8f6 100644 --- a/hw/mc146818rtc.c +++ b/hw/mc146818rtc.c @@ -377,6 +377,21 @@ static void rtc_calibrate_time(RTCState *s) s->current_tm = *ret; } +static int update_in_progress(RTCState *s) +{ + int64_t guest_usec; + + if (s->cmos_data[RTC_REG_B] & REG_B_SET) { + return 0; + } + guest_usec = get_guest_rtc_us(s); + /* UIP bit will be set at last 244us of every second. */ + if ((guest_usec % USEC_PER_SEC) >= (USEC_PER_SEC - 244)) { + return 1; + } + return 0; +} + static uint32_t cmos_ioport_read(void *opaque, uint32_t addr) { RTCState *s = opaque; @@ -402,6 +417,9 @@ static uint32_t cmos_ioport_read(void *opaque, uint32_t addr) break; case RTC_REG_A: ret = s->cmos_data[s->cmos_index]; + if (update_in_progress(s)) { + ret |= REG_A_UIP; + } break; case RTC_REG_C: ret = s->cmos_data[s->cmos_index];