diff mbox

[v4,3/7] RTC: Add UIP(update in progress) check logic

Message ID A9667DDFB95DB7438FA9D7D576C3D87E09E741@SHSMSX101.ccr.corp.intel.com
State New
Headers show

Commit Message

Zhang, Yang Z March 19, 2012, 6:14 a.m. UTC
The UIP(update in progress) is set when RTC is updating. And the update cycle begins 244us later after UIP is set. And it is cleared when update end.

Signed-off-by: Yang Zhang <yang.z.zhang@Intel.com>
---
 hw/mc146818rtc.c |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)

--
1.7.1

Comments

Stefano Stabellini March 20, 2012, 2:26 p.m. UTC | #1
On Mon, 19 Mar 2012, Zhang, Yang Z wrote:
> The UIP(update in progress) is set when RTC is updating. And the update cycle begins 244us later after UIP is set. And it is cleared when update end.

this patch seems good to me


> Signed-off-by: Yang Zhang <yang.z.zhang@Intel.com>
> ---
>  hw/mc146818rtc.c |   18 ++++++++++++++++++
>  1 files changed, 18 insertions(+), 0 deletions(-)
> 
> diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c
> index 82a5b8a..6ebb8f6 100644
> --- a/hw/mc146818rtc.c
> +++ b/hw/mc146818rtc.c
> @@ -377,6 +377,21 @@ static void rtc_calibrate_time(RTCState *s)
>      s->current_tm = *ret;
>  }
> 
> +static int update_in_progress(RTCState *s)
> +{
> +    int64_t guest_usec;
> +
> +    if (s->cmos_data[RTC_REG_B] & REG_B_SET) {
> +        return 0;
> +    }
> +    guest_usec = get_guest_rtc_us(s);
> +    /* UIP bit will be set at last 244us of every second. */
> +    if ((guest_usec % USEC_PER_SEC) >= (USEC_PER_SEC - 244)) {
> +        return 1;
> +    }
> +    return 0;
> +}
> +
>  static uint32_t cmos_ioport_read(void *opaque, uint32_t addr)
>  {
>      RTCState *s = opaque;
> @@ -402,6 +417,9 @@ static uint32_t cmos_ioport_read(void *opaque, uint32_t addr)
>              break;
>          case RTC_REG_A:
>              ret = s->cmos_data[s->cmos_index];
> +            if (update_in_progress(s)) {
> +                ret |= REG_A_UIP;
> +            }
>              break;
>          case RTC_REG_C:
>              ret = s->cmos_data[s->cmos_index];
> --
> 1.7.1
>
diff mbox

Patch

diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c
index 82a5b8a..6ebb8f6 100644
--- a/hw/mc146818rtc.c
+++ b/hw/mc146818rtc.c
@@ -377,6 +377,21 @@  static void rtc_calibrate_time(RTCState *s)
     s->current_tm = *ret;
 }

+static int update_in_progress(RTCState *s)
+{
+    int64_t guest_usec;
+
+    if (s->cmos_data[RTC_REG_B] & REG_B_SET) {
+        return 0;
+    }
+    guest_usec = get_guest_rtc_us(s);
+    /* UIP bit will be set at last 244us of every second. */
+    if ((guest_usec % USEC_PER_SEC) >= (USEC_PER_SEC - 244)) {
+        return 1;
+    }
+    return 0;
+}
+
 static uint32_t cmos_ioport_read(void *opaque, uint32_t addr)
 {
     RTCState *s = opaque;
@@ -402,6 +417,9 @@  static uint32_t cmos_ioport_read(void *opaque, uint32_t addr)
             break;
         case RTC_REG_A:
             ret = s->cmos_data[s->cmos_index];
+            if (update_in_progress(s)) {
+                ret |= REG_A_UIP;
+            }
             break;
         case RTC_REG_C:
             ret = s->cmos_data[s->cmos_index];