1 /* $NetBSD: ecc_plb.c,v 1.10 2005/12/24 22:45:36 perry Exp $ */
4 * Copyright 2001 Wasabi Systems, Inc.
7 * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed for the NetBSD Project by
20 * Wasabi Systems, Inc.
21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 * or promote products derived from this software without specific prior
25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
38 #include <sys/cdefs.h>
39 __KERNEL_RCSID(0, "$NetBSD: ecc_plb.c,v 1.10 2005/12/24 22:45:36 perry Exp $");
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/device.h>
47 #include <prop/proplib.h>
49 #include <machine/cpu.h>
50 #include <powerpc/ibm4xx/dcr405gp.h>
51 #include <powerpc/ibm4xx/dev/plbvar.h>
54 struct ecc_plb_softc
{
57 u_quad_t sc_ecc_iv
; /* Interval */
63 static int ecc_plbmatch(struct device
*, struct cfdata
*, void *);
64 static void ecc_plbattach(struct device
*, struct device
*, void *);
65 static void ecc_plb_deferred(struct device
*);
66 static int ecc_plb_intr(void *);
68 CFATTACH_DECL(ecc_plb
, sizeof(struct ecc_plb_softc
),
69 ecc_plbmatch
, ecc_plbattach
, NULL
, NULL
);
71 static int ecc_plb_found
;
74 ecc_plbmatch(struct device
*parent
, struct cfdata
*cf
, void *aux
)
76 struct plb_attach_args
*paa
= aux
;
78 if (strcmp(paa
->plb_name
, cf
->cf_name
) != 0)
81 if (cf
->cf_loc
[PLBCF_IRQ
] == PLBCF_IRQ_DEFAULT
)
82 panic("ecc_plbmatch: wildcard IRQ not allowed");
84 paa
->plb_irq
= cf
->cf_loc
[PLBCF_IRQ
];
86 return (!ecc_plb_found
);
90 ecc_plbattach(struct device
*parent
, struct device
*self
, void *aux
)
92 struct ecc_plb_softc
*sc
= (struct ecc_plb_softc
*)self
;
93 struct plb_attach_args
*paa
= aux
;
94 unsigned int processor_freq
;
100 pn
= prop_dictionary_get(board_properties
, "processor-frequency");
102 processor_freq
= (unsigned int) prop_number_integer_value(pn
);
104 pn
= prop_dictionary_get(board_properties
, "mem-size");
106 memsiz
= (unsigned int) prop_number_integer_value(pn
);
108 printf(": ECC controller\n");
112 sc
->sc_ecc_iv
= processor_freq
; /* Set interval */
113 sc
->sc_memsize
= memsiz
;
114 sc
->sc_irq
= paa
->plb_irq
;
117 * Defer hooking the interrupt until all PLB devices have attached
118 * since the interrupt controller may well be one of those devices...
120 config_defer(self
, ecc_plb_deferred
);
124 ecc_plb_deferred(struct device
*self
)
126 struct ecc_plb_softc
*sc
= (struct ecc_plb_softc
*)self
;
128 intr_establish(sc
->sc_irq
, IST_LEVEL
, IPL_SERIAL
, ecc_plb_intr
, NULL
);
135 ecc_plb_intr(void *arg
)
137 struct ecc_plb_softc
*sc
= arg
;
141 u_long tmp
, msr
, dat
;
143 /* This code needs to be improved to handle double-bit errors */
144 /* in some intelligent fashion. */
146 mtdcr(DCR_SDRAM0_CFGADDR
, DCR_SDRAM0_ECCESR
);
147 esr
= mfdcr(DCR_SDRAM0_CFGDATA
);
149 mtdcr(DCR_SDRAM0_CFGADDR
, DCR_SDRAM0_BEAR
);
150 ear
= mfdcr(DCR_SDRAM0_CFGDATA
);
152 /* Always clear the error to stop the intr ASAP. */
154 mtdcr(DCR_SDRAM0_CFGADDR
, DCR_SDRAM0_ECCESR
);
155 mtdcr(DCR_SDRAM0_CFGDATA
, 0xffffffff);
158 /* No current error. Could happen due to intr. nesting */
163 * Only report errors every once per second max. Do this using the TB,
164 * because the system time (via microtime) may be adjusted when the
165 * date is set and can't reliably be used to measure intervals.
168 __asm ("1: mftbu %0; mftb %0+1; mftbu %1; cmpw %0,%1; bne 1b"
169 : "=r"(tb
), "=r"(tmp
));
172 if ((tb
- sc
->sc_ecc_tb
) < sc
->sc_ecc_iv
)
175 ce
= (esr
& SDRAM0_ECCESR_CE
) != 0x00;
176 ue
= (esr
& SDRAM0_ECCESR_UE
) != 0x00;
178 printf("ECC: Error CNT=%d ESR=%x EAR=%x %s BKNE=%d%d%d%d "
179 "BLCE=%d%d%d%d CBE=%d%d.\n",
180 sc
->sc_ecc_cnt
, esr
, ear
,
181 (ue
) ? "Uncorrectable" : "Correctable",
182 ((esr
& SDRAM0_ECCESR_BKEN(0)) != 0x00),
183 ((esr
& SDRAM0_ECCESR_BKEN(1)) != 0x00),
184 ((esr
& SDRAM0_ECCESR_BKEN(2)) != 0x00),
185 ((esr
& SDRAM0_ECCESR_BKEN(3)) != 0x00),
186 ((esr
& SDRAM0_ECCESR_BLCEN(0)) != 0x00),
187 ((esr
& SDRAM0_ECCESR_BLCEN(1)) != 0x00),
188 ((esr
& SDRAM0_ECCESR_BLCEN(2)) != 0x00),
189 ((esr
& SDRAM0_ECCESR_BLCEN(3)) != 0x00),
190 ((esr
& SDRAM0_ECCESR_CBEN(0)) != 0x00),
191 ((esr
& SDRAM0_ECCESR_CBEN(1)) != 0x00));
193 /* Should check for uncorrectable errors and panic... */
195 if (sc
->sc_ecc_cnt
> 1000) {
196 printf("ECC: Too many errors, recycling entire "
197 "SDRAM (size = %d).\n", sc
->sc_memsize
);
200 * Can this code be changed to run without disabling data MMU
201 * and disabling intrs?
202 * Does kernel always map all of physical RAM VA=PA? If so,
203 * just loop over lowmem.
208 "ori %1, %1, 0x8010;"
222 "addic. %3, %3, -0x20;"
226 : "=&r" (msr
), "=&r" (tmp
), "=&r" (dat
)
227 : "r" (sc
->sc_memsize
) : "0" );
229 mtdcr(DCR_SDRAM0_CFGADDR
, DCR_SDRAM0_ECCESR
);
230 esr
= mfdcr(DCR_SDRAM0_CFGDATA
);
232 mtdcr(DCR_SDRAM0_CFGADDR
, DCR_SDRAM0_ECCESR
);
233 mtdcr(DCR_SDRAM0_CFGDATA
, 0xffffffff);
236 * Correctable errors here are OK, mem should be clean now.
238 * Should check for uncorrectable errors and panic...
240 printf("ECC: Recycling complete, ESR=%x. "
241 "Checking for persistent errors.\n", esr
);
246 "ori %1, %1, 0x8010;"
260 "addic. %3, %3, -0x20;"
264 : "=&r" (msr
), "=&r" (tmp
), "=&r" (dat
)
265 : "r" (sc
->sc_memsize
) : "0" );
267 mtdcr(DCR_SDRAM0_CFGADDR
, DCR_SDRAM0_ECCESR
);
268 esr
= mfdcr(DCR_SDRAM0_CFGDATA
);
271 * If esr is non zero here, we're screwed.
272 * Should check this and panic.
274 printf("ECC: Persistent error check complete, "
275 "final ESR=%x.\n", esr
);