pci_machdep_common.c revision 1.13 1 /* $NetBSD: pci_machdep_common.c,v 1.13 2011/06/22 18:06:34 matt Exp $ */
2
3 /*-
4 * Copyright (c) 2007 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Tim Rightnour
9 *
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.
18 *
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.
30 */
31
32 /*
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.
37 */
38
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: pci_machdep_common.c,v 1.13 2011/06/22 18:06:34 matt Exp $");
41
42 #define _POWERPC_BUS_DMA_PRIVATE
43
44 #include <sys/param.h>
45 #include <sys/bus.h>
46 #include <sys/device.h>
47 #include <sys/errno.h>
48 #include <sys/extent.h>
49 #include <sys/intr.h>
50 #include <sys/malloc.h>
51 #include <sys/systm.h>
52 #include <sys/time.h>
53
54 #include <uvm/uvm_extern.h>
55
56 #include <dev/pci/pcivar.h>
57 #include <dev/pci/pcireg.h>
58 #include <dev/pci/pcidevs.h>
59 #include <dev/pci/pciconf.h>
60 #include <dev/pci/pciidereg.h>
61
62 /*
63 * PCI doesn't have any special needs; just use the generic versions
64 * of these functions.
65 */
66 struct powerpc_bus_dma_tag pci_bus_dma_tag = {
67 0, /* _bounce_thresh */
68 _bus_dmamap_create,
69 _bus_dmamap_destroy,
70 _bus_dmamap_load,
71 _bus_dmamap_load_mbuf,
72 _bus_dmamap_load_uio,
73 _bus_dmamap_load_raw,
74 _bus_dmamap_unload,
75 NULL, /* _dmamap_sync */
76 _bus_dmamem_alloc,
77 _bus_dmamem_free,
78 _bus_dmamem_map,
79 _bus_dmamem_unmap,
80 _bus_dmamem_mmap,
81 };
82
83 int
84 genppc_pci_bus_maxdevs(void *v, int busno)
85 {
86 return 32;
87 }
88
89 const char *
90 genppc_pci_intr_string(void *v, pci_intr_handle_t ih)
91 {
92 static char irqstr[8]; /* 4 + 2 + NULL + sanity */
93
94 #ifdef ICU_LEN
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
100 )
101 panic("pci_intr_string: bogus handle 0x%x", ih);
102 #endif
103
104 sprintf(irqstr, "irq %d", ih);
105 return (irqstr);
106
107 }
108
109 const struct evcnt *
110 genppc_pci_intr_evcnt(void *v, pci_intr_handle_t ih)
111 {
112
113 /* XXX for now, no evcnt parent reported */
114 return NULL;
115 }
116
117 void *
118 genppc_pci_intr_establish(void *v, pci_intr_handle_t ih, int level,
119 int (*func)(void *), void *arg)
120 {
121
122 #ifdef ICU_LEN
123 if (ih == 0 || ih >= ICU_LEN
124 #ifdef IRQ_SLAVE
125 || ih == IRQ_SLAVE
126 #endif
127 )
128 panic("pci_intr_establish: bogus handle 0x%x", ih);
129 #endif
130
131 return intr_establish(ih, IST_LEVEL, level, func, arg);
132 }
133
134 void
135 genppc_pci_intr_disestablish(void *v, void *cookie)
136 {
137
138 intr_disestablish(cookie);
139 }
140
141 int
142 genppc_pci_intr_setattr(void *v, pci_intr_handle_t *ihp, int attr,
143 uint64_t data)
144 {
145
146 return ENODEV;
147 }
148
149 void
150 genppc_pci_conf_interrupt(void *v, int bus, int dev, int pin,
151 int swiz, int *iline)
152 {
153 /* do nothing */
154 }
155
156 int
157 genppc_pci_conf_hook(void *v, int bus, int dev, int func, pcireg_t id)
158 {
159 return (PCI_CONF_DEFAULT);
160 }
161
162 int
163 genppc_pci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
164 {
165 int pin = pa->pa_intrpin;
166 int line = pa->pa_intrline;
167
168 #ifdef DEBUG
169 printf("%s: pin: %d, line: %d\n", __func__, pin, line);
170 #endif
171
172 if (pin == 0) {
173 /* No IRQ used. */
174 aprint_error("pci_intr_map: interrupt pin %d\n", pin);
175 goto bad;
176 }
177
178 if (pin > 4) {
179 aprint_error("pci_intr_map: bad interrupt pin %d\n", pin);
180 goto bad;
181 }
182
183 /*
184 * Section 6.2.4, `Miscellaneous Functions', says that 255 means
185 * `unknown' or `no connection' on a PC. We assume that a device with
186 * `no connection' either doesn't have an interrupt (in which case the
187 * pin number should be 0, and would have been noticed above), or
188 * wasn't configured by the BIOS (in which case we punt, since there's
189 * no real way we can know how the interrupt lines are mapped in the
190 * hardware).
191 *
192 * XXX
193 * Since IRQ 0 is only used by the clock, and we can't actually be sure
194 * that the BIOS did its job, we also recognize that as meaning that
195 * the BIOS has not configured the device.
196 */
197 if (line == 0 || line == 255) {
198 aprint_error("pci_intr_map: no mapping for pin %c\n", '@' + pin);
199 goto bad;
200 #ifdef ICU_LEN
201 } else {
202 if (line >= ICU_LEN) {
203 aprint_error("pci_intr_map: bad interrupt line %d\n", line);
204 goto bad;
205 }
206 #endif
207 }
208
209 *ihp = line;
210 return 0;
211
212 bad:
213 *ihp = -1;
214 return 1;
215 }
216
217 #ifdef __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH
218 #include <machine/isa_machdep.h>
219 #include "isa.h"
220
221 void *genppc_pciide_machdep_compat_intr_establish(device_t,
222 struct pci_attach_args *, int, int (*)(void *), void *);
223
224 void *
225 genppc_pciide_machdep_compat_intr_establish(device_t dev,
226 struct pci_attach_args *pa, int chan, int (*func)(void *), void *arg)
227 {
228 #if NISA > 0
229 int irq;
230 void *cookie;
231
232 irq = PCIIDE_COMPAT_IRQ(chan);
233 cookie = isa_intr_establish(NULL, irq, IST_LEVEL, IPL_BIO, func, arg);
234 if (cookie == NULL)
235 return (NULL);
236 aprint_normal_dev(dev, "%s channel interrupting at irq %d\n",
237 PCIIDE_CHANNEL_NAME(chan), irq);
238 return (cookie);
239 #else
240 panic("pciide_machdep_compat_intr_establish() called");
241 #endif
242 }
243 #endif /* __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH */
244