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