From: Gleb Natapov <gleb@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH] s3: wake up on RTC event
Date: Tue, 5 Mar 2013 14:27:02 +0200 [thread overview]
Message-ID: <20130305122702.GA11223@redhat.com> (raw)
In-Reply-To: <1362474978-17353-1-git-send-email-pbonzini@redhat.com>
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.
next prev parent reply other threads:[~2013-03-05 12:27 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-05 9:16 [PATCH] s3: wake up on RTC event Paolo Bonzini
2013-03-05 12:27 ` Gleb Natapov [this message]
2013-03-06 0:55 ` Marcelo Tosatti
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=20130305122702.GA11223@redhat.com \
--to=gleb@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.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