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