acpi/apei/einj: Add extensions to EINJ from rev 5.0 of acpi spec
[deliverable/linux.git] / drivers / acpi / apei / einj.c
CommitLineData
e4021345
HY
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 *
6e320ec1 10 * Copyright 2009-2010 Intel Corp.
e4021345
HY
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>
35#include <acpi/acpi.h>
36
37#include "apei-internal.h"
38
39#define EINJ_PFX "EINJ: "
40
41#define SPIN_UNIT 100 /* 100ns */
e8a8b252 42/* Firmware should respond within 1 milliseconds */
e4021345
HY
43#define FIRMWARE_TIMEOUT (1 * NSEC_PER_MSEC)
44
c130bd6f
TL
45/*
46 * ACPI version 5 provides a SET_ERROR_TYPE_WITH_ADDRESS action.
47 */
48static int acpi5;
49
50struct 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};
59enum {
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 */
68struct 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
77static u32 vendor_flags;
78static struct debugfs_blob_wrapper vendor_blob;
79static char vendor_dev[64];
80
6e320ec1
HY
81/*
82 * Some BIOSes allow parameters to the SET_ERROR_TYPE entries in the
83 * EINJ table through an unpublished extension. Use with caution as
84 * most will ignore the parameter and make their own choice of address
c3e6088e
HY
85 * for error injection. This extension is used only if
86 * param_extension module parameter is specified.
6e320ec1
HY
87 */
88struct einj_parameter {
89 u64 type;
90 u64 reserved1;
91 u64 reserved2;
92 u64 param1;
93 u64 param2;
94};
95
e4021345
HY
96#define EINJ_OP_BUSY 0x1
97#define EINJ_STATUS_SUCCESS 0x0
98#define EINJ_STATUS_FAIL 0x1
99#define EINJ_STATUS_INVAL 0x2
100
101#define EINJ_TAB_ENTRY(tab) \
102 ((struct acpi_whea_header *)((char *)(tab) + \
103 sizeof(struct acpi_table_einj)))
104
c3e6088e
HY
105static bool param_extension;
106module_param(param_extension, bool, 0);
107
e4021345
HY
108static struct acpi_table_einj *einj_tab;
109
110static struct apei_resources einj_resources;
111
112static struct apei_exec_ins_type einj_ins_type[] = {
113 [ACPI_EINJ_READ_REGISTER] = {
114 .flags = APEI_EXEC_INS_ACCESS_REGISTER,
115 .run = apei_exec_read_register,
116 },
117 [ACPI_EINJ_READ_REGISTER_VALUE] = {
118 .flags = APEI_EXEC_INS_ACCESS_REGISTER,
119 .run = apei_exec_read_register_value,
120 },
121 [ACPI_EINJ_WRITE_REGISTER] = {
122 .flags = APEI_EXEC_INS_ACCESS_REGISTER,
123 .run = apei_exec_write_register,
124 },
125 [ACPI_EINJ_WRITE_REGISTER_VALUE] = {
126 .flags = APEI_EXEC_INS_ACCESS_REGISTER,
127 .run = apei_exec_write_register_value,
128 },
129 [ACPI_EINJ_NOOP] = {
130 .flags = 0,
131 .run = apei_exec_noop,
132 },
133};
134
135/*
136 * Prevent EINJ interpreter to run simultaneously, because the
137 * corresponding firmware implementation may not work properly when
138 * invoked simultaneously.
139 */
140static DEFINE_MUTEX(einj_mutex);
141
c130bd6f
TL
142static void *einj_param;
143
144#ifndef readq
145static inline __u64 readq(volatile void __iomem *addr)
146{
147 return ((__u64)readl(addr+4) << 32) + readl(addr);
148}
149#endif
6e320ec1 150
dbee8a0a
RD
151#ifndef writeq
152static inline void writeq(__u64 val, volatile void __iomem *addr)
153{
154 writel(val, addr);
155 writel(val >> 32, addr+4);
156}
157#endif
158
e4021345
HY
159static void einj_exec_ctx_init(struct apei_exec_context *ctx)
160{
161 apei_exec_ctx_init(ctx, einj_ins_type, ARRAY_SIZE(einj_ins_type),
162 EINJ_TAB_ENTRY(einj_tab), einj_tab->entries);
163}
164
165static int __einj_get_available_error_type(u32 *type)
166{
167 struct apei_exec_context ctx;
168 int rc;
169
170 einj_exec_ctx_init(&ctx);
171 rc = apei_exec_run(&ctx, ACPI_EINJ_GET_ERROR_TYPE);
172 if (rc)
173 return rc;
174 *type = apei_exec_ctx_get_output(&ctx);
175
176 return 0;
177}
178
179/* Get error injection capabilities of the platform */
180static int einj_get_available_error_type(u32 *type)
181{
182 int rc;
183
184 mutex_lock(&einj_mutex);
185 rc = __einj_get_available_error_type(type);
186 mutex_unlock(&einj_mutex);
187
188 return rc;
189}
190
191static int einj_timedout(u64 *t)
192{
193 if ((s64)*t < SPIN_UNIT) {
194 pr_warning(FW_WARN EINJ_PFX
195 "Firmware does not respond in time\n");
196 return 1;
197 }
198 *t -= SPIN_UNIT;
199 ndelay(SPIN_UNIT);
200 touch_nmi_watchdog();
201 return 0;
202}
203
c130bd6f
TL
204static 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
225static void *einj_get_parameter_address(void)
6e320ec1
HY
226{
227 int i;
c130bd6f 228 u64 paddrv4 = 0, paddrv5 = 0;
6e320ec1
HY
229 struct acpi_whea_header *entry;
230
231 entry = EINJ_TAB_ENTRY(einj_tab);
232 for (i = 0; i < einj_tab->entries; i++) {
233 if (entry->action == ACPI_EINJ_SET_ERROR_TYPE &&
234 entry->instruction == ACPI_EINJ_WRITE_REGISTER &&
235 entry->register_region.space_id ==
236 ACPI_ADR_SPACE_SYSTEM_MEMORY)
c130bd6f
TL
237 memcpy(&paddrv4, &entry->register_region.address,
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));
6e320ec1
HY
245 entry++;
246 }
c130bd6f
TL
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 }
6e320ec1 269
c130bd6f 270 return 0;
6e320ec1
HY
271}
272
e4021345
HY
273/* do sanity check to trigger table */
274static int einj_check_trigger_header(struct acpi_einj_trigger *trigger_tab)
275{
276 if (trigger_tab->header_size != sizeof(struct acpi_einj_trigger))
277 return -EINVAL;
278 if (trigger_tab->table_size > PAGE_SIZE ||
279 trigger_tab->table_size <= trigger_tab->header_size)
280 return -EINVAL;
281 if (trigger_tab->entry_count !=
282 (trigger_tab->table_size - trigger_tab->header_size) /
283 sizeof(struct acpi_einj_entry))
284 return -EINVAL;
285
286 return 0;
287}
288
289/* Execute instructions in trigger error action table */
290static int __einj_error_trigger(u64 trigger_paddr)
291{
292 struct acpi_einj_trigger *trigger_tab = NULL;
293 struct apei_exec_context trigger_ctx;
294 struct apei_resources trigger_resources;
295 struct acpi_whea_header *trigger_entry;
296 struct resource *r;
297 u32 table_size;
298 int rc = -EIO;
299
300 r = request_mem_region(trigger_paddr, sizeof(*trigger_tab),
301 "APEI EINJ Trigger Table");
302 if (!r) {
303 pr_err(EINJ_PFX
304 "Can not request iomem region <%016llx-%016llx> for Trigger table.\n",
305 (unsigned long long)trigger_paddr,
306 (unsigned long long)trigger_paddr+sizeof(*trigger_tab));
307 goto out;
308 }
309 trigger_tab = ioremap_cache(trigger_paddr, sizeof(*trigger_tab));
310 if (!trigger_tab) {
311 pr_err(EINJ_PFX "Failed to map trigger table!\n");
312 goto out_rel_header;
313 }
314 rc = einj_check_trigger_header(trigger_tab);
315 if (rc) {
316 pr_warning(FW_BUG EINJ_PFX
317 "The trigger error action table is invalid\n");
318 goto out_rel_header;
319 }
320 rc = -EIO;
321 table_size = trigger_tab->table_size;
322 r = request_mem_region(trigger_paddr + sizeof(*trigger_tab),
323 table_size - sizeof(*trigger_tab),
324 "APEI EINJ Trigger Table");
325 if (!r) {
326 pr_err(EINJ_PFX
327"Can not request iomem region <%016llx-%016llx> for Trigger Table Entry.\n",
328 (unsigned long long)trigger_paddr+sizeof(*trigger_tab),
329 (unsigned long long)trigger_paddr + table_size);
330 goto out_rel_header;
331 }
332 iounmap(trigger_tab);
333 trigger_tab = ioremap_cache(trigger_paddr, table_size);
334 if (!trigger_tab) {
335 pr_err(EINJ_PFX "Failed to map trigger table!\n");
336 goto out_rel_entry;
337 }
338 trigger_entry = (struct acpi_whea_header *)
339 ((char *)trigger_tab + sizeof(struct acpi_einj_trigger));
340 apei_resources_init(&trigger_resources);
341 apei_exec_ctx_init(&trigger_ctx, einj_ins_type,
342 ARRAY_SIZE(einj_ins_type),
343 trigger_entry, trigger_tab->entry_count);
344 rc = apei_exec_collect_resources(&trigger_ctx, &trigger_resources);
345 if (rc)
346 goto out_fini;
347 rc = apei_resources_sub(&trigger_resources, &einj_resources);
348 if (rc)
349 goto out_fini;
350 rc = apei_resources_request(&trigger_resources, "APEI EINJ Trigger");
351 if (rc)
352 goto out_fini;
353 rc = apei_exec_pre_map_gars(&trigger_ctx);
354 if (rc)
355 goto out_release;
356
357 rc = apei_exec_run(&trigger_ctx, ACPI_EINJ_TRIGGER_ERROR);
358
359 apei_exec_post_unmap_gars(&trigger_ctx);
360out_release:
361 apei_resources_release(&trigger_resources);
362out_fini:
363 apei_resources_fini(&trigger_resources);
364out_rel_entry:
365 release_mem_region(trigger_paddr + sizeof(*trigger_tab),
366 table_size - sizeof(*trigger_tab));
367out_rel_header:
368 release_mem_region(trigger_paddr, sizeof(*trigger_tab));
369out:
370 if (trigger_tab)
371 iounmap(trigger_tab);
372
373 return rc;
374}
375
6e320ec1 376static int __einj_error_inject(u32 type, u64 param1, u64 param2)
e4021345
HY
377{
378 struct apei_exec_context ctx;
379 u64 val, trigger_paddr, timeout = FIRMWARE_TIMEOUT;
380 int rc;
381
382 einj_exec_ctx_init(&ctx);
383
392913de 384 rc = apei_exec_run_optional(&ctx, ACPI_EINJ_BEGIN_OPERATION);
e4021345
HY
385 if (rc)
386 return rc;
387 apei_exec_ctx_set_input(&ctx, type);
c130bd6f
TL
388 if (acpi5) {
389 struct set_error_type_with_address *v5param = einj_param;
390
391 writel(type, &v5param->type);
392 if (type & 0x80000000) {
393 switch (vendor_flags) {
394 case SETWA_FLAGS_APICID:
395 writel(param1, &v5param->apicid);
396 break;
397 case SETWA_FLAGS_MEM:
398 writeq(param1, &v5param->memory_address);
399 writeq(param2, &v5param->memory_address_range);
400 break;
401 case SETWA_FLAGS_PCIE_SBDF:
402 writel(param1, &v5param->pcie_sbdf);
403 break;
404 }
405 writel(vendor_flags, &v5param->flags);
406 } else {
407 switch (type) {
408 case ACPI_EINJ_PROCESSOR_CORRECTABLE:
409 case ACPI_EINJ_PROCESSOR_UNCORRECTABLE:
410 case ACPI_EINJ_PROCESSOR_FATAL:
411 writel(param1, &v5param->apicid);
412 writel(SETWA_FLAGS_APICID, &v5param->flags);
413 break;
414 case ACPI_EINJ_MEMORY_CORRECTABLE:
415 case ACPI_EINJ_MEMORY_UNCORRECTABLE:
416 case ACPI_EINJ_MEMORY_FATAL:
417 writeq(param1, &v5param->memory_address);
418 writeq(param2, &v5param->memory_address_range);
419 writel(SETWA_FLAGS_MEM, &v5param->flags);
420 break;
421 case ACPI_EINJ_PCIX_CORRECTABLE:
422 case ACPI_EINJ_PCIX_UNCORRECTABLE:
423 case ACPI_EINJ_PCIX_FATAL:
424 writel(param1, &v5param->pcie_sbdf);
425 writel(SETWA_FLAGS_PCIE_SBDF, &v5param->flags);
426 break;
427 }
428 }
429 } else {
430 rc = apei_exec_run(&ctx, ACPI_EINJ_SET_ERROR_TYPE);
431 if (rc)
432 return rc;
433 if (einj_param) {
434 struct einj_parameter *v4param = einj_param;
435 writeq(param1, &v4param->param1);
436 writeq(param2, &v4param->param2);
437 }
6e320ec1 438 }
e4021345
HY
439 rc = apei_exec_run(&ctx, ACPI_EINJ_EXECUTE_OPERATION);
440 if (rc)
441 return rc;
442 for (;;) {
443 rc = apei_exec_run(&ctx, ACPI_EINJ_CHECK_BUSY_STATUS);
444 if (rc)
445 return rc;
446 val = apei_exec_ctx_get_output(&ctx);
447 if (!(val & EINJ_OP_BUSY))
448 break;
449 if (einj_timedout(&timeout))
450 return -EIO;
451 }
452 rc = apei_exec_run(&ctx, ACPI_EINJ_GET_COMMAND_STATUS);
453 if (rc)
454 return rc;
455 val = apei_exec_ctx_get_output(&ctx);
456 if (val != EINJ_STATUS_SUCCESS)
457 return -EBUSY;
458
459 rc = apei_exec_run(&ctx, ACPI_EINJ_GET_TRIGGER_TABLE);
460 if (rc)
461 return rc;
462 trigger_paddr = apei_exec_ctx_get_output(&ctx);
463 rc = __einj_error_trigger(trigger_paddr);
464 if (rc)
465 return rc;
392913de 466 rc = apei_exec_run_optional(&ctx, ACPI_EINJ_END_OPERATION);
e4021345
HY
467
468 return rc;
469}
470
471/* Inject the specified hardware error */
6e320ec1 472static int einj_error_inject(u32 type, u64 param1, u64 param2)
e4021345
HY
473{
474 int rc;
475
476 mutex_lock(&einj_mutex);
6e320ec1 477 rc = __einj_error_inject(type, param1, param2);
e4021345
HY
478 mutex_unlock(&einj_mutex);
479
480 return rc;
481}
482
483static u32 error_type;
6e320ec1
HY
484static u64 error_param1;
485static u64 error_param2;
e4021345
HY
486static struct dentry *einj_debug_dir;
487
488static int available_error_type_show(struct seq_file *m, void *v)
489{
490 int rc;
491 u32 available_error_type = 0;
492
493 rc = einj_get_available_error_type(&available_error_type);
494 if (rc)
495 return rc;
496 if (available_error_type & 0x0001)
497 seq_printf(m, "0x00000001\tProcessor Correctable\n");
498 if (available_error_type & 0x0002)
499 seq_printf(m, "0x00000002\tProcessor Uncorrectable non-fatal\n");
500 if (available_error_type & 0x0004)
501 seq_printf(m, "0x00000004\tProcessor Uncorrectable fatal\n");
502 if (available_error_type & 0x0008)
503 seq_printf(m, "0x00000008\tMemory Correctable\n");
504 if (available_error_type & 0x0010)
505 seq_printf(m, "0x00000010\tMemory Uncorrectable non-fatal\n");
506 if (available_error_type & 0x0020)
507 seq_printf(m, "0x00000020\tMemory Uncorrectable fatal\n");
508 if (available_error_type & 0x0040)
509 seq_printf(m, "0x00000040\tPCI Express Correctable\n");
510 if (available_error_type & 0x0080)
511 seq_printf(m, "0x00000080\tPCI Express Uncorrectable non-fatal\n");
512 if (available_error_type & 0x0100)
513 seq_printf(m, "0x00000100\tPCI Express Uncorrectable fatal\n");
514 if (available_error_type & 0x0200)
515 seq_printf(m, "0x00000200\tPlatform Correctable\n");
516 if (available_error_type & 0x0400)
517 seq_printf(m, "0x00000400\tPlatform Uncorrectable non-fatal\n");
518 if (available_error_type & 0x0800)
519 seq_printf(m, "0x00000800\tPlatform Uncorrectable fatal\n");
520
521 return 0;
522}
523
524static int available_error_type_open(struct inode *inode, struct file *file)
525{
526 return single_open(file, available_error_type_show, NULL);
527}
528
529static const struct file_operations available_error_type_fops = {
530 .open = available_error_type_open,
531 .read = seq_read,
532 .llseek = seq_lseek,
533 .release = single_release,
534};
535
536static int error_type_get(void *data, u64 *val)
537{
538 *val = error_type;
539
540 return 0;
541}
542
543static int error_type_set(void *data, u64 val)
544{
545 int rc;
546 u32 available_error_type = 0;
c130bd6f
TL
547 u32 tval, vendor;
548
549 /*
550 * Vendor defined types have 0x80000000 bit set, and
551 * are not enumerated by ACPI_EINJ_GET_ERROR_TYPE
552 */
553 vendor = val & 0x80000000;
554 tval = val & 0x7fffffff;
e4021345
HY
555
556 /* Only one error type can be specified */
c130bd6f 557 if (tval & (tval - 1))
e4021345 558 return -EINVAL;
c130bd6f
TL
559 if (!vendor) {
560 rc = einj_get_available_error_type(&available_error_type);
561 if (rc)
562 return rc;
563 if (!(val & available_error_type))
564 return -EINVAL;
565 }
e4021345
HY
566 error_type = val;
567
568 return 0;
569}
570
571DEFINE_SIMPLE_ATTRIBUTE(error_type_fops, error_type_get,
572 error_type_set, "0x%llx\n");
573
574static int error_inject_set(void *data, u64 val)
575{
576 if (!error_type)
577 return -EINVAL;
578
6e320ec1 579 return einj_error_inject(error_type, error_param1, error_param2);
e4021345
HY
580}
581
582DEFINE_SIMPLE_ATTRIBUTE(error_inject_fops, NULL,
583 error_inject_set, "%llu\n");
584
585static int einj_check_table(struct acpi_table_einj *einj_tab)
586{
3a78f965
HY
587 if ((einj_tab->header_length !=
588 (sizeof(struct acpi_table_einj) - sizeof(einj_tab->header)))
589 && (einj_tab->header_length != sizeof(struct acpi_table_einj)))
e4021345
HY
590 return -EINVAL;
591 if (einj_tab->header.length < sizeof(struct acpi_table_einj))
592 return -EINVAL;
593 if (einj_tab->entries !=
594 (einj_tab->header.length - sizeof(struct acpi_table_einj)) /
595 sizeof(struct acpi_einj_entry))
596 return -EINVAL;
597
598 return 0;
599}
600
601static int __init einj_init(void)
602{
603 int rc;
604 acpi_status status;
605 struct dentry *fentry;
606 struct apei_exec_context ctx;
607
608 if (acpi_disabled)
609 return -ENODEV;
610
611 status = acpi_get_table(ACPI_SIG_EINJ, 0,
612 (struct acpi_table_header **)&einj_tab);
613 if (status == AE_NOT_FOUND) {
614 pr_info(EINJ_PFX "Table is not found!\n");
615 return -ENODEV;
616 } else if (ACPI_FAILURE(status)) {
617 const char *msg = acpi_format_exception(status);
618 pr_err(EINJ_PFX "Failed to get table, %s\n", msg);
619 return -EINVAL;
620 }
621
622 rc = einj_check_table(einj_tab);
623 if (rc) {
624 pr_warning(FW_BUG EINJ_PFX "EINJ table is invalid\n");
625 return -EINVAL;
626 }
627
628 rc = -ENOMEM;
629 einj_debug_dir = debugfs_create_dir("einj", apei_get_debugfs_dir());
630 if (!einj_debug_dir)
631 goto err_cleanup;
632 fentry = debugfs_create_file("available_error_type", S_IRUSR,
633 einj_debug_dir, NULL,
634 &available_error_type_fops);
635 if (!fentry)
636 goto err_cleanup;
637 fentry = debugfs_create_file("error_type", S_IRUSR | S_IWUSR,
638 einj_debug_dir, NULL, &error_type_fops);
639 if (!fentry)
640 goto err_cleanup;
641 fentry = debugfs_create_file("error_inject", S_IWUSR,
642 einj_debug_dir, NULL, &error_inject_fops);
643 if (!fentry)
644 goto err_cleanup;
645
646 apei_resources_init(&einj_resources);
647 einj_exec_ctx_init(&ctx);
648 rc = apei_exec_collect_resources(&ctx, &einj_resources);
649 if (rc)
650 goto err_fini;
651 rc = apei_resources_request(&einj_resources, "APEI EINJ");
652 if (rc)
653 goto err_fini;
654 rc = apei_exec_pre_map_gars(&ctx);
655 if (rc)
656 goto err_release;
c130bd6f
TL
657
658 einj_param = einj_get_parameter_address();
659 if ((param_extension || acpi5) && einj_param) {
660 fentry = debugfs_create_x64("param1", S_IRUSR | S_IWUSR,
661 einj_debug_dir, &error_param1);
662 if (!fentry)
663 goto err_unmap;
664 fentry = debugfs_create_x64("param2", S_IRUSR | S_IWUSR,
665 einj_debug_dir, &error_param2);
666 if (!fentry)
667 goto err_unmap;
668 }
669
670 if (vendor_dev[0]) {
671 vendor_blob.data = vendor_dev;
672 vendor_blob.size = strlen(vendor_dev);
673 fentry = debugfs_create_blob("vendor", S_IRUSR,
674 einj_debug_dir, &vendor_blob);
675 if (!fentry)
676 goto err_unmap;
677 fentry = debugfs_create_x32("vendor_flags", S_IRUSR | S_IWUSR,
678 einj_debug_dir, &vendor_flags);
679 if (!fentry)
680 goto err_unmap;
6e320ec1 681 }
e4021345
HY
682
683 pr_info(EINJ_PFX "Error INJection is initialized.\n");
684
685 return 0;
686
6e320ec1 687err_unmap:
c3e6088e
HY
688 if (einj_param)
689 iounmap(einj_param);
6e320ec1 690 apei_exec_post_unmap_gars(&ctx);
e4021345
HY
691err_release:
692 apei_resources_release(&einj_resources);
693err_fini:
694 apei_resources_fini(&einj_resources);
695err_cleanup:
696 debugfs_remove_recursive(einj_debug_dir);
697
698 return rc;
699}
700
701static void __exit einj_exit(void)
702{
703 struct apei_exec_context ctx;
704
6e320ec1
HY
705 if (einj_param)
706 iounmap(einj_param);
e4021345
HY
707 einj_exec_ctx_init(&ctx);
708 apei_exec_post_unmap_gars(&ctx);
709 apei_resources_release(&einj_resources);
710 apei_resources_fini(&einj_resources);
711 debugfs_remove_recursive(einj_debug_dir);
712}
713
714module_init(einj_init);
715module_exit(einj_exit);
716
717MODULE_AUTHOR("Huang Ying");
718MODULE_DESCRIPTION("APEI Error INJection support");
719MODULE_LICENSE("GPL");
This page took 0.13061 seconds and 5 git commands to generate.