1 /* $OpenBSD: apecs.c,v 1.13 2001/06/26 21:13:43 art Exp $ */ 2 /* $NetBSD: apecs.c,v 1.16 1996/12/05 01:39:34 cgd Exp $ */ 3 4 /*- 5 * Copyright (c) 2000 The NetBSD Foundation, Inc. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to The NetBSD Foundation 9 * by Jason R. Thorpe. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. All advertising materials mentioning features or use of this software 20 * must display the following acknowledgement: 21 * This product includes software developed by the NetBSD 22 * Foundation, Inc. and its contributors. 23 * 4. Neither the name of The NetBSD Foundation nor the names of its 24 * contributors may be used to endorse or promote products derived 25 * from this software without specific prior written permission. 26 * 27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 * POSSIBILITY OF SUCH DAMAGE. 38 */ 39 40 /* 41 * Copyright (c) 1995, 1996 Carnegie-Mellon University. 42 * All rights reserved. 43 * 44 * Author: Chris G. Demetriou 45 * 46 * Permission to use, copy, modify and distribute this software and 47 * its documentation is hereby granted, provided that both the copyright 48 * notice and this permission notice appear in all copies of the 49 * software, derivative works or modified versions, and any portions 50 * thereof, and that both notices appear in supporting documentation. 51 * 52 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 53 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 54 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 55 * 56 * Carnegie Mellon requests users of this software to return to 57 * 58 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 59 * School of Computer Science 60 * Carnegie Mellon University 61 * Pittsburgh PA 15213-3890 62 * 63 * any improvements or extensions that they make and grant Carnegie the 64 * rights to redistribute these changes. 65 */ 66 67 #include <sys/param.h> 68 #include <sys/systm.h> 69 #include <sys/kernel.h> 70 #include <sys/malloc.h> 71 #include <sys/device.h> 72 #include <vm/vm.h> 73 74 #include <machine/autoconf.h> 75 #include <machine/rpb.h> 76 77 #include <dev/isa/isareg.h> 78 #include <dev/isa/isavar.h> 79 80 #include <dev/pci/pcireg.h> 81 #include <dev/pci/pcivar.h> 82 #include <alpha/pci/apecsreg.h> 83 #include <alpha/pci/apecsvar.h> 84 #ifdef DEC_2100_A50 85 #include <alpha/pci/pci_2100_a50.h> 86 #endif 87 #ifdef DEC_EB64PLUS 88 #include <alpha/pci/pci_eb64plus.h> 89 #endif 90 #ifdef DEC_1000A 91 #include <alpha/pci/pci_1000a.h> 92 #endif 93 #ifdef DEC_1000 94 #include <alpha/pci/pci_1000.h> 95 #endif 96 97 int apecsmatch __P((struct device *, void *, void *)); 98 void apecsattach __P((struct device *, struct device *, void *)); 99 100 struct cfattach apecs_ca = { 101 sizeof(struct apecs_softc), apecsmatch, apecsattach, 102 }; 103 104 struct cfdriver apecs_cd = { 105 NULL, "apecs", DV_DULL, 106 }; 107 108 int apecsprint __P((void *, const char *pnp)); 109 110 /* There can be only one. */ 111 int apecsfound; 112 struct apecs_config apecs_configuration; 113 114 int 115 apecsmatch(parent, match, aux) 116 struct device *parent; 117 void *match; 118 void *aux; 119 { 120 struct mainbus_attach_args *ma = aux; 121 122 /* Make sure that we're looking for an APECS. */ 123 if (strcmp(ma->ma_name, apecs_cd.cd_name) != 0) 124 return (0); 125 126 if (apecsfound) 127 return (0); 128 129 return (1); 130 } 131 132 /* 133 * Set up the chipset's function pointers. 134 */ 135 void 136 apecs_init(acp, mallocsafe) 137 struct apecs_config *acp; 138 int mallocsafe; 139 { 140 acp->ac_comanche_pass2 = 141 (REGVAL(COMANCHE_ED) & COMANCHE_ED_PASS2) != 0; 142 acp->ac_memwidth = 143 (REGVAL(COMANCHE_GCR) & COMANCHE_GCR_WIDEMEM) != 0 ? 128 : 64; 144 acp->ac_epic_pass2 = 145 (REGVAL(EPIC_DCSR) & EPIC_DCSR_PASS2) != 0; 146 147 acp->ac_haxr1 = REGVAL(EPIC_HAXR1); 148 acp->ac_haxr2 = REGVAL(EPIC_HAXR2); 149 150 if (!acp->ac_initted) { 151 /* don't do these twice since they set up extents */ 152 acp->ac_iot = apecs_bus_io_init(acp); 153 acp->ac_memt = apecs_bus_mem_init(acp); 154 155 #if 0 156 /* 157 * We have two I/O windows and 3 MEM windows. 158 */ 159 alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_IO] = 2; 160 alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_MEM] = 3; 161 alpha_bus_get_window = apecs_bus_get_window; 162 #endif 163 } 164 acp->ac_mallocsafe = mallocsafe; 165 166 apecs_pci_init(&acp->ac_pc, acp); 167 alpha_pci_chipset = &acp->ac_pc; 168 alpha_pci_chipset->pc_name = "apecs"; 169 alpha_pci_chipset->pc_mem = APECS_PCI_SPARSE; 170 alpha_pci_chipset->pc_dense = APECS_PCI_DENSE; 171 alpha_pci_chipset->pc_bwx = 0; 172 173 acp->ac_initted = 1; 174 } 175 176 void 177 apecsattach(parent, self, aux) 178 struct device *parent, *self; 179 void *aux; 180 { 181 struct apecs_softc *sc = (struct apecs_softc *)self; 182 struct apecs_config *acp; 183 struct pcibus_attach_args pba; 184 185 /* note that we've attached the chipset; can't have 2 APECSes. */ 186 apecsfound = 1; 187 188 /* 189 * set up the chipset's info; done once at console init time 190 * (maybe), but doesn't hurt to do twice. 191 */ 192 acp = sc->sc_acp = &apecs_configuration; 193 apecs_init(acp, 1); 194 195 apecs_dma_init(acp); 196 197 printf(": DECchip %s Core Logic chipset\n", 198 acp->ac_memwidth == 128 ? "21072" : "21071"); 199 printf("%s: DC21071-CA pass %d, %d-bit memory bus\n", 200 self->dv_xname, acp->ac_comanche_pass2 ? 2 : 1, acp->ac_memwidth); 201 printf("%s: DC21071-DA pass %d\n", self->dv_xname, 202 acp->ac_epic_pass2 ? 2 : 1); 203 /* XXX print bcache size */ 204 205 if (!acp->ac_epic_pass2) 206 printf("WARNING: 21071-DA NOT PASS2... NO BETS...\n"); 207 208 switch (cputype) { 209 #ifdef DEC_2100_A50 210 case ST_DEC_2100_A50: 211 pci_2100_a50_pickintr(acp); 212 break; 213 #endif 214 215 #ifdef DEC_EB64PLUS 216 case ST_EB64P: 217 pci_eb64plus_pickintr(acp); 218 break; 219 #endif 220 221 #ifdef DEC_1000A 222 case ST_DEC_1000A: 223 pci_1000a_pickintr(acp, &acp->ac_iot, &acp->ac_memt, 224 &acp->ac_pc); 225 break; 226 #endif 227 228 #ifdef DEC_1000 229 case ST_DEC_1000: 230 pci_1000_pickintr(acp, &acp->ac_iot, &acp->ac_memt, 231 &acp->ac_pc); 232 break; 233 #endif 234 235 default: 236 panic("apecsattach: shouldn't be here, really..."); 237 } 238 239 pba.pba_busname = "pci"; 240 pba.pba_iot = acp->ac_iot; 241 pba.pba_memt = acp->ac_memt; 242 pba.pba_dmat = 243 alphabus_dma_get_tag(&acp->ac_dmat_direct, ALPHA_BUS_PCI); 244 pba.pba_pc = &acp->ac_pc; 245 pba.pba_bus = 0; 246 #ifdef notyet 247 pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED | 248 PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY; 249 #endif 250 config_found(self, &pba, apecsprint); 251 } 252 253 int 254 apecsprint(aux, pnp) 255 void *aux; 256 const char *pnp; 257 { 258 register struct pcibus_attach_args *pba = aux; 259 260 /* only PCIs can attach to APECSes; easy. */ 261 if (pnp) 262 printf("%s at %s", pba->pba_busname, pnp); 263 printf(" bus %d", pba->pba_bus); 264 return (UNCONF); 265 } 266 267 #if 0 268 int 269 apecs_bus_get_window(type, window, abst) 270 int type, window; 271 struct alpha_bus_space_translation *abst; 272 { 273 struct apecs_config *acp = &apecs_configuration; 274 bus_space_tag_t st; 275 276 switch (type) { 277 case ALPHA_BUS_TYPE_PCI_IO: 278 st = &acp->ac_iot; 279 break; 280 281 case ALPHA_BUS_TYPE_PCI_MEM: 282 st = &acp->ac_memt; 283 break; 284 285 default: 286 panic("apecs_bus_get_window"); 287 } 288 289 return (alpha_bus_space_get_window(st, window, abst)); 290 } 291 #endif 292