pci_machdep.c revision 1.36 1 1.36 nonaka /* $NetBSD: pci_machdep.c,v 1.36 2016/11/26 15:03:23 nonaka Exp $ */
2 1.1 briggs
3 1.1 briggs /*
4 1.1 briggs * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
5 1.1 briggs * Copyright (c) 1994 Charles M. Hannum. All rights reserved.
6 1.1 briggs *
7 1.1 briggs * Redistribution and use in source and binary forms, with or without
8 1.1 briggs * modification, are permitted provided that the following conditions
9 1.1 briggs * are met:
10 1.1 briggs * 1. Redistributions of source code must retain the above copyright
11 1.1 briggs * notice, this list of conditions and the following disclaimer.
12 1.1 briggs * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 briggs * notice, this list of conditions and the following disclaimer in the
14 1.1 briggs * documentation and/or other materials provided with the distribution.
15 1.1 briggs * 3. All advertising materials mentioning features or use of this software
16 1.1 briggs * must display the following acknowledgement:
17 1.1 briggs * This product includes software developed by Charles M. Hannum.
18 1.1 briggs * 4. The name of the author may not be used to endorse or promote products
19 1.1 briggs * derived from this software without specific prior written permission.
20 1.1 briggs *
21 1.1 briggs * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.1 briggs * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.1 briggs * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.1 briggs * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.1 briggs * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.1 briggs * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.1 briggs * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.1 briggs * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.1 briggs * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.1 briggs * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.1 briggs */
32 1.1 briggs
33 1.1 briggs /*
34 1.1 briggs * Machine-specific functions for PCI autoconfiguration.
35 1.1 briggs *
36 1.1 briggs * On PCs, there are two methods of generating PCI configuration cycles.
37 1.1 briggs * We try to detect the appropriate mechanism for this machine and set
38 1.1 briggs * up a few function pointers to access the correct method directly.
39 1.1 briggs *
40 1.1 briggs * The configuration method can be hard-coded in the config file by
41 1.1 briggs * using `options PCI_CONF_MODE=N', where `N' is the configuration mode
42 1.1 briggs * as defined section 3.6.4.1, `Generating Configuration Cycles'.
43 1.1 briggs */
44 1.11 lukem
45 1.11 lukem #include <sys/cdefs.h>
46 1.36 nonaka __KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.36 2016/11/26 15:03:23 nonaka Exp $");
47 1.17 nisimura
48 1.17 nisimura #include "opt_pci.h"
49 1.1 briggs
50 1.1 briggs #include <sys/types.h>
51 1.1 briggs #include <sys/param.h>
52 1.1 briggs #include <sys/device.h>
53 1.1 briggs #include <sys/errno.h>
54 1.1 briggs #include <sys/extent.h>
55 1.35 nonaka #include <sys/kmem.h>
56 1.1 briggs #include <sys/malloc.h>
57 1.1 briggs #include <sys/queue.h>
58 1.1 briggs #include <sys/systm.h>
59 1.1 briggs #include <sys/time.h>
60 1.1 briggs
61 1.4 briggs #define _POWERPC_BUS_DMA_PRIVATE
62 1.29 dyoung #include <sys/bus.h>
63 1.13 garbled #include <machine/intr.h>
64 1.1 briggs #include <machine/pio.h>
65 1.1 briggs
66 1.1 briggs #include <dev/isa/isavar.h>
67 1.1 briggs #include <dev/pci/pcivar.h>
68 1.1 briggs #include <dev/pci/pcireg.h>
69 1.1 briggs #include <dev/pci/pciconf.h>
70 1.13 garbled #include <dev/pci/pcidevs.h>
71 1.1 briggs
72 1.4 briggs struct powerpc_bus_dma_tag pci_bus_dma_tag = {
73 1.1 briggs 0, /* _bounce_thresh */
74 1.1 briggs _bus_dmamap_create,
75 1.1 briggs _bus_dmamap_destroy,
76 1.1 briggs _bus_dmamap_load,
77 1.1 briggs _bus_dmamap_load_mbuf,
78 1.1 briggs _bus_dmamap_load_uio,
79 1.1 briggs _bus_dmamap_load_raw,
80 1.1 briggs _bus_dmamap_unload,
81 1.1 briggs NULL, /* _dmamap_sync */
82 1.1 briggs _bus_dmamem_alloc,
83 1.1 briggs _bus_dmamem_free,
84 1.1 briggs _bus_dmamem_map,
85 1.1 briggs _bus_dmamem_unmap,
86 1.1 briggs _bus_dmamem_mmap,
87 1.1 briggs };
88 1.1 briggs
89 1.18 phx /*#define EPIC_DEBUGIRQ*/
90 1.13 garbled
91 1.13 garbled static int brdtype;
92 1.13 garbled #define BRD_SANDPOINTX2 2
93 1.13 garbled #define BRD_SANDPOINTX3 3
94 1.13 garbled #define BRD_ENCOREPP1 10
95 1.13 garbled #define BRD_KUROBOX 100
96 1.25 phx #define BRD_QNAPTS 101
97 1.13 garbled #define BRD_SYNOLOGY 102
98 1.21 nisimura #define BRD_STORCENTER 103
99 1.22 nisimura #define BRD_DLINKDSM 104
100 1.23 nisimura #define BRD_NH230NAS 105
101 1.13 garbled #define BRD_UNKNOWN -1
102 1.13 garbled
103 1.1 briggs #define PCI_CONFIG_ENABLE 0x80000000UL
104 1.1 briggs
105 1.1 briggs void
106 1.28 matt pci_attach_hook(device_t parent, device_t self, struct pcibus_attach_args *pba)
107 1.1 briggs {
108 1.13 garbled pcitag_t tag;
109 1.22 nisimura pcireg_t dev11, dev22, dev15, dev13, dev16;
110 1.13 garbled
111 1.13 garbled tag = pci_make_tag(pba->pba_pc, pba->pba_bus, 11, 0);
112 1.13 garbled dev11 = pci_conf_read(pba->pba_pc, tag, PCI_CLASS_REG);
113 1.13 garbled if (PCI_CLASS(dev11) == PCI_CLASS_BRIDGE) {
114 1.13 garbled /* WinBond/Symphony Lab 83C553 at dev 11 */
115 1.13 garbled /*
116 1.13 garbled * XXX distinguish SP3 from SP2 by fiddling ISA GPIO #7/6.
117 1.13 garbled * XXX SP3 #7 output values loopback to #6 input.
118 1.13 garbled */
119 1.13 garbled brdtype = BRD_SANDPOINTX3;
120 1.13 garbled return;
121 1.13 garbled }
122 1.13 garbled tag = pci_make_tag(pba->pba_pc, pba->pba_bus, 22, 0);
123 1.13 garbled dev22 = pci_conf_read(pba->pba_pc, tag, PCI_CLASS_REG);
124 1.13 garbled if (PCI_CLASS(dev22) == PCI_CLASS_BRIDGE) {
125 1.13 garbled /* VIA 82C686B at dev 22 */
126 1.13 garbled brdtype = BRD_ENCOREPP1;
127 1.13 garbled return;
128 1.13 garbled }
129 1.13 garbled tag = pci_make_tag(pba->pba_pc, pba->pba_bus, 11, 0);
130 1.13 garbled dev11 = pci_conf_read(pba->pba_pc, tag, PCI_CLASS_REG);
131 1.13 garbled if (PCI_CLASS(dev11) == PCI_CLASS_NETWORK) {
132 1.13 garbled /* tlp (ADMtek AN985) or re (RealTek 8169S) at dev 11 */
133 1.13 garbled brdtype = BRD_KUROBOX;
134 1.13 garbled return;
135 1.13 garbled }
136 1.13 garbled tag = pci_make_tag(pba->pba_pc, pba->pba_bus, 15, 0);
137 1.13 garbled dev15 = pci_conf_read(pba->pba_pc, tag, PCI_ID_REG);
138 1.13 garbled if (PCI_VENDOR(dev15) == PCI_VENDOR_MARVELL) {
139 1.13 garbled /* Marvell GbE at dev 15 */
140 1.13 garbled brdtype = BRD_SYNOLOGY;
141 1.13 garbled return;
142 1.13 garbled }
143 1.21 nisimura tag = pci_make_tag(pba->pba_pc, pba->pba_bus, 13, 0);
144 1.21 nisimura dev13 = pci_conf_read(pba->pba_pc, tag, PCI_ID_REG);
145 1.21 nisimura if (PCI_VENDOR(dev13) == PCI_VENDOR_VIATECH) {
146 1.21 nisimura /* VIA 6410 PCIIDE at dev 13 */
147 1.21 nisimura brdtype = BRD_STORCENTER;
148 1.21 nisimura return;
149 1.21 nisimura }
150 1.22 nisimura tag = pci_make_tag(pba->pba_pc, pba->pba_bus, 16, 0);
151 1.22 nisimura dev16 = pci_conf_read(pba->pba_pc, tag, PCI_ID_REG);
152 1.22 nisimura if (PCI_VENDOR(dev16) == PCI_VENDOR_ACARD) {
153 1.22 nisimura /* ACARD ATP865 at dev 16 */
154 1.22 nisimura brdtype = BRD_DLINKDSM;
155 1.22 nisimura return;
156 1.22 nisimura }
157 1.23 nisimura if (PCI_VENDOR(dev16) == PCI_VENDOR_ITE
158 1.23 nisimura || PCI_VENDOR(dev16) == PCI_VENDOR_CMDTECH) {
159 1.23 nisimura brdtype = BRD_NH230NAS;
160 1.23 nisimura return;
161 1.23 nisimura }
162 1.27 phx if (PCI_VENDOR(dev15) == PCI_VENDOR_INTEL
163 1.27 phx || PCI_VENDOR(dev15) == PCI_VENDOR_REALTEK) {
164 1.27 phx /* Intel or Realtek GbE at dev 15 */
165 1.27 phx brdtype = BRD_QNAPTS;
166 1.27 phx return;
167 1.27 phx }
168 1.22 nisimura
169 1.13 garbled brdtype = BRD_UNKNOWN;
170 1.1 briggs }
171 1.1 briggs
172 1.1 briggs int
173 1.14 nisimura pci_bus_maxdevs(pci_chipset_tag_t pc, int busno)
174 1.1 briggs {
175 1.1 briggs
176 1.14 nisimura return 32;
177 1.1 briggs }
178 1.1 briggs
179 1.1 briggs pcitag_t
180 1.14 nisimura pci_make_tag(pci_chipset_tag_t pc, int bus, int device, int function)
181 1.1 briggs {
182 1.1 briggs pcitag_t tag;
183 1.1 briggs
184 1.1 briggs if (bus >= 256 || device >= 32 || function >= 8)
185 1.1 briggs panic("pci_make_tag: bad request");
186 1.1 briggs
187 1.1 briggs tag = PCI_CONFIG_ENABLE |
188 1.1 briggs (bus << 16) | (device << 11) | (function << 8);
189 1.1 briggs return tag;
190 1.1 briggs }
191 1.1 briggs
192 1.1 briggs void
193 1.14 nisimura pci_decompose_tag(pci_chipset_tag_t pc, pcitag_t tag,
194 1.14 nisimura int *bp, int *dp, int *fp)
195 1.1 briggs {
196 1.1 briggs
197 1.1 briggs if (bp != NULL)
198 1.1 briggs *bp = (tag >> 16) & 0xff;
199 1.1 briggs if (dp != NULL)
200 1.1 briggs *dp = (tag >> 11) & 0x1f;
201 1.1 briggs if (fp != NULL)
202 1.1 briggs *fp = (tag >> 8) & 0x7;
203 1.1 briggs return;
204 1.1 briggs }
205 1.1 briggs
206 1.1 briggs /*
207 1.1 briggs * The Kahlua documentation says that "reg" should be left-shifted by two
208 1.1 briggs * and be in bits 2-7. Apparently not. It doesn't work that way, and the
209 1.1 briggs * DINK32 ROM doesn't do it that way (I peeked at 0xfec00000 after running
210 1.1 briggs * the DINK32 "pcf" command).
211 1.1 briggs */
212 1.1 briggs pcireg_t
213 1.14 nisimura pci_conf_read(pci_chipset_tag_t pc, pcitag_t tag, int reg)
214 1.1 briggs {
215 1.1 briggs pcireg_t data;
216 1.1 briggs
217 1.34 msaitoh if ((unsigned int)reg >= PCI_CONF_SIZE)
218 1.34 msaitoh return (pcireg_t) -1;
219 1.34 msaitoh
220 1.14 nisimura out32rb(SANDPOINT_PCI_CONFIG_ADDR, tag | reg);
221 1.1 briggs data = in32rb(SANDPOINT_PCI_CONFIG_DATA);
222 1.1 briggs out32rb(SANDPOINT_PCI_CONFIG_ADDR, 0);
223 1.1 briggs return data;
224 1.1 briggs }
225 1.1 briggs
226 1.1 briggs void
227 1.14 nisimura pci_conf_write(pci_chipset_tag_t pc, pcitag_t tag, int reg, pcireg_t data)
228 1.1 briggs {
229 1.14 nisimura
230 1.34 msaitoh if ((unsigned int)reg >= PCI_CONF_SIZE)
231 1.34 msaitoh return;
232 1.34 msaitoh
233 1.14 nisimura out32rb(SANDPOINT_PCI_CONFIG_ADDR, tag | reg);
234 1.1 briggs out32rb(SANDPOINT_PCI_CONFIG_DATA, data);
235 1.1 briggs out32rb(SANDPOINT_PCI_CONFIG_ADDR, 0);
236 1.1 briggs }
237 1.1 briggs
238 1.1 briggs int
239 1.26 dyoung pci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
240 1.1 briggs {
241 1.1 briggs int pin = pa->pa_intrpin;
242 1.1 briggs int line = pa->pa_intrline;
243 1.1 briggs
244 1.13 garbled /* No IRQ used. */
245 1.13 garbled if (pin == 0)
246 1.1 briggs goto bad;
247 1.1 briggs if (pin > 4) {
248 1.13 garbled aprint_error("pci_intr_map: bad interrupt pin %d\n", pin);
249 1.1 briggs goto bad;
250 1.1 briggs }
251 1.1 briggs
252 1.1 briggs /*
253 1.1 briggs * Section 6.2.4, `Miscellaneous Functions', says that 255 means
254 1.1 briggs * `unknown' or `no connection' on a PC. We assume that a device with
255 1.1 briggs * `no connection' either doesn't have an interrupt (in which case the
256 1.1 briggs * pin number should be 0, and would have been noticed above), or
257 1.1 briggs * wasn't configured by the BIOS (in which case we punt, since there's
258 1.1 briggs * no real way we can know how the interrupt lines are mapped in the
259 1.1 briggs * hardware).
260 1.1 briggs *
261 1.1 briggs * XXX
262 1.1 briggs * Since IRQ 0 is only used by the clock, and we can't actually be sure
263 1.1 briggs * that the BIOS did its job, we also recognize that as meaning that
264 1.1 briggs * the BIOS has not configured the device.
265 1.1 briggs */
266 1.1 briggs if (line == 255) {
267 1.13 garbled aprint_error("pci_intr_map: no mapping for pin %c\n",
268 1.13 garbled '@' + pin);
269 1.1 briggs goto bad;
270 1.8 briggs }
271 1.13 garbled #ifdef EPIC_DEBUGIRQ
272 1.18 phx printf("line %d, pin %c", line, pin + '@');
273 1.13 garbled #endif
274 1.13 garbled switch (brdtype) {
275 1.13 garbled /* Sandpoint has 4 PCI slots in a weird order.
276 1.13 garbled * From next to MPMC mezzanine card toward the board edge,
277 1.13 garbled * 64bit slot PCI AD14
278 1.13 garbled * 64bit slot PCI AD13
279 1.13 garbled * 32bit slot PCI AD16
280 1.13 garbled * 32bit slot PCI AD15
281 1.13 garbled * Don't believe identifying labels printed on PCB and
282 1.13 garbled * documents confusing as well since Moto names the slots
283 1.13 garbled * as number 1 origin.
284 1.13 garbled */
285 1.13 garbled case BRD_SANDPOINTX3:
286 1.13 garbled /*
287 1.13 garbled * Sandpoint X3 brd uses EPIC serial mode IRQ.
288 1.13 garbled * - i8259 PIC interrupt to EPIC IRQ0.
289 1.13 garbled * - WinBond IDE PCI C/D to EPIC IRQ8/9.
290 1.15 nisimura * - PCI AD13 pin A to EPIC IRQ2.
291 1.15 nisimura * - PCI AD14 pin A to EPIC IRQ3.
292 1.15 nisimura * - PCI AD15 pin A to EPIC IRQ4.
293 1.15 nisimura * - PCI AD16 pin A to EPIC IRQ5.
294 1.13 garbled */
295 1.13 garbled if (line == 11
296 1.13 garbled && pa->pa_function == 1 && pa->pa_bus == 0) {
297 1.13 garbled /* X3 wires 83c553 pin C,D to EPIC IRQ8,9 */
298 1.13 garbled *ihp = 8; /* pin C only, indeed */
299 1.8 briggs break;
300 1.13 garbled }
301 1.13 garbled if (line < 13 || line > 16) {
302 1.13 garbled aprint_error("pci_intr_map: bad interrupt line %d,%c\n",
303 1.8 briggs line, pin + '@');
304 1.8 briggs goto bad;
305 1.13 garbled }
306 1.15 nisimura line -= 13; /* B/C/D is not available */
307 1.15 nisimura *ihp = 2 + line;
308 1.13 garbled break;
309 1.13 garbled case BRD_SANDPOINTX2:
310 1.13 garbled /*
311 1.13 garbled * Sandpoint X2 brd uses EPIC direct mode IRQ.
312 1.13 garbled * - i8259 PIC interrupt EPIC IRQ2.
313 1.13 garbled * - PCI AD13 pin A,B,C,D to EPIC IRQ0,1,2,3.
314 1.13 garbled * - PCI AD14 pin A,B,C,D to EPIC IRQ1,2,3,0.
315 1.13 garbled * - PCI AD15 pin A,B,C,D to EPIC IRQ2,3,0,1.
316 1.13 garbled * - PCI AD16 pin A,B,C,D to EPIC IRQ3,0,1,2.
317 1.13 garbled * - PCI AD12 is wired to PMPC device itself.
318 1.13 garbled */
319 1.13 garbled if (line == 11
320 1.13 garbled && pa->pa_function == 1 && pa->pa_bus == 0) {
321 1.13 garbled /* 83C553 PCI IDE comes thru EPIC IRQ2 */
322 1.13 garbled *ihp = 2;
323 1.8 briggs break;
324 1.8 briggs }
325 1.1 briggs if (line < 13 || line > 16) {
326 1.13 garbled aprint_error("pci_intr_map: bad interrupt line %d,%c\n",
327 1.8 briggs line, pin + '@');
328 1.1 briggs goto bad;
329 1.1 briggs }
330 1.13 garbled line -= 13; pin -= 1;
331 1.13 garbled *ihp = (line + pin) & 03;
332 1.13 garbled break;
333 1.13 garbled case BRD_ENCOREPP1:
334 1.13 garbled /*
335 1.15 nisimura * Ampro EnCorePP1 brd uses EPIC direct mode IRQ.
336 1.15 nisimura * PDF says VIA 686B SB i8259 interrupt goes through EPC IRQ0,
337 1.15 nisimura * while PCI pin A-D are tied with EPIC IRQ1-4.
338 1.15 nisimura *
339 1.15 nisimura * It mentions i82559 is at AD24, however, found at AD25 instead.
340 1.15 nisimura * Heuristics show that i82559 responds to EPIC 2 (!). Then we
341 1.15 nisimura * decided to return EPIC 2 here since i82559 is the only one PCI
342 1.15 nisimura * device ENCPP1 can have;
343 1.13 garbled */
344 1.15 nisimura if (pa->pa_device != 25)
345 1.15 nisimura goto bad; /* eeh !? */
346 1.15 nisimura *ihp = 2;
347 1.13 garbled break;
348 1.13 garbled case BRD_KUROBOX:
349 1.30 phx /* map line 11,12,13,14 to EPIC IRQ 0,1,4,3 */
350 1.13 garbled *ihp = (line == 13) ? 4 : line - 11;
351 1.13 garbled break;
352 1.25 phx case BRD_QNAPTS:
353 1.19 phx /* map line 13-16 to EPIC IRQ0-3 */
354 1.19 phx *ihp = line - 13;
355 1.13 garbled break;
356 1.13 garbled case BRD_SYNOLOGY:
357 1.30 phx /* map line 12,13-15 to EPIC IRQ 4,0-2 */
358 1.13 garbled *ihp = (line == 12) ? 4 : line - 13;
359 1.13 garbled break;
360 1.22 nisimura case BRD_DLINKDSM:
361 1.30 phx /* map line 13,14A,14B,14C,15,16 to EPIC IRQ 0,1,1,2,3,4 */
362 1.22 nisimura *ihp = (line < 15) ? line - 13 : line - 12;
363 1.24 phx if (line == 14 && pin == 3)
364 1.24 phx *ihp += 1; /* USB pin C (EHCI) uses next IRQ */
365 1.22 nisimura break;
366 1.23 nisimura case BRD_NH230NAS:
367 1.23 nisimura /* map line 13,14,15,16 to EPIC IRQ0,3,1,2 */
368 1.23 nisimura *ihp = (line == 16) ? 2 :
369 1.23 nisimura (line == 15) ? 1 :
370 1.23 nisimura (line == 14) ? 3 : 0;
371 1.23 nisimura break;
372 1.21 nisimura case BRD_STORCENTER:
373 1.30 phx /* map line 13,14A,14B,14C,15 to EPIC IRQ 1,2,3,4,0 */
374 1.31 phx *ihp = (line == 15) ? 0 :
375 1.31 phx (line == 13) ? 1 : 1 + pin;
376 1.30 phx break;
377 1.13 garbled default:
378 1.30 phx /* simply map line 12-15 to EPIC IRQ0-3 */
379 1.13 garbled *ihp = line - 12;
380 1.31 phx #if defined(DIAGNOSTIC) || defined(DEBUG)
381 1.31 phx printf("pci_intr_map: line %d, pin %c for unknown board"
382 1.31 phx " mapped to irq %d\n", line, pin + '@', *ihp);
383 1.31 phx #endif
384 1.13 garbled break;
385 1.13 garbled }
386 1.13 garbled #ifdef EPIC_DEBUGIRQ
387 1.18 phx printf(" = EPIC %d\n", *ihp);
388 1.6 briggs #endif
389 1.1 briggs return 0;
390 1.13 garbled bad:
391 1.1 briggs *ihp = -1;
392 1.1 briggs return 1;
393 1.1 briggs }
394 1.1 briggs
395 1.1 briggs const char *
396 1.33 christos pci_intr_string(pci_chipset_tag_t pc, pci_intr_handle_t ih, char *buf,
397 1.33 christos size_t len)
398 1.1 briggs {
399 1.14 nisimura if (ih < 0 || ih >= OPENPIC_ICU)
400 1.10 provos panic("pci_intr_string: bogus handle 0x%x", ih);
401 1.1 briggs
402 1.33 christos snprintf(buf, len, "irq %d", ih + I8259_ICU);
403 1.33 christos return buf;
404 1.1 briggs
405 1.1 briggs }
406 1.1 briggs
407 1.1 briggs const struct evcnt *
408 1.35 nonaka pci_intr_evcnt(pci_chipset_tag_t pc, pci_intr_handle_t ih)
409 1.1 briggs {
410 1.1 briggs
411 1.1 briggs /* XXX for now, no evcnt parent reported */
412 1.1 briggs return NULL;
413 1.1 briggs }
414 1.1 briggs
415 1.16 ad int
416 1.16 ad pci_intr_setattr(pci_chipset_tag_t pc, pci_intr_handle_t *ih,
417 1.16 ad int attr, uint64_t data)
418 1.16 ad {
419 1.16 ad
420 1.16 ad switch (attr) {
421 1.16 ad case PCI_INTR_MPSAFE:
422 1.16 ad return 0;
423 1.16 ad default:
424 1.16 ad return ENODEV;
425 1.16 ad }
426 1.16 ad }
427 1.16 ad
428 1.1 briggs void *
429 1.35 nonaka pci_intr_establish(pci_chipset_tag_t pc, pci_intr_handle_t ih, int level,
430 1.14 nisimura int (*func)(void *), void *arg)
431 1.1 briggs {
432 1.35 nonaka
433 1.35 nonaka return pci_intr_establish_xname(pc, ih, level, func, arg, NULL);
434 1.35 nonaka }
435 1.35 nonaka
436 1.35 nonaka void *
437 1.35 nonaka pci_intr_establish_xname(pci_chipset_tag_t pc, pci_intr_handle_t ih, int level,
438 1.35 nonaka int (*func)(void *), void *arg, const char *xname)
439 1.35 nonaka {
440 1.31 phx int type;
441 1.31 phx
442 1.31 phx if (brdtype == BRD_STORCENTER && ih == 1) {
443 1.31 phx /*
444 1.31 phx * XXX This is a workaround for the VT6410 IDE controller!
445 1.31 phx * Apparently its interrupt cannot be disabled and remains
446 1.31 phx * asserted during the whole device probing procedure,
447 1.31 phx * causing an interrupt storm.
448 1.31 phx * Using an edge-trigger fixes that and triggers the
449 1.31 phx * interrupt only once during probing.
450 1.31 phx */
451 1.35 nonaka type = IST_EDGE;
452 1.31 phx } else
453 1.31 phx type = IST_LEVEL;
454 1.35 nonaka
455 1.1 briggs /*
456 1.1 briggs * ih is the value assigned in pci_intr_map(), above.
457 1.13 garbled * It's the EPIC IRQ #.
458 1.1 briggs */
459 1.35 nonaka return intr_establish_xname(ih + I8259_ICU, type, level, func, arg,
460 1.35 nonaka xname);
461 1.1 briggs }
462 1.1 briggs
463 1.1 briggs void
464 1.35 nonaka pci_intr_disestablish(pci_chipset_tag_t pc, void *cookie)
465 1.1 briggs {
466 1.14 nisimura
467 1.3 lukem intr_disestablish(cookie);
468 1.1 briggs }
469 1.1 briggs
470 1.17 nisimura #if defined(PCI_NETBSD_CONFIGURE)
471 1.1 briggs void
472 1.14 nisimura pci_conf_interrupt(pci_chipset_tag_t pc, int bus, int dev,
473 1.14 nisimura int pin, int swiz, int *iline)
474 1.1 briggs {
475 1.2 briggs if (bus == 0) {
476 1.2 briggs *iline = dev;
477 1.2 briggs } else {
478 1.2 briggs /*
479 1.2 briggs * If we are not on bus zero, we're behind a bridge, so we
480 1.2 briggs * swizzle.
481 1.2 briggs *
482 1.2 briggs * The documentation lies about this. In slot 3 (numbering
483 1.2 briggs * from 0) aka device 16, INTD# becomes an interrupt for
484 1.2 briggs * slot 2. INTC# becomes an interrupt for slot 1, etc.
485 1.2 briggs * In slot 2 aka device 16, INTD# becomes an interrupt for
486 1.2 briggs * slot 1, etc.
487 1.2 briggs *
488 1.2 briggs * Verified for INTD# on device 16, INTC# on device 16,
489 1.2 briggs * INTD# on device 15, INTD# on device 13, and INTC# on
490 1.2 briggs * device 14. I presume that the rest follow the same
491 1.2 briggs * pattern.
492 1.2 briggs *
493 1.2 briggs * Slot 0 is device 13, and is the base for the rest.
494 1.2 briggs */
495 1.2 briggs *iline = 13 + ((swiz + dev + 3) & 3);
496 1.2 briggs }
497 1.1 briggs }
498 1.17 nisimura #endif
499 1.35 nonaka
500 1.36 nonaka pci_intr_type_t
501 1.36 nonaka pci_intr_type(pci_chipset_tag_t pc, pci_intr_handle_t ih)
502 1.36 nonaka {
503 1.36 nonaka
504 1.36 nonaka return PCI_INTR_TYPE_INTX;
505 1.36 nonaka }
506 1.36 nonaka
507 1.36 nonaka int
508 1.36 nonaka pci_intr_alloc(const struct pci_attach_args *pa, pci_intr_handle_t **ihps,
509 1.36 nonaka int *counts, pci_intr_type_t max_type)
510 1.36 nonaka {
511 1.36 nonaka
512 1.36 nonaka if (counts != NULL && counts[PCI_INTR_TYPE_INTX] == 0)
513 1.36 nonaka return EINVAL;
514 1.36 nonaka
515 1.36 nonaka return pci_intx_alloc(pa, ihps);
516 1.36 nonaka }
517 1.36 nonaka
518 1.36 nonaka void
519 1.36 nonaka pci_intr_release(pci_chipset_tag_t pc, pci_intr_handle_t *pih, int count)
520 1.36 nonaka {
521 1.36 nonaka
522 1.36 nonaka kmem_free(pih, sizeof(*pih));
523 1.36 nonaka }
524 1.36 nonaka
525 1.35 nonaka int
526 1.35 nonaka pci_intx_alloc(const struct pci_attach_args *pa, pci_intr_handle_t **ihpp)
527 1.35 nonaka {
528 1.35 nonaka pci_intr_handle_t *ihp;
529 1.35 nonaka
530 1.35 nonaka ihp = kmem_alloc(sizeof(*ihp), KM_SLEEP);
531 1.35 nonaka if (ihp == NULL)
532 1.35 nonaka return ENOMEM;
533 1.35 nonaka
534 1.35 nonaka if (pci_intr_map(pa, ihp)) {
535 1.35 nonaka kmem_free(ihp, sizeof(*ihp));
536 1.35 nonaka return EINVAL;
537 1.35 nonaka }
538 1.35 nonaka
539 1.35 nonaka *ihpp = ihp;
540 1.35 nonaka return 0;
541 1.35 nonaka }
542 1.35 nonaka
543 1.35 nonaka /* experimental MSI support */
544 1.35 nonaka int
545 1.35 nonaka pci_msi_alloc(const struct pci_attach_args *pa, pci_intr_handle_t **ihps,
546 1.35 nonaka int *count)
547 1.35 nonaka {
548 1.35 nonaka
549 1.35 nonaka return EOPNOTSUPP;
550 1.35 nonaka }
551 1.35 nonaka
552 1.35 nonaka int
553 1.35 nonaka pci_msi_alloc_exact(const struct pci_attach_args *pa, pci_intr_handle_t **ihps,
554 1.35 nonaka int count)
555 1.35 nonaka {
556 1.35 nonaka
557 1.35 nonaka return EOPNOTSUPP;
558 1.35 nonaka }
559 1.35 nonaka
560 1.35 nonaka /* experimental MSI-X support */
561 1.35 nonaka int
562 1.35 nonaka pci_msix_alloc(const struct pci_attach_args *pa, pci_intr_handle_t **ihps,
563 1.35 nonaka int *count)
564 1.35 nonaka {
565 1.35 nonaka
566 1.35 nonaka return EOPNOTSUPP;
567 1.35 nonaka }
568 1.35 nonaka
569 1.35 nonaka int
570 1.35 nonaka pci_msix_alloc_exact(const struct pci_attach_args *pa, pci_intr_handle_t **ihps,
571 1.35 nonaka int count)
572 1.35 nonaka {
573 1.35 nonaka
574 1.35 nonaka return EOPNOTSUPP;
575 1.35 nonaka }
576 1.35 nonaka
577 1.35 nonaka int
578 1.35 nonaka pci_msix_alloc_map(const struct pci_attach_args *pa, pci_intr_handle_t **ihps,
579 1.35 nonaka u_int *table_indexes, int count)
580 1.35 nonaka {
581 1.35 nonaka
582 1.35 nonaka return EOPNOTSUPP;
583 1.35 nonaka }
584