Thor Thayer | 3dab6bd | 2018-04-27 13:37:17 -0500 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 2 | /* |
Thor Thayer | 3dab6bd | 2018-04-27 13:37:17 -0500 | [diff] [blame] | 3 | * Copyright (C) 2017-2018, Intel Corporation. All rights reserved |
Thor Thayer | c3eea19 | 2016-02-10 13:26:21 -0600 | [diff] [blame] | 4 | * Copyright Altera Corporation (C) 2014-2016. All rights reserved. |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 5 | * Copyright 2011-2012 Calxeda, Inc. |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 6 | */ |
| 7 | |
Thor Thayer | c3eea19 | 2016-02-10 13:26:21 -0600 | [diff] [blame] | 8 | #include <asm/cacheflush.h> |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 9 | #include <linux/ctype.h> |
Thor Thayer | 1166fde9 | 2016-06-22 08:58:57 -0500 | [diff] [blame] | 10 | #include <linux/delay.h> |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 11 | #include <linux/edac.h> |
Thor Thayer | fad9fab | 2019-04-02 17:40:56 +0200 | [diff] [blame] | 12 | #include <linux/firmware/intel/stratix10-smc.h> |
Thor Thayer | c3eea19 | 2016-02-10 13:26:21 -0600 | [diff] [blame] | 13 | #include <linux/genalloc.h> |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 14 | #include <linux/interrupt.h> |
Thor Thayer | 13ab844 | 2016-06-07 15:35:57 -0500 | [diff] [blame] | 15 | #include <linux/irqchip/chained_irq.h> |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 16 | #include <linux/kernel.h> |
| 17 | #include <linux/mfd/syscon.h> |
Thor Thayer | e9918d7 | 2018-05-11 18:00:10 -0500 | [diff] [blame] | 18 | #include <linux/notifier.h> |
Thor Thayer | 588cb03 | 2016-03-21 11:01:44 -0500 | [diff] [blame] | 19 | #include <linux/of_address.h> |
Thor Thayer | 13ab844 | 2016-06-07 15:35:57 -0500 | [diff] [blame] | 20 | #include <linux/of_irq.h> |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 21 | #include <linux/of_platform.h> |
| 22 | #include <linux/platform_device.h> |
| 23 | #include <linux/regmap.h> |
| 24 | #include <linux/types.h> |
| 25 | #include <linux/uaccess.h> |
| 26 | |
Thor Thayer | 143f4a5 | 2015-06-04 09:28:46 -0500 | [diff] [blame] | 27 | #include "altera_edac.h" |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 28 | #include "edac_module.h" |
| 29 | |
| 30 | #define EDAC_MOD_STR "altera_edac" |
Thor Thayer | c3eea19 | 2016-02-10 13:26:21 -0600 | [diff] [blame] | 31 | #define EDAC_DEVICE "Altera" |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 32 | |
Thor Thayer | 580b5cf | 2019-02-25 12:56:45 -0600 | [diff] [blame] | 33 | #ifdef CONFIG_EDAC_ALTERA_SDRAM |
Thor Thayer | 143f4a5 | 2015-06-04 09:28:46 -0500 | [diff] [blame] | 34 | static const struct altr_sdram_prv_data c5_data = { |
| 35 | .ecc_ctrl_offset = CV_CTLCFG_OFST, |
| 36 | .ecc_ctl_en_mask = CV_CTLCFG_ECC_AUTO_EN, |
| 37 | .ecc_stat_offset = CV_DRAMSTS_OFST, |
| 38 | .ecc_stat_ce_mask = CV_DRAMSTS_SBEERR, |
| 39 | .ecc_stat_ue_mask = CV_DRAMSTS_DBEERR, |
| 40 | .ecc_saddr_offset = CV_ERRADDR_OFST, |
Thor Thayer | 73bcc94 | 2015-06-04 09:28:47 -0500 | [diff] [blame] | 41 | .ecc_daddr_offset = CV_ERRADDR_OFST, |
Thor Thayer | 143f4a5 | 2015-06-04 09:28:46 -0500 | [diff] [blame] | 42 | .ecc_cecnt_offset = CV_SBECOUNT_OFST, |
| 43 | .ecc_uecnt_offset = CV_DBECOUNT_OFST, |
| 44 | .ecc_irq_en_offset = CV_DRAMINTR_OFST, |
| 45 | .ecc_irq_en_mask = CV_DRAMINTR_INTREN, |
| 46 | .ecc_irq_clr_offset = CV_DRAMINTR_OFST, |
| 47 | .ecc_irq_clr_mask = (CV_DRAMINTR_INTRCLR | CV_DRAMINTR_INTREN), |
| 48 | .ecc_cnt_rst_offset = CV_DRAMINTR_OFST, |
| 49 | .ecc_cnt_rst_mask = CV_DRAMINTR_INTRCLR, |
Thor Thayer | 143f4a5 | 2015-06-04 09:28:46 -0500 | [diff] [blame] | 50 | .ce_ue_trgr_offset = CV_CTLCFG_OFST, |
| 51 | .ce_set_mask = CV_CTLCFG_GEN_SB_ERR, |
| 52 | .ue_set_mask = CV_CTLCFG_GEN_DB_ERR, |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 53 | }; |
| 54 | |
Thor Thayer | 73bcc94 | 2015-06-04 09:28:47 -0500 | [diff] [blame] | 55 | static const struct altr_sdram_prv_data a10_data = { |
| 56 | .ecc_ctrl_offset = A10_ECCCTRL1_OFST, |
| 57 | .ecc_ctl_en_mask = A10_ECCCTRL1_ECC_EN, |
| 58 | .ecc_stat_offset = A10_INTSTAT_OFST, |
| 59 | .ecc_stat_ce_mask = A10_INTSTAT_SBEERR, |
| 60 | .ecc_stat_ue_mask = A10_INTSTAT_DBEERR, |
| 61 | .ecc_saddr_offset = A10_SERRADDR_OFST, |
| 62 | .ecc_daddr_offset = A10_DERRADDR_OFST, |
| 63 | .ecc_irq_en_offset = A10_ERRINTEN_OFST, |
| 64 | .ecc_irq_en_mask = A10_ECC_IRQ_EN_MASK, |
| 65 | .ecc_irq_clr_offset = A10_INTSTAT_OFST, |
| 66 | .ecc_irq_clr_mask = (A10_INTSTAT_SBEERR | A10_INTSTAT_DBEERR), |
| 67 | .ecc_cnt_rst_offset = A10_ECCCTRL1_OFST, |
| 68 | .ecc_cnt_rst_mask = A10_ECC_CNT_RESET_MASK, |
Thor Thayer | 73bcc94 | 2015-06-04 09:28:47 -0500 | [diff] [blame] | 69 | .ce_ue_trgr_offset = A10_DIAGINTTEST_OFST, |
| 70 | .ce_set_mask = A10_DIAGINT_TSERRA_MASK, |
| 71 | .ue_set_mask = A10_DIAGINT_TDERRA_MASK, |
Thor Thayer | 73bcc94 | 2015-06-04 09:28:47 -0500 | [diff] [blame] | 72 | }; |
| 73 | |
Thor Thayer | c3eea19 | 2016-02-10 13:26:21 -0600 | [diff] [blame] | 74 | /*********************** EDAC Memory Controller Functions ****************/ |
| 75 | |
| 76 | /* The SDRAM controller uses the EDAC Memory Controller framework. */ |
| 77 | |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 78 | static irqreturn_t altr_sdram_mc_err_handler(int irq, void *dev_id) |
| 79 | { |
| 80 | struct mem_ctl_info *mci = dev_id; |
| 81 | struct altr_sdram_mc_data *drvdata = mci->pvt_info; |
Thor Thayer | 143f4a5 | 2015-06-04 09:28:46 -0500 | [diff] [blame] | 82 | const struct altr_sdram_prv_data *priv = drvdata->data; |
Thor Thayer | 73bcc94 | 2015-06-04 09:28:47 -0500 | [diff] [blame] | 83 | u32 status, err_count = 1, err_addr; |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 84 | |
Thor Thayer | 143f4a5 | 2015-06-04 09:28:46 -0500 | [diff] [blame] | 85 | regmap_read(drvdata->mc_vbase, priv->ecc_stat_offset, &status); |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 86 | |
Thor Thayer | 143f4a5 | 2015-06-04 09:28:46 -0500 | [diff] [blame] | 87 | if (status & priv->ecc_stat_ue_mask) { |
Thor Thayer | 73bcc94 | 2015-06-04 09:28:47 -0500 | [diff] [blame] | 88 | regmap_read(drvdata->mc_vbase, priv->ecc_daddr_offset, |
| 89 | &err_addr); |
| 90 | if (priv->ecc_uecnt_offset) |
| 91 | regmap_read(drvdata->mc_vbase, priv->ecc_uecnt_offset, |
| 92 | &err_count); |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 93 | panic("\nEDAC: [%d Uncorrectable errors @ 0x%08X]\n", |
| 94 | err_count, err_addr); |
| 95 | } |
Thor Thayer | 143f4a5 | 2015-06-04 09:28:46 -0500 | [diff] [blame] | 96 | if (status & priv->ecc_stat_ce_mask) { |
Thor Thayer | 73bcc94 | 2015-06-04 09:28:47 -0500 | [diff] [blame] | 97 | regmap_read(drvdata->mc_vbase, priv->ecc_saddr_offset, |
| 98 | &err_addr); |
| 99 | if (priv->ecc_uecnt_offset) |
| 100 | regmap_read(drvdata->mc_vbase, priv->ecc_cecnt_offset, |
| 101 | &err_count); |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 102 | edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, err_count, |
| 103 | err_addr >> PAGE_SHIFT, |
| 104 | err_addr & ~PAGE_MASK, 0, |
| 105 | 0, 0, -1, mci->ctl_name, ""); |
Thor Thayer | 73bcc94 | 2015-06-04 09:28:47 -0500 | [diff] [blame] | 106 | /* Clear IRQ to resume */ |
| 107 | regmap_write(drvdata->mc_vbase, priv->ecc_irq_clr_offset, |
| 108 | priv->ecc_irq_clr_mask); |
| 109 | |
| 110 | return IRQ_HANDLED; |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 111 | } |
Thor Thayer | 73bcc94 | 2015-06-04 09:28:47 -0500 | [diff] [blame] | 112 | return IRQ_NONE; |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 113 | } |
| 114 | |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 115 | static ssize_t altr_sdr_mc_err_inject_write(struct file *file, |
| 116 | const char __user *data, |
| 117 | size_t count, loff_t *ppos) |
| 118 | { |
| 119 | struct mem_ctl_info *mci = file->private_data; |
| 120 | struct altr_sdram_mc_data *drvdata = mci->pvt_info; |
Thor Thayer | 143f4a5 | 2015-06-04 09:28:46 -0500 | [diff] [blame] | 121 | const struct altr_sdram_prv_data *priv = drvdata->data; |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 122 | u32 *ptemp; |
| 123 | dma_addr_t dma_handle; |
| 124 | u32 reg, read_reg; |
| 125 | |
| 126 | ptemp = dma_alloc_coherent(mci->pdev, 16, &dma_handle, GFP_KERNEL); |
| 127 | if (!ptemp) { |
| 128 | dma_free_coherent(mci->pdev, 16, ptemp, dma_handle); |
| 129 | edac_printk(KERN_ERR, EDAC_MC, |
| 130 | "Inject: Buffer Allocation error\n"); |
| 131 | return -ENOMEM; |
| 132 | } |
| 133 | |
Thor Thayer | 143f4a5 | 2015-06-04 09:28:46 -0500 | [diff] [blame] | 134 | regmap_read(drvdata->mc_vbase, priv->ce_ue_trgr_offset, |
| 135 | &read_reg); |
| 136 | read_reg &= ~(priv->ce_set_mask | priv->ue_set_mask); |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 137 | |
| 138 | /* Error are injected by writing a word while the SBE or DBE |
| 139 | * bit in the CTLCFG register is set. Reading the word will |
| 140 | * trigger the SBE or DBE error and the corresponding IRQ. |
| 141 | */ |
| 142 | if (count == 3) { |
| 143 | edac_printk(KERN_ALERT, EDAC_MC, |
| 144 | "Inject Double bit error\n"); |
Thor Thayer | 90e493d | 2016-10-19 14:53:47 -0500 | [diff] [blame] | 145 | local_irq_disable(); |
Thor Thayer | 143f4a5 | 2015-06-04 09:28:46 -0500 | [diff] [blame] | 146 | regmap_write(drvdata->mc_vbase, priv->ce_ue_trgr_offset, |
| 147 | (read_reg | priv->ue_set_mask)); |
Thor Thayer | 90e493d | 2016-10-19 14:53:47 -0500 | [diff] [blame] | 148 | local_irq_enable(); |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 149 | } else { |
| 150 | edac_printk(KERN_ALERT, EDAC_MC, |
| 151 | "Inject Single bit error\n"); |
Thor Thayer | 90e493d | 2016-10-19 14:53:47 -0500 | [diff] [blame] | 152 | local_irq_disable(); |
Thor Thayer | 143f4a5 | 2015-06-04 09:28:46 -0500 | [diff] [blame] | 153 | regmap_write(drvdata->mc_vbase, priv->ce_ue_trgr_offset, |
| 154 | (read_reg | priv->ce_set_mask)); |
Thor Thayer | 90e493d | 2016-10-19 14:53:47 -0500 | [diff] [blame] | 155 | local_irq_enable(); |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | ptemp[0] = 0x5A5A5A5A; |
| 159 | ptemp[1] = 0xA5A5A5A5; |
| 160 | |
| 161 | /* Clear the error injection bits */ |
Thor Thayer | 143f4a5 | 2015-06-04 09:28:46 -0500 | [diff] [blame] | 162 | regmap_write(drvdata->mc_vbase, priv->ce_ue_trgr_offset, read_reg); |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 163 | /* Ensure it has been written out */ |
| 164 | wmb(); |
| 165 | |
| 166 | /* |
| 167 | * To trigger the error, we need to read the data back |
| 168 | * (the data was written with errors above). |
Mark Rutland | 332efa6 | 2017-10-23 14:07:12 -0700 | [diff] [blame] | 169 | * The READ_ONCE macros and printk are used to prevent the |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 170 | * the compiler optimizing these reads out. |
| 171 | */ |
Mark Rutland | 332efa6 | 2017-10-23 14:07:12 -0700 | [diff] [blame] | 172 | reg = READ_ONCE(ptemp[0]); |
| 173 | read_reg = READ_ONCE(ptemp[1]); |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 174 | /* Force Read */ |
| 175 | rmb(); |
| 176 | |
| 177 | edac_printk(KERN_ALERT, EDAC_MC, "Read Data [0x%X, 0x%X]\n", |
| 178 | reg, read_reg); |
| 179 | |
| 180 | dma_free_coherent(mci->pdev, 16, ptemp, dma_handle); |
| 181 | |
| 182 | return count; |
| 183 | } |
| 184 | |
| 185 | static const struct file_operations altr_sdr_mc_debug_inject_fops = { |
| 186 | .open = simple_open, |
| 187 | .write = altr_sdr_mc_err_inject_write, |
| 188 | .llseek = generic_file_llseek, |
| 189 | }; |
| 190 | |
| 191 | static void altr_sdr_mc_create_debugfs_nodes(struct mem_ctl_info *mci) |
| 192 | { |
Borislav Petkov | bba3b31 | 2015-09-22 12:27:29 +0200 | [diff] [blame] | 193 | if (!IS_ENABLED(CONFIG_EDAC_DEBUG)) |
| 194 | return; |
| 195 | |
| 196 | if (!mci->debugfs) |
| 197 | return; |
| 198 | |
Thor Thayer | b8978ba | 2016-08-19 11:04:26 -0500 | [diff] [blame] | 199 | edac_debugfs_create_file("altr_trigger", S_IWUSR, mci->debugfs, mci, |
Borislav Petkov | bba3b31 | 2015-09-22 12:27:29 +0200 | [diff] [blame] | 200 | &altr_sdr_mc_debug_inject_fops); |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 201 | } |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 202 | |
Thor Thayer | f9ae487 | 2015-06-04 09:28:45 -0500 | [diff] [blame] | 203 | /* Get total memory size from Open Firmware DTB */ |
| 204 | static unsigned long get_total_mem(void) |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 205 | { |
Thor Thayer | f9ae487 | 2015-06-04 09:28:45 -0500 | [diff] [blame] | 206 | struct device_node *np = NULL; |
Chris Packham | ff0abed | 2017-06-07 11:54:59 +1200 | [diff] [blame] | 207 | struct resource res; |
| 208 | int ret; |
| 209 | unsigned long total_mem = 0; |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 210 | |
Thor Thayer | f9ae487 | 2015-06-04 09:28:45 -0500 | [diff] [blame] | 211 | for_each_node_by_type(np, "memory") { |
Chris Packham | ff0abed | 2017-06-07 11:54:59 +1200 | [diff] [blame] | 212 | ret = of_address_to_resource(np, 0, &res); |
| 213 | if (ret) |
| 214 | continue; |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 215 | |
Chris Packham | ff0abed | 2017-06-07 11:54:59 +1200 | [diff] [blame] | 216 | total_mem += resource_size(&res); |
Thor Thayer | f9ae487 | 2015-06-04 09:28:45 -0500 | [diff] [blame] | 217 | } |
| 218 | edac_dbg(0, "total_mem 0x%lx\n", total_mem); |
| 219 | return total_mem; |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 220 | } |
| 221 | |
Thor Thayer | 143f4a5 | 2015-06-04 09:28:46 -0500 | [diff] [blame] | 222 | static const struct of_device_id altr_sdram_ctrl_of_match[] = { |
Arnd Bergmann | 2c911f6 | 2016-04-16 22:13:55 +0200 | [diff] [blame] | 223 | { .compatible = "altr,sdram-edac", .data = &c5_data}, |
| 224 | { .compatible = "altr,sdram-edac-a10", .data = &a10_data}, |
Thor Thayer | 143f4a5 | 2015-06-04 09:28:46 -0500 | [diff] [blame] | 225 | {}, |
| 226 | }; |
| 227 | MODULE_DEVICE_TABLE(of, altr_sdram_ctrl_of_match); |
| 228 | |
Thor Thayer | 73bcc94 | 2015-06-04 09:28:47 -0500 | [diff] [blame] | 229 | static int a10_init(struct regmap *mc_vbase) |
| 230 | { |
| 231 | if (regmap_update_bits(mc_vbase, A10_INTMODE_OFST, |
| 232 | A10_INTMODE_SB_INT, A10_INTMODE_SB_INT)) { |
| 233 | edac_printk(KERN_ERR, EDAC_MC, |
| 234 | "Error setting SB IRQ mode\n"); |
| 235 | return -ENODEV; |
| 236 | } |
| 237 | |
| 238 | if (regmap_write(mc_vbase, A10_SERRCNTREG_OFST, 1)) { |
| 239 | edac_printk(KERN_ERR, EDAC_MC, |
| 240 | "Error setting trigger count\n"); |
| 241 | return -ENODEV; |
| 242 | } |
| 243 | |
| 244 | return 0; |
| 245 | } |
| 246 | |
| 247 | static int a10_unmask_irq(struct platform_device *pdev, u32 mask) |
| 248 | { |
| 249 | void __iomem *sm_base; |
| 250 | int ret = 0; |
| 251 | |
| 252 | if (!request_mem_region(A10_SYMAN_INTMASK_CLR, sizeof(u32), |
| 253 | dev_name(&pdev->dev))) { |
| 254 | edac_printk(KERN_ERR, EDAC_MC, |
| 255 | "Unable to request mem region\n"); |
| 256 | return -EBUSY; |
| 257 | } |
| 258 | |
| 259 | sm_base = ioremap(A10_SYMAN_INTMASK_CLR, sizeof(u32)); |
| 260 | if (!sm_base) { |
| 261 | edac_printk(KERN_ERR, EDAC_MC, |
| 262 | "Unable to ioremap device\n"); |
| 263 | |
| 264 | ret = -ENOMEM; |
| 265 | goto release; |
| 266 | } |
| 267 | |
| 268 | iowrite32(mask, sm_base); |
| 269 | |
| 270 | iounmap(sm_base); |
| 271 | |
| 272 | release: |
| 273 | release_mem_region(A10_SYMAN_INTMASK_CLR, sizeof(u32)); |
| 274 | |
| 275 | return ret; |
| 276 | } |
| 277 | |
Thor Thayer | 08f08bf | 2018-09-25 08:49:00 -0500 | [diff] [blame] | 278 | static int socfpga_is_a10(void); |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 279 | static int altr_sdram_probe(struct platform_device *pdev) |
| 280 | { |
Thor Thayer | 143f4a5 | 2015-06-04 09:28:46 -0500 | [diff] [blame] | 281 | const struct of_device_id *id; |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 282 | struct edac_mc_layer layers[2]; |
| 283 | struct mem_ctl_info *mci; |
| 284 | struct altr_sdram_mc_data *drvdata; |
Thor Thayer | 143f4a5 | 2015-06-04 09:28:46 -0500 | [diff] [blame] | 285 | const struct altr_sdram_prv_data *priv; |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 286 | struct regmap *mc_vbase; |
| 287 | struct dimm_info *dimm; |
Thor Thayer | 143f4a5 | 2015-06-04 09:28:46 -0500 | [diff] [blame] | 288 | u32 read_reg; |
Thor Thayer | 73bcc94 | 2015-06-04 09:28:47 -0500 | [diff] [blame] | 289 | int irq, irq2, res = 0; |
| 290 | unsigned long mem_size, irqflags = 0; |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 291 | |
Thor Thayer | 143f4a5 | 2015-06-04 09:28:46 -0500 | [diff] [blame] | 292 | id = of_match_device(altr_sdram_ctrl_of_match, &pdev->dev); |
| 293 | if (!id) |
| 294 | return -ENODEV; |
| 295 | |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 296 | /* Grab the register range from the sdr controller in device tree */ |
| 297 | mc_vbase = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, |
| 298 | "altr,sdr-syscon"); |
| 299 | if (IS_ERR(mc_vbase)) { |
| 300 | edac_printk(KERN_ERR, EDAC_MC, |
| 301 | "regmap for altr,sdr-syscon lookup failed.\n"); |
| 302 | return -ENODEV; |
| 303 | } |
| 304 | |
Thor Thayer | 143f4a5 | 2015-06-04 09:28:46 -0500 | [diff] [blame] | 305 | /* Check specific dependencies for the module */ |
| 306 | priv = of_match_node(altr_sdram_ctrl_of_match, |
| 307 | pdev->dev.of_node)->data; |
| 308 | |
| 309 | /* Validate the SDRAM controller has ECC enabled */ |
| 310 | if (regmap_read(mc_vbase, priv->ecc_ctrl_offset, &read_reg) || |
| 311 | ((read_reg & priv->ecc_ctl_en_mask) != priv->ecc_ctl_en_mask)) { |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 312 | edac_printk(KERN_ERR, EDAC_MC, |
| 313 | "No ECC/ECC disabled [0x%08X]\n", read_reg); |
| 314 | return -ENODEV; |
| 315 | } |
| 316 | |
| 317 | /* Grab memory size from device tree. */ |
Thor Thayer | f9ae487 | 2015-06-04 09:28:45 -0500 | [diff] [blame] | 318 | mem_size = get_total_mem(); |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 319 | if (!mem_size) { |
Thor Thayer | f9ae487 | 2015-06-04 09:28:45 -0500 | [diff] [blame] | 320 | edac_printk(KERN_ERR, EDAC_MC, "Unable to calculate memory size\n"); |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 321 | return -ENODEV; |
| 322 | } |
| 323 | |
Thor Thayer | 143f4a5 | 2015-06-04 09:28:46 -0500 | [diff] [blame] | 324 | /* Ensure the SDRAM Interrupt is disabled */ |
| 325 | if (regmap_update_bits(mc_vbase, priv->ecc_irq_en_offset, |
| 326 | priv->ecc_irq_en_mask, 0)) { |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 327 | edac_printk(KERN_ERR, EDAC_MC, |
Thor Thayer | 143f4a5 | 2015-06-04 09:28:46 -0500 | [diff] [blame] | 328 | "Error disabling SDRAM ECC IRQ\n"); |
| 329 | return -ENODEV; |
| 330 | } |
| 331 | |
| 332 | /* Toggle to clear the SDRAM Error count */ |
| 333 | if (regmap_update_bits(mc_vbase, priv->ecc_cnt_rst_offset, |
| 334 | priv->ecc_cnt_rst_mask, |
| 335 | priv->ecc_cnt_rst_mask)) { |
| 336 | edac_printk(KERN_ERR, EDAC_MC, |
| 337 | "Error clearing SDRAM ECC count\n"); |
| 338 | return -ENODEV; |
| 339 | } |
| 340 | |
| 341 | if (regmap_update_bits(mc_vbase, priv->ecc_cnt_rst_offset, |
| 342 | priv->ecc_cnt_rst_mask, 0)) { |
| 343 | edac_printk(KERN_ERR, EDAC_MC, |
| 344 | "Error clearing SDRAM ECC count\n"); |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 345 | return -ENODEV; |
| 346 | } |
| 347 | |
| 348 | irq = platform_get_irq(pdev, 0); |
| 349 | if (irq < 0) { |
| 350 | edac_printk(KERN_ERR, EDAC_MC, |
| 351 | "No irq %d in DT\n", irq); |
| 352 | return -ENODEV; |
| 353 | } |
| 354 | |
Thor Thayer | 73bcc94 | 2015-06-04 09:28:47 -0500 | [diff] [blame] | 355 | /* Arria10 has a 2nd IRQ */ |
| 356 | irq2 = platform_get_irq(pdev, 1); |
| 357 | |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 358 | layers[0].type = EDAC_MC_LAYER_CHIP_SELECT; |
| 359 | layers[0].size = 1; |
| 360 | layers[0].is_virt_csrow = true; |
| 361 | layers[1].type = EDAC_MC_LAYER_CHANNEL; |
| 362 | layers[1].size = 1; |
| 363 | layers[1].is_virt_csrow = false; |
| 364 | mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers, |
| 365 | sizeof(struct altr_sdram_mc_data)); |
| 366 | if (!mci) |
| 367 | return -ENOMEM; |
| 368 | |
| 369 | mci->pdev = &pdev->dev; |
| 370 | drvdata = mci->pvt_info; |
| 371 | drvdata->mc_vbase = mc_vbase; |
Thor Thayer | 143f4a5 | 2015-06-04 09:28:46 -0500 | [diff] [blame] | 372 | drvdata->data = priv; |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 373 | platform_set_drvdata(pdev, mci); |
| 374 | |
| 375 | if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL)) { |
Thor Thayer | 143f4a5 | 2015-06-04 09:28:46 -0500 | [diff] [blame] | 376 | edac_printk(KERN_ERR, EDAC_MC, |
| 377 | "Unable to get managed device resource\n"); |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 378 | res = -ENOMEM; |
| 379 | goto free; |
| 380 | } |
| 381 | |
| 382 | mci->mtype_cap = MEM_FLAG_DDR3; |
| 383 | mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_SECDED; |
| 384 | mci->edac_cap = EDAC_FLAG_SECDED; |
| 385 | mci->mod_name = EDAC_MOD_STR; |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 386 | mci->ctl_name = dev_name(&pdev->dev); |
| 387 | mci->scrub_mode = SCRUB_SW_SRC; |
| 388 | mci->dev_name = dev_name(&pdev->dev); |
| 389 | |
| 390 | dimm = *mci->dimms; |
| 391 | dimm->nr_pages = ((mem_size - 1) >> PAGE_SHIFT) + 1; |
| 392 | dimm->grain = 8; |
| 393 | dimm->dtype = DEV_X8; |
| 394 | dimm->mtype = MEM_DDR3; |
| 395 | dimm->edac_mode = EDAC_SECDED; |
| 396 | |
| 397 | res = edac_mc_add_mc(mci); |
| 398 | if (res < 0) |
| 399 | goto err; |
| 400 | |
Thor Thayer | 73bcc94 | 2015-06-04 09:28:47 -0500 | [diff] [blame] | 401 | /* Only the Arria10 has separate IRQs */ |
Thor Thayer | 08f08bf | 2018-09-25 08:49:00 -0500 | [diff] [blame] | 402 | if (socfpga_is_a10()) { |
Thor Thayer | 73bcc94 | 2015-06-04 09:28:47 -0500 | [diff] [blame] | 403 | /* Arria10 specific initialization */ |
| 404 | res = a10_init(mc_vbase); |
| 405 | if (res < 0) |
| 406 | goto err2; |
| 407 | |
| 408 | res = devm_request_irq(&pdev->dev, irq2, |
| 409 | altr_sdram_mc_err_handler, |
| 410 | IRQF_SHARED, dev_name(&pdev->dev), mci); |
| 411 | if (res < 0) { |
| 412 | edac_mc_printk(mci, KERN_ERR, |
| 413 | "Unable to request irq %d\n", irq2); |
| 414 | res = -ENODEV; |
| 415 | goto err2; |
| 416 | } |
| 417 | |
| 418 | res = a10_unmask_irq(pdev, A10_DDR0_IRQ_MASK); |
| 419 | if (res < 0) |
| 420 | goto err2; |
| 421 | |
| 422 | irqflags = IRQF_SHARED; |
| 423 | } |
| 424 | |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 425 | res = devm_request_irq(&pdev->dev, irq, altr_sdram_mc_err_handler, |
Thor Thayer | 73bcc94 | 2015-06-04 09:28:47 -0500 | [diff] [blame] | 426 | irqflags, dev_name(&pdev->dev), mci); |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 427 | if (res < 0) { |
| 428 | edac_mc_printk(mci, KERN_ERR, |
| 429 | "Unable to request irq %d\n", irq); |
| 430 | res = -ENODEV; |
| 431 | goto err2; |
| 432 | } |
| 433 | |
Thor Thayer | 143f4a5 | 2015-06-04 09:28:46 -0500 | [diff] [blame] | 434 | /* Infrastructure ready - enable the IRQ */ |
| 435 | if (regmap_update_bits(drvdata->mc_vbase, priv->ecc_irq_en_offset, |
| 436 | priv->ecc_irq_en_mask, priv->ecc_irq_en_mask)) { |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 437 | edac_mc_printk(mci, KERN_ERR, |
| 438 | "Error enabling SDRAM ECC IRQ\n"); |
| 439 | res = -ENODEV; |
| 440 | goto err2; |
| 441 | } |
| 442 | |
| 443 | altr_sdr_mc_create_debugfs_nodes(mci); |
| 444 | |
| 445 | devres_close_group(&pdev->dev, NULL); |
| 446 | |
| 447 | return 0; |
| 448 | |
| 449 | err2: |
| 450 | edac_mc_del_mc(&pdev->dev); |
| 451 | err: |
| 452 | devres_release_group(&pdev->dev, NULL); |
| 453 | free: |
| 454 | edac_mc_free(mci); |
| 455 | edac_printk(KERN_ERR, EDAC_MC, |
| 456 | "EDAC Probe Failed; Error %d\n", res); |
| 457 | |
| 458 | return res; |
| 459 | } |
| 460 | |
| 461 | static int altr_sdram_remove(struct platform_device *pdev) |
| 462 | { |
| 463 | struct mem_ctl_info *mci = platform_get_drvdata(pdev); |
| 464 | |
| 465 | edac_mc_del_mc(&pdev->dev); |
| 466 | edac_mc_free(mci); |
| 467 | platform_set_drvdata(pdev, NULL); |
| 468 | |
| 469 | return 0; |
| 470 | } |
| 471 | |
Thor Thayer | 580b5cf | 2019-02-25 12:56:45 -0600 | [diff] [blame] | 472 | /* |
| 473 | * If you want to suspend, need to disable EDAC by removing it |
| 474 | * from the device tree or defconfig. |
| 475 | */ |
| 476 | #ifdef CONFIG_PM |
| 477 | static int altr_sdram_prepare(struct device *dev) |
| 478 | { |
| 479 | pr_err("Suspend not allowed when EDAC is enabled.\n"); |
| 480 | |
| 481 | return -EPERM; |
| 482 | } |
| 483 | |
| 484 | static const struct dev_pm_ops altr_sdram_pm_ops = { |
| 485 | .prepare = altr_sdram_prepare, |
| 486 | }; |
| 487 | #endif |
| 488 | |
| 489 | static struct platform_driver altr_sdram_edac_driver = { |
| 490 | .probe = altr_sdram_probe, |
| 491 | .remove = altr_sdram_remove, |
| 492 | .driver = { |
| 493 | .name = "altr_sdram_edac", |
| 494 | #ifdef CONFIG_PM |
| 495 | .pm = &altr_sdram_pm_ops, |
| 496 | #endif |
| 497 | .of_match_table = altr_sdram_ctrl_of_match, |
| 498 | }, |
| 499 | }; |
| 500 | |
| 501 | module_platform_driver(altr_sdram_edac_driver); |
| 502 | |
| 503 | #endif /* CONFIG_EDAC_ALTERA_SDRAM */ |
| 504 | |
Thor Thayer | 3dab6bd | 2018-04-27 13:37:17 -0500 | [diff] [blame] | 505 | /**************** Stratix 10 EDAC Memory Controller Functions ************/ |
| 506 | |
| 507 | /** |
| 508 | * s10_protected_reg_write |
| 509 | * Write to a protected SMC register. |
| 510 | * @context: Not used. |
| 511 | * @reg: Address of register |
| 512 | * @value: Value to write |
| 513 | * Return: INTEL_SIP_SMC_STATUS_OK (0) on success |
| 514 | * INTEL_SIP_SMC_REG_ERROR on error |
| 515 | * INTEL_SIP_SMC_RETURN_UNKNOWN_FUNCTION if not supported |
| 516 | */ |
| 517 | static int s10_protected_reg_write(void *context, unsigned int reg, |
| 518 | unsigned int val) |
| 519 | { |
| 520 | struct arm_smccc_res result; |
Thor Thayer | 08f08bf | 2018-09-25 08:49:00 -0500 | [diff] [blame] | 521 | unsigned long offset = (unsigned long)context; |
Thor Thayer | 3dab6bd | 2018-04-27 13:37:17 -0500 | [diff] [blame] | 522 | |
Thor Thayer | 08f08bf | 2018-09-25 08:49:00 -0500 | [diff] [blame] | 523 | arm_smccc_smc(INTEL_SIP_SMC_REG_WRITE, offset + reg, val, 0, 0, |
Thor Thayer | 3dab6bd | 2018-04-27 13:37:17 -0500 | [diff] [blame] | 524 | 0, 0, 0, &result); |
| 525 | |
| 526 | return (int)result.a0; |
| 527 | } |
| 528 | |
| 529 | /** |
| 530 | * s10_protected_reg_read |
| 531 | * Read the status of a protected SMC register |
| 532 | * @context: Not used. |
| 533 | * @reg: Address of register |
| 534 | * @value: Value read. |
| 535 | * Return: INTEL_SIP_SMC_STATUS_OK (0) on success |
| 536 | * INTEL_SIP_SMC_REG_ERROR on error |
| 537 | * INTEL_SIP_SMC_RETURN_UNKNOWN_FUNCTION if not supported |
| 538 | */ |
| 539 | static int s10_protected_reg_read(void *context, unsigned int reg, |
| 540 | unsigned int *val) |
| 541 | { |
| 542 | struct arm_smccc_res result; |
Thor Thayer | 08f08bf | 2018-09-25 08:49:00 -0500 | [diff] [blame] | 543 | unsigned long offset = (unsigned long)context; |
Thor Thayer | 3dab6bd | 2018-04-27 13:37:17 -0500 | [diff] [blame] | 544 | |
Thor Thayer | 08f08bf | 2018-09-25 08:49:00 -0500 | [diff] [blame] | 545 | arm_smccc_smc(INTEL_SIP_SMC_REG_READ, offset + reg, 0, 0, 0, |
Thor Thayer | 3dab6bd | 2018-04-27 13:37:17 -0500 | [diff] [blame] | 546 | 0, 0, 0, &result); |
| 547 | |
| 548 | *val = (unsigned int)result.a1; |
| 549 | |
| 550 | return (int)result.a0; |
| 551 | } |
| 552 | |
Thor Thayer | 3dab6bd | 2018-04-27 13:37:17 -0500 | [diff] [blame] | 553 | static const struct regmap_config s10_sdram_regmap_cfg = { |
| 554 | .name = "s10_ddr", |
| 555 | .reg_bits = 32, |
| 556 | .reg_stride = 4, |
| 557 | .val_bits = 32, |
Thor Thayer | 08f08bf | 2018-09-25 08:49:00 -0500 | [diff] [blame] | 558 | .max_register = 0xffd12228, |
Thor Thayer | 3dab6bd | 2018-04-27 13:37:17 -0500 | [diff] [blame] | 559 | .reg_read = s10_protected_reg_read, |
| 560 | .reg_write = s10_protected_reg_write, |
David Frey | 1c96a2f | 2018-09-01 09:50:41 -0700 | [diff] [blame] | 561 | .use_single_read = true, |
| 562 | .use_single_write = true, |
Meng Li | 56d9e7b | 2019-11-21 12:30:46 -0600 | [diff] [blame] | 563 | .fast_io = true, |
Thor Thayer | 3dab6bd | 2018-04-27 13:37:17 -0500 | [diff] [blame] | 564 | }; |
| 565 | |
Thor Thayer | 3dab6bd | 2018-04-27 13:37:17 -0500 | [diff] [blame] | 566 | /************** </Stratix10 EDAC Memory Controller Functions> ***********/ |
| 567 | |
Thor Thayer | c3eea19 | 2016-02-10 13:26:21 -0600 | [diff] [blame] | 568 | /************************* EDAC Parent Probe *************************/ |
| 569 | |
| 570 | static const struct of_device_id altr_edac_device_of_match[]; |
| 571 | |
| 572 | static const struct of_device_id altr_edac_of_match[] = { |
| 573 | { .compatible = "altr,socfpga-ecc-manager" }, |
| 574 | {}, |
| 575 | }; |
| 576 | MODULE_DEVICE_TABLE(of, altr_edac_of_match); |
| 577 | |
| 578 | static int altr_edac_probe(struct platform_device *pdev) |
| 579 | { |
| 580 | of_platform_populate(pdev->dev.of_node, altr_edac_device_of_match, |
| 581 | NULL, &pdev->dev); |
| 582 | return 0; |
| 583 | } |
| 584 | |
| 585 | static struct platform_driver altr_edac_driver = { |
| 586 | .probe = altr_edac_probe, |
| 587 | .driver = { |
| 588 | .name = "socfpga_ecc_manager", |
| 589 | .of_match_table = altr_edac_of_match, |
| 590 | }, |
| 591 | }; |
| 592 | module_platform_driver(altr_edac_driver); |
| 593 | |
| 594 | /************************* EDAC Device Functions *************************/ |
| 595 | |
| 596 | /* |
| 597 | * EDAC Device Functions (shared between various IPs). |
| 598 | * The discrete memories use the EDAC Device framework. The probe |
| 599 | * and error handling functions are very similar between memories |
| 600 | * so they are shared. The memory allocation and freeing for EDAC |
| 601 | * trigger testing are different for each memory. |
| 602 | */ |
| 603 | |
Thor Thayer | 1cf7037 | 2016-06-22 08:58:54 -0500 | [diff] [blame] | 604 | static const struct edac_device_prv_data ocramecc_data; |
| 605 | static const struct edac_device_prv_data l2ecc_data; |
| 606 | static const struct edac_device_prv_data a10_ocramecc_data; |
| 607 | static const struct edac_device_prv_data a10_l2ecc_data; |
Thor Thayer | c3eea19 | 2016-02-10 13:26:21 -0600 | [diff] [blame] | 608 | |
Thor Thayer | c3eea19 | 2016-02-10 13:26:21 -0600 | [diff] [blame] | 609 | static irqreturn_t altr_edac_device_handler(int irq, void *dev_id) |
| 610 | { |
| 611 | irqreturn_t ret_value = IRQ_NONE; |
| 612 | struct edac_device_ctl_info *dci = dev_id; |
| 613 | struct altr_edac_device_dev *drvdata = dci->pvt_info; |
| 614 | const struct edac_device_prv_data *priv = drvdata->data; |
| 615 | |
| 616 | if (irq == drvdata->sb_irq) { |
| 617 | if (priv->ce_clear_mask) |
| 618 | writel(priv->ce_clear_mask, drvdata->base); |
| 619 | edac_device_handle_ce(dci, 0, 0, drvdata->edac_dev_name); |
| 620 | ret_value = IRQ_HANDLED; |
| 621 | } else if (irq == drvdata->db_irq) { |
| 622 | if (priv->ue_clear_mask) |
| 623 | writel(priv->ue_clear_mask, drvdata->base); |
| 624 | edac_device_handle_ue(dci, 0, 0, drvdata->edac_dev_name); |
| 625 | panic("\nEDAC:ECC_DEVICE[Uncorrectable errors]\n"); |
| 626 | ret_value = IRQ_HANDLED; |
| 627 | } else { |
| 628 | WARN_ON(1); |
| 629 | } |
| 630 | |
| 631 | return ret_value; |
| 632 | } |
| 633 | |
| 634 | static ssize_t altr_edac_device_trig(struct file *file, |
| 635 | const char __user *user_buf, |
| 636 | size_t count, loff_t *ppos) |
| 637 | |
| 638 | { |
| 639 | u32 *ptemp, i, error_mask; |
| 640 | int result = 0; |
| 641 | u8 trig_type; |
| 642 | unsigned long flags; |
| 643 | struct edac_device_ctl_info *edac_dci = file->private_data; |
| 644 | struct altr_edac_device_dev *drvdata = edac_dci->pvt_info; |
| 645 | const struct edac_device_prv_data *priv = drvdata->data; |
| 646 | void *generic_ptr = edac_dci->dev; |
| 647 | |
| 648 | if (!user_buf || get_user(trig_type, user_buf)) |
| 649 | return -EFAULT; |
| 650 | |
| 651 | if (!priv->alloc_mem) |
| 652 | return -ENOMEM; |
| 653 | |
| 654 | /* |
| 655 | * Note that generic_ptr is initialized to the device * but in |
| 656 | * some alloc_functions, this is overridden and returns data. |
| 657 | */ |
| 658 | ptemp = priv->alloc_mem(priv->trig_alloc_sz, &generic_ptr); |
| 659 | if (!ptemp) { |
| 660 | edac_printk(KERN_ERR, EDAC_DEVICE, |
| 661 | "Inject: Buffer Allocation error\n"); |
| 662 | return -ENOMEM; |
| 663 | } |
| 664 | |
| 665 | if (trig_type == ALTR_UE_TRIGGER_CHAR) |
| 666 | error_mask = priv->ue_set_mask; |
| 667 | else |
| 668 | error_mask = priv->ce_set_mask; |
| 669 | |
| 670 | edac_printk(KERN_ALERT, EDAC_DEVICE, |
| 671 | "Trigger Error Mask (0x%X)\n", error_mask); |
| 672 | |
| 673 | local_irq_save(flags); |
| 674 | /* write ECC corrupted data out. */ |
| 675 | for (i = 0; i < (priv->trig_alloc_sz / sizeof(*ptemp)); i++) { |
| 676 | /* Read data so we're in the correct state */ |
| 677 | rmb(); |
Mark Rutland | 332efa6 | 2017-10-23 14:07:12 -0700 | [diff] [blame] | 678 | if (READ_ONCE(ptemp[i])) |
Thor Thayer | c3eea19 | 2016-02-10 13:26:21 -0600 | [diff] [blame] | 679 | result = -1; |
| 680 | /* Toggle Error bit (it is latched), leave ECC enabled */ |
Thor Thayer | 811fce4 | 2016-03-21 11:01:42 -0500 | [diff] [blame] | 681 | writel(error_mask, (drvdata->base + priv->set_err_ofst)); |
| 682 | writel(priv->ecc_enable_mask, (drvdata->base + |
| 683 | priv->set_err_ofst)); |
Thor Thayer | c3eea19 | 2016-02-10 13:26:21 -0600 | [diff] [blame] | 684 | ptemp[i] = i; |
| 685 | } |
| 686 | /* Ensure it has been written out */ |
| 687 | wmb(); |
| 688 | local_irq_restore(flags); |
| 689 | |
| 690 | if (result) |
| 691 | edac_printk(KERN_ERR, EDAC_DEVICE, "Mem Not Cleared\n"); |
| 692 | |
| 693 | /* Read out written data. ECC error caused here */ |
| 694 | for (i = 0; i < ALTR_TRIGGER_READ_WRD_CNT; i++) |
Mark Rutland | 332efa6 | 2017-10-23 14:07:12 -0700 | [diff] [blame] | 695 | if (READ_ONCE(ptemp[i]) != i) |
Thor Thayer | c3eea19 | 2016-02-10 13:26:21 -0600 | [diff] [blame] | 696 | edac_printk(KERN_ERR, EDAC_DEVICE, |
| 697 | "Read doesn't match written data\n"); |
| 698 | |
| 699 | if (priv->free_mem) |
| 700 | priv->free_mem(ptemp, priv->trig_alloc_sz, generic_ptr); |
| 701 | |
| 702 | return count; |
| 703 | } |
| 704 | |
| 705 | static const struct file_operations altr_edac_device_inject_fops = { |
| 706 | .open = simple_open, |
| 707 | .write = altr_edac_device_trig, |
| 708 | .llseek = generic_file_llseek, |
| 709 | }; |
| 710 | |
Thor Thayer | c7b4be8 | 2016-04-06 20:22:54 -0500 | [diff] [blame] | 711 | static ssize_t altr_edac_a10_device_trig(struct file *file, |
| 712 | const char __user *user_buf, |
| 713 | size_t count, loff_t *ppos); |
| 714 | |
| 715 | static const struct file_operations altr_edac_a10_device_inject_fops = { |
| 716 | .open = simple_open, |
| 717 | .write = altr_edac_a10_device_trig, |
| 718 | .llseek = generic_file_llseek, |
| 719 | }; |
| 720 | |
Thor Thayer | 064acbd | 2018-09-25 08:49:01 -0500 | [diff] [blame] | 721 | static ssize_t altr_edac_a10_device_trig2(struct file *file, |
| 722 | const char __user *user_buf, |
| 723 | size_t count, loff_t *ppos); |
| 724 | |
| 725 | static const struct file_operations altr_edac_a10_device_inject2_fops = { |
| 726 | .open = simple_open, |
| 727 | .write = altr_edac_a10_device_trig2, |
| 728 | .llseek = generic_file_llseek, |
| 729 | }; |
| 730 | |
Thor Thayer | c3eea19 | 2016-02-10 13:26:21 -0600 | [diff] [blame] | 731 | static void altr_create_edacdev_dbgfs(struct edac_device_ctl_info *edac_dci, |
| 732 | const struct edac_device_prv_data *priv) |
| 733 | { |
| 734 | struct altr_edac_device_dev *drvdata = edac_dci->pvt_info; |
| 735 | |
| 736 | if (!IS_ENABLED(CONFIG_EDAC_DEBUG)) |
| 737 | return; |
| 738 | |
| 739 | drvdata->debugfs_dir = edac_debugfs_create_dir(drvdata->edac_dev_name); |
| 740 | if (!drvdata->debugfs_dir) |
| 741 | return; |
| 742 | |
Thor Thayer | f399f34 | 2016-08-19 11:04:25 -0500 | [diff] [blame] | 743 | if (!edac_debugfs_create_file("altr_trigger", S_IWUSR, |
Thor Thayer | c3eea19 | 2016-02-10 13:26:21 -0600 | [diff] [blame] | 744 | drvdata->debugfs_dir, edac_dci, |
Thor Thayer | e17ced2 | 2016-03-31 13:48:01 -0500 | [diff] [blame] | 745 | priv->inject_fops)) |
Thor Thayer | c3eea19 | 2016-02-10 13:26:21 -0600 | [diff] [blame] | 746 | debugfs_remove_recursive(drvdata->debugfs_dir); |
| 747 | } |
| 748 | |
| 749 | static const struct of_device_id altr_edac_device_of_match[] = { |
| 750 | #ifdef CONFIG_EDAC_ALTERA_L2C |
Arnd Bergmann | 2c911f6 | 2016-04-16 22:13:55 +0200 | [diff] [blame] | 751 | { .compatible = "altr,socfpga-l2-ecc", .data = &l2ecc_data }, |
Thor Thayer | c3eea19 | 2016-02-10 13:26:21 -0600 | [diff] [blame] | 752 | #endif |
| 753 | #ifdef CONFIG_EDAC_ALTERA_OCRAM |
Arnd Bergmann | 2c911f6 | 2016-04-16 22:13:55 +0200 | [diff] [blame] | 754 | { .compatible = "altr,socfpga-ocram-ecc", .data = &ocramecc_data }, |
Thor Thayer | c3eea19 | 2016-02-10 13:26:21 -0600 | [diff] [blame] | 755 | #endif |
| 756 | {}, |
| 757 | }; |
| 758 | MODULE_DEVICE_TABLE(of, altr_edac_device_of_match); |
| 759 | |
| 760 | /* |
| 761 | * altr_edac_device_probe() |
| 762 | * This is a generic EDAC device driver that will support |
| 763 | * various Altera memory devices such as the L2 cache ECC and |
| 764 | * OCRAM ECC as well as the memories for other peripherals. |
| 765 | * Module specific initialization is done by passing the |
| 766 | * function index in the device tree. |
| 767 | */ |
| 768 | static int altr_edac_device_probe(struct platform_device *pdev) |
| 769 | { |
| 770 | struct edac_device_ctl_info *dci; |
| 771 | struct altr_edac_device_dev *drvdata; |
| 772 | struct resource *r; |
| 773 | int res = 0; |
| 774 | struct device_node *np = pdev->dev.of_node; |
| 775 | char *ecc_name = (char *)np->name; |
| 776 | static int dev_instance; |
| 777 | |
| 778 | if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL)) { |
| 779 | edac_printk(KERN_ERR, EDAC_DEVICE, |
| 780 | "Unable to open devm\n"); |
| 781 | return -ENOMEM; |
| 782 | } |
| 783 | |
| 784 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 785 | if (!r) { |
| 786 | edac_printk(KERN_ERR, EDAC_DEVICE, |
| 787 | "Unable to get mem resource\n"); |
| 788 | res = -ENODEV; |
| 789 | goto fail; |
| 790 | } |
| 791 | |
| 792 | if (!devm_request_mem_region(&pdev->dev, r->start, resource_size(r), |
| 793 | dev_name(&pdev->dev))) { |
| 794 | edac_printk(KERN_ERR, EDAC_DEVICE, |
| 795 | "%s:Error requesting mem region\n", ecc_name); |
| 796 | res = -EBUSY; |
| 797 | goto fail; |
| 798 | } |
| 799 | |
| 800 | dci = edac_device_alloc_ctl_info(sizeof(*drvdata), ecc_name, |
| 801 | 1, ecc_name, 1, 0, NULL, 0, |
| 802 | dev_instance++); |
| 803 | |
| 804 | if (!dci) { |
| 805 | edac_printk(KERN_ERR, EDAC_DEVICE, |
| 806 | "%s: Unable to allocate EDAC device\n", ecc_name); |
| 807 | res = -ENOMEM; |
| 808 | goto fail; |
| 809 | } |
| 810 | |
| 811 | drvdata = dci->pvt_info; |
| 812 | dci->dev = &pdev->dev; |
| 813 | platform_set_drvdata(pdev, dci); |
| 814 | drvdata->edac_dev_name = ecc_name; |
| 815 | |
| 816 | drvdata->base = devm_ioremap(&pdev->dev, r->start, resource_size(r)); |
Christophe JAILLET | 8b073d9 | 2017-08-16 07:05:06 +0200 | [diff] [blame] | 817 | if (!drvdata->base) { |
| 818 | res = -ENOMEM; |
Thor Thayer | c3eea19 | 2016-02-10 13:26:21 -0600 | [diff] [blame] | 819 | goto fail1; |
Christophe JAILLET | 8b073d9 | 2017-08-16 07:05:06 +0200 | [diff] [blame] | 820 | } |
Thor Thayer | c3eea19 | 2016-02-10 13:26:21 -0600 | [diff] [blame] | 821 | |
| 822 | /* Get driver specific data for this EDAC device */ |
| 823 | drvdata->data = of_match_node(altr_edac_device_of_match, np)->data; |
| 824 | |
| 825 | /* Check specific dependencies for the module */ |
| 826 | if (drvdata->data->setup) { |
Thor Thayer | 328ca7a | 2016-03-21 11:01:40 -0500 | [diff] [blame] | 827 | res = drvdata->data->setup(drvdata); |
Thor Thayer | c3eea19 | 2016-02-10 13:26:21 -0600 | [diff] [blame] | 828 | if (res) |
| 829 | goto fail1; |
| 830 | } |
| 831 | |
| 832 | drvdata->sb_irq = platform_get_irq(pdev, 0); |
| 833 | res = devm_request_irq(&pdev->dev, drvdata->sb_irq, |
| 834 | altr_edac_device_handler, |
| 835 | 0, dev_name(&pdev->dev), dci); |
| 836 | if (res) |
| 837 | goto fail1; |
| 838 | |
| 839 | drvdata->db_irq = platform_get_irq(pdev, 1); |
| 840 | res = devm_request_irq(&pdev->dev, drvdata->db_irq, |
| 841 | altr_edac_device_handler, |
| 842 | 0, dev_name(&pdev->dev), dci); |
| 843 | if (res) |
| 844 | goto fail1; |
| 845 | |
| 846 | dci->mod_name = "Altera ECC Manager"; |
| 847 | dci->dev_name = drvdata->edac_dev_name; |
| 848 | |
| 849 | res = edac_device_add_device(dci); |
| 850 | if (res) |
| 851 | goto fail1; |
| 852 | |
| 853 | altr_create_edacdev_dbgfs(dci, drvdata->data); |
| 854 | |
| 855 | devres_close_group(&pdev->dev, NULL); |
| 856 | |
| 857 | return 0; |
| 858 | |
| 859 | fail1: |
| 860 | edac_device_free_ctl_info(dci); |
| 861 | fail: |
| 862 | devres_release_group(&pdev->dev, NULL); |
| 863 | edac_printk(KERN_ERR, EDAC_DEVICE, |
| 864 | "%s:Error setting up EDAC device: %d\n", ecc_name, res); |
| 865 | |
| 866 | return res; |
| 867 | } |
| 868 | |
| 869 | static int altr_edac_device_remove(struct platform_device *pdev) |
| 870 | { |
| 871 | struct edac_device_ctl_info *dci = platform_get_drvdata(pdev); |
| 872 | struct altr_edac_device_dev *drvdata = dci->pvt_info; |
| 873 | |
| 874 | debugfs_remove_recursive(drvdata->debugfs_dir); |
| 875 | edac_device_del_device(&pdev->dev); |
| 876 | edac_device_free_ctl_info(dci); |
| 877 | |
| 878 | return 0; |
| 879 | } |
| 880 | |
| 881 | static struct platform_driver altr_edac_device_driver = { |
| 882 | .probe = altr_edac_device_probe, |
| 883 | .remove = altr_edac_device_remove, |
| 884 | .driver = { |
| 885 | .name = "altr_edac_device", |
| 886 | .of_match_table = altr_edac_device_of_match, |
| 887 | }, |
| 888 | }; |
| 889 | module_platform_driver(altr_edac_device_driver); |
| 890 | |
Thor Thayer | 6b300fb | 2016-06-22 08:58:55 -0500 | [diff] [blame] | 891 | /******************* Arria10 Device ECC Shared Functions *****************/ |
Thor Thayer | c3eea19 | 2016-02-10 13:26:21 -0600 | [diff] [blame] | 892 | |
Arnd Bergmann | 1aa6eb5 | 2016-04-16 22:13:56 +0200 | [diff] [blame] | 893 | /* |
| 894 | * Test for memory's ECC dependencies upon entry because platform specific |
| 895 | * startup should have initialized the memory and enabled the ECC. |
| 896 | * Can't turn on ECC here because accessing un-initialized memory will |
| 897 | * cause CE/UE errors possibly causing an ABORT. |
| 898 | */ |
Thor Thayer | 6b300fb | 2016-06-22 08:58:55 -0500 | [diff] [blame] | 899 | static int __maybe_unused |
| 900 | altr_check_ecc_deps(struct altr_edac_device_dev *device) |
Arnd Bergmann | 1aa6eb5 | 2016-04-16 22:13:56 +0200 | [diff] [blame] | 901 | { |
| 902 | void __iomem *base = device->base; |
| 903 | const struct edac_device_prv_data *prv = device->data; |
| 904 | |
| 905 | if (readl(base + prv->ecc_en_ofst) & prv->ecc_enable_mask) |
| 906 | return 0; |
| 907 | |
| 908 | edac_printk(KERN_ERR, EDAC_DEVICE, |
| 909 | "%s: No ECC present or ECC disabled.\n", |
| 910 | device->edac_dev_name); |
| 911 | return -ENODEV; |
| 912 | } |
Thor Thayer | c3eea19 | 2016-02-10 13:26:21 -0600 | [diff] [blame] | 913 | |
Thor Thayer | 6b300fb | 2016-06-22 08:58:55 -0500 | [diff] [blame] | 914 | static irqreturn_t __maybe_unused altr_edac_a10_ecc_irq(int irq, void *dev_id) |
| 915 | { |
| 916 | struct altr_edac_device_dev *dci = dev_id; |
| 917 | void __iomem *base = dci->base; |
| 918 | |
| 919 | if (irq == dci->sb_irq) { |
| 920 | writel(ALTR_A10_ECC_SERRPENA, |
| 921 | base + ALTR_A10_ECC_INTSTAT_OFST); |
| 922 | edac_device_handle_ce(dci->edac_dev, 0, 0, dci->edac_dev_name); |
| 923 | |
| 924 | return IRQ_HANDLED; |
| 925 | } else if (irq == dci->db_irq) { |
| 926 | writel(ALTR_A10_ECC_DERRPENA, |
| 927 | base + ALTR_A10_ECC_INTSTAT_OFST); |
| 928 | edac_device_handle_ue(dci->edac_dev, 0, 0, dci->edac_dev_name); |
| 929 | if (dci->data->panic) |
| 930 | panic("\nEDAC:ECC_DEVICE[Uncorrectable errors]\n"); |
| 931 | |
| 932 | return IRQ_HANDLED; |
| 933 | } |
| 934 | |
| 935 | WARN_ON(1); |
| 936 | |
| 937 | return IRQ_NONE; |
| 938 | } |
| 939 | |
Thor Thayer | 1166fde9 | 2016-06-22 08:58:57 -0500 | [diff] [blame] | 940 | /******************* Arria10 Memory Buffer Functions *********************/ |
| 941 | |
| 942 | static inline int a10_get_irq_mask(struct device_node *np) |
| 943 | { |
| 944 | int irq; |
| 945 | const u32 *handle = of_get_property(np, "interrupts", NULL); |
| 946 | |
| 947 | if (!handle) |
| 948 | return -ENODEV; |
| 949 | irq = be32_to_cpup(handle); |
| 950 | return irq; |
| 951 | } |
| 952 | |
| 953 | static inline void ecc_set_bits(u32 bit_mask, void __iomem *ioaddr) |
| 954 | { |
| 955 | u32 value = readl(ioaddr); |
| 956 | |
| 957 | value |= bit_mask; |
| 958 | writel(value, ioaddr); |
| 959 | } |
| 960 | |
| 961 | static inline void ecc_clear_bits(u32 bit_mask, void __iomem *ioaddr) |
| 962 | { |
| 963 | u32 value = readl(ioaddr); |
| 964 | |
| 965 | value &= ~bit_mask; |
| 966 | writel(value, ioaddr); |
| 967 | } |
| 968 | |
| 969 | static inline int ecc_test_bits(u32 bit_mask, void __iomem *ioaddr) |
| 970 | { |
| 971 | u32 value = readl(ioaddr); |
| 972 | |
| 973 | return (value & bit_mask) ? 1 : 0; |
| 974 | } |
| 975 | |
| 976 | /* |
| 977 | * This function uses the memory initialization block in the Arria10 ECC |
| 978 | * controller to initialize/clear the entire memory data and ECC data. |
| 979 | */ |
| 980 | static int __maybe_unused altr_init_memory_port(void __iomem *ioaddr, int port) |
| 981 | { |
| 982 | int limit = ALTR_A10_ECC_INIT_WATCHDOG_10US; |
| 983 | u32 init_mask, stat_mask, clear_mask; |
| 984 | int ret = 0; |
| 985 | |
| 986 | if (port) { |
| 987 | init_mask = ALTR_A10_ECC_INITB; |
| 988 | stat_mask = ALTR_A10_ECC_INITCOMPLETEB; |
| 989 | clear_mask = ALTR_A10_ECC_ERRPENB_MASK; |
| 990 | } else { |
| 991 | init_mask = ALTR_A10_ECC_INITA; |
| 992 | stat_mask = ALTR_A10_ECC_INITCOMPLETEA; |
| 993 | clear_mask = ALTR_A10_ECC_ERRPENA_MASK; |
| 994 | } |
| 995 | |
| 996 | ecc_set_bits(init_mask, (ioaddr + ALTR_A10_ECC_CTRL_OFST)); |
| 997 | while (limit--) { |
| 998 | if (ecc_test_bits(stat_mask, |
| 999 | (ioaddr + ALTR_A10_ECC_INITSTAT_OFST))) |
| 1000 | break; |
| 1001 | udelay(1); |
| 1002 | } |
| 1003 | if (limit < 0) |
| 1004 | ret = -EBUSY; |
| 1005 | |
| 1006 | /* Clear any pending ECC interrupts */ |
| 1007 | writel(clear_mask, (ioaddr + ALTR_A10_ECC_INTSTAT_OFST)); |
| 1008 | |
| 1009 | return ret; |
| 1010 | } |
| 1011 | |
Thor Thayer | 064acbd | 2018-09-25 08:49:01 -0500 | [diff] [blame] | 1012 | static int socfpga_is_a10(void) |
| 1013 | { |
| 1014 | return of_machine_is_compatible("altr,socfpga-arria10"); |
| 1015 | } |
| 1016 | |
Thor Thayer | 1166fde9 | 2016-06-22 08:58:57 -0500 | [diff] [blame] | 1017 | static __init int __maybe_unused |
| 1018 | altr_init_a10_ecc_block(struct device_node *np, u32 irq_mask, |
| 1019 | u32 ecc_ctrl_en_mask, bool dual_port) |
| 1020 | { |
| 1021 | int ret = 0; |
| 1022 | void __iomem *ecc_block_base; |
| 1023 | struct regmap *ecc_mgr_map; |
| 1024 | char *ecc_name; |
| 1025 | struct device_node *np_eccmgr; |
| 1026 | |
| 1027 | ecc_name = (char *)np->name; |
| 1028 | |
| 1029 | /* Get the ECC Manager - parent of the device EDACs */ |
| 1030 | np_eccmgr = of_get_parent(np); |
Thor Thayer | 064acbd | 2018-09-25 08:49:01 -0500 | [diff] [blame] | 1031 | |
| 1032 | if (socfpga_is_a10()) { |
| 1033 | ecc_mgr_map = syscon_regmap_lookup_by_phandle(np_eccmgr, |
| 1034 | "altr,sysmgr-syscon"); |
| 1035 | } else { |
| 1036 | struct device_node *sysmgr_np; |
| 1037 | struct resource res; |
Arnd Bergmann | 8537bf10 | 2018-09-27 12:09:26 +0200 | [diff] [blame] | 1038 | uintptr_t base; |
Thor Thayer | 064acbd | 2018-09-25 08:49:01 -0500 | [diff] [blame] | 1039 | |
| 1040 | sysmgr_np = of_parse_phandle(np_eccmgr, |
| 1041 | "altr,sysmgr-syscon", 0); |
| 1042 | if (!sysmgr_np) { |
| 1043 | edac_printk(KERN_ERR, EDAC_DEVICE, |
| 1044 | "Unable to find altr,sysmgr-syscon\n"); |
| 1045 | return -ENODEV; |
| 1046 | } |
| 1047 | |
Huang Zijiang | 7f73659 | 2019-02-14 14:39:07 +0800 | [diff] [blame] | 1048 | if (of_address_to_resource(sysmgr_np, 0, &res)) { |
| 1049 | of_node_put(sysmgr_np); |
Thor Thayer | 064acbd | 2018-09-25 08:49:01 -0500 | [diff] [blame] | 1050 | return -ENOMEM; |
Huang Zijiang | 7f73659 | 2019-02-14 14:39:07 +0800 | [diff] [blame] | 1051 | } |
Thor Thayer | 064acbd | 2018-09-25 08:49:01 -0500 | [diff] [blame] | 1052 | |
| 1053 | /* Need physical address for SMCC call */ |
Arnd Bergmann | 8537bf10 | 2018-09-27 12:09:26 +0200 | [diff] [blame] | 1054 | base = res.start; |
Thor Thayer | 064acbd | 2018-09-25 08:49:01 -0500 | [diff] [blame] | 1055 | |
Arnd Bergmann | 8537bf10 | 2018-09-27 12:09:26 +0200 | [diff] [blame] | 1056 | ecc_mgr_map = regmap_init(NULL, NULL, (void *)base, |
Thor Thayer | 064acbd | 2018-09-25 08:49:01 -0500 | [diff] [blame] | 1057 | &s10_sdram_regmap_cfg); |
Huang Zijiang | 7f73659 | 2019-02-14 14:39:07 +0800 | [diff] [blame] | 1058 | of_node_put(sysmgr_np); |
Thor Thayer | 064acbd | 2018-09-25 08:49:01 -0500 | [diff] [blame] | 1059 | } |
Thor Thayer | 1166fde9 | 2016-06-22 08:58:57 -0500 | [diff] [blame] | 1060 | of_node_put(np_eccmgr); |
| 1061 | if (IS_ERR(ecc_mgr_map)) { |
| 1062 | edac_printk(KERN_ERR, EDAC_DEVICE, |
| 1063 | "Unable to get syscon altr,sysmgr-syscon\n"); |
| 1064 | return -ENODEV; |
| 1065 | } |
| 1066 | |
| 1067 | /* Map the ECC Block */ |
| 1068 | ecc_block_base = of_iomap(np, 0); |
| 1069 | if (!ecc_block_base) { |
| 1070 | edac_printk(KERN_ERR, EDAC_DEVICE, |
| 1071 | "Unable to map %s ECC block\n", ecc_name); |
| 1072 | return -ENODEV; |
| 1073 | } |
| 1074 | |
| 1075 | /* Disable ECC */ |
| 1076 | regmap_write(ecc_mgr_map, A10_SYSMGR_ECC_INTMASK_SET_OFST, irq_mask); |
| 1077 | writel(ALTR_A10_ECC_SERRINTEN, |
| 1078 | (ecc_block_base + ALTR_A10_ECC_ERRINTENR_OFST)); |
| 1079 | ecc_clear_bits(ecc_ctrl_en_mask, |
| 1080 | (ecc_block_base + ALTR_A10_ECC_CTRL_OFST)); |
| 1081 | /* Ensure all writes complete */ |
| 1082 | wmb(); |
| 1083 | /* Use HW initialization block to initialize memory for ECC */ |
| 1084 | ret = altr_init_memory_port(ecc_block_base, 0); |
| 1085 | if (ret) { |
| 1086 | edac_printk(KERN_ERR, EDAC_DEVICE, |
| 1087 | "ECC: cannot init %s PORTA memory\n", ecc_name); |
| 1088 | goto out; |
| 1089 | } |
| 1090 | |
| 1091 | if (dual_port) { |
| 1092 | ret = altr_init_memory_port(ecc_block_base, 1); |
| 1093 | if (ret) { |
| 1094 | edac_printk(KERN_ERR, EDAC_DEVICE, |
| 1095 | "ECC: cannot init %s PORTB memory\n", |
| 1096 | ecc_name); |
| 1097 | goto out; |
| 1098 | } |
| 1099 | } |
| 1100 | |
| 1101 | /* Interrupt mode set to every SBERR */ |
| 1102 | regmap_write(ecc_mgr_map, ALTR_A10_ECC_INTMODE_OFST, |
| 1103 | ALTR_A10_ECC_INTMODE); |
| 1104 | /* Enable ECC */ |
| 1105 | ecc_set_bits(ecc_ctrl_en_mask, (ecc_block_base + |
| 1106 | ALTR_A10_ECC_CTRL_OFST)); |
| 1107 | writel(ALTR_A10_ECC_SERRINTEN, |
| 1108 | (ecc_block_base + ALTR_A10_ECC_ERRINTENS_OFST)); |
| 1109 | regmap_write(ecc_mgr_map, A10_SYSMGR_ECC_INTMASK_CLR_OFST, irq_mask); |
| 1110 | /* Ensure all writes complete */ |
| 1111 | wmb(); |
| 1112 | out: |
| 1113 | iounmap(ecc_block_base); |
| 1114 | return ret; |
| 1115 | } |
| 1116 | |
| 1117 | static int validate_parent_available(struct device_node *np); |
| 1118 | static const struct of_device_id altr_edac_a10_device_of_match[]; |
| 1119 | static int __init __maybe_unused altr_init_a10_ecc_device_type(char *compat) |
| 1120 | { |
| 1121 | int irq; |
Thor Thayer | 25b223d | 2017-04-05 13:01:02 -0500 | [diff] [blame] | 1122 | struct device_node *child, *np; |
| 1123 | |
Thor Thayer | 25b223d | 2017-04-05 13:01:02 -0500 | [diff] [blame] | 1124 | np = of_find_compatible_node(NULL, NULL, |
| 1125 | "altr,socfpga-a10-ecc-manager"); |
Thor Thayer | 1166fde9 | 2016-06-22 08:58:57 -0500 | [diff] [blame] | 1126 | if (!np) { |
| 1127 | edac_printk(KERN_ERR, EDAC_DEVICE, "ECC Manager not found\n"); |
| 1128 | return -ENODEV; |
| 1129 | } |
| 1130 | |
| 1131 | for_each_child_of_node(np, child) { |
| 1132 | const struct of_device_id *pdev_id; |
| 1133 | const struct edac_device_prv_data *prv; |
| 1134 | |
| 1135 | if (!of_device_is_available(child)) |
| 1136 | continue; |
| 1137 | if (!of_device_is_compatible(child, compat)) |
| 1138 | continue; |
| 1139 | |
| 1140 | if (validate_parent_available(child)) |
| 1141 | continue; |
| 1142 | |
| 1143 | irq = a10_get_irq_mask(child); |
| 1144 | if (irq < 0) |
| 1145 | continue; |
| 1146 | |
| 1147 | /* Get matching node and check for valid result */ |
| 1148 | pdev_id = of_match_node(altr_edac_a10_device_of_match, child); |
| 1149 | if (IS_ERR_OR_NULL(pdev_id)) |
| 1150 | continue; |
| 1151 | |
| 1152 | /* Validate private data pointer before dereferencing */ |
| 1153 | prv = pdev_id->data; |
| 1154 | if (!prv) |
| 1155 | continue; |
| 1156 | |
| 1157 | altr_init_a10_ecc_block(child, BIT(irq), |
| 1158 | prv->ecc_enable_mask, 0); |
| 1159 | } |
| 1160 | |
| 1161 | of_node_put(np); |
| 1162 | return 0; |
| 1163 | } |
| 1164 | |
Thor Thayer | 3123c5c | 2019-07-12 13:28:43 -0500 | [diff] [blame] | 1165 | /*********************** SDRAM EDAC Device Functions *********************/ |
| 1166 | |
| 1167 | #ifdef CONFIG_EDAC_ALTERA_SDRAM |
| 1168 | |
| 1169 | static const struct edac_device_prv_data s10_sdramecc_data = { |
| 1170 | .setup = altr_check_ecc_deps, |
| 1171 | .ce_clear_mask = ALTR_S10_ECC_SERRPENA, |
| 1172 | .ue_clear_mask = ALTR_S10_ECC_DERRPENA, |
| 1173 | .ecc_enable_mask = ALTR_S10_ECC_EN, |
| 1174 | .ecc_en_ofst = ALTR_S10_ECC_CTRL_SDRAM_OFST, |
| 1175 | .ce_set_mask = ALTR_S10_ECC_TSERRA, |
| 1176 | .ue_set_mask = ALTR_S10_ECC_TDERRA, |
| 1177 | .set_err_ofst = ALTR_S10_ECC_INTTEST_OFST, |
| 1178 | .ecc_irq_handler = altr_edac_a10_ecc_irq, |
| 1179 | .inject_fops = &altr_edac_a10_device_inject_fops, |
| 1180 | }; |
| 1181 | #endif /* CONFIG_EDAC_ALTERA_SDRAM */ |
| 1182 | |
Thor Thayer | 6b300fb | 2016-06-22 08:58:55 -0500 | [diff] [blame] | 1183 | /*********************** OCRAM EDAC Device Functions *********************/ |
| 1184 | |
| 1185 | #ifdef CONFIG_EDAC_ALTERA_OCRAM |
| 1186 | |
Thor Thayer | c3eea19 | 2016-02-10 13:26:21 -0600 | [diff] [blame] | 1187 | static void *ocram_alloc_mem(size_t size, void **other) |
| 1188 | { |
| 1189 | struct device_node *np; |
| 1190 | struct gen_pool *gp; |
| 1191 | void *sram_addr; |
| 1192 | |
| 1193 | np = of_find_compatible_node(NULL, NULL, "altr,socfpga-ocram-ecc"); |
| 1194 | if (!np) |
| 1195 | return NULL; |
| 1196 | |
| 1197 | gp = of_gen_pool_get(np, "iram", 0); |
| 1198 | of_node_put(np); |
| 1199 | if (!gp) |
| 1200 | return NULL; |
| 1201 | |
| 1202 | sram_addr = (void *)gen_pool_alloc(gp, size); |
| 1203 | if (!sram_addr) |
| 1204 | return NULL; |
| 1205 | |
| 1206 | memset(sram_addr, 0, size); |
| 1207 | /* Ensure data is written out */ |
| 1208 | wmb(); |
| 1209 | |
| 1210 | /* Remember this handle for freeing later */ |
| 1211 | *other = gp; |
| 1212 | |
| 1213 | return sram_addr; |
| 1214 | } |
| 1215 | |
| 1216 | static void ocram_free_mem(void *p, size_t size, void *other) |
| 1217 | { |
Thor Thayer | 9ef2075 | 2018-05-14 12:04:01 -0500 | [diff] [blame] | 1218 | gen_pool_free((struct gen_pool *)other, (unsigned long)p, size); |
Thor Thayer | c3eea19 | 2016-02-10 13:26:21 -0600 | [diff] [blame] | 1219 | } |
| 1220 | |
Thor Thayer | 1cf7037 | 2016-06-22 08:58:54 -0500 | [diff] [blame] | 1221 | static const struct edac_device_prv_data ocramecc_data = { |
Thor Thayer | aa1f06d | 2016-03-31 13:48:03 -0500 | [diff] [blame] | 1222 | .setup = altr_check_ecc_deps, |
Thor Thayer | c3eea19 | 2016-02-10 13:26:21 -0600 | [diff] [blame] | 1223 | .ce_clear_mask = (ALTR_OCR_ECC_EN | ALTR_OCR_ECC_SERR), |
| 1224 | .ue_clear_mask = (ALTR_OCR_ECC_EN | ALTR_OCR_ECC_DERR), |
Thor Thayer | c3eea19 | 2016-02-10 13:26:21 -0600 | [diff] [blame] | 1225 | .alloc_mem = ocram_alloc_mem, |
| 1226 | .free_mem = ocram_free_mem, |
| 1227 | .ecc_enable_mask = ALTR_OCR_ECC_EN, |
Thor Thayer | 943ad91 | 2016-03-31 13:48:02 -0500 | [diff] [blame] | 1228 | .ecc_en_ofst = ALTR_OCR_ECC_REG_OFFSET, |
Thor Thayer | c3eea19 | 2016-02-10 13:26:21 -0600 | [diff] [blame] | 1229 | .ce_set_mask = (ALTR_OCR_ECC_EN | ALTR_OCR_ECC_INJS), |
| 1230 | .ue_set_mask = (ALTR_OCR_ECC_EN | ALTR_OCR_ECC_INJD), |
Thor Thayer | 811fce4 | 2016-03-21 11:01:42 -0500 | [diff] [blame] | 1231 | .set_err_ofst = ALTR_OCR_ECC_REG_OFFSET, |
Thor Thayer | c3eea19 | 2016-02-10 13:26:21 -0600 | [diff] [blame] | 1232 | .trig_alloc_sz = ALTR_TRIG_OCRAM_BYTE_SIZE, |
Thor Thayer | e17ced2 | 2016-03-31 13:48:01 -0500 | [diff] [blame] | 1233 | .inject_fops = &altr_edac_device_inject_fops, |
Thor Thayer | c3eea19 | 2016-02-10 13:26:21 -0600 | [diff] [blame] | 1234 | }; |
| 1235 | |
Thor Thayer | 17e47dc | 2019-04-23 09:36:34 -0500 | [diff] [blame] | 1236 | static int __maybe_unused |
| 1237 | altr_check_ocram_deps_init(struct altr_edac_device_dev *device) |
| 1238 | { |
| 1239 | void __iomem *base = device->base; |
| 1240 | int ret; |
| 1241 | |
| 1242 | ret = altr_check_ecc_deps(device); |
| 1243 | if (ret) |
| 1244 | return ret; |
| 1245 | |
| 1246 | /* Verify OCRAM has been initialized */ |
| 1247 | if (!ecc_test_bits(ALTR_A10_ECC_INITCOMPLETEA, |
| 1248 | (base + ALTR_A10_ECC_INITSTAT_OFST))) |
| 1249 | return -ENODEV; |
| 1250 | |
| 1251 | /* Enable IRQ on Single Bit Error */ |
| 1252 | writel(ALTR_A10_ECC_SERRINTEN, (base + ALTR_A10_ECC_ERRINTENS_OFST)); |
| 1253 | /* Ensure all writes complete */ |
| 1254 | wmb(); |
| 1255 | |
| 1256 | return 0; |
| 1257 | } |
| 1258 | |
Thor Thayer | 1cf7037 | 2016-06-22 08:58:54 -0500 | [diff] [blame] | 1259 | static const struct edac_device_prv_data a10_ocramecc_data = { |
Thor Thayer | 17e47dc | 2019-04-23 09:36:34 -0500 | [diff] [blame] | 1260 | .setup = altr_check_ocram_deps_init, |
Thor Thayer | c7b4be8 | 2016-04-06 20:22:54 -0500 | [diff] [blame] | 1261 | .ce_clear_mask = ALTR_A10_ECC_SERRPENA, |
| 1262 | .ue_clear_mask = ALTR_A10_ECC_DERRPENA, |
| 1263 | .irq_status_mask = A10_SYSMGR_ECC_INTSTAT_OCRAM, |
Thor Thayer | c7b4be8 | 2016-04-06 20:22:54 -0500 | [diff] [blame] | 1264 | .ecc_enable_mask = ALTR_A10_OCRAM_ECC_EN_CTL, |
| 1265 | .ecc_en_ofst = ALTR_A10_ECC_CTRL_OFST, |
| 1266 | .ce_set_mask = ALTR_A10_ECC_TSERRA, |
| 1267 | .ue_set_mask = ALTR_A10_ECC_TDERRA, |
| 1268 | .set_err_ofst = ALTR_A10_ECC_INTTEST_OFST, |
| 1269 | .ecc_irq_handler = altr_edac_a10_ecc_irq, |
Thor Thayer | 17e47dc | 2019-04-23 09:36:34 -0500 | [diff] [blame] | 1270 | .inject_fops = &altr_edac_a10_device_inject2_fops, |
Thor Thayer | 2b083d6 | 2016-06-22 08:58:53 -0500 | [diff] [blame] | 1271 | /* |
| 1272 | * OCRAM panic on uncorrectable error because sleep/resume |
| 1273 | * functions and FPGA contents are stored in OCRAM. Prefer |
| 1274 | * a kernel panic over executing/loading corrupted data. |
| 1275 | */ |
| 1276 | .panic = true, |
Thor Thayer | c7b4be8 | 2016-04-06 20:22:54 -0500 | [diff] [blame] | 1277 | }; |
| 1278 | |
Thor Thayer | c3eea19 | 2016-02-10 13:26:21 -0600 | [diff] [blame] | 1279 | #endif /* CONFIG_EDAC_ALTERA_OCRAM */ |
| 1280 | |
| 1281 | /********************* L2 Cache EDAC Device Functions ********************/ |
| 1282 | |
| 1283 | #ifdef CONFIG_EDAC_ALTERA_L2C |
| 1284 | |
| 1285 | static void *l2_alloc_mem(size_t size, void **other) |
| 1286 | { |
| 1287 | struct device *dev = *other; |
| 1288 | void *ptemp = devm_kzalloc(dev, size, GFP_KERNEL); |
| 1289 | |
| 1290 | if (!ptemp) |
| 1291 | return NULL; |
| 1292 | |
| 1293 | /* Make sure everything is written out */ |
| 1294 | wmb(); |
| 1295 | |
| 1296 | /* |
| 1297 | * Clean all cache levels up to LoC (includes L2) |
| 1298 | * This ensures the corrupted data is written into |
| 1299 | * L2 cache for readback test (which causes ECC error). |
| 1300 | */ |
| 1301 | flush_cache_all(); |
| 1302 | |
| 1303 | return ptemp; |
| 1304 | } |
| 1305 | |
| 1306 | static void l2_free_mem(void *p, size_t size, void *other) |
| 1307 | { |
| 1308 | struct device *dev = other; |
| 1309 | |
| 1310 | if (dev && p) |
| 1311 | devm_kfree(dev, p); |
| 1312 | } |
| 1313 | |
| 1314 | /* |
| 1315 | * altr_l2_check_deps() |
| 1316 | * Test for L2 cache ECC dependencies upon entry because |
| 1317 | * platform specific startup should have initialized the L2 |
| 1318 | * memory and enabled the ECC. |
| 1319 | * Bail if ECC is not enabled. |
| 1320 | * Note that L2 Cache Enable is forced at build time. |
| 1321 | */ |
Thor Thayer | 328ca7a | 2016-03-21 11:01:40 -0500 | [diff] [blame] | 1322 | static int altr_l2_check_deps(struct altr_edac_device_dev *device) |
Thor Thayer | c3eea19 | 2016-02-10 13:26:21 -0600 | [diff] [blame] | 1323 | { |
Thor Thayer | 328ca7a | 2016-03-21 11:01:40 -0500 | [diff] [blame] | 1324 | void __iomem *base = device->base; |
Thor Thayer | 27439a1 | 2016-03-21 11:01:41 -0500 | [diff] [blame] | 1325 | const struct edac_device_prv_data *prv = device->data; |
| 1326 | |
| 1327 | if ((readl(base) & prv->ecc_enable_mask) == |
| 1328 | prv->ecc_enable_mask) |
Thor Thayer | c3eea19 | 2016-02-10 13:26:21 -0600 | [diff] [blame] | 1329 | return 0; |
| 1330 | |
| 1331 | edac_printk(KERN_ERR, EDAC_DEVICE, |
| 1332 | "L2: No ECC present, or ECC disabled\n"); |
| 1333 | return -ENODEV; |
| 1334 | } |
| 1335 | |
Thor Thayer | 13ab844 | 2016-06-07 15:35:57 -0500 | [diff] [blame] | 1336 | static irqreturn_t altr_edac_a10_l2_irq(int irq, void *dev_id) |
Thor Thayer | 588cb03 | 2016-03-21 11:01:44 -0500 | [diff] [blame] | 1337 | { |
Thor Thayer | 13ab844 | 2016-06-07 15:35:57 -0500 | [diff] [blame] | 1338 | struct altr_edac_device_dev *dci = dev_id; |
| 1339 | |
| 1340 | if (irq == dci->sb_irq) { |
Thor Thayer | 588cb03 | 2016-03-21 11:01:44 -0500 | [diff] [blame] | 1341 | regmap_write(dci->edac->ecc_mgr_map, |
| 1342 | A10_SYSGMR_MPU_CLEAR_L2_ECC_OFST, |
| 1343 | A10_SYSGMR_MPU_CLEAR_L2_ECC_SB); |
| 1344 | edac_device_handle_ce(dci->edac_dev, 0, 0, dci->edac_dev_name); |
Thor Thayer | 13ab844 | 2016-06-07 15:35:57 -0500 | [diff] [blame] | 1345 | |
| 1346 | return IRQ_HANDLED; |
| 1347 | } else if (irq == dci->db_irq) { |
Thor Thayer | 588cb03 | 2016-03-21 11:01:44 -0500 | [diff] [blame] | 1348 | regmap_write(dci->edac->ecc_mgr_map, |
| 1349 | A10_SYSGMR_MPU_CLEAR_L2_ECC_OFST, |
| 1350 | A10_SYSGMR_MPU_CLEAR_L2_ECC_MB); |
| 1351 | edac_device_handle_ue(dci->edac_dev, 0, 0, dci->edac_dev_name); |
| 1352 | panic("\nEDAC:ECC_DEVICE[Uncorrectable errors]\n"); |
Thor Thayer | 13ab844 | 2016-06-07 15:35:57 -0500 | [diff] [blame] | 1353 | |
| 1354 | return IRQ_HANDLED; |
Thor Thayer | 588cb03 | 2016-03-21 11:01:44 -0500 | [diff] [blame] | 1355 | } |
Thor Thayer | 13ab844 | 2016-06-07 15:35:57 -0500 | [diff] [blame] | 1356 | |
| 1357 | WARN_ON(1); |
| 1358 | |
| 1359 | return IRQ_NONE; |
Thor Thayer | 588cb03 | 2016-03-21 11:01:44 -0500 | [diff] [blame] | 1360 | } |
| 1361 | |
Thor Thayer | 1cf7037 | 2016-06-22 08:58:54 -0500 | [diff] [blame] | 1362 | static const struct edac_device_prv_data l2ecc_data = { |
Thor Thayer | c3eea19 | 2016-02-10 13:26:21 -0600 | [diff] [blame] | 1363 | .setup = altr_l2_check_deps, |
| 1364 | .ce_clear_mask = 0, |
| 1365 | .ue_clear_mask = 0, |
Thor Thayer | c3eea19 | 2016-02-10 13:26:21 -0600 | [diff] [blame] | 1366 | .alloc_mem = l2_alloc_mem, |
| 1367 | .free_mem = l2_free_mem, |
| 1368 | .ecc_enable_mask = ALTR_L2_ECC_EN, |
| 1369 | .ce_set_mask = (ALTR_L2_ECC_EN | ALTR_L2_ECC_INJS), |
| 1370 | .ue_set_mask = (ALTR_L2_ECC_EN | ALTR_L2_ECC_INJD), |
Thor Thayer | 811fce4 | 2016-03-21 11:01:42 -0500 | [diff] [blame] | 1371 | .set_err_ofst = ALTR_L2_ECC_REG_OFFSET, |
Thor Thayer | c3eea19 | 2016-02-10 13:26:21 -0600 | [diff] [blame] | 1372 | .trig_alloc_sz = ALTR_TRIG_L2C_BYTE_SIZE, |
Thor Thayer | e17ced2 | 2016-03-31 13:48:01 -0500 | [diff] [blame] | 1373 | .inject_fops = &altr_edac_device_inject_fops, |
Thor Thayer | c3eea19 | 2016-02-10 13:26:21 -0600 | [diff] [blame] | 1374 | }; |
| 1375 | |
Thor Thayer | 1cf7037 | 2016-06-22 08:58:54 -0500 | [diff] [blame] | 1376 | static const struct edac_device_prv_data a10_l2ecc_data = { |
Thor Thayer | 588cb03 | 2016-03-21 11:01:44 -0500 | [diff] [blame] | 1377 | .setup = altr_l2_check_deps, |
| 1378 | .ce_clear_mask = ALTR_A10_L2_ECC_SERR_CLR, |
| 1379 | .ue_clear_mask = ALTR_A10_L2_ECC_MERR_CLR, |
| 1380 | .irq_status_mask = A10_SYSMGR_ECC_INTSTAT_L2, |
Thor Thayer | 588cb03 | 2016-03-21 11:01:44 -0500 | [diff] [blame] | 1381 | .alloc_mem = l2_alloc_mem, |
| 1382 | .free_mem = l2_free_mem, |
| 1383 | .ecc_enable_mask = ALTR_A10_L2_ECC_EN_CTL, |
| 1384 | .ce_set_mask = ALTR_A10_L2_ECC_CE_INJ_MASK, |
| 1385 | .ue_set_mask = ALTR_A10_L2_ECC_UE_INJ_MASK, |
| 1386 | .set_err_ofst = ALTR_A10_L2_ECC_INJ_OFST, |
| 1387 | .ecc_irq_handler = altr_edac_a10_l2_irq, |
| 1388 | .trig_alloc_sz = ALTR_TRIG_L2C_BYTE_SIZE, |
Thor Thayer | e17ced2 | 2016-03-31 13:48:01 -0500 | [diff] [blame] | 1389 | .inject_fops = &altr_edac_device_inject_fops, |
Thor Thayer | 588cb03 | 2016-03-21 11:01:44 -0500 | [diff] [blame] | 1390 | }; |
| 1391 | |
Thor Thayer | c3eea19 | 2016-02-10 13:26:21 -0600 | [diff] [blame] | 1392 | #endif /* CONFIG_EDAC_ALTERA_L2C */ |
| 1393 | |
Thor Thayer | ab8c1e0 | 2016-06-22 08:58:58 -0500 | [diff] [blame] | 1394 | /********************* Ethernet Device Functions ********************/ |
| 1395 | |
| 1396 | #ifdef CONFIG_EDAC_ALTERA_ETHERNET |
| 1397 | |
Thor Thayer | 788586e | 2019-03-26 16:29:31 -0500 | [diff] [blame] | 1398 | static int __init socfpga_init_ethernet_ecc(struct altr_edac_device_dev *dev) |
| 1399 | { |
| 1400 | int ret; |
| 1401 | |
| 1402 | ret = altr_init_a10_ecc_device_type("altr,socfpga-eth-mac-ecc"); |
| 1403 | if (ret) |
| 1404 | return ret; |
| 1405 | |
| 1406 | return altr_check_ecc_deps(dev); |
| 1407 | } |
| 1408 | |
Thor Thayer | ab8c1e0 | 2016-06-22 08:58:58 -0500 | [diff] [blame] | 1409 | static const struct edac_device_prv_data a10_enetecc_data = { |
Thor Thayer | 788586e | 2019-03-26 16:29:31 -0500 | [diff] [blame] | 1410 | .setup = socfpga_init_ethernet_ecc, |
Thor Thayer | ab8c1e0 | 2016-06-22 08:58:58 -0500 | [diff] [blame] | 1411 | .ce_clear_mask = ALTR_A10_ECC_SERRPENA, |
| 1412 | .ue_clear_mask = ALTR_A10_ECC_DERRPENA, |
Thor Thayer | ab8c1e0 | 2016-06-22 08:58:58 -0500 | [diff] [blame] | 1413 | .ecc_enable_mask = ALTR_A10_COMMON_ECC_EN_CTL, |
| 1414 | .ecc_en_ofst = ALTR_A10_ECC_CTRL_OFST, |
| 1415 | .ce_set_mask = ALTR_A10_ECC_TSERRA, |
| 1416 | .ue_set_mask = ALTR_A10_ECC_TDERRA, |
| 1417 | .set_err_ofst = ALTR_A10_ECC_INTTEST_OFST, |
| 1418 | .ecc_irq_handler = altr_edac_a10_ecc_irq, |
Thor Thayer | 064acbd | 2018-09-25 08:49:01 -0500 | [diff] [blame] | 1419 | .inject_fops = &altr_edac_a10_device_inject2_fops, |
Thor Thayer | ab8c1e0 | 2016-06-22 08:58:58 -0500 | [diff] [blame] | 1420 | }; |
| 1421 | |
Thor Thayer | ab8c1e0 | 2016-06-22 08:58:58 -0500 | [diff] [blame] | 1422 | #endif /* CONFIG_EDAC_ALTERA_ETHERNET */ |
| 1423 | |
Thor Thayer | c6882fb | 2016-07-14 11:06:43 -0500 | [diff] [blame] | 1424 | /********************** NAND Device Functions **********************/ |
| 1425 | |
| 1426 | #ifdef CONFIG_EDAC_ALTERA_NAND |
| 1427 | |
Thor Thayer | 788586e | 2019-03-26 16:29:31 -0500 | [diff] [blame] | 1428 | static int __init socfpga_init_nand_ecc(struct altr_edac_device_dev *device) |
| 1429 | { |
| 1430 | int ret; |
| 1431 | |
| 1432 | ret = altr_init_a10_ecc_device_type("altr,socfpga-nand-ecc"); |
| 1433 | if (ret) |
| 1434 | return ret; |
| 1435 | |
| 1436 | return altr_check_ecc_deps(device); |
| 1437 | } |
| 1438 | |
Thor Thayer | c6882fb | 2016-07-14 11:06:43 -0500 | [diff] [blame] | 1439 | static const struct edac_device_prv_data a10_nandecc_data = { |
Thor Thayer | 788586e | 2019-03-26 16:29:31 -0500 | [diff] [blame] | 1440 | .setup = socfpga_init_nand_ecc, |
Thor Thayer | c6882fb | 2016-07-14 11:06:43 -0500 | [diff] [blame] | 1441 | .ce_clear_mask = ALTR_A10_ECC_SERRPENA, |
| 1442 | .ue_clear_mask = ALTR_A10_ECC_DERRPENA, |
Thor Thayer | c6882fb | 2016-07-14 11:06:43 -0500 | [diff] [blame] | 1443 | .ecc_enable_mask = ALTR_A10_COMMON_ECC_EN_CTL, |
| 1444 | .ecc_en_ofst = ALTR_A10_ECC_CTRL_OFST, |
| 1445 | .ce_set_mask = ALTR_A10_ECC_TSERRA, |
| 1446 | .ue_set_mask = ALTR_A10_ECC_TDERRA, |
| 1447 | .set_err_ofst = ALTR_A10_ECC_INTTEST_OFST, |
| 1448 | .ecc_irq_handler = altr_edac_a10_ecc_irq, |
| 1449 | .inject_fops = &altr_edac_a10_device_inject_fops, |
| 1450 | }; |
| 1451 | |
Thor Thayer | c6882fb | 2016-07-14 11:06:43 -0500 | [diff] [blame] | 1452 | #endif /* CONFIG_EDAC_ALTERA_NAND */ |
| 1453 | |
Thor Thayer | e826379 | 2016-07-28 10:03:57 +0200 | [diff] [blame] | 1454 | /********************** DMA Device Functions **********************/ |
| 1455 | |
| 1456 | #ifdef CONFIG_EDAC_ALTERA_DMA |
| 1457 | |
Thor Thayer | 788586e | 2019-03-26 16:29:31 -0500 | [diff] [blame] | 1458 | static int __init socfpga_init_dma_ecc(struct altr_edac_device_dev *device) |
| 1459 | { |
| 1460 | int ret; |
| 1461 | |
| 1462 | ret = altr_init_a10_ecc_device_type("altr,socfpga-dma-ecc"); |
| 1463 | if (ret) |
| 1464 | return ret; |
| 1465 | |
| 1466 | return altr_check_ecc_deps(device); |
| 1467 | } |
| 1468 | |
Thor Thayer | e826379 | 2016-07-28 10:03:57 +0200 | [diff] [blame] | 1469 | static const struct edac_device_prv_data a10_dmaecc_data = { |
Thor Thayer | 788586e | 2019-03-26 16:29:31 -0500 | [diff] [blame] | 1470 | .setup = socfpga_init_dma_ecc, |
Thor Thayer | e826379 | 2016-07-28 10:03:57 +0200 | [diff] [blame] | 1471 | .ce_clear_mask = ALTR_A10_ECC_SERRPENA, |
| 1472 | .ue_clear_mask = ALTR_A10_ECC_DERRPENA, |
Thor Thayer | e826379 | 2016-07-28 10:03:57 +0200 | [diff] [blame] | 1473 | .ecc_enable_mask = ALTR_A10_COMMON_ECC_EN_CTL, |
| 1474 | .ecc_en_ofst = ALTR_A10_ECC_CTRL_OFST, |
| 1475 | .ce_set_mask = ALTR_A10_ECC_TSERRA, |
| 1476 | .ue_set_mask = ALTR_A10_ECC_TDERRA, |
| 1477 | .set_err_ofst = ALTR_A10_ECC_INTTEST_OFST, |
| 1478 | .ecc_irq_handler = altr_edac_a10_ecc_irq, |
| 1479 | .inject_fops = &altr_edac_a10_device_inject_fops, |
| 1480 | }; |
| 1481 | |
Thor Thayer | e826379 | 2016-07-28 10:03:57 +0200 | [diff] [blame] | 1482 | #endif /* CONFIG_EDAC_ALTERA_DMA */ |
| 1483 | |
Thor Thayer | c609581 | 2016-07-14 11:06:45 -0500 | [diff] [blame] | 1484 | /********************** USB Device Functions **********************/ |
| 1485 | |
| 1486 | #ifdef CONFIG_EDAC_ALTERA_USB |
| 1487 | |
Thor Thayer | 788586e | 2019-03-26 16:29:31 -0500 | [diff] [blame] | 1488 | static int __init socfpga_init_usb_ecc(struct altr_edac_device_dev *device) |
| 1489 | { |
| 1490 | int ret; |
| 1491 | |
| 1492 | ret = altr_init_a10_ecc_device_type("altr,socfpga-usb-ecc"); |
| 1493 | if (ret) |
| 1494 | return ret; |
| 1495 | |
| 1496 | return altr_check_ecc_deps(device); |
| 1497 | } |
| 1498 | |
Thor Thayer | c609581 | 2016-07-14 11:06:45 -0500 | [diff] [blame] | 1499 | static const struct edac_device_prv_data a10_usbecc_data = { |
Thor Thayer | 788586e | 2019-03-26 16:29:31 -0500 | [diff] [blame] | 1500 | .setup = socfpga_init_usb_ecc, |
Thor Thayer | c609581 | 2016-07-14 11:06:45 -0500 | [diff] [blame] | 1501 | .ce_clear_mask = ALTR_A10_ECC_SERRPENA, |
| 1502 | .ue_clear_mask = ALTR_A10_ECC_DERRPENA, |
Thor Thayer | c609581 | 2016-07-14 11:06:45 -0500 | [diff] [blame] | 1503 | .ecc_enable_mask = ALTR_A10_COMMON_ECC_EN_CTL, |
| 1504 | .ecc_en_ofst = ALTR_A10_ECC_CTRL_OFST, |
| 1505 | .ce_set_mask = ALTR_A10_ECC_TSERRA, |
| 1506 | .ue_set_mask = ALTR_A10_ECC_TDERRA, |
| 1507 | .set_err_ofst = ALTR_A10_ECC_INTTEST_OFST, |
| 1508 | .ecc_irq_handler = altr_edac_a10_ecc_irq, |
Thor Thayer | 064acbd | 2018-09-25 08:49:01 -0500 | [diff] [blame] | 1509 | .inject_fops = &altr_edac_a10_device_inject2_fops, |
Thor Thayer | c609581 | 2016-07-14 11:06:45 -0500 | [diff] [blame] | 1510 | }; |
| 1511 | |
Thor Thayer | c609581 | 2016-07-14 11:06:45 -0500 | [diff] [blame] | 1512 | #endif /* CONFIG_EDAC_ALTERA_USB */ |
| 1513 | |
Thor Thayer | 485fe9e | 2016-07-14 11:06:46 -0500 | [diff] [blame] | 1514 | /********************** QSPI Device Functions **********************/ |
| 1515 | |
| 1516 | #ifdef CONFIG_EDAC_ALTERA_QSPI |
| 1517 | |
Thor Thayer | 788586e | 2019-03-26 16:29:31 -0500 | [diff] [blame] | 1518 | static int __init socfpga_init_qspi_ecc(struct altr_edac_device_dev *device) |
| 1519 | { |
| 1520 | int ret; |
| 1521 | |
| 1522 | ret = altr_init_a10_ecc_device_type("altr,socfpga-qspi-ecc"); |
| 1523 | if (ret) |
| 1524 | return ret; |
| 1525 | |
| 1526 | return altr_check_ecc_deps(device); |
| 1527 | } |
| 1528 | |
Thor Thayer | 485fe9e | 2016-07-14 11:06:46 -0500 | [diff] [blame] | 1529 | static const struct edac_device_prv_data a10_qspiecc_data = { |
Thor Thayer | 788586e | 2019-03-26 16:29:31 -0500 | [diff] [blame] | 1530 | .setup = socfpga_init_qspi_ecc, |
Thor Thayer | 485fe9e | 2016-07-14 11:06:46 -0500 | [diff] [blame] | 1531 | .ce_clear_mask = ALTR_A10_ECC_SERRPENA, |
| 1532 | .ue_clear_mask = ALTR_A10_ECC_DERRPENA, |
Thor Thayer | 485fe9e | 2016-07-14 11:06:46 -0500 | [diff] [blame] | 1533 | .ecc_enable_mask = ALTR_A10_COMMON_ECC_EN_CTL, |
| 1534 | .ecc_en_ofst = ALTR_A10_ECC_CTRL_OFST, |
| 1535 | .ce_set_mask = ALTR_A10_ECC_TSERRA, |
| 1536 | .ue_set_mask = ALTR_A10_ECC_TDERRA, |
| 1537 | .set_err_ofst = ALTR_A10_ECC_INTTEST_OFST, |
| 1538 | .ecc_irq_handler = altr_edac_a10_ecc_irq, |
| 1539 | .inject_fops = &altr_edac_a10_device_inject_fops, |
| 1540 | }; |
| 1541 | |
Thor Thayer | 485fe9e | 2016-07-14 11:06:46 -0500 | [diff] [blame] | 1542 | #endif /* CONFIG_EDAC_ALTERA_QSPI */ |
| 1543 | |
Thor Thayer | 9110498 | 2016-08-09 09:40:52 -0500 | [diff] [blame] | 1544 | /********************* SDMMC Device Functions **********************/ |
| 1545 | |
| 1546 | #ifdef CONFIG_EDAC_ALTERA_SDMMC |
| 1547 | |
| 1548 | static const struct edac_device_prv_data a10_sdmmceccb_data; |
| 1549 | static int altr_portb_setup(struct altr_edac_device_dev *device) |
| 1550 | { |
| 1551 | struct edac_device_ctl_info *dci; |
| 1552 | struct altr_edac_device_dev *altdev; |
| 1553 | char *ecc_name = "sdmmcb-ecc"; |
| 1554 | int edac_idx, rc; |
| 1555 | struct device_node *np; |
| 1556 | const struct edac_device_prv_data *prv = &a10_sdmmceccb_data; |
| 1557 | |
| 1558 | rc = altr_check_ecc_deps(device); |
| 1559 | if (rc) |
| 1560 | return rc; |
| 1561 | |
| 1562 | np = of_find_compatible_node(NULL, NULL, "altr,socfpga-sdmmc-ecc"); |
| 1563 | if (!np) { |
| 1564 | edac_printk(KERN_WARNING, EDAC_DEVICE, "SDMMC node not found\n"); |
| 1565 | return -ENODEV; |
| 1566 | } |
| 1567 | |
| 1568 | /* Create the PortB EDAC device */ |
| 1569 | edac_idx = edac_device_alloc_index(); |
| 1570 | dci = edac_device_alloc_ctl_info(sizeof(*altdev), ecc_name, 1, |
| 1571 | ecc_name, 1, 0, NULL, 0, edac_idx); |
| 1572 | if (!dci) { |
| 1573 | edac_printk(KERN_ERR, EDAC_DEVICE, |
| 1574 | "%s: Unable to allocate PortB EDAC device\n", |
| 1575 | ecc_name); |
| 1576 | return -ENOMEM; |
| 1577 | } |
| 1578 | |
| 1579 | /* Initialize the PortB EDAC device structure from PortA structure */ |
| 1580 | altdev = dci->pvt_info; |
| 1581 | *altdev = *device; |
| 1582 | |
| 1583 | if (!devres_open_group(&altdev->ddev, altr_portb_setup, GFP_KERNEL)) |
| 1584 | return -ENOMEM; |
| 1585 | |
| 1586 | /* Update PortB specific values */ |
| 1587 | altdev->edac_dev_name = ecc_name; |
| 1588 | altdev->edac_idx = edac_idx; |
| 1589 | altdev->edac_dev = dci; |
| 1590 | altdev->data = prv; |
| 1591 | dci->dev = &altdev->ddev; |
| 1592 | dci->ctl_name = "Altera ECC Manager"; |
| 1593 | dci->mod_name = ecc_name; |
| 1594 | dci->dev_name = ecc_name; |
| 1595 | |
Thor Thayer | a428b4d | 2019-04-23 09:36:36 -0500 | [diff] [blame] | 1596 | /* Update the PortB IRQs - A10 has 4, S10 has 2, Index accordingly */ |
| 1597 | #ifdef CONFIG_ARCH_STRATIX10 |
| 1598 | altdev->sb_irq = irq_of_parse_and_map(np, 1); |
| 1599 | #else |
Thor Thayer | 9110498 | 2016-08-09 09:40:52 -0500 | [diff] [blame] | 1600 | altdev->sb_irq = irq_of_parse_and_map(np, 2); |
Thor Thayer | a428b4d | 2019-04-23 09:36:36 -0500 | [diff] [blame] | 1601 | #endif |
Thor Thayer | 9110498 | 2016-08-09 09:40:52 -0500 | [diff] [blame] | 1602 | if (!altdev->sb_irq) { |
| 1603 | edac_printk(KERN_ERR, EDAC_DEVICE, "Error PortB SBIRQ alloc\n"); |
| 1604 | rc = -ENODEV; |
| 1605 | goto err_release_group_1; |
| 1606 | } |
| 1607 | rc = devm_request_irq(&altdev->ddev, altdev->sb_irq, |
| 1608 | prv->ecc_irq_handler, |
Thor Thayer | a29d64a | 2016-09-22 17:13:39 -0500 | [diff] [blame] | 1609 | IRQF_ONESHOT | IRQF_TRIGGER_HIGH, |
| 1610 | ecc_name, altdev); |
Thor Thayer | 9110498 | 2016-08-09 09:40:52 -0500 | [diff] [blame] | 1611 | if (rc) { |
| 1612 | edac_printk(KERN_ERR, EDAC_DEVICE, "PortB SBERR IRQ error\n"); |
| 1613 | goto err_release_group_1; |
| 1614 | } |
| 1615 | |
Thor Thayer | a428b4d | 2019-04-23 09:36:36 -0500 | [diff] [blame] | 1616 | #ifdef CONFIG_ARCH_STRATIX10 |
| 1617 | /* Use IRQ to determine SError origin instead of assigning IRQ */ |
| 1618 | rc = of_property_read_u32_index(np, "interrupts", 1, &altdev->db_irq); |
| 1619 | if (rc) { |
| 1620 | edac_printk(KERN_ERR, EDAC_DEVICE, |
| 1621 | "Error PortB DBIRQ alloc\n"); |
| 1622 | goto err_release_group_1; |
| 1623 | } |
| 1624 | #else |
Thor Thayer | 9110498 | 2016-08-09 09:40:52 -0500 | [diff] [blame] | 1625 | altdev->db_irq = irq_of_parse_and_map(np, 3); |
| 1626 | if (!altdev->db_irq) { |
| 1627 | edac_printk(KERN_ERR, EDAC_DEVICE, "Error PortB DBIRQ alloc\n"); |
| 1628 | rc = -ENODEV; |
| 1629 | goto err_release_group_1; |
| 1630 | } |
| 1631 | rc = devm_request_irq(&altdev->ddev, altdev->db_irq, |
| 1632 | prv->ecc_irq_handler, |
Thor Thayer | a29d64a | 2016-09-22 17:13:39 -0500 | [diff] [blame] | 1633 | IRQF_ONESHOT | IRQF_TRIGGER_HIGH, |
| 1634 | ecc_name, altdev); |
Thor Thayer | 9110498 | 2016-08-09 09:40:52 -0500 | [diff] [blame] | 1635 | if (rc) { |
| 1636 | edac_printk(KERN_ERR, EDAC_DEVICE, "PortB DBERR IRQ error\n"); |
| 1637 | goto err_release_group_1; |
| 1638 | } |
Thor Thayer | a428b4d | 2019-04-23 09:36:36 -0500 | [diff] [blame] | 1639 | #endif |
Thor Thayer | 9110498 | 2016-08-09 09:40:52 -0500 | [diff] [blame] | 1640 | |
| 1641 | rc = edac_device_add_device(dci); |
| 1642 | if (rc) { |
| 1643 | edac_printk(KERN_ERR, EDAC_DEVICE, |
| 1644 | "edac_device_add_device portB failed\n"); |
| 1645 | rc = -ENOMEM; |
| 1646 | goto err_release_group_1; |
| 1647 | } |
| 1648 | altr_create_edacdev_dbgfs(dci, prv); |
| 1649 | |
| 1650 | list_add(&altdev->next, &altdev->edac->a10_ecc_devices); |
| 1651 | |
| 1652 | devres_remove_group(&altdev->ddev, altr_portb_setup); |
| 1653 | |
| 1654 | return 0; |
| 1655 | |
| 1656 | err_release_group_1: |
| 1657 | edac_device_free_ctl_info(dci); |
| 1658 | devres_release_group(&altdev->ddev, altr_portb_setup); |
| 1659 | edac_printk(KERN_ERR, EDAC_DEVICE, |
| 1660 | "%s:Error setting up EDAC device: %d\n", ecc_name, rc); |
| 1661 | return rc; |
| 1662 | } |
| 1663 | |
Thor Thayer | 788586e | 2019-03-26 16:29:31 -0500 | [diff] [blame] | 1664 | static int __init socfpga_init_sdmmc_ecc(struct altr_edac_device_dev *device) |
| 1665 | { |
| 1666 | int rc = -ENODEV; |
| 1667 | struct device_node *child; |
| 1668 | |
| 1669 | child = of_find_compatible_node(NULL, NULL, "altr,socfpga-sdmmc-ecc"); |
| 1670 | if (!child) |
| 1671 | return -ENODEV; |
| 1672 | |
| 1673 | if (!of_device_is_available(child)) |
| 1674 | goto exit; |
| 1675 | |
| 1676 | if (validate_parent_available(child)) |
| 1677 | goto exit; |
| 1678 | |
| 1679 | /* Init portB */ |
| 1680 | rc = altr_init_a10_ecc_block(child, ALTR_A10_SDMMC_IRQ_MASK, |
| 1681 | a10_sdmmceccb_data.ecc_enable_mask, 1); |
| 1682 | if (rc) |
| 1683 | goto exit; |
| 1684 | |
| 1685 | /* Setup portB */ |
| 1686 | return altr_portb_setup(device); |
| 1687 | |
| 1688 | exit: |
| 1689 | of_node_put(child); |
| 1690 | return rc; |
| 1691 | } |
| 1692 | |
Thor Thayer | 9110498 | 2016-08-09 09:40:52 -0500 | [diff] [blame] | 1693 | static irqreturn_t altr_edac_a10_ecc_irq_portb(int irq, void *dev_id) |
| 1694 | { |
| 1695 | struct altr_edac_device_dev *ad = dev_id; |
| 1696 | void __iomem *base = ad->base; |
| 1697 | const struct edac_device_prv_data *priv = ad->data; |
| 1698 | |
| 1699 | if (irq == ad->sb_irq) { |
| 1700 | writel(priv->ce_clear_mask, |
| 1701 | base + ALTR_A10_ECC_INTSTAT_OFST); |
| 1702 | edac_device_handle_ce(ad->edac_dev, 0, 0, ad->edac_dev_name); |
| 1703 | return IRQ_HANDLED; |
| 1704 | } else if (irq == ad->db_irq) { |
| 1705 | writel(priv->ue_clear_mask, |
| 1706 | base + ALTR_A10_ECC_INTSTAT_OFST); |
| 1707 | edac_device_handle_ue(ad->edac_dev, 0, 0, ad->edac_dev_name); |
| 1708 | return IRQ_HANDLED; |
| 1709 | } |
| 1710 | |
| 1711 | WARN_ONCE(1, "Unhandled IRQ%d on Port B.", irq); |
| 1712 | |
| 1713 | return IRQ_NONE; |
| 1714 | } |
| 1715 | |
| 1716 | static const struct edac_device_prv_data a10_sdmmcecca_data = { |
Thor Thayer | 788586e | 2019-03-26 16:29:31 -0500 | [diff] [blame] | 1717 | .setup = socfpga_init_sdmmc_ecc, |
Thor Thayer | 9110498 | 2016-08-09 09:40:52 -0500 | [diff] [blame] | 1718 | .ce_clear_mask = ALTR_A10_ECC_SERRPENA, |
| 1719 | .ue_clear_mask = ALTR_A10_ECC_DERRPENA, |
Thor Thayer | 9110498 | 2016-08-09 09:40:52 -0500 | [diff] [blame] | 1720 | .ecc_enable_mask = ALTR_A10_COMMON_ECC_EN_CTL, |
| 1721 | .ecc_en_ofst = ALTR_A10_ECC_CTRL_OFST, |
| 1722 | .ce_set_mask = ALTR_A10_ECC_SERRPENA, |
| 1723 | .ue_set_mask = ALTR_A10_ECC_DERRPENA, |
| 1724 | .set_err_ofst = ALTR_A10_ECC_INTTEST_OFST, |
| 1725 | .ecc_irq_handler = altr_edac_a10_ecc_irq, |
| 1726 | .inject_fops = &altr_edac_a10_device_inject_fops, |
| 1727 | }; |
| 1728 | |
| 1729 | static const struct edac_device_prv_data a10_sdmmceccb_data = { |
Thor Thayer | 788586e | 2019-03-26 16:29:31 -0500 | [diff] [blame] | 1730 | .setup = socfpga_init_sdmmc_ecc, |
Thor Thayer | 9110498 | 2016-08-09 09:40:52 -0500 | [diff] [blame] | 1731 | .ce_clear_mask = ALTR_A10_ECC_SERRPENB, |
| 1732 | .ue_clear_mask = ALTR_A10_ECC_DERRPENB, |
Thor Thayer | 9110498 | 2016-08-09 09:40:52 -0500 | [diff] [blame] | 1733 | .ecc_enable_mask = ALTR_A10_COMMON_ECC_EN_CTL, |
| 1734 | .ecc_en_ofst = ALTR_A10_ECC_CTRL_OFST, |
| 1735 | .ce_set_mask = ALTR_A10_ECC_TSERRB, |
| 1736 | .ue_set_mask = ALTR_A10_ECC_TDERRB, |
| 1737 | .set_err_ofst = ALTR_A10_ECC_INTTEST_OFST, |
| 1738 | .ecc_irq_handler = altr_edac_a10_ecc_irq_portb, |
| 1739 | .inject_fops = &altr_edac_a10_device_inject_fops, |
| 1740 | }; |
| 1741 | |
Thor Thayer | 9110498 | 2016-08-09 09:40:52 -0500 | [diff] [blame] | 1742 | #endif /* CONFIG_EDAC_ALTERA_SDMMC */ |
| 1743 | |
Thor Thayer | 588cb03 | 2016-03-21 11:01:44 -0500 | [diff] [blame] | 1744 | /********************* Arria10 EDAC Device Functions *************************/ |
Thor Thayer | ab564cb | 2016-05-25 11:29:41 -0500 | [diff] [blame] | 1745 | static const struct of_device_id altr_edac_a10_device_of_match[] = { |
| 1746 | #ifdef CONFIG_EDAC_ALTERA_L2C |
| 1747 | { .compatible = "altr,socfpga-a10-l2-ecc", .data = &a10_l2ecc_data }, |
| 1748 | #endif |
| 1749 | #ifdef CONFIG_EDAC_ALTERA_OCRAM |
| 1750 | { .compatible = "altr,socfpga-a10-ocram-ecc", |
| 1751 | .data = &a10_ocramecc_data }, |
| 1752 | #endif |
Thor Thayer | ab8c1e0 | 2016-06-22 08:58:58 -0500 | [diff] [blame] | 1753 | #ifdef CONFIG_EDAC_ALTERA_ETHERNET |
| 1754 | { .compatible = "altr,socfpga-eth-mac-ecc", |
| 1755 | .data = &a10_enetecc_data }, |
| 1756 | #endif |
Thor Thayer | c6882fb | 2016-07-14 11:06:43 -0500 | [diff] [blame] | 1757 | #ifdef CONFIG_EDAC_ALTERA_NAND |
| 1758 | { .compatible = "altr,socfpga-nand-ecc", .data = &a10_nandecc_data }, |
| 1759 | #endif |
Thor Thayer | e826379 | 2016-07-28 10:03:57 +0200 | [diff] [blame] | 1760 | #ifdef CONFIG_EDAC_ALTERA_DMA |
| 1761 | { .compatible = "altr,socfpga-dma-ecc", .data = &a10_dmaecc_data }, |
| 1762 | #endif |
Thor Thayer | c609581 | 2016-07-14 11:06:45 -0500 | [diff] [blame] | 1763 | #ifdef CONFIG_EDAC_ALTERA_USB |
| 1764 | { .compatible = "altr,socfpga-usb-ecc", .data = &a10_usbecc_data }, |
| 1765 | #endif |
Thor Thayer | 485fe9e | 2016-07-14 11:06:46 -0500 | [diff] [blame] | 1766 | #ifdef CONFIG_EDAC_ALTERA_QSPI |
| 1767 | { .compatible = "altr,socfpga-qspi-ecc", .data = &a10_qspiecc_data }, |
| 1768 | #endif |
Thor Thayer | 9110498 | 2016-08-09 09:40:52 -0500 | [diff] [blame] | 1769 | #ifdef CONFIG_EDAC_ALTERA_SDMMC |
| 1770 | { .compatible = "altr,socfpga-sdmmc-ecc", .data = &a10_sdmmcecca_data }, |
| 1771 | #endif |
Thor Thayer | 3123c5c | 2019-07-12 13:28:43 -0500 | [diff] [blame] | 1772 | #ifdef CONFIG_EDAC_ALTERA_SDRAM |
| 1773 | { .compatible = "altr,sdram-edac-s10", .data = &s10_sdramecc_data }, |
| 1774 | #endif |
Thor Thayer | ab564cb | 2016-05-25 11:29:41 -0500 | [diff] [blame] | 1775 | {}, |
| 1776 | }; |
| 1777 | MODULE_DEVICE_TABLE(of, altr_edac_a10_device_of_match); |
Thor Thayer | 588cb03 | 2016-03-21 11:01:44 -0500 | [diff] [blame] | 1778 | |
| 1779 | /* |
| 1780 | * The Arria10 EDAC Device Functions differ from the Cyclone5/Arria5 |
| 1781 | * because 2 IRQs are shared among the all ECC peripherals. The ECC |
| 1782 | * manager manages the IRQs and the children. |
| 1783 | * Based on xgene_edac.c peripheral code. |
| 1784 | */ |
| 1785 | |
Thor Thayer | c7b4be8 | 2016-04-06 20:22:54 -0500 | [diff] [blame] | 1786 | static ssize_t altr_edac_a10_device_trig(struct file *file, |
| 1787 | const char __user *user_buf, |
| 1788 | size_t count, loff_t *ppos) |
| 1789 | { |
| 1790 | struct edac_device_ctl_info *edac_dci = file->private_data; |
| 1791 | struct altr_edac_device_dev *drvdata = edac_dci->pvt_info; |
| 1792 | const struct edac_device_prv_data *priv = drvdata->data; |
| 1793 | void __iomem *set_addr = (drvdata->base + priv->set_err_ofst); |
| 1794 | unsigned long flags; |
| 1795 | u8 trig_type; |
| 1796 | |
| 1797 | if (!user_buf || get_user(trig_type, user_buf)) |
| 1798 | return -EFAULT; |
| 1799 | |
| 1800 | local_irq_save(flags); |
| 1801 | if (trig_type == ALTR_UE_TRIGGER_CHAR) |
| 1802 | writel(priv->ue_set_mask, set_addr); |
| 1803 | else |
| 1804 | writel(priv->ce_set_mask, set_addr); |
Thor Thayer | 064acbd | 2018-09-25 08:49:01 -0500 | [diff] [blame] | 1805 | |
| 1806 | /* Ensure the interrupt test bits are set */ |
| 1807 | wmb(); |
| 1808 | local_irq_restore(flags); |
| 1809 | |
| 1810 | return count; |
| 1811 | } |
| 1812 | |
| 1813 | /* |
| 1814 | * The Stratix10 EDAC Error Injection Functions differ from Arria10 |
| 1815 | * slightly. A few Arria10 peripherals can use this injection function. |
| 1816 | * Inject the error into the memory and then readback to trigger the IRQ. |
| 1817 | */ |
| 1818 | static ssize_t altr_edac_a10_device_trig2(struct file *file, |
| 1819 | const char __user *user_buf, |
| 1820 | size_t count, loff_t *ppos) |
| 1821 | { |
| 1822 | struct edac_device_ctl_info *edac_dci = file->private_data; |
| 1823 | struct altr_edac_device_dev *drvdata = edac_dci->pvt_info; |
| 1824 | const struct edac_device_prv_data *priv = drvdata->data; |
| 1825 | void __iomem *set_addr = (drvdata->base + priv->set_err_ofst); |
| 1826 | unsigned long flags; |
| 1827 | u8 trig_type; |
| 1828 | |
| 1829 | if (!user_buf || get_user(trig_type, user_buf)) |
| 1830 | return -EFAULT; |
| 1831 | |
| 1832 | local_irq_save(flags); |
| 1833 | if (trig_type == ALTR_UE_TRIGGER_CHAR) { |
| 1834 | writel(priv->ue_set_mask, set_addr); |
| 1835 | } else { |
Thor Thayer | 436b0a5 | 2019-03-26 16:29:30 -0500 | [diff] [blame] | 1836 | /* Setup read/write of 4 bytes */ |
Thor Thayer | 064acbd | 2018-09-25 08:49:01 -0500 | [diff] [blame] | 1837 | writel(ECC_WORD_WRITE, drvdata->base + ECC_BLK_DBYTECTRL_OFST); |
| 1838 | /* Setup Address to 0 */ |
Thor Thayer | 436b0a5 | 2019-03-26 16:29:30 -0500 | [diff] [blame] | 1839 | writel(0, drvdata->base + ECC_BLK_ADDRESS_OFST); |
| 1840 | /* Setup accctrl to read & ecc & data override */ |
| 1841 | writel(ECC_READ_EDOVR, drvdata->base + ECC_BLK_ACCCTRL_OFST); |
Thor Thayer | 064acbd | 2018-09-25 08:49:01 -0500 | [diff] [blame] | 1842 | /* Kick it. */ |
| 1843 | writel(ECC_XACT_KICK, drvdata->base + ECC_BLK_STARTACC_OFST); |
| 1844 | /* Setup write for single bit change */ |
Thor Thayer | 436b0a5 | 2019-03-26 16:29:30 -0500 | [diff] [blame] | 1845 | writel(readl(drvdata->base + ECC_BLK_RDATA0_OFST) ^ 0x1, |
| 1846 | drvdata->base + ECC_BLK_WDATA0_OFST); |
| 1847 | writel(readl(drvdata->base + ECC_BLK_RDATA1_OFST), |
| 1848 | drvdata->base + ECC_BLK_WDATA1_OFST); |
| 1849 | writel(readl(drvdata->base + ECC_BLK_RDATA2_OFST), |
| 1850 | drvdata->base + ECC_BLK_WDATA2_OFST); |
| 1851 | writel(readl(drvdata->base + ECC_BLK_RDATA3_OFST), |
| 1852 | drvdata->base + ECC_BLK_WDATA3_OFST); |
| 1853 | |
Thor Thayer | 064acbd | 2018-09-25 08:49:01 -0500 | [diff] [blame] | 1854 | /* Copy Read ECC to Write ECC */ |
| 1855 | writel(readl(drvdata->base + ECC_BLK_RECC0_OFST), |
| 1856 | drvdata->base + ECC_BLK_WECC0_OFST); |
| 1857 | writel(readl(drvdata->base + ECC_BLK_RECC1_OFST), |
| 1858 | drvdata->base + ECC_BLK_WECC1_OFST); |
| 1859 | /* Setup accctrl to write & ecc override & data override */ |
| 1860 | writel(ECC_WRITE_EDOVR, drvdata->base + ECC_BLK_ACCCTRL_OFST); |
| 1861 | /* Kick it. */ |
| 1862 | writel(ECC_XACT_KICK, drvdata->base + ECC_BLK_STARTACC_OFST); |
| 1863 | /* Setup accctrl to read & ecc overwrite & data overwrite */ |
| 1864 | writel(ECC_READ_EDOVR, drvdata->base + ECC_BLK_ACCCTRL_OFST); |
| 1865 | /* Kick it. */ |
| 1866 | writel(ECC_XACT_KICK, drvdata->base + ECC_BLK_STARTACC_OFST); |
| 1867 | } |
| 1868 | |
Thor Thayer | c7b4be8 | 2016-04-06 20:22:54 -0500 | [diff] [blame] | 1869 | /* Ensure the interrupt test bits are set */ |
| 1870 | wmb(); |
| 1871 | local_irq_restore(flags); |
| 1872 | |
| 1873 | return count; |
| 1874 | } |
| 1875 | |
Thor Thayer | 13ab844 | 2016-06-07 15:35:57 -0500 | [diff] [blame] | 1876 | static void altr_edac_a10_irq_handler(struct irq_desc *desc) |
Thor Thayer | 588cb03 | 2016-03-21 11:01:44 -0500 | [diff] [blame] | 1877 | { |
Thor Thayer | 13ab844 | 2016-06-07 15:35:57 -0500 | [diff] [blame] | 1878 | int dberr, bit, sm_offset, irq_status; |
| 1879 | struct altr_arria10_edac *edac = irq_desc_get_handler_data(desc); |
| 1880 | struct irq_chip *chip = irq_desc_get_chip(desc); |
| 1881 | int irq = irq_desc_get_irq(desc); |
Dan Carpenter | 8faa1cf | 2019-06-24 16:47:17 +0300 | [diff] [blame] | 1882 | unsigned long bits; |
Thor Thayer | 13ab844 | 2016-06-07 15:35:57 -0500 | [diff] [blame] | 1883 | |
| 1884 | dberr = (irq == edac->db_irq) ? 1 : 0; |
| 1885 | sm_offset = dberr ? A10_SYSMGR_ECC_INTSTAT_DERR_OFST : |
| 1886 | A10_SYSMGR_ECC_INTSTAT_SERR_OFST; |
| 1887 | |
| 1888 | chained_irq_enter(chip, desc); |
Thor Thayer | 588cb03 | 2016-03-21 11:01:44 -0500 | [diff] [blame] | 1889 | |
| 1890 | regmap_read(edac->ecc_mgr_map, sm_offset, &irq_status); |
| 1891 | |
Dan Carpenter | 8faa1cf | 2019-06-24 16:47:17 +0300 | [diff] [blame] | 1892 | bits = irq_status; |
| 1893 | for_each_set_bit(bit, &bits, 32) { |
Thor Thayer | 13ab844 | 2016-06-07 15:35:57 -0500 | [diff] [blame] | 1894 | irq = irq_linear_revmap(edac->domain, dberr * 32 + bit); |
| 1895 | if (irq) |
| 1896 | generic_handle_irq(irq); |
Thor Thayer | 588cb03 | 2016-03-21 11:01:44 -0500 | [diff] [blame] | 1897 | } |
| 1898 | |
Thor Thayer | 13ab844 | 2016-06-07 15:35:57 -0500 | [diff] [blame] | 1899 | chained_irq_exit(chip, desc); |
Thor Thayer | 588cb03 | 2016-03-21 11:01:44 -0500 | [diff] [blame] | 1900 | } |
| 1901 | |
Thor Thayer | 44ec9b3 | 2016-06-22 08:58:52 -0500 | [diff] [blame] | 1902 | static int validate_parent_available(struct device_node *np) |
| 1903 | { |
| 1904 | struct device_node *parent; |
| 1905 | int ret = 0; |
| 1906 | |
Thor Thayer | 3123c5c | 2019-07-12 13:28:43 -0500 | [diff] [blame] | 1907 | /* SDRAM must be present for Linux (implied parent) */ |
| 1908 | if (of_device_is_compatible(np, "altr,sdram-edac-s10")) |
| 1909 | return 0; |
| 1910 | |
Thor Thayer | 44ec9b3 | 2016-06-22 08:58:52 -0500 | [diff] [blame] | 1911 | /* Ensure parent device is enabled if parent node exists */ |
| 1912 | parent = of_parse_phandle(np, "altr,ecc-parent", 0); |
| 1913 | if (parent && !of_device_is_available(parent)) |
| 1914 | ret = -ENODEV; |
| 1915 | |
| 1916 | of_node_put(parent); |
| 1917 | return ret; |
| 1918 | } |
| 1919 | |
Thor Thayer | 3123c5c | 2019-07-12 13:28:43 -0500 | [diff] [blame] | 1920 | static int get_s10_sdram_edac_resource(struct device_node *np, |
| 1921 | struct resource *res) |
| 1922 | { |
| 1923 | struct device_node *parent; |
| 1924 | int ret; |
| 1925 | |
| 1926 | parent = of_parse_phandle(np, "altr,sdr-syscon", 0); |
| 1927 | if (!parent) |
| 1928 | return -ENODEV; |
| 1929 | |
| 1930 | ret = of_address_to_resource(parent, 0, res); |
| 1931 | of_node_put(parent); |
| 1932 | |
| 1933 | return ret; |
| 1934 | } |
| 1935 | |
Thor Thayer | 588cb03 | 2016-03-21 11:01:44 -0500 | [diff] [blame] | 1936 | static int altr_edac_a10_device_add(struct altr_arria10_edac *edac, |
| 1937 | struct device_node *np) |
| 1938 | { |
| 1939 | struct edac_device_ctl_info *dci; |
| 1940 | struct altr_edac_device_dev *altdev; |
| 1941 | char *ecc_name = (char *)np->name; |
| 1942 | struct resource res; |
| 1943 | int edac_idx; |
| 1944 | int rc = 0; |
| 1945 | const struct edac_device_prv_data *prv; |
| 1946 | /* Get matching node and check for valid result */ |
| 1947 | const struct of_device_id *pdev_id = |
Thor Thayer | ab564cb | 2016-05-25 11:29:41 -0500 | [diff] [blame] | 1948 | of_match_node(altr_edac_a10_device_of_match, np); |
Thor Thayer | 588cb03 | 2016-03-21 11:01:44 -0500 | [diff] [blame] | 1949 | if (IS_ERR_OR_NULL(pdev_id)) |
| 1950 | return -ENODEV; |
| 1951 | |
| 1952 | /* Get driver specific data for this EDAC device */ |
| 1953 | prv = pdev_id->data; |
| 1954 | if (IS_ERR_OR_NULL(prv)) |
| 1955 | return -ENODEV; |
| 1956 | |
Thor Thayer | 44ec9b3 | 2016-06-22 08:58:52 -0500 | [diff] [blame] | 1957 | if (validate_parent_available(np)) |
| 1958 | return -ENODEV; |
| 1959 | |
Thor Thayer | 588cb03 | 2016-03-21 11:01:44 -0500 | [diff] [blame] | 1960 | if (!devres_open_group(edac->dev, altr_edac_a10_device_add, GFP_KERNEL)) |
| 1961 | return -ENOMEM; |
| 1962 | |
Thor Thayer | 3123c5c | 2019-07-12 13:28:43 -0500 | [diff] [blame] | 1963 | if (of_device_is_compatible(np, "altr,sdram-edac-s10")) |
| 1964 | rc = get_s10_sdram_edac_resource(np, &res); |
| 1965 | else |
| 1966 | rc = of_address_to_resource(np, 0, &res); |
| 1967 | |
Thor Thayer | 588cb03 | 2016-03-21 11:01:44 -0500 | [diff] [blame] | 1968 | if (rc < 0) { |
| 1969 | edac_printk(KERN_ERR, EDAC_DEVICE, |
| 1970 | "%s: no resource address\n", ecc_name); |
| 1971 | goto err_release_group; |
| 1972 | } |
| 1973 | |
| 1974 | edac_idx = edac_device_alloc_index(); |
| 1975 | dci = edac_device_alloc_ctl_info(sizeof(*altdev), ecc_name, |
| 1976 | 1, ecc_name, 1, 0, NULL, 0, |
| 1977 | edac_idx); |
| 1978 | |
| 1979 | if (!dci) { |
| 1980 | edac_printk(KERN_ERR, EDAC_DEVICE, |
| 1981 | "%s: Unable to allocate EDAC device\n", ecc_name); |
| 1982 | rc = -ENOMEM; |
| 1983 | goto err_release_group; |
| 1984 | } |
| 1985 | |
| 1986 | altdev = dci->pvt_info; |
| 1987 | dci->dev = edac->dev; |
| 1988 | altdev->edac_dev_name = ecc_name; |
| 1989 | altdev->edac_idx = edac_idx; |
| 1990 | altdev->edac = edac; |
| 1991 | altdev->edac_dev = dci; |
| 1992 | altdev->data = prv; |
| 1993 | altdev->ddev = *edac->dev; |
| 1994 | dci->dev = &altdev->ddev; |
| 1995 | dci->ctl_name = "Altera ECC Manager"; |
| 1996 | dci->mod_name = ecc_name; |
| 1997 | dci->dev_name = ecc_name; |
| 1998 | |
| 1999 | altdev->base = devm_ioremap_resource(edac->dev, &res); |
| 2000 | if (IS_ERR(altdev->base)) { |
| 2001 | rc = PTR_ERR(altdev->base); |
| 2002 | goto err_release_group1; |
| 2003 | } |
| 2004 | |
| 2005 | /* Check specific dependencies for the module */ |
| 2006 | if (altdev->data->setup) { |
| 2007 | rc = altdev->data->setup(altdev); |
| 2008 | if (rc) |
| 2009 | goto err_release_group1; |
| 2010 | } |
| 2011 | |
Thor Thayer | 13ab844 | 2016-06-07 15:35:57 -0500 | [diff] [blame] | 2012 | altdev->sb_irq = irq_of_parse_and_map(np, 0); |
| 2013 | if (!altdev->sb_irq) { |
| 2014 | edac_printk(KERN_ERR, EDAC_DEVICE, "Error allocating SBIRQ\n"); |
| 2015 | rc = -ENODEV; |
| 2016 | goto err_release_group1; |
| 2017 | } |
Thor Thayer | a29d64a | 2016-09-22 17:13:39 -0500 | [diff] [blame] | 2018 | rc = devm_request_irq(edac->dev, altdev->sb_irq, prv->ecc_irq_handler, |
| 2019 | IRQF_ONESHOT | IRQF_TRIGGER_HIGH, |
| 2020 | ecc_name, altdev); |
Thor Thayer | 13ab844 | 2016-06-07 15:35:57 -0500 | [diff] [blame] | 2021 | if (rc) { |
Thor Thayer | 3763569 | 2016-09-22 17:13:38 -0500 | [diff] [blame] | 2022 | edac_printk(KERN_ERR, EDAC_DEVICE, "No SBERR IRQ resource\n"); |
Thor Thayer | 13ab844 | 2016-06-07 15:35:57 -0500 | [diff] [blame] | 2023 | goto err_release_group1; |
| 2024 | } |
| 2025 | |
Thor Thayer | 1bd76ff | 2019-03-13 10:27:22 -0500 | [diff] [blame] | 2026 | #ifdef CONFIG_ARCH_STRATIX10 |
| 2027 | /* Use IRQ to determine SError origin instead of assigning IRQ */ |
| 2028 | rc = of_property_read_u32_index(np, "interrupts", 0, &altdev->db_irq); |
| 2029 | if (rc) { |
| 2030 | edac_printk(KERN_ERR, EDAC_DEVICE, |
| 2031 | "Unable to parse DB IRQ index\n"); |
| 2032 | goto err_release_group1; |
| 2033 | } |
| 2034 | #else |
Thor Thayer | 13ab844 | 2016-06-07 15:35:57 -0500 | [diff] [blame] | 2035 | altdev->db_irq = irq_of_parse_and_map(np, 1); |
| 2036 | if (!altdev->db_irq) { |
| 2037 | edac_printk(KERN_ERR, EDAC_DEVICE, "Error allocating DBIRQ\n"); |
| 2038 | rc = -ENODEV; |
| 2039 | goto err_release_group1; |
| 2040 | } |
Thor Thayer | a29d64a | 2016-09-22 17:13:39 -0500 | [diff] [blame] | 2041 | rc = devm_request_irq(edac->dev, altdev->db_irq, prv->ecc_irq_handler, |
| 2042 | IRQF_ONESHOT | IRQF_TRIGGER_HIGH, |
| 2043 | ecc_name, altdev); |
Thor Thayer | 13ab844 | 2016-06-07 15:35:57 -0500 | [diff] [blame] | 2044 | if (rc) { |
| 2045 | edac_printk(KERN_ERR, EDAC_DEVICE, "No DBERR IRQ resource\n"); |
| 2046 | goto err_release_group1; |
| 2047 | } |
Thor Thayer | 1bd76ff | 2019-03-13 10:27:22 -0500 | [diff] [blame] | 2048 | #endif |
Thor Thayer | 13ab844 | 2016-06-07 15:35:57 -0500 | [diff] [blame] | 2049 | |
Thor Thayer | 588cb03 | 2016-03-21 11:01:44 -0500 | [diff] [blame] | 2050 | rc = edac_device_add_device(dci); |
| 2051 | if (rc) { |
| 2052 | dev_err(edac->dev, "edac_device_add_device failed\n"); |
| 2053 | rc = -ENOMEM; |
| 2054 | goto err_release_group1; |
| 2055 | } |
| 2056 | |
| 2057 | altr_create_edacdev_dbgfs(dci, prv); |
| 2058 | |
| 2059 | list_add(&altdev->next, &edac->a10_ecc_devices); |
| 2060 | |
| 2061 | devres_remove_group(edac->dev, altr_edac_a10_device_add); |
| 2062 | |
| 2063 | return 0; |
| 2064 | |
| 2065 | err_release_group1: |
| 2066 | edac_device_free_ctl_info(dci); |
| 2067 | err_release_group: |
Thor Thayer | 588cb03 | 2016-03-21 11:01:44 -0500 | [diff] [blame] | 2068 | devres_release_group(edac->dev, NULL); |
| 2069 | edac_printk(KERN_ERR, EDAC_DEVICE, |
| 2070 | "%s:Error setting up EDAC device: %d\n", ecc_name, rc); |
| 2071 | |
| 2072 | return rc; |
| 2073 | } |
| 2074 | |
Thor Thayer | 13ab844 | 2016-06-07 15:35:57 -0500 | [diff] [blame] | 2075 | static void a10_eccmgr_irq_mask(struct irq_data *d) |
| 2076 | { |
| 2077 | struct altr_arria10_edac *edac = irq_data_get_irq_chip_data(d); |
| 2078 | |
| 2079 | regmap_write(edac->ecc_mgr_map, A10_SYSMGR_ECC_INTMASK_SET_OFST, |
| 2080 | BIT(d->hwirq)); |
| 2081 | } |
| 2082 | |
| 2083 | static void a10_eccmgr_irq_unmask(struct irq_data *d) |
| 2084 | { |
| 2085 | struct altr_arria10_edac *edac = irq_data_get_irq_chip_data(d); |
| 2086 | |
| 2087 | regmap_write(edac->ecc_mgr_map, A10_SYSMGR_ECC_INTMASK_CLR_OFST, |
| 2088 | BIT(d->hwirq)); |
| 2089 | } |
| 2090 | |
| 2091 | static int a10_eccmgr_irqdomain_map(struct irq_domain *d, unsigned int irq, |
| 2092 | irq_hw_number_t hwirq) |
| 2093 | { |
| 2094 | struct altr_arria10_edac *edac = d->host_data; |
| 2095 | |
| 2096 | irq_set_chip_and_handler(irq, &edac->irq_chip, handle_simple_irq); |
| 2097 | irq_set_chip_data(irq, edac); |
| 2098 | irq_set_noprobe(irq); |
| 2099 | |
| 2100 | return 0; |
| 2101 | } |
| 2102 | |
Tobias Klauser | 18caec2 | 2017-05-24 15:35:05 +0200 | [diff] [blame] | 2103 | static const struct irq_domain_ops a10_eccmgr_ic_ops = { |
Thor Thayer | 13ab844 | 2016-06-07 15:35:57 -0500 | [diff] [blame] | 2104 | .map = a10_eccmgr_irqdomain_map, |
| 2105 | .xlate = irq_domain_xlate_twocell, |
| 2106 | }; |
| 2107 | |
Thor Thayer | d5fc912 | 2018-09-25 08:48:58 -0500 | [diff] [blame] | 2108 | /************** Stratix 10 EDAC Double Bit Error Handler ************/ |
| 2109 | #define to_a10edac(p, m) container_of(p, struct altr_arria10_edac, m) |
| 2110 | |
Thor Thayer | 1bd76ff | 2019-03-13 10:27:22 -0500 | [diff] [blame] | 2111 | #ifdef CONFIG_ARCH_STRATIX10 |
| 2112 | /* panic routine issues reboot on non-zero panic_timeout */ |
| 2113 | extern int panic_timeout; |
| 2114 | |
Thor Thayer | d5fc912 | 2018-09-25 08:48:58 -0500 | [diff] [blame] | 2115 | /* |
| 2116 | * The double bit error is handled through SError which is fatal. This is |
| 2117 | * called as a panic notifier to printout ECC error info as part of the panic. |
| 2118 | */ |
| 2119 | static int s10_edac_dberr_handler(struct notifier_block *this, |
| 2120 | unsigned long event, void *ptr) |
| 2121 | { |
| 2122 | struct altr_arria10_edac *edac = to_a10edac(this, panic_notifier); |
| 2123 | int err_addr, dberror; |
| 2124 | |
| 2125 | regmap_read(edac->ecc_mgr_map, S10_SYSMGR_ECC_INTSTAT_DERR_OFST, |
| 2126 | &dberror); |
| 2127 | regmap_write(edac->ecc_mgr_map, S10_SYSMGR_UE_VAL_OFST, dberror); |
Thor Thayer | 1bd76ff | 2019-03-13 10:27:22 -0500 | [diff] [blame] | 2128 | if (dberror & S10_DBE_IRQ_MASK) { |
| 2129 | struct list_head *position; |
| 2130 | struct altr_edac_device_dev *ed; |
| 2131 | struct arm_smccc_res result; |
| 2132 | |
| 2133 | /* Find the matching DBE in the list of devices */ |
| 2134 | list_for_each(position, &edac->a10_ecc_devices) { |
| 2135 | ed = list_entry(position, struct altr_edac_device_dev, |
| 2136 | next); |
| 2137 | if (!(BIT(ed->db_irq) & dberror)) |
| 2138 | continue; |
| 2139 | |
| 2140 | writel(ALTR_A10_ECC_DERRPENA, |
| 2141 | ed->base + ALTR_A10_ECC_INTSTAT_OFST); |
| 2142 | err_addr = readl(ed->base + ALTR_S10_DERR_ADDRA_OFST); |
| 2143 | regmap_write(edac->ecc_mgr_map, |
| 2144 | S10_SYSMGR_UE_ADDR_OFST, err_addr); |
| 2145 | edac_printk(KERN_ERR, EDAC_DEVICE, |
| 2146 | "EDAC: [Fatal DBE on %s @ 0x%08X]\n", |
| 2147 | ed->edac_dev_name, err_addr); |
| 2148 | break; |
| 2149 | } |
| 2150 | /* Notify the System through SMC. Reboot delay = 1 second */ |
| 2151 | panic_timeout = 1; |
| 2152 | arm_smccc_smc(INTEL_SIP_SMC_ECC_DBE, dberror, 0, 0, 0, 0, |
| 2153 | 0, 0, &result); |
Thor Thayer | d5fc912 | 2018-09-25 08:48:58 -0500 | [diff] [blame] | 2154 | } |
| 2155 | |
| 2156 | return NOTIFY_DONE; |
| 2157 | } |
Thor Thayer | 1bd76ff | 2019-03-13 10:27:22 -0500 | [diff] [blame] | 2158 | #endif |
Thor Thayer | d5fc912 | 2018-09-25 08:48:58 -0500 | [diff] [blame] | 2159 | |
| 2160 | /****************** Arria 10 EDAC Probe Function *********************/ |
Thor Thayer | 588cb03 | 2016-03-21 11:01:44 -0500 | [diff] [blame] | 2161 | static int altr_edac_a10_probe(struct platform_device *pdev) |
| 2162 | { |
| 2163 | struct altr_arria10_edac *edac; |
| 2164 | struct device_node *child; |
Thor Thayer | 588cb03 | 2016-03-21 11:01:44 -0500 | [diff] [blame] | 2165 | |
| 2166 | edac = devm_kzalloc(&pdev->dev, sizeof(*edac), GFP_KERNEL); |
| 2167 | if (!edac) |
| 2168 | return -ENOMEM; |
| 2169 | |
| 2170 | edac->dev = &pdev->dev; |
| 2171 | platform_set_drvdata(pdev, edac); |
| 2172 | INIT_LIST_HEAD(&edac->a10_ecc_devices); |
| 2173 | |
Thor Thayer | d5fc912 | 2018-09-25 08:48:58 -0500 | [diff] [blame] | 2174 | if (socfpga_is_a10()) { |
| 2175 | edac->ecc_mgr_map = |
| 2176 | syscon_regmap_lookup_by_phandle(pdev->dev.of_node, |
Thor Thayer | 588cb03 | 2016-03-21 11:01:44 -0500 | [diff] [blame] | 2177 | "altr,sysmgr-syscon"); |
Thor Thayer | d5fc912 | 2018-09-25 08:48:58 -0500 | [diff] [blame] | 2178 | } else { |
| 2179 | struct device_node *sysmgr_np; |
| 2180 | struct resource res; |
Arnd Bergmann | 8537bf10 | 2018-09-27 12:09:26 +0200 | [diff] [blame] | 2181 | uintptr_t base; |
Thor Thayer | d5fc912 | 2018-09-25 08:48:58 -0500 | [diff] [blame] | 2182 | |
| 2183 | sysmgr_np = of_parse_phandle(pdev->dev.of_node, |
| 2184 | "altr,sysmgr-syscon", 0); |
| 2185 | if (!sysmgr_np) { |
| 2186 | edac_printk(KERN_ERR, EDAC_DEVICE, |
| 2187 | "Unable to find altr,sysmgr-syscon\n"); |
| 2188 | return -ENODEV; |
| 2189 | } |
| 2190 | |
| 2191 | if (of_address_to_resource(sysmgr_np, 0, &res)) |
| 2192 | return -ENOMEM; |
| 2193 | |
| 2194 | /* Need physical address for SMCC call */ |
Arnd Bergmann | 8537bf10 | 2018-09-27 12:09:26 +0200 | [diff] [blame] | 2195 | base = res.start; |
Thor Thayer | d5fc912 | 2018-09-25 08:48:58 -0500 | [diff] [blame] | 2196 | |
Arnd Bergmann | 8537bf10 | 2018-09-27 12:09:26 +0200 | [diff] [blame] | 2197 | edac->ecc_mgr_map = devm_regmap_init(&pdev->dev, NULL, |
| 2198 | (void *)base, |
Thor Thayer | d5fc912 | 2018-09-25 08:48:58 -0500 | [diff] [blame] | 2199 | &s10_sdram_regmap_cfg); |
| 2200 | } |
| 2201 | |
Thor Thayer | 588cb03 | 2016-03-21 11:01:44 -0500 | [diff] [blame] | 2202 | if (IS_ERR(edac->ecc_mgr_map)) { |
| 2203 | edac_printk(KERN_ERR, EDAC_DEVICE, |
| 2204 | "Unable to get syscon altr,sysmgr-syscon\n"); |
| 2205 | return PTR_ERR(edac->ecc_mgr_map); |
| 2206 | } |
| 2207 | |
Thor Thayer | 13ab844 | 2016-06-07 15:35:57 -0500 | [diff] [blame] | 2208 | edac->irq_chip.name = pdev->dev.of_node->name; |
| 2209 | edac->irq_chip.irq_mask = a10_eccmgr_irq_mask; |
| 2210 | edac->irq_chip.irq_unmask = a10_eccmgr_irq_unmask; |
| 2211 | edac->domain = irq_domain_add_linear(pdev->dev.of_node, 64, |
| 2212 | &a10_eccmgr_ic_ops, edac); |
| 2213 | if (!edac->domain) { |
| 2214 | dev_err(&pdev->dev, "Error adding IRQ domain\n"); |
| 2215 | return -ENOMEM; |
Thor Thayer | 588cb03 | 2016-03-21 11:01:44 -0500 | [diff] [blame] | 2216 | } |
| 2217 | |
Thor Thayer | 13ab844 | 2016-06-07 15:35:57 -0500 | [diff] [blame] | 2218 | edac->sb_irq = platform_get_irq(pdev, 0); |
| 2219 | if (edac->sb_irq < 0) { |
| 2220 | dev_err(&pdev->dev, "No SBERR IRQ resource\n"); |
| 2221 | return edac->sb_irq; |
Thor Thayer | 588cb03 | 2016-03-21 11:01:44 -0500 | [diff] [blame] | 2222 | } |
| 2223 | |
Thor Thayer | 13ab844 | 2016-06-07 15:35:57 -0500 | [diff] [blame] | 2224 | irq_set_chained_handler_and_data(edac->sb_irq, |
| 2225 | altr_edac_a10_irq_handler, |
| 2226 | edac); |
| 2227 | |
Thor Thayer | 1bd76ff | 2019-03-13 10:27:22 -0500 | [diff] [blame] | 2228 | #ifdef CONFIG_ARCH_STRATIX10 |
| 2229 | { |
Thor Thayer | d5fc912 | 2018-09-25 08:48:58 -0500 | [diff] [blame] | 2230 | int dberror, err_addr; |
| 2231 | |
| 2232 | edac->panic_notifier.notifier_call = s10_edac_dberr_handler; |
| 2233 | atomic_notifier_chain_register(&panic_notifier_list, |
| 2234 | &edac->panic_notifier); |
| 2235 | |
| 2236 | /* Printout a message if uncorrectable error previously. */ |
| 2237 | regmap_read(edac->ecc_mgr_map, S10_SYSMGR_UE_VAL_OFST, |
| 2238 | &dberror); |
| 2239 | if (dberror) { |
| 2240 | regmap_read(edac->ecc_mgr_map, S10_SYSMGR_UE_ADDR_OFST, |
| 2241 | &err_addr); |
| 2242 | edac_printk(KERN_ERR, EDAC_DEVICE, |
| 2243 | "Previous Boot UE detected[0x%X] @ 0x%X\n", |
| 2244 | dberror, err_addr); |
| 2245 | /* Reset the sticky registers */ |
| 2246 | regmap_write(edac->ecc_mgr_map, |
| 2247 | S10_SYSMGR_UE_VAL_OFST, 0); |
| 2248 | regmap_write(edac->ecc_mgr_map, |
| 2249 | S10_SYSMGR_UE_ADDR_OFST, 0); |
| 2250 | } |
Thor Thayer | 13ab844 | 2016-06-07 15:35:57 -0500 | [diff] [blame] | 2251 | } |
Thor Thayer | 1bd76ff | 2019-03-13 10:27:22 -0500 | [diff] [blame] | 2252 | #else |
| 2253 | edac->db_irq = platform_get_irq(pdev, 1); |
| 2254 | if (edac->db_irq < 0) { |
| 2255 | dev_err(&pdev->dev, "No DBERR IRQ resource\n"); |
| 2256 | return edac->db_irq; |
| 2257 | } |
| 2258 | irq_set_chained_handler_and_data(edac->db_irq, |
| 2259 | altr_edac_a10_irq_handler, edac); |
| 2260 | #endif |
Thor Thayer | 13ab844 | 2016-06-07 15:35:57 -0500 | [diff] [blame] | 2261 | |
Thor Thayer | 588cb03 | 2016-03-21 11:01:44 -0500 | [diff] [blame] | 2262 | for_each_child_of_node(pdev->dev.of_node, child) { |
| 2263 | if (!of_device_is_available(child)) |
| 2264 | continue; |
Thor Thayer | c6882fb | 2016-07-14 11:06:43 -0500 | [diff] [blame] | 2265 | |
Thor Thayer | 08a260d | 2019-11-07 14:01:29 -0600 | [diff] [blame^] | 2266 | if (of_match_node(altr_edac_a10_device_of_match, child)) |
Thor Thayer | 588cb03 | 2016-03-21 11:01:44 -0500 | [diff] [blame] | 2267 | altr_edac_a10_device_add(edac, child); |
Thor Thayer | c6882fb | 2016-07-14 11:06:43 -0500 | [diff] [blame] | 2268 | |
Thor Thayer | 580b5cf | 2019-02-25 12:56:45 -0600 | [diff] [blame] | 2269 | #ifdef CONFIG_EDAC_ALTERA_SDRAM |
Thor Thayer | 3123c5c | 2019-07-12 13:28:43 -0500 | [diff] [blame] | 2270 | else if (of_device_is_compatible(child, "altr,sdram-edac-a10")) |
Thor Thayer | ab564cb | 2016-05-25 11:29:41 -0500 | [diff] [blame] | 2271 | of_platform_populate(pdev->dev.of_node, |
| 2272 | altr_sdram_ctrl_of_match, |
| 2273 | NULL, &pdev->dev); |
Thor Thayer | 580b5cf | 2019-02-25 12:56:45 -0600 | [diff] [blame] | 2274 | #endif |
Thor Thayer | 588cb03 | 2016-03-21 11:01:44 -0500 | [diff] [blame] | 2275 | } |
| 2276 | |
| 2277 | return 0; |
| 2278 | } |
| 2279 | |
| 2280 | static const struct of_device_id altr_edac_a10_of_match[] = { |
| 2281 | { .compatible = "altr,socfpga-a10-ecc-manager" }, |
Thor Thayer | d5fc912 | 2018-09-25 08:48:58 -0500 | [diff] [blame] | 2282 | { .compatible = "altr,socfpga-s10-ecc-manager" }, |
Thor Thayer | 588cb03 | 2016-03-21 11:01:44 -0500 | [diff] [blame] | 2283 | {}, |
| 2284 | }; |
| 2285 | MODULE_DEVICE_TABLE(of, altr_edac_a10_of_match); |
| 2286 | |
| 2287 | static struct platform_driver altr_edac_a10_driver = { |
| 2288 | .probe = altr_edac_a10_probe, |
| 2289 | .driver = { |
| 2290 | .name = "socfpga_a10_ecc_manager", |
| 2291 | .of_match_table = altr_edac_a10_of_match, |
| 2292 | }, |
| 2293 | }; |
| 2294 | module_platform_driver(altr_edac_a10_driver); |
| 2295 | |
Thor Thayer | 71bcada | 2014-09-03 10:27:54 -0500 | [diff] [blame] | 2296 | MODULE_LICENSE("GPL v2"); |
| 2297 | MODULE_AUTHOR("Thor Thayer"); |
Thor Thayer | c3eea19 | 2016-02-10 13:26:21 -0600 | [diff] [blame] | 2298 | MODULE_DESCRIPTION("EDAC Driver for Altera Memories"); |