2 * Freescale MPC85xx Memory Controller kenel module
4 * Author: Dave Jiang <djiang@mvista.com>
6 * 2006-2007 (c) MontaVista Software, Inc. This file is licensed under
7 * the terms of the GNU General Public License version 2. This program
8 * is licensed "as is" without any warranty of any kind, whether express
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/slab.h>
15 #include <linux/interrupt.h>
16 #include <linux/ctype.h>
18 #include <linux/mod_devicetable.h>
19 #include <linux/edac.h>
21 #include <linux/of_platform.h>
22 #include <linux/of_device.h>
23 #include "edac_module.h"
24 #include "edac_core.h"
25 #include "mpc85xx_edac.h"
27 static int edac_dev_idx
;
28 static int edac_pci_idx
;
29 static int edac_mc_idx
;
31 static u32 orig_ddr_err_disable
;
32 static u32 orig_ddr_err_sbe
;
38 static u32 orig_pci_err_cap_dr
;
39 static u32 orig_pci_err_en
;
42 static u32 orig_l2_err_disable
;
45 /************************ MC SYSFS parts ***********************************/
47 static ssize_t
mpc85xx_mc_inject_data_hi_show(struct mem_ctl_info
*mci
,
50 struct mpc85xx_mc_pdata
*pdata
= mci
->pvt_info
;
51 return sprintf(data
, "0x%08x",
52 in_be32(pdata
->mc_vbase
+
53 MPC85XX_MC_DATA_ERR_INJECT_HI
));
56 static ssize_t
mpc85xx_mc_inject_data_lo_show(struct mem_ctl_info
*mci
,
59 struct mpc85xx_mc_pdata
*pdata
= mci
->pvt_info
;
60 return sprintf(data
, "0x%08x",
61 in_be32(pdata
->mc_vbase
+
62 MPC85XX_MC_DATA_ERR_INJECT_LO
));
65 static ssize_t
mpc85xx_mc_inject_ctrl_show(struct mem_ctl_info
*mci
, char *data
)
67 struct mpc85xx_mc_pdata
*pdata
= mci
->pvt_info
;
68 return sprintf(data
, "0x%08x",
69 in_be32(pdata
->mc_vbase
+ MPC85XX_MC_ECC_ERR_INJECT
));
72 static ssize_t
mpc85xx_mc_inject_data_hi_store(struct mem_ctl_info
*mci
,
73 const char *data
, size_t count
)
75 struct mpc85xx_mc_pdata
*pdata
= mci
->pvt_info
;
77 out_be32(pdata
->mc_vbase
+ MPC85XX_MC_DATA_ERR_INJECT_HI
,
78 simple_strtoul(data
, NULL
, 0));
84 static ssize_t
mpc85xx_mc_inject_data_lo_store(struct mem_ctl_info
*mci
,
85 const char *data
, size_t count
)
87 struct mpc85xx_mc_pdata
*pdata
= mci
->pvt_info
;
89 out_be32(pdata
->mc_vbase
+ MPC85XX_MC_DATA_ERR_INJECT_LO
,
90 simple_strtoul(data
, NULL
, 0));
96 static ssize_t
mpc85xx_mc_inject_ctrl_store(struct mem_ctl_info
*mci
,
97 const char *data
, size_t count
)
99 struct mpc85xx_mc_pdata
*pdata
= mci
->pvt_info
;
100 if (isdigit(*data
)) {
101 out_be32(pdata
->mc_vbase
+ MPC85XX_MC_ECC_ERR_INJECT
,
102 simple_strtoul(data
, NULL
, 0));
108 static struct mcidev_sysfs_attribute mpc85xx_mc_sysfs_attributes
[] = {
111 .name
= "inject_data_hi",
112 .mode
= (S_IRUGO
| S_IWUSR
)
114 .show
= mpc85xx_mc_inject_data_hi_show
,
115 .store
= mpc85xx_mc_inject_data_hi_store
},
118 .name
= "inject_data_lo",
119 .mode
= (S_IRUGO
| S_IWUSR
)
121 .show
= mpc85xx_mc_inject_data_lo_show
,
122 .store
= mpc85xx_mc_inject_data_lo_store
},
125 .name
= "inject_ctrl",
126 .mode
= (S_IRUGO
| S_IWUSR
)
128 .show
= mpc85xx_mc_inject_ctrl_show
,
129 .store
= mpc85xx_mc_inject_ctrl_store
},
133 .attr
= {.name
= NULL
}
137 static void mpc85xx_set_mc_sysfs_attributes(struct mem_ctl_info
*mci
)
139 mci
->mc_driver_sysfs_attributes
= mpc85xx_mc_sysfs_attributes
;
142 /**************************** PCI Err device ***************************/
145 static void mpc85xx_pci_check(struct edac_pci_ctl_info
*pci
)
147 struct mpc85xx_pci_pdata
*pdata
= pci
->pvt_info
;
150 err_detect
= in_be32(pdata
->pci_vbase
+ MPC85XX_PCI_ERR_DR
);
152 /* master aborts can happen during PCI config cycles */
153 if (!(err_detect
& ~(PCI_EDE_MULTI_ERR
| PCI_EDE_MST_ABRT
))) {
154 out_be32(pdata
->pci_vbase
+ MPC85XX_PCI_ERR_DR
, err_detect
);
158 printk(KERN_ERR
"PCI error(s) detected\n");
159 printk(KERN_ERR
"PCI/X ERR_DR register: %#08x\n", err_detect
);
161 printk(KERN_ERR
"PCI/X ERR_ATTRIB register: %#08x\n",
162 in_be32(pdata
->pci_vbase
+ MPC85XX_PCI_ERR_ATTRIB
));
163 printk(KERN_ERR
"PCI/X ERR_ADDR register: %#08x\n",
164 in_be32(pdata
->pci_vbase
+ MPC85XX_PCI_ERR_ADDR
));
165 printk(KERN_ERR
"PCI/X ERR_EXT_ADDR register: %#08x\n",
166 in_be32(pdata
->pci_vbase
+ MPC85XX_PCI_ERR_EXT_ADDR
));
167 printk(KERN_ERR
"PCI/X ERR_DL register: %#08x\n",
168 in_be32(pdata
->pci_vbase
+ MPC85XX_PCI_ERR_DL
));
169 printk(KERN_ERR
"PCI/X ERR_DH register: %#08x\n",
170 in_be32(pdata
->pci_vbase
+ MPC85XX_PCI_ERR_DH
));
172 /* clear error bits */
173 out_be32(pdata
->pci_vbase
+ MPC85XX_PCI_ERR_DR
, err_detect
);
175 if (err_detect
& PCI_EDE_PERR_MASK
)
176 edac_pci_handle_pe(pci
, pci
->ctl_name
);
178 if ((err_detect
& ~PCI_EDE_MULTI_ERR
) & ~PCI_EDE_PERR_MASK
)
179 edac_pci_handle_npe(pci
, pci
->ctl_name
);
182 static irqreturn_t
mpc85xx_pci_isr(int irq
, void *dev_id
)
184 struct edac_pci_ctl_info
*pci
= dev_id
;
185 struct mpc85xx_pci_pdata
*pdata
= pci
->pvt_info
;
188 err_detect
= in_be32(pdata
->pci_vbase
+ MPC85XX_PCI_ERR_DR
);
193 mpc85xx_pci_check(pci
);
198 static int __devinit
mpc85xx_pci_err_probe(struct of_device
*op
,
199 const struct of_device_id
*match
)
201 struct edac_pci_ctl_info
*pci
;
202 struct mpc85xx_pci_pdata
*pdata
;
206 if (!devres_open_group(&op
->dev
, mpc85xx_pci_err_probe
, GFP_KERNEL
))
209 pci
= edac_pci_alloc_ctl_info(sizeof(*pdata
), "mpc85xx_pci_err");
213 pdata
= pci
->pvt_info
;
214 pdata
->name
= "mpc85xx_pci_err";
216 dev_set_drvdata(&op
->dev
, pci
);
218 pci
->mod_name
= EDAC_MOD_STR
;
219 pci
->ctl_name
= pdata
->name
;
220 pci
->dev_name
= op
->dev
.bus_id
;
222 if (edac_op_state
== EDAC_OPSTATE_POLL
)
223 pci
->edac_check
= mpc85xx_pci_check
;
225 pdata
->edac_idx
= edac_pci_idx
++;
227 res
= of_address_to_resource(op
->node
, 0, &r
);
229 printk(KERN_ERR
"%s: Unable to get resource for "
230 "PCI err regs\n", __func__
);
234 /* we only need the error registers */
237 if (!devm_request_mem_region(&op
->dev
, r
.start
,
238 r
.end
- r
.start
+ 1, pdata
->name
)) {
239 printk(KERN_ERR
"%s: Error while requesting mem region\n",
245 pdata
->pci_vbase
= devm_ioremap(&op
->dev
, r
.start
,
246 r
.end
- r
.start
+ 1);
247 if (!pdata
->pci_vbase
) {
248 printk(KERN_ERR
"%s: Unable to setup PCI err regs\n", __func__
);
253 orig_pci_err_cap_dr
=
254 in_be32(pdata
->pci_vbase
+ MPC85XX_PCI_ERR_CAP_DR
);
256 /* PCI master abort is expected during config cycles */
257 out_be32(pdata
->pci_vbase
+ MPC85XX_PCI_ERR_CAP_DR
, 0x40);
259 orig_pci_err_en
= in_be32(pdata
->pci_vbase
+ MPC85XX_PCI_ERR_EN
);
261 /* disable master abort reporting */
262 out_be32(pdata
->pci_vbase
+ MPC85XX_PCI_ERR_EN
, ~0x40);
264 /* clear error bits */
265 out_be32(pdata
->pci_vbase
+ MPC85XX_PCI_ERR_DR
, ~0);
267 if (edac_pci_add_device(pci
, pdata
->edac_idx
) > 0) {
268 debugf3("%s(): failed edac_pci_add_device()\n", __func__
);
272 if (edac_op_state
== EDAC_OPSTATE_INT
) {
273 pdata
->irq
= irq_of_parse_and_map(op
->node
, 0);
274 res
= devm_request_irq(&op
->dev
, pdata
->irq
,
275 mpc85xx_pci_isr
, IRQF_DISABLED
,
276 "[EDAC] PCI err", pci
);
279 "%s: Unable to requiest irq %d for "
280 "MPC85xx PCI err\n", __func__
, pdata
->irq
);
281 irq_dispose_mapping(pdata
->irq
);
286 printk(KERN_INFO EDAC_MOD_STR
" acquired irq %d for PCI Err\n",
290 devres_remove_group(&op
->dev
, mpc85xx_pci_err_probe
);
291 debugf3("%s(): success\n", __func__
);
292 printk(KERN_INFO EDAC_MOD_STR
" PCI err registered\n");
297 edac_pci_del_device(&op
->dev
);
299 edac_pci_free_ctl_info(pci
);
300 devres_release_group(&op
->dev
, mpc85xx_pci_err_probe
);
304 static int mpc85xx_pci_err_remove(struct of_device
*op
)
306 struct edac_pci_ctl_info
*pci
= dev_get_drvdata(&op
->dev
);
307 struct mpc85xx_pci_pdata
*pdata
= pci
->pvt_info
;
309 debugf0("%s()\n", __func__
);
311 out_be32(pdata
->pci_vbase
+ MPC85XX_PCI_ERR_CAP_DR
,
312 orig_pci_err_cap_dr
);
314 out_be32(pdata
->pci_vbase
+ MPC85XX_PCI_ERR_EN
, orig_pci_err_en
);
316 edac_pci_del_device(pci
->dev
);
318 if (edac_op_state
== EDAC_OPSTATE_INT
)
319 irq_dispose_mapping(pdata
->irq
);
321 edac_pci_free_ctl_info(pci
);
326 static struct of_device_id mpc85xx_pci_err_of_match
[] = {
328 .compatible
= "fsl,mpc8540-pcix",
331 .compatible
= "fsl,mpc8540-pci",
336 static struct of_platform_driver mpc85xx_pci_err_driver
= {
337 .owner
= THIS_MODULE
,
338 .name
= "mpc85xx_pci_err",
339 .match_table
= mpc85xx_pci_err_of_match
,
340 .probe
= mpc85xx_pci_err_probe
,
341 .remove
= __devexit_p(mpc85xx_pci_err_remove
),
343 .name
= "mpc85xx_pci_err",
344 .owner
= THIS_MODULE
,
348 #endif /* CONFIG_PCI */
350 /**************************** L2 Err device ***************************/
352 /************************ L2 SYSFS parts ***********************************/
354 static ssize_t
mpc85xx_l2_inject_data_hi_show(struct edac_device_ctl_info
355 *edac_dev
, char *data
)
357 struct mpc85xx_l2_pdata
*pdata
= edac_dev
->pvt_info
;
358 return sprintf(data
, "0x%08x",
359 in_be32(pdata
->l2_vbase
+ MPC85XX_L2_ERRINJHI
));
362 static ssize_t
mpc85xx_l2_inject_data_lo_show(struct edac_device_ctl_info
363 *edac_dev
, char *data
)
365 struct mpc85xx_l2_pdata
*pdata
= edac_dev
->pvt_info
;
366 return sprintf(data
, "0x%08x",
367 in_be32(pdata
->l2_vbase
+ MPC85XX_L2_ERRINJLO
));
370 static ssize_t
mpc85xx_l2_inject_ctrl_show(struct edac_device_ctl_info
371 *edac_dev
, char *data
)
373 struct mpc85xx_l2_pdata
*pdata
= edac_dev
->pvt_info
;
374 return sprintf(data
, "0x%08x",
375 in_be32(pdata
->l2_vbase
+ MPC85XX_L2_ERRINJCTL
));
378 static ssize_t
mpc85xx_l2_inject_data_hi_store(struct edac_device_ctl_info
379 *edac_dev
, const char *data
,
382 struct mpc85xx_l2_pdata
*pdata
= edac_dev
->pvt_info
;
383 if (isdigit(*data
)) {
384 out_be32(pdata
->l2_vbase
+ MPC85XX_L2_ERRINJHI
,
385 simple_strtoul(data
, NULL
, 0));
391 static ssize_t
mpc85xx_l2_inject_data_lo_store(struct edac_device_ctl_info
392 *edac_dev
, const char *data
,
395 struct mpc85xx_l2_pdata
*pdata
= edac_dev
->pvt_info
;
396 if (isdigit(*data
)) {
397 out_be32(pdata
->l2_vbase
+ MPC85XX_L2_ERRINJLO
,
398 simple_strtoul(data
, NULL
, 0));
404 static ssize_t
mpc85xx_l2_inject_ctrl_store(struct edac_device_ctl_info
405 *edac_dev
, const char *data
,
408 struct mpc85xx_l2_pdata
*pdata
= edac_dev
->pvt_info
;
409 if (isdigit(*data
)) {
410 out_be32(pdata
->l2_vbase
+ MPC85XX_L2_ERRINJCTL
,
411 simple_strtoul(data
, NULL
, 0));
417 static struct edac_dev_sysfs_attribute mpc85xx_l2_sysfs_attributes
[] = {
420 .name
= "inject_data_hi",
421 .mode
= (S_IRUGO
| S_IWUSR
)
423 .show
= mpc85xx_l2_inject_data_hi_show
,
424 .store
= mpc85xx_l2_inject_data_hi_store
},
427 .name
= "inject_data_lo",
428 .mode
= (S_IRUGO
| S_IWUSR
)
430 .show
= mpc85xx_l2_inject_data_lo_show
,
431 .store
= mpc85xx_l2_inject_data_lo_store
},
434 .name
= "inject_ctrl",
435 .mode
= (S_IRUGO
| S_IWUSR
)
437 .show
= mpc85xx_l2_inject_ctrl_show
,
438 .store
= mpc85xx_l2_inject_ctrl_store
},
442 .attr
= {.name
= NULL
}
446 static void mpc85xx_set_l2_sysfs_attributes(struct edac_device_ctl_info
449 edac_dev
->sysfs_attributes
= mpc85xx_l2_sysfs_attributes
;
452 /***************************** L2 ops ***********************************/
454 static void mpc85xx_l2_check(struct edac_device_ctl_info
*edac_dev
)
456 struct mpc85xx_l2_pdata
*pdata
= edac_dev
->pvt_info
;
459 err_detect
= in_be32(pdata
->l2_vbase
+ MPC85XX_L2_ERRDET
);
461 if (!(err_detect
& L2_EDE_MASK
))
464 printk(KERN_ERR
"ECC Error in CPU L2 cache\n");
465 printk(KERN_ERR
"L2 Error Detect Register: 0x%08x\n", err_detect
);
466 printk(KERN_ERR
"L2 Error Capture Data High Register: 0x%08x\n",
467 in_be32(pdata
->l2_vbase
+ MPC85XX_L2_CAPTDATAHI
));
468 printk(KERN_ERR
"L2 Error Capture Data Lo Register: 0x%08x\n",
469 in_be32(pdata
->l2_vbase
+ MPC85XX_L2_CAPTDATALO
));
470 printk(KERN_ERR
"L2 Error Syndrome Register: 0x%08x\n",
471 in_be32(pdata
->l2_vbase
+ MPC85XX_L2_CAPTECC
));
472 printk(KERN_ERR
"L2 Error Attributes Capture Register: 0x%08x\n",
473 in_be32(pdata
->l2_vbase
+ MPC85XX_L2_ERRATTR
));
474 printk(KERN_ERR
"L2 Error Address Capture Register: 0x%08x\n",
475 in_be32(pdata
->l2_vbase
+ MPC85XX_L2_ERRADDR
));
477 /* clear error detect register */
478 out_be32(pdata
->l2_vbase
+ MPC85XX_L2_ERRDET
, err_detect
);
480 if (err_detect
& L2_EDE_CE_MASK
)
481 edac_device_handle_ce(edac_dev
, 0, 0, edac_dev
->ctl_name
);
483 if (err_detect
& L2_EDE_UE_MASK
)
484 edac_device_handle_ue(edac_dev
, 0, 0, edac_dev
->ctl_name
);
487 static irqreturn_t
mpc85xx_l2_isr(int irq
, void *dev_id
)
489 struct edac_device_ctl_info
*edac_dev
= dev_id
;
490 struct mpc85xx_l2_pdata
*pdata
= edac_dev
->pvt_info
;
493 err_detect
= in_be32(pdata
->l2_vbase
+ MPC85XX_L2_ERRDET
);
495 if (!(err_detect
& L2_EDE_MASK
))
498 mpc85xx_l2_check(edac_dev
);
503 static int __devinit
mpc85xx_l2_err_probe(struct of_device
*op
,
504 const struct of_device_id
*match
)
506 struct edac_device_ctl_info
*edac_dev
;
507 struct mpc85xx_l2_pdata
*pdata
;
511 if (!devres_open_group(&op
->dev
, mpc85xx_l2_err_probe
, GFP_KERNEL
))
514 edac_dev
= edac_device_alloc_ctl_info(sizeof(*pdata
),
515 "cpu", 1, "L", 1, 2, NULL
, 0,
518 devres_release_group(&op
->dev
, mpc85xx_l2_err_probe
);
522 pdata
= edac_dev
->pvt_info
;
523 pdata
->name
= "mpc85xx_l2_err";
525 edac_dev
->dev
= &op
->dev
;
526 dev_set_drvdata(edac_dev
->dev
, edac_dev
);
527 edac_dev
->ctl_name
= pdata
->name
;
528 edac_dev
->dev_name
= pdata
->name
;
530 res
= of_address_to_resource(op
->node
, 0, &r
);
532 printk(KERN_ERR
"%s: Unable to get resource for "
533 "L2 err regs\n", __func__
);
537 /* we only need the error registers */
540 if (!devm_request_mem_region(&op
->dev
, r
.start
,
541 r
.end
- r
.start
+ 1, pdata
->name
)) {
542 printk(KERN_ERR
"%s: Error while requesting mem region\n",
548 pdata
->l2_vbase
= devm_ioremap(&op
->dev
, r
.start
, r
.end
- r
.start
+ 1);
549 if (!pdata
->l2_vbase
) {
550 printk(KERN_ERR
"%s: Unable to setup L2 err regs\n", __func__
);
555 out_be32(pdata
->l2_vbase
+ MPC85XX_L2_ERRDET
, ~0);
557 orig_l2_err_disable
= in_be32(pdata
->l2_vbase
+ MPC85XX_L2_ERRDIS
);
559 /* clear the err_dis */
560 out_be32(pdata
->l2_vbase
+ MPC85XX_L2_ERRDIS
, 0);
562 edac_dev
->mod_name
= EDAC_MOD_STR
;
564 if (edac_op_state
== EDAC_OPSTATE_POLL
)
565 edac_dev
->edac_check
= mpc85xx_l2_check
;
567 mpc85xx_set_l2_sysfs_attributes(edac_dev
);
569 pdata
->edac_idx
= edac_dev_idx
++;
571 if (edac_device_add_device(edac_dev
) > 0) {
572 debugf3("%s(): failed edac_device_add_device()\n", __func__
);
576 if (edac_op_state
== EDAC_OPSTATE_INT
) {
577 pdata
->irq
= irq_of_parse_and_map(op
->node
, 0);
578 res
= devm_request_irq(&op
->dev
, pdata
->irq
,
579 mpc85xx_l2_isr
, IRQF_DISABLED
,
580 "[EDAC] L2 err", edac_dev
);
583 "%s: Unable to requiest irq %d for "
584 "MPC85xx L2 err\n", __func__
, pdata
->irq
);
585 irq_dispose_mapping(pdata
->irq
);
590 printk(KERN_INFO EDAC_MOD_STR
" acquired irq %d for L2 Err\n",
593 edac_dev
->op_state
= OP_RUNNING_INTERRUPT
;
595 out_be32(pdata
->l2_vbase
+ MPC85XX_L2_ERRINTEN
, L2_EIE_MASK
);
598 devres_remove_group(&op
->dev
, mpc85xx_l2_err_probe
);
600 debugf3("%s(): success\n", __func__
);
601 printk(KERN_INFO EDAC_MOD_STR
" L2 err registered\n");
606 edac_device_del_device(&op
->dev
);
608 devres_release_group(&op
->dev
, mpc85xx_l2_err_probe
);
609 edac_device_free_ctl_info(edac_dev
);
613 static int mpc85xx_l2_err_remove(struct of_device
*op
)
615 struct edac_device_ctl_info
*edac_dev
= dev_get_drvdata(&op
->dev
);
616 struct mpc85xx_l2_pdata
*pdata
= edac_dev
->pvt_info
;
618 debugf0("%s()\n", __func__
);
620 if (edac_op_state
== EDAC_OPSTATE_INT
) {
621 out_be32(pdata
->l2_vbase
+ MPC85XX_L2_ERRINTEN
, 0);
622 irq_dispose_mapping(pdata
->irq
);
625 out_be32(pdata
->l2_vbase
+ MPC85XX_L2_ERRDIS
, orig_l2_err_disable
);
626 edac_device_del_device(&op
->dev
);
627 edac_device_free_ctl_info(edac_dev
);
631 static struct of_device_id mpc85xx_l2_err_of_match
[] = {
633 .compatible
= "fsl,8540-l2-cache-controller",
636 .compatible
= "fsl,8541-l2-cache-controller",
639 .compatible
= "fsl,8544-l2-cache-controller",
642 .compatible
= "fsl,8548-l2-cache-controller",
645 .compatible
= "fsl,8555-l2-cache-controller",
648 .compatible
= "fsl,8568-l2-cache-controller",
653 static struct of_platform_driver mpc85xx_l2_err_driver
= {
654 .owner
= THIS_MODULE
,
655 .name
= "mpc85xx_l2_err",
656 .match_table
= mpc85xx_l2_err_of_match
,
657 .probe
= mpc85xx_l2_err_probe
,
658 .remove
= mpc85xx_l2_err_remove
,
660 .name
= "mpc85xx_l2_err",
661 .owner
= THIS_MODULE
,
665 /**************************** MC Err device ***************************/
667 static void mpc85xx_mc_check(struct mem_ctl_info
*mci
)
669 struct mpc85xx_mc_pdata
*pdata
= mci
->pvt_info
;
670 struct csrow_info
*csrow
;
677 err_detect
= in_be32(pdata
->mc_vbase
+ MPC85XX_MC_ERR_DETECT
);
681 mpc85xx_mc_printk(mci
, KERN_ERR
, "Err Detect Register: %#8.8x\n",
684 /* no more processing if not ECC bit errors */
685 if (!(err_detect
& (DDR_EDE_SBE
| DDR_EDE_MBE
))) {
686 out_be32(pdata
->mc_vbase
+ MPC85XX_MC_ERR_DETECT
, err_detect
);
690 syndrome
= in_be32(pdata
->mc_vbase
+ MPC85XX_MC_CAPTURE_ECC
);
691 err_addr
= in_be32(pdata
->mc_vbase
+ MPC85XX_MC_CAPTURE_ADDRESS
);
692 pfn
= err_addr
>> PAGE_SHIFT
;
694 for (row_index
= 0; row_index
< mci
->nr_csrows
; row_index
++) {
695 csrow
= &mci
->csrows
[row_index
];
696 if ((pfn
>= csrow
->first_page
) && (pfn
<= csrow
->last_page
))
700 mpc85xx_mc_printk(mci
, KERN_ERR
, "Capture Data High: %#8.8x\n",
701 in_be32(pdata
->mc_vbase
+
702 MPC85XX_MC_CAPTURE_DATA_HI
));
703 mpc85xx_mc_printk(mci
, KERN_ERR
, "Capture Data Low: %#8.8x\n",
704 in_be32(pdata
->mc_vbase
+
705 MPC85XX_MC_CAPTURE_DATA_LO
));
706 mpc85xx_mc_printk(mci
, KERN_ERR
, "syndrome: %#8.8x\n", syndrome
);
707 mpc85xx_mc_printk(mci
, KERN_ERR
, "err addr: %#8.8x\n", err_addr
);
708 mpc85xx_mc_printk(mci
, KERN_ERR
, "PFN: %#8.8x\n", pfn
);
710 /* we are out of range */
711 if (row_index
== mci
->nr_csrows
)
712 mpc85xx_mc_printk(mci
, KERN_ERR
, "PFN out of range!\n");
714 if (err_detect
& DDR_EDE_SBE
)
715 edac_mc_handle_ce(mci
, pfn
, err_addr
& PAGE_MASK
,
716 syndrome
, row_index
, 0, mci
->ctl_name
);
718 if (err_detect
& DDR_EDE_MBE
)
719 edac_mc_handle_ue(mci
, pfn
, err_addr
& PAGE_MASK
,
720 row_index
, mci
->ctl_name
);
722 out_be32(pdata
->mc_vbase
+ MPC85XX_MC_ERR_DETECT
, err_detect
);
725 static irqreturn_t
mpc85xx_mc_isr(int irq
, void *dev_id
)
727 struct mem_ctl_info
*mci
= dev_id
;
728 struct mpc85xx_mc_pdata
*pdata
= mci
->pvt_info
;
731 err_detect
= in_be32(pdata
->mc_vbase
+ MPC85XX_MC_ERR_DETECT
);
735 mpc85xx_mc_check(mci
);
740 static void __devinit
mpc85xx_init_csrows(struct mem_ctl_info
*mci
)
742 struct mpc85xx_mc_pdata
*pdata
= mci
->pvt_info
;
743 struct csrow_info
*csrow
;
750 sdram_ctl
= in_be32(pdata
->mc_vbase
+ MPC85XX_MC_DDR_SDRAM_CFG
);
752 sdtype
= sdram_ctl
& DSC_SDTYPE_MASK
;
753 if (sdram_ctl
& DSC_RD_EN
) {
758 case DSC_SDTYPE_DDR2
:
770 case DSC_SDTYPE_DDR2
:
779 for (index
= 0; index
< mci
->nr_csrows
; index
++) {
783 csrow
= &mci
->csrows
[index
];
784 cs_bnds
= in_be32(pdata
->mc_vbase
+ MPC85XX_MC_CS_BNDS_0
+
785 (index
* MPC85XX_MC_CS_BNDS_OFS
));
786 start
= (cs_bnds
& 0xfff0000) << 4;
787 end
= ((cs_bnds
& 0xfff) << 20);
794 continue; /* not populated */
796 csrow
->first_page
= start
>> PAGE_SHIFT
;
797 csrow
->last_page
= end
>> PAGE_SHIFT
;
798 csrow
->nr_pages
= csrow
->last_page
+ 1 - csrow
->first_page
;
800 csrow
->mtype
= mtype
;
801 csrow
->dtype
= DEV_UNKNOWN
;
802 if (sdram_ctl
& DSC_X32_EN
)
803 csrow
->dtype
= DEV_X32
;
804 csrow
->edac_mode
= EDAC_SECDED
;
808 static int __devinit
mpc85xx_mc_err_probe(struct of_device
*op
,
809 const struct of_device_id
*match
)
811 struct mem_ctl_info
*mci
;
812 struct mpc85xx_mc_pdata
*pdata
;
817 if (!devres_open_group(&op
->dev
, mpc85xx_mc_err_probe
, GFP_KERNEL
))
820 mci
= edac_mc_alloc(sizeof(*pdata
), 4, 1, edac_mc_idx
);
822 devres_release_group(&op
->dev
, mpc85xx_mc_err_probe
);
826 pdata
= mci
->pvt_info
;
827 pdata
->name
= "mpc85xx_mc_err";
830 pdata
->edac_idx
= edac_mc_idx
++;
831 dev_set_drvdata(mci
->dev
, mci
);
832 mci
->ctl_name
= pdata
->name
;
833 mci
->dev_name
= pdata
->name
;
835 res
= of_address_to_resource(op
->node
, 0, &r
);
837 printk(KERN_ERR
"%s: Unable to get resource for MC err regs\n",
842 if (!devm_request_mem_region(&op
->dev
, r
.start
,
843 r
.end
- r
.start
+ 1, pdata
->name
)) {
844 printk(KERN_ERR
"%s: Error while requesting mem region\n",
850 pdata
->mc_vbase
= devm_ioremap(&op
->dev
, r
.start
, r
.end
- r
.start
+ 1);
851 if (!pdata
->mc_vbase
) {
852 printk(KERN_ERR
"%s: Unable to setup MC err regs\n", __func__
);
857 sdram_ctl
= in_be32(pdata
->mc_vbase
+ MPC85XX_MC_DDR_SDRAM_CFG
);
858 if (!(sdram_ctl
& DSC_ECC_EN
)) {
860 printk(KERN_WARNING
"%s: No ECC DIMMs discovered\n", __func__
);
865 debugf3("%s(): init mci\n", __func__
);
866 mci
->mtype_cap
= MEM_FLAG_RDDR
| MEM_FLAG_RDDR2
|
867 MEM_FLAG_DDR
| MEM_FLAG_DDR2
;
868 mci
->edac_ctl_cap
= EDAC_FLAG_NONE
| EDAC_FLAG_SECDED
;
869 mci
->edac_cap
= EDAC_FLAG_SECDED
;
870 mci
->mod_name
= EDAC_MOD_STR
;
871 mci
->mod_ver
= MPC85XX_REVISION
;
873 if (edac_op_state
== EDAC_OPSTATE_POLL
)
874 mci
->edac_check
= mpc85xx_mc_check
;
876 mci
->ctl_page_to_phys
= NULL
;
878 mci
->scrub_mode
= SCRUB_SW_SRC
;
880 mpc85xx_set_mc_sysfs_attributes(mci
);
882 mpc85xx_init_csrows(mci
);
884 #ifdef CONFIG_EDAC_DEBUG
885 edac_mc_register_mcidev_debug((struct attribute
**)debug_attr
);
888 /* store the original error disable bits */
889 orig_ddr_err_disable
=
890 in_be32(pdata
->mc_vbase
+ MPC85XX_MC_ERR_DISABLE
);
891 out_be32(pdata
->mc_vbase
+ MPC85XX_MC_ERR_DISABLE
, 0);
893 /* clear all error bits */
894 out_be32(pdata
->mc_vbase
+ MPC85XX_MC_ERR_DETECT
, ~0);
896 if (edac_mc_add_mc(mci
)) {
897 debugf3("%s(): failed edac_mc_add_mc()\n", __func__
);
901 if (edac_op_state
== EDAC_OPSTATE_INT
) {
902 out_be32(pdata
->mc_vbase
+ MPC85XX_MC_ERR_INT_EN
,
903 DDR_EIE_MBEE
| DDR_EIE_SBEE
);
905 /* store the original error management threshold */
906 orig_ddr_err_sbe
= in_be32(pdata
->mc_vbase
+
907 MPC85XX_MC_ERR_SBE
) & 0xff0000;
909 /* set threshold to 1 error per interrupt */
910 out_be32(pdata
->mc_vbase
+ MPC85XX_MC_ERR_SBE
, 0x10000);
912 /* register interrupts */
913 pdata
->irq
= irq_of_parse_and_map(op
->node
, 0);
914 res
= devm_request_irq(&op
->dev
, pdata
->irq
,
915 mpc85xx_mc_isr
, IRQF_DISABLED
,
916 "[EDAC] MC err", mci
);
918 printk(KERN_ERR
"%s: Unable to request irq %d for "
919 "MPC85xx DRAM ERR\n", __func__
, pdata
->irq
);
920 irq_dispose_mapping(pdata
->irq
);
925 printk(KERN_INFO EDAC_MOD_STR
" acquired irq %d for MC\n",
929 devres_remove_group(&op
->dev
, mpc85xx_mc_err_probe
);
930 debugf3("%s(): success\n", __func__
);
931 printk(KERN_INFO EDAC_MOD_STR
" MC err registered\n");
936 edac_mc_del_mc(&op
->dev
);
938 devres_release_group(&op
->dev
, mpc85xx_mc_err_probe
);
943 static int mpc85xx_mc_err_remove(struct of_device
*op
)
945 struct mem_ctl_info
*mci
= dev_get_drvdata(&op
->dev
);
946 struct mpc85xx_mc_pdata
*pdata
= mci
->pvt_info
;
948 debugf0("%s()\n", __func__
);
950 if (edac_op_state
== EDAC_OPSTATE_INT
) {
951 out_be32(pdata
->mc_vbase
+ MPC85XX_MC_ERR_INT_EN
, 0);
952 irq_dispose_mapping(pdata
->irq
);
955 out_be32(pdata
->mc_vbase
+ MPC85XX_MC_ERR_DISABLE
,
956 orig_ddr_err_disable
);
957 out_be32(pdata
->mc_vbase
+ MPC85XX_MC_ERR_SBE
, orig_ddr_err_sbe
);
959 edac_mc_del_mc(&op
->dev
);
964 static struct of_device_id mpc85xx_mc_err_of_match
[] = {
966 .compatible
= "fsl,8540-memory-controller",
969 .compatible
= "fsl,8541-memory-controller",
972 .compatible
= "fsl,8544-memory-controller",
975 .compatible
= "fsl,8548-memory-controller",
978 .compatible
= "fsl,8555-memory-controller",
981 .compatible
= "fsl,8568-memory-controller",
986 static struct of_platform_driver mpc85xx_mc_err_driver
= {
987 .owner
= THIS_MODULE
,
988 .name
= "mpc85xx_mc_err",
989 .match_table
= mpc85xx_mc_err_of_match
,
990 .probe
= mpc85xx_mc_err_probe
,
991 .remove
= mpc85xx_mc_err_remove
,
993 .name
= "mpc85xx_mc_err",
994 .owner
= THIS_MODULE
,
998 static int __init
mpc85xx_mc_init(void)
1002 printk(KERN_INFO
"Freescale(R) MPC85xx EDAC driver, "
1003 "(C) 2006 Montavista Software\n");
1005 /* make sure error reporting method is sane */
1006 switch (edac_op_state
) {
1007 case EDAC_OPSTATE_POLL
:
1008 case EDAC_OPSTATE_INT
:
1011 edac_op_state
= EDAC_OPSTATE_INT
;
1015 res
= of_register_platform_driver(&mpc85xx_mc_err_driver
);
1017 printk(KERN_WARNING EDAC_MOD_STR
"MC fails to register\n");
1019 res
= of_register_platform_driver(&mpc85xx_l2_err_driver
);
1021 printk(KERN_WARNING EDAC_MOD_STR
"L2 fails to register\n");
1024 res
= of_register_platform_driver(&mpc85xx_pci_err_driver
);
1026 printk(KERN_WARNING EDAC_MOD_STR
"PCI fails to register\n");
1030 * need to clear HID1[RFXE] to disable machine check int
1031 * so we can catch it
1033 if (edac_op_state
== EDAC_OPSTATE_INT
) {
1034 orig_hid1
= mfspr(SPRN_HID1
);
1035 mtspr(SPRN_HID1
, (orig_hid1
& ~0x20000));
1041 module_init(mpc85xx_mc_init
);
1043 static void __exit
mpc85xx_mc_exit(void)
1045 mtspr(SPRN_HID1
, orig_hid1
);
1047 of_unregister_platform_driver(&mpc85xx_pci_err_driver
);
1049 of_unregister_platform_driver(&mpc85xx_l2_err_driver
);
1050 of_unregister_platform_driver(&mpc85xx_mc_err_driver
);
1053 module_exit(mpc85xx_mc_exit
);
1055 MODULE_LICENSE("GPL");
1056 MODULE_AUTHOR("Montavista Software, Inc.");
1057 module_param(edac_op_state
, int, 0444);
1058 MODULE_PARM_DESC(edac_op_state
,
1059 "EDAC Error Reporting state: 0=Poll, 2=Interrupt");