15 #include <linux/kernel.h>
17 #include <linux/module.h>
20 #include <linux/types.h>
111 #define EDAC_OPSTATE_INT_STR "interrupt"
112 #define EDAC_OPSTATE_POLL_STR "polled"
113 #define EDAC_OPSTATE_UNKNOWN_STR "unknown"
115 #define PPC4XX_EDAC_MODULE_NAME "ppc4xx_edac"
116 #define PPC4XX_EDAC_MODULE_REVISION "v1.0.0"
118 #define PPC4XX_EDAC_MESSAGE_SIZE 256
123 #define ppc4xx_edac_printk(level, fmt, arg...) \
124 edac_printk(level, "PPC4xx MC", fmt, ##arg)
129 #define ppc4xx_edac_mc_printk(level, mci, fmt, arg...) \
130 edac_mc_chipset_printk(mci, level, "PPC4xx", fmt, ##arg)
136 #define SDRAM_MBCF_SZ_MiB_MIN 4
137 #define SDRAM_MBCF_SZ_TO_MiB(n) (SDRAM_MBCF_SZ_MiB_MIN \
138 << (SDRAM_MBCF_SZ_DECODE(n)))
139 #define SDRAM_MBCF_SZ_TO_PAGES(n) (SDRAM_MBCF_SZ_MiB_MIN \
140 << (20 - PAGE_SHIFT + \
141 SDRAM_MBCF_SZ_DECODE(n)))
150 #define SDRAM_DCR_RESOURCE_LEN 2
151 #define SDRAM_DCR_ADDR_OFFSET 0
152 #define SDRAM_DCR_DATA_OFFSET 1
157 #define INTMAP_ECCDED_INDEX 0
158 #define INTMAP_ECCSEC_INDEX 1
198 .compatible =
"ibm,sdram-4xx-ddr2"
204 .probe = ppc4xx_edac_probe,
205 .remove = ppc4xx_edac_remove,
209 .of_match_table = ppc4xx_edac_match,
217 static const unsigned ppc4xx_edac_nr_csrows = 2;
218 static const unsigned ppc4xx_edac_nr_chans = 1;
224 static const char *
const ppc4xx_plb_masters[9] = {
247 mfsdram(
const dcr_host_t *dcr_host,
unsigned int idcr_n)
264 mtsdram(
const dcr_host_t *dcr_host,
unsigned int idcr_n,
u32 value)
322 unsigned int row,
rows;
326 if (n < 0 || n >= size)
333 for (rows = 0, row = 0; row < mci->
nr_csrows; row++) {
334 if (ppc4xx_edac_check_bank_error(status, row)) {
336 (rows++ ?
", " :
""), row);
338 if (n < 0 || n >= size)
347 n =
snprintf(buffer, size,
"%s; ", rows ?
"" :
"None");
349 if (n < 0 || n >= size)
378 ppc4xx_edac_generate_checkbit_message(
const struct mem_ctl_info *mci,
384 const char *ckber =
NULL;
415 return snprintf(buffer, size,
"Checkbit Error: %s", ckber);
436 ppc4xx_edac_generate_lane_message(
const struct mem_ctl_info *mci,
442 unsigned int lane,
lanes;
443 const unsigned int first_lane = 0;
444 const unsigned int lane_count = 16;
446 n =
snprintf(buffer, size,
"; Byte Lane Errors: ");
448 if (n < 0 || n >= size)
455 for (lanes = 0, lane = first_lane; lane < lane_count; lane++) {
459 (lanes++ ?
", " :
""), lane);
461 if (n < 0 || n >= size)
470 n =
snprintf(buffer, size,
"%s; ", lanes ?
"" :
"None");
472 if (n < 0 || n >= size)
501 ppc4xx_edac_generate_ecc_message(
const struct mem_ctl_info *mci,
508 n = ppc4xx_edac_generate_bank_message(mci, status, buffer, size);
510 if (n < 0 || n >= size)
517 n = ppc4xx_edac_generate_checkbit_message(mci, status, buffer, size);
519 if (n < 0 || n >= size)
526 n = ppc4xx_edac_generate_lane_message(mci, status, buffer, size);
528 if (n < 0 || n >= size)
557 ppc4xx_edac_generate_plb_message(
const struct mem_ctl_info *mci,
576 "%s error w/ PLB master %u \"%s\"; ",
577 (read ?
"Read" :
"Write"),
581 ppc4xx_plb_masters[master] :
"UNKNOWN"));
598 ppc4xx_edac_generate_message(
const struct mem_ctl_info *mci,
605 if (buffer ==
NULL || size == 0)
608 n = ppc4xx_edac_generate_ecc_message(mci, status, buffer, size);
610 if (n < 0 || n >= size)
616 ppc4xx_edac_generate_plb_message(mci, status, buffer, size);
636 ppc4xx_edac_generate_message(mci, status, message,
sizeof(message));
643 "\tBEAR: 0x%08x%08x\n"
726 ppc4xx_edac_generate_message(mci, status, message,
sizeof(message));
728 for (row = 0; row < mci->
nr_csrows; row++)
729 if (ppc4xx_edac_check_bank_error(status, row))
757 ppc4xx_edac_generate_message(mci, status, message,
sizeof(message));
759 for (row = 0; row < mci->
nr_csrows; row++)
760 if (ppc4xx_edac_check_bank_error(status, row))
781 static unsigned int count;
785 ppc4xx_ecc_get_status(mci, &status);
788 if (count++ % 30 == 0)
789 ppc4xx_ecc_dump_status(mci, &status);
793 ppc4xx_edac_handle_ue(mci, &status);
796 ppc4xx_edac_handle_ce(mci, &status);
798 ppc4xx_ecc_clear_status(mci, &status);
815 ppc4xx_edac_isr(
int irq,
void *
dev_id)
819 ppc4xx_edac_check(mci);
842 ppc4xx_edac_get_dtype(
u32 mcopt1)
866 ppc4xx_edac_get_mtype(
u32 mcopt1)
909 mtype = ppc4xx_edac_get_mtype(mcopt1);
910 dtype = ppc4xx_edac_get_dtype(mcopt1);
926 for (row = 0; row < mci->
nr_csrows; row++) {
960 "Unrecognized memory bank %d "
1017 const dcr_host_t *dcr_host,
1084 status = ppc4xx_edac_init_csrows(mci, mcopt1);
1088 "Failed to initialize rows!\n");
1112 int ded_irq, sec_irq;
1121 "Unable to map interrupts.\n");
1134 "Unable to request irq %d for ECC DED",
1148 "Unable to request irq %d for ECC SEC",
1157 pdata->
irqs.ded = ded_irq;
1158 pdata->
irqs.sec = sec_irq;
1187 ppc4xx_edac_map_dcrs(
const struct device_node *np, dcr_host_t *dcr_host)
1189 unsigned int dcr_base, dcr_len;
1191 if (np ==
NULL || dcr_host ==
NULL)
1199 if (dcr_base == 0 || dcr_len == 0) {
1201 "Failed to obtain DCR property.\n");
1207 "Unexpected DCR length %d, expected %d.\n",
1214 *dcr_host = dcr_map(np, dcr_base, dcr_len);
1216 if (!DCR_MAP_OK(*dcr_host)) {
1238 u32 mcopt1, memcheck;
1239 dcr_host_t dcr_host;
1243 static int ppc4xx_edac_instance;
1253 "Only the PPC405EX[r] is supported.\n");
1262 status = ppc4xx_edac_map_dcrs(np, &dcr_host);
1289 layers[0].size = ppc4xx_edac_nr_csrows;
1290 layers[0].is_virt_csrow =
true;
1292 layers[1].size = ppc4xx_edac_nr_chans;
1293 layers[1].is_virt_csrow =
false;
1298 "Failed to allocate EDAC MC instance!\n",
1304 status = ppc4xx_edac_mc_init(mci, op, &dcr_host, mcopt1);
1308 "Failed to initialize instance!\n");
1320 "Failed to add instance!\n");
1326 status = ppc4xx_edac_register_irq(op, mci);
1332 ppc4xx_edac_instance++;
1386 static inline void __init
1387 ppc4xx_edac_opstate_init(
void)
1415 ppc4xx_edac_init(
void)
1419 ppc4xx_edac_opstate_init();
1432 ppc4xx_edac_exit(
void)