Home | History | Annotate | Line # | Download | only in ibm4xx
cpu.c revision 1.2.8.1
      1  1.2.8.1  gehenna /*	$NetBSD: cpu.c,v 1.2.8.1 2002/07/16 13:09:57 gehenna Exp $	*/
      2      1.1      eeh 
      3      1.1      eeh /*
      4      1.1      eeh  * Copyright 2001 Wasabi Systems, Inc.
      5      1.1      eeh  * All rights reserved.
      6      1.1      eeh  *
      7      1.1      eeh  * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
      8      1.1      eeh  *
      9      1.1      eeh  * Redistribution and use in source and binary forms, with or without
     10      1.1      eeh  * modification, are permitted provided that the following conditions
     11      1.1      eeh  * are met:
     12      1.1      eeh  * 1. Redistributions of source code must retain the above copyright
     13      1.1      eeh  *    notice, this list of conditions and the following disclaimer.
     14      1.1      eeh  * 2. Redistributions in binary form must reproduce the above copyright
     15      1.1      eeh  *    notice, this list of conditions and the following disclaimer in the
     16      1.1      eeh  *    documentation and/or other materials provided with the distribution.
     17      1.1      eeh  * 3. All advertising materials mentioning features or use of this software
     18      1.1      eeh  *    must display the following acknowledgement:
     19      1.1      eeh  *      This product includes software developed for the NetBSD Project by
     20      1.1      eeh  *      Wasabi Systems, Inc.
     21      1.1      eeh  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22      1.1      eeh  *    or promote products derived from this software without specific prior
     23      1.1      eeh  *    written permission.
     24      1.1      eeh  *
     25      1.1      eeh  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26      1.1      eeh  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27      1.1      eeh  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28      1.1      eeh  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29      1.1      eeh  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30      1.1      eeh  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31      1.1      eeh  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32      1.1      eeh  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33      1.1      eeh  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34      1.1      eeh  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35      1.1      eeh  * POSSIBILITY OF SUCH DAMAGE.
     36      1.1      eeh  */
     37      1.1      eeh 
     38      1.1      eeh #include <sys/param.h>
     39      1.1      eeh #include <sys/systm.h>
     40      1.1      eeh #include <sys/device.h>
     41      1.2      eeh #include <sys/properties.h>
     42      1.1      eeh 
     43      1.1      eeh #include <machine/autoconf.h>
     44      1.1      eeh #include <machine/dcr.h>
     45      1.2      eeh #include <machine/cpu.h>
     46      1.1      eeh 
     47      1.1      eeh struct cputab {
     48      1.1      eeh 	int version;
     49      1.1      eeh 	char *name;
     50      1.1      eeh };
     51      1.1      eeh static struct cputab models[] = {
     52      1.1      eeh 	{ PVR_401A1 >> 16, "401A1" },
     53      1.1      eeh 	{ PVR_401B2 >> 16, "401B21" },
     54      1.1      eeh 	{ PVR_401C2 >> 16, "401C2" },
     55      1.1      eeh 	{ PVR_401D2 >> 16, "401D2" },
     56      1.1      eeh 	{ PVR_401E2 >> 16, "401E2" },
     57      1.1      eeh 	{ PVR_401F2 >> 16, "401F2" },
     58      1.1      eeh 	{ PVR_401G2 >> 16, "401G2" },
     59      1.1      eeh 	{ PVR_403 >> 16, "403" },
     60      1.1      eeh 	{ PVR_405GP >> 16, "405GP" },
     61      1.1      eeh 	{ 0,		    NULL }
     62      1.1      eeh };
     63      1.1      eeh 
     64      1.1      eeh static int	cpumatch(struct device *, struct cfdata *, void *);
     65      1.1      eeh static void	cpuattach(struct device *, struct device *, void *);
     66      1.1      eeh 
     67      1.1      eeh /*
     68      1.1      eeh  * Arguably the ECC stuff belongs somewhere else....
     69      1.1      eeh  */
     70      1.1      eeh int intr_ecc(void *);
     71      1.1      eeh 
     72      1.1      eeh u_quad_t		intr_ecc_tb;
     73      1.1      eeh u_quad_t		intr_ecc_iv;	 /* Interval */
     74      1.1      eeh u_int32_t		intr_ecc_cnt;
     75      1.1      eeh 
     76      1.1      eeh struct cfattach cpu_ca = {
     77      1.1      eeh 	sizeof(struct device), cpumatch, cpuattach
     78      1.1      eeh };
     79      1.1      eeh 
     80      1.1      eeh int ncpus;
     81      1.1      eeh 
     82      1.1      eeh struct cpu_info cpu_info_store;
     83      1.1      eeh 
     84      1.1      eeh int cpufound = 0;
     85      1.1      eeh 
     86      1.1      eeh static int
     87      1.1      eeh cpumatch(struct device *parent, struct cfdata *cf, void *aux)
     88      1.1      eeh {
     89      1.1      eeh 	struct mainbus_attach_args *maa = aux;
     90      1.1      eeh 
     91      1.1      eeh 	/* make sure that we're looking for a CPU */
     92      1.1      eeh 	if (strcmp(maa->mb_name, cf->cf_driver->cd_name) != 0)
     93  1.2.8.1  gehenna 		return (0);
     94      1.1      eeh 
     95      1.1      eeh 	return !cpufound;
     96      1.1      eeh }
     97      1.1      eeh 
     98      1.1      eeh static void
     99      1.1      eeh cpuattach(struct device *parent, struct device *self, void *aux)
    100      1.1      eeh {
    101      1.1      eeh 	int pvr, cpu;
    102      1.1      eeh 	int own, pcf, cas, pcl, aid;
    103      1.1      eeh 	struct cputab *cp = models;
    104      1.2      eeh 	unsigned int processor_freq;
    105      1.2      eeh 
    106  1.2.8.1  gehenna 	if (board_info_get("processor-frequency",
    107      1.2      eeh 		&processor_freq, sizeof(processor_freq)) == -1)
    108      1.2      eeh 		panic("no processor-frequency");
    109      1.1      eeh 
    110      1.1      eeh 	cpufound++;
    111      1.1      eeh 	ncpus++;
    112      1.1      eeh 
    113      1.1      eeh 	asm ("mfpvr %0" : "=r"(pvr));
    114      1.1      eeh 	cpu = pvr >> 16;
    115      1.1      eeh 
    116      1.1      eeh 	/* Break PVR up into separate fields and print them out. */
    117      1.1      eeh 	own = (pvr >> 20) & 0xfff;
    118      1.1      eeh 	pcf = (pvr >> 16) & 0xf;
    119      1.1      eeh 	cas = (pvr >> 10) & 0x3f;
    120      1.1      eeh 	pcl = (pvr >> 6) & 0xf;
    121      1.1      eeh 	aid = pvr & 0x3f;
    122      1.1      eeh 
    123      1.1      eeh 	while (cp->name) {
    124      1.1      eeh 		if (cp->version == cpu)
    125      1.1      eeh 			break;
    126      1.1      eeh 		cp++;
    127      1.1      eeh 	}
    128      1.1      eeh 	if (cp->name)
    129      1.1      eeh 		strcpy(cpu_model, cp->name);
    130      1.1      eeh 	else
    131      1.1      eeh 		sprintf(cpu_model, "Version 0x%x", cpu);
    132      1.1      eeh 	sprintf(cpu_model + strlen(cpu_model), " (Revision %d.%d)",
    133      1.1      eeh 		(pvr >> 8) & 0xff, pvr & 0xff);
    134      1.1      eeh 
    135      1.1      eeh #if 1
    136      1.2      eeh 	printf(": %dMHz %s\n", processor_freq / 1000 / 1000,
    137      1.1      eeh 	    cpu_model);
    138      1.1      eeh #endif
    139      1.1      eeh 
    140      1.1      eeh 	cpu_probe_cache();
    141      1.1      eeh 
    142  1.2.8.1  gehenna 	printf("Instruction cache size %d line size %d\n",
    143      1.1      eeh 		curcpu()->ci_ci.icache_size, curcpu()->ci_ci.icache_line_size);
    144  1.2.8.1  gehenna 	printf("Data cache size %d line size %d\n",
    145      1.1      eeh 		curcpu()->ci_ci.dcache_size, curcpu()->ci_ci.dcache_line_size);
    146      1.1      eeh 
    147      1.1      eeh #ifdef DEBUG
    148      1.1      eeh 	/* It sux that the cache info here is useless. */
    149      1.1      eeh 	printf("PVR: owner %x core family %x cache %x version %x asic %x\n",
    150      1.1      eeh 		own, pcf, cas, pcl, aid);
    151      1.1      eeh #endif
    152      1.1      eeh 
    153      1.1      eeh 	/* Initialize ECC error-logging handler.  This is always enabled,
    154      1.1      eeh 	 * but it will never be called on systems that do not have ECC
    155      1.1      eeh 	 * enabled by POST code in the bootloader.
    156  1.2.8.1  gehenna 	 */
    157      1.1      eeh 
    158      1.1      eeh 	printf("Enabling ecc handler\n");
    159      1.1      eeh 	intr_ecc_tb = 0;
    160      1.2      eeh 	intr_ecc_iv = processor_freq; /* Set interval */
    161      1.1      eeh 	intr_ecc_cnt = 0;
    162      1.1      eeh 
    163      1.1      eeh 	intr_establish(16, IST_LEVEL, IPL_SERIAL, intr_ecc, NULL);
    164      1.1      eeh }
    165      1.1      eeh 
    166      1.1      eeh /*
    167  1.2.8.1  gehenna  * This routine must be explicitly called to initialize the
    168  1.2.8.1  gehenna  * CPU cache information so cache flushe and memcpy operation
    169      1.1      eeh  * work.
    170      1.1      eeh  */
    171      1.1      eeh void
    172      1.1      eeh cpu_probe_cache()
    173      1.1      eeh {
    174      1.1      eeh 	int version;
    175      1.1      eeh 
    176      1.1      eeh 	/*
    177  1.2.8.1  gehenna 	 * First we need to identify the cpu and determine the
    178      1.1      eeh 	 * cache line size, or things like memset/memcpy may lose
    179      1.1      eeh 	 * badly.
    180      1.1      eeh 	 */
    181      1.1      eeh 	__asm __volatile("mfpvr %0" : "=r" (version));
    182      1.1      eeh 	switch (version & 0xffff0000) {
    183      1.1      eeh 	case PVR_401A1:
    184      1.1      eeh 		curcpu()->ci_ci.dcache_size = 1024;
    185      1.1      eeh 		curcpu()->ci_ci.dcache_line_size = 16;
    186      1.1      eeh 		curcpu()->ci_ci.icache_size = 2848;
    187      1.1      eeh 		curcpu()->ci_ci.icache_line_size = 16;
    188      1.1      eeh 		break;
    189      1.1      eeh 	case PVR_401B2:
    190      1.1      eeh 		curcpu()->ci_ci.dcache_size = 8192;
    191      1.1      eeh 		curcpu()->ci_ci.dcache_line_size = 16;
    192      1.1      eeh 		curcpu()->ci_ci.icache_size = 16384;
    193      1.1      eeh 		curcpu()->ci_ci.icache_line_size = 16;
    194      1.1      eeh 		break;
    195      1.1      eeh 	case PVR_401C2:
    196      1.1      eeh 		curcpu()->ci_ci.dcache_size = 8192;
    197      1.1      eeh 		curcpu()->ci_ci.dcache_line_size = 16;
    198      1.1      eeh 		curcpu()->ci_ci.icache_size = 0;
    199      1.1      eeh 		curcpu()->ci_ci.icache_line_size = 16;
    200      1.1      eeh 		break;
    201      1.1      eeh 	case PVR_401D2:
    202      1.1      eeh 		curcpu()->ci_ci.dcache_size = 2848;
    203      1.1      eeh 		curcpu()->ci_ci.dcache_line_size = 16;
    204      1.1      eeh 		curcpu()->ci_ci.icache_size = 4096;
    205      1.1      eeh 		curcpu()->ci_ci.icache_line_size = 16;
    206      1.1      eeh 		break;
    207      1.1      eeh 	case PVR_401E2:
    208      1.1      eeh 		curcpu()->ci_ci.dcache_size = 0;
    209      1.1      eeh 		curcpu()->ci_ci.dcache_line_size = 16;
    210      1.1      eeh 		curcpu()->ci_ci.icache_size = 0;
    211      1.1      eeh 		curcpu()->ci_ci.icache_line_size = 16;
    212      1.1      eeh 		break;
    213      1.1      eeh 	case PVR_401F2:
    214      1.1      eeh 		curcpu()->ci_ci.dcache_size = 2048;
    215      1.1      eeh 		curcpu()->ci_ci.dcache_line_size = 16;
    216      1.1      eeh 		curcpu()->ci_ci.icache_size = 2848;
    217      1.1      eeh 		curcpu()->ci_ci.icache_line_size = 16;
    218      1.1      eeh 		break;
    219      1.1      eeh 	case PVR_401G2:
    220      1.1      eeh 		curcpu()->ci_ci.dcache_size = 2848;
    221      1.1      eeh 		curcpu()->ci_ci.dcache_line_size = 16;
    222      1.1      eeh 		curcpu()->ci_ci.icache_size = 8192;
    223      1.1      eeh 		curcpu()->ci_ci.icache_line_size = 16;
    224      1.1      eeh 		break;
    225      1.1      eeh 	case PVR_403:
    226      1.1      eeh 		curcpu()->ci_ci.dcache_line_size = 16;
    227      1.1      eeh 		curcpu()->ci_ci.icache_line_size = 16;
    228      1.1      eeh 		break;
    229      1.1      eeh 	case PVR_405GP:
    230      1.1      eeh 		curcpu()->ci_ci.dcache_size = 8192;
    231      1.1      eeh 		curcpu()->ci_ci.dcache_line_size = 32;
    232      1.1      eeh 		curcpu()->ci_ci.icache_size = 8192;
    233      1.1      eeh 		curcpu()->ci_ci.icache_line_size = 32;
    234      1.1      eeh 		break;
    235      1.1      eeh 	default:
    236  1.2.8.1  gehenna 		/*
    237  1.2.8.1  gehenna 		 * Unknown CPU type.  For safety we'll specify a
    238  1.2.8.1  gehenna 		 * cache with a 4-byte line size.  That way cache
    239      1.1      eeh 		 * flush routines won't miss any lines.
    240      1.1      eeh 		 */
    241      1.1      eeh 		curcpu()->ci_ci.dcache_line_size = 4;
    242      1.1      eeh 		curcpu()->ci_ci.icache_line_size = 4;
    243      1.1      eeh 		break;
    244      1.1      eeh 	}
    245      1.1      eeh 
    246      1.1      eeh }
    247      1.1      eeh 
    248      1.1      eeh /*
    249      1.1      eeh  * These small routines may have to be replaced,
    250      1.1      eeh  * if/when we support processors other that the 604.
    251      1.1      eeh  */
    252      1.1      eeh 
    253      1.1      eeh void
    254      1.1      eeh dcache_flush_page(vaddr_t va)
    255      1.1      eeh {
    256      1.1      eeh 	int i;
    257      1.1      eeh 
    258      1.1      eeh 	if (curcpu()->ci_ci.dcache_line_size)
    259      1.1      eeh 		for (i = 0; i < NBPG; i += curcpu()->ci_ci.dcache_line_size)
    260      1.1      eeh 			asm volatile("dcbf %0,%1" : : "r" (va), "r" (i));
    261      1.1      eeh 	asm volatile("sync;isync" : : );
    262      1.1      eeh }
    263      1.1      eeh 
    264      1.1      eeh void
    265      1.1      eeh icache_flush_page(vaddr_t va)
    266      1.1      eeh {
    267      1.1      eeh 	int i;
    268      1.1      eeh 
    269      1.1      eeh 	if (curcpu()->ci_ci.icache_line_size)
    270      1.1      eeh 		for (i = 0; i < NBPG; i += curcpu()->ci_ci.icache_line_size)
    271      1.1      eeh 			asm volatile("icbi %0,%1" : : "r" (va), "r" (i));
    272      1.1      eeh 	asm volatile("sync;isync" : : );
    273      1.1      eeh }
    274      1.1      eeh 
    275      1.1      eeh void
    276      1.1      eeh dcache_flush(vaddr_t va, vsize_t len)
    277      1.1      eeh {
    278      1.1      eeh 	int i;
    279      1.1      eeh 
    280      1.1      eeh 	if (len == 0)
    281      1.1      eeh 		return;
    282      1.1      eeh 
    283      1.1      eeh 	/* Make sure we flush all cache lines */
    284      1.1      eeh 	len += va & (curcpu()->ci_ci.dcache_line_size-1);
    285      1.1      eeh 	if (curcpu()->ci_ci.dcache_line_size)
    286      1.1      eeh 		for (i = 0; i < len; i += curcpu()->ci_ci.dcache_line_size)
    287      1.1      eeh 			asm volatile("dcbf %0,%1" : : "r" (va), "r" (i));
    288      1.1      eeh 	asm volatile("sync;isync" : : );
    289      1.1      eeh }
    290      1.1      eeh 
    291      1.1      eeh void
    292      1.1      eeh icache_flush(vaddr_t va, vsize_t len)
    293      1.1      eeh {
    294      1.1      eeh 	int i;
    295      1.1      eeh 
    296      1.1      eeh 	if (len == 0)
    297      1.1      eeh 		return;
    298      1.1      eeh 
    299      1.1      eeh 	/* Make sure we flush all cache lines */
    300      1.1      eeh 	len += va & (curcpu()->ci_ci.icache_line_size-1);
    301      1.1      eeh 	if (curcpu()->ci_ci.icache_line_size)
    302      1.1      eeh 		for (i = 0; i < len; i += curcpu()->ci_ci.icache_line_size)
    303      1.1      eeh 			asm volatile("icbi %0,%1" : : "r" (va), "r" (i));
    304      1.1      eeh 	asm volatile("sync;isync" : : );
    305      1.1      eeh }
    306      1.1      eeh 
    307      1.1      eeh /*
    308      1.1      eeh  * ECC fault handler.
    309      1.1      eeh  */
    310      1.1      eeh int
    311      1.1      eeh intr_ecc(void * arg)
    312      1.1      eeh {
    313      1.1      eeh 	u_int32_t		esr, ear;
    314      1.1      eeh 	int			ce, ue;
    315      1.1      eeh 	u_quad_t		tb;
    316      1.1      eeh 	u_long			tmp, msr, dat;
    317      1.2      eeh 	unsigned int		memsiz;
    318      1.2      eeh 
    319      1.2      eeh 	if (board_info_get("mem-size", &memsiz, sizeof(memsiz)) == -1)
    320      1.2      eeh 		panic("no mem-size");
    321  1.2.8.1  gehenna 
    322      1.1      eeh 	/* This code needs to be improved to handle double-bit errors */
    323      1.1      eeh 	/* in some intelligent fashion. */
    324      1.1      eeh 
    325      1.1      eeh 	mtdcr(DCR_SDRAM0_CFGADDR, DCR_SDRAM0_ECCESR);
    326      1.1      eeh 	esr = mfdcr(DCR_SDRAM0_CFGDATA);
    327      1.1      eeh 
    328      1.1      eeh 	mtdcr(DCR_SDRAM0_CFGADDR, DCR_SDRAM0_BEAR);
    329      1.1      eeh 	ear = mfdcr(DCR_SDRAM0_CFGDATA);
    330      1.1      eeh 
    331  1.2.8.1  gehenna 	/* Always clear the error to stop the intr ASAP. */
    332      1.1      eeh 
    333      1.1      eeh 	mtdcr(DCR_SDRAM0_CFGADDR, DCR_SDRAM0_ECCESR);
    334      1.1      eeh 	mtdcr(DCR_SDRAM0_CFGDATA, 0xffffffff);
    335      1.1      eeh 
    336  1.2.8.1  gehenna 	if (esr == 0x00) {
    337      1.1      eeh 		/* No current error.  Could happen due to intr. nesting */
    338      1.1      eeh 		return(1);
    339      1.1      eeh 	};
    340      1.1      eeh 
    341      1.1      eeh 	/* Only report errors every once per second max. Do this using the TB, */
    342      1.1      eeh 	/* because the system time (via microtime) may be adjusted when the date is set */
    343  1.2.8.1  gehenna 	/* and can't reliably be used to measure intervals. */
    344  1.2.8.1  gehenna 
    345  1.2.8.1  gehenna 	asm ("1: mftbu %0; mftb %0+1; mftbu %1; cmpw %0,%1; bne 1b"
    346      1.1      eeh 		: "=r"(tb), "=r"(tmp));
    347      1.1      eeh 	intr_ecc_cnt++;
    348      1.1      eeh 
    349      1.1      eeh 	if ((tb - intr_ecc_tb) < intr_ecc_iv) {
    350      1.1      eeh 		return(1);
    351  1.2.8.1  gehenna 	};
    352      1.1      eeh 
    353      1.1      eeh 	ce = (esr & SDRAM0_ECCESR_CE) != 0x00;
    354      1.1      eeh 	ue = (esr & SDRAM0_ECCESR_UE) != 0x00;
    355      1.1      eeh 
    356      1.1      eeh 	printf("ECC: Error CNT=%d ESR=%x EAR=%x %s BKNE=%d%d%d%d "
    357      1.1      eeh 		"BLCE=%d%d%d%d CBE=%d%d.\n",
    358      1.1      eeh 		intr_ecc_cnt, esr, ear,
    359  1.2.8.1  gehenna 		(ue) ? "Uncorrectable" : "Correctable",
    360  1.2.8.1  gehenna 		((esr & SDRAM0_ECCESR_BKEN(0)) != 0x00),
    361      1.1      eeh 		((esr & SDRAM0_ECCESR_BKEN(1)) != 0x00),
    362  1.2.8.1  gehenna 		((esr & SDRAM0_ECCESR_BKEN(2)) != 0x00),
    363  1.2.8.1  gehenna 		((esr & SDRAM0_ECCESR_BKEN(3)) != 0x00),
    364  1.2.8.1  gehenna 		((esr & SDRAM0_ECCESR_BLCEN(0)) != 0x00),
    365  1.2.8.1  gehenna 		((esr & SDRAM0_ECCESR_BLCEN(1)) != 0x00),
    366  1.2.8.1  gehenna 		((esr & SDRAM0_ECCESR_BLCEN(2)) != 0x00),
    367      1.1      eeh 		((esr & SDRAM0_ECCESR_BLCEN(3)) != 0x00),
    368      1.1      eeh 		((esr & SDRAM0_ECCESR_CBEN(0)) != 0x00),
    369      1.1      eeh 		((esr & SDRAM0_ECCESR_CBEN(1)) != 0x00));
    370      1.1      eeh 
    371      1.1      eeh 	/* Should check for uncorrectable errors and panic... */
    372      1.1      eeh 
    373      1.1      eeh 	if (intr_ecc_cnt > 1000) {
    374      1.1      eeh 		printf("ECC: Too many errors, recycling entire "
    375      1.2      eeh 			"SDRAM (size = %d).\n", memsiz);
    376      1.1      eeh 
    377      1.1      eeh 		/* Can this code be changed to run without disabling data MMU and disabling intrs? */
    378      1.1      eeh 		/* Does kernel always map all of physical RAM VA=PA? If so, just loop over lowmem. */
    379      1.1      eeh 
    380      1.1      eeh 		asm volatile(
    381      1.1      eeh 			"mfmsr 	%0;"
    382      1.1      eeh 			"li	%1, 0x00;"
    383      1.1      eeh 			"ori	%1, %1, 0x8010;"
    384      1.1      eeh 			"andc	%1, %0, %1;"
    385      1.1      eeh 			"mtmsr	%1;"
    386      1.1      eeh 			"sync;isync;"
    387      1.1      eeh 			"li	%1, 0x00;"
    388      1.1      eeh 			"1:"
    389      1.1      eeh 			"dcbt	0, %1;"
    390      1.1      eeh 			"sync;isync;"
    391      1.1      eeh 			"lwz	%2, 0(%1);"
    392      1.1      eeh 			"stw	%2, 0(%1);"
    393      1.1      eeh 			"sync;isync;"
    394      1.1      eeh 			"dcbf	0, %1;"
    395      1.1      eeh 			"sync;isync;"
    396      1.1      eeh 			"addi	%1, %1, 0x20;"
    397      1.1      eeh 			"addic.	%3, %3, -0x20;"
    398      1.1      eeh 			"bge 	1b;"
    399      1.1      eeh 			"mtmsr %0;"
    400      1.1      eeh 			"sync;isync;"
    401      1.1      eeh 		: "=&r" (msr), "=&r" (tmp), "=&r" (dat)
    402      1.2      eeh 		: "r" (memsiz) : "0" );
    403      1.1      eeh 
    404      1.1      eeh 		mtdcr(DCR_SDRAM0_CFGADDR, DCR_SDRAM0_ECCESR);
    405      1.1      eeh 		esr = mfdcr(DCR_SDRAM0_CFGDATA);
    406      1.1      eeh 
    407      1.1      eeh 		mtdcr(DCR_SDRAM0_CFGADDR, DCR_SDRAM0_ECCESR);
    408      1.1      eeh 		mtdcr(DCR_SDRAM0_CFGDATA, 0xffffffff);
    409      1.1      eeh 
    410      1.1      eeh 		/* Correctable errors here are OK, mem should be clean now. */
    411      1.1      eeh 		/* Should check for uncorrectable errors and panic... */
    412      1.1      eeh 		printf("ECC: Recycling complete, ESR=%x. "
    413      1.1      eeh 			"Checking for persistent errors.\n", esr);
    414  1.2.8.1  gehenna 
    415      1.1      eeh 		asm volatile(
    416      1.1      eeh 			"mfmsr 	%0;"
    417      1.1      eeh 			"li	%1, 0x00;"
    418      1.1      eeh 			"ori	%1, %1, 0x8010;"
    419      1.1      eeh 			"andc	%1, %0, %1;"
    420      1.1      eeh 			"mtmsr	%1;"
    421      1.1      eeh 			"sync;isync;"
    422      1.1      eeh 			"li	%1, 0x00;"
    423      1.1      eeh 			"1:"
    424      1.1      eeh 			"dcbt	0, %1;"
    425      1.1      eeh 			"sync;isync;"
    426      1.1      eeh 			"lwz	%2, 0(%1);"
    427      1.1      eeh 			"stw	%2, 0(%1);"
    428      1.1      eeh 			"sync;isync;"
    429      1.1      eeh 			"dcbf	0, %1;"
    430      1.1      eeh 			"sync;isync;"
    431      1.1      eeh 			"addi	%1, %1, 0x20;"
    432      1.1      eeh 			"addic.	%3, %3, -0x20;"
    433      1.1      eeh 			"bge 	1b;"
    434      1.1      eeh 			"mtmsr %0;"
    435      1.1      eeh 			"sync;isync;"
    436      1.1      eeh 		: "=&r" (msr), "=&r" (tmp), "=&r" (dat)
    437      1.2      eeh 		: "r" (memsiz) : "0" );
    438      1.1      eeh 
    439      1.1      eeh 		mtdcr(DCR_SDRAM0_CFGADDR, DCR_SDRAM0_ECCESR);
    440      1.1      eeh 		esr = mfdcr(DCR_SDRAM0_CFGDATA);
    441      1.1      eeh 
    442      1.1      eeh 		/* If esr is non zero here, we're screwed.  Should check this and panic. */
    443      1.1      eeh 		printf("ECC: Persistent error check complete, "
    444      1.1      eeh 			"final ESR=%x.\n", esr);
    445      1.1      eeh 	};
    446      1.1      eeh 
    447      1.1      eeh 	intr_ecc_tb = tb;
    448      1.1      eeh 	intr_ecc_cnt = 0;
    449      1.1      eeh 
    450      1.1      eeh 	return(1);
    451      1.1      eeh };
    452