Implement the watchdog timer of HiFive 1 rev b.
Subsystems (3)
v6 cover Implement the watchdog timer of HiFive 1 rev b.
The HiFive 1 rev b includes a watchdog module based on a 32-bit counter. The watchdog timer is in the always-on domain device of HiFive 1 rev b, so this patch added the AON device to the sifive_e machine. This patch only implemented the functionality of the watchdog timer, not all the functionality of the AON device.
You can test the patchset by the QTest tests/qtest/sifive-e-aon-watchdog-test.c
Changes since v1 ( Thank Alistair for the feedback ):
- Use the register field macro.
- Delete the public create function. The board creates the aon device itself.
- Keep all variable declarations at the top of the code block.
Changes since v2 ( Thank Alistair for the feedback ):
- Delete the declaration and definition of the create function.
Changes since v3 ( Thank Alistair and Thomas for the feedback ):
- Use device_class_set_props() for the properties in sifive_e_aon device.
- Add SPDX identifier in QTEST.
- Use libqtest.h in QTEST.
- Let the statements on one line as long as they still fit into 80 columns.
Changes since v4 ( Thank Phil for the feedback ):
- Improve code style consistency.
- Move the timer create function to the sifive_e_aon_init.
- Allocate the sifive_e_aon device state in the SoC.
Changes since v5 ( Thank Alistair for the feedback ):
- Rebase to the riscv-to-apply.next branch.
Tommy Wu (3):
hw/misc: sifive_e_aon: Support the watchdog timer of HiFive 1 rev b. hw/riscv: sifive_e: Support the watchdog timer of HiFive 1 rev b. tests/qtest: sifive-e-aon-watchdog-test.c: Add QTest of watchdog of
sifive_e
hw/misc/Kconfig | 3 + hw/misc/meson.build | 1 + hw/misc/sifive_e_aon.c | 319 ++++++++++++++++ hw/riscv/Kconfig | 1 + hw/riscv/sifive_e.c | 17 +- include/hw/misc/sifive_e_aon.h | 60 +++ include/hw/riscv/sifive_e.h | 9 +- tests/qtest/meson.build | 3 + tests/qtest/sifive-e-aon-watchdog-test.c | 450 +++++++++++++++++++++++ 9 files changed, 858 insertions(+), 5 deletions(-) create mode 100644 hw/misc/sifive_e_aon.c create mode 100644 include/hw/misc/sifive_e_aon.h create mode 100644 tests/qtest/sifive-e-aon-watchdog-test.c
Signature · 1 line
2.31.1
PATCH v6 1/3 hw/misc: sifive_e_aon: Support the watchdog timer of HiFive 1 rev b.
The watchdog timer is in the always-on domain device of HiFive 1 rev b, so this patch added the AON device to the sifive_e machine. This patch only implemented the functionality of the watchdog timer.
--- hw/misc/Kconfig | 3 + hw/misc/meson.build | 1 + hw/misc/sifive_e_aon.c | 319 +++++++++++++++++++++++++++++++++ include/hw/misc/sifive_e_aon.h | 60 +++++++ 4 files changed, 383 insertions(+) create mode 100644 hw/misc/sifive_e_aon.c create mode 100644 include/hw/misc/sifive_e_aon.h
hw/misc/Kconfig +3 -0
@@ -158,6 +158,9 @@ config SIFIVE_TEST config SIFIVE_E_PRCI bool +config SIFIVE_E_AON + bool + config SIFIVE_U_OTP bool
hw/misc/meson.build +1 -0
@@ -30,6 +30,7 @@ system_ss.add(when: 'CONFIG_MCHP_PFSOC_IOSCB', if_true: files('mchp_pfsoc_ioscb. system_ss.add(when: 'CONFIG_MCHP_PFSOC_SYSREG', if_true: files('mchp_pfsoc_sysreg.c')) system_ss.add(when: 'CONFIG_SIFIVE_TEST', if_true: files('sifive_test.c')) system_ss.add(when: 'CONFIG_SIFIVE_E_PRCI', if_true: files('sifive_e_prci.c')) +system_ss.add(when: 'CONFIG_SIFIVE_E_AON', if_true: files('sifive_e_aon.c')) system_ss.add(when: 'CONFIG_SIFIVE_U_OTP', if_true: files('sifive_u_otp.c')) system_ss.add(when: 'CONFIG_SIFIVE_U_PRCI', if_true: files('sifive_u_prci.c'))
hw/misc/sifive_e_aon.c new file +319 -0
319 lines not on this page · raw message
include/hw/misc/sifive_e_aon.h new file +60 -0
60 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v6 2/3 hw/riscv: sifive_e: Support the watchdog timer of HiFive 1 rev b.
In reply to Tommy WuCreate the AON device when we realize the sifive_e machine. This patch only implemented the functionality of the watchdog timer, not all the functionality of the AON device.
--- hw/riscv/Kconfig | 1 + hw/riscv/sifive_e.c | 17 +++++++++++++++-- include/hw/riscv/sifive_e.h | 9 ++++++--- 3 files changed, 22 insertions(+), 5 deletions(-)
hw/riscv/Kconfig +1 -0
@@ -60,6 +60,7 @@ config SIFIVE_E select SIFIVE_PLIC select SIFIVE_UART select SIFIVE_E_PRCI + select SIFIVE_E_AON select UNIMP config SIFIVE_U
hw/riscv/sifive_e.c +15 -2
@@ -45,6 +45,7 @@#include "hw/intc/riscv_aclint.h" #include "hw/intc/sifive_plic.h" #include "hw/misc/sifive_e_prci.h" +#include "hw/misc/sifive_e_aon.h" #include "chardev/char.h" #include "sysemu/sysemu.h"
@@ -185,6 +186,8 @@ static void sifive_e_soc_init(Object *obj)object_property_set_int (OBJECT (&s->cpus),"resetvec" ,0x1004 , &error_abort);object_initialize_child (obj,"riscv.sifive.e.gpio0" , &s->gpio,TYPE_SIFIVE_GPIO ); +object_initialize_child (obj,"riscv.sifive.e.aon" , &s->aon, +TYPE_SIFIVE_E_AON ); }static void sifive_e_soc_realize (DeviceState *dev,Error **errp)
@@ -223,10 +226,17 @@ static void sifive_e_soc_realize(DeviceState *dev, Error **errp)RISCV_ACLINT_DEFAULT_MTIMER_SIZE ,0 , ms->smp.cpus,RISCV_ACLINT_DEFAULT_MTIMECMP ,RISCV_ACLINT_DEFAULT_MTIME , RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ, false); -create_unimplemented_device ("riscv.sifive.e.aon" , - memmap[SIFIVE_E_DEV_AON ].base, memmap[SIFIVE_E_DEV_AON ].size);sifive_e_prci_create (memmap[SIFIVE_E_DEV_PRCI ].base); +/* AON */ + +if (!sysbus_realize (SYS_BUS_DEVICE (&s->aon), errp)) { +return ; + } + +/* Map AON registers */ +sysbus_mmio_map (SYS_BUS_DEVICE (&s->aon),0 , memmap[SIFIVE_E_DEV_AON ].base); +/* GPIO */ if (!sysbus_realize (SYS_BUS_DEVICE (&s->gpio), errp)) {
@@ -245,6 +255,9 @@ static void sifive_e_soc_realize(DeviceState *dev, Error **errp)qdev_get_gpio_in (DEVICE (s->plic), SIFIVE_E_GPIO0_IRQ0 + i)); } +sysbus_connect_irq (SYS_BUS_DEVICE (&s->aon),0 , +qdev_get_gpio_in (DEVICE (s->plic), +SIFIVE_E_AON_WDT_IRQ ));sifive_uart_create (sys_mem, memmap[SIFIVE_E_DEV_UART0 ].base,serial_hd (0 ),qdev_get_gpio_in (DEVICE (s->plic),SIFIVE_E_UART0_IRQ ));
include/hw/riscv/sifive_e.h +6 -3
@@ -22,6 +22,7 @@#include "hw/riscv/riscv_hart.h" #include "hw/riscv/sifive_cpu.h" #include "hw/gpio/sifive_gpio.h" +#include "hw/misc/sifive_e_aon.h" #include "hw/boards.h" #define TYPE_RISCV_E_SOC "riscv.sifive.e.soc"
@@ -35,6 +36,7 @@ typedef struct SiFiveESoCState {/*< public >*/ RISCVHartArrayState cpus;DeviceState *plic; +SiFiveEAONState aon;SIFIVEGPIOState gpio;MemoryRegion xip_mem;MemoryRegion mask_rom;
@@ -76,9 +78,10 @@ enum { };enum { -SIFIVE_E_UART0_IRQ =3 , -SIFIVE_E_UART1_IRQ =4 , -SIFIVE_E_GPIO0_IRQ0 =8 +SIFIVE_E_AON_WDT_IRQ =1 , +SIFIVE_E_UART0_IRQ =3 , +SIFIVE_E_UART1_IRQ =4 , +SIFIVE_E_GPIO0_IRQ0 =8 };#define SIFIVE_E_PLIC_HART_CONFIG "M"
Signature · 1 line
2.31.1
Re: [PATCH v6 2/3] hw/riscv: sifive_e: Support the watchdog timer of HiFive 1 rev b.
Quoted 4 lines · Tommy Wu
Create the AON device when we realize the
sifive_emachine. This patch only implemented the functionality of the watchdog timer, not all the functionality of the AON device.
Quoted 8 lines
Signed-off-by Tommy Wu <[email protected]>Reviewed-by Frank Chang <[email protected]>Reviewed-by Alistair Francis <[email protected]>--- hw/riscv/Kconfig | 1 + hw/riscv/sifive_e.c | 17 +++++++++++++++-- include/hw/riscv/sifive_e.h | 9 ++++++--- 3 files changed, 22 insertions(+), 5 deletions(-)
PATCH v6 3/3 tests/qtest: sifive-e-aon-watchdog-test.c: Add QTest of watchdog of sifive_e
In reply to Tommy WuAdd some simple tests of the watchdog timer in the always-on domain device of HiFive 1 rev b.
--- tests/qtest/meson.build | 3 + tests/qtest/sifive-e-aon-watchdog-test.c | 450 +++++++++++++++++++++++ 2 files changed, 453 insertions(+) create mode 100644 tests/qtest/sifive-e-aon-watchdog-test.c
tests/qtest/meson.build +3 -0
@@ -234,6 +234,9 @@ qtests_s390x = \ 'cpu-plug-test', 'migration-test'] +qtests_riscv32 = \ + (config_all_devices.has_key('CONFIG_SIFIVE_E_AON') ? ['sifive-e-aon-watchdog-test'] : []) + qos_test_ss = ss.source_set() qos_test_ss.add( 'ac97-test.c',
tests/qtest/sifive-e-aon-watchdog-test.c new file +450 -0
450 lines not on this page · raw message
Signature · 1 line
2.31.1
Alistair Francis
AppliedQuoted 28 lines · Tommy Wu
The HiFive 1 rev b includes a watchdog module based on a 32-bit counter. The watchdog timer is in the always-on domain device of HiFive 1 rev b, so this patch added the AON device to the
sifive_emachine. This patch only implemented the functionality of the watchdog timer, not all the functionality of the AON device.You can test the patchset by the QTest
tests/qtest/sifive-e-aon-watchdog-test.cChanges since v1 ( Thank Alistair for the feedback ):
- Use the register field macro.
- Delete the public create function. The board creates the aon device itself.
- Keep all variable declarations at the top of the code block.Changes since v2 ( Thank Alistair for the feedback ):
- Delete the declaration and definition of the create function.Changes since v3 ( Thank Alistair and Thomas for the feedback ):
- Usedevice_class_set_props()for the properties insifive_e_aondevice.
- Add SPDX identifier in QTEST.
- Uselibqtest.hin QTEST.
- Let the statements on one line as long as they still fit into 80 columns.Changes since v4 ( Thank Phil for the feedback ):
- Improve code style consistency.
- Move the timer create function to thesifive_e_aon_init.
- Allocate thesifive_e_aondevice state in the SoC.
Quoted 8 lines
Changes since v5 ( Thank Alistair for the feedback ):
- Rebase to the riscv-to-apply.next branch.Tommy Wu (3):
hw/misc:sifive_e_aon: Support the watchdog timer of HiFive 1 rev b. hw/riscv:sifive_e: Support the watchdog timer of HiFive 1 rev b. tests/qtest:sifive-e-aon-watchdog-test.c: Add QTest of watchdog of
sifive_e
Thanks!
Applied to riscv-to-apply.next
Alistair
Quoted 19 lines
hw/misc/Kconfig | 3 + hw/misc/meson.build | 1 + hw/misc/sifive_e_aon.c | 319 ++++++++++++++++ hw/riscv/Kconfig | 1 + hw/riscv/sifive_e.c | 17 +- include/hw/misc/sifive_e_aon.h | 60 +++ include/hw/riscv/sifive_e.h | 9 +- tests/qtest/meson.build | 3 + tests/qtest/sifive-e-aon-watchdog-test.c | 450 +++++++++++++++++++++++ 9 files changed, 858 insertions(+), 5 deletions(-) create mode 100644 hw/misc/sifive_e_aon.c create mode 100644 include/hw/misc/sifive_e_aon.h create mode 100644 tests/qtest/sifive-e-aon-watchdog-test.c--
2.31.1