1 // SPDX-License-Identifier: GPL-2.0-only
3 * APEI Error INJection support
5 * EINJ provides a hardware error injection mechanism, this is useful
6 * for debugging and testing of other APEI and RAS features.
8 * For more information about EINJ, please refer to ACPI Specification
9 * version 4.0, section 17.5.
11 * Copyright 2009-2010 Intel Corp.
12 * Author: Huang Ying <ying.huang@intel.com>
15 #include <linux/kernel.h>
16 #include <linux/module.h>
17 #include <linux/init.h>
19 #include <linux/debugfs.h>
20 #include <linux/seq_file.h>
21 #include <linux/nmi.h>
22 #include <linux/delay.h>
24 #include <linux/platform_device.h>
25 #include <linux/unaligned.h>
27 #include "apei-internal.h"
30 #define pr_fmt(fmt) "EINJ: " fmt
32 #define SLEEP_UNIT_MIN 1000 /* 1ms */
33 #define SLEEP_UNIT_MAX 5000 /* 5ms */
34 /* Firmware should respond within 1 seconds */
35 #define FIRMWARE_TIMEOUT (1 * USEC_PER_SEC)
36 #define ACPI5_VENDOR_BIT BIT(31)
37 #define MEM_ERROR_MASK (ACPI_EINJ_MEMORY_CORRECTABLE | \
38 ACPI_EINJ_MEMORY_UNCORRECTABLE | \
39 ACPI_EINJ_MEMORY_FATAL)
40 #define CXL_ERROR_MASK (ACPI_EINJ_CXL_CACHE_CORRECTABLE | \
41 ACPI_EINJ_CXL_CACHE_UNCORRECTABLE | \
42 ACPI_EINJ_CXL_CACHE_FATAL | \
43 ACPI_EINJ_CXL_MEM_CORRECTABLE | \
44 ACPI_EINJ_CXL_MEM_UNCORRECTABLE | \
45 ACPI_EINJ_CXL_MEM_FATAL)
48 * ACPI version 5 provides a SET_ERROR_TYPE_WITH_ADDRESS action.
52 struct set_error_type_with_address
{
58 u64 memory_address_range
;
62 SETWA_FLAGS_APICID
= 1,
64 SETWA_FLAGS_PCIE_SBDF
= 4,
68 * Vendor extensions for platform specific operations
70 struct vendor_error_type_extension
{
81 static u32 vendor_flags
;
82 static struct debugfs_blob_wrapper vendor_blob
;
83 static struct debugfs_blob_wrapper vendor_errors
;
84 static char vendor_dev
[64];
87 * Some BIOSes allow parameters to the SET_ERROR_TYPE entries in the
88 * EINJ table through an unpublished extension. Use with caution as
89 * most will ignore the parameter and make their own choice of address
90 * for error injection. This extension is used only if
91 * param_extension module parameter is specified.
93 struct einj_parameter
{
101 #define EINJ_OP_BUSY 0x1
102 #define EINJ_STATUS_SUCCESS 0x0
103 #define EINJ_STATUS_FAIL 0x1
104 #define EINJ_STATUS_INVAL 0x2
106 #define EINJ_TAB_ENTRY(tab) \
107 ((struct acpi_whea_header *)((char *)(tab) + \
108 sizeof(struct acpi_table_einj)))
110 static bool param_extension
;
111 module_param(param_extension
, bool, 0);
113 static struct acpi_table_einj
*einj_tab
;
115 static struct apei_resources einj_resources
;
117 static struct apei_exec_ins_type einj_ins_type
[] = {
118 [ACPI_EINJ_READ_REGISTER
] = {
119 .flags
= APEI_EXEC_INS_ACCESS_REGISTER
,
120 .run
= apei_exec_read_register
,
122 [ACPI_EINJ_READ_REGISTER_VALUE
] = {
123 .flags
= APEI_EXEC_INS_ACCESS_REGISTER
,
124 .run
= apei_exec_read_register_value
,
126 [ACPI_EINJ_WRITE_REGISTER
] = {
127 .flags
= APEI_EXEC_INS_ACCESS_REGISTER
,
128 .run
= apei_exec_write_register
,
130 [ACPI_EINJ_WRITE_REGISTER_VALUE
] = {
131 .flags
= APEI_EXEC_INS_ACCESS_REGISTER
,
132 .run
= apei_exec_write_register_value
,
136 .run
= apei_exec_noop
,
141 * Prevent EINJ interpreter to run simultaneously, because the
142 * corresponding firmware implementation may not work properly when
143 * invoked simultaneously.
145 static DEFINE_MUTEX(einj_mutex
);
148 * Exported APIs use this flag to exit early if einj_probe() failed.
150 bool einj_initialized __ro_after_init
;
152 static void *einj_param
;
154 static void einj_exec_ctx_init(struct apei_exec_context
*ctx
)
156 apei_exec_ctx_init(ctx
, einj_ins_type
, ARRAY_SIZE(einj_ins_type
),
157 EINJ_TAB_ENTRY(einj_tab
), einj_tab
->entries
);
160 static int __einj_get_available_error_type(u32
*type
)
162 struct apei_exec_context ctx
;
165 einj_exec_ctx_init(&ctx
);
166 rc
= apei_exec_run(&ctx
, ACPI_EINJ_GET_ERROR_TYPE
);
169 *type
= apei_exec_ctx_get_output(&ctx
);
174 /* Get error injection capabilities of the platform */
175 int einj_get_available_error_type(u32
*type
)
179 mutex_lock(&einj_mutex
);
180 rc
= __einj_get_available_error_type(type
);
181 mutex_unlock(&einj_mutex
);
186 static int einj_timedout(u64
*t
)
188 if ((s64
)*t
< SLEEP_UNIT_MIN
) {
189 pr_warn(FW_WARN
"Firmware does not respond in time\n");
192 *t
-= SLEEP_UNIT_MIN
;
193 usleep_range(SLEEP_UNIT_MIN
, SLEEP_UNIT_MAX
);
198 static void get_oem_vendor_struct(u64 paddr
, int offset
,
199 struct vendor_error_type_extension
*v
)
201 unsigned long vendor_size
;
202 u64 target_pa
= paddr
+ offset
+ sizeof(struct vendor_error_type_extension
);
204 vendor_size
= v
->length
- sizeof(struct vendor_error_type_extension
);
207 vendor_errors
.data
= acpi_os_map_memory(target_pa
, vendor_size
);
209 if (vendor_errors
.data
)
210 vendor_errors
.size
= vendor_size
;
213 static void check_vendor_extension(u64 paddr
,
214 struct set_error_type_with_address
*v5param
)
216 int offset
= v5param
->vendor_extension
;
217 struct vendor_error_type_extension
*v
;
222 v
= acpi_os_map_iomem(paddr
+ offset
, sizeof(*v
));
225 get_oem_vendor_struct(paddr
, offset
, v
);
227 sprintf(vendor_dev
, "%x:%x:%x.%x vendor_id=%x device_id=%x rev_id=%x\n",
228 sbdf
>> 24, (sbdf
>> 16) & 0xff,
229 (sbdf
>> 11) & 0x1f, (sbdf
>> 8) & 0x7,
230 v
->vendor_id
, v
->device_id
, v
->rev_id
);
231 acpi_os_unmap_iomem(v
, sizeof(*v
));
234 static void *einj_get_parameter_address(void)
237 u64 pa_v4
= 0, pa_v5
= 0;
238 struct acpi_whea_header
*entry
;
240 entry
= EINJ_TAB_ENTRY(einj_tab
);
241 for (i
= 0; i
< einj_tab
->entries
; i
++) {
242 if (entry
->action
== ACPI_EINJ_SET_ERROR_TYPE
&&
243 entry
->instruction
== ACPI_EINJ_WRITE_REGISTER
&&
244 entry
->register_region
.space_id
==
245 ACPI_ADR_SPACE_SYSTEM_MEMORY
)
246 pa_v4
= get_unaligned(&entry
->register_region
.address
);
247 if (entry
->action
== ACPI_EINJ_SET_ERROR_TYPE_WITH_ADDRESS
&&
248 entry
->instruction
== ACPI_EINJ_WRITE_REGISTER
&&
249 entry
->register_region
.space_id
==
250 ACPI_ADR_SPACE_SYSTEM_MEMORY
)
251 pa_v5
= get_unaligned(&entry
->register_region
.address
);
255 struct set_error_type_with_address
*v5param
;
257 v5param
= acpi_os_map_iomem(pa_v5
, sizeof(*v5param
));
260 check_vendor_extension(pa_v5
, v5param
);
264 if (param_extension
&& pa_v4
) {
265 struct einj_parameter
*v4param
;
267 v4param
= acpi_os_map_iomem(pa_v4
, sizeof(*v4param
));
270 if (v4param
->reserved1
|| v4param
->reserved2
) {
271 acpi_os_unmap_iomem(v4param
, sizeof(*v4param
));
280 /* do sanity check to trigger table */
281 static int einj_check_trigger_header(struct acpi_einj_trigger
*trigger_tab
)
283 if (trigger_tab
->header_size
!= sizeof(struct acpi_einj_trigger
))
285 if (trigger_tab
->table_size
> PAGE_SIZE
||
286 trigger_tab
->table_size
< trigger_tab
->header_size
)
288 if (trigger_tab
->entry_count
!=
289 (trigger_tab
->table_size
- trigger_tab
->header_size
) /
290 sizeof(struct acpi_einj_entry
))
296 static struct acpi_generic_address
*einj_get_trigger_parameter_region(
297 struct acpi_einj_trigger
*trigger_tab
, u64 param1
, u64 param2
)
300 struct acpi_whea_header
*entry
;
302 entry
= (struct acpi_whea_header
*)
303 ((char *)trigger_tab
+ sizeof(struct acpi_einj_trigger
));
304 for (i
= 0; i
< trigger_tab
->entry_count
; i
++) {
305 if (entry
->action
== ACPI_EINJ_TRIGGER_ERROR
&&
306 entry
->instruction
<= ACPI_EINJ_WRITE_REGISTER_VALUE
&&
307 entry
->register_region
.space_id
==
308 ACPI_ADR_SPACE_SYSTEM_MEMORY
&&
309 (entry
->register_region
.address
& param2
) == (param1
& param2
))
310 return &entry
->register_region
;
316 /* Execute instructions in trigger error action table */
317 static int __einj_error_trigger(u64 trigger_paddr
, u32 type
,
318 u64 param1
, u64 param2
)
320 struct acpi_einj_trigger
*trigger_tab
= NULL
;
321 struct apei_exec_context trigger_ctx
;
322 struct apei_resources trigger_resources
;
323 struct acpi_whea_header
*trigger_entry
;
327 struct acpi_generic_address
*trigger_param_region
= NULL
;
329 r
= request_mem_region(trigger_paddr
, sizeof(*trigger_tab
),
330 "APEI EINJ Trigger Table");
332 pr_err("Can not request [mem %#010llx-%#010llx] for Trigger table\n",
333 (unsigned long long)trigger_paddr
,
334 (unsigned long long)trigger_paddr
+
335 sizeof(*trigger_tab
) - 1);
338 trigger_tab
= ioremap_cache(trigger_paddr
, sizeof(*trigger_tab
));
340 pr_err("Failed to map trigger table!\n");
343 rc
= einj_check_trigger_header(trigger_tab
);
345 pr_warn(FW_BUG
"Invalid trigger error action table.\n");
349 /* No action structures in the TRIGGER_ERROR table, nothing to do */
350 if (!trigger_tab
->entry_count
)
354 table_size
= trigger_tab
->table_size
;
355 r
= request_mem_region(trigger_paddr
+ sizeof(*trigger_tab
),
356 table_size
- sizeof(*trigger_tab
),
357 "APEI EINJ Trigger Table");
359 pr_err("Can not request [mem %#010llx-%#010llx] for Trigger Table Entry\n",
360 (unsigned long long)trigger_paddr
+ sizeof(*trigger_tab
),
361 (unsigned long long)trigger_paddr
+ table_size
- 1);
364 iounmap(trigger_tab
);
365 trigger_tab
= ioremap_cache(trigger_paddr
, table_size
);
367 pr_err("Failed to map trigger table!\n");
370 trigger_entry
= (struct acpi_whea_header
*)
371 ((char *)trigger_tab
+ sizeof(struct acpi_einj_trigger
));
372 apei_resources_init(&trigger_resources
);
373 apei_exec_ctx_init(&trigger_ctx
, einj_ins_type
,
374 ARRAY_SIZE(einj_ins_type
),
375 trigger_entry
, trigger_tab
->entry_count
);
376 rc
= apei_exec_collect_resources(&trigger_ctx
, &trigger_resources
);
379 rc
= apei_resources_sub(&trigger_resources
, &einj_resources
);
383 * Some firmware will access target address specified in
384 * param1 to trigger the error when injecting memory error.
385 * This will cause resource conflict with regular memory. So
386 * remove it from trigger table resources.
388 if ((param_extension
|| acpi5
) && (type
& MEM_ERROR_MASK
) && param2
) {
389 struct apei_resources addr_resources
;
391 apei_resources_init(&addr_resources
);
392 trigger_param_region
= einj_get_trigger_parameter_region(
393 trigger_tab
, param1
, param2
);
394 if (trigger_param_region
) {
395 rc
= apei_resources_add(&addr_resources
,
396 trigger_param_region
->address
,
397 trigger_param_region
->bit_width
/8, true);
400 rc
= apei_resources_sub(&trigger_resources
,
403 apei_resources_fini(&addr_resources
);
407 rc
= apei_resources_request(&trigger_resources
, "APEI EINJ Trigger");
410 rc
= apei_exec_pre_map_gars(&trigger_ctx
);
414 rc
= apei_exec_run(&trigger_ctx
, ACPI_EINJ_TRIGGER_ERROR
);
416 apei_exec_post_unmap_gars(&trigger_ctx
);
418 apei_resources_release(&trigger_resources
);
420 apei_resources_fini(&trigger_resources
);
422 release_mem_region(trigger_paddr
+ sizeof(*trigger_tab
),
423 table_size
- sizeof(*trigger_tab
));
425 release_mem_region(trigger_paddr
, sizeof(*trigger_tab
));
428 iounmap(trigger_tab
);
433 static int __einj_error_inject(u32 type
, u32 flags
, u64 param1
, u64 param2
,
434 u64 param3
, u64 param4
)
436 struct apei_exec_context ctx
;
437 u64 val
, trigger_paddr
, timeout
= FIRMWARE_TIMEOUT
;
440 einj_exec_ctx_init(&ctx
);
442 rc
= apei_exec_run_optional(&ctx
, ACPI_EINJ_BEGIN_OPERATION
);
445 apei_exec_ctx_set_input(&ctx
, type
);
447 struct set_error_type_with_address
*v5param
= einj_param
;
449 v5param
->type
= type
;
450 if (type
& ACPI5_VENDOR_BIT
) {
451 switch (vendor_flags
) {
452 case SETWA_FLAGS_APICID
:
453 v5param
->apicid
= param1
;
455 case SETWA_FLAGS_MEM
:
456 v5param
->memory_address
= param1
;
457 v5param
->memory_address_range
= param2
;
459 case SETWA_FLAGS_PCIE_SBDF
:
460 v5param
->pcie_sbdf
= param1
;
463 v5param
->flags
= vendor_flags
;
465 v5param
->flags
= flags
;
466 v5param
->memory_address
= param1
;
467 v5param
->memory_address_range
= param2
;
468 v5param
->apicid
= param3
;
469 v5param
->pcie_sbdf
= param4
;
472 case ACPI_EINJ_PROCESSOR_CORRECTABLE
:
473 case ACPI_EINJ_PROCESSOR_UNCORRECTABLE
:
474 case ACPI_EINJ_PROCESSOR_FATAL
:
475 v5param
->apicid
= param1
;
476 v5param
->flags
= SETWA_FLAGS_APICID
;
478 case ACPI_EINJ_MEMORY_CORRECTABLE
:
479 case ACPI_EINJ_MEMORY_UNCORRECTABLE
:
480 case ACPI_EINJ_MEMORY_FATAL
:
481 v5param
->memory_address
= param1
;
482 v5param
->memory_address_range
= param2
;
483 v5param
->flags
= SETWA_FLAGS_MEM
;
485 case ACPI_EINJ_PCIX_CORRECTABLE
:
486 case ACPI_EINJ_PCIX_UNCORRECTABLE
:
487 case ACPI_EINJ_PCIX_FATAL
:
488 v5param
->pcie_sbdf
= param1
;
489 v5param
->flags
= SETWA_FLAGS_PCIE_SBDF
;
494 rc
= apei_exec_run(&ctx
, ACPI_EINJ_SET_ERROR_TYPE
);
498 struct einj_parameter
*v4param
= einj_param
;
500 v4param
->param1
= param1
;
501 v4param
->param2
= param2
;
504 rc
= apei_exec_run(&ctx
, ACPI_EINJ_EXECUTE_OPERATION
);
508 rc
= apei_exec_run(&ctx
, ACPI_EINJ_CHECK_BUSY_STATUS
);
511 val
= apei_exec_ctx_get_output(&ctx
);
512 if (!(val
& EINJ_OP_BUSY
))
514 if (einj_timedout(&timeout
))
517 rc
= apei_exec_run(&ctx
, ACPI_EINJ_GET_COMMAND_STATUS
);
520 val
= apei_exec_ctx_get_output(&ctx
);
521 if (val
== EINJ_STATUS_FAIL
)
523 else if (val
== EINJ_STATUS_INVAL
)
527 * The error is injected into the platform successfully, then it needs
528 * to trigger the error.
530 rc
= apei_exec_run(&ctx
, ACPI_EINJ_GET_TRIGGER_TABLE
);
533 trigger_paddr
= apei_exec_ctx_get_output(&ctx
);
534 if (notrigger
== 0) {
535 rc
= __einj_error_trigger(trigger_paddr
, type
, param1
, param2
);
539 rc
= apei_exec_run_optional(&ctx
, ACPI_EINJ_END_OPERATION
);
544 /* Inject the specified hardware error */
545 int einj_error_inject(u32 type
, u32 flags
, u64 param1
, u64 param2
, u64 param3
,
551 /* If user manually set "flags", make sure it is legal */
552 if (flags
&& (flags
&
553 ~(SETWA_FLAGS_APICID
|SETWA_FLAGS_MEM
|SETWA_FLAGS_PCIE_SBDF
)))
557 * We need extra sanity checks for memory errors.
558 * Other types leap directly to injection.
561 /* ensure param1/param2 existed */
562 if (!(param_extension
|| acpi5
))
565 /* ensure injection is memory related */
566 if (type
& ACPI5_VENDOR_BIT
) {
567 if (vendor_flags
!= SETWA_FLAGS_MEM
)
569 } else if (!(type
& MEM_ERROR_MASK
) && !(flags
& SETWA_FLAGS_MEM
)) {
574 * Injections targeting a CXL 1.0/1.1 port have to be injected
575 * via the einj_cxl_rch_error_inject() path as that does the proper
576 * validation of the given RCRB base (MMIO) address.
578 if (einj_is_cxl_error_type(type
) && (flags
& SETWA_FLAGS_MEM
))
582 * Disallow crazy address masks that give BIOS leeway to pick
583 * injection address almost anywhere. Insist on page or
584 * better granularity and that target address is normal RAM or
587 base_addr
= param1
& param2
;
590 if (((param2
& PAGE_MASK
) != PAGE_MASK
) ||
591 ((region_intersects(base_addr
, size
, IORESOURCE_SYSTEM_RAM
, IORES_DESC_NONE
)
592 != REGION_INTERSECTS
) &&
593 (region_intersects(base_addr
, size
, IORESOURCE_MEM
, IORES_DESC_PERSISTENT_MEMORY
)
594 != REGION_INTERSECTS
) &&
595 (region_intersects(base_addr
, size
, IORESOURCE_MEM
, IORES_DESC_SOFT_RESERVED
)
596 != REGION_INTERSECTS
) &&
597 !arch_is_platform_page(base_addr
)))
600 if (is_zero_pfn(base_addr
>> PAGE_SHIFT
))
604 mutex_lock(&einj_mutex
);
605 rc
= __einj_error_inject(type
, flags
, param1
, param2
, param3
, param4
);
606 mutex_unlock(&einj_mutex
);
611 int einj_cxl_rch_error_inject(u32 type
, u32 flags
, u64 param1
, u64 param2
,
612 u64 param3
, u64 param4
)
616 if (!(einj_is_cxl_error_type(type
) && (flags
& SETWA_FLAGS_MEM
)))
619 mutex_lock(&einj_mutex
);
620 rc
= __einj_error_inject(type
, flags
, param1
, param2
, param3
, param4
);
621 mutex_unlock(&einj_mutex
);
626 static u32 error_type
;
627 static u32 error_flags
;
628 static u64 error_param1
;
629 static u64 error_param2
;
630 static u64 error_param3
;
631 static u64 error_param4
;
632 static struct dentry
*einj_debug_dir
;
633 static struct { u32 mask
; const char *str
; } const einj_error_type_string
[] = {
634 { BIT(0), "Processor Correctable" },
635 { BIT(1), "Processor Uncorrectable non-fatal" },
636 { BIT(2), "Processor Uncorrectable fatal" },
637 { BIT(3), "Memory Correctable" },
638 { BIT(4), "Memory Uncorrectable non-fatal" },
639 { BIT(5), "Memory Uncorrectable fatal" },
640 { BIT(6), "PCI Express Correctable" },
641 { BIT(7), "PCI Express Uncorrectable non-fatal" },
642 { BIT(8), "PCI Express Uncorrectable fatal" },
643 { BIT(9), "Platform Correctable" },
644 { BIT(10), "Platform Uncorrectable non-fatal" },
645 { BIT(11), "Platform Uncorrectable fatal"},
646 { BIT(31), "Vendor Defined Error Types" },
649 static int available_error_type_show(struct seq_file
*m
, void *v
)
654 rc
= einj_get_available_error_type(&error_type
);
657 for (int pos
= 0; pos
< ARRAY_SIZE(einj_error_type_string
); pos
++)
658 if (error_type
& einj_error_type_string
[pos
].mask
)
659 seq_printf(m
, "0x%08x\t%s\n", einj_error_type_string
[pos
].mask
,
660 einj_error_type_string
[pos
].str
);
665 DEFINE_SHOW_ATTRIBUTE(available_error_type
);
667 static int error_type_get(void *data
, u64
*val
)
674 bool einj_is_cxl_error_type(u64 type
)
676 return (type
& CXL_ERROR_MASK
) && (!(type
& ACPI5_VENDOR_BIT
));
679 int einj_validate_error_type(u64 type
)
681 u32 tval
, vendor
, available_error_type
= 0;
684 /* Only low 32 bits for error type are valid */
685 if (type
& GENMASK_ULL(63, 32))
689 * Vendor defined types have 0x80000000 bit set, and
690 * are not enumerated by ACPI_EINJ_GET_ERROR_TYPE
692 vendor
= type
& ACPI5_VENDOR_BIT
;
693 tval
= type
& GENMASK(30, 0);
695 /* Only one error type can be specified */
696 if (tval
& (tval
- 1))
699 rc
= einj_get_available_error_type(&available_error_type
);
702 if (!(type
& available_error_type
))
709 static int error_type_set(void *data
, u64 val
)
713 rc
= einj_validate_error_type(val
);
722 DEFINE_DEBUGFS_ATTRIBUTE(error_type_fops
, error_type_get
, error_type_set
,
725 static int error_inject_set(void *data
, u64 val
)
730 return einj_error_inject(error_type
, error_flags
, error_param1
, error_param2
,
731 error_param3
, error_param4
);
734 DEFINE_DEBUGFS_ATTRIBUTE(error_inject_fops
, NULL
, error_inject_set
, "%llu\n");
736 static int einj_check_table(struct acpi_table_einj
*einj_tab
)
738 if ((einj_tab
->header_length
!=
739 (sizeof(struct acpi_table_einj
) - sizeof(einj_tab
->header
)))
740 && (einj_tab
->header_length
!= sizeof(struct acpi_table_einj
)))
742 if (einj_tab
->header
.length
< sizeof(struct acpi_table_einj
))
744 if (einj_tab
->entries
!=
745 (einj_tab
->header
.length
- sizeof(struct acpi_table_einj
)) /
746 sizeof(struct acpi_einj_entry
))
752 static int __init
einj_probe(struct platform_device
*pdev
)
756 struct apei_exec_context ctx
;
759 pr_debug("ACPI disabled.\n");
763 status
= acpi_get_table(ACPI_SIG_EINJ
, 0,
764 (struct acpi_table_header
**)&einj_tab
);
765 if (status
== AE_NOT_FOUND
) {
766 pr_debug("EINJ table not found.\n");
768 } else if (ACPI_FAILURE(status
)) {
769 pr_err("Failed to get EINJ table: %s\n",
770 acpi_format_exception(status
));
774 rc
= einj_check_table(einj_tab
);
776 pr_warn(FW_BUG
"Invalid EINJ table.\n");
781 einj_debug_dir
= debugfs_create_dir("einj", apei_get_debugfs_dir());
783 debugfs_create_file("available_error_type", S_IRUSR
, einj_debug_dir
,
784 NULL
, &available_error_type_fops
);
785 debugfs_create_file_unsafe("error_type", 0600, einj_debug_dir
,
786 NULL
, &error_type_fops
);
787 debugfs_create_file_unsafe("error_inject", 0200, einj_debug_dir
,
788 NULL
, &error_inject_fops
);
790 apei_resources_init(&einj_resources
);
791 einj_exec_ctx_init(&ctx
);
792 rc
= apei_exec_collect_resources(&ctx
, &einj_resources
);
794 pr_err("Error collecting EINJ resources.\n");
798 rc
= apei_resources_request(&einj_resources
, "APEI EINJ");
800 pr_err("Error requesting memory/port resources.\n");
804 rc
= apei_exec_pre_map_gars(&ctx
);
806 pr_err("Error pre-mapping GARs.\n");
810 einj_param
= einj_get_parameter_address();
811 if ((param_extension
|| acpi5
) && einj_param
) {
812 debugfs_create_x32("flags", S_IRUSR
| S_IWUSR
, einj_debug_dir
,
814 debugfs_create_x64("param1", S_IRUSR
| S_IWUSR
, einj_debug_dir
,
816 debugfs_create_x64("param2", S_IRUSR
| S_IWUSR
, einj_debug_dir
,
818 debugfs_create_x64("param3", S_IRUSR
| S_IWUSR
, einj_debug_dir
,
820 debugfs_create_x64("param4", S_IRUSR
| S_IWUSR
, einj_debug_dir
,
822 debugfs_create_x32("notrigger", S_IRUSR
| S_IWUSR
,
823 einj_debug_dir
, ¬rigger
);
827 vendor_blob
.data
= vendor_dev
;
828 vendor_blob
.size
= strlen(vendor_dev
);
829 debugfs_create_blob("vendor", S_IRUSR
, einj_debug_dir
,
831 debugfs_create_x32("vendor_flags", S_IRUSR
| S_IWUSR
,
832 einj_debug_dir
, &vendor_flags
);
835 if (vendor_errors
.size
)
836 debugfs_create_blob("oem_error", 0600, einj_debug_dir
,
839 pr_info("Error INJection is initialized.\n");
844 apei_resources_release(&einj_resources
);
846 apei_resources_fini(&einj_resources
);
847 debugfs_remove_recursive(einj_debug_dir
);
849 acpi_put_table((struct acpi_table_header
*)einj_tab
);
854 static void __exit
einj_remove(struct platform_device
*pdev
)
856 struct apei_exec_context ctx
;
859 acpi_size size
= (acpi5
) ?
860 sizeof(struct set_error_type_with_address
) :
861 sizeof(struct einj_parameter
);
863 acpi_os_unmap_iomem(einj_param
, size
);
864 if (vendor_errors
.size
)
865 acpi_os_unmap_memory(vendor_errors
.data
, vendor_errors
.size
);
867 einj_exec_ctx_init(&ctx
);
868 apei_exec_post_unmap_gars(&ctx
);
869 apei_resources_release(&einj_resources
);
870 apei_resources_fini(&einj_resources
);
871 debugfs_remove_recursive(einj_debug_dir
);
872 acpi_put_table((struct acpi_table_header
*)einj_tab
);
875 static struct platform_device
*einj_dev
;
877 * einj_remove() lives in .exit.text. For drivers registered via
878 * platform_driver_probe() this is ok because they cannot get unbound at
879 * runtime. So mark the driver struct with __refdata to prevent modpost
880 * triggering a section mismatch warning.
882 static struct platform_driver einj_driver __refdata
= {
883 .remove
= __exit_p(einj_remove
),
889 static int __init
einj_init(void)
891 struct platform_device_info einj_dev_info
= {
897 einj_dev
= platform_device_register_full(&einj_dev_info
);
898 if (IS_ERR(einj_dev
))
899 return PTR_ERR(einj_dev
);
901 rc
= platform_driver_probe(&einj_driver
, einj_probe
);
902 einj_initialized
= rc
== 0;
907 static void __exit
einj_exit(void)
909 if (einj_initialized
)
910 platform_driver_unregister(&einj_driver
);
912 platform_device_unregister(einj_dev
);
915 module_init(einj_init
);
916 module_exit(einj_exit
);
918 MODULE_AUTHOR("Huang Ying");
919 MODULE_DESCRIPTION("APEI Error INJection support");
920 MODULE_LICENSE("GPL");