Huang Ying | 9dc9666 | 2010-05-18 14:35:13 +0800 | [diff] [blame] | 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> |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 37 | #include <linux/platform_device.h> |
Huang Ying | 9dc9666 | 2010-05-18 14:35:13 +0800 | [diff] [blame] | 38 | #include <acpi/apei.h> |
| 39 | |
| 40 | #include "apei-internal.h" |
| 41 | |
| 42 | #define HEST_PFX "HEST: " |
| 43 | |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 44 | bool hest_disable; |
Huang Ying | 9dc9666 | 2010-05-18 14:35:13 +0800 | [diff] [blame] | 45 | EXPORT_SYMBOL_GPL(hest_disable); |
| 46 | |
| 47 | /* HEST table parsing */ |
| 48 | |
Jan Beulich | bec4f22 | 2010-12-07 14:58:44 +0000 | [diff] [blame] | 49 | static struct acpi_table_hest *__read_mostly hest_tab; |
Huang Ying | 9dc9666 | 2010-05-18 14:35:13 +0800 | [diff] [blame] | 50 | |
Jan Beulich | bec4f22 | 2010-12-07 14:58:44 +0000 | [diff] [blame] | 51 | static const int hest_esrc_len_tab[ACPI_HEST_TYPE_RESERVED] = { |
Huang Ying | 9dc9666 | 2010-05-18 14:35:13 +0800 | [diff] [blame] | 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 | |
| 61 | static 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 | |
| 87 | int apei_hest_parse(apei_hest_func_t func, void *data) |
| 88 | { |
| 89 | struct acpi_hest_header *hest_hdr; |
| 90 | int i, rc, len; |
| 91 | |
Rafael J. Wysocki | a84363d | 2013-02-23 00:14:57 +0100 | [diff] [blame] | 92 | if (hest_disable || !hest_tab) |
Huang Ying | 9dc9666 | 2010-05-18 14:35:13 +0800 | [diff] [blame] | 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 | } |
| 122 | EXPORT_SYMBOL_GPL(apei_hest_parse); |
| 123 | |
Naveen N. Rao | c3d1fb5 | 2013-07-01 21:08:47 +0530 | [diff] [blame] | 124 | /* |
| 125 | * Check if firmware advertises firmware first mode. We need FF bit to be set |
| 126 | * along with a set of MC banks which work in FF mode. |
| 127 | */ |
| 128 | static int __init hest_parse_cmc(struct acpi_hest_header *hest_hdr, void *data) |
| 129 | { |
Tomasz Nowicki | 9dae3d0 | 2014-07-22 11:20:11 +0200 | [diff] [blame] | 130 | return arch_apei_enable_cmcff(hest_hdr, data); |
Naveen N. Rao | c3d1fb5 | 2013-07-01 21:08:47 +0530 | [diff] [blame] | 131 | } |
| 132 | |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 133 | struct ghes_arr { |
| 134 | struct platform_device **ghes_devs; |
| 135 | unsigned int count; |
| 136 | }; |
| 137 | |
Jan Beulich | bec4f22 | 2010-12-07 14:58:44 +0000 | [diff] [blame] | 138 | static int __init hest_parse_ghes_count(struct acpi_hest_header *hest_hdr, void *data) |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 139 | { |
| 140 | int *count = data; |
| 141 | |
| 142 | if (hest_hdr->type == ACPI_HEST_TYPE_GENERIC_ERROR) |
| 143 | (*count)++; |
| 144 | return 0; |
| 145 | } |
| 146 | |
Jan Beulich | bec4f22 | 2010-12-07 14:58:44 +0000 | [diff] [blame] | 147 | static int __init hest_parse_ghes(struct acpi_hest_header *hest_hdr, void *data) |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 148 | { |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 149 | struct platform_device *ghes_dev; |
| 150 | struct ghes_arr *ghes_arr = data; |
Huang Ying | 4d2b295 | 2011-07-13 13:14:12 +0800 | [diff] [blame] | 151 | int rc, i; |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 152 | |
| 153 | if (hest_hdr->type != ACPI_HEST_TYPE_GENERIC_ERROR) |
| 154 | return 0; |
Jin Dongming | 1dd6b20 | 2010-09-29 19:53:53 +0800 | [diff] [blame] | 155 | |
| 156 | if (!((struct acpi_hest_generic *)hest_hdr)->enabled) |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 157 | return 0; |
Huang Ying | 4d2b295 | 2011-07-13 13:14:12 +0800 | [diff] [blame] | 158 | for (i = 0; i < ghes_arr->count; i++) { |
| 159 | struct acpi_hest_header *hdr; |
| 160 | ghes_dev = ghes_arr->ghes_devs[i]; |
| 161 | hdr = *(struct acpi_hest_header **)ghes_dev->dev.platform_data; |
| 162 | if (hdr->source_id == hest_hdr->source_id) { |
| 163 | pr_warning(FW_WARN HEST_PFX "Duplicated hardware error source ID: %d.\n", |
| 164 | hdr->source_id); |
| 165 | return -EIO; |
| 166 | } |
| 167 | } |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 168 | ghes_dev = platform_device_alloc("GHES", hest_hdr->source_id); |
| 169 | if (!ghes_dev) |
| 170 | return -ENOMEM; |
Jin Dongming | 1dd6b20 | 2010-09-29 19:53:53 +0800 | [diff] [blame] | 171 | |
| 172 | rc = platform_device_add_data(ghes_dev, &hest_hdr, sizeof(void *)); |
| 173 | if (rc) |
| 174 | goto err; |
| 175 | |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 176 | rc = platform_device_add(ghes_dev); |
| 177 | if (rc) |
| 178 | goto err; |
| 179 | ghes_arr->ghes_devs[ghes_arr->count++] = ghes_dev; |
| 180 | |
| 181 | return 0; |
| 182 | err: |
| 183 | platform_device_put(ghes_dev); |
| 184 | return rc; |
| 185 | } |
| 186 | |
Jan Beulich | bec4f22 | 2010-12-07 14:58:44 +0000 | [diff] [blame] | 187 | static int __init hest_ghes_dev_register(unsigned int ghes_count) |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 188 | { |
| 189 | int rc, i; |
| 190 | struct ghes_arr ghes_arr; |
| 191 | |
| 192 | ghes_arr.count = 0; |
| 193 | ghes_arr.ghes_devs = kmalloc(sizeof(void *) * ghes_count, GFP_KERNEL); |
| 194 | if (!ghes_arr.ghes_devs) |
| 195 | return -ENOMEM; |
| 196 | |
| 197 | rc = apei_hest_parse(hest_parse_ghes, &ghes_arr); |
| 198 | if (rc) |
| 199 | goto err; |
| 200 | out: |
| 201 | kfree(ghes_arr.ghes_devs); |
| 202 | return rc; |
| 203 | err: |
| 204 | for (i = 0; i < ghes_arr.count; i++) |
| 205 | platform_device_unregister(ghes_arr.ghes_devs[i]); |
| 206 | goto out; |
| 207 | } |
| 208 | |
Huang Ying | 9dc9666 | 2010-05-18 14:35:13 +0800 | [diff] [blame] | 209 | static int __init setup_hest_disable(char *str) |
| 210 | { |
| 211 | hest_disable = 1; |
| 212 | return 0; |
| 213 | } |
| 214 | |
| 215 | __setup("hest_disable", setup_hest_disable); |
| 216 | |
Rafael J. Wysocki | 415e12b | 2011-01-07 00:55:09 +0100 | [diff] [blame] | 217 | void __init acpi_hest_init(void) |
Huang Ying | 9dc9666 | 2010-05-18 14:35:13 +0800 | [diff] [blame] | 218 | { |
| 219 | acpi_status status; |
| 220 | int rc = -ENODEV; |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 221 | unsigned int ghes_count = 0; |
Huang Ying | 9dc9666 | 2010-05-18 14:35:13 +0800 | [diff] [blame] | 222 | |
Huang Ying | 9dc9666 | 2010-05-18 14:35:13 +0800 | [diff] [blame] | 223 | if (hest_disable) { |
Rafael J. Wysocki | 415e12b | 2011-01-07 00:55:09 +0100 | [diff] [blame] | 224 | pr_info(HEST_PFX "Table parsing disabled.\n"); |
| 225 | return; |
Huang Ying | 9dc9666 | 2010-05-18 14:35:13 +0800 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | status = acpi_get_table(ACPI_SIG_HEST, 0, |
| 229 | (struct acpi_table_header **)&hest_tab); |
Huang Ying | ad68615 | 2011-12-08 11:25:43 +0800 | [diff] [blame] | 230 | if (status == AE_NOT_FOUND) |
Huang Ying | 9dc9666 | 2010-05-18 14:35:13 +0800 | [diff] [blame] | 231 | goto err; |
Huang Ying | ad68615 | 2011-12-08 11:25:43 +0800 | [diff] [blame] | 232 | else if (ACPI_FAILURE(status)) { |
Huang Ying | 9dc9666 | 2010-05-18 14:35:13 +0800 | [diff] [blame] | 233 | const char *msg = acpi_format_exception(status); |
| 234 | pr_err(HEST_PFX "Failed to get table, %s\n", msg); |
| 235 | rc = -EINVAL; |
| 236 | goto err; |
| 237 | } |
| 238 | |
Naveen N. Rao | 9ad9587 | 2013-07-01 21:08:54 +0530 | [diff] [blame] | 239 | if (!acpi_disable_cmcff) |
| 240 | apei_hest_parse(hest_parse_cmc, NULL); |
Naveen N. Rao | c3d1fb5 | 2013-07-01 21:08:47 +0530 | [diff] [blame] | 241 | |
Huang Ying | b6a9501 | 2011-07-13 13:14:19 +0800 | [diff] [blame] | 242 | if (!ghes_disable) { |
| 243 | rc = apei_hest_parse(hest_parse_ghes_count, &ghes_count); |
| 244 | if (rc) |
| 245 | goto err; |
| 246 | rc = hest_ghes_dev_register(ghes_count); |
| 247 | if (rc) |
| 248 | goto err; |
Rafael J. Wysocki | 415e12b | 2011-01-07 00:55:09 +0100 | [diff] [blame] | 249 | } |
Huang Ying | 9dc9666 | 2010-05-18 14:35:13 +0800 | [diff] [blame] | 250 | |
Huang Ying | b6a9501 | 2011-07-13 13:14:19 +0800 | [diff] [blame] | 251 | pr_info(HEST_PFX "Table parsing has been initialized.\n"); |
| 252 | return; |
Huang Ying | 9dc9666 | 2010-05-18 14:35:13 +0800 | [diff] [blame] | 253 | err: |
| 254 | hest_disable = 1; |
Huang Ying | 9dc9666 | 2010-05-18 14:35:13 +0800 | [diff] [blame] | 255 | } |