Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Tyler Baicar | 7edda08 | 2017-06-21 12:17:09 -0600 | [diff] [blame] | 2 | #ifndef GHES_H |
| 3 | #define GHES_H |
| 4 | |
Mauro Carvalho Chehab | 40e0641 | 2013-02-15 05:41:22 -0300 | [diff] [blame] | 5 | #include <acpi/apei.h> |
| 6 | #include <acpi/hed.h> |
| 7 | |
| 8 | /* |
| 9 | * One struct ghes is created for each generic hardware error source. |
| 10 | * It provides the context for APEI hardware error timer/IRQ/SCI/NMI |
| 11 | * handler. |
| 12 | * |
| 13 | * estatus: memory buffer for error status block, allocated during |
| 14 | * HEST parsing. |
| 15 | */ |
| 16 | #define GHES_TO_CLEAR 0x0001 |
| 17 | #define GHES_EXITING 0x0002 |
| 18 | |
| 19 | struct ghes { |
Tyler Baicar | 42aa560 | 2017-06-21 12:17:04 -0600 | [diff] [blame] | 20 | union { |
| 21 | struct acpi_hest_generic *generic; |
| 22 | struct acpi_hest_generic_v2 *generic_v2; |
| 23 | }; |
Lv Zheng | 0a00fd5 | 2014-06-03 16:32:53 +0800 | [diff] [blame] | 24 | struct acpi_hest_generic_status *estatus; |
Mauro Carvalho Chehab | 40e0641 | 2013-02-15 05:41:22 -0300 | [diff] [blame] | 25 | u64 buffer_paddr; |
| 26 | unsigned long flags; |
| 27 | union { |
| 28 | struct list_head list; |
| 29 | struct timer_list timer; |
| 30 | unsigned int irq; |
| 31 | }; |
| 32 | }; |
| 33 | |
| 34 | struct ghes_estatus_node { |
| 35 | struct llist_node llnode; |
| 36 | struct acpi_hest_generic *generic; |
Mauro Carvalho Chehab | 2148054 | 2013-02-15 06:10:39 -0300 | [diff] [blame] | 37 | struct ghes *ghes; |
Mauro Carvalho Chehab | 40e0641 | 2013-02-15 05:41:22 -0300 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | struct ghes_estatus_cache { |
| 41 | u32 estatus_len; |
| 42 | atomic_t count; |
| 43 | struct acpi_hest_generic *generic; |
| 44 | unsigned long long time_in; |
| 45 | struct rcu_head rcu; |
| 46 | }; |
| 47 | |
| 48 | enum { |
| 49 | GHES_SEV_NO = 0x0, |
| 50 | GHES_SEV_CORRECTED = 0x1, |
| 51 | GHES_SEV_RECOVERABLE = 0x2, |
| 52 | GHES_SEV_PANIC = 0x3, |
| 53 | }; |
Mauro Carvalho Chehab | 2148054 | 2013-02-15 06:10:39 -0300 | [diff] [blame] | 54 | |
| 55 | /* From drivers/edac/ghes_edac.c */ |
| 56 | |
| 57 | #ifdef CONFIG_EDAC_GHES |
| 58 | void ghes_edac_report_mem_error(struct ghes *ghes, int sev, |
| 59 | struct cper_sec_mem_err *mem_err); |
| 60 | |
| 61 | int ghes_edac_register(struct ghes *ghes, struct device *dev); |
| 62 | |
| 63 | void ghes_edac_unregister(struct ghes *ghes); |
| 64 | |
| 65 | #else |
| 66 | static inline void ghes_edac_report_mem_error(struct ghes *ghes, int sev, |
| 67 | struct cper_sec_mem_err *mem_err) |
| 68 | { |
| 69 | } |
| 70 | |
| 71 | static inline int ghes_edac_register(struct ghes *ghes, struct device *dev) |
| 72 | { |
| 73 | return 0; |
| 74 | } |
| 75 | |
| 76 | static inline void ghes_edac_unregister(struct ghes *ghes) |
| 77 | { |
| 78 | } |
| 79 | #endif |
Tyler Baicar | bbcc2e7 | 2017-06-21 12:17:05 -0600 | [diff] [blame] | 80 | |
| 81 | static inline int acpi_hest_get_version(struct acpi_hest_generic_data *gdata) |
| 82 | { |
| 83 | return gdata->revision >> 8; |
| 84 | } |
| 85 | |
| 86 | static inline void *acpi_hest_get_payload(struct acpi_hest_generic_data *gdata) |
| 87 | { |
| 88 | if (acpi_hest_get_version(gdata) >= 3) |
| 89 | return (void *)(((struct acpi_hest_generic_data_v300 *)(gdata)) + 1); |
| 90 | |
| 91 | return gdata + 1; |
| 92 | } |
| 93 | |
| 94 | static inline int acpi_hest_get_error_length(struct acpi_hest_generic_data *gdata) |
| 95 | { |
| 96 | return ((struct acpi_hest_generic_data *)(gdata))->error_data_length; |
| 97 | } |
| 98 | |
| 99 | static inline int acpi_hest_get_size(struct acpi_hest_generic_data *gdata) |
| 100 | { |
| 101 | if (acpi_hest_get_version(gdata) >= 3) |
| 102 | return sizeof(struct acpi_hest_generic_data_v300); |
| 103 | |
| 104 | return sizeof(struct acpi_hest_generic_data); |
| 105 | } |
| 106 | |
| 107 | static inline int acpi_hest_get_record_size(struct acpi_hest_generic_data *gdata) |
| 108 | { |
| 109 | return (acpi_hest_get_size(gdata) + acpi_hest_get_error_length(gdata)); |
| 110 | } |
| 111 | |
| 112 | static inline void *acpi_hest_get_next(struct acpi_hest_generic_data *gdata) |
| 113 | { |
| 114 | return (void *)(gdata) + acpi_hest_get_record_size(gdata); |
| 115 | } |
Tyler Baicar | 7edda08 | 2017-06-21 12:17:09 -0600 | [diff] [blame] | 116 | |
gengdongjiu | c4335fd | 2017-08-17 20:07:18 +0800 | [diff] [blame] | 117 | #define apei_estatus_for_each_section(estatus, section) \ |
| 118 | for (section = (struct acpi_hest_generic_data *)(estatus + 1); \ |
| 119 | (void *)section - (void *)(estatus + 1) < estatus->data_length; \ |
| 120 | section = acpi_hest_get_next(section)) |
| 121 | |
Tyler Baicar | 621f48e | 2017-06-21 12:17:14 -0600 | [diff] [blame] | 122 | int ghes_notify_sea(void); |
Tyler Baicar | 7edda08 | 2017-06-21 12:17:09 -0600 | [diff] [blame] | 123 | |
| 124 | #endif /* GHES_H */ |