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