pci_machdep.c revision 1.15 1 /* $NetBSD: pci_machdep.c,v 1.15 2004/09/29 04:06:52 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.15 2004/09/29 04:06:52 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(struct device *parent, struct device *self, struct pcibus_attach_args *pba)
78 {
79 /* XXX */
80
81 return;
82 }
83
84 int
85 pci_bus_maxdevs(pci_chipset_tag_t pc, int busno)
86 {
87
88 if (busno == 0)
89 return 5; /* 2 on-board SCSI chips, slots 0, 1 and 2 */
90 else
91 return 0; /* XXX */
92 }
93
94 pcitag_t
95 pci_make_tag(pci_chipset_tag_t pc, int bus, int device, int function)
96 {
97
98 return (bus << 16) | (device << 11) | (function << 8);
99 }
100
101 void
102 pci_decompose_tag(pci_chipset_tag_t pc, pcitag_t tag, int *bp, int *dp, int *fp)
103 {
104
105 if (bp != NULL)
106 *bp = (tag >> 16) & 0xff;
107 if (dp != NULL)
108 *dp = (tag >> 11) & 0x1f;
109 if (fp != NULL)
110 *fp = (tag >> 8) & 0x07;
111 }
112
113 pcireg_t
114 pci_conf_read(pci_chipset_tag_t pc, pcitag_t tag, int reg)
115 {
116
117 return (*pc->pc_conf_read)(pc, tag, reg);
118 }
119
120 void
121 pci_conf_write(pci_chipset_tag_t pc, pcitag_t tag, int reg, pcireg_t data)
122 {
123
124 (*pc->pc_conf_write)(pc, tag, reg, data);
125 }
126
127 int
128 pci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
129 {
130 pci_chipset_tag_t pc = pa->pa_pc;
131 pcitag_t intrtag = pa->pa_intrtag;
132 int pin = pa->pa_intrpin;
133 int bus, dev, func, start;
134
135 pci_decompose_tag(pc, intrtag, &bus, &dev, &func);
136
137 if (dev < 3 && pin != PCI_INTERRUPT_PIN_A)
138 panic("SCSI0 and SCSI1 must be hardwired!");
139
140 switch (pin) {
141 default:
142 case PCI_INTERRUPT_PIN_NONE:
143 return -1;
144
145 case PCI_INTERRUPT_PIN_A:
146 /*
147 * Each of SCSI{0,1}, & slots 0 - 2 has dedicated interrupt
148 * for pin A?
149 */
150 *ihp = dev + 7;
151 return 0;
152
153 case PCI_INTERRUPT_PIN_B:
154 start = 0;
155 break;
156 case PCI_INTERRUPT_PIN_C:
157 start = 1;
158 break;
159 case PCI_INTERRUPT_PIN_D:
160 start = 2;
161 break;
162 }
163
164 /* Pins B,C,D are mapped to PCI_SHARED0 - PCI_SHARED2 interrupts */
165 *ihp = 13 /* PCI_SHARED0 */ + (start + dev - 3) % 3;
166 return 0;
167 }
168
169 const char *
170 pci_intr_string(pci_chipset_tag_t pc, pci_intr_handle_t ih)
171 {
172 static char irqstr[32];
173
174 sprintf(irqstr, "crime interrupt %d", ih);
175 return irqstr;
176 }
177
178 const struct evcnt *
179 pci_intr_evcnt(pci_chipset_tag_t pc, pci_intr_handle_t ih)
180 {
181
182 /* XXX for now, no evcnt parent reported */
183 return NULL;
184 }
185
186 void *
187 pci_intr_establish(pci_chipset_tag_t pc, pci_intr_handle_t ih, int level,
188 int (*func)(void *), void *arg)
189 {
190
191 return (void *)(pc->intr_establish)(ih, 0, func, arg);
192 }
193
194 void
195 pci_intr_disestablish(pci_chipset_tag_t pc, void *cookie)
196 {
197
198 (pc->intr_disestablish)(cookie);
199 }
200