Commit | Line | Data |
---|---|---|
2a9036af HC |
1 | /* |
2 | * cpc925_edac.c, EDAC driver for IBM CPC925 Bridge and Memory Controller. | |
3 | * | |
4 | * Copyright (c) 2008 Wind River Systems, Inc. | |
5 | * | |
6 | * Authors: Cao Qingtao <qingtao.cao@windriver.com> | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License version 2 as | |
10 | * published by the Free Software Foundation. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
15 | * See the GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with this program; if not, write to the Free Software | |
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
20 | */ | |
21 | ||
22 | #include <linux/module.h> | |
23 | #include <linux/init.h> | |
24 | #include <linux/io.h> | |
25 | #include <linux/edac.h> | |
26 | #include <linux/of.h> | |
27 | #include <linux/platform_device.h> | |
5a0e3ad6 | 28 | #include <linux/gfp.h> |
2a9036af HC |
29 | |
30 | #include "edac_core.h" | |
31 | #include "edac_module.h" | |
32 | ||
152ba394 | 33 | #define CPC925_EDAC_REVISION " Ver: 1.0.0" |
2a9036af HC |
34 | #define CPC925_EDAC_MOD_STR "cpc925_edac" |
35 | ||
36 | #define cpc925_printk(level, fmt, arg...) \ | |
37 | edac_printk(level, "CPC925", fmt, ##arg) | |
38 | ||
39 | #define cpc925_mc_printk(mci, level, fmt, arg...) \ | |
40 | edac_mc_chipset_printk(mci, level, "CPC925", fmt, ##arg) | |
41 | ||
42 | /* | |
43 | * CPC925 registers are of 32 bits with bit0 defined at the | |
44 | * most significant bit and bit31 at that of least significant. | |
45 | */ | |
46 | #define CPC925_BITS_PER_REG 32 | |
47 | #define CPC925_BIT(nr) (1UL << (CPC925_BITS_PER_REG - 1 - nr)) | |
48 | ||
49 | /* | |
50 | * EDAC device names for the error detections of | |
51 | * CPU Interface and Hypertransport Link. | |
52 | */ | |
53 | #define CPC925_CPU_ERR_DEV "cpu" | |
54 | #define CPC925_HT_LINK_DEV "htlink" | |
55 | ||
56 | /* Suppose DDR Refresh cycle is 15.6 microsecond */ | |
57 | #define CPC925_REF_FREQ 0xFA69 | |
58 | #define CPC925_SCRUB_BLOCK_SIZE 64 /* bytes */ | |
59 | #define CPC925_NR_CSROWS 8 | |
60 | ||
61 | /* | |
62 | * All registers and bits definitions are taken from | |
63 | * "CPC925 Bridge and Memory Controller User Manual, SA14-2761-02". | |
64 | */ | |
65 | ||
66 | /* | |
67 | * CPU and Memory Controller Registers | |
68 | */ | |
69 | /************************************************************ | |
70 | * Processor Interface Exception Mask Register (APIMASK) | |
71 | ************************************************************/ | |
72 | #define REG_APIMASK_OFFSET 0x30070 | |
73 | enum apimask_bits { | |
74 | APIMASK_DART = CPC925_BIT(0), /* DART Exception */ | |
75 | APIMASK_ADI0 = CPC925_BIT(1), /* Handshake Error on PI0_ADI */ | |
76 | APIMASK_ADI1 = CPC925_BIT(2), /* Handshake Error on PI1_ADI */ | |
77 | APIMASK_STAT = CPC925_BIT(3), /* Status Exception */ | |
78 | APIMASK_DERR = CPC925_BIT(4), /* Data Error Exception */ | |
79 | APIMASK_ADRS0 = CPC925_BIT(5), /* Addressing Exception on PI0 */ | |
80 | APIMASK_ADRS1 = CPC925_BIT(6), /* Addressing Exception on PI1 */ | |
81 | /* BIT(7) Reserved */ | |
82 | APIMASK_ECC_UE_H = CPC925_BIT(8), /* UECC upper */ | |
83 | APIMASK_ECC_CE_H = CPC925_BIT(9), /* CECC upper */ | |
84 | APIMASK_ECC_UE_L = CPC925_BIT(10), /* UECC lower */ | |
85 | APIMASK_ECC_CE_L = CPC925_BIT(11), /* CECC lower */ | |
86 | ||
87 | CPU_MASK_ENABLE = (APIMASK_DART | APIMASK_ADI0 | APIMASK_ADI1 | | |
88 | APIMASK_STAT | APIMASK_DERR | APIMASK_ADRS0 | | |
89 | APIMASK_ADRS1), | |
90 | ECC_MASK_ENABLE = (APIMASK_ECC_UE_H | APIMASK_ECC_CE_H | | |
91 | APIMASK_ECC_UE_L | APIMASK_ECC_CE_L), | |
92 | }; | |
ce395088 | 93 | #define APIMASK_ADI(n) CPC925_BIT(((n)+1)) |
2a9036af HC |
94 | |
95 | /************************************************************ | |
96 | * Processor Interface Exception Register (APIEXCP) | |
97 | ************************************************************/ | |
98 | #define REG_APIEXCP_OFFSET 0x30060 | |
99 | enum apiexcp_bits { | |
100 | APIEXCP_DART = CPC925_BIT(0), /* DART Exception */ | |
101 | APIEXCP_ADI0 = CPC925_BIT(1), /* Handshake Error on PI0_ADI */ | |
102 | APIEXCP_ADI1 = CPC925_BIT(2), /* Handshake Error on PI1_ADI */ | |
103 | APIEXCP_STAT = CPC925_BIT(3), /* Status Exception */ | |
104 | APIEXCP_DERR = CPC925_BIT(4), /* Data Error Exception */ | |
105 | APIEXCP_ADRS0 = CPC925_BIT(5), /* Addressing Exception on PI0 */ | |
106 | APIEXCP_ADRS1 = CPC925_BIT(6), /* Addressing Exception on PI1 */ | |
107 | /* BIT(7) Reserved */ | |
108 | APIEXCP_ECC_UE_H = CPC925_BIT(8), /* UECC upper */ | |
109 | APIEXCP_ECC_CE_H = CPC925_BIT(9), /* CECC upper */ | |
110 | APIEXCP_ECC_UE_L = CPC925_BIT(10), /* UECC lower */ | |
111 | APIEXCP_ECC_CE_L = CPC925_BIT(11), /* CECC lower */ | |
112 | ||
113 | CPU_EXCP_DETECTED = (APIEXCP_DART | APIEXCP_ADI0 | APIEXCP_ADI1 | | |
114 | APIEXCP_STAT | APIEXCP_DERR | APIEXCP_ADRS0 | | |
115 | APIEXCP_ADRS1), | |
116 | UECC_EXCP_DETECTED = (APIEXCP_ECC_UE_H | APIEXCP_ECC_UE_L), | |
117 | CECC_EXCP_DETECTED = (APIEXCP_ECC_CE_H | APIEXCP_ECC_CE_L), | |
118 | ECC_EXCP_DETECTED = (UECC_EXCP_DETECTED | CECC_EXCP_DETECTED), | |
119 | }; | |
120 | ||
121 | /************************************************************ | |
122 | * Memory Bus Configuration Register (MBCR) | |
123 | ************************************************************/ | |
124 | #define REG_MBCR_OFFSET 0x2190 | |
125 | #define MBCR_64BITCFG_SHIFT 23 | |
126 | #define MBCR_64BITCFG_MASK (1UL << MBCR_64BITCFG_SHIFT) | |
127 | #define MBCR_64BITBUS_SHIFT 22 | |
128 | #define MBCR_64BITBUS_MASK (1UL << MBCR_64BITBUS_SHIFT) | |
129 | ||
130 | /************************************************************ | |
131 | * Memory Bank Mode Register (MBMR) | |
132 | ************************************************************/ | |
133 | #define REG_MBMR_OFFSET 0x21C0 | |
134 | #define MBMR_MODE_MAX_VALUE 0xF | |
135 | #define MBMR_MODE_SHIFT 25 | |
136 | #define MBMR_MODE_MASK (MBMR_MODE_MAX_VALUE << MBMR_MODE_SHIFT) | |
137 | #define MBMR_BBA_SHIFT 24 | |
138 | #define MBMR_BBA_MASK (1UL << MBMR_BBA_SHIFT) | |
139 | ||
140 | /************************************************************ | |
141 | * Memory Bank Boundary Address Register (MBBAR) | |
142 | ************************************************************/ | |
143 | #define REG_MBBAR_OFFSET 0x21D0 | |
144 | #define MBBAR_BBA_MAX_VALUE 0xFF | |
145 | #define MBBAR_BBA_SHIFT 24 | |
146 | #define MBBAR_BBA_MASK (MBBAR_BBA_MAX_VALUE << MBBAR_BBA_SHIFT) | |
147 | ||
148 | /************************************************************ | |
149 | * Memory Scrub Control Register (MSCR) | |
150 | ************************************************************/ | |
151 | #define REG_MSCR_OFFSET 0x2400 | |
152 | #define MSCR_SCRUB_MOD_MASK 0xC0000000 /* scrub_mod - bit0:1*/ | |
153 | #define MSCR_BACKGR_SCRUB 0x40000000 /* 01 */ | |
154 | #define MSCR_SI_SHIFT 16 /* si - bit8:15*/ | |
155 | #define MSCR_SI_MAX_VALUE 0xFF | |
156 | #define MSCR_SI_MASK (MSCR_SI_MAX_VALUE << MSCR_SI_SHIFT) | |
157 | ||
158 | /************************************************************ | |
159 | * Memory Scrub Range Start Register (MSRSR) | |
160 | ************************************************************/ | |
161 | #define REG_MSRSR_OFFSET 0x2410 | |
162 | ||
163 | /************************************************************ | |
164 | * Memory Scrub Range End Register (MSRER) | |
165 | ************************************************************/ | |
166 | #define REG_MSRER_OFFSET 0x2420 | |
167 | ||
168 | /************************************************************ | |
169 | * Memory Scrub Pattern Register (MSPR) | |
170 | ************************************************************/ | |
171 | #define REG_MSPR_OFFSET 0x2430 | |
172 | ||
173 | /************************************************************ | |
174 | * Memory Check Control Register (MCCR) | |
175 | ************************************************************/ | |
176 | #define REG_MCCR_OFFSET 0x2440 | |
177 | enum mccr_bits { | |
178 | MCCR_ECC_EN = CPC925_BIT(0), /* ECC high and low check */ | |
179 | }; | |
180 | ||
181 | /************************************************************ | |
182 | * Memory Check Range End Register (MCRER) | |
183 | ************************************************************/ | |
184 | #define REG_MCRER_OFFSET 0x2450 | |
185 | ||
186 | /************************************************************ | |
187 | * Memory Error Address Register (MEAR) | |
188 | ************************************************************/ | |
189 | #define REG_MEAR_OFFSET 0x2460 | |
190 | #define MEAR_BCNT_MAX_VALUE 0x3 | |
191 | #define MEAR_BCNT_SHIFT 30 | |
192 | #define MEAR_BCNT_MASK (MEAR_BCNT_MAX_VALUE << MEAR_BCNT_SHIFT) | |
193 | #define MEAR_RANK_MAX_VALUE 0x7 | |
194 | #define MEAR_RANK_SHIFT 27 | |
195 | #define MEAR_RANK_MASK (MEAR_RANK_MAX_VALUE << MEAR_RANK_SHIFT) | |
196 | #define MEAR_COL_MAX_VALUE 0x7FF | |
197 | #define MEAR_COL_SHIFT 16 | |
198 | #define MEAR_COL_MASK (MEAR_COL_MAX_VALUE << MEAR_COL_SHIFT) | |
199 | #define MEAR_BANK_MAX_VALUE 0x3 | |
200 | #define MEAR_BANK_SHIFT 14 | |
201 | #define MEAR_BANK_MASK (MEAR_BANK_MAX_VALUE << MEAR_BANK_SHIFT) | |
202 | #define MEAR_ROW_MASK 0x00003FFF | |
203 | ||
204 | /************************************************************ | |
205 | * Memory Error Syndrome Register (MESR) | |
206 | ************************************************************/ | |
207 | #define REG_MESR_OFFSET 0x2470 | |
208 | #define MESR_ECC_SYN_H_MASK 0xFF00 | |
209 | #define MESR_ECC_SYN_L_MASK 0x00FF | |
210 | ||
211 | /************************************************************ | |
212 | * Memory Mode Control Register (MMCR) | |
213 | ************************************************************/ | |
214 | #define REG_MMCR_OFFSET 0x2500 | |
215 | enum mmcr_bits { | |
216 | MMCR_REG_DIMM_MODE = CPC925_BIT(3), | |
217 | }; | |
218 | ||
219 | /* | |
220 | * HyperTransport Link Registers | |
221 | */ | |
222 | /************************************************************ | |
223 | * Error Handling/Enumeration Scratch Pad Register (ERRCTRL) | |
224 | ************************************************************/ | |
225 | #define REG_ERRCTRL_OFFSET 0x70140 | |
226 | enum errctrl_bits { /* nonfatal interrupts for */ | |
227 | ERRCTRL_SERR_NF = CPC925_BIT(0), /* system error */ | |
228 | ERRCTRL_CRC_NF = CPC925_BIT(1), /* CRC error */ | |
229 | ERRCTRL_RSP_NF = CPC925_BIT(2), /* Response error */ | |
230 | ERRCTRL_EOC_NF = CPC925_BIT(3), /* End-Of-Chain error */ | |
231 | ERRCTRL_OVF_NF = CPC925_BIT(4), /* Overflow error */ | |
232 | ERRCTRL_PROT_NF = CPC925_BIT(5), /* Protocol error */ | |
233 | ||
234 | ERRCTRL_RSP_ERR = CPC925_BIT(6), /* Response error received */ | |
235 | ERRCTRL_CHN_FAL = CPC925_BIT(7), /* Sync flooding detected */ | |
236 | ||
237 | HT_ERRCTRL_ENABLE = (ERRCTRL_SERR_NF | ERRCTRL_CRC_NF | | |
238 | ERRCTRL_RSP_NF | ERRCTRL_EOC_NF | | |
239 | ERRCTRL_OVF_NF | ERRCTRL_PROT_NF), | |
240 | HT_ERRCTRL_DETECTED = (ERRCTRL_RSP_ERR | ERRCTRL_CHN_FAL), | |
241 | }; | |
242 | ||
243 | /************************************************************ | |
244 | * Link Configuration and Link Control Register (LINKCTRL) | |
245 | ************************************************************/ | |
246 | #define REG_LINKCTRL_OFFSET 0x70110 | |
247 | enum linkctrl_bits { | |
248 | LINKCTRL_CRC_ERR = (CPC925_BIT(22) | CPC925_BIT(23)), | |
249 | LINKCTRL_LINK_FAIL = CPC925_BIT(27), | |
250 | ||
251 | HT_LINKCTRL_DETECTED = (LINKCTRL_CRC_ERR | LINKCTRL_LINK_FAIL), | |
252 | }; | |
253 | ||
254 | /************************************************************ | |
255 | * Link FreqCap/Error/Freq/Revision ID Register (LINKERR) | |
256 | ************************************************************/ | |
257 | #define REG_LINKERR_OFFSET 0x70120 | |
258 | enum linkerr_bits { | |
259 | LINKERR_EOC_ERR = CPC925_BIT(17), /* End-Of-Chain error */ | |
260 | LINKERR_OVF_ERR = CPC925_BIT(18), /* Receive Buffer Overflow */ | |
261 | LINKERR_PROT_ERR = CPC925_BIT(19), /* Protocol error */ | |
262 | ||
263 | HT_LINKERR_DETECTED = (LINKERR_EOC_ERR | LINKERR_OVF_ERR | | |
264 | LINKERR_PROT_ERR), | |
265 | }; | |
266 | ||
267 | /************************************************************ | |
268 | * Bridge Control Register (BRGCTRL) | |
269 | ************************************************************/ | |
270 | #define REG_BRGCTRL_OFFSET 0x70300 | |
271 | enum brgctrl_bits { | |
272 | BRGCTRL_DETSERR = CPC925_BIT(0), /* SERR on Secondary Bus */ | |
273 | BRGCTRL_SECBUSRESET = CPC925_BIT(9), /* Secondary Bus Reset */ | |
274 | }; | |
275 | ||
276 | /* Private structure for edac memory controller */ | |
277 | struct cpc925_mc_pdata { | |
278 | void __iomem *vbase; | |
279 | unsigned long total_mem; | |
280 | const char *name; | |
281 | int edac_idx; | |
282 | }; | |
283 | ||
284 | /* Private structure for common edac device */ | |
285 | struct cpc925_dev_info { | |
286 | void __iomem *vbase; | |
287 | struct platform_device *pdev; | |
288 | char *ctl_name; | |
289 | int edac_idx; | |
290 | struct edac_device_ctl_info *edac_dev; | |
291 | void (*init)(struct cpc925_dev_info *dev_info); | |
292 | void (*exit)(struct cpc925_dev_info *dev_info); | |
293 | void (*check)(struct edac_device_ctl_info *edac_dev); | |
294 | }; | |
295 | ||
296 | /* Get total memory size from Open Firmware DTB */ | |
297 | static void get_total_mem(struct cpc925_mc_pdata *pdata) | |
298 | { | |
299 | struct device_node *np = NULL; | |
300 | const unsigned int *reg, *reg_end; | |
301 | int len, sw, aw; | |
302 | unsigned long start, size; | |
303 | ||
304 | np = of_find_node_by_type(NULL, "memory"); | |
305 | if (!np) | |
306 | return; | |
307 | ||
308 | aw = of_n_addr_cells(np); | |
309 | sw = of_n_size_cells(np); | |
310 | reg = (const unsigned int *)of_get_property(np, "reg", &len); | |
311 | reg_end = reg + len/4; | |
312 | ||
313 | pdata->total_mem = 0; | |
314 | do { | |
315 | start = of_read_number(reg, aw); | |
316 | reg += aw; | |
317 | size = of_read_number(reg, sw); | |
318 | reg += sw; | |
319 | debugf1("%s: start 0x%lx, size 0x%lx\n", __func__, | |
320 | start, size); | |
321 | pdata->total_mem += size; | |
322 | } while (reg < reg_end); | |
323 | ||
324 | of_node_put(np); | |
325 | debugf0("%s: total_mem 0x%lx\n", __func__, pdata->total_mem); | |
326 | } | |
327 | ||
328 | static void cpc925_init_csrows(struct mem_ctl_info *mci) | |
329 | { | |
330 | struct cpc925_mc_pdata *pdata = mci->pvt_info; | |
331 | struct csrow_info *csrow; | |
084a4fcc MCC |
332 | struct dimm_info *dimm; |
333 | int index, j; | |
2a9036af | 334 | u32 mbmr, mbbar, bba; |
a895bf8b | 335 | unsigned long row_size, nr_pages, last_nr_pages = 0; |
2a9036af HC |
336 | |
337 | get_total_mem(pdata); | |
338 | ||
339 | for (index = 0; index < mci->nr_csrows; index++) { | |
340 | mbmr = __raw_readl(pdata->vbase + REG_MBMR_OFFSET + | |
341 | 0x20 * index); | |
342 | mbbar = __raw_readl(pdata->vbase + REG_MBBAR_OFFSET + | |
343 | 0x20 + index); | |
344 | bba = (((mbmr & MBMR_BBA_MASK) >> MBMR_BBA_SHIFT) << 8) | | |
345 | ((mbbar & MBBAR_BBA_MASK) >> MBBAR_BBA_SHIFT); | |
346 | ||
347 | if (bba == 0) | |
348 | continue; /* not populated */ | |
349 | ||
350 | csrow = &mci->csrows[index]; | |
351 | ||
352 | row_size = bba * (1UL << 28); /* 256M */ | |
353 | csrow->first_page = last_nr_pages; | |
a895bf8b MCC |
354 | nr_pages = row_size >> PAGE_SHIFT; |
355 | csrow->last_page = csrow->first_page + nr_pages - 1; | |
2a9036af HC |
356 | last_nr_pages = csrow->last_page + 1; |
357 | ||
084a4fcc MCC |
358 | for (j = 0; j < csrow->nr_channels; j++) { |
359 | dimm = csrow->channels[j].dimm; | |
a895bf8b MCC |
360 | |
361 | dimm->nr_pages = nr_pages / csrow->nr_channels; | |
084a4fcc MCC |
362 | dimm->mtype = MEM_RDDR; |
363 | dimm->edac_mode = EDAC_SECDED; | |
364 | ||
365 | switch (csrow->nr_channels) { | |
366 | case 1: /* Single channel */ | |
367 | dimm->grain = 32; /* four-beat burst of 32 bytes */ | |
368 | break; | |
369 | case 2: /* Dual channel */ | |
370 | default: | |
371 | dimm->grain = 64; /* four-beat burst of 64 bytes */ | |
372 | break; | |
373 | } | |
374 | ||
375 | switch ((mbmr & MBMR_MODE_MASK) >> MBMR_MODE_SHIFT) { | |
376 | case 6: /* 0110, no way to differentiate X8 VS X16 */ | |
377 | case 5: /* 0101 */ | |
378 | case 8: /* 1000 */ | |
379 | dimm->dtype = DEV_X16; | |
380 | break; | |
381 | case 7: /* 0111 */ | |
382 | case 9: /* 1001 */ | |
383 | dimm->dtype = DEV_X8; | |
384 | break; | |
385 | default: | |
386 | dimm->dtype = DEV_UNKNOWN; | |
387 | break; | |
388 | } | |
2a9036af HC |
389 | } |
390 | } | |
391 | } | |
392 | ||
393 | /* Enable memory controller ECC detection */ | |
394 | static void cpc925_mc_init(struct mem_ctl_info *mci) | |
395 | { | |
396 | struct cpc925_mc_pdata *pdata = mci->pvt_info; | |
397 | u32 apimask; | |
398 | u32 mccr; | |
399 | ||
400 | /* Enable various ECC error exceptions */ | |
401 | apimask = __raw_readl(pdata->vbase + REG_APIMASK_OFFSET); | |
402 | if ((apimask & ECC_MASK_ENABLE) == 0) { | |
403 | apimask |= ECC_MASK_ENABLE; | |
404 | __raw_writel(apimask, pdata->vbase + REG_APIMASK_OFFSET); | |
405 | } | |
406 | ||
407 | /* Enable ECC detection */ | |
408 | mccr = __raw_readl(pdata->vbase + REG_MCCR_OFFSET); | |
409 | if ((mccr & MCCR_ECC_EN) == 0) { | |
410 | mccr |= MCCR_ECC_EN; | |
411 | __raw_writel(mccr, pdata->vbase + REG_MCCR_OFFSET); | |
412 | } | |
413 | } | |
414 | ||
415 | /* Disable memory controller ECC detection */ | |
416 | static void cpc925_mc_exit(struct mem_ctl_info *mci) | |
417 | { | |
418 | /* | |
419 | * WARNING: | |
420 | * We are supposed to clear the ECC error detection bits, | |
421 | * and it will be no problem to do so. However, once they | |
422 | * are cleared here if we want to re-install CPC925 EDAC | |
423 | * module later, setting them up in cpc925_mc_init() will | |
424 | * trigger machine check exception. | |
425 | * Also, it's ok to leave ECC error detection bits enabled, | |
426 | * since they are reset to 1 by default or by boot loader. | |
427 | */ | |
428 | ||
429 | return; | |
430 | } | |
431 | ||
432 | /* | |
433 | * Revert DDR column/row/bank addresses into page frame number and | |
434 | * offset in page. | |
435 | * | |
436 | * Suppose memory mode is 0x0111(128-bit mode, identical DIMM pairs), | |
437 | * physical address(PA) bits to column address(CA) bits mappings are: | |
438 | * CA 0 1 2 3 4 5 6 7 8 9 10 | |
439 | * PA 59 58 57 56 55 54 53 52 51 50 49 | |
440 | * | |
441 | * physical address(PA) bits to bank address(BA) bits mappings are: | |
442 | * BA 0 1 | |
443 | * PA 43 44 | |
444 | * | |
445 | * physical address(PA) bits to row address(RA) bits mappings are: | |
446 | * RA 0 1 2 3 4 5 6 7 8 9 10 11 12 | |
447 | * PA 36 35 34 48 47 46 45 40 41 42 39 38 37 | |
448 | */ | |
449 | static void cpc925_mc_get_pfn(struct mem_ctl_info *mci, u32 mear, | |
450 | unsigned long *pfn, unsigned long *offset, int *csrow) | |
451 | { | |
452 | u32 bcnt, rank, col, bank, row; | |
453 | u32 c; | |
454 | unsigned long pa; | |
455 | int i; | |
456 | ||
457 | bcnt = (mear & MEAR_BCNT_MASK) >> MEAR_BCNT_SHIFT; | |
458 | rank = (mear & MEAR_RANK_MASK) >> MEAR_RANK_SHIFT; | |
459 | col = (mear & MEAR_COL_MASK) >> MEAR_COL_SHIFT; | |
460 | bank = (mear & MEAR_BANK_MASK) >> MEAR_BANK_SHIFT; | |
461 | row = mear & MEAR_ROW_MASK; | |
462 | ||
463 | *csrow = rank; | |
464 | ||
465 | #ifdef CONFIG_EDAC_DEBUG | |
466 | if (mci->csrows[rank].first_page == 0) { | |
467 | cpc925_mc_printk(mci, KERN_ERR, "ECC occurs in a " | |
468 | "non-populated csrow, broken hardware?\n"); | |
469 | return; | |
470 | } | |
471 | #endif | |
472 | ||
473 | /* Revert csrow number */ | |
474 | pa = mci->csrows[rank].first_page << PAGE_SHIFT; | |
475 | ||
476 | /* Revert column address */ | |
477 | col += bcnt; | |
478 | for (i = 0; i < 11; i++) { | |
479 | c = col & 0x1; | |
480 | col >>= 1; | |
481 | pa |= c << (14 - i); | |
482 | } | |
483 | ||
484 | /* Revert bank address */ | |
485 | pa |= bank << 19; | |
486 | ||
487 | /* Revert row address, in 4 steps */ | |
488 | for (i = 0; i < 3; i++) { | |
489 | c = row & 0x1; | |
490 | row >>= 1; | |
491 | pa |= c << (26 - i); | |
492 | } | |
493 | ||
494 | for (i = 0; i < 3; i++) { | |
495 | c = row & 0x1; | |
496 | row >>= 1; | |
497 | pa |= c << (21 + i); | |
498 | } | |
499 | ||
500 | for (i = 0; i < 4; i++) { | |
501 | c = row & 0x1; | |
502 | row >>= 1; | |
503 | pa |= c << (18 - i); | |
504 | } | |
505 | ||
506 | for (i = 0; i < 3; i++) { | |
507 | c = row & 0x1; | |
508 | row >>= 1; | |
509 | pa |= c << (29 - i); | |
510 | } | |
511 | ||
512 | *offset = pa & (PAGE_SIZE - 1); | |
513 | *pfn = pa >> PAGE_SHIFT; | |
514 | ||
515 | debugf0("%s: ECC physical address 0x%lx\n", __func__, pa); | |
516 | } | |
517 | ||
518 | static int cpc925_mc_find_channel(struct mem_ctl_info *mci, u16 syndrome) | |
519 | { | |
520 | if ((syndrome & MESR_ECC_SYN_H_MASK) == 0) | |
521 | return 0; | |
522 | ||
523 | if ((syndrome & MESR_ECC_SYN_L_MASK) == 0) | |
524 | return 1; | |
525 | ||
526 | cpc925_mc_printk(mci, KERN_INFO, "Unexpected syndrome value: 0x%x\n", | |
527 | syndrome); | |
528 | return 1; | |
529 | } | |
530 | ||
531 | /* Check memory controller registers for ECC errors */ | |
532 | static void cpc925_mc_check(struct mem_ctl_info *mci) | |
533 | { | |
534 | struct cpc925_mc_pdata *pdata = mci->pvt_info; | |
535 | u32 apiexcp; | |
536 | u32 mear; | |
537 | u32 mesr; | |
538 | u16 syndrome; | |
539 | unsigned long pfn = 0, offset = 0; | |
540 | int csrow = 0, channel = 0; | |
541 | ||
542 | /* APIEXCP is cleared when read */ | |
543 | apiexcp = __raw_readl(pdata->vbase + REG_APIEXCP_OFFSET); | |
544 | if ((apiexcp & ECC_EXCP_DETECTED) == 0) | |
545 | return; | |
546 | ||
547 | mesr = __raw_readl(pdata->vbase + REG_MESR_OFFSET); | |
548 | syndrome = mesr | (MESR_ECC_SYN_H_MASK | MESR_ECC_SYN_L_MASK); | |
549 | ||
550 | mear = __raw_readl(pdata->vbase + REG_MEAR_OFFSET); | |
551 | ||
552 | /* Revert column/row addresses into page frame number, etc */ | |
553 | cpc925_mc_get_pfn(mci, mear, &pfn, &offset, &csrow); | |
554 | ||
555 | if (apiexcp & CECC_EXCP_DETECTED) { | |
556 | cpc925_mc_printk(mci, KERN_INFO, "DRAM CECC Fault\n"); | |
557 | channel = cpc925_mc_find_channel(mci, syndrome); | |
558 | edac_mc_handle_ce(mci, pfn, offset, syndrome, | |
559 | csrow, channel, mci->ctl_name); | |
560 | } | |
561 | ||
562 | if (apiexcp & UECC_EXCP_DETECTED) { | |
563 | cpc925_mc_printk(mci, KERN_INFO, "DRAM UECC Fault\n"); | |
564 | edac_mc_handle_ue(mci, pfn, offset, csrow, mci->ctl_name); | |
565 | } | |
566 | ||
567 | cpc925_mc_printk(mci, KERN_INFO, "Dump registers:\n"); | |
568 | cpc925_mc_printk(mci, KERN_INFO, "APIMASK 0x%08x\n", | |
569 | __raw_readl(pdata->vbase + REG_APIMASK_OFFSET)); | |
570 | cpc925_mc_printk(mci, KERN_INFO, "APIEXCP 0x%08x\n", | |
571 | apiexcp); | |
572 | cpc925_mc_printk(mci, KERN_INFO, "Mem Scrub Ctrl 0x%08x\n", | |
573 | __raw_readl(pdata->vbase + REG_MSCR_OFFSET)); | |
574 | cpc925_mc_printk(mci, KERN_INFO, "Mem Scrub Rge Start 0x%08x\n", | |
575 | __raw_readl(pdata->vbase + REG_MSRSR_OFFSET)); | |
576 | cpc925_mc_printk(mci, KERN_INFO, "Mem Scrub Rge End 0x%08x\n", | |
577 | __raw_readl(pdata->vbase + REG_MSRER_OFFSET)); | |
578 | cpc925_mc_printk(mci, KERN_INFO, "Mem Scrub Pattern 0x%08x\n", | |
579 | __raw_readl(pdata->vbase + REG_MSPR_OFFSET)); | |
580 | cpc925_mc_printk(mci, KERN_INFO, "Mem Chk Ctrl 0x%08x\n", | |
581 | __raw_readl(pdata->vbase + REG_MCCR_OFFSET)); | |
582 | cpc925_mc_printk(mci, KERN_INFO, "Mem Chk Rge End 0x%08x\n", | |
583 | __raw_readl(pdata->vbase + REG_MCRER_OFFSET)); | |
584 | cpc925_mc_printk(mci, KERN_INFO, "Mem Err Address 0x%08x\n", | |
585 | mesr); | |
586 | cpc925_mc_printk(mci, KERN_INFO, "Mem Err Syndrome 0x%08x\n", | |
587 | syndrome); | |
588 | } | |
589 | ||
590 | /******************** CPU err device********************************/ | |
ce395088 DES |
591 | static u32 cpc925_cpu_mask_disabled(void) |
592 | { | |
593 | struct device_node *cpus; | |
594 | struct device_node *cpunode = NULL; | |
595 | static u32 mask = 0; | |
596 | ||
597 | /* use cached value if available */ | |
598 | if (mask != 0) | |
599 | return mask; | |
600 | ||
601 | mask = APIMASK_ADI0 | APIMASK_ADI1; | |
602 | ||
603 | cpus = of_find_node_by_path("/cpus"); | |
604 | if (cpus == NULL) { | |
605 | cpc925_printk(KERN_DEBUG, "No /cpus node !\n"); | |
606 | return 0; | |
607 | } | |
608 | ||
609 | while ((cpunode = of_get_next_child(cpus, cpunode)) != NULL) { | |
610 | const u32 *reg = of_get_property(cpunode, "reg", NULL); | |
611 | ||
612 | if (strcmp(cpunode->type, "cpu")) { | |
613 | cpc925_printk(KERN_ERR, "Not a cpu node in /cpus: %s\n", cpunode->name); | |
614 | continue; | |
615 | } | |
616 | ||
617 | if (reg == NULL || *reg > 2) { | |
618 | cpc925_printk(KERN_ERR, "Bad reg value at %s\n", cpunode->full_name); | |
619 | continue; | |
620 | } | |
621 | ||
622 | mask &= ~APIMASK_ADI(*reg); | |
623 | } | |
624 | ||
625 | if (mask != (APIMASK_ADI0 | APIMASK_ADI1)) { | |
626 | /* We assume that each CPU sits on it's own PI and that | |
627 | * for present CPUs the reg property equals to the PI | |
628 | * interface id */ | |
629 | cpc925_printk(KERN_WARNING, | |
630 | "Assuming PI id is equal to CPU MPIC id!\n"); | |
631 | } | |
632 | ||
633 | of_node_put(cpunode); | |
634 | of_node_put(cpus); | |
635 | ||
636 | return mask; | |
637 | } | |
638 | ||
2a9036af HC |
639 | /* Enable CPU Errors detection */ |
640 | static void cpc925_cpu_init(struct cpc925_dev_info *dev_info) | |
641 | { | |
642 | u32 apimask; | |
ce395088 | 643 | u32 cpumask; |
2a9036af HC |
644 | |
645 | apimask = __raw_readl(dev_info->vbase + REG_APIMASK_OFFSET); | |
ce395088 DES |
646 | |
647 | cpumask = cpc925_cpu_mask_disabled(); | |
648 | if (apimask & cpumask) { | |
649 | cpc925_printk(KERN_WARNING, "CPU(s) not present, " | |
650 | "but enabled in APIMASK, disabling\n"); | |
651 | apimask &= ~cpumask; | |
2a9036af | 652 | } |
ce395088 DES |
653 | |
654 | if ((apimask & CPU_MASK_ENABLE) == 0) | |
655 | apimask |= CPU_MASK_ENABLE; | |
656 | ||
657 | __raw_writel(apimask, dev_info->vbase + REG_APIMASK_OFFSET); | |
2a9036af HC |
658 | } |
659 | ||
660 | /* Disable CPU Errors detection */ | |
661 | static void cpc925_cpu_exit(struct cpc925_dev_info *dev_info) | |
662 | { | |
663 | /* | |
664 | * WARNING: | |
665 | * We are supposed to clear the CPU error detection bits, | |
666 | * and it will be no problem to do so. However, once they | |
667 | * are cleared here if we want to re-install CPC925 EDAC | |
668 | * module later, setting them up in cpc925_cpu_init() will | |
669 | * trigger machine check exception. | |
670 | * Also, it's ok to leave CPU error detection bits enabled, | |
671 | * since they are reset to 1 by default. | |
672 | */ | |
673 | ||
674 | return; | |
675 | } | |
676 | ||
677 | /* Check for CPU Errors */ | |
678 | static void cpc925_cpu_check(struct edac_device_ctl_info *edac_dev) | |
679 | { | |
680 | struct cpc925_dev_info *dev_info = edac_dev->pvt_info; | |
681 | u32 apiexcp; | |
682 | u32 apimask; | |
683 | ||
684 | /* APIEXCP is cleared when read */ | |
685 | apiexcp = __raw_readl(dev_info->vbase + REG_APIEXCP_OFFSET); | |
686 | if ((apiexcp & CPU_EXCP_DETECTED) == 0) | |
687 | return; | |
688 | ||
ce395088 DES |
689 | if ((apiexcp & ~cpc925_cpu_mask_disabled()) == 0) |
690 | return; | |
691 | ||
2a9036af HC |
692 | apimask = __raw_readl(dev_info->vbase + REG_APIMASK_OFFSET); |
693 | cpc925_printk(KERN_INFO, "Processor Interface Fault\n" | |
694 | "Processor Interface register dump:\n"); | |
695 | cpc925_printk(KERN_INFO, "APIMASK 0x%08x\n", apimask); | |
696 | cpc925_printk(KERN_INFO, "APIEXCP 0x%08x\n", apiexcp); | |
697 | ||
698 | edac_device_handle_ue(edac_dev, 0, 0, edac_dev->ctl_name); | |
699 | } | |
700 | ||
701 | /******************** HT Link err device****************************/ | |
702 | /* Enable HyperTransport Link Error detection */ | |
703 | static void cpc925_htlink_init(struct cpc925_dev_info *dev_info) | |
704 | { | |
705 | u32 ht_errctrl; | |
706 | ||
707 | ht_errctrl = __raw_readl(dev_info->vbase + REG_ERRCTRL_OFFSET); | |
708 | if ((ht_errctrl & HT_ERRCTRL_ENABLE) == 0) { | |
709 | ht_errctrl |= HT_ERRCTRL_ENABLE; | |
710 | __raw_writel(ht_errctrl, dev_info->vbase + REG_ERRCTRL_OFFSET); | |
711 | } | |
712 | } | |
713 | ||
714 | /* Disable HyperTransport Link Error detection */ | |
715 | static void cpc925_htlink_exit(struct cpc925_dev_info *dev_info) | |
716 | { | |
717 | u32 ht_errctrl; | |
718 | ||
719 | ht_errctrl = __raw_readl(dev_info->vbase + REG_ERRCTRL_OFFSET); | |
720 | ht_errctrl &= ~HT_ERRCTRL_ENABLE; | |
721 | __raw_writel(ht_errctrl, dev_info->vbase + REG_ERRCTRL_OFFSET); | |
722 | } | |
723 | ||
724 | /* Check for HyperTransport Link errors */ | |
725 | static void cpc925_htlink_check(struct edac_device_ctl_info *edac_dev) | |
726 | { | |
727 | struct cpc925_dev_info *dev_info = edac_dev->pvt_info; | |
728 | u32 brgctrl = __raw_readl(dev_info->vbase + REG_BRGCTRL_OFFSET); | |
729 | u32 linkctrl = __raw_readl(dev_info->vbase + REG_LINKCTRL_OFFSET); | |
730 | u32 errctrl = __raw_readl(dev_info->vbase + REG_ERRCTRL_OFFSET); | |
731 | u32 linkerr = __raw_readl(dev_info->vbase + REG_LINKERR_OFFSET); | |
732 | ||
733 | if (!((brgctrl & BRGCTRL_DETSERR) || | |
734 | (linkctrl & HT_LINKCTRL_DETECTED) || | |
735 | (errctrl & HT_ERRCTRL_DETECTED) || | |
736 | (linkerr & HT_LINKERR_DETECTED))) | |
737 | return; | |
738 | ||
739 | cpc925_printk(KERN_INFO, "HT Link Fault\n" | |
740 | "HT register dump:\n"); | |
741 | cpc925_printk(KERN_INFO, "Bridge Ctrl 0x%08x\n", | |
742 | brgctrl); | |
743 | cpc925_printk(KERN_INFO, "Link Config Ctrl 0x%08x\n", | |
744 | linkctrl); | |
745 | cpc925_printk(KERN_INFO, "Error Enum and Ctrl 0x%08x\n", | |
746 | errctrl); | |
747 | cpc925_printk(KERN_INFO, "Link Error 0x%08x\n", | |
748 | linkerr); | |
749 | ||
750 | /* Clear by write 1 */ | |
751 | if (brgctrl & BRGCTRL_DETSERR) | |
752 | __raw_writel(BRGCTRL_DETSERR, | |
753 | dev_info->vbase + REG_BRGCTRL_OFFSET); | |
754 | ||
755 | if (linkctrl & HT_LINKCTRL_DETECTED) | |
756 | __raw_writel(HT_LINKCTRL_DETECTED, | |
757 | dev_info->vbase + REG_LINKCTRL_OFFSET); | |
758 | ||
759 | /* Initiate Secondary Bus Reset to clear the chain failure */ | |
760 | if (errctrl & ERRCTRL_CHN_FAL) | |
761 | __raw_writel(BRGCTRL_SECBUSRESET, | |
762 | dev_info->vbase + REG_BRGCTRL_OFFSET); | |
763 | ||
764 | if (errctrl & ERRCTRL_RSP_ERR) | |
765 | __raw_writel(ERRCTRL_RSP_ERR, | |
766 | dev_info->vbase + REG_ERRCTRL_OFFSET); | |
767 | ||
768 | if (linkerr & HT_LINKERR_DETECTED) | |
769 | __raw_writel(HT_LINKERR_DETECTED, | |
770 | dev_info->vbase + REG_LINKERR_OFFSET); | |
771 | ||
772 | edac_device_handle_ce(edac_dev, 0, 0, edac_dev->ctl_name); | |
773 | } | |
774 | ||
775 | static struct cpc925_dev_info cpc925_devs[] = { | |
776 | { | |
777 | .ctl_name = CPC925_CPU_ERR_DEV, | |
778 | .init = cpc925_cpu_init, | |
779 | .exit = cpc925_cpu_exit, | |
780 | .check = cpc925_cpu_check, | |
781 | }, | |
782 | { | |
783 | .ctl_name = CPC925_HT_LINK_DEV, | |
784 | .init = cpc925_htlink_init, | |
785 | .exit = cpc925_htlink_exit, | |
786 | .check = cpc925_htlink_check, | |
787 | }, | |
788 | {0}, /* Terminated by NULL */ | |
789 | }; | |
790 | ||
791 | /* | |
792 | * Add CPU Err detection and HyperTransport Link Err detection | |
793 | * as common "edac_device", they have no corresponding device | |
794 | * nodes in the Open Firmware DTB and we have to add platform | |
795 | * devices for them. Also, they will share the MMIO with that | |
796 | * of memory controller. | |
797 | */ | |
798 | static void cpc925_add_edac_devices(void __iomem *vbase) | |
799 | { | |
800 | struct cpc925_dev_info *dev_info; | |
801 | ||
802 | if (!vbase) { | |
803 | cpc925_printk(KERN_ERR, "MMIO not established yet\n"); | |
804 | return; | |
805 | } | |
806 | ||
807 | for (dev_info = &cpc925_devs[0]; dev_info->init; dev_info++) { | |
808 | dev_info->vbase = vbase; | |
809 | dev_info->pdev = platform_device_register_simple( | |
810 | dev_info->ctl_name, 0, NULL, 0); | |
811 | if (IS_ERR(dev_info->pdev)) { | |
812 | cpc925_printk(KERN_ERR, | |
813 | "Can't register platform device for %s\n", | |
814 | dev_info->ctl_name); | |
815 | continue; | |
816 | } | |
817 | ||
818 | /* | |
819 | * Don't have to allocate private structure but | |
820 | * make use of cpc925_devs[] instead. | |
821 | */ | |
822 | dev_info->edac_idx = edac_device_alloc_index(); | |
823 | dev_info->edac_dev = | |
824 | edac_device_alloc_ctl_info(0, dev_info->ctl_name, | |
825 | 1, NULL, 0, 0, NULL, 0, dev_info->edac_idx); | |
826 | if (!dev_info->edac_dev) { | |
827 | cpc925_printk(KERN_ERR, "No memory for edac device\n"); | |
828 | goto err1; | |
829 | } | |
830 | ||
831 | dev_info->edac_dev->pvt_info = dev_info; | |
832 | dev_info->edac_dev->dev = &dev_info->pdev->dev; | |
833 | dev_info->edac_dev->ctl_name = dev_info->ctl_name; | |
834 | dev_info->edac_dev->mod_name = CPC925_EDAC_MOD_STR; | |
835 | dev_info->edac_dev->dev_name = dev_name(&dev_info->pdev->dev); | |
836 | ||
837 | if (edac_op_state == EDAC_OPSTATE_POLL) | |
838 | dev_info->edac_dev->edac_check = dev_info->check; | |
839 | ||
840 | if (dev_info->init) | |
841 | dev_info->init(dev_info); | |
842 | ||
843 | if (edac_device_add_device(dev_info->edac_dev) > 0) { | |
844 | cpc925_printk(KERN_ERR, | |
845 | "Unable to add edac device for %s\n", | |
846 | dev_info->ctl_name); | |
847 | goto err2; | |
848 | } | |
849 | ||
850 | debugf0("%s: Successfully added edac device for %s\n", | |
851 | __func__, dev_info->ctl_name); | |
852 | ||
853 | continue; | |
854 | ||
855 | err2: | |
856 | if (dev_info->exit) | |
857 | dev_info->exit(dev_info); | |
858 | edac_device_free_ctl_info(dev_info->edac_dev); | |
859 | err1: | |
860 | platform_device_unregister(dev_info->pdev); | |
861 | } | |
862 | } | |
863 | ||
864 | /* | |
865 | * Delete the common "edac_device" for CPU Err Detection | |
866 | * and HyperTransport Link Err Detection | |
867 | */ | |
868 | static void cpc925_del_edac_devices(void) | |
869 | { | |
870 | struct cpc925_dev_info *dev_info; | |
871 | ||
872 | for (dev_info = &cpc925_devs[0]; dev_info->init; dev_info++) { | |
873 | if (dev_info->edac_dev) { | |
874 | edac_device_del_device(dev_info->edac_dev->dev); | |
875 | edac_device_free_ctl_info(dev_info->edac_dev); | |
876 | platform_device_unregister(dev_info->pdev); | |
877 | } | |
878 | ||
879 | if (dev_info->exit) | |
880 | dev_info->exit(dev_info); | |
881 | ||
882 | debugf0("%s: Successfully deleted edac device for %s\n", | |
883 | __func__, dev_info->ctl_name); | |
884 | } | |
885 | } | |
886 | ||
25985edc | 887 | /* Convert current back-ground scrub rate into byte/sec bandwidth */ |
39094443 | 888 | static int cpc925_get_sdram_scrub_rate(struct mem_ctl_info *mci) |
2a9036af HC |
889 | { |
890 | struct cpc925_mc_pdata *pdata = mci->pvt_info; | |
39094443 | 891 | int bw; |
2a9036af HC |
892 | u32 mscr; |
893 | u8 si; | |
894 | ||
895 | mscr = __raw_readl(pdata->vbase + REG_MSCR_OFFSET); | |
896 | si = (mscr & MSCR_SI_MASK) >> MSCR_SI_SHIFT; | |
897 | ||
898 | debugf0("%s, Mem Scrub Ctrl Register 0x%x\n", __func__, mscr); | |
899 | ||
900 | if (((mscr & MSCR_SCRUB_MOD_MASK) != MSCR_BACKGR_SCRUB) || | |
901 | (si == 0)) { | |
902 | cpc925_mc_printk(mci, KERN_INFO, "Scrub mode not enabled\n"); | |
39094443 | 903 | bw = 0; |
2a9036af | 904 | } else |
39094443 | 905 | bw = CPC925_SCRUB_BLOCK_SIZE * 0xFA67 / si; |
2a9036af | 906 | |
39094443 | 907 | return bw; |
2a9036af HC |
908 | } |
909 | ||
910 | /* Return 0 for single channel; 1 for dual channel */ | |
911 | static int cpc925_mc_get_channels(void __iomem *vbase) | |
912 | { | |
913 | int dual = 0; | |
914 | u32 mbcr; | |
915 | ||
916 | mbcr = __raw_readl(vbase + REG_MBCR_OFFSET); | |
917 | ||
918 | /* | |
919 | * Dual channel only when 128-bit wide physical bus | |
920 | * and 128-bit configuration. | |
921 | */ | |
922 | if (((mbcr & MBCR_64BITCFG_MASK) == 0) && | |
923 | ((mbcr & MBCR_64BITBUS_MASK) == 0)) | |
924 | dual = 1; | |
925 | ||
926 | debugf0("%s: %s channel\n", __func__, | |
927 | (dual > 0) ? "Dual" : "Single"); | |
928 | ||
929 | return dual; | |
930 | } | |
931 | ||
932 | static int __devinit cpc925_probe(struct platform_device *pdev) | |
933 | { | |
934 | static int edac_mc_idx; | |
935 | struct mem_ctl_info *mci; | |
936 | void __iomem *vbase; | |
937 | struct cpc925_mc_pdata *pdata; | |
938 | struct resource *r; | |
939 | int res = 0, nr_channels; | |
940 | ||
941 | debugf0("%s: %s platform device found!\n", __func__, pdev->name); | |
942 | ||
943 | if (!devres_open_group(&pdev->dev, cpc925_probe, GFP_KERNEL)) { | |
944 | res = -ENOMEM; | |
945 | goto out; | |
946 | } | |
947 | ||
948 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); | |
949 | if (!r) { | |
950 | cpc925_printk(KERN_ERR, "Unable to get resource\n"); | |
951 | res = -ENOENT; | |
952 | goto err1; | |
953 | } | |
954 | ||
955 | if (!devm_request_mem_region(&pdev->dev, | |
956 | r->start, | |
30a61fff | 957 | resource_size(r), |
2a9036af HC |
958 | pdev->name)) { |
959 | cpc925_printk(KERN_ERR, "Unable to request mem region\n"); | |
960 | res = -EBUSY; | |
961 | goto err1; | |
962 | } | |
963 | ||
30a61fff | 964 | vbase = devm_ioremap(&pdev->dev, r->start, resource_size(r)); |
2a9036af HC |
965 | if (!vbase) { |
966 | cpc925_printk(KERN_ERR, "Unable to ioremap device\n"); | |
967 | res = -ENOMEM; | |
968 | goto err2; | |
969 | } | |
970 | ||
084a4fcc | 971 | nr_channels = cpc925_mc_get_channels(vbase) + 1; |
2a9036af | 972 | mci = edac_mc_alloc(sizeof(struct cpc925_mc_pdata), |
084a4fcc | 973 | CPC925_NR_CSROWS, nr_channels, edac_mc_idx); |
2a9036af HC |
974 | if (!mci) { |
975 | cpc925_printk(KERN_ERR, "No memory for mem_ctl_info\n"); | |
976 | res = -ENOMEM; | |
977 | goto err2; | |
978 | } | |
979 | ||
980 | pdata = mci->pvt_info; | |
981 | pdata->vbase = vbase; | |
982 | pdata->edac_idx = edac_mc_idx++; | |
983 | pdata->name = pdev->name; | |
984 | ||
985 | mci->dev = &pdev->dev; | |
986 | platform_set_drvdata(pdev, mci); | |
987 | mci->dev_name = dev_name(&pdev->dev); | |
988 | mci->mtype_cap = MEM_FLAG_RDDR | MEM_FLAG_DDR; | |
989 | mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_SECDED; | |
990 | mci->edac_cap = EDAC_FLAG_SECDED; | |
991 | mci->mod_name = CPC925_EDAC_MOD_STR; | |
992 | mci->mod_ver = CPC925_EDAC_REVISION; | |
993 | mci->ctl_name = pdev->name; | |
994 | ||
995 | if (edac_op_state == EDAC_OPSTATE_POLL) | |
996 | mci->edac_check = cpc925_mc_check; | |
997 | ||
998 | mci->ctl_page_to_phys = NULL; | |
999 | mci->scrub_mode = SCRUB_SW_SRC; | |
1000 | mci->set_sdram_scrub_rate = NULL; | |
1001 | mci->get_sdram_scrub_rate = cpc925_get_sdram_scrub_rate; | |
1002 | ||
1003 | cpc925_init_csrows(mci); | |
1004 | ||
1005 | /* Setup memory controller registers */ | |
1006 | cpc925_mc_init(mci); | |
1007 | ||
1008 | if (edac_mc_add_mc(mci) > 0) { | |
1009 | cpc925_mc_printk(mci, KERN_ERR, "Failed edac_mc_add_mc()\n"); | |
1010 | goto err3; | |
1011 | } | |
1012 | ||
1013 | cpc925_add_edac_devices(vbase); | |
1014 | ||
1015 | /* get this far and it's successful */ | |
1016 | debugf0("%s: success\n", __func__); | |
1017 | ||
1018 | res = 0; | |
1019 | goto out; | |
1020 | ||
1021 | err3: | |
1022 | cpc925_mc_exit(mci); | |
1023 | edac_mc_free(mci); | |
1024 | err2: | |
30a61fff | 1025 | devm_release_mem_region(&pdev->dev, r->start, resource_size(r)); |
2a9036af HC |
1026 | err1: |
1027 | devres_release_group(&pdev->dev, cpc925_probe); | |
1028 | out: | |
1029 | return res; | |
1030 | } | |
1031 | ||
1032 | static int cpc925_remove(struct platform_device *pdev) | |
1033 | { | |
1034 | struct mem_ctl_info *mci = platform_get_drvdata(pdev); | |
1035 | ||
1036 | /* | |
1037 | * Delete common edac devices before edac mc, because | |
1038 | * the former share the MMIO of the latter. | |
1039 | */ | |
1040 | cpc925_del_edac_devices(); | |
1041 | cpc925_mc_exit(mci); | |
1042 | ||
1043 | edac_mc_del_mc(&pdev->dev); | |
1044 | edac_mc_free(mci); | |
1045 | ||
1046 | return 0; | |
1047 | } | |
1048 | ||
1049 | static struct platform_driver cpc925_edac_driver = { | |
1050 | .probe = cpc925_probe, | |
1051 | .remove = cpc925_remove, | |
1052 | .driver = { | |
1053 | .name = "cpc925_edac", | |
1054 | } | |
1055 | }; | |
1056 | ||
1057 | static int __init cpc925_edac_init(void) | |
1058 | { | |
1059 | int ret = 0; | |
1060 | ||
1061 | printk(KERN_INFO "IBM CPC925 EDAC driver " CPC925_EDAC_REVISION "\n"); | |
1062 | printk(KERN_INFO "\t(c) 2008 Wind River Systems, Inc\n"); | |
1063 | ||
1064 | /* Only support POLL mode so far */ | |
1065 | edac_op_state = EDAC_OPSTATE_POLL; | |
1066 | ||
1067 | ret = platform_driver_register(&cpc925_edac_driver); | |
1068 | if (ret) { | |
1069 | printk(KERN_WARNING "Failed to register %s\n", | |
1070 | CPC925_EDAC_MOD_STR); | |
1071 | } | |
1072 | ||
1073 | return ret; | |
1074 | } | |
1075 | ||
1076 | static void __exit cpc925_edac_exit(void) | |
1077 | { | |
1078 | platform_driver_unregister(&cpc925_edac_driver); | |
1079 | } | |
1080 | ||
1081 | module_init(cpc925_edac_init); | |
1082 | module_exit(cpc925_edac_exit); | |
1083 | ||
1084 | MODULE_LICENSE("GPL"); | |
1085 | MODULE_AUTHOR("Cao Qingtao <qingtao.cao@windriver.com>"); | |
1086 | MODULE_DESCRIPTION("IBM CPC925 Bridge and MC EDAC kernel module"); |