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