pci_machdep.c revision 1.2 1 /* NetBSD: pci_machdep.c,v 1.12 2001/06/19 11:56:27 nonaka 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/types.h>
42 #include <sys/param.h>
43 #include <sys/time.h>
44 #include <sys/systm.h>
45 #include <sys/errno.h>
46 #include <sys/extent.h>
47 #include <sys/device.h>
48
49 #include <uvm/uvm_extern.h>
50
51 #define _POWERPC_BUS_DMA_PRIVATE
52 #include <machine/bus.h>
53 #include <machine/intr.h>
54
55 #include <dev/isa/isavar.h>
56
57 #include <dev/pci/pcivar.h>
58 #include <dev/pci/pcireg.h>
59 #include <dev/pci/pcidevs.h>
60 #include <dev/pci/pciconf.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 ibmnws_pci_bus_maxdevs(void *v, int busno)
85 {
86
87 /*
88 * Bus number is irrelevant. Configuration Mechanism 1 is in
89 * use, can have devices 0-32 (i.e. the `normal' range).
90 */
91 return (32);
92 }
93
94
95 int
96 ibmnws_pci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
97 {
98 int pin = pa->pa_intrpin;
99 int line = pa->pa_intrline;
100
101 if (pin == 0) {
102 /* No IRQ used. */
103 goto bad;
104 }
105
106 if (pin > 4) {
107 printf("pci_intr_map: bad interrupt pin %d\n", pin);
108 goto bad;
109 }
110
111 /*
112 * Section 6.2.4, `Miscellaneous Functions', says that 255 means
113 * `unknown' or `no connection' on a PC. We assume that a device with
114 * `no connection' either doesn't have an interrupt (in which case the
115 * pin number should be 0, and would have been noticed above), or
116 * wasn't configured by the BIOS (in which case we punt, since there's
117 * no real way we can know how the interrupt lines are mapped in the
118 * hardware).
119 *
120 * XXX
121 * Since IRQ 0 is only used by the clock, and we can't actually be sure
122 * that the BIOS did its job, we also recognize that as meaning that
123 * the BIOS has not configured the device.
124 */
125 if (line == 0 || line == 255) {
126 printf("pci_intr_map: no mapping for pin %c\n", '@' + pin);
127 goto bad;
128 } else {
129 if (line >= ICU_LEN) {
130 printf("pci_intr_map: bad interrupt line %d\n", line);
131 goto bad;
132 }
133 if (line == IRQ_SLAVE) {
134 printf("pci_intr_map: changed line 2 to line 9\n");
135 line = 9;
136 }
137 }
138
139 *ihp = line;
140 return 0;
141
142 bad:
143 *ihp = -1;
144 return 1;
145 }
146
147 const char *
148 ibmnws_pci_intr_string(void *v, pci_intr_handle_t ih)
149 {
150 static char irqstr[8]; /* 4 + 2 + NULL + sanity */
151
152 if (ih == 0 || ih >= ICU_LEN || ih == IRQ_SLAVE)
153 panic("pci_intr_string: bogus handle 0x%x", ih);
154
155 sprintf(irqstr, "irq %d", ih);
156 return (irqstr);
157
158 }
159
160 const struct evcnt *
161 ibmnws_pci_intr_evcnt(void *v, pci_intr_handle_t ih)
162 {
163
164 /* XXX for now, no evcnt parent reported */
165 return NULL;
166 }
167
168 void *
169 ibmnws_pci_intr_establish(void *v, pci_intr_handle_t ih, int level,
170 int (*func)(void *), void *arg)
171 {
172
173 if (ih == 0 || ih >= ICU_LEN || ih == IRQ_SLAVE)
174 panic("pci_intr_establish: bogus handle 0x%x", ih);
175
176 return isa_intr_establish(NULL, ih, IST_LEVEL, level, func, arg);
177 }
178
179 void
180 ibmnws_pci_intr_disestablish(void *v, void *cookie)
181 {
182
183 isa_intr_disestablish(NULL, cookie);
184 }
185
186 void
187 ibmnws_pci_conf_interrupt(void *v, int bus, int dev, int pin,
188 int swiz, int *iline)
189 {
190 }
191
192 int
193 ibmnws_pci_conf_hook(void *v, int bus, int dev, int func, pcireg_t id)
194 {
195
196 /*
197 * The P9100 board found in some IBM machines cannot be
198 * over-configured.
199 */
200 if (PCI_VENDOR(id) == PCI_VENDOR_WEITEK &&
201 PCI_PRODUCT(id) == PCI_PRODUCT_WEITEK_P9100)
202 return 0;
203
204 return (PCI_CONF_DEFAULT);
205 }
206