Home | History | Annotate | Line # | Download | only in ev64260
machdep.c revision 1.29
      1  1.29      matt /*	$NetBSD: machdep.c,v 1.29 2011/06/20 07:18:06 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.29      matt __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.29 2011/06/20 07:18:06 matt Exp $");
     36   1.1      matt 
     37   1.1      matt #include "opt_marvell.h"
     38  1.24       apb #include "opt_modular.h"
     39   1.8      matt #include "opt_ev64260.h"
     40   1.1      matt #include "opt_compat_netbsd.h"
     41   1.1      matt #include "opt_ddb.h"
     42   1.1      matt #include "opt_inet.h"
     43   1.1      matt #include "opt_ccitt.h"
     44   1.1      matt #include "opt_iso.h"
     45   1.1      matt #include "opt_ns.h"
     46   1.1      matt #include "opt_ipkdb.h"
     47   1.1      matt 
     48  1.27  kiyohara #define _POWERPC_BUS_DMA_PRIVATE
     49  1.27  kiyohara 
     50   1.1      matt #include <sys/param.h>
     51  1.27  kiyohara #include <sys/bus.h>
     52   1.1      matt #include <sys/conf.h>
     53   1.1      matt #include <sys/device.h>
     54  1.27  kiyohara #include <sys/extent.h>
     55   1.1      matt #include <sys/kernel.h>
     56  1.27  kiyohara #include <sys/ksyms.h>
     57   1.1      matt #include <sys/mount.h>
     58   1.1      matt #include <sys/reboot.h>
     59   1.1      matt #include <sys/systm.h>
     60   1.6      matt #include <sys/termios.h>
     61  1.27  kiyohara #include <sys/vnode.h>
     62   1.1      matt 
     63   1.1      matt #include <uvm/uvm_extern.h>
     64   1.1      matt 
     65  1.29      matt #include <machine/powerpc.h>
     66   1.1      matt 
     67  1.29      matt #include <powerpc/db_machdep.h>
     68  1.29      matt #include <powerpc/pmap.h>
     69   1.1      matt 
     70   1.1      matt #include <powerpc/oea/bat.h>
     71  1.27  kiyohara #include <powerpc/pic/picvar.h>
     72  1.27  kiyohara #include <powerpc/pio.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 "com.h"
     79   1.1      matt #if (NCOM > 0)
     80   1.1      matt #include <dev/ic/comreg.h>
     81   1.1      matt #include <dev/ic/comvar.h>
     82   1.1      matt #endif
     83   1.1      matt 
     84   1.2      matt #include <dev/marvell/gtreg.h>
     85   1.1      matt #include <dev/marvell/gtvar.h>
     86   1.1      matt 
     87   1.6      matt #include "gtmpsc.h"
     88   1.6      matt #if (NGTMPSC > 0)
     89  1.27  kiyohara #include <dev/marvell/gtbrgreg.h>
     90   1.6      matt #include <dev/marvell/gtsdmareg.h>
     91   1.6      matt #include <dev/marvell/gtmpscreg.h>
     92   1.6      matt #include <dev/marvell/gtmpscvar.h>
     93   1.6      matt #endif
     94   1.6      matt 
     95  1.11     ragge #include "ksyms.h"
     96  1.27  kiyohara #include "locators.h"
     97  1.27  kiyohara 
     98  1.11     ragge 
     99   1.1      matt /*
    100   1.1      matt  * Global variables used here and there
    101   1.1      matt  */
    102   1.1      matt #define	PMONMEMREGIONS	32
    103   1.1      matt struct mem_region physmemr[PMONMEMREGIONS], availmemr[PMONMEMREGIONS];
    104   1.1      matt 
    105  1.27  kiyohara void initppc(u_int, u_int, u_int, void *); /* Called from locore */
    106  1.27  kiyohara static void gt_bus_space_init(void);
    107  1.27  kiyohara static inline void gt_record_memory(int, paddr_t, paddr_t, paddr_t);
    108  1.27  kiyohara static void gt_find_memory(paddr_t);
    109  1.27  kiyohara 
    110  1.27  kiyohara bus_addr_t gt_base = 0;
    111   1.1      matt 
    112  1.27  kiyohara extern int primary_pic;
    113  1.27  kiyohara struct pic_ops *discovery_pic;
    114  1.27  kiyohara struct pic_ops *discovery_gpp_pic[4];
    115   1.4      matt 
    116   1.8      matt 
    117  1.27  kiyohara struct powerpc_bus_space ev64260_pci0_mem_bs_tag = {
    118   1.4      matt 	_BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE,
    119   1.4      matt 	0x00000000, 0x00000000, 0x00000000,
    120   1.4      matt };
    121  1.27  kiyohara struct powerpc_bus_space ev64260_pci0_io_bs_tag = {
    122   1.4      matt 	_BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_IO_TYPE,
    123   1.4      matt 	0x00000000, 0x00000000, 0x00000000,
    124   1.4      matt };
    125  1.27  kiyohara struct powerpc_bus_space ev64260_pci1_mem_bs_tag = {
    126   1.4      matt 	_BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE,
    127   1.4      matt 	0x00000000, 0x00000000, 0x00000000,
    128   1.4      matt };
    129  1.27  kiyohara struct powerpc_bus_space ev64260_pci1_io_bs_tag = {
    130   1.4      matt 	_BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_IO_TYPE,
    131   1.4      matt 	0x00000000, 0x00000000, 0x00000000,
    132   1.4      matt };
    133  1.27  kiyohara struct powerpc_bus_space ev64260_obio0_bs_tag = {
    134   1.8      matt 	_BUS_SPACE_BIG_ENDIAN|_BUS_SPACE_MEM_TYPE|OBIO0_STRIDE,
    135   1.8      matt 	0x00000000, 0x00000000, 0x00000000,
    136   1.8      matt };
    137  1.27  kiyohara struct powerpc_bus_space ev64260_obio1_bs_tag = {
    138   1.8      matt 	_BUS_SPACE_BIG_ENDIAN|_BUS_SPACE_MEM_TYPE|OBIO1_STRIDE,
    139   1.8      matt 	0x00000000, 0x00000000, 0x00000000,
    140   1.8      matt };
    141  1.27  kiyohara struct powerpc_bus_space ev64260_obio2_bs_tag = {
    142   1.8      matt 	_BUS_SPACE_BIG_ENDIAN|_BUS_SPACE_MEM_TYPE|OBIO2_STRIDE,
    143   1.8      matt 	0x00000000, 0x00000000, 0x00000000,
    144   1.8      matt };
    145  1.27  kiyohara struct powerpc_bus_space ev64260_obio3_bs_tag = {
    146   1.8      matt 	_BUS_SPACE_BIG_ENDIAN|_BUS_SPACE_MEM_TYPE|OBIO3_STRIDE,
    147   1.8      matt 	0x00000000, 0x00000000, 0x00000000,
    148   1.8      matt };
    149  1.27  kiyohara struct powerpc_bus_space ev64260_bootcs_bs_tag = {
    150   1.8      matt 	_BUS_SPACE_BIG_ENDIAN|_BUS_SPACE_MEM_TYPE,
    151   1.4      matt 	0x00000000, 0x00000000, 0x00000000,
    152   1.4      matt };
    153  1.27  kiyohara struct powerpc_bus_space ev64260_gt_bs_tag = {
    154   1.4      matt 	_BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE,
    155  1.27  kiyohara 	0x00000000, 0x00000000, GT_SIZE,
    156   1.4      matt };
    157   1.4      matt 
    158  1.27  kiyohara struct powerpc_bus_space *ev64260_obio_bs_tags[5] = {
    159  1.27  kiyohara 	&ev64260_obio0_bs_tag, &ev64260_obio1_bs_tag, &ev64260_obio2_bs_tag,
    160  1.27  kiyohara 	&ev64260_obio3_bs_tag, &ev64260_bootcs_bs_tag
    161   1.4      matt };
    162   1.1      matt 
    163   1.8      matt static char ex_storage[10][EXTENT_FIXED_STORAGE_SIZE(8)]
    164   1.4      matt     __attribute__((aligned(8)));
    165   1.4      matt 
    166   1.8      matt const struct gt_decode_info {
    167   1.8      matt 	bus_addr_t low_decode;
    168   1.8      matt 	bus_addr_t high_decode;
    169   1.8      matt } decode_regs[] = {
    170   1.8      matt     {	GT_SCS0_Low_Decode,	GT_SCS0_High_Decode },
    171   1.8      matt     {	GT_SCS1_Low_Decode,	GT_SCS1_High_Decode },
    172   1.8      matt     {	GT_SCS2_Low_Decode,	GT_SCS2_High_Decode },
    173   1.8      matt     {	GT_SCS3_Low_Decode,	GT_SCS3_High_Decode },
    174   1.8      matt     {	GT_CS0_Low_Decode,	GT_CS0_High_Decode },
    175   1.8      matt     {	GT_CS1_Low_Decode,	GT_CS1_High_Decode },
    176   1.8      matt     {	GT_CS2_Low_Decode,	GT_CS2_High_Decode },
    177   1.8      matt     {	GT_CS3_Low_Decode,	GT_CS3_High_Decode },
    178   1.8      matt     {	GT_BootCS_Low_Decode,	GT_BootCS_High_Decode },
    179   1.1      matt };
    180   1.1      matt 
    181  1.27  kiyohara struct powerpc_bus_dma_tag ev64260_bus_dma_tag = {
    182  1.27  kiyohara         0,				/* _bounce_thresh */
    183  1.27  kiyohara 	_bus_dmamap_create,
    184  1.27  kiyohara 	_bus_dmamap_destroy,
    185  1.27  kiyohara 	_bus_dmamap_load,
    186  1.27  kiyohara 	_bus_dmamap_load_mbuf,
    187  1.27  kiyohara 	_bus_dmamap_load_uio,
    188  1.27  kiyohara 	_bus_dmamap_load_raw,
    189  1.27  kiyohara 	_bus_dmamap_unload,
    190  1.27  kiyohara 	_bus_dmamap_sync,
    191  1.27  kiyohara 	_bus_dmamem_alloc,
    192  1.27  kiyohara 	_bus_dmamem_free,
    193  1.27  kiyohara 	_bus_dmamem_map,
    194  1.27  kiyohara 	_bus_dmamem_unmap,
    195  1.27  kiyohara 	_bus_dmamem_mmap,
    196  1.27  kiyohara };
    197  1.27  kiyohara 
    198  1.27  kiyohara 
    199   1.1      matt void
    200  1.25       dsl initppc(u_int startkernel, u_int endkernel, u_int args, void *btinfo)
    201   1.1      matt {
    202  1.27  kiyohara 	extern struct cfdata cfdata[];
    203  1.27  kiyohara 	cfdata_t cf = &cfdata[0];
    204   1.1      matt 
    205  1.27  kiyohara 	/* Get mapped address of gt(System Controller) */
    206  1.27  kiyohara 	while (cf->cf_name != NULL) {
    207  1.27  kiyohara 		if (strcmp(cf->cf_name, "gt") == 0 &&
    208  1.27  kiyohara 		    *cf->cf_loc != MAINBUSCF_ADDR_DEFAULT)
    209  1.27  kiyohara 			break;
    210  1.27  kiyohara 		cf++;
    211  1.27  kiyohara 	}
    212  1.27  kiyohara 	if (cf->cf_name == NULL)
    213  1.27  kiyohara 		panic("where is gt?");
    214  1.27  kiyohara 	gt_base = *cf->cf_loc;
    215  1.27  kiyohara 
    216  1.27  kiyohara 	ev64260_gt_bs_tag.pbs_offset = gt_base;
    217  1.27  kiyohara 	ev64260_gt_bs_tag.pbs_base = gt_base;
    218  1.27  kiyohara 	ev64260_gt_bs_tag.pbs_limit += gt_base;
    219  1.27  kiyohara 	oea_batinit(gt_base, BAT_BL_256M);
    220  1.27  kiyohara 
    221  1.27  kiyohara 	oea_init(NULL);
    222   1.1      matt 
    223   1.4      matt 	gt_bus_space_init();
    224  1.27  kiyohara 	gt_find_memory(roundup(endkernel, PAGE_SIZE));
    225   1.5      matt 
    226   1.4      matt 	consinit();
    227   1.1      matt 
    228  1.27  kiyohara 	/*
    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.22        ad #if NKSYMS || defined(DDB) || defined(MODULAR)
    239   1.8      matt 	{
    240   1.8      matt 		extern void *startsym, *endsym;
    241  1.23    martin 		ksyms_addsyms_elf((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 /*
    256   1.1      matt  * Machine dependent startup code.
    257   1.1      matt  */
    258   1.1      matt void
    259   1.8      matt cpu_startup(void)
    260   1.1      matt {
    261   1.1      matt 	register_t msr;
    262   1.1      matt 
    263   1.1      matt 	oea_startup(NULL);
    264   1.1      matt 
    265  1.27  kiyohara 	pic_init();
    266  1.27  kiyohara 	discovery_pic = setup_discovery_pic();
    267  1.27  kiyohara 	primary_pic = 0;
    268  1.27  kiyohara 	discovery_gpp_pic[0] = setup_discovery_gpp_pic(discovery_pic, 0);
    269  1.27  kiyohara 	discovery_gpp_pic[1] = setup_discovery_gpp_pic(discovery_pic, 8);
    270  1.27  kiyohara 	discovery_gpp_pic[2] = setup_discovery_gpp_pic(discovery_pic, 16);
    271  1.27  kiyohara 	discovery_gpp_pic[3] = setup_discovery_gpp_pic(discovery_pic, 24);
    272  1.27  kiyohara 	/*
    273  1.27  kiyohara 	 * GPP interrupts establishes later.
    274  1.27  kiyohara 	 */
    275  1.27  kiyohara 
    276  1.27  kiyohara 	oea_install_extint(pic_ext_intr);
    277  1.27  kiyohara 
    278   1.1      matt 	/*
    279   1.1      matt 	 * Now that we have VM, malloc()s are OK in bus_space.
    280   1.1      matt 	 */
    281   1.3      matt 	bus_space_mallocok();
    282   1.1      matt 
    283   1.1      matt 	/*
    284   1.1      matt 	 * Now allow hardware interrupts.
    285   1.1      matt 	 */
    286  1.27  kiyohara 	splraise(-1);
    287  1.19     perry 	__asm volatile ("mfmsr %0; ori %0,%0,%1; mtmsr %0"
    288   1.1      matt 	    :	"=r"(msr)
    289   1.1      matt 	    :	"K"(PSL_EE));
    290   1.1      matt }
    291   1.1      matt 
    292   1.1      matt /*
    293   1.1      matt  * consinit
    294   1.1      matt  * Initialize system console.
    295   1.1      matt  */
    296   1.1      matt void
    297   1.8      matt consinit(void)
    298   1.1      matt {
    299  1.27  kiyohara 
    300   1.6      matt #ifdef MPSC_CONSOLE
    301   1.6      matt 	/* PMON using MPSC0 @ 9600 */
    302  1.27  kiyohara 	const int brg = GTMPSC_CRR_BRG0;
    303  1.27  kiyohara 	const int baud = 9600;
    304  1.27  kiyohara 	uint32_t cr;
    305  1.27  kiyohara 
    306  1.27  kiyohara #if 1
    307  1.27  kiyohara 	/*
    308  1.27  kiyohara 	 * XXX HACK FIXME
    309  1.27  kiyohara 	 * PMON output has not been flushed.  give him a chance
    310  1.27  kiyohara 	 */
    311  1.27  kiyohara 	DELAY(100000);  /* XXX */
    312  1.27  kiyohara #endif
    313  1.27  kiyohara 	/* Setup MPSC Routing Registers */
    314  1.27  kiyohara 	out32rb(gt_base + GTMPSC_MRR, GTMPSC_MRR_RES);
    315  1.27  kiyohara 	cr = in32rb(gt_base + GTMPSC_RCRR);
    316  1.27  kiyohara 	cr &= ~GTMPSC_CRR(MPSC_CONSOLE, GTMPSC_CRR_MASK);
    317  1.27  kiyohara 	cr |= GTMPSC_CRR(MPSC_CONSOLE, brg);
    318  1.27  kiyohara 	out32rb(gt_base + GTMPSC_RCRR, cr);
    319  1.27  kiyohara 	out32rb(gt_base + GTMPSC_TCRR, cr);
    320  1.27  kiyohara 
    321  1.27  kiyohara 	/* Setup Baud Rate Configuration Register of Baud Rate Generator */
    322  1.27  kiyohara 	out32rb(gt_base + BRG_BCR(brg),
    323  1.27  kiyohara 	    BRG_BCR_EN | GT_MPSC_CLOCK_SOURCE | compute_cdv(baud));
    324  1.27  kiyohara 
    325  1.27  kiyohara 	gtmpsccnattach(&ev64260_gt_bs_tag, &ev64260_bus_dma_tag, gt_base,
    326  1.27  kiyohara 	    MPSC_CONSOLE, brg, baud,
    327   1.6      matt 	    (TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8);
    328   1.6      matt #else
    329   1.4      matt 	/* PPCBOOT using COM1 @ 57600 */
    330  1.12   thorpej 	comcnattach(&gt_obio2_bs_tag, 0, 57600,
    331  1.12   thorpej 	    COM_FREQ*2, COM_TYPE_NORMAL,
    332   1.4      matt 	    (TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8);
    333   1.4      matt #endif
    334   1.1      matt }
    335   1.1      matt 
    336   1.1      matt /*
    337   1.1      matt  * Halt or reboot the machine after syncing/dumping according to howto.
    338   1.1      matt  */
    339   1.1      matt void
    340   1.8      matt cpu_reboot(int howto, char *what)
    341   1.1      matt {
    342   1.1      matt 	static int syncing;
    343   1.1      matt 	static char str[256];
    344   1.1      matt 	char *ap = str, *ap1 = ap;
    345   1.1      matt 
    346   1.1      matt 	boothowto = howto;
    347   1.1      matt 	if (!cold && !(howto & RB_NOSYNC) && !syncing) {
    348   1.1      matt 		syncing = 1;
    349   1.1      matt 		vfs_shutdown();		/* sync */
    350   1.1      matt 		resettodr();		/* set wall clock */
    351   1.1      matt 	}
    352   1.1      matt 	splhigh();
    353   1.1      matt 	if (howto & RB_HALT) {
    354   1.1      matt 		doshutdownhooks();
    355  1.21    dyoung 		pmf_system_shutdown(boothowto);
    356   1.1      matt 		printf("halted\n\n");
    357   1.1      matt 		cnhalt();
    358   1.1      matt 		while(1);
    359   1.1      matt 	}
    360   1.1      matt 	if (!cold && (howto & RB_DUMP))
    361   1.1      matt 		oea_dumpsys();
    362   1.1      matt 	doshutdownhooks();
    363  1.21    dyoung 
    364  1.21    dyoung 	pmf_system_shutdown(boothowto);
    365   1.1      matt 	printf("rebooting\n\n");
    366   1.1      matt 	if (what && *what) {
    367   1.1      matt 		if (strlen(what) > sizeof str - 5)
    368   1.1      matt 			printf("boot string too large, ignored\n");
    369   1.1      matt 		else {
    370   1.1      matt 			strcpy(str, what);
    371   1.1      matt 			ap1 = ap = str + strlen(str);
    372   1.1      matt 			*ap++ = ' ';
    373   1.1      matt 		}
    374   1.1      matt 	}
    375   1.1      matt 	*ap++ = '-';
    376   1.1      matt 	if (howto & RB_SINGLE)
    377   1.1      matt 		*ap++ = 's';
    378   1.1      matt 	if (howto & RB_KDB)
    379   1.1      matt 		*ap++ = 'd';
    380   1.1      matt 	*ap++ = 0;
    381   1.1      matt 	if (ap[-2] == '-')
    382   1.1      matt 		*ap1 = 0;
    383   1.1      matt 	gt_watchdog_reset();
    384   1.1      matt 	/* NOTREACHED */
    385   1.1      matt 	while (1);
    386   1.1      matt }
    387   1.1      matt 
    388   1.8      matt void
    389  1.27  kiyohara mem_regions(struct mem_region **mem, struct mem_region **avail)
    390   1.8      matt {
    391   1.8      matt 
    392  1.27  kiyohara 	*mem = physmemr;
    393  1.27  kiyohara 	*avail = availmemr;
    394   1.8      matt }
    395   1.8      matt 
    396  1.27  kiyohara static void
    397   1.4      matt gt_bus_space_init(void)
    398   1.4      matt {
    399   1.8      matt 	const struct gt_decode_info *di;
    400   1.4      matt 	uint32_t datal, datah;
    401  1.27  kiyohara 	int error, bs, i;
    402   1.4      matt 
    403  1.27  kiyohara 	bs = 0;
    404  1.27  kiyohara 	error = bus_space_init(&ev64260_gt_bs_tag, "gt",
    405   1.8      matt 	    ex_storage[bs], sizeof(ex_storage[bs]));
    406  1.27  kiyohara 	bs++;
    407   1.4      matt 
    408  1.27  kiyohara 	for (i = 0, di = &decode_regs[4]; i < 5; i++, di++) {
    409  1.27  kiyohara 		struct powerpc_bus_space *memt = ev64260_obio_bs_tags[i];
    410   1.4      matt 
    411  1.27  kiyohara 		datal = in32rb(gt_base + di->low_decode);
    412  1.27  kiyohara 		datah = in32rb(gt_base + di->high_decode);
    413   1.8      matt 
    414   1.8      matt 		if (GT_LowAddr_GET(datal) >= GT_HighAddr_GET(datal)) {
    415  1.27  kiyohara 			ev64260_obio_bs_tags[i] = NULL;
    416   1.8      matt 			continue;
    417   1.8      matt 		}
    418   1.8      matt 		memt->pbs_offset = GT_LowAddr_GET(datal);
    419   1.8      matt 		memt->pbs_limit  = GT_HighAddr_GET(datah) + 1 -
    420   1.8      matt 		    memt->pbs_offset;
    421   1.8      matt 
    422   1.8      matt 		error = bus_space_init(memt, "obio2",
    423   1.8      matt 		    ex_storage[bs], sizeof(ex_storage[bs]));
    424   1.8      matt 		bs++;
    425   1.8      matt 	}
    426   1.4      matt 
    427  1.27  kiyohara 	datal = in32rb(gt_base + GT_PCI0_Mem0_Low_Decode);
    428  1.27  kiyohara 	datah = in32rb(gt_base + GT_PCI0_Mem0_High_Decode);
    429   1.9      matt #if defined(GT_PCI0_MEMBASE)
    430   1.9      matt 	datal &= ~0xfff;
    431   1.9      matt 	datal |= (GT_PCI0_MEMBASE >> 20);
    432  1.27  kiyohara 	out32rb(gt_base + GT_PCI0_Mem0_Low_Decode, datal);
    433   1.9      matt #endif
    434   1.9      matt #if defined(GT_PCI0_MEMSIZE)
    435   1.9      matt 	datah &= ~0xfff;
    436  1.27  kiyohara 	datah |= (GT_PCI0_MEMSIZE + GT_LowAddr_GET(datal) - 1) >> 20;
    437  1.27  kiyohara 	out32rb(gt_base + GT_PCI0_Mem0_High_Decode, datal);
    438   1.9      matt #endif
    439  1.27  kiyohara 	ev64260_pci0_mem_bs_tag.pbs_base  = GT_LowAddr_GET(datal);
    440  1.27  kiyohara 	ev64260_pci0_mem_bs_tag.pbs_limit = GT_HighAddr_GET(datah) + 1;
    441   1.4      matt 
    442  1.27  kiyohara 	error = bus_space_init(&ev64260_pci0_mem_bs_tag, "pci0-mem",
    443   1.8      matt 	    ex_storage[bs], sizeof(ex_storage[bs]));
    444   1.8      matt 	bs++;
    445   1.4      matt 
    446  1.27  kiyohara #if 1	/* XXXXXX */
    447   1.6      matt 	/*
    448   1.7      matt 	 * Make sure PCI0 Memory is BAT mapped.
    449   1.7      matt 	 */
    450   1.8      matt 	if (GT_LowAddr_GET(datal) < GT_HighAddr_GET(datal))
    451  1.27  kiyohara 		oea_iobat_add(ev64260_pci0_mem_bs_tag.pbs_base & SEGMENT_MASK,
    452  1.27  kiyohara 		    BAT_BL_256M);
    453  1.27  kiyohara #endif
    454   1.7      matt 
    455   1.7      matt 	/*
    456   1.6      matt 	 * Make sure that I/O space start at 0.
    457   1.6      matt 	 */
    458  1.27  kiyohara 	out32rb(gt_base + GT_PCI1_IO_Remap, 0);
    459   1.6      matt 
    460  1.27  kiyohara 	datal = in32rb(gt_base + GT_PCI0_IO_Low_Decode);
    461  1.27  kiyohara 	datah = in32rb(gt_base + GT_PCI0_IO_High_Decode);
    462   1.9      matt #if defined(GT_PCI0_IOBASE)
    463   1.9      matt 	datal &= ~0xfff;
    464   1.9      matt 	datal |= (GT_PCI0_IOBASE >> 20);
    465  1.27  kiyohara 	out32rb(gt_base + GT_PCI0_IO_Low_Decode, datal);
    466   1.9      matt #endif
    467   1.9      matt #if defined(GT_PCI0_IOSIZE)
    468   1.9      matt 	datah &= ~0xfff;
    469  1.27  kiyohara 	datah |= (GT_PCI0_IOSIZE + GT_LowAddr_GET(datal) - 1) >> 20;
    470  1.27  kiyohara 	out32rb(gt_base + GT_PCI0_IO_High_Decode, datal);
    471   1.9      matt #endif
    472  1.27  kiyohara 	ev64260_pci0_io_bs_tag.pbs_offset = GT_LowAddr_GET(datal);
    473  1.27  kiyohara 	ev64260_pci0_io_bs_tag.pbs_limit = GT_HighAddr_GET(datah) + 1 -
    474  1.27  kiyohara 	    ev64260_pci0_io_bs_tag.pbs_offset;
    475   1.4      matt 
    476  1.27  kiyohara 	error = bus_space_init(&ev64260_pci0_io_bs_tag, "pci0-ioport",
    477   1.8      matt 	    ex_storage[bs], sizeof(ex_storage[bs]));
    478   1.8      matt 	bs++;
    479   1.4      matt 
    480  1.27  kiyohara 	datal = in32rb(gt_base + GT_PCI1_Mem0_Low_Decode);
    481  1.27  kiyohara 	datah = in32rb(gt_base + GT_PCI1_Mem0_High_Decode);
    482   1.9      matt #if defined(GT_PCI1_MEMBASE)
    483   1.9      matt 	datal &= ~0xfff;
    484   1.9      matt 	datal |= (GT_PCI1_MEMBASE >> 20);
    485  1.27  kiyohara 	out32rb(gt_base + GT_PCI1_Mem0_Low_Decode, datal);
    486   1.9      matt #endif
    487   1.9      matt #if defined(GT_PCI1_MEMSIZE)
    488   1.9      matt 	datah &= ~0xfff;
    489  1.27  kiyohara 	datah |= (GT_PCI1_MEMSIZE + GT_LowAddr_GET(datal) - 1) >> 20;
    490  1.27  kiyohara 	out32rb(gt_base + GT_PCI1_Mem0_High_Decode, datal);
    491   1.9      matt #endif
    492  1.27  kiyohara 	ev64260_pci1_mem_bs_tag.pbs_base  = GT_LowAddr_GET(datal);
    493  1.27  kiyohara 	ev64260_pci1_mem_bs_tag.pbs_limit = GT_HighAddr_GET(datah) + 1;
    494   1.4      matt 
    495  1.27  kiyohara 	error = bus_space_init(&ev64260_pci1_mem_bs_tag, "pci1-mem",
    496   1.8      matt 	    ex_storage[bs], sizeof(ex_storage[bs]));
    497   1.8      matt 	bs++;
    498   1.7      matt 
    499  1.27  kiyohara #if 1	/* XXXXXX */
    500   1.7      matt 	/*
    501   1.7      matt 	 * Make sure PCI1 Memory is BAT mapped.
    502   1.7      matt 	 */
    503   1.8      matt 	if (GT_LowAddr_GET(datal) < GT_HighAddr_GET(datal))
    504  1.27  kiyohara 		oea_iobat_add(ev64260_pci1_mem_bs_tag.pbs_base & SEGMENT_MASK,
    505  1.27  kiyohara 		    BAT_BL_256M);
    506  1.27  kiyohara #endif
    507   1.4      matt 
    508   1.6      matt 	/*
    509   1.6      matt 	 * Make sure that I/O space start at 0.
    510   1.6      matt 	 */
    511  1.27  kiyohara 	out32rb(gt_base + GT_PCI1_IO_Remap, 0);
    512   1.6      matt 
    513  1.27  kiyohara 	datal = in32rb(gt_base + GT_PCI1_IO_Low_Decode);
    514  1.27  kiyohara 	datah = in32rb(gt_base + GT_PCI1_IO_High_Decode);
    515   1.9      matt #if defined(GT_PCI1_IOBASE)
    516   1.9      matt 	datal &= ~0xfff;
    517   1.9      matt 	datal |= (GT_PCI1_IOBASE >> 20);
    518  1.27  kiyohara 	out32rb(gt_base + GT_PCI1_IO_Low_Decode, datal);
    519   1.9      matt #endif
    520   1.9      matt #if defined(GT_PCI1_IOSIZE)
    521   1.9      matt 	datah &= ~0xfff;
    522  1.27  kiyohara 	datah |= (GT_PCI1_IOSIZE + GT_LowAddr_GET(datal) - 1) >> 20;
    523  1.27  kiyohara 	out32rb(gt_base + GT_PCI1_IO_High_Decode, datal);
    524   1.9      matt #endif
    525  1.27  kiyohara 	ev64260_pci1_io_bs_tag.pbs_offset = GT_LowAddr_GET(datal);
    526  1.27  kiyohara 	ev64260_pci1_io_bs_tag.pbs_limit = GT_HighAddr_GET(datah) + 1 -
    527  1.27  kiyohara 	    ev64260_pci1_io_bs_tag.pbs_offset;
    528   1.4      matt 
    529  1.27  kiyohara 	error = bus_space_init(&ev64260_pci1_io_bs_tag, "pci1-ioport",
    530   1.8      matt 	    ex_storage[bs], sizeof(ex_storage[bs]));
    531   1.8      matt 	bs++;
    532  1.27  kiyohara }
    533  1.27  kiyohara 
    534  1.27  kiyohara static inline void
    535  1.27  kiyohara gt_record_memory(int j, paddr_t start, paddr_t end, paddr_t endkernel)
    536  1.27  kiyohara {
    537  1.27  kiyohara 	physmemr[j].start = start;
    538  1.27  kiyohara 	physmemr[j].size = end - start;
    539  1.27  kiyohara 	if (start < endkernel)
    540  1.27  kiyohara 		start = endkernel;
    541  1.27  kiyohara 	availmemr[j].start = start;
    542  1.27  kiyohara 	availmemr[j].size = end - start;
    543  1.27  kiyohara }
    544   1.4      matt 
    545  1.27  kiyohara static void
    546  1.27  kiyohara gt_find_memory(paddr_t endkernel)
    547  1.27  kiyohara {
    548  1.27  kiyohara 	paddr_t start = ~0, end = 0;
    549  1.27  kiyohara 	const struct gt_decode_info *di;
    550  1.27  kiyohara 	int i, j = 0, first = 1;
    551  1.27  kiyohara 
    552  1.27  kiyohara 	/*
    553  1.27  kiyohara 	 * Round kernel end to a page boundary.
    554  1.27  kiyohara 	 */
    555  1.27  kiyohara 	for (i = 0; i < 4; i++) {
    556  1.27  kiyohara 		paddr_t nstart, nend;
    557  1.27  kiyohara 
    558  1.27  kiyohara 		di = &decode_regs[i];
    559  1.27  kiyohara 		nstart = GT_LowAddr_GET(in32rb(gt_base + di->low_decode));
    560  1.27  kiyohara 		nend = GT_HighAddr_GET(in32rb(gt_base + di->high_decode)) + 1;
    561  1.27  kiyohara 		if (nstart >= nend)
    562  1.27  kiyohara 			continue;
    563  1.27  kiyohara 		if (first) {
    564  1.27  kiyohara 			/*
    565  1.27  kiyohara 			 * First entry?  Just remember it.
    566  1.27  kiyohara 			 */
    567  1.27  kiyohara 			start = nstart;
    568  1.27  kiyohara 			end = nend;
    569  1.27  kiyohara 			first = 0;
    570  1.27  kiyohara 		} else if (nstart == end) {
    571  1.27  kiyohara 			/*
    572  1.27  kiyohara 			 * Contiguous?  Just update the end.
    573  1.27  kiyohara 			 */
    574  1.27  kiyohara 			end = nend;
    575  1.27  kiyohara 		} else {
    576  1.27  kiyohara 			/*
    577  1.27  kiyohara 			 * Disjoint?  record it.
    578  1.27  kiyohara 			 */
    579  1.27  kiyohara 			gt_record_memory(j, start, end, endkernel);
    580  1.27  kiyohara 			start = nstart;
    581  1.27  kiyohara 			end = nend;
    582  1.27  kiyohara 			j++;
    583  1.27  kiyohara 		}
    584  1.27  kiyohara 	}
    585  1.27  kiyohara 	gt_record_memory(j, start, end, endkernel);
    586   1.4      matt }
    587