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