1 /* $NetBSD: apecs.c,v 1.59 2021/08/07 16:18:41 thorpej Exp $ */ 2 3 /*- 4 * Copyright (c) 2000 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 /* 33 * Copyright (c) 1995, 1996 Carnegie-Mellon University. 34 * All rights reserved. 35 * 36 * Author: Chris G. Demetriou 37 * 38 * Permission to use, copy, modify and distribute this software and 39 * its documentation is hereby granted, provided that both the copyright 40 * notice and this permission notice appear in all copies of the 41 * software, derivative works or modified versions, and any portions 42 * thereof, and that both notices appear in supporting documentation. 43 * 44 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 45 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 46 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 47 * 48 * Carnegie Mellon requests users of this software to return to 49 * 50 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 51 * School of Computer Science 52 * Carnegie Mellon University 53 * Pittsburgh PA 15213-3890 54 * 55 * any improvements or extensions that they make and grant Carnegie the 56 * rights to redistribute these changes. 57 */ 58 59 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ 60 61 __KERNEL_RCSID(0, "$NetBSD: apecs.c,v 1.59 2021/08/07 16:18:41 thorpej Exp $"); 62 63 #include <sys/param.h> 64 #include <sys/systm.h> 65 #include <sys/kernel.h> 66 #include <sys/device.h> 67 68 #include <machine/autoconf.h> 69 #include <machine/rpb.h> 70 #include <machine/sysarch.h> 71 72 #include <dev/isa/isareg.h> 73 #include <dev/isa/isavar.h> 74 75 #include <dev/pci/pcireg.h> 76 #include <dev/pci/pcivar.h> 77 #include <alpha/pci/apecsreg.h> 78 #include <alpha/pci/apecsvar.h> 79 80 static int apecsmatch(device_t, cfdata_t, void *); 81 static void apecsattach(device_t, device_t, void *); 82 83 CFATTACH_DECL_NEW(apecs, 0, apecsmatch, apecsattach, NULL, NULL); 84 85 extern struct cfdriver apecs_cd; 86 87 static int apecs_bus_get_window(int, int, 88 struct alpha_bus_space_translation *); 89 90 /* There can be only one. */ 91 static int apecsfound; 92 struct apecs_config apecs_configuration; 93 94 static int 95 apecsmatch(device_t parent, cfdata_t match, void *aux) 96 { 97 struct mainbus_attach_args *ma = aux; 98 99 /* Make sure that we're looking for an APECS. */ 100 if (strcmp(ma->ma_name, apecs_cd.cd_name) != 0) 101 return (0); 102 103 if (apecsfound) 104 return (0); 105 106 return (1); 107 } 108 109 /* 110 * Set up the chipset's function pointers. 111 */ 112 void 113 apecs_init(struct apecs_config *acp, int mallocsafe) 114 { 115 acp->ac_comanche_pass2 = 116 (REGVAL(COMANCHE_ED) & COMANCHE_ED_PASS2) != 0; 117 acp->ac_memwidth = 118 (REGVAL(COMANCHE_GCR) & COMANCHE_GCR_WIDEMEM) != 0 ? 128 : 64; 119 acp->ac_epic_pass2 = 120 (REGVAL(EPIC_DCSR) & EPIC_DCSR_PASS2) != 0; 121 122 acp->ac_haxr1 = REGVAL(EPIC_HAXR1); 123 acp->ac_haxr2 = REGVAL(EPIC_HAXR2); 124 125 if (!acp->ac_initted) { 126 /* don't do these twice since they set up extents */ 127 apecs_bus_io_init(&acp->ac_iot, acp); 128 apecs_bus_mem_init(&acp->ac_memt, acp); 129 130 /* 131 * We have two I/O windows and 3 MEM windows. 132 */ 133 alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_IO] = 2; 134 alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_MEM] = 3; 135 alpha_bus_get_window = apecs_bus_get_window; 136 } 137 acp->ac_mallocsafe = mallocsafe; 138 139 apecs_pci_init(&acp->ac_pc, acp); 140 alpha_pci_chipset = &acp->ac_pc; 141 142 acp->ac_initted = 1; 143 } 144 145 static void 146 apecsattach(device_t parent, device_t self, void *aux) 147 { 148 struct apecs_config *acp; 149 struct pcibus_attach_args pba; 150 151 /* note that we've attached the chipset; can't have 2 APECSes. */ 152 apecsfound = 1; 153 154 /* 155 * set up the chipset's info; done once at console init time 156 * (maybe), but doesn't hurt to do twice. 157 */ 158 acp = &apecs_configuration; 159 apecs_init(acp, 1); 160 161 apecs_dma_init(acp); 162 163 aprint_normal(": DECchip %s Core Logic chipset\n", 164 acp->ac_memwidth == 128 ? "21072" : "21071"); 165 aprint_normal_dev(self, "DC21071-CA pass %d, %d-bit memory bus\n", 166 acp->ac_comanche_pass2 ? 2 : 1, acp->ac_memwidth); 167 aprint_normal_dev(self, "DC21071-DA pass %d\n", 168 acp->ac_epic_pass2 ? 2 : 1); 169 /* XXX print bcache size */ 170 171 if (!acp->ac_epic_pass2) 172 printf("WARNING: 21071-DA NOT PASS2... NO BETS...\n"); 173 174 alpha_pci_intr_init(acp, &acp->ac_iot, &acp->ac_memt, &acp->ac_pc); 175 176 pba.pba_iot = &acp->ac_iot; 177 pba.pba_memt = &acp->ac_memt; 178 pba.pba_dmat = 179 alphabus_dma_get_tag(&acp->ac_dmat_direct, ALPHA_BUS_PCI); 180 pba.pba_dmat64 = NULL; 181 pba.pba_pc = &acp->ac_pc; 182 pba.pba_bus = 0; 183 pba.pba_bridgetag = NULL; 184 pba.pba_flags = PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY | 185 PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY; 186 config_found(self, &pba, pcibusprint, CFARGS_NONE); 187 } 188 189 static int 190 apecs_bus_get_window(int type, int window, 191 struct alpha_bus_space_translation *abst) 192 { 193 struct apecs_config *acp = &apecs_configuration; 194 bus_space_tag_t st; 195 196 switch (type) { 197 case ALPHA_BUS_TYPE_PCI_IO: 198 st = &acp->ac_iot; 199 break; 200 201 case ALPHA_BUS_TYPE_PCI_MEM: 202 st = &acp->ac_memt; 203 break; 204 205 default: 206 panic("apecs_bus_get_window"); 207 } 208 209 return (alpha_bus_space_get_window(st, window, abst)); 210 } 211