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