ext3: Add journal error check into ext3_delete_entry()
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / acpi / apei / hest.c
blobdaa7bc63f1d4bad00fd988ddcce3681fdc74f804
1 /*
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
8 * error registers).
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.
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
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>
40 #include "apei-internal.h"
42 #define HEST_PFX "HEST: "
44 int hest_disable;
45 EXPORT_SYMBOL_GPL(hest_disable);
47 /* HEST table parsing */
49 static struct acpi_table_hest *__read_mostly hest_tab;
51 static 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),
61 static int hest_esrc_len(struct acpi_hest_header *hest_hdr)
63 u16 hest_type = hest_hdr->type;
64 int len;
66 if (hest_type >= ACPI_HEST_TYPE_RESERVED)
67 return 0;
69 len = hest_esrc_len_tab[hest_type];
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);
82 BUG_ON(len == -1);
84 return len;
87 int apei_hest_parse(apei_hest_func_t func, void *data)
89 struct acpi_hest_header *hest_hdr;
90 int i, rc, len;
92 if (hest_disable)
93 return -EINVAL;
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;
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;
113 rc = func(hest_hdr, data);
114 if (rc)
115 return rc;
117 hest_hdr = (void *)hest_hdr + len;
120 return 0;
122 EXPORT_SYMBOL_GPL(apei_hest_parse);
124 struct ghes_arr {
125 struct platform_device **ghes_devs;
126 unsigned int count;
129 static int __init hest_parse_ghes_count(struct acpi_hest_header *hest_hdr, void *data)
131 int *count = data;
133 if (hest_hdr->type == ACPI_HEST_TYPE_GENERIC_ERROR)
134 (*count)++;
135 return 0;
138 static int __init hest_parse_ghes(struct acpi_hest_header *hest_hdr, void *data)
140 struct platform_device *ghes_dev;
141 struct ghes_arr *ghes_arr = data;
142 int rc;
144 if (hest_hdr->type != ACPI_HEST_TYPE_GENERIC_ERROR)
145 return 0;
147 if (!((struct acpi_hest_generic *)hest_hdr)->enabled)
148 return 0;
149 ghes_dev = platform_device_alloc("GHES", hest_hdr->source_id);
150 if (!ghes_dev)
151 return -ENOMEM;
153 rc = platform_device_add_data(ghes_dev, &hest_hdr, sizeof(void *));
154 if (rc)
155 goto err;
157 rc = platform_device_add(ghes_dev);
158 if (rc)
159 goto err;
160 ghes_arr->ghes_devs[ghes_arr->count++] = ghes_dev;
162 return 0;
163 err:
164 platform_device_put(ghes_dev);
165 return rc;
168 static int __init hest_ghes_dev_register(unsigned int ghes_count)
170 int rc, i;
171 struct ghes_arr ghes_arr;
173 ghes_arr.count = 0;
174 ghes_arr.ghes_devs = kmalloc(sizeof(void *) * ghes_count, GFP_KERNEL);
175 if (!ghes_arr.ghes_devs)
176 return -ENOMEM;
178 rc = apei_hest_parse(hest_parse_ghes, &ghes_arr);
179 if (rc)
180 goto err;
181 out:
182 kfree(ghes_arr.ghes_devs);
183 return rc;
184 err:
185 for (i = 0; i < ghes_arr.count; i++)
186 platform_device_unregister(ghes_arr.ghes_devs[i]);
187 goto out;
190 static int __init setup_hest_disable(char *str)
192 hest_disable = 1;
193 return 0;
196 __setup("hest_disable", setup_hest_disable);
198 static int __init hest_init(void)
200 acpi_status status;
201 int rc = -ENODEV;
202 unsigned int ghes_count = 0;
204 if (acpi_disabled)
205 goto err;
207 if (hest_disable) {
208 pr_info(HEST_PFX "HEST tabling parsing is disabled.\n");
209 goto err;
212 status = acpi_get_table(ACPI_SIG_HEST, 0,
213 (struct acpi_table_header **)&hest_tab);
214 if (status == AE_NOT_FOUND) {
215 pr_info(HEST_PFX "Table is not found!\n");
216 goto err;
217 } else if (ACPI_FAILURE(status)) {
218 const char *msg = acpi_format_exception(status);
219 pr_err(HEST_PFX "Failed to get table, %s\n", msg);
220 rc = -EINVAL;
221 goto err;
224 rc = apei_hest_parse(hest_parse_ghes_count, &ghes_count);
225 if (rc)
226 goto err;
228 rc = hest_ghes_dev_register(ghes_count);
229 if (rc)
230 goto err;
232 pr_info(HEST_PFX "HEST table parsing is initialized.\n");
234 return 0;
235 err:
236 hest_disable = 1;
237 return rc;
240 subsys_initcall(hest_init);