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