Skip to content

Commit e1bca85

Browse files
rabarasuryasaimadhu
authored andcommitted
EDAC/altera: Add SDRAM ECC check for U-Boot
A bug in legacy U-Boot causes a crash during SDRAM boot if ECC is not enabled in the bitstream but enabled in the Linux config. Memory mapped read of the ECC Enabled bit was only enabled if U-Boot determined ECC was enabled in the bitstream. The Linux driver checks the ECC enable bit using a memory map read. In the ECC disabled bitstream case, U-Boot didn't enable ECC register memory map reads and since they are not allowed this results in a crash. Always read the ECC Enable register through a SMC call which is always allowed and it works with legacy and current U-Boot. [ bp: Massage commit message. ] Signed-off-by: Rabara Niravkumar L <niravkumar.l.rabara@intel.com> Signed-off-by: Borislav Petkov <bp@suse.de> Acked-by: Dinh Nguyen <dinguyen@kernel.org> Link: https://lore.kernel.org/r/20220305014118.4794-1-niravkumar.l.rabara@intel.com
1 parent b0596da commit e1bca85

1 file changed

Lines changed: 39 additions & 1 deletion

File tree

drivers/edac/altera_edac.c

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,8 +1083,46 @@ static int __init __maybe_unused altr_init_a10_ecc_device_type(char *compat)
10831083

10841084
#ifdef CONFIG_EDAC_ALTERA_SDRAM
10851085

1086+
/*
1087+
* A legacy U-Boot bug only enabled memory mapped access to the ECC Enable
1088+
* register if ECC is enabled. Linux checks the ECC Enable register to
1089+
* determine ECC status.
1090+
* Use an SMC call (which always works) to determine ECC enablement.
1091+
*/
1092+
static int altr_s10_sdram_check_ecc_deps(struct altr_edac_device_dev *device)
1093+
{
1094+
const struct edac_device_prv_data *prv = device->data;
1095+
unsigned long sdram_ecc_addr;
1096+
struct arm_smccc_res result;
1097+
struct device_node *np;
1098+
phys_addr_t sdram_addr;
1099+
u32 read_reg;
1100+
int ret;
1101+
1102+
np = of_find_compatible_node(NULL, NULL, "altr,sdr-ctl");
1103+
if (!np)
1104+
goto sdram_err;
1105+
1106+
sdram_addr = of_translate_address(np, of_get_address(np, 0,
1107+
NULL, NULL));
1108+
of_node_put(np);
1109+
sdram_ecc_addr = (unsigned long)sdram_addr + prv->ecc_en_ofst;
1110+
arm_smccc_smc(INTEL_SIP_SMC_REG_READ, sdram_ecc_addr,
1111+
0, 0, 0, 0, 0, 0, &result);
1112+
read_reg = (unsigned int)result.a1;
1113+
ret = (int)result.a0;
1114+
if (!ret && (read_reg & prv->ecc_enable_mask))
1115+
return 0;
1116+
1117+
sdram_err:
1118+
edac_printk(KERN_ERR, EDAC_DEVICE,
1119+
"%s: No ECC present or ECC disabled.\n",
1120+
device->edac_dev_name);
1121+
return -ENODEV;
1122+
}
1123+
10861124
static const struct edac_device_prv_data s10_sdramecc_data = {
1087-
.setup = altr_check_ecc_deps,
1125+
.setup = altr_s10_sdram_check_ecc_deps,
10881126
.ce_clear_mask = ALTR_S10_ECC_SERRPENA,
10891127
.ue_clear_mask = ALTR_S10_ECC_DERRPENA,
10901128
.ecc_enable_mask = ALTR_S10_ECC_EN,

0 commit comments

Comments
 (0)