hed.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. #include <linux/kernel.h>
  12. #include <linux/module.h>
  13. #include <linux/init.h>
  14. #include <linux/acpi.h>
  15. #include <acpi/hed.h>
  16. static const struct acpi_device_id acpi_hed_ids[] = {
  17. {"PNP0C33", 0},
  18. {"", 0},
  19. };
  20. MODULE_DEVICE_TABLE(acpi, acpi_hed_ids);
  21. static acpi_handle hed_handle;
  22. static BLOCKING_NOTIFIER_HEAD(acpi_hed_notify_list);
  23. int register_acpi_hed_notifier(struct notifier_block *nb)
  24. {
  25. return blocking_notifier_chain_register(&acpi_hed_notify_list, nb);
  26. }
  27. EXPORT_SYMBOL_GPL(register_acpi_hed_notifier);
  28. void unregister_acpi_hed_notifier(struct notifier_block *nb)
  29. {
  30. blocking_notifier_chain_unregister(&acpi_hed_notify_list, nb);
  31. }
  32. EXPORT_SYMBOL_GPL(unregister_acpi_hed_notifier);
  33. /*
  34. * SCI to report hardware error is forwarded to the listeners of HED,
  35. * it is used by HEST Generic Hardware Error Source with notify type
  36. * SCI.
  37. */
  38. static void acpi_hed_notify(acpi_handle handle, u32 event, void *data)
  39. {
  40. blocking_notifier_call_chain(&acpi_hed_notify_list, 0, NULL);
  41. }
  42. static int acpi_hed_add(struct acpi_device *device)
  43. {
  44. int err;
  45. /* Only one hardware error device */
  46. if (hed_handle)
  47. return -EINVAL;
  48. hed_handle = device->handle;
  49. err = acpi_dev_install_notify_handler(device, ACPI_DEVICE_NOTIFY,
  50. acpi_hed_notify, device);
  51. if (err)
  52. hed_handle = NULL;
  53. return err;
  54. }
  55. static void acpi_hed_remove(struct acpi_device *device)
  56. {
  57. acpi_dev_remove_notify_handler(device, ACPI_DEVICE_NOTIFY,
  58. acpi_hed_notify);
  59. hed_handle = NULL;
  60. }
  61. static struct acpi_driver acpi_hed_driver = {
  62. .name = "hardware_error_device",
  63. .class = "hardware_error",
  64. .ids = acpi_hed_ids,
  65. .ops = {
  66. .add = acpi_hed_add,
  67. .remove = acpi_hed_remove,
  68. },
  69. };
  70. static int __init acpi_hed_driver_init(void)
  71. {
  72. return acpi_bus_register_driver(&acpi_hed_driver);
  73. }
  74. subsys_initcall(acpi_hed_driver_init);
  75. MODULE_AUTHOR("Huang Ying");
  76. MODULE_DESCRIPTION("ACPI Hardware Error Device Driver");
  77. MODULE_LICENSE("GPL");