1 /* $NetBSD: pci_machdep_common.c,v 1.7 2008/01/17 23:42:59 garbled Exp $ */
4 * Copyright (c) 2007 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Generic PowerPC functions for dealing with a PCI bridge. For most cases,
34 * these functions will work just fine, however, some machines may need
35 * specialized code, so those ports are free to write thier own functions
36 * and call those instead where appropriate.
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: pci_machdep_common.c,v 1.7 2008/01/17 23:42:59 garbled Exp $");
42 #include <sys/types.h>
43 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/errno.h>
47 #include <sys/extent.h>
48 #include <sys/device.h>
49 #include <sys/malloc.h>
51 #include <uvm/uvm_extern.h>
53 #define _POWERPC_BUS_DMA_PRIVATE
54 #include <machine/bus.h>
55 #include <machine/intr.h>
57 #include <dev/pci/pcivar.h>
58 #include <dev/pci/pcireg.h>
59 #include <dev/pci/pcidevs.h>
60 #include <dev/pci/pciconf.h>
61 #include <dev/pci/pciidereg.h>
64 * PCI doesn't have any special needs; just use the generic versions
67 struct powerpc_bus_dma_tag pci_bus_dma_tag
= {
68 0, /* _bounce_thresh */
72 _bus_dmamap_load_mbuf
,
76 NULL
, /* _dmamap_sync */
85 genppc_pci_bus_maxdevs(pci_chipset_tag_t pc
, int busno
)
91 genppc_pci_intr_string(void *v
, pci_intr_handle_t ih
)
93 static char irqstr
[8]; /* 4 + 2 + NULL + sanity */
95 if (ih
== 0 || ih
>= ICU_LEN
96 /* XXX on macppc it's completely legal to have PCI interrupts on a slave PIC */
101 panic("pci_intr_string: bogus handle 0x%x", ih
);
103 sprintf(irqstr
, "irq %d", ih
);
109 genppc_pci_intr_evcnt(void *v
, pci_intr_handle_t ih
)
112 /* XXX for now, no evcnt parent reported */
117 genppc_pci_intr_establish(void *v
, pci_intr_handle_t ih
, int level
,
118 int (*func
)(void *), void *arg
)
121 if (ih
== 0 || ih
>= ICU_LEN
126 panic("pci_intr_establish: bogus handle 0x%x", ih
);
128 return intr_establish(ih
, IST_LEVEL
, level
, func
, arg
);
132 genppc_pci_intr_disestablish(void *v
, void *cookie
)
135 intr_disestablish(cookie
);
139 genppc_pci_conf_interrupt(pci_chipset_tag_t pct
, int bus
, int dev
, int pin
,
140 int swiz
, int *iline
)
146 genppc_pci_conf_hook(pci_chipset_tag_t pct
, int bus
, int dev
, int func
,
149 return (PCI_CONF_DEFAULT
);
153 genppc_pci_intr_map(struct pci_attach_args
*pa
, pci_intr_handle_t
*ihp
)
155 int pin
= pa
->pa_intrpin
;
156 int line
= pa
->pa_intrline
;
159 printf("%s: pin: %d, line: %d\n", __func__
, pin
, line
);
164 aprint_error("pci_intr_map: interrupt pin %d\n", pin
);
169 aprint_error("pci_intr_map: bad interrupt pin %d\n", pin
);
174 * Section 6.2.4, `Miscellaneous Functions', says that 255 means
175 * `unknown' or `no connection' on a PC. We assume that a device with
176 * `no connection' either doesn't have an interrupt (in which case the
177 * pin number should be 0, and would have been noticed above), or
178 * wasn't configured by the BIOS (in which case we punt, since there's
179 * no real way we can know how the interrupt lines are mapped in the
183 * Since IRQ 0 is only used by the clock, and we can't actually be sure
184 * that the BIOS did its job, we also recognize that as meaning that
185 * the BIOS has not configured the device.
187 if (line
== 0 || line
== 255) {
188 aprint_error("pci_intr_map: no mapping for pin %c\n", '@' + pin
);
191 if (line
>= ICU_LEN
) {
192 aprint_error("pci_intr_map: bad interrupt line %d\n", line
);
205 #ifdef __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH
206 #include <machine/isa_machdep.h>
209 void *genppc_pciide_machdep_compat_intr_establish(struct device
*,
210 struct pci_attach_args
*, int, int (*)(void *), void *);
213 genppc_pciide_machdep_compat_intr_establish(struct device
*dev
,
214 struct pci_attach_args
*pa
, int chan
, int (*func
)(void *), void *arg
)
220 irq
= PCIIDE_COMPAT_IRQ(chan
);
221 cookie
= isa_intr_establish(NULL
, irq
, IST_LEVEL
, IPL_BIO
, func
, arg
);
224 printf("%s: %s channel interrupting at irq %d\n", dev
->dv_xname
,
225 PCIIDE_CHANNEL_NAME(chan
), irq
);
228 panic("pciide_machdep_compat_intr_establish() called");
231 #endif /* __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH */