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