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