1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * ACPI Hardware Error Device (PNP0C33) Driver 4 * 5 * Copyright (C) 2010, Intel Corp. 6 * Author: Huang Ying <ying.huang@intel.com> 7 * 8 * ACPI Hardware Error Device is used to report some hardware errors 9 * notified via SCI, mainly the corrected errors. 10 */ 11 12 #include <linux/kernel.h> 13 #include <linux/module.h> 14 #include <linux/init.h> 15 #include <linux/acpi.h> 16 #include <linux/platform_device.h> 17 #include <acpi/hed.h> 18 19 static const struct acpi_device_id acpi_hed_ids[] = { 20 {"PNP0C33", 0}, 21 {"", 0}, 22 }; 23 MODULE_DEVICE_TABLE(acpi, acpi_hed_ids); 24 25 static acpi_handle hed_handle; 26 27 static BLOCKING_NOTIFIER_HEAD(acpi_hed_notify_list); 28 29 int register_acpi_hed_notifier(struct notifier_block *nb) 30 { 31 return blocking_notifier_chain_register(&acpi_hed_notify_list, nb); 32 } 33 EXPORT_SYMBOL_GPL(register_acpi_hed_notifier); 34 35 void unregister_acpi_hed_notifier(struct notifier_block *nb) 36 { 37 blocking_notifier_chain_unregister(&acpi_hed_notify_list, nb); 38 } 39 EXPORT_SYMBOL_GPL(unregister_acpi_hed_notifier); 40 41 /* 42 * SCI to report hardware error is forwarded to the listeners of HED, 43 * it is used by HEST Generic Hardware Error Source with notify type 44 * SCI. 45 */ 46 static void acpi_hed_notify(acpi_handle handle, u32 event, void *data) 47 { 48 blocking_notifier_call_chain(&acpi_hed_notify_list, 0, NULL); 49 } 50 51 static int acpi_hed_probe(struct platform_device *pdev) 52 { 53 struct acpi_device *device; 54 int err; 55 56 device = ACPI_COMPANION(&pdev->dev); 57 if (!device) 58 return -ENODEV; 59 60 /* Only one hardware error device */ 61 if (hed_handle) 62 return -EINVAL; 63 hed_handle = device->handle; 64 65 err = acpi_dev_install_notify_handler(device, ACPI_DEVICE_NOTIFY, 66 acpi_hed_notify, device); 67 if (err) 68 hed_handle = NULL; 69 70 return err; 71 } 72 73 static void acpi_hed_remove(struct platform_device *pdev) 74 { 75 struct acpi_device *device = ACPI_COMPANION(&pdev->dev); 76 77 acpi_dev_remove_notify_handler(device, ACPI_DEVICE_NOTIFY, 78 acpi_hed_notify); 79 hed_handle = NULL; 80 } 81 82 static struct platform_driver acpi_hed_driver = { 83 .probe = acpi_hed_probe, 84 .remove = acpi_hed_remove, 85 .driver = { 86 .name = "acpi-hardware-error-device", 87 .acpi_match_table = acpi_hed_ids, 88 }, 89 }; 90 91 static int __init acpi_hed_driver_init(void) 92 { 93 return platform_driver_register(&acpi_hed_driver); 94 } 95 subsys_initcall(acpi_hed_driver_init); 96 97 MODULE_AUTHOR("Huang Ying"); 98 MODULE_DESCRIPTION("ACPI Hardware Error Device Driver"); 99 MODULE_LICENSE("GPL"); 100