2 * Copyright (c) 2008 Nuovation System Designs, LLC
3 * Grant Erickson <gerickson@nuovations.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; version 2 of the
12 #include <linux/edac.h>
13 #include <linux/interrupt.h>
14 #include <linux/irq.h>
15 #include <linux/kernel.h>
17 #include <linux/module.h>
18 #include <linux/of_device.h>
19 #include <linux/of_platform.h>
20 #include <linux/types.h>
24 #include "edac_core.h"
25 #include "ppc4xx_edac.h"
28 * This file implements a driver for monitoring and handling events
29 * associated with the IMB DDR2 ECC controller found in the AMCC/IBM
30 * 405EX[r], 440SP, 440SPe, 460EX, 460GT and 460SX.
32 * As realized in the 405EX[r], this controller features:
34 * - Support for registered- and non-registered DDR1 and DDR2 memory.
35 * - 32-bit or 16-bit memory interface with optional ECC.
37 * o ECC support includes:
40 * - Aligned-nibble error detect
43 * - Two (2) memory banks/ranks.
44 * - Up to 1 GiB per bank/rank in 32-bit mode and up to 512 MiB per
45 * bank/rank in 16-bit mode.
47 * As realized in the 440SP and 440SPe, this controller changes/adds:
49 * - 64-bit or 32-bit memory interface with optional ECC.
51 * o ECC support includes:
54 * - Aligned-nibble error detect
57 * - Up to 4 GiB per bank/rank in 64-bit mode and up to 2 GiB
58 * per bank/rank in 32-bit mode.
60 * As realized in the 460EX and 460GT, this controller changes/adds:
62 * - 64-bit or 32-bit memory interface with optional ECC.
64 * o ECC support includes:
67 * - Aligned-nibble error detect
70 * - Four (4) memory banks/ranks.
71 * - Up to 16 GiB per bank/rank in 64-bit mode and up to 8 GiB
72 * per bank/rank in 32-bit mode.
74 * At present, this driver has ONLY been tested against the controller
75 * realization in the 405EX[r] on the AMCC Kilauea and Haleakala
76 * boards (256 MiB w/o ECC memory soldered onto the board) and a
77 * proprietary board based on those designs (128 MiB ECC memory, also
78 * soldered onto the board).
80 * Dynamic feature detection and handling needs to be added for the
81 * other realizations of this controller listed above.
83 * Eventually, this driver will likely be adapted to the above variant
84 * realizations of this controller as well as broken apart to handle
85 * the other known ECC-capable controllers prevalent in other 4xx
88 * - IBM SDRAM (405GP, 405CR and 405EP) "ibm,sdram-4xx"
89 * - IBM DDR1 (440GP, 440GX, 440EP and 440GR) "ibm,sdram-4xx-ddr"
90 * - Denali DDR1/DDR2 (440EPX and 440GRX) "denali,sdram-4xx-ddr2"
92 * For this controller, unfortunately, correctable errors report
93 * nothing more than the beat/cycle and byte/lane the correction
94 * occurred on and the check bit group that covered the error.
96 * In contrast, uncorrectable errors also report the failing address,
97 * the bus master and the transaction direction (i.e. read or write)
99 * Regardless of whether the error is a CE or a UE, we report the
100 * following pieces of information in the driver-unique message to the
105 * - Check bit error group
109 /* Preprocessor Definitions */
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 " __DATE__
118 #define PPC4XX_EDAC_MESSAGE_SIZE 256
121 * Kernel logging without an EDAC instance
123 #define ppc4xx_edac_printk(level, fmt, arg...) \
124 edac_printk(level, "PPC4xx MC", fmt, ##arg)
127 * Kernel logging with an EDAC instance
129 #define ppc4xx_edac_mc_printk(level, mci, fmt, arg...) \
130 edac_mc_chipset_printk(mci, level, "PPC4xx", fmt, ##arg)
133 * Macros to convert bank configuration size enumerations into MiB and
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)))
144 * The ibm,sdram-4xx-ddr2 Device Control Registers (DCRs) are
145 * indirectly acccessed and have a base and length defined by the
146 * device tree. The base can be anything; however, we expect the
147 * length to be precisely two registers, the first for the address
148 * window and the second for the data window.
150 #define SDRAM_DCR_RESOURCE_LEN 2
151 #define SDRAM_DCR_ADDR_OFFSET 0
152 #define SDRAM_DCR_DATA_OFFSET 1
155 * Device tree interrupt indices
157 #define INTMAP_ECCDED_INDEX 0 /* Double-bit Error Detect */
158 #define INTMAP_ECCSEC_INDEX 1 /* Single-bit Error Correct */
160 /* Type Definitions */
163 * PPC4xx SDRAM memory controller private instance data
165 struct ppc4xx_edac_pdata
{
166 dcr_host_t dcr_host
; /* Indirect DCR address/data window mapping */
168 int sec
; /* Single-bit correctable error IRQ assigned */
169 int ded
; /* Double-bit detectable error IRQ assigned */
174 * Various status data gathered and manipulated when checking and
175 * reporting ECC status.
177 struct ppc4xx_ecc_status
{
185 /* Function Prototypes */
187 static int ppc4xx_edac_probe(struct platform_device
*device
,
188 const struct of_device_id
*device_id
);
189 static int ppc4xx_edac_remove(struct platform_device
*device
);
191 /* Global Variables */
194 * Device tree node type and compatible tuples this driver can match
197 static struct of_device_id ppc4xx_edac_match
[] = {
199 .compatible
= "ibm,sdram-4xx-ddr2"
204 static struct of_platform_driver ppc4xx_edac_driver
= {
205 .probe
= ppc4xx_edac_probe
,
206 .remove
= ppc4xx_edac_remove
,
208 .owner
= THIS_MODULE
,
209 .name
= PPC4XX_EDAC_MODULE_NAME
210 .of_match_table
= ppc4xx_edac_match
,
215 * TODO: The row and channel parameters likely need to be dynamically
216 * set based on the aforementioned variant controller realizations.
218 static const unsigned ppc4xx_edac_nr_csrows
= 2;
219 static const unsigned ppc4xx_edac_nr_chans
= 1;
222 * Strings associated with PLB master IDs capable of being posted in
223 * SDRAM_BESR or SDRAM_WMIRQ on uncorrectable ECC errors.
225 static const char * const ppc4xx_plb_masters
[9] = {
226 [SDRAM_PLB_M0ID_ICU
] = "ICU",
227 [SDRAM_PLB_M0ID_PCIE0
] = "PCI-E 0",
228 [SDRAM_PLB_M0ID_PCIE1
] = "PCI-E 1",
229 [SDRAM_PLB_M0ID_DMA
] = "DMA",
230 [SDRAM_PLB_M0ID_DCU
] = "DCU",
231 [SDRAM_PLB_M0ID_OPB
] = "OPB",
232 [SDRAM_PLB_M0ID_MAL
] = "MAL",
233 [SDRAM_PLB_M0ID_SEC
] = "SEC",
234 [SDRAM_PLB_M0ID_AHB
] = "AHB"
238 * mfsdram - read and return controller register data
239 * @dcr_host: A pointer to the DCR mapping.
240 * @idcr_n: The indirect DCR register to read.
242 * This routine reads and returns the data associated with the
243 * controller's specified indirect DCR register.
245 * Returns the read data.
248 mfsdram(const dcr_host_t
*dcr_host
, unsigned int idcr_n
)
250 return __mfdcri(dcr_host
->base
+ SDRAM_DCR_ADDR_OFFSET
,
251 dcr_host
->base
+ SDRAM_DCR_DATA_OFFSET
,
256 * mtsdram - write controller register data
257 * @dcr_host: A pointer to the DCR mapping.
258 * @idcr_n: The indirect DCR register to write.
259 * @value: The data to write.
261 * This routine writes the provided data to the controller's specified
262 * indirect DCR register.
265 mtsdram(const dcr_host_t
*dcr_host
, unsigned int idcr_n
, u32 value
)
267 return __mtdcri(dcr_host
->base
+ SDRAM_DCR_ADDR_OFFSET
,
268 dcr_host
->base
+ SDRAM_DCR_DATA_OFFSET
,
274 * ppc4xx_edac_check_bank_error - check a bank for an ECC bank error
275 * @status: A pointer to the ECC status structure to check for an
277 * @bank: The bank to check for an ECC error.
279 * This routine determines whether the specified bank has an ECC
282 * Returns true if the specified bank has an ECC error; otherwise,
286 ppc4xx_edac_check_bank_error(const struct ppc4xx_ecc_status
*status
,
291 return status
->ecces
& SDRAM_ECCES_BK0ER
;
293 return status
->ecces
& SDRAM_ECCES_BK1ER
;
300 * ppc4xx_edac_generate_bank_message - generate interpretted bank status message
301 * @mci: A pointer to the EDAC memory controller instance associated
302 * with the bank message being generated.
303 * @status: A pointer to the ECC status structure to generate the
305 * @buffer: A pointer to the buffer in which to generate the
307 * @size: The size, in bytes, of space available in buffer.
309 * This routine generates to the provided buffer the portion of the
310 * driver-unique report message associated with the ECCESS[BKNER]
311 * field of the specified ECC status.
313 * Returns the number of characters generated on success; otherwise, <
317 ppc4xx_edac_generate_bank_message(const struct mem_ctl_info
*mci
,
318 const struct ppc4xx_ecc_status
*status
,
323 unsigned int row
, rows
;
325 n
= snprintf(buffer
, size
, "%s: Banks: ", mci
->dev_name
);
327 if (n
< 0 || n
>= size
)
334 for (rows
= 0, row
= 0; row
< mci
->nr_csrows
; row
++) {
335 if (ppc4xx_edac_check_bank_error(status
, row
)) {
336 n
= snprintf(buffer
, size
, "%s%u",
337 (rows
++ ? ", " : ""), row
);
339 if (n
< 0 || n
>= size
)
348 n
= snprintf(buffer
, size
, "%s; ", rows
? "" : "None");
350 if (n
< 0 || n
>= size
)
362 * ppc4xx_edac_generate_checkbit_message - generate interpretted checkbit message
363 * @mci: A pointer to the EDAC memory controller instance associated
364 * with the checkbit message being generated.
365 * @status: A pointer to the ECC status structure to generate the
367 * @buffer: A pointer to the buffer in which to generate the
369 * @size: The size, in bytes, of space available in buffer.
371 * This routine generates to the provided buffer the portion of the
372 * driver-unique report message associated with the ECCESS[CKBER]
373 * field of the specified ECC status.
375 * Returns the number of characters generated on success; otherwise, <
379 ppc4xx_edac_generate_checkbit_message(const struct mem_ctl_info
*mci
,
380 const struct ppc4xx_ecc_status
*status
,
384 const struct ppc4xx_edac_pdata
*pdata
= mci
->pvt_info
;
385 const char *ckber
= NULL
;
387 switch (status
->ecces
& SDRAM_ECCES_CKBER_MASK
) {
388 case SDRAM_ECCES_CKBER_NONE
:
391 case SDRAM_ECCES_CKBER_32_ECC_0_3
:
394 case SDRAM_ECCES_CKBER_32_ECC_4_8
:
395 switch (mfsdram(&pdata
->dcr_host
, SDRAM_MCOPT1
) &
396 SDRAM_MCOPT1_WDTH_MASK
) {
397 case SDRAM_MCOPT1_WDTH_16
:
400 case SDRAM_MCOPT1_WDTH_32
:
408 case SDRAM_ECCES_CKBER_32_ECC_0_8
:
416 return snprintf(buffer
, size
, "Checkbit Error: %s", ckber
);
420 * ppc4xx_edac_generate_lane_message - generate interpretted byte lane message
421 * @mci: A pointer to the EDAC memory controller instance associated
422 * with the byte lane message being generated.
423 * @status: A pointer to the ECC status structure to generate the
425 * @buffer: A pointer to the buffer in which to generate the
427 * @size: The size, in bytes, of space available in buffer.
429 * This routine generates to the provided buffer the portion of the
430 * driver-unique report message associated with the ECCESS[BNCE]
431 * field of the specified ECC status.
433 * Returns the number of characters generated on success; otherwise, <
437 ppc4xx_edac_generate_lane_message(const struct mem_ctl_info
*mci
,
438 const struct ppc4xx_ecc_status
*status
,
443 unsigned int lane
, lanes
;
444 const unsigned int first_lane
= 0;
445 const unsigned int lane_count
= 16;
447 n
= snprintf(buffer
, size
, "; Byte Lane Errors: ");
449 if (n
< 0 || n
>= size
)
456 for (lanes
= 0, lane
= first_lane
; lane
< lane_count
; lane
++) {
457 if ((status
->ecces
& SDRAM_ECCES_BNCE_ENCODE(lane
)) != 0) {
458 n
= snprintf(buffer
, size
,
460 (lanes
++ ? ", " : ""), lane
);
462 if (n
< 0 || n
>= size
)
471 n
= snprintf(buffer
, size
, "%s; ", lanes
? "" : "None");
473 if (n
< 0 || n
>= size
)
485 * ppc4xx_edac_generate_ecc_message - generate interpretted ECC status message
486 * @mci: A pointer to the EDAC memory controller instance associated
487 * with the ECCES message being generated.
488 * @status: A pointer to the ECC status structure to generate the
490 * @buffer: A pointer to the buffer in which to generate the
492 * @size: The size, in bytes, of space available in buffer.
494 * This routine generates to the provided buffer the portion of the
495 * driver-unique report message associated with the ECCESS register of
496 * the specified ECC status.
498 * Returns the number of characters generated on success; otherwise, <
502 ppc4xx_edac_generate_ecc_message(const struct mem_ctl_info
*mci
,
503 const struct ppc4xx_ecc_status
*status
,
509 n
= ppc4xx_edac_generate_bank_message(mci
, status
, buffer
, size
);
511 if (n
< 0 || n
>= size
)
518 n
= ppc4xx_edac_generate_checkbit_message(mci
, status
, buffer
, size
);
520 if (n
< 0 || n
>= size
)
527 n
= ppc4xx_edac_generate_lane_message(mci
, status
, buffer
, size
);
529 if (n
< 0 || n
>= size
)
541 * ppc4xx_edac_generate_plb_message - generate interpretted PLB status message
542 * @mci: A pointer to the EDAC memory controller instance associated
543 * with the PLB message being generated.
544 * @status: A pointer to the ECC status structure to generate the
546 * @buffer: A pointer to the buffer in which to generate the
548 * @size: The size, in bytes, of space available in buffer.
550 * This routine generates to the provided buffer the portion of the
551 * driver-unique report message associated with the PLB-related BESR
552 * and/or WMIRQ registers of the specified ECC status.
554 * Returns the number of characters generated on success; otherwise, <
558 ppc4xx_edac_generate_plb_message(const struct mem_ctl_info
*mci
,
559 const struct ppc4xx_ecc_status
*status
,
566 if ((status
->besr
& SDRAM_BESR_MASK
) == 0)
569 if ((status
->besr
& SDRAM_BESR_M0ET_MASK
) == SDRAM_BESR_M0ET_NONE
)
572 read
= ((status
->besr
& SDRAM_BESR_M0RW_MASK
) == SDRAM_BESR_M0RW_READ
);
574 master
= SDRAM_BESR_M0ID_DECODE(status
->besr
);
576 return snprintf(buffer
, size
,
577 "%s error w/ PLB master %u \"%s\"; ",
578 (read
? "Read" : "Write"),
580 (((master
>= SDRAM_PLB_M0ID_FIRST
) &&
581 (master
<= SDRAM_PLB_M0ID_LAST
)) ?
582 ppc4xx_plb_masters
[master
] : "UNKNOWN"));
586 * ppc4xx_edac_generate_message - generate interpretted status message
587 * @mci: A pointer to the EDAC memory controller instance associated
588 * with the driver-unique message being generated.
589 * @status: A pointer to the ECC status structure to generate the
591 * @buffer: A pointer to the buffer in which to generate the
593 * @size: The size, in bytes, of space available in buffer.
595 * This routine generates to the provided buffer the driver-unique
596 * EDAC report message from the specified ECC status.
599 ppc4xx_edac_generate_message(const struct mem_ctl_info
*mci
,
600 const struct ppc4xx_ecc_status
*status
,
606 if (buffer
== NULL
|| size
== 0)
609 n
= ppc4xx_edac_generate_ecc_message(mci
, status
, buffer
, size
);
611 if (n
< 0 || n
>= size
)
617 ppc4xx_edac_generate_plb_message(mci
, status
, buffer
, size
);
622 * ppc4xx_ecc_dump_status - dump controller ECC status registers
623 * @mci: A pointer to the EDAC memory controller instance
624 * associated with the status being dumped.
625 * @status: A pointer to the ECC status structure to generate the
628 * This routine dumps to the kernel log buffer the raw and
629 * interpretted specified ECC status.
632 ppc4xx_ecc_dump_status(const struct mem_ctl_info
*mci
,
633 const struct ppc4xx_ecc_status
*status
)
635 char message
[PPC4XX_EDAC_MESSAGE_SIZE
];
637 ppc4xx_edac_generate_message(mci
, status
, message
, sizeof(message
));
639 ppc4xx_edac_mc_printk(KERN_INFO
, mci
,
644 "\tBEAR: 0x%08x%08x\n"
656 * ppc4xx_ecc_get_status - get controller ECC status
657 * @mci: A pointer to the EDAC memory controller instance
658 * associated with the status being retrieved.
659 * @status: A pointer to the ECC status structure to populate the
662 * This routine reads and masks, as appropriate, all the relevant
663 * status registers that deal with ibm,sdram-4xx-ddr2 ECC errors.
664 * While we read all of them, for correctable errors, we only expect
665 * to deal with ECCES. For uncorrectable errors, we expect to deal
669 ppc4xx_ecc_get_status(const struct mem_ctl_info
*mci
,
670 struct ppc4xx_ecc_status
*status
)
672 const struct ppc4xx_edac_pdata
*pdata
= mci
->pvt_info
;
673 const dcr_host_t
*dcr_host
= &pdata
->dcr_host
;
675 status
->ecces
= mfsdram(dcr_host
, SDRAM_ECCES
) & SDRAM_ECCES_MASK
;
676 status
->wmirq
= mfsdram(dcr_host
, SDRAM_WMIRQ
) & SDRAM_WMIRQ_MASK
;
677 status
->besr
= mfsdram(dcr_host
, SDRAM_BESR
) & SDRAM_BESR_MASK
;
678 status
->bearl
= mfsdram(dcr_host
, SDRAM_BEARL
);
679 status
->bearh
= mfsdram(dcr_host
, SDRAM_BEARH
);
683 * ppc4xx_ecc_clear_status - clear controller ECC status
684 * @mci: A pointer to the EDAC memory controller instance
685 * associated with the status being cleared.
686 * @status: A pointer to the ECC status structure containing the
687 * values to write to clear the ECC status.
689 * This routine clears--by writing the masked (as appropriate) status
690 * values back to--the status registers that deal with
691 * ibm,sdram-4xx-ddr2 ECC errors.
694 ppc4xx_ecc_clear_status(const struct mem_ctl_info
*mci
,
695 const struct ppc4xx_ecc_status
*status
)
697 const struct ppc4xx_edac_pdata
*pdata
= mci
->pvt_info
;
698 const dcr_host_t
*dcr_host
= &pdata
->dcr_host
;
700 mtsdram(dcr_host
, SDRAM_ECCES
, status
->ecces
& SDRAM_ECCES_MASK
);
701 mtsdram(dcr_host
, SDRAM_WMIRQ
, status
->wmirq
& SDRAM_WMIRQ_MASK
);
702 mtsdram(dcr_host
, SDRAM_BESR
, status
->besr
& SDRAM_BESR_MASK
);
703 mtsdram(dcr_host
, SDRAM_BEARL
, 0);
704 mtsdram(dcr_host
, SDRAM_BEARH
, 0);
708 * ppc4xx_edac_handle_ce - handle controller correctable ECC error (CE)
709 * @mci: A pointer to the EDAC memory controller instance
710 * associated with the correctable error being handled and reported.
711 * @status: A pointer to the ECC status structure associated with
712 * the correctable error being handled and reported.
714 * This routine handles an ibm,sdram-4xx-ddr2 controller ECC
715 * correctable error. Per the aforementioned discussion, there's not
716 * enough status available to use the full EDAC correctable error
717 * interface, so we just pass driver-unique message to the "no info"
721 ppc4xx_edac_handle_ce(struct mem_ctl_info
*mci
,
722 const struct ppc4xx_ecc_status
*status
)
725 char message
[PPC4XX_EDAC_MESSAGE_SIZE
];
727 ppc4xx_edac_generate_message(mci
, status
, message
, sizeof(message
));
729 for (row
= 0; row
< mci
->nr_csrows
; row
++)
730 if (ppc4xx_edac_check_bank_error(status
, row
))
731 edac_mc_handle_ce_no_info(mci
, message
);
735 * ppc4xx_edac_handle_ue - handle controller uncorrectable ECC error (UE)
736 * @mci: A pointer to the EDAC memory controller instance
737 * associated with the uncorrectable error being handled and
739 * @status: A pointer to the ECC status structure associated with
740 * the uncorrectable error being handled and reported.
742 * This routine handles an ibm,sdram-4xx-ddr2 controller ECC
743 * uncorrectable error.
746 ppc4xx_edac_handle_ue(struct mem_ctl_info
*mci
,
747 const struct ppc4xx_ecc_status
*status
)
749 const u64 bear
= ((u64
)status
->bearh
<< 32 | status
->bearl
);
750 const unsigned long page
= bear
>> PAGE_SHIFT
;
751 const unsigned long offset
= bear
& ~PAGE_MASK
;
753 char message
[PPC4XX_EDAC_MESSAGE_SIZE
];
755 ppc4xx_edac_generate_message(mci
, status
, message
, sizeof(message
));
757 for (row
= 0; row
< mci
->nr_csrows
; row
++)
758 if (ppc4xx_edac_check_bank_error(status
, row
))
759 edac_mc_handle_ue(mci
, page
, offset
, row
, message
);
763 * ppc4xx_edac_check - check controller for ECC errors
764 * @mci: A pointer to the EDAC memory controller instance
765 * associated with the ibm,sdram-4xx-ddr2 controller being
768 * This routine is used to check and post ECC errors and is called by
769 * both the EDAC polling thread and this driver's CE and UE interrupt
773 ppc4xx_edac_check(struct mem_ctl_info
*mci
)
776 static unsigned int count
;
778 struct ppc4xx_ecc_status status
;
780 ppc4xx_ecc_get_status(mci
, &status
);
783 if (count
++ % 30 == 0)
784 ppc4xx_ecc_dump_status(mci
, &status
);
787 if (status
.ecces
& SDRAM_ECCES_UE
)
788 ppc4xx_edac_handle_ue(mci
, &status
);
790 if (status
.ecces
& SDRAM_ECCES_CE
)
791 ppc4xx_edac_handle_ce(mci
, &status
);
793 ppc4xx_ecc_clear_status(mci
, &status
);
797 * ppc4xx_edac_isr - SEC (CE) and DED (UE) interrupt service routine
798 * @irq: The virtual interrupt number being serviced.
799 * @dev_id: A pointer to the EDAC memory controller instance
800 * associated with the interrupt being handled.
802 * This routine implements the interrupt handler for both correctable
803 * (CE) and uncorrectable (UE) ECC errors for the ibm,sdram-4xx-ddr2
804 * controller. It simply calls through to the same routine used during
805 * polling to check, report and clear the ECC status.
807 * Unconditionally returns IRQ_HANDLED.
810 ppc4xx_edac_isr(int irq
, void *dev_id
)
812 struct mem_ctl_info
*mci
= dev_id
;
814 ppc4xx_edac_check(mci
);
820 * ppc4xx_edac_get_dtype - return the controller memory width
821 * @mcopt1: The 32-bit Memory Controller Option 1 register value
822 * currently set for the controller, from which the width
825 * This routine returns the EDAC device type width appropriate for the
826 * current controller configuration.
828 * TODO: This needs to be conditioned dynamically through feature
829 * flags or some such when other controller variants are supported as
830 * the 405EX[r] is 16-/32-bit and the others are 32-/64-bit with the
831 * 16- and 64-bit field definition/value/enumeration (b1) overloaded
834 * Returns a device type width enumeration.
836 static enum dev_type __devinit
837 ppc4xx_edac_get_dtype(u32 mcopt1
)
839 switch (mcopt1
& SDRAM_MCOPT1_WDTH_MASK
) {
840 case SDRAM_MCOPT1_WDTH_16
:
842 case SDRAM_MCOPT1_WDTH_32
:
850 * ppc4xx_edac_get_mtype - return controller memory type
851 * @mcopt1: The 32-bit Memory Controller Option 1 register value
852 * currently set for the controller, from which the memory type
855 * This routine returns the EDAC memory type appropriate for the
856 * current controller configuration.
858 * Returns a memory type enumeration.
860 static enum mem_type __devinit
861 ppc4xx_edac_get_mtype(u32 mcopt1
)
863 bool rden
= ((mcopt1
& SDRAM_MCOPT1_RDEN_MASK
) == SDRAM_MCOPT1_RDEN
);
865 switch (mcopt1
& SDRAM_MCOPT1_DDR_TYPE_MASK
) {
866 case SDRAM_MCOPT1_DDR2_TYPE
:
867 return rden
? MEM_RDDR2
: MEM_DDR2
;
868 case SDRAM_MCOPT1_DDR1_TYPE
:
869 return rden
? MEM_RDDR
: MEM_DDR
;
876 * ppc4xx_edac_init_csrows - intialize driver instance rows
877 * @mci: A pointer to the EDAC memory controller instance
878 * associated with the ibm,sdram-4xx-ddr2 controller for which
879 * the csrows (i.e. banks/ranks) are being initialized.
880 * @mcopt1: The 32-bit Memory Controller Option 1 register value
881 * currently set for the controller, from which bank width
882 * and memory typ information is derived.
884 * This routine intializes the virtual "chip select rows" associated
885 * with the EDAC memory controller instance. An ibm,sdram-4xx-ddr2
886 * controller bank/rank is mapped to a row.
888 * Returns 0 if OK; otherwise, -EINVAL if the memory bank size
889 * configuration cannot be determined.
892 ppc4xx_edac_init_csrows(struct mem_ctl_info
*mci
, u32 mcopt1
)
894 const struct ppc4xx_edac_pdata
*pdata
= mci
->pvt_info
;
898 enum edac_type edac_mode
;
901 static u32 ppc4xx_last_page
;
903 /* Establish the memory type and width */
905 mtype
= ppc4xx_edac_get_mtype(mcopt1
);
906 dtype
= ppc4xx_edac_get_dtype(mcopt1
);
908 /* Establish EDAC mode */
910 if (mci
->edac_cap
& EDAC_FLAG_SECDED
)
911 edac_mode
= EDAC_SECDED
;
912 else if (mci
->edac_cap
& EDAC_FLAG_EC
)
915 edac_mode
= EDAC_NONE
;
918 * Initialize each chip select row structure which correspond
919 * 1:1 with a controller bank/rank.
922 for (row
= 0; row
< mci
->nr_csrows
; row
++) {
923 struct csrow_info
*csi
= &mci
->csrows
[row
];
926 * Get the configuration settings for this
927 * row/bank/rank and skip disabled banks.
930 mbxcf
= mfsdram(&pdata
->dcr_host
, SDRAM_MBXCF(row
));
932 if ((mbxcf
& SDRAM_MBCF_BE_MASK
) != SDRAM_MBCF_BE_ENABLE
)
935 /* Map the bank configuration size setting to pages. */
937 size
= mbxcf
& SDRAM_MBCF_SZ_MASK
;
940 case SDRAM_MBCF_SZ_4MB
:
941 case SDRAM_MBCF_SZ_8MB
:
942 case SDRAM_MBCF_SZ_16MB
:
943 case SDRAM_MBCF_SZ_32MB
:
944 case SDRAM_MBCF_SZ_64MB
:
945 case SDRAM_MBCF_SZ_128MB
:
946 case SDRAM_MBCF_SZ_256MB
:
947 case SDRAM_MBCF_SZ_512MB
:
948 case SDRAM_MBCF_SZ_1GB
:
949 case SDRAM_MBCF_SZ_2GB
:
950 case SDRAM_MBCF_SZ_4GB
:
951 case SDRAM_MBCF_SZ_8GB
:
952 csi
->nr_pages
= SDRAM_MBCF_SZ_TO_PAGES(size
);
955 ppc4xx_edac_mc_printk(KERN_ERR
, mci
,
956 "Unrecognized memory bank %d "
958 row
, SDRAM_MBCF_SZ_DECODE(size
));
963 csi
->first_page
= ppc4xx_last_page
;
964 csi
->last_page
= csi
->first_page
+ csi
->nr_pages
- 1;
968 * It's unclear exactly what grain should be set to
969 * here. The SDRAM_ECCES register allows resolution of
970 * an error down to a nibble which would potentially
971 * argue for a grain of '1' byte, even though we only
972 * know the associated address for uncorrectable
973 * errors. This value is not used at present for
974 * anything other than error reporting so getting it
975 * wrong should be of little consequence. Other
976 * possible values would be the PLB width (16), the
977 * page size (PAGE_SIZE) or the memory width (2 or 4).
985 csi
->edac_mode
= edac_mode
;
987 ppc4xx_last_page
+= csi
->nr_pages
;
995 * ppc4xx_edac_mc_init - intialize driver instance
996 * @mci: A pointer to the EDAC memory controller instance being
998 * @op: A pointer to the OpenFirmware device tree node associated
999 * with the controller this EDAC instance is bound to.
1000 * @match: A pointer to the OpenFirmware device tree match
1001 * information associated with the controller this EDAC instance
1003 * @dcr_host: A pointer to the DCR data containing the DCR mapping
1004 * for this controller instance.
1005 * @mcopt1: The 32-bit Memory Controller Option 1 register value
1006 * currently set for the controller, from which ECC capabilities
1007 * and scrub mode are derived.
1009 * This routine performs initialization of the EDAC memory controller
1010 * instance and related driver-private data associated with the
1011 * ibm,sdram-4xx-ddr2 memory controller the instance is bound to.
1013 * Returns 0 if OK; otherwise, < 0 on error.
1015 static int __devinit
1016 ppc4xx_edac_mc_init(struct mem_ctl_info
*mci
,
1017 struct platform_device
*op
,
1018 const struct of_device_id
*match
,
1019 const dcr_host_t
*dcr_host
,
1023 const u32 memcheck
= (mcopt1
& SDRAM_MCOPT1_MCHK_MASK
);
1024 struct ppc4xx_edac_pdata
*pdata
= NULL
;
1025 const struct device_node
*np
= op
->dev
.of_node
;
1030 /* Initial driver pointers and private data */
1032 mci
->dev
= &op
->dev
;
1034 dev_set_drvdata(mci
->dev
, mci
);
1036 pdata
= mci
->pvt_info
;
1038 pdata
->dcr_host
= *dcr_host
;
1039 pdata
->irqs
.sec
= NO_IRQ
;
1040 pdata
->irqs
.ded
= NO_IRQ
;
1042 /* Initialize controller capabilities and configuration */
1044 mci
->mtype_cap
= (MEM_FLAG_DDR
| MEM_FLAG_RDDR
|
1045 MEM_FLAG_DDR2
| MEM_FLAG_RDDR2
);
1047 mci
->edac_ctl_cap
= (EDAC_FLAG_NONE
|
1051 mci
->scrub_cap
= SCRUB_NONE
;
1052 mci
->scrub_mode
= SCRUB_NONE
;
1055 * Update the actual capabilites based on the MCOPT1[MCHK]
1056 * settings. Scrubbing is only useful if reporting is enabled.
1060 case SDRAM_MCOPT1_MCHK_CHK
:
1061 mci
->edac_cap
= EDAC_FLAG_EC
;
1063 case SDRAM_MCOPT1_MCHK_CHK_REP
:
1064 mci
->edac_cap
= (EDAC_FLAG_EC
| EDAC_FLAG_SECDED
);
1065 mci
->scrub_mode
= SCRUB_SW_SRC
;
1068 mci
->edac_cap
= EDAC_FLAG_NONE
;
1072 /* Initialize strings */
1074 mci
->mod_name
= PPC4XX_EDAC_MODULE_NAME
;
1075 mci
->mod_ver
= PPC4XX_EDAC_MODULE_REVISION
;
1076 mci
->ctl_name
= match
->compatible
,
1077 mci
->dev_name
= np
->full_name
;
1079 /* Initialize callbacks */
1081 mci
->edac_check
= ppc4xx_edac_check
;
1082 mci
->ctl_page_to_phys
= NULL
;
1084 /* Initialize chip select rows */
1086 status
= ppc4xx_edac_init_csrows(mci
, mcopt1
);
1089 ppc4xx_edac_mc_printk(KERN_ERR
, mci
,
1090 "Failed to initialize rows!\n");
1096 * ppc4xx_edac_register_irq - setup and register controller interrupts
1097 * @op: A pointer to the OpenFirmware device tree node associated
1098 * with the controller this EDAC instance is bound to.
1099 * @mci: A pointer to the EDAC memory controller instance
1100 * associated with the ibm,sdram-4xx-ddr2 controller for which
1101 * interrupts are being registered.
1103 * This routine parses the correctable (CE) and uncorrectable error (UE)
1104 * interrupts from the device tree node and maps and assigns them to
1105 * the associated EDAC memory controller instance.
1107 * Returns 0 if OK; otherwise, -ENODEV if the interrupts could not be
1108 * mapped and assigned.
1110 static int __devinit
1111 ppc4xx_edac_register_irq(struct platform_device
*op
, struct mem_ctl_info
*mci
)
1114 int ded_irq
, sec_irq
;
1115 struct ppc4xx_edac_pdata
*pdata
= mci
->pvt_info
;
1116 struct device_node
*np
= op
->dev
.of_node
;
1118 ded_irq
= irq_of_parse_and_map(np
, INTMAP_ECCDED_INDEX
);
1119 sec_irq
= irq_of_parse_and_map(np
, INTMAP_ECCSEC_INDEX
);
1121 if (ded_irq
== NO_IRQ
|| sec_irq
== NO_IRQ
) {
1122 ppc4xx_edac_mc_printk(KERN_ERR
, mci
,
1123 "Unable to map interrupts.\n");
1128 status
= request_irq(ded_irq
,
1135 ppc4xx_edac_mc_printk(KERN_ERR
, mci
,
1136 "Unable to request irq %d for ECC DED",
1142 status
= request_irq(sec_irq
,
1149 ppc4xx_edac_mc_printk(KERN_ERR
, mci
,
1150 "Unable to request irq %d for ECC SEC",
1156 ppc4xx_edac_mc_printk(KERN_INFO
, mci
, "ECCDED irq is %d\n", ded_irq
);
1157 ppc4xx_edac_mc_printk(KERN_INFO
, mci
, "ECCSEC irq is %d\n", sec_irq
);
1159 pdata
->irqs
.ded
= ded_irq
;
1160 pdata
->irqs
.sec
= sec_irq
;
1165 free_irq(sec_irq
, mci
);
1168 free_irq(ded_irq
, mci
);
1175 * ppc4xx_edac_map_dcrs - locate and map controller registers
1176 * @np: A pointer to the device tree node containing the DCR
1178 * @dcr_host: A pointer to the DCR data to populate with the
1181 * This routine attempts to locate in the device tree and map the DCR
1182 * register resources associated with the controller's indirect DCR
1183 * address and data windows.
1185 * Returns 0 if the DCRs were successfully mapped; otherwise, < 0 on
1188 static int __devinit
1189 ppc4xx_edac_map_dcrs(const struct device_node
*np
, dcr_host_t
*dcr_host
)
1191 unsigned int dcr_base
, dcr_len
;
1193 if (np
== NULL
|| dcr_host
== NULL
)
1196 /* Get the DCR resource extent and sanity check the values. */
1198 dcr_base
= dcr_resource_start(np
, 0);
1199 dcr_len
= dcr_resource_len(np
, 0);
1201 if (dcr_base
== 0 || dcr_len
== 0) {
1202 ppc4xx_edac_printk(KERN_ERR
,
1203 "Failed to obtain DCR property.\n");
1207 if (dcr_len
!= SDRAM_DCR_RESOURCE_LEN
) {
1208 ppc4xx_edac_printk(KERN_ERR
,
1209 "Unexpected DCR length %d, expected %d.\n",
1210 dcr_len
, SDRAM_DCR_RESOURCE_LEN
);
1214 /* Attempt to map the DCR extent. */
1216 *dcr_host
= dcr_map(np
, dcr_base
, dcr_len
);
1218 if (!DCR_MAP_OK(*dcr_host
)) {
1219 ppc4xx_edac_printk(KERN_INFO
, "Failed to map DCRs.\n");
1227 * ppc4xx_edac_probe - check controller and bind driver
1228 * @op: A pointer to the OpenFirmware device tree node associated
1229 * with the controller being probed for driver binding.
1230 * @match: A pointer to the OpenFirmware device tree match
1231 * information associated with the controller being probed
1232 * for driver binding.
1234 * This routine probes a specific ibm,sdram-4xx-ddr2 controller
1235 * instance for binding with the driver.
1237 * Returns 0 if the controller instance was successfully bound to the
1238 * driver; otherwise, < 0 on error.
1240 static int __devinit
1241 ppc4xx_edac_probe(struct platform_device
*op
, const struct of_device_id
*match
)
1244 u32 mcopt1
, memcheck
;
1245 dcr_host_t dcr_host
;
1246 const struct device_node
*np
= op
->dev
.of_node
;
1247 struct mem_ctl_info
*mci
= NULL
;
1248 static int ppc4xx_edac_instance
;
1251 * At this point, we only support the controller realized on
1252 * the AMCC PPC 405EX[r]. Reject anything else.
1255 if (!of_device_is_compatible(np
, "ibm,sdram-405ex") &&
1256 !of_device_is_compatible(np
, "ibm,sdram-405exr")) {
1257 ppc4xx_edac_printk(KERN_NOTICE
,
1258 "Only the PPC405EX[r] is supported.\n");
1263 * Next, get the DCR property and attempt to map it so that we
1264 * can probe the controller.
1267 status
= ppc4xx_edac_map_dcrs(np
, &dcr_host
);
1273 * First determine whether ECC is enabled at all. If not,
1274 * there is no useful checking or monitoring that can be done
1275 * for this controller.
1278 mcopt1
= mfsdram(&dcr_host
, SDRAM_MCOPT1
);
1279 memcheck
= (mcopt1
& SDRAM_MCOPT1_MCHK_MASK
);
1281 if (memcheck
== SDRAM_MCOPT1_MCHK_NON
) {
1282 ppc4xx_edac_printk(KERN_INFO
, "%s: No ECC memory detected or "
1283 "ECC is disabled.\n", np
->full_name
);
1289 * At this point, we know ECC is enabled, allocate an EDAC
1290 * controller instance and perform the appropriate
1294 mci
= edac_mc_alloc(sizeof(struct ppc4xx_edac_pdata
),
1295 ppc4xx_edac_nr_csrows
,
1296 ppc4xx_edac_nr_chans
,
1297 ppc4xx_edac_instance
);
1300 ppc4xx_edac_printk(KERN_ERR
, "%s: "
1301 "Failed to allocate EDAC MC instance!\n",
1307 status
= ppc4xx_edac_mc_init(mci
, op
, match
, &dcr_host
, mcopt1
);
1310 ppc4xx_edac_mc_printk(KERN_ERR
, mci
,
1311 "Failed to initialize instance!\n");
1316 * We have a valid, initialized EDAC instance bound to the
1317 * controller. Attempt to register it with the EDAC subsystem
1318 * and, if necessary, register interrupts.
1321 if (edac_mc_add_mc(mci
)) {
1322 ppc4xx_edac_mc_printk(KERN_ERR
, mci
,
1323 "Failed to add instance!\n");
1328 if (edac_op_state
== EDAC_OPSTATE_INT
) {
1329 status
= ppc4xx_edac_register_irq(op
, mci
);
1335 ppc4xx_edac_instance
++;
1340 edac_mc_del_mc(mci
->dev
);
1350 * ppc4xx_edac_remove - unbind driver from controller
1351 * @op: A pointer to the OpenFirmware device tree node associated
1352 * with the controller this EDAC instance is to be unbound/removed
1355 * This routine unbinds the EDAC memory controller instance associated
1356 * with the specified ibm,sdram-4xx-ddr2 controller described by the
1357 * OpenFirmware device tree node passed as a parameter.
1359 * Unconditionally returns 0.
1362 ppc4xx_edac_remove(struct platform_device
*op
)
1364 struct mem_ctl_info
*mci
= dev_get_drvdata(&op
->dev
);
1365 struct ppc4xx_edac_pdata
*pdata
= mci
->pvt_info
;
1367 if (edac_op_state
== EDAC_OPSTATE_INT
) {
1368 free_irq(pdata
->irqs
.sec
, mci
);
1369 free_irq(pdata
->irqs
.ded
, mci
);
1372 dcr_unmap(pdata
->dcr_host
, SDRAM_DCR_RESOURCE_LEN
);
1374 edac_mc_del_mc(mci
->dev
);
1381 * ppc4xx_edac_opstate_init - initialize EDAC reporting method
1383 * This routine ensures that the EDAC memory controller reporting
1384 * method is mapped to a sane value as the EDAC core defines the value
1385 * to EDAC_OPSTATE_INVAL by default. We don't call the global
1386 * opstate_init as that defaults to polling and we want interrupt as
1389 static inline void __init
1390 ppc4xx_edac_opstate_init(void)
1392 switch (edac_op_state
) {
1393 case EDAC_OPSTATE_POLL
:
1394 case EDAC_OPSTATE_INT
:
1397 edac_op_state
= EDAC_OPSTATE_INT
;
1401 ppc4xx_edac_printk(KERN_INFO
, "Reporting type: %s\n",
1402 ((edac_op_state
== EDAC_OPSTATE_POLL
) ?
1403 EDAC_OPSTATE_POLL_STR
:
1404 ((edac_op_state
== EDAC_OPSTATE_INT
) ?
1405 EDAC_OPSTATE_INT_STR
:
1406 EDAC_OPSTATE_UNKNOWN_STR
)));
1410 * ppc4xx_edac_init - driver/module insertion entry point
1412 * This routine is the driver/module insertion entry point. It
1413 * initializes the EDAC memory controller reporting state and
1414 * registers the driver as an OpenFirmware device tree platform
1418 ppc4xx_edac_init(void)
1420 ppc4xx_edac_printk(KERN_INFO
, PPC4XX_EDAC_MODULE_REVISION
"\n");
1422 ppc4xx_edac_opstate_init();
1424 return of_register_platform_driver(&ppc4xx_edac_driver
);
1428 * ppc4xx_edac_exit - driver/module removal entry point
1430 * This routine is the driver/module removal entry point. It
1431 * unregisters the driver as an OpenFirmware device tree platform
1435 ppc4xx_edac_exit(void)
1437 of_unregister_platform_driver(&ppc4xx_edac_driver
);
1440 module_init(ppc4xx_edac_init
);
1441 module_exit(ppc4xx_edac_exit
);
1443 MODULE_LICENSE("GPL v2");
1444 MODULE_AUTHOR("Grant Erickson <gerickson@nuovations.com>");
1445 MODULE_DESCRIPTION("EDAC MC Driver for the PPC4xx IBM DDR2 Memory Controller");
1446 module_param(edac_op_state
, int, 0444);
1447 MODULE_PARM_DESC(edac_op_state
, "EDAC Error Reporting State: "
1448 "0=" EDAC_OPSTATE_POLL_STR
", 2=" EDAC_OPSTATE_INT_STR
);