From: Igor Mammedov <[email protected]> Add build_gwdt_wdat() to generate a Watchdog Action Table designed for SBSA Generic Watchdog Timer.
Signed-off-by: Igor Mammedov <[email protected]> Reviewed-by: Eric Auger <[email protected]> Reviewed-by: Michael S. Tsirkin <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> Message-ID: <[email protected]> --- include/hw/acpi/wdat-gwdt.h | 19 +++++++ hw/acpi/wdat-gwdt-stub.c | 16 ++++++ hw/acpi/wdat-gwdt.c | 99 +++++++++++++++++++++++++++++++++++++ hw/acpi/meson.build | 2 + 4 files changed, 136 insertions(+) create mode 100644 include/hw/acpi/wdat-gwdt.h create mode 100644 hw/acpi/wdat-gwdt-stub.c create mode 100644 hw/acpi/wdat-gwdt.c diff --git a/include/hw/acpi/wdat-gwdt.h b/include/hw/acpi/wdat-gwdt.h new file mode 100644 index 0000000000..42339e031e --- /dev/null +++ b/include/hw/acpi/wdat-gwdt.h @@ -0,0 +1,19 @@ +/* + * GWDT Watchdog Action Table (WDAT) definition + * + * Copyright Red Hat, Inc. 2026 + * Author(s): Igor Mammedov <[email protected]> + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#ifndef QEMU_HW_ACPI_WDAT_GWDT_H +#define QEMU_HW_ACPI_WDAT_GWDT_H + +#include "hw/acpi/aml-build.h" +#include "hw/watchdog/sbsa_gwdt.h" + +void build_gwdt_wdat(GArray *table_data, BIOSLinker *linker, const char *oem_id, + const char *oem_table_id, uint64_t rbase, uint64_t cbase, + uint64_t freq); + +#endif /* QEMU_HW_ACPI_WDAT_GWDT_H */ diff --git a/hw/acpi/wdat-gwdt-stub.c b/hw/acpi/wdat-gwdt-stub.c new file mode 100644 index 0000000000..4d43783f70 --- /dev/null +++ b/hw/acpi/wdat-gwdt-stub.c @@ -0,0 +1,16 @@ +/* + * Copyright Red Hat, Inc. 2026 + * Author(s): Igor Mammedov <[email protected]> + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "hw/acpi/wdat-gwdt.h" + +void build_gwdt_wdat(GArray *table_data, BIOSLinker *linker, const char *oem_id, + const char *oem_table_id, uint64_t rbase, uint64_t cbase, + uint64_t freq) +{ + g_assert_not_reached(); +} diff --git a/hw/acpi/wdat-gwdt.c b/hw/acpi/wdat-gwdt.c new file mode 100644 index 0000000000..b30566ef6a --- /dev/null +++ b/hw/acpi/wdat-gwdt.c @@ -0,0 +1,99 @@ +/* + * SBSA GWDT Watchdog Action Table (WDAT) + * + * Copyright Red Hat, Inc. 2026 + * Author(s): Igor Mammedov <[email protected]> + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "hw/acpi/aml-build.h" +#include "hw/acpi/wdat-gwdt.h" +#include "hw/acpi/wdat.h" +#include "hw/watchdog/sbsa_gwdt.h" + +#define GWDT_REG(base, reg_offset, reg_width) { \ + .space_id = AML_AS_SYSTEM_MEMORY, \ + .address = base + reg_offset, .bit_width = reg_width, \ + .access_width = AML_DWORD_ACC }; + +/* + * "Hardware Watchdog Timers Design Specification" + * https://uefi.org/acpi 'Watchdog Action Table (WDAT)' + */ +void build_gwdt_wdat(GArray *table_data, BIOSLinker *linker, const char *oem_id, + const char *oem_table_id, uint64_t rbase, uint64_t cbase, + uint64_t freq) +{ + AcpiTable table = { .sig = "WDAT", .rev = 1, .oem_id = oem_id, + .oem_table_id = oem_table_id }; + + struct AcpiGenericAddress wrr = GWDT_REG(rbase, 0x0, 32); + struct AcpiGenericAddress wor_l = GWDT_REG(cbase, SBSA_GWDT_WOR, 32); + struct AcpiGenericAddress wcs = GWDT_REG(cbase, SBSA_GWDT_WCS, 32); + + acpi_table_begin(&table, table_data); + build_append_int_noprefix(table_data, 0x20, 4); /* Watchdog Header Length */ + /* + * PCI location fields are set to 0xff to indicate + * that the watchdog is not a PCI device. + */ + build_append_int_noprefix(table_data, 0xff, 2); /* PCI Segment */ + build_append_int_noprefix(table_data, 0xff, 1); /* PCI Bus Number */ + build_append_int_noprefix(table_data, 0xff, 1); /* PCI Device Number */ + build_append_int_noprefix(table_data, 0xff, 1); /* PCI Function Number */ + build_append_int_noprefix(table_data, 0, 3); /* Reserved */ + /* + * WDAT spec: "The clock interval that the WDT uses must be + * greater than or equal to 1 millisecond." + */ + g_assert(freq <= 1000); + /* Timer Period, ms */ + build_append_int_noprefix(table_data, 1000 / freq, 4); + /* + * WDAT spec: "The time-out period before the WDT fires is recommended + * to be at least 5 minutes." + * Set max count to 10min and min count to 5sec. + */ + build_append_int_noprefix(table_data, 600 * freq, 4); /* Maximum Count */ + build_append_int_noprefix(table_data, 5 * freq, 4); /* Minimum Count */ + /* + * WATCHDOG_ENABLED | WATCHDOG_STOPPED_IN_SLEEP_STATE + */ + build_append_int_noprefix(table_data, 0x81, 1); /* Watchdog Flags */ + build_append_int_noprefix(table_data, 0, 3); /* Reserved */ + /* + * watchdog instruction entries + */ + build_append_int_noprefix(table_data, 8, 4); + /* Action table: WCS (control/status) register actions */ + build_append_wdat_ins(table_data, WDAT_ACTION_QUERY_RUNNING_STATE, + WDAT_INS_READ_VALUE, + wcs, 0x1, 0x1); + build_append_wdat_ins(table_data, WDAT_ACTION_SET_RUNNING_STATE, + WDAT_INS_WRITE_VALUE | WDAT_INS_PRESERVE_REGISTER, + wcs, 1, 0x00000001); + build_append_wdat_ins(table_data, WDAT_ACTION_QUERY_STOPPED_STATE, + WDAT_INS_READ_VALUE, + wcs, 0x0, 0x00000001); + build_append_wdat_ins(table_data, WDAT_ACTION_SET_STOPPED_STATE, + WDAT_INS_WRITE_VALUE | WDAT_INS_PRESERVE_REGISTER, + wcs, 0x0, 0x00000001); + build_append_wdat_ins(table_data, WDAT_ACTION_QUERY_WATCHDOG_STATUS, + WDAT_INS_READ_VALUE, + wcs, 0x4, 0x00000004); + /* WOR (offset) and WRR (refresh) register actions */ + build_append_wdat_ins(table_data, WDAT_ACTION_SET_COUNTDOWN_PERIOD, + WDAT_INS_WRITE_COUNTDOWN, + wor_l, 0, 0xffffffff); + /* WRR: any write refreshes the watchdog, value is ignored */ + build_append_wdat_ins(table_data, WDAT_ACTION_RESET, + WDAT_INS_WRITE_VALUE, + wrr, 0x1, 0x1); + build_append_wdat_ins(table_data, WDAT_ACTION_SET_WATCHDOG_STATUS, + WDAT_INS_WRITE_VALUE | WDAT_INS_PRESERVE_REGISTER, + wrr, 0x4, 0x4); + + acpi_table_end(linker, &table); +} diff --git a/hw/acpi/meson.build b/hw/acpi/meson.build index 0c7bfb278a..09ad488a04 100644 --- a/hw/acpi/meson.build +++ b/hw/acpi/meson.build @@ -31,11 +31,13 @@ acpi_ss.add(when: 'CONFIG_ACPI_ERST', if_true: files('erst.c')) acpi_ss.add(when: 'CONFIG_IPMI', if_true: files('ipmi.c')) stub_ss.add(files('ipmi-stub.c')) stub_ss.add(files('acpi-x86-stub.c')) +acpi_ss.add(when: 'CONFIG_WDT_SBSA', if_true: files('wdat-gwdt.c')) if have_tpm acpi_ss.add(files('tpm.c')) endif stub_ss.add(files('acpi-stub.c', 'aml-build-stub.c', 'ghes-stub.c')) stub_ss.add(files('pci-bridge-stub.c')) +stub_ss.add(files('wdat-gwdt-stub.c')) system_ss.add_all(when: 'CONFIG_ACPI', if_true: acpi_ss) system_ss.add(when: 'CONFIG_GHES_CPER', if_true: files('ghes_cper.c')) stub_ss.add(files('ghes_cper_stub.c')) -- MST
