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