2 * APEI Hardware Error Souce Table support
4 * HEST describes error sources in detail; communicates operational
5 * parameters (i.e. severity levels, masking bits, and threshold
6 * values) to Linux as necessary. It also allows the BIOS to report
7 * non-standard error sources to Linux (for example, chipset-specific
10 * For more information about HEST, please refer to ACPI Specification
11 * version 4.0, section 17.3.2.
13 * Copyright 2009 Intel Corp.
14 * Author: Huang Ying <ying.huang@intel.com>
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License version
18 * 2 as published by the Free Software Foundation;
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
26 #include <linux/kernel.h>
27 #include <linux/module.h>
28 #include <linux/init.h>
29 #include <linux/acpi.h>
30 #include <linux/kdebug.h>
31 #include <linux/highmem.h>
33 #include <linux/platform_device.h>
34 #include <acpi/apei.h>
36 #include "apei-internal.h"
38 #define HEST_PFX "HEST: "
41 EXPORT_SYMBOL_GPL(hest_disable
);
43 /* HEST table parsing */
45 static struct acpi_table_hest
*__read_mostly hest_tab
;
47 static const int hest_esrc_len_tab
[ACPI_HEST_TYPE_RESERVED
] = {
48 [ACPI_HEST_TYPE_IA32_CHECK
] = -1, /* need further calculation */
49 [ACPI_HEST_TYPE_IA32_CORRECTED_CHECK
] = -1,
50 [ACPI_HEST_TYPE_IA32_NMI
] = sizeof(struct acpi_hest_ia_nmi
),
51 [ACPI_HEST_TYPE_AER_ROOT_PORT
] = sizeof(struct acpi_hest_aer_root
),
52 [ACPI_HEST_TYPE_AER_ENDPOINT
] = sizeof(struct acpi_hest_aer
),
53 [ACPI_HEST_TYPE_AER_BRIDGE
] = sizeof(struct acpi_hest_aer_bridge
),
54 [ACPI_HEST_TYPE_GENERIC_ERROR
] = sizeof(struct acpi_hest_generic
),
57 static int hest_esrc_len(struct acpi_hest_header
*hest_hdr
)
59 u16 hest_type
= hest_hdr
->type
;
62 if (hest_type
>= ACPI_HEST_TYPE_RESERVED
)
65 len
= hest_esrc_len_tab
[hest_type
];
67 if (hest_type
== ACPI_HEST_TYPE_IA32_CORRECTED_CHECK
) {
68 struct acpi_hest_ia_corrected
*cmc
;
69 cmc
= (struct acpi_hest_ia_corrected
*)hest_hdr
;
70 len
= sizeof(*cmc
) + cmc
->num_hardware_banks
*
71 sizeof(struct acpi_hest_ia_error_bank
);
72 } else if (hest_type
== ACPI_HEST_TYPE_IA32_CHECK
) {
73 struct acpi_hest_ia_machine_check
*mc
;
74 mc
= (struct acpi_hest_ia_machine_check
*)hest_hdr
;
75 len
= sizeof(*mc
) + mc
->num_hardware_banks
*
76 sizeof(struct acpi_hest_ia_error_bank
);
83 int apei_hest_parse(apei_hest_func_t func
, void *data
)
85 struct acpi_hest_header
*hest_hdr
;
88 if (hest_disable
|| !hest_tab
)
91 hest_hdr
= (struct acpi_hest_header
*)(hest_tab
+ 1);
92 for (i
= 0; i
< hest_tab
->error_source_count
; i
++) {
93 len
= hest_esrc_len(hest_hdr
);
95 pr_warning(FW_WARN HEST_PFX
96 "Unknown or unused hardware error source "
97 "type: %d for hardware error source: %d.\n",
98 hest_hdr
->type
, hest_hdr
->source_id
);
101 if ((void *)hest_hdr
+ len
>
102 (void *)hest_tab
+ hest_tab
->header
.length
) {
103 pr_warning(FW_BUG HEST_PFX
104 "Table contents overflow for hardware error source: %d.\n",
105 hest_hdr
->source_id
);
109 rc
= func(hest_hdr
, data
);
113 hest_hdr
= (void *)hest_hdr
+ len
;
118 EXPORT_SYMBOL_GPL(apei_hest_parse
);
121 * Check if firmware advertises firmware first mode. We need FF bit to be set
122 * along with a set of MC banks which work in FF mode.
124 static int __init
hest_parse_cmc(struct acpi_hest_header
*hest_hdr
, void *data
)
126 if (hest_hdr
->type
!= ACPI_HEST_TYPE_IA32_CORRECTED_CHECK
)
129 if (!acpi_disable_cmcff
)
130 return !arch_apei_enable_cmcff(hest_hdr
, data
);
136 struct platform_device
**ghes_devs
;
140 static int __init
hest_parse_ghes_count(struct acpi_hest_header
*hest_hdr
, void *data
)
144 if (hest_hdr
->type
== ACPI_HEST_TYPE_GENERIC_ERROR
)
149 static int __init
hest_parse_ghes(struct acpi_hest_header
*hest_hdr
, void *data
)
151 struct platform_device
*ghes_dev
;
152 struct ghes_arr
*ghes_arr
= data
;
155 if (hest_hdr
->type
!= ACPI_HEST_TYPE_GENERIC_ERROR
)
158 if (!((struct acpi_hest_generic
*)hest_hdr
)->enabled
)
160 for (i
= 0; i
< ghes_arr
->count
; i
++) {
161 struct acpi_hest_header
*hdr
;
162 ghes_dev
= ghes_arr
->ghes_devs
[i
];
163 hdr
= *(struct acpi_hest_header
**)ghes_dev
->dev
.platform_data
;
164 if (hdr
->source_id
== hest_hdr
->source_id
) {
165 pr_warning(FW_WARN HEST_PFX
"Duplicated hardware error source ID: %d.\n",
170 ghes_dev
= platform_device_alloc("GHES", hest_hdr
->source_id
);
174 rc
= platform_device_add_data(ghes_dev
, &hest_hdr
, sizeof(void *));
178 rc
= platform_device_add(ghes_dev
);
181 ghes_arr
->ghes_devs
[ghes_arr
->count
++] = ghes_dev
;
185 platform_device_put(ghes_dev
);
189 static int __init
hest_ghes_dev_register(unsigned int ghes_count
)
192 struct ghes_arr ghes_arr
;
195 ghes_arr
.ghes_devs
= kmalloc(sizeof(void *) * ghes_count
, GFP_KERNEL
);
196 if (!ghes_arr
.ghes_devs
)
199 rc
= apei_hest_parse(hest_parse_ghes
, &ghes_arr
);
203 kfree(ghes_arr
.ghes_devs
);
206 for (i
= 0; i
< ghes_arr
.count
; i
++)
207 platform_device_unregister(ghes_arr
.ghes_devs
[i
]);
211 static int __init
setup_hest_disable(char *str
)
217 __setup("hest_disable", setup_hest_disable
);
219 void __init
acpi_hest_init(void)
223 unsigned int ghes_count
= 0;
226 pr_info(HEST_PFX
"Table parsing disabled.\n");
230 status
= acpi_get_table(ACPI_SIG_HEST
, 0,
231 (struct acpi_table_header
**)&hest_tab
);
232 if (status
== AE_NOT_FOUND
)
234 else if (ACPI_FAILURE(status
)) {
235 const char *msg
= acpi_format_exception(status
);
236 pr_err(HEST_PFX
"Failed to get table, %s\n", msg
);
241 rc
= apei_hest_parse(hest_parse_cmc
, NULL
);
246 rc
= apei_hest_parse(hest_parse_ghes_count
, &ghes_count
);
249 rc
= hest_ghes_dev_register(ghes_count
);
254 pr_info(HEST_PFX
"Table parsing has been initialized.\n");