0001
0002
0003
0004
0005
0006
0007 #ifndef _ALTERA_EDAC_H
0008 #define _ALTERA_EDAC_H
0009
0010 #include <linux/arm-smccc.h>
0011 #include <linux/edac.h>
0012 #include <linux/types.h>
0013
0014
0015 #define CV_CTLCFG_OFST 0x00
0016
0017
0018 #define CV_CTLCFG_ECC_EN 0x400
0019 #define CV_CTLCFG_ECC_CORR_EN 0x800
0020 #define CV_CTLCFG_GEN_SB_ERR 0x2000
0021 #define CV_CTLCFG_GEN_DB_ERR 0x4000
0022
0023 #define CV_CTLCFG_ECC_AUTO_EN (CV_CTLCFG_ECC_EN)
0024
0025
0026 #define CV_DRAMADDRW_OFST 0x2C
0027
0028
0029 #define DRAMADDRW_COLBIT_MASK 0x001F
0030 #define DRAMADDRW_COLBIT_SHIFT 0
0031 #define DRAMADDRW_ROWBIT_MASK 0x03E0
0032 #define DRAMADDRW_ROWBIT_SHIFT 5
0033 #define CV_DRAMADDRW_BANKBIT_MASK 0x1C00
0034 #define CV_DRAMADDRW_BANKBIT_SHIFT 10
0035 #define CV_DRAMADDRW_CSBIT_MASK 0xE000
0036 #define CV_DRAMADDRW_CSBIT_SHIFT 13
0037
0038
0039 #define CV_DRAMIFWIDTH_OFST 0x30
0040
0041
0042 #define CV_DRAMIFWIDTH_16B_ECC 24
0043 #define CV_DRAMIFWIDTH_32B_ECC 40
0044
0045
0046 #define CV_DRAMSTS_OFST 0x38
0047
0048
0049 #define CV_DRAMSTS_SBEERR 0x04
0050 #define CV_DRAMSTS_DBEERR 0x08
0051 #define CV_DRAMSTS_CORR_DROP 0x10
0052
0053
0054 #define CV_DRAMINTR_OFST 0x3C
0055
0056
0057 #define CV_DRAMINTR_INTREN 0x01
0058 #define CV_DRAMINTR_SBEMASK 0x02
0059 #define CV_DRAMINTR_DBEMASK 0x04
0060 #define CV_DRAMINTR_CORRDROPMASK 0x08
0061 #define CV_DRAMINTR_INTRCLR 0x10
0062
0063
0064 #define CV_SBECOUNT_OFST 0x40
0065
0066
0067 #define CV_DBECOUNT_OFST 0x44
0068
0069
0070 #define CV_ERRADDR_OFST 0x48
0071
0072
0073
0074
0075 #define A10_ECCCTRL1_OFST 0x00
0076
0077
0078 #define A10_ECCCTRL1_ECC_EN 0x001
0079 #define A10_ECCCTRL1_CNT_RST 0x010
0080 #define A10_ECCCTRL1_AWB_CNT_RST 0x100
0081 #define A10_ECC_CNT_RESET_MASK (A10_ECCCTRL1_CNT_RST | \
0082 A10_ECCCTRL1_AWB_CNT_RST)
0083
0084
0085 #define CV_DRAMADDRW 0xFFC2502C
0086 #define A10_DRAMADDRW 0xFFCFA0A8
0087 #define S10_DRAMADDRW 0xF80110E0
0088
0089
0090 #define DRAMADDRW_COLBIT_MASK 0x001F
0091 #define DRAMADDRW_COLBIT_SHIFT 0
0092 #define DRAMADDRW_ROWBIT_MASK 0x03E0
0093 #define DRAMADDRW_ROWBIT_SHIFT 5
0094 #define CV_DRAMADDRW_BANKBIT_MASK 0x1C00
0095 #define CV_DRAMADDRW_BANKBIT_SHIFT 10
0096 #define CV_DRAMADDRW_CSBIT_MASK 0xE000
0097 #define CV_DRAMADDRW_CSBIT_SHIFT 13
0098
0099 #define A10_DRAMADDRW_BANKBIT_MASK 0x3C00
0100 #define A10_DRAMADDRW_BANKBIT_SHIFT 10
0101 #define A10_DRAMADDRW_GRPBIT_MASK 0xC000
0102 #define A10_DRAMADDRW_GRPBIT_SHIFT 14
0103 #define A10_DRAMADDRW_CSBIT_MASK 0x70000
0104 #define A10_DRAMADDRW_CSBIT_SHIFT 16
0105
0106
0107 #define CV_DRAMIFWIDTH 0xFFC25030
0108 #define A10_DRAMIFWIDTH 0xFFCFB008
0109 #define S10_DRAMIFWIDTH 0xF8011008
0110
0111
0112 #define CV_DRAMIFWIDTH_16B_ECC 24
0113 #define CV_DRAMIFWIDTH_32B_ECC 40
0114
0115 #define A10_DRAMIFWIDTH_16B 0x0
0116 #define A10_DRAMIFWIDTH_32B 0x1
0117 #define A10_DRAMIFWIDTH_64B 0x2
0118
0119
0120 #define A10_ERRINTEN_OFST 0x10
0121
0122
0123 #define A10_ERRINTEN_SERRINTEN 0x01
0124 #define A10_ERRINTEN_DERRINTEN 0x02
0125 #define A10_ECC_IRQ_EN_MASK (A10_ERRINTEN_SERRINTEN | \
0126 A10_ERRINTEN_DERRINTEN)
0127
0128
0129 #define A10_INTMODE_OFST 0x1C
0130 #define A10_INTMODE_SB_INT 1
0131
0132
0133 #define A10_INTSTAT_OFST 0x20
0134
0135
0136 #define A10_INTSTAT_SBEERR 0x01
0137 #define A10_INTSTAT_DBEERR 0x02
0138
0139
0140 #define A10_DERRADDR_OFST 0x2C
0141 #define A10_SERRADDR_OFST 0x30
0142
0143
0144 #define A10_DIAGINTTEST_OFST 0x24
0145
0146 #define A10_DIAGINT_TSERRA_MASK 0x0001
0147 #define A10_DIAGINT_TDERRA_MASK 0x0100
0148
0149 #define A10_SBERR_IRQ 34
0150 #define A10_DBERR_IRQ 32
0151
0152
0153 #define A10_SERRCNTREG_OFST 0x3C
0154
0155 #define A10_SYMAN_INTMASK_CLR 0xFFD06098
0156 #define A10_INTMASK_CLR_OFST 0x10
0157 #define A10_DDR0_IRQ_MASK BIT(17)
0158
0159 struct altr_sdram_prv_data {
0160 int ecc_ctrl_offset;
0161 int ecc_ctl_en_mask;
0162 int ecc_cecnt_offset;
0163 int ecc_uecnt_offset;
0164 int ecc_stat_offset;
0165 int ecc_stat_ce_mask;
0166 int ecc_stat_ue_mask;
0167 int ecc_saddr_offset;
0168 int ecc_daddr_offset;
0169 int ecc_irq_en_offset;
0170 int ecc_irq_en_mask;
0171 int ecc_irq_clr_offset;
0172 int ecc_irq_clr_mask;
0173 int ecc_cnt_rst_offset;
0174 int ecc_cnt_rst_mask;
0175 struct edac_dev_sysfs_attribute *eccmgr_sysfs_attr;
0176 int ecc_enable_mask;
0177 int ce_set_mask;
0178 int ue_set_mask;
0179 int ce_ue_trgr_offset;
0180 };
0181
0182
0183 struct altr_sdram_mc_data {
0184 struct regmap *mc_vbase;
0185 int sb_irq;
0186 int db_irq;
0187 const struct altr_sdram_prv_data *data;
0188 };
0189
0190
0191
0192 #define ALTR_UE_TRIGGER_CHAR 'U'
0193 #define ALTR_TRIGGER_READ_WRD_CNT 32
0194 #define ALTR_TRIG_OCRAM_BYTE_SIZE 128
0195 #define ALTR_TRIG_L2C_BYTE_SIZE 4096
0196
0197
0198
0199 #define ALTR_MAN_GRP_OCRAM_ECC_OFFSET 0x04
0200 #define ALTR_OCR_ECC_REG_OFFSET 0x00
0201 #define ALTR_OCR_ECC_EN BIT(0)
0202 #define ALTR_OCR_ECC_INJS BIT(1)
0203 #define ALTR_OCR_ECC_INJD BIT(2)
0204 #define ALTR_OCR_ECC_SERR BIT(3)
0205 #define ALTR_OCR_ECC_DERR BIT(4)
0206
0207
0208 #define ALTR_MAN_GRP_L2_ECC_OFFSET 0x00
0209 #define ALTR_L2_ECC_REG_OFFSET 0x00
0210 #define ALTR_L2_ECC_EN BIT(0)
0211 #define ALTR_L2_ECC_INJS BIT(1)
0212 #define ALTR_L2_ECC_INJD BIT(2)
0213
0214
0215 #define ALTR_A10_ECC_CTRL_OFST 0x08
0216 #define ALTR_A10_ECC_EN BIT(0)
0217 #define ALTR_A10_ECC_INITA BIT(16)
0218 #define ALTR_A10_ECC_INITB BIT(24)
0219
0220 #define ALTR_A10_ECC_INITSTAT_OFST 0x0C
0221 #define ALTR_A10_ECC_INITCOMPLETEA BIT(0)
0222 #define ALTR_A10_ECC_INITCOMPLETEB BIT(8)
0223
0224 #define ALTR_A10_ECC_ERRINTEN_OFST 0x10
0225 #define ALTR_A10_ECC_ERRINTENS_OFST 0x14
0226 #define ALTR_A10_ECC_ERRINTENR_OFST 0x18
0227 #define ALTR_A10_ECC_SERRINTEN BIT(0)
0228
0229 #define ALTR_A10_ECC_INTMODE_OFST 0x1C
0230 #define ALTR_A10_ECC_INTMODE BIT(0)
0231
0232 #define ALTR_A10_ECC_INTSTAT_OFST 0x20
0233 #define ALTR_A10_ECC_SERRPENA BIT(0)
0234 #define ALTR_A10_ECC_DERRPENA BIT(8)
0235 #define ALTR_A10_ECC_ERRPENA_MASK (ALTR_A10_ECC_SERRPENA | \
0236 ALTR_A10_ECC_DERRPENA)
0237 #define ALTR_A10_ECC_SERRPENB BIT(16)
0238 #define ALTR_A10_ECC_DERRPENB BIT(24)
0239 #define ALTR_A10_ECC_ERRPENB_MASK (ALTR_A10_ECC_SERRPENB | \
0240 ALTR_A10_ECC_DERRPENB)
0241
0242 #define ALTR_A10_ECC_INTTEST_OFST 0x24
0243 #define ALTR_A10_ECC_TSERRA BIT(0)
0244 #define ALTR_A10_ECC_TDERRA BIT(8)
0245 #define ALTR_A10_ECC_TSERRB BIT(16)
0246 #define ALTR_A10_ECC_TDERRB BIT(24)
0247
0248
0249 #define A10_SYSMGR_ECC_INTMASK_SET_OFST 0x94
0250 #define A10_SYSMGR_ECC_INTMASK_CLR_OFST 0x98
0251 #define A10_SYSMGR_ECC_INTMASK_OCRAM BIT(1)
0252
0253 #define A10_SYSMGR_ECC_INTSTAT_SERR_OFST 0x9C
0254 #define A10_SYSMGR_ECC_INTSTAT_DERR_OFST 0xA0
0255 #define A10_SYSMGR_ECC_INTSTAT_L2 BIT(0)
0256 #define A10_SYSMGR_ECC_INTSTAT_OCRAM BIT(1)
0257
0258 #define A10_SYSGMR_MPU_CLEAR_L2_ECC_OFST 0xA8
0259 #define A10_SYSGMR_MPU_CLEAR_L2_ECC_SB BIT(15)
0260 #define A10_SYSGMR_MPU_CLEAR_L2_ECC_MB BIT(31)
0261
0262
0263 #define ALTR_A10_L2_ECC_CTL_OFST 0x0
0264 #define ALTR_A10_L2_ECC_EN_CTL BIT(0)
0265
0266 #define ALTR_A10_L2_ECC_STATUS 0xFFD060A4
0267 #define ALTR_A10_L2_ECC_STAT_OFST 0xA4
0268 #define ALTR_A10_L2_ECC_SERR_PEND BIT(0)
0269 #define ALTR_A10_L2_ECC_MERR_PEND BIT(0)
0270
0271 #define ALTR_A10_L2_ECC_CLR_OFST 0x4
0272 #define ALTR_A10_L2_ECC_SERR_CLR BIT(15)
0273 #define ALTR_A10_L2_ECC_MERR_CLR BIT(31)
0274
0275 #define ALTR_A10_L2_ECC_INJ_OFST ALTR_A10_L2_ECC_CTL_OFST
0276 #define ALTR_A10_L2_ECC_CE_INJ_MASK 0x00000101
0277 #define ALTR_A10_L2_ECC_UE_INJ_MASK 0x00010101
0278
0279
0280 #define ALTR_A10_OCRAM_ECC_EN_CTL (BIT(1) | BIT(0))
0281
0282
0283 #define ALTR_A10_COMMON_ECC_EN_CTL BIT(0)
0284
0285
0286 #define ALTR_A10_SDMMC_IRQ_MASK (BIT(16) | BIT(15))
0287
0288
0289 #define ALTR_A10_ECC_INIT_WATCHDOG_10US 10000
0290
0291
0292 #define ALTR_S10_ECC_CTRL_SDRAM_OFST 0x00
0293 #define ALTR_S10_ECC_EN BIT(0)
0294
0295 #define ALTR_S10_ECC_ERRINTEN_OFST 0x10
0296 #define ALTR_S10_ECC_ERRINTENS_OFST 0x14
0297 #define ALTR_S10_ECC_ERRINTENR_OFST 0x18
0298 #define ALTR_S10_ECC_SERRINTEN BIT(0)
0299
0300 #define ALTR_S10_ECC_INTMODE_OFST 0x1C
0301 #define ALTR_S10_ECC_INTMODE BIT(0)
0302
0303 #define ALTR_S10_ECC_INTSTAT_OFST 0x20
0304 #define ALTR_S10_ECC_SERRPENA BIT(0)
0305 #define ALTR_S10_ECC_DERRPENA BIT(8)
0306 #define ALTR_S10_ECC_ERRPENA_MASK (ALTR_S10_ECC_SERRPENA | \
0307 ALTR_S10_ECC_DERRPENA)
0308
0309 #define ALTR_S10_ECC_INTTEST_OFST 0x24
0310 #define ALTR_S10_ECC_TSERRA BIT(0)
0311 #define ALTR_S10_ECC_TDERRA BIT(8)
0312 #define ALTR_S10_ECC_TSERRB BIT(16)
0313 #define ALTR_S10_ECC_TDERRB BIT(24)
0314
0315 #define ALTR_S10_DERR_ADDRA_OFST 0x2C
0316
0317
0318 #define S10_SYSMGR_ECC_INTMASK_CLR_OFST 0x98
0319 #define S10_SYSMGR_ECC_INTSTAT_DERR_OFST 0xA0
0320
0321
0322 #define S10_SYSMGR_UE_VAL_OFST 0x220
0323 #define S10_SYSMGR_UE_ADDR_OFST 0x224
0324
0325 #define S10_DDR0_IRQ_MASK BIT(16)
0326 #define S10_DBE_IRQ_MASK 0x3FFFE
0327
0328
0329 #define ECC_BLK_ADDRESS_OFST 0x40
0330 #define ECC_BLK_RDATA0_OFST 0x44
0331 #define ECC_BLK_RDATA1_OFST 0x48
0332 #define ECC_BLK_RDATA2_OFST 0x4C
0333 #define ECC_BLK_RDATA3_OFST 0x50
0334 #define ECC_BLK_WDATA0_OFST 0x54
0335 #define ECC_BLK_WDATA1_OFST 0x58
0336 #define ECC_BLK_WDATA2_OFST 0x5C
0337 #define ECC_BLK_WDATA3_OFST 0x60
0338 #define ECC_BLK_RECC0_OFST 0x64
0339 #define ECC_BLK_RECC1_OFST 0x68
0340 #define ECC_BLK_WECC0_OFST 0x6C
0341 #define ECC_BLK_WECC1_OFST 0x70
0342 #define ECC_BLK_DBYTECTRL_OFST 0x74
0343 #define ECC_BLK_ACCCTRL_OFST 0x78
0344 #define ECC_BLK_STARTACC_OFST 0x7C
0345
0346 #define ECC_XACT_KICK 0x10000
0347 #define ECC_WORD_WRITE 0xFF
0348 #define ECC_WRITE_DOVR 0x101
0349 #define ECC_WRITE_EDOVR 0x103
0350 #define ECC_READ_EOVR 0x2
0351 #define ECC_READ_EDOVR 0x3
0352
0353 struct altr_edac_device_dev;
0354
0355 struct edac_device_prv_data {
0356 int (*setup)(struct altr_edac_device_dev *device);
0357 int ce_clear_mask;
0358 int ue_clear_mask;
0359 int irq_status_mask;
0360 void * (*alloc_mem)(size_t size, void **other);
0361 void (*free_mem)(void *p, size_t size, void *other);
0362 int ecc_enable_mask;
0363 int ecc_en_ofst;
0364 int ce_set_mask;
0365 int ue_set_mask;
0366 int set_err_ofst;
0367 irqreturn_t (*ecc_irq_handler)(int irq, void *dev_id);
0368 int trig_alloc_sz;
0369 const struct file_operations *inject_fops;
0370 bool panic;
0371 };
0372
0373 struct altr_edac_device_dev {
0374 struct list_head next;
0375 void __iomem *base;
0376 int sb_irq;
0377 int db_irq;
0378 const struct edac_device_prv_data *data;
0379 struct dentry *debugfs_dir;
0380 char *edac_dev_name;
0381 struct altr_arria10_edac *edac;
0382 struct edac_device_ctl_info *edac_dev;
0383 struct device ddev;
0384 int edac_idx;
0385 };
0386
0387 struct altr_arria10_edac {
0388 struct device *dev;
0389 struct regmap *ecc_mgr_map;
0390 int sb_irq;
0391 int db_irq;
0392 struct irq_domain *domain;
0393 struct irq_chip irq_chip;
0394 struct list_head a10_ecc_devices;
0395 struct notifier_block panic_notifier;
0396 };
0397
0398 #endif