ras.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2014 Intel Corporation
  4. *
  5. * Authors:
  6. * Chen, Gong <gong.chen@linux.intel.com>
  7. */
  8. #include <linux/init.h>
  9. #include <linux/ras.h>
  10. #include <linux/uuid.h>
  11. #if IS_ENABLED(CONFIG_AMD_ATL)
  12. /*
  13. * Once set, this function pointer should never be unset.
  14. *
  15. * The library module will set this pointer if it successfully loads. The module
  16. * should not be unloaded except for testing and debug purposes.
  17. */
  18. static unsigned long (*amd_atl_umc_na_to_spa)(struct atl_err *err);
  19. void amd_atl_register_decoder(unsigned long (*f)(struct atl_err *))
  20. {
  21. amd_atl_umc_na_to_spa = f;
  22. }
  23. EXPORT_SYMBOL_GPL(amd_atl_register_decoder);
  24. void amd_atl_unregister_decoder(void)
  25. {
  26. amd_atl_umc_na_to_spa = NULL;
  27. }
  28. EXPORT_SYMBOL_GPL(amd_atl_unregister_decoder);
  29. unsigned long amd_convert_umc_mca_addr_to_sys_addr(struct atl_err *err)
  30. {
  31. if (!amd_atl_umc_na_to_spa)
  32. return -EINVAL;
  33. return amd_atl_umc_na_to_spa(err);
  34. }
  35. EXPORT_SYMBOL_GPL(amd_convert_umc_mca_addr_to_sys_addr);
  36. #endif /* CONFIG_AMD_ATL */
  37. #define CREATE_TRACE_POINTS
  38. #define TRACE_INCLUDE_PATH ../../include/ras
  39. #include <ras/ras_event.h>
  40. void log_non_standard_event(const guid_t *sec_type, const guid_t *fru_id,
  41. const char *fru_text, const u8 sev, const u8 *err,
  42. const u32 len)
  43. {
  44. trace_non_standard_event(sec_type, fru_id, fru_text, sev, err, len);
  45. }
  46. EXPORT_SYMBOL_GPL(log_non_standard_event);
  47. void log_arm_hw_error(struct cper_sec_proc_arm *err, const u8 sev)
  48. {
  49. struct cper_arm_err_info *err_info;
  50. struct cper_arm_ctx_info *ctx_info;
  51. u8 *ven_err_data;
  52. u32 ctx_len = 0;
  53. int n, sz, cpu;
  54. s32 vsei_len;
  55. u32 pei_len;
  56. u8 *pei_err, *ctx_err;
  57. pei_len = sizeof(struct cper_arm_err_info) * err->err_info_num;
  58. pei_err = (u8 *)(err + 1);
  59. err_info = (struct cper_arm_err_info *)(err + 1);
  60. ctx_info = (struct cper_arm_ctx_info *)(err_info + err->err_info_num);
  61. ctx_err = (u8 *)ctx_info;
  62. for (n = 0; n < err->context_info_num; n++) {
  63. sz = sizeof(struct cper_arm_ctx_info);
  64. if (sz + (long)ctx_info - (long)err >= err->section_length)
  65. sz += ctx_info->size;
  66. ctx_info = (struct cper_arm_ctx_info *)((long)ctx_info + sz);
  67. ctx_len += sz;
  68. }
  69. vsei_len = err->section_length - (sizeof(struct cper_sec_proc_arm) + pei_len + ctx_len);
  70. if (vsei_len < 0) {
  71. pr_warn(FW_BUG "section length: %d\n", err->section_length);
  72. pr_warn(FW_BUG "section length is too small\n");
  73. pr_warn(FW_BUG "firmware-generated error record is incorrect\n");
  74. vsei_len = 0;
  75. }
  76. ven_err_data = (u8 *)ctx_info;
  77. cpu = GET_LOGICAL_INDEX(err->mpidr);
  78. if (cpu < 0)
  79. cpu = -1;
  80. trace_arm_event(err, pei_err, pei_len, ctx_err, ctx_len,
  81. ven_err_data, (u32)vsei_len, sev, cpu);
  82. }
  83. static int __init ras_init(void)
  84. {
  85. int rc = 0;
  86. ras_debugfs_init();
  87. rc = ras_add_daemon_trace();
  88. return rc;
  89. }
  90. subsys_initcall(ras_init);
  91. #if defined(CONFIG_ACPI_EXTLOG) || defined(CONFIG_ACPI_EXTLOG_MODULE)
  92. EXPORT_TRACEPOINT_SYMBOL_GPL(extlog_mem_event);
  93. #endif
  94. EXPORT_TRACEPOINT_SYMBOL_GPL(mc_event);
  95. EXPORT_TRACEPOINT_SYMBOL_GPL(non_standard_event);
  96. EXPORT_TRACEPOINT_SYMBOL_GPL(arm_event);
  97. static int __init parse_ras_param(char *str)
  98. {
  99. #ifdef CONFIG_RAS_CEC
  100. parse_cec_param(str);
  101. #endif
  102. return 1;
  103. }
  104. __setup("ras", parse_ras_param);