obs600_machdep.c revision 1.1.4.3       1  1.1.4.2  rmind /*	$NetBSD: obs600_machdep.c,v 1.1.4.3 2011/03/05 20:50:17 rmind Exp $	*/
      2  1.1.4.2  rmind /*	Original: md_machdep.c,v 1.3 2005/01/24 18:47:37 shige Exp $	*/
      3  1.1.4.2  rmind 
      4  1.1.4.2  rmind /*
      5  1.1.4.2  rmind  * Copyright 2001, 2002 Wasabi Systems, Inc.
      6  1.1.4.2  rmind  * All rights reserved.
      7  1.1.4.2  rmind  *
      8  1.1.4.2  rmind  * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
      9  1.1.4.2  rmind  *
     10  1.1.4.2  rmind  * Redistribution and use in source and binary forms, with or without
     11  1.1.4.2  rmind  * modification, are permitted provided that the following conditions
     12  1.1.4.2  rmind  * are met:
     13  1.1.4.2  rmind  * 1. Redistributions of source code must retain the above copyright
     14  1.1.4.2  rmind  *    notice, this list of conditions and the following disclaimer.
     15  1.1.4.2  rmind  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1.4.2  rmind  *    notice, this list of conditions and the following disclaimer in the
     17  1.1.4.2  rmind  *    documentation and/or other materials provided with the distribution.
     18  1.1.4.2  rmind  * 3. All advertising materials mentioning features or use of this software
     19  1.1.4.2  rmind  *    must display the following acknowledgement:
     20  1.1.4.2  rmind  *      This product includes software developed for the NetBSD Project by
     21  1.1.4.2  rmind  *      Wasabi Systems, Inc.
     22  1.1.4.2  rmind  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     23  1.1.4.2  rmind  *    or promote products derived from this software without specific prior
     24  1.1.4.2  rmind  *    written permission.
     25  1.1.4.2  rmind  *
     26  1.1.4.2  rmind  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     27  1.1.4.2  rmind  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1.4.2  rmind  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1.4.2  rmind  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     30  1.1.4.2  rmind  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1.4.2  rmind  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1.4.2  rmind  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1.4.2  rmind  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1.4.2  rmind  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1.4.2  rmind  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1.4.2  rmind  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1.4.2  rmind  */
     38  1.1.4.2  rmind 
     39  1.1.4.2  rmind /*
     40  1.1.4.2  rmind  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
     41  1.1.4.2  rmind  * Copyright (C) 1995, 1996 TooLs GmbH.
     42  1.1.4.2  rmind  * All rights reserved.
     43  1.1.4.2  rmind  *
     44  1.1.4.2  rmind  * Redistribution and use in source and binary forms, with or without
     45  1.1.4.2  rmind  * modification, are permitted provided that the following conditions
     46  1.1.4.2  rmind  * are met:
     47  1.1.4.2  rmind  * 1. Redistributions of source code must retain the above copyright
     48  1.1.4.2  rmind  *    notice, this list of conditions and the following disclaimer.
     49  1.1.4.2  rmind  * 2. Redistributions in binary form must reproduce the above copyright
     50  1.1.4.2  rmind  *    notice, this list of conditions and the following disclaimer in the
     51  1.1.4.2  rmind  *    documentation and/or other materials provided with the distribution.
     52  1.1.4.2  rmind  * 3. All advertising materials mentioning features or use of this software
     53  1.1.4.2  rmind  *    must display the following acknowledgement:
     54  1.1.4.2  rmind  *	This product includes software developed by TooLs GmbH.
     55  1.1.4.2  rmind  * 4. The name of TooLs GmbH may not be used to endorse or promote products
     56  1.1.4.2  rmind  *    derived from this software without specific prior written permission.
     57  1.1.4.2  rmind  *
     58  1.1.4.2  rmind  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
     59  1.1.4.2  rmind  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     60  1.1.4.2  rmind  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     61  1.1.4.2  rmind  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     62  1.1.4.2  rmind  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     63  1.1.4.2  rmind  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     64  1.1.4.2  rmind  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     65  1.1.4.2  rmind  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     66  1.1.4.2  rmind  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     67  1.1.4.2  rmind  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     68  1.1.4.2  rmind  */
     69  1.1.4.2  rmind 
     70  1.1.4.2  rmind #include <sys/cdefs.h>
     71  1.1.4.2  rmind __KERNEL_RCSID(0, "$NetBSD: obs600_machdep.c,v 1.1.4.3 2011/03/05 20:50:17 rmind Exp $");
     72  1.1.4.2  rmind 
     73  1.1.4.2  rmind #include "opt_compat_netbsd.h"
     74  1.1.4.2  rmind #include "opt_ddb.h"
     75  1.1.4.2  rmind #include "opt_ipkdb.h"
     76  1.1.4.2  rmind #include "opt_modular.h"
     77  1.1.4.2  rmind 
     78  1.1.4.2  rmind #include <sys/param.h>
     79  1.1.4.2  rmind #include <sys/bus.h>
     80  1.1.4.2  rmind #include <sys/errno.h>
     81  1.1.4.2  rmind #include <sys/kernel.h>
     82  1.1.4.2  rmind #include <sys/ksyms.h>
     83  1.1.4.2  rmind #include <sys/mount.h>
     84  1.1.4.2  rmind #include <sys/reboot.h>
     85  1.1.4.2  rmind #include <sys/systm.h>
     86  1.1.4.2  rmind #include <sys/device.h>
     87  1.1.4.2  rmind 
     88  1.1.4.2  rmind #include <uvm/uvm_extern.h>
     89  1.1.4.2  rmind 
     90  1.1.4.2  rmind #include <machine/bus.h>
     91  1.1.4.2  rmind #include <machine/cpu.h>
     92  1.1.4.2  rmind #include <machine/obs600.h>
     93  1.1.4.2  rmind 
     94  1.1.4.2  rmind #include <powerpc/ibm4xx/amcc405ex.h>
     95  1.1.4.2  rmind #include <powerpc/ibm4xx/dcr4xx.h>
     96  1.1.4.2  rmind #include <powerpc/ibm4xx/dev/comopbvar.h>
     97  1.1.4.2  rmind #include <powerpc/ibm4xx/dev/gpiicreg.h>
     98  1.1.4.2  rmind #include <powerpc/ibm4xx/dev/opbvar.h>
     99  1.1.4.2  rmind #include <powerpc/ibm4xx/spr.h>
    100  1.1.4.2  rmind #include <powerpc/spr.h>
    101  1.1.4.2  rmind 
    102  1.1.4.2  rmind #include <dev/ic/comreg.h>
    103  1.1.4.2  rmind 
    104  1.1.4.2  rmind #include "ksyms.h"
    105  1.1.4.2  rmind 
    106  1.1.4.2  rmind #include "com.h"
    107  1.1.4.2  rmind #if (NCOM > 0)
    108  1.1.4.2  rmind #include <sys/termios.h>
    109  1.1.4.2  rmind 
    110  1.1.4.2  rmind #ifndef CONADDR
    111  1.1.4.2  rmind #define CONADDR		AMCC405EX_UART0_BASE
    112  1.1.4.2  rmind #endif
    113  1.1.4.2  rmind #ifndef CONSPEED
    114  1.1.4.2  rmind #define CONSPEED	B115200
    115  1.1.4.2  rmind #endif
    116  1.1.4.2  rmind #ifndef CONMODE
    117  1.1.4.2  rmind 			/* 8N1 */
    118  1.1.4.2  rmind #define CONMODE		((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8)
    119  1.1.4.2  rmind #endif
    120  1.1.4.2  rmind #endif	/* NCOM */
    121  1.1.4.2  rmind 
    122  1.1.4.2  rmind /*
    123  1.1.4.2  rmind  * XXXX:
    124  1.1.4.2  rmind  * It is very troublesome though we can calculate from various registers. X-<
    125  1.1.4.2  rmind  */
    126  1.1.4.2  rmind #define OBS600_CPU_FREQ	(600 * 1000 * 1000)
    127  1.1.4.2  rmind #define OBS600_MEM_SIZE	(1 * 1024 * 1024 * 1024)
    128  1.1.4.2  rmind 
    129  1.1.4.2  rmind #define	TLB_PG_SIZE 	(16 * 1024 * 1024)
    130  1.1.4.2  rmind 
    131  1.1.4.2  rmind /*
    132  1.1.4.2  rmind  * Global variables used here and there
    133  1.1.4.2  rmind  */
    134  1.1.4.2  rmind char bootpath[256];
    135  1.1.4.2  rmind 
    136  1.1.4.2  rmind extern paddr_t msgbuf_paddr;
    137  1.1.4.2  rmind 
    138  1.1.4.2  rmind #if NKSYMS || defined(DDB) || defined(MODULAR)
    139  1.1.4.2  rmind void *startsym, *endsym;
    140  1.1.4.2  rmind #endif
    141  1.1.4.2  rmind 
    142  1.1.4.2  rmind void initppc(u_int, u_int, int, char *[], char *);
    143  1.1.4.2  rmind int lcsplx(int);
    144  1.1.4.2  rmind static int read_eeprom(int, char *);
    145  1.1.4.2  rmind 
    146  1.1.4.2  rmind 
    147  1.1.4.2  rmind void
    148  1.1.4.2  rmind initppc(u_int startkernel, u_int endkernel, int argc, char *argv[],
    149  1.1.4.2  rmind 	char *argstr)
    150  1.1.4.2  rmind {
    151  1.1.4.2  rmind 	vaddr_t va;
    152  1.1.4.2  rmind 	u_int memsize;
    153  1.1.4.2  rmind 
    154  1.1.4.2  rmind 	memsize = OBS600_MEM_SIZE;
    155  1.1.4.2  rmind 
    156  1.1.4.2  rmind 	/* Linear map kernel memory */
    157  1.1.4.2  rmind 	for (va = 0; va < endkernel; va += TLB_PG_SIZE)
    158  1.1.4.2  rmind 		ppc4xx_tlb_reserve(va, va, TLB_PG_SIZE, TLB_EX);
    159  1.1.4.2  rmind 
    160  1.1.4.2  rmind 	/*
    161  1.1.4.2  rmind 	 * Map console and I2C after RAM. (see pmap_tlbmiss())
    162  1.1.4.2  rmind 	 * All peripherals mapped on a page.
    163  1.1.4.2  rmind 	 */
    164  1.1.4.2  rmind 	ppc4xx_tlb_reserve(AMCC405EX_OPB_BASE, roundup(memsize, TLB_PG_SIZE),
    165  1.1.4.2  rmind 	    TLB_PG_SIZE, TLB_I | TLB_G);
    166  1.1.4.2  rmind 
    167  1.1.4.2  rmind 	/* Initialize AMCC 405EX CPU */
    168  1.1.4.2  rmind 	ibm40x_memsize_init(memsize, startkernel);
    169  1.1.4.2  rmind 	ibm4xx_init((void (*)(void))ext_intr);
    170  1.1.4.2  rmind 
    171  1.1.4.2  rmind 	/* Disable Watchdog, PIT and FIT interrupts. (u-boot uses PIT...) */
    172  1.1.4.2  rmind 	mtspr(SPR_TCR, 0);
    173  1.1.4.2  rmind 
    174  1.1.4.2  rmind 	/*
    175  1.1.4.2  rmind 	 * Set the page size.
    176  1.1.4.2  rmind 	 */
    177  1.1.4.2  rmind 	uvm_setpagesize();
    178  1.1.4.2  rmind 
    179  1.1.4.2  rmind 	/*
    180  1.1.4.2  rmind 	 * Initialize pmap module.
    181  1.1.4.2  rmind 	 */
    182  1.1.4.2  rmind 	pmap_bootstrap(startkernel, endkernel);
    183  1.1.4.2  rmind 
    184  1.1.4.2  rmind 
    185  1.1.4.2  rmind #if NKSYMS || defined(DDB) || defined(MODULAR)
    186  1.1.4.2  rmind 	ksyms_addsyms_elf((int)((u_int)endsym - (u_int)startsym), startsym, endsym);
    187  1.1.4.2  rmind #endif
    188  1.1.4.2  rmind #ifdef DDB
    189  1.1.4.2  rmind 	if (boothowto & RB_KDB)
    190  1.1.4.2  rmind 		Debugger();
    191  1.1.4.2  rmind #endif
    192  1.1.4.2  rmind #ifdef IPKDB
    193  1.1.4.2  rmind 	/*
    194  1.1.4.2  rmind 	 * Now trap to IPKDB
    195  1.1.4.2  rmind 	 */
    196  1.1.4.2  rmind 	ipkdb_init();
    197  1.1.4.2  rmind 	if (boothowto & RB_KDB)
    198  1.1.4.2  rmind 		ipkdb_connect(0);
    199  1.1.4.2  rmind #endif
    200  1.1.4.2  rmind }
    201  1.1.4.2  rmind 
    202  1.1.4.2  rmind void
    203  1.1.4.2  rmind consinit(void)
    204  1.1.4.2  rmind {
    205  1.1.4.2  rmind 
    206  1.1.4.2  rmind #if (NCOM > 0)
    207  1.1.4.2  rmind 	com_opb_cnattach(OBS600_COM_FREQ, CONADDR, CONSPEED, CONMODE);
    208  1.1.4.2  rmind #endif /* NCOM */
    209  1.1.4.2  rmind }
    210  1.1.4.2  rmind 
    211  1.1.4.2  rmind int
    212  1.1.4.2  rmind lcsplx(int ipl)
    213  1.1.4.2  rmind {
    214  1.1.4.2  rmind 
    215  1.1.4.2  rmind 	return spllower(ipl); 	/* XXX */
    216  1.1.4.2  rmind }
    217  1.1.4.2  rmind 
    218  1.1.4.2  rmind 
    219  1.1.4.2  rmind /*
    220  1.1.4.2  rmind  * Machine dependent startup code.
    221  1.1.4.2  rmind  */
    222  1.1.4.2  rmind void
    223  1.1.4.2  rmind cpu_startup(void)
    224  1.1.4.2  rmind {
    225  1.1.4.2  rmind 	prop_number_t pn;
    226  1.1.4.2  rmind 	prop_data_t pd;
    227  1.1.4.2  rmind 	u_char *macaddr, *macaddr1;
    228  1.1.4.2  rmind 	static u_char buf[16];	/* MAC address x2 buffer */
    229  1.1.4.2  rmind 
    230  1.1.4.2  rmind 	/*
    231  1.1.4.2  rmind 	 * cpu common startup
    232  1.1.4.2  rmind 	 */
    233  1.1.4.2  rmind 	ibm4xx_cpu_startup("OpenBlockS600 AMCC PowerPC 405EX Board");
    234  1.1.4.2  rmind 
    235  1.1.4.2  rmind 	/*
    236  1.1.4.2  rmind 	 * Set up the board properties database.
    237  1.1.4.2  rmind 	 */
    238  1.1.4.2  rmind 	board_info_init();
    239  1.1.4.2  rmind 
    240  1.1.4.2  rmind 	read_eeprom(sizeof(buf), buf);
    241  1.1.4.2  rmind 	macaddr = &buf[0];
    242  1.1.4.2  rmind 	macaddr1 = &buf[8];
    243  1.1.4.2  rmind 
    244  1.1.4.2  rmind 	pn = prop_number_create_integer(OBS600_CPU_FREQ);
    245  1.1.4.2  rmind 	KASSERT(pn != NULL);
    246  1.1.4.2  rmind 	if (prop_dictionary_set(board_properties, "processor-frequency", pn) ==
    247  1.1.4.2  rmind 	    false)
    248  1.1.4.2  rmind 		panic("setting processor-frequency");
    249  1.1.4.2  rmind 	prop_object_release(pn);
    250  1.1.4.2  rmind 
    251  1.1.4.2  rmind 	pn = prop_number_create_integer(OBS600_MEM_SIZE);
    252  1.1.4.2  rmind 	KASSERT(pn != NULL);
    253  1.1.4.2  rmind 	if (prop_dictionary_set(board_properties, "mem-size", pn) == false)
    254  1.1.4.2  rmind 		panic("setting mem-size");
    255  1.1.4.2  rmind 	prop_object_release(pn);
    256  1.1.4.2  rmind 
    257  1.1.4.2  rmind #define ETHER_ADDR_LEN	6
    258  1.1.4.2  rmind 
    259  1.1.4.2  rmind 	pd = prop_data_create_data_nocopy(macaddr, ETHER_ADDR_LEN);
    260  1.1.4.2  rmind 	KASSERT(pd != NULL);
    261  1.1.4.2  rmind 	if (prop_dictionary_set(board_properties, "emac0-mac-addr", pd) ==
    262  1.1.4.2  rmind 	    false)
    263  1.1.4.2  rmind 		panic("setting emac0-mac-addr");
    264  1.1.4.2  rmind 	prop_object_release(pd);
    265  1.1.4.2  rmind 	pd = prop_data_create_data_nocopy(macaddr1, ETHER_ADDR_LEN);
    266  1.1.4.2  rmind 	KASSERT(pd != NULL);
    267  1.1.4.2  rmind 	if (prop_dictionary_set(board_properties, "emac1-mac-addr", pd) ==
    268  1.1.4.2  rmind 	    false)
    269  1.1.4.2  rmind 		panic("setting emac1-mac-addr");
    270  1.1.4.2  rmind 	prop_object_release(pd);
    271  1.1.4.2  rmind 
    272  1.1.4.2  rmind 	/* emac0 connects to phy 2 and emac1 to phy 3 via RGMII. */
    273  1.1.4.2  rmind 	pn = prop_number_create_integer(2);
    274  1.1.4.2  rmind 	KASSERT(pn != NULL);
    275  1.1.4.2  rmind 	if (prop_dictionary_set(board_properties, "emac0-mii-phy", pn) == false)
    276  1.1.4.2  rmind 		panic("setting emac0-mii-phy");
    277  1.1.4.2  rmind 	prop_object_release(pn);
    278  1.1.4.2  rmind 	pn = prop_number_create_integer(3);
    279  1.1.4.2  rmind 	KASSERT(pn != NULL);
    280  1.1.4.2  rmind 	if (prop_dictionary_set(board_properties, "emac1-mii-phy", pn) == false)
    281  1.1.4.2  rmind 		panic("setting emac1-mii-phy");
    282  1.1.4.2  rmind 	prop_object_release(pn);
    283  1.1.4.2  rmind 
    284  1.1.4.2  rmind 	/*
    285  1.1.4.2  rmind 	 * Now that we have VM, malloc()s are OK in bus_space.
    286  1.1.4.2  rmind 	 */
    287  1.1.4.2  rmind 	bus_space_mallocok();
    288  1.1.4.2  rmind 
    289  1.1.4.2  rmind 	/*
    290  1.1.4.2  rmind 	 * no fake mapiodev
    291  1.1.4.2  rmind 	 */
    292  1.1.4.2  rmind 	fake_mapiodev = 0;
    293  1.1.4.3  rmind 
    294  1.1.4.3  rmind 	splraise(-1);
    295  1.1.4.2  rmind }
    296  1.1.4.2  rmind 
    297  1.1.4.2  rmind /*
    298  1.1.4.2  rmind  * Halt or reboot the machine after syncing/dumping according to howto.
    299  1.1.4.2  rmind  */
    300  1.1.4.2  rmind void
    301  1.1.4.2  rmind cpu_reboot(int howto, char *what)
    302  1.1.4.2  rmind {
    303  1.1.4.2  rmind 	static int syncing;
    304  1.1.4.2  rmind 	static char str[256];
    305  1.1.4.2  rmind 	char *ap = str, *ap1 = ap;
    306  1.1.4.2  rmind 
    307  1.1.4.2  rmind 	boothowto = howto;
    308  1.1.4.2  rmind 	if (!cold && !(howto & RB_NOSYNC) && !syncing) {
    309  1.1.4.2  rmind 		syncing = 1;
    310  1.1.4.2  rmind 		vfs_shutdown();		/* sync */
    311  1.1.4.2  rmind 		resettodr();		/* set wall clock */
    312  1.1.4.2  rmind 	}
    313  1.1.4.2  rmind 
    314  1.1.4.2  rmind 	splhigh();
    315  1.1.4.2  rmind 
    316  1.1.4.2  rmind 	if (!cold && (howto & RB_DUMP))
    317  1.1.4.2  rmind 		ibm4xx_dumpsys();
    318  1.1.4.2  rmind 
    319  1.1.4.2  rmind 	doshutdownhooks();
    320  1.1.4.2  rmind 
    321  1.1.4.2  rmind 	pmf_system_shutdown(boothowto);
    322  1.1.4.2  rmind 
    323  1.1.4.2  rmind 	if ((howto & RB_POWERDOWN) == RB_POWERDOWN) {
    324  1.1.4.2  rmind 	  /* Power off here if we know how...*/
    325  1.1.4.2  rmind 	}
    326  1.1.4.2  rmind 
    327  1.1.4.2  rmind 	if (howto & RB_HALT) {
    328  1.1.4.2  rmind 		printf("halted\n\n");
    329  1.1.4.2  rmind 
    330  1.1.4.2  rmind #if 0
    331  1.1.4.2  rmind 		goto reboot;	/* XXX for now... */
    332  1.1.4.2  rmind #endif
    333  1.1.4.2  rmind 
    334  1.1.4.2  rmind #ifdef DDB
    335  1.1.4.2  rmind 		printf("dropping to debugger\n");
    336  1.1.4.2  rmind 		while(1)
    337  1.1.4.2  rmind 			Debugger();
    338  1.1.4.2  rmind #endif
    339  1.1.4.2  rmind 	}
    340  1.1.4.2  rmind 
    341  1.1.4.2  rmind 	printf("rebooting\n\n");
    342  1.1.4.2  rmind 	if (what && *what) {
    343  1.1.4.2  rmind 		if (strlen(what) > sizeof str - 5)
    344  1.1.4.2  rmind 			printf("boot string too large, ignored\n");
    345  1.1.4.2  rmind 		else {
    346  1.1.4.2  rmind 			strcpy(str, what);
    347  1.1.4.2  rmind 			ap1 = ap = str + strlen(str);
    348  1.1.4.2  rmind 			*ap++ = ' ';
    349  1.1.4.2  rmind 		}
    350  1.1.4.2  rmind 	}
    351  1.1.4.2  rmind 	*ap++ = '-';
    352  1.1.4.2  rmind 	if (howto & RB_SINGLE)
    353  1.1.4.2  rmind 		*ap++ = 's';
    354  1.1.4.2  rmind 	if (howto & RB_KDB)
    355  1.1.4.2  rmind 		*ap++ = 'd';
    356  1.1.4.2  rmind 	*ap++ = 0;
    357  1.1.4.2  rmind 	if (ap[-2] == '-')
    358  1.1.4.2  rmind 		*ap1 = 0;
    359  1.1.4.2  rmind 
    360  1.1.4.2  rmind 	/* flush cache for msgbuf */
    361  1.1.4.2  rmind 	__syncicache((void *)msgbuf_paddr, round_page(MSGBUFSIZE));
    362  1.1.4.2  rmind 
    363  1.1.4.2  rmind #if 0
    364  1.1.4.2  rmind  reboot:
    365  1.1.4.2  rmind #endif
    366  1.1.4.2  rmind 	ppc4xx_reset();
    367  1.1.4.2  rmind 
    368  1.1.4.2  rmind 	printf("ppc4xx_reset() failed!\n");
    369  1.1.4.2  rmind #ifdef DDB
    370  1.1.4.2  rmind 	while(1)
    371  1.1.4.2  rmind 		Debugger();
    372  1.1.4.2  rmind #else
    373  1.1.4.2  rmind 	while (1)
    374  1.1.4.2  rmind 		/* nothing */;
    375  1.1.4.2  rmind #endif
    376  1.1.4.2  rmind }
    377  1.1.4.2  rmind 
    378  1.1.4.2  rmind /* This function assume already initialized for I2C... */
    379  1.1.4.2  rmind static int
    380  1.1.4.2  rmind read_eeprom(int len, char *buf)
    381  1.1.4.2  rmind {
    382  1.1.4.2  rmind 	bus_space_tag_t bst = opb_get_bus_space_tag();
    383  1.1.4.2  rmind 	bus_space_handle_t bsh;
    384  1.1.4.2  rmind 	uint8_t mdcntl, sts;
    385  1.1.4.2  rmind 	int cnt, i = 0;
    386  1.1.4.2  rmind 
    387  1.1.4.2  rmind #define I2C_EEPROM_ADDR	0x52
    388  1.1.4.2  rmind 
    389  1.1.4.2  rmind 	if (bus_space_map(bst, AMCC405EX_IIC0_BASE, IIC_NREG, 0, &bsh))
    390  1.1.4.2  rmind 		return ENOMEM; /* ??? */
    391  1.1.4.2  rmind 
    392  1.1.4.2  rmind 	/* Clear Stop Complete Bit */
    393  1.1.4.2  rmind 	bus_space_write_1(bst, bsh, IIC_STS, IIC_STS_SCMP);
    394  1.1.4.2  rmind 	/* Check init */
    395  1.1.4.2  rmind 	do {
    396  1.1.4.2  rmind 		/* Get status */
    397  1.1.4.2  rmind 		sts = bus_space_read_1(bst, bsh, IIC_STS);
    398  1.1.4.2  rmind 	} while ((sts & IIC_STS_PT));
    399  1.1.4.2  rmind 
    400  1.1.4.2  rmind 	mdcntl = bus_space_read_1(bst, bsh, IIC_MDCNTL);
    401  1.1.4.2  rmind 	bus_space_write_1(bst, bsh, IIC_MDCNTL,
    402  1.1.4.2  rmind 	    mdcntl | IIC_MDCNTL_FMDB | IIC_MDCNTL_FSDB);
    403  1.1.4.2  rmind 
    404  1.1.4.2  rmind 	/* 7-bit adressing */
    405  1.1.4.2  rmind 	bus_space_write_1(bst, bsh, IIC_HMADR, 0);
    406  1.1.4.2  rmind 	bus_space_write_1(bst, bsh, IIC_LMADR, I2C_EEPROM_ADDR << 1);
    407  1.1.4.2  rmind 
    408  1.1.4.2  rmind 	bus_space_write_1(bst, bsh, IIC_MDBUF, 0);
    409  1.1.4.2  rmind 	bus_space_write_1(bst, bsh, IIC_CNTL, IIC_CNTL_PT);
    410  1.1.4.2  rmind 	do {
    411  1.1.4.2  rmind 		/* Get status */
    412  1.1.4.2  rmind 		sts = bus_space_read_1(bst, bsh, IIC_STS);
    413  1.1.4.2  rmind 	} while ((sts & IIC_STS_PT) && !(sts & IIC_STS_ERR));
    414  1.1.4.2  rmind 
    415  1.1.4.2  rmind 	cnt = 0;
    416  1.1.4.2  rmind 	while (cnt < len) {
    417  1.1.4.2  rmind 		/* always read 4byte */
    418  1.1.4.2  rmind 		bus_space_write_1(bst, bsh, IIC_CNTL,
    419  1.1.4.2  rmind 		    IIC_CNTL_PT | IIC_CNTL_RW | IIC_CNTL_TCT);
    420  1.1.4.2  rmind 		do {
    421  1.1.4.2  rmind 			/* Get status */
    422  1.1.4.2  rmind 			sts = bus_space_read_1(bst, bsh, IIC_STS);
    423  1.1.4.2  rmind 		} while ((sts & IIC_STS_PT) && !(sts & IIC_STS_ERR));
    424  1.1.4.2  rmind 
    425  1.1.4.2  rmind 		if ((sts & IIC_STS_PT) || (sts & IIC_STS_ERR))
    426  1.1.4.2  rmind 			break;
    427  1.1.4.2  rmind 		if (sts & IIC_STS_MDBS) {
    428  1.1.4.2  rmind 			delay(1);
    429  1.1.4.2  rmind 			/* read 4byte */
    430  1.1.4.2  rmind 			for (i = 0; i < 4 && cnt < len; i++, cnt++)
    431  1.1.4.2  rmind 				buf[cnt] =
    432  1.1.4.2  rmind 				    bus_space_read_1(bst, bsh, IIC_MDBUF);
    433  1.1.4.2  rmind 		}
    434  1.1.4.2  rmind 	}
    435  1.1.4.2  rmind 	for ( ; i < 4; i++)
    436  1.1.4.2  rmind 		(void) bus_space_read_1(bst, bsh, IIC_MDBUF);
    437  1.1.4.2  rmind 
    438  1.1.4.2  rmind 	bus_space_unmap(bst, bsh, IIC_NREG);
    439  1.1.4.2  rmind 
    440  1.1.4.2  rmind 	return (cnt == len) ? 0 : EINVAL;
    441  1.1.4.2  rmind }
    442