1 1.36 thorpej /* $NetBSD: mcpcia.c,v 1.36 2023/12/04 00:32:10 thorpej Exp $ */ 2 1.5 thorpej 3 1.5 thorpej /*- 4 1.5 thorpej * Copyright (c) 1999 The NetBSD Foundation, Inc. 5 1.5 thorpej * All rights reserved. 6 1.5 thorpej * 7 1.5 thorpej * This code is derived from software contributed to The NetBSD Foundation 8 1.5 thorpej * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 9 1.5 thorpej * NASA Ames Research Center. 10 1.5 thorpej * 11 1.5 thorpej * Redistribution and use in source and binary forms, with or without 12 1.5 thorpej * modification, are permitted provided that the following conditions 13 1.5 thorpej * are met: 14 1.5 thorpej * 1. Redistributions of source code must retain the above copyright 15 1.5 thorpej * notice, this list of conditions and the following disclaimer. 16 1.5 thorpej * 2. Redistributions in binary form must reproduce the above copyright 17 1.5 thorpej * notice, this list of conditions and the following disclaimer in the 18 1.5 thorpej * documentation and/or other materials provided with the distribution. 19 1.5 thorpej * 20 1.5 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 1.5 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 1.5 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 1.5 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 1.5 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 1.5 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 1.5 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 1.5 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 1.5 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 1.5 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 1.5 thorpej * POSSIBILITY OF SUCH DAMAGE. 31 1.5 thorpej */ 32 1.1 mjacob 33 1.1 mjacob /* 34 1.1 mjacob * Copyright (c) 1998 by Matthew Jacob 35 1.1 mjacob * NASA AMES Research Center. 36 1.1 mjacob * All rights reserved. 37 1.1 mjacob * 38 1.1 mjacob * Redistribution and use in source and binary forms, with or without 39 1.1 mjacob * modification, are permitted provided that the following conditions 40 1.1 mjacob * are met: 41 1.1 mjacob * 1. Redistributions of source code must retain the above copyright 42 1.1 mjacob * notice immediately at the beginning of the file, without modification, 43 1.1 mjacob * this list of conditions, and the following disclaimer. 44 1.1 mjacob * 2. Redistributions in binary form must reproduce the above copyright 45 1.1 mjacob * notice, this list of conditions and the following disclaimer in the 46 1.1 mjacob * documentation and/or other materials provided with the distribution. 47 1.1 mjacob * 3. The name of the author may not be used to endorse or promote products 48 1.1 mjacob * derived from this software without specific prior written permission. 49 1.1 mjacob * 50 1.1 mjacob * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 51 1.1 mjacob * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 52 1.1 mjacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 53 1.1 mjacob * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 54 1.1 mjacob * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 55 1.1 mjacob * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 56 1.1 mjacob * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 57 1.1 mjacob * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 58 1.1 mjacob * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 59 1.1 mjacob * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 60 1.1 mjacob * SUCH DAMAGE. 61 1.1 mjacob */ 62 1.1 mjacob 63 1.1 mjacob /* 64 1.1 mjacob * MCPCIA mcbus to PCI bus adapter 65 1.1 mjacob * found on AlphaServer 4100 systems. 66 1.1 mjacob */ 67 1.1 mjacob 68 1.1 mjacob #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ 69 1.1 mjacob 70 1.36 thorpej __KERNEL_RCSID(0, "$NetBSD: mcpcia.c,v 1.36 2023/12/04 00:32:10 thorpej Exp $"); 71 1.1 mjacob 72 1.1 mjacob #include <sys/param.h> 73 1.1 mjacob #include <sys/systm.h> 74 1.1 mjacob #include <sys/device.h> 75 1.30 thorpej #include <sys/kmem.h> 76 1.1 mjacob 77 1.1 mjacob #include <machine/autoconf.h> 78 1.1 mjacob #include <machine/rpb.h> 79 1.10 thorpej #include <machine/sysarch.h> 80 1.1 mjacob 81 1.1 mjacob #include <alpha/mcbus/mcbusreg.h> 82 1.1 mjacob #include <alpha/mcbus/mcbusvar.h> 83 1.1 mjacob #include <alpha/pci/mcpciareg.h> 84 1.1 mjacob #include <alpha/pci/mcpciavar.h> 85 1.1 mjacob 86 1.20 christos #define KV(_addr) ((void *)ALPHA_PHYS_TO_K0SEG((_addr))) 87 1.5 thorpej #define MCPCIA_SYSBASE(mc) \ 88 1.5 thorpej ((((unsigned long) (mc)->cc_gid) << MCBUS_GID_SHIFT) | \ 89 1.5 thorpej (((unsigned long) (mc)->cc_mid) << MCBUS_MID_SHIFT) | \ 90 1.1 mjacob (MCBUS_IOSPACE)) 91 1.1 mjacob 92 1.7 mjacob #define MCPCIA_PROBE(mid, gid) \ 93 1.7 mjacob badaddr((void *)KV(((((unsigned long) gid) << MCBUS_GID_SHIFT) | \ 94 1.7 mjacob (((unsigned long) mid) << MCBUS_MID_SHIFT) | \ 95 1.7 mjacob (MCBUS_IOSPACE) | MCPCIA_PCI_BRIDGE | _MCPCIA_PCI_REV)), \ 96 1.29 matt sizeof(uint32_t)) 97 1.7 mjacob 98 1.28 matt static int mcpciamatch(device_t, cfdata_t, void *); 99 1.28 matt static void mcpciaattach(device_t, device_t, void *); 100 1.28 matt 101 1.28 matt CFATTACH_DECL_NEW(mcpcia, sizeof(struct mcpcia_softc), 102 1.15 thorpej mcpciamatch, mcpciaattach, NULL, NULL); 103 1.1 mjacob 104 1.36 thorpej void mcpcia_init0(struct mcpcia_config *); 105 1.5 thorpej 106 1.5 thorpej /* 107 1.5 thorpej * We have one statically-allocated mcpcia_config structure; this is 108 1.5 thorpej * the one used for the console (which, coincidentally, is the only 109 1.5 thorpej * MCPCIA with an EISA adapter attached to it). 110 1.5 thorpej */ 111 1.5 thorpej struct mcpcia_config mcpcia_console_configuration; 112 1.5 thorpej 113 1.32 thorpej static int mcpcia_bus_get_window(int, int, 114 1.32 thorpej struct alpha_bus_space_translation *abst); 115 1.10 thorpej 116 1.1 mjacob static int 117 1.28 matt mcpciamatch(device_t parent, cfdata_t cf, void *aux) 118 1.1 mjacob { 119 1.1 mjacob struct mcbus_dev_attach_args *ma = aux; 120 1.1 mjacob if (ma->ma_type == MCBUS_TYPE_PCI) 121 1.1 mjacob return (1); 122 1.1 mjacob return (0); 123 1.1 mjacob } 124 1.1 mjacob 125 1.1 mjacob static void 126 1.28 matt mcpciaattach(device_t parent, device_t self, void *aux) 127 1.1 mjacob { 128 1.1 mjacob struct mcbus_dev_attach_args *ma = aux; 129 1.28 matt struct mcpcia_softc *mcp = device_private(self); 130 1.5 thorpej struct mcpcia_config *ccp; 131 1.1 mjacob struct pcibus_attach_args pba; 132 1.29 matt uint32_t ctl; 133 1.1 mjacob 134 1.7 mjacob /* 135 1.7 mjacob * Make sure this MCPCIA exists... 136 1.7 mjacob */ 137 1.7 mjacob if (MCPCIA_PROBE(ma->ma_mid, ma->ma_gid)) { 138 1.7 mjacob mcp->mcpcia_cc = NULL; 139 1.7 mjacob printf(" (not present)\n"); 140 1.7 mjacob return; 141 1.7 mjacob } 142 1.1 mjacob printf("\n"); 143 1.1 mjacob 144 1.5 thorpej /* 145 1.5 thorpej * Determine if we're the console's MCPCIA. 146 1.5 thorpej */ 147 1.5 thorpej if (ma->ma_mid == mcpcia_console_configuration.cc_mid && 148 1.5 thorpej ma->ma_gid == mcpcia_console_configuration.cc_gid) 149 1.5 thorpej ccp = &mcpcia_console_configuration; 150 1.5 thorpej else { 151 1.30 thorpej ccp = kmem_zalloc(sizeof(struct mcpcia_config), KM_SLEEP); 152 1.5 thorpej ccp->cc_mid = ma->ma_mid; 153 1.5 thorpej ccp->cc_gid = ma->ma_gid; 154 1.1 mjacob } 155 1.5 thorpej 156 1.28 matt mcp->mcpcia_dev = self; 157 1.5 thorpej mcp->mcpcia_cc = ccp; 158 1.5 thorpej ccp->cc_sc = mcp; 159 1.5 thorpej 160 1.5 thorpej /* This initializes cc_sysbase so we can do register access. */ 161 1.36 thorpej mcpcia_init0(ccp); 162 1.5 thorpej 163 1.5 thorpej ctl = REGVAL(MCPCIA_PCI_REV(ccp)); 164 1.28 matt aprint_normal_dev(self, 165 1.28 matt "Horse Revision %d, %s Handed Saddle Revision %d," 166 1.28 matt " CAP Revision %d\n", HORSE_REV(ctl), 167 1.5 thorpej (SADDLE_TYPE(ctl) & 1)? "Right": "Left", SADDLE_REV(ctl), 168 1.5 thorpej CAP_REV(ctl)); 169 1.5 thorpej 170 1.5 thorpej mcpcia_dma_init(ccp); 171 1.1 mjacob 172 1.1 mjacob /* 173 1.1 mjacob * Set up interrupts 174 1.1 mjacob */ 175 1.34 thorpej alpha_pci_intr_init(ccp, &ccp->cc_iot, &ccp->cc_memt, &ccp->cc_pc); 176 1.1 mjacob 177 1.1 mjacob /* 178 1.1 mjacob * Attach PCI bus 179 1.1 mjacob */ 180 1.5 thorpej pba.pba_iot = &ccp->cc_iot; 181 1.5 thorpej pba.pba_memt = &ccp->cc_memt; 182 1.1 mjacob pba.pba_dmat = /* start with direct, may change... */ 183 1.5 thorpej alphabus_dma_get_tag(&ccp->cc_dmat_direct, ALPHA_BUS_PCI); 184 1.17 fvdl pba.pba_dmat64 = NULL; 185 1.5 thorpej pba.pba_pc = &ccp->cc_pc; 186 1.1 mjacob pba.pba_bus = 0; 187 1.13 thorpej pba.pba_bridgetag = NULL; 188 1.27 dyoung pba.pba_flags = PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY | 189 1.6 thorpej PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY; 190 1.35 thorpej config_found(self, &pba, pcibusprint, CFARGS_NONE); 191 1.5 thorpej 192 1.5 thorpej /* 193 1.5 thorpej * Clear any errors that may have occurred during the probe 194 1.5 thorpej * sequence. 195 1.5 thorpej */ 196 1.5 thorpej REGVAL(MCPCIA_CAP_ERR(ccp)) = 0xFFFFFFFF; 197 1.5 thorpej alpha_mb(); 198 1.5 thorpej } 199 1.5 thorpej 200 1.5 thorpej void 201 1.26 cegger mcpcia_init(void) 202 1.5 thorpej { 203 1.5 thorpej struct mcpcia_config *ccp = &mcpcia_console_configuration; 204 1.5 thorpej int i; 205 1.5 thorpej 206 1.5 thorpej /* 207 1.5 thorpej * Look for all of the MCPCIAs on the system. One of them 208 1.5 thorpej * will have an EISA attached to it. This MCPCIA is the 209 1.5 thorpej * only one that can be used for the console. Once we find 210 1.5 thorpej * that one, initialize it. 211 1.5 thorpej */ 212 1.5 thorpej 213 1.5 thorpej for (i = 0; i < MCPCIA_PER_MCBUS; i++) { 214 1.5 thorpej ccp->cc_mid = mcbus_mcpcia_probe_order[i]; 215 1.5 thorpej /* 216 1.5 thorpej * XXX If we ever support more than one MCBUS, we'll 217 1.5 thorpej * XXX have to probe for them, and map them to unit 218 1.5 thorpej * XXX numbers. 219 1.5 thorpej */ 220 1.5 thorpej ccp->cc_gid = MCBUS_GID_FROM_INSTANCE(0); 221 1.5 thorpej ccp->cc_sysbase = MCPCIA_SYSBASE(ccp); 222 1.5 thorpej 223 1.5 thorpej if (badaddr((void *)ALPHA_PHYS_TO_K0SEG(MCPCIA_PCI_REV(ccp)), 224 1.29 matt sizeof(uint32_t))) 225 1.5 thorpej continue; 226 1.5 thorpej 227 1.5 thorpej if (EISA_PRESENT(REGVAL(MCPCIA_PCI_REV(ccp)))) { 228 1.36 thorpej mcpcia_init0(ccp); 229 1.10 thorpej 230 1.10 thorpej alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_IO] = 2; 231 1.10 thorpej alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_MEM] = 3; 232 1.10 thorpej 233 1.10 thorpej alpha_bus_get_window = mcpcia_bus_get_window; 234 1.5 thorpej return; 235 1.5 thorpej } 236 1.5 thorpej } 237 1.5 thorpej 238 1.5 thorpej panic("mcpcia_init: unable to find EISA bus"); 239 1.1 mjacob } 240 1.1 mjacob 241 1.1 mjacob void 242 1.36 thorpej mcpcia_init0(struct mcpcia_config *ccp) 243 1.1 mjacob { 244 1.29 matt uint32_t ctl; 245 1.1 mjacob 246 1.1 mjacob if (ccp->cc_initted == 0) { 247 1.5 thorpej /* don't do these twice since they set up extents */ 248 1.1 mjacob mcpcia_bus_io_init(&ccp->cc_iot, ccp); 249 1.1 mjacob mcpcia_bus_mem_init(&ccp->cc_memt, ccp); 250 1.1 mjacob } 251 1.5 thorpej 252 1.1 mjacob mcpcia_pci_init(&ccp->cc_pc, ccp); 253 1.1 mjacob 254 1.1 mjacob /* 255 1.1 mjacob * Establish a precalculated base for convenience's sake. 256 1.1 mjacob */ 257 1.5 thorpej ccp->cc_sysbase = MCPCIA_SYSBASE(ccp); 258 1.1 mjacob 259 1.1 mjacob /* 260 1.1 mjacob * Disable interrupts and clear errors prior to probing 261 1.1 mjacob */ 262 1.5 thorpej REGVAL(MCPCIA_INT_MASK0(ccp)) = 0; 263 1.5 thorpej REGVAL(MCPCIA_INT_MASK1(ccp)) = 0; 264 1.5 thorpej REGVAL(MCPCIA_CAP_ERR(ccp)) = 0xFFFFFFFF; 265 1.1 mjacob alpha_mb(); 266 1.1 mjacob 267 1.12 thorpej if (ccp == &mcpcia_console_configuration) { 268 1.12 thorpej /* 269 1.12 thorpej * Use this opportunity to also find out the MID and CPU 270 1.12 thorpej * type of the currently running CPU (that's us, billybob....) 271 1.12 thorpej */ 272 1.12 thorpej ctl = REGVAL(MCPCIA_WHOAMI(ccp)); 273 1.12 thorpej mcbus_primary.mcbus_cpu_mid = MCBUS_CPU_MID(ctl); 274 1.12 thorpej if ((MCBUS_CPU_INFO(ctl) & CPU_Fill_Err) == 0 && 275 1.12 thorpej mcbus_primary.mcbus_valid == 0) { 276 1.12 thorpej mcbus_primary.mcbus_bcache = 277 1.12 thorpej MCBUS_CPU_INFO(ctl) & CPU_BCacheMask; 278 1.12 thorpej mcbus_primary.mcbus_valid = 1; 279 1.12 thorpej } 280 1.12 thorpej alpha_mb(); 281 1.1 mjacob } 282 1.5 thorpej 283 1.1 mjacob ccp->cc_initted = 1; 284 1.1 mjacob } 285 1.1 mjacob 286 1.5 thorpej #ifdef TEST_PROBE_DEATH 287 1.4 mjacob static void 288 1.24 dsl die_heathen_dog(void *arg) 289 1.4 mjacob { 290 1.5 thorpej struct mcpcia_config *ccp = arg; 291 1.5 thorpej 292 1.4 mjacob /* this causes a fatal machine check (0x670) */ 293 1.5 thorpej REGVAL(MCPCIA_CAP_DIAG(ccp)) |= CAP_DIAG_MC_ADRPE; 294 1.4 mjacob } 295 1.4 mjacob #endif 296 1.4 mjacob 297 1.1 mjacob void 298 1.26 cegger mcpcia_config_cleanup(void) 299 1.1 mjacob { 300 1.29 matt volatile uint32_t ctl; 301 1.1 mjacob struct mcpcia_softc *mcp; 302 1.5 thorpej struct mcpcia_config *ccp; 303 1.5 thorpej int i; 304 1.5 thorpej extern struct cfdriver mcpcia_cd; 305 1.1 mjacob 306 1.1 mjacob /* 307 1.1 mjacob * Turn on Hard, Soft error interrupts. Maybe i2c too. 308 1.1 mjacob */ 309 1.5 thorpej for (i = 0; i < mcpcia_cd.cd_ndevs; i++) { 310 1.22 dogcow if ((mcp = device_lookup_private(&mcpcia_cd, i)) == NULL) 311 1.5 thorpej continue; 312 1.5 thorpej 313 1.5 thorpej ccp = mcp->mcpcia_cc; 314 1.7 mjacob if (ccp == NULL) 315 1.7 mjacob continue; 316 1.5 thorpej 317 1.5 thorpej ctl = REGVAL(MCPCIA_INT_MASK0(ccp)); 318 1.1 mjacob ctl |= MCPCIA_GEN_IENABL; 319 1.5 thorpej REGVAL(MCPCIA_INT_MASK0(ccp)) = ctl; 320 1.1 mjacob alpha_mb(); 321 1.5 thorpej 322 1.1 mjacob /* force stall while write completes */ 323 1.5 thorpej ctl = REGVAL(MCPCIA_INT_MASK0(ccp)); 324 1.4 mjacob } 325 1.5 thorpej #ifdef TEST_PROBE_DEATH 326 1.5 thorpej (void) timeout (die_heathen_dog, &mcpcia_console_configuration, 327 1.5 thorpej 30 * hz); 328 1.4 mjacob #endif 329 1.10 thorpej } 330 1.10 thorpej 331 1.32 thorpej static int 332 1.32 thorpej mcpcia_bus_get_window(int type, int window, 333 1.32 thorpej struct alpha_bus_space_translation *abst) 334 1.10 thorpej { 335 1.10 thorpej struct mcpcia_config *ccp = &mcpcia_console_configuration; 336 1.10 thorpej bus_space_tag_t st; 337 1.10 thorpej 338 1.10 thorpej switch (type) { 339 1.10 thorpej case ALPHA_BUS_TYPE_PCI_IO: 340 1.10 thorpej st = &ccp->cc_iot; 341 1.10 thorpej break; 342 1.10 thorpej 343 1.10 thorpej case ALPHA_BUS_TYPE_PCI_MEM: 344 1.10 thorpej st = &ccp->cc_memt; 345 1.10 thorpej break; 346 1.10 thorpej 347 1.10 thorpej default: 348 1.10 thorpej panic("mcpcia_bus_get_window"); 349 1.10 thorpej } 350 1.10 thorpej 351 1.10 thorpej return (alpha_bus_space_get_window(st, window, abst)); 352 1.1 mjacob } 353