pci_subr.c revision 1.21 1 1.21 enami /* $NetBSD: pci_subr.c,v 1.21 1997/09/13 08:49:51 enami Exp $ */
2 1.3 cgd
3 1.1 mycroft /*
4 1.13 cgd * Copyright (c) 1995, 1996 Christopher G. Demetriou. All rights reserved.
5 1.1 mycroft * Copyright (c) 1994 Charles Hannum. All rights reserved.
6 1.1 mycroft *
7 1.1 mycroft * Redistribution and use in source and binary forms, with or without
8 1.1 mycroft * modification, are permitted provided that the following conditions
9 1.1 mycroft * are met:
10 1.1 mycroft * 1. Redistributions of source code must retain the above copyright
11 1.1 mycroft * notice, this list of conditions and the following disclaimer.
12 1.1 mycroft * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 mycroft * notice, this list of conditions and the following disclaimer in the
14 1.1 mycroft * documentation and/or other materials provided with the distribution.
15 1.1 mycroft * 3. All advertising materials mentioning features or use of this software
16 1.1 mycroft * must display the following acknowledgement:
17 1.1 mycroft * This product includes software developed by Charles Hannum.
18 1.1 mycroft * 4. The name of the author may not be used to endorse or promote products
19 1.1 mycroft * derived from this software without specific prior written permission.
20 1.1 mycroft *
21 1.1 mycroft * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.1 mycroft * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.1 mycroft * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.1 mycroft * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.1 mycroft * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.1 mycroft * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.1 mycroft * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.1 mycroft * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.1 mycroft * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.1 mycroft * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.1 mycroft */
32 1.1 mycroft
33 1.1 mycroft /*
34 1.10 cgd * PCI autoconfiguration support functions.
35 1.1 mycroft */
36 1.21 enami
37 1.21 enami #include "opt_pciverbose.h"
38 1.1 mycroft
39 1.1 mycroft #include <sys/param.h>
40 1.10 cgd #include <sys/systm.h>
41 1.1 mycroft #include <sys/device.h>
42 1.1 mycroft
43 1.10 cgd #include <dev/pci/pcireg.h>
44 1.7 cgd #include <dev/pci/pcivar.h>
45 1.10 cgd #ifdef PCIVERBOSE
46 1.10 cgd #include <dev/pci/pcidevs.h>
47 1.10 cgd #endif
48 1.10 cgd
49 1.10 cgd /*
50 1.10 cgd * Descriptions of known PCI classes and subclasses.
51 1.10 cgd *
52 1.10 cgd * Subclasses are described in the same way as classes, but have a
53 1.10 cgd * NULL subclass pointer.
54 1.10 cgd */
55 1.10 cgd struct pci_class {
56 1.10 cgd char *name;
57 1.10 cgd int val; /* as wide as pci_{,sub}class_t */
58 1.10 cgd struct pci_class *subclasses;
59 1.10 cgd };
60 1.10 cgd
61 1.10 cgd struct pci_class pci_subclass_prehistoric[] = {
62 1.10 cgd { "miscellaneous", PCI_SUBCLASS_PREHISTORIC_MISC, },
63 1.10 cgd { "VGA", PCI_SUBCLASS_PREHISTORIC_VGA, },
64 1.10 cgd { 0 }
65 1.10 cgd };
66 1.10 cgd
67 1.10 cgd struct pci_class pci_subclass_mass_storage[] = {
68 1.10 cgd { "SCSI", PCI_SUBCLASS_MASS_STORAGE_SCSI, },
69 1.10 cgd { "IDE", PCI_SUBCLASS_MASS_STORAGE_IDE, },
70 1.10 cgd { "floppy", PCI_SUBCLASS_MASS_STORAGE_FLOPPY, },
71 1.10 cgd { "IPI", PCI_SUBCLASS_MASS_STORAGE_IPI, },
72 1.20 cgd { "RAID", PCI_SUBCLASS_MASS_STORAGE_RAID, },
73 1.10 cgd { "miscellaneous", PCI_SUBCLASS_MASS_STORAGE_MISC, },
74 1.10 cgd { 0 },
75 1.10 cgd };
76 1.10 cgd
77 1.10 cgd struct pci_class pci_subclass_network[] = {
78 1.10 cgd { "ethernet", PCI_SUBCLASS_NETWORK_ETHERNET, },
79 1.10 cgd { "token ring", PCI_SUBCLASS_NETWORK_TOKENRING, },
80 1.10 cgd { "FDDI", PCI_SUBCLASS_NETWORK_FDDI, },
81 1.20 cgd { "ATM", PCI_SUBCLASS_NETWORK_ATM, },
82 1.10 cgd { "miscellaneous", PCI_SUBCLASS_NETWORK_MISC, },
83 1.10 cgd { 0 },
84 1.10 cgd };
85 1.10 cgd
86 1.10 cgd struct pci_class pci_subclass_display[] = {
87 1.10 cgd { "VGA", PCI_SUBCLASS_DISPLAY_VGA, },
88 1.10 cgd { "XGA", PCI_SUBCLASS_DISPLAY_XGA, },
89 1.10 cgd { "miscellaneous", PCI_SUBCLASS_DISPLAY_MISC, },
90 1.10 cgd { 0 },
91 1.10 cgd };
92 1.10 cgd
93 1.10 cgd struct pci_class pci_subclass_multimedia[] = {
94 1.10 cgd { "video", PCI_SUBCLASS_MULTIMEDIA_VIDEO, },
95 1.10 cgd { "audio", PCI_SUBCLASS_MULTIMEDIA_AUDIO, },
96 1.10 cgd { "miscellaneous", PCI_SUBCLASS_MULTIMEDIA_MISC, },
97 1.10 cgd { 0 },
98 1.10 cgd };
99 1.10 cgd
100 1.10 cgd struct pci_class pci_subclass_memory[] = {
101 1.10 cgd { "RAM", PCI_SUBCLASS_MEMORY_RAM, },
102 1.10 cgd { "flash", PCI_SUBCLASS_MEMORY_FLASH, },
103 1.10 cgd { "miscellaneous", PCI_SUBCLASS_MEMORY_MISC, },
104 1.10 cgd { 0 },
105 1.10 cgd };
106 1.10 cgd
107 1.10 cgd struct pci_class pci_subclass_bridge[] = {
108 1.10 cgd { "host", PCI_SUBCLASS_BRIDGE_HOST, },
109 1.10 cgd { "ISA", PCI_SUBCLASS_BRIDGE_ISA, },
110 1.10 cgd { "EISA", PCI_SUBCLASS_BRIDGE_EISA, },
111 1.10 cgd { "MicroChannel", PCI_SUBCLASS_BRIDGE_MC, },
112 1.10 cgd { "PCI", PCI_SUBCLASS_BRIDGE_PCI, },
113 1.10 cgd { "PCMCIA", PCI_SUBCLASS_BRIDGE_PCMCIA, },
114 1.20 cgd { "NuBus", PCI_SUBCLASS_BRIDGE_NUBUS, },
115 1.20 cgd { "CardBus", PCI_SUBCLASS_BRIDGE_CARDBUS, },
116 1.10 cgd { "miscellaneous", PCI_SUBCLASS_BRIDGE_MISC, },
117 1.10 cgd { 0 },
118 1.10 cgd };
119 1.10 cgd
120 1.20 cgd struct pci_class pci_subclass_communications[] = {
121 1.20 cgd { "serial", PCI_SUBCLASS_COMMUNICATIONS_SERIAL, },
122 1.20 cgd { "parallel", PCI_SUBCLASS_COMMUNICATIONS_PARALLEL, },
123 1.20 cgd { "miscellaneous", PCI_SUBCLASS_COMMUNICATIONS_MISC, },
124 1.20 cgd { 0 },
125 1.20 cgd };
126 1.20 cgd
127 1.20 cgd struct pci_class pci_subclass_system[] = {
128 1.20 cgd { "8259 PIC", PCI_SUBCLASS_SYSTEM_PIC, },
129 1.20 cgd { "8237 DMA", PCI_SUBCLASS_SYSTEM_DMA, },
130 1.20 cgd { "8254 timer", PCI_SUBCLASS_SYSTEM_TIMER, },
131 1.20 cgd { "RTC", PCI_SUBCLASS_SYSTEM_RTC, },
132 1.20 cgd { "miscellaneous", PCI_SUBCLASS_SYSTEM_MISC, },
133 1.20 cgd { 0 },
134 1.20 cgd };
135 1.20 cgd
136 1.20 cgd struct pci_class pci_subclass_input[] = {
137 1.20 cgd { "keyboard", PCI_SUBCLASS_INPUT_KEYBOARD, },
138 1.20 cgd { "digitizer", PCI_SUBCLASS_INPUT_DIGITIZER, },
139 1.20 cgd { "mouse", PCI_SUBCLASS_INPUT_MOUSE, },
140 1.20 cgd { "miscellaneous", PCI_SUBCLASS_INPUT_MISC, },
141 1.20 cgd { 0 },
142 1.20 cgd };
143 1.20 cgd
144 1.20 cgd struct pci_class pci_subclass_dock[] = {
145 1.20 cgd { "generic", PCI_SUBCLASS_DOCK_GENERIC, },
146 1.20 cgd { "miscellaneous", PCI_SUBCLASS_DOCK_MISC, },
147 1.20 cgd { 0 },
148 1.20 cgd };
149 1.20 cgd
150 1.20 cgd struct pci_class pci_subclass_processor[] = {
151 1.20 cgd { "386", PCI_SUBCLASS_PROCESSOR_386, },
152 1.20 cgd { "486", PCI_SUBCLASS_PROCESSOR_486, },
153 1.20 cgd { "Pentium", PCI_SUBCLASS_PROCESSOR_PENTIUM, },
154 1.20 cgd { "Alpha", PCI_SUBCLASS_PROCESSOR_ALPHA, },
155 1.20 cgd { "PowerPC", PCI_SUBCLASS_PROCESSOR_POWERPC, },
156 1.20 cgd { "Co-processor", PCI_SUBCLASS_PROCESSOR_COPROC, },
157 1.20 cgd { 0 },
158 1.20 cgd };
159 1.20 cgd
160 1.20 cgd struct pci_class pci_subclass_serialbus[] = {
161 1.20 cgd { "Firewire", PCI_SUBCLASS_SERIALBUS_FIREWIRE, },
162 1.20 cgd { "ACCESS.bus", PCI_SUBCLASS_SERIALBUS_ACCESS, },
163 1.20 cgd { "SSA", PCI_SUBCLASS_SERIALBUS_SSA, },
164 1.20 cgd { "USB", PCI_SUBCLASS_SERIALBUS_USB, },
165 1.20 cgd { "Fiber Channel", PCI_SUBCLASS_SERIALBUS_FIBER, },
166 1.20 cgd { 0 },
167 1.20 cgd };
168 1.20 cgd
169 1.10 cgd struct pci_class pci_class[] = {
170 1.10 cgd { "prehistoric", PCI_CLASS_PREHISTORIC,
171 1.10 cgd pci_subclass_prehistoric, },
172 1.10 cgd { "mass storage", PCI_CLASS_MASS_STORAGE,
173 1.10 cgd pci_subclass_mass_storage, },
174 1.10 cgd { "network", PCI_CLASS_NETWORK,
175 1.10 cgd pci_subclass_network, },
176 1.10 cgd { "display", PCI_CLASS_DISPLAY,
177 1.11 cgd pci_subclass_display, },
178 1.10 cgd { "multimedia", PCI_CLASS_MULTIMEDIA,
179 1.10 cgd pci_subclass_multimedia, },
180 1.10 cgd { "memory", PCI_CLASS_MEMORY,
181 1.10 cgd pci_subclass_memory, },
182 1.10 cgd { "bridge", PCI_CLASS_BRIDGE,
183 1.10 cgd pci_subclass_bridge, },
184 1.20 cgd { "communications", PCI_CLASS_COMMUNICATIONS,
185 1.20 cgd pci_subclass_communications, },
186 1.20 cgd { "system", PCI_CLASS_SYSTEM,
187 1.20 cgd pci_subclass_system, },
188 1.20 cgd { "input", PCI_CLASS_INPUT,
189 1.20 cgd pci_subclass_input, },
190 1.20 cgd { "dock", PCI_CLASS_DOCK,
191 1.20 cgd pci_subclass_dock, },
192 1.20 cgd { "processor", PCI_CLASS_PROCESSOR,
193 1.20 cgd pci_subclass_processor, },
194 1.20 cgd { "serial bus", PCI_CLASS_SERIALBUS,
195 1.20 cgd pci_subclass_serialbus, },
196 1.10 cgd { "undefined", PCI_CLASS_UNDEFINED,
197 1.10 cgd 0, },
198 1.10 cgd { 0 },
199 1.10 cgd };
200 1.10 cgd
201 1.10 cgd #ifdef PCIVERBOSE
202 1.10 cgd /*
203 1.10 cgd * Descriptions of of known vendors and devices ("products").
204 1.10 cgd */
205 1.10 cgd struct pci_knowndev {
206 1.10 cgd pci_vendor_id_t vendor;
207 1.10 cgd pci_product_id_t product;
208 1.10 cgd int flags;
209 1.10 cgd char *vendorname, *productname;
210 1.10 cgd };
211 1.13 cgd #define PCI_KNOWNDEV_NOPROD 0x01 /* match on vendor only */
212 1.10 cgd
213 1.10 cgd #include <dev/pci/pcidevs_data.h>
214 1.10 cgd #endif /* PCIVERBOSE */
215 1.10 cgd
216 1.10 cgd void
217 1.13 cgd pci_devinfo(id_reg, class_reg, showclass, cp)
218 1.10 cgd pcireg_t id_reg, class_reg;
219 1.13 cgd int showclass;
220 1.10 cgd char *cp;
221 1.10 cgd {
222 1.10 cgd pci_vendor_id_t vendor;
223 1.10 cgd pci_product_id_t product;
224 1.10 cgd pci_class_t class;
225 1.10 cgd pci_subclass_t subclass;
226 1.10 cgd pci_interface_t interface;
227 1.10 cgd pci_revision_t revision;
228 1.10 cgd char *vendor_namep, *product_namep;
229 1.10 cgd struct pci_class *classp, *subclassp;
230 1.10 cgd #ifdef PCIVERBOSE
231 1.10 cgd struct pci_knowndev *kdp;
232 1.16 cgd const char *unmatched = "unknown ";
233 1.15 cgd #else
234 1.16 cgd const char *unmatched = "";
235 1.10 cgd #endif
236 1.10 cgd
237 1.10 cgd vendor = PCI_VENDOR(id_reg);
238 1.10 cgd product = PCI_PRODUCT(id_reg);
239 1.10 cgd
240 1.10 cgd class = PCI_CLASS(class_reg);
241 1.10 cgd subclass = PCI_SUBCLASS(class_reg);
242 1.10 cgd interface = PCI_INTERFACE(class_reg);
243 1.10 cgd revision = PCI_REVISION(class_reg);
244 1.10 cgd
245 1.10 cgd #ifdef PCIVERBOSE
246 1.10 cgd kdp = pci_knowndevs;
247 1.10 cgd while (kdp->vendorname != NULL) { /* all have vendor name */
248 1.10 cgd if (kdp->vendor == vendor && (kdp->product == product ||
249 1.10 cgd (kdp->flags & PCI_KNOWNDEV_NOPROD) != 0))
250 1.10 cgd break;
251 1.10 cgd kdp++;
252 1.10 cgd }
253 1.13 cgd if (kdp->vendorname == NULL)
254 1.10 cgd vendor_namep = product_namep = NULL;
255 1.13 cgd else {
256 1.10 cgd vendor_namep = kdp->vendorname;
257 1.10 cgd product_namep = (kdp->flags & PCI_KNOWNDEV_NOPROD) == 0 ?
258 1.10 cgd kdp->productname : NULL;
259 1.10 cgd }
260 1.10 cgd #else /* PCIVERBOSE */
261 1.10 cgd vendor_namep = product_namep = NULL;
262 1.10 cgd #endif /* PCIVERBOSE */
263 1.10 cgd
264 1.10 cgd classp = pci_class;
265 1.10 cgd while (classp->name != NULL) {
266 1.10 cgd if (class == classp->val)
267 1.10 cgd break;
268 1.10 cgd classp++;
269 1.10 cgd }
270 1.10 cgd
271 1.10 cgd subclassp = (classp->name != NULL) ? classp->subclasses : NULL;
272 1.10 cgd while (subclassp && subclassp->name != NULL) {
273 1.10 cgd if (subclass == subclassp->val)
274 1.10 cgd break;
275 1.10 cgd subclassp++;
276 1.10 cgd }
277 1.10 cgd
278 1.10 cgd if (vendor_namep == NULL)
279 1.19 christos cp += sprintf(cp, "%svendor 0x%04x product 0x%04x",
280 1.15 cgd unmatched, vendor, product);
281 1.10 cgd else if (product_namep != NULL)
282 1.19 christos cp += sprintf(cp, "%s %s", vendor_namep, product_namep);
283 1.10 cgd else
284 1.20 cgd cp += sprintf(cp, "%s product 0x%04x",
285 1.10 cgd vendor_namep, product);
286 1.13 cgd if (showclass) {
287 1.19 christos cp += sprintf(cp, " (");
288 1.13 cgd if (classp->name == NULL)
289 1.20 cgd cp += sprintf(cp, "class 0x%02x, subclass 0x%02x",
290 1.13 cgd class, subclass);
291 1.13 cgd else {
292 1.13 cgd if (subclassp == NULL || subclassp->name == NULL)
293 1.20 cgd cp += sprintf(cp,
294 1.20 cgd "%s subclass 0x%02x",
295 1.20 cgd classp->name, subclass);
296 1.13 cgd else
297 1.20 cgd cp += sprintf(cp, "%s %s",
298 1.20 cgd subclassp->name, classp->name);
299 1.13 cgd }
300 1.20 cgd if (interface != 0)
301 1.20 cgd cp += sprintf(cp, ", interface 0x%02x", interface);
302 1.20 cgd if (revision != 0)
303 1.20 cgd cp += sprintf(cp, ", revision 0x%02x", revision);
304 1.20 cgd cp += sprintf(cp, ")");
305 1.13 cgd }
306 1.1 mycroft }
307