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