mbox series

[v6,0/3] Add and connect the ZynqMP RTC

Message ID cover.1519406423.git.alistair.francis@xilinx.com
Headers show
Series Add and connect the ZynqMP RTC | expand

Message

Alistair Francis Feb. 23, 2018, 5:21 p.m. UTC
V6:
 - Migrate tick_offset and add a pre_save call

V5:
 - Recalculate tick_offset after migration

V4:
 - Use the RegisterAccessInfo .unimp functionality

V3:
 - Store an offset value
 - Use mktimegm()
 - Log unimplemented writes

V2:
 - Delete unused realise function
 - Add cover letter
 - Convert DB_PRINT() macro to trace


Alistair Francis (3):
  xlnx-zynqmp-rtc: Initial commit
  xlnx-zynqmp-rtc: Add basic time support
  xlnx-zynqmp: Connect the RTC device

 include/hw/arm/xlnx-zynqmp.h       |   2 +
 include/hw/timer/xlnx-zynqmp-rtc.h |  87 ++++++++++++
 hw/arm/xlnx-zynqmp.c               |  14 ++
 hw/timer/xlnx-zynqmp-rtc.c         | 271 +++++++++++++++++++++++++++++++++++++
 hw/timer/Makefile.objs             |   1 +
 hw/timer/trace-events              |   3 +
 6 files changed, 378 insertions(+)
 create mode 100644 include/hw/timer/xlnx-zynqmp-rtc.h
 create mode 100644 hw/timer/xlnx-zynqmp-rtc.c

Comments

Peter Maydell Feb. 27, 2018, 4:36 p.m. UTC | #1
On 23 February 2018 at 17:21, Alistair Francis
<alistair.francis@xilinx.com> wrote:
> Allow the guest to determine the time set from the QEMU command line.
>
> This includes adding a trace event to debug the new time.
>
> Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>

Thanks for reworking this -- I think it looks simpler this way.

> diff --git a/include/hw/timer/xlnx-zynqmp-rtc.h b/include/hw/timer/xlnx-zynqmp-rtc.h
> index 87649836cc..2867563bdd 100644
> --- a/include/hw/timer/xlnx-zynqmp-rtc.h
> +++ b/include/hw/timer/xlnx-zynqmp-rtc.h
> @@ -79,6 +79,9 @@ typedef struct XlnxZynqMPRTC {
>      qemu_irq irq_rtc_int;
>      qemu_irq irq_addr_error_int;
>
> +    struct tm current_tm;
> +    uint32_t tick_offset;
> +

Do we need current_tm to be a struct field now?

> @@ -143,6 +164,10 @@ static void rtc_reset(DeviceState *dev)
>          register_reset(&s->regs_info[i]);
>      }
>
> +    trace_xlnx_zynqmp_rtc_gettime(s->current_tm.tm_year, s->current_tm.tm_mon,
> +                                  s->current_tm.tm_mday, s->current_tm.tm_hour,
> +                                  s->current_tm.tm_min, s->current_tm.tm_sec);
> +

...this trace is in reset, and is the only place we read
current_tm, except for...

>      rtc_int_update_irq(s);
>      addr_error_int_update_irq(s);
>  }
> @@ -178,14 +203,46 @@ static void rtc_init(Object *obj)
>      sysbus_init_mmio(sbd, &s->iomem);
>      sysbus_init_irq(sbd, &s->irq_rtc_int);
>      sysbus_init_irq(sbd, &s->irq_addr_error_int);
> +
> +    qemu_get_timedate(&s->current_tm, 0);
> +    s->tick_offset = mktimegm(&s->current_tm) -
> +        qemu_clock_get_ns(rtc_clock) / NANOSECONDS_PER_SECOND;

...this code in init, which could just use a local variable
instead, since the trace in reset isn't really reporting
interesting information any more (the value never changes, so
you could trace it in init instead).

> +}
>

thanks
-- PMM
Alistair Francis Feb. 27, 2018, 5:23 p.m. UTC | #2
On Tue, Feb 27, 2018 at 8:36 AM, Peter Maydell <peter.maydell@linaro.org> wrote:
> On 23 February 2018 at 17:21, Alistair Francis
> <alistair.francis@xilinx.com> wrote:
>> Allow the guest to determine the time set from the QEMU command line.
>>
>> This includes adding a trace event to debug the new time.
>>
>> Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
>
> Thanks for reworking this -- I think it looks simpler this way.
>
>> diff --git a/include/hw/timer/xlnx-zynqmp-rtc.h b/include/hw/timer/xlnx-zynqmp-rtc.h
>> index 87649836cc..2867563bdd 100644
>> --- a/include/hw/timer/xlnx-zynqmp-rtc.h
>> +++ b/include/hw/timer/xlnx-zynqmp-rtc.h
>> @@ -79,6 +79,9 @@ typedef struct XlnxZynqMPRTC {
>>      qemu_irq irq_rtc_int;
>>      qemu_irq irq_addr_error_int;
>>
>> +    struct tm current_tm;
>> +    uint32_t tick_offset;
>> +
>
> Do we need current_tm to be a struct field now?
>
>> @@ -143,6 +164,10 @@ static void rtc_reset(DeviceState *dev)
>>          register_reset(&s->regs_info[i]);
>>      }
>>
>> +    trace_xlnx_zynqmp_rtc_gettime(s->current_tm.tm_year, s->current_tm.tm_mon,
>> +                                  s->current_tm.tm_mday, s->current_tm.tm_hour,
>> +                                  s->current_tm.tm_min, s->current_tm.tm_sec);
>> +
>
> ...this trace is in reset, and is the only place we read
> current_tm, except for...
>
>>      rtc_int_update_irq(s);
>>      addr_error_int_update_irq(s);
>>  }
>> @@ -178,14 +203,46 @@ static void rtc_init(Object *obj)
>>      sysbus_init_mmio(sbd, &s->iomem);
>>      sysbus_init_irq(sbd, &s->irq_rtc_int);
>>      sysbus_init_irq(sbd, &s->irq_addr_error_int);
>> +
>> +    qemu_get_timedate(&s->current_tm, 0);
>> +    s->tick_offset = mktimegm(&s->current_tm) -
>> +        qemu_clock_get_ns(rtc_clock) / NANOSECONDS_PER_SECOND;
>
> ...this code in init, which could just use a local variable
> instead, since the trace in reset isn't really reporting
> interesting information any more (the value never changes, so
> you could trace it in init instead).

Yeah you are right. I have moved it all to the init() function.

Alistair

>
>> +}
>>
>
> thanks
> -- PMM