xref: /OK3568_Linux_fs/kernel/drivers/acpi/hed.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * ACPI Hardware Error Device (PNP0C33) Driver
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (C) 2010, Intel Corp.
6*4882a593Smuzhiyun  *	Author: Huang Ying <ying.huang@intel.com>
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  * ACPI Hardware Error Device is used to report some hardware errors
9*4882a593Smuzhiyun  * notified via SCI, mainly the corrected errors.
10*4882a593Smuzhiyun  */
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun #include <linux/kernel.h>
13*4882a593Smuzhiyun #include <linux/module.h>
14*4882a593Smuzhiyun #include <linux/init.h>
15*4882a593Smuzhiyun #include <linux/acpi.h>
16*4882a593Smuzhiyun #include <acpi/hed.h>
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun static const struct acpi_device_id acpi_hed_ids[] = {
19*4882a593Smuzhiyun 	{"PNP0C33", 0},
20*4882a593Smuzhiyun 	{"", 0},
21*4882a593Smuzhiyun };
22*4882a593Smuzhiyun MODULE_DEVICE_TABLE(acpi, acpi_hed_ids);
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun static acpi_handle hed_handle;
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun static BLOCKING_NOTIFIER_HEAD(acpi_hed_notify_list);
27*4882a593Smuzhiyun 
register_acpi_hed_notifier(struct notifier_block * nb)28*4882a593Smuzhiyun int register_acpi_hed_notifier(struct notifier_block *nb)
29*4882a593Smuzhiyun {
30*4882a593Smuzhiyun 	return blocking_notifier_chain_register(&acpi_hed_notify_list, nb);
31*4882a593Smuzhiyun }
32*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(register_acpi_hed_notifier);
33*4882a593Smuzhiyun 
unregister_acpi_hed_notifier(struct notifier_block * nb)34*4882a593Smuzhiyun void unregister_acpi_hed_notifier(struct notifier_block *nb)
35*4882a593Smuzhiyun {
36*4882a593Smuzhiyun 	blocking_notifier_chain_unregister(&acpi_hed_notify_list, nb);
37*4882a593Smuzhiyun }
38*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(unregister_acpi_hed_notifier);
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun /*
41*4882a593Smuzhiyun  * SCI to report hardware error is forwarded to the listeners of HED,
42*4882a593Smuzhiyun  * it is used by HEST Generic Hardware Error Source with notify type
43*4882a593Smuzhiyun  * SCI.
44*4882a593Smuzhiyun  */
acpi_hed_notify(struct acpi_device * device,u32 event)45*4882a593Smuzhiyun static void acpi_hed_notify(struct acpi_device *device, u32 event)
46*4882a593Smuzhiyun {
47*4882a593Smuzhiyun 	blocking_notifier_call_chain(&acpi_hed_notify_list, 0, NULL);
48*4882a593Smuzhiyun }
49*4882a593Smuzhiyun 
acpi_hed_add(struct acpi_device * device)50*4882a593Smuzhiyun static int acpi_hed_add(struct acpi_device *device)
51*4882a593Smuzhiyun {
52*4882a593Smuzhiyun 	/* Only one hardware error device */
53*4882a593Smuzhiyun 	if (hed_handle)
54*4882a593Smuzhiyun 		return -EINVAL;
55*4882a593Smuzhiyun 	hed_handle = device->handle;
56*4882a593Smuzhiyun 	return 0;
57*4882a593Smuzhiyun }
58*4882a593Smuzhiyun 
acpi_hed_remove(struct acpi_device * device)59*4882a593Smuzhiyun static int acpi_hed_remove(struct acpi_device *device)
60*4882a593Smuzhiyun {
61*4882a593Smuzhiyun 	hed_handle = NULL;
62*4882a593Smuzhiyun 	return 0;
63*4882a593Smuzhiyun }
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun static struct acpi_driver acpi_hed_driver = {
66*4882a593Smuzhiyun 	.name = "hardware_error_device",
67*4882a593Smuzhiyun 	.class = "hardware_error",
68*4882a593Smuzhiyun 	.ids = acpi_hed_ids,
69*4882a593Smuzhiyun 	.ops = {
70*4882a593Smuzhiyun 		.add = acpi_hed_add,
71*4882a593Smuzhiyun 		.remove = acpi_hed_remove,
72*4882a593Smuzhiyun 		.notify = acpi_hed_notify,
73*4882a593Smuzhiyun 	},
74*4882a593Smuzhiyun };
75*4882a593Smuzhiyun module_acpi_driver(acpi_hed_driver);
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun ACPI_MODULE_NAME("hed");
78*4882a593Smuzhiyun MODULE_AUTHOR("Huang Ying");
79*4882a593Smuzhiyun MODULE_DESCRIPTION("ACPI Hardware Error Device Driver");
80*4882a593Smuzhiyun MODULE_LICENSE("GPL");
81