Sun Sep 16 12:10:57 2012 UTC ()
Be consistent with applying __HAVE_PCI_CONF_HOOK around bcmpax_conf_hook
implementation as well.  Fixes build for BCM5301X evbarm kernel.


(he)
diff -r1.2 -r1.3 src/sys/arch/arm/broadcom/bcm53xx_pax.c

cvs diff -r1.2 -r1.3 src/sys/arch/arm/broadcom/bcm53xx_pax.c (switch to unified diff)

--- src/sys/arch/arm/broadcom/bcm53xx_pax.c 2012/09/14 04:53:58 1.2
+++ src/sys/arch/arm/broadcom/bcm53xx_pax.c 2012/09/16 12:10:57 1.3
@@ -1,407 +1,409 @@ @@ -1,407 +1,409 @@
1/*- 1/*-
2 * Copyright (c) 2012 The NetBSD Foundation, Inc. 2 * Copyright (c) 2012 The NetBSD Foundation, Inc.
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * This code is derived from software contributed to The NetBSD Foundation 5 * This code is derived from software contributed to The NetBSD Foundation
6 * by Matt Thomas of 3am Software Foundry. 6 * by Matt Thomas of 3am Software Foundry.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution. 15 * documentation and/or other materials provided with the distribution.
16 * 16 *
17 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 17 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE. 27 * POSSIBILITY OF SUCH DAMAGE.
28 */ 28 */
29 29
30#define PCIE_PRIVATE 30#define PCIE_PRIVATE
31 31
32#include "locators.h" 32#include "locators.h"
33 33
34#include <sys/cdefs.h> 34#include <sys/cdefs.h>
35 35
36__KERNEL_RCSID(1, "$NetBSD: bcm53xx_pax.c,v 1.2 2012/09/14 04:53:58 matt Exp $"); 36__KERNEL_RCSID(1, "$NetBSD: bcm53xx_pax.c,v 1.3 2012/09/16 12:10:57 he Exp $");
37 37
38#include <sys/bus.h> 38#include <sys/bus.h>
39#include <sys/device.h> 39#include <sys/device.h>
40#include <sys/extent.h> 40#include <sys/extent.h>
41#include <sys/intr.h> 41#include <sys/intr.h>
42#include <sys/systm.h> 42#include <sys/systm.h>
43 43
44#include <dev/pci/pcireg.h> 44#include <dev/pci/pcireg.h>
45#include <dev/pci/pcivar.h> 45#include <dev/pci/pcivar.h>
46#include <dev/pci/pciconf.h> 46#include <dev/pci/pciconf.h>
47 47
48#include <arm/broadcom/bcm53xx_reg.h> 48#include <arm/broadcom/bcm53xx_reg.h>
49#include <arm/broadcom/bcm53xx_var.h> 49#include <arm/broadcom/bcm53xx_var.h>
50 50
51static const struct { 51static const struct {
52 paddr_t owin_base; 52 paddr_t owin_base;
53 psize_t owin_size; 53 psize_t owin_size;
54} bcmpax_owins[] = { 54} bcmpax_owins[] = {
55 [0] = { BCM53XX_PCIE0_OWIN_PBASE, BCM53XX_PCIE0_OWIN_SIZE }, 55 [0] = { BCM53XX_PCIE0_OWIN_PBASE, BCM53XX_PCIE0_OWIN_SIZE },
56 [1] = { BCM53XX_PCIE1_OWIN_PBASE, BCM53XX_PCIE1_OWIN_SIZE }, 56 [1] = { BCM53XX_PCIE1_OWIN_PBASE, BCM53XX_PCIE1_OWIN_SIZE },
57 [2] = { BCM53XX_PCIE2_OWIN_PBASE, BCM53XX_PCIE2_OWIN_SIZE }, 57 [2] = { BCM53XX_PCIE2_OWIN_PBASE, BCM53XX_PCIE2_OWIN_SIZE },
58}; 58};
59 59
60static int bcmpax_ccb_match(device_t, cfdata_t, void *); 60static int bcmpax_ccb_match(device_t, cfdata_t, void *);
61static void bcmpax_ccb_attach(device_t, device_t, void *); 61static void bcmpax_ccb_attach(device_t, device_t, void *);
62 62
63struct bcmpax_softc { 63struct bcmpax_softc {
64 device_t sc_dev; 64 device_t sc_dev;
65 bus_space_tag_t sc_bst; 65 bus_space_tag_t sc_bst;
66 bus_space_handle_t sc_bsh; 66 bus_space_handle_t sc_bsh;
67 bus_dma_tag_t sc_dmat; 67 bus_dma_tag_t sc_dmat;
68 kmutex_t *sc_lock; 68 kmutex_t *sc_lock;
69 kmutex_t *sc_cfg_lock; 69 kmutex_t *sc_cfg_lock;
70 bool sc_linkup; 70 bool sc_linkup;
71 int sc_pba_flags; 71 int sc_pba_flags;
72 struct arm32_pci_chipset sc_pc; 72 struct arm32_pci_chipset sc_pc;
73}; 73};
74 74
75static inline uint32_t 75static inline uint32_t
76bcmpax_read_4(struct bcmpax_softc *sc, bus_size_t o) 76bcmpax_read_4(struct bcmpax_softc *sc, bus_size_t o)
77{ 77{
78 return bus_space_read_4(sc->sc_bst, sc->sc_bsh, o); 78 return bus_space_read_4(sc->sc_bst, sc->sc_bsh, o);
79} 79}
80 80
81static inline void 81static inline void
82bcmpax_write_4(struct bcmpax_softc *sc, bus_size_t o, uint32_t v) 82bcmpax_write_4(struct bcmpax_softc *sc, bus_size_t o, uint32_t v)
83{ 83{
84 bus_space_write_4(sc->sc_bst, sc->sc_bsh, o, v); 84 bus_space_write_4(sc->sc_bst, sc->sc_bsh, o, v);
85} 85}
86 86
87static void bcmpax_attach_hook(device_t, device_t, struct pcibus_attach_args *); 87static void bcmpax_attach_hook(device_t, device_t, struct pcibus_attach_args *);
88static int bcmpax_bus_maxdevs(void *, int); 88static int bcmpax_bus_maxdevs(void *, int);
89static pcitag_t bcmpax_make_tag(void *, int, int, int); 89static pcitag_t bcmpax_make_tag(void *, int, int, int);
90static void bcmpax_decompose_tag(void *, pcitag_t, int *, int *, int *); 90static void bcmpax_decompose_tag(void *, pcitag_t, int *, int *, int *);
91static pcireg_t bcmpax_conf_read(void *, pcitag_t, int); 91static pcireg_t bcmpax_conf_read(void *, pcitag_t, int);
92static void bcmpax_conf_write(void *, pcitag_t, int, pcireg_t); 92static void bcmpax_conf_write(void *, pcitag_t, int, pcireg_t);
93 93
94static int bcmpax_intr_map(const struct pci_attach_args *, pci_intr_handle_t *); 94static int bcmpax_intr_map(const struct pci_attach_args *, pci_intr_handle_t *);
95static const char *bcmpax_intr_string(void *, pci_intr_handle_t); 95static const char *bcmpax_intr_string(void *, pci_intr_handle_t);
96static const struct evcnt *bcmpax_intr_evcnt(void *, pci_intr_handle_t); 96static const struct evcnt *bcmpax_intr_evcnt(void *, pci_intr_handle_t);
97static void *bcmpax_intr_establish(void *, pci_intr_handle_t, int, 97static void *bcmpax_intr_establish(void *, pci_intr_handle_t, int,
98 int (*)(void *), void *); 98 int (*)(void *), void *);
99static void bcmpax_intr_disestablish(void *, void *); 99static void bcmpax_intr_disestablish(void *, void *);
100 100
101#ifdef __HAVE_PCI_CONF_HOOK 101#ifdef __HAVE_PCI_CONF_HOOK
102static int bcmpax_conf_hook(void *, int, int, int, pcireg_t); 102static int bcmpax_conf_hook(void *, int, int, int, pcireg_t);
103#endif 103#endif
104static void bcmpax_conf_interrupt(void *, int, int, int, int, int *); 104static void bcmpax_conf_interrupt(void *, int, int, int, int, int *);
105 105
106 106
107CFATTACH_DECL_NEW(bcmpax_ccb, sizeof(struct bcmpax_softc), 107CFATTACH_DECL_NEW(bcmpax_ccb, sizeof(struct bcmpax_softc),
108 bcmpax_ccb_match, bcmpax_ccb_attach, NULL, NULL); 108 bcmpax_ccb_match, bcmpax_ccb_attach, NULL, NULL);
109 109
110static int 110static int
111bcmpax_ccb_match(device_t parent, cfdata_t cf, void *aux) 111bcmpax_ccb_match(device_t parent, cfdata_t cf, void *aux)
112{ 112{
113 struct bcmccb_attach_args * const ccbaa = aux; 113 struct bcmccb_attach_args * const ccbaa = aux;
114 const struct bcm_locators * const loc = &ccbaa->ccbaa_loc; 114 const struct bcm_locators * const loc = &ccbaa->ccbaa_loc;
115 115
116 if (strcmp(cf->cf_name, loc->loc_name)) 116 if (strcmp(cf->cf_name, loc->loc_name))
117 return 0; 117 return 0;
118 118
119#ifdef DIAGNOSTIC 119#ifdef DIAGNOSTIC
120 const int port = cf->cf_loc[BCMCCBCF_PORT]; 120 const int port = cf->cf_loc[BCMCCBCF_PORT];
121#endif 121#endif
122 KASSERT(port == BCMCCBCF_PORT_DEFAULT || port == loc->loc_port); 122 KASSERT(port == BCMCCBCF_PORT_DEFAULT || port == loc->loc_port);
123 123
124 return 1; 124 return 1;
125} 125}
126 126
127static void 127static void
128bcmpax_ccb_attach(device_t parent, device_t self, void *aux) 128bcmpax_ccb_attach(device_t parent, device_t self, void *aux)
129{ 129{
130 struct bcmpax_softc * const sc = device_private(self); 130 struct bcmpax_softc * const sc = device_private(self);
131 struct bcmccb_attach_args * const ccbaa = aux; 131 struct bcmccb_attach_args * const ccbaa = aux;
132 const struct bcm_locators * const loc = &ccbaa->ccbaa_loc; 132 const struct bcm_locators * const loc = &ccbaa->ccbaa_loc;
133 133
134 sc->sc_dev = self; 134 sc->sc_dev = self;
135 135
136 sc->sc_bst = ccbaa->ccbaa_ccb_bst; 136 sc->sc_bst = ccbaa->ccbaa_ccb_bst;
137 sc->sc_dmat = ccbaa->ccbaa_dmat; 137 sc->sc_dmat = ccbaa->ccbaa_dmat;
138 138
139 bus_space_subregion(sc->sc_bst, ccbaa->ccbaa_ccb_bsh, 139 bus_space_subregion(sc->sc_bst, ccbaa->ccbaa_ccb_bsh,
140 loc->loc_offset, loc->loc_size, &sc->sc_bsh); 140 loc->loc_offset, loc->loc_size, &sc->sc_bsh);
141 141
142 bcmpax_write_4(sc, PCIE_CLK_CONTROL, 3); 142 bcmpax_write_4(sc, PCIE_CLK_CONTROL, 3);
143 delay(250); 143 delay(250);
144 bcmpax_write_4(sc, PCIE_CLK_CONTROL, 1); 144 bcmpax_write_4(sc, PCIE_CLK_CONTROL, 1);
145 // delay(100*1000); 145 // delay(100*1000);
146 146
147 uint32_t v = bcmpax_read_4(sc, PCIE_STRAP_STATUS); 147 uint32_t v = bcmpax_read_4(sc, PCIE_STRAP_STATUS);
148 const bool enabled = (v & STRAP_PCIE_IF_ENABLE) != 0; 148 const bool enabled = (v & STRAP_PCIE_IF_ENABLE) != 0;
149 const bool is_v2_p = (v & STRAP_PCIE_USER_FOR_CE_GEN1) == 0; 149 const bool is_v2_p = (v & STRAP_PCIE_USER_FOR_CE_GEN1) == 0;
150 const bool is_x2_p = (v & STRAP_PCIE_USER_FOR_CE_1LANE) == 0; 150 const bool is_x2_p = (v & STRAP_PCIE_USER_FOR_CE_1LANE) == 0;
151 const bool is_rc_p = (v & STRAP_PCIE_USER_RC_MODE) != 0; 151 const bool is_rc_p = (v & STRAP_PCIE_USER_RC_MODE) != 0;
152 152
153 aprint_naive("\n"); 153 aprint_naive("\n");
154 aprint_normal(": PCI Express V%u %u-lane %s Controller%s\n", 154 aprint_normal(": PCI Express V%u %u-lane %s Controller%s\n",
155 is_v2_p ? 2 : 1, 155 is_v2_p ? 2 : 1,
156 is_x2_p ? 2 : 1, 156 is_x2_p ? 2 : 1,
157 is_rc_p ? "RC" : "EP", 157 is_rc_p ? "RC" : "EP",
158 enabled ? "" : "(disabled)"); 158 enabled ? "" : "(disabled)");
159 if (!enabled || !is_rc_p) 159 if (!enabled || !is_rc_p)
160 return; 160 return;
161 161
162 sc->sc_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_VM); 162 sc->sc_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_VM);
163 sc->sc_cfg_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_VM); 163 sc->sc_cfg_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_VM);
164 164
165 sc->sc_pc.pc_conf_v = sc; 165 sc->sc_pc.pc_conf_v = sc;
166 sc->sc_pc.pc_attach_hook = bcmpax_attach_hook; 166 sc->sc_pc.pc_attach_hook = bcmpax_attach_hook;
167 sc->sc_pc.pc_bus_maxdevs = bcmpax_bus_maxdevs; 167 sc->sc_pc.pc_bus_maxdevs = bcmpax_bus_maxdevs;
168 sc->sc_pc.pc_make_tag = bcmpax_make_tag; 168 sc->sc_pc.pc_make_tag = bcmpax_make_tag;
169 sc->sc_pc.pc_decompose_tag = bcmpax_decompose_tag; 169 sc->sc_pc.pc_decompose_tag = bcmpax_decompose_tag;
170 sc->sc_pc.pc_conf_read = bcmpax_conf_read; 170 sc->sc_pc.pc_conf_read = bcmpax_conf_read;
171 sc->sc_pc.pc_conf_write = bcmpax_conf_write; 171 sc->sc_pc.pc_conf_write = bcmpax_conf_write;
172 172
173 sc->sc_pc.pc_intr_v = sc; 173 sc->sc_pc.pc_intr_v = sc;
174 sc->sc_pc.pc_intr_map = bcmpax_intr_map; 174 sc->sc_pc.pc_intr_map = bcmpax_intr_map;
175 sc->sc_pc.pc_intr_string = bcmpax_intr_string; 175 sc->sc_pc.pc_intr_string = bcmpax_intr_string;
176 sc->sc_pc.pc_intr_evcnt = bcmpax_intr_evcnt; 176 sc->sc_pc.pc_intr_evcnt = bcmpax_intr_evcnt;
177 sc->sc_pc.pc_intr_establish = bcmpax_intr_establish; 177 sc->sc_pc.pc_intr_establish = bcmpax_intr_establish;
178 sc->sc_pc.pc_intr_disestablish = bcmpax_intr_disestablish; 178 sc->sc_pc.pc_intr_disestablish = bcmpax_intr_disestablish;
179 179
180#ifdef __HAVE_PCI_CONF_HOOK 180#ifdef __HAVE_PCI_CONF_HOOK
181 sc->sc_pc.pc_conf_hook = bcmpax_conf_hook; 181 sc->sc_pc.pc_conf_hook = bcmpax_conf_hook;
182#endif 182#endif
183 sc->sc_pc.pc_conf_interrupt = bcmpax_conf_interrupt; 183 sc->sc_pc.pc_conf_interrupt = bcmpax_conf_interrupt;
184 184
185 // sc->sc_pba_flags |= PCI_FLAGS_MSI_OKAY; 185 // sc->sc_pba_flags |= PCI_FLAGS_MSI_OKAY;
186 // sc->sc_pba_flags |= PCI_FLAGS_MSIX_OKAY; 186 // sc->sc_pba_flags |= PCI_FLAGS_MSIX_OKAY;
187 187
188 int offset; 188 int offset;
189 const bool ok = pci_get_capability(&sc->sc_pc, 0, PCI_CAP_PCIEXPRESS, 189 const bool ok = pci_get_capability(&sc->sc_pc, 0, PCI_CAP_PCIEXPRESS,
190 &offset, NULL); 190 &offset, NULL);
191 KASSERT(ok); 191 KASSERT(ok);
192 192
193 /* 193 /*
194 * Now we wait (.1sec) for the link to come up. 194 * Now we wait (.1sec) for the link to come up.
195 */ 195 */
196 offset += PCI_PCIE_LCSR; 196 offset += PCI_PCIE_LCSR;
197 for (size_t timo = 0;; timo++) { 197 for (size_t timo = 0;; timo++) {
198 const pcireg_t lcsr = bcmpax_conf_read(sc, 0, offset);  198 const pcireg_t lcsr = bcmpax_conf_read(sc, 0, offset);
199 sc->sc_linkup = __SHIFTOUT(lcsr, PCI_PCIE_LCSR_NLW) != 0 199 sc->sc_linkup = __SHIFTOUT(lcsr, PCI_PCIE_LCSR_NLW) != 0
200 && (1 || (lcsr & PCI_PCIE_LCSR_DLACTIVE) != 0); 200 && (1 || (lcsr & PCI_PCIE_LCSR_DLACTIVE) != 0);
201 if (sc->sc_linkup || timo == 250) { 201 if (sc->sc_linkup || timo == 250) {
202 aprint_debug_dev(self, 202 aprint_debug_dev(self,
203 "lcsr=%#x nlw=%jd linkup=%d, timo=%zu\n", 203 "lcsr=%#x nlw=%jd linkup=%d, timo=%zu\n",
204 lcsr, __SHIFTOUT(lcsr, PCI_PCIE_LCSR_NLW), 204 lcsr, __SHIFTOUT(lcsr, PCI_PCIE_LCSR_NLW),
205 sc->sc_linkup, timo); 205 sc->sc_linkup, timo);
206 break; 206 break;
207 } 207 }
208 DELAY(1000); 208 DELAY(1000);
209 } 209 }
210 210
211 if (sc->sc_linkup) { 211 if (sc->sc_linkup) {
212 paddr_t base = bcmpax_owins[loc->loc_port].owin_base; 212 paddr_t base = bcmpax_owins[loc->loc_port].owin_base;
213 psize_t size = bcmpax_owins[loc->loc_port].owin_size; 213 psize_t size = bcmpax_owins[loc->loc_port].owin_size;
214 KASSERT((size & ~PCIE_OARR_ADDR) == 0); 214 KASSERT((size & ~PCIE_OARR_ADDR) == 0);
215 if (size > 0) { 215 if (size > 0) {
216 bcmpax_write_4(sc, PCIE_OARR_0, base); 216 bcmpax_write_4(sc, PCIE_OARR_0, base);
217 bcmpax_write_4(sc, PCIE_OMAP_0_LOWER, base | 1); 217 bcmpax_write_4(sc, PCIE_OMAP_0_LOWER, base | 1);
218 } 218 }
219 if (size > __LOWEST_SET_BIT(PCIE_OARR_ADDR)) { 219 if (size > __LOWEST_SET_BIT(PCIE_OARR_ADDR)) {
220 paddr_t base1 = base + __LOWEST_SET_BIT(PCIE_OARR_ADDR); 220 paddr_t base1 = base + __LOWEST_SET_BIT(PCIE_OARR_ADDR);
221 bcmpax_write_4(sc, PCIE_OARR_1, base1); 221 bcmpax_write_4(sc, PCIE_OARR_1, base1);
222 bcmpax_write_4(sc, PCIE_OMAP_1_LOWER, base1 | 1); 222 bcmpax_write_4(sc, PCIE_OMAP_1_LOWER, base1 | 1);
223 } 223 }
224 224
225 struct extent *memext = extent_create("pcimem", base, 225 struct extent *memext = extent_create("pcimem", base,
226 base + size, NULL, 0, EX_NOWAIT); 226 base + size, NULL, 0, EX_NOWAIT);
227 227
228 int error = pci_configure_bus(&sc->sc_pc, 228 int error = pci_configure_bus(&sc->sc_pc,
229 NULL, memext, NULL, 0, arm_pcache.dcache_line_size); 229 NULL, memext, NULL, 0, arm_pcache.dcache_line_size);
230 230
231 extent_destroy(memext); 231 extent_destroy(memext);
232 232
233 if (error) { 233 if (error) {
234 aprint_normal_dev(self, "configuration failed\n"); 234 aprint_normal_dev(self, "configuration failed\n");
235 return; 235 return;
236 } 236 }
237 } 237 }
238 238
239 struct pcibus_attach_args pba; 239 struct pcibus_attach_args pba;
240 memset(&pba, 0, sizeof(pba)); 240 memset(&pba, 0, sizeof(pba));
241  241
242 pba.pba_flags = sc->sc_pba_flags; 242 pba.pba_flags = sc->sc_pba_flags;
243 pba.pba_flags |= PCI_FLAGS_MEM_OKAY; 243 pba.pba_flags |= PCI_FLAGS_MEM_OKAY;
244 pba.pba_memt = sc->sc_bst; 244 pba.pba_memt = sc->sc_bst;
245 pba.pba_dmat = sc->sc_dmat; 245 pba.pba_dmat = sc->sc_dmat;
246 pba.pba_pc = &sc->sc_pc; 246 pba.pba_pc = &sc->sc_pc;
247 pba.pba_bus = 0; 247 pba.pba_bus = 0;
248 248
249 config_found_ia(self, "pcibus", &pba, pcibusprint); 249 config_found_ia(self, "pcibus", &pba, pcibusprint);
250} 250}
251 251
252static void 252static void
253bcmpax_attach_hook(device_t parent, device_t self, 253bcmpax_attach_hook(device_t parent, device_t self,
254 struct pcibus_attach_args *pba) 254 struct pcibus_attach_args *pba)
255{ 255{
256} 256}
257 257
258static int 258static int
259bcmpax_bus_maxdevs(void *v, int bus) 259bcmpax_bus_maxdevs(void *v, int bus)
260{ 260{
261 struct bcmpax_softc * const sc = v; 261 struct bcmpax_softc * const sc = v;
262 262
263 if (__predict_true(sc->sc_linkup)) 263 if (__predict_true(sc->sc_linkup))
264 return bus > 1 ? 32 : 1; 264 return bus > 1 ? 32 : 1;
265 265
266 return bus ? 0 : 1; 266 return bus ? 0 : 1;
267} 267}
268 268
269static void 269static void
270bcmpax_decompose_tag(void *v, pcitag_t tag, int *busp, int *devp, int *funcp) 270bcmpax_decompose_tag(void *v, pcitag_t tag, int *busp, int *devp, int *funcp)
271{ 271{
272 if (busp) 272 if (busp)
273 *busp = __SHIFTOUT(tag, CFG_ADDR_BUS); 273 *busp = __SHIFTOUT(tag, CFG_ADDR_BUS);
274 if (devp) 274 if (devp)
275 *devp = __SHIFTOUT(tag, CFG_ADDR_DEV); 275 *devp = __SHIFTOUT(tag, CFG_ADDR_DEV);
276 if (funcp) 276 if (funcp)
277 *funcp = __SHIFTOUT(tag, CFG_ADDR_FUNC); 277 *funcp = __SHIFTOUT(tag, CFG_ADDR_FUNC);
278}  278}
279 279
280static pcitag_t 280static pcitag_t
281bcmpax_make_tag(void *v, int bus, int dev, int func) 281bcmpax_make_tag(void *v, int bus, int dev, int func)
282{ 282{
283 return __SHIFTIN(bus, CFG_ADDR_BUS) 283 return __SHIFTIN(bus, CFG_ADDR_BUS)
284 | __SHIFTIN(dev, CFG_ADDR_DEV) 284 | __SHIFTIN(dev, CFG_ADDR_DEV)
285 | __SHIFTIN(func, CFG_ADDR_FUNC) 285 | __SHIFTIN(func, CFG_ADDR_FUNC)
286 | (bus == 0 ? CFG_ADDR_TYPE0 : CFG_ADDR_TYPE1); 286 | (bus == 0 ? CFG_ADDR_TYPE0 : CFG_ADDR_TYPE1);
287} 287}
288 288
289static inline bus_size_t 289static inline bus_size_t
290bcmpax_conf_addr_write(struct bcmpax_softc *sc, pcitag_t tag) 290bcmpax_conf_addr_write(struct bcmpax_softc *sc, pcitag_t tag)
291{ 291{
292 if ((tag & (CFG_ADDR_BUS|CFG_ADDR_DEV)) == 0) { 292 if ((tag & (CFG_ADDR_BUS|CFG_ADDR_DEV)) == 0) {
293 uint32_t reg = __SHIFTOUT(tag, CFG_ADDR_REG); 293 uint32_t reg = __SHIFTOUT(tag, CFG_ADDR_REG);
294 uint32_t func = __SHIFTOUT(tag, CFG_ADDR_FUNC); 294 uint32_t func = __SHIFTOUT(tag, CFG_ADDR_FUNC);
295 bcmpax_write_4(sc, PCIE_CFG_IND_ADDR, 295 bcmpax_write_4(sc, PCIE_CFG_IND_ADDR,
296 __SHIFTIN(func, CFG_IND_ADDR_FUNC) 296 __SHIFTIN(func, CFG_IND_ADDR_FUNC)
297 | __SHIFTIN(reg, CFG_IND_ADDR_REG)); 297 | __SHIFTIN(reg, CFG_IND_ADDR_REG));
298 __asm __volatile("dsb"); 298 __asm __volatile("dsb");
299 return PCIE_CFG_IND_DATA; 299 return PCIE_CFG_IND_DATA;
300 } 300 }
301 if (sc->sc_linkup) { 301 if (sc->sc_linkup) {
302 bcmpax_write_4(sc, PCIE_CFG_ADDR, tag); 302 bcmpax_write_4(sc, PCIE_CFG_ADDR, tag);
303 __asm __volatile("dsb"); 303 __asm __volatile("dsb");
304 return PCIE_CFG_DATA; 304 return PCIE_CFG_DATA;
305 }  305 }
306 return 0; 306 return 0;
307} 307}
308 308
309static pcireg_t 309static pcireg_t
310bcmpax_conf_read(void *v, pcitag_t tag, int reg) 310bcmpax_conf_read(void *v, pcitag_t tag, int reg)
311{ 311{
312 struct bcmpax_softc * const sc = v; 312 struct bcmpax_softc * const sc = v;
313 313
314 /* 314 /*
315 * Even in RC mode, the PCI Express Root Complex return itself 315 * Even in RC mode, the PCI Express Root Complex return itself
316 * as BCM Ethernet Controller!. We could change ppb.c to match it 316 * as BCM Ethernet Controller!. We could change ppb.c to match it
317 * but we'll just lie and say we are a PPB bridge. 317 * but we'll just lie and say we are a PPB bridge.
318 */ 318 */
319 if ((tag & (CFG_ADDR_BUS|CFG_ADDR_DEV|CFG_ADDR_FUNC)) == 0 319 if ((tag & (CFG_ADDR_BUS|CFG_ADDR_DEV|CFG_ADDR_FUNC)) == 0
320 && reg == PCI_CLASS_REG) { 320 && reg == PCI_CLASS_REG) {
321 return PCI_CLASS_CODE(PCI_CLASS_BRIDGE, 321 return PCI_CLASS_CODE(PCI_CLASS_BRIDGE,
322 PCI_SUBCLASS_BRIDGE_PCI, 0); 322 PCI_SUBCLASS_BRIDGE_PCI, 0);
323 } 323 }
324 324
325 //printf("%s: tag %#lx reg %#x:", __func__, tag, reg); 325 //printf("%s: tag %#lx reg %#x:", __func__, tag, reg);
326 326
327 mutex_enter(sc->sc_cfg_lock); 327 mutex_enter(sc->sc_cfg_lock);
328 bus_size_t data_reg = bcmpax_conf_addr_write(sc, tag | reg); 328 bus_size_t data_reg = bcmpax_conf_addr_write(sc, tag | reg);
329 329
330 //printf(" [from %#lx]:\n", data_reg); 330 //printf(" [from %#lx]:\n", data_reg);
331 331
332 pcireg_t rv; 332 pcireg_t rv;
333 if (data_reg) 333 if (data_reg)
334 rv = bcmpax_read_4(sc, data_reg); 334 rv = bcmpax_read_4(sc, data_reg);
335 else 335 else
336 rv = 0xffffffff; 336 rv = 0xffffffff;
337 337
338 mutex_exit(sc->sc_cfg_lock); 338 mutex_exit(sc->sc_cfg_lock);
339 339
340 //printf(" %#x\n", rv); 340 //printf(" %#x\n", rv);
341 341
342 return rv; 342 return rv;
343} 343}
344 344
345static void 345static void
346bcmpax_conf_write(void *v, pcitag_t tag, int reg, pcireg_t val) 346bcmpax_conf_write(void *v, pcitag_t tag, int reg, pcireg_t val)
347{ 347{
348 struct bcmpax_softc * const sc = v; 348 struct bcmpax_softc * const sc = v;
349 349
350 mutex_enter(sc->sc_cfg_lock); 350 mutex_enter(sc->sc_cfg_lock);
351 bus_size_t data_reg = bcmpax_conf_addr_write(sc, tag | reg); 351 bus_size_t data_reg = bcmpax_conf_addr_write(sc, tag | reg);
352 352
353 //printf("%s: tag %#lx reg %#x:", __func__, tag, reg); 353 //printf("%s: tag %#lx reg %#x:", __func__, tag, reg);
354 354
355 if (data_reg) { 355 if (data_reg) {
356 //printf(" [to %#lx]:\n", data_reg); 356 //printf(" [to %#lx]:\n", data_reg);
357 bcmpax_write_4(sc, data_reg, val); 357 bcmpax_write_4(sc, data_reg, val);
358 //printf(" %#x\n", val); 358 //printf(" %#x\n", val);
359 } 359 }
360 360
361 mutex_exit(sc->sc_cfg_lock); 361 mutex_exit(sc->sc_cfg_lock);
362} 362}
363 363
364static void 364static void
365bcmpax_conf_interrupt(void *v, int bus, int dev, int ipin, int swiz, int *ilinep) 365bcmpax_conf_interrupt(void *v, int bus, int dev, int ipin, int swiz, int *ilinep)
366{ 366{
367 *ilinep = 5; /* (ipin + swiz) & 3; */ 367 *ilinep = 5; /* (ipin + swiz) & 3; */
368} 368}
369 369
 370#ifdef __HAVE_PCI_CONF_HOOK
370static int 371static int
371bcmpax_conf_hook(void *v, int bus, int dev, int func, pcireg_t id) 372bcmpax_conf_hook(void *v, int bus, int dev, int func, pcireg_t id)
372{ 373{
373 if (func > 0) 374 if (func > 0)
374 return 0; 375 return 0;
375 376
376 return PCI_CONF_ENABLE_MEM | PCI_CONF_MAP_MEM; 377 return PCI_CONF_ENABLE_MEM | PCI_CONF_MAP_MEM;
377} 378}
 379#endif
378 380
379static int 381static int
380bcmpax_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *pihp) 382bcmpax_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *pihp)
381{ 383{
382 return EINVAL; 384 return EINVAL;
383} 385}
384 386
385static const char * 387static const char *
386bcmpax_intr_string(void *v, pci_intr_handle_t pih) 388bcmpax_intr_string(void *v, pci_intr_handle_t pih)
387{ 389{
388 return NULL; 390 return NULL;
389} 391}
390 392
391static const struct evcnt * 393static const struct evcnt *
392bcmpax_intr_evcnt(void *v, pci_intr_handle_t pih) 394bcmpax_intr_evcnt(void *v, pci_intr_handle_t pih)
393{ 395{
394 return NULL; 396 return NULL;
395} 397}
396 398
397static void * 399static void *
398bcmpax_intr_establish(void *v, pci_intr_handle_t pih, int ipl, 400bcmpax_intr_establish(void *v, pci_intr_handle_t pih, int ipl,
399 int (*func)(void *), void *arg) 401 int (*func)(void *), void *arg)
400{ 402{
401 return NULL; 403 return NULL;
402} 404}
403 405
404static void 406static void
405bcmpax_intr_disestablish(void *v, void *ih) 407bcmpax_intr_disestablish(void *v, void *ih)
406{ 408{
407} 409}