From patchwork Tue Mar 5 09:16:18 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 2218271 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 7EB3B3FCF2 for ; Tue, 5 Mar 2013 09:16:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755451Ab3CEJQ0 (ORCPT ); Tue, 5 Mar 2013 04:16:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59665 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755429Ab3CEJQW (ORCPT ); Tue, 5 Mar 2013 04:16:22 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r259GMSb027126 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 5 Mar 2013 04:16:22 -0500 Received: from yakj.usersys.redhat.com (ovpn-112-30.ams2.redhat.com [10.36.112.30]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r259GKkw026466 for ; Tue, 5 Mar 2013 04:16:21 -0500 From: Paolo Bonzini To: kvm@vger.kernel.org Subject: [PATCH] s3: wake up on RTC event Date: Tue, 5 Mar 2013 10:16:18 +0100 Message-Id: <1362474978-17353-1-git-send-email-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The S3 test requires user interaction to terminate. Set up the RTC alarm instead, so that the test will end after one second. Signed-off-by: Paolo Bonzini --- x86/s3.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/x86/s3.c b/x86/s3.c index d7df92d..30634bb 100644 --- a/x86/s3.c +++ b/x86/s3.c @@ -127,6 +127,32 @@ u32* find_resume_vector_addr(void) return 0; } +#define RTC_SECONDS_ALARM 1 +#define RTC_MINUTES_ALARM 3 +#define RTC_HOURS_ALARM 5 +#define RTC_ALARM_DONT_CARE 0xC0 + +#define RTC_REG_A 10 +#define RTC_REG_B 11 +#define RTC_REG_C 12 + +#define REG_A_UIP 0x80 +#define REG_B_AIE 0x20 + +static inline int rtc_in(u8 reg) +{ + u8 x = reg; + asm volatile("outb %b1, $0x70; inb $0x71, %b0" + : "+a"(x) : "0"(x)); + return x; +} + +static inline void rtc_out(u8 reg, u8 val) +{ + asm volatile("outb %b1, $0x70; mov %b2, %b1; outb %b1, $0x71" + : "+a"(reg) : "0"(reg), "ri"(val)); +} + extern char resume_start, resume_end; int main(int argc, char **argv) @@ -140,6 +166,16 @@ int main(int argc, char **argv) for (addr = &resume_start; addr < &resume_end; addr++) *resume_vec++ = *addr; printf("copy resume code from %x\n", &resume_start); + + /* Setup RTC alarm to wake up on the next second. */ + while ((rtc_in(RTC_REG_A) & REG_A_UIP) == 0); + while ((rtc_in(RTC_REG_A) & REG_A_UIP) != 0); + rtc_in(RTC_REG_C); + rtc_out(RTC_SECONDS_ALARM, RTC_ALARM_DONT_CARE); + rtc_out(RTC_MINUTES_ALARM, RTC_ALARM_DONT_CARE); + rtc_out(RTC_HOURS_ALARM, RTC_ALARM_DONT_CARE); + rtc_out(RTC_REG_B, rtc_in(RTC_REG_B) | REG_B_AIE); + *(volatile int*)0 = 0; asm volatile("out %0, %1" :: "a"(0x2400), "d"((short)0xb004):"memory"); while(1)