pci_subr.c revision 1.37 1 /* $NetBSD: pci_subr.c,v 1.37 2000/08/03 19:58:55 nathanw Exp $ */
2
3 /*
4 * Copyright (c) 1997 Zubin D. Dittia. All rights reserved.
5 * Copyright (c) 1995, 1996, 1998
6 * Christopher G. Demetriou. All rights reserved.
7 * Copyright (c) 1994 Charles M. Hannum. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by Charles M. Hannum.
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 /*
36 * PCI autoconfiguration support functions.
37 */
38
39 #include "opt_pci.h"
40
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/device.h>
44
45 #include <machine/intr.h>
46
47 #include <dev/pci/pcireg.h>
48 #include <dev/pci/pcivar.h>
49 #ifdef PCIVERBOSE
50 #include <dev/pci/pcidevs.h>
51 #endif
52
53 static void pci_conf_print_common __P((pci_chipset_tag_t, pcitag_t,
54 const pcireg_t *regs));
55 static int pci_conf_print_bar __P((pci_chipset_tag_t, pcitag_t,
56 const pcireg_t *regs, int, const char *));
57 static void pci_conf_print_regs __P((const pcireg_t *regs, int first,
58 int pastlast));
59 static void pci_conf_print_type0 __P((pci_chipset_tag_t, pcitag_t,
60 const pcireg_t *regs));
61 static void pci_conf_print_type1 __P((pci_chipset_tag_t, pcitag_t,
62 const pcireg_t *regs));
63 static void pci_conf_print_type2 __P((pci_chipset_tag_t, pcitag_t,
64 const pcireg_t *regs));
65
66 /*
67 * Descriptions of known PCI classes and subclasses.
68 *
69 * Subclasses are described in the same way as classes, but have a
70 * NULL subclass pointer.
71 */
72 struct pci_class {
73 char *name;
74 int val; /* as wide as pci_{,sub}class_t */
75 struct pci_class *subclasses;
76 };
77
78 struct pci_class pci_subclass_prehistoric[] = {
79 { "miscellaneous", PCI_SUBCLASS_PREHISTORIC_MISC, },
80 { "VGA", PCI_SUBCLASS_PREHISTORIC_VGA, },
81 { 0 }
82 };
83
84 struct pci_class pci_subclass_mass_storage[] = {
85 { "SCSI", PCI_SUBCLASS_MASS_STORAGE_SCSI, },
86 { "IDE", PCI_SUBCLASS_MASS_STORAGE_IDE, },
87 { "floppy", PCI_SUBCLASS_MASS_STORAGE_FLOPPY, },
88 { "IPI", PCI_SUBCLASS_MASS_STORAGE_IPI, },
89 { "RAID", PCI_SUBCLASS_MASS_STORAGE_RAID, },
90 { "miscellaneous", PCI_SUBCLASS_MASS_STORAGE_MISC, },
91 { 0 },
92 };
93
94 struct pci_class pci_subclass_network[] = {
95 { "ethernet", PCI_SUBCLASS_NETWORK_ETHERNET, },
96 { "token ring", PCI_SUBCLASS_NETWORK_TOKENRING, },
97 { "FDDI", PCI_SUBCLASS_NETWORK_FDDI, },
98 { "ATM", PCI_SUBCLASS_NETWORK_ATM, },
99 { "ISDN", PCI_SUBCLASS_NETWORK_ISDN, },
100 { "miscellaneous", PCI_SUBCLASS_NETWORK_MISC, },
101 { 0 },
102 };
103
104 struct pci_class pci_subclass_display[] = {
105 { "VGA", PCI_SUBCLASS_DISPLAY_VGA, },
106 { "XGA", PCI_SUBCLASS_DISPLAY_XGA, },
107 { "3D", PCI_SUBCLASS_DISPLAY_3D, },
108 { "miscellaneous", PCI_SUBCLASS_DISPLAY_MISC, },
109 { 0 },
110 };
111
112 struct pci_class pci_subclass_multimedia[] = {
113 { "video", PCI_SUBCLASS_MULTIMEDIA_VIDEO, },
114 { "audio", PCI_SUBCLASS_MULTIMEDIA_AUDIO, },
115 { "telephony", PCI_SUBCLASS_MULTIMEDIA_TELEPHONY, },
116 { "miscellaneous", PCI_SUBCLASS_MULTIMEDIA_MISC, },
117 { 0 },
118 };
119
120 struct pci_class pci_subclass_memory[] = {
121 { "RAM", PCI_SUBCLASS_MEMORY_RAM, },
122 { "flash", PCI_SUBCLASS_MEMORY_FLASH, },
123 { "miscellaneous", PCI_SUBCLASS_MEMORY_MISC, },
124 { 0 },
125 };
126
127 struct pci_class pci_subclass_bridge[] = {
128 { "host", PCI_SUBCLASS_BRIDGE_HOST, },
129 { "ISA", PCI_SUBCLASS_BRIDGE_ISA, },
130 { "EISA", PCI_SUBCLASS_BRIDGE_EISA, },
131 { "MicroChannel", PCI_SUBCLASS_BRIDGE_MC, },
132 { "PCI", PCI_SUBCLASS_BRIDGE_PCI, },
133 { "PCMCIA", PCI_SUBCLASS_BRIDGE_PCMCIA, },
134 { "NuBus", PCI_SUBCLASS_BRIDGE_NUBUS, },
135 { "CardBus", PCI_SUBCLASS_BRIDGE_CARDBUS, },
136 { "RACEway", PCI_SUBCLASS_BRIDGE_RACEWAY, },
137 { "miscellaneous", PCI_SUBCLASS_BRIDGE_MISC, },
138 { 0 },
139 };
140
141 struct pci_class pci_subclass_communications[] = {
142 { "serial", PCI_SUBCLASS_COMMUNICATIONS_SERIAL, },
143 { "parallel", PCI_SUBCLASS_COMMUNICATIONS_PARALLEL, },
144 { "multi-port serial", PCI_SUBCLASS_COMMUNICATIONS_MPSERIAL, },
145 { "modem", PCI_SUBCLASS_COMMUNICATIONS_MODEM, },
146 { "miscellaneous", PCI_SUBCLASS_COMMUNICATIONS_MISC, },
147 { 0 },
148 };
149
150 struct pci_class pci_subclass_system[] = {
151 { "8259 PIC", PCI_SUBCLASS_SYSTEM_PIC, },
152 { "8237 DMA", PCI_SUBCLASS_SYSTEM_DMA, },
153 { "8254 timer", PCI_SUBCLASS_SYSTEM_TIMER, },
154 { "RTC", PCI_SUBCLASS_SYSTEM_RTC, },
155 { "PCI Hot-Plug", PCI_SUBCLASS_SYSTEM_RTC, },
156 { "miscellaneous", PCI_SUBCLASS_SYSTEM_MISC, },
157 { 0 },
158 };
159
160 struct pci_class pci_subclass_input[] = {
161 { "keyboard", PCI_SUBCLASS_INPUT_KEYBOARD, },
162 { "digitizer", PCI_SUBCLASS_INPUT_DIGITIZER, },
163 { "mouse", PCI_SUBCLASS_INPUT_MOUSE, },
164 { "scanner", PCI_SUBCLASS_INPUT_SCANNER, },
165 { "game port", PCI_SUBCLASS_INPUT_GAMEPORT, },
166 { "miscellaneous", PCI_SUBCLASS_INPUT_MISC, },
167 { 0 },
168 };
169
170 struct pci_class pci_subclass_dock[] = {
171 { "generic", PCI_SUBCLASS_DOCK_GENERIC, },
172 { "miscellaneous", PCI_SUBCLASS_DOCK_MISC, },
173 { 0 },
174 };
175
176 struct pci_class pci_subclass_processor[] = {
177 { "386", PCI_SUBCLASS_PROCESSOR_386, },
178 { "486", PCI_SUBCLASS_PROCESSOR_486, },
179 { "Pentium", PCI_SUBCLASS_PROCESSOR_PENTIUM, },
180 { "Alpha", PCI_SUBCLASS_PROCESSOR_ALPHA, },
181 { "PowerPC", PCI_SUBCLASS_PROCESSOR_POWERPC, },
182 { "MIPS", PCI_SUBCLASS_PROCESSOR_MIPS, },
183 { "Co-processor", PCI_SUBCLASS_PROCESSOR_COPROC, },
184 { 0 },
185 };
186
187 struct pci_class pci_subclass_serialbus[] = {
188 { "Firewire", PCI_SUBCLASS_SERIALBUS_FIREWIRE, },
189 { "ACCESS.bus", PCI_SUBCLASS_SERIALBUS_ACCESS, },
190 { "SSA", PCI_SUBCLASS_SERIALBUS_SSA, },
191 { "USB", PCI_SUBCLASS_SERIALBUS_USB, },
192 /* XXX Fiber Channel/_FIBRECHANNEL */
193 { "Fiber Channel", PCI_SUBCLASS_SERIALBUS_FIBER, },
194 { "SMBus", PCI_SUBCLASS_SERIALBUS_SMBUS, },
195 { 0 },
196 };
197
198 struct pci_class pci_subclass_wireless[] = {
199 { "iRDA", PCI_SUBCLASS_WIRELESS_IRDA, },
200 { "Consumer IR", PCI_SUBCLASS_WIRELESS_CONSUMERIR, },
201 { "RF", PCI_SUBCLASS_WIRELESS_RF, },
202 { "miscellaneous", PCI_SUBCLASS_WIRELESS_MISC, },
203 { 0 },
204 };
205
206 struct pci_class pci_subclass_i2o[] = {
207 { "1.0", PCI_SUBCLASS_I2O_10, },
208 { 0 },
209 };
210
211 struct pci_class pci_subclass_satcom[] = {
212 { "TV", PCI_SUBCLASS_SATCOM_TV, },
213 { "audio", PCI_SUBCLASS_SATCOM_AUDIO, },
214 { "voice", PCI_SUBCLASS_SATCOM_VOICE, },
215 { "data", PCI_SUBCLASS_SATCOM_DATA, },
216 { 0 },
217 };
218
219 struct pci_class pci_subclass_crypto[] = {
220 { "network/computing", PCI_SUBCLASS_CRYPTO_NETCOMP, },
221 { "entertainment", PCI_SUBCLASS_CRYPTO_ENTERTAINMENT, },
222 { "miscellaneous", PCI_SUBCLASS_CRYPTO_MISC, },
223 { 0 },
224 };
225
226 struct pci_class pci_subclass_dasp[] = {
227 { "DPIO", PCI_SUBCLASS_DASP_DPIO, },
228 { "miscellaneous", PCI_SUBCLASS_DASP_MISC, },
229 { 0 },
230 };
231
232 struct pci_class pci_class[] = {
233 { "prehistoric", PCI_CLASS_PREHISTORIC,
234 pci_subclass_prehistoric, },
235 { "mass storage", PCI_CLASS_MASS_STORAGE,
236 pci_subclass_mass_storage, },
237 { "network", PCI_CLASS_NETWORK,
238 pci_subclass_network, },
239 { "display", PCI_CLASS_DISPLAY,
240 pci_subclass_display, },
241 { "multimedia", PCI_CLASS_MULTIMEDIA,
242 pci_subclass_multimedia, },
243 { "memory", PCI_CLASS_MEMORY,
244 pci_subclass_memory, },
245 { "bridge", PCI_CLASS_BRIDGE,
246 pci_subclass_bridge, },
247 { "communications", PCI_CLASS_COMMUNICATIONS,
248 pci_subclass_communications, },
249 { "system", PCI_CLASS_SYSTEM,
250 pci_subclass_system, },
251 { "input", PCI_CLASS_INPUT,
252 pci_subclass_input, },
253 { "dock", PCI_CLASS_DOCK,
254 pci_subclass_dock, },
255 { "processor", PCI_CLASS_PROCESSOR,
256 pci_subclass_processor, },
257 { "serial bus", PCI_CLASS_SERIALBUS,
258 pci_subclass_serialbus, },
259 { "wireless", PCI_CLASS_WIRELESS,
260 pci_subclass_wireless, },
261 { "I2O", PCI_CLASS_I2O,
262 pci_subclass_i2o, },
263 { "satellite comm", PCI_CLASS_SATCOM,
264 pci_subclass_satcom, },
265 { "crypto", PCI_CLASS_CRYPTO,
266 pci_subclass_crypto, },
267 { "DASP", PCI_CLASS_DASP,
268 pci_subclass_dasp, },
269 { "undefined", PCI_CLASS_UNDEFINED,
270 0, },
271 { 0 },
272 };
273
274 #ifdef PCIVERBOSE
275 /*
276 * Descriptions of of known vendors and devices ("products").
277 */
278 struct pci_knowndev {
279 pci_vendor_id_t vendor;
280 pci_product_id_t product;
281 int flags;
282 char *vendorname, *productname;
283 };
284 #define PCI_KNOWNDEV_NOPROD 0x01 /* match on vendor only */
285
286 #include <dev/pci/pcidevs_data.h>
287 #endif /* PCIVERBOSE */
288
289 char *
290 pci_findvendor(id_reg)
291 pcireg_t id_reg;
292 {
293 #ifdef PCIVERBOSE
294 pci_vendor_id_t vendor = PCI_VENDOR(id_reg);
295 struct pci_knowndev *kdp;
296
297 kdp = pci_knowndevs;
298 while (kdp->vendorname != NULL) { /* all have vendor name */
299 if (kdp->vendor == vendor)
300 break;
301 kdp++;
302 }
303 return (kdp->vendorname);
304 #else
305 return (NULL);
306 #endif
307 }
308
309 void
310 pci_devinfo(id_reg, class_reg, showclass, cp)
311 pcireg_t id_reg, class_reg;
312 int showclass;
313 char *cp;
314 {
315 pci_vendor_id_t vendor;
316 pci_product_id_t product;
317 pci_class_t class;
318 pci_subclass_t subclass;
319 pci_interface_t interface;
320 pci_revision_t revision;
321 char *vendor_namep, *product_namep;
322 struct pci_class *classp, *subclassp;
323 #ifdef PCIVERBOSE
324 struct pci_knowndev *kdp;
325 const char *unmatched = "unknown ";
326 #else
327 const char *unmatched = "";
328 #endif
329
330 vendor = PCI_VENDOR(id_reg);
331 product = PCI_PRODUCT(id_reg);
332
333 class = PCI_CLASS(class_reg);
334 subclass = PCI_SUBCLASS(class_reg);
335 interface = PCI_INTERFACE(class_reg);
336 revision = PCI_REVISION(class_reg);
337
338 #ifdef PCIVERBOSE
339 kdp = pci_knowndevs;
340 while (kdp->vendorname != NULL) { /* all have vendor name */
341 if (kdp->vendor == vendor && (kdp->product == product ||
342 (kdp->flags & PCI_KNOWNDEV_NOPROD) != 0))
343 break;
344 kdp++;
345 }
346 if (kdp->vendorname == NULL)
347 vendor_namep = product_namep = NULL;
348 else {
349 vendor_namep = kdp->vendorname;
350 product_namep = (kdp->flags & PCI_KNOWNDEV_NOPROD) == 0 ?
351 kdp->productname : NULL;
352 }
353 #else /* PCIVERBOSE */
354 vendor_namep = product_namep = NULL;
355 #endif /* PCIVERBOSE */
356
357 classp = pci_class;
358 while (classp->name != NULL) {
359 if (class == classp->val)
360 break;
361 classp++;
362 }
363
364 subclassp = (classp->name != NULL) ? classp->subclasses : NULL;
365 while (subclassp && subclassp->name != NULL) {
366 if (subclass == subclassp->val)
367 break;
368 subclassp++;
369 }
370
371 if (vendor_namep == NULL)
372 cp += sprintf(cp, "%svendor 0x%04x product 0x%04x",
373 unmatched, vendor, product);
374 else if (product_namep != NULL)
375 cp += sprintf(cp, "%s %s", vendor_namep, product_namep);
376 else
377 cp += sprintf(cp, "%s product 0x%04x",
378 vendor_namep, product);
379 if (showclass) {
380 cp += sprintf(cp, " (");
381 if (classp->name == NULL)
382 cp += sprintf(cp, "class 0x%02x, subclass 0x%02x",
383 class, subclass);
384 else {
385 if (subclassp == NULL || subclassp->name == NULL)
386 cp += sprintf(cp,
387 "%s subclass 0x%02x",
388 classp->name, subclass);
389 else
390 cp += sprintf(cp, "%s %s",
391 subclassp->name, classp->name);
392 }
393 if (interface != 0)
394 cp += sprintf(cp, ", interface 0x%02x", interface);
395 if (revision != 0)
396 cp += sprintf(cp, ", revision 0x%02x", revision);
397 cp += sprintf(cp, ")");
398 }
399 }
400
401 /*
402 * Print out most of the PCI configuration registers. Typically used
403 * in a device attach routine like this:
404 *
405 * #ifdef MYDEV_DEBUG
406 * printf("%s: ", sc->sc_dev.dv_xname);
407 * pci_conf_print(pa->pa_pc, pa->pa_tag);
408 * #endif
409 */
410
411 #define i2o(i) ((i) * 4)
412 #define o2i(o) ((o) / 4)
413 #define onoff(str, bit) \
414 printf(" %s: %s\n", (str), (rval & (bit)) ? "on" : "off");
415
416 static void
417 pci_conf_print_common(pc, tag, regs)
418 pci_chipset_tag_t pc;
419 pcitag_t tag;
420 const pcireg_t *regs;
421 {
422 #ifdef PCIVERBOSE
423 struct pci_knowndev *kdp;
424 #endif
425 struct pci_class *classp, *subclassp;
426 pcireg_t rval;
427
428 rval = regs[o2i(PCI_ID_REG)];
429 #ifndef PCIVERBOSE
430 printf(" Vendor ID: 0x%04x\n", PCI_VENDOR(rval));
431 printf(" Device ID: 0x%04x\n", PCI_PRODUCT(rval));
432 #else
433 for (kdp = pci_knowndevs; kdp->vendorname != NULL; kdp++) {
434 if (kdp->vendor == PCI_VENDOR(rval) &&
435 (kdp->product == PCI_PRODUCT(rval) ||
436 (kdp->flags & PCI_KNOWNDEV_NOPROD) != 0)) {
437 break;
438 }
439 }
440 if (kdp->vendorname != NULL)
441 printf(" Vendor Name: %s (0x%04x)\n", kdp->vendorname,
442 PCI_VENDOR(rval));
443 else
444 printf(" Vendor ID: 0x%04x\n", PCI_VENDOR(rval));
445 if (kdp->productname != NULL && (kdp->flags & PCI_KNOWNDEV_NOPROD) == 0)
446 printf(" Device Name: %s (0x%04x)\n", kdp->productname,
447 PCI_PRODUCT(rval));
448 else
449 printf(" Device ID: 0x%04x\n", PCI_PRODUCT(rval));
450 #endif /* PCIVERBOSE */
451
452 rval = regs[o2i(PCI_COMMAND_STATUS_REG)];
453
454 printf(" Command register: 0x%04x\n", rval & 0xffff);
455 onoff("I/O space accesses", PCI_COMMAND_IO_ENABLE);
456 onoff("Memory space accesses", PCI_COMMAND_MEM_ENABLE);
457 onoff("Bus mastering", PCI_COMMAND_MASTER_ENABLE);
458 onoff("Special cycles", PCI_COMMAND_SPECIAL_ENABLE);
459 onoff("MWI transactions", PCI_COMMAND_INVALIDATE_ENABLE);
460 onoff("Palette snooping", PCI_COMMAND_PALETTE_ENABLE);
461 onoff("Parity error checking", PCI_COMMAND_PARITY_ENABLE);
462 onoff("Address/data stepping", PCI_COMMAND_STEPPING_ENABLE);
463 onoff("System error (SERR)", PCI_COMMAND_SERR_ENABLE);
464 onoff("Fast back-to-back transactions", PCI_COMMAND_BACKTOBACK_ENABLE);
465
466 printf(" Status register: 0x%04x\n", (rval >> 16) & 0xffff);
467 onoff("Capability List support", PCI_STATUS_CAPLIST_SUPPORT);
468 onoff("66 MHz capable", PCI_STATUS_66MHZ_SUPPORT);
469 onoff("User Definable Features (UDF) support", PCI_STATUS_UDF_SUPPORT);
470 onoff("Fast back-to-back capable", PCI_STATUS_BACKTOBACK_SUPPORT);
471 onoff("Data parity error detected", PCI_STATUS_PARITY_ERROR);
472
473 printf(" DEVSEL timing: ");
474 switch (rval & PCI_STATUS_DEVSEL_MASK) {
475 case PCI_STATUS_DEVSEL_FAST:
476 printf("fast");
477 break;
478 case PCI_STATUS_DEVSEL_MEDIUM:
479 printf("medium");
480 break;
481 case PCI_STATUS_DEVSEL_SLOW:
482 printf("slow");
483 break;
484 default:
485 printf("unknown/reserved"); /* XXX */
486 break;
487 }
488 printf(" (0x%x)\n", (rval & PCI_STATUS_DEVSEL_MASK) >> 25);
489
490 onoff("Slave signaled Target Abort", PCI_STATUS_TARGET_TARGET_ABORT);
491 onoff("Master received Target Abort", PCI_STATUS_MASTER_TARGET_ABORT);
492 onoff("Master received Master Abort", PCI_STATUS_MASTER_ABORT);
493 onoff("Asserted System Error (SERR)", PCI_STATUS_SPECIAL_ERROR);
494 onoff("Parity error detected", PCI_STATUS_PARITY_DETECT);
495
496 rval = regs[o2i(PCI_CLASS_REG)];
497 for (classp = pci_class; classp->name != NULL; classp++) {
498 if (PCI_CLASS(rval) == classp->val)
499 break;
500 }
501 subclassp = (classp->name != NULL) ? classp->subclasses : NULL;
502 while (subclassp && subclassp->name != NULL) {
503 if (PCI_SUBCLASS(rval) == subclassp->val)
504 break;
505 subclassp++;
506 }
507 if (classp->name != NULL) {
508 printf(" Class Name: %s (0x%02x)\n", classp->name,
509 PCI_CLASS(rval));
510 if (subclassp != NULL && subclassp->name != NULL)
511 printf(" Subclass Name: %s (0x%02x)\n",
512 subclassp->name, PCI_SUBCLASS(rval));
513 else
514 printf(" Subclass ID: 0x%02x\n", PCI_SUBCLASS(rval));
515 } else {
516 printf(" Class ID: 0x%02x\n", PCI_CLASS(rval));
517 printf(" Subclass ID: 0x%02x\n", PCI_SUBCLASS(rval));
518 }
519 printf(" Interface: 0x%02x\n", PCI_INTERFACE(rval));
520 printf(" Revision ID: 0x%02x\n", PCI_REVISION(rval));
521
522 rval = regs[o2i(PCI_BHLC_REG)];
523 printf(" BIST: 0x%02x\n", PCI_BIST(rval));
524 printf(" Header Type: 0x%02x%s (0x%02x)\n", PCI_HDRTYPE_TYPE(rval),
525 PCI_HDRTYPE_MULTIFN(rval) ? "+multifunction" : "",
526 PCI_HDRTYPE(rval));
527 printf(" Latency Timer: 0x%02x\n", PCI_LATTIMER(rval));
528 printf(" Cache Line Size: 0x%02x\n", PCI_CACHELINE(rval));
529 }
530
531 static int
532 pci_conf_print_bar(pc, tag, regs, reg, name)
533 pci_chipset_tag_t pc;
534 pcitag_t tag;
535 const pcireg_t *regs;
536 int reg;
537 const char *name;
538 {
539 int s, width;
540 pcireg_t mask, rval;
541 pcireg_t mask64h, rval64h;
542
543 width = 4;
544
545 /*
546 * Section 6.2.5.1, `Address Maps', tells us that:
547 *
548 * 1) The builtin software should have already mapped the
549 * device in a reasonable way.
550 *
551 * 2) A device which wants 2^n bytes of memory will hardwire
552 * the bottom n bits of the address to 0. As recommended,
553 * we write all 1s and see what we get back.
554 */
555 rval = regs[o2i(reg)];
556 if (rval != 0) {
557 /*
558 * The following sequence seems to make some devices
559 * (e.g. host bus bridges, which don't normally
560 * have their space mapped) very unhappy, to
561 * the point of crashing the system.
562 *
563 * Therefore, if the mapping register is zero to
564 * start out with, don't bother trying.
565 */
566 s = splhigh();
567 pci_conf_write(pc, tag, reg, 0xffffffff);
568 mask = pci_conf_read(pc, tag, reg);
569 pci_conf_write(pc, tag, reg, rval);
570 if (PCI_MAPREG_TYPE(rval) == PCI_MAPREG_TYPE_MEM &&
571 PCI_MAPREG_MEM_TYPE(rval) == PCI_MAPREG_MEM_TYPE_64BIT) {
572 rval64h = regs[o2i(reg + 4)];
573 pci_conf_write(pc, tag, reg + 4, 0xffffffff);
574 mask64h = pci_conf_read(pc, tag, reg + 4);
575 pci_conf_write(pc, tag, reg + 4, rval64h);
576 width = 8;
577 }
578 splx(s);
579 } else
580 mask = 0;
581
582 printf(" Base address register at 0x%02x", reg);
583 if (name)
584 printf(" (%s)", name);
585 printf("\n ");
586 if (rval == 0) {
587 printf("not implemented(?)\n");
588 return width;
589 }
590 printf("type: ");
591 if (PCI_MAPREG_TYPE(rval) == PCI_MAPREG_TYPE_MEM) {
592 const char *type, *prefetch;
593
594 switch (PCI_MAPREG_MEM_TYPE(rval)) {
595 case PCI_MAPREG_MEM_TYPE_32BIT:
596 type = "32-bit";
597 break;
598 case PCI_MAPREG_MEM_TYPE_32BIT_1M:
599 type = "32-bit-1M";
600 break;
601 case PCI_MAPREG_MEM_TYPE_64BIT:
602 type = "64-bit";
603 break;
604 default:
605 type = "unknown (XXX)";
606 break;
607 }
608 if (PCI_MAPREG_MEM_PREFETCHABLE(rval))
609 prefetch = "";
610 else
611 prefetch = "non";
612 printf("%s %sprefetchable memory\n", type, prefetch);
613 switch (PCI_MAPREG_MEM_TYPE(rval)) {
614 case PCI_MAPREG_MEM_TYPE_64BIT:
615 printf(" base: 0x%016llx, size: 0x%016llx\n",
616 PCI_MAPREG_MEM64_ADDR(
617 ((((long long) rval64h) << 32) | rval)),
618 PCI_MAPREG_MEM64_SIZE(
619 ((((long long) mask64h) << 32) | mask)));
620 break;
621 case PCI_MAPREG_MEM_TYPE_32BIT:
622 case PCI_MAPREG_MEM_TYPE_32BIT_1M:
623 default:
624 printf(" base: 0x%08x, size: 0x%08x\n",
625 PCI_MAPREG_MEM_ADDR(rval),
626 PCI_MAPREG_MEM_SIZE(mask));
627 break;
628 }
629
630 } else {
631 printf("i/o\n");
632 printf(" base: 0x%08x, size: 0x%08x\n",
633 PCI_MAPREG_IO_ADDR(rval),
634 PCI_MAPREG_IO_SIZE(mask));
635 }
636
637 return width;
638 }
639
640 static void
641 pci_conf_print_regs(regs, first, pastlast)
642 const pcireg_t *regs;
643 int first, pastlast;
644 {
645 int off, needaddr, neednl;
646
647 needaddr = 1;
648 neednl = 0;
649 for (off = first; off < pastlast; off += 4) {
650 if ((off % 16) == 0 || needaddr) {
651 printf(" 0x%02x:", off);
652 needaddr = 0;
653 }
654 printf(" 0x%08x", regs[o2i(off)]);
655 neednl = 1;
656 if ((off % 16) == 12) {
657 printf("\n");
658 neednl = 0;
659 }
660 }
661 if (neednl)
662 printf("\n");
663 }
664
665 static void
666 pci_conf_print_type0(pc, tag, regs)
667 pci_chipset_tag_t pc;
668 pcitag_t tag;
669 const pcireg_t *regs;
670 {
671 int off, width;
672 pcireg_t rval;
673
674 for (off = PCI_MAPREG_START; off < PCI_MAPREG_END; off += width)
675 width = pci_conf_print_bar(pc, tag, regs, off, NULL);
676
677 printf(" Cardbus CIS Pointer: 0x%08x\n", regs[o2i(0x28)]);
678
679 rval = regs[o2i(PCI_SUBSYS_ID_REG)];
680 printf(" Subsystem vendor ID: 0x%04x\n", PCI_VENDOR(rval));
681 printf(" Subsystem ID: 0x%04x\n", PCI_PRODUCT(rval));
682
683 /* XXX */
684 printf(" Expansion ROM Base Address: 0x%08x\n", regs[o2i(0x30)]);
685
686 if (regs[o2i(PCI_COMMAND_STATUS_REG)] & PCI_STATUS_CAPLIST_SUPPORT)
687 printf(" Capability list pointer: 0x%02x\n",
688 PCI_CAPLIST_PTR(regs[o2i(PCI_CAPLISTPTR_REG)]));
689 else
690 printf(" Reserved @ 0x34: 0x%08x\n", regs[o2i(0x34)]);
691
692 printf(" Reserved @ 0x38: 0x%08x\n", regs[o2i(0x38)]);
693
694 rval = regs[o2i(PCI_INTERRUPT_REG)];
695 printf(" Maximum Latency: 0x%02x\n", (rval >> 24) & 0xff);
696 printf(" Minimum Grant: 0x%02x\n", (rval >> 16) & 0xff);
697 printf(" Interrupt pin: 0x%02x ", PCI_INTERRUPT_PIN(rval));
698 switch (PCI_INTERRUPT_PIN(rval)) {
699 case PCI_INTERRUPT_PIN_NONE:
700 printf("(none)");
701 break;
702 case PCI_INTERRUPT_PIN_A:
703 printf("(pin A)");
704 break;
705 case PCI_INTERRUPT_PIN_B:
706 printf("(pin B)");
707 break;
708 case PCI_INTERRUPT_PIN_C:
709 printf("(pin C)");
710 break;
711 case PCI_INTERRUPT_PIN_D:
712 printf("(pin D)");
713 break;
714 default:
715 printf("(? ? ?)");
716 break;
717 }
718 printf("\n");
719 printf(" Interrupt line: 0x%02x\n", PCI_INTERRUPT_LINE(rval));
720
721 if (regs[o2i(PCI_COMMAND_STATUS_REG)] & PCI_STATUS_CAPLIST_SUPPORT) {
722 for (off = PCI_CAPLIST_PTR(regs[o2i(PCI_CAPLISTPTR_REG)]);
723 off != 0;
724 off = PCI_CAPLIST_NEXT(regs[o2i(off)])) {
725 rval = regs[o2i(off)];
726 printf(" Capability register at 0x%02x\n", off);
727
728 printf(" type: 0x%02x (", PCI_CAPLIST_CAP(rval));
729 switch (PCI_CAPLIST_CAP(rval)) {
730 case PCI_CAP_PWRMGMT:
731 printf("Power Management, rev. %d.0",
732 (rval >> 0) & 0x07); /* XXX not clear */
733 break;
734 case PCI_CAP_AGP:
735 printf("AGP, rev. %d.%d",
736 (rval >> 24) & 0x0f,
737 (rval >> 20) & 0x0f);
738 break;
739 case PCI_CAP_VPD:
740 printf("VPD");
741 break;
742 case PCI_CAP_SLOTID:
743 printf("SlotID");
744 break;
745 case PCI_CAP_MBI:
746 printf("MBI");
747 break;
748 case PCI_CAP_HOTSWAP:
749 printf("Hot-swapping");
750 break;
751 default:
752 printf("unknown/reserved");
753 }
754 printf(")\n");
755 }
756 }
757 }
758
759 static void
760 pci_conf_print_type1(pc, tag, regs)
761 pci_chipset_tag_t pc;
762 pcitag_t tag;
763 const pcireg_t *regs;
764 {
765 int off, width;
766 pcireg_t rval;
767
768 /*
769 * XXX these need to be printed in more detail, need to be
770 * XXX checked against specs/docs, etc.
771 *
772 * This layout was cribbed from the TI PCI2030 PCI-to-PCI
773 * Bridge chip documentation, and may not be correct with
774 * respect to various standards. (XXX)
775 */
776
777 for (off = 0x10; off < 0x18; off += width)
778 width = pci_conf_print_bar(pc, tag, regs, off, NULL);
779
780 printf(" Primary bus number: 0x%02x\n",
781 (regs[o2i(0x18)] >> 0) & 0xff);
782 printf(" Secondary bus number: 0x%02x\n",
783 (regs[o2i(0x18)] >> 8) & 0xff);
784 printf(" Subordinate bus number: 0x%02x\n",
785 (regs[o2i(0x18)] >> 16) & 0xff);
786 printf(" Secondary bus latency timer: 0x%02x\n",
787 (regs[o2i(0x18)] >> 24) & 0xff);
788
789 rval = (regs[o2i(0x1c)] >> 16) & 0xffff;
790 printf(" Secondary status register: 0x%04x\n", rval); /* XXX bits */
791 onoff("66 MHz capable", 0x0020);
792 onoff("User Definable Features (UDF) support", 0x0040);
793 onoff("Fast back-to-back capable", 0x0080);
794 onoff("Data parity error detected", 0x0100);
795
796 printf(" DEVSEL timing: ");
797 switch (rval & 0x0600) {
798 case 0x0000:
799 printf("fast");
800 break;
801 case 0x0200:
802 printf("medium");
803 break;
804 case 0x0400:
805 printf("slow");
806 break;
807 default:
808 printf("unknown/reserved"); /* XXX */
809 break;
810 }
811 printf(" (0x%x)\n", (rval & 0x0600) >> 9);
812
813 onoff("Signaled Target Abort", 0x0800);
814 onoff("Received Target Abort", 0x1000);
815 onoff("Received Master Abort", 0x2000);
816 onoff("System Error", 0x4000);
817 onoff("Parity Error", 0x8000);
818
819 /* XXX Print more prettily */
820 printf(" I/O region:\n");
821 printf(" base register: 0x%02x\n", (regs[o2i(0x1c)] >> 0) & 0xff);
822 printf(" limit register: 0x%02x\n", (regs[o2i(0x1c)] >> 8) & 0xff);
823 printf(" base upper 16 bits register: 0x%04x\n",
824 (regs[o2i(0x30)] >> 0) & 0xffff);
825 printf(" limit upper 16 bits register: 0x%04x\n",
826 (regs[o2i(0x30)] >> 16) & 0xffff);
827
828 /* XXX Print more prettily */
829 printf(" Memory region:\n");
830 printf(" base register: 0x%04x\n",
831 (regs[o2i(0x20)] >> 0) & 0xffff);
832 printf(" limit register: 0x%04x\n",
833 (regs[o2i(0x20)] >> 16) & 0xffff);
834
835 /* XXX Print more prettily */
836 printf(" Prefetchable memory region:\n");
837 printf(" base register: 0x%04x\n",
838 (regs[o2i(0x24)] >> 0) & 0xffff);
839 printf(" limit register: 0x%04x\n",
840 (regs[o2i(0x24)] >> 16) & 0xffff);
841 printf(" base upper 32 bits register: 0x%08x\n", regs[o2i(0x28)]);
842 printf(" limit upper 32 bits register: 0x%08x\n", regs[o2i(0x2c)]);
843
844 printf(" Reserved @ 0x34: 0x%08x\n", regs[o2i(0x34)]);
845 /* XXX */
846 printf(" Expansion ROM Base Address: 0x%08x\n", regs[o2i(0x38)]);
847
848 printf(" Interrupt line: 0x%02x\n",
849 (regs[o2i(0x3c)] >> 0) & 0xff);
850 printf(" Interrupt pin: 0x%02x ",
851 (regs[o2i(0x3c)] >> 8) & 0xff);
852 switch ((regs[o2i(0x3c)] >> 8) & 0xff) {
853 case PCI_INTERRUPT_PIN_NONE:
854 printf("(none)");
855 break;
856 case PCI_INTERRUPT_PIN_A:
857 printf("(pin A)");
858 break;
859 case PCI_INTERRUPT_PIN_B:
860 printf("(pin B)");
861 break;
862 case PCI_INTERRUPT_PIN_C:
863 printf("(pin C)");
864 break;
865 case PCI_INTERRUPT_PIN_D:
866 printf("(pin D)");
867 break;
868 default:
869 printf("(? ? ?)");
870 break;
871 }
872 printf("\n");
873 rval = (regs[o2i(0x3c)] >> 16) & 0xffff;
874 printf(" Bridge control register: 0x%04x\n", rval); /* XXX bits */
875 onoff("Parity error response", 0x0001);
876 onoff("Secondary SERR forwarding", 0x0002);
877 onoff("ISA enable", 0x0004);
878 onoff("VGA enable", 0x0008);
879 onoff("Master abort reporting", 0x0020);
880 onoff("Secondary bus reset", 0x0040);
881 onoff("Fast back-to-back capable", 0x0080);
882 }
883
884 static void
885 pci_conf_print_type2(pc, tag, regs)
886 pci_chipset_tag_t pc;
887 pcitag_t tag;
888 const pcireg_t *regs;
889 {
890 pcireg_t rval;
891
892 /*
893 * XXX these need to be printed in more detail, need to be
894 * XXX checked against specs/docs, etc.
895 *
896 * This layout was cribbed from the TI PCI1130 PCI-to-CardBus
897 * controller chip documentation, and may not be correct with
898 * respect to various standards. (XXX)
899 */
900
901 pci_conf_print_bar(pc, tag, regs, 0x10,
902 "CardBus socket/ExCA registers");
903
904 printf(" Reserved @ 0x14: 0x%04x\n",
905 (regs[o2i(0x14)] >> 0) & 0xffff);
906 rval = (regs[o2i(0x14)] >> 16) & 0xffff;
907 printf(" Secondary status register: 0x%04x\n", rval);
908 onoff("66 MHz capable", 0x0020);
909 onoff("User Definable Features (UDF) support", 0x0040);
910 onoff("Fast back-to-back capable", 0x0080);
911 onoff("Data parity error detection", 0x0100);
912
913 printf(" DEVSEL timing: ");
914 switch (rval & 0x0600) {
915 case 0x0000:
916 printf("fast");
917 break;
918 case 0x0200:
919 printf("medium");
920 break;
921 case 0x0400:
922 printf("slow");
923 break;
924 default:
925 printf("unknown/reserved"); /* XXX */
926 break;
927 }
928 printf(" (0x%x)\n", (rval & 0x0600) >> 9);
929 onoff("PCI target aborts terminate CardBus bus master transactions",
930 0x0800);
931 onoff("CardBus target aborts terminate PCI bus master transactions",
932 0x1000);
933 onoff("Bus initiator aborts terminate initiator transactions",
934 0x2000);
935 onoff("System error", 0x4000);
936 onoff("Parity error", 0x8000);
937
938 printf(" PCI bus number: 0x%02x\n",
939 (regs[o2i(0x18)] >> 0) & 0xff);
940 printf(" CardBus bus number: 0x%02x\n",
941 (regs[o2i(0x18)] >> 8) & 0xff);
942 printf(" Subordinate bus number: 0x%02x\n",
943 (regs[o2i(0x18)] >> 16) & 0xff);
944 printf(" CardBus latency timer: 0x%02x\n",
945 (regs[o2i(0x18)] >> 24) & 0xff);
946
947 /* XXX Print more prettily */
948 printf(" CardBus memory region 0:\n");
949 printf(" base register: 0x%08x\n", regs[o2i(0x1c)]);
950 printf(" limit register: 0x%08x\n", regs[o2i(0x20)]);
951 printf(" CardBus memory region 1:\n");
952 printf(" base register: 0x%08x\n", regs[o2i(0x24)]);
953 printf(" limit register: 0x%08x\n", regs[o2i(0x28)]);
954 printf(" CardBus I/O region 0:\n");
955 printf(" base register: 0x%08x\n", regs[o2i(0x2c)]);
956 printf(" limit register: 0x%08x\n", regs[o2i(0x30)]);
957 printf(" CardBus I/O region 1:\n");
958 printf(" base register: 0x%08x\n", regs[o2i(0x34)]);
959 printf(" limit register: 0x%08x\n", regs[o2i(0x38)]);
960
961 printf(" Interrupt line: 0x%02x\n",
962 (regs[o2i(0x3c)] >> 0) & 0xff);
963 printf(" Interrupt pin: 0x%02x ",
964 (regs[o2i(0x3c)] >> 8) & 0xff);
965 switch ((regs[o2i(0x3c)] >> 8) & 0xff) {
966 case PCI_INTERRUPT_PIN_NONE:
967 printf("(none)");
968 break;
969 case PCI_INTERRUPT_PIN_A:
970 printf("(pin A)");
971 break;
972 case PCI_INTERRUPT_PIN_B:
973 printf("(pin B)");
974 break;
975 case PCI_INTERRUPT_PIN_C:
976 printf("(pin C)");
977 break;
978 case PCI_INTERRUPT_PIN_D:
979 printf("(pin D)");
980 break;
981 default:
982 printf("(? ? ?)");
983 break;
984 }
985 printf("\n");
986 rval = (regs[o2i(0x3c)] >> 16) & 0xffff;
987 printf(" Bridge control register: 0x%04x\n", rval);
988 onoff("Parity error response", 0x0001);
989 onoff("CardBus SERR forwarding", 0x0002);
990 onoff("ISA enable", 0x0004);
991 onoff("VGA enable", 0x0008);
992 onoff("CardBus master abort reporting", 0x0020);
993 onoff("CardBus reset", 0x0040);
994 onoff("Functional interrupts routed by ExCA registers", 0x0080);
995 onoff("Memory window 0 prefetchable", 0x0100);
996 onoff("Memory window 1 prefetchable", 0x0200);
997 onoff("Write posting enable", 0x0400);
998
999 rval = regs[o2i(0x40)];
1000 printf(" Subsystem vendor ID: 0x%04x\n", PCI_VENDOR(rval));
1001 printf(" Subsystem ID: 0x%04x\n", PCI_PRODUCT(rval));
1002
1003 pci_conf_print_bar(pc, tag, regs, 0x44, "legacy-mode registers");
1004 }
1005
1006 void
1007 pci_conf_print(pc, tag, printfn)
1008 pci_chipset_tag_t pc;
1009 pcitag_t tag;
1010 void (*printfn)(pci_chipset_tag_t, pcitag_t, const pcireg_t *);
1011 {
1012 pcireg_t regs[o2i(256)];
1013 int off, endoff, hdrtype;
1014 const char *typename;
1015 void (*typeprintfn)(pci_chipset_tag_t, pcitag_t, const pcireg_t *);
1016
1017 printf("PCI configuration registers:\n");
1018
1019 for (off = 0; off < 256; off += 4)
1020 regs[o2i(off)] = pci_conf_read(pc, tag, off);
1021
1022 /* common header */
1023 printf(" Common header:\n");
1024 pci_conf_print_regs(regs, 0, 16);
1025
1026 printf("\n");
1027 pci_conf_print_common(pc, tag, regs);
1028 printf("\n");
1029
1030 /* type-dependent header */
1031 hdrtype = PCI_HDRTYPE_TYPE(regs[o2i(PCI_BHLC_REG)]);
1032 switch (hdrtype) { /* XXX make a table, eventually */
1033 case 0:
1034 /* Standard device header */
1035 typename = "\"normal\" device";
1036 typeprintfn = &pci_conf_print_type0;
1037 endoff = 64;
1038 break;
1039 case 1:
1040 /* PCI-PCI bridge header */
1041 typename = "PCI-PCI bridge";
1042 typeprintfn = &pci_conf_print_type1;
1043 endoff = 64;
1044 break;
1045 case 2:
1046 /* PCI-CardBus bridge header */
1047 typename = "PCI-CardBus bridge";
1048 typeprintfn = &pci_conf_print_type2;
1049 endoff = 72;
1050 break;
1051 default:
1052 typename = NULL;
1053 typeprintfn = 0;
1054 endoff = 64;
1055 break;
1056 }
1057 printf(" Type %d ", hdrtype);
1058 if (typename != NULL)
1059 printf("(%s) ", typename);
1060 printf("header:\n");
1061 pci_conf_print_regs(regs, 16, endoff);
1062 printf("\n");
1063 if (typeprintfn)
1064 (*typeprintfn)(pc, tag, regs);
1065 else
1066 printf(" Don't know how to pretty-print type %d header.\n",
1067 hdrtype);
1068 printf("\n");
1069
1070 /* device-dependent header */
1071 printf(" Device-dependent header:\n");
1072 pci_conf_print_regs(regs, endoff, 256);
1073 printf("\n");
1074 if (printfn)
1075 (*printfn)(pc, tag, regs);
1076 else
1077 printf(" Don't know how to pretty-print device-dependent header.\n");
1078 printf("\n");
1079 }
1080