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