/src/qemu/hw/acpi/wdat-ich9.c
Line | Count | Source |
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 | 0 | #define TCO_REG(base, reg_offset, reg_width) { .space_id = AML_AS_SYSTEM_IO, \ |
16 | 0 | .address = base + reg_offset, .bit_width = reg_width, \ |
17 | 0 | .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 | 0 | { |
28 | 0 | AcpiTable table = { .sig = "WDAT", .rev = 1, .oem_id = oem_id, |
29 | 0 | .oem_table_id = oem_table_id }; |
30 | 0 | struct AcpiGenericAddress tco_rld = TCO_REG(tco_base, 0x0, 16); |
31 | 0 | struct AcpiGenericAddress tco2_sts = TCO_REG(tco_base, 0x6, 16); |
32 | 0 | struct AcpiGenericAddress tco1_cnt = TCO_REG(tco_base, 0x8, 16); |
33 | 0 | struct AcpiGenericAddress tco_tmr = TCO_REG(tco_base, 0x12, 16); |
34 | |
|
35 | 0 | acpi_table_begin(&table, table_data); |
36 | 0 | build_append_int_noprefix(table_data, 0x20, 4); /* Watchdog Header Length */ |
37 | 0 | build_append_int_noprefix(table_data, 0xff, 2); /* PCI Segment */ |
38 | 0 | build_append_int_noprefix(table_data, 0xff, 1); /* PCI Bus Number */ |
39 | 0 | build_append_int_noprefix(table_data, 0xff, 1); /* PCI Device Number */ |
40 | 0 | build_append_int_noprefix(table_data, 0xff, 1); /* PCI Function Number */ |
41 | 0 | build_append_int_noprefix(table_data, 0, 3); /* Reserved */ |
42 | | /* |
43 | | * limits/resolution are defined by ICH9 TCO spec |
44 | | */ |
45 | 0 | build_append_int_noprefix(table_data, 0x258, 4);/* Timer Period, ms */ |
46 | 0 | build_append_int_noprefix(table_data, 0x3ff, 4);/* Maximum Count */ |
47 | 0 | build_append_int_noprefix(table_data, 0x4, 4); /* Minimum Count */ |
48 | | /* |
49 | | * WATCHDOG_ENABLED & WATCHDOG_STOPPED_IN_SLEEP_STATE |
50 | | */ |
51 | 0 | build_append_int_noprefix(table_data, 0x81, 1); /* Watchdog Flags */ |
52 | 0 | build_append_int_noprefix(table_data, 0, 3); /* Reserved */ |
53 | | /* |
54 | | * watchdog instruction entries |
55 | | */ |
56 | 0 | build_append_int_noprefix(table_data, 10 /* # of actions below */, 4); |
57 | | /* Action table */ |
58 | 0 | build_append_wdat_ins(table_data, WDAT_ACTION_RESET, |
59 | 0 | WDAT_INS_WRITE_VALUE, |
60 | 0 | tco_rld, 0x1, 0x1ff); |
61 | 0 | build_append_wdat_ins(table_data, WDAT_ACTION_QUERY_RUNNING_STATE, |
62 | 0 | WDAT_INS_READ_VALUE, |
63 | 0 | tco1_cnt, 0x0, 0x800); |
64 | 0 | build_append_wdat_ins(table_data, WDAT_ACTION_SET_RUNNING_STATE, |
65 | 0 | WDAT_INS_WRITE_VALUE | WDAT_INS_PRESERVE_REGISTER, |
66 | 0 | tco1_cnt, 0, 0x800); |
67 | 0 | build_append_wdat_ins(table_data, WDAT_ACTION_QUERY_STOPPED_STATE, |
68 | 0 | WDAT_INS_READ_VALUE, |
69 | 0 | tco1_cnt, 0x800, 0x800); |
70 | 0 | build_append_wdat_ins(table_data, WDAT_ACTION_SET_STOPPED_STATE, |
71 | 0 | WDAT_INS_WRITE_VALUE | WDAT_INS_PRESERVE_REGISTER, |
72 | 0 | tco1_cnt, 0x800, 0x800); |
73 | 0 | build_append_wdat_ins(table_data, WDAT_ACTION_SET_COUNTDOWN_PERIOD, |
74 | 0 | WDAT_INS_WRITE_COUNTDOWN, |
75 | 0 | tco_tmr, 0x0, 0x3FF); |
76 | 0 | build_append_wdat_ins(table_data, WDAT_ACTION_QUERY_COUNTDOWN_PERIOD, |
77 | 0 | WDAT_INS_READ_COUNTDOWN, |
78 | 0 | tco_tmr, 0x0, 0x3FF); |
79 | 0 | build_append_wdat_ins(table_data, WDAT_ACTION_QUERY_WATCHDOG_STATUS, |
80 | 0 | WDAT_INS_READ_VALUE, |
81 | 0 | tco2_sts, 0x2, 0x2); |
82 | 0 | build_append_wdat_ins(table_data, WDAT_ACTION_SET_WATCHDOG_STATUS, |
83 | 0 | WDAT_INS_WRITE_VALUE | WDAT_INS_PRESERVE_REGISTER, |
84 | 0 | tco2_sts, 0x2, 0x2); |
85 | 0 | build_append_wdat_ins(table_data, WDAT_ACTION_SET_WATCHDOG_STATUS, |
86 | 0 | WDAT_INS_WRITE_VALUE | WDAT_INS_PRESERVE_REGISTER, |
87 | 0 | tco2_sts, 0x4, 0x4); |
88 | |
|
89 | 0 | acpi_table_end(linker, &table); |
90 | 0 | } |