Home | History | Annotate | Line # | Download | only in pci
ttwoga.c revision 1.14
      1 /* $NetBSD: ttwoga.c,v 1.14 2011/06/14 15:34:22 matt Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include "opt_dec_2100_a500.h"
     33 #include "opt_dec_2100a_a500.h"
     34 
     35 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     36 
     37 __KERNEL_RCSID(0, "$NetBSD: ttwoga.c,v 1.14 2011/06/14 15:34:22 matt Exp $");
     38 
     39 #include <sys/param.h>
     40 #include <sys/systm.h>
     41 #include <sys/kernel.h>
     42 #include <sys/malloc.h>
     43 #include <sys/device.h>
     44 
     45 #include <machine/autoconf.h>
     46 #include <machine/rpb.h>
     47 
     48 #include <dev/isa/isareg.h>
     49 #include <dev/isa/isavar.h>
     50 
     51 #include <dev/eisa/eisavar.h>
     52 
     53 #include <dev/pci/pcireg.h>
     54 #include <dev/pci/pcivar.h>
     55 
     56 #include <alpha/pci/ttwogareg.h>
     57 #include <alpha/pci/ttwogavar.h>
     58 
     59 #if defined(DEC_2100_A500) || defined(DEC_2100A_A500)
     60 #include <alpha/pci/pci_2100_a500.h>
     61 #endif
     62 
     63 #include "locators.h"
     64 
     65 int	ttwogamatch(device_t, cfdata_t, void *);
     66 void	ttwogaattach(device_t, device_t, void *);
     67 
     68 CFATTACH_DECL_NEW(ttwoga, 0,
     69     ttwogamatch, ttwogaattach, NULL, NULL);
     70 
     71 int	ttwogaprint(void *, const char *);
     72 
     73 int	ttwopcimatch(device_t, cfdata_t, void *);
     74 void	ttwopciattach(device_t, device_t, void *);
     75 
     76 CFATTACH_DECL_NEW(ttwopci, 0,
     77     ttwopcimatch, ttwopciattach, NULL, NULL);
     78 
     79 int	ttwosableioprint(void *, const char *);
     80 
     81 /*
     82  * There can be only one, but it might have 2 primary PCI busses.
     83  */
     84 int ttwogafound;
     85 struct ttwoga_config ttwoga_configuration[2];
     86 
     87 /* CBUS address bias for Gamma systems. */
     88 bus_addr_t ttwoga_gamma_cbus_bias;
     89 
     90 #define	GIGABYTE	(1024UL * 1024UL * 1024UL)
     91 #define	MEGABYTE	(1024UL * 1024UL)
     92 
     93 const struct ttwoga_sysmap ttwoga_sysmap[2] = {
     94 /*	  Base			System size	Bus size	*/
     95 	{ T2_PCI0_SIO_BASE,	256UL * MEGABYTE, 8UL * MEGABYTE,
     96 	  T2_PCI0_SMEM_BASE,	4UL * GIGABYTE,	128UL * MEGABYTE,
     97 	  T2_PCI0_DMEM_BASE,	1UL * GIGABYTE,	1UL * GIGABYTE,
     98 	  T2_PCI0_CONF_BASE,
     99 	},
    100 	{ T2_PCI1_SIO_BASE,	256UL * MEGABYTE, 8UL * MEGABYTE,
    101 	  T2_PCI1_SMEM_BASE,	2UL * GIGABYTE,	64UL * MEGABYTE,
    102 	  T2_PCI1_DMEM_BASE,	2UL * GIGABYTE,	2UL * GIGABYTE,
    103 	  T2_PCI1_CONF_BASE,
    104 	},
    105 };
    106 
    107 #undef GIGABYTE
    108 #undef MEGABYTE
    109 
    110 int
    111 ttwogamatch(device_t parent, cfdata_t match, void *aux)
    112 {
    113 	struct mainbus_attach_args *ma = aux;
    114 
    115 	/* Make sure that we're looking for a T2 Gate Array. */
    116 	if (strcmp(ma->ma_name, match->cf_name) != 0)
    117 		return (0);
    118 
    119 	if (ttwogafound)
    120 		return (0);
    121 
    122 	return (1);
    123 }
    124 
    125 void
    126 ttwogaattach(device_t parent, device_t self, void *aux)
    127 {
    128 	struct pcibus_attach_args pba;
    129 	int hose;
    130 
    131 	printf("\n");
    132 
    133 	/* note that we've attached the chipset; can't have 2 T2s */
    134 	ttwogafound = 1;
    135 
    136 	/*
    137 	 * Don't do much here; real work is deferred to the ttwopci
    138 	 * layer.
    139 	 */
    140 	for (hose = 0; hose < 1 /* XXX */; hose++) {
    141 #if 0 /* XXX */
    142 		if (badaddr(_T2GA(hose, T2_IOCSR), sizeof(u_int64_t)))
    143 			continue;
    144 #endif
    145 		memset(&pba, 0, sizeof(pba));
    146 		pba.pba_bus = hose;
    147 
    148 		(void) config_found_ia(self, "ttwoga", &pba, ttwogaprint);
    149 	}
    150 }
    151 
    152 int
    153 ttwogaprint(void *aux, const char *pnp)
    154 {
    155 	struct pcibus_attach_args *pba = aux;
    156 
    157 	if (pnp)
    158 		aprint_normal("ttwopci at %s", pnp);
    159 	aprint_normal(" hose %d", pba->pba_bus);
    160 	return (UNCONF);
    161 }
    162 
    163 /*
    164  * Set up the chipset's function pointers.
    165  */
    166 struct ttwoga_config *
    167 ttwoga_init(int hose, int mallocsafe)
    168 {
    169 	struct ttwoga_config *tcp;
    170 
    171 	if (hose < 0 || hose > 1)
    172 		panic("ttwoga_init: bad hose # %d", hose);
    173 
    174 	tcp = &ttwoga_configuration[hose];
    175 	tcp->tc_hose = hose;
    176 
    177 	tcp->tc_sysmap = &ttwoga_sysmap[hose];
    178 
    179 	/*
    180 	 * Sable-Gamma has a CBUS address bias.
    181 	 */
    182 	ttwoga_gamma_cbus_bias = (alpha_implver() == ALPHA_IMPLVER_EV5) ?
    183 	    T2_GAMMA_CBUS_BIAS : 0;
    184 
    185 	alpha_mb();
    186 
    187 	tcp->tc_io_bus_start = (T2GA(tcp, T2_HAE0_2) & HAE0_2_PUA2) << 23;
    188 	tcp->tc_d_mem_bus_start = (T2GA(tcp, T2_HAE0_4) & HAE0_4_PUA1) << 30;
    189 	tcp->tc_s_mem_bus_start = (T2GA(tcp, T2_HAE0_1) & HAE0_1_PUA1) << 27;
    190 
    191 	tcp->tc_rev  = (T2GA(tcp, T2_IOCSR) & IOCSR_TRN) >> IOCSR_TRN_SHIFT;
    192 
    193 	if (tcp->tc_initted == 0) {
    194 		/* don't do these twice since they set up extents */
    195 		ttwoga_bus_io_init(&tcp->tc_iot, tcp);
    196 		ttwoga_bus_mem_init(&tcp->tc_memt, tcp);
    197 	}
    198 	tcp->tc_mallocsafe = mallocsafe;
    199 
    200 	ttwoga_pci_init(&tcp->tc_pc, tcp);
    201 
    202 	tcp->tc_initted = 1;
    203 
    204 	return (tcp);
    205 }
    206 
    207 int
    208 ttwopcimatch(device_t parent, cfdata_t match, void *aux)
    209 {
    210 	struct pcibus_attach_args *pba = aux;
    211 
    212 	if (match->cf_loc[PCIBUSCF_BUS] != PCIBUSCF_BUS_DEFAULT &&
    213 	    match->cf_loc[PCIBUSCF_BUS] != pba->pba_bus)
    214 		return (0);
    215 
    216 	return (1);
    217 }
    218 
    219 void
    220 ttwopciattach(device_t parent, device_t self, void *aux)
    221 {
    222 	struct pcibus_attach_args *pba = aux, npba;
    223 	struct ttwoga_config *tcp;
    224 
    225 	/*
    226 	 * set up the chipset's info; done one at console init time
    227 	 * (maybe), but doesn't hurt to do it twice.
    228 	 */
    229 	tcp = ttwoga_init(pba->pba_bus, 1);
    230 
    231 	ttwoga_dma_init(tcp);
    232 
    233 	aprint_normal(": %s Gate Array rev. %d\n",
    234 	    (tcp->tc_rev < TRN_T3) ? "T2" : "T3 or T4",
    235 	    tcp->tc_rev);
    236 
    237 	if (tcp->tc_rev < 1)
    238 		aprint_normal_dev(self, "WARNING: T2 NOT PASS2... NO BETS...\n");
    239 
    240 	switch (cputype) {
    241 #if defined(DEC_2100_A500) || defined(DEC_2100A_A500)
    242 	case ST_DEC_2100_A500:
    243 	case ST_DEC_2100A_A500:
    244 		pci_2100_a500_pickintr(tcp);
    245 		break;
    246 #endif
    247 
    248 	default:
    249 		panic("ttwogaattach: shouldn't be here, really...");
    250 	}
    251 
    252 	npba.pba_iot = &tcp->tc_iot;
    253 	npba.pba_memt = &tcp->tc_memt;
    254 	npba.pba_dmat =
    255 	    alphabus_dma_get_tag(&tcp->tc_dmat_direct, ALPHA_BUS_PCI);
    256 	npba.pba_dmat64 = NULL;
    257 	npba.pba_pc = &tcp->tc_pc;
    258 	npba.pba_bus = 0;
    259 	npba.pba_bridgetag = NULL;
    260 	npba.pba_flags = PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY;
    261 
    262 	/*
    263 	 * Hose 0 has the STDIO module.
    264 	 */
    265 	if (pba->pba_bus == 0) {
    266 		(void) config_found_ia(self, "sableiobus", &npba,
    267 				       ttwosableioprint);
    268 	}
    269 
    270 	(void) config_found_ia(self, "pcibus", &npba, pcibusprint);
    271 }
    272 
    273 int
    274 ttwosableioprint(void *aux, const char *pnp)
    275 {
    276 	struct pcibus_attach_args *pba = aux;
    277 
    278 	if (pnp)
    279 		aprint_normal("sableio at %s", pnp);
    280 	aprint_normal(" bus %d", pba->pba_bus);
    281 	return (UNCONF);
    282 }
    283