xref: /linux/include/acpi/ghes.h (revision 69050f8d6d075dc01af7a5f2f550a8067510366f)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef GHES_H
3 #define GHES_H
4 
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_EXITING		0x0002
17 
18 struct ghes {
19 	union {
20 		struct acpi_hest_generic *generic;
21 		struct acpi_hest_generic_v2 *generic_v2;
22 	};
23 	struct acpi_hest_generic_status *estatus;
24 	unsigned int estatus_length;
25 	unsigned long flags;
26 	union {
27 		struct list_head list;
28 		struct timer_list timer;
29 		unsigned int irq;
30 	};
31 	struct device *dev;
32 	struct list_head elist;
33 	void __iomem *error_status_vaddr;
34 };
35 
36 struct ghes_estatus_node {
37 	struct llist_node llnode;
38 	struct acpi_hest_generic *generic;
39 	struct ghes *ghes;
40 };
41 
42 struct ghes_estatus_cache {
43 	u32 estatus_len;
44 	atomic_t count;
45 	struct acpi_hest_generic *generic;
46 	unsigned long long time_in;
47 	struct rcu_head rcu;
48 };
49 
50 enum {
51 	GHES_SEV_NO = 0x0,
52 	GHES_SEV_CORRECTED = 0x1,
53 	GHES_SEV_RECOVERABLE = 0x2,
54 	GHES_SEV_PANIC = 0x3,
55 };
56 
57 #ifdef CONFIG_ACPI_APEI_GHES
58 /**
59  * ghes_register_vendor_record_notifier - register a notifier for vendor
60  * records that the kernel would otherwise ignore.
61  * @nb: pointer to the notifier_block structure of the event handler.
62  *
63  * return 0 : SUCCESS, non-zero : FAIL
64  */
65 int ghes_register_vendor_record_notifier(struct notifier_block *nb);
66 
67 /**
68  * ghes_unregister_vendor_record_notifier - unregister the previously
69  * registered vendor record notifier.
70  * @nb: pointer to the notifier_block structure of the vendor record handler.
71  */
72 void ghes_unregister_vendor_record_notifier(struct notifier_block *nb);
73 
74 struct list_head *ghes_get_devices(void);
75 
76 void ghes_estatus_pool_region_free(unsigned long addr, u32 size);
77 #else
78 static inline struct list_head *ghes_get_devices(void) { return NULL; }
79 
80 static inline void ghes_estatus_pool_region_free(unsigned long addr, u32 size) { return; }
81 #endif
82 
83 int ghes_estatus_pool_init(unsigned int num_ghes);
84 
85 static inline int acpi_hest_get_version(struct acpi_hest_generic_data *gdata)
86 {
87 	return gdata->revision >> 8;
88 }
89 
90 static inline void *acpi_hest_get_payload(struct acpi_hest_generic_data *gdata)
91 {
92 	if (acpi_hest_get_version(gdata) >= 3)
93 		return (void *)(((struct acpi_hest_generic_data_v300 *)(gdata)) + 1);
94 
95 	return gdata + 1;
96 }
97 
98 static inline int acpi_hest_get_error_length(struct acpi_hest_generic_data *gdata)
99 {
100 	return ((struct acpi_hest_generic_data *)(gdata))->error_data_length;
101 }
102 
103 static inline int acpi_hest_get_size(struct acpi_hest_generic_data *gdata)
104 {
105 	if (acpi_hest_get_version(gdata) >= 3)
106 		return sizeof(struct acpi_hest_generic_data_v300);
107 
108 	return sizeof(struct acpi_hest_generic_data);
109 }
110 
111 static inline int acpi_hest_get_record_size(struct acpi_hest_generic_data *gdata)
112 {
113 	return (acpi_hest_get_size(gdata) + acpi_hest_get_error_length(gdata));
114 }
115 
116 static inline void *acpi_hest_get_next(struct acpi_hest_generic_data *gdata)
117 {
118 	return (void *)(gdata) + acpi_hest_get_record_size(gdata);
119 }
120 
121 #define apei_estatus_for_each_section(estatus, section)			\
122 	for (section = (struct acpi_hest_generic_data *)(estatus + 1);	\
123 	     (void *)section - (void *)(estatus + 1) < estatus->data_length; \
124 	     section = acpi_hest_get_next(section))
125 
126 #ifdef CONFIG_ACPI_APEI_SEA
127 int ghes_notify_sea(void);
128 #else
129 static inline int ghes_notify_sea(void) { return -ENOENT; }
130 #endif
131 
132 struct notifier_block;
133 extern void ghes_register_report_chain(struct notifier_block *nb);
134 extern void ghes_unregister_report_chain(struct notifier_block *nb);
135 #endif /* GHES_H */
136