RTC support for QEMU RISC-V virt machine
v8 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.4-rc4 plus defconfig changes available in 'goldfish_rtc_v2' branch of:
https://github.com/avpatel/linux.git
Changes since v7:
- Fix broken "stdout-path" in "/chosen" DT node of virt machine
Changes since v6:
- Rebased on latest QEMU master
- Addressed all nit comments from Philippe Mathieu-Daude
Changes since v5:
- Rebased on latest QEMU master
- Added maintainer entry for Goldfish RTC
Changes since v4:
- Fixed typo in trace event usage
- Moved goldfish_rtc.h to correct location
Changes since v3:
- Address all nit comments from Alistair
Changes since v2:
- Rebased on RTC code refactoring
Changes since v1:
- Implemented VMState save/restore callbacks
Anup Patel (3):
hw: rtc: Add Goldfish RTC device
riscv: virt: Use Goldfish RTC device
MAINTAINERS: Add maintainer entry for Goldfish RTC
MAINTAINERS | 8 + hw/riscv/Kconfig | 1 + hw/riscv/virt.c | 16 ++ hw/rtc/Kconfig | 3 + hw/rtc/Makefile.objs | 1 + hw/rtc/goldfish_rtc.c | 285 ++++++++++++++++++++++++++++++++++ hw/rtc/trace-events | 4 + include/hw/riscv/virt.h | 2 + include/hw/rtc/goldfish_rtc.h | 46 ++++++ 9 files changed, 366 insertions(+) create mode 100644 hw/rtc/goldfish_rtc.c create mode 100644 include/hw/rtc/goldfish_rtc.h
--
2.17.1
PATCH v8 1/3 hw: rtc: 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 available but untested for Goldfish RTC device. It will be hardened in-future when we implement VM migration for KVM RISC-V.
--- hw/rtc/Kconfig | 3 + hw/rtc/Makefile.objs | 1 + hw/rtc/goldfish_rtc.c | 285 ++++++++++++++++++++++++++++++++++ hw/rtc/trace-events | 4 + include/hw/rtc/goldfish_rtc.h | 46 ++++++ 5 files changed, 339 insertions(+) create mode 100644 hw/rtc/goldfish_rtc.c create mode 100644 include/hw/rtc/goldfish_rtc.h
hw/rtc/Kconfig +3 -0
@@ -21,3 +21,6 @@ config MC146818RTC config SUN4V_RTC bool + +config GOLDFISH_RTC + bool
hw/rtc/Makefile.objs +1 -0
@@ -11,3 +11,4 @@ common-obj-$(CONFIG_EXYNOS4) += exynos4210_rtc.o obj-$(CONFIG_MC146818RTC) += mc146818rtc.o common-obj-$(CONFIG_SUN4V_RTC) += sun4v-rtc.o common-obj-$(CONFIG_ASPEED_SOC) += aspeed_rtc.o +common-obj-$(CONFIG_GOLDFISH_RTC) += goldfish_rtc.o
hw/rtc/goldfish_rtc.c new file +285 -0
285 lines not on this page · raw message
hw/rtc/trace-events +4 -0
@@ -17,3 +17,7 @@ pl031_set_alarm(uint32_t ticks) "alarm set for %u ticks" # 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 + +# goldfish_rtc.c +goldfish_rtc_read(uint64_t addr, uint64_t value) "addr 0x%02" PRIx64 " value 0x%08" PRIx64 +goldfish_rtc_write(uint64_t addr, uint64_t value) "addr 0x%02" PRIx64 " value 0x%08" PRIx64
include/hw/rtc/goldfish_rtc.h new file +46 -0
46 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v8 2/3 riscv: virt: Use Goldfish RTC device
In reply to Anup PatelWe 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 | 16 ++++++++++++++++ include/hw/riscv/virt.h | 2 ++ 3 files changed, 19 insertions(+)
hw/riscv/Kconfig +1 -0
@@ -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 PFLASH_CFI01
hw/riscv/virt.c +16 -0
@@ -58,6 +58,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 },
@@ -383,6 +384,18 @@ static void create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap, }g_free (nodename); + 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 ); +g_free (nodename); + nodename =g_strdup_printf ("/flash@%" PRIx64, flashbase);qemu_fdt_add_subnode (s->fdt, nodename);qemu_fdt_setprop_string (s->fdt, nodename,"compatible" ,"cfi-flash" );
@@ -579,6 +592,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 )); +virt_flash_create (s);for (i =0 ; i <ARRAY_SIZE (s->flash); i++) {
include/hw/riscv/virt.h +2 -0
@@ -44,6 +44,7 @@ enum {VIRT_DEBUG ,VIRT_MROM ,VIRT_TEST , +VIRT_RTC ,VIRT_CLINT ,VIRT_PLIC , VIRT_UART0,
@@ -57,6 +58,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
PATCH v8 3/3 MAINTAINERS: Add maintainer entry for Goldfish RTC
In reply to Anup PatelAdd myself as Goldfish RTC maintainer until someone else is willing to maintain it.
--- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
@@ -558,6 +558,14 @@ F: include/hw/arm/digic.h F: hw/*/digic* F: include/hw/*/digic* +Goldfish RTC +M: Anup Patel <[email protected]> +M: Alistair Francis <[email protected]> +L: [email protected] +S: Maintained +F: hw/rtc/goldfish_rtc.c +F: include/hw/rtc/goldfish_rtc.h + Gumstix M: Peter Maydell <[email protected]> R: Philippe Mathieu-Daud?? <[email protected]>
Signature · 1 line
2.17.1
Palmer Dabbelt
maintainerQuoted 40 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
Kconfigfor RISCV and also update Linux defconfigs.We have tested this series with Linux-5.4-rc4 plus defconfig changes available in '
goldfish_rtc_v2' branch of:
https://github.com/avpatel/linux.gitChanges since v7:
- Fix broken "stdout-path" in "/chosen" DT node of virt machineChanges since v6:
- Rebased on latest QEMU master
- Addressed all nit comments from Philippe Mathieu-DaudeChanges since v5:
- Rebased on latest QEMU master
- Added maintainer entry for Goldfish RTCChanges since v4:
- Fixed typo in trace event usage
- Movedgoldfish_rtc.hto correct locationChanges since v3:
- Address all nit comments from AlistairChanges since v2:
- Rebased on RTC code refactoringChanges since v1:
- Implemented VMState save/restore callbacksAnup Patel (3):
hw: rtc: Add Goldfish RTC device
riscv: virt: Use Goldfish RTC device
MAINTAINERS: Add maintainer entry for Goldfish RTC
Quoted 12 lines
MAINTAINERS | 8 + hw/riscv/Kconfig | 1 + hw/riscv/virt.c | 16 ++ hw/rtc/Kconfig | 3 + hw/rtc/Makefile.objs | 1 + hw/rtc/goldfish_rtc.c | 285 ++++++++++++++++++++++++++++++++++ hw/rtc/trace-events | 4 + include/hw/riscv/virt.h | 2 + include/hw/rtc/goldfish_rtc.h | 46 ++++++ 9 files changed, 366 insertions(+) create mode 100644 hw/rtc/goldfish_rtc.c create mode 100644 include/hw/rtc/goldfish_rtc.h
Thanks. I've updated the patches on my queue, LMK if there are any more changes!
Quoted 54 lines · Palmer Dabbelt
Quoted 49 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
Kconfigfor RISCV and also update Linux defconfigs.We have tested this series with Linux-5.4-rc4 plus defconfig changes available in '
goldfish_rtc_v2' branch of:
https://github.com/avpatel/linux.gitChanges since v7:
- Fix broken "stdout-path" in "/chosen" DT node of virt machineChanges since v6:
- Rebased on latest QEMU master
- Addressed all nit comments from Philippe Mathieu-DaudeChanges since v5:
- Rebased on latest QEMU master
- Added maintainer entry for Goldfish RTCChanges since v4:
- Fixed typo in trace event usage
- Movedgoldfish_rtc.hto correct locationChanges since v3:
- Address all nit comments from AlistairChanges since v2:
- Rebased on RTC code refactoringChanges since v1:
- Implemented VMState save/restore callbacksAnup Patel (3):
hw: rtc: Add Goldfish RTC device
riscv: virt: Use Goldfish RTC device
MAINTAINERS: Add maintainer entry for Goldfish RTCMAINTAINERS | 8 +
hw/riscv/Kconfig | 1 +
hw/riscv/virt.c | 16 ++
hw/rtc/Kconfig | 3 +
hw/rtc/Makefile.objs | 1 +
hw/rtc/goldfish_rtc.c | 285 ++++++++++++++++++++++++++++++++++ hw/rtc/trace-events | 4 + include/hw/riscv/virt.h | 2 +include/hw/rtc/goldfish_rtc.h| 46 ++++++Quoted 3 lines
9 files changed, 366 insertions(+)create mode 100644
hw/rtc/goldfish_rtc.c
create mode 100644include/hw/rtc/goldfish_rtc.h
Quoted 1 line
Thanks. I've updated the patches on my queue, LMK if there are any more changes!
I'm happy with the series, thanks Anup for addressing all the comments.
Regards,
Phil.
Quoted 55 lines · Palmer Dabbelt
Quoted 40 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
Kconfigfor RISCV and also update Linux defconfigs.We have tested this series with Linux-5.4-rc4 plus defconfig changes available in '
goldfish_rtc_v2' branch of:
https://github.com/avpatel/linux.gitChanges since v7:
- Fix broken "stdout-path" in "/chosen" DT node of virt machineChanges since v6:
- Rebased on latest QEMU master
- Addressed all nit comments from Philippe Mathieu-DaudeChanges since v5:
- Rebased on latest QEMU master
- Added maintainer entry for Goldfish RTCChanges since v4:
- Fixed typo in trace event usage
- Movedgoldfish_rtc.hto correct locationChanges since v3:
- Address all nit comments from AlistairChanges since v2:
- Rebased on RTC code refactoringChanges since v1:
- Implemented VMState save/restore callbacksAnup Patel (3):
hw: rtc: Add Goldfish RTC device
riscv: virt: Use Goldfish RTC device
MAINTAINERS: Add maintainer entry for Goldfish RTCQuoted 12 lines
MAINTAINERS | 8 + hw/riscv/Kconfig | 1 + hw/riscv/virt.c | 16 ++ hw/rtc/Kconfig | 3 + hw/rtc/Makefile.objs | 1 + hw/rtc/goldfish_rtc.c | 285 ++++++++++++++++++++++++++++++++++ hw/rtc/trace-events | 4 + include/hw/riscv/virt.h | 2 + include/hw/rtc/goldfish_rtc.h | 46 ++++++ 9 files changed, 366 insertions(+) create mode 100644 hw/rtc/goldfish_rtc.c create mode 100644 include/hw/rtc/goldfish_rtc.h
Quoted 2 lines
Thanks. I've updated the patches on my queue, LMK if there are any more changes!
Can this series be taken for QEMU 5.0 ?
It's already 2 months since it was reviewed.
Regards,
Anup