27 #include <linux/kernel.h>
28 #include <linux/module.h>
39 #define EINJ_PFX "EINJ: "
43 #define FIRMWARE_TIMEOUT (1 * NSEC_PER_MSEC)
79 static u32 vendor_flags;
81 static char vendor_dev[64];
98 #define EINJ_OP_BUSY 0x1
99 #define EINJ_STATUS_SUCCESS 0x0
100 #define EINJ_STATUS_FAIL 0x1
101 #define EINJ_STATUS_INVAL 0x2
103 #define EINJ_TAB_ENTRY(tab) \
104 ((struct acpi_whea_header *)((char *)(tab) + \
105 sizeof(struct acpi_table_einj)))
107 static bool param_extension;
144 static void *einj_param;
152 static int __einj_get_available_error_type(
u32 *
type)
157 einj_exec_ctx_init(&ctx);
161 *type = apei_exec_ctx_get_output(&ctx);
167 static int einj_get_available_error_type(
u32 *type)
172 rc = __einj_get_available_error_type(type);
178 static int einj_timedout(
u64 *
t)
182 "Firmware does not respond in time\n");
191 static void check_vendor_extension(
u64 paddr,
204 sprintf(vendor_dev,
"%x:%x:%x.%x vendor_id=%x device_id=%x rev_id=%x\n",
205 sbdf >> 24, (sbdf >> 16) & 0xff,
206 (sbdf >> 11) & 0x1f, (sbdf >> 8) & 0x7,
211 static void *einj_get_parameter_address(
void)
214 u64 paddrv4 = 0, paddrv5 = 0;
218 for (i = 0; i < einj_tab->
entries; i++) {
239 check_vendor_extension(paddrv5, v5param);
243 if (param_extension && paddrv4) {
296 static int __einj_error_trigger(
u64 trigger_paddr,
u32 type,
309 "APEI EINJ Trigger Table");
312 "Can not request [mem %#010llx-%#010llx] for Trigger table\n",
313 (
unsigned long long)trigger_paddr,
314 (
unsigned long long)trigger_paddr +
315 sizeof(*trigger_tab) - 1);
318 trigger_tab =
ioremap_cache(trigger_paddr,
sizeof(*trigger_tab));
323 rc = einj_check_trigger_header(trigger_tab);
326 "The trigger error action table is invalid\n");
337 table_size -
sizeof(*trigger_tab),
338 "APEI EINJ Trigger Table");
341 "Can not request [mem %#010llx-%#010llx] for Trigger Table Entry\n",
342 (
unsigned long long)trigger_paddr +
sizeof(*trigger_tab),
343 (
unsigned long long)trigger_paddr + table_size - 1);
354 apei_resources_init(&trigger_resources);
370 if (param_extension && (type & 0x0038) && param2) {
372 apei_resources_init(&addr_resources);
373 trigger_param_region = einj_get_trigger_parameter_region(
374 trigger_tab, param1, param2);
375 if (trigger_param_region) {
378 trigger_param_region->
bit_width/8,
true);
404 table_size -
sizeof(*trigger_tab));
414 static int __einj_error_inject(
u32 type,
u64 param1,
u64 param2)
420 einj_exec_ctx_init(&ctx);
425 apei_exec_ctx_set_input(&ctx, type);
430 if (type & 0x80000000) {
431 switch (vendor_flags) {
443 v5param->
flags = vendor_flags;
484 val = apei_exec_ctx_get_output(&ctx);
487 if (einj_timedout(&timeout))
493 val = apei_exec_ctx_get_output(&ctx);
500 trigger_paddr = apei_exec_ctx_get_output(&ctx);
501 if (notrigger == 0) {
502 rc = __einj_error_trigger(trigger_paddr, type, param1, param2);
512 static int einj_error_inject(
u32 type,
u64 param1,
u64 param2)
517 rc = __einj_error_inject(type, param1, param2);
524 static u64 error_param1;
525 static u64 error_param2;
526 static struct dentry *einj_debug_dir;
528 static int available_error_type_show(
struct seq_file *
m,
void *v)
531 u32 available_error_type = 0;
533 rc = einj_get_available_error_type(&available_error_type);
536 if (available_error_type & 0x0001)
537 seq_printf(m,
"0x00000001\tProcessor Correctable\n");
538 if (available_error_type & 0x0002)
539 seq_printf(m,
"0x00000002\tProcessor Uncorrectable non-fatal\n");
540 if (available_error_type & 0x0004)
541 seq_printf(m,
"0x00000004\tProcessor Uncorrectable fatal\n");
542 if (available_error_type & 0x0008)
543 seq_printf(m,
"0x00000008\tMemory Correctable\n");
544 if (available_error_type & 0x0010)
545 seq_printf(m,
"0x00000010\tMemory Uncorrectable non-fatal\n");
546 if (available_error_type & 0x0020)
547 seq_printf(m,
"0x00000020\tMemory Uncorrectable fatal\n");
548 if (available_error_type & 0x0040)
549 seq_printf(m,
"0x00000040\tPCI Express Correctable\n");
550 if (available_error_type & 0x0080)
551 seq_printf(m,
"0x00000080\tPCI Express Uncorrectable non-fatal\n");
552 if (available_error_type & 0x0100)
553 seq_printf(m,
"0x00000100\tPCI Express Uncorrectable fatal\n");
554 if (available_error_type & 0x0200)
555 seq_printf(m,
"0x00000200\tPlatform Correctable\n");
556 if (available_error_type & 0x0400)
557 seq_printf(m,
"0x00000400\tPlatform Uncorrectable non-fatal\n");
558 if (available_error_type & 0x0800)
559 seq_printf(m,
"0x00000800\tPlatform Uncorrectable fatal\n");
570 .open = available_error_type_open,
576 static int error_type_get(
void *
data,
u64 *val)
583 static int error_type_set(
void *
data,
u64 val)
586 u32 available_error_type = 0;
593 vendor = val & 0x80000000;
594 tval = val & 0x7fffffff;
597 if (tval & (tval - 1))
600 rc = einj_get_available_error_type(&available_error_type);
603 if (!(val & available_error_type))
612 error_type_set,
"0x%llx\n");
614 static int error_inject_set(
void *data,
u64 val)
619 return einj_error_inject(error_type, error_param1, error_param2);
623 error_inject_set,
"%llu\n");
641 static int __init einj_init(
void)
661 rc = einj_check_table(einj_tab);
672 einj_debug_dir,
NULL,
673 &available_error_type_fops);
677 einj_debug_dir,
NULL, &error_type_fops);
681 einj_debug_dir,
NULL, &error_inject_fops);
685 apei_resources_init(&einj_resources);
686 einj_exec_ctx_init(&ctx);
697 einj_param = einj_get_parameter_address();
698 if ((param_extension || acpi5) && einj_param) {
700 einj_debug_dir, &error_param1);
704 einj_debug_dir, &error_param2);
709 einj_debug_dir, ¬rigger);
715 vendor_blob.data = vendor_dev;
716 vendor_blob.size =
strlen(vendor_dev);
718 einj_debug_dir, &vendor_blob);
722 einj_debug_dir, &vendor_flags);
733 acpi_size
size = (acpi5) ?
750 static void __exit einj_exit(
void)
755 acpi_size
size = (acpi5) ?
761 einj_exec_ctx_init(&ctx);