From patchwork Thu Oct 25 06:39:19 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pekka Enberg X-Patchwork-Id: 1642091 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id AD9F4DF264 for ; Thu, 25 Oct 2012 06:39:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754303Ab2JYGj1 (ORCPT ); Thu, 25 Oct 2012 02:39:27 -0400 Received: from mail-la0-f46.google.com ([209.85.215.46]:65353 "EHLO mail-la0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751976Ab2JYGj0 (ORCPT ); Thu, 25 Oct 2012 02:39:26 -0400 Received: by mail-la0-f46.google.com with SMTP id h6so1027803lag.19 for ; Wed, 24 Oct 2012 23:39:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer; bh=reuXCpFooUQgV3bUVY7mLHGGuUWp3qNLSGLrMtpuNzY=; b=wgqRZ76KpoMoI9y9rMY6uXuN2o5ZPiBh6x0ifjJ/cYI08nomU0BtoGYW4Fn9Snb6zr j2gA5fMiqeKHCD6dHbfsaJpu1VOuH9oCWhAxh8bgI+5z+icQEQp5vNgluwnJcaPzV8ZR /0/ZnnRBLFLb3cjgUKTMdzAlrypI2ZyCfDwxNpuF1VBFlQ6QkCmNO1hn7jD7zLhIlmVt ww7xLVWQ+KeGk4VYniA8b2nEa0OigQn1VzERmP5P8AFm2N2bYsv8JwKv8xc3C0/7uASV mzdj8gzWXhv3PNQUfGp8UEBWuQSxqGnoxGrP3Zv7bnLxn0Qym48Lwo7A+FCvZrqZYhV2 CXsA== Received: by 10.112.101.131 with SMTP id fg3mr7404426lbb.12.1351147164523; Wed, 24 Oct 2012 23:39:24 -0700 (PDT) Received: from tux.office.valotrading.com ([62.236.217.108]) by mx.google.com with ESMTPS id g5sm5563883lbk.7.2012.10.24.23.39.23 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 24 Oct 2012 23:39:24 -0700 (PDT) From: Pekka Enberg To: kvm@vger.kernel.org Cc: Pekka Enberg , Ingo Molnar , "H. Peter Anvin" , Ron Minnich , Asias He , Cyrill Gorcunov , Sasha Levin Subject: [PATCH] kvm tools: Fix reported RTC century and year Date: Thu, 25 Oct 2012 09:39:19 +0300 Message-Id: <1351147159-28849-1-git-send-email-penberg@kernel.org> X-Mailer: git-send-email 1.7.7.6 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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 Cc: Ingo Molnar Cc: H. Peter Anvin Cc: Ron Minnich Cc: Asias He Cc: Cyrill Gorcunov Cc: Sasha Levin Signed-off-by: Pekka Enberg --- 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;