pci_machdep.c revision 1.8 1 /* $NetBSD: pci_machdep.c,v 1.8 2003/10/04 09:19:23 tsutsui 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.8 2003/10/04 09:19:23 tsutsui 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
51 #include <dev/pci/pcivar.h>
52 #include <dev/pci/pcireg.h>
53 #include <dev/pci/pcidevs.h>
54
55 /*
56 * PCI doesn't have any special needs; just use
57 * the generic versions of these functions.
58 */
59 struct sgimips_bus_dma_tag pci_bus_dma_tag = {
60 _bus_dmamap_create,
61 _bus_dmamap_destroy,
62 _bus_dmamap_load,
63 _bus_dmamap_load_mbuf,
64 _bus_dmamap_load_uio,
65 _bus_dmamap_load_raw,
66 _bus_dmamap_unload,
67 _bus_dmamap_sync,
68 _bus_dmamem_alloc,
69 _bus_dmamem_free,
70 _bus_dmamem_map,
71 _bus_dmamem_unmap,
72 _bus_dmamem_mmap,
73 };
74
75 void
76 pci_attach_hook(parent, self, pba)
77 struct device *parent, *self;
78 struct pcibus_attach_args *pba;
79 {
80 /* XXX */
81
82 return;
83 }
84
85 int
86 pci_bus_maxdevs(pc, busno)
87 pci_chipset_tag_t pc;
88 int busno;
89 {
90
91 return 5; /* 2 on-board SCSI chips, slots 0, 1 and 2 */
92 }
93
94 pcitag_t
95 pci_make_tag(pc, bus, device, function)
96 pci_chipset_tag_t pc;
97 int bus, device, function;
98 {
99
100 return (bus << 16) | (device << 11) | (function << 8);
101 }
102
103 void
104 pci_decompose_tag(pc, tag, bp, dp, fp)
105 pci_chipset_tag_t pc;
106 pcitag_t tag;
107 int *bp, *dp, *fp;
108 {
109
110 if (bp != NULL)
111 *bp = (tag >> 16) & 0xff;
112 if (dp != NULL)
113 *dp = (tag >> 11) & 0x1f;
114 if (fp != NULL)
115 *fp = (tag >> 8) & 0x07;
116 }
117
118 pcireg_t
119 pci_conf_read(pc, tag, reg)
120 pci_chipset_tag_t pc;
121 pcitag_t tag;
122 int reg;
123 {
124
125 return (*pc->pc_conf_read)(pc, tag, reg);
126 }
127
128 void
129 pci_conf_write(pc, tag, reg, data)
130 pci_chipset_tag_t pc;
131 pcitag_t tag;
132 int reg;
133 pcireg_t data;
134 {
135
136 (*pc->pc_conf_write)(pc, tag, reg, data);
137 }
138
139 int
140 pci_intr_map(pa, ihp)
141 struct pci_attach_args *pa;
142 pci_intr_handle_t *ihp;
143 {
144 pci_chipset_tag_t pc = pa->pa_pc;
145 pcitag_t intrtag = pa->pa_intrtag;
146 int pin = pa->pa_intrpin;
147 int bus, dev, func, start;
148
149 pci_decompose_tag(pc, intrtag, &bus, &dev, &func);
150
151 if (dev < 3 && pin != PCI_INTERRUPT_PIN_A)
152 panic("SCSI0 and SCSI1 must be hardwired!");
153
154 switch (pin) {
155 case PCI_INTERRUPT_PIN_NONE:
156 return -1;
157
158 case PCI_INTERRUPT_PIN_A:
159 /*
160 * Each of SCSI{0,1}, & slots 0 - 2 has dedicated interrupt
161 * for pin A?
162 */
163 *ihp = dev + 7;
164 return 0;
165
166 case PCI_INTERRUPT_PIN_B:
167 start = 0;
168 break;
169 case PCI_INTERRUPT_PIN_C:
170 start = 1;
171 break;
172 case PCI_INTERRUPT_PIN_D:
173 start = 2;
174 break;
175 }
176
177 /* Pins B,C,D are mapped to PCI_SHARED0 - PCI_SHARED2 interrupts */
178 *ihp = 13 /* PCI_SHARED0 */ + (start + dev - 3) % 3;
179 return 0;
180 }
181
182 const char *
183 pci_intr_string(pc, ih)
184 pci_chipset_tag_t pc;
185 pci_intr_handle_t ih;
186 {
187 static char irqstr[32];
188
189 sprintf(irqstr, "crime interrupt %d", ih);
190 return irqstr;
191 }
192
193 const struct evcnt *
194 pci_intr_evcnt(pc, ih)
195 pci_chipset_tag_t pc;
196 pci_intr_handle_t ih;
197 {
198
199 /* XXX for now, no evcnt parent reported */
200 return NULL;
201 }
202
203 extern void * crime_intr_establish(int, int, int, int (*)(void *), void *);
204
205 void *
206 pci_intr_establish(pc, ih, level, func, arg)
207 pci_chipset_tag_t pc;
208 pci_intr_handle_t ih;
209 int level, (*func)(void *);
210 void *arg;
211 {
212
213 return crime_intr_establish(ih, 0, 0, func, arg);
214 }
215
216 void
217 pci_intr_disestablish(pc, cookie)
218 pci_chipset_tag_t pc;
219 void *cookie;
220 {
221
222 panic("pci_intr_disestablish: not implemented");
223 }
224