No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / powerpc / pci / pci_machdep_common.c
blobc25644d671cb5ca8a91bcae580d52a27843ede32
1 /* $NetBSD: pci_machdep_common.c,v 1.7 2008/01/17 23:42:59 garbled Exp $ */
3 /*-
4 * Copyright (c) 2007 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Tim Rightnour
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
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>
44 #include <sys/time.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
65 * of these functions.
67 struct powerpc_bus_dma_tag pci_bus_dma_tag = {
68 0, /* _bounce_thresh */
69 _bus_dmamap_create,
70 _bus_dmamap_destroy,
71 _bus_dmamap_load,
72 _bus_dmamap_load_mbuf,
73 _bus_dmamap_load_uio,
74 _bus_dmamap_load_raw,
75 _bus_dmamap_unload,
76 NULL, /* _dmamap_sync */
77 _bus_dmamem_alloc,
78 _bus_dmamem_free,
79 _bus_dmamem_map,
80 _bus_dmamem_unmap,
81 _bus_dmamem_mmap,
84 int
85 genppc_pci_bus_maxdevs(pci_chipset_tag_t pc, int busno)
87 return 32;
90 const char *
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 */
97 #ifdef IRQ_SLAVE
98 || ih == IRQ_SLAVE
99 #endif
101 panic("pci_intr_string: bogus handle 0x%x", ih);
103 sprintf(irqstr, "irq %d", ih);
104 return (irqstr);
108 const struct evcnt *
109 genppc_pci_intr_evcnt(void *v, pci_intr_handle_t ih)
112 /* XXX for now, no evcnt parent reported */
113 return NULL;
116 void *
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
122 #ifdef IRQ_SLAVE
123 || ih == IRQ_SLAVE
124 #endif
126 panic("pci_intr_establish: bogus handle 0x%x", ih);
128 return intr_establish(ih, IST_LEVEL, level, func, arg);
131 void
132 genppc_pci_intr_disestablish(void *v, void *cookie)
135 intr_disestablish(cookie);
138 void
139 genppc_pci_conf_interrupt(pci_chipset_tag_t pct, int bus, int dev, int pin,
140 int swiz, int *iline)
142 /* do nothing */
146 genppc_pci_conf_hook(pci_chipset_tag_t pct, int bus, int dev, int func,
147 pcireg_t id)
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;
158 #ifdef DEBUG
159 printf("%s: pin: %d, line: %d\n", __func__, pin, line);
160 #endif
162 if (pin == 0) {
163 /* No IRQ used. */
164 aprint_error("pci_intr_map: interrupt pin %d\n", pin);
165 goto bad;
168 if (pin > 4) {
169 aprint_error("pci_intr_map: bad interrupt pin %d\n", pin);
170 goto bad;
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
180 * hardware).
182 * XXX
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);
189 goto bad;
190 } else {
191 if (line >= ICU_LEN) {
192 aprint_error("pci_intr_map: bad interrupt line %d\n", line);
193 goto bad;
197 *ihp = line;
198 return 0;
200 bad:
201 *ihp = -1;
202 return 1;
205 #ifdef __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH
206 #include <machine/isa_machdep.h>
207 #include "isa.h"
209 void *genppc_pciide_machdep_compat_intr_establish(struct device *,
210 struct pci_attach_args *, int, int (*)(void *), void *);
212 void *
213 genppc_pciide_machdep_compat_intr_establish(struct device *dev,
214 struct pci_attach_args *pa, int chan, int (*func)(void *), void *arg)
216 #if NISA > 0
217 int irq;
218 void *cookie;
220 irq = PCIIDE_COMPAT_IRQ(chan);
221 cookie = isa_intr_establish(NULL, irq, IST_LEVEL, IPL_BIO, func, arg);
222 if (cookie == NULL)
223 return (NULL);
224 printf("%s: %s channel interrupting at irq %d\n", dev->dv_xname,
225 PCIIDE_CHANNEL_NAME(chan), irq);
226 return (cookie);
227 #else
228 panic("pciide_machdep_compat_intr_establish() called");
229 #endif
231 #endif /* __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH */