Add the generic ARM timer
PATCH v2 1/2 arm_generic_timer: Add the ARM Generic Timer
In reply to Alistair FrancisAdd the ARM generic timer. This allows the guest to poll the timer for values and also supports secure writes only.
---
V2:
- Fix couter/counter typo
hw/timer/Makefile.objs | 1 + hw/timer/arm_generic_timer.c | 216 +++++++++++++++++++++++++++++++++++ include/hw/timer/arm_generic_timer.h | 60 ++++++++++ 3 files changed, 277 insertions(+) create mode 100644 hw/timer/arm_generic_timer.c create mode 100644 include/hw/timer/arm_generic_timer.h
hw/timer/Makefile.objs +1 -0
@@ -17,6 +17,7 @@ common-obj-$(CONFIG_IMX) += imx_epit.o common-obj-$(CONFIG_IMX) += imx_gpt.o common-obj-$(CONFIG_LM32) += lm32_timer.o common-obj-$(CONFIG_MILKYMIST) += milkymist-sysctl.o +common-obj-$(CONFIG_XLNX_ZYNQMP) += arm_generic_timer.o obj-$(CONFIG_EXYNOS4) += exynos4210_mct.o obj-$(CONFIG_EXYNOS4) += exynos4210_pwm.o
hw/timer/arm_generic_timer.c new file +216 -0
216 lines not on this page · raw message
include/hw/timer/arm_generic_timer.h new file +60 -0
60 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v2 2/2 xlnx-zynqmp: Connect the ARM Generic Timer
In reply to Alistair Francis---
hw/arm/xlnx-zynqmp.c | 13 +++++++++++++ include/hw/arm/xlnx-zynqmp.h | 2 ++ 2 files changed, 15 insertions(+)
hw/arm/xlnx-zynqmp.c +13 -0
@@ -38,6 +38,8 @@#define SATA_ADDR 0xFD0C0000#define SATA_NUM_PORTS 2 +#define ARM_GEN_TIMER_ADDR 0xFF260000 +#define DP_ADDR 0xfd4a0000#define DP_IRQ 113
@@ -172,6 +174,10 @@ static void xlnx_zynqmp_init(Object *obj)qdev_set_parent_bus (DEVICE (&s->spi[i]),sysbus_get_default ()); } +object_initialize (&s->arm_gen_timer,sizeof (s->arm_gen_timer), +TYPE_ARM_GEN_TIMER ); +qdev_set_parent_bus (DEVICE (&s->arm_gen_timer),sysbus_get_default ()); +object_initialize (&s->dp,sizeof (s->dp),TYPE_XLNX_DP );qdev_set_parent_bus (DEVICE (&s->dp),sysbus_get_default ());
@@ -405,6 +411,13 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)g_free (bus_name); } +object_property_set_bool (OBJECT (&s->arm_gen_timer), true,"realized" , &err); +if (err) { +error_propagate (errp, err); +return ; + } +sysbus_mmio_map (SYS_BUS_DEVICE (&s->arm_gen_timer),0 ,ARM_GEN_TIMER_ADDR ); +object_property_set_bool (OBJECT (&s->dp), true,"realized" , &err);if (err) {error_propagate (errp, err);
include/hw/arm/xlnx-zynqmp.h +2 -0
@@ -26,6 +26,7 @@#include "hw/ide/ahci.h" #include "hw/sd/sdhci.h" #include "hw/ssi/xilinx_spips.h" +#include "hw/timer/arm_generic_timer.h" #include "hw/dma/xlnx_dpdma.h" #include "hw/display/xlnx_dp.h"
@@ -83,6 +84,7 @@ typedef struct XlnxZynqMPState {SysbusAHCIState sata;SDHCIState sdhci[XLNX_ZYNQMP_NUM_SDHCI ];XilinxSPIPS spi[XLNX_ZYNQMP_NUM_SPIS ]; +ARMGenTimer arm_gen_timer;XlnxDPState dp;XlnxDPDMAState dpdma;
Signature · 1 line
2.7.4
v2 cover Add the generic ARM timer
These two patches and and connect the Generic ARM Timer. This includes support for dropping insecure writes.
V2:
- Fix couter/counter typo
Alistair Francis (2):
arm_generic_timer: Add the ARM Generic Timer
xlnx-zynqmp: Connect the ARM Generic Timer
hw/arm/xlnx-zynqmp.c | 13 +++ hw/timer/Makefile.objs | 1 + hw/timer/arm_generic_timer.c | 216 +++++++++++++++++++++++++++++++++++ include/hw/arm/xlnx-zynqmp.h | 2 + include/hw/timer/arm_generic_timer.h | 60 ++++++++++ 5 files changed, 292 insertions(+) create mode 100644 hw/timer/arm_generic_timer.c create mode 100644 include/hw/timer/arm_generic_timer.h
Signature · 1 line
2.7.4
Re: [Qemu-arm] [PATCH v2 1/2] arm_generic_timer: Add the ARM Generic Timer
In reply to Alistair FrancisQuoted 8 lines · Alistair Francis
Add the ARM generic timer. This allows the guest to poll the timer for values and also supports secure writes only.
Signed-off-by Alistair Francis <[email protected]>---
V2:
- Fix couter/counter typo
Quoted 6 lines
hw/timer/Makefile.objs | 1 + hw/timer/arm_generic_timer.c | 216 +++++++++++++++++++++++++++++++++++ include/hw/timer/arm_generic_timer.h | 60 ++++++++++ 3 files changed, 277 insertions(+) create mode 100644 hw/timer/arm_generic_timer.c create mode 100644 include/hw/timer/arm_generic_timer.h
I can't quite seem to make this line up with the spec in the v8 ARM ARM (chapter 11 "System Level Implementation of the Generic Timer"). The generic timer documented there looks quite like this, but has extra ID registers at 0xFD0..0xFFC which this code doesn't implement, and also has the "CNTReadBase" memory map (which exposes just the count value and ID registers) as well as the "CNTControlBase" map that looks like what you have here. (The register names here differ from the conventions in the ARM ARM too.)
Is this code trying to implement that Generic Timer, or something else with a similar name?
hw/timer/Makefile.objs common-obj-$(CONFIG_IMX) += imx_epit.o · line 20
Quoted 9 lines
hw/timer/Makefile.objs +1
-0@@ -17,6 +17,7 @@ common-obj-$(CONFIG_IMX) += imx_epit.o common-obj-$(CONFIG_IMX) += imx_gpt.o common-obj-$(CONFIG_LM32) += lm32_timer.o common-obj-$(CONFIG_MILKYMIST) += milkymist-sysctl.o +common-obj-$(CONFIG_XLNX_ZYNQMP) += arm_generic_timer.o
If this is really generic I think it ought to have its own CONFIG_foo rather than using the XLNX_ZYNQMP symbol.
Quoted 30 lines
hw/timer/Makefile.objs +26
-0obj-$(CONFIG_EXYNOS4) += exynos4210_mct.o obj-$(CONFIG_EXYNOS4) += exynos4210_pwm.o +static uint64_t counter_low_value_postr(RegisterInfo *reg, uint64_t val64) +{ + ARMGenTimer *s = ARM_GEN_TIMER(reg->opaque); + uint64_t current_ticks, total_ticks; + uint32_t low_ticks; + + if (s->enabled) { + current_ticks = muldiv64(qemu_clock_get_us(QEMU_CLOCK_VIRTUAL), + NANOSECONDS_PER_SECOND, 1000000); + total_ticks = current_ticks - s->tick_offset; + low_ticks = (uint32_t) total_ticks; + } else { + /* Timer is disabled, return the time when it was disabled */ + low_ticks = (uint32_t) s->tick_offset; + } + + return low_ticks; +} + +static uint64_t counter_high_value_postr(RegisterInfo *reg, uint64_t val64) +{ + ARMGenTimer *s = ARM_GEN_TIMER(reg->opaque); + uint64_t current_ticks, total_ticks; + uint32_t high_ticks; + + if (s->enabled) {
hw/timer/Makefile.objs common-obj-$(CONFIG_IMX) += imx_epit.o
Quoted 10 lines
hw/timer/Makefile.objs +10
-0+ current_ticks = muldiv64(qemu_clock_get_us(QEMU_CLOCK_VIRTUAL), + NANOSECONDS_PER_SECOND, 1000000); + total_ticks = current_ticks - s->tick_offset; + high_ticks = (uint32_t) (total_ticks >> 32); + } else { + /* Timer is disabled, return the time when it was disabled */ + high_ticks = (uint32_t) (s->tick_offset >> 32); + } + + return high_ticks;
These two functions are very similar and would benefit from being refactored to call a utility function that just returned the 64-bit count.
thanks
-- PMM
Re: [Qemu-arm] [PATCH v2 1/2] arm_generic_timer: Add the ARM Generic Timer
Quoted 17 lines · Peter Maydell
Quoted 8 lines · Alistair Francis
Add the ARM generic timer. This allows the guest to poll the timer for values and also supports secure writes only.
Signed-off-by Alistair Francis <[email protected]>---
V2:
- Fix couter/counter typoQuoted 6 lines
hw/timer/Makefile.objs | 1 + hw/timer/arm_generic_timer.c | 216 +++++++++++++++++++++++++++++++++++ include/hw/timer/arm_generic_timer.h | 60 ++++++++++ 3 files changed, 277 insertions(+) create mode 100644 hw/timer/arm_generic_timer.c create mode 100644 include/hw/timer/arm_generic_timer.h
Quoted 9 lines
I can't quite seem to make this line up with the spec in the v8 ARM ARM (chapter 11 "System Level Implementation of the Generic Timer"). The generic timer documented there looks quite like this, but has extra ID registers at 0xFD0..0xFFC which this code doesn't implement, and also has the "CNTReadBase" memory map (which exposes just the count value and ID registers) as well as the "CNTControlBase" map that looks like what you have here. (The register names here differ from the conventions in the ARM ARM too.)
Of course they don't line up :(
I wrote it based off the Xilinx documentation, I (wrongly) assumed that we would follow the normal convention but apparently not.
Quoted 3 lines
Is this code trying to implement that Generic Timer, or something else with a similar name?
I'm not sure now which one it is.
I will dig into this and hopefully can respin this based on what is in the ARM ARM.
Quoted 13 lines
hw/timer/Makefile.objs common-obj-$(CONFIG_IMX) += imx_epit.o · line 20
Quoted 10 lines
hw/timer/Makefile.objs +1
-0@@ -17,6 +17,7 @@ common-obj-$(CONFIG_IMX) += imx_epit.o common-obj-$(CONFIG_IMX) += imx_gpt.o common-obj-$(CONFIG_LM32) += lm32_timer.o common-obj-$(CONFIG_MILKYMIST) += milkymist-sysctl.o +common-obj-$(CONFIG_XLNX_ZYNQMP) += arm_generic_timer.oIf this is really generic I think it ought to have its own
CONFIG_foorather than using theXLNX_ZYNQMPsymbol.
Yes, Fred pointed that out as well. I will fix that up in the next version.
Quoted 37 lines
Quoted 37 lines
hw/timer/Makefile.objs +32
-0obj-$(CONFIG_EXYNOS4) += exynos4210_mct.o obj-$(CONFIG_EXYNOS4) += exynos4210_pwm.o +static uint64_t counter_low_value_postr(RegisterInfo *reg, uint64_t val64) +{ + ARMGenTimer *s = ARM_GEN_TIMER(reg->opaque); + uint64_t current_ticks, total_ticks; + uint32_t low_ticks; + + if (s->enabled) { + current_ticks = muldiv64(qemu_clock_get_us(QEMU_CLOCK_VIRTUAL), + NANOSECONDS_PER_SECOND, 1000000); + total_ticks = current_ticks - s->tick_offset; + low_ticks = (uint32_t) total_ticks; + } else { + /* Timer is disabled, return the time when it was disabled */ + low_ticks = (uint32_t) s->tick_offset; + } + + return low_ticks; +} + +static uint64_t counter_high_value_postr(RegisterInfo *reg, uint64_t val64) +{ + ARMGenTimer *s = ARM_GEN_TIMER(reg->opaque); + uint64_t current_ticks, total_ticks; + uint32_t high_ticks; + + if (s->enabled) { + current_ticks = muldiv64(qemu_clock_get_us(QEMU_CLOCK_VIRTUAL), + NANOSECONDS_PER_SECOND, 1000000); + total_ticks = current_ticks - s->tick_offset; + high_ticks = (uint32_t) (total_ticks >> 32); + } else { + /* Timer is disabled, return the time when it was disabled */
Quoted 8 lines
hw/timer/Makefile.objs
Quoted 4 lines
hw/timer/Makefile.objs +4
-0+ high_ticks = (uint32_t) (s->tick_offset >> 32); + } + + return high_ticks;These two functions are very similar and would benefit from being refactored to call a utility function that just returned the 64-bit count.
Good point.
Thanks,
Alistair
Quoted 3 lines
thanks
-- PMM
Re: [Qemu-arm] [PATCH v2 1/2] arm_generic_timer: Add the ARM Generic Timer
Quoted 34 lines · Alistair Francis
Quoted 17 lines · Peter Maydell
Quoted 8 lines · Alistair Francis
Add the ARM generic timer. This allows the guest to poll the timer for values and also supports secure writes only.
Signed-off-by Alistair Francis <[email protected]>---
V2:
- Fix couter/counter typoQuoted 6 lines
hw/timer/Makefile.objs | 1 + hw/timer/arm_generic_timer.c | 216 +++++++++++++++++++++++++++++++++++ include/hw/timer/arm_generic_timer.h | 60 ++++++++++ 3 files changed, 277 insertions(+) create mode 100644 hw/timer/arm_generic_timer.c create mode 100644 include/hw/timer/arm_generic_timer.hQuoted 9 lines
I can't quite seem to make this line up with the spec in the v8 ARM ARM (chapter 11 "System Level Implementation of the Generic Timer"). The generic timer documented there looks quite like this, but has extra ID registers at 0xFD0..0xFFC which this code doesn't implement, and also has the "CNTReadBase" memory map (which exposes just the count value and ID registers) as well as the "CNTControlBase" map that looks like what you have here. (The register names here differ from the conventions in the ARM ARM too.)
Of course they don't line up :(
I wrote it based off the Xilinx documentation, I (wrongly) assumed that we would follow the normal convention but apparently not.
Quoted 1 line
Quoted 7 lines
Quoted 2 lines
Is this code trying to implement that Generic Timer, or something else with a similar name?
I'm not sure now which one it is.
I will dig into this and hopefully can respin this based on what is in the ARM ARM.
It turns out it is pretty close.
I have fixed up the names to be more like the ARM ARM. I have added some comments about the implementation specific registers and I have added the read base registers as well.
Sending out a V3.
Thanks,
Alistair
Quoted 72 lines
Quoted 14 lines
hw/timer/Makefile.objs common-obj-$(CONFIG_IMX) += imx_epit.o · line 20
Quoted 11 lines
hw/timer/Makefile.objs +1
-0@@ -17,6 +17,7 @@ common-obj-$(CONFIG_IMX) += imx_epit.o common-obj-$(CONFIG_IMX) += imx_gpt.o common-obj-$(CONFIG_LM32) += lm32_timer.o common-obj-$(CONFIG_MILKYMIST) += milkymist-sysctl.o +common-obj-$(CONFIG_XLNX_ZYNQMP) += arm_generic_timer.oIf this is really generic I think it ought to have its own
CONFIG_foorather than using theXLNX_ZYNQMPsymbol.Yes, Fred pointed that out as well. I will fix that up in the next version.
Quoted 37 lines
Quoted 37 lines
hw/timer/Makefile.objs +32
-0obj-$(CONFIG_EXYNOS4) += exynos4210_mct.o obj-$(CONFIG_EXYNOS4) += exynos4210_pwm.o +static uint64_t counter_low_value_postr(RegisterInfo *reg, uint64_t val64) +{ + ARMGenTimer *s = ARM_GEN_TIMER(reg->opaque); + uint64_t current_ticks, total_ticks; + uint32_t low_ticks; + + if (s->enabled) { + current_ticks = muldiv64(qemu_clock_get_us(QEMU_CLOCK_VIRTUAL), + NANOSECONDS_PER_SECOND, 1000000); + total_ticks = current_ticks - s->tick_offset; + low_ticks = (uint32_t) total_ticks; + } else { + /* Timer is disabled, return the time when it was disabled */ + low_ticks = (uint32_t) s->tick_offset; + } + + return low_ticks; +} + +static uint64_t counter_high_value_postr(RegisterInfo *reg, uint64_t val64) +{ + ARMGenTimer *s = ARM_GEN_TIMER(reg->opaque); + uint64_t current_ticks, total_ticks; + uint32_t high_ticks; + + if (s->enabled) { + current_ticks = muldiv64(qemu_clock_get_us(QEMU_CLOCK_VIRTUAL), + NANOSECONDS_PER_SECOND, 1000000); + total_ticks = current_ticks - s->tick_offset; + high_ticks = (uint32_t) (total_ticks >> 32); + } else { + /* Timer is disabled, return the time when it was disabled */Quoted 8 lines
hw/timer/Makefile.objs
Quoted 4 lines
hw/timer/Makefile.objs +4
-0+ high_ticks = (uint32_t) (s->tick_offset >> 32); + } + + return high_ticks;These two functions are very similar and would benefit from being refactored to call a utility function that just returned the 64-bit count.
Good point.
Thanks,
Alistair
Quoted 3 lines
thanks
-- PMM