ghes.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef GHES_H
  3. #define GHES_H
  4. #include <acpi/apei.h>
  5. #include <acpi/hed.h>
  6. /*
  7. * One struct ghes is created for each generic hardware error source.
  8. * It provides the context for APEI hardware error timer/IRQ/SCI/NMI
  9. * handler.
  10. *
  11. * estatus: memory buffer for error status block, allocated during
  12. * HEST parsing.
  13. */
  14. #define GHES_EXITING 0x0002
  15. struct ghes {
  16. union {
  17. struct acpi_hest_generic *generic;
  18. struct acpi_hest_generic_v2 *generic_v2;
  19. };
  20. struct acpi_hest_generic_status *estatus;
  21. unsigned int estatus_length;
  22. unsigned long flags;
  23. union {
  24. struct list_head list;
  25. struct timer_list timer;
  26. unsigned int irq;
  27. };
  28. struct device *dev;
  29. struct list_head elist;
  30. void __iomem *error_status_vaddr;
  31. };
  32. struct ghes_estatus_node {
  33. struct llist_node llnode;
  34. struct acpi_hest_generic *generic;
  35. struct ghes *ghes;
  36. };
  37. struct ghes_estatus_cache {
  38. u32 estatus_len;
  39. atomic_t count;
  40. struct acpi_hest_generic *generic;
  41. unsigned long long time_in;
  42. struct rcu_head rcu;
  43. };
  44. enum {
  45. GHES_SEV_NO = 0x0,
  46. GHES_SEV_CORRECTED = 0x1,
  47. GHES_SEV_RECOVERABLE = 0x2,
  48. GHES_SEV_PANIC = 0x3,
  49. };
  50. #ifdef CONFIG_ACPI_APEI_GHES
  51. /**
  52. * ghes_register_vendor_record_notifier - register a notifier for vendor
  53. * records that the kernel would otherwise ignore.
  54. * @nb: pointer to the notifier_block structure of the event handler.
  55. *
  56. * return 0 : SUCCESS, non-zero : FAIL
  57. */
  58. int ghes_register_vendor_record_notifier(struct notifier_block *nb);
  59. /**
  60. * ghes_unregister_vendor_record_notifier - unregister the previously
  61. * registered vendor record notifier.
  62. * @nb: pointer to the notifier_block structure of the vendor record handler.
  63. */
  64. void ghes_unregister_vendor_record_notifier(struct notifier_block *nb);
  65. struct list_head *ghes_get_devices(void);
  66. void ghes_estatus_pool_region_free(unsigned long addr, u32 size);
  67. #else
  68. static inline struct list_head *ghes_get_devices(void) { return NULL; }
  69. static inline void ghes_estatus_pool_region_free(unsigned long addr, u32 size) { return; }
  70. #endif
  71. int ghes_estatus_pool_init(unsigned int num_ghes);
  72. static inline int acpi_hest_get_version(struct acpi_hest_generic_data *gdata)
  73. {
  74. return gdata->revision >> 8;
  75. }
  76. static inline void *acpi_hest_get_payload(struct acpi_hest_generic_data *gdata)
  77. {
  78. if (acpi_hest_get_version(gdata) >= 3)
  79. return (void *)(((struct acpi_hest_generic_data_v300 *)(gdata)) + 1);
  80. return gdata + 1;
  81. }
  82. static inline int acpi_hest_get_error_length(struct acpi_hest_generic_data *gdata)
  83. {
  84. return ((struct acpi_hest_generic_data *)(gdata))->error_data_length;
  85. }
  86. static inline int acpi_hest_get_size(struct acpi_hest_generic_data *gdata)
  87. {
  88. if (acpi_hest_get_version(gdata) >= 3)
  89. return sizeof(struct acpi_hest_generic_data_v300);
  90. return sizeof(struct acpi_hest_generic_data);
  91. }
  92. static inline int acpi_hest_get_record_size(struct acpi_hest_generic_data *gdata)
  93. {
  94. return (acpi_hest_get_size(gdata) + acpi_hest_get_error_length(gdata));
  95. }
  96. static inline void *acpi_hest_get_next(struct acpi_hest_generic_data *gdata)
  97. {
  98. return (void *)(gdata) + acpi_hest_get_record_size(gdata);
  99. }
  100. #define apei_estatus_for_each_section(estatus, section) \
  101. for (section = (struct acpi_hest_generic_data *)(estatus + 1); \
  102. (void *)section - (void *)(estatus + 1) < estatus->data_length; \
  103. section = acpi_hest_get_next(section))
  104. #ifdef CONFIG_ACPI_APEI_SEA
  105. int ghes_notify_sea(void);
  106. #else
  107. static inline int ghes_notify_sea(void) { return -ENOENT; }
  108. #endif
  109. struct notifier_block;
  110. extern void ghes_register_report_chain(struct notifier_block *nb);
  111. extern void ghes_unregister_report_chain(struct notifier_block *nb);
  112. #endif /* GHES_H */