admpci.c revision 1.1.8.2 1 1.1.8.2 ad /* $NetBSD: admpci.c,v 1.1.8.2 2007/06/09 21:36:53 ad Exp $ */
2 1.1.8.2 ad
3 1.1.8.2 ad /*-
4 1.1.8.2 ad * Copyright (c) 2007 David Young. All rights reserved.
5 1.1.8.2 ad *
6 1.1.8.2 ad * Redistribution and use in source and binary forms, with or
7 1.1.8.2 ad * without modification, are permitted provided that the following
8 1.1.8.2 ad * conditions are met:
9 1.1.8.2 ad * 1. Redistributions of source code must retain the above copyright
10 1.1.8.2 ad * notice, this list of conditions and the following disclaimer.
11 1.1.8.2 ad * 2. Redistributions in binary form must reproduce the above
12 1.1.8.2 ad * copyright notice, this list of conditions and the following
13 1.1.8.2 ad * disclaimer in the documentation and/or other materials provided
14 1.1.8.2 ad * with the distribution.
15 1.1.8.2 ad * 3. The name of the author may not be used to endorse or promote
16 1.1.8.2 ad * products derived from this software without specific prior
17 1.1.8.2 ad * written permission.
18 1.1.8.2 ad *
19 1.1.8.2 ad * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
20 1.1.8.2 ad * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 1.1.8.2 ad * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22 1.1.8.2 ad * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
23 1.1.8.2 ad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24 1.1.8.2 ad * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 1.1.8.2 ad * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
26 1.1.8.2 ad * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 1.1.8.2 ad * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
28 1.1.8.2 ad * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29 1.1.8.2 ad * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30 1.1.8.2 ad * OF SUCH DAMAGE.
31 1.1.8.2 ad */
32 1.1.8.2 ad /*-
33 1.1.8.2 ad * Copyright (c) 2006 Itronix Inc.
34 1.1.8.2 ad * All rights reserved.
35 1.1.8.2 ad *
36 1.1.8.2 ad * Written by Garrett D'Amore for Itronix Inc.
37 1.1.8.2 ad *
38 1.1.8.2 ad * Redistribution and use in source and binary forms, with or without
39 1.1.8.2 ad * modification, are permitted provided that the following conditions
40 1.1.8.2 ad * are met:
41 1.1.8.2 ad * 1. Redistributions of source code must retain the above copyright
42 1.1.8.2 ad * notice, this list of conditions and the following disclaimer.
43 1.1.8.2 ad * 2. Redistributions in binary form must reproduce the above copyright
44 1.1.8.2 ad * notice, this list of conditions and the following disclaimer in the
45 1.1.8.2 ad * documentation and/or other materials provided with the distribution.
46 1.1.8.2 ad * 3. The name of Itronix Inc. may not be used to endorse
47 1.1.8.2 ad * or promote products derived from this software without specific
48 1.1.8.2 ad * prior written permission.
49 1.1.8.2 ad *
50 1.1.8.2 ad * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND
51 1.1.8.2 ad * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
52 1.1.8.2 ad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
53 1.1.8.2 ad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
54 1.1.8.2 ad * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
55 1.1.8.2 ad * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
56 1.1.8.2 ad * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
57 1.1.8.2 ad * ON ANY THEORY OF LIABILITY, WHETHER IN
58 1.1.8.2 ad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
59 1.1.8.2 ad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
60 1.1.8.2 ad * POSSIBILITY OF SUCH DAMAGE.
61 1.1.8.2 ad */
62 1.1.8.2 ad
63 1.1.8.2 ad #include "opt_pci.h"
64 1.1.8.2 ad #include "pci.h"
65 1.1.8.2 ad
66 1.1.8.2 ad #include <sys/cdefs.h>
67 1.1.8.2 ad __KERNEL_RCSID(0, "$NetBSD: admpci.c,v 1.1.8.2 2007/06/09 21:36:53 ad Exp $");
68 1.1.8.2 ad
69 1.1.8.2 ad #include <sys/types.h>
70 1.1.8.2 ad #include <sys/param.h>
71 1.1.8.2 ad #include <sys/time.h>
72 1.1.8.2 ad #include <sys/systm.h>
73 1.1.8.2 ad #include <sys/errno.h>
74 1.1.8.2 ad #include <sys/device.h>
75 1.1.8.2 ad #include <sys/malloc.h>
76 1.1.8.2 ad #include <sys/extent.h>
77 1.1.8.2 ad
78 1.1.8.2 ad #include <uvm/uvm_extern.h>
79 1.1.8.2 ad
80 1.1.8.2 ad #include <machine/bus.h>
81 1.1.8.2 ad #include <machine/cpu.h>
82 1.1.8.2 ad #include <machine/pte.h>
83 1.1.8.2 ad
84 1.1.8.2 ad #include <dev/pci/pcivar.h>
85 1.1.8.2 ad #include <dev/pci/pcireg.h>
86 1.1.8.2 ad #include <dev/pci/pciconf.h>
87 1.1.8.2 ad
88 1.1.8.2 ad #ifdef PCI_NETBSD_CONFIGURE
89 1.1.8.2 ad #include <mips/cache.h>
90 1.1.8.2 ad #endif
91 1.1.8.2 ad
92 1.1.8.2 ad #include <mips/adm5120/include/adm5120_mainbusvar.h>
93 1.1.8.2 ad #include <mips/adm5120/include/adm5120reg.h>
94 1.1.8.2 ad #include <mips/adm5120/include/adm5120var.h>
95 1.1.8.2 ad
96 1.1.8.2 ad #ifdef ADMPCI_DEBUG
97 1.1.8.2 ad int admpci_debug = 1;
98 1.1.8.2 ad #define ADMPCI_DPRINTF(__fmt, ...) \
99 1.1.8.2 ad do { \
100 1.1.8.2 ad if (admpci_debug) \
101 1.1.8.2 ad printf((__fmt), __VA_ARGS__); \
102 1.1.8.2 ad } while (/*CONSTCOND*/0)
103 1.1.8.2 ad #else /* !ADMPCI_DEBUG */
104 1.1.8.2 ad #define ADMPCI_DPRINTF(__fmt, ...) do { } while (/*CONSTCOND*/0)
105 1.1.8.2 ad #endif /* ADMPCI_DEBUG */
106 1.1.8.2 ad
107 1.1.8.2 ad #define ADMPCI_TAG_BUS_MASK __BITS(23, 16)
108 1.1.8.2 ad /* Bit 11 is reserved. It selects the AHB-PCI bridge. Let device 0
109 1.1.8.2 ad * be the bridge. For all other device numbers, let bit[11] == 0.
110 1.1.8.2 ad */
111 1.1.8.2 ad #define ADMPCI_TAG_DEVICE_MASK __BITS(15, 11)
112 1.1.8.2 ad #define ADMPCI_TAG_DEVICE_SUBMASK __BITS(15, 12)
113 1.1.8.2 ad #define ADMPCI_TAG_DEVICE_BRIDGE __BIT(11)
114 1.1.8.2 ad #define ADMPCI_TAG_FUNCTION_MASK __BITS(10, 8)
115 1.1.8.2 ad #define ADMPCI_TAG_REGISTER_MASK __BITS(7, 0)
116 1.1.8.2 ad
117 1.1.8.2 ad #define ADMPCI_MAX_DEVICE
118 1.1.8.2 ad
119 1.1.8.2 ad struct admpci_softc {
120 1.1.8.2 ad struct device sc_dev;
121 1.1.8.2 ad struct mips_pci_chipset sc_pc;
122 1.1.8.2 ad
123 1.1.8.2 ad bus_space_tag_t sc_memt;
124 1.1.8.2 ad bus_space_tag_t sc_iot;
125 1.1.8.2 ad
126 1.1.8.2 ad bus_space_tag_t sc_conft;
127 1.1.8.2 ad bus_space_handle_t sc_addrh;
128 1.1.8.2 ad bus_space_handle_t sc_datah;
129 1.1.8.2 ad };
130 1.1.8.2 ad
131 1.1.8.2 ad int admpcimatch(struct device *, struct cfdata *, void *);
132 1.1.8.2 ad void admpciattach(struct device *, struct device *, void *);
133 1.1.8.2 ad
134 1.1.8.2 ad #if NPCI > 0
135 1.1.8.2 ad static void admpci_attach_hook(struct device *, struct device *,
136 1.1.8.2 ad struct pcibus_attach_args *);
137 1.1.8.2 ad static int admpci_bus_maxdevs(void *, int);
138 1.1.8.2 ad static pcitag_t admpci_make_tag(void *, int, int, int);
139 1.1.8.2 ad static void admpci_decompose_tag(void *, pcitag_t, int *, int *, int *);
140 1.1.8.2 ad static pcireg_t admpci_conf_read(void *, pcitag_t, int);
141 1.1.8.2 ad static void admpci_conf_write(void *, pcitag_t, int, pcireg_t);
142 1.1.8.2 ad static const char *admpci_intr_string(void *, pci_intr_handle_t);
143 1.1.8.2 ad static void admpci_conf_interrupt(void *, int, int, int, int, int *);
144 1.1.8.2 ad static void *admpci_intr_establish(void *, pci_intr_handle_t, int,
145 1.1.8.2 ad int (*)(void *), void *);
146 1.1.8.2 ad static void admpci_intr_disestablish(void *, void *);
147 1.1.8.2 ad static int admpci_intr_map(struct pci_attach_args *, pci_intr_handle_t *);
148 1.1.8.2 ad
149 1.1.8.2 ad #ifdef PCI_NETBSD_CONFIGURE
150 1.1.8.2 ad static struct extent *io_ex = NULL;
151 1.1.8.2 ad static struct extent *mem_ex = NULL;
152 1.1.8.2 ad #endif /* PCI_NETBSD_CONFIGURE */
153 1.1.8.2 ad
154 1.1.8.2 ad #endif /* NPCI > 0 */
155 1.1.8.2 ad
156 1.1.8.2 ad CFATTACH_DECL(admpci, sizeof(struct admpci_softc),
157 1.1.8.2 ad admpcimatch, admpciattach, NULL, NULL);
158 1.1.8.2 ad
159 1.1.8.2 ad int admpci_found = 0;
160 1.1.8.2 ad
161 1.1.8.2 ad /*
162 1.1.8.2 ad * Physical PCI addresses are 36-bits long, so we need to have
163 1.1.8.2 ad * adequate storage space for them.
164 1.1.8.2 ad */
165 1.1.8.2 ad #if NPCI > 0
166 1.1.8.2 ad #if !defined(_MIPS_PADDR_T_64BIT) && !defined(_LP64)
167 1.1.8.2 ad #error "admpci requires 64 bit paddr_t!"
168 1.1.8.2 ad #endif
169 1.1.8.2 ad #endif
170 1.1.8.2 ad
171 1.1.8.2 ad int
172 1.1.8.2 ad admpcimatch(struct device *parent, struct cfdata *match, void *aux)
173 1.1.8.2 ad {
174 1.1.8.2 ad struct mainbus_attach_args *ma = (struct mainbus_attach_args *)aux;
175 1.1.8.2 ad
176 1.1.8.2 ad return !admpci_found && strcmp(ma->ma_name, "admpci") == 0;
177 1.1.8.2 ad }
178 1.1.8.2 ad
179 1.1.8.2 ad void
180 1.1.8.2 ad admpciattach(struct device *parent, struct device *self, void *aux)
181 1.1.8.2 ad {
182 1.1.8.2 ad struct adm5120_config *admc = &adm5120_configuration;
183 1.1.8.2 ad struct admpci_softc *sc = (struct admpci_softc *)self;
184 1.1.8.2 ad struct mainbus_attach_args *ma = (struct mainbus_attach_args *)aux;
185 1.1.8.2 ad #if NPCI > 0
186 1.1.8.2 ad u_long result;
187 1.1.8.2 ad pcitag_t tag;
188 1.1.8.2 ad struct pcibus_attach_args pba;
189 1.1.8.2 ad #endif
190 1.1.8.2 ad
191 1.1.8.2 ad admpci_found = 1;
192 1.1.8.2 ad
193 1.1.8.2 ad sc->sc_conft = ma->ma_obiot;
194 1.1.8.2 ad if (bus_space_map(sc->sc_conft, ADM5120_BASE_PCI_CONFDATA, 4, 0,
195 1.1.8.2 ad &sc->sc_datah) != 0) {
196 1.1.8.2 ad printf(
197 1.1.8.2 ad "\n%s: unable to map PCI Configuration Data register\n",
198 1.1.8.2 ad device_xname(&sc->sc_dev));
199 1.1.8.2 ad return;
200 1.1.8.2 ad }
201 1.1.8.2 ad if (bus_space_map(sc->sc_conft, ADM5120_BASE_PCI_CONFADDR, 4, 0,
202 1.1.8.2 ad &sc->sc_addrh) != 0) {
203 1.1.8.2 ad printf(
204 1.1.8.2 ad "\n%s: unable to map PCI Configuration Address register\n",
205 1.1.8.2 ad device_xname(&sc->sc_dev));
206 1.1.8.2 ad return;
207 1.1.8.2 ad }
208 1.1.8.2 ad
209 1.1.8.2 ad printf(": ADM5120 Host-PCI Bridge, data %lx addr %lx, sc %p\n",
210 1.1.8.2 ad sc->sc_datah, sc->sc_addrh, (void *)sc);
211 1.1.8.2 ad
212 1.1.8.2 ad #if NPCI > 0
213 1.1.8.2 ad sc->sc_memt = &admc->pcimem_space;
214 1.1.8.2 ad sc->sc_iot = &admc->pciio_space;
215 1.1.8.2 ad
216 1.1.8.2 ad sc->sc_pc.pc_conf_v = sc;
217 1.1.8.2 ad sc->sc_pc.pc_attach_hook = admpci_attach_hook;
218 1.1.8.2 ad sc->sc_pc.pc_bus_maxdevs = admpci_bus_maxdevs;
219 1.1.8.2 ad sc->sc_pc.pc_make_tag = admpci_make_tag;
220 1.1.8.2 ad sc->sc_pc.pc_decompose_tag = admpci_decompose_tag;
221 1.1.8.2 ad sc->sc_pc.pc_conf_read = admpci_conf_read;
222 1.1.8.2 ad sc->sc_pc.pc_conf_write = admpci_conf_write;
223 1.1.8.2 ad
224 1.1.8.2 ad sc->sc_pc.pc_intr_v = sc;
225 1.1.8.2 ad sc->sc_pc.pc_intr_map = admpci_intr_map;
226 1.1.8.2 ad sc->sc_pc.pc_intr_string = admpci_intr_string;
227 1.1.8.2 ad sc->sc_pc.pc_intr_establish = admpci_intr_establish;
228 1.1.8.2 ad sc->sc_pc.pc_intr_disestablish = admpci_intr_disestablish;
229 1.1.8.2 ad sc->sc_pc.pc_conf_interrupt = admpci_conf_interrupt;
230 1.1.8.2 ad
231 1.1.8.2 ad tag = pci_make_tag(&sc->sc_pc, 0, 0, 0);
232 1.1.8.2 ad ADMPCI_DPRINTF("%s: BAR 0x10 0x%08x\n", __func__,
233 1.1.8.2 ad pci_conf_read(&sc->sc_pc, tag, PCI_MAPREG_START));
234 1.1.8.2 ad
235 1.1.8.2 ad #ifdef PCI_NETBSD_CONFIGURE
236 1.1.8.2 ad mem_ex = extent_create("pcimem",
237 1.1.8.2 ad ADM5120_BOTTOM, ADM5120_TOP,
238 1.1.8.2 ad M_DEVBUF, NULL, 0, EX_WAITOK);
239 1.1.8.2 ad (void)extent_alloc_subregion(mem_ex,
240 1.1.8.2 ad ADM5120_BASE_SRAM1, ADM5120_BASE_PCI_MEM - 1,
241 1.1.8.2 ad ADM5120_BASE_PCI_MEM - ADM5120_BASE_SRAM1,
242 1.1.8.2 ad ADM5120_BASE_PCI_MEM - ADM5120_BASE_SRAM1,
243 1.1.8.2 ad 0, EX_WAITOK, &result);
244 1.1.8.2 ad (void)extent_alloc_subregion(mem_ex,
245 1.1.8.2 ad ADM5120_BASE_PCI_IO, ADM5120_TOP,
246 1.1.8.2 ad ADM5120_TOP - ADM5120_BASE_PCI_IO + 1,
247 1.1.8.2 ad ADM5120_TOP - ADM5120_BASE_PCI_IO + 1,
248 1.1.8.2 ad 0, EX_WAITOK, &result);
249 1.1.8.2 ad
250 1.1.8.2 ad io_ex = extent_create("pciio",
251 1.1.8.2 ad ADM5120_BASE_PCI_IO, ADM5120_BASE_PCI_CONFADDR - 1,
252 1.1.8.2 ad M_DEVBUF, NULL, 0, EX_WAITOK);
253 1.1.8.2 ad
254 1.1.8.2 ad pci_configure_bus(&sc->sc_pc,
255 1.1.8.2 ad io_ex, mem_ex, NULL, 0, mips_dcache_align);
256 1.1.8.2 ad extent_destroy(mem_ex);
257 1.1.8.2 ad extent_destroy(io_ex);
258 1.1.8.2 ad #endif
259 1.1.8.2 ad
260 1.1.8.2 ad pba.pba_iot = sc->sc_iot;
261 1.1.8.2 ad pba.pba_memt = sc->sc_memt;
262 1.1.8.2 ad /* XXX: review dma tag logic */
263 1.1.8.2 ad pba.pba_dmat = ma->ma_dmat;
264 1.1.8.2 ad pba.pba_dmat64 = NULL;
265 1.1.8.2 ad pba.pba_pc = &sc->sc_pc;
266 1.1.8.2 ad pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
267 1.1.8.2 ad pba.pba_bus = 0;
268 1.1.8.2 ad pba.pba_bridgetag = NULL;
269 1.1.8.2 ad
270 1.1.8.2 ad config_found_ia(self, "pcibus", &pba, pcibusprint);
271 1.1.8.2 ad #endif /* NPCI > 0 */
272 1.1.8.2 ad }
273 1.1.8.2 ad
274 1.1.8.2 ad #if NPCI > 0
275 1.1.8.2 ad
276 1.1.8.2 ad void
277 1.1.8.2 ad admpci_attach_hook(struct device *parent, struct device *self,
278 1.1.8.2 ad struct pcibus_attach_args *pba)
279 1.1.8.2 ad {
280 1.1.8.2 ad }
281 1.1.8.2 ad
282 1.1.8.2 ad /* There are at most four devices on bus 0. The ADM5120 has
283 1.1.8.2 ad * request/grant lines for 3 PCI devices: 1, 2, and 3. The host
284 1.1.8.2 ad * bridge is device 0.
285 1.1.8.2 ad */
286 1.1.8.2 ad int
287 1.1.8.2 ad admpci_bus_maxdevs(void *v, int bus)
288 1.1.8.2 ad {
289 1.1.8.2 ad if (bus == 0)
290 1.1.8.2 ad return 4;
291 1.1.8.2 ad
292 1.1.8.2 ad return 1 + __SHIFTOUT_MASK(ADMPCI_TAG_DEVICE_MASK);
293 1.1.8.2 ad }
294 1.1.8.2 ad
295 1.1.8.2 ad pcitag_t
296 1.1.8.2 ad admpci_make_tag(void *v, int bus, int device, int function)
297 1.1.8.2 ad {
298 1.1.8.2 ad if (bus > __SHIFTOUT_MASK(ADMPCI_TAG_BUS_MASK) ||
299 1.1.8.2 ad device > __SHIFTOUT_MASK(ADMPCI_TAG_DEVICE_MASK) ||
300 1.1.8.2 ad function > __SHIFTOUT_MASK(ADMPCI_TAG_FUNCTION_MASK))
301 1.1.8.2 ad panic("%s: bad request", __func__);
302 1.1.8.2 ad
303 1.1.8.2 ad return __SHIFTIN(bus, ADMPCI_TAG_BUS_MASK) |
304 1.1.8.2 ad __SHIFTIN(device, ADMPCI_TAG_DEVICE_MASK) |
305 1.1.8.2 ad __SHIFTIN(function, ADMPCI_TAG_FUNCTION_MASK);
306 1.1.8.2 ad }
307 1.1.8.2 ad
308 1.1.8.2 ad void
309 1.1.8.2 ad admpci_decompose_tag(void *v, pcitag_t tag, int *b, int *d, int *f)
310 1.1.8.2 ad {
311 1.1.8.2 ad int bus, device, function;
312 1.1.8.2 ad
313 1.1.8.2 ad bus = __SHIFTOUT(tag, ADMPCI_TAG_BUS_MASK);
314 1.1.8.2 ad device = __SHIFTOUT(tag, ADMPCI_TAG_DEVICE_MASK);
315 1.1.8.2 ad function = __SHIFTOUT(tag, ADMPCI_TAG_FUNCTION_MASK);
316 1.1.8.2 ad
317 1.1.8.2 ad if (b != NULL)
318 1.1.8.2 ad *b = bus;
319 1.1.8.2 ad if (d != NULL)
320 1.1.8.2 ad *d = device;
321 1.1.8.2 ad if (f != NULL)
322 1.1.8.2 ad *f = function;
323 1.1.8.2 ad }
324 1.1.8.2 ad
325 1.1.8.2 ad static int
326 1.1.8.2 ad admpci_tag_to_addr(void *v, pcitag_t tag, int reg, bus_addr_t *addrp)
327 1.1.8.2 ad {
328 1.1.8.2 ad int bus, device, function;
329 1.1.8.2 ad
330 1.1.8.2 ad KASSERT(addrp != NULL);
331 1.1.8.2 ad /* panics if tag is not well-formed */
332 1.1.8.2 ad admpci_decompose_tag(v, tag, &bus, &device, &function);
333 1.1.8.2 ad if (reg > __SHIFTOUT_MASK(ADMPCI_TAG_REGISTER_MASK))
334 1.1.8.2 ad panic("%s: bad register", __func__);
335 1.1.8.2 ad
336 1.1.8.2 ad *addrp = 0x80000000 | tag | __SHIFTIN(reg, ADMPCI_TAG_REGISTER_MASK);
337 1.1.8.2 ad
338 1.1.8.2 ad return 0;
339 1.1.8.2 ad }
340 1.1.8.2 ad
341 1.1.8.2 ad static pcireg_t
342 1.1.8.2 ad admpci_conf_read(void *v, pcitag_t tag, int reg)
343 1.1.8.2 ad {
344 1.1.8.2 ad int s;
345 1.1.8.2 ad struct admpci_softc *sc = (struct admpci_softc *)v;
346 1.1.8.2 ad uint32_t data;
347 1.1.8.2 ad bus_addr_t addr;
348 1.1.8.2 ad
349 1.1.8.2 ad ADMPCI_DPRINTF("%s: sc %p tag %lx reg %d\n", __func__, (void *)sc, tag,
350 1.1.8.2 ad reg);
351 1.1.8.2 ad
352 1.1.8.2 ad if (admpci_tag_to_addr(v, tag, reg, &addr) == -1)
353 1.1.8.2 ad return 0xffffffff;
354 1.1.8.2 ad
355 1.1.8.2 ad ADMPCI_DPRINTF("%s: sc_addrh %lx sc_datah %lx addr %lx\n", __func__,
356 1.1.8.2 ad sc->sc_addrh, sc->sc_datah, addr);
357 1.1.8.2 ad
358 1.1.8.2 ad s = splhigh();
359 1.1.8.2 ad bus_space_write_4(sc->sc_conft, sc->sc_addrh, 0, addr);
360 1.1.8.2 ad data = bus_space_read_4(sc->sc_conft, sc->sc_datah, 0);
361 1.1.8.2 ad splx(s);
362 1.1.8.2 ad
363 1.1.8.2 ad ADMPCI_DPRINTF("%s: read 0x%" PRIx32 "\n", __func__, data);
364 1.1.8.2 ad return data;
365 1.1.8.2 ad }
366 1.1.8.2 ad
367 1.1.8.2 ad void
368 1.1.8.2 ad admpci_conf_write(void *v, pcitag_t tag, int reg, pcireg_t data)
369 1.1.8.2 ad {
370 1.1.8.2 ad int s;
371 1.1.8.2 ad struct admpci_softc *sc = (struct admpci_softc *)v;
372 1.1.8.2 ad bus_addr_t addr;
373 1.1.8.2 ad
374 1.1.8.2 ad ADMPCI_DPRINTF("%s: sc %p tag %lx reg %d\n", __func__, (void *)sc, tag,
375 1.1.8.2 ad reg);
376 1.1.8.2 ad
377 1.1.8.2 ad if (admpci_tag_to_addr(v, tag, reg, &addr) == -1)
378 1.1.8.2 ad return;
379 1.1.8.2 ad
380 1.1.8.2 ad ADMPCI_DPRINTF("%s: sc_addrh %lx sc_datah %lx addr %lx\n", __func__,
381 1.1.8.2 ad sc->sc_addrh, sc->sc_datah, addr);
382 1.1.8.2 ad
383 1.1.8.2 ad s = splhigh();
384 1.1.8.2 ad bus_space_write_4(sc->sc_conft, sc->sc_addrh, 0, addr);
385 1.1.8.2 ad bus_space_write_4(sc->sc_conft, sc->sc_datah, 0, data);
386 1.1.8.2 ad splx(s);
387 1.1.8.2 ad }
388 1.1.8.2 ad
389 1.1.8.2 ad const char *
390 1.1.8.2 ad admpci_intr_string(void *v, pci_intr_handle_t ih)
391 1.1.8.2 ad {
392 1.1.8.2 ad static char name[16];
393 1.1.8.2 ad
394 1.1.8.2 ad (void)snprintf(name, sizeof(name), "irq %u", (unsigned)ih);
395 1.1.8.2 ad return name;
396 1.1.8.2 ad }
397 1.1.8.2 ad
398 1.1.8.2 ad void *
399 1.1.8.2 ad admpci_intr_establish(void *v, pci_intr_handle_t ih, int ipl,
400 1.1.8.2 ad int (*handler)(void *), void *arg)
401 1.1.8.2 ad {
402 1.1.8.2 ad return adm5120_intr_establish(ih, ipl, handler, arg);
403 1.1.8.2 ad }
404 1.1.8.2 ad
405 1.1.8.2 ad void
406 1.1.8.2 ad admpci_intr_disestablish(void *v, void *cookie)
407 1.1.8.2 ad {
408 1.1.8.2 ad adm5120_intr_disestablish(cookie);
409 1.1.8.2 ad }
410 1.1.8.2 ad
411 1.1.8.2 ad void
412 1.1.8.2 ad admpci_conf_interrupt(void *v, int bus, int dev, int ipin, int swiz, int *iline)
413 1.1.8.2 ad {
414 1.1.8.2 ad /*
415 1.1.8.2 ad * We let the machdep_pci_intr_map take care of IRQ routing.
416 1.1.8.2 ad * On some platforms the BIOS may have handled this properly,
417 1.1.8.2 ad * on others it might not have. For now we avoid clobbering
418 1.1.8.2 ad * the settings establishsed by the BIOS, so that they will be
419 1.1.8.2 ad * there if the platform logic is confident that it can rely
420 1.1.8.2 ad * on them.
421 1.1.8.2 ad */
422 1.1.8.2 ad }
423 1.1.8.2 ad
424 1.1.8.2 ad /*
425 1.1.8.2 ad * Map the bus 0 device numbers 1, 2, and 3 to IRQ 6, 7, and 8,
426 1.1.8.2 ad * respectively.
427 1.1.8.2 ad *
428 1.1.8.2 ad * XXX How to handle bridges?
429 1.1.8.2 ad */
430 1.1.8.2 ad static int
431 1.1.8.2 ad admpci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
432 1.1.8.2 ad {
433 1.1.8.2 ad int bus, device, function;
434 1.1.8.2 ad
435 1.1.8.2 ad admpci_decompose_tag(pa->pa_pc->pc_conf_v, pa->pa_tag,
436 1.1.8.2 ad &bus, &device, &function);
437 1.1.8.2 ad
438 1.1.8.2 ad if (bus != 0 || device > 3)
439 1.1.8.2 ad return -1;
440 1.1.8.2 ad
441 1.1.8.2 ad *ihp = (device - 1) + 6;
442 1.1.8.2 ad
443 1.1.8.2 ad return 0;
444 1.1.8.2 ad }
445 1.1.8.2 ad #endif
446