Skip to contentSkip to conversation

RTC support for QEMU RISC-V virt machine

PATCH Superseded Anup Patel 2 participants 5 messages Sep 24, 2019 – Sep 25, 2019 RISC-V

v2 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Anup Patel

author
#0 lore raw

v2 cover RTC support for QEMU RISC-V virt machine

This series adds RTC device to QEMU RISC-V virt machine. We have selected Goldfish RTC device model for this. It's a pretty simple synthetic device with few MMIO registers and no dependency external clock. The driver for Goldfish RTC is already available in Linux so we just need to enable it in Kconfig for RISCV and also update Linux defconfigs.

We have tested this series with Linux-5.3 plus defconfig changes available in 'goldfish_rtc_v1' branch of:
https://github.com/avpatel/linux.git

Changes since v1:
- Removed redundant object properties from Goldfish RTC emulation
- Added vmstate for Goldfish RTC

Anup Patel (2):
hw: timer: Add Goldfish RTC device
riscv: virt: Use Goldfish RTC device

 hw/riscv/Kconfig                |   1 +
 hw/riscv/virt.c                 |  15 ++
 hw/timer/Kconfig                |   3 +
 hw/timer/Makefile.objs          |   1 +
 hw/timer/goldfish_rtc.c         | 278 ++++++++++++++++++++++++++++++++
 include/hw/riscv/virt.h         |   2 +
 include/hw/timer/goldfish_rtc.h |  46 ++++++
 7 files changed, 346 insertions(+)
 create mode 100644 hw/timer/goldfish_rtc.c
 create mode 100644 include/hw/timer/goldfish_rtc.h

--
2.17.1

author
#1 lore raw

PATCH v2 1/2 hw: timer: Add Goldfish RTC device

This patch adds model for Google Goldfish virtual platform RTC device.

We will be adding Goldfish RTC device to the QEMU RISC-V virt machine for providing real date-time to Guest Linux. The corresponding Linux driver for Goldfish RTC device is already available in upstream Linux.

For now, VM migration support is not available for Goldfish RTC device but it will be added later when we implement VM migration for KVM RISC-V.

---
 hw/timer/Kconfig                |   3 +
 hw/timer/Makefile.objs          |   1 +
 hw/timer/goldfish_rtc.c         | 278 ++++++++++++++++++++++++++++++++
 include/hw/timer/goldfish_rtc.h |  46 ++++++
 4 files changed, 328 insertions(+)
 create mode 100644 hw/timer/goldfish_rtc.c
 create mode 100644 include/hw/timer/goldfish_rtc.h
hw/timer/Kconfig +3 -0
index eefc95f35e..bd1831fbe8 100644
@@ -58,3 +58,6 @@ config CMSDK_APB_TIMER
 config CMSDK_APB_DUALTIMER
     bool
     select PTIMER
+
+config GOLDFISH_RTC
+    bool
hw/timer/Makefile.objs +1 -0
index 123d92c969..5dc6f880af 100644
@@ -47,3 +47,4 @@ common-obj-$(CONFIG_SUN4V_RTC) += sun4v-rtc.o
 common-obj-$(CONFIG_CMSDK_APB_TIMER) += cmsdk-apb-timer.o
 common-obj-$(CONFIG_CMSDK_APB_DUALTIMER) += cmsdk-apb-dualtimer.o
 common-obj-$(CONFIG_MSF2) += mss-timer.o
+common-obj-$(CONFIG_GOLDFISH_RTC) += goldfish_rtc.o
hw/timer/goldfish_rtc.c new file +278 -0

278 lines not on this page · raw message

include/hw/timer/goldfish_rtc.h new file +46 -0

46 lines not on this page · raw message

Signature · 1 line
2.17.1
author
#2 lore raw

PATCH v2 2/2 riscv: virt: Use Goldfish RTC device

In reply to Anup Patel

We extend QEMU RISC-V virt machine by adding Goldfish RTC device to it. This will allow Guest Linux to sync it's local date/time with Host date/time via RTC device.

---
 hw/riscv/Kconfig        |  1 +
 hw/riscv/virt.c         | 15 +++++++++++++++
 include/hw/riscv/virt.h |  2 ++
 3 files changed, 18 insertions(+)
hw/riscv/Kconfig +1 -0
index fb19b2df3a..b33753c780 100644
@@ -34,6 +34,7 @@ config RISCV_VIRT
     select PCI
     select HART
     select SERIAL
+    select GOLDFISH_RTC
     select VIRTIO_MMIO
     select PCI_EXPRESS_GENERIC_BRIDGE
     select SIFIVE
hw/riscv/virt.c +15 -0
index d36f5625ec..95c42ab993 100644
@@ -57,6 +57,7 @@ static const struct MemmapEntry {
     [VIRT_DEBUG] =       {        0x0,         0x100 },
     [VIRT_MROM] =        {     0x1000,       0x11000 },
     [VIRT_TEST] =        {   0x100000,        0x1000 },
+    [VIRT_RTC] =         {   0x101000,        0x1000 },
     [VIRT_CLINT] =       {  0x2000000,       0x10000 },
     [VIRT_PLIC] =        {  0xc000000,     0x4000000 },
     [VIRT_UART0] =       { 0x10000000,         0x100 },
@@ -310,6 +311,17 @@ static void create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap,
     qemu_fdt_setprop_cell(fdt, nodename, "interrupt-parent", plic_phandle);
     qemu_fdt_setprop_cell(fdt, nodename, "interrupts", UART0_IRQ);
 
+    nodename = g_strdup_printf("/rtc@%lx",
+        (long)memmap[VIRT_RTC].base);
+    qemu_fdt_add_subnode(fdt, nodename);
+    qemu_fdt_setprop_string(fdt, nodename, "compatible",
+        "google,goldfish-rtc");
+    qemu_fdt_setprop_cells(fdt, nodename, "reg",
+        0x0, memmap[VIRT_RTC].base,
+        0x0, memmap[VIRT_RTC].size);
+    qemu_fdt_setprop_cell(fdt, nodename, "interrupt-parent", plic_phandle);
+    qemu_fdt_setprop_cell(fdt, nodename, "interrupts", RTC_IRQ);
+
     qemu_fdt_add_subnode(fdt, "/chosen");
     qemu_fdt_setprop_string(fdt, "/chosen", "stdout-path", nodename);
     if (cmdline) {
@@ -496,6 +508,9 @@ static void riscv_virt_board_init(MachineState *machine)
         0, qdev_get_gpio_in(DEVICE(s->plic), UART0_IRQ), 399193,
         serial_hd(0), DEVICE_LITTLE_ENDIAN);
 
+    sysbus_create_simple("goldfish_rtc", memmap[VIRT_RTC].base,
+        qdev_get_gpio_in(DEVICE(s->plic), RTC_IRQ));
+
     g_free(plic_hart_config);
 }
 
include/hw/riscv/virt.h +2 -0
index 6e5fbe5d3b..e6423258d3 100644
@@ -37,6 +37,7 @@ enum {
     VIRT_DEBUG,
     VIRT_MROM,
     VIRT_TEST,
+    VIRT_RTC,
     VIRT_CLINT,
     VIRT_PLIC,
     VIRT_UART0,
@@ -49,6 +50,7 @@ enum {
 
 enum {
     UART0_IRQ = 10,
+    RTC_IRQ = 11,
     VIRTIO_IRQ = 1, /* 1 to 8 */
     VIRTIO_COUNT = 8,
     PCIE_IRQ = 0x20, /* 32 to 35 */
Signature · 1 line
2.17.1
#3 lore raw
In reply to Anup Patel

Hi Anup,

Quoted 19 lines · Anup Patel

This series adds RTC device to QEMU RISC-V virt machine. We have selected Goldfish RTC device model for this. It's a pretty simple synthetic device with few MMIO registers and no dependency external clock. The driver for Goldfish RTC is already available in Linux so we just need to enable it in Kconfig for RISCV and also update Linux defconfigs.

We have tested this series with Linux-5.3 plus defconfig changes available in 'goldfish_rtc_v1' branch of:
https://github.com/avpatel/linux.git

Changes since v1:
- Removed redundant object properties from Goldfish RTC emulation
- Added vmstate for Goldfish RTC

Anup Patel (2):
hw: timer: Add Goldfish RTC device
riscv: virt: Use Goldfish RTC device

Quoted 7 lines
 hw/riscv/Kconfig                |   1 +
 hw/riscv/virt.c                 |  15 ++
 hw/timer/Kconfig                |   3 +
 hw/timer/Makefile.objs          |   1 +
 hw/timer/goldfish_rtc.c         | 278 ++++++++++++++++++++++++++++++++
 include/hw/riscv/virt.h         |   2 +
 include/hw/timer/goldfish_rtc.h |  46 ++++++

Minor comment, if my ongoing series "Split RTC devices from hw/timer/ to hw/rtc/" is accepted, you'd have to rebase this in hw/rtc/goldfish_rtc:
https://lists.gnu.org/archive/html/qemu-devel/2019-09/msg03334.html
(no logical change involved).

Regards,

Phil.

author
#4 lore raw
Quoted 41 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: Tuesday, September 24, 2019 7:35 PM
To: Anup Patel <[email protected]>; Peter Maydell <[email protected]>; Palmer Dabbelt <[email protected]>; Alistair Francis <[email protected]>; Sagar Karandikar <[email protected]>; Bastian Koppelmann <[email protected] paderborn.de>
Cc: Atish Patra <[email protected]>; [email protected]; qemu- [email protected]; Anup Patel <[email protected]>
Subject: Re: [PATCH v2 0/2] RTC support for QEMU RISC-V virt machine

Hi Anup,

Quoted 19 lines · Anup Patel

This series adds RTC device to QEMU RISC-V virt machine. We have selected Goldfish RTC device model for this. It's a pretty simple synthetic device with few MMIO registers and no dependency external clock. The driver for Goldfish RTC is already available in Linux so we just need to enable it in Kconfig for RISCV and also update Linux defconfigs.

We have tested this series with Linux-5.3 plus defconfig changes available in 'goldfish_rtc_v1' branch of:
https://github.com/avpatel/linux.git

Changes since v1:
- Removed redundant object properties from Goldfish RTC emulation
- Added vmstate for Goldfish RTC

Anup Patel (2):
hw: timer: Add Goldfish RTC device
riscv: virt: Use Goldfish RTC device

Quoted 5 lines
 hw/riscv/Kconfig                |   1 +
 hw/riscv/virt.c                 |  15 ++
 hw/timer/Kconfig                |   3 +
 hw/timer/Makefile.objs          |   1 +
 hw/timer/goldfish_rtc.c         | 278
Quoted 8 lines

++++++++++++++++++++++++++++++++

Quoted 2 lines
 include/hw/riscv/virt.h         |   2 +
 include/hw/timer/goldfish_rtc.h |  46 ++++++

Minor comment, if my ongoing series "Split RTC devices from hw/timer/ to hw/rtc/" is accepted, you'd have to rebase this in hw/rtc/goldfish_rtc:
https://lists.gnu.org/archive/html/qemu-devel/2019-09/msg03334.html
(no logical change involved).

No problem, I will rebase these patches once your series after it is accepted.

Regards,
Anup