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