aupci.c revision 1.5.20.2 1 1.5.20.2 rpaulo /* $NetBSD: aupci.c,v 1.5.20.2 2006/09/09 02:41:14 rpaulo Exp $ */
2 1.5.20.2 rpaulo
3 1.5.20.2 rpaulo /*-
4 1.5.20.2 rpaulo * Copyright (c) 2006 Itronix Inc.
5 1.5.20.2 rpaulo * All rights reserved.
6 1.5.20.2 rpaulo *
7 1.5.20.2 rpaulo * Written by Garrett D'Amore for Itronix Inc.
8 1.5.20.2 rpaulo *
9 1.5.20.2 rpaulo * Redistribution and use in source and binary forms, with or without
10 1.5.20.2 rpaulo * modification, are permitted provided that the following conditions
11 1.5.20.2 rpaulo * are met:
12 1.5.20.2 rpaulo * 1. Redistributions of source code must retain the above copyright
13 1.5.20.2 rpaulo * notice, this list of conditions and the following disclaimer.
14 1.5.20.2 rpaulo * 2. Redistributions in binary form must reproduce the above copyright
15 1.5.20.2 rpaulo * notice, this list of conditions and the following disclaimer in the
16 1.5.20.2 rpaulo * documentation and/or other materials provided with the distribution.
17 1.5.20.2 rpaulo * 3. The name of Itronix Inc. may not be used to endorse
18 1.5.20.2 rpaulo * or promote products derived from this software without specific
19 1.5.20.2 rpaulo * prior written permission.
20 1.5.20.2 rpaulo *
21 1.5.20.2 rpaulo * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND
22 1.5.20.2 rpaulo * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 1.5.20.2 rpaulo * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 1.5.20.2 rpaulo * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
25 1.5.20.2 rpaulo * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 1.5.20.2 rpaulo * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 1.5.20.2 rpaulo * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 1.5.20.2 rpaulo * ON ANY THEORY OF LIABILITY, WHETHER IN
29 1.5.20.2 rpaulo * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 1.5.20.2 rpaulo * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 1.5.20.2 rpaulo * POSSIBILITY OF SUCH DAMAGE.
32 1.5.20.2 rpaulo */
33 1.5.20.2 rpaulo
34 1.5.20.2 rpaulo #include "opt_pci.h"
35 1.5.20.2 rpaulo #include "pci.h"
36 1.5.20.2 rpaulo
37 1.5.20.2 rpaulo #include <sys/cdefs.h>
38 1.5.20.2 rpaulo __KERNEL_RCSID(0, "$NetBSD: aupci.c,v 1.5.20.2 2006/09/09 02:41:14 rpaulo Exp $");
39 1.5.20.2 rpaulo
40 1.5.20.2 rpaulo #include <sys/types.h>
41 1.5.20.2 rpaulo #include <sys/param.h>
42 1.5.20.2 rpaulo #include <sys/time.h>
43 1.5.20.2 rpaulo #include <sys/systm.h>
44 1.5.20.2 rpaulo #include <sys/errno.h>
45 1.5.20.2 rpaulo #include <sys/device.h>
46 1.5.20.2 rpaulo #include <sys/malloc.h>
47 1.5.20.2 rpaulo #include <sys/extent.h>
48 1.5.20.2 rpaulo
49 1.5.20.2 rpaulo #include <uvm/uvm_extern.h>
50 1.5.20.2 rpaulo
51 1.5.20.2 rpaulo #include <machine/bus.h>
52 1.5.20.2 rpaulo #include <machine/cpu.h>
53 1.5.20.2 rpaulo #include <machine/pte.h>
54 1.5.20.2 rpaulo
55 1.5.20.2 rpaulo #include <dev/pci/pcivar.h>
56 1.5.20.2 rpaulo #include <dev/pci/pcireg.h>
57 1.5.20.2 rpaulo #include <dev/pci/pciconf.h>
58 1.5.20.2 rpaulo
59 1.5.20.2 rpaulo #ifdef PCI_NETBSD_CONFIGURE
60 1.5.20.2 rpaulo #include <mips/cache.h>
61 1.5.20.2 rpaulo #endif
62 1.5.20.2 rpaulo
63 1.5.20.2 rpaulo #include <mips/alchemy/include/au_himem_space.h>
64 1.5.20.2 rpaulo #include <mips/alchemy/include/aubusvar.h>
65 1.5.20.2 rpaulo #include <mips/alchemy/include/aureg.h>
66 1.5.20.2 rpaulo #include <mips/alchemy/include/auvar.h>
67 1.5.20.2 rpaulo
68 1.5.20.2 rpaulo #include <mips/alchemy/dev/aupcireg.h>
69 1.5.20.2 rpaulo #include <mips/alchemy/dev/aupcivar.h>
70 1.5.20.2 rpaulo
71 1.5.20.2 rpaulo struct aupci_softc {
72 1.5.20.2 rpaulo struct device sc_dev;
73 1.5.20.2 rpaulo struct mips_pci_chipset sc_pc;
74 1.5.20.2 rpaulo struct mips_bus_space sc_mem_space;
75 1.5.20.2 rpaulo struct mips_bus_space sc_io_space;
76 1.5.20.2 rpaulo struct mips_bus_space sc_cfg_space;
77 1.5.20.2 rpaulo
78 1.5.20.2 rpaulo bus_space_tag_t sc_memt;
79 1.5.20.2 rpaulo bus_space_tag_t sc_iot;
80 1.5.20.2 rpaulo bus_space_tag_t sc_cfgt;
81 1.5.20.2 rpaulo
82 1.5.20.2 rpaulo bus_space_tag_t sc_bust;
83 1.5.20.2 rpaulo
84 1.5.20.2 rpaulo bus_space_handle_t sc_bush;
85 1.5.20.2 rpaulo paddr_t sc_cfgbase;
86 1.5.20.2 rpaulo paddr_t sc_membase;
87 1.5.20.2 rpaulo paddr_t sc_iobase;
88 1.5.20.2 rpaulo
89 1.5.20.2 rpaulo /* XXX: dma tag */
90 1.5.20.2 rpaulo };
91 1.5.20.2 rpaulo
92 1.5.20.2 rpaulo int aupcimatch(struct device *, struct cfdata *, void *);
93 1.5.20.2 rpaulo void aupciattach(struct device *, struct device *, void *);
94 1.5.20.2 rpaulo
95 1.5.20.2 rpaulo #if NPCI > 0
96 1.5.20.2 rpaulo static void aupci_attach_hook(struct device *, struct device *,
97 1.5.20.2 rpaulo struct pcibus_attach_args *);
98 1.5.20.2 rpaulo static int aupci_bus_maxdevs(void *, int);
99 1.5.20.2 rpaulo static pcitag_t aupci_make_tag(void *, int, int, int);
100 1.5.20.2 rpaulo static void aupci_decompose_tag(void *, pcitag_t, int *, int *, int *);
101 1.5.20.2 rpaulo static pcireg_t aupci_conf_read(void *, pcitag_t, int);
102 1.5.20.2 rpaulo static void aupci_conf_write(void *, pcitag_t, int, pcireg_t);
103 1.5.20.2 rpaulo static const char *aupci_intr_string(void *, pci_intr_handle_t);
104 1.5.20.2 rpaulo static void aupci_conf_interrupt(void *, int, int, int, int, int *);
105 1.5.20.2 rpaulo static void *aupci_intr_establish(void *, pci_intr_handle_t, int,
106 1.5.20.2 rpaulo int (*)(void *), void *);
107 1.5.20.2 rpaulo static void aupci_intr_disestablish(void *, void *);
108 1.5.20.2 rpaulo
109 1.5.20.2 rpaulo #ifdef PCI_NETBSD_CONFIGURE
110 1.5.20.2 rpaulo static struct extent *io_ex = NULL;
111 1.5.20.2 rpaulo static struct extent *mem_ex = NULL;
112 1.5.20.2 rpaulo #endif /* PCI_NETBSD_CONFIGURE */
113 1.5.20.2 rpaulo
114 1.5.20.2 rpaulo #define PCI_CFG_READ 0
115 1.5.20.2 rpaulo #define PCI_CFG_WRITE 1
116 1.5.20.2 rpaulo
117 1.5.20.2 rpaulo #endif /* NPCI > 0 */
118 1.5.20.2 rpaulo
119 1.5.20.2 rpaulo CFATTACH_DECL(aupci, sizeof(struct aupci_softc),
120 1.5.20.2 rpaulo aupcimatch, aupciattach, NULL, NULL);
121 1.5.20.2 rpaulo
122 1.5.20.2 rpaulo int aupci_found = 0;
123 1.5.20.2 rpaulo
124 1.5.20.2 rpaulo /*
125 1.5.20.2 rpaulo * Physical PCI addresses are 36-bits long, so we need to have
126 1.5.20.2 rpaulo * adequate storage space for them.
127 1.5.20.2 rpaulo */
128 1.5.20.2 rpaulo #if NPCI > 0
129 1.5.20.2 rpaulo #if !defined(_MIPS_PADDR_T_64BIT) && !defined(_LP64)
130 1.5.20.2 rpaulo #error "aupci requires 64 bit paddr_t!"
131 1.5.20.2 rpaulo #endif
132 1.5.20.2 rpaulo #endif
133 1.5.20.2 rpaulo
134 1.5.20.2 rpaulo int
135 1.5.20.2 rpaulo aupcimatch(struct device *parent, struct cfdata *match, void *aux)
136 1.5.20.2 rpaulo {
137 1.5.20.2 rpaulo struct aubus_attach_args *aa = (struct aubus_attach_args *)aux;
138 1.5.20.2 rpaulo
139 1.5.20.2 rpaulo if (strcmp(aa->aa_name, "aupci") != 0)
140 1.5.20.2 rpaulo return 0;
141 1.5.20.2 rpaulo
142 1.5.20.2 rpaulo if (aupci_found)
143 1.5.20.2 rpaulo return 0;
144 1.5.20.2 rpaulo
145 1.5.20.2 rpaulo return 1;
146 1.5.20.2 rpaulo }
147 1.5.20.2 rpaulo
148 1.5.20.2 rpaulo void
149 1.5.20.2 rpaulo aupciattach(struct device *parent, struct device *self, void *aux)
150 1.5.20.2 rpaulo {
151 1.5.20.2 rpaulo struct aupci_softc *sc = (struct aupci_softc *)self;
152 1.5.20.2 rpaulo struct aubus_attach_args *aa = (struct aubus_attach_args *)aux;
153 1.5.20.2 rpaulo uint32_t cfg;
154 1.5.20.2 rpaulo #if NPCI > 0
155 1.5.20.2 rpaulo uint32_t mbar, mask;
156 1.5.20.2 rpaulo bus_addr_t mstart;
157 1.5.20.2 rpaulo struct pcibus_attach_args pba;
158 1.5.20.2 rpaulo #endif
159 1.5.20.2 rpaulo
160 1.5.20.2 rpaulo aupci_found = 1;
161 1.5.20.2 rpaulo
162 1.5.20.2 rpaulo sc->sc_bust = aa->aa_st;
163 1.5.20.2 rpaulo if (bus_space_map(sc->sc_bust, aa->aa_addrs[0], 512, 0,
164 1.5.20.2 rpaulo &sc->sc_bush) != 0) {
165 1.5.20.2 rpaulo printf("\n%s: unable to map PCI registers\n",
166 1.5.20.2 rpaulo sc->sc_dev.dv_xname);
167 1.5.20.2 rpaulo return;
168 1.5.20.2 rpaulo }
169 1.5.20.2 rpaulo
170 1.5.20.2 rpaulo #if NPCI > 0
171 1.5.20.2 rpaulo /*
172 1.5.20.2 rpaulo * These physical addresses are locked in on the CPUs we have
173 1.5.20.2 rpaulo * seen. Perhaps these should be passed in via locators, thru
174 1.5.20.2 rpaulo * the configuration file.
175 1.5.20.2 rpaulo */
176 1.5.20.2 rpaulo sc->sc_cfgbase = PCI_CONFIG_BASE;
177 1.5.20.2 rpaulo sc->sc_membase = PCI_MEM_BASE;
178 1.5.20.2 rpaulo sc->sc_iobase = PCI_IO_BASE;
179 1.5.20.2 rpaulo #endif
180 1.5.20.2 rpaulo
181 1.5.20.2 rpaulo /*
182 1.5.20.2 rpaulo * Configure byte swapping, as YAMON doesn't do it. YAMON does take
183 1.5.20.2 rpaulo * care of most of the rest of the details (clocking, etc.), however.
184 1.5.20.2 rpaulo */
185 1.5.20.2 rpaulo #if _BYTE_ORDER == _BIG_ENDIAN
186 1.5.20.2 rpaulo /*
187 1.5.20.2 rpaulo * N.B.: This still doesn't do the DMA thing properly. I have
188 1.5.20.2 rpaulo * not yet figured out how to get DMA access to work properly
189 1.5.20.2 rpaulo * without having bytes swapped while the processor is in
190 1.5.20.2 rpaulo * big-endian mode. I'm not even sure that the Alchemy part
191 1.5.20.2 rpaulo * can do it without swapping the bytes (which would be a
192 1.5.20.2 rpaulo * bummer, since then only parts which had hardware detection
193 1.5.20.2 rpaulo * and swapping support would work without special hacks in
194 1.5.20.2 rpaulo * their drivers.)
195 1.5.20.2 rpaulo */
196 1.5.20.2 rpaulo cfg = AUPCI_CONFIG_CH | AUPCI_CONFIG_R1H |
197 1.5.20.2 rpaulo AUPCI_CONFIG_R2H | AUPCI_CONFIG_AEN |
198 1.5.20.2 rpaulo AUPCI_CONFIG_SM | AUPCI_CONFIG_ST | AUPCI_CONFIG_SIC_DATA;
199 1.5.20.2 rpaulo #else
200 1.5.20.2 rpaulo cfg = AUPCI_CONFIG_CH | AUPCI_CONFIG_R1H |
201 1.5.20.2 rpaulo AUPCI_CONFIG_R2H | AUPCI_CONFIG_AEN;
202 1.5.20.2 rpaulo #endif
203 1.5.20.2 rpaulo bus_space_write_4(sc->sc_bust, sc->sc_bush, AUPCI_CONFIG, cfg);
204 1.5.20.2 rpaulo
205 1.5.20.2 rpaulo cfg = bus_space_read_4(sc->sc_bust, sc->sc_bush, AUPCI_COMMAND_STATUS);
206 1.5.20.2 rpaulo
207 1.5.20.2 rpaulo printf(": Alchemy Host-PCI Bridge");
208 1.5.20.2 rpaulo if (cfg & PCI_STATUS_66MHZ_SUPPORT)
209 1.5.20.2 rpaulo printf(", 66MHz");
210 1.5.20.2 rpaulo else
211 1.5.20.2 rpaulo printf(", 33MHz");
212 1.5.20.2 rpaulo
213 1.5.20.2 rpaulo printf("\n");
214 1.5.20.2 rpaulo
215 1.5.20.2 rpaulo #if NPCI > 0
216 1.5.20.2 rpaulo /*
217 1.5.20.2 rpaulo * PCI configuration space. Address in this bus are
218 1.5.20.2 rpaulo * orthogonal to other spaces. We need to make the entire
219 1.5.20.2 rpaulo * 32-bit address space available.
220 1.5.20.2 rpaulo */
221 1.5.20.2 rpaulo sc->sc_cfgt = &sc->sc_cfg_space;
222 1.5.20.2 rpaulo au_himem_space_init(sc->sc_cfgt, "pcicfg", sc->sc_cfgbase,
223 1.5.20.2 rpaulo 0x00000000, 0xffffffff, AU_HIMEM_SPACE_IO);
224 1.5.20.2 rpaulo
225 1.5.20.2 rpaulo /*
226 1.5.20.2 rpaulo * Virtual PCI memory. Configured so that we don't overlap
227 1.5.20.2 rpaulo * with PCI memory space.
228 1.5.20.2 rpaulo */
229 1.5.20.2 rpaulo mask = bus_space_read_4(sc->sc_bust, sc->sc_bush, AUPCI_MWMASK);
230 1.5.20.2 rpaulo mask >>= AUPCI_MWMASK_SHIFT;
231 1.5.20.2 rpaulo mask <<= AUPCI_MWMASK_SHIFT;
232 1.5.20.2 rpaulo
233 1.5.20.2 rpaulo mbar = bus_space_read_4(sc->sc_bust, sc->sc_bush, AUPCI_MBAR);
234 1.5.20.2 rpaulo mstart = (mbar & mask) + (~mask + 1);
235 1.5.20.2 rpaulo
236 1.5.20.2 rpaulo sc->sc_memt = &sc->sc_mem_space;
237 1.5.20.2 rpaulo au_himem_space_init(sc->sc_memt, "pcimem", sc->sc_membase,
238 1.5.20.2 rpaulo mstart, 0xffffffff, AU_HIMEM_SPACE_LITTLE_ENDIAN);
239 1.5.20.2 rpaulo
240 1.5.20.2 rpaulo /*
241 1.5.20.2 rpaulo * IO space. Address in this bus are orthogonal to other spaces.
242 1.5.20.2 rpaulo * 16 MB should be plenty. We don't start from zero to avoid
243 1.5.20.2 rpaulo * potential device bugs.
244 1.5.20.2 rpaulo */
245 1.5.20.2 rpaulo sc->sc_iot = &sc->sc_io_space;
246 1.5.20.2 rpaulo au_himem_space_init(sc->sc_iot, "pciio",
247 1.5.20.2 rpaulo sc->sc_iobase, AUPCI_IO_START, AUPCI_IO_END,
248 1.5.20.2 rpaulo AU_HIMEM_SPACE_LITTLE_ENDIAN | AU_HIMEM_SPACE_IO);
249 1.5.20.2 rpaulo
250 1.5.20.2 rpaulo sc->sc_pc.pc_conf_v = sc;
251 1.5.20.2 rpaulo sc->sc_pc.pc_attach_hook = aupci_attach_hook;
252 1.5.20.2 rpaulo sc->sc_pc.pc_bus_maxdevs = aupci_bus_maxdevs;
253 1.5.20.2 rpaulo sc->sc_pc.pc_make_tag = aupci_make_tag;
254 1.5.20.2 rpaulo sc->sc_pc.pc_decompose_tag = aupci_decompose_tag;
255 1.5.20.2 rpaulo sc->sc_pc.pc_conf_read = aupci_conf_read;
256 1.5.20.2 rpaulo sc->sc_pc.pc_conf_write = aupci_conf_write;
257 1.5.20.2 rpaulo
258 1.5.20.2 rpaulo sc->sc_pc.pc_intr_v = sc;
259 1.5.20.2 rpaulo sc->sc_pc.pc_intr_map = aupci_intr_map;
260 1.5.20.2 rpaulo sc->sc_pc.pc_intr_string = aupci_intr_string;
261 1.5.20.2 rpaulo sc->sc_pc.pc_intr_establish = aupci_intr_establish;
262 1.5.20.2 rpaulo sc->sc_pc.pc_intr_disestablish = aupci_intr_disestablish;
263 1.5.20.2 rpaulo sc->sc_pc.pc_conf_interrupt = aupci_conf_interrupt;
264 1.5.20.2 rpaulo
265 1.5.20.2 rpaulo #ifdef PCI_NETBSD_CONFIGURE
266 1.5.20.2 rpaulo mem_ex = extent_create("pcimem", mstart, 0xffffffff,
267 1.5.20.2 rpaulo M_DEVBUF, NULL, 0, EX_WAITOK);
268 1.5.20.2 rpaulo
269 1.5.20.2 rpaulo io_ex = extent_create("pciio", AUPCI_IO_START, AUPCI_IO_END,
270 1.5.20.2 rpaulo M_DEVBUF, NULL, 0, EX_WAITOK);
271 1.5.20.2 rpaulo
272 1.5.20.2 rpaulo pci_configure_bus(&sc->sc_pc,
273 1.5.20.2 rpaulo io_ex, mem_ex, NULL, 0, mips_dcache_align);
274 1.5.20.2 rpaulo extent_destroy(mem_ex);
275 1.5.20.2 rpaulo extent_destroy(io_ex);
276 1.5.20.2 rpaulo #endif
277 1.5.20.2 rpaulo
278 1.5.20.2 rpaulo pba.pba_iot = sc->sc_iot;
279 1.5.20.2 rpaulo pba.pba_memt = sc->sc_memt;
280 1.5.20.2 rpaulo /* XXX: review dma tag logic */
281 1.5.20.2 rpaulo pba.pba_dmat = aa->aa_dt;
282 1.5.20.2 rpaulo pba.pba_dmat64 = NULL;
283 1.5.20.2 rpaulo pba.pba_pc = &sc->sc_pc;
284 1.5.20.2 rpaulo pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
285 1.5.20.2 rpaulo pba.pba_bus = 0;
286 1.5.20.2 rpaulo pba.pba_bridgetag = NULL;
287 1.5.20.2 rpaulo
288 1.5.20.2 rpaulo config_found_ia(self, "pcibus", &pba, pcibusprint);
289 1.5.20.2 rpaulo #endif /* NPCI > 0 */
290 1.5.20.2 rpaulo }
291 1.5.20.2 rpaulo
292 1.5.20.2 rpaulo #if NPCI > 0
293 1.5.20.2 rpaulo
294 1.5.20.2 rpaulo void
295 1.5.20.2 rpaulo aupci_attach_hook(struct device *parent, struct device *self,
296 1.5.20.2 rpaulo struct pcibus_attach_args *pba)
297 1.5.20.2 rpaulo {
298 1.5.20.2 rpaulo }
299 1.5.20.2 rpaulo
300 1.5.20.2 rpaulo int
301 1.5.20.2 rpaulo aupci_bus_maxdevs(void *v, int busno)
302 1.5.20.2 rpaulo {
303 1.5.20.2 rpaulo
304 1.5.20.2 rpaulo return 32;
305 1.5.20.2 rpaulo }
306 1.5.20.2 rpaulo
307 1.5.20.2 rpaulo pcitag_t
308 1.5.20.2 rpaulo aupci_make_tag(void *v, int bus, int device, int function)
309 1.5.20.2 rpaulo {
310 1.5.20.2 rpaulo pcitag_t tag;
311 1.5.20.2 rpaulo
312 1.5.20.2 rpaulo if (bus >= 256 || device >= 32 || function >= 8)
313 1.5.20.2 rpaulo panic("aupci_make_tag: bad request");
314 1.5.20.2 rpaulo
315 1.5.20.2 rpaulo tag = (bus << 16) | (device << 11) | (function << 8);
316 1.5.20.2 rpaulo
317 1.5.20.2 rpaulo return tag;
318 1.5.20.2 rpaulo }
319 1.5.20.2 rpaulo
320 1.5.20.2 rpaulo void
321 1.5.20.2 rpaulo aupci_decompose_tag(void *v, pcitag_t tag, int *b, int *d, int *f)
322 1.5.20.2 rpaulo {
323 1.5.20.2 rpaulo
324 1.5.20.2 rpaulo if (b != NULL)
325 1.5.20.2 rpaulo *b = (tag >> 16) & 0xff;
326 1.5.20.2 rpaulo if (d != NULL)
327 1.5.20.2 rpaulo *d = (tag >> 11) & 0x1f;
328 1.5.20.2 rpaulo if (f != NULL)
329 1.5.20.2 rpaulo *f = (tag >> 8) & 0x07;
330 1.5.20.2 rpaulo }
331 1.5.20.2 rpaulo
332 1.5.20.2 rpaulo static inline boolean_t
333 1.5.20.2 rpaulo aupci_conf_access(void *v, int dir, pcitag_t tag, int reg, pcireg_t *datap)
334 1.5.20.2 rpaulo {
335 1.5.20.2 rpaulo struct aupci_softc *sc = (struct aupci_softc *)v;
336 1.5.20.2 rpaulo uint32_t status;
337 1.5.20.2 rpaulo int s;
338 1.5.20.2 rpaulo bus_addr_t addr;
339 1.5.20.2 rpaulo int b, d, f;
340 1.5.20.2 rpaulo bus_space_handle_t h;
341 1.5.20.2 rpaulo
342 1.5.20.2 rpaulo aupci_decompose_tag(v, tag, &b, &d, &f);
343 1.5.20.2 rpaulo if (b) {
344 1.5.20.2 rpaulo /* configuration type 1 */
345 1.5.20.2 rpaulo addr = 0x80000000 | tag;
346 1.5.20.2 rpaulo } else if (d > 19) {
347 1.5.20.2 rpaulo /* device num too big for bus 0 */
348 1.5.20.2 rpaulo return FALSE;
349 1.5.20.2 rpaulo } else {
350 1.5.20.2 rpaulo addr = (0x800 << d) | (f << 8);
351 1.5.20.2 rpaulo }
352 1.5.20.2 rpaulo
353 1.5.20.2 rpaulo /* probing illegal target is OK, return an error indication */
354 1.5.20.2 rpaulo if (addr == 0)
355 1.5.20.2 rpaulo return FALSE;
356 1.5.20.2 rpaulo
357 1.5.20.2 rpaulo if (bus_space_map(sc->sc_cfgt, addr, 256, 0, &h) != 0)
358 1.5.20.2 rpaulo return FALSE;
359 1.5.20.2 rpaulo
360 1.5.20.2 rpaulo s = splhigh();
361 1.5.20.2 rpaulo
362 1.5.20.2 rpaulo if (dir == PCI_CFG_WRITE)
363 1.5.20.2 rpaulo bus_space_write_4(sc->sc_cfgt, h, reg, *datap);
364 1.5.20.2 rpaulo else
365 1.5.20.2 rpaulo *datap = bus_space_read_4(sc->sc_cfgt, h, reg);
366 1.5.20.2 rpaulo
367 1.5.20.2 rpaulo DELAY(2);
368 1.5.20.2 rpaulo
369 1.5.20.2 rpaulo /* check for and clear master abort condition */
370 1.5.20.2 rpaulo status = bus_space_read_4(sc->sc_bust, sc->sc_bush, AUPCI_CONFIG);
371 1.5.20.2 rpaulo bus_space_write_4(sc->sc_bust, sc->sc_bush, AUPCI_CONFIG,
372 1.5.20.2 rpaulo status & ~(AUPCI_CONFIG_EF));
373 1.5.20.2 rpaulo
374 1.5.20.2 rpaulo splx(s);
375 1.5.20.2 rpaulo
376 1.5.20.2 rpaulo bus_space_unmap(sc->sc_cfgt, h, 256);
377 1.5.20.2 rpaulo
378 1.5.20.2 rpaulo /* if we got a PCI master abort, fail it */
379 1.5.20.2 rpaulo if (status & AUPCI_CONFIG_EF)
380 1.5.20.2 rpaulo return FALSE;
381 1.5.20.2 rpaulo
382 1.5.20.2 rpaulo
383 1.5.20.2 rpaulo return TRUE;
384 1.5.20.2 rpaulo }
385 1.5.20.2 rpaulo
386 1.5.20.2 rpaulo pcireg_t
387 1.5.20.2 rpaulo aupci_conf_read(void *v, pcitag_t tag, int reg)
388 1.5.20.2 rpaulo {
389 1.5.20.2 rpaulo pcireg_t data;
390 1.5.20.2 rpaulo
391 1.5.20.2 rpaulo if (aupci_conf_access(v, PCI_CFG_READ, tag, reg, &data) == FALSE)
392 1.5.20.2 rpaulo return 0xffffffff;
393 1.5.20.2 rpaulo
394 1.5.20.2 rpaulo return (data);
395 1.5.20.2 rpaulo }
396 1.5.20.2 rpaulo
397 1.5.20.2 rpaulo void
398 1.5.20.2 rpaulo aupci_conf_write(void *v, pcitag_t tag, int reg, pcireg_t data)
399 1.5.20.2 rpaulo {
400 1.5.20.2 rpaulo
401 1.5.20.2 rpaulo aupci_conf_access(v, PCI_CFG_WRITE, tag, reg, &data);
402 1.5.20.2 rpaulo }
403 1.5.20.2 rpaulo
404 1.5.20.2 rpaulo const char *
405 1.5.20.2 rpaulo aupci_intr_string(void *v, pci_intr_handle_t ih)
406 1.5.20.2 rpaulo {
407 1.5.20.2 rpaulo static char name[16];
408 1.5.20.2 rpaulo
409 1.5.20.2 rpaulo sprintf(name, "irq %u", (unsigned)ih);
410 1.5.20.2 rpaulo return (name);
411 1.5.20.2 rpaulo }
412 1.5.20.2 rpaulo
413 1.5.20.2 rpaulo void *
414 1.5.20.2 rpaulo aupci_intr_establish(void *v, pci_intr_handle_t ih, int ipl,
415 1.5.20.2 rpaulo int (*handler)(void *), void *arg)
416 1.5.20.2 rpaulo {
417 1.5.20.2 rpaulo
418 1.5.20.2 rpaulo return (au_intr_establish(ih, 0, ipl, IST_LEVEL_LOW, handler, arg));
419 1.5.20.2 rpaulo }
420 1.5.20.2 rpaulo
421 1.5.20.2 rpaulo void
422 1.5.20.2 rpaulo aupci_intr_disestablish(void *v, void *cookie)
423 1.5.20.2 rpaulo {
424 1.5.20.2 rpaulo
425 1.5.20.2 rpaulo au_intr_disestablish(cookie);
426 1.5.20.2 rpaulo }
427 1.5.20.2 rpaulo
428 1.5.20.2 rpaulo void
429 1.5.20.2 rpaulo aupci_conf_interrupt(void *v, int bus, int dev, int ipin, int swiz, int *iline)
430 1.5.20.2 rpaulo {
431 1.5.20.2 rpaulo /*
432 1.5.20.2 rpaulo * We let the machdep_pci_intr_map take care of IRQ routing.
433 1.5.20.2 rpaulo * On some platforms the BIOS may have handled this properly,
434 1.5.20.2 rpaulo * on others it might not have. For now we avoid clobbering
435 1.5.20.2 rpaulo * the settings establishsed by the BIOS, so that they will be
436 1.5.20.2 rpaulo * there if the platform logic is confident that it can rely
437 1.5.20.2 rpaulo * on them.
438 1.5.20.2 rpaulo */
439 1.5.20.2 rpaulo }
440 1.5.20.2 rpaulo
441 1.5.20.2 rpaulo #endif
442