xref: /linux/include/acpi/ghes.h (revision 6fa6b5cb60490db2591bb93872b95f72315e5f53)
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 /**
75  * devm_ghes_register_vendor_record_notifier - device-managed vendor
76  * record notifier registration.
77  * @dev: device that owns the notifier lifetime
78  * @nb: pointer to the notifier_block structure of the vendor record handler
79  *
80  * Return: 0 on success, negative errno on failure.
81  */
82 int devm_ghes_register_vendor_record_notifier(struct device *dev,
83 					      struct notifier_block *nb);
84 
85 struct list_head *ghes_get_devices(void);
86 
87 void ghes_estatus_pool_region_free(unsigned long addr, u32 size);
88 #else
89 static inline struct list_head *ghes_get_devices(void) { return NULL; }
90 
91 static inline void ghes_estatus_pool_region_free(unsigned long addr, u32 size) { return; }
92 #endif
93 
94 int ghes_estatus_pool_init(unsigned int num_ghes);
95 
96 static inline int acpi_hest_get_version(struct acpi_hest_generic_data *gdata)
97 {
98 	return gdata->revision >> 8;
99 }
100 
101 static inline void *acpi_hest_get_payload(struct acpi_hest_generic_data *gdata)
102 {
103 	if (acpi_hest_get_version(gdata) >= 3)
104 		return (void *)(((struct acpi_hest_generic_data_v300 *)(gdata)) + 1);
105 
106 	return gdata + 1;
107 }
108 
109 static inline int acpi_hest_get_error_length(struct acpi_hest_generic_data *gdata)
110 {
111 	return ((struct acpi_hest_generic_data *)(gdata))->error_data_length;
112 }
113 
114 static inline int acpi_hest_get_size(struct acpi_hest_generic_data *gdata)
115 {
116 	if (acpi_hest_get_version(gdata) >= 3)
117 		return sizeof(struct acpi_hest_generic_data_v300);
118 
119 	return sizeof(struct acpi_hest_generic_data);
120 }
121 
122 static inline int acpi_hest_get_record_size(struct acpi_hest_generic_data *gdata)
123 {
124 	return (acpi_hest_get_size(gdata) + acpi_hest_get_error_length(gdata));
125 }
126 
127 static inline void *acpi_hest_get_next(struct acpi_hest_generic_data *gdata)
128 {
129 	return (void *)(gdata) + acpi_hest_get_record_size(gdata);
130 }
131 
132 #define apei_estatus_for_each_section(estatus, section)			\
133 	for (section = (struct acpi_hest_generic_data *)(estatus + 1);	\
134 	     (void *)section - (void *)(estatus + 1) < estatus->data_length; \
135 	     section = acpi_hest_get_next(section))
136 
137 #ifdef CONFIG_ACPI_APEI_SEA
138 int ghes_notify_sea(void);
139 #else
140 static inline int ghes_notify_sea(void) { return -ENOENT; }
141 #endif
142 
143 struct notifier_block;
144 extern void ghes_register_report_chain(struct notifier_block *nb);
145 extern void ghes_unregister_report_chain(struct notifier_block *nb);
146 #endif /* GHES_H */
147