Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge remote-tracking branches 'ras/edac-amd-atl', 'ras/edac-misc' and 'ras/edac-drivers' into edac-updates

* ras/edac-amd-atl:
RAS/AMD/ATL: Translate normalized to system physical addresses using PRM
ACPI: PRM: Add PRM handler direct call support

* ras/edac-misc:
EDAC/synopsys: Fix error injection on Zynq UltraScale+

* ras/edac-drivers:
EDAC: Drop obsolete PPC4xx driver
EDAC/sb_edac: Fix the compile warning of large frame size
EDAC/{skx_common,i10nm}: Remove the AMAP register for determing DDR5
EDAC/{skx_common,skx,i10nm}: Move the common debug code to skx_common
EDAC/igen6: Fix conversion of system address to physical memory address

Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>

+115 -1729
-9
drivers/edac/Kconfig
··· 311 311 Cell Broadband Engine internal memory controller 312 312 on platform without a hypervisor 313 313 314 - config EDAC_PPC4XX 315 - tristate "PPC4xx IBM DDR2 Memory Controller" 316 - depends on 4xx 317 - help 318 - This enables support for EDAC on the ECC memory used 319 - with the IBM DDR2 memory controller found in various 320 - PowerPC 4xx embedded processors such as the 405EX[r], 321 - 440SP, 440SPe, 460EX, 460GT and 460SX. 322 - 323 314 config EDAC_AMD8131 324 315 tristate "AMD8131 HyperTransport PCI-X Tunnel" 325 316 depends on PCI && PPC_MAPLE
-1
drivers/edac/Makefile
··· 63 63 obj-$(CONFIG_EDAC_I10NM) += i10nm_edac.o skx_edac_common.o 64 64 65 65 obj-$(CONFIG_EDAC_CELL) += cell_edac.o 66 - obj-$(CONFIG_EDAC_PPC4XX) += ppc4xx_edac.o 67 66 obj-$(CONFIG_EDAC_AMD8111) += amd8111_edac.o 68 67 obj-$(CONFIG_EDAC_AMD8131) += amd8131_edac.o 69 68
+4 -57
drivers/edac/i10nm_base.c
··· 47 47 readl((m)->mbase + ((m)->hbm_mc ? 0xef8 : \ 48 48 (res_cfg->type == GNR ? 0xaf8 : 0x20ef8)) + \ 49 49 (i) * (m)->chan_mmio_sz) 50 - #define I10NM_GET_AMAP(m, i) \ 51 - readl((m)->mbase + ((m)->hbm_mc ? 0x814 : \ 52 - (res_cfg->type == GNR ? 0xc14 : 0x20814)) + \ 53 - (i) * (m)->chan_mmio_sz) 54 50 #define I10NM_GET_REG32(m, i, offset) \ 55 51 readl((m)->mbase + (i) * (m)->chan_mmio_sz + (offset)) 56 52 #define I10NM_GET_REG64(m, i, offset) \ ··· 967 971 { 968 972 struct skx_pvt *pvt = mci->pvt_info; 969 973 struct skx_imc *imc = pvt->imc; 970 - u32 mtr, amap, mcddrtcfg = 0; 974 + u32 mtr, mcddrtcfg = 0; 971 975 struct dimm_info *dimm; 972 976 int i, j, ndimms; 973 977 ··· 976 980 continue; 977 981 978 982 ndimms = 0; 979 - amap = I10NM_GET_AMAP(imc, i); 980 983 981 984 if (res_cfg->type != GNR) 982 985 mcddrtcfg = I10NM_GET_MCDDRTCFG(imc, i); ··· 987 992 mtr, mcddrtcfg, imc->mc, i, j); 988 993 989 994 if (IS_DIMM_PRESENT(mtr)) 990 - ndimms += skx_get_dimm_info(mtr, 0, amap, dimm, 995 + ndimms += skx_get_dimm_info(mtr, 0, 0, dimm, 991 996 imc, i, j, cfg); 992 997 else if (IS_NVDIMM_PRESENT(mcddrtcfg, j)) 993 998 ndimms += skx_get_nvdimm_info(dimm, imc, i, j, ··· 1007 1012 .notifier_call = skx_mce_check_error, 1008 1013 .priority = MCE_PRIO_EDAC, 1009 1014 }; 1010 - 1011 - #ifdef CONFIG_EDAC_DEBUG 1012 - /* 1013 - * Debug feature. 1014 - * Exercise the address decode logic by writing an address to 1015 - * /sys/kernel/debug/edac/i10nm_test/addr. 1016 - */ 1017 - static struct dentry *i10nm_test; 1018 - 1019 - static int debugfs_u64_set(void *data, u64 val) 1020 - { 1021 - struct mce m; 1022 - 1023 - pr_warn_once("Fake error to 0x%llx injected via debugfs\n", val); 1024 - 1025 - memset(&m, 0, sizeof(m)); 1026 - /* ADDRV + MemRd + Unknown channel */ 1027 - m.status = MCI_STATUS_ADDRV + 0x90; 1028 - /* One corrected error */ 1029 - m.status |= BIT_ULL(MCI_STATUS_CEC_SHIFT); 1030 - m.addr = val; 1031 - skx_mce_check_error(NULL, 0, &m); 1032 - 1033 - return 0; 1034 - } 1035 - DEFINE_SIMPLE_ATTRIBUTE(fops_u64_wo, NULL, debugfs_u64_set, "%llu\n"); 1036 - 1037 - static void setup_i10nm_debug(void) 1038 - { 1039 - i10nm_test = edac_debugfs_create_dir("i10nm_test"); 1040 - if (!i10nm_test) 1041 - return; 1042 - 1043 - if (!edac_debugfs_create_file("addr", 0200, i10nm_test, 1044 - NULL, &fops_u64_wo)) { 1045 - debugfs_remove(i10nm_test); 1046 - i10nm_test = NULL; 1047 - } 1048 - } 1049 - 1050 - static void teardown_i10nm_debug(void) 1051 - { 1052 - debugfs_remove_recursive(i10nm_test); 1053 - } 1054 - #else 1055 - static inline void setup_i10nm_debug(void) {} 1056 - static inline void teardown_i10nm_debug(void) {} 1057 - #endif /*CONFIG_EDAC_DEBUG*/ 1058 1015 1059 1016 static int __init i10nm_init(void) 1060 1017 { ··· 1106 1159 1107 1160 opstate_init(); 1108 1161 mce_register_decode_chain(&i10nm_mce_dec); 1109 - setup_i10nm_debug(); 1162 + skx_setup_debug("i10nm_test"); 1110 1163 1111 1164 if (retry_rd_err_log && res_cfg->offsets_scrub && res_cfg->offsets_demand) { 1112 1165 skx_set_decode(i10nm_mc_decode, show_retry_rd_err_log); ··· 1134 1187 enable_retry_rd_err_log(false); 1135 1188 } 1136 1189 1137 - teardown_i10nm_debug(); 1190 + skx_teardown_debug(); 1138 1191 mce_unregister_decode_chain(&i10nm_mce_dec); 1139 1192 skx_adxl_put(); 1140 1193 skx_remove();
+1 -1
drivers/edac/igen6_edac.c
··· 316 316 if (igen6_tom <= _4GB) 317 317 return eaddr + igen6_tolud - _4GB; 318 318 319 - if (eaddr < _4GB) 319 + if (eaddr >= igen6_tom) 320 320 return eaddr + igen6_tolud - igen6_tom; 321 321 322 322 return eaddr;
-1425
drivers/edac/ppc4xx_edac.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* 3 - * Copyright (c) 2008 Nuovation System Designs, LLC 4 - * Grant Erickson <gerickson@nuovations.com> 5 - */ 6 - 7 - #include <linux/edac.h> 8 - #include <linux/interrupt.h> 9 - #include <linux/irq.h> 10 - #include <linux/kernel.h> 11 - #include <linux/mm.h> 12 - #include <linux/module.h> 13 - #include <linux/of_device.h> 14 - #include <linux/of_irq.h> 15 - #include <linux/of_platform.h> 16 - #include <linux/types.h> 17 - 18 - #include <asm/dcr.h> 19 - 20 - #include "edac_module.h" 21 - #include "ppc4xx_edac.h" 22 - 23 - /* 24 - * This file implements a driver for monitoring and handling events 25 - * associated with the IMB DDR2 ECC controller found in the AMCC/IBM 26 - * 405EX[r], 440SP, 440SPe, 460EX, 460GT and 460SX. 27 - * 28 - * As realized in the 405EX[r], this controller features: 29 - * 30 - * - Support for registered- and non-registered DDR1 and DDR2 memory. 31 - * - 32-bit or 16-bit memory interface with optional ECC. 32 - * 33 - * o ECC support includes: 34 - * 35 - * - 4-bit SEC/DED 36 - * - Aligned-nibble error detect 37 - * - Bypass mode 38 - * 39 - * - Two (2) memory banks/ranks. 40 - * - Up to 1 GiB per bank/rank in 32-bit mode and up to 512 MiB per 41 - * bank/rank in 16-bit mode. 42 - * 43 - * As realized in the 440SP and 440SPe, this controller changes/adds: 44 - * 45 - * - 64-bit or 32-bit memory interface with optional ECC. 46 - * 47 - * o ECC support includes: 48 - * 49 - * - 8-bit SEC/DED 50 - * - Aligned-nibble error detect 51 - * - Bypass mode 52 - * 53 - * - Up to 4 GiB per bank/rank in 64-bit mode and up to 2 GiB 54 - * per bank/rank in 32-bit mode. 55 - * 56 - * As realized in the 460EX and 460GT, this controller changes/adds: 57 - * 58 - * - 64-bit or 32-bit memory interface with optional ECC. 59 - * 60 - * o ECC support includes: 61 - * 62 - * - 8-bit SEC/DED 63 - * - Aligned-nibble error detect 64 - * - Bypass mode 65 - * 66 - * - Four (4) memory banks/ranks. 67 - * - Up to 16 GiB per bank/rank in 64-bit mode and up to 8 GiB 68 - * per bank/rank in 32-bit mode. 69 - * 70 - * At present, this driver has ONLY been tested against the controller 71 - * realization in the 405EX[r] on the AMCC Kilauea and Haleakala 72 - * boards (256 MiB w/o ECC memory soldered onto the board) and a 73 - * proprietary board based on those designs (128 MiB ECC memory, also 74 - * soldered onto the board). 75 - * 76 - * Dynamic feature detection and handling needs to be added for the 77 - * other realizations of this controller listed above. 78 - * 79 - * Eventually, this driver will likely be adapted to the above variant 80 - * realizations of this controller as well as broken apart to handle 81 - * the other known ECC-capable controllers prevalent in other 4xx 82 - * processors: 83 - * 84 - * - IBM SDRAM (405GP, 405CR and 405EP) "ibm,sdram-4xx" 85 - * - IBM DDR1 (440GP, 440GX, 440EP and 440GR) "ibm,sdram-4xx-ddr" 86 - * - Denali DDR1/DDR2 (440EPX and 440GRX) "denali,sdram-4xx-ddr2" 87 - * 88 - * For this controller, unfortunately, correctable errors report 89 - * nothing more than the beat/cycle and byte/lane the correction 90 - * occurred on and the check bit group that covered the error. 91 - * 92 - * In contrast, uncorrectable errors also report the failing address, 93 - * the bus master and the transaction direction (i.e. read or write) 94 - * 95 - * Regardless of whether the error is a CE or a UE, we report the 96 - * following pieces of information in the driver-unique message to the 97 - * EDAC subsystem: 98 - * 99 - * - Device tree path 100 - * - Bank(s) 101 - * - Check bit error group 102 - * - Beat(s)/lane(s) 103 - */ 104 - 105 - /* Preprocessor Definitions */ 106 - 107 - #define EDAC_OPSTATE_INT_STR "interrupt" 108 - #define EDAC_OPSTATE_POLL_STR "polled" 109 - #define EDAC_OPSTATE_UNKNOWN_STR "unknown" 110 - 111 - #define PPC4XX_EDAC_MODULE_NAME "ppc4xx_edac" 112 - #define PPC4XX_EDAC_MODULE_REVISION "v1.0.0" 113 - 114 - #define PPC4XX_EDAC_MESSAGE_SIZE 256 115 - 116 - /* 117 - * Kernel logging without an EDAC instance 118 - */ 119 - #define ppc4xx_edac_printk(level, fmt, arg...) \ 120 - edac_printk(level, "PPC4xx MC", fmt, ##arg) 121 - 122 - /* 123 - * Kernel logging with an EDAC instance 124 - */ 125 - #define ppc4xx_edac_mc_printk(level, mci, fmt, arg...) \ 126 - edac_mc_chipset_printk(mci, level, "PPC4xx", fmt, ##arg) 127 - 128 - /* 129 - * Macros to convert bank configuration size enumerations into MiB and 130 - * page values. 131 - */ 132 - #define SDRAM_MBCF_SZ_MiB_MIN 4 133 - #define SDRAM_MBCF_SZ_TO_MiB(n) (SDRAM_MBCF_SZ_MiB_MIN \ 134 - << (SDRAM_MBCF_SZ_DECODE(n))) 135 - #define SDRAM_MBCF_SZ_TO_PAGES(n) (SDRAM_MBCF_SZ_MiB_MIN \ 136 - << (20 - PAGE_SHIFT + \ 137 - SDRAM_MBCF_SZ_DECODE(n))) 138 - 139 - /* 140 - * The ibm,sdram-4xx-ddr2 Device Control Registers (DCRs) are 141 - * indirectly accessed and have a base and length defined by the 142 - * device tree. The base can be anything; however, we expect the 143 - * length to be precisely two registers, the first for the address 144 - * window and the second for the data window. 145 - */ 146 - #define SDRAM_DCR_RESOURCE_LEN 2 147 - #define SDRAM_DCR_ADDR_OFFSET 0 148 - #define SDRAM_DCR_DATA_OFFSET 1 149 - 150 - /* 151 - * Device tree interrupt indices 152 - */ 153 - #define INTMAP_ECCDED_INDEX 0 /* Double-bit Error Detect */ 154 - #define INTMAP_ECCSEC_INDEX 1 /* Single-bit Error Correct */ 155 - 156 - /* Type Definitions */ 157 - 158 - /* 159 - * PPC4xx SDRAM memory controller private instance data 160 - */ 161 - struct ppc4xx_edac_pdata { 162 - dcr_host_t dcr_host; /* Indirect DCR address/data window mapping */ 163 - struct { 164 - int sec; /* Single-bit correctable error IRQ assigned */ 165 - int ded; /* Double-bit detectable error IRQ assigned */ 166 - } irqs; 167 - }; 168 - 169 - /* 170 - * Various status data gathered and manipulated when checking and 171 - * reporting ECC status. 172 - */ 173 - struct ppc4xx_ecc_status { 174 - u32 ecces; 175 - u32 besr; 176 - u32 bearh; 177 - u32 bearl; 178 - u32 wmirq; 179 - }; 180 - 181 - /* Global Variables */ 182 - 183 - /* 184 - * Device tree node type and compatible tuples this driver can match 185 - * on. 186 - */ 187 - static const struct of_device_id ppc4xx_edac_match[] = { 188 - { 189 - .compatible = "ibm,sdram-4xx-ddr2" 190 - }, 191 - { } 192 - }; 193 - MODULE_DEVICE_TABLE(of, ppc4xx_edac_match); 194 - 195 - /* 196 - * TODO: The row and channel parameters likely need to be dynamically 197 - * set based on the aforementioned variant controller realizations. 198 - */ 199 - static const unsigned ppc4xx_edac_nr_csrows = 2; 200 - static const unsigned ppc4xx_edac_nr_chans = 1; 201 - 202 - /* 203 - * Strings associated with PLB master IDs capable of being posted in 204 - * SDRAM_BESR or SDRAM_WMIRQ on uncorrectable ECC errors. 205 - */ 206 - static const char * const ppc4xx_plb_masters[9] = { 207 - [SDRAM_PLB_M0ID_ICU] = "ICU", 208 - [SDRAM_PLB_M0ID_PCIE0] = "PCI-E 0", 209 - [SDRAM_PLB_M0ID_PCIE1] = "PCI-E 1", 210 - [SDRAM_PLB_M0ID_DMA] = "DMA", 211 - [SDRAM_PLB_M0ID_DCU] = "DCU", 212 - [SDRAM_PLB_M0ID_OPB] = "OPB", 213 - [SDRAM_PLB_M0ID_MAL] = "MAL", 214 - [SDRAM_PLB_M0ID_SEC] = "SEC", 215 - [SDRAM_PLB_M0ID_AHB] = "AHB" 216 - }; 217 - 218 - /** 219 - * mfsdram - read and return controller register data 220 - * @dcr_host: A pointer to the DCR mapping. 221 - * @idcr_n: The indirect DCR register to read. 222 - * 223 - * This routine reads and returns the data associated with the 224 - * controller's specified indirect DCR register. 225 - * 226 - * Returns the read data. 227 - */ 228 - static inline u32 229 - mfsdram(const dcr_host_t *dcr_host, unsigned int idcr_n) 230 - { 231 - return __mfdcri(dcr_host->base + SDRAM_DCR_ADDR_OFFSET, 232 - dcr_host->base + SDRAM_DCR_DATA_OFFSET, 233 - idcr_n); 234 - } 235 - 236 - /** 237 - * mtsdram - write controller register data 238 - * @dcr_host: A pointer to the DCR mapping. 239 - * @idcr_n: The indirect DCR register to write. 240 - * @value: The data to write. 241 - * 242 - * This routine writes the provided data to the controller's specified 243 - * indirect DCR register. 244 - */ 245 - static inline void 246 - mtsdram(const dcr_host_t *dcr_host, unsigned int idcr_n, u32 value) 247 - { 248 - return __mtdcri(dcr_host->base + SDRAM_DCR_ADDR_OFFSET, 249 - dcr_host->base + SDRAM_DCR_DATA_OFFSET, 250 - idcr_n, 251 - value); 252 - } 253 - 254 - /** 255 - * ppc4xx_edac_check_bank_error - check a bank for an ECC bank error 256 - * @status: A pointer to the ECC status structure to check for an 257 - * ECC bank error. 258 - * @bank: The bank to check for an ECC error. 259 - * 260 - * This routine determines whether the specified bank has an ECC 261 - * error. 262 - * 263 - * Returns true if the specified bank has an ECC error; otherwise, 264 - * false. 265 - */ 266 - static bool 267 - ppc4xx_edac_check_bank_error(const struct ppc4xx_ecc_status *status, 268 - unsigned int bank) 269 - { 270 - switch (bank) { 271 - case 0: 272 - return status->ecces & SDRAM_ECCES_BK0ER; 273 - case 1: 274 - return status->ecces & SDRAM_ECCES_BK1ER; 275 - default: 276 - return false; 277 - } 278 - } 279 - 280 - /** 281 - * ppc4xx_edac_generate_bank_message - generate interpretted bank status message 282 - * @mci: A pointer to the EDAC memory controller instance associated 283 - * with the bank message being generated. 284 - * @status: A pointer to the ECC status structure to generate the 285 - * message from. 286 - * @buffer: A pointer to the buffer in which to generate the 287 - * message. 288 - * @size: The size, in bytes, of space available in buffer. 289 - * 290 - * This routine generates to the provided buffer the portion of the 291 - * driver-unique report message associated with the ECCESS[BKNER] 292 - * field of the specified ECC status. 293 - * 294 - * Returns the number of characters generated on success; otherwise, < 295 - * 0 on error. 296 - */ 297 - static int 298 - ppc4xx_edac_generate_bank_message(const struct mem_ctl_info *mci, 299 - const struct ppc4xx_ecc_status *status, 300 - char *buffer, 301 - size_t size) 302 - { 303 - int n, total = 0; 304 - unsigned int row, rows; 305 - 306 - n = snprintf(buffer, size, "%s: Banks: ", mci->dev_name); 307 - 308 - if (n < 0 || n >= size) 309 - goto fail; 310 - 311 - buffer += n; 312 - size -= n; 313 - total += n; 314 - 315 - for (rows = 0, row = 0; row < mci->nr_csrows; row++) { 316 - if (ppc4xx_edac_check_bank_error(status, row)) { 317 - n = snprintf(buffer, size, "%s%u", 318 - (rows++ ? ", " : ""), row); 319 - 320 - if (n < 0 || n >= size) 321 - goto fail; 322 - 323 - buffer += n; 324 - size -= n; 325 - total += n; 326 - } 327 - } 328 - 329 - n = snprintf(buffer, size, "%s; ", rows ? "" : "None"); 330 - 331 - if (n < 0 || n >= size) 332 - goto fail; 333 - 334 - buffer += n; 335 - size -= n; 336 - total += n; 337 - 338 - fail: 339 - return total; 340 - } 341 - 342 - /** 343 - * ppc4xx_edac_generate_checkbit_message - generate interpretted checkbit message 344 - * @mci: A pointer to the EDAC memory controller instance associated 345 - * with the checkbit message being generated. 346 - * @status: A pointer to the ECC status structure to generate the 347 - * message from. 348 - * @buffer: A pointer to the buffer in which to generate the 349 - * message. 350 - * @size: The size, in bytes, of space available in buffer. 351 - * 352 - * This routine generates to the provided buffer the portion of the 353 - * driver-unique report message associated with the ECCESS[CKBER] 354 - * field of the specified ECC status. 355 - * 356 - * Returns the number of characters generated on success; otherwise, < 357 - * 0 on error. 358 - */ 359 - static int 360 - ppc4xx_edac_generate_checkbit_message(const struct mem_ctl_info *mci, 361 - const struct ppc4xx_ecc_status *status, 362 - char *buffer, 363 - size_t size) 364 - { 365 - const struct ppc4xx_edac_pdata *pdata = mci->pvt_info; 366 - const char *ckber = NULL; 367 - 368 - switch (status->ecces & SDRAM_ECCES_CKBER_MASK) { 369 - case SDRAM_ECCES_CKBER_NONE: 370 - ckber = "None"; 371 - break; 372 - case SDRAM_ECCES_CKBER_32_ECC_0_3: 373 - ckber = "ECC0:3"; 374 - break; 375 - case SDRAM_ECCES_CKBER_32_ECC_4_8: 376 - switch (mfsdram(&pdata->dcr_host, SDRAM_MCOPT1) & 377 - SDRAM_MCOPT1_WDTH_MASK) { 378 - case SDRAM_MCOPT1_WDTH_16: 379 - ckber = "ECC0:3"; 380 - break; 381 - case SDRAM_MCOPT1_WDTH_32: 382 - ckber = "ECC4:8"; 383 - break; 384 - default: 385 - ckber = "Unknown"; 386 - break; 387 - } 388 - break; 389 - case SDRAM_ECCES_CKBER_32_ECC_0_8: 390 - ckber = "ECC0:8"; 391 - break; 392 - default: 393 - ckber = "Unknown"; 394 - break; 395 - } 396 - 397 - return snprintf(buffer, size, "Checkbit Error: %s", ckber); 398 - } 399 - 400 - /** 401 - * ppc4xx_edac_generate_lane_message - generate interpretted byte lane message 402 - * @mci: A pointer to the EDAC memory controller instance associated 403 - * with the byte lane message being generated. 404 - * @status: A pointer to the ECC status structure to generate the 405 - * message from. 406 - * @buffer: A pointer to the buffer in which to generate the 407 - * message. 408 - * @size: The size, in bytes, of space available in buffer. 409 - * 410 - * This routine generates to the provided buffer the portion of the 411 - * driver-unique report message associated with the ECCESS[BNCE] 412 - * field of the specified ECC status. 413 - * 414 - * Returns the number of characters generated on success; otherwise, < 415 - * 0 on error. 416 - */ 417 - static int 418 - ppc4xx_edac_generate_lane_message(const struct mem_ctl_info *mci, 419 - const struct ppc4xx_ecc_status *status, 420 - char *buffer, 421 - size_t size) 422 - { 423 - int n, total = 0; 424 - unsigned int lane, lanes; 425 - const unsigned int first_lane = 0; 426 - const unsigned int lane_count = 16; 427 - 428 - n = snprintf(buffer, size, "; Byte Lane Errors: "); 429 - 430 - if (n < 0 || n >= size) 431 - goto fail; 432 - 433 - buffer += n; 434 - size -= n; 435 - total += n; 436 - 437 - for (lanes = 0, lane = first_lane; lane < lane_count; lane++) { 438 - if ((status->ecces & SDRAM_ECCES_BNCE_ENCODE(lane)) != 0) { 439 - n = snprintf(buffer, size, 440 - "%s%u", 441 - (lanes++ ? ", " : ""), lane); 442 - 443 - if (n < 0 || n >= size) 444 - goto fail; 445 - 446 - buffer += n; 447 - size -= n; 448 - total += n; 449 - } 450 - } 451 - 452 - n = snprintf(buffer, size, "%s; ", lanes ? "" : "None"); 453 - 454 - if (n < 0 || n >= size) 455 - goto fail; 456 - 457 - buffer += n; 458 - size -= n; 459 - total += n; 460 - 461 - fail: 462 - return total; 463 - } 464 - 465 - /** 466 - * ppc4xx_edac_generate_ecc_message - generate interpretted ECC status message 467 - * @mci: A pointer to the EDAC memory controller instance associated 468 - * with the ECCES message being generated. 469 - * @status: A pointer to the ECC status structure to generate the 470 - * message from. 471 - * @buffer: A pointer to the buffer in which to generate the 472 - * message. 473 - * @size: The size, in bytes, of space available in buffer. 474 - * 475 - * This routine generates to the provided buffer the portion of the 476 - * driver-unique report message associated with the ECCESS register of 477 - * the specified ECC status. 478 - * 479 - * Returns the number of characters generated on success; otherwise, < 480 - * 0 on error. 481 - */ 482 - static int 483 - ppc4xx_edac_generate_ecc_message(const struct mem_ctl_info *mci, 484 - const struct ppc4xx_ecc_status *status, 485 - char *buffer, 486 - size_t size) 487 - { 488 - int n, total = 0; 489 - 490 - n = ppc4xx_edac_generate_bank_message(mci, status, buffer, size); 491 - 492 - if (n < 0 || n >= size) 493 - goto fail; 494 - 495 - buffer += n; 496 - size -= n; 497 - total += n; 498 - 499 - n = ppc4xx_edac_generate_checkbit_message(mci, status, buffer, size); 500 - 501 - if (n < 0 || n >= size) 502 - goto fail; 503 - 504 - buffer += n; 505 - size -= n; 506 - total += n; 507 - 508 - n = ppc4xx_edac_generate_lane_message(mci, status, buffer, size); 509 - 510 - if (n < 0 || n >= size) 511 - goto fail; 512 - 513 - buffer += n; 514 - size -= n; 515 - total += n; 516 - 517 - fail: 518 - return total; 519 - } 520 - 521 - /** 522 - * ppc4xx_edac_generate_plb_message - generate interpretted PLB status message 523 - * @mci: A pointer to the EDAC memory controller instance associated 524 - * with the PLB message being generated. 525 - * @status: A pointer to the ECC status structure to generate the 526 - * message from. 527 - * @buffer: A pointer to the buffer in which to generate the 528 - * message. 529 - * @size: The size, in bytes, of space available in buffer. 530 - * 531 - * This routine generates to the provided buffer the portion of the 532 - * driver-unique report message associated with the PLB-related BESR 533 - * and/or WMIRQ registers of the specified ECC status. 534 - * 535 - * Returns the number of characters generated on success; otherwise, < 536 - * 0 on error. 537 - */ 538 - static int 539 - ppc4xx_edac_generate_plb_message(const struct mem_ctl_info *mci, 540 - const struct ppc4xx_ecc_status *status, 541 - char *buffer, 542 - size_t size) 543 - { 544 - unsigned int master; 545 - bool read; 546 - 547 - if ((status->besr & SDRAM_BESR_MASK) == 0) 548 - return 0; 549 - 550 - if ((status->besr & SDRAM_BESR_M0ET_MASK) == SDRAM_BESR_M0ET_NONE) 551 - return 0; 552 - 553 - read = ((status->besr & SDRAM_BESR_M0RW_MASK) == SDRAM_BESR_M0RW_READ); 554 - 555 - master = SDRAM_BESR_M0ID_DECODE(status->besr); 556 - 557 - return snprintf(buffer, size, 558 - "%s error w/ PLB master %u \"%s\"; ", 559 - (read ? "Read" : "Write"), 560 - master, 561 - (((master >= SDRAM_PLB_M0ID_FIRST) && 562 - (master <= SDRAM_PLB_M0ID_LAST)) ? 563 - ppc4xx_plb_masters[master] : "UNKNOWN")); 564 - } 565 - 566 - /** 567 - * ppc4xx_edac_generate_message - generate interpretted status message 568 - * @mci: A pointer to the EDAC memory controller instance associated 569 - * with the driver-unique message being generated. 570 - * @status: A pointer to the ECC status structure to generate the 571 - * message from. 572 - * @buffer: A pointer to the buffer in which to generate the 573 - * message. 574 - * @size: The size, in bytes, of space available in buffer. 575 - * 576 - * This routine generates to the provided buffer the driver-unique 577 - * EDAC report message from the specified ECC status. 578 - */ 579 - static void 580 - ppc4xx_edac_generate_message(const struct mem_ctl_info *mci, 581 - const struct ppc4xx_ecc_status *status, 582 - char *buffer, 583 - size_t size) 584 - { 585 - int n; 586 - 587 - if (buffer == NULL || size == 0) 588 - return; 589 - 590 - n = ppc4xx_edac_generate_ecc_message(mci, status, buffer, size); 591 - 592 - if (n < 0 || n >= size) 593 - return; 594 - 595 - buffer += n; 596 - size -= n; 597 - 598 - ppc4xx_edac_generate_plb_message(mci, status, buffer, size); 599 - } 600 - 601 - #ifdef DEBUG 602 - /** 603 - * ppc4xx_ecc_dump_status - dump controller ECC status registers 604 - * @mci: A pointer to the EDAC memory controller instance 605 - * associated with the status being dumped. 606 - * @status: A pointer to the ECC status structure to generate the 607 - * dump from. 608 - * 609 - * This routine dumps to the kernel log buffer the raw and 610 - * interpretted specified ECC status. 611 - */ 612 - static void 613 - ppc4xx_ecc_dump_status(const struct mem_ctl_info *mci, 614 - const struct ppc4xx_ecc_status *status) 615 - { 616 - char message[PPC4XX_EDAC_MESSAGE_SIZE]; 617 - 618 - ppc4xx_edac_generate_message(mci, status, message, sizeof(message)); 619 - 620 - ppc4xx_edac_mc_printk(KERN_INFO, mci, 621 - "\n" 622 - "\tECCES: 0x%08x\n" 623 - "\tWMIRQ: 0x%08x\n" 624 - "\tBESR: 0x%08x\n" 625 - "\tBEAR: 0x%08x%08x\n" 626 - "\t%s\n", 627 - status->ecces, 628 - status->wmirq, 629 - status->besr, 630 - status->bearh, 631 - status->bearl, 632 - message); 633 - } 634 - #endif /* DEBUG */ 635 - 636 - /** 637 - * ppc4xx_ecc_get_status - get controller ECC status 638 - * @mci: A pointer to the EDAC memory controller instance 639 - * associated with the status being retrieved. 640 - * @status: A pointer to the ECC status structure to populate the 641 - * ECC status with. 642 - * 643 - * This routine reads and masks, as appropriate, all the relevant 644 - * status registers that deal with ibm,sdram-4xx-ddr2 ECC errors. 645 - * While we read all of them, for correctable errors, we only expect 646 - * to deal with ECCES. For uncorrectable errors, we expect to deal 647 - * with all of them. 648 - */ 649 - static void 650 - ppc4xx_ecc_get_status(const struct mem_ctl_info *mci, 651 - struct ppc4xx_ecc_status *status) 652 - { 653 - const struct ppc4xx_edac_pdata *pdata = mci->pvt_info; 654 - const dcr_host_t *dcr_host = &pdata->dcr_host; 655 - 656 - status->ecces = mfsdram(dcr_host, SDRAM_ECCES) & SDRAM_ECCES_MASK; 657 - status->wmirq = mfsdram(dcr_host, SDRAM_WMIRQ) & SDRAM_WMIRQ_MASK; 658 - status->besr = mfsdram(dcr_host, SDRAM_BESR) & SDRAM_BESR_MASK; 659 - status->bearl = mfsdram(dcr_host, SDRAM_BEARL); 660 - status->bearh = mfsdram(dcr_host, SDRAM_BEARH); 661 - } 662 - 663 - /** 664 - * ppc4xx_ecc_clear_status - clear controller ECC status 665 - * @mci: A pointer to the EDAC memory controller instance 666 - * associated with the status being cleared. 667 - * @status: A pointer to the ECC status structure containing the 668 - * values to write to clear the ECC status. 669 - * 670 - * This routine clears--by writing the masked (as appropriate) status 671 - * values back to--the status registers that deal with 672 - * ibm,sdram-4xx-ddr2 ECC errors. 673 - */ 674 - static void 675 - ppc4xx_ecc_clear_status(const struct mem_ctl_info *mci, 676 - const struct ppc4xx_ecc_status *status) 677 - { 678 - const struct ppc4xx_edac_pdata *pdata = mci->pvt_info; 679 - const dcr_host_t *dcr_host = &pdata->dcr_host; 680 - 681 - mtsdram(dcr_host, SDRAM_ECCES, status->ecces & SDRAM_ECCES_MASK); 682 - mtsdram(dcr_host, SDRAM_WMIRQ, status->wmirq & SDRAM_WMIRQ_MASK); 683 - mtsdram(dcr_host, SDRAM_BESR, status->besr & SDRAM_BESR_MASK); 684 - mtsdram(dcr_host, SDRAM_BEARL, 0); 685 - mtsdram(dcr_host, SDRAM_BEARH, 0); 686 - } 687 - 688 - /** 689 - * ppc4xx_edac_handle_ce - handle controller correctable ECC error (CE) 690 - * @mci: A pointer to the EDAC memory controller instance 691 - * associated with the correctable error being handled and reported. 692 - * @status: A pointer to the ECC status structure associated with 693 - * the correctable error being handled and reported. 694 - * 695 - * This routine handles an ibm,sdram-4xx-ddr2 controller ECC 696 - * correctable error. Per the aforementioned discussion, there's not 697 - * enough status available to use the full EDAC correctable error 698 - * interface, so we just pass driver-unique message to the "no info" 699 - * interface. 700 - */ 701 - static void 702 - ppc4xx_edac_handle_ce(struct mem_ctl_info *mci, 703 - const struct ppc4xx_ecc_status *status) 704 - { 705 - int row; 706 - char message[PPC4XX_EDAC_MESSAGE_SIZE]; 707 - 708 - ppc4xx_edac_generate_message(mci, status, message, sizeof(message)); 709 - 710 - for (row = 0; row < mci->nr_csrows; row++) 711 - if (ppc4xx_edac_check_bank_error(status, row)) 712 - edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 1, 713 - 0, 0, 0, 714 - row, 0, -1, 715 - message, ""); 716 - } 717 - 718 - /** 719 - * ppc4xx_edac_handle_ue - handle controller uncorrectable ECC error (UE) 720 - * @mci: A pointer to the EDAC memory controller instance 721 - * associated with the uncorrectable error being handled and 722 - * reported. 723 - * @status: A pointer to the ECC status structure associated with 724 - * the uncorrectable error being handled and reported. 725 - * 726 - * This routine handles an ibm,sdram-4xx-ddr2 controller ECC 727 - * uncorrectable error. 728 - */ 729 - static void 730 - ppc4xx_edac_handle_ue(struct mem_ctl_info *mci, 731 - const struct ppc4xx_ecc_status *status) 732 - { 733 - const u64 bear = ((u64)status->bearh << 32 | status->bearl); 734 - const unsigned long page = bear >> PAGE_SHIFT; 735 - const unsigned long offset = bear & ~PAGE_MASK; 736 - int row; 737 - char message[PPC4XX_EDAC_MESSAGE_SIZE]; 738 - 739 - ppc4xx_edac_generate_message(mci, status, message, sizeof(message)); 740 - 741 - for (row = 0; row < mci->nr_csrows; row++) 742 - if (ppc4xx_edac_check_bank_error(status, row)) 743 - edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 1, 744 - page, offset, 0, 745 - row, 0, -1, 746 - message, ""); 747 - } 748 - 749 - /** 750 - * ppc4xx_edac_check - check controller for ECC errors 751 - * @mci: A pointer to the EDAC memory controller instance 752 - * associated with the ibm,sdram-4xx-ddr2 controller being 753 - * checked. 754 - * 755 - * This routine is used to check and post ECC errors and is called by 756 - * both the EDAC polling thread and this driver's CE and UE interrupt 757 - * handler. 758 - */ 759 - static void 760 - ppc4xx_edac_check(struct mem_ctl_info *mci) 761 - { 762 - #ifdef DEBUG 763 - static unsigned int count; 764 - #endif 765 - struct ppc4xx_ecc_status status; 766 - 767 - ppc4xx_ecc_get_status(mci, &status); 768 - 769 - #ifdef DEBUG 770 - if (count++ % 30 == 0) 771 - ppc4xx_ecc_dump_status(mci, &status); 772 - #endif 773 - 774 - if (status.ecces & SDRAM_ECCES_UE) 775 - ppc4xx_edac_handle_ue(mci, &status); 776 - 777 - if (status.ecces & SDRAM_ECCES_CE) 778 - ppc4xx_edac_handle_ce(mci, &status); 779 - 780 - ppc4xx_ecc_clear_status(mci, &status); 781 - } 782 - 783 - /** 784 - * ppc4xx_edac_isr - SEC (CE) and DED (UE) interrupt service routine 785 - * @irq: The virtual interrupt number being serviced. 786 - * @dev_id: A pointer to the EDAC memory controller instance 787 - * associated with the interrupt being handled. 788 - * 789 - * This routine implements the interrupt handler for both correctable 790 - * (CE) and uncorrectable (UE) ECC errors for the ibm,sdram-4xx-ddr2 791 - * controller. It simply calls through to the same routine used during 792 - * polling to check, report and clear the ECC status. 793 - * 794 - * Unconditionally returns IRQ_HANDLED. 795 - */ 796 - static irqreturn_t 797 - ppc4xx_edac_isr(int irq, void *dev_id) 798 - { 799 - struct mem_ctl_info *mci = dev_id; 800 - 801 - ppc4xx_edac_check(mci); 802 - 803 - return IRQ_HANDLED; 804 - } 805 - 806 - /** 807 - * ppc4xx_edac_get_dtype - return the controller memory width 808 - * @mcopt1: The 32-bit Memory Controller Option 1 register value 809 - * currently set for the controller, from which the width 810 - * is derived. 811 - * 812 - * This routine returns the EDAC device type width appropriate for the 813 - * current controller configuration. 814 - * 815 - * TODO: This needs to be conditioned dynamically through feature 816 - * flags or some such when other controller variants are supported as 817 - * the 405EX[r] is 16-/32-bit and the others are 32-/64-bit with the 818 - * 16- and 64-bit field definition/value/enumeration (b1) overloaded 819 - * among them. 820 - * 821 - * Returns a device type width enumeration. 822 - */ 823 - static enum dev_type ppc4xx_edac_get_dtype(u32 mcopt1) 824 - { 825 - switch (mcopt1 & SDRAM_MCOPT1_WDTH_MASK) { 826 - case SDRAM_MCOPT1_WDTH_16: 827 - return DEV_X2; 828 - case SDRAM_MCOPT1_WDTH_32: 829 - return DEV_X4; 830 - default: 831 - return DEV_UNKNOWN; 832 - } 833 - } 834 - 835 - /** 836 - * ppc4xx_edac_get_mtype - return controller memory type 837 - * @mcopt1: The 32-bit Memory Controller Option 1 register value 838 - * currently set for the controller, from which the memory type 839 - * is derived. 840 - * 841 - * This routine returns the EDAC memory type appropriate for the 842 - * current controller configuration. 843 - * 844 - * Returns a memory type enumeration. 845 - */ 846 - static enum mem_type ppc4xx_edac_get_mtype(u32 mcopt1) 847 - { 848 - bool rden = ((mcopt1 & SDRAM_MCOPT1_RDEN_MASK) == SDRAM_MCOPT1_RDEN); 849 - 850 - switch (mcopt1 & SDRAM_MCOPT1_DDR_TYPE_MASK) { 851 - case SDRAM_MCOPT1_DDR2_TYPE: 852 - return rden ? MEM_RDDR2 : MEM_DDR2; 853 - case SDRAM_MCOPT1_DDR1_TYPE: 854 - return rden ? MEM_RDDR : MEM_DDR; 855 - default: 856 - return MEM_UNKNOWN; 857 - } 858 - } 859 - 860 - /** 861 - * ppc4xx_edac_init_csrows - initialize driver instance rows 862 - * @mci: A pointer to the EDAC memory controller instance 863 - * associated with the ibm,sdram-4xx-ddr2 controller for which 864 - * the csrows (i.e. banks/ranks) are being initialized. 865 - * @mcopt1: The 32-bit Memory Controller Option 1 register value 866 - * currently set for the controller, from which bank width 867 - * and memory typ information is derived. 868 - * 869 - * This routine initializes the virtual "chip select rows" associated 870 - * with the EDAC memory controller instance. An ibm,sdram-4xx-ddr2 871 - * controller bank/rank is mapped to a row. 872 - * 873 - * Returns 0 if OK; otherwise, -EINVAL if the memory bank size 874 - * configuration cannot be determined. 875 - */ 876 - static int ppc4xx_edac_init_csrows(struct mem_ctl_info *mci, u32 mcopt1) 877 - { 878 - const struct ppc4xx_edac_pdata *pdata = mci->pvt_info; 879 - int status = 0; 880 - enum mem_type mtype; 881 - enum dev_type dtype; 882 - enum edac_type edac_mode; 883 - int row, j; 884 - u32 mbxcf, size, nr_pages; 885 - 886 - /* Establish the memory type and width */ 887 - 888 - mtype = ppc4xx_edac_get_mtype(mcopt1); 889 - dtype = ppc4xx_edac_get_dtype(mcopt1); 890 - 891 - /* Establish EDAC mode */ 892 - 893 - if (mci->edac_cap & EDAC_FLAG_SECDED) 894 - edac_mode = EDAC_SECDED; 895 - else if (mci->edac_cap & EDAC_FLAG_EC) 896 - edac_mode = EDAC_EC; 897 - else 898 - edac_mode = EDAC_NONE; 899 - 900 - /* 901 - * Initialize each chip select row structure which correspond 902 - * 1:1 with a controller bank/rank. 903 - */ 904 - 905 - for (row = 0; row < mci->nr_csrows; row++) { 906 - struct csrow_info *csi = mci->csrows[row]; 907 - 908 - /* 909 - * Get the configuration settings for this 910 - * row/bank/rank and skip disabled banks. 911 - */ 912 - 913 - mbxcf = mfsdram(&pdata->dcr_host, SDRAM_MBXCF(row)); 914 - 915 - if ((mbxcf & SDRAM_MBCF_BE_MASK) != SDRAM_MBCF_BE_ENABLE) 916 - continue; 917 - 918 - /* Map the bank configuration size setting to pages. */ 919 - 920 - size = mbxcf & SDRAM_MBCF_SZ_MASK; 921 - 922 - switch (size) { 923 - case SDRAM_MBCF_SZ_4MB: 924 - case SDRAM_MBCF_SZ_8MB: 925 - case SDRAM_MBCF_SZ_16MB: 926 - case SDRAM_MBCF_SZ_32MB: 927 - case SDRAM_MBCF_SZ_64MB: 928 - case SDRAM_MBCF_SZ_128MB: 929 - case SDRAM_MBCF_SZ_256MB: 930 - case SDRAM_MBCF_SZ_512MB: 931 - case SDRAM_MBCF_SZ_1GB: 932 - case SDRAM_MBCF_SZ_2GB: 933 - case SDRAM_MBCF_SZ_4GB: 934 - case SDRAM_MBCF_SZ_8GB: 935 - nr_pages = SDRAM_MBCF_SZ_TO_PAGES(size); 936 - break; 937 - default: 938 - ppc4xx_edac_mc_printk(KERN_ERR, mci, 939 - "Unrecognized memory bank %d " 940 - "size 0x%08x\n", 941 - row, SDRAM_MBCF_SZ_DECODE(size)); 942 - status = -EINVAL; 943 - goto done; 944 - } 945 - 946 - /* 947 - * It's unclear exactly what grain should be set to 948 - * here. The SDRAM_ECCES register allows resolution of 949 - * an error down to a nibble which would potentially 950 - * argue for a grain of '1' byte, even though we only 951 - * know the associated address for uncorrectable 952 - * errors. This value is not used at present for 953 - * anything other than error reporting so getting it 954 - * wrong should be of little consequence. Other 955 - * possible values would be the PLB width (16), the 956 - * page size (PAGE_SIZE) or the memory width (2 or 4). 957 - */ 958 - for (j = 0; j < csi->nr_channels; j++) { 959 - struct dimm_info *dimm = csi->channels[j]->dimm; 960 - 961 - dimm->nr_pages = nr_pages / csi->nr_channels; 962 - dimm->grain = 1; 963 - 964 - dimm->mtype = mtype; 965 - dimm->dtype = dtype; 966 - 967 - dimm->edac_mode = edac_mode; 968 - } 969 - } 970 - 971 - done: 972 - return status; 973 - } 974 - 975 - /** 976 - * ppc4xx_edac_mc_init - initialize driver instance 977 - * @mci: A pointer to the EDAC memory controller instance being 978 - * initialized. 979 - * @op: A pointer to the OpenFirmware device tree node associated 980 - * with the controller this EDAC instance is bound to. 981 - * @dcr_host: A pointer to the DCR data containing the DCR mapping 982 - * for this controller instance. 983 - * @mcopt1: The 32-bit Memory Controller Option 1 register value 984 - * currently set for the controller, from which ECC capabilities 985 - * and scrub mode are derived. 986 - * 987 - * This routine performs initialization of the EDAC memory controller 988 - * instance and related driver-private data associated with the 989 - * ibm,sdram-4xx-ddr2 memory controller the instance is bound to. 990 - * 991 - * Returns 0 if OK; otherwise, < 0 on error. 992 - */ 993 - static int ppc4xx_edac_mc_init(struct mem_ctl_info *mci, 994 - struct platform_device *op, 995 - const dcr_host_t *dcr_host, u32 mcopt1) 996 - { 997 - int status = 0; 998 - const u32 memcheck = (mcopt1 & SDRAM_MCOPT1_MCHK_MASK); 999 - struct ppc4xx_edac_pdata *pdata = NULL; 1000 - const struct device_node *np = op->dev.of_node; 1001 - 1002 - if (of_match_device(ppc4xx_edac_match, &op->dev) == NULL) 1003 - return -EINVAL; 1004 - 1005 - /* Initial driver pointers and private data */ 1006 - 1007 - mci->pdev = &op->dev; 1008 - 1009 - dev_set_drvdata(mci->pdev, mci); 1010 - 1011 - pdata = mci->pvt_info; 1012 - 1013 - pdata->dcr_host = *dcr_host; 1014 - 1015 - /* Initialize controller capabilities and configuration */ 1016 - 1017 - mci->mtype_cap = (MEM_FLAG_DDR | MEM_FLAG_RDDR | 1018 - MEM_FLAG_DDR2 | MEM_FLAG_RDDR2); 1019 - 1020 - mci->edac_ctl_cap = (EDAC_FLAG_NONE | 1021 - EDAC_FLAG_EC | 1022 - EDAC_FLAG_SECDED); 1023 - 1024 - mci->scrub_cap = SCRUB_NONE; 1025 - mci->scrub_mode = SCRUB_NONE; 1026 - 1027 - /* 1028 - * Update the actual capabilites based on the MCOPT1[MCHK] 1029 - * settings. Scrubbing is only useful if reporting is enabled. 1030 - */ 1031 - 1032 - switch (memcheck) { 1033 - case SDRAM_MCOPT1_MCHK_CHK: 1034 - mci->edac_cap = EDAC_FLAG_EC; 1035 - break; 1036 - case SDRAM_MCOPT1_MCHK_CHK_REP: 1037 - mci->edac_cap = (EDAC_FLAG_EC | EDAC_FLAG_SECDED); 1038 - mci->scrub_mode = SCRUB_SW_SRC; 1039 - break; 1040 - default: 1041 - mci->edac_cap = EDAC_FLAG_NONE; 1042 - break; 1043 - } 1044 - 1045 - /* Initialize strings */ 1046 - 1047 - mci->mod_name = PPC4XX_EDAC_MODULE_NAME; 1048 - mci->ctl_name = ppc4xx_edac_match->compatible; 1049 - mci->dev_name = np->full_name; 1050 - 1051 - /* Initialize callbacks */ 1052 - 1053 - mci->edac_check = ppc4xx_edac_check; 1054 - mci->ctl_page_to_phys = NULL; 1055 - 1056 - /* Initialize chip select rows */ 1057 - 1058 - status = ppc4xx_edac_init_csrows(mci, mcopt1); 1059 - 1060 - if (status) 1061 - ppc4xx_edac_mc_printk(KERN_ERR, mci, 1062 - "Failed to initialize rows!\n"); 1063 - 1064 - return status; 1065 - } 1066 - 1067 - /** 1068 - * ppc4xx_edac_register_irq - setup and register controller interrupts 1069 - * @op: A pointer to the OpenFirmware device tree node associated 1070 - * with the controller this EDAC instance is bound to. 1071 - * @mci: A pointer to the EDAC memory controller instance 1072 - * associated with the ibm,sdram-4xx-ddr2 controller for which 1073 - * interrupts are being registered. 1074 - * 1075 - * This routine parses the correctable (CE) and uncorrectable error (UE) 1076 - * interrupts from the device tree node and maps and assigns them to 1077 - * the associated EDAC memory controller instance. 1078 - * 1079 - * Returns 0 if OK; otherwise, -ENODEV if the interrupts could not be 1080 - * mapped and assigned. 1081 - */ 1082 - static int ppc4xx_edac_register_irq(struct platform_device *op, 1083 - struct mem_ctl_info *mci) 1084 - { 1085 - int status = 0; 1086 - int ded_irq, sec_irq; 1087 - struct ppc4xx_edac_pdata *pdata = mci->pvt_info; 1088 - struct device_node *np = op->dev.of_node; 1089 - 1090 - ded_irq = irq_of_parse_and_map(np, INTMAP_ECCDED_INDEX); 1091 - sec_irq = irq_of_parse_and_map(np, INTMAP_ECCSEC_INDEX); 1092 - 1093 - if (!ded_irq || !sec_irq) { 1094 - ppc4xx_edac_mc_printk(KERN_ERR, mci, 1095 - "Unable to map interrupts.\n"); 1096 - status = -ENODEV; 1097 - goto fail; 1098 - } 1099 - 1100 - status = request_irq(ded_irq, 1101 - ppc4xx_edac_isr, 1102 - 0, 1103 - "[EDAC] MC ECCDED", 1104 - mci); 1105 - 1106 - if (status < 0) { 1107 - ppc4xx_edac_mc_printk(KERN_ERR, mci, 1108 - "Unable to request irq %d for ECC DED", 1109 - ded_irq); 1110 - status = -ENODEV; 1111 - goto fail1; 1112 - } 1113 - 1114 - status = request_irq(sec_irq, 1115 - ppc4xx_edac_isr, 1116 - 0, 1117 - "[EDAC] MC ECCSEC", 1118 - mci); 1119 - 1120 - if (status < 0) { 1121 - ppc4xx_edac_mc_printk(KERN_ERR, mci, 1122 - "Unable to request irq %d for ECC SEC", 1123 - sec_irq); 1124 - status = -ENODEV; 1125 - goto fail2; 1126 - } 1127 - 1128 - ppc4xx_edac_mc_printk(KERN_INFO, mci, "ECCDED irq is %d\n", ded_irq); 1129 - ppc4xx_edac_mc_printk(KERN_INFO, mci, "ECCSEC irq is %d\n", sec_irq); 1130 - 1131 - pdata->irqs.ded = ded_irq; 1132 - pdata->irqs.sec = sec_irq; 1133 - 1134 - return 0; 1135 - 1136 - fail2: 1137 - free_irq(sec_irq, mci); 1138 - 1139 - fail1: 1140 - free_irq(ded_irq, mci); 1141 - 1142 - fail: 1143 - return status; 1144 - } 1145 - 1146 - /** 1147 - * ppc4xx_edac_map_dcrs - locate and map controller registers 1148 - * @np: A pointer to the device tree node containing the DCR 1149 - * resources to map. 1150 - * @dcr_host: A pointer to the DCR data to populate with the 1151 - * DCR mapping. 1152 - * 1153 - * This routine attempts to locate in the device tree and map the DCR 1154 - * register resources associated with the controller's indirect DCR 1155 - * address and data windows. 1156 - * 1157 - * Returns 0 if the DCRs were successfully mapped; otherwise, < 0 on 1158 - * error. 1159 - */ 1160 - static int ppc4xx_edac_map_dcrs(const struct device_node *np, 1161 - dcr_host_t *dcr_host) 1162 - { 1163 - unsigned int dcr_base, dcr_len; 1164 - 1165 - if (np == NULL || dcr_host == NULL) 1166 - return -EINVAL; 1167 - 1168 - /* Get the DCR resource extent and sanity check the values. */ 1169 - 1170 - dcr_base = dcr_resource_start(np, 0); 1171 - dcr_len = dcr_resource_len(np, 0); 1172 - 1173 - if (dcr_base == 0 || dcr_len == 0) { 1174 - ppc4xx_edac_printk(KERN_ERR, 1175 - "Failed to obtain DCR property.\n"); 1176 - return -ENODEV; 1177 - } 1178 - 1179 - if (dcr_len != SDRAM_DCR_RESOURCE_LEN) { 1180 - ppc4xx_edac_printk(KERN_ERR, 1181 - "Unexpected DCR length %d, expected %d.\n", 1182 - dcr_len, SDRAM_DCR_RESOURCE_LEN); 1183 - return -ENODEV; 1184 - } 1185 - 1186 - /* Attempt to map the DCR extent. */ 1187 - 1188 - *dcr_host = dcr_map(np, dcr_base, dcr_len); 1189 - 1190 - if (!DCR_MAP_OK(*dcr_host)) { 1191 - ppc4xx_edac_printk(KERN_INFO, "Failed to map DCRs.\n"); 1192 - return -ENODEV; 1193 - } 1194 - 1195 - return 0; 1196 - } 1197 - 1198 - /** 1199 - * ppc4xx_edac_probe - check controller and bind driver 1200 - * @op: A pointer to the OpenFirmware device tree node associated 1201 - * with the controller being probed for driver binding. 1202 - * 1203 - * This routine probes a specific ibm,sdram-4xx-ddr2 controller 1204 - * instance for binding with the driver. 1205 - * 1206 - * Returns 0 if the controller instance was successfully bound to the 1207 - * driver; otherwise, < 0 on error. 1208 - */ 1209 - static int ppc4xx_edac_probe(struct platform_device *op) 1210 - { 1211 - int status = 0; 1212 - u32 mcopt1, memcheck; 1213 - dcr_host_t dcr_host; 1214 - const struct device_node *np = op->dev.of_node; 1215 - struct mem_ctl_info *mci = NULL; 1216 - struct edac_mc_layer layers[2]; 1217 - static int ppc4xx_edac_instance; 1218 - 1219 - /* 1220 - * At this point, we only support the controller realized on 1221 - * the AMCC PPC 405EX[r]. Reject anything else. 1222 - */ 1223 - 1224 - if (!of_device_is_compatible(np, "ibm,sdram-405ex") && 1225 - !of_device_is_compatible(np, "ibm,sdram-405exr")) { 1226 - ppc4xx_edac_printk(KERN_NOTICE, 1227 - "Only the PPC405EX[r] is supported.\n"); 1228 - return -ENODEV; 1229 - } 1230 - 1231 - /* 1232 - * Next, get the DCR property and attempt to map it so that we 1233 - * can probe the controller. 1234 - */ 1235 - 1236 - status = ppc4xx_edac_map_dcrs(np, &dcr_host); 1237 - 1238 - if (status) 1239 - return status; 1240 - 1241 - /* 1242 - * First determine whether ECC is enabled at all. If not, 1243 - * there is no useful checking or monitoring that can be done 1244 - * for this controller. 1245 - */ 1246 - 1247 - mcopt1 = mfsdram(&dcr_host, SDRAM_MCOPT1); 1248 - memcheck = (mcopt1 & SDRAM_MCOPT1_MCHK_MASK); 1249 - 1250 - if (memcheck == SDRAM_MCOPT1_MCHK_NON) { 1251 - ppc4xx_edac_printk(KERN_INFO, "%pOF: No ECC memory detected or " 1252 - "ECC is disabled.\n", np); 1253 - status = -ENODEV; 1254 - goto done; 1255 - } 1256 - 1257 - /* 1258 - * At this point, we know ECC is enabled, allocate an EDAC 1259 - * controller instance and perform the appropriate 1260 - * initialization. 1261 - */ 1262 - layers[0].type = EDAC_MC_LAYER_CHIP_SELECT; 1263 - layers[0].size = ppc4xx_edac_nr_csrows; 1264 - layers[0].is_virt_csrow = true; 1265 - layers[1].type = EDAC_MC_LAYER_CHANNEL; 1266 - layers[1].size = ppc4xx_edac_nr_chans; 1267 - layers[1].is_virt_csrow = false; 1268 - mci = edac_mc_alloc(ppc4xx_edac_instance, ARRAY_SIZE(layers), layers, 1269 - sizeof(struct ppc4xx_edac_pdata)); 1270 - if (mci == NULL) { 1271 - ppc4xx_edac_printk(KERN_ERR, "%pOF: " 1272 - "Failed to allocate EDAC MC instance!\n", 1273 - np); 1274 - status = -ENOMEM; 1275 - goto done; 1276 - } 1277 - 1278 - status = ppc4xx_edac_mc_init(mci, op, &dcr_host, mcopt1); 1279 - 1280 - if (status) { 1281 - ppc4xx_edac_mc_printk(KERN_ERR, mci, 1282 - "Failed to initialize instance!\n"); 1283 - goto fail; 1284 - } 1285 - 1286 - /* 1287 - * We have a valid, initialized EDAC instance bound to the 1288 - * controller. Attempt to register it with the EDAC subsystem 1289 - * and, if necessary, register interrupts. 1290 - */ 1291 - 1292 - if (edac_mc_add_mc(mci)) { 1293 - ppc4xx_edac_mc_printk(KERN_ERR, mci, 1294 - "Failed to add instance!\n"); 1295 - status = -ENODEV; 1296 - goto fail; 1297 - } 1298 - 1299 - if (edac_op_state == EDAC_OPSTATE_INT) { 1300 - status = ppc4xx_edac_register_irq(op, mci); 1301 - 1302 - if (status) 1303 - goto fail1; 1304 - } 1305 - 1306 - ppc4xx_edac_instance++; 1307 - 1308 - return 0; 1309 - 1310 - fail1: 1311 - edac_mc_del_mc(mci->pdev); 1312 - 1313 - fail: 1314 - edac_mc_free(mci); 1315 - 1316 - done: 1317 - return status; 1318 - } 1319 - 1320 - /** 1321 - * ppc4xx_edac_remove - unbind driver from controller 1322 - * @op: A pointer to the OpenFirmware device tree node associated 1323 - * with the controller this EDAC instance is to be unbound/removed 1324 - * from. 1325 - * 1326 - * This routine unbinds the EDAC memory controller instance associated 1327 - * with the specified ibm,sdram-4xx-ddr2 controller described by the 1328 - * OpenFirmware device tree node passed as a parameter. 1329 - * 1330 - * Unconditionally returns 0. 1331 - */ 1332 - static void ppc4xx_edac_remove(struct platform_device *op) 1333 - { 1334 - struct mem_ctl_info *mci = dev_get_drvdata(&op->dev); 1335 - struct ppc4xx_edac_pdata *pdata = mci->pvt_info; 1336 - 1337 - if (edac_op_state == EDAC_OPSTATE_INT) { 1338 - free_irq(pdata->irqs.sec, mci); 1339 - free_irq(pdata->irqs.ded, mci); 1340 - } 1341 - 1342 - dcr_unmap(pdata->dcr_host, SDRAM_DCR_RESOURCE_LEN); 1343 - 1344 - edac_mc_del_mc(mci->pdev); 1345 - edac_mc_free(mci); 1346 - } 1347 - 1348 - /** 1349 - * ppc4xx_edac_opstate_init - initialize EDAC reporting method 1350 - * 1351 - * This routine ensures that the EDAC memory controller reporting 1352 - * method is mapped to a sane value as the EDAC core defines the value 1353 - * to EDAC_OPSTATE_INVAL by default. We don't call the global 1354 - * opstate_init as that defaults to polling and we want interrupt as 1355 - * the default. 1356 - */ 1357 - static inline void __init 1358 - ppc4xx_edac_opstate_init(void) 1359 - { 1360 - switch (edac_op_state) { 1361 - case EDAC_OPSTATE_POLL: 1362 - case EDAC_OPSTATE_INT: 1363 - break; 1364 - default: 1365 - edac_op_state = EDAC_OPSTATE_INT; 1366 - break; 1367 - } 1368 - 1369 - ppc4xx_edac_printk(KERN_INFO, "Reporting type: %s\n", 1370 - ((edac_op_state == EDAC_OPSTATE_POLL) ? 1371 - EDAC_OPSTATE_POLL_STR : 1372 - ((edac_op_state == EDAC_OPSTATE_INT) ? 1373 - EDAC_OPSTATE_INT_STR : 1374 - EDAC_OPSTATE_UNKNOWN_STR))); 1375 - } 1376 - 1377 - static struct platform_driver ppc4xx_edac_driver = { 1378 - .probe = ppc4xx_edac_probe, 1379 - .remove_new = ppc4xx_edac_remove, 1380 - .driver = { 1381 - .name = PPC4XX_EDAC_MODULE_NAME, 1382 - .of_match_table = ppc4xx_edac_match, 1383 - }, 1384 - }; 1385 - 1386 - /** 1387 - * ppc4xx_edac_init - driver/module insertion entry point 1388 - * 1389 - * This routine is the driver/module insertion entry point. It 1390 - * initializes the EDAC memory controller reporting state and 1391 - * registers the driver as an OpenFirmware device tree platform 1392 - * driver. 1393 - */ 1394 - static int __init 1395 - ppc4xx_edac_init(void) 1396 - { 1397 - ppc4xx_edac_printk(KERN_INFO, PPC4XX_EDAC_MODULE_REVISION "\n"); 1398 - 1399 - ppc4xx_edac_opstate_init(); 1400 - 1401 - return platform_driver_register(&ppc4xx_edac_driver); 1402 - } 1403 - 1404 - /** 1405 - * ppc4xx_edac_exit - driver/module removal entry point 1406 - * 1407 - * This routine is the driver/module removal entry point. It 1408 - * unregisters the driver as an OpenFirmware device tree platform 1409 - * driver. 1410 - */ 1411 - static void __exit 1412 - ppc4xx_edac_exit(void) 1413 - { 1414 - platform_driver_unregister(&ppc4xx_edac_driver); 1415 - } 1416 - 1417 - module_init(ppc4xx_edac_init); 1418 - module_exit(ppc4xx_edac_exit); 1419 - 1420 - MODULE_LICENSE("GPL v2"); 1421 - MODULE_AUTHOR("Grant Erickson <gerickson@nuovations.com>"); 1422 - MODULE_DESCRIPTION("EDAC MC Driver for the PPC4xx IBM DDR2 Memory Controller"); 1423 - module_param(edac_op_state, int, 0444); 1424 - MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting State: " 1425 - "0=" EDAC_OPSTATE_POLL_STR ", 2=" EDAC_OPSTATE_INT_STR);
-167
drivers/edac/ppc4xx_edac.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0-only */ 2 - /* 3 - * Copyright (c) 2008 Nuovation System Designs, LLC 4 - * Grant Erickson <gerickson@nuovations.com> 5 - * 6 - * This file defines processor mnemonics for accessing and managing 7 - * the IBM DDR1/DDR2 ECC controller found in the 405EX[r], 440SP, 8 - * 440SPe, 460EX, 460GT and 460SX. 9 - */ 10 - 11 - #ifndef __PPC4XX_EDAC_H 12 - #define __PPC4XX_EDAC_H 13 - 14 - #include <linux/types.h> 15 - 16 - /* 17 - * Macro for generating register field mnemonics 18 - */ 19 - #define PPC_REG_BITS 32 20 - #define PPC_REG_VAL(bit, val) ((val) << ((PPC_REG_BITS - 1) - (bit))) 21 - #define PPC_REG_DECODE(bit, val) ((val) >> ((PPC_REG_BITS - 1) - (bit))) 22 - 23 - /* 24 - * IBM 4xx DDR1/DDR2 SDRAM memory controller registers (at least those 25 - * relevant to ECC) 26 - */ 27 - #define SDRAM_BESR 0x00 /* Error status (read/clear) */ 28 - #define SDRAM_BESRT 0x01 /* Error statuss (test/set) */ 29 - #define SDRAM_BEARL 0x02 /* Error address low */ 30 - #define SDRAM_BEARH 0x03 /* Error address high */ 31 - #define SDRAM_WMIRQ 0x06 /* Write master (read/clear) */ 32 - #define SDRAM_WMIRQT 0x07 /* Write master (test/set) */ 33 - #define SDRAM_MCOPT1 0x20 /* Controller options 1 */ 34 - #define SDRAM_MBXCF_BASE 0x40 /* Bank n configuration base */ 35 - #define SDRAM_MBXCF(n) (SDRAM_MBXCF_BASE + (4 * (n))) 36 - #define SDRAM_MB0CF SDRAM_MBXCF(0) 37 - #define SDRAM_MB1CF SDRAM_MBXCF(1) 38 - #define SDRAM_MB2CF SDRAM_MBXCF(2) 39 - #define SDRAM_MB3CF SDRAM_MBXCF(3) 40 - #define SDRAM_ECCCR 0x98 /* ECC error status */ 41 - #define SDRAM_ECCES SDRAM_ECCCR 42 - 43 - /* 44 - * PLB Master IDs 45 - */ 46 - #define SDRAM_PLB_M0ID_FIRST 0 47 - #define SDRAM_PLB_M0ID_ICU SDRAM_PLB_M0ID_FIRST 48 - #define SDRAM_PLB_M0ID_PCIE0 1 49 - #define SDRAM_PLB_M0ID_PCIE1 2 50 - #define SDRAM_PLB_M0ID_DMA 3 51 - #define SDRAM_PLB_M0ID_DCU 4 52 - #define SDRAM_PLB_M0ID_OPB 5 53 - #define SDRAM_PLB_M0ID_MAL 6 54 - #define SDRAM_PLB_M0ID_SEC 7 55 - #define SDRAM_PLB_M0ID_AHB 8 56 - #define SDRAM_PLB_M0ID_LAST SDRAM_PLB_M0ID_AHB 57 - #define SDRAM_PLB_M0ID_COUNT (SDRAM_PLB_M0ID_LAST - \ 58 - SDRAM_PLB_M0ID_FIRST + 1) 59 - 60 - /* 61 - * Memory Controller Bus Error Status Register 62 - */ 63 - #define SDRAM_BESR_MASK PPC_REG_VAL(7, 0xFF) 64 - #define SDRAM_BESR_M0ID_MASK PPC_REG_VAL(3, 0xF) 65 - #define SDRAM_BESR_M0ID_DECODE(n) PPC_REG_DECODE(3, n) 66 - #define SDRAM_BESR_M0ID_ICU PPC_REG_VAL(3, SDRAM_PLB_M0ID_ICU) 67 - #define SDRAM_BESR_M0ID_PCIE0 PPC_REG_VAL(3, SDRAM_PLB_M0ID_PCIE0) 68 - #define SDRAM_BESR_M0ID_PCIE1 PPC_REG_VAL(3, SDRAM_PLB_M0ID_PCIE1) 69 - #define SDRAM_BESR_M0ID_DMA PPC_REG_VAL(3, SDRAM_PLB_M0ID_DMA) 70 - #define SDRAM_BESR_M0ID_DCU PPC_REG_VAL(3, SDRAM_PLB_M0ID_DCU) 71 - #define SDRAM_BESR_M0ID_OPB PPC_REG_VAL(3, SDRAM_PLB_M0ID_OPB) 72 - #define SDRAM_BESR_M0ID_MAL PPC_REG_VAL(3, SDRAM_PLB_M0ID_MAL) 73 - #define SDRAM_BESR_M0ID_SEC PPC_REG_VAL(3, SDRAM_PLB_M0ID_SEC) 74 - #define SDRAM_BESR_M0ID_AHB PPC_REG_VAL(3, SDRAM_PLB_M0ID_AHB) 75 - #define SDRAM_BESR_M0ET_MASK PPC_REG_VAL(6, 0x7) 76 - #define SDRAM_BESR_M0ET_NONE PPC_REG_VAL(6, 0) 77 - #define SDRAM_BESR_M0ET_ECC PPC_REG_VAL(6, 1) 78 - #define SDRAM_BESR_M0RW_MASK PPC_REG_VAL(7, 1) 79 - #define SDRAM_BESR_M0RW_WRITE PPC_REG_VAL(7, 0) 80 - #define SDRAM_BESR_M0RW_READ PPC_REG_VAL(7, 1) 81 - 82 - /* 83 - * Memory Controller PLB Write Master Interrupt Register 84 - */ 85 - #define SDRAM_WMIRQ_MASK PPC_REG_VAL(8, 0x1FF) 86 - #define SDRAM_WMIRQ_ENCODE(id) PPC_REG_VAL((id % \ 87 - SDRAM_PLB_M0ID_COUNT), 1) 88 - #define SDRAM_WMIRQ_ICU PPC_REG_VAL(SDRAM_PLB_M0ID_ICU, 1) 89 - #define SDRAM_WMIRQ_PCIE0 PPC_REG_VAL(SDRAM_PLB_M0ID_PCIE0, 1) 90 - #define SDRAM_WMIRQ_PCIE1 PPC_REG_VAL(SDRAM_PLB_M0ID_PCIE1, 1) 91 - #define SDRAM_WMIRQ_DMA PPC_REG_VAL(SDRAM_PLB_M0ID_DMA, 1) 92 - #define SDRAM_WMIRQ_DCU PPC_REG_VAL(SDRAM_PLB_M0ID_DCU, 1) 93 - #define SDRAM_WMIRQ_OPB PPC_REG_VAL(SDRAM_PLB_M0ID_OPB, 1) 94 - #define SDRAM_WMIRQ_MAL PPC_REG_VAL(SDRAM_PLB_M0ID_MAL, 1) 95 - #define SDRAM_WMIRQ_SEC PPC_REG_VAL(SDRAM_PLB_M0ID_SEC, 1) 96 - #define SDRAM_WMIRQ_AHB PPC_REG_VAL(SDRAM_PLB_M0ID_AHB, 1) 97 - 98 - /* 99 - * Memory Controller Options 1 Register 100 - */ 101 - #define SDRAM_MCOPT1_MCHK_MASK PPC_REG_VAL(3, 0x3) /* ECC mask */ 102 - #define SDRAM_MCOPT1_MCHK_NON PPC_REG_VAL(3, 0x0) /* No ECC gen */ 103 - #define SDRAM_MCOPT1_MCHK_GEN PPC_REG_VAL(3, 0x2) /* ECC gen */ 104 - #define SDRAM_MCOPT1_MCHK_CHK PPC_REG_VAL(3, 0x1) /* ECC gen and chk */ 105 - #define SDRAM_MCOPT1_MCHK_CHK_REP PPC_REG_VAL(3, 0x3) /* ECC gen/chk/rpt */ 106 - #define SDRAM_MCOPT1_MCHK_DECODE(n) ((((u32)(n)) >> 28) & 0x3) 107 - #define SDRAM_MCOPT1_RDEN_MASK PPC_REG_VAL(4, 0x1) /* Rgstrd DIMM mask */ 108 - #define SDRAM_MCOPT1_RDEN PPC_REG_VAL(4, 0x1) /* Rgstrd DIMM enbl */ 109 - #define SDRAM_MCOPT1_WDTH_MASK PPC_REG_VAL(7, 0x1) /* Width mask */ 110 - #define SDRAM_MCOPT1_WDTH_32 PPC_REG_VAL(7, 0x0) /* 32 bits */ 111 - #define SDRAM_MCOPT1_WDTH_16 PPC_REG_VAL(7, 0x1) /* 16 bits */ 112 - #define SDRAM_MCOPT1_DDR_TYPE_MASK PPC_REG_VAL(11, 0x1) /* DDR type mask */ 113 - #define SDRAM_MCOPT1_DDR1_TYPE PPC_REG_VAL(11, 0x0) /* DDR1 type */ 114 - #define SDRAM_MCOPT1_DDR2_TYPE PPC_REG_VAL(11, 0x1) /* DDR2 type */ 115 - 116 - /* 117 - * Memory Bank 0 - n Configuration Register 118 - */ 119 - #define SDRAM_MBCF_BA_MASK PPC_REG_VAL(12, 0x1FFF) 120 - #define SDRAM_MBCF_SZ_MASK PPC_REG_VAL(19, 0xF) 121 - #define SDRAM_MBCF_SZ_DECODE(mbxcf) PPC_REG_DECODE(19, mbxcf) 122 - #define SDRAM_MBCF_SZ_4MB PPC_REG_VAL(19, 0x0) 123 - #define SDRAM_MBCF_SZ_8MB PPC_REG_VAL(19, 0x1) 124 - #define SDRAM_MBCF_SZ_16MB PPC_REG_VAL(19, 0x2) 125 - #define SDRAM_MBCF_SZ_32MB PPC_REG_VAL(19, 0x3) 126 - #define SDRAM_MBCF_SZ_64MB PPC_REG_VAL(19, 0x4) 127 - #define SDRAM_MBCF_SZ_128MB PPC_REG_VAL(19, 0x5) 128 - #define SDRAM_MBCF_SZ_256MB PPC_REG_VAL(19, 0x6) 129 - #define SDRAM_MBCF_SZ_512MB PPC_REG_VAL(19, 0x7) 130 - #define SDRAM_MBCF_SZ_1GB PPC_REG_VAL(19, 0x8) 131 - #define SDRAM_MBCF_SZ_2GB PPC_REG_VAL(19, 0x9) 132 - #define SDRAM_MBCF_SZ_4GB PPC_REG_VAL(19, 0xA) 133 - #define SDRAM_MBCF_SZ_8GB PPC_REG_VAL(19, 0xB) 134 - #define SDRAM_MBCF_AM_MASK PPC_REG_VAL(23, 0xF) 135 - #define SDRAM_MBCF_AM_MODE0 PPC_REG_VAL(23, 0x0) 136 - #define SDRAM_MBCF_AM_MODE1 PPC_REG_VAL(23, 0x1) 137 - #define SDRAM_MBCF_AM_MODE2 PPC_REG_VAL(23, 0x2) 138 - #define SDRAM_MBCF_AM_MODE3 PPC_REG_VAL(23, 0x3) 139 - #define SDRAM_MBCF_AM_MODE4 PPC_REG_VAL(23, 0x4) 140 - #define SDRAM_MBCF_AM_MODE5 PPC_REG_VAL(23, 0x5) 141 - #define SDRAM_MBCF_AM_MODE6 PPC_REG_VAL(23, 0x6) 142 - #define SDRAM_MBCF_AM_MODE7 PPC_REG_VAL(23, 0x7) 143 - #define SDRAM_MBCF_AM_MODE8 PPC_REG_VAL(23, 0x8) 144 - #define SDRAM_MBCF_AM_MODE9 PPC_REG_VAL(23, 0x9) 145 - #define SDRAM_MBCF_BE_MASK PPC_REG_VAL(31, 0x1) 146 - #define SDRAM_MBCF_BE_DISABLE PPC_REG_VAL(31, 0x0) 147 - #define SDRAM_MBCF_BE_ENABLE PPC_REG_VAL(31, 0x1) 148 - 149 - /* 150 - * ECC Error Status 151 - */ 152 - #define SDRAM_ECCES_MASK PPC_REG_VAL(21, 0x3FFFFF) 153 - #define SDRAM_ECCES_BNCE_MASK PPC_REG_VAL(15, 0xFFFF) 154 - #define SDRAM_ECCES_BNCE_ENCODE(lane) PPC_REG_VAL(((lane) & 0xF), 1) 155 - #define SDRAM_ECCES_CKBER_MASK PPC_REG_VAL(17, 0x3) 156 - #define SDRAM_ECCES_CKBER_NONE PPC_REG_VAL(17, 0) 157 - #define SDRAM_ECCES_CKBER_16_ECC_0_3 PPC_REG_VAL(17, 2) 158 - #define SDRAM_ECCES_CKBER_32_ECC_0_3 PPC_REG_VAL(17, 1) 159 - #define SDRAM_ECCES_CKBER_32_ECC_4_8 PPC_REG_VAL(17, 2) 160 - #define SDRAM_ECCES_CKBER_32_ECC_0_8 PPC_REG_VAL(17, 3) 161 - #define SDRAM_ECCES_CE PPC_REG_VAL(18, 1) 162 - #define SDRAM_ECCES_UE PPC_REG_VAL(19, 1) 163 - #define SDRAM_ECCES_BKNER_MASK PPC_REG_VAL(21, 0x3) 164 - #define SDRAM_ECCES_BK0ER PPC_REG_VAL(20, 1) 165 - #define SDRAM_ECCES_BK1ER PPC_REG_VAL(21, 1) 166 - 167 - #endif /* __PPC4XX_EDAC_H */
+18 -17
drivers/edac/sb_edac.c
··· 29 29 30 30 /* Static vars */ 31 31 static LIST_HEAD(sbridge_edac_list); 32 + static char sb_msg[256]; 33 + static char sb_msg_full[512]; 32 34 33 35 /* 34 36 * Alter this version for the module when modifications are made ··· 3081 3079 struct mem_ctl_info *new_mci; 3082 3080 struct sbridge_pvt *pvt = mci->pvt_info; 3083 3081 enum hw_event_mc_err_type tp_event; 3084 - char *optype, msg[256], msg_full[512]; 3085 3082 bool ripv = GET_BITFIELD(m->mcgstatus, 0, 0); 3086 3083 bool overflow = GET_BITFIELD(m->status, 62, 62); 3087 3084 bool uncorrected_error = GET_BITFIELD(m->status, 61, 61); ··· 3096 3095 * aligned address reported by patrol scrubber. 3097 3096 */ 3098 3097 u32 lsb = GET_BITFIELD(m->misc, 0, 5); 3098 + char *optype, *area_type = "DRAM"; 3099 3099 long channel_mask, first_channel; 3100 3100 u8 rank = 0xff, socket, ha; 3101 3101 int rc, dimm; 3102 - char *area_type = "DRAM"; 3103 3102 3104 3103 if (pvt->info.type != SANDY_BRIDGE) 3105 3104 recoverable = true; ··· 3169 3168 channel = knl_channel_remap(m->bank == 16, channel); 3170 3169 channel_mask = 1 << channel; 3171 3170 3172 - snprintf(msg, sizeof(msg), 3173 - "%s%s err_code:%04x:%04x channel:%d (DIMM_%c)", 3174 - overflow ? " OVERFLOW" : "", 3175 - (uncorrected_error && recoverable) 3176 - ? " recoverable" : " ", 3177 - mscod, errcode, channel, A + channel); 3171 + snprintf(sb_msg, sizeof(sb_msg), 3172 + "%s%s err_code:%04x:%04x channel:%d (DIMM_%c)", 3173 + overflow ? " OVERFLOW" : "", 3174 + (uncorrected_error && recoverable) 3175 + ? " recoverable" : " ", 3176 + mscod, errcode, channel, A + channel); 3178 3177 edac_mc_handle_error(tp_event, mci, core_err_cnt, 3179 3178 m->addr >> PAGE_SHIFT, m->addr & ~PAGE_MASK, 0, 3180 3179 channel, 0, -1, 3181 - optype, msg); 3180 + optype, sb_msg); 3182 3181 } 3183 3182 return; 3184 3183 } else if (lsb < 12) { 3185 3184 rc = get_memory_error_data(mci, m->addr, &socket, &ha, 3186 3185 &channel_mask, &rank, 3187 - &area_type, msg); 3186 + &area_type, sb_msg); 3188 3187 } else { 3189 3188 rc = get_memory_error_data_from_mce(mci, m, &socket, &ha, 3190 - &channel_mask, msg); 3189 + &channel_mask, sb_msg); 3191 3190 } 3192 3191 3193 3192 if (rc < 0) 3194 3193 goto err_parsing; 3195 3194 new_mci = get_mci_for_node_id(socket, ha); 3196 3195 if (!new_mci) { 3197 - strcpy(msg, "Error: socket got corrupted!"); 3196 + strscpy(sb_msg, "Error: socket got corrupted!"); 3198 3197 goto err_parsing; 3199 3198 } 3200 3199 mci = new_mci; ··· 3219 3218 */ 3220 3219 if (!pvt->is_lockstep && !pvt->is_cur_addr_mirrored && !pvt->is_close_pg) 3221 3220 channel = first_channel; 3222 - snprintf(msg_full, sizeof(msg_full), 3221 + snprintf(sb_msg_full, sizeof(sb_msg_full), 3223 3222 "%s%s area:%s err_code:%04x:%04x socket:%d ha:%d channel_mask:%ld rank:%d %s", 3224 3223 overflow ? " OVERFLOW" : "", 3225 3224 (uncorrected_error && recoverable) ? " recoverable" : "", ··· 3227 3226 mscod, errcode, 3228 3227 socket, ha, 3229 3228 channel_mask, 3230 - rank, msg); 3229 + rank, sb_msg); 3231 3230 3232 - edac_dbg(0, "%s\n", msg_full); 3231 + edac_dbg(0, "%s\n", sb_msg_full); 3233 3232 3234 3233 /* FIXME: need support for channel mask */ 3235 3234 ··· 3240 3239 edac_mc_handle_error(tp_event, mci, core_err_cnt, 3241 3240 m->addr >> PAGE_SHIFT, m->addr & ~PAGE_MASK, 0, 3242 3241 channel, dimm, -1, 3243 - optype, msg_full); 3242 + optype, sb_msg_full); 3244 3243 return; 3245 3244 err_parsing: 3246 3245 edac_mc_handle_error(tp_event, mci, core_err_cnt, 0, 0, 0, 3247 3246 -1, -1, -1, 3248 - msg, ""); 3247 + sb_msg, ""); 3249 3248 3250 3249 } 3251 3250
+2 -50
drivers/edac/skx_base.c
··· 587 587 .priority = MCE_PRIO_EDAC, 588 588 }; 589 589 590 - #ifdef CONFIG_EDAC_DEBUG 591 - /* 592 - * Debug feature. 593 - * Exercise the address decode logic by writing an address to 594 - * /sys/kernel/debug/edac/skx_test/addr. 595 - */ 596 - static struct dentry *skx_test; 597 - 598 - static int debugfs_u64_set(void *data, u64 val) 599 - { 600 - struct mce m; 601 - 602 - pr_warn_once("Fake error to 0x%llx injected via debugfs\n", val); 603 - 604 - memset(&m, 0, sizeof(m)); 605 - /* ADDRV + MemRd + Unknown channel */ 606 - m.status = MCI_STATUS_ADDRV + 0x90; 607 - /* One corrected error */ 608 - m.status |= BIT_ULL(MCI_STATUS_CEC_SHIFT); 609 - m.addr = val; 610 - skx_mce_check_error(NULL, 0, &m); 611 - 612 - return 0; 613 - } 614 - DEFINE_SIMPLE_ATTRIBUTE(fops_u64_wo, NULL, debugfs_u64_set, "%llu\n"); 615 - 616 - static void setup_skx_debug(void) 617 - { 618 - skx_test = edac_debugfs_create_dir("skx_test"); 619 - if (!skx_test) 620 - return; 621 - 622 - if (!edac_debugfs_create_file("addr", 0200, skx_test, 623 - NULL, &fops_u64_wo)) { 624 - debugfs_remove(skx_test); 625 - skx_test = NULL; 626 - } 627 - } 628 - 629 - static void teardown_skx_debug(void) 630 - { 631 - debugfs_remove_recursive(skx_test); 632 - } 633 - #else 634 - static inline void setup_skx_debug(void) {} 635 - static inline void teardown_skx_debug(void) {} 636 - #endif /*CONFIG_EDAC_DEBUG*/ 637 - 638 590 /* 639 591 * skx_init: 640 592 * make sure we are running on the correct cpu model ··· 680 728 /* Ensure that the OPSTATE is set correctly for POLL or NMI */ 681 729 opstate_init(); 682 730 683 - setup_skx_debug(); 731 + skx_setup_debug("skx_test"); 684 732 685 733 mce_register_decode_chain(&skx_mce_dec); 686 734 ··· 694 742 { 695 743 edac_dbg(2, "\n"); 696 744 mce_unregister_decode_chain(&skx_mce_dec); 697 - teardown_skx_debug(); 745 + skx_teardown_debug(); 698 746 if (nvdimm_count) 699 747 skx_adxl_put(); 700 748 skx_remove();
+48 -1
drivers/edac/skx_common.c
··· 363 363 if (imc->hbm_mc) { 364 364 banks = 32; 365 365 mtype = MEM_HBM2; 366 - } else if (cfg->support_ddr5 && (amap & 0x8)) { 366 + } else if (cfg->support_ddr5) { 367 367 banks = 32; 368 368 mtype = MEM_DDR5; 369 369 } else { ··· 738 738 } 739 739 } 740 740 EXPORT_SYMBOL_GPL(skx_remove); 741 + 742 + #ifdef CONFIG_EDAC_DEBUG 743 + /* 744 + * Debug feature. 745 + * Exercise the address decode logic by writing an address to 746 + * /sys/kernel/debug/edac/{skx,i10nm}_test/addr. 747 + */ 748 + static struct dentry *skx_test; 749 + 750 + static int debugfs_u64_set(void *data, u64 val) 751 + { 752 + struct mce m; 753 + 754 + pr_warn_once("Fake error to 0x%llx injected via debugfs\n", val); 755 + 756 + memset(&m, 0, sizeof(m)); 757 + /* ADDRV + MemRd + Unknown channel */ 758 + m.status = MCI_STATUS_ADDRV + 0x90; 759 + /* One corrected error */ 760 + m.status |= BIT_ULL(MCI_STATUS_CEC_SHIFT); 761 + m.addr = val; 762 + skx_mce_check_error(NULL, 0, &m); 763 + 764 + return 0; 765 + } 766 + DEFINE_SIMPLE_ATTRIBUTE(fops_u64_wo, NULL, debugfs_u64_set, "%llu\n"); 767 + 768 + void skx_setup_debug(const char *name) 769 + { 770 + skx_test = edac_debugfs_create_dir(name); 771 + if (!skx_test) 772 + return; 773 + 774 + if (!edac_debugfs_create_file("addr", 0200, skx_test, 775 + NULL, &fops_u64_wo)) { 776 + debugfs_remove(skx_test); 777 + skx_test = NULL; 778 + } 779 + } 780 + EXPORT_SYMBOL_GPL(skx_setup_debug); 781 + 782 + void skx_teardown_debug(void) 783 + { 784 + debugfs_remove_recursive(skx_test); 785 + } 786 + EXPORT_SYMBOL_GPL(skx_teardown_debug); 787 + #endif /*CONFIG_EDAC_DEBUG*/ 741 788 742 789 MODULE_LICENSE("GPL v2"); 743 790 MODULE_AUTHOR("Tony Luck");
+8
drivers/edac/skx_common.h
··· 260 260 261 261 void skx_remove(void); 262 262 263 + #ifdef CONFIG_EDAC_DEBUG 264 + void skx_setup_debug(const char *name); 265 + void skx_teardown_debug(void); 266 + #else 267 + static inline void skx_setup_debug(const char *name) {} 268 + static inline void skx_teardown_debug(void) {} 269 + #endif 270 + 263 271 #endif /* _SKX_COMM_EDAC_H */
+34 -1
drivers/edac/synopsys_edac.c
··· 10 10 #include <linux/module.h> 11 11 #include <linux/platform_device.h> 12 12 #include <linux/spinlock.h> 13 + #include <linux/sizes.h> 13 14 #include <linux/interrupt.h> 14 15 #include <linux/of.h> 15 16 ··· 338 337 * @get_mtype: Get mtype. 339 338 * @get_dtype: Get dtype. 340 339 * @get_ecc_state: Get ECC state. 340 + * @get_mem_info: Get EDAC memory info 341 341 * @quirks: To differentiate IPs. 342 342 */ 343 343 struct synps_platform_data { ··· 346 344 enum mem_type (*get_mtype)(const void __iomem *base); 347 345 enum dev_type (*get_dtype)(const void __iomem *base); 348 346 bool (*get_ecc_state)(void __iomem *base); 347 + #ifdef CONFIG_EDAC_DEBUG 348 + u64 (*get_mem_info)(struct synps_edac_priv *priv); 349 + #endif 349 350 int quirks; 350 351 }; 351 352 ··· 406 401 407 402 return 0; 408 403 } 404 + 405 + #ifdef CONFIG_EDAC_DEBUG 406 + /** 407 + * zynqmp_get_mem_info - Get the current memory info. 408 + * @priv: DDR memory controller private instance data. 409 + * 410 + * Return: host interface address. 411 + */ 412 + static u64 zynqmp_get_mem_info(struct synps_edac_priv *priv) 413 + { 414 + u64 hif_addr = 0, linear_addr; 415 + 416 + linear_addr = priv->poison_addr; 417 + if (linear_addr >= SZ_32G) 418 + linear_addr = linear_addr - SZ_32G + SZ_2G; 419 + hif_addr = linear_addr >> 3; 420 + return hif_addr; 421 + } 422 + #endif 409 423 410 424 /** 411 425 * zynqmp_get_error_info - Get the current ECC error info. ··· 946 922 .get_mtype = zynqmp_get_mtype, 947 923 .get_dtype = zynqmp_get_dtype, 948 924 .get_ecc_state = zynqmp_get_ecc_state, 925 + #ifdef CONFIG_EDAC_DEBUG 926 + .get_mem_info = zynqmp_get_mem_info, 927 + #endif 949 928 .quirks = (DDR_ECC_INTR_SUPPORT 950 929 #ifdef CONFIG_EDAC_DEBUG 951 930 | DDR_ECC_DATA_POISON_SUPPORT ··· 1002 975 static void ddr_poison_setup(struct synps_edac_priv *priv) 1003 976 { 1004 977 int col = 0, row = 0, bank = 0, bankgrp = 0, rank = 0, regval; 978 + const struct synps_platform_data *p_data; 1005 979 int index; 1006 980 ulong hif_addr = 0; 1007 981 1008 - hif_addr = priv->poison_addr >> 3; 982 + p_data = priv->p_data; 983 + 984 + if (p_data->get_mem_info) 985 + hif_addr = p_data->get_mem_info(priv); 986 + else 987 + hif_addr = priv->poison_addr >> 3; 1009 988 1010 989 for (index = 0; index < DDR_MAX_ROW_SHIFT; index++) { 1011 990 if (priv->row_shift[index])