| 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 | } |