1 1.9 riastrad /* $NetBSD: sbbrz.c,v 1.9 2022/03/03 06:27:21 riastradh Exp $ */ 2 1.2 matt 3 1.2 matt /* 4 1.2 matt * Copyright 2000, 2001 5 1.2 matt * Broadcom Corporation. All rights reserved. 6 1.7 skrll * 7 1.2 matt * This software is furnished under license and may be used and copied only 8 1.2 matt * in accordance with the following terms and conditions. Subject to these 9 1.2 matt * conditions, you may download, copy, install, use, modify and distribute 10 1.2 matt * modified or unmodified copies of this software in source and/or binary 11 1.2 matt * form. No title or ownership is transferred hereby. 12 1.7 skrll * 13 1.2 matt * 1) Any source code used, modified or distributed must reproduce and 14 1.2 matt * retain this copyright notice and list of conditions as they appear in 15 1.2 matt * the source file. 16 1.7 skrll * 17 1.2 matt * 2) No right is granted to use any trade name, trademark, or logo of 18 1.2 matt * Broadcom Corporation. Neither the "Broadcom Corporation" name nor any 19 1.2 matt * trademark or logo of Broadcom Corporation may be used to endorse or 20 1.2 matt * promote products derived from this software without the prior written 21 1.2 matt * permission of Broadcom Corporation. 22 1.7 skrll * 23 1.2 matt * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED 24 1.2 matt * WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF 25 1.2 matt * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR 26 1.2 matt * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE 27 1.2 matt * FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE 28 1.2 matt * LIABLE FOR DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 1.2 matt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 1.2 matt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 31 1.2 matt * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 32 1.2 matt * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 33 1.2 matt * OR OTHERWISE), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 1.2 matt */ 35 1.2 matt 36 1.2 matt /* from: $NetBSD: apecs.c,v 1.38 2000/06/29 08:58:45 mrg Exp */ 37 1.2 matt 38 1.2 matt /*- 39 1.2 matt * Copyright (c) 2000, 2010 The NetBSD Foundation, Inc. 40 1.2 matt * All rights reserved. 41 1.2 matt * 42 1.2 matt * This code is derived from software contributed to The NetBSD Foundation 43 1.2 matt * by Jason R. Thorpe. 44 1.2 matt * 45 1.2 matt * Redistribution and use in source and binary forms, with or without 46 1.2 matt * modification, are permitted provided that the following conditions 47 1.2 matt * are met: 48 1.2 matt * 1. Redistributions of source code must retain the above copyright 49 1.2 matt * notice, this list of conditions and the following disclaimer. 50 1.2 matt * 2. Redistributions in binary form must reproduce the above copyright 51 1.2 matt * notice, this list of conditions and the following disclaimer in the 52 1.2 matt * documentation and/or other materials provided with the distribution. 53 1.2 matt * 54 1.2 matt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 55 1.2 matt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 56 1.2 matt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 57 1.2 matt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 58 1.2 matt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 59 1.2 matt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 60 1.2 matt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 61 1.2 matt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 62 1.2 matt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 63 1.2 matt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 64 1.2 matt * POSSIBILITY OF SUCH DAMAGE. 65 1.2 matt */ 66 1.2 matt 67 1.2 matt /* 68 1.2 matt * Copyright (c) 1995, 1996 Carnegie-Mellon University. 69 1.2 matt * All rights reserved. 70 1.2 matt * 71 1.2 matt * Author: Chris G. Demetriou 72 1.7 skrll * 73 1.2 matt * Permission to use, copy, modify and distribute this software and 74 1.2 matt * its documentation is hereby granted, provided that both the copyright 75 1.2 matt * notice and this permission notice appear in all copies of the 76 1.2 matt * software, derivative works or modified versions, and any portions 77 1.2 matt * thereof, and that both notices appear in supporting documentation. 78 1.7 skrll * 79 1.7 skrll * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 80 1.7 skrll * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 81 1.2 matt * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 82 1.7 skrll * 83 1.2 matt * Carnegie Mellon requests users of this software to return to 84 1.2 matt * 85 1.2 matt * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU 86 1.2 matt * School of Computer Science 87 1.2 matt * Carnegie Mellon University 88 1.2 matt * Pittsburgh PA 15213-3890 89 1.2 matt * 90 1.2 matt * any improvements or extensions that they make and grant Carnegie the 91 1.2 matt * rights to redistribute these changes. 92 1.2 matt */ 93 1.2 matt 94 1.2 matt /* 95 1.2 matt * Driver for SB-1250 I/O bridge 0, which provides the PCI and LDT 96 1.2 matt * interfaces. 97 1.2 matt */ 98 1.2 matt 99 1.2 matt #define _MIPS_BUS_DMA_PRIVATE 100 1.2 matt 101 1.2 matt #include <sys/param.h> 102 1.2 matt #include <sys/device.h> 103 1.2 matt #include <sys/systm.h> 104 1.2 matt #include <sys/bus.h> 105 1.2 matt 106 1.2 matt #include <dev/pci/pcireg.h> 107 1.2 matt #include <dev/pci/pcivar.h> 108 1.2 matt #include <dev/pci/pcidevs.h> 109 1.2 matt 110 1.2 matt #include <mips/locore.h> 111 1.2 matt #include <mips/sibyte/include/sb1250_regs.h> 112 1.2 matt #include <mips/sibyte/include/sb1250_scd.h> 113 1.2 matt #include <mips/sibyte/include/zbbusvar.h> 114 1.2 matt #include <mips/sibyte/pci/sbbrzvar.h> 115 1.2 matt 116 1.2 matt static int sbbrz_match(device_t, cfdata_t, void *); 117 1.2 matt static void sbbrz_attach(device_t, device_t, void *); 118 1.2 matt 119 1.2 matt CFATTACH_DECL_NEW(sbbrz, 0, sbbrz_match, sbbrz_attach, NULL, NULL); 120 1.2 matt 121 1.2 matt static int sbbrz_print(void *, const char *pnp); 122 1.2 matt 123 1.2 matt /* There can be only one. */ 124 1.2 matt struct sbbrz_softc sbbrz_softc; 125 1.2 matt 126 1.2 matt static int 127 1.2 matt sbbrz_match(device_t parent, cfdata_t match, void *aux) 128 1.2 matt { 129 1.2 matt struct zbbus_attach_args *zap = aux; 130 1.2 matt 131 1.2 matt if (zap->za_locs.za_type != ZBBUS_ENTTYPE_BRZ) 132 1.2 matt return (0); 133 1.7 skrll 134 1.2 matt if (sbbrz_softc.sc_dev != NULL) 135 1.2 matt return (0); 136 1.2 matt 137 1.2 matt return 1; 138 1.2 matt } 139 1.2 matt 140 1.2 matt /* 141 1.2 matt * Set up the chipset's function pointers. 142 1.2 matt */ 143 1.2 matt static void 144 1.2 matt sbbrz_init(struct sbbrz_softc *sc) 145 1.2 matt { 146 1.2 matt int error; 147 1.2 matt 148 1.2 matt sbbrz_bus_io_init(&sc->sc_iot, sc); 149 1.2 matt sbbrz_bus_mem_init(&sc->sc_memt, sc); 150 1.2 matt 151 1.2 matt bus_dma_tag_t t = &sc->sc_dmat64; 152 1.2 matt t->_cookie = sc; 153 1.2 matt t->_wbase = 0; 154 1.2 matt t->_bounce_alloc_lo = 0; 155 1.2 matt t->_bounce_alloc_hi = 0; 156 1.2 matt t->_dmamap_ops = mips_bus_dmamap_ops; 157 1.2 matt t->_dmamem_ops = mips_bus_dmamem_ops; 158 1.2 matt t->_dmatag_ops = mips_bus_dmatag_ops; 159 1.2 matt 160 1.8 skrll error = bus_dmatag_subregion(t, 0, __MASK(32), &sc->sc_dmat32, 0); 161 1.2 matt if (error) 162 1.7 skrll panic("%s: failed to create 32bit dma tag: %d", 163 1.2 matt __func__, error); 164 1.2 matt 165 1.2 matt sbbrz_pci_init(&sc->sc_pc, sc); 166 1.2 matt } 167 1.2 matt 168 1.2 matt static void 169 1.2 matt sbbrz_attach(device_t parent, device_t self, void *aux) 170 1.2 matt { 171 1.2 matt struct sbbrz_softc *sc = &sbbrz_softc; 172 1.2 matt struct pcibus_attach_args pba; 173 1.2 matt uint64_t regval; 174 1.2 matt bool host; 175 1.2 matt 176 1.2 matt /* Tell the user whether it's host or device mode. */ 177 1.4 christos regval = mips3_ld((register_t)MIPS_PHYS_TO_KSEG1(A_SCD_SYSTEM_CFG)); 178 1.2 matt host = (regval & M_SYS_PCI_HOST) != 0; 179 1.2 matt 180 1.2 matt aprint_normal(": %s pci mode\n", host ? "host" : "device"); 181 1.2 matt 182 1.2 matt /* note that we've attached the bridge; can't have two. */ 183 1.2 matt sc->sc_dev = self; 184 1.9 riastrad device_set_private(self, sc); 185 1.2 matt 186 1.2 matt /* 187 1.2 matt * set up the bridge's info; done once at console init time 188 1.2 matt * (maybe), but doesn't hurt to do twice. 189 1.2 matt */ 190 1.2 matt sbbrz_init(sc); 191 1.2 matt 192 1.2 matt #if _has_pba_busname 193 1.2 matt pba.pba_busname = "pci"; 194 1.2 matt #endif 195 1.2 matt pba.pba_iot = &sc->sc_iot; 196 1.2 matt pba.pba_memt = &sc->sc_memt; 197 1.2 matt pba.pba_dmat64 = &sc->sc_dmat64; 198 1.2 matt pba.pba_dmat = sc->sc_dmat32; 199 1.2 matt pba.pba_pc = &sc->sc_pc; 200 1.2 matt pba.pba_bus = 0; 201 1.2 matt pba.pba_bridgetag = NULL; 202 1.3 dyoung pba.pba_flags = PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY | 203 1.2 matt PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY; 204 1.6 thorpej config_found(self, &pba, sbbrz_print, CFARGS_NONE); 205 1.2 matt } 206 1.2 matt 207 1.2 matt static int 208 1.2 matt sbbrz_print(void *aux, const char *pnp) 209 1.2 matt { 210 1.2 matt struct pcibus_attach_args *pba = aux; 211 1.7 skrll 212 1.2 matt /* only PCIs can attach to sbbrz; easy. */ 213 1.2 matt if (pnp) 214 1.2 matt #if _has_pba_busname 215 1.2 matt aprint_normal("%s at %s\n", pba->pba_busname, pnp); 216 1.2 matt #else 217 1.2 matt aprint_normal("\n* sbbrz_pci at %s", pnp); 218 1.2 matt #endif 219 1.2 matt aprint_normal(" bus %d", pba->pba_bus); 220 1.2 matt return (UNCONF); 221 1.7 skrll } 222