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