diff options
Diffstat (limited to 'drivers/acpi/apei')
-rw-r--r-- | drivers/acpi/apei/einj.c | 224 |
1 files changed, 188 insertions, 36 deletions
diff --git a/drivers/acpi/apei/einj.c b/drivers/acpi/apei/einj.c index 6e6512e68a2d..5b898d4dda99 100644 --- a/drivers/acpi/apei/einj.c +++ b/drivers/acpi/apei/einj.c | |||
@@ -43,6 +43,42 @@ | |||
43 | #define FIRMWARE_TIMEOUT (1 * NSEC_PER_MSEC) | 43 | #define FIRMWARE_TIMEOUT (1 * NSEC_PER_MSEC) |
44 | 44 | ||
45 | /* | 45 | /* |
46 | * ACPI version 5 provides a SET_ERROR_TYPE_WITH_ADDRESS action. | ||
47 | */ | ||
48 | static int acpi5; | ||
49 | |||
50 | struct set_error_type_with_address { | ||
51 | u32 type; | ||
52 | u32 vendor_extension; | ||
53 | u32 flags; | ||
54 | u32 apicid; | ||
55 | u64 memory_address; | ||
56 | u64 memory_address_range; | ||
57 | u32 pcie_sbdf; | ||
58 | }; | ||
59 | enum { | ||
60 | SETWA_FLAGS_APICID = 1, | ||
61 | SETWA_FLAGS_MEM = 2, | ||
62 | SETWA_FLAGS_PCIE_SBDF = 4, | ||
63 | }; | ||
64 | |||
65 | /* | ||
66 | * Vendor extensions for platform specific operations | ||
67 | */ | ||
68 | struct vendor_error_type_extension { | ||
69 | u32 length; | ||
70 | u32 pcie_sbdf; | ||
71 | u16 vendor_id; | ||
72 | u16 device_id; | ||
73 | u8 rev_id; | ||
74 | u8 reserved[3]; | ||
75 | }; | ||
76 | |||
77 | static u32 vendor_flags; | ||
78 | static struct debugfs_blob_wrapper vendor_blob; | ||
79 | static char vendor_dev[64]; | ||
80 | |||
81 | /* | ||
46 | * Some BIOSes allow parameters to the SET_ERROR_TYPE entries in the | 82 | * Some BIOSes allow parameters to the SET_ERROR_TYPE entries in the |
47 | * EINJ table through an unpublished extension. Use with caution as | 83 | * EINJ table through an unpublished extension. Use with caution as |
48 | * most will ignore the parameter and make their own choice of address | 84 | * most will ignore the parameter and make their own choice of address |
@@ -103,7 +139,14 @@ static struct apei_exec_ins_type einj_ins_type[] = { | |||
103 | */ | 139 | */ |
104 | static DEFINE_MUTEX(einj_mutex); | 140 | static DEFINE_MUTEX(einj_mutex); |
105 | 141 | ||
106 | static struct einj_parameter *einj_param; | 142 | static void *einj_param; |
143 | |||
144 | #ifndef readq | ||
145 | static inline __u64 readq(volatile void __iomem *addr) | ||
146 | { | ||
147 | return ((__u64)readl(addr+4) << 32) + readl(addr); | ||
148 | } | ||
149 | #endif | ||
107 | 150 | ||
108 | #ifndef writeq | 151 | #ifndef writeq |
109 | static inline void writeq(__u64 val, volatile void __iomem *addr) | 152 | static inline void writeq(__u64 val, volatile void __iomem *addr) |
@@ -158,10 +201,31 @@ static int einj_timedout(u64 *t) | |||
158 | return 0; | 201 | return 0; |
159 | } | 202 | } |
160 | 203 | ||
161 | static u64 einj_get_parameter_address(void) | 204 | static void check_vendor_extension(u64 paddr, |
205 | struct set_error_type_with_address *v5param) | ||
206 | { | ||
207 | int offset = readl(&v5param->vendor_extension); | ||
208 | struct vendor_error_type_extension *v; | ||
209 | u32 sbdf; | ||
210 | |||
211 | if (!offset) | ||
212 | return; | ||
213 | v = ioremap(paddr + offset, sizeof(*v)); | ||
214 | if (!v) | ||
215 | return; | ||
216 | sbdf = readl(&v->pcie_sbdf); | ||
217 | sprintf(vendor_dev, "%x:%x:%x.%x vendor_id=%x device_id=%x rev_id=%x\n", | ||
218 | sbdf >> 24, (sbdf >> 16) & 0xff, | ||
219 | (sbdf >> 11) & 0x1f, (sbdf >> 8) & 0x7, | ||
220 | readw(&v->vendor_id), readw(&v->device_id), | ||
221 | readb(&v->rev_id)); | ||
222 | iounmap(v); | ||
223 | } | ||
224 | |||
225 | static void *einj_get_parameter_address(void) | ||
162 | { | 226 | { |
163 | int i; | 227 | int i; |
164 | u64 paddr = 0; | 228 | u64 paddrv4 = 0, paddrv5 = 0; |
165 | struct acpi_whea_header *entry; | 229 | struct acpi_whea_header *entry; |
166 | 230 | ||
167 | entry = EINJ_TAB_ENTRY(einj_tab); | 231 | entry = EINJ_TAB_ENTRY(einj_tab); |
@@ -170,12 +234,40 @@ static u64 einj_get_parameter_address(void) | |||
170 | entry->instruction == ACPI_EINJ_WRITE_REGISTER && | 234 | entry->instruction == ACPI_EINJ_WRITE_REGISTER && |
171 | entry->register_region.space_id == | 235 | entry->register_region.space_id == |
172 | ACPI_ADR_SPACE_SYSTEM_MEMORY) | 236 | ACPI_ADR_SPACE_SYSTEM_MEMORY) |
173 | memcpy(&paddr, &entry->register_region.address, | 237 | memcpy(&paddrv4, &entry->register_region.address, |
174 | sizeof(paddr)); | 238 | sizeof(paddrv4)); |
239 | if (entry->action == ACPI_EINJ_SET_ERROR_TYPE_WITH_ADDRESS && | ||
240 | entry->instruction == ACPI_EINJ_WRITE_REGISTER && | ||
241 | entry->register_region.space_id == | ||
242 | ACPI_ADR_SPACE_SYSTEM_MEMORY) | ||
243 | memcpy(&paddrv5, &entry->register_region.address, | ||
244 | sizeof(paddrv5)); | ||
175 | entry++; | 245 | entry++; |
176 | } | 246 | } |
247 | if (paddrv5) { | ||
248 | struct set_error_type_with_address *v5param; | ||
249 | |||
250 | v5param = ioremap(paddrv5, sizeof(*v5param)); | ||
251 | if (v5param) { | ||
252 | acpi5 = 1; | ||
253 | check_vendor_extension(paddrv5, v5param); | ||
254 | return v5param; | ||
255 | } | ||
256 | } | ||
257 | if (paddrv4) { | ||
258 | struct einj_parameter *v4param; | ||
259 | |||
260 | v4param = ioremap(paddrv4, sizeof(*v4param)); | ||
261 | if (!v4param) | ||
262 | return 0; | ||
263 | if (readq(&v4param->reserved1) || readq(&v4param->reserved2)) { | ||
264 | iounmap(v4param); | ||
265 | return 0; | ||
266 | } | ||
267 | return v4param; | ||
268 | } | ||
177 | 269 | ||
178 | return paddr; | 270 | return 0; |
179 | } | 271 | } |
180 | 272 | ||
181 | /* do sanity check to trigger table */ | 273 | /* do sanity check to trigger table */ |
@@ -340,12 +432,56 @@ static int __einj_error_inject(u32 type, u64 param1, u64 param2) | |||
340 | if (rc) | 432 | if (rc) |
341 | return rc; | 433 | return rc; |
342 | apei_exec_ctx_set_input(&ctx, type); | 434 | apei_exec_ctx_set_input(&ctx, type); |
343 | rc = apei_exec_run(&ctx, ACPI_EINJ_SET_ERROR_TYPE); | 435 | if (acpi5) { |
344 | if (rc) | 436 | struct set_error_type_with_address *v5param = einj_param; |
345 | return rc; | 437 | |
346 | if (einj_param) { | 438 | writel(type, &v5param->type); |
347 | writeq(param1, &einj_param->param1); | 439 | if (type & 0x80000000) { |
348 | writeq(param2, &einj_param->param2); | 440 | switch (vendor_flags) { |
441 | case SETWA_FLAGS_APICID: | ||
442 | writel(param1, &v5param->apicid); | ||
443 | break; | ||
444 | case SETWA_FLAGS_MEM: | ||
445 | writeq(param1, &v5param->memory_address); | ||
446 | writeq(param2, &v5param->memory_address_range); | ||
447 | break; | ||
448 | case SETWA_FLAGS_PCIE_SBDF: | ||
449 | writel(param1, &v5param->pcie_sbdf); | ||
450 | break; | ||
451 | } | ||
452 | writel(vendor_flags, &v5param->flags); | ||
453 | } else { | ||
454 | switch (type) { | ||
455 | case ACPI_EINJ_PROCESSOR_CORRECTABLE: | ||
456 | case ACPI_EINJ_PROCESSOR_UNCORRECTABLE: | ||
457 | case ACPI_EINJ_PROCESSOR_FATAL: | ||
458 | writel(param1, &v5param->apicid); | ||
459 | writel(SETWA_FLAGS_APICID, &v5param->flags); | ||
460 | break; | ||
461 | case ACPI_EINJ_MEMORY_CORRECTABLE: | ||
462 | case ACPI_EINJ_MEMORY_UNCORRECTABLE: | ||
463 | case ACPI_EINJ_MEMORY_FATAL: | ||
464 | writeq(param1, &v5param->memory_address); | ||
465 | writeq(param2, &v5param->memory_address_range); | ||
466 | writel(SETWA_FLAGS_MEM, &v5param->flags); | ||
467 | break; | ||
468 | case ACPI_EINJ_PCIX_CORRECTABLE: | ||
469 | case ACPI_EINJ_PCIX_UNCORRECTABLE: | ||
470 | case ACPI_EINJ_PCIX_FATAL: | ||
471 | writel(param1, &v5param->pcie_sbdf); | ||
472 | writel(SETWA_FLAGS_PCIE_SBDF, &v5param->flags); | ||
473 | break; | ||
474 | } | ||
475 | } | ||
476 | } else { | ||
477 | rc = apei_exec_run(&ctx, ACPI_EINJ_SET_ERROR_TYPE); | ||
478 | if (rc) | ||
479 | return rc; | ||
480 | if (einj_param) { | ||
481 | struct einj_parameter *v4param = einj_param; | ||
482 | writeq(param1, &v4param->param1); | ||
483 | writeq(param2, &v4param->param2); | ||
484 | } | ||
349 | } | 485 | } |
350 | rc = apei_exec_run(&ctx, ACPI_EINJ_EXECUTE_OPERATION); | 486 | rc = apei_exec_run(&ctx, ACPI_EINJ_EXECUTE_OPERATION); |
351 | if (rc) | 487 | if (rc) |
@@ -455,15 +591,25 @@ static int error_type_set(void *data, u64 val) | |||
455 | { | 591 | { |
456 | int rc; | 592 | int rc; |
457 | u32 available_error_type = 0; | 593 | u32 available_error_type = 0; |
594 | u32 tval, vendor; | ||
595 | |||
596 | /* | ||
597 | * Vendor defined types have 0x80000000 bit set, and | ||
598 | * are not enumerated by ACPI_EINJ_GET_ERROR_TYPE | ||
599 | */ | ||
600 | vendor = val & 0x80000000; | ||
601 | tval = val & 0x7fffffff; | ||
458 | 602 | ||
459 | /* Only one error type can be specified */ | 603 | /* Only one error type can be specified */ |
460 | if (val & (val - 1)) | 604 | if (tval & (tval - 1)) |
461 | return -EINVAL; | ||
462 | rc = einj_get_available_error_type(&available_error_type); | ||
463 | if (rc) | ||
464 | return rc; | ||
465 | if (!(val & available_error_type)) | ||
466 | return -EINVAL; | 605 | return -EINVAL; |
606 | if (!vendor) { | ||
607 | rc = einj_get_available_error_type(&available_error_type); | ||
608 | if (rc) | ||
609 | return rc; | ||
610 | if (!(val & available_error_type)) | ||
611 | return -EINVAL; | ||
612 | } | ||
467 | error_type = val; | 613 | error_type = val; |
468 | 614 | ||
469 | return 0; | 615 | return 0; |
@@ -502,7 +648,6 @@ static int einj_check_table(struct acpi_table_einj *einj_tab) | |||
502 | static int __init einj_init(void) | 648 | static int __init einj_init(void) |
503 | { | 649 | { |
504 | int rc; | 650 | int rc; |
505 | u64 param_paddr; | ||
506 | acpi_status status; | 651 | acpi_status status; |
507 | struct dentry *fentry; | 652 | struct dentry *fentry; |
508 | struct apei_exec_context ctx; | 653 | struct apei_exec_context ctx; |
@@ -555,23 +700,30 @@ static int __init einj_init(void) | |||
555 | rc = apei_exec_pre_map_gars(&ctx); | 700 | rc = apei_exec_pre_map_gars(&ctx); |
556 | if (rc) | 701 | if (rc) |
557 | goto err_release; | 702 | goto err_release; |
558 | if (param_extension) { | 703 | |
559 | param_paddr = einj_get_parameter_address(); | 704 | einj_param = einj_get_parameter_address(); |
560 | if (param_paddr) { | 705 | if ((param_extension || acpi5) && einj_param) { |
561 | einj_param = ioremap(param_paddr, sizeof(*einj_param)); | 706 | fentry = debugfs_create_x64("param1", S_IRUSR | S_IWUSR, |
562 | rc = -ENOMEM; | 707 | einj_debug_dir, &error_param1); |
563 | if (!einj_param) | 708 | if (!fentry) |
564 | goto err_unmap; | 709 | goto err_unmap; |
565 | fentry = debugfs_create_x64("param1", S_IRUSR | S_IWUSR, | 710 | fentry = debugfs_create_x64("param2", S_IRUSR | S_IWUSR, |
566 | einj_debug_dir, &error_param1); | 711 | einj_debug_dir, &error_param2); |
567 | if (!fentry) | 712 | if (!fentry) |
568 | goto err_unmap; | 713 | goto err_unmap; |
569 | fentry = debugfs_create_x64("param2", S_IRUSR | S_IWUSR, | 714 | } |
570 | einj_debug_dir, &error_param2); | 715 | |
571 | if (!fentry) | 716 | if (vendor_dev[0]) { |
572 | goto err_unmap; | 717 | vendor_blob.data = vendor_dev; |
573 | } else | 718 | vendor_blob.size = strlen(vendor_dev); |
574 | pr_warn(EINJ_PFX "Parameter extension is not supported.\n"); | 719 | fentry = debugfs_create_blob("vendor", S_IRUSR, |
720 | einj_debug_dir, &vendor_blob); | ||
721 | if (!fentry) | ||
722 | goto err_unmap; | ||
723 | fentry = debugfs_create_x32("vendor_flags", S_IRUSR | S_IWUSR, | ||
724 | einj_debug_dir, &vendor_flags); | ||
725 | if (!fentry) | ||
726 | goto err_unmap; | ||
575 | } | 727 | } |
576 | 728 | ||
577 | pr_info(EINJ_PFX "Error INJection is initialized.\n"); | 729 | pr_info(EINJ_PFX "Error INJection is initialized.\n"); |