Home | History | Annotate | Line # | Download | only in ev64260
machdep.c revision 1.12
      1  1.12  thorpej /*	$NetBSD: machdep.c,v 1.12 2003/06/14 17:01:11 thorpej Exp $	*/
      2   1.1     matt 
      3   1.1     matt /*
      4   1.1     matt  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
      5   1.1     matt  * Copyright (C) 1995, 1996 TooLs GmbH.
      6   1.1     matt  * All rights reserved.
      7   1.1     matt  *
      8   1.1     matt  * Redistribution and use in source and binary forms, with or without
      9   1.1     matt  * modification, are permitted provided that the following conditions
     10   1.1     matt  * are met:
     11   1.1     matt  * 1. Redistributions of source code must retain the above copyright
     12   1.1     matt  *    notice, this list of conditions and the following disclaimer.
     13   1.1     matt  * 2. Redistributions in binary form must reproduce the above copyright
     14   1.1     matt  *    notice, this list of conditions and the following disclaimer in the
     15   1.1     matt  *    documentation and/or other materials provided with the distribution.
     16   1.1     matt  * 3. All advertising materials mentioning features or use of this software
     17   1.1     matt  *    must display the following acknowledgement:
     18   1.1     matt  *	This product includes software developed by TooLs GmbH.
     19   1.1     matt  * 4. The name of TooLs GmbH may not be used to endorse or promote products
     20   1.1     matt  *    derived from this software without specific prior written permission.
     21   1.1     matt  *
     22   1.1     matt  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
     23   1.1     matt  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24   1.1     matt  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25   1.1     matt  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     26   1.1     matt  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     27   1.1     matt  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     28   1.1     matt  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     29   1.1     matt  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     30   1.1     matt  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     31   1.1     matt  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32   1.1     matt  */
     33   1.1     matt 
     34   1.1     matt #include "opt_marvell.h"
     35   1.8     matt #include "opt_ev64260.h"
     36   1.1     matt #include "opt_compat_netbsd.h"
     37   1.1     matt #include "opt_ddb.h"
     38   1.1     matt #include "opt_inet.h"
     39   1.1     matt #include "opt_ccitt.h"
     40   1.1     matt #include "opt_iso.h"
     41   1.1     matt #include "opt_ns.h"
     42   1.1     matt #include "opt_ipkdb.h"
     43   1.1     matt 
     44   1.1     matt #include <sys/param.h>
     45   1.1     matt #include <sys/conf.h>
     46   1.1     matt #include <sys/device.h>
     47   1.1     matt #include <sys/kernel.h>
     48   1.1     matt #include <sys/malloc.h>
     49   1.1     matt #include <sys/mount.h>
     50   1.1     matt #include <sys/msgbuf.h>
     51   1.1     matt #include <sys/proc.h>
     52   1.1     matt #include <sys/reboot.h>
     53   1.4     matt #include <sys/extent.h>
     54   1.1     matt #include <sys/syslog.h>
     55   1.1     matt #include <sys/systm.h>
     56   1.6     matt #include <sys/termios.h>
     57  1.11    ragge #include <sys/ksyms.h>
     58   1.1     matt 
     59   1.1     matt #include <uvm/uvm.h>
     60   1.1     matt #include <uvm/uvm_extern.h>
     61   1.1     matt 
     62   1.1     matt #include <net/netisr.h>
     63   1.1     matt 
     64   1.1     matt #include <machine/bus.h>
     65   1.1     matt #include <machine/db_machdep.h>
     66   1.1     matt #include <machine/intr.h>
     67   1.1     matt #include <machine/pmap.h>
     68   1.1     matt #include <machine/powerpc.h>
     69   1.1     matt #include <machine/trap.h>
     70   1.1     matt 
     71   1.1     matt #include <powerpc/oea/bat.h>
     72   1.1     matt #include <powerpc/marvell/watchdog.h>
     73   1.1     matt 
     74   1.1     matt #include <ddb/db_extern.h>
     75   1.1     matt 
     76   1.1     matt #include <dev/cons.h>
     77   1.1     matt 
     78   1.1     matt #include "vga.h"
     79   1.1     matt #if (NVGA > 0)
     80   1.1     matt #include <dev/ic/mc6845reg.h>
     81   1.1     matt #include <dev/ic/pcdisplayvar.h>
     82   1.1     matt #include <dev/ic/vgareg.h>
     83   1.1     matt #include <dev/ic/vgavar.h>
     84   1.1     matt #endif
     85   1.1     matt 
     86   1.1     matt #include "isa.h"
     87   1.1     matt #if (NISA > 0)
     88   1.1     matt void isa_intr_init(void);
     89   1.1     matt #endif
     90   1.1     matt 
     91   1.1     matt #include "pckbc.h"
     92   1.1     matt #if (NPCKBC > 0)
     93   1.1     matt #include <dev/isa/isareg.h>
     94   1.1     matt #include <dev/ic/i8042reg.h>
     95   1.1     matt #include <dev/ic/pckbcvar.h>
     96   1.1     matt #endif
     97   1.1     matt 
     98   1.1     matt #include "com.h"
     99   1.1     matt #if (NCOM > 0)
    100   1.1     matt #include <dev/ic/comreg.h>
    101   1.1     matt #include <dev/ic/comvar.h>
    102   1.1     matt #endif
    103   1.1     matt 
    104   1.2     matt #include <dev/marvell/gtreg.h>
    105   1.1     matt #include <dev/marvell/gtvar.h>
    106   1.8     matt #include <dev/marvell/gtethreg.h>
    107   1.1     matt 
    108   1.6     matt #include "gtmpsc.h"
    109   1.6     matt #if (NGTMPSC > 0)
    110   1.6     matt #include <dev/marvell/gtsdmareg.h>
    111   1.6     matt #include <dev/marvell/gtmpscreg.h>
    112   1.6     matt #include <dev/marvell/gtmpscvar.h>
    113   1.6     matt #endif
    114   1.6     matt 
    115  1.11    ragge #include "ksyms.h"
    116  1.11    ragge 
    117   1.1     matt /*
    118   1.1     matt  * Global variables used here and there
    119   1.1     matt  */
    120   1.1     matt extern struct user *proc0paddr;
    121   1.1     matt 
    122   1.1     matt #define	PMONMEMREGIONS	32
    123   1.1     matt struct mem_region physmemr[PMONMEMREGIONS], availmemr[PMONMEMREGIONS];
    124   1.1     matt 
    125   1.1     matt char *bootpath;
    126   1.1     matt 
    127   1.1     matt void initppc(u_int, u_int, u_int, void *); /* Called from locore */
    128   1.1     matt void strayintr(int);
    129   1.1     matt int lcsplx(int);
    130   1.4     matt void gt_bus_space_init(void);
    131   1.8     matt void gt_find_memory(bus_space_tag_t, bus_space_handle_t, paddr_t);
    132   1.8     matt void gt_halt(bus_space_tag_t, bus_space_handle_t);
    133   1.5     matt void return_to_dink(int);
    134   1.5     matt void calc_delayconst(void);
    135   1.4     matt 
    136   1.8     matt void kcomcnputs(dev_t, const char *);
    137   1.8     matt 
    138   1.4     matt struct powerpc_bus_space gt_pci0_mem_bs_tag = {
    139   1.4     matt 	_BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE,
    140   1.4     matt 	0x00000000, 0x00000000, 0x00000000,
    141   1.4     matt };
    142   1.4     matt struct powerpc_bus_space gt_pci0_io_bs_tag = {
    143   1.4     matt 	_BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_IO_TYPE,
    144   1.4     matt 	0x00000000, 0x00000000, 0x00000000,
    145   1.4     matt };
    146   1.4     matt struct powerpc_bus_space gt_pci1_mem_bs_tag = {
    147   1.4     matt 	_BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE,
    148   1.4     matt 	0x00000000, 0x00000000, 0x00000000,
    149   1.4     matt };
    150   1.4     matt struct powerpc_bus_space gt_pci1_io_bs_tag = {
    151   1.4     matt 	_BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_IO_TYPE,
    152   1.4     matt 	0x00000000, 0x00000000, 0x00000000,
    153   1.4     matt };
    154   1.8     matt struct powerpc_bus_space gt_obio0_bs_tag = {
    155   1.8     matt 	_BUS_SPACE_BIG_ENDIAN|_BUS_SPACE_MEM_TYPE|OBIO0_STRIDE,
    156   1.8     matt 	0x00000000, 0x00000000, 0x00000000,
    157   1.8     matt };
    158   1.8     matt struct powerpc_bus_space gt_obio1_bs_tag = {
    159   1.8     matt 	_BUS_SPACE_BIG_ENDIAN|_BUS_SPACE_MEM_TYPE|OBIO1_STRIDE,
    160   1.8     matt 	0x00000000, 0x00000000, 0x00000000,
    161   1.8     matt };
    162   1.4     matt struct powerpc_bus_space gt_obio2_bs_tag = {
    163   1.8     matt 	_BUS_SPACE_BIG_ENDIAN|_BUS_SPACE_MEM_TYPE|OBIO2_STRIDE,
    164   1.8     matt 	0x00000000, 0x00000000, 0x00000000,
    165   1.8     matt };
    166   1.8     matt struct powerpc_bus_space gt_obio3_bs_tag = {
    167   1.8     matt 	_BUS_SPACE_BIG_ENDIAN|_BUS_SPACE_MEM_TYPE|OBIO3_STRIDE,
    168   1.8     matt 	0x00000000, 0x00000000, 0x00000000,
    169   1.8     matt };
    170   1.8     matt struct powerpc_bus_space gt_bootcs_bs_tag = {
    171   1.8     matt 	_BUS_SPACE_BIG_ENDIAN|_BUS_SPACE_MEM_TYPE,
    172   1.4     matt 	0x00000000, 0x00000000, 0x00000000,
    173   1.4     matt };
    174   1.4     matt struct powerpc_bus_space gt_mem_bs_tag = {
    175   1.4     matt 	_BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE,
    176   1.4     matt 	GT_BASE, 0x00000000, 0x00010000,
    177   1.4     matt };
    178   1.4     matt 
    179   1.4     matt bus_space_handle_t gt_memh;
    180   1.4     matt 
    181   1.8     matt struct powerpc_bus_space *obio_bs_tags[5] = {
    182   1.8     matt 	&gt_obio0_bs_tag, &gt_obio1_bs_tag, &gt_obio2_bs_tag,
    183   1.9     matt 	&gt_obio3_bs_tag, &gt_bootcs_bs_tag
    184   1.4     matt };
    185   1.1     matt 
    186   1.8     matt static char ex_storage[10][EXTENT_FIXED_STORAGE_SIZE(8)]
    187   1.4     matt     __attribute__((aligned(8)));
    188   1.4     matt 
    189   1.8     matt const struct gt_decode_info {
    190   1.8     matt 	bus_addr_t low_decode;
    191   1.8     matt 	bus_addr_t high_decode;
    192   1.8     matt } decode_regs[] = {
    193   1.8     matt     {	GT_SCS0_Low_Decode,	GT_SCS0_High_Decode },
    194   1.8     matt     {	GT_SCS1_Low_Decode,	GT_SCS1_High_Decode },
    195   1.8     matt     {	GT_SCS2_Low_Decode,	GT_SCS2_High_Decode },
    196   1.8     matt     {	GT_SCS3_Low_Decode,	GT_SCS3_High_Decode },
    197   1.8     matt     {	GT_CS0_Low_Decode,	GT_CS0_High_Decode },
    198   1.8     matt     {	GT_CS1_Low_Decode,	GT_CS1_High_Decode },
    199   1.8     matt     {	GT_CS2_Low_Decode,	GT_CS2_High_Decode },
    200   1.8     matt     {	GT_CS3_Low_Decode,	GT_CS3_High_Decode },
    201   1.8     matt     {	GT_BootCS_Low_Decode,	GT_BootCS_High_Decode },
    202   1.1     matt };
    203   1.1     matt 
    204   1.1     matt void
    205   1.1     matt initppc(startkernel, endkernel, args, btinfo)
    206   1.1     matt 	u_int startkernel, endkernel, args;
    207   1.1     matt 	void *btinfo;
    208   1.1     matt {
    209   1.8     matt 	oea_batinit(0xf0000000, BAT_BL_256M);
    210   1.8     matt 	oea_init((void (*)(void))ext_intr);
    211   1.1     matt 
    212   1.8     matt 	calc_delayconst();			/* Set CPU clock */
    213   1.1     matt 
    214   1.8     matt 	DELAY(100000);
    215   1.1     matt 
    216   1.4     matt 	gt_bus_space_init();
    217  1.10  thorpej 	gt_find_memory(&gt_mem_bs_tag, gt_memh, roundup(endkernel, PAGE_SIZE));
    218   1.8     matt 	gt_halt(&gt_mem_bs_tag, gt_memh);
    219   1.1     matt 
    220   1.8     matt 	/*
    221   1.8     matt 	 * Now that we known how much memory, reinit the bats.
    222   1.8     matt 	 */
    223   1.8     matt 	oea_batinit(0xf0000000, BAT_BL_256M);
    224   1.5     matt 
    225   1.4     matt 	consinit();
    226   1.1     matt 
    227   1.1     matt #if (NISA > 0)
    228   1.1     matt 	isa_intr_init();
    229   1.1     matt #endif
    230   1.1     matt 
    231   1.1     matt         /*
    232   1.1     matt 	 * Set the page size.
    233   1.1     matt 	 */
    234   1.1     matt 	uvm_setpagesize();
    235   1.1     matt 
    236   1.1     matt 	/*
    237   1.1     matt 	 * Initialize pmap module.
    238   1.1     matt 	 */
    239   1.1     matt 	pmap_bootstrap(startkernel, endkernel);
    240   1.1     matt 
    241  1.11    ragge #if NKSYMS || defined(DDB) || defined(LKM)
    242   1.8     matt 	{
    243   1.8     matt 		extern void *startsym, *endsym;
    244  1.11    ragge 		ksyms_init((int)((u_int)endsym - (u_int)startsym),
    245   1.8     matt 		    startsym, endsym);
    246   1.8     matt 	}
    247   1.1     matt #endif
    248   1.1     matt #ifdef IPKDB
    249   1.1     matt 	/*
    250   1.1     matt 	 * Now trap to IPKDB
    251   1.1     matt 	 */
    252   1.1     matt 	ipkdb_init();
    253   1.1     matt 	if (boothowto & RB_KDB)
    254   1.1     matt 		ipkdb_connect(0);
    255   1.1     matt #endif
    256   1.1     matt }
    257   1.1     matt 
    258   1.1     matt void
    259   1.8     matt mem_regions(struct mem_region **mem, struct mem_region **avail)
    260   1.1     matt {
    261   1.1     matt 	*mem = physmemr;
    262   1.1     matt 	*avail = availmemr;
    263   1.1     matt }
    264   1.1     matt 
    265   1.8     matt static __inline void
    266   1.8     matt gt_record_memory(int j, paddr_t start, paddr_t end, paddr_t endkernel)
    267   1.8     matt {
    268   1.8     matt 	physmemr[j].start = start;
    269   1.8     matt 	physmemr[j].size = end - start;
    270   1.8     matt 	if (start < endkernel)
    271   1.8     matt 		start = endkernel;
    272   1.8     matt 	availmemr[j].start = start;
    273   1.8     matt 	availmemr[j].size = end - start;
    274   1.8     matt }
    275   1.8     matt 
    276   1.8     matt void
    277   1.8     matt gt_find_memory(bus_space_tag_t memt, bus_space_handle_t memh,
    278   1.8     matt 	paddr_t endkernel)
    279   1.8     matt {
    280   1.8     matt 	paddr_t start, end;
    281   1.8     matt 	int i, j = 0, first = 1;
    282   1.8     matt 
    283   1.8     matt 	/*
    284   1.8     matt 	 * Round kernel end to a page boundary.
    285   1.8     matt 	 */
    286   1.8     matt 	for (i = 0; i < 4; i++) {
    287   1.8     matt 		paddr_t nstart, nend;
    288   1.8     matt 		nstart = GT_LowAddr_GET(bus_space_read_4(&gt_mem_bs_tag,
    289   1.8     matt 		    gt_memh, decode_regs[i].low_decode));
    290   1.8     matt 		nend = GT_HighAddr_GET(bus_space_read_4(&gt_mem_bs_tag,
    291   1.8     matt 		    gt_memh, decode_regs[i].high_decode)) + 1;
    292   1.8     matt 		if (nstart >= nend)
    293   1.8     matt 			continue;
    294   1.8     matt 		if (first) {
    295   1.8     matt 			/*
    296   1.8     matt 			 * First entry?  Just remember it.
    297   1.8     matt 			 */
    298   1.8     matt 			start = nstart;
    299   1.8     matt 			end  = nend;
    300   1.8     matt 			first = 0;
    301   1.8     matt 		} else if (nstart == end) {
    302   1.8     matt 			/*
    303   1.8     matt 			 * Contiguous?  Just update the end.
    304   1.8     matt 			 */
    305   1.8     matt 			end = nend;
    306   1.8     matt 		} else {
    307   1.8     matt 			/*
    308   1.8     matt 			 * Disjoint?  record it.
    309   1.8     matt 			 */
    310   1.8     matt 			gt_record_memory(j, start, end, endkernel);
    311   1.8     matt 			start = nstart;
    312   1.8     matt 			end = nend;
    313   1.8     matt 			j++;
    314   1.8     matt 		}
    315   1.8     matt 	}
    316   1.8     matt 	gt_record_memory(j, start, end, endkernel);
    317   1.8     matt }
    318   1.8     matt 
    319   1.1     matt /*
    320   1.1     matt  * Machine dependent startup code.
    321   1.1     matt  */
    322   1.1     matt void
    323   1.8     matt cpu_startup(void)
    324   1.1     matt {
    325   1.1     matt 	register_t msr;
    326   1.1     matt 
    327   1.1     matt 	oea_startup(NULL);
    328   1.1     matt 
    329   1.1     matt 	/*
    330   1.1     matt 	 * Now that we have VM, malloc()s are OK in bus_space.
    331   1.1     matt 	 */
    332   1.3     matt 	bus_space_mallocok();
    333   1.1     matt 
    334   1.1     matt 	/*
    335   1.1     matt 	 * Now allow hardware interrupts.
    336   1.1     matt 	 */
    337   1.1     matt 	splhigh();
    338   1.1     matt 	__asm __volatile ("mfmsr %0; ori %0,%0,%1; mtmsr %0"
    339   1.1     matt 	    :	"=r"(msr)
    340   1.1     matt 	    :	"K"(PSL_EE));
    341   1.1     matt }
    342   1.1     matt 
    343   1.1     matt /*
    344   1.1     matt  * consinit
    345   1.1     matt  * Initialize system console.
    346   1.1     matt  */
    347   1.1     matt void
    348   1.8     matt consinit(void)
    349   1.1     matt {
    350   1.6     matt #ifdef MPSC_CONSOLE
    351   1.6     matt 	/* PMON using MPSC0 @ 9600 */
    352   1.8     matt 	gtmpsccnattach(&gt_mem_bs_tag, gt_memh, MPSC_CONSOLE, 9600,
    353   1.6     matt 	    (TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8);
    354   1.6     matt #else
    355   1.4     matt 	/* PPCBOOT using COM1 @ 57600 */
    356  1.12  thorpej 	comcnattach(&gt_obio2_bs_tag, 0, 57600,
    357  1.12  thorpej 	    COM_FREQ*2, COM_TYPE_NORMAL,
    358   1.4     matt 	    (TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8);
    359   1.4     matt #endif
    360   1.1     matt }
    361   1.1     matt 
    362   1.1     matt #if (NPCKBC > 0) && (NPCKBD == 0)
    363   1.1     matt /*
    364   1.1     matt  * glue code to support old console code with the
    365   1.1     matt  * mi keyboard controller driver
    366   1.1     matt  */
    367   1.1     matt int
    368   1.8     matt pckbc_machdep_cnattach(pckbc_tag_t kbctag, pckbc_slot_t kbcslot)
    369   1.1     matt {
    370   1.1     matt #if (NPC > 0)
    371   1.1     matt 	return (pcconskbd_cnattach(kbctag, kbcslot));
    372   1.1     matt #else
    373   1.1     matt 	return (ENXIO);
    374   1.1     matt #endif
    375   1.1     matt }
    376   1.1     matt #endif
    377   1.1     matt 
    378   1.1     matt /*
    379   1.1     matt  * Stray interrupts.
    380   1.1     matt  */
    381   1.1     matt void
    382   1.1     matt strayintr(int irq)
    383   1.1     matt {
    384   1.1     matt 	log(LOG_ERR, "stray interrupt %d\n", irq);
    385   1.1     matt }
    386   1.1     matt 
    387   1.1     matt /*
    388   1.1     matt  * Halt or reboot the machine after syncing/dumping according to howto.
    389   1.1     matt  */
    390   1.1     matt void
    391   1.8     matt cpu_reboot(int howto, char *what)
    392   1.1     matt {
    393   1.1     matt 	static int syncing;
    394   1.1     matt 	static char str[256];
    395   1.1     matt 	char *ap = str, *ap1 = ap;
    396   1.1     matt 
    397   1.1     matt 	boothowto = howto;
    398   1.1     matt 	if (!cold && !(howto & RB_NOSYNC) && !syncing) {
    399   1.1     matt 		syncing = 1;
    400   1.1     matt 		vfs_shutdown();		/* sync */
    401   1.1     matt 		resettodr();		/* set wall clock */
    402   1.1     matt 	}
    403   1.1     matt 	splhigh();
    404   1.1     matt 	if (howto & RB_HALT) {
    405   1.1     matt 		doshutdownhooks();
    406   1.1     matt 		printf("halted\n\n");
    407   1.1     matt 		cnhalt();
    408   1.1     matt 		while(1);
    409   1.1     matt 	}
    410   1.1     matt 	if (!cold && (howto & RB_DUMP))
    411   1.1     matt 		oea_dumpsys();
    412   1.1     matt 	doshutdownhooks();
    413   1.1     matt 	printf("rebooting\n\n");
    414   1.1     matt 	if (what && *what) {
    415   1.1     matt 		if (strlen(what) > sizeof str - 5)
    416   1.1     matt 			printf("boot string too large, ignored\n");
    417   1.1     matt 		else {
    418   1.1     matt 			strcpy(str, what);
    419   1.1     matt 			ap1 = ap = str + strlen(str);
    420   1.1     matt 			*ap++ = ' ';
    421   1.1     matt 		}
    422   1.1     matt 	}
    423   1.1     matt 	*ap++ = '-';
    424   1.1     matt 	if (howto & RB_SINGLE)
    425   1.1     matt 		*ap++ = 's';
    426   1.1     matt 	if (howto & RB_KDB)
    427   1.1     matt 		*ap++ = 'd';
    428   1.1     matt 	*ap++ = 0;
    429   1.1     matt 	if (ap[-2] == '-')
    430   1.1     matt 		*ap1 = 0;
    431   1.1     matt #if 0
    432   1.1     matt 	{
    433   1.1     matt 		void mvpppc_reboot(void);
    434   1.1     matt 		mvpppc_reboot();
    435   1.1     matt 	}
    436   1.1     matt #endif
    437   1.1     matt 	gt_watchdog_reset();
    438   1.1     matt 	/* NOTREACHED */
    439   1.1     matt 	while (1);
    440   1.1     matt }
    441   1.1     matt 
    442   1.1     matt int
    443   1.8     matt lcsplx(int ipl)
    444   1.1     matt {
    445   1.1     matt 	return spllower(ipl);
    446   1.1     matt }
    447   1.1     matt 
    448   1.8     matt void
    449   1.8     matt gt_halt(bus_space_tag_t gt_memt, bus_space_handle_t gt_memh)
    450   1.8     matt {
    451   1.8     matt 	int i;
    452   1.8     matt 	u_int32_t data;
    453   1.8     matt 
    454   1.9     matt 	/*
    455   1.9     matt 	 * Shut down the MPSC ports
    456   1.9     matt 	 */
    457   1.9     matt 	for (i = 0; i < 2; i++) {
    458   1.9     matt 		bus_space_write_4(gt_memt, gt_memh,
    459   1.9     matt 		    SDMA_U_SDCM(i), SDMA_SDCM_AR|SDMA_SDCM_AT);
    460   1.9     matt 		for (;;) {
    461   1.9     matt 			data = bus_space_read_4(gt_memt, gt_memh,
    462   1.9     matt 			    SDMA_U_SDCM(i));
    463   1.9     matt 			if (((SDMA_SDCM_AR|SDMA_SDCM_AT) & data) == 0)
    464   1.9     matt 				break;
    465   1.9     matt 		}
    466   1.9     matt 	}
    467   1.9     matt 
    468   1.8     matt 	/*
    469   1.8     matt 	 * Shut down the Ethernets
    470   1.8     matt 	 */
    471   1.8     matt 	for (i = 0; i < 3; i++) {
    472   1.8     matt 		bus_space_write_4(gt_memt, gt_memh,
    473   1.8     matt 		    ETH_ESDCMR(2), ETH_ESDCMR_AR|ETH_ESDCMR_AT);
    474   1.8     matt 		for (;;) {
    475   1.8     matt 			data = bus_space_read_4(gt_memt, gt_memh,
    476   1.8     matt 			    ETH_ESDCMR(i));
    477   1.8     matt 			if (((ETH_ESDCMR_AR|ETH_ESDCMR_AT) & data) == 0)
    478   1.8     matt 				break;
    479   1.8     matt 		}
    480   1.8     matt 		data = bus_space_read_4(gt_memt, gt_memh, ETH_EPCR(i));
    481   1.8     matt 		data &= ~ETH_EPCR_EN;
    482   1.8     matt 		bus_space_write_4(gt_memt, gt_memh, ETH_EPCR(i), data);
    483   1.8     matt 	}
    484   1.8     matt }
    485   1.8     matt 
    486   1.1     matt int
    487   1.1     matt gtget_macaddr(struct gt_softc *gt, int macno, char *enaddr)
    488   1.1     matt {
    489   1.1     matt 	enaddr[0] = 0x02;
    490   1.1     matt 	enaddr[1] = 0x00;
    491   1.1     matt 	enaddr[2] = 0x04;
    492   1.1     matt 	enaddr[3] = 0x00;
    493   1.1     matt 	enaddr[4] = 0x00;
    494   1.1     matt 	enaddr[5] = 0x04 + macno;
    495   1.1     matt 
    496   1.1     matt 	return 0;
    497   1.1     matt }
    498   1.4     matt 
    499   1.4     matt void
    500   1.4     matt gt_bus_space_init(void)
    501   1.4     matt {
    502   1.4     matt 	bus_space_tag_t gt_memt = &gt_mem_bs_tag;
    503   1.8     matt 	const struct gt_decode_info *di;
    504   1.4     matt 	uint32_t datal, datah;
    505   1.4     matt 	int error;
    506   1.8     matt 	int bs = 0;
    507   1.8     matt 	int j;
    508   1.4     matt 
    509   1.4     matt 	error = bus_space_init(&gt_mem_bs_tag, "gtmem",
    510   1.8     matt 	    ex_storage[bs], sizeof(ex_storage[bs]));
    511   1.4     matt 
    512   1.8     matt 	error = bus_space_map(gt_memt, 0, 0x10000, 0, &gt_memh);
    513   1.4     matt 
    514   1.8     matt 	for (j = 0, di = &decode_regs[4]; j < 5; j++, di++) {
    515   1.8     matt 		struct powerpc_bus_space *memt = obio_bs_tags[j];
    516   1.8     matt 		datal = bus_space_read_4(gt_memt, gt_memh, di->low_decode);
    517   1.8     matt 		datah = bus_space_read_4(gt_memt, gt_memh, di->high_decode);
    518   1.8     matt 
    519   1.8     matt 		if (GT_LowAddr_GET(datal) >= GT_HighAddr_GET(datal)) {
    520   1.8     matt 			obio_bs_tags[j] = NULL;
    521   1.8     matt 			continue;
    522   1.8     matt 		}
    523   1.8     matt 		memt->pbs_offset = GT_LowAddr_GET(datal);
    524   1.8     matt 		memt->pbs_limit  = GT_HighAddr_GET(datah) + 1 -
    525   1.8     matt 		    memt->pbs_offset;
    526   1.8     matt 
    527   1.8     matt 		error = bus_space_init(memt, "obio2",
    528   1.8     matt 		    ex_storage[bs], sizeof(ex_storage[bs]));
    529   1.8     matt 		bs++;
    530   1.8     matt 	}
    531   1.4     matt 
    532   1.4     matt 	datal = bus_space_read_4(gt_memt, gt_memh, GT_PCI0_Mem0_Low_Decode);
    533   1.4     matt 	datah = bus_space_read_4(gt_memt, gt_memh, GT_PCI0_Mem0_High_Decode);
    534   1.9     matt #if defined(GT_PCI0_MEMBASE)
    535   1.9     matt 	datal &= ~0xfff;
    536   1.9     matt 	datal |= (GT_PCI0_MEMBASE >> 20);
    537   1.9     matt 	bus_space_write_4(gt_memt, gt_memh, GT_PCI0_Mem0_Low_Decode, datal);
    538   1.9     matt #endif
    539   1.9     matt #if defined(GT_PCI0_MEMSIZE)
    540   1.9     matt 	datah &= ~0xfff;
    541   1.9     matt 	datah |= (GT_PCI0_MEMSIZE + GT_LowAddr_GET(datal) - 1)  >> 20;
    542   1.9     matt 	bus_space_write_4(gt_memt, gt_memh, GT_PCI0_Mem0_High_Decode, datal);
    543   1.9     matt #endif
    544   1.4     matt 	gt_pci0_mem_bs_tag.pbs_base  = GT_LowAddr_GET(datal);
    545   1.4     matt 	gt_pci0_mem_bs_tag.pbs_limit = GT_HighAddr_GET(datah) + 1;
    546   1.4     matt 
    547   1.4     matt 	error = bus_space_init(&gt_pci0_mem_bs_tag, "pci0-mem",
    548   1.8     matt 	    ex_storage[bs], sizeof(ex_storage[bs]));
    549   1.8     matt 	bs++;
    550   1.4     matt 
    551   1.6     matt 	/*
    552   1.7     matt 	 * Make sure PCI0 Memory is BAT mapped.
    553   1.7     matt 	 */
    554   1.8     matt 	if (GT_LowAddr_GET(datal) < GT_HighAddr_GET(datal))
    555   1.8     matt 		oea_iobat_add(gt_pci0_mem_bs_tag.pbs_base & SEGMENT_MASK, BAT_BL_256M);
    556   1.7     matt 
    557   1.7     matt 	/*
    558   1.6     matt 	 * Make sure that I/O space start at 0.
    559   1.6     matt 	 */
    560   1.6     matt 	bus_space_write_4(gt_memt, gt_memh, GT_PCI1_IO_Remap, 0);
    561   1.6     matt 
    562   1.4     matt 	datal = bus_space_read_4(gt_memt, gt_memh, GT_PCI0_IO_Low_Decode);
    563   1.4     matt 	datah = bus_space_read_4(gt_memt, gt_memh, GT_PCI0_IO_High_Decode);
    564   1.9     matt #if defined(GT_PCI0_IOBASE)
    565   1.9     matt 	datal &= ~0xfff;
    566   1.9     matt 	datal |= (GT_PCI0_IOBASE >> 20);
    567   1.9     matt 	bus_space_write_4(gt_memt, gt_memh, GT_PCI0_IO_Low_Decode, datal);
    568   1.9     matt #endif
    569   1.9     matt #if defined(GT_PCI0_IOSIZE)
    570   1.9     matt 	datah &= ~0xfff;
    571   1.9     matt 	datah |= (GT_PCI0_IOSIZE + GT_LowAddr_GET(datal) - 1)  >> 20;
    572   1.9     matt 	bus_space_write_4(gt_memt, gt_memh, GT_PCI0_IO_High_Decode, datal);
    573   1.9     matt #endif
    574   1.9     matt 	gt_pci0_io_bs_tag.pbs_offset = GT_LowAddr_GET(datal);
    575   1.4     matt 	gt_pci0_io_bs_tag.pbs_limit = GT_HighAddr_GET(datah) + 1 -
    576   1.4     matt 	    gt_pci0_io_bs_tag.pbs_offset;
    577   1.4     matt 
    578   1.4     matt 	error = bus_space_init(&gt_pci0_io_bs_tag, "pci0-ioport",
    579   1.8     matt 	    ex_storage[bs], sizeof(ex_storage[bs]));
    580   1.8     matt 	bs++;
    581   1.4     matt 
    582   1.4     matt #if 0
    583   1.4     matt 	error = extent_alloc_region(gt_pci0_io_bs_tag.pbs_extent,
    584   1.4     matt 	    0x10000, 0x7F0000, EX_NOWAIT);
    585   1.4     matt 	if (error)
    586   1.4     matt 		panic("gt_bus_space_init: can't block out reserved "
    587   1.4     matt 		    "I/O space 0x10000-0x7fffff: error=%d\n", error);
    588   1.4     matt #endif
    589   1.4     matt 
    590   1.4     matt 	datal = bus_space_read_4(gt_memt, gt_memh, GT_PCI1_Mem0_Low_Decode);
    591   1.4     matt 	datah = bus_space_read_4(gt_memt, gt_memh, GT_PCI1_Mem0_High_Decode);
    592   1.9     matt #if defined(GT_PCI1_MEMBASE)
    593   1.9     matt 	datal &= ~0xfff;
    594   1.9     matt 	datal |= (GT_PCI1_MEMBASE >> 20);
    595   1.9     matt 	bus_space_write_4(gt_memt, gt_memh, GT_PCI1_Mem0_Low_Decode, datal);
    596   1.9     matt #endif
    597   1.9     matt #if defined(GT_PCI1_MEMSIZE)
    598   1.9     matt 	datah &= ~0xfff;
    599   1.9     matt 	datah |= (GT_PCI1_MEMSIZE + GT_LowAddr_GET(datal) - 1)  >> 20;
    600   1.9     matt 	bus_space_write_4(gt_memt, gt_memh, GT_PCI1_Mem0_High_Decode, datal);
    601   1.9     matt #endif
    602   1.4     matt 	gt_pci1_mem_bs_tag.pbs_base  = GT_LowAddr_GET(datal);
    603   1.4     matt 	gt_pci1_mem_bs_tag.pbs_limit = GT_HighAddr_GET(datah) + 1;
    604   1.4     matt 
    605   1.4     matt 	error = bus_space_init(&gt_pci1_mem_bs_tag, "pci1-mem",
    606   1.8     matt 	    ex_storage[bs], sizeof(ex_storage[bs]));
    607   1.8     matt 	bs++;
    608   1.7     matt 
    609   1.7     matt 	/*
    610   1.7     matt 	 * Make sure PCI1 Memory is BAT mapped.
    611   1.7     matt 	 */
    612   1.8     matt 	if (GT_LowAddr_GET(datal) < GT_HighAddr_GET(datal))
    613   1.8     matt 		oea_iobat_add(gt_pci1_mem_bs_tag.pbs_base & SEGMENT_MASK, BAT_BL_256M);
    614   1.4     matt 
    615   1.6     matt 	/*
    616   1.6     matt 	 * Make sure that I/O space start at 0.
    617   1.6     matt 	 */
    618   1.6     matt 	bus_space_write_4(gt_memt, gt_memh, GT_PCI1_IO_Remap, 0);
    619   1.6     matt 
    620   1.4     matt 	datal = bus_space_read_4(gt_memt, gt_memh, GT_PCI1_IO_Low_Decode);
    621   1.4     matt 	datah = bus_space_read_4(gt_memt, gt_memh, GT_PCI1_IO_High_Decode);
    622   1.9     matt #if defined(GT_PCI1_IOBASE)
    623   1.9     matt 	datal &= ~0xfff;
    624   1.9     matt 	datal |= (GT_PCI1_IOBASE >> 20);
    625   1.9     matt 	bus_space_write_4(gt_memt, gt_memh, GT_PCI1_IO_Low_Decode, datal);
    626   1.9     matt #endif
    627   1.9     matt #if defined(GT_PCI1_IOSIZE)
    628   1.9     matt 	datah &= ~0xfff;
    629   1.9     matt 	datah |= (GT_PCI1_IOSIZE + GT_LowAddr_GET(datal) - 1)  >> 20;
    630   1.9     matt 	bus_space_write_4(gt_memt, gt_memh, GT_PCI1_IO_High_Decode, datal);
    631   1.9     matt #endif
    632   1.6     matt 	gt_pci1_io_bs_tag.pbs_offset = GT_LowAddr_GET(datal);
    633   1.6     matt 	gt_pci1_io_bs_tag.pbs_limit = GT_HighAddr_GET(datah) + 1 -
    634   1.6     matt 	    gt_pci1_io_bs_tag.pbs_offset;
    635   1.4     matt 
    636   1.4     matt 	error = bus_space_init(&gt_pci1_io_bs_tag, "pci1-ioport",
    637   1.8     matt 	    ex_storage[bs], sizeof(ex_storage[bs]));
    638   1.8     matt 	bs++;
    639   1.4     matt 
    640   1.4     matt #if 0
    641   1.4     matt 	error = extent_alloc_region(gt_pci1_io_bs_tag.pbs_extent,
    642   1.4     matt 	     0x10000, 0x7F0000, EX_NOWAIT);
    643   1.4     matt 	if (error)
    644   1.4     matt 		panic("gt_bus_space_init: can't block out reserved "
    645   1.4     matt 		    "I/O space 0x10000-0x7fffff: error=%d\n", error);
    646   1.4     matt #endif
    647   1.4     matt }
    648