From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gleb Natapov Subject: Re: [PATCH] s3: wake up on RTC event Date: Tue, 5 Mar 2013 14:27:02 +0200 Message-ID: <20130305122702.GA11223@redhat.com> References: <1362474978-17353-1-git-send-email-pbonzini@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: kvm@vger.kernel.org To: Paolo Bonzini Return-path: Received: from mx1.redhat.com ([209.132.183.28]:42321 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753270Ab3CEM1D (ORCPT ); Tue, 5 Mar 2013 07:27:03 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r25CR3ox015277 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 5 Mar 2013 07:27:03 -0500 Content-Disposition: inline In-Reply-To: <1362474978-17353-1-git-send-email-pbonzini@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On Tue, Mar 05, 2013 at 10:16:18AM +0100, Paolo Bonzini wrote: > 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 Heh, nice! > --- > 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) > -- > 1.8.1.2 > > -- > To unsubscribe from this list: send the line "unsubscribe kvm" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html -- Gleb.