| 1 | /* |
| 2 | * Support for generating APEI tables and recording CPER for Guests |
| 3 | * |
| 4 | * Copyright (c) 2020 HUAWEI TECHNOLOGIES CO., LTD. |
| 5 | * |
| 6 | * Author: Dongjiu Geng <gengdongjiu@huawei.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | |
| 18 | * You should have received a copy of the GNU General Public License along |
| 19 | * with this program; if not, see <http://www.gnu.org/licenses/>. |
| 20 | */ |
| 21 | |
| 22 | #ifndef ACPI_GHES_H |
| 23 | #define ACPI_GHES_H |
| 24 | |
| 25 | #include "hw/acpi/bios-linker-loader.h" |
| 26 | #include "qapi/error.h" |
| 27 | #include "qemu/notify.h" |
| 28 | |
| 29 | extern NotifierList acpi_generic_error_notifiers; |
| 30 | |
| 31 | /* |
| 32 | * Values for Hardware Error Notification Type field |
| 33 | */ |
| 34 | enum AcpiGhesNotifyType { |
| 35 | /* Polled */ |
| 36 | ACPI_GHES_NOTIFY_POLLED = 0, |
| 37 | /* External Interrupt */ |
| 38 | ACPI_GHES_NOTIFY_EXTERNAL = 1, |
| 39 | /* Local Interrupt */ |
| 40 | ACPI_GHES_NOTIFY_LOCAL = 2, |
| 41 | /* SCI */ |
| 42 | ACPI_GHES_NOTIFY_SCI = 3, |
| 43 | /* NMI */ |
| 44 | ACPI_GHES_NOTIFY_NMI = 4, |
| 45 | /* CMCI, ACPI 5.0: 18.3.2.7, Table 18-290 */ |
| 46 | ACPI_GHES_NOTIFY_CMCI = 5, |
| 47 | /* MCE, ACPI 5.0: 18.3.2.7, Table 18-290 */ |
| 48 | ACPI_GHES_NOTIFY_MCE = 6, |
| 49 | /* GPIO-Signal, ACPI 6.0: 18.3.2.7, Table 18-332 */ |
| 50 | ACPI_GHES_NOTIFY_GPIO = 7, |
| 51 | /* ARMv8 SEA, ACPI 6.1: 18.3.2.9, Table 18-345 */ |
| 52 | ACPI_GHES_NOTIFY_SEA = 8, |
| 53 | /* ARMv8 SEI, ACPI 6.1: 18.3.2.9, Table 18-345 */ |
| 54 | ACPI_GHES_NOTIFY_SEI = 9, |
| 55 | /* External Interrupt - GSIV, ACPI 6.1: 18.3.2.9, Table 18-345 */ |
| 56 | ACPI_GHES_NOTIFY_GSIV = 10, |
| 57 | /* Software Delegated Exception, ACPI 6.2: 18.3.2.9, Table 18-383 */ |
| 58 | ACPI_GHES_NOTIFY_SDEI = 11, |
| 59 | /* 12 and greater are reserved */ |
| 60 | ACPI_GHES_NOTIFY_RESERVED = 12 |
| 61 | }; |
| 62 | |
| 63 | /* |
| 64 | * ID numbers used to fill HEST source ID field |
| 65 | */ |
| 66 | enum AcpiGhesSourceID { |
| 67 | ACPI_HEST_SRC_ID_SYNC, |
| 68 | ACPI_HEST_SRC_ID_QMP, /* Use it only for QMP injected errors */ |
| 69 | }; |
| 70 | |
| 71 | typedef struct AcpiNotificationSourceId { |
| 72 | enum AcpiGhesSourceID source_id; |
| 73 | enum AcpiGhesNotifyType notify; |
| 74 | } AcpiNotificationSourceId; |
| 75 | |
| 76 | /* |
| 77 | * AcpiGhesState stores GPA values that will be used to fill HEST entries. |
| 78 | * |
| 79 | * When use_hest_addr is false, the GPA of the etc/hardware_errors firmware |
| 80 | * is stored at hw_error_le. This is the default on QEMU 9.x. |
| 81 | * |
| 82 | * When use_hest_addr is true, the GPA of the HEST table is stored at |
| 83 | * hest_addr_le. This is the default for QEMU 10.x and above. |
| 84 | * |
| 85 | * Whe both GPA values are equal to zero means that GHES is not present. |
| 86 | */ |
| 87 | typedef struct AcpiGhesState { |
| 88 | uint64_t hest_addr_le; |
| 89 | uint64_t hw_error_le; |
| 90 | bool use_hest_addr; /* True if HEST address is present */ |
| 91 | } AcpiGhesState; |
| 92 | |
| 93 | void acpi_build_hest(AcpiGhesState *ags, GArray *table_data, |
| 94 | GArray *hardware_errors, |
| 95 | BIOSLinker *linker, |
| 96 | const AcpiNotificationSourceId * const notif_source, |
| 97 | int num_sources, |
| 98 | const char *oem_id, const char *oem_table_id); |
| 99 | void acpi_ghes_add_fw_cfg(AcpiGhesState *vms, FWCfgState *s, |
| 100 | GArray *hardware_errors); |
| 101 | bool acpi_ghes_memory_errors(AcpiGhesState *ags, uint16_t source_id, |
| 102 | uint64_t error_physical_addr, Error **errp); |
| 103 | bool ghes_record_cper_errors(AcpiGhesState *ags, const void *cper, size_t len, |
| 104 | uint16_t source_id, Error **errp); |
| 105 | |
| 106 | /** |
| 107 | * acpi_ghes_get_state: Get a pointer for ACPI ghes state |
| 108 | * |
| 109 | * Returns: a pointer to ghes state if the system has an ACPI GHES table, |
| 110 | * NULL, otherwise. |
| 111 | */ |
| 112 | AcpiGhesState *acpi_ghes_get_state(void); |
| 113 | #endif |