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