Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Extended Error Log driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2013 Intel Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Author: Chen, Gong <gong.chen@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/cper.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/ratelimit.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/edac.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/ras.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <asm/cpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <asm/mce.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "apei/apei-internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <ras/ras_event.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define EXT_ELOG_ENTRY_MASK	GENMASK_ULL(51, 0) /* elog entry address mask */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define EXTLOG_DSM_REV		0x0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define	EXTLOG_FN_ADDR		0x1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define FLAG_OS_OPTIN		BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define ELOG_ENTRY_VALID	(1ULL<<63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define ELOG_ENTRY_LEN		0x1000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define EMCA_BUG \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	"Can not request iomem region <0x%016llx-0x%016llx> - eMCA disabled\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) struct extlog_l1_head {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	u32 ver;	/* Header Version */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	u32 hdr_len;	/* Header Length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	u64 total_len;	/* entire L1 Directory length including this header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	u64 elog_base;	/* MCA Error Log Directory base address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	u64 elog_len;	/* MCA Error Log Directory length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	u32 flags;	/* bit 0 - OS/VMM Opt-in */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	u8  rev0[12];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	u32 entries;	/* Valid L1 Directory entries per logical processor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	u8  rev1[12];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) static u8 extlog_dsm_uuid[] __initdata = "663E35AF-CC10-41A4-88EA-5470AF055295";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) /* L1 table related physical address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) static u64 elog_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) static size_t elog_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) static u64 l1_dirbase;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) static size_t l1_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) /* L1 table related virtual address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) static void __iomem *extlog_l1_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) static void __iomem *elog_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) static void *elog_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) static u64 *l1_entry_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) static u32 l1_percpu_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) #define ELOG_IDX(cpu, bank) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	(cpu_physical_id(cpu) * l1_percpu_entry + (bank))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) #define ELOG_ENTRY_DATA(idx) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	(*(l1_entry_base + (idx)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) #define ELOG_ENTRY_ADDR(phyaddr) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	(phyaddr - elog_base + (u8 *)elog_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) static struct acpi_hest_generic_status *extlog_elog_entry_check(int cpu, int bank)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	u64 data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	struct acpi_hest_generic_status *estatus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	WARN_ON(cpu < 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	idx = ELOG_IDX(cpu, bank);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	data = ELOG_ENTRY_DATA(idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	if ((data & ELOG_ENTRY_VALID) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	data &= EXT_ELOG_ENTRY_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	estatus = (struct acpi_hest_generic_status *)ELOG_ENTRY_ADDR(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	/* if no valid data in elog entry, just return */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	if (estatus->block_status == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	return estatus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) static void __print_extlog_rcd(const char *pfx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			       struct acpi_hest_generic_status *estatus, int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	static atomic_t seqno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	unsigned int curr_seqno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	char pfx_seq[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	if (!pfx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		if (estatus->error_severity <= CPER_SEV_CORRECTED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			pfx = KERN_INFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			pfx = KERN_ERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	curr_seqno = atomic_inc_return(&seqno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}", pfx, curr_seqno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	printk("%s""Hardware error detected on CPU%d\n", pfx_seq, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	cper_estatus_print(pfx_seq, estatus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static int print_extlog_rcd(const char *pfx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 			    struct acpi_hest_generic_status *estatus, int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	/* Not more than 2 messages every 5 seconds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	static DEFINE_RATELIMIT_STATE(ratelimit_corrected, 5*HZ, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	static DEFINE_RATELIMIT_STATE(ratelimit_uncorrected, 5*HZ, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	struct ratelimit_state *ratelimit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	if (estatus->error_severity == CPER_SEV_CORRECTED ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	    (estatus->error_severity == CPER_SEV_INFORMATIONAL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		ratelimit = &ratelimit_corrected;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		ratelimit = &ratelimit_uncorrected;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	if (__ratelimit(ratelimit)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		__print_extlog_rcd(pfx, estatus, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) static int extlog_print(struct notifier_block *nb, unsigned long val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 			void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	struct mce *mce = (struct mce *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	int	bank = mce->bank;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	int	cpu = mce->extcpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	struct acpi_hest_generic_status *estatus, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	struct acpi_hest_generic_data *gdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	const guid_t *fru_id = &guid_null;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	char *fru_text = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	guid_t *sec_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	static u32 err_seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	estatus = extlog_elog_entry_check(cpu, bank);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	if (estatus == NULL || (mce->kflags & MCE_HANDLED_CEC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	memcpy(elog_buf, (void *)estatus, ELOG_ENTRY_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	/* clear record status to enable BIOS to update it again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	estatus->block_status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	tmp = (struct acpi_hest_generic_status *)elog_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	if (!ras_userspace_consumers()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		print_extlog_rcd(NULL, tmp, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	/* log event via trace */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	err_seq++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	gdata = (struct acpi_hest_generic_data *)(tmp + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	if (gdata->validation_bits & CPER_SEC_VALID_FRU_ID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		fru_id = (guid_t *)gdata->fru_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	if (gdata->validation_bits & CPER_SEC_VALID_FRU_TEXT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		fru_text = gdata->fru_text;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	sec_type = (guid_t *)gdata->section_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	if (guid_equal(sec_type, &CPER_SEC_PLATFORM_MEM)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		struct cper_sec_mem_err *mem = (void *)(gdata + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		if (gdata->error_data_length >= sizeof(*mem))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 			trace_extlog_mem_event(mem, err_seq, fru_id, fru_text,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 					       (u8)gdata->error_severity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	mce->kflags |= MCE_HANDLED_EXTLOG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	return NOTIFY_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) static bool __init extlog_get_l1addr(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	guid_t guid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	acpi_handle handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	union acpi_object *obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	if (guid_parse(extlog_dsm_uuid, &guid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	if (ACPI_FAILURE(acpi_get_handle(NULL, "\\_SB", &handle)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	if (!acpi_check_dsm(handle, &guid, EXTLOG_DSM_REV, 1 << EXTLOG_FN_ADDR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	obj = acpi_evaluate_dsm_typed(handle, &guid, EXTLOG_DSM_REV,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 				      EXTLOG_FN_ADDR, NULL, ACPI_TYPE_INTEGER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	if (!obj) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		l1_dirbase = obj->integer.value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		ACPI_FREE(obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	/* Spec says L1 directory must be 4K aligned, bail out if it isn't */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	if (l1_dirbase & ((1 << 12) - 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		pr_warn(FW_BUG "L1 Directory is invalid at physical %llx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			l1_dirbase);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) static struct notifier_block extlog_mce_dec = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	.notifier_call	= extlog_print,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	.priority	= MCE_PRIO_EXTLOG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) static int __init extlog_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	struct extlog_l1_head *l1_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	void __iomem *extlog_l1_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	size_t l1_hdr_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	struct resource *r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	u64 cap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	if (rdmsrl_safe(MSR_IA32_MCG_CAP, &cap) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	    !(cap & MCG_ELOG_P) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	    !extlog_get_l1addr())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	/* get L1 header to fetch necessary information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	l1_hdr_size = sizeof(struct extlog_l1_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	r = request_mem_region(l1_dirbase, l1_hdr_size, "L1 DIR HDR");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	if (!r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		pr_warn(FW_BUG EMCA_BUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			(unsigned long long)l1_dirbase,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			(unsigned long long)l1_dirbase + l1_hdr_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	extlog_l1_hdr = acpi_os_map_iomem(l1_dirbase, l1_hdr_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	l1_head = (struct extlog_l1_head *)extlog_l1_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	l1_size = l1_head->total_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	l1_percpu_entry = l1_head->entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	elog_base = l1_head->elog_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	elog_size = l1_head->elog_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	acpi_os_unmap_iomem(extlog_l1_hdr, l1_hdr_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	release_mem_region(l1_dirbase, l1_hdr_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	/* remap L1 header again based on completed information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	r = request_mem_region(l1_dirbase, l1_size, "L1 Table");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	if (!r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		pr_warn(FW_BUG EMCA_BUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 			(unsigned long long)l1_dirbase,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 			(unsigned long long)l1_dirbase + l1_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	extlog_l1_addr = acpi_os_map_iomem(l1_dirbase, l1_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	l1_entry_base = (u64 *)((u8 *)extlog_l1_addr + l1_hdr_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	/* remap elog table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	r = request_mem_region(elog_base, elog_size, "Elog Table");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	if (!r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		pr_warn(FW_BUG EMCA_BUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 			(unsigned long long)elog_base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 			(unsigned long long)elog_base + elog_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		goto err_release_l1_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	elog_addr = acpi_os_map_iomem(elog_base, elog_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	/* allocate buffer to save elog record */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	elog_buf = kmalloc(ELOG_ENTRY_LEN, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	if (elog_buf == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		goto err_release_elog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	mce_register_decode_chain(&extlog_mce_dec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	/* enable OS to be involved to take over management from BIOS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	((struct extlog_l1_head *)extlog_l1_addr)->flags |= FLAG_OS_OPTIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) err_release_elog:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	if (elog_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		acpi_os_unmap_iomem(elog_addr, elog_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	release_mem_region(elog_base, elog_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) err_release_l1_dir:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	if (extlog_l1_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		acpi_os_unmap_iomem(extlog_l1_addr, l1_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	release_mem_region(l1_dirbase, l1_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	pr_warn(FW_BUG "Extended error log disabled because of problems parsing f/w tables\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) static void __exit extlog_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	mce_unregister_decode_chain(&extlog_mce_dec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	((struct extlog_l1_head *)extlog_l1_addr)->flags &= ~FLAG_OS_OPTIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	if (extlog_l1_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		acpi_os_unmap_iomem(extlog_l1_addr, l1_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	if (elog_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		acpi_os_unmap_iomem(elog_addr, elog_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	release_mem_region(elog_base, elog_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	release_mem_region(l1_dirbase, l1_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	kfree(elog_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) module_init(extlog_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) module_exit(extlog_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) MODULE_AUTHOR("Chen, Gong <gong.chen@intel.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) MODULE_DESCRIPTION("Extended MCA Error Log Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) MODULE_LICENSE("GPL");