Huang Ying | e402134 | 2010-05-18 14:35:14 +0800 | [diff] [blame] | 1 | /* |
| 2 | * APEI Error INJection support |
| 3 | * |
| 4 | * EINJ provides a hardware error injection mechanism, this is useful |
| 5 | * for debugging and testing of other APEI and RAS features. |
| 6 | * |
| 7 | * For more information about EINJ, please refer to ACPI Specification |
| 8 | * version 4.0, section 17.5. |
| 9 | * |
Huang Ying | 6e320ec | 2010-05-18 14:35:24 +0800 | [diff] [blame] | 10 | * Copyright 2009-2010 Intel Corp. |
Huang Ying | e402134 | 2010-05-18 14:35:14 +0800 | [diff] [blame] | 11 | * Author: Huang Ying <ying.huang@intel.com> |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or |
| 14 | * modify it under the terms of the GNU General Public License version |
| 15 | * 2 as published by the Free Software Foundation. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 | */ |
| 26 | |
| 27 | #include <linux/kernel.h> |
| 28 | #include <linux/module.h> |
| 29 | #include <linux/init.h> |
| 30 | #include <linux/io.h> |
| 31 | #include <linux/debugfs.h> |
| 32 | #include <linux/seq_file.h> |
| 33 | #include <linux/nmi.h> |
| 34 | #include <linux/delay.h> |
Chen Gong | c5a1303 | 2013-06-06 15:20:51 -0700 | [diff] [blame] | 35 | #include <linux/mm.h> |
Huang Ying | e402134 | 2010-05-18 14:35:14 +0800 | [diff] [blame] | 36 | #include <acpi/acpi.h> |
| 37 | |
| 38 | #include "apei-internal.h" |
| 39 | |
| 40 | #define EINJ_PFX "EINJ: " |
| 41 | |
| 42 | #define SPIN_UNIT 100 /* 100ns */ |
Stefan Weil | e8a8b25 | 2011-01-02 15:12:42 +0100 | [diff] [blame] | 43 | /* Firmware should respond within 1 milliseconds */ |
Huang Ying | e402134 | 2010-05-18 14:35:14 +0800 | [diff] [blame] | 44 | #define FIRMWARE_TIMEOUT (1 * NSEC_PER_MSEC) |
Chen Gong | c5a1303 | 2013-06-06 15:20:51 -0700 | [diff] [blame] | 45 | #define ACPI5_VENDOR_BIT BIT(31) |
| 46 | #define MEM_ERROR_MASK (ACPI_EINJ_MEMORY_CORRECTABLE | \ |
| 47 | ACPI_EINJ_MEMORY_UNCORRECTABLE | \ |
| 48 | ACPI_EINJ_MEMORY_FATAL) |
Huang Ying | e402134 | 2010-05-18 14:35:14 +0800 | [diff] [blame] | 49 | |
Huang Ying | 6e320ec | 2010-05-18 14:35:24 +0800 | [diff] [blame] | 50 | /* |
Tony Luck | c130bd6 | 2012-01-17 12:10:16 -0800 | [diff] [blame] | 51 | * ACPI version 5 provides a SET_ERROR_TYPE_WITH_ADDRESS action. |
| 52 | */ |
| 53 | static int acpi5; |
| 54 | |
| 55 | struct set_error_type_with_address { |
| 56 | u32 type; |
| 57 | u32 vendor_extension; |
| 58 | u32 flags; |
| 59 | u32 apicid; |
| 60 | u64 memory_address; |
| 61 | u64 memory_address_range; |
| 62 | u32 pcie_sbdf; |
| 63 | }; |
| 64 | enum { |
| 65 | SETWA_FLAGS_APICID = 1, |
| 66 | SETWA_FLAGS_MEM = 2, |
| 67 | SETWA_FLAGS_PCIE_SBDF = 4, |
| 68 | }; |
| 69 | |
| 70 | /* |
| 71 | * Vendor extensions for platform specific operations |
| 72 | */ |
| 73 | struct vendor_error_type_extension { |
| 74 | u32 length; |
| 75 | u32 pcie_sbdf; |
| 76 | u16 vendor_id; |
| 77 | u16 device_id; |
| 78 | u8 rev_id; |
| 79 | u8 reserved[3]; |
| 80 | }; |
| 81 | |
Chen Gong | ee49089 | 2012-03-15 16:53:36 +0800 | [diff] [blame] | 82 | static u32 notrigger; |
| 83 | |
Tony Luck | c130bd6 | 2012-01-17 12:10:16 -0800 | [diff] [blame] | 84 | static u32 vendor_flags; |
| 85 | static struct debugfs_blob_wrapper vendor_blob; |
| 86 | static char vendor_dev[64]; |
| 87 | |
| 88 | /* |
Huang Ying | 6e320ec | 2010-05-18 14:35:24 +0800 | [diff] [blame] | 89 | * Some BIOSes allow parameters to the SET_ERROR_TYPE entries in the |
| 90 | * EINJ table through an unpublished extension. Use with caution as |
| 91 | * most will ignore the parameter and make their own choice of address |
Huang Ying | c3e6088 | 2011-07-20 16:09:29 +0800 | [diff] [blame] | 92 | * for error injection. This extension is used only if |
| 93 | * param_extension module parameter is specified. |
Huang Ying | 6e320ec | 2010-05-18 14:35:24 +0800 | [diff] [blame] | 94 | */ |
| 95 | struct einj_parameter { |
| 96 | u64 type; |
| 97 | u64 reserved1; |
| 98 | u64 reserved2; |
| 99 | u64 param1; |
| 100 | u64 param2; |
| 101 | }; |
| 102 | |
Huang Ying | e402134 | 2010-05-18 14:35:14 +0800 | [diff] [blame] | 103 | #define EINJ_OP_BUSY 0x1 |
| 104 | #define EINJ_STATUS_SUCCESS 0x0 |
| 105 | #define EINJ_STATUS_FAIL 0x1 |
| 106 | #define EINJ_STATUS_INVAL 0x2 |
| 107 | |
| 108 | #define EINJ_TAB_ENTRY(tab) \ |
| 109 | ((struct acpi_whea_header *)((char *)(tab) + \ |
| 110 | sizeof(struct acpi_table_einj))) |
| 111 | |
Huang Ying | c3e6088 | 2011-07-20 16:09:29 +0800 | [diff] [blame] | 112 | static bool param_extension; |
| 113 | module_param(param_extension, bool, 0); |
| 114 | |
Huang Ying | e402134 | 2010-05-18 14:35:14 +0800 | [diff] [blame] | 115 | static struct acpi_table_einj *einj_tab; |
| 116 | |
| 117 | static struct apei_resources einj_resources; |
| 118 | |
| 119 | static struct apei_exec_ins_type einj_ins_type[] = { |
| 120 | [ACPI_EINJ_READ_REGISTER] = { |
| 121 | .flags = APEI_EXEC_INS_ACCESS_REGISTER, |
| 122 | .run = apei_exec_read_register, |
| 123 | }, |
| 124 | [ACPI_EINJ_READ_REGISTER_VALUE] = { |
| 125 | .flags = APEI_EXEC_INS_ACCESS_REGISTER, |
| 126 | .run = apei_exec_read_register_value, |
| 127 | }, |
| 128 | [ACPI_EINJ_WRITE_REGISTER] = { |
| 129 | .flags = APEI_EXEC_INS_ACCESS_REGISTER, |
| 130 | .run = apei_exec_write_register, |
| 131 | }, |
| 132 | [ACPI_EINJ_WRITE_REGISTER_VALUE] = { |
| 133 | .flags = APEI_EXEC_INS_ACCESS_REGISTER, |
| 134 | .run = apei_exec_write_register_value, |
| 135 | }, |
| 136 | [ACPI_EINJ_NOOP] = { |
| 137 | .flags = 0, |
| 138 | .run = apei_exec_noop, |
| 139 | }, |
| 140 | }; |
| 141 | |
| 142 | /* |
| 143 | * Prevent EINJ interpreter to run simultaneously, because the |
| 144 | * corresponding firmware implementation may not work properly when |
| 145 | * invoked simultaneously. |
| 146 | */ |
| 147 | static DEFINE_MUTEX(einj_mutex); |
| 148 | |
Tony Luck | c130bd6 | 2012-01-17 12:10:16 -0800 | [diff] [blame] | 149 | static void *einj_param; |
| 150 | |
Huang Ying | e402134 | 2010-05-18 14:35:14 +0800 | [diff] [blame] | 151 | static void einj_exec_ctx_init(struct apei_exec_context *ctx) |
| 152 | { |
| 153 | apei_exec_ctx_init(ctx, einj_ins_type, ARRAY_SIZE(einj_ins_type), |
| 154 | EINJ_TAB_ENTRY(einj_tab), einj_tab->entries); |
| 155 | } |
| 156 | |
| 157 | static int __einj_get_available_error_type(u32 *type) |
| 158 | { |
| 159 | struct apei_exec_context ctx; |
| 160 | int rc; |
| 161 | |
| 162 | einj_exec_ctx_init(&ctx); |
| 163 | rc = apei_exec_run(&ctx, ACPI_EINJ_GET_ERROR_TYPE); |
| 164 | if (rc) |
| 165 | return rc; |
| 166 | *type = apei_exec_ctx_get_output(&ctx); |
| 167 | |
| 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | /* Get error injection capabilities of the platform */ |
| 172 | static int einj_get_available_error_type(u32 *type) |
| 173 | { |
| 174 | int rc; |
| 175 | |
| 176 | mutex_lock(&einj_mutex); |
| 177 | rc = __einj_get_available_error_type(type); |
| 178 | mutex_unlock(&einj_mutex); |
| 179 | |
| 180 | return rc; |
| 181 | } |
| 182 | |
| 183 | static int einj_timedout(u64 *t) |
| 184 | { |
| 185 | if ((s64)*t < SPIN_UNIT) { |
| 186 | pr_warning(FW_WARN EINJ_PFX |
| 187 | "Firmware does not respond in time\n"); |
| 188 | return 1; |
| 189 | } |
| 190 | *t -= SPIN_UNIT; |
| 191 | ndelay(SPIN_UNIT); |
| 192 | touch_nmi_watchdog(); |
| 193 | return 0; |
| 194 | } |
| 195 | |
Tony Luck | c130bd6 | 2012-01-17 12:10:16 -0800 | [diff] [blame] | 196 | static void check_vendor_extension(u64 paddr, |
| 197 | struct set_error_type_with_address *v5param) |
| 198 | { |
Luck, Tony | 459413d | 2012-01-23 15:27:56 -0800 | [diff] [blame] | 199 | int offset = v5param->vendor_extension; |
Tony Luck | c130bd6 | 2012-01-17 12:10:16 -0800 | [diff] [blame] | 200 | struct vendor_error_type_extension *v; |
| 201 | u32 sbdf; |
| 202 | |
| 203 | if (!offset) |
| 204 | return; |
Luck, Tony | 459413d | 2012-01-23 15:27:56 -0800 | [diff] [blame] | 205 | v = acpi_os_map_memory(paddr + offset, sizeof(*v)); |
Tony Luck | c130bd6 | 2012-01-17 12:10:16 -0800 | [diff] [blame] | 206 | if (!v) |
| 207 | return; |
Luck, Tony | 459413d | 2012-01-23 15:27:56 -0800 | [diff] [blame] | 208 | sbdf = v->pcie_sbdf; |
Tony Luck | c130bd6 | 2012-01-17 12:10:16 -0800 | [diff] [blame] | 209 | sprintf(vendor_dev, "%x:%x:%x.%x vendor_id=%x device_id=%x rev_id=%x\n", |
| 210 | sbdf >> 24, (sbdf >> 16) & 0xff, |
| 211 | (sbdf >> 11) & 0x1f, (sbdf >> 8) & 0x7, |
Luck, Tony | 459413d | 2012-01-23 15:27:56 -0800 | [diff] [blame] | 212 | v->vendor_id, v->device_id, v->rev_id); |
| 213 | acpi_os_unmap_memory(v, sizeof(*v)); |
Tony Luck | c130bd6 | 2012-01-17 12:10:16 -0800 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | static void *einj_get_parameter_address(void) |
Huang Ying | 6e320ec | 2010-05-18 14:35:24 +0800 | [diff] [blame] | 217 | { |
| 218 | int i; |
Tony Luck | c130bd6 | 2012-01-17 12:10:16 -0800 | [diff] [blame] | 219 | u64 paddrv4 = 0, paddrv5 = 0; |
Huang Ying | 6e320ec | 2010-05-18 14:35:24 +0800 | [diff] [blame] | 220 | struct acpi_whea_header *entry; |
| 221 | |
| 222 | entry = EINJ_TAB_ENTRY(einj_tab); |
| 223 | for (i = 0; i < einj_tab->entries; i++) { |
| 224 | if (entry->action == ACPI_EINJ_SET_ERROR_TYPE && |
| 225 | entry->instruction == ACPI_EINJ_WRITE_REGISTER && |
| 226 | entry->register_region.space_id == |
| 227 | ACPI_ADR_SPACE_SYSTEM_MEMORY) |
Tony Luck | c130bd6 | 2012-01-17 12:10:16 -0800 | [diff] [blame] | 228 | memcpy(&paddrv4, &entry->register_region.address, |
| 229 | sizeof(paddrv4)); |
| 230 | if (entry->action == ACPI_EINJ_SET_ERROR_TYPE_WITH_ADDRESS && |
| 231 | entry->instruction == ACPI_EINJ_WRITE_REGISTER && |
| 232 | entry->register_region.space_id == |
| 233 | ACPI_ADR_SPACE_SYSTEM_MEMORY) |
| 234 | memcpy(&paddrv5, &entry->register_region.address, |
| 235 | sizeof(paddrv5)); |
Huang Ying | 6e320ec | 2010-05-18 14:35:24 +0800 | [diff] [blame] | 236 | entry++; |
| 237 | } |
Tony Luck | c130bd6 | 2012-01-17 12:10:16 -0800 | [diff] [blame] | 238 | if (paddrv5) { |
| 239 | struct set_error_type_with_address *v5param; |
Huang Ying | 6e320ec | 2010-05-18 14:35:24 +0800 | [diff] [blame] | 240 | |
Luck, Tony | 459413d | 2012-01-23 15:27:56 -0800 | [diff] [blame] | 241 | v5param = acpi_os_map_memory(paddrv5, sizeof(*v5param)); |
Tony Luck | c130bd6 | 2012-01-17 12:10:16 -0800 | [diff] [blame] | 242 | if (v5param) { |
| 243 | acpi5 = 1; |
| 244 | check_vendor_extension(paddrv5, v5param); |
| 245 | return v5param; |
| 246 | } |
| 247 | } |
Chen Gong | 185210c | 2012-03-03 11:56:43 +0800 | [diff] [blame] | 248 | if (param_extension && paddrv4) { |
Tony Luck | c130bd6 | 2012-01-17 12:10:16 -0800 | [diff] [blame] | 249 | struct einj_parameter *v4param; |
| 250 | |
Luck, Tony | 459413d | 2012-01-23 15:27:56 -0800 | [diff] [blame] | 251 | v4param = acpi_os_map_memory(paddrv4, sizeof(*v4param)); |
Tony Luck | c130bd6 | 2012-01-17 12:10:16 -0800 | [diff] [blame] | 252 | if (!v4param) |
Dan Carpenter | 29924b9 | 2012-01-20 10:57:14 +0300 | [diff] [blame] | 253 | return NULL; |
Luck, Tony | 459413d | 2012-01-23 15:27:56 -0800 | [diff] [blame] | 254 | if (v4param->reserved1 || v4param->reserved2) { |
| 255 | acpi_os_unmap_memory(v4param, sizeof(*v4param)); |
Dan Carpenter | 29924b9 | 2012-01-20 10:57:14 +0300 | [diff] [blame] | 256 | return NULL; |
Tony Luck | c130bd6 | 2012-01-17 12:10:16 -0800 | [diff] [blame] | 257 | } |
| 258 | return v4param; |
| 259 | } |
| 260 | |
Dan Carpenter | 29924b9 | 2012-01-20 10:57:14 +0300 | [diff] [blame] | 261 | return NULL; |
Huang Ying | 6e320ec | 2010-05-18 14:35:24 +0800 | [diff] [blame] | 262 | } |
| 263 | |
Huang Ying | e402134 | 2010-05-18 14:35:14 +0800 | [diff] [blame] | 264 | /* do sanity check to trigger table */ |
| 265 | static int einj_check_trigger_header(struct acpi_einj_trigger *trigger_tab) |
| 266 | { |
| 267 | if (trigger_tab->header_size != sizeof(struct acpi_einj_trigger)) |
| 268 | return -EINVAL; |
| 269 | if (trigger_tab->table_size > PAGE_SIZE || |
Niklas Söderlund | 4c40aed | 2012-01-09 16:49:44 +0100 | [diff] [blame] | 270 | trigger_tab->table_size < trigger_tab->header_size) |
Huang Ying | e402134 | 2010-05-18 14:35:14 +0800 | [diff] [blame] | 271 | return -EINVAL; |
| 272 | if (trigger_tab->entry_count != |
| 273 | (trigger_tab->table_size - trigger_tab->header_size) / |
| 274 | sizeof(struct acpi_einj_entry)) |
| 275 | return -EINVAL; |
| 276 | |
| 277 | return 0; |
| 278 | } |
| 279 | |
Xiao, Hui | b4e008d | 2011-12-08 11:25:48 +0800 | [diff] [blame] | 280 | static struct acpi_generic_address *einj_get_trigger_parameter_region( |
| 281 | struct acpi_einj_trigger *trigger_tab, u64 param1, u64 param2) |
| 282 | { |
| 283 | int i; |
| 284 | struct acpi_whea_header *entry; |
| 285 | |
| 286 | entry = (struct acpi_whea_header *) |
| 287 | ((char *)trigger_tab + sizeof(struct acpi_einj_trigger)); |
| 288 | for (i = 0; i < trigger_tab->entry_count; i++) { |
| 289 | if (entry->action == ACPI_EINJ_TRIGGER_ERROR && |
| 290 | entry->instruction == ACPI_EINJ_WRITE_REGISTER_VALUE && |
| 291 | entry->register_region.space_id == |
| 292 | ACPI_ADR_SPACE_SYSTEM_MEMORY && |
| 293 | (entry->register_region.address & param2) == (param1 & param2)) |
| 294 | return &entry->register_region; |
| 295 | entry++; |
| 296 | } |
| 297 | |
| 298 | return NULL; |
| 299 | } |
Huang Ying | e402134 | 2010-05-18 14:35:14 +0800 | [diff] [blame] | 300 | /* Execute instructions in trigger error action table */ |
Huang Ying | fdea163 | 2011-12-08 11:25:47 +0800 | [diff] [blame] | 301 | static int __einj_error_trigger(u64 trigger_paddr, u32 type, |
| 302 | u64 param1, u64 param2) |
Huang Ying | e402134 | 2010-05-18 14:35:14 +0800 | [diff] [blame] | 303 | { |
| 304 | struct acpi_einj_trigger *trigger_tab = NULL; |
| 305 | struct apei_exec_context trigger_ctx; |
| 306 | struct apei_resources trigger_resources; |
| 307 | struct acpi_whea_header *trigger_entry; |
| 308 | struct resource *r; |
| 309 | u32 table_size; |
| 310 | int rc = -EIO; |
Xiao, Hui | b4e008d | 2011-12-08 11:25:48 +0800 | [diff] [blame] | 311 | struct acpi_generic_address *trigger_param_region = NULL; |
Huang Ying | e402134 | 2010-05-18 14:35:14 +0800 | [diff] [blame] | 312 | |
| 313 | r = request_mem_region(trigger_paddr, sizeof(*trigger_tab), |
| 314 | "APEI EINJ Trigger Table"); |
| 315 | if (!r) { |
| 316 | pr_err(EINJ_PFX |
Bjorn Helgaas | 46b91e3 | 2011-12-08 11:25:42 +0800 | [diff] [blame] | 317 | "Can not request [mem %#010llx-%#010llx] for Trigger table\n", |
Huang Ying | e402134 | 2010-05-18 14:35:14 +0800 | [diff] [blame] | 318 | (unsigned long long)trigger_paddr, |
Bjorn Helgaas | 46b91e3 | 2011-12-08 11:25:42 +0800 | [diff] [blame] | 319 | (unsigned long long)trigger_paddr + |
| 320 | sizeof(*trigger_tab) - 1); |
Huang Ying | e402134 | 2010-05-18 14:35:14 +0800 | [diff] [blame] | 321 | goto out; |
| 322 | } |
| 323 | trigger_tab = ioremap_cache(trigger_paddr, sizeof(*trigger_tab)); |
| 324 | if (!trigger_tab) { |
| 325 | pr_err(EINJ_PFX "Failed to map trigger table!\n"); |
| 326 | goto out_rel_header; |
| 327 | } |
| 328 | rc = einj_check_trigger_header(trigger_tab); |
| 329 | if (rc) { |
| 330 | pr_warning(FW_BUG EINJ_PFX |
| 331 | "The trigger error action table is invalid\n"); |
| 332 | goto out_rel_header; |
| 333 | } |
Niklas Söderlund | 4c40aed | 2012-01-09 16:49:44 +0100 | [diff] [blame] | 334 | |
| 335 | /* No action structures in the TRIGGER_ERROR table, nothing to do */ |
| 336 | if (!trigger_tab->entry_count) |
| 337 | goto out_rel_header; |
| 338 | |
Huang Ying | e402134 | 2010-05-18 14:35:14 +0800 | [diff] [blame] | 339 | rc = -EIO; |
| 340 | table_size = trigger_tab->table_size; |
| 341 | r = request_mem_region(trigger_paddr + sizeof(*trigger_tab), |
| 342 | table_size - sizeof(*trigger_tab), |
| 343 | "APEI EINJ Trigger Table"); |
| 344 | if (!r) { |
| 345 | pr_err(EINJ_PFX |
Bjorn Helgaas | 46b91e3 | 2011-12-08 11:25:42 +0800 | [diff] [blame] | 346 | "Can not request [mem %#010llx-%#010llx] for Trigger Table Entry\n", |
| 347 | (unsigned long long)trigger_paddr + sizeof(*trigger_tab), |
| 348 | (unsigned long long)trigger_paddr + table_size - 1); |
Huang Ying | e402134 | 2010-05-18 14:35:14 +0800 | [diff] [blame] | 349 | goto out_rel_header; |
| 350 | } |
| 351 | iounmap(trigger_tab); |
| 352 | trigger_tab = ioremap_cache(trigger_paddr, table_size); |
| 353 | if (!trigger_tab) { |
| 354 | pr_err(EINJ_PFX "Failed to map trigger table!\n"); |
| 355 | goto out_rel_entry; |
| 356 | } |
| 357 | trigger_entry = (struct acpi_whea_header *) |
| 358 | ((char *)trigger_tab + sizeof(struct acpi_einj_trigger)); |
| 359 | apei_resources_init(&trigger_resources); |
| 360 | apei_exec_ctx_init(&trigger_ctx, einj_ins_type, |
| 361 | ARRAY_SIZE(einj_ins_type), |
| 362 | trigger_entry, trigger_tab->entry_count); |
| 363 | rc = apei_exec_collect_resources(&trigger_ctx, &trigger_resources); |
| 364 | if (rc) |
| 365 | goto out_fini; |
| 366 | rc = apei_resources_sub(&trigger_resources, &einj_resources); |
| 367 | if (rc) |
| 368 | goto out_fini; |
Huang Ying | fdea163 | 2011-12-08 11:25:47 +0800 | [diff] [blame] | 369 | /* |
| 370 | * Some firmware will access target address specified in |
| 371 | * param1 to trigger the error when injecting memory error. |
| 372 | * This will cause resource conflict with regular memory. So |
| 373 | * remove it from trigger table resources. |
| 374 | */ |
Chen Gong | c5a1303 | 2013-06-06 15:20:51 -0700 | [diff] [blame] | 375 | if ((param_extension || acpi5) && (type & MEM_ERROR_MASK) && param2) { |
Huang Ying | fdea163 | 2011-12-08 11:25:47 +0800 | [diff] [blame] | 376 | struct apei_resources addr_resources; |
| 377 | apei_resources_init(&addr_resources); |
Xiao, Hui | b4e008d | 2011-12-08 11:25:48 +0800 | [diff] [blame] | 378 | trigger_param_region = einj_get_trigger_parameter_region( |
| 379 | trigger_tab, param1, param2); |
| 380 | if (trigger_param_region) { |
| 381 | rc = apei_resources_add(&addr_resources, |
| 382 | trigger_param_region->address, |
| 383 | trigger_param_region->bit_width/8, true); |
| 384 | if (rc) |
| 385 | goto out_fini; |
| 386 | rc = apei_resources_sub(&trigger_resources, |
| 387 | &addr_resources); |
| 388 | } |
Huang Ying | fdea163 | 2011-12-08 11:25:47 +0800 | [diff] [blame] | 389 | apei_resources_fini(&addr_resources); |
| 390 | if (rc) |
| 391 | goto out_fini; |
| 392 | } |
Huang Ying | e402134 | 2010-05-18 14:35:14 +0800 | [diff] [blame] | 393 | rc = apei_resources_request(&trigger_resources, "APEI EINJ Trigger"); |
| 394 | if (rc) |
| 395 | goto out_fini; |
| 396 | rc = apei_exec_pre_map_gars(&trigger_ctx); |
| 397 | if (rc) |
| 398 | goto out_release; |
| 399 | |
| 400 | rc = apei_exec_run(&trigger_ctx, ACPI_EINJ_TRIGGER_ERROR); |
| 401 | |
| 402 | apei_exec_post_unmap_gars(&trigger_ctx); |
| 403 | out_release: |
| 404 | apei_resources_release(&trigger_resources); |
| 405 | out_fini: |
| 406 | apei_resources_fini(&trigger_resources); |
| 407 | out_rel_entry: |
| 408 | release_mem_region(trigger_paddr + sizeof(*trigger_tab), |
| 409 | table_size - sizeof(*trigger_tab)); |
| 410 | out_rel_header: |
| 411 | release_mem_region(trigger_paddr, sizeof(*trigger_tab)); |
| 412 | out: |
| 413 | if (trigger_tab) |
| 414 | iounmap(trigger_tab); |
| 415 | |
| 416 | return rc; |
| 417 | } |
| 418 | |
Luck, Tony | 3482fb5 | 2013-11-06 13:30:36 -0800 | [diff] [blame^] | 419 | static int __einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2, |
| 420 | u64 param3, u64 param4) |
Huang Ying | e402134 | 2010-05-18 14:35:14 +0800 | [diff] [blame] | 421 | { |
| 422 | struct apei_exec_context ctx; |
| 423 | u64 val, trigger_paddr, timeout = FIRMWARE_TIMEOUT; |
| 424 | int rc; |
| 425 | |
| 426 | einj_exec_ctx_init(&ctx); |
| 427 | |
Huang Ying | 392913d | 2011-07-13 13:14:17 +0800 | [diff] [blame] | 428 | rc = apei_exec_run_optional(&ctx, ACPI_EINJ_BEGIN_OPERATION); |
Huang Ying | e402134 | 2010-05-18 14:35:14 +0800 | [diff] [blame] | 429 | if (rc) |
| 430 | return rc; |
| 431 | apei_exec_ctx_set_input(&ctx, type); |
Tony Luck | c130bd6 | 2012-01-17 12:10:16 -0800 | [diff] [blame] | 432 | if (acpi5) { |
| 433 | struct set_error_type_with_address *v5param = einj_param; |
| 434 | |
Luck, Tony | 459413d | 2012-01-23 15:27:56 -0800 | [diff] [blame] | 435 | v5param->type = type; |
Chen Gong | c5a1303 | 2013-06-06 15:20:51 -0700 | [diff] [blame] | 436 | if (type & ACPI5_VENDOR_BIT) { |
Tony Luck | c130bd6 | 2012-01-17 12:10:16 -0800 | [diff] [blame] | 437 | switch (vendor_flags) { |
| 438 | case SETWA_FLAGS_APICID: |
Luck, Tony | 459413d | 2012-01-23 15:27:56 -0800 | [diff] [blame] | 439 | v5param->apicid = param1; |
Tony Luck | c130bd6 | 2012-01-17 12:10:16 -0800 | [diff] [blame] | 440 | break; |
| 441 | case SETWA_FLAGS_MEM: |
Luck, Tony | 459413d | 2012-01-23 15:27:56 -0800 | [diff] [blame] | 442 | v5param->memory_address = param1; |
| 443 | v5param->memory_address_range = param2; |
Tony Luck | c130bd6 | 2012-01-17 12:10:16 -0800 | [diff] [blame] | 444 | break; |
| 445 | case SETWA_FLAGS_PCIE_SBDF: |
Luck, Tony | 459413d | 2012-01-23 15:27:56 -0800 | [diff] [blame] | 446 | v5param->pcie_sbdf = param1; |
Tony Luck | c130bd6 | 2012-01-17 12:10:16 -0800 | [diff] [blame] | 447 | break; |
| 448 | } |
Luck, Tony | 459413d | 2012-01-23 15:27:56 -0800 | [diff] [blame] | 449 | v5param->flags = vendor_flags; |
Luck, Tony | 3482fb5 | 2013-11-06 13:30:36 -0800 | [diff] [blame^] | 450 | } else if (flags) { |
| 451 | v5param->flags = flags; |
| 452 | v5param->memory_address = param1; |
| 453 | v5param->memory_address_range = param2; |
| 454 | v5param->apicid = param3; |
| 455 | v5param->pcie_sbdf = param4; |
Tony Luck | c130bd6 | 2012-01-17 12:10:16 -0800 | [diff] [blame] | 456 | } else { |
| 457 | switch (type) { |
| 458 | case ACPI_EINJ_PROCESSOR_CORRECTABLE: |
| 459 | case ACPI_EINJ_PROCESSOR_UNCORRECTABLE: |
| 460 | case ACPI_EINJ_PROCESSOR_FATAL: |
Luck, Tony | 459413d | 2012-01-23 15:27:56 -0800 | [diff] [blame] | 461 | v5param->apicid = param1; |
| 462 | v5param->flags = SETWA_FLAGS_APICID; |
Tony Luck | c130bd6 | 2012-01-17 12:10:16 -0800 | [diff] [blame] | 463 | break; |
| 464 | case ACPI_EINJ_MEMORY_CORRECTABLE: |
| 465 | case ACPI_EINJ_MEMORY_UNCORRECTABLE: |
| 466 | case ACPI_EINJ_MEMORY_FATAL: |
Luck, Tony | 459413d | 2012-01-23 15:27:56 -0800 | [diff] [blame] | 467 | v5param->memory_address = param1; |
| 468 | v5param->memory_address_range = param2; |
| 469 | v5param->flags = SETWA_FLAGS_MEM; |
Tony Luck | c130bd6 | 2012-01-17 12:10:16 -0800 | [diff] [blame] | 470 | break; |
| 471 | case ACPI_EINJ_PCIX_CORRECTABLE: |
| 472 | case ACPI_EINJ_PCIX_UNCORRECTABLE: |
| 473 | case ACPI_EINJ_PCIX_FATAL: |
Luck, Tony | 459413d | 2012-01-23 15:27:56 -0800 | [diff] [blame] | 474 | v5param->pcie_sbdf = param1; |
| 475 | v5param->flags = SETWA_FLAGS_PCIE_SBDF; |
Tony Luck | c130bd6 | 2012-01-17 12:10:16 -0800 | [diff] [blame] | 476 | break; |
| 477 | } |
| 478 | } |
| 479 | } else { |
| 480 | rc = apei_exec_run(&ctx, ACPI_EINJ_SET_ERROR_TYPE); |
| 481 | if (rc) |
| 482 | return rc; |
| 483 | if (einj_param) { |
| 484 | struct einj_parameter *v4param = einj_param; |
Luck, Tony | 459413d | 2012-01-23 15:27:56 -0800 | [diff] [blame] | 485 | v4param->param1 = param1; |
| 486 | v4param->param2 = param2; |
Tony Luck | c130bd6 | 2012-01-17 12:10:16 -0800 | [diff] [blame] | 487 | } |
Huang Ying | 6e320ec | 2010-05-18 14:35:24 +0800 | [diff] [blame] | 488 | } |
Huang Ying | e402134 | 2010-05-18 14:35:14 +0800 | [diff] [blame] | 489 | rc = apei_exec_run(&ctx, ACPI_EINJ_EXECUTE_OPERATION); |
| 490 | if (rc) |
| 491 | return rc; |
| 492 | for (;;) { |
| 493 | rc = apei_exec_run(&ctx, ACPI_EINJ_CHECK_BUSY_STATUS); |
| 494 | if (rc) |
| 495 | return rc; |
| 496 | val = apei_exec_ctx_get_output(&ctx); |
| 497 | if (!(val & EINJ_OP_BUSY)) |
| 498 | break; |
| 499 | if (einj_timedout(&timeout)) |
| 500 | return -EIO; |
| 501 | } |
| 502 | rc = apei_exec_run(&ctx, ACPI_EINJ_GET_COMMAND_STATUS); |
| 503 | if (rc) |
| 504 | return rc; |
| 505 | val = apei_exec_ctx_get_output(&ctx); |
| 506 | if (val != EINJ_STATUS_SUCCESS) |
| 507 | return -EBUSY; |
| 508 | |
| 509 | rc = apei_exec_run(&ctx, ACPI_EINJ_GET_TRIGGER_TABLE); |
| 510 | if (rc) |
| 511 | return rc; |
| 512 | trigger_paddr = apei_exec_ctx_get_output(&ctx); |
Chen Gong | ee49089 | 2012-03-15 16:53:36 +0800 | [diff] [blame] | 513 | if (notrigger == 0) { |
| 514 | rc = __einj_error_trigger(trigger_paddr, type, param1, param2); |
| 515 | if (rc) |
| 516 | return rc; |
| 517 | } |
Huang Ying | 392913d | 2011-07-13 13:14:17 +0800 | [diff] [blame] | 518 | rc = apei_exec_run_optional(&ctx, ACPI_EINJ_END_OPERATION); |
Huang Ying | e402134 | 2010-05-18 14:35:14 +0800 | [diff] [blame] | 519 | |
| 520 | return rc; |
| 521 | } |
| 522 | |
| 523 | /* Inject the specified hardware error */ |
Luck, Tony | 3482fb5 | 2013-11-06 13:30:36 -0800 | [diff] [blame^] | 524 | static int einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2, |
| 525 | u64 param3, u64 param4) |
Huang Ying | e402134 | 2010-05-18 14:35:14 +0800 | [diff] [blame] | 526 | { |
| 527 | int rc; |
Chen Gong | c5a1303 | 2013-06-06 15:20:51 -0700 | [diff] [blame] | 528 | unsigned long pfn; |
Huang Ying | e402134 | 2010-05-18 14:35:14 +0800 | [diff] [blame] | 529 | |
Luck, Tony | 3482fb5 | 2013-11-06 13:30:36 -0800 | [diff] [blame^] | 530 | /* If user manually set "flags", make sure it is legal */ |
| 531 | if (flags && (flags & |
| 532 | ~(SETWA_FLAGS_APICID|SETWA_FLAGS_MEM|SETWA_FLAGS_PCIE_SBDF))) |
| 533 | return -EINVAL; |
| 534 | |
Chen Gong | c5a1303 | 2013-06-06 15:20:51 -0700 | [diff] [blame] | 535 | /* |
| 536 | * We need extra sanity checks for memory errors. |
| 537 | * Other types leap directly to injection. |
| 538 | */ |
| 539 | |
| 540 | /* ensure param1/param2 existed */ |
| 541 | if (!(param_extension || acpi5)) |
| 542 | goto inject; |
| 543 | |
| 544 | /* ensure injection is memory related */ |
| 545 | if (type & ACPI5_VENDOR_BIT) { |
| 546 | if (vendor_flags != SETWA_FLAGS_MEM) |
| 547 | goto inject; |
Luck, Tony | 3482fb5 | 2013-11-06 13:30:36 -0800 | [diff] [blame^] | 548 | } else if (!(type & MEM_ERROR_MASK) && !(flags & SETWA_FLAGS_MEM)) |
Chen Gong | c5a1303 | 2013-06-06 15:20:51 -0700 | [diff] [blame] | 549 | goto inject; |
| 550 | |
| 551 | /* |
| 552 | * Disallow crazy address masks that give BIOS leeway to pick |
| 553 | * injection address almost anywhere. Insist on page or |
| 554 | * better granularity and that target address is normal RAM. |
| 555 | */ |
| 556 | pfn = PFN_DOWN(param1 & param2); |
| 557 | if (!page_is_ram(pfn) || ((param2 & PAGE_MASK) != PAGE_MASK)) |
| 558 | return -EINVAL; |
| 559 | |
| 560 | inject: |
Huang Ying | e402134 | 2010-05-18 14:35:14 +0800 | [diff] [blame] | 561 | mutex_lock(&einj_mutex); |
Luck, Tony | 3482fb5 | 2013-11-06 13:30:36 -0800 | [diff] [blame^] | 562 | rc = __einj_error_inject(type, flags, param1, param2, param3, param4); |
Huang Ying | e402134 | 2010-05-18 14:35:14 +0800 | [diff] [blame] | 563 | mutex_unlock(&einj_mutex); |
| 564 | |
| 565 | return rc; |
| 566 | } |
| 567 | |
| 568 | static u32 error_type; |
Luck, Tony | 3482fb5 | 2013-11-06 13:30:36 -0800 | [diff] [blame^] | 569 | static u32 error_flags; |
Huang Ying | 6e320ec | 2010-05-18 14:35:24 +0800 | [diff] [blame] | 570 | static u64 error_param1; |
| 571 | static u64 error_param2; |
Luck, Tony | 3482fb5 | 2013-11-06 13:30:36 -0800 | [diff] [blame^] | 572 | static u64 error_param3; |
| 573 | static u64 error_param4; |
Huang Ying | e402134 | 2010-05-18 14:35:14 +0800 | [diff] [blame] | 574 | static struct dentry *einj_debug_dir; |
| 575 | |
| 576 | static int available_error_type_show(struct seq_file *m, void *v) |
| 577 | { |
| 578 | int rc; |
| 579 | u32 available_error_type = 0; |
| 580 | |
| 581 | rc = einj_get_available_error_type(&available_error_type); |
| 582 | if (rc) |
| 583 | return rc; |
| 584 | if (available_error_type & 0x0001) |
| 585 | seq_printf(m, "0x00000001\tProcessor Correctable\n"); |
| 586 | if (available_error_type & 0x0002) |
| 587 | seq_printf(m, "0x00000002\tProcessor Uncorrectable non-fatal\n"); |
| 588 | if (available_error_type & 0x0004) |
| 589 | seq_printf(m, "0x00000004\tProcessor Uncorrectable fatal\n"); |
| 590 | if (available_error_type & 0x0008) |
| 591 | seq_printf(m, "0x00000008\tMemory Correctable\n"); |
| 592 | if (available_error_type & 0x0010) |
| 593 | seq_printf(m, "0x00000010\tMemory Uncorrectable non-fatal\n"); |
| 594 | if (available_error_type & 0x0020) |
| 595 | seq_printf(m, "0x00000020\tMemory Uncorrectable fatal\n"); |
| 596 | if (available_error_type & 0x0040) |
| 597 | seq_printf(m, "0x00000040\tPCI Express Correctable\n"); |
| 598 | if (available_error_type & 0x0080) |
| 599 | seq_printf(m, "0x00000080\tPCI Express Uncorrectable non-fatal\n"); |
| 600 | if (available_error_type & 0x0100) |
| 601 | seq_printf(m, "0x00000100\tPCI Express Uncorrectable fatal\n"); |
| 602 | if (available_error_type & 0x0200) |
| 603 | seq_printf(m, "0x00000200\tPlatform Correctable\n"); |
| 604 | if (available_error_type & 0x0400) |
| 605 | seq_printf(m, "0x00000400\tPlatform Uncorrectable non-fatal\n"); |
| 606 | if (available_error_type & 0x0800) |
| 607 | seq_printf(m, "0x00000800\tPlatform Uncorrectable fatal\n"); |
| 608 | |
| 609 | return 0; |
| 610 | } |
| 611 | |
| 612 | static int available_error_type_open(struct inode *inode, struct file *file) |
| 613 | { |
| 614 | return single_open(file, available_error_type_show, NULL); |
| 615 | } |
| 616 | |
| 617 | static const struct file_operations available_error_type_fops = { |
| 618 | .open = available_error_type_open, |
| 619 | .read = seq_read, |
| 620 | .llseek = seq_lseek, |
| 621 | .release = single_release, |
| 622 | }; |
| 623 | |
| 624 | static int error_type_get(void *data, u64 *val) |
| 625 | { |
| 626 | *val = error_type; |
| 627 | |
| 628 | return 0; |
| 629 | } |
| 630 | |
| 631 | static int error_type_set(void *data, u64 val) |
| 632 | { |
| 633 | int rc; |
| 634 | u32 available_error_type = 0; |
Tony Luck | c130bd6 | 2012-01-17 12:10:16 -0800 | [diff] [blame] | 635 | u32 tval, vendor; |
| 636 | |
| 637 | /* |
| 638 | * Vendor defined types have 0x80000000 bit set, and |
| 639 | * are not enumerated by ACPI_EINJ_GET_ERROR_TYPE |
| 640 | */ |
Chen Gong | c5a1303 | 2013-06-06 15:20:51 -0700 | [diff] [blame] | 641 | vendor = val & ACPI5_VENDOR_BIT; |
Tony Luck | c130bd6 | 2012-01-17 12:10:16 -0800 | [diff] [blame] | 642 | tval = val & 0x7fffffff; |
Huang Ying | e402134 | 2010-05-18 14:35:14 +0800 | [diff] [blame] | 643 | |
| 644 | /* Only one error type can be specified */ |
Tony Luck | c130bd6 | 2012-01-17 12:10:16 -0800 | [diff] [blame] | 645 | if (tval & (tval - 1)) |
Huang Ying | e402134 | 2010-05-18 14:35:14 +0800 | [diff] [blame] | 646 | return -EINVAL; |
Tony Luck | c130bd6 | 2012-01-17 12:10:16 -0800 | [diff] [blame] | 647 | if (!vendor) { |
| 648 | rc = einj_get_available_error_type(&available_error_type); |
| 649 | if (rc) |
| 650 | return rc; |
| 651 | if (!(val & available_error_type)) |
| 652 | return -EINVAL; |
| 653 | } |
Huang Ying | e402134 | 2010-05-18 14:35:14 +0800 | [diff] [blame] | 654 | error_type = val; |
| 655 | |
| 656 | return 0; |
| 657 | } |
| 658 | |
| 659 | DEFINE_SIMPLE_ATTRIBUTE(error_type_fops, error_type_get, |
| 660 | error_type_set, "0x%llx\n"); |
| 661 | |
| 662 | static int error_inject_set(void *data, u64 val) |
| 663 | { |
| 664 | if (!error_type) |
| 665 | return -EINVAL; |
| 666 | |
Luck, Tony | 3482fb5 | 2013-11-06 13:30:36 -0800 | [diff] [blame^] | 667 | return einj_error_inject(error_type, error_flags, error_param1, error_param2, |
| 668 | error_param3, error_param4); |
Huang Ying | e402134 | 2010-05-18 14:35:14 +0800 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | DEFINE_SIMPLE_ATTRIBUTE(error_inject_fops, NULL, |
| 672 | error_inject_set, "%llu\n"); |
| 673 | |
| 674 | static int einj_check_table(struct acpi_table_einj *einj_tab) |
| 675 | { |
Huang Ying | 3a78f96 | 2010-09-29 19:53:51 +0800 | [diff] [blame] | 676 | if ((einj_tab->header_length != |
| 677 | (sizeof(struct acpi_table_einj) - sizeof(einj_tab->header))) |
| 678 | && (einj_tab->header_length != sizeof(struct acpi_table_einj))) |
Huang Ying | e402134 | 2010-05-18 14:35:14 +0800 | [diff] [blame] | 679 | return -EINVAL; |
| 680 | if (einj_tab->header.length < sizeof(struct acpi_table_einj)) |
| 681 | return -EINVAL; |
| 682 | if (einj_tab->entries != |
| 683 | (einj_tab->header.length - sizeof(struct acpi_table_einj)) / |
| 684 | sizeof(struct acpi_einj_entry)) |
| 685 | return -EINVAL; |
| 686 | |
| 687 | return 0; |
| 688 | } |
| 689 | |
| 690 | static int __init einj_init(void) |
| 691 | { |
| 692 | int rc; |
| 693 | acpi_status status; |
| 694 | struct dentry *fentry; |
| 695 | struct apei_exec_context ctx; |
| 696 | |
| 697 | if (acpi_disabled) |
| 698 | return -ENODEV; |
| 699 | |
| 700 | status = acpi_get_table(ACPI_SIG_EINJ, 0, |
| 701 | (struct acpi_table_header **)&einj_tab); |
Huang Ying | ad68615 | 2011-12-08 11:25:43 +0800 | [diff] [blame] | 702 | if (status == AE_NOT_FOUND) |
Huang Ying | e402134 | 2010-05-18 14:35:14 +0800 | [diff] [blame] | 703 | return -ENODEV; |
Huang Ying | ad68615 | 2011-12-08 11:25:43 +0800 | [diff] [blame] | 704 | else if (ACPI_FAILURE(status)) { |
Huang Ying | e402134 | 2010-05-18 14:35:14 +0800 | [diff] [blame] | 705 | const char *msg = acpi_format_exception(status); |
| 706 | pr_err(EINJ_PFX "Failed to get table, %s\n", msg); |
| 707 | return -EINVAL; |
| 708 | } |
| 709 | |
| 710 | rc = einj_check_table(einj_tab); |
| 711 | if (rc) { |
| 712 | pr_warning(FW_BUG EINJ_PFX "EINJ table is invalid\n"); |
| 713 | return -EINVAL; |
| 714 | } |
| 715 | |
| 716 | rc = -ENOMEM; |
| 717 | einj_debug_dir = debugfs_create_dir("einj", apei_get_debugfs_dir()); |
| 718 | if (!einj_debug_dir) |
| 719 | goto err_cleanup; |
| 720 | fentry = debugfs_create_file("available_error_type", S_IRUSR, |
| 721 | einj_debug_dir, NULL, |
| 722 | &available_error_type_fops); |
| 723 | if (!fentry) |
| 724 | goto err_cleanup; |
| 725 | fentry = debugfs_create_file("error_type", S_IRUSR | S_IWUSR, |
| 726 | einj_debug_dir, NULL, &error_type_fops); |
| 727 | if (!fentry) |
| 728 | goto err_cleanup; |
| 729 | fentry = debugfs_create_file("error_inject", S_IWUSR, |
| 730 | einj_debug_dir, NULL, &error_inject_fops); |
| 731 | if (!fentry) |
| 732 | goto err_cleanup; |
| 733 | |
| 734 | apei_resources_init(&einj_resources); |
| 735 | einj_exec_ctx_init(&ctx); |
| 736 | rc = apei_exec_collect_resources(&ctx, &einj_resources); |
| 737 | if (rc) |
| 738 | goto err_fini; |
| 739 | rc = apei_resources_request(&einj_resources, "APEI EINJ"); |
| 740 | if (rc) |
| 741 | goto err_fini; |
| 742 | rc = apei_exec_pre_map_gars(&ctx); |
| 743 | if (rc) |
| 744 | goto err_release; |
Tony Luck | c130bd6 | 2012-01-17 12:10:16 -0800 | [diff] [blame] | 745 | |
Wei Yongjun | b8edb64 | 2013-06-05 16:18:12 -0700 | [diff] [blame] | 746 | rc = -ENOMEM; |
Tony Luck | c130bd6 | 2012-01-17 12:10:16 -0800 | [diff] [blame] | 747 | einj_param = einj_get_parameter_address(); |
| 748 | if ((param_extension || acpi5) && einj_param) { |
Luck, Tony | 3482fb5 | 2013-11-06 13:30:36 -0800 | [diff] [blame^] | 749 | fentry = debugfs_create_x32("flags", S_IRUSR | S_IWUSR, |
| 750 | einj_debug_dir, &error_flags); |
| 751 | if (!fentry) |
| 752 | goto err_unmap; |
Tony Luck | c130bd6 | 2012-01-17 12:10:16 -0800 | [diff] [blame] | 753 | fentry = debugfs_create_x64("param1", S_IRUSR | S_IWUSR, |
| 754 | einj_debug_dir, &error_param1); |
| 755 | if (!fentry) |
| 756 | goto err_unmap; |
| 757 | fentry = debugfs_create_x64("param2", S_IRUSR | S_IWUSR, |
| 758 | einj_debug_dir, &error_param2); |
| 759 | if (!fentry) |
| 760 | goto err_unmap; |
Luck, Tony | 3482fb5 | 2013-11-06 13:30:36 -0800 | [diff] [blame^] | 761 | fentry = debugfs_create_x64("param3", S_IRUSR | S_IWUSR, |
| 762 | einj_debug_dir, &error_param3); |
| 763 | if (!fentry) |
| 764 | goto err_unmap; |
| 765 | fentry = debugfs_create_x64("param4", S_IRUSR | S_IWUSR, |
| 766 | einj_debug_dir, &error_param4); |
| 767 | if (!fentry) |
| 768 | goto err_unmap; |
Chen Gong | ee49089 | 2012-03-15 16:53:36 +0800 | [diff] [blame] | 769 | |
| 770 | fentry = debugfs_create_x32("notrigger", S_IRUSR | S_IWUSR, |
| 771 | einj_debug_dir, ¬rigger); |
| 772 | if (!fentry) |
| 773 | goto err_unmap; |
Tony Luck | c130bd6 | 2012-01-17 12:10:16 -0800 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | if (vendor_dev[0]) { |
| 777 | vendor_blob.data = vendor_dev; |
| 778 | vendor_blob.size = strlen(vendor_dev); |
| 779 | fentry = debugfs_create_blob("vendor", S_IRUSR, |
| 780 | einj_debug_dir, &vendor_blob); |
| 781 | if (!fentry) |
| 782 | goto err_unmap; |
| 783 | fentry = debugfs_create_x32("vendor_flags", S_IRUSR | S_IWUSR, |
| 784 | einj_debug_dir, &vendor_flags); |
| 785 | if (!fentry) |
| 786 | goto err_unmap; |
Huang Ying | 6e320ec | 2010-05-18 14:35:24 +0800 | [diff] [blame] | 787 | } |
Huang Ying | e402134 | 2010-05-18 14:35:14 +0800 | [diff] [blame] | 788 | |
| 789 | pr_info(EINJ_PFX "Error INJection is initialized.\n"); |
| 790 | |
| 791 | return 0; |
| 792 | |
Huang Ying | 6e320ec | 2010-05-18 14:35:24 +0800 | [diff] [blame] | 793 | err_unmap: |
Luck, Tony | 459413d | 2012-01-23 15:27:56 -0800 | [diff] [blame] | 794 | if (einj_param) { |
| 795 | acpi_size size = (acpi5) ? |
| 796 | sizeof(struct set_error_type_with_address) : |
| 797 | sizeof(struct einj_parameter); |
| 798 | |
| 799 | acpi_os_unmap_memory(einj_param, size); |
| 800 | } |
Huang Ying | 6e320ec | 2010-05-18 14:35:24 +0800 | [diff] [blame] | 801 | apei_exec_post_unmap_gars(&ctx); |
Huang Ying | e402134 | 2010-05-18 14:35:14 +0800 | [diff] [blame] | 802 | err_release: |
| 803 | apei_resources_release(&einj_resources); |
| 804 | err_fini: |
| 805 | apei_resources_fini(&einj_resources); |
| 806 | err_cleanup: |
| 807 | debugfs_remove_recursive(einj_debug_dir); |
| 808 | |
| 809 | return rc; |
| 810 | } |
| 811 | |
| 812 | static void __exit einj_exit(void) |
| 813 | { |
| 814 | struct apei_exec_context ctx; |
| 815 | |
Luck, Tony | 459413d | 2012-01-23 15:27:56 -0800 | [diff] [blame] | 816 | if (einj_param) { |
| 817 | acpi_size size = (acpi5) ? |
| 818 | sizeof(struct set_error_type_with_address) : |
| 819 | sizeof(struct einj_parameter); |
| 820 | |
| 821 | acpi_os_unmap_memory(einj_param, size); |
| 822 | } |
Huang Ying | e402134 | 2010-05-18 14:35:14 +0800 | [diff] [blame] | 823 | einj_exec_ctx_init(&ctx); |
| 824 | apei_exec_post_unmap_gars(&ctx); |
| 825 | apei_resources_release(&einj_resources); |
| 826 | apei_resources_fini(&einj_resources); |
| 827 | debugfs_remove_recursive(einj_debug_dir); |
| 828 | } |
| 829 | |
| 830 | module_init(einj_init); |
| 831 | module_exit(einj_exit); |
| 832 | |
| 833 | MODULE_AUTHOR("Huang Ying"); |
| 834 | MODULE_DESCRIPTION("APEI Error INJection support"); |
| 835 | MODULE_LICENSE("GPL"); |