pci_machdep.c revision 1.23 1 /* $NetBSD: pci_machdep.c,v 1.23 2006/02/23 19:44:02 garbled Exp $ */
2
3 /*
4 * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
5 * Copyright (c) 1994 Charles M. Hannum. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Charles M. Hannum.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 /*
34 * Machine-specific functions for PCI autoconfiguration.
35 *
36 * On PCs, there are two methods of generating PCI configuration cycles.
37 * We try to detect the appropriate mechanism for this machine and set
38 * up a few function pointers to access the correct method directly.
39 */
40
41 #include <sys/cdefs.h>
42 __KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.23 2006/02/23 19:44:02 garbled Exp $");
43
44 #include <sys/types.h>
45 #include <sys/param.h>
46 #include <sys/time.h>
47 #include <sys/systm.h>
48 #include <sys/errno.h>
49 #include <sys/extent.h>
50 #include <sys/device.h>
51
52 #include <uvm/uvm_extern.h>
53
54 #define _POWERPC_BUS_DMA_PRIVATE
55 #include <machine/bus.h>
56 #include <machine/intr.h>
57 #include <machine/platform.h>
58
59 #include <dev/isa/isavar.h>
60
61 #include <dev/pci/pcivar.h>
62 #include <dev/pci/pcireg.h>
63 #include <dev/pci/pcidevs.h>
64 #include <dev/pci/pciconf.h>
65
66 /*
67 * PCI doesn't have any special needs; just use the generic versions
68 * of these functions.
69 */
70 struct powerpc_bus_dma_tag pci_bus_dma_tag = {
71 0, /* _bounce_thresh */
72 _bus_dmamap_create,
73 _bus_dmamap_destroy,
74 _bus_dmamap_load,
75 _bus_dmamap_load_mbuf,
76 _bus_dmamap_load_uio,
77 _bus_dmamap_load_raw,
78 _bus_dmamap_unload,
79 NULL, /* _dmamap_sync */
80 _bus_dmamem_alloc,
81 _bus_dmamem_free,
82 _bus_dmamem_map,
83 _bus_dmamem_unmap,
84 _bus_dmamem_mmap,
85 };
86
87 int
88 prep_pci_bus_maxdevs(void *v, int busno)
89 {
90
91 /*
92 * Bus number is irrelevant. Configuration Mechanism 1 is in
93 * use, can have devices 0-32 (i.e. the `normal' range).
94 */
95 return (32);
96 }
97
98
99 int
100 prep_pci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
101 {
102 int pin = pa->pa_intrpin;
103 int line = pa->pa_intrline;
104
105 if (pin == 0) {
106 /* No IRQ used. */
107 goto bad;
108 }
109
110 if (pin > 4) {
111 printf("pci_intr_map: bad interrupt pin %d\n", pin);
112 goto bad;
113 }
114
115 /*
116 * Section 6.2.4, `Miscellaneous Functions', says that 255 means
117 * `unknown' or `no connection' on a PC. We assume that a device with
118 * `no connection' either doesn't have an interrupt (in which case the
119 * pin number should be 0, and would have been noticed above), or
120 * wasn't configured by the BIOS (in which case we punt, since there's
121 * no real way we can know how the interrupt lines are mapped in the
122 * hardware).
123 *
124 * XXX
125 * Since IRQ 0 is only used by the clock, and we can't actually be sure
126 * that the BIOS did its job, we also recognize that as meaning that
127 * the BIOS has not configured the device.
128 */
129 if (line == 0 || line == 255) {
130 printf("pci_intr_map: no mapping for pin %c\n", '@' + pin);
131 goto bad;
132 } else {
133 if (line >= ICU_LEN) {
134 printf("pci_intr_map: bad interrupt line %d\n", line);
135 goto bad;
136 }
137 if (line == IRQ_SLAVE) {
138 printf("pci_intr_map: changed line 2 to line 9\n");
139 line = 9;
140 }
141 }
142
143 *ihp = line;
144 return 0;
145
146 bad:
147 *ihp = -1;
148 return 1;
149 }
150
151 const char *
152 prep_pci_intr_string(void *v, pci_intr_handle_t ih)
153 {
154 static char irqstr[8]; /* 4 + 2 + NULL + sanity */
155
156 if (ih == 0 || ih >= ICU_LEN || ih == IRQ_SLAVE)
157 panic("pci_intr_string: bogus handle 0x%x", ih);
158
159 sprintf(irqstr, "irq %d", ih);
160 return (irqstr);
161
162 }
163
164 const struct evcnt *
165 prep_pci_intr_evcnt(void *v, pci_intr_handle_t ih)
166 {
167
168 /* XXX for now, no evcnt parent reported */
169 return NULL;
170 }
171
172 void *
173 prep_pci_intr_establish(void *v, pci_intr_handle_t ih, int level,
174 int (*func)(void *), void *arg)
175 {
176
177 if (ih == 0 || ih >= ICU_LEN || ih == IRQ_SLAVE)
178 panic("pci_intr_establish: bogus handle 0x%x", ih);
179
180 return isa_intr_establish(NULL, ih, IST_LEVEL, level, func, arg);
181 }
182
183 void
184 prep_pci_intr_disestablish(void *v, void *cookie)
185 {
186
187 isa_intr_disestablish(NULL, cookie);
188 }
189
190 void
191 prep_pci_conf_interrupt(void *v, int bus, int dev, int pin,
192 int swiz, int *iline)
193 {
194
195 (*platform->pci_intr_fixup)(bus, dev, pin, swiz, iline);
196 }
197
198 int
199 prep_pci_conf_hook(void *v, int bus, int dev, int func, pcireg_t id)
200 {
201
202 /*
203 * The P9100 board found in some IBM machines cannot be
204 * over-configured.
205 */
206 if (PCI_VENDOR(id) == PCI_VENDOR_WEITEK &&
207 PCI_PRODUCT(id) == PCI_PRODUCT_WEITEK_P9100)
208 return 0;
209
210 /* We have allready mapped the MPIC2 if we have one, so leave it
211 alone */
212 if (PCI_VENDOR(id) == PCI_VENDOR_IBM &&
213 PCI_PRODUCT(id) == PCI_PRODUCT_IBM_MPIC2)
214 return 0;
215
216 return (PCI_CONF_DEFAULT);
217 }
218