Home | History | Annotate | Line # | Download | only in pci
      1 /* $NetBSD: ttwoga.c,v 1.21 2023/12/04 00:32:10 thorpej 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.21 2023/12/04 00:32:10 thorpej Exp $");
     38 
     39 #include <sys/param.h>
     40 #include <sys/systm.h>
     41 #include <sys/kernel.h>
     42 #include <sys/device.h>
     43 
     44 #include <machine/autoconf.h>
     45 #include <machine/rpb.h>
     46 
     47 #include <dev/isa/isareg.h>
     48 #include <dev/isa/isavar.h>
     49 
     50 #include <dev/eisa/eisavar.h>
     51 
     52 #include <dev/pci/pcireg.h>
     53 #include <dev/pci/pcivar.h>
     54 
     55 #include <alpha/pci/ttwogareg.h>
     56 #include <alpha/pci/ttwogavar.h>
     57 
     58 #if defined(DEC_2100_A500) || defined(DEC_2100A_A500)
     59 #include <alpha/pci/pci_2100_a500.h>
     60 #endif
     61 
     62 #include "locators.h"
     63 
     64 static int	ttwogamatch(device_t, cfdata_t, void *);
     65 static void	ttwogaattach(device_t, device_t, void *);
     66 
     67 CFATTACH_DECL_NEW(ttwoga, 0,
     68     ttwogamatch, ttwogaattach, NULL, NULL);
     69 
     70 static int	ttwogaprint(void *, const char *);
     71 
     72 static int	ttwopcimatch(device_t, cfdata_t, void *);
     73 static void	ttwopciattach(device_t, device_t, void *);
     74 
     75 CFATTACH_DECL_NEW(ttwopci, 0,
     76     ttwopcimatch, ttwopciattach, NULL, NULL);
     77 
     78 static int	ttwosableioprint(void *, const char *);
     79 
     80 /*
     81  * There can be only one, but it might have 2 primary PCI busses.
     82  */
     83 static int ttwogafound;
     84 static struct ttwoga_config ttwoga_configuration[2];
     85 
     86 /* CBUS address bias for Gamma systems. */
     87 bus_addr_t ttwoga_gamma_cbus_bias;
     88 
     89 #define	GIGABYTE	(1024UL * 1024UL * 1024UL)
     90 #define	MEGABYTE	(1024UL * 1024UL)
     91 
     92 static const struct ttwoga_sysmap ttwoga_sysmap[2] = {
     93 /*	  Base			System size	Bus size	*/
     94 	{ T2_PCI0_SIO_BASE,	256UL * MEGABYTE, 8UL * MEGABYTE,
     95 	  T2_PCI0_SMEM_BASE,	4UL * GIGABYTE,	128UL * MEGABYTE,
     96 	  T2_PCI0_DMEM_BASE,	1UL * GIGABYTE,	1UL * GIGABYTE,
     97 	  T2_PCI0_CONF_BASE,
     98 	},
     99 	{ T2_PCI1_SIO_BASE,	256UL * MEGABYTE, 8UL * MEGABYTE,
    100 	  T2_PCI1_SMEM_BASE,	2UL * GIGABYTE,	64UL * MEGABYTE,
    101 	  T2_PCI1_DMEM_BASE,	2UL * GIGABYTE,	2UL * GIGABYTE,
    102 	  T2_PCI1_CONF_BASE,
    103 	},
    104 };
    105 
    106 #undef GIGABYTE
    107 #undef MEGABYTE
    108 
    109 static int
    110 ttwogamatch(device_t parent, cfdata_t match, void *aux)
    111 {
    112 	struct mainbus_attach_args *ma = aux;
    113 
    114 	/* Make sure that we're looking for a T2 Gate Array. */
    115 	if (strcmp(ma->ma_name, match->cf_name) != 0)
    116 		return (0);
    117 
    118 	if (ttwogafound)
    119 		return (0);
    120 
    121 	return (1);
    122 }
    123 
    124 static void
    125 ttwogaattach(device_t parent, device_t self, void *aux)
    126 {
    127 	struct pcibus_attach_args pba;
    128 	int hose;
    129 
    130 	printf("\n");
    131 
    132 	/* note that we've attached the chipset; can't have 2 T2s */
    133 	ttwogafound = 1;
    134 
    135 	/*
    136 	 * Don't do much here; real work is deferred to the ttwopci
    137 	 * layer.
    138 	 */
    139 	for (hose = 0; hose < 1 /* XXX */; hose++) {
    140 #if 0 /* XXX */
    141 		if (badaddr(_T2GA(hose, T2_IOCSR), sizeof(uint64_t)))
    142 			continue;
    143 #endif
    144 		memset(&pba, 0, sizeof(pba));
    145 		pba.pba_bus = hose;
    146 
    147 		config_found(self, &pba, ttwogaprint, CFARGS_NONE);
    148 	}
    149 }
    150 
    151 static int
    152 ttwogaprint(void *aux, const char *pnp)
    153 {
    154 	struct pcibus_attach_args *pba = aux;
    155 
    156 	if (pnp)
    157 		aprint_normal("ttwopci at %s", pnp);
    158 	aprint_normal(" hose %d", pba->pba_bus);
    159 	return (UNCONF);
    160 }
    161 
    162 /*
    163  * Set up the chipset's function pointers.
    164  */
    165 struct ttwoga_config *
    166 ttwoga_init(int hose)
    167 {
    168 	struct ttwoga_config *tcp;
    169 
    170 	if (hose < 0 || hose > 1)
    171 		panic("ttwoga_init: bad hose # %d", hose);
    172 
    173 	tcp = &ttwoga_configuration[hose];
    174 	tcp->tc_hose = hose;
    175 
    176 	tcp->tc_sysmap = &ttwoga_sysmap[hose];
    177 
    178 	/*
    179 	 * Sable-Gamma has a CBUS address bias.
    180 	 */
    181 	ttwoga_gamma_cbus_bias = (alpha_implver() == ALPHA_IMPLVER_EV5) ?
    182 	    T2_GAMMA_CBUS_BIAS : 0;
    183 
    184 	alpha_mb();
    185 
    186 	tcp->tc_io_bus_start = (T2GA(tcp, T2_HAE0_2) & HAE0_2_PUA2) << 23;
    187 	tcp->tc_d_mem_bus_start = (T2GA(tcp, T2_HAE0_4) & HAE0_4_PUA1) << 30;
    188 	tcp->tc_s_mem_bus_start = (T2GA(tcp, T2_HAE0_1) & HAE0_1_PUA1) << 27;
    189 
    190 	tcp->tc_rev  = (T2GA(tcp, T2_IOCSR) & IOCSR_TRN) >> IOCSR_TRN_SHIFT;
    191 
    192 	if (tcp->tc_initted == 0) {
    193 		/* don't do these twice since they set up extents */
    194 		ttwoga_bus_io_init(&tcp->tc_iot, tcp);
    195 		ttwoga_bus_mem_init(&tcp->tc_memt, tcp);
    196 	}
    197 
    198 	ttwoga_pci_init(&tcp->tc_pc, tcp);
    199 
    200 	tcp->tc_initted = 1;
    201 
    202 	return (tcp);
    203 }
    204 
    205 static int
    206 ttwopcimatch(device_t parent, cfdata_t match, void *aux)
    207 {
    208 	struct pcibus_attach_args *pba = aux;
    209 
    210 	if (match->cf_loc[PCIBUSCF_BUS] != PCIBUSCF_BUS_DEFAULT &&
    211 	    match->cf_loc[PCIBUSCF_BUS] != pba->pba_bus)
    212 		return (0);
    213 
    214 	return (1);
    215 }
    216 
    217 static void
    218 ttwopciattach(device_t parent, device_t self, void *aux)
    219 {
    220 	struct pcibus_attach_args *pba = aux, npba;
    221 	struct ttwoga_config *tcp;
    222 
    223 	/*
    224 	 * set up the chipset's info; done one at console init time
    225 	 * (maybe), but doesn't hurt to do it twice.
    226 	 */
    227 	tcp = ttwoga_init(pba->pba_bus);
    228 
    229 	ttwoga_dma_init(tcp);
    230 
    231 	aprint_normal(": %s Gate Array rev. %d\n",
    232 	    (tcp->tc_rev < TRN_T3) ? "T2" : "T3 or T4",
    233 	    tcp->tc_rev);
    234 
    235 	if (tcp->tc_rev < 1)
    236 		aprint_normal_dev(self,
    237 		    "WARNING: T2 NOT PASS2... NO BETS...\n");
    238 
    239 	alpha_pci_intr_init(tcp, &tcp->tc_iot, &tcp->tc_memt, &tcp->tc_pc);
    240 
    241 	npba.pba_iot = &tcp->tc_iot;
    242 	npba.pba_memt = &tcp->tc_memt;
    243 	npba.pba_dmat =
    244 	    alphabus_dma_get_tag(&tcp->tc_dmat_direct, ALPHA_BUS_PCI);
    245 	npba.pba_dmat64 = NULL;
    246 	npba.pba_pc = &tcp->tc_pc;
    247 	npba.pba_bus = 0;
    248 	npba.pba_bridgetag = NULL;
    249 	npba.pba_flags = PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY;
    250 
    251 	/*
    252 	 * Hose 0 has the STDIO module.
    253 	 */
    254 	if (pba->pba_bus == 0) {
    255 		config_found(self, &npba, ttwosableioprint,
    256 		    CFARGS(.iattr = "sableiobus"));
    257 	}
    258 
    259 	config_found(self, &npba, pcibusprint,
    260 	    CFARGS(.iattr = "pcibus"));
    261 }
    262 
    263 static int
    264 ttwosableioprint(void *aux, const char *pnp)
    265 {
    266 	struct pcibus_attach_args *pba = aux;
    267 
    268 	if (pnp)
    269 		aprint_normal("sableio at %s", pnp);
    270 	aprint_normal(" bus %d", pba->pba_bus);
    271 	return (UNCONF);
    272 }
    273