@samitouri / QOSamiQemu / commits / f7060ac4e7

x86: q35: generate WDAT ACPI table

It will generate WDAT table [1] customized for TCO watchdog. This allows Windows guests (Windows Server 2008/Vista+) to use TCO watchdog using built-in generic driver, which alleviates need to install vendor specific drivers. Given that enabling it might change guest behaviour (both Windows/Linux) the feature is disabled by default. Users that need it can enable the feature with following CLI option. -machine wdat=on 1) "Hardware Watchdog Timers Design Specification" https://uefi.org/acpi 'Watchdog Action Table (WDAT)' Signed-off-by: Igor Mammedov <imammedo@redhat.com> Reviewed-by: Ani Sinha <anisinha@redhat.com> Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Message-Id: <20260303092532.2410177-4-imammedo@redhat.com>

Igor Mammedov committed Mar 3, 2026 at 10:25 UTC f7060ac4e7dda3edc6153356c6d665f27847368c
5 files changed +134 -1
hw/acpi/meson.build
+2 -1
@@ -25,7 +25,8 @@ acpi_ss.add(when: 'CONFIG_ACPI_PCI_BRIDGE', if_true: files('pci-bridge.c'))
25 acpi_ss.add(when: 'CONFIG_ACPI_PCIHP', if_true: files('pcihp.c'))
26 stub_ss.add(files('acpi-pci-hotplug-stub.c'))
27 acpi_ss.add(when: 'CONFIG_ACPI_VIOT', if_true: files('viot.c'))
28 -acpi_ss.add(when: 'CONFIG_ACPI_ICH9', if_true: files('ich9.c', 'ich9_tco.c', 'ich9_timer.c'))
28 +acpi_ss.add(when: 'CONFIG_ACPI_ICH9', if_true: files('ich9.c', 'ich9_tco.c', 'ich9_timer.c', 'wdat-ich9.c'))
29 +stub_ss.add(files('wdat-ich9-stub.c'))
30 acpi_ss.add(when: 'CONFIG_ACPI_ERST', if_true: files('erst.c'))
31 acpi_ss.add(when: 'CONFIG_IPMI', if_true: files('ipmi.c'))
32 stub_ss.add(files('ipmi-stub.c'))
hw/acpi/wdat-ich9-stub.c new
+15
@@ -0,0 +1,15 @@
1 +/*
2 + * Copyright Red Hat, Inc. 2026
3 + * Author(s): Igor Mammedov <imammedo@redhat.com>
4 + *
5 + * SPDX-License-Identifier: GPL-2.0-or-later
6 + */
7 +
8 +#include "qemu/osdep.h"
9 +#include "hw/acpi/wdat-ich9.h"
10 +
11 +void build_ich9_wdat(GArray *table_data, BIOSLinker *linker, const char *oem_id,
12 + const char *oem_table_id, uint64_t tco_base)
13 +{
14 + g_assert_not_reached();
15 +}
hw/acpi/wdat-ich9.c new
+90
@@ -0,0 +1,90 @@
1 +/*
2 + * TCO Watchdog Action Table (WDAT)
3 + *
4 + * Copyright Red Hat, Inc. 2026
5 + * Author(s): Igor Mammedov <imammedo@redhat.com>
6 + *
7 + * SPDX-License-Identifier: GPL-2.0-or-later
8 + */
9 +
10 +#include "qemu/osdep.h"
11 +#include "hw/acpi/wdat.h"
12 +#include "hw/acpi/wdat-ich9.h"
13 +#include "hw/southbridge/ich9.h"
14 +
15 +#define TCO_REG(base, reg_offset, reg_width) { .space_id = AML_AS_SYSTEM_IO, \
16 + .address = base + reg_offset, .bit_width = reg_width, \
17 + .access_width = AML_WORD_ACC, };
18 +
19 +/*
20 + * "Hardware Watchdog Timers Design Specification"
21 + * https://uefi.org/acpi 'Watchdog Action Table (WDAT)'
22 + *
23 + * ICH9 specific implementation.
24 + */
25 +void build_ich9_wdat(GArray *table_data, BIOSLinker *linker, const char *oem_id,
26 + const char *oem_table_id, uint64_t tco_base)
27 +{
28 + AcpiTable table = { .sig = "WDAT", .rev = 1, .oem_id = oem_id,
29 + .oem_table_id = oem_table_id };
30 + struct AcpiGenericAddress tco_rld = TCO_REG(tco_base, 0x0, 16);
31 + struct AcpiGenericAddress tco2_sts = TCO_REG(tco_base, 0x6, 16);
32 + struct AcpiGenericAddress tco1_cnt = TCO_REG(tco_base, 0x8, 16);
33 + struct AcpiGenericAddress tco_tmr = TCO_REG(tco_base, 0x12, 16);
34 +
35 + acpi_table_begin(&table, table_data);
36 + build_append_int_noprefix(table_data, 0x20, 4); /* Watchdog Header Length */
37 + build_append_int_noprefix(table_data, 0xff, 2); /* PCI Segment */
38 + build_append_int_noprefix(table_data, 0xff, 1); /* PCI Bus Number */
39 + build_append_int_noprefix(table_data, 0xff, 1); /* PCI Device Number */
40 + build_append_int_noprefix(table_data, 0xff, 1); /* PCI Function Number */
41 + build_append_int_noprefix(table_data, 0, 3); /* Reserved */
42 + /*
43 + * limits/resolution are defined by ICH9 TCO spec
44 + */
45 + build_append_int_noprefix(table_data, 0x258, 4);/* Timer Period, ms */
46 + build_append_int_noprefix(table_data, 0x3ff, 4);/* Maximum Count */
47 + build_append_int_noprefix(table_data, 0x4, 4); /* Minimum Count */
48 + /*
49 + * WATCHDOG_ENABLED & WATCHDOG_STOPPED_IN_SLEEP_STATE
50 + */
51 + build_append_int_noprefix(table_data, 0x81, 1); /* Watchdog Flags */
52 + build_append_int_noprefix(table_data, 0, 3); /* Reserved */
53 + /*
54 + * watchdog instruction entries
55 + */
56 + build_append_int_noprefix(table_data, 10 /* # of actions below */, 4);
57 + /* Action table */
58 + build_append_wdat_ins(table_data, WDAT_ACTION_RESET,
59 + WDAT_INS_WRITE_VALUE,
60 + tco_rld, 0x1, 0x1ff);
61 + build_append_wdat_ins(table_data, WDAT_ACTION_QUERY_RUNNING_STATE,
62 + WDAT_INS_READ_VALUE,
63 + tco1_cnt, 0x0, 0x800);
64 + build_append_wdat_ins(table_data, WDAT_ACTION_SET_RUNNING_STATE,
65 + WDAT_INS_WRITE_VALUE | WDAT_INS_PRESERVE_REGISTER,
66 + tco1_cnt, 0, 0x800);
67 + build_append_wdat_ins(table_data, WDAT_ACTION_QUERY_STOPPED_STATE,
68 + WDAT_INS_READ_VALUE,
69 + tco1_cnt, 0x800, 0x800);
70 + build_append_wdat_ins(table_data, WDAT_ACTION_SET_STOPPED_STATE,
71 + WDAT_INS_WRITE_VALUE | WDAT_INS_PRESERVE_REGISTER,
72 + tco1_cnt, 0x800, 0x800);
73 + build_append_wdat_ins(table_data, WDAT_ACTION_SET_COUNTDOWN_PERIOD,
74 + WDAT_INS_WRITE_COUNTDOWN,
75 + tco_tmr, 0x0, 0x3FF);
76 + build_append_wdat_ins(table_data, WDAT_ACTION_QUERY_COUNTDOWN_PERIOD,
77 + WDAT_INS_READ_COUNTDOWN,
78 + tco_tmr, 0x0, 0x3FF);
79 + build_append_wdat_ins(table_data, WDAT_ACTION_QUERY_WATCHDOG_STATUS,
80 + WDAT_INS_READ_VALUE,
81 + tco2_sts, 0x2, 0x2);
82 + build_append_wdat_ins(table_data, WDAT_ACTION_SET_WATCHDOG_STATUS,
83 + WDAT_INS_WRITE_VALUE | WDAT_INS_PRESERVE_REGISTER,
84 + tco2_sts, 0x2, 0x2);
85 + build_append_wdat_ins(table_data, WDAT_ACTION_SET_WATCHDOG_STATUS,
86 + WDAT_INS_WRITE_VALUE | WDAT_INS_PRESERVE_REGISTER,
87 + tco2_sts, 0x4, 0x4);
88 +
89 + acpi_table_end(linker, &table);
90 +}
hw/i386/acpi-build.c
+12
@@ -78,6 +78,7 @@
78
79 #include "hw/acpi/hmat.h"
80 #include "hw/acpi/viot.h"
81 +#include "hw/acpi/wdat-ich9.h"
82
83 #include CONFIG_DEVICES
84
@@ -110,6 +111,7 @@ typedef struct AcpiPmInfo {
111 uint16_t cpu_hp_io_base;
112 uint16_t pcihp_io_base;
113 uint16_t pcihp_io_len;
114 + uint64_t tco_io_base;
115 } AcpiPmInfo;
116
117 typedef struct AcpiMiscInfo {
@@ -204,6 +206,7 @@ static void acpi_get_pm_info(MachineState *machine, AcpiPmInfo *pm)
206 pm->pcihp_io_len = 0;
207 pm->smi_on_cpuhp = false;
208 pm->smi_on_cpu_unplug = false;
209 + pm->tco_io_base = 0;
210
211 assert(obj);
212 init_common_fadt_data(machine, obj, &pm->fadt);
@@ -225,6 +228,8 @@ static void acpi_get_pm_info(MachineState *machine, AcpiPmInfo *pm)
228 !!(smi_features & BIT_ULL(ICH9_LPC_SMI_F_CPU_HOTPLUG_BIT));
229 pm->smi_on_cpu_unplug =
230 !!(smi_features & BIT_ULL(ICH9_LPC_SMI_F_CPU_HOT_UNPLUG_BIT));
231 + pm->tco_io_base = object_property_get_uint(obj, ACPI_PM_PROP_PM_IO_BASE,
232 + NULL) + ICH9_PMIO_TCO_RLD;
233 }
234 pm->pcihp_io_base =
235 object_property_get_uint(obj, ACPI_PCIHP_IO_BASE_PROP, NULL);
@@ -2078,6 +2083,13 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)
2083 acpi_add_table(table_offsets, tables_blob);
2084 build_waet(tables_blob, tables->linker, x86ms->oem_id, x86ms->oem_table_id);
2085
2086 + if (pcms->wdat_enabled == true) {
2087 + g_assert(pm.tco_io_base);
2088 + acpi_add_table(table_offsets, tables_blob);
2089 + build_ich9_wdat(tables_blob, tables->linker, x86ms->oem_id,
2090 + x86ms->oem_table_id, pm.tco_io_base);
2091 + }
2092 +
2093 /* Add tables supplied by user (if any) */
2094 for (u = acpi_table_first(); u; u = acpi_table_next(u)) {
2095 unsigned len = acpi_table_len(u);
include/hw/acpi/wdat-ich9.h new
+15
@@ -0,0 +1,15 @@
1 +/*
2 + * Copyright Red Hat, Inc. 2026
3 + * Author(s): Igor Mammedov <imammedo@redhat.com>
4 + *
5 + * SPDX-License-Identifier: GPL-2.0-or-later
6 + */
7 +#ifndef QEMU_HW_ACPI_WDAT_ICH9_H
8 +#define QEMU_HW_ACPI_WDAT_ICH9_H
9 +
10 +#include "hw/acpi/aml-build.h"
11 +
12 +void build_ich9_wdat(GArray *table_data, BIOSLinker *linker, const char *oem_id,
13 + const char *oem_table_id, uint64_t tco_base);
14 +
15 +#endif /* QEMU_HW_ACPI_WDAT_ICH9_H */