pci_subr.c revision 1.26 1 1.26 cgd /* $NetBSD: pci_subr.c,v 1.26 1998/05/18 17:25:17 cgd Exp $ */
2 1.3 cgd
3 1.1 mycroft /*
4 1.22 thorpej * Copyright (c) 1997 Zubin D. Dittia. All rights reserved.
5 1.26 cgd * Copyright (c) 1995, 1996, 1998
6 1.26 cgd * Christopher G. Demetriou. All rights reserved.
7 1.1 mycroft * Copyright (c) 1994 Charles Hannum. All rights reserved.
8 1.1 mycroft *
9 1.1 mycroft * Redistribution and use in source and binary forms, with or without
10 1.1 mycroft * modification, are permitted provided that the following conditions
11 1.1 mycroft * are met:
12 1.1 mycroft * 1. Redistributions of source code must retain the above copyright
13 1.1 mycroft * notice, this list of conditions and the following disclaimer.
14 1.1 mycroft * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 mycroft * notice, this list of conditions and the following disclaimer in the
16 1.1 mycroft * documentation and/or other materials provided with the distribution.
17 1.1 mycroft * 3. All advertising materials mentioning features or use of this software
18 1.1 mycroft * must display the following acknowledgement:
19 1.1 mycroft * This product includes software developed by Charles Hannum.
20 1.1 mycroft * 4. The name of the author may not be used to endorse or promote products
21 1.1 mycroft * derived from this software without specific prior written permission.
22 1.1 mycroft *
23 1.1 mycroft * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 1.1 mycroft * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 1.1 mycroft * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 1.1 mycroft * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 1.1 mycroft * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 1.1 mycroft * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 1.1 mycroft * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 1.1 mycroft * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 1.1 mycroft * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 1.1 mycroft * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 1.1 mycroft */
34 1.1 mycroft
35 1.1 mycroft /*
36 1.10 cgd * PCI autoconfiguration support functions.
37 1.1 mycroft */
38 1.21 enami
39 1.21 enami #include "opt_pciverbose.h"
40 1.1 mycroft
41 1.1 mycroft #include <sys/param.h>
42 1.10 cgd #include <sys/systm.h>
43 1.1 mycroft #include <sys/device.h>
44 1.1 mycroft
45 1.24 thorpej #include <machine/intr.h>
46 1.24 thorpej
47 1.10 cgd #include <dev/pci/pcireg.h>
48 1.7 cgd #include <dev/pci/pcivar.h>
49 1.10 cgd #ifdef PCIVERBOSE
50 1.10 cgd #include <dev/pci/pcidevs.h>
51 1.10 cgd #endif
52 1.10 cgd
53 1.26 cgd static void pci_conf_print_common __P((pci_chipset_tag_t, pcitag_t,
54 1.26 cgd const pcireg_t *regs));
55 1.26 cgd static void pci_conf_print_type1 __P((pci_chipset_tag_t, pcitag_t,
56 1.26 cgd const pcireg_t *regs));
57 1.26 cgd
58 1.10 cgd /*
59 1.10 cgd * Descriptions of known PCI classes and subclasses.
60 1.10 cgd *
61 1.10 cgd * Subclasses are described in the same way as classes, but have a
62 1.10 cgd * NULL subclass pointer.
63 1.10 cgd */
64 1.10 cgd struct pci_class {
65 1.10 cgd char *name;
66 1.10 cgd int val; /* as wide as pci_{,sub}class_t */
67 1.10 cgd struct pci_class *subclasses;
68 1.10 cgd };
69 1.10 cgd
70 1.10 cgd struct pci_class pci_subclass_prehistoric[] = {
71 1.10 cgd { "miscellaneous", PCI_SUBCLASS_PREHISTORIC_MISC, },
72 1.10 cgd { "VGA", PCI_SUBCLASS_PREHISTORIC_VGA, },
73 1.10 cgd { 0 }
74 1.10 cgd };
75 1.10 cgd
76 1.10 cgd struct pci_class pci_subclass_mass_storage[] = {
77 1.10 cgd { "SCSI", PCI_SUBCLASS_MASS_STORAGE_SCSI, },
78 1.10 cgd { "IDE", PCI_SUBCLASS_MASS_STORAGE_IDE, },
79 1.10 cgd { "floppy", PCI_SUBCLASS_MASS_STORAGE_FLOPPY, },
80 1.10 cgd { "IPI", PCI_SUBCLASS_MASS_STORAGE_IPI, },
81 1.20 cgd { "RAID", PCI_SUBCLASS_MASS_STORAGE_RAID, },
82 1.10 cgd { "miscellaneous", PCI_SUBCLASS_MASS_STORAGE_MISC, },
83 1.10 cgd { 0 },
84 1.10 cgd };
85 1.10 cgd
86 1.10 cgd struct pci_class pci_subclass_network[] = {
87 1.10 cgd { "ethernet", PCI_SUBCLASS_NETWORK_ETHERNET, },
88 1.10 cgd { "token ring", PCI_SUBCLASS_NETWORK_TOKENRING, },
89 1.10 cgd { "FDDI", PCI_SUBCLASS_NETWORK_FDDI, },
90 1.20 cgd { "ATM", PCI_SUBCLASS_NETWORK_ATM, },
91 1.10 cgd { "miscellaneous", PCI_SUBCLASS_NETWORK_MISC, },
92 1.10 cgd { 0 },
93 1.10 cgd };
94 1.10 cgd
95 1.10 cgd struct pci_class pci_subclass_display[] = {
96 1.10 cgd { "VGA", PCI_SUBCLASS_DISPLAY_VGA, },
97 1.10 cgd { "XGA", PCI_SUBCLASS_DISPLAY_XGA, },
98 1.10 cgd { "miscellaneous", PCI_SUBCLASS_DISPLAY_MISC, },
99 1.10 cgd { 0 },
100 1.10 cgd };
101 1.10 cgd
102 1.10 cgd struct pci_class pci_subclass_multimedia[] = {
103 1.10 cgd { "video", PCI_SUBCLASS_MULTIMEDIA_VIDEO, },
104 1.10 cgd { "audio", PCI_SUBCLASS_MULTIMEDIA_AUDIO, },
105 1.10 cgd { "miscellaneous", PCI_SUBCLASS_MULTIMEDIA_MISC, },
106 1.10 cgd { 0 },
107 1.10 cgd };
108 1.10 cgd
109 1.10 cgd struct pci_class pci_subclass_memory[] = {
110 1.10 cgd { "RAM", PCI_SUBCLASS_MEMORY_RAM, },
111 1.10 cgd { "flash", PCI_SUBCLASS_MEMORY_FLASH, },
112 1.10 cgd { "miscellaneous", PCI_SUBCLASS_MEMORY_MISC, },
113 1.10 cgd { 0 },
114 1.10 cgd };
115 1.10 cgd
116 1.10 cgd struct pci_class pci_subclass_bridge[] = {
117 1.10 cgd { "host", PCI_SUBCLASS_BRIDGE_HOST, },
118 1.10 cgd { "ISA", PCI_SUBCLASS_BRIDGE_ISA, },
119 1.10 cgd { "EISA", PCI_SUBCLASS_BRIDGE_EISA, },
120 1.10 cgd { "MicroChannel", PCI_SUBCLASS_BRIDGE_MC, },
121 1.10 cgd { "PCI", PCI_SUBCLASS_BRIDGE_PCI, },
122 1.10 cgd { "PCMCIA", PCI_SUBCLASS_BRIDGE_PCMCIA, },
123 1.20 cgd { "NuBus", PCI_SUBCLASS_BRIDGE_NUBUS, },
124 1.20 cgd { "CardBus", PCI_SUBCLASS_BRIDGE_CARDBUS, },
125 1.10 cgd { "miscellaneous", PCI_SUBCLASS_BRIDGE_MISC, },
126 1.10 cgd { 0 },
127 1.10 cgd };
128 1.10 cgd
129 1.20 cgd struct pci_class pci_subclass_communications[] = {
130 1.20 cgd { "serial", PCI_SUBCLASS_COMMUNICATIONS_SERIAL, },
131 1.20 cgd { "parallel", PCI_SUBCLASS_COMMUNICATIONS_PARALLEL, },
132 1.20 cgd { "miscellaneous", PCI_SUBCLASS_COMMUNICATIONS_MISC, },
133 1.20 cgd { 0 },
134 1.20 cgd };
135 1.20 cgd
136 1.20 cgd struct pci_class pci_subclass_system[] = {
137 1.20 cgd { "8259 PIC", PCI_SUBCLASS_SYSTEM_PIC, },
138 1.20 cgd { "8237 DMA", PCI_SUBCLASS_SYSTEM_DMA, },
139 1.20 cgd { "8254 timer", PCI_SUBCLASS_SYSTEM_TIMER, },
140 1.20 cgd { "RTC", PCI_SUBCLASS_SYSTEM_RTC, },
141 1.20 cgd { "miscellaneous", PCI_SUBCLASS_SYSTEM_MISC, },
142 1.20 cgd { 0 },
143 1.20 cgd };
144 1.20 cgd
145 1.20 cgd struct pci_class pci_subclass_input[] = {
146 1.20 cgd { "keyboard", PCI_SUBCLASS_INPUT_KEYBOARD, },
147 1.20 cgd { "digitizer", PCI_SUBCLASS_INPUT_DIGITIZER, },
148 1.20 cgd { "mouse", PCI_SUBCLASS_INPUT_MOUSE, },
149 1.20 cgd { "miscellaneous", PCI_SUBCLASS_INPUT_MISC, },
150 1.20 cgd { 0 },
151 1.20 cgd };
152 1.20 cgd
153 1.20 cgd struct pci_class pci_subclass_dock[] = {
154 1.20 cgd { "generic", PCI_SUBCLASS_DOCK_GENERIC, },
155 1.20 cgd { "miscellaneous", PCI_SUBCLASS_DOCK_MISC, },
156 1.20 cgd { 0 },
157 1.20 cgd };
158 1.20 cgd
159 1.20 cgd struct pci_class pci_subclass_processor[] = {
160 1.20 cgd { "386", PCI_SUBCLASS_PROCESSOR_386, },
161 1.20 cgd { "486", PCI_SUBCLASS_PROCESSOR_486, },
162 1.20 cgd { "Pentium", PCI_SUBCLASS_PROCESSOR_PENTIUM, },
163 1.20 cgd { "Alpha", PCI_SUBCLASS_PROCESSOR_ALPHA, },
164 1.20 cgd { "PowerPC", PCI_SUBCLASS_PROCESSOR_POWERPC, },
165 1.20 cgd { "Co-processor", PCI_SUBCLASS_PROCESSOR_COPROC, },
166 1.20 cgd { 0 },
167 1.20 cgd };
168 1.20 cgd
169 1.20 cgd struct pci_class pci_subclass_serialbus[] = {
170 1.20 cgd { "Firewire", PCI_SUBCLASS_SERIALBUS_FIREWIRE, },
171 1.20 cgd { "ACCESS.bus", PCI_SUBCLASS_SERIALBUS_ACCESS, },
172 1.20 cgd { "SSA", PCI_SUBCLASS_SERIALBUS_SSA, },
173 1.20 cgd { "USB", PCI_SUBCLASS_SERIALBUS_USB, },
174 1.20 cgd { "Fiber Channel", PCI_SUBCLASS_SERIALBUS_FIBER, },
175 1.20 cgd { 0 },
176 1.20 cgd };
177 1.20 cgd
178 1.10 cgd struct pci_class pci_class[] = {
179 1.10 cgd { "prehistoric", PCI_CLASS_PREHISTORIC,
180 1.10 cgd pci_subclass_prehistoric, },
181 1.10 cgd { "mass storage", PCI_CLASS_MASS_STORAGE,
182 1.10 cgd pci_subclass_mass_storage, },
183 1.10 cgd { "network", PCI_CLASS_NETWORK,
184 1.10 cgd pci_subclass_network, },
185 1.10 cgd { "display", PCI_CLASS_DISPLAY,
186 1.11 cgd pci_subclass_display, },
187 1.10 cgd { "multimedia", PCI_CLASS_MULTIMEDIA,
188 1.10 cgd pci_subclass_multimedia, },
189 1.10 cgd { "memory", PCI_CLASS_MEMORY,
190 1.10 cgd pci_subclass_memory, },
191 1.10 cgd { "bridge", PCI_CLASS_BRIDGE,
192 1.10 cgd pci_subclass_bridge, },
193 1.20 cgd { "communications", PCI_CLASS_COMMUNICATIONS,
194 1.20 cgd pci_subclass_communications, },
195 1.20 cgd { "system", PCI_CLASS_SYSTEM,
196 1.20 cgd pci_subclass_system, },
197 1.20 cgd { "input", PCI_CLASS_INPUT,
198 1.20 cgd pci_subclass_input, },
199 1.20 cgd { "dock", PCI_CLASS_DOCK,
200 1.20 cgd pci_subclass_dock, },
201 1.20 cgd { "processor", PCI_CLASS_PROCESSOR,
202 1.20 cgd pci_subclass_processor, },
203 1.20 cgd { "serial bus", PCI_CLASS_SERIALBUS,
204 1.20 cgd pci_subclass_serialbus, },
205 1.10 cgd { "undefined", PCI_CLASS_UNDEFINED,
206 1.10 cgd 0, },
207 1.10 cgd { 0 },
208 1.10 cgd };
209 1.10 cgd
210 1.10 cgd #ifdef PCIVERBOSE
211 1.10 cgd /*
212 1.10 cgd * Descriptions of of known vendors and devices ("products").
213 1.10 cgd */
214 1.10 cgd struct pci_knowndev {
215 1.10 cgd pci_vendor_id_t vendor;
216 1.10 cgd pci_product_id_t product;
217 1.10 cgd int flags;
218 1.10 cgd char *vendorname, *productname;
219 1.10 cgd };
220 1.13 cgd #define PCI_KNOWNDEV_NOPROD 0x01 /* match on vendor only */
221 1.10 cgd
222 1.10 cgd #include <dev/pci/pcidevs_data.h>
223 1.10 cgd #endif /* PCIVERBOSE */
224 1.10 cgd
225 1.10 cgd void
226 1.13 cgd pci_devinfo(id_reg, class_reg, showclass, cp)
227 1.10 cgd pcireg_t id_reg, class_reg;
228 1.13 cgd int showclass;
229 1.10 cgd char *cp;
230 1.10 cgd {
231 1.10 cgd pci_vendor_id_t vendor;
232 1.10 cgd pci_product_id_t product;
233 1.10 cgd pci_class_t class;
234 1.10 cgd pci_subclass_t subclass;
235 1.10 cgd pci_interface_t interface;
236 1.10 cgd pci_revision_t revision;
237 1.10 cgd char *vendor_namep, *product_namep;
238 1.10 cgd struct pci_class *classp, *subclassp;
239 1.10 cgd #ifdef PCIVERBOSE
240 1.10 cgd struct pci_knowndev *kdp;
241 1.16 cgd const char *unmatched = "unknown ";
242 1.15 cgd #else
243 1.16 cgd const char *unmatched = "";
244 1.10 cgd #endif
245 1.10 cgd
246 1.10 cgd vendor = PCI_VENDOR(id_reg);
247 1.10 cgd product = PCI_PRODUCT(id_reg);
248 1.10 cgd
249 1.10 cgd class = PCI_CLASS(class_reg);
250 1.10 cgd subclass = PCI_SUBCLASS(class_reg);
251 1.10 cgd interface = PCI_INTERFACE(class_reg);
252 1.10 cgd revision = PCI_REVISION(class_reg);
253 1.10 cgd
254 1.10 cgd #ifdef PCIVERBOSE
255 1.10 cgd kdp = pci_knowndevs;
256 1.10 cgd while (kdp->vendorname != NULL) { /* all have vendor name */
257 1.10 cgd if (kdp->vendor == vendor && (kdp->product == product ||
258 1.10 cgd (kdp->flags & PCI_KNOWNDEV_NOPROD) != 0))
259 1.10 cgd break;
260 1.10 cgd kdp++;
261 1.10 cgd }
262 1.13 cgd if (kdp->vendorname == NULL)
263 1.10 cgd vendor_namep = product_namep = NULL;
264 1.13 cgd else {
265 1.10 cgd vendor_namep = kdp->vendorname;
266 1.10 cgd product_namep = (kdp->flags & PCI_KNOWNDEV_NOPROD) == 0 ?
267 1.10 cgd kdp->productname : NULL;
268 1.10 cgd }
269 1.10 cgd #else /* PCIVERBOSE */
270 1.10 cgd vendor_namep = product_namep = NULL;
271 1.10 cgd #endif /* PCIVERBOSE */
272 1.10 cgd
273 1.10 cgd classp = pci_class;
274 1.10 cgd while (classp->name != NULL) {
275 1.10 cgd if (class == classp->val)
276 1.10 cgd break;
277 1.10 cgd classp++;
278 1.10 cgd }
279 1.10 cgd
280 1.10 cgd subclassp = (classp->name != NULL) ? classp->subclasses : NULL;
281 1.10 cgd while (subclassp && subclassp->name != NULL) {
282 1.10 cgd if (subclass == subclassp->val)
283 1.10 cgd break;
284 1.10 cgd subclassp++;
285 1.10 cgd }
286 1.10 cgd
287 1.10 cgd if (vendor_namep == NULL)
288 1.19 christos cp += sprintf(cp, "%svendor 0x%04x product 0x%04x",
289 1.15 cgd unmatched, vendor, product);
290 1.10 cgd else if (product_namep != NULL)
291 1.19 christos cp += sprintf(cp, "%s %s", vendor_namep, product_namep);
292 1.10 cgd else
293 1.20 cgd cp += sprintf(cp, "%s product 0x%04x",
294 1.10 cgd vendor_namep, product);
295 1.13 cgd if (showclass) {
296 1.19 christos cp += sprintf(cp, " (");
297 1.13 cgd if (classp->name == NULL)
298 1.20 cgd cp += sprintf(cp, "class 0x%02x, subclass 0x%02x",
299 1.13 cgd class, subclass);
300 1.13 cgd else {
301 1.13 cgd if (subclassp == NULL || subclassp->name == NULL)
302 1.20 cgd cp += sprintf(cp,
303 1.20 cgd "%s subclass 0x%02x",
304 1.20 cgd classp->name, subclass);
305 1.13 cgd else
306 1.20 cgd cp += sprintf(cp, "%s %s",
307 1.20 cgd subclassp->name, classp->name);
308 1.13 cgd }
309 1.20 cgd if (interface != 0)
310 1.20 cgd cp += sprintf(cp, ", interface 0x%02x", interface);
311 1.20 cgd if (revision != 0)
312 1.20 cgd cp += sprintf(cp, ", revision 0x%02x", revision);
313 1.20 cgd cp += sprintf(cp, ")");
314 1.13 cgd }
315 1.22 thorpej }
316 1.22 thorpej
317 1.22 thorpej /*
318 1.22 thorpej * Print out most of the PCI configuration registers. Typically used
319 1.22 thorpej * in a device attach routine like this:
320 1.22 thorpej *
321 1.22 thorpej * #ifdef MYDEV_DEBUG
322 1.22 thorpej * printf("%s: ", sc->sc_dev.dv_xname);
323 1.22 thorpej * pci_conf_print(pa->pa_pc, pa->pa_tag);
324 1.22 thorpej * #endif
325 1.22 thorpej */
326 1.26 cgd
327 1.26 cgd #define i2o(i) ((i) * 4)
328 1.26 cgd #define o2i(o) ((o) / 4)
329 1.26 cgd
330 1.26 cgd static void
331 1.26 cgd pci_conf_print_common(pc, tag, regs)
332 1.22 thorpej pci_chipset_tag_t pc;
333 1.22 thorpej pcitag_t tag;
334 1.26 cgd const pcireg_t *regs;
335 1.22 thorpej {
336 1.22 thorpej #ifdef PCIVERBOSE
337 1.22 thorpej struct pci_knowndev *kdp;
338 1.22 thorpej #endif
339 1.22 thorpej struct pci_class *classp, *subclassp;
340 1.26 cgd pcireg_t rval;
341 1.22 thorpej
342 1.26 cgd rval = regs[o2i(PCI_ID_REG)];
343 1.22 thorpej #ifndef PCIVERBOSE
344 1.26 cgd printf(" Vendor ID: 0x%04x\n", PCI_VENDOR(rval));
345 1.26 cgd printf(" Device ID: 0x%04x\n", PCI_PRODUCT(rval));
346 1.22 thorpej #else
347 1.22 thorpej for (kdp = pci_knowndevs; kdp->vendorname != NULL; kdp++) {
348 1.22 thorpej if (kdp->vendor == PCI_VENDOR(rval) &&
349 1.22 thorpej (kdp->product == PCI_PRODUCT(rval) ||
350 1.22 thorpej (kdp->flags & PCI_KNOWNDEV_NOPROD) != 0)) {
351 1.22 thorpej break;
352 1.22 thorpej }
353 1.22 thorpej }
354 1.22 thorpej if (kdp->vendorname != NULL)
355 1.26 cgd printf(" Vendor Name: %s (0x%04x)\n", kdp->vendorname,
356 1.26 cgd PCI_VENDOR(rval));
357 1.22 thorpej else
358 1.26 cgd printf(" Vendor ID: 0x%04x\n", PCI_VENDOR(rval));
359 1.22 thorpej if (kdp->productname != NULL && (kdp->flags & PCI_KNOWNDEV_NOPROD) == 0)
360 1.26 cgd printf(" Device Name: %s (0x%04x)\n", kdp->productname,
361 1.26 cgd PCI_PRODUCT(rval));
362 1.22 thorpej else
363 1.26 cgd printf(" Device ID: 0x%04x\n", PCI_PRODUCT(rval));
364 1.22 thorpej #endif /* PCIVERBOSE */
365 1.22 thorpej
366 1.26 cgd #define onoff(str, bit) \
367 1.26 cgd printf(" %s: %s\n", (str), (rval & (bit)) ? "on" : "off");
368 1.22 thorpej
369 1.26 cgd rval = regs[o2i(PCI_COMMAND_STATUS_REG)];
370 1.23 drochner
371 1.26 cgd printf(" Command register: 0x%04x\n", rval & 0xffff);
372 1.26 cgd onoff("I/O space accesses", PCI_COMMAND_IO_ENABLE);
373 1.26 cgd onoff("Memory space accesses", PCI_COMMAND_MEM_ENABLE);
374 1.26 cgd onoff("Bus mastering", PCI_COMMAND_MASTER_ENABLE);
375 1.26 cgd onoff("Special cycles", PCI_COMMAND_SPECIAL_ENABLE);
376 1.26 cgd onoff("MWI transactions", PCI_COMMAND_INVALIDATE_ENABLE);
377 1.26 cgd onoff("Palette snooping", PCI_COMMAND_PALETTE_ENABLE);
378 1.26 cgd onoff("Parity error checking", PCI_COMMAND_PARITY_ENABLE);
379 1.26 cgd onoff("Address/data stepping", PCI_COMMAND_STEPPING_ENABLE);
380 1.26 cgd onoff("System error (SERR)", PCI_COMMAND_SERR_ENABLE);
381 1.26 cgd onoff("Fast back-to-back transactions", PCI_COMMAND_BACKTOBACK_ENABLE);
382 1.26 cgd
383 1.26 cgd printf(" Status register: 0x%04x\n", (rval >> 16) & 0xffff);
384 1.26 cgd onoff("66 MHz capable", PCI_STATUS_66MHZ_SUPPORT);
385 1.26 cgd onoff("User Definable Features (UDF) support", PCI_STATUS_UDF_SUPPORT);
386 1.26 cgd onoff("Fast back-to-back capable", PCI_STATUS_BACKTOBACK_SUPPORT);
387 1.26 cgd onoff("Data parity error detected", PCI_STATUS_PARITY_ERROR);
388 1.22 thorpej
389 1.26 cgd printf(" DEVSEL timing: ");
390 1.22 thorpej switch (rval & PCI_STATUS_DEVSEL_MASK) {
391 1.22 thorpej case PCI_STATUS_DEVSEL_FAST:
392 1.22 thorpej printf("fast");
393 1.22 thorpej break;
394 1.22 thorpej case PCI_STATUS_DEVSEL_MEDIUM:
395 1.22 thorpej printf("medium");
396 1.22 thorpej break;
397 1.22 thorpej case PCI_STATUS_DEVSEL_SLOW:
398 1.22 thorpej printf("slow");
399 1.22 thorpej break;
400 1.26 cgd default:
401 1.26 cgd printf("unknown/reserved"); /* XXX */
402 1.26 cgd break;
403 1.22 thorpej }
404 1.26 cgd printf(" (0x%x)\n", (rval & PCI_STATUS_DEVSEL_MASK) >> 25);
405 1.22 thorpej
406 1.26 cgd onoff("Slave signaled Target Abort", PCI_STATUS_TARGET_TARGET_ABORT);
407 1.26 cgd onoff("Master received Target Abort", PCI_STATUS_MASTER_TARGET_ABORT);
408 1.26 cgd onoff("Master received Master Abort", PCI_STATUS_MASTER_ABORT);
409 1.26 cgd onoff("Asserted System Error (SERR)", PCI_STATUS_SPECIAL_ERROR);
410 1.26 cgd onoff("Parity error detected", PCI_STATUS_PARITY_DETECT);
411 1.22 thorpej
412 1.26 cgd #undef onoff
413 1.22 thorpej
414 1.26 cgd rval = regs[o2i(PCI_CLASS_REG)];
415 1.22 thorpej for (classp = pci_class; classp->name != NULL; classp++) {
416 1.22 thorpej if (PCI_CLASS(rval) == classp->val)
417 1.22 thorpej break;
418 1.22 thorpej }
419 1.22 thorpej subclassp = (classp->name != NULL) ? classp->subclasses : NULL;
420 1.22 thorpej while (subclassp && subclassp->name != NULL) {
421 1.22 thorpej if (PCI_SUBCLASS(rval) == subclassp->val)
422 1.22 thorpej break;
423 1.22 thorpej subclassp++;
424 1.22 thorpej }
425 1.22 thorpej if (classp->name != NULL) {
426 1.26 cgd printf(" Class Name: %s (0x%02x)\n", classp->name,
427 1.26 cgd PCI_CLASS(rval));
428 1.22 thorpej if (subclassp != NULL && subclassp->name != NULL)
429 1.26 cgd printf(" Subclass Name: %s (0x%02x)\n",
430 1.26 cgd subclassp->name, PCI_SUBCLASS(rval));
431 1.22 thorpej else
432 1.26 cgd printf(" Subclass ID: 0x%02x\n", PCI_SUBCLASS(rval));
433 1.22 thorpej } else {
434 1.26 cgd printf(" Class ID: 0x%02x\n", PCI_CLASS(rval));
435 1.26 cgd printf(" Subclass ID: 0x%02x\n", PCI_SUBCLASS(rval));
436 1.22 thorpej }
437 1.26 cgd printf(" Interface: 0x%02x\n", PCI_INTERFACE(rval));
438 1.26 cgd printf(" Revision ID: 0x%02x\n", PCI_REVISION(rval));
439 1.22 thorpej
440 1.26 cgd rval = regs[o2i(PCI_BHLC_REG)];
441 1.26 cgd printf(" BIST: 0x%02x\n", PCI_BIST(rval));
442 1.26 cgd printf(" Header Type: 0x%02x%s (0x%02x)\n", PCI_HDRTYPE_TYPE(rval),
443 1.26 cgd PCI_HDRTYPE_MULTIFN(rval) ? "+multifunction" : "",
444 1.26 cgd PCI_HDRTYPE(rval));
445 1.26 cgd printf(" Latency Timer: 0x%02x\n", PCI_LATTIMER(rval));
446 1.26 cgd printf(" Cache Line Size: 0x%02x\n", PCI_CACHELINE(rval));
447 1.26 cgd }
448 1.22 thorpej
449 1.26 cgd static void
450 1.26 cgd pci_conf_print_type1(pc, tag, regs)
451 1.26 cgd pci_chipset_tag_t pc;
452 1.26 cgd pcitag_t tag;
453 1.26 cgd const pcireg_t *regs;
454 1.26 cgd {
455 1.26 cgd int off, s;
456 1.26 cgd pcireg_t mask, rval;
457 1.22 thorpej
458 1.26 cgd for (off = PCI_MAPREG_START; off < PCI_MAPREG_END; off += 4) {
459 1.24 thorpej /*
460 1.24 thorpej * Section 6.2.5.1, `Address Maps', tells us that:
461 1.24 thorpej *
462 1.24 thorpej * 1) The builtin software should have already mapped the
463 1.24 thorpej * device in a reasonable way.
464 1.24 thorpej *
465 1.24 thorpej * 2) A device which wants 2^n bytes of memory will hardwire
466 1.24 thorpej * the bottom n bits of the address to 0. As recommended,
467 1.24 thorpej * we write all 1s and see what we get back.
468 1.24 thorpej */
469 1.26 cgd rval = regs[o2i(off)];
470 1.26 cgd if (rval != 0) {
471 1.26 cgd /*
472 1.26 cgd * The following sequence seems to make some devices
473 1.26 cgd * (e.g. host bus bridges, which don't normally
474 1.26 cgd * have their space mapped) very unhappy, to
475 1.26 cgd * the point of crashing the system.
476 1.26 cgd *
477 1.26 cgd * Therefore, if the mapping register is zero to
478 1.26 cgd * start out with, don't bother trying.
479 1.26 cgd */
480 1.26 cgd s = splhigh();
481 1.26 cgd pci_conf_write(pc, tag, off, 0xffffffff);
482 1.26 cgd mask = pci_conf_read(pc, tag, off);
483 1.26 cgd pci_conf_write(pc, tag, off, rval);
484 1.26 cgd splx(s);
485 1.26 cgd } else
486 1.26 cgd mask = 0;
487 1.26 cgd
488 1.26 cgd printf(" Mapping register at 0x%02x: ", off);
489 1.26 cgd if (rval == 0) {
490 1.26 cgd printf("not implemented(?)\n");
491 1.26 cgd } else if (PCI_MAPREG_TYPE(rval) == PCI_MAPREG_TYPE_MEM) {
492 1.26 cgd const char *type, *cache;
493 1.26 cgd
494 1.22 thorpej switch (PCI_MAPREG_MEM_TYPE(rval)) {
495 1.22 thorpej case PCI_MAPREG_MEM_TYPE_32BIT:
496 1.26 cgd type = "32-bit";
497 1.22 thorpej break;
498 1.22 thorpej case PCI_MAPREG_MEM_TYPE_32BIT_1M:
499 1.26 cgd type = "32-bit-1M";
500 1.22 thorpej break;
501 1.22 thorpej case PCI_MAPREG_MEM_TYPE_64BIT:
502 1.26 cgd type = "64-bit";
503 1.26 cgd break;
504 1.26 cgd default:
505 1.26 cgd type = "unknown (XXX)";
506 1.22 thorpej break;
507 1.22 thorpej }
508 1.22 thorpej if (PCI_MAPREG_MEM_CACHEABLE(rval))
509 1.26 cgd cache = "";
510 1.22 thorpej else
511 1.26 cgd cache = "non";
512 1.26 cgd printf("%s %scacheable memory\n", type, cache);
513 1.26 cgd printf(" base address: 0x%08x, size: 0x%08x\n",
514 1.26 cgd PCI_MAPREG_MEM_ADDR(rval),
515 1.26 cgd PCI_MAPREG_MEM_SIZE(mask));
516 1.22 thorpej } else {
517 1.26 cgd printf("i/o\n");
518 1.26 cgd printf(" base address: 0x%08x, size: 0x%08x\n",
519 1.26 cgd PCI_MAPREG_IO_ADDR(rval),
520 1.24 thorpej PCI_MAPREG_IO_SIZE(mask));
521 1.22 thorpej }
522 1.22 thorpej }
523 1.22 thorpej
524 1.26 cgd printf(" Cardbus CIS Pointer: 0x%08x\n", regs[o2i(0x28)]);
525 1.22 thorpej
526 1.26 cgd rval = regs[o2i(0x2c)];
527 1.26 cgd printf(" Subsystem vendor ID: 0x%04x\n", PCI_VENDOR(rval));
528 1.26 cgd printf(" Subsystem ID: 0x%04x\n", PCI_PRODUCT(rval));
529 1.26 cgd
530 1.26 cgd /* XXX */
531 1.26 cgd printf(" Expansion ROM Base Address: 0x%08x\n", regs[o2i(0x30)]);
532 1.26 cgd printf(" Reserved @ 0x34: 0x%08x\n", regs[o2i(0x34)]);
533 1.26 cgd printf(" Reserved @ 0x38: 0x%08x\n", regs[o2i(0x38)]);
534 1.26 cgd
535 1.26 cgd rval = regs[o2i(PCI_INTERRUPT_REG)];
536 1.26 cgd printf(" Maximum Latency: 0x%02x\n", (rval >> 24) & 0xff);
537 1.26 cgd printf(" Minimum Grant: 0x%02x\n", (rval >> 16) & 0xff);
538 1.26 cgd printf(" Interrupt pin: 0x%02x", PCI_INTERRUPT_PIN(rval));
539 1.22 thorpej switch (PCI_INTERRUPT_PIN(rval)) {
540 1.22 thorpej case PCI_INTERRUPT_PIN_NONE:
541 1.22 thorpej printf(" (none)");
542 1.22 thorpej break;
543 1.22 thorpej case PCI_INTERRUPT_PIN_A:
544 1.22 thorpej printf(" (pin A)");
545 1.22 thorpej break;
546 1.22 thorpej case PCI_INTERRUPT_PIN_B:
547 1.22 thorpej printf(" (pin B)");
548 1.22 thorpej break;
549 1.22 thorpej case PCI_INTERRUPT_PIN_C:
550 1.22 thorpej printf(" (pin C)");
551 1.22 thorpej break;
552 1.22 thorpej case PCI_INTERRUPT_PIN_D:
553 1.22 thorpej printf(" (pin D)");
554 1.22 thorpej break;
555 1.22 thorpej }
556 1.22 thorpej printf("\n");
557 1.26 cgd printf(" Interrupt line: 0x%02x\n", PCI_INTERRUPT_LINE(rval));
558 1.26 cgd }
559 1.26 cgd
560 1.26 cgd void
561 1.26 cgd pci_conf_print(pc, tag, printfn)
562 1.26 cgd pci_chipset_tag_t pc;
563 1.26 cgd pcitag_t tag;
564 1.26 cgd void (*printfn)(pci_chipset_tag_t, pcitag_t, const pcireg_t *);
565 1.26 cgd {
566 1.26 cgd pcireg_t regs[o2i(256)];
567 1.26 cgd int off, hdrtype;
568 1.26 cgd void (*typeprintfn)(pci_chipset_tag_t, pcitag_t, const pcireg_t *);
569 1.26 cgd
570 1.26 cgd printf("PCI configuration registers:\n");
571 1.26 cgd
572 1.26 cgd for (off = 0; off < 256; off += 4)
573 1.26 cgd regs[o2i(off)] = pci_conf_read(pc, tag, off);
574 1.26 cgd
575 1.26 cgd #define print16regs(offset) \
576 1.26 cgd printf(" 0x%02x: 0x%08x 0x%08x 0x%08x 0x%08x\n", (offset), \
577 1.26 cgd regs[o2i((offset))], regs[o2i((offset) + 4)], \
578 1.26 cgd regs[o2i((offset) + 8)], regs[o2i((offset) + 12)]);
579 1.26 cgd
580 1.26 cgd /* common header */
581 1.26 cgd printf(" Common header:\n");
582 1.26 cgd for (off = 0; off < 16; off += 16)
583 1.26 cgd print16regs(off);
584 1.26 cgd printf("\n");
585 1.26 cgd pci_conf_print_common(pc, tag, regs);
586 1.26 cgd printf("\n");
587 1.26 cgd
588 1.26 cgd /* type-dependent header */
589 1.26 cgd hdrtype = PCI_HDRTYPE_TYPE(regs[o2i(PCI_BHLC_REG)]);
590 1.26 cgd printf(" Type %d header:\n", hdrtype);
591 1.26 cgd for (off = 16; off < 64; off += 16)
592 1.26 cgd print16regs(off);
593 1.26 cgd printf("\n");
594 1.26 cgd switch (hdrtype) { /* XXX make a table, eventually */
595 1.26 cgd case 0:
596 1.26 cgd typeprintfn = &pci_conf_print_type1;
597 1.26 cgd break;
598 1.26 cgd case 1:
599 1.26 cgd /* XXX */
600 1.26 cgd default:
601 1.26 cgd typeprintfn = 0;
602 1.26 cgd }
603 1.26 cgd if (typeprintfn)
604 1.26 cgd (*typeprintfn)(pc, tag, regs);
605 1.26 cgd else
606 1.26 cgd printf(" Don't know how to pretty-print type %d header.\n",
607 1.26 cgd hdrtype);
608 1.26 cgd printf("\n");
609 1.26 cgd
610 1.26 cgd /* device-dependent header */
611 1.26 cgd printf(" Device-dependent header:\n");
612 1.26 cgd for (off = 64; off < 256; off += 16)
613 1.26 cgd print16regs(off);
614 1.26 cgd printf("\n");
615 1.26 cgd if (printfn)
616 1.26 cgd (*printfn)(pc, tag, regs);
617 1.26 cgd else
618 1.26 cgd printf(" Don't know how to pretty-print device-dependent header.\n");
619 1.26 cgd printf("\n");
620 1.1 mycroft }
621