Skip to contentSkip to conversation

arm: aspeed: Add RTC Model

PATCH In review Joel Stanley 3 participants 7 messages Apr 30, 2019 – May 6, 2019 Arm/Aspeed machine support

lore
Share & tools
lore

Joel Stanley

author maintainer
#0 lore raw

v3 cover arm: aspeed: Add RTC Model

v3: Add some commit messages, resend as v2 didn't send properly
v2: Minor fixes, added vmstate and reset, and rebased on Cédric's series

Based-on: [email protected]
[PATCH 3/3] aspeed: use sysbus_init_child_obj() to initialize children

A model for the ASPEED BMC real time clock (RTC). The model is sufficient for running the guest Linux kernel driver, and ticks in time with the host when programmed.

It does not implement the alarm functionality, which includes the interrupt.

Joel Stanley (2):
hw: timer: Add ASPEED RTC device
hw/arm/aspeed: Add RTC to SoC

 hw/arm/aspeed_soc.c           |  13 +++
 hw/timer/Makefile.objs        |   2 +-
 hw/timer/aspeed_rtc.c         | 180 ++++++++++++++++++++++++++++++++++
 hw/timer/trace-events         |   4 +
 include/hw/arm/aspeed_soc.h   |   2 +
 include/hw/timer/aspeed_rtc.h |  31 ++++++
 6 files changed, 231 insertions(+), 1 deletion(-)
 create mode 100644 hw/timer/aspeed_rtc.c
 create mode 100644 include/hw/timer/aspeed_rtc.h
Signature · 1 line
2.20.1
author maintainer
#1 lore raw

PATCH v3 1/2 hw: timer: Add ASPEED RTC device

The RTC is modeled to provide time and date functionality. It is initialised at zero to match the hardware.

There is no modelling of the alarm functionality, which includes the IRQ line. As there is no guest code to exercise this function that is acceptable for now.

---
v3: Add commit message
v2:
Use g_assert_not_reached
Add vmstate
Add reset callback
Annotate fall through cases

---
 hw/timer/Makefile.objs        |   2 +-
 hw/timer/aspeed_rtc.c         | 180 ++++++++++++++++++++++++++++++++++
 hw/timer/trace-events         |   4 +
 include/hw/timer/aspeed_rtc.h |  31 ++++++
 4 files changed, 216 insertions(+), 1 deletion(-)
 create mode 100644 hw/timer/aspeed_rtc.c
 create mode 100644 include/hw/timer/aspeed_rtc.h
hw/timer/Makefile.objs +1 -1
index 0e9a4530f848..123d92c9692c 100644
@@ -41,7 +41,7 @@ obj-$(CONFIG_MC146818RTC) += mc146818rtc.o
 obj-$(CONFIG_ALLWINNER_A10_PIT) += allwinner-a10-pit.o
 
 common-obj-$(CONFIG_STM32F2XX_TIMER) += stm32f2xx_timer.o
-common-obj-$(CONFIG_ASPEED_SOC) += aspeed_timer.o
+common-obj-$(CONFIG_ASPEED_SOC) += aspeed_timer.o aspeed_rtc.o
 
 common-obj-$(CONFIG_SUN4V_RTC) += sun4v-rtc.o
 common-obj-$(CONFIG_CMSDK_APB_TIMER) += cmsdk-apb-timer.o
hw/timer/aspeed_rtc.c new file +180 -0

180 lines not on this page · raw message

hw/timer/trace-events +4 -0
index dcaf3d6da6c8..db02a9142cda 100644
@@ -66,6 +66,10 @@ cmsdk_apb_dualtimer_read(uint64_t offset, uint64_t data, unsigned size) "CMSDK A
 cmsdk_apb_dualtimer_write(uint64_t offset, uint64_t data, unsigned size) "CMSDK APB dualtimer write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u"
 cmsdk_apb_dualtimer_reset(void) "CMSDK APB dualtimer: reset"
 
+# hw/timer/aspeed-rtc.c
+aspeed_rtc_read(uint64_t addr, uint64_t value) "addr 0x%02" PRIx64 " value 0x%08" PRIx64
+aspeed_rtc_write(uint64_t addr, uint64_t value) "addr 0x%02" PRIx64 " value 0x%08" PRIx64
+
 # sun4v-rtc.c
 sun4v_rtc_read(uint64_t addr, uint64_t value) "read: addr 0x%" PRIx64 " value 0x%" PRIx64
 sun4v_rtc_write(uint64_t addr, uint64_t value) "write: addr 0x%" PRIx64 " value 0x%" PRIx64
include/hw/timer/aspeed_rtc.h new file +31 -0
new file mode 100644
index 000000000000..1f1155a676c1
@@ -0,0 +1,31 @@
+/*
+ * ASPEED Real Time Clock
+ * Joel Stanley <[email protected]>
+ *
+ * Copyright 2019 IBM Corp
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#ifndef ASPEED_RTC_H
+#define ASPEED_RTC_H
+
+#include <stdint.h>
+
+#include "hw/hw.h"
+#include "hw/irq.h"
+#include "hw/sysbus.h"
+
+typedef struct AspeedRtcState {
+    SysBusDevice parent_obj;
+
+    MemoryRegion iomem;
+    qemu_irq irq;
+
+    uint32_t reg[0x18];
+    int offset;
+
+} AspeedRtcState;
+
+#define TYPE_ASPEED_RTC "aspeed.rtc"
+#define ASPEED_RTC(obj) OBJECT_CHECK(AspeedRtcState, (obj), TYPE_ASPEED_RTC)
+
+#endif /* ASPEED_RTC_H */
Signature · 1 line
2.20.1
Reviewed-by on v3 1/2
#2 lore raw

Re: [Qemu-arm] [PATCH v3 1/2] hw: timer: Add ASPEED RTC device

Quoted 9 lines · Joel Stanley

The RTC is modeled to provide time and date functionality. It is initialised at zero to match the hardware.

There is no modelling of the alarm functionality, which includes the IRQ line. As there is no guest code to exercise this function that is acceptable for now.

thanks
-- PMM

author maintainer
#3 lore raw

PATCH v3 2/2 hw/arm/aspeed: Add RTC to SoC

In reply to Joel Stanley

All systems have an RTC.

The IRQ is hooked up but the model does not use it at this stage. There is no guest code that uses it, so this limitation is acceptable.

---
v3: Add commit message
v2: Rebase on Cedric's patches ([email protected])

---
 hw/arm/aspeed_soc.c         | 13 +++++++++++++
 include/hw/arm/aspeed_soc.h |  2 ++
 2 files changed, 15 insertions(+)
hw/arm/aspeed_soc.c +13 -0
index 110956828c44..ea9700c35bc4 100644
@@ -229,6 +229,9 @@ static void aspeed_soc_init(Object *obj)
     sysbus_init_child_obj(obj, "vic", OBJECT(&s->vic), sizeof(s->vic),
                           TYPE_ASPEED_VIC);
 
+    sysbus_init_child_obj(obj, "rtc", OBJECT(&s->rtc), sizeof(s->rtc),
+                          TYPE_ASPEED_RTC);
+
     sysbus_init_child_obj(obj, "timerctrl", OBJECT(&s->timerctrl),
                           sizeof(s->timerctrl), TYPE_ASPEED_TIMER);
     object_property_add_const_link(OBJECT(&s->timerctrl), "scu",
@@ -315,6 +318,16 @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
     sysbus_connect_irq(SYS_BUS_DEVICE(&s->vic), 1,
                        qdev_get_gpio_in(DEVICE(&s->cpu), ARM_CPU_FIQ));
 
+    /* RTC */
+    object_property_set_bool(OBJECT(&s->rtc), true, "realized", &err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->rtc), 0, sc->info->memmap[ASPEED_RTC]);
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->rtc), 0,
+                       aspeed_soc_get_irq(s, ASPEED_RTC));
+
     /* Timer */
     object_property_set_bool(OBJECT(&s->timerctrl), true, "realized", &err);
     if (err) {
include/hw/arm/aspeed_soc.h +2 -0
index eda9094660b5..d124674f25d8 100644
@@ -17,6 +17,7 @@
 #include "hw/misc/aspeed_scu.h"
 #include "hw/misc/aspeed_sdmc.h"
 #include "hw/timer/aspeed_timer.h"
+#include "hw/timer/aspeed_rtc.h"
 #include "hw/i2c/aspeed_i2c.h"
 #include "hw/ssi/aspeed_smc.h"
 #include "hw/watchdog/wdt_aspeed.h"
@@ -33,6 +34,7 @@ typedef struct AspeedSoCState {
     ARMCPU cpu;
     MemoryRegion sram;
     AspeedVICState vic;
+    AspeedRtcState rtc;
     AspeedTimerCtrlState timerctrl;
     AspeedI2CState i2c;
     AspeedSCUState scu;
Signature · 1 line
2.20.1
#5 lore raw
In reply to Joel Stanley
Quoted 7 lines · Joel Stanley

v3: Add some commit messages, resend as v2 didn't send properly
v2: Minor fixes, added vmstate and reset, and rebased on Cédric's series

Based-on: [email protected]
[PATCH 3/3] aspeed: use sysbus_init_child_obj() to initialize children

Quoted 6 lines

A model for the ASPEED BMC real time clock (RTC). The model is sufficient for running the guest Linux kernel driver, and ticks in time with the host when programmed.

It does not implement the alarm functionality, which includes the interrupt.

Hi -- I've reviewed this series, but can't apply it yet as it's based on Cedric's patchset which needs a respin. If I forget to apply this when I apply the respin of that one, please ping me...

thanks
-- PMM

#6 lore raw
Quoted 12 lines · Peter Maydell
Quoted 11 lines · Joel Stanley

v3: Add some commit messages, resend as v2 didn't send properly
v2: Minor fixes, added vmstate and reset, and rebased on Cédric's series

Based-on: [email protected]
[PATCH 3/3] aspeed: use sysbus_init_child_obj() to initialize children

A model for the ASPEED BMC real time clock (RTC). The model is sufficient for running the guest Linux kernel driver, and ticks in time with the host when programmed.

Quoted 7 lines
Quoted 2 lines

It does not implement the alarm functionality, which includes the interrupt.

Hi -- I've reviewed this series, but can't apply it yet as it's based on Cedric's patchset which needs a respin. If I forget to apply this when I apply the respin of that one, please ping me...

I will work on a fix ASAP.

Thanks,

C.