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