altera_edac.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. /*
  2. *
  3. * Copyright (C) 2015 Altera Corporation
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef _ALTERA_EDAC_H
  18. #define _ALTERA_EDAC_H
  19. #include <linux/edac.h>
  20. #include <linux/types.h>
  21. /* SDRAM Controller CtrlCfg Register */
  22. #define CV_CTLCFG_OFST 0x00
  23. /* SDRAM Controller CtrlCfg Register Bit Masks */
  24. #define CV_CTLCFG_ECC_EN 0x400
  25. #define CV_CTLCFG_ECC_CORR_EN 0x800
  26. #define CV_CTLCFG_GEN_SB_ERR 0x2000
  27. #define CV_CTLCFG_GEN_DB_ERR 0x4000
  28. #define CV_CTLCFG_ECC_AUTO_EN (CV_CTLCFG_ECC_EN)
  29. /* SDRAM Controller Address Width Register */
  30. #define CV_DRAMADDRW_OFST 0x2C
  31. /* SDRAM Controller Address Widths Field Register */
  32. #define DRAMADDRW_COLBIT_MASK 0x001F
  33. #define DRAMADDRW_COLBIT_SHIFT 0
  34. #define DRAMADDRW_ROWBIT_MASK 0x03E0
  35. #define DRAMADDRW_ROWBIT_SHIFT 5
  36. #define CV_DRAMADDRW_BANKBIT_MASK 0x1C00
  37. #define CV_DRAMADDRW_BANKBIT_SHIFT 10
  38. #define CV_DRAMADDRW_CSBIT_MASK 0xE000
  39. #define CV_DRAMADDRW_CSBIT_SHIFT 13
  40. /* SDRAM Controller Interface Data Width Register */
  41. #define CV_DRAMIFWIDTH_OFST 0x30
  42. /* SDRAM Controller Interface Data Width Defines */
  43. #define CV_DRAMIFWIDTH_16B_ECC 24
  44. #define CV_DRAMIFWIDTH_32B_ECC 40
  45. /* SDRAM Controller DRAM Status Register */
  46. #define CV_DRAMSTS_OFST 0x38
  47. /* SDRAM Controller DRAM Status Register Bit Masks */
  48. #define CV_DRAMSTS_SBEERR 0x04
  49. #define CV_DRAMSTS_DBEERR 0x08
  50. #define CV_DRAMSTS_CORR_DROP 0x10
  51. /* SDRAM Controller DRAM IRQ Register */
  52. #define CV_DRAMINTR_OFST 0x3C
  53. /* SDRAM Controller DRAM IRQ Register Bit Masks */
  54. #define CV_DRAMINTR_INTREN 0x01
  55. #define CV_DRAMINTR_SBEMASK 0x02
  56. #define CV_DRAMINTR_DBEMASK 0x04
  57. #define CV_DRAMINTR_CORRDROPMASK 0x08
  58. #define CV_DRAMINTR_INTRCLR 0x10
  59. /* SDRAM Controller Single Bit Error Count Register */
  60. #define CV_SBECOUNT_OFST 0x40
  61. /* SDRAM Controller Double Bit Error Count Register */
  62. #define CV_DBECOUNT_OFST 0x44
  63. /* SDRAM Controller ECC Error Address Register */
  64. #define CV_ERRADDR_OFST 0x48
  65. /*-----------------------------------------*/
  66. /* SDRAM Controller EccCtrl Register */
  67. #define A10_ECCCTRL1_OFST 0x00
  68. /* SDRAM Controller EccCtrl Register Bit Masks */
  69. #define A10_ECCCTRL1_ECC_EN 0x001
  70. #define A10_ECCCTRL1_CNT_RST 0x010
  71. #define A10_ECCCTRL1_AWB_CNT_RST 0x100
  72. #define A10_ECC_CNT_RESET_MASK (A10_ECCCTRL1_CNT_RST | \
  73. A10_ECCCTRL1_AWB_CNT_RST)
  74. /* SDRAM Controller Address Width Register */
  75. #define CV_DRAMADDRW 0xFFC2502C
  76. #define A10_DRAMADDRW 0xFFCFA0A8
  77. /* SDRAM Controller Address Widths Field Register */
  78. #define DRAMADDRW_COLBIT_MASK 0x001F
  79. #define DRAMADDRW_COLBIT_SHIFT 0
  80. #define DRAMADDRW_ROWBIT_MASK 0x03E0
  81. #define DRAMADDRW_ROWBIT_SHIFT 5
  82. #define CV_DRAMADDRW_BANKBIT_MASK 0x1C00
  83. #define CV_DRAMADDRW_BANKBIT_SHIFT 10
  84. #define CV_DRAMADDRW_CSBIT_MASK 0xE000
  85. #define CV_DRAMADDRW_CSBIT_SHIFT 13
  86. #define A10_DRAMADDRW_BANKBIT_MASK 0x3C00
  87. #define A10_DRAMADDRW_BANKBIT_SHIFT 10
  88. #define A10_DRAMADDRW_GRPBIT_MASK 0xC000
  89. #define A10_DRAMADDRW_GRPBIT_SHIFT 14
  90. #define A10_DRAMADDRW_CSBIT_MASK 0x70000
  91. #define A10_DRAMADDRW_CSBIT_SHIFT 16
  92. /* SDRAM Controller Interface Data Width Register */
  93. #define CV_DRAMIFWIDTH 0xFFC25030
  94. #define A10_DRAMIFWIDTH 0xFFCFB008
  95. /* SDRAM Controller Interface Data Width Defines */
  96. #define CV_DRAMIFWIDTH_16B_ECC 24
  97. #define CV_DRAMIFWIDTH_32B_ECC 40
  98. #define A10_DRAMIFWIDTH_16B 0x0
  99. #define A10_DRAMIFWIDTH_32B 0x1
  100. #define A10_DRAMIFWIDTH_64B 0x2
  101. /* SDRAM Controller DRAM IRQ Register */
  102. #define A10_ERRINTEN_OFST 0x10
  103. /* SDRAM Controller DRAM IRQ Register Bit Masks */
  104. #define A10_ERRINTEN_SERRINTEN 0x01
  105. #define A10_ERRINTEN_DERRINTEN 0x02
  106. #define A10_ECC_IRQ_EN_MASK (A10_ERRINTEN_SERRINTEN | \
  107. A10_ERRINTEN_DERRINTEN)
  108. /* SDRAM Interrupt Mode Register */
  109. #define A10_INTMODE_OFST 0x1C
  110. #define A10_INTMODE_SB_INT 1
  111. /* SDRAM Controller Error Status Register */
  112. #define A10_INTSTAT_OFST 0x20
  113. /* SDRAM Controller Error Status Register Bit Masks */
  114. #define A10_INTSTAT_SBEERR 0x01
  115. #define A10_INTSTAT_DBEERR 0x02
  116. /* SDRAM Controller ECC Error Address Register */
  117. #define A10_DERRADDR_OFST 0x2C
  118. #define A10_SERRADDR_OFST 0x30
  119. /* SDRAM Controller ECC Diagnostic Register */
  120. #define A10_DIAGINTTEST_OFST 0x24
  121. #define A10_DIAGINT_TSERRA_MASK 0x0001
  122. #define A10_DIAGINT_TDERRA_MASK 0x0100
  123. #define A10_SBERR_IRQ 34
  124. #define A10_DBERR_IRQ 32
  125. /* SDRAM Single Bit Error Count Compare Set Register */
  126. #define A10_SERRCNTREG_OFST 0x3C
  127. #define A10_SYMAN_INTMASK_CLR 0xFFD06098
  128. #define A10_INTMASK_CLR_OFST 0x10
  129. #define A10_DDR0_IRQ_MASK BIT(17)
  130. struct altr_sdram_prv_data {
  131. int ecc_ctrl_offset;
  132. int ecc_ctl_en_mask;
  133. int ecc_cecnt_offset;
  134. int ecc_uecnt_offset;
  135. int ecc_stat_offset;
  136. int ecc_stat_ce_mask;
  137. int ecc_stat_ue_mask;
  138. int ecc_saddr_offset;
  139. int ecc_daddr_offset;
  140. int ecc_irq_en_offset;
  141. int ecc_irq_en_mask;
  142. int ecc_irq_clr_offset;
  143. int ecc_irq_clr_mask;
  144. int ecc_cnt_rst_offset;
  145. int ecc_cnt_rst_mask;
  146. struct edac_dev_sysfs_attribute *eccmgr_sysfs_attr;
  147. int ecc_enable_mask;
  148. int ce_set_mask;
  149. int ue_set_mask;
  150. int ce_ue_trgr_offset;
  151. };
  152. /* Altera SDRAM Memory Controller data */
  153. struct altr_sdram_mc_data {
  154. struct regmap *mc_vbase;
  155. int sb_irq;
  156. int db_irq;
  157. const struct altr_sdram_prv_data *data;
  158. };
  159. /************************** EDAC Device Defines **************************/
  160. /***** General Device Trigger Defines *****/
  161. #define ALTR_UE_TRIGGER_CHAR 'U' /* Trigger for UE */
  162. #define ALTR_TRIGGER_READ_WRD_CNT 32 /* Line size x 4 */
  163. #define ALTR_TRIG_OCRAM_BYTE_SIZE 128 /* Line size x 4 */
  164. #define ALTR_TRIG_L2C_BYTE_SIZE 4096 /* Full Page */
  165. /******* Cyclone5 and Arria5 Defines *******/
  166. /* OCRAM ECC Management Group Defines */
  167. #define ALTR_MAN_GRP_OCRAM_ECC_OFFSET 0x04
  168. #define ALTR_OCR_ECC_REG_OFFSET 0x00
  169. #define ALTR_OCR_ECC_EN BIT(0)
  170. #define ALTR_OCR_ECC_INJS BIT(1)
  171. #define ALTR_OCR_ECC_INJD BIT(2)
  172. #define ALTR_OCR_ECC_SERR BIT(3)
  173. #define ALTR_OCR_ECC_DERR BIT(4)
  174. /* L2 ECC Management Group Defines */
  175. #define ALTR_MAN_GRP_L2_ECC_OFFSET 0x00
  176. #define ALTR_L2_ECC_REG_OFFSET 0x00
  177. #define ALTR_L2_ECC_EN BIT(0)
  178. #define ALTR_L2_ECC_INJS BIT(1)
  179. #define ALTR_L2_ECC_INJD BIT(2)
  180. /* Arria10 General ECC Block Module Defines */
  181. #define ALTR_A10_ECC_CTRL_OFST 0x08
  182. #define ALTR_A10_ECC_EN BIT(0)
  183. #define ALTR_A10_ECC_INITA BIT(16)
  184. #define ALTR_A10_ECC_INITB BIT(24)
  185. #define ALTR_A10_ECC_INITSTAT_OFST 0x0C
  186. #define ALTR_A10_ECC_INITCOMPLETEA BIT(0)
  187. #define ALTR_A10_ECC_INITCOMPLETEB BIT(8)
  188. #define ALTR_A10_ECC_ERRINTEN_OFST 0x10
  189. #define ALTR_A10_ECC_ERRINTENS_OFST 0x14
  190. #define ALTR_A10_ECC_ERRINTENR_OFST 0x18
  191. #define ALTR_A10_ECC_SERRINTEN BIT(0)
  192. #define ALTR_A10_ECC_INTMODE_OFST 0x1C
  193. #define ALTR_A10_ECC_INTMODE BIT(0)
  194. #define ALTR_A10_ECC_INTSTAT_OFST 0x20
  195. #define ALTR_A10_ECC_SERRPENA BIT(0)
  196. #define ALTR_A10_ECC_DERRPENA BIT(8)
  197. #define ALTR_A10_ECC_ERRPENA_MASK (ALTR_A10_ECC_SERRPENA | \
  198. ALTR_A10_ECC_DERRPENA)
  199. #define ALTR_A10_ECC_SERRPENB BIT(16)
  200. #define ALTR_A10_ECC_DERRPENB BIT(24)
  201. #define ALTR_A10_ECC_ERRPENB_MASK (ALTR_A10_ECC_SERRPENB | \
  202. ALTR_A10_ECC_DERRPENB)
  203. #define ALTR_A10_ECC_INTTEST_OFST 0x24
  204. #define ALTR_A10_ECC_TSERRA BIT(0)
  205. #define ALTR_A10_ECC_TDERRA BIT(8)
  206. #define ALTR_A10_ECC_TSERRB BIT(16)
  207. #define ALTR_A10_ECC_TDERRB BIT(24)
  208. /* ECC Manager Defines */
  209. #define A10_SYSMGR_ECC_INTMASK_SET_OFST 0x94
  210. #define A10_SYSMGR_ECC_INTMASK_CLR_OFST 0x98
  211. #define A10_SYSMGR_ECC_INTMASK_OCRAM BIT(1)
  212. #define A10_SYSMGR_ECC_INTSTAT_SERR_OFST 0x9C
  213. #define A10_SYSMGR_ECC_INTSTAT_DERR_OFST 0xA0
  214. #define A10_SYSMGR_ECC_INTSTAT_L2 BIT(0)
  215. #define A10_SYSMGR_ECC_INTSTAT_OCRAM BIT(1)
  216. #define A10_SYSGMR_MPU_CLEAR_L2_ECC_OFST 0xA8
  217. #define A10_SYSGMR_MPU_CLEAR_L2_ECC_SB BIT(15)
  218. #define A10_SYSGMR_MPU_CLEAR_L2_ECC_MB BIT(31)
  219. /* Arria 10 L2 ECC Management Group Defines */
  220. #define ALTR_A10_L2_ECC_CTL_OFST 0x0
  221. #define ALTR_A10_L2_ECC_EN_CTL BIT(0)
  222. #define ALTR_A10_L2_ECC_STATUS 0xFFD060A4
  223. #define ALTR_A10_L2_ECC_STAT_OFST 0xA4
  224. #define ALTR_A10_L2_ECC_SERR_PEND BIT(0)
  225. #define ALTR_A10_L2_ECC_MERR_PEND BIT(0)
  226. #define ALTR_A10_L2_ECC_CLR_OFST 0x4
  227. #define ALTR_A10_L2_ECC_SERR_CLR BIT(15)
  228. #define ALTR_A10_L2_ECC_MERR_CLR BIT(31)
  229. #define ALTR_A10_L2_ECC_INJ_OFST ALTR_A10_L2_ECC_CTL_OFST
  230. #define ALTR_A10_L2_ECC_CE_INJ_MASK 0x00000101
  231. #define ALTR_A10_L2_ECC_UE_INJ_MASK 0x00010101
  232. /* Arria 10 OCRAM ECC Management Group Defines */
  233. #define ALTR_A10_OCRAM_ECC_EN_CTL (BIT(1) | BIT(0))
  234. /* Arria 10 Ethernet ECC Management Group Defines */
  235. #define ALTR_A10_COMMON_ECC_EN_CTL BIT(0)
  236. /* Arria 10 SDMMC ECC Management Group Defines */
  237. #define ALTR_A10_SDMMC_IRQ_MASK (BIT(16) | BIT(15))
  238. /* A10 ECC Controller memory initialization timeout */
  239. #define ALTR_A10_ECC_INIT_WATCHDOG_10US 10000
  240. struct altr_edac_device_dev;
  241. struct edac_device_prv_data {
  242. int (*setup)(struct altr_edac_device_dev *device);
  243. int ce_clear_mask;
  244. int ue_clear_mask;
  245. int irq_status_mask;
  246. void * (*alloc_mem)(size_t size, void **other);
  247. void (*free_mem)(void *p, size_t size, void *other);
  248. int ecc_enable_mask;
  249. int ecc_en_ofst;
  250. int ce_set_mask;
  251. int ue_set_mask;
  252. int set_err_ofst;
  253. irqreturn_t (*ecc_irq_handler)(int irq, void *dev_id);
  254. int trig_alloc_sz;
  255. const struct file_operations *inject_fops;
  256. bool panic;
  257. };
  258. struct altr_edac_device_dev {
  259. struct list_head next;
  260. void __iomem *base;
  261. int sb_irq;
  262. int db_irq;
  263. const struct edac_device_prv_data *data;
  264. struct dentry *debugfs_dir;
  265. char *edac_dev_name;
  266. struct altr_arria10_edac *edac;
  267. struct edac_device_ctl_info *edac_dev;
  268. struct device ddev;
  269. int edac_idx;
  270. };
  271. struct altr_arria10_edac {
  272. struct device *dev;
  273. struct regmap *ecc_mgr_map;
  274. int sb_irq;
  275. int db_irq;
  276. struct irq_domain *domain;
  277. struct irq_chip irq_chip;
  278. struct list_head a10_ecc_devices;
  279. };
  280. #endif /* #ifndef _ALTERA_EDAC_H */