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