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