kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pekka Enberg <penberg@kernel.org>
To: kvm@vger.kernel.org
Cc: Pekka Enberg <penberg@kernel.org>, Ingo Molnar <mingo@kernel.org>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Ron Minnich <rminnich@gmail.com>,
	Asias He <asias.hejun@gmail.com>,
	Cyrill Gorcunov <gorcunov@openvz.org>,
	Sasha Levin <levinsasha928@gmail.com>
Subject: [PATCH] kvm tools: Fix reported RTC century and year
Date: Thu, 25 Oct 2012 09:39:19 +0300	[thread overview]
Message-ID: <1351147159-28849-1-git-send-email-penberg@kernel.org> (raw)

Commit 13d5097 ("kvm tools: Fix reported year in RTC emulation)
attempted to fix wrongly reported RTC year. However, as pointed out by
hpa the proper way to deal with this is to support the RTC century
field.

Suggested-by: H. Peter Anvin <hpa@zytor.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Ron Minnich <rminnich@gmail.com>
Cc: Asias He <asias.hejun@gmail.com>
Cc: Cyrill Gorcunov <gorcunov@openvz.org>
Cc: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
---
 tools/kvm/hw/rtc.c |   30 ++++++++++++++++++------------
 1 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/tools/kvm/hw/rtc.c b/tools/kvm/hw/rtc.c
index 4a862d6..5232bd7 100644
--- a/tools/kvm/hw/rtc.c
+++ b/tools/kvm/hw/rtc.c
@@ -18,6 +18,7 @@
 #define RTC_DAY_OF_MONTH		0x07
 #define RTC_MONTH			0x08
 #define RTC_YEAR			0x09
+#define RTC_CENTURY			0x32
 
 #define RTC_REG_A			0x0A
 #define RTC_REG_B			0x0B
@@ -40,7 +41,6 @@ static bool cmos_ram_data_in(struct ioport *ioport, struct kvm *kvm, u16 port, v
 {
 	struct tm *tm;
 	time_t ti;
-	int year;
 
 	time(&ti);
 
@@ -65,18 +65,24 @@ static bool cmos_ram_data_in(struct ioport *ioport, struct kvm *kvm, u16 port, v
 	case RTC_MONTH:
 		ioport__write8(data, bin2bcd(tm->tm_mon + 1));
 		break;
-	case RTC_YEAR:
-		/*
-		 * The gmtime() function returns time since 1900. The CMOS
-		 * standard is time since 2000. If the year is < 100, do
-		 * nothing; if it is > 100, subtract 100; this is the best fit
-		 * with the twisted CMOS logic.
-		 */
-		year = tm->tm_year;
-		if (year > 99)
-			year -= 100;
-		ioport__write8(data, bin2bcd(year));
+	case RTC_YEAR: {
+		int year;
+
+		year = tm->tm_year + 1900;
+
+		ioport__write8(data, bin2bcd(year % 100));
+
 		break;
+	}
+	case RTC_CENTURY: {
+		int year;
+
+		year = tm->tm_year + 1900;
+
+		ioport__write8(data, bin2bcd(year / 100));
+
+		break;
+	}
 	default:
 		ioport__write8(data, rtc.cmos_data[rtc.cmos_idx]);
 		break;
-- 
1.7.7.6


                 reply	other threads:[~2012-10-25  6:39 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1351147159-28849-1-git-send-email-penberg@kernel.org \
    --to=penberg@kernel.org \
    --cc=asias.hejun@gmail.com \
    --cc=gorcunov@openvz.org \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=levinsasha928@gmail.com \
    --cc=mingo@kernel.org \
    --cc=rminnich@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).