blob: 82cb4eb225a4dfac0d129b4b0b565ea890e44046 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Tyler Baicar7edda082017-06-21 12:17:09 -06002#ifndef GHES_H
3#define GHES_H
4
Mauro Carvalho Chehab40e06412013-02-15 05:41:22 -03005#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
19struct ghes {
Tyler Baicar42aa5602017-06-21 12:17:04 -060020 union {
21 struct acpi_hest_generic *generic;
22 struct acpi_hest_generic_v2 *generic_v2;
23 };
Lv Zheng0a00fd52014-06-03 16:32:53 +080024 struct acpi_hest_generic_status *estatus;
Mauro Carvalho Chehab40e06412013-02-15 05:41:22 -030025 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
34struct ghes_estatus_node {
35 struct llist_node llnode;
36 struct acpi_hest_generic *generic;
Mauro Carvalho Chehab21480542013-02-15 06:10:39 -030037 struct ghes *ghes;
Mauro Carvalho Chehab40e06412013-02-15 05:41:22 -030038};
39
40struct 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
48enum {
49 GHES_SEV_NO = 0x0,
50 GHES_SEV_CORRECTED = 0x1,
51 GHES_SEV_RECOVERABLE = 0x2,
52 GHES_SEV_PANIC = 0x3,
53};
Mauro Carvalho Chehab21480542013-02-15 06:10:39 -030054
55/* From drivers/edac/ghes_edac.c */
56
57#ifdef CONFIG_EDAC_GHES
Alexandru Gagniuc305d0e02018-04-30 16:33:50 -050058void ghes_edac_report_mem_error(int sev, struct cper_sec_mem_err *mem_err);
Mauro Carvalho Chehab21480542013-02-15 06:10:39 -030059
60int ghes_edac_register(struct ghes *ghes, struct device *dev);
61
62void ghes_edac_unregister(struct ghes *ghes);
63
64#else
Alexandru Gagniuc305d0e02018-04-30 16:33:50 -050065static inline void ghes_edac_report_mem_error(int sev,
Mauro Carvalho Chehab21480542013-02-15 06:10:39 -030066 struct cper_sec_mem_err *mem_err)
67{
68}
69
70static inline int ghes_edac_register(struct ghes *ghes, struct device *dev)
71{
Borislav Petkovcc7f3f12018-04-23 14:16:46 +020072 return -ENODEV;
Mauro Carvalho Chehab21480542013-02-15 06:10:39 -030073}
74
75static inline void ghes_edac_unregister(struct ghes *ghes)
76{
77}
78#endif
Tyler Baicarbbcc2e72017-06-21 12:17:05 -060079
80static inline int acpi_hest_get_version(struct acpi_hest_generic_data *gdata)
81{
82 return gdata->revision >> 8;
83}
84
85static 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
93static 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
98static 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
106static 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
111static 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 Baicar7edda082017-06-21 12:17:09 -0600115
gengdongjiuc4335fd2017-08-17 20:07:18 +0800116#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 Geng1035a072018-08-07 12:26:15 -0400121#ifdef CONFIG_ACPI_APEI_SEA
Tyler Baicar621f48e2017-06-21 12:17:14 -0600122int ghes_notify_sea(void);
Dongjiu Geng1035a072018-08-07 12:26:15 -0400123#else
124static inline int ghes_notify_sea(void) { return -ENOENT; }
125#endif
Tyler Baicar7edda082017-06-21 12:17:09 -0600126
127#endif /* GHES_H */