public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] s3: wake up on RTC event
@ 2013-03-05  9:16 Paolo Bonzini
  2013-03-05 12:27 ` Gleb Natapov
  2013-03-06  0:55 ` Marcelo Tosatti
  0 siblings, 2 replies; 3+ messages in thread
From: Paolo Bonzini @ 2013-03-05  9:16 UTC (permalink / raw)
  To: kvm

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 <pbonzini@redhat.com>
---
 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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] s3: wake up on RTC event
  2013-03-05  9:16 [PATCH] s3: wake up on RTC event Paolo Bonzini
@ 2013-03-05 12:27 ` Gleb Natapov
  2013-03-06  0:55 ` Marcelo Tosatti
  1 sibling, 0 replies; 3+ messages in thread
From: Gleb Natapov @ 2013-03-05 12:27 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: kvm

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 <pbonzini@redhat.com>
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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] s3: wake up on RTC event
  2013-03-05  9:16 [PATCH] s3: wake up on RTC event Paolo Bonzini
  2013-03-05 12:27 ` Gleb Natapov
@ 2013-03-06  0:55 ` Marcelo Tosatti
  1 sibling, 0 replies; 3+ messages in thread
From: Marcelo Tosatti @ 2013-03-06  0:55 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: kvm

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 <pbonzini@redhat.com>
> ---
>  x86/s3.c | 36 ++++++++++++++++++++++++++++++++++++
>  1 file changed, 36 insertions(+)

Applied, thanks.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-03-06  1:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-05  9:16 [PATCH] s3: wake up on RTC event Paolo Bonzini
2013-03-05 12:27 ` Gleb Natapov
2013-03-06  0:55 ` Marcelo Tosatti

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox