pci_machdep.c revision 1.2 1 /* $NetBSD: pci_machdep.c,v 1.2 1995/08/03 00:33:58 cgd Exp $ */
2
3 /*
4 * Copyright (c) 1994 Charles Hannum. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Charles Hannum.
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 /*
33 * Machine-specific functions for PCI autoconfiguration.
34 */
35
36 #include <sys/types.h>
37 #include <sys/param.h>
38 #include <sys/time.h>
39 #include <sys/systm.h>
40 #include <sys/errno.h>
41 #include <sys/device.h>
42
43 #include <vm/vm.h>
44
45 #include <dev/isa/isavar.h>
46 #include <dev/pci/pcivar.h>
47 #include <dev/pci/pcireg.h>
48 #include <dev/pci/pcidevs.h>
49 #include <alpha/pci/pci_chipset.h>
50
51 #include "pcivga.h"
52 #include "tga.h"
53
54 int pcimatch __P((struct device *, void *, void *));
55 void pciattach __P((struct device *, struct device *, void *));
56
57 struct cfdriver pcicd = {
58 NULL, "pci", pcimatch, pciattach, DV_DULL, sizeof(struct device)
59 };
60
61 int
62 pcimatch(parent, match, aux)
63 struct device *parent;
64 void *match, *aux;
65 {
66
67 return 1;
68 }
69
70 void
71 pciattach(parent, self, aux)
72 struct device *parent, *self;
73 void *aux;
74 {
75
76 printf("\n");
77 (*pci_cs_fcns->cs_setup)();
78 (*pci_cfg_fcns->cfg_attach)(parent, self, aux);
79 }
80
81 pcitag_t
82 pci_make_tag(bus, device, function)
83 int bus, device, function;
84 {
85
86 return (*pci_cs_fcns->cs_make_tag)(bus, device, function);
87 }
88
89 pcireg_t
90 pci_conf_read(tag, offset)
91 pcitag_t tag;
92 int offset; /* XXX */
93 {
94
95 return (*pci_cs_fcns->cs_conf_read)(tag, offset);
96 }
97
98 void
99 pci_conf_write(tag, offset, data)
100 pcitag_t tag;
101 int offset; /* XXX */
102 pcireg_t data;
103 {
104
105 (*pci_cs_fcns->cs_conf_write)(tag, offset, data);
106 }
107
108 int
109 pci_map_io(tag, reg, iobasep)
110 pcitag_t tag;
111 int reg;
112 int *iobasep;
113 {
114
115 return (*pci_cs_fcns->cs_map_io)(tag, reg, iobasep);
116 }
117
118 int
119 pci_map_mem(tag, reg, vap, pap)
120 pcitag_t tag;
121 int reg;
122 vm_offset_t *vap, *pap;
123 {
124
125 return (*pci_cs_fcns->cs_map_mem)(tag, reg, vap, pap);
126 }
127
128 int
129 pcidma_map(addr, size, mappings)
130 caddr_t addr;
131 vm_size_t size;
132 vm_offset_t *mappings;
133 {
134
135 return (*pci_cs_fcns->cs_pcidma_map)(addr, size, mappings);
136 }
137
138 void
139 pcidma_unmap(addr, size, nmappings, mappings)
140 caddr_t addr;
141 vm_size_t size;
142 int nmappings;
143 vm_offset_t *mappings;
144 {
145
146 (*pci_cs_fcns->cs_pcidma_unmap)(addr, size, nmappings, mappings);
147 }
148
149 void *
150 pci_map_int(tag, level, func, arg)
151 pcitag_t tag;
152 pci_intrlevel level;
153 int (*func) __P((void *));
154 void *arg;
155 {
156 pcireg_t data;
157 int pin;
158
159 data = pci_conf_read(tag, PCI_INTERRUPT_REG);
160
161 pin = PCI_INTERRUPT_PIN(data);
162
163 if (pin == 0) {
164 /* No IRQ used. */
165 return 0;
166 }
167
168 if (pin > 4) {
169 printf("pci_map_int: bad interrupt pin %d\n", pin);
170 return NULL;
171 }
172
173 return (*pci_cfg_fcns->cfg_map_int)(tag, level, func, arg, pin);
174 }
175
176 isa_intrlevel
177 pcilevel_to_isa(level)
178 pci_intrlevel level;
179 {
180
181 switch (level) {
182 case PCI_IPL_NONE:
183 return (ISA_IPL_NONE);
184
185 case PCI_IPL_BIO:
186 return (ISA_IPL_BIO);
187
188 case PCI_IPL_NET:
189 return (ISA_IPL_NET);
190
191 case PCI_IPL_TTY:
192 return (ISA_IPL_TTY);
193
194 case PCI_IPL_CLOCK:
195 return (ISA_IPL_CLOCK);
196
197 default:
198 panic("pcilevel_to_isa: unknown level %d\n", level);
199 }
200 }
201
202 void
203 pci_display_console(bus, device, function)
204 int bus, device, function;
205 {
206 pcitag_t tag;
207 pcireg_t id, class;
208
209 /* XXX */
210 tag = pci_make_tag(bus, device, function);
211
212 id = pci_conf_read(tag, PCI_ID_REG);
213 if (id == 0 || id == 0xffffffff)
214 panic("pci_display_console: no device at %d/%d/%d",
215 bus, device, function);
216 class = pci_conf_read(tag, PCI_CLASS_REG);
217
218 if (PCI_CLASS(class) != PCI_CLASS_DISPLAY &&
219 !(PCI_CLASS(class) == PCI_CLASS_PREHISTORIC &&
220 PCI_SUBCLASS(class) == PCI_SUBCLASS_PREHISTORIC_VGA))
221 panic("pci_display_console: device at %d/%d/%d not a display",
222 bus, device, function);
223
224 if ((PCI_CLASS(class) == PCI_CLASS_DISPLAY &&
225 PCI_SUBCLASS(class) == PCI_SUBCLASS_DISPLAY_VGA) ||
226 (PCI_CLASS(class) == PCI_CLASS_PREHISTORIC &&
227 PCI_SUBCLASS(class) == PCI_SUBCLASS_PREHISTORIC_VGA)) {
228 #if NPCIVGA
229 pcivga_console(bus, device, function);
230 #else
231 panic("pci_display_console: pcivga is console, not configured");
232 #endif
233 return;
234 }
235
236 if (PCI_VENDOR(id) == PCI_VENDOR_DEC &&
237 PCI_PRODUCT(id) == PCI_PRODUCT_DEC_21030) {
238 #if NTGA
239 tga_console(bus, device, function);
240 #else
241 panic("pci_display_console: tga is console, not configured");
242 #endif
243 return;
244 }
245
246 panic("pci_display_console: unsupported device at %d/%d/%d",
247 bus, device, function);
248 }
249