pci_machdep.c revision 1.13 1 /* $NetBSD: pci_machdep.c,v 1.13 2004/01/18 00:50:08 sekiya Exp $ */
2
3 /*
4 * Copyright (c) 2000 Soren S. Jorvang
5 * 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 for the
18 * NetBSD Project. See http://www.NetBSD.org/ for
19 * information about NetBSD.
20 * 4. The name of the author may not be used to endorse or promote products
21 * derived from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.13 2004/01/18 00:50:08 sekiya Exp $");
37
38 #include <sys/types.h>
39 #include <sys/param.h>
40 #include <sys/time.h>
41 #include <sys/systm.h>
42 #include <sys/errno.h>
43 #include <sys/device.h>
44
45 #include <uvm/uvm_extern.h>
46
47 #define _SGIMIPS_BUS_DMA_PRIVATE
48 #include <machine/bus.h>
49 #include <machine/intr.h>
50 #include <machine/sysconf.h>
51
52 #include <dev/pci/pcivar.h>
53 #include <dev/pci/pcireg.h>
54 #include <dev/pci/pcidevs.h>
55
56 /*
57 * PCI doesn't have any special needs; just use
58 * the generic versions of these functions.
59 */
60 struct sgimips_bus_dma_tag pci_bus_dma_tag = {
61 _bus_dmamap_create,
62 _bus_dmamap_destroy,
63 _bus_dmamap_load,
64 _bus_dmamap_load_mbuf,
65 _bus_dmamap_load_uio,
66 _bus_dmamap_load_raw,
67 _bus_dmamap_unload,
68 _bus_dmamap_sync_mips3,
69 _bus_dmamem_alloc,
70 _bus_dmamem_free,
71 _bus_dmamem_map,
72 _bus_dmamem_unmap,
73 _bus_dmamem_mmap,
74 };
75
76 void
77 pci_attach_hook(parent, self, pba)
78 struct device *parent, *self;
79 struct pcibus_attach_args *pba;
80 {
81 /* XXX */
82
83 return;
84 }
85
86 int
87 pci_bus_maxdevs(pc, busno)
88 pci_chipset_tag_t pc;
89 int busno;
90 {
91
92 if (busno == 0)
93 return 5; /* 2 on-board SCSI chips, slots 0, 1 and 2 */
94 else
95 return 0; /* XXX */
96 }
97
98 pcitag_t
99 pci_make_tag(pc, bus, device, function)
100 pci_chipset_tag_t pc;
101 int bus, device, function;
102 {
103
104 return (bus << 16) | (device << 11) | (function << 8);
105 }
106
107 void
108 pci_decompose_tag(pc, tag, bp, dp, fp)
109 pci_chipset_tag_t pc;
110 pcitag_t tag;
111 int *bp, *dp, *fp;
112 {
113
114 if (bp != NULL)
115 *bp = (tag >> 16) & 0xff;
116 if (dp != NULL)
117 *dp = (tag >> 11) & 0x1f;
118 if (fp != NULL)
119 *fp = (tag >> 8) & 0x07;
120 }
121
122 pcireg_t
123 pci_conf_read(pc, tag, reg)
124 pci_chipset_tag_t pc;
125 pcitag_t tag;
126 int reg;
127 {
128
129 return (*pc->pc_conf_read)(pc, tag, reg);
130 }
131
132 void
133 pci_conf_write(pc, tag, reg, data)
134 pci_chipset_tag_t pc;
135 pcitag_t tag;
136 int reg;
137 pcireg_t data;
138 {
139
140 (*pc->pc_conf_write)(pc, tag, reg, data);
141 }
142
143 int
144 pci_intr_map(pa, ihp)
145 struct pci_attach_args *pa;
146 pci_intr_handle_t *ihp;
147 {
148 pci_chipset_tag_t pc = pa->pa_pc;
149 pcitag_t intrtag = pa->pa_intrtag;
150 int pin = pa->pa_intrpin;
151 int bus, dev, func, start;
152
153 pci_decompose_tag(pc, intrtag, &bus, &dev, &func);
154
155 if (dev < 3 && pin != PCI_INTERRUPT_PIN_A)
156 panic("SCSI0 and SCSI1 must be hardwired!");
157
158 switch (pin) {
159 default:
160 case PCI_INTERRUPT_PIN_NONE:
161 return -1;
162
163 case PCI_INTERRUPT_PIN_A:
164 /*
165 * Each of SCSI{0,1}, & slots 0 - 2 has dedicated interrupt
166 * for pin A?
167 */
168 *ihp = dev + 7;
169 return 0;
170
171 case PCI_INTERRUPT_PIN_B:
172 start = 0;
173 break;
174 case PCI_INTERRUPT_PIN_C:
175 start = 1;
176 break;
177 case PCI_INTERRUPT_PIN_D:
178 start = 2;
179 break;
180 }
181
182 /* Pins B,C,D are mapped to PCI_SHARED0 - PCI_SHARED2 interrupts */
183 *ihp = 13 /* PCI_SHARED0 */ + (start + dev - 3) % 3;
184 return 0;
185 }
186
187 const char *
188 pci_intr_string(pc, ih)
189 pci_chipset_tag_t pc;
190 pci_intr_handle_t ih;
191 {
192 static char irqstr[32];
193
194 sprintf(irqstr, "crime interrupt %d", ih);
195 return irqstr;
196 }
197
198 const struct evcnt *
199 pci_intr_evcnt(pc, ih)
200 pci_chipset_tag_t pc;
201 pci_intr_handle_t ih;
202 {
203
204 /* XXX for now, no evcnt parent reported */
205 return NULL;
206 }
207
208 void *
209 pci_intr_establish(pc, ih, level, func, arg)
210 pci_chipset_tag_t pc;
211 pci_intr_handle_t ih;
212 int level, (*func)(void *);
213 void *arg;
214 {
215
216 return (void *)(*platform.intr_establish)(ih, 0, func, arg);
217 }
218
219 void
220 pci_intr_disestablish(pc, cookie)
221 pci_chipset_tag_t pc;
222 void *cookie;
223 {
224
225 panic("pci_intr_disestablish: not implemented");
226 }
227