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