RTC support for QEMU RISC-V virt machine
v7 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 v6:
- Rebased on latest QEMU master
- Addressed all nit comments from Philippe Mathieu-Daud??
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 | 15 ++ 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, 365 insertions(+) create mode 100644 hw/rtc/goldfish_rtc.c create mode 100644 include/hw/rtc/goldfish_rtc.h
--
2.17.1
PATCH v7 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 v7 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 | 15 +++++++++++++++ include/hw/riscv/virt.h | 2 ++ 3 files changed, 18 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 +15 -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 },
@@ -376,6 +377,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) {
@@ -579,6 +591,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
Re: [PATCH v7 2/3] riscv: virt: Use Goldfish RTC device
Quoted 44 lines · 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.
Signed-off-by Anup Patel <[email protected]>Reviewed-by Palmer Dabbelt <[email protected]>Acked-by Palmer Dabbelt <[email protected]>Reviewed-by Alistair Francis <[email protected]>--- 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@@ -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_CFI01hw/riscv/virt.c +2
-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 },@@ -376,6 +377,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",
hw/riscv/virt.c static void create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap, · line 390
Quoted 10 lines
hw/riscv/virt.c +10
-0+ (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 ); +
We cannot create RTC node here because "nodename" is directly used as "stdout-path" below. Due to this patch, U-Boot S-mode stops working on QEMU because it see incorrect "stdout-path".
I will quickly send updated v8 series.
Quoted 34 lines
hw/riscv/virt.c +3
-0qemu_fdt_add_subnode (fdt,"/chosen" );qemu_fdt_setprop_string (fdt,"/chosen" ,"stdout-path" , nodename);if (cmdline) {@@ -579,6 +591,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
-1@@ -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 */ --
Quoted 2 lines
2.17.1
Regards,
Anup
PATCH v7 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