pci_machdep_common.c revision 1.2.4.3 1 1.2.4.3 yamt /* $NetBSD: pci_machdep_common.c,v 1.2.4.3 2008/01/21 09:38:25 yamt Exp $ */
2 1.2.4.2 yamt
3 1.2.4.2 yamt /*-
4 1.2.4.2 yamt * Copyright (c) 2007 The NetBSD Foundation, Inc.
5 1.2.4.2 yamt * All rights reserved.
6 1.2.4.2 yamt *
7 1.2.4.2 yamt * This code is derived from software contributed to The NetBSD Foundation
8 1.2.4.2 yamt * by Tim Rightnour
9 1.2.4.2 yamt *
10 1.2.4.2 yamt * Redistribution and use in source and binary forms, with or without
11 1.2.4.2 yamt * modification, are permitted provided that the following conditions
12 1.2.4.2 yamt * are met:
13 1.2.4.2 yamt * 1. Redistributions of source code must retain the above copyright
14 1.2.4.2 yamt * notice, this list of conditions and the following disclaimer.
15 1.2.4.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
16 1.2.4.2 yamt * notice, this list of conditions and the following disclaimer in the
17 1.2.4.2 yamt * documentation and/or other materials provided with the distribution.
18 1.2.4.2 yamt * 3. All advertising materials mentioning features or use of this software
19 1.2.4.2 yamt * must display the following acknowledgement:
20 1.2.4.2 yamt * This product includes software developed by the NetBSD
21 1.2.4.2 yamt * Foundation, Inc. and its contributors.
22 1.2.4.2 yamt * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.2.4.2 yamt * contributors may be used to endorse or promote products derived
24 1.2.4.2 yamt * from this software without specific prior written permission.
25 1.2.4.2 yamt *
26 1.2.4.2 yamt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.2.4.2 yamt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.2.4.2 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.2.4.2 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.2.4.2 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.2.4.2 yamt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.2.4.2 yamt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.2.4.2 yamt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.2.4.2 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.2.4.2 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.2.4.2 yamt * POSSIBILITY OF SUCH DAMAGE.
37 1.2.4.2 yamt */
38 1.2.4.2 yamt
39 1.2.4.2 yamt /*
40 1.2.4.2 yamt * Generic PowerPC functions for dealing with a PCI bridge. For most cases,
41 1.2.4.2 yamt * these functions will work just fine, however, some machines may need
42 1.2.4.2 yamt * specialized code, so those ports are free to write thier own functions
43 1.2.4.2 yamt * and call those instead where appropriate.
44 1.2.4.2 yamt */
45 1.2.4.2 yamt
46 1.2.4.2 yamt #include <sys/cdefs.h>
47 1.2.4.3 yamt __KERNEL_RCSID(0, "$NetBSD: pci_machdep_common.c,v 1.2.4.3 2008/01/21 09:38:25 yamt Exp $");
48 1.2.4.2 yamt
49 1.2.4.2 yamt #include <sys/types.h>
50 1.2.4.2 yamt #include <sys/param.h>
51 1.2.4.2 yamt #include <sys/time.h>
52 1.2.4.2 yamt #include <sys/systm.h>
53 1.2.4.2 yamt #include <sys/errno.h>
54 1.2.4.2 yamt #include <sys/extent.h>
55 1.2.4.2 yamt #include <sys/device.h>
56 1.2.4.2 yamt #include <sys/malloc.h>
57 1.2.4.2 yamt
58 1.2.4.2 yamt #include <uvm/uvm_extern.h>
59 1.2.4.2 yamt
60 1.2.4.2 yamt #define _POWERPC_BUS_DMA_PRIVATE
61 1.2.4.2 yamt #include <machine/bus.h>
62 1.2.4.2 yamt #include <machine/intr.h>
63 1.2.4.2 yamt
64 1.2.4.2 yamt #include <dev/pci/pcivar.h>
65 1.2.4.2 yamt #include <dev/pci/pcireg.h>
66 1.2.4.2 yamt #include <dev/pci/pcidevs.h>
67 1.2.4.2 yamt #include <dev/pci/pciconf.h>
68 1.2.4.3 yamt #include <dev/pci/pciidereg.h>
69 1.2.4.2 yamt
70 1.2.4.2 yamt /*
71 1.2.4.2 yamt * PCI doesn't have any special needs; just use the generic versions
72 1.2.4.2 yamt * of these functions.
73 1.2.4.2 yamt */
74 1.2.4.2 yamt struct powerpc_bus_dma_tag pci_bus_dma_tag = {
75 1.2.4.2 yamt 0, /* _bounce_thresh */
76 1.2.4.2 yamt _bus_dmamap_create,
77 1.2.4.2 yamt _bus_dmamap_destroy,
78 1.2.4.2 yamt _bus_dmamap_load,
79 1.2.4.2 yamt _bus_dmamap_load_mbuf,
80 1.2.4.2 yamt _bus_dmamap_load_uio,
81 1.2.4.2 yamt _bus_dmamap_load_raw,
82 1.2.4.2 yamt _bus_dmamap_unload,
83 1.2.4.2 yamt NULL, /* _dmamap_sync */
84 1.2.4.2 yamt _bus_dmamem_alloc,
85 1.2.4.2 yamt _bus_dmamem_free,
86 1.2.4.2 yamt _bus_dmamem_map,
87 1.2.4.2 yamt _bus_dmamem_unmap,
88 1.2.4.2 yamt _bus_dmamem_mmap,
89 1.2.4.2 yamt };
90 1.2.4.3 yamt
91 1.2.4.2 yamt int
92 1.2.4.2 yamt genppc_pci_bus_maxdevs(pci_chipset_tag_t pc, int busno)
93 1.2.4.2 yamt {
94 1.2.4.2 yamt return 32;
95 1.2.4.2 yamt }
96 1.2.4.2 yamt
97 1.2.4.2 yamt const char *
98 1.2.4.2 yamt genppc_pci_intr_string(void *v, pci_intr_handle_t ih)
99 1.2.4.2 yamt {
100 1.2.4.2 yamt static char irqstr[8]; /* 4 + 2 + NULL + sanity */
101 1.2.4.2 yamt
102 1.2.4.2 yamt if (ih == 0 || ih >= ICU_LEN
103 1.2.4.2 yamt /* XXX on macppc it's completely legal to have PCI interrupts on a slave PIC */
104 1.2.4.2 yamt #ifdef IRQ_SLAVE
105 1.2.4.2 yamt || ih == IRQ_SLAVE
106 1.2.4.2 yamt #endif
107 1.2.4.2 yamt )
108 1.2.4.2 yamt panic("pci_intr_string: bogus handle 0x%x", ih);
109 1.2.4.2 yamt
110 1.2.4.2 yamt sprintf(irqstr, "irq %d", ih);
111 1.2.4.2 yamt return (irqstr);
112 1.2.4.2 yamt
113 1.2.4.2 yamt }
114 1.2.4.2 yamt
115 1.2.4.2 yamt const struct evcnt *
116 1.2.4.2 yamt genppc_pci_intr_evcnt(void *v, pci_intr_handle_t ih)
117 1.2.4.2 yamt {
118 1.2.4.2 yamt
119 1.2.4.2 yamt /* XXX for now, no evcnt parent reported */
120 1.2.4.2 yamt return NULL;
121 1.2.4.2 yamt }
122 1.2.4.2 yamt
123 1.2.4.2 yamt void *
124 1.2.4.2 yamt genppc_pci_intr_establish(void *v, pci_intr_handle_t ih, int level,
125 1.2.4.2 yamt int (*func)(void *), void *arg)
126 1.2.4.2 yamt {
127 1.2.4.2 yamt
128 1.2.4.2 yamt if (ih == 0 || ih >= ICU_LEN
129 1.2.4.2 yamt #ifdef IRQ_SLAVE
130 1.2.4.2 yamt || ih == IRQ_SLAVE
131 1.2.4.2 yamt #endif
132 1.2.4.2 yamt )
133 1.2.4.2 yamt panic("pci_intr_establish: bogus handle 0x%x", ih);
134 1.2.4.2 yamt
135 1.2.4.2 yamt return intr_establish(ih, IST_LEVEL, level, func, arg);
136 1.2.4.2 yamt }
137 1.2.4.2 yamt
138 1.2.4.2 yamt void
139 1.2.4.2 yamt genppc_pci_intr_disestablish(void *v, void *cookie)
140 1.2.4.2 yamt {
141 1.2.4.2 yamt
142 1.2.4.2 yamt intr_disestablish(cookie);
143 1.2.4.2 yamt }
144 1.2.4.2 yamt
145 1.2.4.2 yamt void
146 1.2.4.2 yamt genppc_pci_conf_interrupt(pci_chipset_tag_t pct, int bus, int dev, int pin,
147 1.2.4.2 yamt int swiz, int *iline)
148 1.2.4.2 yamt {
149 1.2.4.2 yamt /* do nothing */
150 1.2.4.2 yamt }
151 1.2.4.2 yamt
152 1.2.4.2 yamt int
153 1.2.4.2 yamt genppc_pci_conf_hook(pci_chipset_tag_t pct, int bus, int dev, int func,
154 1.2.4.2 yamt pcireg_t id)
155 1.2.4.2 yamt {
156 1.2.4.2 yamt return (PCI_CONF_DEFAULT);
157 1.2.4.2 yamt }
158 1.2.4.2 yamt
159 1.2.4.2 yamt int
160 1.2.4.2 yamt genppc_pci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
161 1.2.4.2 yamt {
162 1.2.4.2 yamt int pin = pa->pa_intrpin;
163 1.2.4.2 yamt int line = pa->pa_intrline;
164 1.2.4.2 yamt
165 1.2.4.3 yamt #ifdef DEBUG
166 1.2.4.3 yamt printf("%s: pin: %d, line: %d\n", __func__, pin, line);
167 1.2.4.2 yamt #endif
168 1.2.4.2 yamt
169 1.2.4.2 yamt if (pin == 0) {
170 1.2.4.2 yamt /* No IRQ used. */
171 1.2.4.2 yamt aprint_error("pci_intr_map: interrupt pin %d\n", pin);
172 1.2.4.2 yamt goto bad;
173 1.2.4.2 yamt }
174 1.2.4.2 yamt
175 1.2.4.2 yamt if (pin > 4) {
176 1.2.4.2 yamt aprint_error("pci_intr_map: bad interrupt pin %d\n", pin);
177 1.2.4.2 yamt goto bad;
178 1.2.4.2 yamt }
179 1.2.4.2 yamt
180 1.2.4.2 yamt /*
181 1.2.4.2 yamt * Section 6.2.4, `Miscellaneous Functions', says that 255 means
182 1.2.4.2 yamt * `unknown' or `no connection' on a PC. We assume that a device with
183 1.2.4.2 yamt * `no connection' either doesn't have an interrupt (in which case the
184 1.2.4.2 yamt * pin number should be 0, and would have been noticed above), or
185 1.2.4.2 yamt * wasn't configured by the BIOS (in which case we punt, since there's
186 1.2.4.2 yamt * no real way we can know how the interrupt lines are mapped in the
187 1.2.4.2 yamt * hardware).
188 1.2.4.2 yamt *
189 1.2.4.2 yamt * XXX
190 1.2.4.2 yamt * Since IRQ 0 is only used by the clock, and we can't actually be sure
191 1.2.4.2 yamt * that the BIOS did its job, we also recognize that as meaning that
192 1.2.4.2 yamt * the BIOS has not configured the device.
193 1.2.4.2 yamt */
194 1.2.4.2 yamt if (line == 0 || line == 255) {
195 1.2.4.2 yamt aprint_error("pci_intr_map: no mapping for pin %c\n", '@' + pin);
196 1.2.4.2 yamt goto bad;
197 1.2.4.2 yamt } else {
198 1.2.4.2 yamt if (line >= ICU_LEN) {
199 1.2.4.2 yamt aprint_error("pci_intr_map: bad interrupt line %d\n", line);
200 1.2.4.2 yamt goto bad;
201 1.2.4.2 yamt }
202 1.2.4.2 yamt }
203 1.2.4.2 yamt
204 1.2.4.2 yamt *ihp = line;
205 1.2.4.2 yamt return 0;
206 1.2.4.2 yamt
207 1.2.4.2 yamt bad:
208 1.2.4.2 yamt *ihp = -1;
209 1.2.4.2 yamt return 1;
210 1.2.4.2 yamt }
211 1.2.4.2 yamt
212 1.2.4.3 yamt #ifdef __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH
213 1.2.4.3 yamt #include <machine/isa_machdep.h>
214 1.2.4.3 yamt #include "isa.h"
215 1.2.4.3 yamt
216 1.2.4.3 yamt void *genppc_pciide_machdep_compat_intr_establish(struct device *,
217 1.2.4.3 yamt struct pci_attach_args *, int, int (*)(void *), void *);
218 1.2.4.3 yamt
219 1.2.4.3 yamt void *
220 1.2.4.3 yamt genppc_pciide_machdep_compat_intr_establish(struct device *dev,
221 1.2.4.3 yamt struct pci_attach_args *pa, int chan, int (*func)(void *), void *arg)
222 1.2.4.3 yamt {
223 1.2.4.3 yamt #if NISA > 0
224 1.2.4.3 yamt int irq;
225 1.2.4.3 yamt void *cookie;
226 1.2.4.3 yamt
227 1.2.4.3 yamt irq = PCIIDE_COMPAT_IRQ(chan);
228 1.2.4.3 yamt cookie = isa_intr_establish(NULL, irq, IST_LEVEL, IPL_BIO, func, arg);
229 1.2.4.3 yamt if (cookie == NULL)
230 1.2.4.3 yamt return (NULL);
231 1.2.4.3 yamt printf("%s: %s channel interrupting at irq %d\n", dev->dv_xname,
232 1.2.4.3 yamt PCIIDE_CHANNEL_NAME(chan), irq);
233 1.2.4.3 yamt return (cookie);
234 1.2.4.3 yamt #else
235 1.2.4.3 yamt panic("pciide_machdep_compat_intr_establish() called");
236 1.2.4.3 yamt #endif
237 1.2.4.3 yamt }
238 1.2.4.3 yamt #endif /* __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH */
239