hw: wdt: implement sbsa watchdog
PATCH 1/1 hw: wdt: implement sbsa watchdog
Initial virtual driver matching linux kernel sbsa_gwdt driver. Driver implements basic functionality and makes watchdog works on virtual machine and allows to reboot secure OS. I.e. atf->optee->efi/uboot->kernel. More information about that device can be found under:
ARM DEN0029B - Server Base System Architecture (SBSA)
--- hw/arm/virt.c | 28 ++++ hw/watchdog/Kconfig | 5 + hw/watchdog/meson.build | 1 + hw/watchdog/sbsa_wdt.c | 293 +++++++++++++++++++++++++++++++++ include/hw/arm/virt.h | 2 + include/hw/watchdog/sbsa-wdt.h | 40 +++++ 6 files changed, 369 insertions(+) create mode 100644 hw/watchdog/sbsa_wdt.c create mode 100644 include/hw/watchdog/sbsa-wdt.h
hw/arm/virt.c +28 -0
@@ -77,6 +77,7 @@#include "hw/acpi/generic_event_device.h" #include "hw/virtio/virtio-iommu.h" #include "hw/char/pl011.h" +#include "hw/watchdog/sbsa-wdt.h" #include "qemu/guest-random.h" #define DEFINE_VIRT_MACHINE_LATEST (major, minor, latest) \
@@ -745,6 +746,31 @@ static void create_gic(VirtMachineState *vms) } } +static void create_sbsa_watchdog (VirtMachineState *vms) +{ +char *nodename; +const char compat[] ="arm,sbsa-gwdt" ; + +object_initialize_child (OBJECT (vms),"arm,sbsa-gwdt" , &vms->watchdog, +TYPE_SBSA_WATCHDOG ); +sysbus_realize (SYS_BUS_DEVICE (&vms->watchdog), &error_fatal); +/* contol */ +sysbus_mmio_map (SYS_BUS_DEVICE (&vms->watchdog),0 ,0x2a440000UL ); +/* refresh */ +sysbus_mmio_map (SYS_BUS_DEVICE (&vms->watchdog),1 ,0x2a450000UL ); +/* dtb */ + nodename =g_strdup_printf ("/watchdog@%" PRIx64,0x2a440000UL ); +qemu_fdt_add_subnode (vms->fdt, nodename); + +qemu_fdt_setprop (vms->fdt, nodename,"compatible" , + compat,sizeof (compat)); +qemu_fdt_setprop_sized_cells (vms->fdt, nodename,"reg" , +2 ,0x2a440000UL ,2 ,0x1000 , +2 ,0x2a450000UL ,2 ,0x1000 ); +qemu_fdt_setprop_cell (vms->fdt, nodename,"timeout-sec" ,30 ); +g_free (nodename); +} +static void create_uart (const VirtMachineState *vms,int uart,MemoryRegion *mem,Chardev *chr) {
@@ -1913,6 +1939,8 @@ static void machvirt_init(MachineState *machine)create_gic (vms); +create_sbsa_watchdog (vms); +fdt_add_pmu_nodes (vms);create_uart (vms,VIRT_UART , sysmem,serial_hd (0 ));
hw/watchdog/Kconfig +5 -0
@@ -17,3 +17,8 @@ config WDT_DIAG288 config WDT_IMX2 bool + +config WDT_SBSA + bool + default y + select PTIMER
hw/watchdog/meson.build +1 -0
@@ -5,3 +5,4 @@ softmmu_ss.add(when: 'CONFIG_WDT_IB700', if_true: files('wdt_ib700.c')) softmmu_ss.add(when: 'CONFIG_WDT_DIAG288', if_true: files('wdt_diag288.c')) softmmu_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('wdt_aspeed.c')) softmmu_ss.add(when: 'CONFIG_WDT_IMX2', if_true: files('wdt_imx2.c')) +softmmu_ss.add(when: 'CONFIG_WDT_SBSA', if_true: files('sbsa_wdt.c'))
hw/watchdog/sbsa_wdt.c new file +293 -0
293 lines not on this page · raw message
include/hw/arm/virt.h +2 -0
@@ -37,6 +37,7 @@#include "hw/block/flash.h" #include "sysemu/kvm.h" #include "hw/intc/arm_gicv3_common.h" +#include "hw/watchdog/sbsa-wdt.h" #include "qom/object.h" #define NUM_GICV2M_SPIS 64
@@ -163,6 +164,7 @@ struct VirtMachineState {DeviceState *gic;DeviceState *acpi_dev;Notifier powerdown_notifier; +SBSAWatchdog watchdog; };#define VIRT_ECAM_ID (high) (high ? VIRT_HIGH_PCIE_ECAM : VIRT_PCIE_ECAM)
include/hw/watchdog/sbsa-wdt.h new file +40 -0
@@ -0,0 +1,40 @@ +/* +* ARM SBSA watchdog emulation +* +* Copyright (c) 2020 Linaro Limited +* Written by Maxim Uvarov +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 or +* (at your option) any later version. +*/ + +#ifndef SBSA_WATCHDOG_H +#define SBSA_WATCHDOG_H + +#include "hw/sysbus.h" +#include "hw/ptimer.h" +#include "qom/object.h" + +#define TYPE_SBSA_WATCHDOG "sbsa-watchdog" +OBJECT_DECLARE_SIMPLE_TYPE(SBSAWatchdog, SBSA_WATCHDOG) + +#define TYPE_LUMINARY_WATCHDOG "sbsa-watchdog" + +struct SBSAWatchdog { +/*< private >*/ +SysBusDevice parent_obj; + +/*< public >*/ +MemoryRegion iomem_control; +MemoryRegion iomem_refresh; +qemu_irq wdogint; +uint32_t timeout_sec; +bool is_two_stages;/* tbd */ +struct ptimer_state *timer; + +bool enable; +uint64_t cur_tick; +}; + +#endif
Signature · 1 line
2.17.1
Quoted 9 lines · Maxim Uvarov
Initial virtual driver matching linux kernel
sbsa_gwdtdriver. Driver implements basic functionality and makes watchdog works on virtual machine and allows to reboot secure OS. I.e. atf->optee->efi/uboot->kernel. More information about that device can be found under:
ARM DEN0029B - Server Base System Architecture (SBSA)Signed-off-by Maxim Uvarov <[email protected]>
Hi; what's the relationship between this SBSA watchdog device model and the one that Shashi posted recently?
https://patchew.org/QEMU/[email protected]/
thanks
-- PMM
Quoted 10 lines · Peter Maydell
Quoted 8 lines · Maxim Uvarov
Initial virtual driver matching linux kernel
sbsa_gwdtdriver. Driver implements basic functionality and makes watchdog works on virtual machine and allows to reboot secure OS. I.e. atf->optee->efi/uboot->kernel. More information about that device can be found under:
ARM DEN0029B - Server Base System Architecture (SBSA)
Quoted 8 lines
Quoted 1 line
Signed-off-by Maxim Uvarov <[email protected]>Hi; what's the relationship between this SBSA watchdog device model and the one that Shashi posted recently?
https://patchew.org/QEMU/[email protected]/thanks
-- PMM
Nice it's the same driver written a little bit differently. I did not see his patch before. 2 things missing in Sashis driver which are useful for me:
1. Add sbsa watchdog to machine virt also. That helped me to reboot a virtual machine with secure payload.
2. I specially did not disable timer on driver close. I.e. "reboot" linux path reboots with that watchdog. And make timeout lower to not wait for a long period.
Can this driver also be considered for virt machine?
Regards,
Maxim.
Quoted 6 lines · Maxim Uvarov
Quoted 3 lines · Peter Maydell
Hi; what's the relationship between this SBSA watchdog device model and the one that Shashi posted recently?
https://patchew.org/QEMU/[email protected]/
Quoted 8 lines
Nice it's the same driver written a little bit differently. I did not see his patch before. 2 things missing in Sashis driver which are useful for me:
1. Add sbsa watchdog to machine virt also. That helped me to reboot a virtual machine with secure payload.
2. I specially did not disable timer on driver close. I.e. "reboot" linux path reboots with that watchdog. And make timeout lower to not wait for a long period.
You should get together and figure out a single version of the patchset that you want to upstream...
Quoted 1 line
Can this driver also be considered for virt machine?
Maybe, but you'd need to explain why it's useful (ie why you can't just plug in the wdt_i6300esb, which I think is a PCI watchdog device). We try not to add devices to virt unless we have to, because they increase the security attack surface.
thanks
-- PMM