From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Zhang, Yang Z" <yang.z.zhang@intel.com>
Subject: [Qemu-devel] [PATCH 5/7] RTC: Add divider reset support
Date: Fri, 20 Jul 2012 12:53:51 +0200 [thread overview]
Message-ID: <1342781633-7288-6-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1342781633-7288-1-git-send-email-pbonzini@redhat.com>
From: "Zhang, Yang Z" <yang.z.zhang@intel.com>
The first update cycle begins one-half seconds after divider
reset is removed. This feature is useful for testing.
Signed-off-by: Yang Zhang <yang.z.zhang@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/mc146818rtc.c | 50 +++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 41 insertions(+), 9 deletions(-)
diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c
index 3a99605..1ab0dc6 100644
--- a/hw/mc146818rtc.c
+++ b/hw/mc146818rtc.c
@@ -81,6 +81,12 @@ static void rtc_update_time(RTCState *s);
static void rtc_set_cmos(RTCState *s);
static inline int rtc_from_bcd(RTCState *s, int a);
+static inline bool rtc_running(RTCState *s)
+{
+ return (!(s->cmos_data[RTC_REG_B] & REG_B_SET) &&
+ (s->cmos_data[RTC_REG_A] & 0x70) <= 0x20);
+}
+
static uint64_t get_guest_rtc_ns(RTCState *s)
{
uint64_t guest_rtc;
@@ -197,11 +203,15 @@ static void check_update_timer(RTCState *s)
uint64_t next_update_time;
uint64_t guest_nsec;
- /* From the data sheet: setting the SET bit does not prevent
- * interrupts from occurring! However, it will prevent an
- * alarm interrupt from occurring, because the time of day is
- * not updated.
+ /* From the data sheet: "Holding the dividers in reset prevents
+ * interrupts from operating, while setting the SET bit allows"
+ * them to occur. However, it will prevent an alarm interrupt
+ * from occurring, because the time of day is not updated.
*/
+ if ((s->cmos_data[RTC_REG_A] & 0x60) == 0x60) {
+ qemu_del_timer(s->update_timer);
+ return;
+ }
if ((s->cmos_data[RTC_REG_C] & REG_C_UF) &&
(s->cmos_data[RTC_REG_B] & REG_B_SET)) {
qemu_del_timer(s->update_timer);
@@ -266,6 +276,8 @@ static void rtc_update_timer(void *opaque)
int32_t irqs = REG_C_UF;
int32_t new_irqs;
+ assert((s->cmos_data[RTC_REG_A] & 0x60) != 0x60);
+
/* UIP might have been latched, update time and clear it. */
rtc_update_time(s);
s->cmos_data[RTC_REG_A] &= ~REG_A_UIP;
@@ -310,12 +322,31 @@ static void cmos_ioport_write(void *opaque, uint32_t addr, uint32_t data)
case RTC_YEAR:
s->cmos_data[s->cmos_index] = data;
/* if in set mode, do not update the time */
- if (!(s->cmos_data[RTC_REG_B] & REG_B_SET)) {
+ if (rtc_running(s)) {
rtc_set_time(s);
check_update_timer(s);
}
break;
case RTC_REG_A:
+ if ((data & 0x60) == 0x60) {
+ if (rtc_running(s)) {
+ rtc_update_time(s);
+ }
+ /* What happens to UIP when divider reset is enabled is
+ * unclear from the datasheet. Shouldn't matter much
+ * though.
+ */
+ s->cmos_data[RTC_REG_A] &= ~REG_A_UIP;
+ } else if (((s->cmos_data[RTC_REG_A] & 0x60) == 0x60) &&
+ (data & 0x70) <= 0x20) {
+ /* when the divider reset is removed, the first update cycle
+ * begins one-half second later*/
+ if (!(s->cmos_data[RTC_REG_B] & REG_B_SET)) {
+ s->offset = 500000000;
+ rtc_set_time(s);
+ }
+ s->cmos_data[RTC_REG_A] &= ~REG_A_UIP;
+ }
/* UIP bit is read only */
s->cmos_data[RTC_REG_A] = (data & ~REG_A_UIP) |
(s->cmos_data[RTC_REG_A] & REG_A_UIP);
@@ -325,7 +356,7 @@ static void cmos_ioport_write(void *opaque, uint32_t addr, uint32_t data)
case RTC_REG_B:
if (data & REG_B_SET) {
/* update cmos to when the rtc was stopping */
- if (!(s->cmos_data[RTC_REG_B] & REG_B_SET)) {
+ if (rtc_running(s)) {
rtc_update_time(s);
}
/* set mode: reset UIP mode */
@@ -333,7 +364,8 @@ static void cmos_ioport_write(void *opaque, uint32_t addr, uint32_t data)
data &= ~REG_B_UIE;
} else {
/* if disabling set mode, update the time */
- if (s->cmos_data[RTC_REG_B] & REG_B_SET) {
+ if ((s->cmos_data[RTC_REG_B] & REG_B_SET) &&
+ (s->cmos_data[RTC_REG_A] & 0x70) <= 0x20) {
s->offset = get_guest_rtc_ns(s) % NSEC_PER_SEC;
rtc_set_time(s);
}
@@ -447,7 +479,7 @@ static int update_in_progress(RTCState *s)
{
int64_t guest_nsec;
- if (s->cmos_data[RTC_REG_B] & REG_B_SET) {
+ if (!rtc_running(s)) {
return 0;
}
if (qemu_timer_pending(s->update_timer)) {
@@ -484,7 +516,7 @@ static uint32_t cmos_ioport_read(void *opaque, uint32_t addr)
case RTC_YEAR:
/* if not in set mode, calibrate cmos before
* reading*/
- if (!(s->cmos_data[RTC_REG_B] & REG_B_SET)) {
+ if (rtc_running(s)) {
rtc_update_time(s);
}
ret = s->cmos_data[s->cmos_index];
--
1.7.10.2
next prev parent reply other threads:[~2012-07-20 10:54 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-20 10:53 [Qemu-devel] [PATCH 0/7] Remove periodic wakeup from RTC timer Paolo Bonzini
2012-07-20 10:53 ` [Qemu-devel] [PATCH 1/7] RTC: Remove the logic to update time format when DM bit changed Paolo Bonzini
2012-07-20 10:53 ` [Qemu-devel] [PATCH 2/7] RTC: Rename rtc_timer_update Paolo Bonzini
2012-07-20 10:53 ` [Qemu-devel] [PATCH 3/7] RTC: Update interrupt state when interrupts are masked/unmasked Paolo Bonzini
2012-07-20 10:53 ` [Qemu-devel] [PATCH 4/7] RTC: Update the RTC clock only when reading it Paolo Bonzini
2012-07-23 5:17 ` Juan Quintela
2012-07-23 7:19 ` Paolo Bonzini
2012-07-20 10:53 ` Paolo Bonzini [this message]
2012-07-20 10:53 ` [Qemu-devel] [PATCH 6/7] RTC: Do not fire timer periodically to catch next alarm Paolo Bonzini
2012-07-20 10:53 ` [Qemu-devel] [PATCH 7/7] RTC: Allow to migrate from old QEMU Paolo Bonzini
2012-07-20 17:38 ` Michael Roth
2012-07-20 19:02 ` Paolo Bonzini
2012-07-23 5:12 ` Juan Quintela
2012-07-23 7:30 ` Paolo Bonzini
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=1342781633-7288-6-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=yang.z.zhang@intel.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;
as well as URLs for NNTP newsgroup(s).