From patchwork Thu May 17 02:28:53 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: 159800 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 CC401B6FB9 for ; Thu, 17 May 2012 12:29:26 +1000 (EST) Received: from localhost ([::1]:44356 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SUqSy-0004Bt-2b for incoming@patchwork.ozlabs.org; Wed, 16 May 2012 22:29:24 -0400 Received: from eggs.gnu.org ([208.118.235.92]:47726) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SUqSj-00045y-8T for qemu-devel@nongnu.org; Wed, 16 May 2012 22:29:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SUqSh-0007gZ-GY for qemu-devel@nongnu.org; Wed, 16 May 2012 22:29:08 -0400 Received: from mga14.intel.com ([143.182.124.37]:62544) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SUqSh-0007fy-AD for qemu-devel@nongnu.org; Wed, 16 May 2012 22:29:07 -0400 Received: from azsmga001.ch.intel.com ([10.2.17.19]) by azsmga102.ch.intel.com with ESMTP; 16 May 2012 19:29:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.71,315,1320652800"; d="scan'208";a="144183521" Received: from azsmsx601.amr.corp.intel.com ([10.2.121.193]) by azsmga001.ch.intel.com with ESMTP; 16 May 2012 19:29:06 -0700 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by azsmsx601.amr.corp.intel.com (10.2.121.193) with Microsoft SMTP Server (TLS) id 8.2.255.0; Wed, 16 May 2012 19:29:05 -0700 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.6]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.90]) with mapi id 14.01.0355.002; Thu, 17 May 2012 10:28:53 +0800 From: "Zhang, Yang Z" To: "'qemu-devel@nongnu.org'" Thread-Topic: [PATCH v6 3/7] RTC: Add UIP(update in progress) check logic Thread-Index: Ac0z1M07pkj3bcK1QPaYfN3g5MutjA== Date: Thu, 17 May 2012 02:28:53 +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 Cc: 'Paolo Bonzini' , "'aliguori@us.ibm.com'" , "'qemu-devel@nongnu.org'" Subject: [Qemu-devel] [PATCH v6 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 will be set when updating cycle begins and cleared after updated cycle ended. 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 24db5cf..b03c420 100644 --- a/hw/mc146818rtc.c +++ b/hw/mc146818rtc.c @@ -344,6 +344,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; @@ -369,6 +384,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];