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 | */ |
Mauro Carvalho Chehab | 40e0641 | 2013-02-15 05:41:22 -0300 | [diff] [blame] | 16 | #define GHES_EXITING 0x0002 |
| 17 | |
| 18 | struct ghes { |
Tyler Baicar | 42aa560 | 2017-06-21 12:17:04 -0600 | [diff] [blame] | 19 | union { |
| 20 | struct acpi_hest_generic *generic; |
| 21 | struct acpi_hest_generic_v2 *generic_v2; |
| 22 | }; |
Lv Zheng | 0a00fd5 | 2014-06-03 16:32:53 +0800 | [diff] [blame] | 23 | struct acpi_hest_generic_status *estatus; |
Mauro Carvalho Chehab | 40e0641 | 2013-02-15 05:41:22 -0300 | [diff] [blame] | 24 | unsigned long flags; |
| 25 | union { |
| 26 | struct list_head list; |
| 27 | struct timer_list timer; |
| 28 | unsigned int irq; |
| 29 | }; |
| 30 | }; |
| 31 | |
| 32 | struct ghes_estatus_node { |
| 33 | struct llist_node llnode; |
| 34 | struct acpi_hest_generic *generic; |
Mauro Carvalho Chehab | 2148054 | 2013-02-15 06:10:39 -0300 | [diff] [blame] | 35 | struct ghes *ghes; |
Mauro Carvalho Chehab | 40e0641 | 2013-02-15 05:41:22 -0300 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | struct ghes_estatus_cache { |
| 39 | u32 estatus_len; |
| 40 | atomic_t count; |
| 41 | struct acpi_hest_generic *generic; |
| 42 | unsigned long long time_in; |
| 43 | struct rcu_head rcu; |
| 44 | }; |
| 45 | |
| 46 | enum { |
| 47 | GHES_SEV_NO = 0x0, |
| 48 | GHES_SEV_CORRECTED = 0x1, |
| 49 | GHES_SEV_RECOVERABLE = 0x2, |
| 50 | GHES_SEV_PANIC = 0x3, |
| 51 | }; |
Mauro Carvalho Chehab | 2148054 | 2013-02-15 06:10:39 -0300 | [diff] [blame] | 52 | |
James Morse | fb7be08 | 2019-01-29 18:48:41 +0000 | [diff] [blame] | 53 | int ghes_estatus_pool_init(int num_ghes); |
James Morse | e147133 | 2019-01-29 18:48:40 +0000 | [diff] [blame] | 54 | |
Mauro Carvalho Chehab | 2148054 | 2013-02-15 06:10:39 -0300 | [diff] [blame] | 55 | /* From drivers/edac/ghes_edac.c */ |
| 56 | |
| 57 | #ifdef CONFIG_EDAC_GHES |
Alexandru Gagniuc | 305d0e0 | 2018-04-30 16:33:50 -0500 | [diff] [blame] | 58 | void ghes_edac_report_mem_error(int sev, struct cper_sec_mem_err *mem_err); |
Mauro Carvalho Chehab | 2148054 | 2013-02-15 06:10:39 -0300 | [diff] [blame] | 59 | |
| 60 | int ghes_edac_register(struct ghes *ghes, struct device *dev); |
| 61 | |
| 62 | void ghes_edac_unregister(struct ghes *ghes); |
| 63 | |
| 64 | #else |
Alexandru Gagniuc | 305d0e0 | 2018-04-30 16:33:50 -0500 | [diff] [blame] | 65 | static inline void ghes_edac_report_mem_error(int sev, |
Mauro Carvalho Chehab | 2148054 | 2013-02-15 06:10:39 -0300 | [diff] [blame] | 66 | struct cper_sec_mem_err *mem_err) |
| 67 | { |
| 68 | } |
| 69 | |
| 70 | static inline int ghes_edac_register(struct ghes *ghes, struct device *dev) |
| 71 | { |
Borislav Petkov | cc7f3f1 | 2018-04-23 14:16:46 +0200 | [diff] [blame] | 72 | return -ENODEV; |
Mauro Carvalho Chehab | 2148054 | 2013-02-15 06:10:39 -0300 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | static inline void ghes_edac_unregister(struct ghes *ghes) |
| 76 | { |
| 77 | } |
| 78 | #endif |
Tyler Baicar | bbcc2e7 | 2017-06-21 12:17:05 -0600 | [diff] [blame] | 79 | |
| 80 | static inline int acpi_hest_get_version(struct acpi_hest_generic_data *gdata) |
| 81 | { |
| 82 | return gdata->revision >> 8; |
| 83 | } |
| 84 | |
| 85 | static inline void *acpi_hest_get_payload(struct acpi_hest_generic_data *gdata) |
| 86 | { |
| 87 | if (acpi_hest_get_version(gdata) >= 3) |
| 88 | return (void *)(((struct acpi_hest_generic_data_v300 *)(gdata)) + 1); |
| 89 | |
| 90 | return gdata + 1; |
| 91 | } |
| 92 | |
| 93 | static inline int acpi_hest_get_error_length(struct acpi_hest_generic_data *gdata) |
| 94 | { |
| 95 | return ((struct acpi_hest_generic_data *)(gdata))->error_data_length; |
| 96 | } |
| 97 | |
| 98 | static inline int acpi_hest_get_size(struct acpi_hest_generic_data *gdata) |
| 99 | { |
| 100 | if (acpi_hest_get_version(gdata) >= 3) |
| 101 | return sizeof(struct acpi_hest_generic_data_v300); |
| 102 | |
| 103 | return sizeof(struct acpi_hest_generic_data); |
| 104 | } |
| 105 | |
| 106 | static inline int acpi_hest_get_record_size(struct acpi_hest_generic_data *gdata) |
| 107 | { |
| 108 | return (acpi_hest_get_size(gdata) + acpi_hest_get_error_length(gdata)); |
| 109 | } |
| 110 | |
| 111 | static inline void *acpi_hest_get_next(struct acpi_hest_generic_data *gdata) |
| 112 | { |
| 113 | return (void *)(gdata) + acpi_hest_get_record_size(gdata); |
| 114 | } |
Tyler Baicar | 7edda08 | 2017-06-21 12:17:09 -0600 | [diff] [blame] | 115 | |
gengdongjiu | c4335fd | 2017-08-17 20:07:18 +0800 | [diff] [blame] | 116 | #define apei_estatus_for_each_section(estatus, section) \ |
| 117 | for (section = (struct acpi_hest_generic_data *)(estatus + 1); \ |
| 118 | (void *)section - (void *)(estatus + 1) < estatus->data_length; \ |
| 119 | section = acpi_hest_get_next(section)) |
| 120 | |
Dongjiu Geng | 1035a07 | 2018-08-07 12:26:15 -0400 | [diff] [blame] | 121 | #ifdef CONFIG_ACPI_APEI_SEA |
Tyler Baicar | 621f48e | 2017-06-21 12:17:14 -0600 | [diff] [blame] | 122 | int ghes_notify_sea(void); |
Dongjiu Geng | 1035a07 | 2018-08-07 12:26:15 -0400 | [diff] [blame] | 123 | #else |
| 124 | static inline int ghes_notify_sea(void) { return -ENOENT; } |
| 125 | #endif |
Tyler Baicar | 7edda08 | 2017-06-21 12:17:09 -0600 | [diff] [blame] | 126 | |
| 127 | #endif /* GHES_H */ |