22 #include <linux/module.h>
33 #define CPC925_EDAC_REVISION " Ver: 1.0.0"
34 #define CPC925_EDAC_MOD_STR "cpc925_edac"
36 #define cpc925_printk(level, fmt, arg...) \
37 edac_printk(level, "CPC925", fmt, ##arg)
39 #define cpc925_mc_printk(mci, level, fmt, arg...) \
40 edac_mc_chipset_printk(mci, level, "CPC925", fmt, ##arg)
46 #define CPC925_BITS_PER_REG 32
47 #define CPC925_BIT(nr) (1UL << (CPC925_BITS_PER_REG - 1 - nr))
53 #define CPC925_CPU_ERR_DEV "cpu"
54 #define CPC925_HT_LINK_DEV "htlink"
57 #define CPC925_REF_FREQ 0xFA69
58 #define CPC925_SCRUB_BLOCK_SIZE 64
59 #define CPC925_NR_CSROWS 8
72 #define REG_APIMASK_OFFSET 0x30070
93 #define APIMASK_ADI(n) CPC925_BIT(((n)+1))
98 #define REG_APIEXCP_OFFSET 0x30060
124 #define REG_MBCR_OFFSET 0x2190
125 #define MBCR_64BITCFG_SHIFT 23
126 #define MBCR_64BITCFG_MASK (1UL << MBCR_64BITCFG_SHIFT)
127 #define MBCR_64BITBUS_SHIFT 22
128 #define MBCR_64BITBUS_MASK (1UL << MBCR_64BITBUS_SHIFT)
133 #define REG_MBMR_OFFSET 0x21C0
134 #define MBMR_MODE_MAX_VALUE 0xF
135 #define MBMR_MODE_SHIFT 25
136 #define MBMR_MODE_MASK (MBMR_MODE_MAX_VALUE << MBMR_MODE_SHIFT)
137 #define MBMR_BBA_SHIFT 24
138 #define MBMR_BBA_MASK (1UL << MBMR_BBA_SHIFT)
143 #define REG_MBBAR_OFFSET 0x21D0
144 #define MBBAR_BBA_MAX_VALUE 0xFF
145 #define MBBAR_BBA_SHIFT 24
146 #define MBBAR_BBA_MASK (MBBAR_BBA_MAX_VALUE << MBBAR_BBA_SHIFT)
151 #define REG_MSCR_OFFSET 0x2400
152 #define MSCR_SCRUB_MOD_MASK 0xC0000000
153 #define MSCR_BACKGR_SCRUB 0x40000000
154 #define MSCR_SI_SHIFT 16
155 #define MSCR_SI_MAX_VALUE 0xFF
156 #define MSCR_SI_MASK (MSCR_SI_MAX_VALUE << MSCR_SI_SHIFT)
161 #define REG_MSRSR_OFFSET 0x2410
166 #define REG_MSRER_OFFSET 0x2420
171 #define REG_MSPR_OFFSET 0x2430
176 #define REG_MCCR_OFFSET 0x2440
184 #define REG_MCRER_OFFSET 0x2450
189 #define REG_MEAR_OFFSET 0x2460
190 #define MEAR_BCNT_MAX_VALUE 0x3
191 #define MEAR_BCNT_SHIFT 30
192 #define MEAR_BCNT_MASK (MEAR_BCNT_MAX_VALUE << MEAR_BCNT_SHIFT)
193 #define MEAR_RANK_MAX_VALUE 0x7
194 #define MEAR_RANK_SHIFT 27
195 #define MEAR_RANK_MASK (MEAR_RANK_MAX_VALUE << MEAR_RANK_SHIFT)
196 #define MEAR_COL_MAX_VALUE 0x7FF
197 #define MEAR_COL_SHIFT 16
198 #define MEAR_COL_MASK (MEAR_COL_MAX_VALUE << MEAR_COL_SHIFT)
199 #define MEAR_BANK_MAX_VALUE 0x3
200 #define MEAR_BANK_SHIFT 14
201 #define MEAR_BANK_MASK (MEAR_BANK_MAX_VALUE << MEAR_BANK_SHIFT)
202 #define MEAR_ROW_MASK 0x00003FFF
207 #define REG_MESR_OFFSET 0x2470
208 #define MESR_ECC_SYN_H_MASK 0xFF00
209 #define MESR_ECC_SYN_L_MASK 0x00FF
214 #define REG_MMCR_OFFSET 0x2500
225 #define REG_ERRCTRL_OFFSET 0x70140
246 #define REG_LINKCTRL_OFFSET 0x70110
257 #define REG_LINKERR_OFFSET 0x70120
270 #define REG_BRGCTRL_OFFSET 0x70300
300 const unsigned int *
reg, *reg_end;
311 reg_end = reg + len/4;
315 start = of_read_number(reg, aw);
317 size = of_read_number(reg, sw);
319 edac_dbg(1,
"start 0x%lx, size 0x%lx\n", start, size);
321 }
while (reg < reg_end);
335 unsigned long row_size,
nr_pages, last_nr_pages = 0;
337 get_total_mem(pdata);
339 for (index = 0; index < mci->
nr_csrows; index++) {
352 row_size = bba * (1
UL << 28);
449 unsigned long *pfn,
unsigned long *
offset,
int *csrow)
451 u32 bcnt, rank, col, bank, row;
464 #ifdef CONFIG_EDAC_DEBUG
465 if (mci->
csrows[rank]->first_page == 0) {
467 "non-populated csrow, broken hardware?\n");
477 for (i = 0; i < 11; i++) {
487 for (i = 0; i < 3; i++) {
493 for (i = 0; i < 3; i++) {
499 for (i = 0; i < 4; i++) {
505 for (i = 0; i < 3; i++) {
514 edac_dbg(0,
"ECC physical address 0x%lx\n", pa);
517 static int cpc925_mc_find_channel(
struct mem_ctl_info *mci,
u16 syndrome)
538 unsigned long pfn = 0, offset = 0;
552 cpc925_mc_get_pfn(mci, mear, &pfn, &offset, &csrow);
556 channel = cpc925_mc_find_channel(mci, syndrome);
558 pfn, offset, syndrome,
595 static u32 cpc925_cpu_mask_disabled(
void)
621 if (reg ==
NULL || *reg > 2) {
634 "Assuming PI id is equal to CPU MPIC id!\n");
637 of_node_put(cpunode);
651 cpumask = cpc925_cpu_mask_disabled();
652 if (apimask & cpumask) {
654 "but enabled in APIMASK, disabling\n");
693 if ((apiexcp & ~cpc925_cpu_mask_disabled()) == 0)
698 "Processor Interface register dump:\n");
744 "HT register dump:\n");
755 if (brgctrl & BRGCTRL_DETSERR)
759 if (linkctrl & HT_LINKCTRL_DETECTED)
772 if (linkerr & HT_LINKERR_DETECTED)
782 .init = cpc925_cpu_init,
783 .exit = cpc925_cpu_exit,
784 .check = cpc925_cpu_check,
788 .init = cpc925_htlink_init,
789 .exit = cpc925_htlink_exit,
790 .check = cpc925_htlink_check,
802 static void cpc925_add_edac_devices(
void __iomem *
vbase)
811 for (dev_info = &cpc925_devs[0]; dev_info->
init; dev_info++) {
813 dev_info->
pdev = platform_device_register_simple(
815 if (IS_ERR(dev_info->
pdev)) {
817 "Can't register platform device for %s\n",
839 dev_info->
edac_dev->dev_name = dev_name(&dev_info->
pdev->dev);
845 dev_info->
init(dev_info);
849 "Unable to add edac device for %s\n",
854 edac_dbg(0,
"Successfully added edac device for %s\n",
861 dev_info->
exit(dev_info);
872 static void cpc925_del_edac_devices(
void)
876 for (dev_info = &cpc925_devs[0]; dev_info->
init; dev_info++) {
884 dev_info->
exit(dev_info);
886 edac_dbg(0,
"Successfully deleted edac device for %s\n",
892 static int cpc925_get_sdram_scrub_rate(
struct mem_ctl_info *mci)
902 edac_dbg(0,
"Mem Scrub Ctrl Register 0x%x\n", mscr);
915 static int cpc925_mc_get_channels(
void __iomem *vbase)
930 edac_dbg(0,
"%s channel\n", (dual > 0) ?
"Dual" :
"Single");
937 static int edac_mc_idx;
943 int res = 0, nr_channels;
975 nr_channels = cpc925_mc_get_channels(vbase) + 1;
979 layers[0].is_virt_csrow =
true;
981 layers[1].size = nr_channels;
982 layers[1].is_virt_csrow =
false;
992 pdata->
vbase = vbase;
997 platform_set_drvdata(pdev, mci);
1014 cpc925_init_csrows(mci);
1017 cpc925_mc_init(mci);
1024 cpc925_add_edac_devices(vbase);
1033 cpc925_mc_exit(mci);
1051 cpc925_del_edac_devices();
1052 cpc925_mc_exit(mci);
1061 .probe = cpc925_probe,
1062 .remove = cpc925_remove,
1064 .name =
"cpc925_edac",
1068 static int __init cpc925_edac_init(
void)
1087 static void __exit cpc925_edac_exit(
void)