@samitouri / QOSamiQemu / commits / f793df3dca

acpi: add API to build WDAT instructions

Add definitions for WDAT[1] actions/instructions and build_append_wdat_ins() API to build table entries. 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> Message-Id: <20260303092532.2410177-2-imammedo@redhat.com> Reviewed-by: Eric Auger <eric.auger@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

Igor Mammedov committed Mar 3, 2026 at 10:25 UTC f793df3dcabab71e794639a794bba1ae1380943c
2 files changed +132
hw/acpi/aml-build.c
+14
@@ -35,6 +35,7 @@
35 #include "hw/acpi/acpi_aml_interface.h"
36 #include "qemu/cutils.h"
37 #include "hw/core/cpu.h"
38 +#include "hw/acpi/wdat.h"
39
40 static GArray *build_alloc_array(void)
41 {
@@ -2872,3 +2873,16 @@ void qbus_build_aml(BusState *bus, Aml *scope)
2873 call_dev_aml_func(DEVICE(kid->child), scope);
2874 }
2875 }
2876 +
2877 +void build_append_wdat_ins(GArray *table_data,
2878 + WDATAction action, uint8_t flags,
2879 + struct AcpiGenericAddress as,
2880 + uint32_t val, uint32_t mask)
2881 +{
2882 + build_append_int_noprefix(table_data, action, 1); /* Watchdog Action */
2883 + build_append_int_noprefix(table_data, flags, 1); /* Instruction Flags */
2884 + build_append_int_noprefix(table_data, 0, 2); /* Reserved */
2885 + build_append_gas_from_struct(table_data, &as); /* Register Region */
2886 + build_append_int_noprefix(table_data, val, 4); /* Value */
2887 + build_append_int_noprefix(table_data, mask, 4); /* Mask */
2888 +}
include/hw/acpi/wdat.h new
+118
@@ -0,0 +1,118 @@
1 +/*
2 + * Watchdog Action Table (WDAT) definitions
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 +#ifndef QEMU_HW_ACPI_WDAT_H
10 +#define QEMU_HW_ACPI_WDAT_H
11 +
12 +#include "hw/acpi/acpi-defs.h"
13 +
14 +/*
15 + * Watchdog actions as described in
16 + * "Hardware Watchdog Timers Design Specification"
17 + * for link to spec see https://uefi.org/acpi
18 + * 'Watchdog Action Table (WDAT)'
19 + */
20 +typedef enum {
21 + /*
22 + * Restarts the watchdog timer's countdown. This action is
23 + * required.
24 + */
25 + WDAT_ACTION_RESET = 0x1,
26 + /*
27 + * Returns the current countdown value of the watchdog hardware
28 + * (in count intervals).
29 + */
30 + WDAT_ACTION_QUERY_CURRENT_COUNTDOWN_PERIOD = 0x4,
31 + /*
32 + * Returns the countdown value the watchdog hardware is
33 + * configured to use when reset (in count intervals).
34 + */
35 + WDAT_ACTION_QUERY_COUNTDOWN_PERIOD = 0x5,
36 + /*
37 + * Sets the countdown value (in count intervals) to be used when
38 + * the watchdog timer is reset. This action is required if
39 + * WDAT_ACTION_RESET does not explicitly write a new
40 + * countdown value to a register during a reset. Otherwise, this
41 + * action is optional.
42 + */
43 + WDAT_ACTION_SET_COUNTDOWN_PERIOD = 0x6,
44 + /*
45 + * Determines if the watchdog hardware is currently in enabled/
46 + * running state. The same result must occur when performed from
47 + * both from enabled/stopped state and enabled/running state. If
48 + * the watchdog hardware is disabled, results are indeterminate.
49 + * This action is required.
50 + */
51 + WDAT_ACTION_QUERY_RUNNING_STATE = 0x8,
52 + /*
53 + * Starts the watchdog, if not already in running state. If the
54 + * watchdog hardware is disabled, results are indeterminate.
55 + * This action is required.
56 + */
57 + WDAT_ACTION_SET_RUNNING_STATE = 0x9,
58 + /*
59 + * Determines if the watchdog hardware is currently in enabled/
60 + * stopped state. The same result must occur when performed from
61 + * both the enabled/stopped state and enabled/running state. If
62 + * the watchdog hardware is disabled, results are indeterminate.
63 + * This action is required.
64 + */
65 + WDAT_ACTION_QUERY_STOPPED_STATE = 0xA,
66 + /*
67 + * Stops the watchdog, if not already in stopped state. If the
68 + * watchdog hardware is disabled, results are indeterminate.
69 + * This action is required.
70 + */
71 + WDAT_ACTION_SET_STOPPED_STATE = 0xB,
72 + /*
73 + * Determines if the watchdog hardware is configured to perform a
74 + * reboot when the watchdog is fired.
75 + */
76 + WDAT_ACTION_QUERY_REBOOT = 0x10,
77 + /*
78 + * Configures the watchdog hardware to perform a reboot when it
79 + * is fired.
80 + */
81 + WDAT_ACTION_SET_REBOOT = 0x11,
82 + /*
83 + * Determines if the watchdog hardware is configured to perform a
84 + * system shutdown when fired.
85 + */
86 + WDAT_ACTION_QUERY_SHUTDOWN = 0x12,
87 + /*
88 + * Configures the watchdog hardware to perform a system shutdown
89 + * when fired.
90 + */
91 + WDAT_ACTION_SET_SHUTDOWN = 0x13,
92 + /*
93 + * Determines if the current boot was caused by the watchdog
94 + * firing. The boot status is required to be set if the watchdog
95 + * fired and caused a reboot. It is recommended that the
96 + * Watchdog Status be set if the watchdog fired and caused a
97 + * shutdown. This action is required.
98 + */
99 + WDAT_ACTION_QUERY_WATCHDOG_STATUS = 0x20,
100 + /*
101 + * Sets the watchdog's boot status to the default value. This
102 + * action is required.
103 + */
104 + WDAT_ACTION_SET_WATCHDOG_STATUS = 0x21,
105 +} WDATAction;
106 +
107 +#define WDAT_INS_READ_VALUE 0x0
108 +#define WDAT_INS_READ_COUNTDOWN 0x1
109 +#define WDAT_INS_WRITE_VALUE 0x2
110 +#define WDAT_INS_WRITE_COUNTDOWN 0x3
111 +#define WDAT_INS_PRESERVE_REGISTER 0x80
112 +
113 +void build_append_wdat_ins(GArray *table_data,
114 + WDATAction action, uint8_t flags,
115 + struct AcpiGenericAddress as,
116 + uint32_t val, uint32_t mask);
117 +
118 +#endif /* QEMU_HW_ACPI_WDAT_H */