Linux Audio

Check our new training course

Loading...
v3.5.6
  1/*
  2 * APEI Hardware Error Souce Table support
  3 *
  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
  8 * error registers).
  9 *
 10 * For more information about HEST, please refer to ACPI Specification
 11 * version 4.0, section 17.3.2.
 12 *
 13 * Copyright 2009 Intel Corp.
 14 *   Author: Huang Ying <ying.huang@intel.com>
 15 *
 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;
 19 *
 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.
 24 *
 25 * You should have received a copy of the GNU General Public License
 26 * along with this program; if not, write to the Free Software
 27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 28 */
 29
 30#include <linux/kernel.h>
 31#include <linux/module.h>
 32#include <linux/init.h>
 33#include <linux/acpi.h>
 34#include <linux/kdebug.h>
 35#include <linux/highmem.h>
 36#include <linux/io.h>
 37#include <linux/platform_device.h>
 38#include <acpi/apei.h>
 
 39
 40#include "apei-internal.h"
 41
 42#define HEST_PFX "HEST: "
 43
 44bool hest_disable;
 45EXPORT_SYMBOL_GPL(hest_disable);
 46
 47/* HEST table parsing */
 48
 49static struct acpi_table_hest *__read_mostly hest_tab;
 50
 51static const int hest_esrc_len_tab[ACPI_HEST_TYPE_RESERVED] = {
 52	[ACPI_HEST_TYPE_IA32_CHECK] = -1,	/* need further calculation */
 53	[ACPI_HEST_TYPE_IA32_CORRECTED_CHECK] = -1,
 54	[ACPI_HEST_TYPE_IA32_NMI] = sizeof(struct acpi_hest_ia_nmi),
 55	[ACPI_HEST_TYPE_AER_ROOT_PORT] = sizeof(struct acpi_hest_aer_root),
 56	[ACPI_HEST_TYPE_AER_ENDPOINT] = sizeof(struct acpi_hest_aer),
 57	[ACPI_HEST_TYPE_AER_BRIDGE] = sizeof(struct acpi_hest_aer_bridge),
 58	[ACPI_HEST_TYPE_GENERIC_ERROR] = sizeof(struct acpi_hest_generic),
 59};
 60
 61static int hest_esrc_len(struct acpi_hest_header *hest_hdr)
 62{
 63	u16 hest_type = hest_hdr->type;
 64	int len;
 65
 66	if (hest_type >= ACPI_HEST_TYPE_RESERVED)
 67		return 0;
 68
 69	len = hest_esrc_len_tab[hest_type];
 70
 71	if (hest_type == ACPI_HEST_TYPE_IA32_CORRECTED_CHECK) {
 72		struct acpi_hest_ia_corrected *cmc;
 73		cmc = (struct acpi_hest_ia_corrected *)hest_hdr;
 74		len = sizeof(*cmc) + cmc->num_hardware_banks *
 75			sizeof(struct acpi_hest_ia_error_bank);
 76	} else if (hest_type == ACPI_HEST_TYPE_IA32_CHECK) {
 77		struct acpi_hest_ia_machine_check *mc;
 78		mc = (struct acpi_hest_ia_machine_check *)hest_hdr;
 79		len = sizeof(*mc) + mc->num_hardware_banks *
 80			sizeof(struct acpi_hest_ia_error_bank);
 81	}
 82	BUG_ON(len == -1);
 83
 84	return len;
 85};
 86
 87int apei_hest_parse(apei_hest_func_t func, void *data)
 88{
 89	struct acpi_hest_header *hest_hdr;
 90	int i, rc, len;
 91
 92	if (hest_disable)
 93		return -EINVAL;
 94
 95	hest_hdr = (struct acpi_hest_header *)(hest_tab + 1);
 96	for (i = 0; i < hest_tab->error_source_count; i++) {
 97		len = hest_esrc_len(hest_hdr);
 98		if (!len) {
 99			pr_warning(FW_WARN HEST_PFX
100				   "Unknown or unused hardware error source "
101				   "type: %d for hardware error source: %d.\n",
102				   hest_hdr->type, hest_hdr->source_id);
103			return -EINVAL;
104		}
105		if ((void *)hest_hdr + len >
106		    (void *)hest_tab + hest_tab->header.length) {
107			pr_warning(FW_BUG HEST_PFX
108		"Table contents overflow for hardware error source: %d.\n",
109				hest_hdr->source_id);
110			return -EINVAL;
111		}
112
113		rc = func(hest_hdr, data);
114		if (rc)
115			return rc;
116
117		hest_hdr = (void *)hest_hdr + len;
118	}
119
120	return 0;
121}
122EXPORT_SYMBOL_GPL(apei_hest_parse);
123
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124struct ghes_arr {
125	struct platform_device **ghes_devs;
126	unsigned int count;
127};
128
129static int __init hest_parse_ghes_count(struct acpi_hest_header *hest_hdr, void *data)
130{
131	int *count = data;
132
133	if (hest_hdr->type == ACPI_HEST_TYPE_GENERIC_ERROR)
134		(*count)++;
135	return 0;
136}
137
138static int __init hest_parse_ghes(struct acpi_hest_header *hest_hdr, void *data)
139{
140	struct platform_device *ghes_dev;
141	struct ghes_arr *ghes_arr = data;
142	int rc, i;
143
144	if (hest_hdr->type != ACPI_HEST_TYPE_GENERIC_ERROR)
145		return 0;
146
147	if (!((struct acpi_hest_generic *)hest_hdr)->enabled)
148		return 0;
149	for (i = 0; i < ghes_arr->count; i++) {
150		struct acpi_hest_header *hdr;
151		ghes_dev = ghes_arr->ghes_devs[i];
152		hdr = *(struct acpi_hest_header **)ghes_dev->dev.platform_data;
153		if (hdr->source_id == hest_hdr->source_id) {
154			pr_warning(FW_WARN HEST_PFX "Duplicated hardware error source ID: %d.\n",
155				   hdr->source_id);
156			return -EIO;
157		}
158	}
159	ghes_dev = platform_device_alloc("GHES", hest_hdr->source_id);
160	if (!ghes_dev)
161		return -ENOMEM;
162
163	rc = platform_device_add_data(ghes_dev, &hest_hdr, sizeof(void *));
164	if (rc)
165		goto err;
166
167	rc = platform_device_add(ghes_dev);
168	if (rc)
169		goto err;
170	ghes_arr->ghes_devs[ghes_arr->count++] = ghes_dev;
171
172	return 0;
173err:
174	platform_device_put(ghes_dev);
175	return rc;
176}
177
178static int __init hest_ghes_dev_register(unsigned int ghes_count)
179{
180	int rc, i;
181	struct ghes_arr ghes_arr;
182
183	ghes_arr.count = 0;
184	ghes_arr.ghes_devs = kmalloc(sizeof(void *) * ghes_count, GFP_KERNEL);
185	if (!ghes_arr.ghes_devs)
186		return -ENOMEM;
187
188	rc = apei_hest_parse(hest_parse_ghes, &ghes_arr);
189	if (rc)
190		goto err;
191out:
192	kfree(ghes_arr.ghes_devs);
193	return rc;
194err:
195	for (i = 0; i < ghes_arr.count; i++)
196		platform_device_unregister(ghes_arr.ghes_devs[i]);
197	goto out;
198}
199
200static int __init setup_hest_disable(char *str)
201{
202	hest_disable = 1;
203	return 0;
204}
205
206__setup("hest_disable", setup_hest_disable);
207
208void __init acpi_hest_init(void)
209{
210	acpi_status status;
211	int rc = -ENODEV;
212	unsigned int ghes_count = 0;
213
214	if (hest_disable) {
215		pr_info(HEST_PFX "Table parsing disabled.\n");
216		return;
217	}
218
219	if (acpi_disabled)
220		goto err;
221
222	status = acpi_get_table(ACPI_SIG_HEST, 0,
223				(struct acpi_table_header **)&hest_tab);
224	if (status == AE_NOT_FOUND)
225		goto err;
226	else if (ACPI_FAILURE(status)) {
227		const char *msg = acpi_format_exception(status);
228		pr_err(HEST_PFX "Failed to get table, %s\n", msg);
229		rc = -EINVAL;
230		goto err;
231	}
 
 
 
232
233	if (!ghes_disable) {
234		rc = apei_hest_parse(hest_parse_ghes_count, &ghes_count);
235		if (rc)
236			goto err;
237		rc = hest_ghes_dev_register(ghes_count);
238		if (rc)
239			goto err;
240	}
241
242	pr_info(HEST_PFX "Table parsing has been initialized.\n");
243	return;
244err:
245	hest_disable = 1;
246}
v3.15
  1/*
  2 * APEI Hardware Error Souce Table support
  3 *
  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
  8 * error registers).
  9 *
 10 * For more information about HEST, please refer to ACPI Specification
 11 * version 4.0, section 17.3.2.
 12 *
 13 * Copyright 2009 Intel Corp.
 14 *   Author: Huang Ying <ying.huang@intel.com>
 15 *
 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;
 19 *
 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.
 24 *
 25 * You should have received a copy of the GNU General Public License
 26 * along with this program; if not, write to the Free Software
 27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 28 */
 29
 30#include <linux/kernel.h>
 31#include <linux/module.h>
 32#include <linux/init.h>
 33#include <linux/acpi.h>
 34#include <linux/kdebug.h>
 35#include <linux/highmem.h>
 36#include <linux/io.h>
 37#include <linux/platform_device.h>
 38#include <acpi/apei.h>
 39#include <asm/mce.h>
 40
 41#include "apei-internal.h"
 42
 43#define HEST_PFX "HEST: "
 44
 45bool hest_disable;
 46EXPORT_SYMBOL_GPL(hest_disable);
 47
 48/* HEST table parsing */
 49
 50static struct acpi_table_hest *__read_mostly hest_tab;
 51
 52static const int hest_esrc_len_tab[ACPI_HEST_TYPE_RESERVED] = {
 53	[ACPI_HEST_TYPE_IA32_CHECK] = -1,	/* need further calculation */
 54	[ACPI_HEST_TYPE_IA32_CORRECTED_CHECK] = -1,
 55	[ACPI_HEST_TYPE_IA32_NMI] = sizeof(struct acpi_hest_ia_nmi),
 56	[ACPI_HEST_TYPE_AER_ROOT_PORT] = sizeof(struct acpi_hest_aer_root),
 57	[ACPI_HEST_TYPE_AER_ENDPOINT] = sizeof(struct acpi_hest_aer),
 58	[ACPI_HEST_TYPE_AER_BRIDGE] = sizeof(struct acpi_hest_aer_bridge),
 59	[ACPI_HEST_TYPE_GENERIC_ERROR] = sizeof(struct acpi_hest_generic),
 60};
 61
 62static int hest_esrc_len(struct acpi_hest_header *hest_hdr)
 63{
 64	u16 hest_type = hest_hdr->type;
 65	int len;
 66
 67	if (hest_type >= ACPI_HEST_TYPE_RESERVED)
 68		return 0;
 69
 70	len = hest_esrc_len_tab[hest_type];
 71
 72	if (hest_type == ACPI_HEST_TYPE_IA32_CORRECTED_CHECK) {
 73		struct acpi_hest_ia_corrected *cmc;
 74		cmc = (struct acpi_hest_ia_corrected *)hest_hdr;
 75		len = sizeof(*cmc) + cmc->num_hardware_banks *
 76			sizeof(struct acpi_hest_ia_error_bank);
 77	} else if (hest_type == ACPI_HEST_TYPE_IA32_CHECK) {
 78		struct acpi_hest_ia_machine_check *mc;
 79		mc = (struct acpi_hest_ia_machine_check *)hest_hdr;
 80		len = sizeof(*mc) + mc->num_hardware_banks *
 81			sizeof(struct acpi_hest_ia_error_bank);
 82	}
 83	BUG_ON(len == -1);
 84
 85	return len;
 86};
 87
 88int apei_hest_parse(apei_hest_func_t func, void *data)
 89{
 90	struct acpi_hest_header *hest_hdr;
 91	int i, rc, len;
 92
 93	if (hest_disable || !hest_tab)
 94		return -EINVAL;
 95
 96	hest_hdr = (struct acpi_hest_header *)(hest_tab + 1);
 97	for (i = 0; i < hest_tab->error_source_count; i++) {
 98		len = hest_esrc_len(hest_hdr);
 99		if (!len) {
100			pr_warning(FW_WARN HEST_PFX
101				   "Unknown or unused hardware error source "
102				   "type: %d for hardware error source: %d.\n",
103				   hest_hdr->type, hest_hdr->source_id);
104			return -EINVAL;
105		}
106		if ((void *)hest_hdr + len >
107		    (void *)hest_tab + hest_tab->header.length) {
108			pr_warning(FW_BUG HEST_PFX
109		"Table contents overflow for hardware error source: %d.\n",
110				hest_hdr->source_id);
111			return -EINVAL;
112		}
113
114		rc = func(hest_hdr, data);
115		if (rc)
116			return rc;
117
118		hest_hdr = (void *)hest_hdr + len;
119	}
120
121	return 0;
122}
123EXPORT_SYMBOL_GPL(apei_hest_parse);
124
125/*
126 * Check if firmware advertises firmware first mode. We need FF bit to be set
127 * along with a set of MC banks which work in FF mode.
128 */
129static int __init hest_parse_cmc(struct acpi_hest_header *hest_hdr, void *data)
130{
131#ifdef CONFIG_X86_MCE
132	int i;
133	struct acpi_hest_ia_corrected *cmc;
134	struct acpi_hest_ia_error_bank *mc_bank;
135
136	if (hest_hdr->type != ACPI_HEST_TYPE_IA32_CORRECTED_CHECK)
137		return 0;
138
139	cmc = (struct acpi_hest_ia_corrected *)hest_hdr;
140	if (!cmc->enabled)
141		return 0;
142
143	/*
144	 * We expect HEST to provide a list of MC banks that report errors
145	 * in firmware first mode. Otherwise, return non-zero value to
146	 * indicate that we are done parsing HEST.
147	 */
148	if (!(cmc->flags & ACPI_HEST_FIRMWARE_FIRST) || !cmc->num_hardware_banks)
149		return 1;
150
151	pr_info(HEST_PFX "Enabling Firmware First mode for corrected errors.\n");
152
153	mc_bank = (struct acpi_hest_ia_error_bank *)(cmc + 1);
154	for (i = 0; i < cmc->num_hardware_banks; i++, mc_bank++)
155		mce_disable_bank(mc_bank->bank_number);
156#endif
157	return 1;
158}
159
160struct ghes_arr {
161	struct platform_device **ghes_devs;
162	unsigned int count;
163};
164
165static int __init hest_parse_ghes_count(struct acpi_hest_header *hest_hdr, void *data)
166{
167	int *count = data;
168
169	if (hest_hdr->type == ACPI_HEST_TYPE_GENERIC_ERROR)
170		(*count)++;
171	return 0;
172}
173
174static int __init hest_parse_ghes(struct acpi_hest_header *hest_hdr, void *data)
175{
176	struct platform_device *ghes_dev;
177	struct ghes_arr *ghes_arr = data;
178	int rc, i;
179
180	if (hest_hdr->type != ACPI_HEST_TYPE_GENERIC_ERROR)
181		return 0;
182
183	if (!((struct acpi_hest_generic *)hest_hdr)->enabled)
184		return 0;
185	for (i = 0; i < ghes_arr->count; i++) {
186		struct acpi_hest_header *hdr;
187		ghes_dev = ghes_arr->ghes_devs[i];
188		hdr = *(struct acpi_hest_header **)ghes_dev->dev.platform_data;
189		if (hdr->source_id == hest_hdr->source_id) {
190			pr_warning(FW_WARN HEST_PFX "Duplicated hardware error source ID: %d.\n",
191				   hdr->source_id);
192			return -EIO;
193		}
194	}
195	ghes_dev = platform_device_alloc("GHES", hest_hdr->source_id);
196	if (!ghes_dev)
197		return -ENOMEM;
198
199	rc = platform_device_add_data(ghes_dev, &hest_hdr, sizeof(void *));
200	if (rc)
201		goto err;
202
203	rc = platform_device_add(ghes_dev);
204	if (rc)
205		goto err;
206	ghes_arr->ghes_devs[ghes_arr->count++] = ghes_dev;
207
208	return 0;
209err:
210	platform_device_put(ghes_dev);
211	return rc;
212}
213
214static int __init hest_ghes_dev_register(unsigned int ghes_count)
215{
216	int rc, i;
217	struct ghes_arr ghes_arr;
218
219	ghes_arr.count = 0;
220	ghes_arr.ghes_devs = kmalloc(sizeof(void *) * ghes_count, GFP_KERNEL);
221	if (!ghes_arr.ghes_devs)
222		return -ENOMEM;
223
224	rc = apei_hest_parse(hest_parse_ghes, &ghes_arr);
225	if (rc)
226		goto err;
227out:
228	kfree(ghes_arr.ghes_devs);
229	return rc;
230err:
231	for (i = 0; i < ghes_arr.count; i++)
232		platform_device_unregister(ghes_arr.ghes_devs[i]);
233	goto out;
234}
235
236static int __init setup_hest_disable(char *str)
237{
238	hest_disable = 1;
239	return 0;
240}
241
242__setup("hest_disable", setup_hest_disable);
243
244void __init acpi_hest_init(void)
245{
246	acpi_status status;
247	int rc = -ENODEV;
248	unsigned int ghes_count = 0;
249
250	if (hest_disable) {
251		pr_info(HEST_PFX "Table parsing disabled.\n");
252		return;
253	}
254
 
 
 
255	status = acpi_get_table(ACPI_SIG_HEST, 0,
256				(struct acpi_table_header **)&hest_tab);
257	if (status == AE_NOT_FOUND)
258		goto err;
259	else if (ACPI_FAILURE(status)) {
260		const char *msg = acpi_format_exception(status);
261		pr_err(HEST_PFX "Failed to get table, %s\n", msg);
262		rc = -EINVAL;
263		goto err;
264	}
265
266	if (!acpi_disable_cmcff)
267		apei_hest_parse(hest_parse_cmc, NULL);
268
269	if (!ghes_disable) {
270		rc = apei_hest_parse(hest_parse_ghes_count, &ghes_count);
271		if (rc)
272			goto err;
273		rc = hest_ghes_dev_register(ghes_count);
274		if (rc)
275			goto err;
276	}
277
278	pr_info(HEST_PFX "Table parsing has been initialized.\n");
279	return;
280err:
281	hest_disable = 1;
282}