pci_machdep_common.c revision 1.1.2.2 1 /* $NetBSD: pci_machdep_common.c,v 1.1.2.2 2007/05/01 17:46:57 garbled 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 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * Generic PowerPC functions for dealing with a PCI bridge. For most cases,
41 * these functions will work just fine, however, some machines may need
42 * specialized code, so those ports are free to write thier own functions
43 * and call those instead where appropriate.
44 */
45
46 #include <sys/cdefs.h>
47 __KERNEL_RCSID(0, "$NetBSD: pci_machdep_common.c,v 1.1.2.2 2007/05/01 17:46:57 garbled Exp $");
48
49 #include <sys/types.h>
50 #include <sys/param.h>
51 #include <sys/time.h>
52 #include <sys/systm.h>
53 #include <sys/errno.h>
54 #include <sys/extent.h>
55 #include <sys/device.h>
56 #include <sys/malloc.h>
57
58 #include <uvm/uvm_extern.h>
59
60 #define _POWERPC_BUS_DMA_PRIVATE
61 #include <machine/bus.h>
62 #include <machine/intr.h>
63
64 #include <dev/pci/pcivar.h>
65 #include <dev/pci/pcireg.h>
66 #include <dev/pci/pcidevs.h>
67 #include <dev/pci/pciconf.h>
68
69 /*
70 * PCI doesn't have any special needs; just use the generic versions
71 * of these functions.
72 */
73 struct powerpc_bus_dma_tag pci_bus_dma_tag = {
74 0, /* _bounce_thresh */
75 _bus_dmamap_create,
76 _bus_dmamap_destroy,
77 _bus_dmamap_load,
78 _bus_dmamap_load_mbuf,
79 _bus_dmamap_load_uio,
80 _bus_dmamap_load_raw,
81 _bus_dmamap_unload,
82 NULL, /* _dmamap_sync */
83 _bus_dmamem_alloc,
84 _bus_dmamem_free,
85 _bus_dmamem_map,
86 _bus_dmamem_unmap,
87 _bus_dmamem_mmap,
88 };
89
90 int
91 genppc_pci_bus_maxdevs(pci_chipset_tag_t pc, int busno)
92 {
93 return 32;
94 }
95
96 const char *
97 genppc_pci_intr_string(void *v, pci_intr_handle_t ih)
98 {
99 static char irqstr[8]; /* 4 + 2 + NULL + sanity */
100
101 if (ih == 0 || ih >= ICU_LEN || ih == IRQ_SLAVE)
102 panic("pci_intr_string: bogus handle 0x%x", ih);
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 if (ih == 0 || ih >= ICU_LEN || ih == IRQ_SLAVE)
123 panic("pci_intr_establish: bogus handle 0x%x", ih);
124
125 return intr_establish(ih, IST_LEVEL, level, func, arg);
126 }
127
128 void
129 genppc_pci_intr_disestablish(void *v, void *cookie)
130 {
131
132 intr_disestablish(cookie);
133 }
134
135 void
136 genppc_pci_conf_interrupt(void *v, int bus, int dev, int pin,
137 int swiz, int *iline)
138 {
139 /* do nothing */
140 }
141
142 int
143 genppc_pci_conf_hook(pci_chipset_tag_t pct, int bus, int dev, int func,
144 pcireg_t id)
145 {
146 return (PCI_CONF_DEFAULT);
147 }
148
149 int
150 genppc_pci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
151 {
152 int pin = pa->pa_intrpin;
153 int line = pa->pa_intrline;
154
155 #if DEBUG
156 printf("%s: pin: %d, line: %d\n", __FUNCTION__, pin, line);
157 #endif
158
159 if (pin == 0) {
160 /* No IRQ used. */
161 aprint_error("pci_intr_map: interrupt pin %d\n", pin);
162 goto bad;
163 }
164
165 if (pin > 4) {
166 aprint_error("pci_intr_map: bad interrupt pin %d\n", pin);
167 goto bad;
168 }
169
170 /*
171 * Section 6.2.4, `Miscellaneous Functions', says that 255 means
172 * `unknown' or `no connection' on a PC. We assume that a device with
173 * `no connection' either doesn't have an interrupt (in which case the
174 * pin number should be 0, and would have been noticed above), or
175 * wasn't configured by the BIOS (in which case we punt, since there's
176 * no real way we can know how the interrupt lines are mapped in the
177 * hardware).
178 *
179 * XXX
180 * Since IRQ 0 is only used by the clock, and we can't actually be sure
181 * that the BIOS did its job, we also recognize that as meaning that
182 * the BIOS has not configured the device.
183 */
184 if (line == 0 || line == 255) {
185 aprint_error("pci_intr_map: no mapping for pin %c\n", '@' + pin);
186 goto bad;
187 } else {
188 if (line >= ICU_LEN) {
189 aprint_error("pci_intr_map: bad interrupt line %d\n", line);
190 goto bad;
191 }
192 }
193
194 *ihp = line;
195 return 0;
196
197 bad:
198 *ihp = -1;
199 return 1;
200 }
201
202