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