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 = ACPI_COMPANION(&pdev->dev); 54 int err; 55 56 /* Only one hardware error device */ 57 if (hed_handle) 58 return -EINVAL; 59 hed_handle = device->handle; 60 61 err = acpi_dev_install_notify_handler(device, ACPI_DEVICE_NOTIFY, 62 acpi_hed_notify, device); 63 if (err) 64 hed_handle = NULL; 65 66 return err; 67 } 68 69 static void acpi_hed_remove(struct platform_device *pdev) 70 { 71 struct acpi_device *device = ACPI_COMPANION(&pdev->dev); 72 73 acpi_dev_remove_notify_handler(device, ACPI_DEVICE_NOTIFY, 74 acpi_hed_notify); 75 hed_handle = NULL; 76 } 77 78 static struct platform_driver acpi_hed_driver = { 79 .probe = acpi_hed_probe, 80 .remove = acpi_hed_remove, 81 .driver = { 82 .name = "acpi-hardware-error-device", 83 .acpi_match_table = acpi_hed_ids, 84 }, 85 }; 86 87 static int __init acpi_hed_driver_init(void) 88 { 89 return platform_driver_register(&acpi_hed_driver); 90 } 91 subsys_initcall(acpi_hed_driver_init); 92 93 MODULE_AUTHOR("Huang Ying"); 94 MODULE_DESCRIPTION("ACPI Hardware Error Device Driver"); 95 MODULE_LICENSE("GPL"); 96