pci_subr.c revision 1.114 1 /* $NetBSD: pci_subr.c,v 1.114 2014/05/23 18:32:13 msaitoh Exp $ */
2
3 /*
4 * Copyright (c) 1997 Zubin D. Dittia. All rights reserved.
5 * Copyright (c) 1995, 1996, 1998, 2000
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 * Note: This file is also built into a userland library (libpci).
39 * Pay attention to this when you make modifications.
40 */
41
42 #include <sys/cdefs.h>
43 __KERNEL_RCSID(0, "$NetBSD: pci_subr.c,v 1.114 2014/05/23 18:32:13 msaitoh Exp $");
44
45 #ifdef _KERNEL_OPT
46 #include "opt_pci.h"
47 #endif
48
49 #include <sys/param.h>
50
51 #ifdef _KERNEL
52 #include <sys/systm.h>
53 #include <sys/intr.h>
54 #include <sys/module.h>
55 #else
56 #include <pci.h>
57 #include <stdbool.h>
58 #include <stdio.h>
59 #endif
60
61 #include <dev/pci/pcireg.h>
62 #ifdef _KERNEL
63 #include <dev/pci/pcivar.h>
64 #endif
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 const char *name;
74 u_int val; /* as wide as pci_{,sub}class_t */
75 const struct pci_class *subclasses;
76 };
77
78 static const struct pci_class pci_subclass_prehistoric[] = {
79 { "miscellaneous", PCI_SUBCLASS_PREHISTORIC_MISC, NULL, },
80 { "VGA", PCI_SUBCLASS_PREHISTORIC_VGA, NULL, },
81 { NULL, 0, NULL, },
82 };
83
84 static const struct pci_class pci_subclass_mass_storage[] = {
85 { "SCSI", PCI_SUBCLASS_MASS_STORAGE_SCSI, NULL, },
86 { "IDE", PCI_SUBCLASS_MASS_STORAGE_IDE, NULL, },
87 { "floppy", PCI_SUBCLASS_MASS_STORAGE_FLOPPY, NULL, },
88 { "IPI", PCI_SUBCLASS_MASS_STORAGE_IPI, NULL, },
89 { "RAID", PCI_SUBCLASS_MASS_STORAGE_RAID, NULL, },
90 { "ATA", PCI_SUBCLASS_MASS_STORAGE_ATA, NULL, },
91 { "SATA", PCI_SUBCLASS_MASS_STORAGE_SATA, NULL, },
92 { "SAS", PCI_SUBCLASS_MASS_STORAGE_SAS, NULL, },
93 { "NVM", PCI_SUBCLASS_MASS_STORAGE_NVM, NULL, },
94 { "miscellaneous", PCI_SUBCLASS_MASS_STORAGE_MISC, NULL, },
95 { NULL, 0, NULL, },
96 };
97
98 static const struct pci_class pci_subclass_network[] = {
99 { "ethernet", PCI_SUBCLASS_NETWORK_ETHERNET, NULL, },
100 { "token ring", PCI_SUBCLASS_NETWORK_TOKENRING, NULL, },
101 { "FDDI", PCI_SUBCLASS_NETWORK_FDDI, NULL, },
102 { "ATM", PCI_SUBCLASS_NETWORK_ATM, NULL, },
103 { "ISDN", PCI_SUBCLASS_NETWORK_ISDN, NULL, },
104 { "WorldFip", PCI_SUBCLASS_NETWORK_WORLDFIP, NULL, },
105 { "PCMIG Multi Computing", PCI_SUBCLASS_NETWORK_PCIMGMULTICOMP, NULL, },
106 { "miscellaneous", PCI_SUBCLASS_NETWORK_MISC, NULL, },
107 { NULL, 0, NULL, },
108 };
109
110 static const struct pci_class pci_subclass_display[] = {
111 { "VGA", PCI_SUBCLASS_DISPLAY_VGA, NULL, },
112 { "XGA", PCI_SUBCLASS_DISPLAY_XGA, NULL, },
113 { "3D", PCI_SUBCLASS_DISPLAY_3D, NULL, },
114 { "miscellaneous", PCI_SUBCLASS_DISPLAY_MISC, NULL, },
115 { NULL, 0, NULL, },
116 };
117
118 static const struct pci_class pci_subclass_multimedia[] = {
119 { "video", PCI_SUBCLASS_MULTIMEDIA_VIDEO, NULL, },
120 { "audio", PCI_SUBCLASS_MULTIMEDIA_AUDIO, NULL, },
121 { "telephony", PCI_SUBCLASS_MULTIMEDIA_TELEPHONY, NULL,},
122 { "HD audio", PCI_SUBCLASS_MULTIMEDIA_HDAUDIO, NULL, },
123 { "miscellaneous", PCI_SUBCLASS_MULTIMEDIA_MISC, NULL, },
124 { NULL, 0, NULL, },
125 };
126
127 static const struct pci_class pci_subclass_memory[] = {
128 { "RAM", PCI_SUBCLASS_MEMORY_RAM, NULL, },
129 { "flash", PCI_SUBCLASS_MEMORY_FLASH, NULL, },
130 { "miscellaneous", PCI_SUBCLASS_MEMORY_MISC, NULL, },
131 { NULL, 0, NULL, },
132 };
133
134 static const struct pci_class pci_subclass_bridge[] = {
135 { "host", PCI_SUBCLASS_BRIDGE_HOST, NULL, },
136 { "ISA", PCI_SUBCLASS_BRIDGE_ISA, NULL, },
137 { "EISA", PCI_SUBCLASS_BRIDGE_EISA, NULL, },
138 { "MicroChannel", PCI_SUBCLASS_BRIDGE_MC, NULL, },
139 { "PCI", PCI_SUBCLASS_BRIDGE_PCI, NULL, },
140 { "PCMCIA", PCI_SUBCLASS_BRIDGE_PCMCIA, NULL, },
141 { "NuBus", PCI_SUBCLASS_BRIDGE_NUBUS, NULL, },
142 { "CardBus", PCI_SUBCLASS_BRIDGE_CARDBUS, NULL, },
143 { "RACEway", PCI_SUBCLASS_BRIDGE_RACEWAY, NULL, },
144 { "Semi-transparent PCI", PCI_SUBCLASS_BRIDGE_STPCI, NULL, },
145 { "InfiniBand", PCI_SUBCLASS_BRIDGE_INFINIBAND, NULL, },
146 { "miscellaneous", PCI_SUBCLASS_BRIDGE_MISC, NULL, },
147 { NULL, 0, NULL, },
148 };
149
150 static const struct pci_class pci_subclass_communications[] = {
151 { "serial", PCI_SUBCLASS_COMMUNICATIONS_SERIAL, NULL, },
152 { "parallel", PCI_SUBCLASS_COMMUNICATIONS_PARALLEL, NULL, },
153 { "multi-port serial", PCI_SUBCLASS_COMMUNICATIONS_MPSERIAL, NULL, },
154 { "modem", PCI_SUBCLASS_COMMUNICATIONS_MODEM, NULL, },
155 { "GPIB", PCI_SUBCLASS_COMMUNICATIONS_GPIB, NULL, },
156 { "smartcard", PCI_SUBCLASS_COMMUNICATIONS_SMARTCARD, NULL, },
157 { "miscellaneous", PCI_SUBCLASS_COMMUNICATIONS_MISC, NULL, },
158 { NULL, 0, NULL, },
159 };
160
161 static const struct pci_class pci_subclass_system[] = {
162 { "interrupt", PCI_SUBCLASS_SYSTEM_PIC, NULL, },
163 { "8237 DMA", PCI_SUBCLASS_SYSTEM_DMA, NULL, },
164 { "8254 timer", PCI_SUBCLASS_SYSTEM_TIMER, NULL, },
165 { "RTC", PCI_SUBCLASS_SYSTEM_RTC, NULL, },
166 { "PCI Hot-Plug", PCI_SUBCLASS_SYSTEM_PCIHOTPLUG, NULL, },
167 { "SD Host Controller", PCI_SUBCLASS_SYSTEM_SDHC, NULL, },
168 { "miscellaneous", PCI_SUBCLASS_SYSTEM_MISC, NULL, },
169 { NULL, 0, NULL, },
170 };
171
172 static const struct pci_class pci_subclass_input[] = {
173 { "keyboard", PCI_SUBCLASS_INPUT_KEYBOARD, NULL, },
174 { "digitizer", PCI_SUBCLASS_INPUT_DIGITIZER, NULL, },
175 { "mouse", PCI_SUBCLASS_INPUT_MOUSE, NULL, },
176 { "scanner", PCI_SUBCLASS_INPUT_SCANNER, NULL, },
177 { "game port", PCI_SUBCLASS_INPUT_GAMEPORT, NULL, },
178 { "miscellaneous", PCI_SUBCLASS_INPUT_MISC, NULL, },
179 { NULL, 0, NULL, },
180 };
181
182 static const struct pci_class pci_subclass_dock[] = {
183 { "generic", PCI_SUBCLASS_DOCK_GENERIC, NULL, },
184 { "miscellaneous", PCI_SUBCLASS_DOCK_MISC, NULL, },
185 { NULL, 0, NULL, },
186 };
187
188 static const struct pci_class pci_subclass_processor[] = {
189 { "386", PCI_SUBCLASS_PROCESSOR_386, NULL, },
190 { "486", PCI_SUBCLASS_PROCESSOR_486, NULL, },
191 { "Pentium", PCI_SUBCLASS_PROCESSOR_PENTIUM, NULL, },
192 { "Alpha", PCI_SUBCLASS_PROCESSOR_ALPHA, NULL, },
193 { "PowerPC", PCI_SUBCLASS_PROCESSOR_POWERPC, NULL, },
194 { "MIPS", PCI_SUBCLASS_PROCESSOR_MIPS, NULL, },
195 { "Co-processor", PCI_SUBCLASS_PROCESSOR_COPROC, NULL, },
196 { NULL, 0, NULL, },
197 };
198
199 static const struct pci_class pci_subclass_serialbus[] = {
200 { "Firewire", PCI_SUBCLASS_SERIALBUS_FIREWIRE, NULL, },
201 { "ACCESS.bus", PCI_SUBCLASS_SERIALBUS_ACCESS, NULL, },
202 { "SSA", PCI_SUBCLASS_SERIALBUS_SSA, NULL, },
203 { "USB", PCI_SUBCLASS_SERIALBUS_USB, NULL, },
204 /* XXX Fiber Channel/_FIBRECHANNEL */
205 { "Fiber Channel", PCI_SUBCLASS_SERIALBUS_FIBER, NULL, },
206 { "SMBus", PCI_SUBCLASS_SERIALBUS_SMBUS, NULL, },
207 { "InfiniBand", PCI_SUBCLASS_SERIALBUS_INFINIBAND, NULL,},
208 { "IPMI", PCI_SUBCLASS_SERIALBUS_IPMI, NULL, },
209 { "SERCOS", PCI_SUBCLASS_SERIALBUS_SERCOS, NULL, },
210 { "CANbus", PCI_SUBCLASS_SERIALBUS_CANBUS, NULL, },
211 { "miscellaneous", PCI_SUBCLASS_SERIALBUS_MISC, NULL, },
212 { NULL, 0, NULL, },
213 };
214
215 static const struct pci_class pci_subclass_wireless[] = {
216 { "IrDA", PCI_SUBCLASS_WIRELESS_IRDA, NULL, },
217 { "Consumer IR", PCI_SUBCLASS_WIRELESS_CONSUMERIR, NULL, },
218 { "RF", PCI_SUBCLASS_WIRELESS_RF, NULL, },
219 { "bluetooth", PCI_SUBCLASS_WIRELESS_BLUETOOTH, NULL, },
220 { "broadband", PCI_SUBCLASS_WIRELESS_BROADBAND, NULL, },
221 { "802.11a (5 GHz)", PCI_SUBCLASS_WIRELESS_802_11A, NULL, },
222 { "802.11b (2.4 GHz)", PCI_SUBCLASS_WIRELESS_802_11B, NULL, },
223 { "miscellaneous", PCI_SUBCLASS_WIRELESS_MISC, NULL, },
224 { NULL, 0, NULL, },
225 };
226
227 static const struct pci_class pci_subclass_i2o[] = {
228 { "standard", PCI_SUBCLASS_I2O_STANDARD, NULL, },
229 { "miscellaneous", PCI_SUBCLASS_I2O_MISC, NULL, },
230 { NULL, 0, NULL, },
231 };
232
233 static const struct pci_class pci_subclass_satcom[] = {
234 { "TV", PCI_SUBCLASS_SATCOM_TV, NULL, },
235 { "audio", PCI_SUBCLASS_SATCOM_AUDIO, NULL, },
236 { "voice", PCI_SUBCLASS_SATCOM_VOICE, NULL, },
237 { "data", PCI_SUBCLASS_SATCOM_DATA, NULL, },
238 { "miscellaneous", PCI_SUBCLASS_SATCOM_MISC, NULL, },
239 { NULL, 0, NULL, },
240 };
241
242 static const struct pci_class pci_subclass_crypto[] = {
243 { "network/computing", PCI_SUBCLASS_CRYPTO_NETCOMP, NULL, },
244 { "entertainment", PCI_SUBCLASS_CRYPTO_ENTERTAINMENT, NULL,},
245 { "miscellaneous", PCI_SUBCLASS_CRYPTO_MISC, NULL, },
246 { NULL, 0, NULL, },
247 };
248
249 static const struct pci_class pci_subclass_dasp[] = {
250 { "DPIO", PCI_SUBCLASS_DASP_DPIO, NULL, },
251 { "Time and Frequency", PCI_SUBCLASS_DASP_TIMEFREQ, NULL, },
252 { "synchronization", PCI_SUBCLASS_DASP_SYNC, NULL, },
253 { "management", PCI_SUBCLASS_DASP_MGMT, NULL, },
254 { "miscellaneous", PCI_SUBCLASS_DASP_MISC, NULL, },
255 { NULL, 0, NULL, },
256 };
257
258 static const struct pci_class pci_class[] = {
259 { "prehistoric", PCI_CLASS_PREHISTORIC,
260 pci_subclass_prehistoric, },
261 { "mass storage", PCI_CLASS_MASS_STORAGE,
262 pci_subclass_mass_storage, },
263 { "network", PCI_CLASS_NETWORK,
264 pci_subclass_network, },
265 { "display", PCI_CLASS_DISPLAY,
266 pci_subclass_display, },
267 { "multimedia", PCI_CLASS_MULTIMEDIA,
268 pci_subclass_multimedia, },
269 { "memory", PCI_CLASS_MEMORY,
270 pci_subclass_memory, },
271 { "bridge", PCI_CLASS_BRIDGE,
272 pci_subclass_bridge, },
273 { "communications", PCI_CLASS_COMMUNICATIONS,
274 pci_subclass_communications, },
275 { "system", PCI_CLASS_SYSTEM,
276 pci_subclass_system, },
277 { "input", PCI_CLASS_INPUT,
278 pci_subclass_input, },
279 { "dock", PCI_CLASS_DOCK,
280 pci_subclass_dock, },
281 { "processor", PCI_CLASS_PROCESSOR,
282 pci_subclass_processor, },
283 { "serial bus", PCI_CLASS_SERIALBUS,
284 pci_subclass_serialbus, },
285 { "wireless", PCI_CLASS_WIRELESS,
286 pci_subclass_wireless, },
287 { "I2O", PCI_CLASS_I2O,
288 pci_subclass_i2o, },
289 { "satellite comm", PCI_CLASS_SATCOM,
290 pci_subclass_satcom, },
291 { "crypto", PCI_CLASS_CRYPTO,
292 pci_subclass_crypto, },
293 { "DASP", PCI_CLASS_DASP,
294 pci_subclass_dasp, },
295 { "undefined", PCI_CLASS_UNDEFINED,
296 NULL, },
297 { NULL, 0,
298 NULL, },
299 };
300
301 void pci_load_verbose(void);
302
303 #if defined(_KERNEL)
304 /*
305 * In kernel, these routines are provided and linked via the
306 * pciverbose module.
307 */
308 const char *pci_findvendor_stub(pcireg_t);
309 const char *pci_findproduct_stub(pcireg_t);
310
311 const char *(*pci_findvendor)(pcireg_t) = pci_findvendor_stub;
312 const char *(*pci_findproduct)(pcireg_t) = pci_findproduct_stub;
313 const char *pci_unmatched = "";
314 #else
315 /*
316 * For userland we just set the vectors here.
317 */
318 const char *(*pci_findvendor)(pcireg_t id_reg) = pci_findvendor_real;
319 const char *(*pci_findproduct)(pcireg_t id_reg) = pci_findproduct_real;
320 const char *pci_unmatched = "unmatched ";
321 #endif
322
323 int pciverbose_loaded = 0;
324
325 #if defined(_KERNEL)
326 /*
327 * Routine to load the pciverbose kernel module as needed
328 */
329 void pci_load_verbose(void)
330 {
331 if (pciverbose_loaded == 0)
332 module_autoload("pciverbose", MODULE_CLASS_MISC);
333 }
334
335 const char *pci_findvendor_stub(pcireg_t id_reg)
336 {
337 pci_load_verbose();
338 if (pciverbose_loaded)
339 return pci_findvendor(id_reg);
340 else
341 return NULL;
342 }
343
344 const char *pci_findproduct_stub(pcireg_t id_reg)
345 {
346 pci_load_verbose();
347 if (pciverbose_loaded)
348 return pci_findproduct(id_reg);
349 else
350 return NULL;
351 }
352 #endif
353
354 void
355 pci_devinfo(pcireg_t id_reg, pcireg_t class_reg, int showclass, char *cp,
356 size_t l)
357 {
358 pci_vendor_id_t vendor;
359 pci_product_id_t product;
360 pci_class_t class;
361 pci_subclass_t subclass;
362 pci_interface_t interface;
363 pci_revision_t revision;
364 const char *unmatched = pci_unmatched;
365 const char *vendor_namep, *product_namep;
366 const struct pci_class *classp, *subclassp;
367 char *ep;
368
369 ep = cp + l;
370
371 vendor = PCI_VENDOR(id_reg);
372 product = PCI_PRODUCT(id_reg);
373
374 class = PCI_CLASS(class_reg);
375 subclass = PCI_SUBCLASS(class_reg);
376 interface = PCI_INTERFACE(class_reg);
377 revision = PCI_REVISION(class_reg);
378
379 vendor_namep = pci_findvendor(id_reg);
380 product_namep = pci_findproduct(id_reg);
381
382 classp = pci_class;
383 while (classp->name != NULL) {
384 if (class == classp->val)
385 break;
386 classp++;
387 }
388
389 subclassp = (classp->name != NULL) ? classp->subclasses : NULL;
390 while (subclassp && subclassp->name != NULL) {
391 if (subclass == subclassp->val)
392 break;
393 subclassp++;
394 }
395
396 if (vendor_namep == NULL)
397 cp += snprintf(cp, ep - cp, "%svendor 0x%04x product 0x%04x",
398 unmatched, vendor, product);
399 else if (product_namep != NULL)
400 cp += snprintf(cp, ep - cp, "%s %s", vendor_namep,
401 product_namep);
402 else
403 cp += snprintf(cp, ep - cp, "%s product 0x%04x",
404 vendor_namep, product);
405 if (showclass) {
406 cp += snprintf(cp, ep - cp, " (");
407 if (classp->name == NULL)
408 cp += snprintf(cp, ep - cp,
409 "class 0x%02x, subclass 0x%02x", class, subclass);
410 else {
411 if (subclassp == NULL || subclassp->name == NULL)
412 cp += snprintf(cp, ep - cp,
413 "%s, subclass 0x%02x",
414 classp->name, subclass);
415 else
416 cp += snprintf(cp, ep - cp, "%s %s",
417 subclassp->name, classp->name);
418 }
419 if (interface != 0)
420 cp += snprintf(cp, ep - cp, ", interface 0x%02x",
421 interface);
422 if (revision != 0)
423 cp += snprintf(cp, ep - cp, ", revision 0x%02x",
424 revision);
425 cp += snprintf(cp, ep - cp, ")");
426 }
427 }
428
429 #ifdef _KERNEL
430 void
431 pci_aprint_devinfo_fancy(const struct pci_attach_args *pa, const char *naive,
432 const char *known, int addrev)
433 {
434 char devinfo[256];
435
436 if (known) {
437 aprint_normal(": %s", known);
438 if (addrev)
439 aprint_normal(" (rev. 0x%02x)",
440 PCI_REVISION(pa->pa_class));
441 aprint_normal("\n");
442 } else {
443 pci_devinfo(pa->pa_id, pa->pa_class, 0,
444 devinfo, sizeof(devinfo));
445 aprint_normal(": %s (rev. 0x%02x)\n", devinfo,
446 PCI_REVISION(pa->pa_class));
447 }
448 if (naive)
449 aprint_naive(": %s\n", naive);
450 else
451 aprint_naive("\n");
452 }
453 #endif
454
455 /*
456 * Print out most of the PCI configuration registers. Typically used
457 * in a device attach routine like this:
458 *
459 * #ifdef MYDEV_DEBUG
460 * printf("%s: ", device_xname(sc->sc_dev));
461 * pci_conf_print(pa->pa_pc, pa->pa_tag, NULL);
462 * #endif
463 */
464
465 #define i2o(i) ((i) * 4)
466 #define o2i(o) ((o) / 4)
467 #define onoff2(str, rval, bit, onstr, offstr) \
468 printf(" %s: %s\n", (str), ((rval) & (bit)) ? onstr : offstr);
469 #define onoff(str, rval, bit) onoff2(str, rval, bit, "on", "off")
470
471 static void
472 pci_conf_print_common(
473 #ifdef _KERNEL
474 pci_chipset_tag_t pc, pcitag_t tag,
475 #endif
476 const pcireg_t *regs)
477 {
478 const char *name;
479 const struct pci_class *classp, *subclassp;
480 pcireg_t rval;
481
482 rval = regs[o2i(PCI_ID_REG)];
483 name = pci_findvendor(rval);
484 if (name)
485 printf(" Vendor Name: %s (0x%04x)\n", name,
486 PCI_VENDOR(rval));
487 else
488 printf(" Vendor ID: 0x%04x\n", PCI_VENDOR(rval));
489 name = pci_findproduct(rval);
490 if (name)
491 printf(" Device Name: %s (0x%04x)\n", name,
492 PCI_PRODUCT(rval));
493 else
494 printf(" Device ID: 0x%04x\n", PCI_PRODUCT(rval));
495
496 rval = regs[o2i(PCI_COMMAND_STATUS_REG)];
497
498 printf(" Command register: 0x%04x\n", rval & 0xffff);
499 onoff("I/O space accesses", rval, PCI_COMMAND_IO_ENABLE);
500 onoff("Memory space accesses", rval, PCI_COMMAND_MEM_ENABLE);
501 onoff("Bus mastering", rval, PCI_COMMAND_MASTER_ENABLE);
502 onoff("Special cycles", rval, PCI_COMMAND_SPECIAL_ENABLE);
503 onoff("MWI transactions", rval, PCI_COMMAND_INVALIDATE_ENABLE);
504 onoff("Palette snooping", rval, PCI_COMMAND_PALETTE_ENABLE);
505 onoff("Parity error checking", rval, PCI_COMMAND_PARITY_ENABLE);
506 onoff("Address/data stepping", rval, PCI_COMMAND_STEPPING_ENABLE);
507 onoff("System error (SERR)", rval, PCI_COMMAND_SERR_ENABLE);
508 onoff("Fast back-to-back transactions", rval, PCI_COMMAND_BACKTOBACK_ENABLE);
509 onoff("Interrupt disable", rval, PCI_COMMAND_INTERRUPT_DISABLE);
510
511 printf(" Status register: 0x%04x\n", (rval >> 16) & 0xffff);
512 onoff2("Interrupt status", rval, PCI_STATUS_INT_STATUS, "active", "inactive");
513 onoff("Capability List support", rval, PCI_STATUS_CAPLIST_SUPPORT);
514 onoff("66 MHz capable", rval, PCI_STATUS_66MHZ_SUPPORT);
515 onoff("User Definable Features (UDF) support", rval, PCI_STATUS_UDF_SUPPORT);
516 onoff("Fast back-to-back capable", rval, PCI_STATUS_BACKTOBACK_SUPPORT);
517 onoff("Data parity error detected", rval, PCI_STATUS_PARITY_ERROR);
518
519 printf(" DEVSEL timing: ");
520 switch (rval & PCI_STATUS_DEVSEL_MASK) {
521 case PCI_STATUS_DEVSEL_FAST:
522 printf("fast");
523 break;
524 case PCI_STATUS_DEVSEL_MEDIUM:
525 printf("medium");
526 break;
527 case PCI_STATUS_DEVSEL_SLOW:
528 printf("slow");
529 break;
530 default:
531 printf("unknown/reserved"); /* XXX */
532 break;
533 }
534 printf(" (0x%x)\n", (rval & PCI_STATUS_DEVSEL_MASK) >> 25);
535
536 onoff("Slave signaled Target Abort", rval, PCI_STATUS_TARGET_TARGET_ABORT);
537 onoff("Master received Target Abort", rval, PCI_STATUS_MASTER_TARGET_ABORT);
538 onoff("Master received Master Abort", rval, PCI_STATUS_MASTER_ABORT);
539 onoff("Asserted System Error (SERR)", rval, PCI_STATUS_SPECIAL_ERROR);
540 onoff("Parity error detected", rval, PCI_STATUS_PARITY_DETECT);
541
542 rval = regs[o2i(PCI_CLASS_REG)];
543 for (classp = pci_class; classp->name != NULL; classp++) {
544 if (PCI_CLASS(rval) == classp->val)
545 break;
546 }
547 subclassp = (classp->name != NULL) ? classp->subclasses : NULL;
548 while (subclassp && subclassp->name != NULL) {
549 if (PCI_SUBCLASS(rval) == subclassp->val)
550 break;
551 subclassp++;
552 }
553 if (classp->name != NULL) {
554 printf(" Class Name: %s (0x%02x)\n", classp->name,
555 PCI_CLASS(rval));
556 if (subclassp != NULL && subclassp->name != NULL)
557 printf(" Subclass Name: %s (0x%02x)\n",
558 subclassp->name, PCI_SUBCLASS(rval));
559 else
560 printf(" Subclass ID: 0x%02x\n", PCI_SUBCLASS(rval));
561 } else {
562 printf(" Class ID: 0x%02x\n", PCI_CLASS(rval));
563 printf(" Subclass ID: 0x%02x\n", PCI_SUBCLASS(rval));
564 }
565 printf(" Interface: 0x%02x\n", PCI_INTERFACE(rval));
566 printf(" Revision ID: 0x%02x\n", PCI_REVISION(rval));
567
568 rval = regs[o2i(PCI_BHLC_REG)];
569 printf(" BIST: 0x%02x\n", PCI_BIST(rval));
570 printf(" Header Type: 0x%02x%s (0x%02x)\n", PCI_HDRTYPE_TYPE(rval),
571 PCI_HDRTYPE_MULTIFN(rval) ? "+multifunction" : "",
572 PCI_HDRTYPE(rval));
573 printf(" Latency Timer: 0x%02x\n", PCI_LATTIMER(rval));
574 printf(" Cache Line Size: 0x%02x\n", PCI_CACHELINE(rval));
575 }
576
577 static int
578 pci_conf_print_bar(
579 #ifdef _KERNEL
580 pci_chipset_tag_t pc, pcitag_t tag,
581 #endif
582 const pcireg_t *regs, int reg, const char *name
583 #ifdef _KERNEL
584 , int sizebar
585 #endif
586 )
587 {
588 int width;
589 pcireg_t rval, rval64h;
590 #ifdef _KERNEL
591 int s;
592 pcireg_t mask, mask64h;
593 #endif
594
595 width = 4;
596
597 /*
598 * Section 6.2.5.1, `Address Maps', tells us that:
599 *
600 * 1) The builtin software should have already mapped the
601 * device in a reasonable way.
602 *
603 * 2) A device which wants 2^n bytes of memory will hardwire
604 * the bottom n bits of the address to 0. As recommended,
605 * we write all 1s and see what we get back.
606 */
607
608 rval = regs[o2i(reg)];
609 if (PCI_MAPREG_TYPE(rval) == PCI_MAPREG_TYPE_MEM &&
610 PCI_MAPREG_MEM_TYPE(rval) == PCI_MAPREG_MEM_TYPE_64BIT) {
611 rval64h = regs[o2i(reg + 4)];
612 width = 8;
613 } else
614 rval64h = 0;
615
616 #ifdef _KERNEL
617 /* XXX don't size unknown memory type? */
618 if (rval != 0 && sizebar) {
619 /*
620 * The following sequence seems to make some devices
621 * (e.g. host bus bridges, which don't normally
622 * have their space mapped) very unhappy, to
623 * the point of crashing the system.
624 *
625 * Therefore, if the mapping register is zero to
626 * start out with, don't bother trying.
627 */
628 s = splhigh();
629 pci_conf_write(pc, tag, reg, 0xffffffff);
630 mask = pci_conf_read(pc, tag, reg);
631 pci_conf_write(pc, tag, reg, rval);
632 if (PCI_MAPREG_TYPE(rval) == PCI_MAPREG_TYPE_MEM &&
633 PCI_MAPREG_MEM_TYPE(rval) == PCI_MAPREG_MEM_TYPE_64BIT) {
634 pci_conf_write(pc, tag, reg + 4, 0xffffffff);
635 mask64h = pci_conf_read(pc, tag, reg + 4);
636 pci_conf_write(pc, tag, reg + 4, rval64h);
637 } else
638 mask64h = 0;
639 splx(s);
640 } else
641 mask = mask64h = 0;
642 #endif /* _KERNEL */
643
644 printf(" Base address register at 0x%02x", reg);
645 if (name)
646 printf(" (%s)", name);
647 printf("\n ");
648 if (rval == 0) {
649 printf("not implemented(?)\n");
650 return width;
651 }
652 printf("type: ");
653 if (PCI_MAPREG_TYPE(rval) == PCI_MAPREG_TYPE_MEM) {
654 const char *type, *prefetch;
655
656 switch (PCI_MAPREG_MEM_TYPE(rval)) {
657 case PCI_MAPREG_MEM_TYPE_32BIT:
658 type = "32-bit";
659 break;
660 case PCI_MAPREG_MEM_TYPE_32BIT_1M:
661 type = "32-bit-1M";
662 break;
663 case PCI_MAPREG_MEM_TYPE_64BIT:
664 type = "64-bit";
665 break;
666 default:
667 type = "unknown (XXX)";
668 break;
669 }
670 if (PCI_MAPREG_MEM_PREFETCHABLE(rval))
671 prefetch = "";
672 else
673 prefetch = "non";
674 printf("%s %sprefetchable memory\n", type, prefetch);
675 switch (PCI_MAPREG_MEM_TYPE(rval)) {
676 case PCI_MAPREG_MEM_TYPE_64BIT:
677 printf(" base: 0x%016llx, ",
678 PCI_MAPREG_MEM64_ADDR(
679 ((((long long) rval64h) << 32) | rval)));
680 #ifdef _KERNEL
681 if (sizebar)
682 printf("size: 0x%016llx",
683 PCI_MAPREG_MEM64_SIZE(
684 ((((long long) mask64h) << 32) | mask)));
685 else
686 #endif /* _KERNEL */
687 printf("not sized");
688 printf("\n");
689 break;
690 case PCI_MAPREG_MEM_TYPE_32BIT:
691 case PCI_MAPREG_MEM_TYPE_32BIT_1M:
692 default:
693 printf(" base: 0x%08x, ",
694 PCI_MAPREG_MEM_ADDR(rval));
695 #ifdef _KERNEL
696 if (sizebar)
697 printf("size: 0x%08x",
698 PCI_MAPREG_MEM_SIZE(mask));
699 else
700 #endif /* _KERNEL */
701 printf("not sized");
702 printf("\n");
703 break;
704 }
705 } else {
706 #ifdef _KERNEL
707 if (sizebar)
708 printf("%d-bit ", mask & ~0x0000ffff ? 32 : 16);
709 #endif /* _KERNEL */
710 printf("i/o\n");
711 printf(" base: 0x%08x, ", PCI_MAPREG_IO_ADDR(rval));
712 #ifdef _KERNEL
713 if (sizebar)
714 printf("size: 0x%08x", PCI_MAPREG_IO_SIZE(mask));
715 else
716 #endif /* _KERNEL */
717 printf("not sized");
718 printf("\n");
719 }
720
721 return width;
722 }
723
724 static void
725 pci_conf_print_regs(const pcireg_t *regs, int first, int pastlast)
726 {
727 int off, needaddr, neednl;
728
729 needaddr = 1;
730 neednl = 0;
731 for (off = first; off < pastlast; off += 4) {
732 if ((off % 16) == 0 || needaddr) {
733 printf(" 0x%02x:", off);
734 needaddr = 0;
735 }
736 printf(" 0x%08x", regs[o2i(off)]);
737 neednl = 1;
738 if ((off % 16) == 12) {
739 printf("\n");
740 neednl = 0;
741 }
742 }
743 if (neednl)
744 printf("\n");
745 }
746
747 static void
748 pci_conf_print_type0(
749 #ifdef _KERNEL
750 pci_chipset_tag_t pc, pcitag_t tag,
751 #endif
752 const pcireg_t *regs
753 #ifdef _KERNEL
754 , int sizebars
755 #endif
756 )
757 {
758 int off, width;
759 pcireg_t rval;
760
761 for (off = PCI_MAPREG_START; off < PCI_MAPREG_END; off += width) {
762 #ifdef _KERNEL
763 width = pci_conf_print_bar(pc, tag, regs, off, NULL, sizebars);
764 #else
765 width = pci_conf_print_bar(regs, off, NULL);
766 #endif
767 }
768
769 printf(" Cardbus CIS Pointer: 0x%08x\n", regs[o2i(0x28)]);
770
771 rval = regs[o2i(PCI_SUBSYS_ID_REG)];
772 printf(" Subsystem vendor ID: 0x%04x\n", PCI_VENDOR(rval));
773 printf(" Subsystem ID: 0x%04x\n", PCI_PRODUCT(rval));
774
775 /* XXX */
776 printf(" Expansion ROM Base Address: 0x%08x\n", regs[o2i(0x30)]);
777
778 if (regs[o2i(PCI_COMMAND_STATUS_REG)] & PCI_STATUS_CAPLIST_SUPPORT)
779 printf(" Capability list pointer: 0x%02x\n",
780 PCI_CAPLIST_PTR(regs[o2i(PCI_CAPLISTPTR_REG)]));
781 else
782 printf(" Reserved @ 0x34: 0x%08x\n", regs[o2i(0x34)]);
783
784 printf(" Reserved @ 0x38: 0x%08x\n", regs[o2i(0x38)]);
785
786 rval = regs[o2i(PCI_INTERRUPT_REG)];
787 printf(" Maximum Latency: 0x%02x\n", (rval >> 24) & 0xff);
788 printf(" Minimum Grant: 0x%02x\n", (rval >> 16) & 0xff);
789 printf(" Interrupt pin: 0x%02x ", PCI_INTERRUPT_PIN(rval));
790 switch (PCI_INTERRUPT_PIN(rval)) {
791 case PCI_INTERRUPT_PIN_NONE:
792 printf("(none)");
793 break;
794 case PCI_INTERRUPT_PIN_A:
795 printf("(pin A)");
796 break;
797 case PCI_INTERRUPT_PIN_B:
798 printf("(pin B)");
799 break;
800 case PCI_INTERRUPT_PIN_C:
801 printf("(pin C)");
802 break;
803 case PCI_INTERRUPT_PIN_D:
804 printf("(pin D)");
805 break;
806 default:
807 printf("(? ? ?)");
808 break;
809 }
810 printf("\n");
811 printf(" Interrupt line: 0x%02x\n", PCI_INTERRUPT_LINE(rval));
812 }
813
814 static void
815 pci_print_pcie_L0s_latency(uint32_t val)
816 {
817
818 switch (val) {
819 case 0x0:
820 printf("Less than 64ns\n");
821 break;
822 case 0x1:
823 case 0x2:
824 case 0x3:
825 printf("%dns to less than %dns\n", 32 << val, 32 << (val + 1));
826 break;
827 case 0x4:
828 printf("512ns to less than 1us\n");
829 break;
830 case 0x5:
831 printf("1us to less than 2us\n");
832 break;
833 case 0x6:
834 printf("2us - 4us\n");
835 break;
836 case 0x7:
837 printf("More than 4us\n");
838 break;
839 }
840 }
841
842 static void
843 pci_print_pcie_L1_latency(uint32_t val)
844 {
845
846 switch (val) {
847 case 0x0:
848 printf("Less than 1us\n");
849 break;
850 case 0x6:
851 printf("32us - 64us\n");
852 break;
853 case 0x7:
854 printf("More than 64us\n");
855 break;
856 default:
857 printf("%dus to less than %dus\n", 1 << (val - 1), 1 << val);
858 break;
859 }
860 }
861
862 static void
863 pci_print_pcie_compl_timeout(uint32_t val)
864 {
865
866 switch (val) {
867 case 0x0:
868 printf("50us to 50ms\n");
869 break;
870 case 0x5:
871 printf("16ms to 55ms\n");
872 break;
873 case 0x6:
874 printf("65ms to 210ms\n");
875 break;
876 case 0x9:
877 printf("260ms to 900ms\n");
878 break;
879 case 0xa:
880 printf("1s to 3.5s\n");
881 break;
882 default:
883 printf("unknown %u value\n", val);
884 break;
885 }
886 }
887
888 static void
889 pci_conf_print_pcie_cap(const pcireg_t *regs, int capoff)
890 {
891 pcireg_t reg; /* for each register */
892 pcireg_t val; /* for each bitfield */
893 bool check_link = false;
894 bool check_slot = false;
895 bool check_rootport = false;
896 unsigned int pciever;
897 static const char * const linkspeeds[] = {"2.5", "5.0", "8.0"};
898 int i;
899
900 printf("\n PCI Express Capabilities Register\n");
901 /* Capability Register */
902 reg = regs[o2i(capoff)];
903 printf(" Capability register: %04x\n", reg >> 16);
904 pciever = (unsigned int)((reg & 0x000f0000) >> 16);
905 printf(" Capability version: %u\n", pciever);
906 printf(" Device type: ");
907 switch ((reg & 0x00f00000) >> 20) {
908 case 0x0:
909 printf("PCI Express Endpoint device\n");
910 check_link = true;
911 break;
912 case 0x1:
913 printf("Legacy PCI Express Endpoint device\n");
914 check_link = true;
915 break;
916 case 0x4:
917 printf("Root Port of PCI Express Root Complex\n");
918 check_link = true;
919 check_slot = true;
920 check_rootport = true;
921 break;
922 case 0x5:
923 printf("Upstream Port of PCI Express Switch\n");
924 break;
925 case 0x6:
926 printf("Downstream Port of PCI Express Switch\n");
927 check_slot = true;
928 check_rootport = true;
929 break;
930 case 0x7:
931 printf("PCI Express to PCI/PCI-X Bridge\n");
932 break;
933 case 0x8:
934 printf("PCI/PCI-X to PCI Express Bridge\n");
935 break;
936 case 0x9:
937 printf("Root Complex Integrated Endpoint\n");
938 break;
939 case 0xa:
940 check_rootport = true;
941 printf("Root Complex Event Collector\n");
942 break;
943 default:
944 printf("unknown\n");
945 break;
946 }
947 if (check_slot && (reg & PCIE_XCAP_SI) != 0)
948 printf(" Slot implemented\n");
949 printf(" Interrupt Message Number: %x\n",
950 (unsigned int)((reg & PCIE_XCAP_IRQ) >> 27));
951
952 /* Device Capability Register */
953 reg = regs[o2i(capoff + PCIE_DCAP)];
954 printf(" Device Capabilities Register: 0x%08x\n", reg);
955 printf(" Max Payload Size Supported: %u bytes max\n",
956 (unsigned int)(reg & PCIE_DCAP_MAX_PAYLOAD) * 256);
957 printf(" Phantom Functions Supported: ");
958 switch ((reg & PCIE_DCAP_PHANTOM_FUNCS) >> 3) {
959 case 0x0:
960 printf("not available\n");
961 break;
962 case 0x1:
963 printf("MSB\n");
964 break;
965 case 0x2:
966 printf("two MSB\n");
967 break;
968 case 0x3:
969 printf("All three bits\n");
970 break;
971 }
972 printf(" Extended Tag Field Supported: %dbit\n",
973 (reg & PCIE_DCAP_EXT_TAG_FIELD) == 0 ? 5 : 8);
974 printf(" Endpoint L0 Acceptable Latency: ");
975 pci_print_pcie_L0s_latency((reg & PCIE_DCAP_L0S_LATENCY) >> 6);
976 printf(" Endpoint L1 Acceptable Latency: ");
977 pci_print_pcie_L1_latency((reg & PCIE_DCAP_L1_LATENCY) >> 9);
978 onoff("Attention Button Present:", reg, PCIE_DCAP_ATTN_BUTTON);
979 onoff("Attention Indicator Present:", reg, PCIE_DCAP_ATTN_IND);
980 onoff("Power Indicator Present", reg, PCIE_DCAP_PWR_IND);
981 onoff("Role-Based Error Report", reg, PCIE_DCAP_ROLE_ERR_RPT);
982 printf(" Captured Slot Power Limit Value: %d\n",
983 (unsigned int)(reg & PCIE_DCAP_SLOT_PWR_LIM_VAL) >> 18);
984 printf(" Captured Slot Power Limit Scale: %d\n",
985 (unsigned int)(reg & PCIE_DCAP_SLOT_PWR_LIM_SCALE) >> 26);
986 onoff("Function-Level Reset Capability", reg, PCIE_DCAP_FLR);
987
988 /* Device Control Register */
989 reg = regs[o2i(capoff + PCIE_DCSR)];
990 printf(" Device Control Register: 0x%04x\n", reg & 0xffff);
991 onoff("Correctable Error Reporting Enable", reg,
992 PCIE_DCSR_ENA_COR_ERR);
993 onoff("Non Fatal Error Reporting Enable", reg, PCIE_DCSR_ENA_NFER);
994 onoff("Fatal Error Reporting Enable", reg, PCIE_DCSR_ENA_FER);
995 onoff("Unsupported Request Reporting Enable", reg, PCIE_DCSR_ENA_URR);
996 onoff("Enable Relaxed Ordering", reg, PCIE_DCSR_ENA_RELAX_ORD);
997 printf(" Max Payload Size: %d byte\n",
998 128 << (((unsigned int)(reg & PCIE_DCSR_MAX_PAYLOAD) >> 5)));
999 onoff("Extended Tag Field Enable", reg, PCIE_DCSR_EXT_TAG_FIELD);
1000 onoff("Phantom Functions Enable", reg, PCIE_DCSR_PHANTOM_FUNCS);
1001 onoff("Aux Power PM Enable", reg, PCIE_DCSR_AUX_POWER_PM);
1002 onoff("Enable No Snoop", reg, PCIE_DCSR_ENA_NO_SNOOP);
1003 printf(" Max Read Request Size: %d byte\n",
1004 128 << ((unsigned int)(reg & PCIE_DCSR_MAX_READ_REQ) >> 12));
1005
1006 /* Device Status Register */
1007 reg = regs[o2i(capoff + PCIE_DCSR)];
1008 printf(" Device Status Register: 0x%04x\n", reg >> 16);
1009 onoff("Correctable Error Detected", reg, PCIE_DCSR_CED);
1010 onoff("Non Fatal Error Detected", reg, PCIE_DCSR_NFED);
1011 onoff("Fatal Error Detected", reg, PCIE_DCSR_FED);
1012 onoff("Unsupported Request Detected", reg, PCIE_DCSR_URD);
1013 onoff("Aux Power Detected", reg, PCIE_DCSR_AUX_PWR);
1014 onoff("Transaction Pending", reg, PCIE_DCSR_TRANSACTION_PND);
1015
1016 if (check_link) {
1017 /* Link Capability Register */
1018 reg = regs[o2i(capoff + PCIE_LCAP)];
1019 printf(" Link Capabilities Register: 0x%08x\n", reg);
1020 printf(" Maximum Link Speed: ");
1021 val = reg & PCIE_LCAP_MAX_SPEED;
1022 if (val < 1 || val > 3) {
1023 printf("unknown %u value\n", val);
1024 } else {
1025 printf("%sGT/s\n", linkspeeds[val - 1]);
1026 }
1027 printf(" Maximum Link Width: x%u lanes\n",
1028 (unsigned int)(reg & PCIE_LCAP_MAX_WIDTH) >> 4);
1029 printf(" Active State PM Support: ");
1030 val = (reg & PCIE_LCAP_ASPM) >> 10;
1031 switch (val) {
1032 case 0x1:
1033 printf("L0s Entry supported\n");
1034 break;
1035 case 0x3:
1036 printf("L0s and L1 supported\n");
1037 break;
1038 default:
1039 printf("Reserved value\n");
1040 break;
1041 }
1042 printf(" L0 Exit Latency: ");
1043 pci_print_pcie_L0s_latency((reg & PCIE_LCAP_L0S_EXIT) >> 12);
1044 printf(" L1 Exit Latency: ");
1045 pci_print_pcie_L1_latency((reg & PCIE_LCAP_L1_EXIT) >> 15);
1046 printf(" Port Number: %u\n", reg >> 24);
1047
1048 /* Link Control Register */
1049 reg = regs[o2i(capoff + PCIE_LCSR)];
1050 printf(" Link Control Register: 0x%04x\n", reg & 0xffff);
1051 printf(" Active State PM Control: ");
1052 val = reg & (PCIE_LCSR_ASPM_L1 | PCIE_LCSR_ASPM_L0S);
1053 switch (val) {
1054 case 0:
1055 printf("disabled\n");
1056 break;
1057 case 1:
1058 printf("L0s Entry Enabled\n");
1059 break;
1060 case 2:
1061 printf("L1 Entry Enabled\n");
1062 break;
1063 case 3:
1064 printf("L0s and L1 Entry Enabled\n");
1065 break;
1066 }
1067 onoff2("Read Completion Boundary Control", reg, PCIE_LCSR_RCB,
1068 "128bytes", "64bytes");
1069 onoff("Link Disable", reg, PCIE_LCSR_LINK_DIS);
1070 onoff("Retrain Link", reg, PCIE_LCSR_RETRAIN);
1071 onoff("Common Clock Configuration", reg, PCIE_LCSR_COMCLKCFG);
1072 onoff("Extended Synch", reg, PCIE_LCSR_EXTNDSYNC);
1073 onoff("Enable Clock Power Management", reg, PCIE_LCSR_ENCLKPM);
1074 onoff("Hardware Autonomous Width Disable", reg,
1075 PCIE_LCSR_HAWD);
1076 onoff("Link Bandwidth Management Interrupt Enable", reg,
1077 PCIE_LCSR_LBMIE);
1078 onoff("Link Autonomous Bandwidth Interrupt Enable", reg,
1079 PCIE_LCSR_LABIE);
1080
1081 /* Link Status Register */
1082 reg = regs[o2i(capoff + PCIE_LCSR)];
1083 printf(" Link Status Register: 0x%04x\n", reg >> 16);
1084 printf(" Negotiated Link Speed: ");
1085 if (((reg >> 16) & 0x000f) < 1 ||
1086 ((reg >> 16) & 0x000f) > 3) {
1087 printf("unknown %u value\n",
1088 (unsigned int)(reg & PCIE_LCSR_LINKSPEED) >> 16);
1089 } else {
1090 printf("%sGT/s\n",
1091 linkspeeds[((reg & PCIE_LCSR_LINKSPEED) >> 16) - 1]);
1092 }
1093 printf(" Negotiated Link Width: x%u lanes\n",
1094 (reg >> 20) & 0x003f);
1095 onoff("Training Error", reg, PCIE_LCSR_LINKTRAIN_ERR);
1096 onoff("Link Training", reg, PCIE_LCSR_LINKTRAIN);
1097 onoff("Slot Clock Configuration", reg, PCIE_LCSR_SLOTCLKCFG);
1098 onoff("Data Link Layer Link Active", reg, PCIE_LCSR_DLACTIVE);
1099 onoff("Link Bandwidth Management Status", reg,
1100 PCIE_LCSR_LINK_BW_MGMT);
1101 onoff("Link Autonomous Bandwidth Status", reg,
1102 PCIE_LCSR_LINK_AUTO_BW);
1103 }
1104
1105 if (check_slot == true) {
1106 /* Slot Capability Register */
1107 reg = regs[o2i(capoff + PCIE_SLCAP)];
1108 printf(" Slot Capability Register: %08x\n", reg);
1109 if ((reg & PCIE_SLCAP_ABP) != 0)
1110 printf(" Attention Button Present\n");
1111 if ((reg & PCIE_SLCAP_PCP) != 0)
1112 printf(" Power Controller Present\n");
1113 if ((reg & PCIE_SLCAP_MSP) != 0)
1114 printf(" MRL Sensor Present\n");
1115 if ((reg & PCIE_SLCAP_AIP) != 0)
1116 printf(" Attention Indicator Present\n");
1117 if ((reg & PCIE_SLCAP_PIP) != 0)
1118 printf(" Power Indicator Present\n");
1119 if ((reg & PCIE_SLCAP_HPS) != 0)
1120 printf(" Hot-Plug Surprise\n");
1121 if ((reg & PCIE_SLCAP_HPC) != 0)
1122 printf(" Hot-Plug Capable\n");
1123 printf(" Slot Power Limit Value: %d\n",
1124 (unsigned int)(reg & PCIE_SLCAP_SPLV) >> 7);
1125 printf(" Slot Power Limit Scale: %d\n",
1126 (unsigned int)(reg & PCIE_SLCAP_SPLS) >> 15);
1127 if ((reg & PCIE_SLCAP_EIP) != 0)
1128 printf(" Electromechanical Interlock Present\n");
1129 if ((reg & PCIE_SLCAP_NCCS) != 0)
1130 printf(" No Command Completed Support\n");
1131 printf(" Physical Slot Number: %d\n",
1132 (unsigned int)(reg & PCIE_SLCAP_PSN) >> 19);
1133
1134 /* Slot Control Register */
1135 reg = regs[o2i(capoff + PCIE_SLCSR)];
1136 printf(" Slot Control Register: %04x\n", reg & 0xffff);
1137 if ((reg & PCIE_SLCSR_ABE) != 0)
1138 printf(" Attention Button Pressed Enabled\n");
1139 if ((reg & PCIE_SLCSR_PFE) != 0)
1140 printf(" Power Fault Detected Enabled\n");
1141 if ((reg & PCIE_SLCSR_MSE) != 0)
1142 printf(" MRL Sensor Changed Enabled\n");
1143 if ((reg & PCIE_SLCSR_PDE) != 0)
1144 printf(" Presense Detect Changed Enabled\n");
1145 if ((reg & PCIE_SLCSR_CCE) != 0)
1146 printf(" Command Completed Interrupt Enabled\n");
1147 if ((reg & PCIE_SLCSR_HPE) != 0)
1148 printf(" Hot-Plug Interrupt Enabled\n");
1149 printf(" Attention Indicator Control: ");
1150 switch ((reg & PCIE_SLCSR_AIC) >> 6) {
1151 case 0x0:
1152 printf("reserved\n");
1153 break;
1154 case 0x1:
1155 printf("on\n");
1156 break;
1157 case 0x2:
1158 printf("blink\n");
1159 break;
1160 case 0x3:
1161 printf("off\n");
1162 break;
1163 }
1164 printf(" Power Indicator Control: ");
1165 switch ((reg & PCIE_SLCSR_PIC) >> 8) {
1166 case 0x0:
1167 printf("reserved\n");
1168 break;
1169 case 0x1:
1170 printf("on\n");
1171 break;
1172 case 0x2:
1173 printf("blink\n");
1174 break;
1175 case 0x3:
1176 printf("off\n");
1177 break;
1178 }
1179 printf(" Power Controller Control: ");
1180 if ((reg & PCIE_SLCSR_PCC) != 0)
1181 printf("off\n");
1182 else
1183 printf("on\n");
1184 if ((reg & PCIE_SLCSR_EIC) != 0)
1185 printf(" Electromechanical Interlock Control\n");
1186 if ((reg & PCIE_SLCSR_LACS) != 0)
1187 printf(" Data Link Layer State Changed Enable\n");
1188
1189 /* Slot Status Register */
1190 printf(" Slot Status Register: %04x\n", reg >> 16);
1191 if ((reg & PCIE_SLCSR_ABP) != 0)
1192 printf(" Attention Button Pressed\n");
1193 if ((reg & PCIE_SLCSR_PFD) != 0)
1194 printf(" Power Fault Detected\n");
1195 if ((reg & PCIE_SLCSR_MSC) != 0)
1196 printf(" MRL Sensor Changed\n");
1197 if ((reg & PCIE_SLCSR_PDC) != 0)
1198 printf(" Presense Detect Changed\n");
1199 if ((reg & PCIE_SLCSR_CC) != 0)
1200 printf(" Command Completed\n");
1201 if ((reg & PCIE_SLCSR_MS) != 0)
1202 printf(" MRL Open\n");
1203 if ((reg & PCIE_SLCSR_PDS) != 0)
1204 printf(" Card Present in slot\n");
1205 if ((reg & PCIE_SLCSR_EIS) != 0)
1206 printf(" Electromechanical Interlock engaged\n");
1207 if ((reg & PCIE_SLCSR_LACS) != 0)
1208 printf(" Data Link Layer State Changed\n");
1209 }
1210
1211 if (check_rootport == true) {
1212 /* Root Control Register */
1213 reg = regs[o2i(capoff + PCIE_RCR)];
1214 printf(" Root Control Register: %04x\n", reg & 0xffff);
1215 if ((reg & PCIE_RCR_SERR_CER) != 0)
1216 printf(" SERR on Correctable Error Enable\n");
1217 if ((reg & PCIE_RCR_SERR_NFER) != 0)
1218 printf(" SERR on Non-Fatal Error Enable\n");
1219 if ((reg & PCIE_RCR_SERR_FER) != 0)
1220 printf(" SERR on Fatal Error Enable\n");
1221 if ((reg & PCIE_RCR_PME_IE) != 0)
1222 printf(" PME Interrupt Enable\n");
1223 if ((reg & PCIE_RCR_CRS_SVE) != 0)
1224 printf(" CRS Software Visibility Enable\n");
1225
1226 /* Root Capability Register */
1227 printf(" Root Capability Register: %04x\n",
1228 reg >> 16);
1229
1230 /* Root Status Register */
1231 reg = regs[o2i(capoff + PCIE_RSR)];
1232 printf(" Root Status Register: %08x\n", reg);
1233 printf(" PME Requester ID: %04x\n",
1234 (unsigned int)(reg & PCIE_RSR_PME_REQESTER));
1235 if ((reg & PCIE_RSR_PME_STAT) != 0)
1236 printf(" PME was asserted\n");
1237 if ((reg & PCIE_RSR_PME_PEND) != 0)
1238 printf(" another PME is pending\n");
1239 }
1240
1241 /* PCIe DW9 to DW14 is for PCIe 2.0 and newer */
1242 if (pciever < 2)
1243 return;
1244
1245 /* Device Capabilities 2 */
1246 reg = regs[o2i(capoff + PCIE_DCAP2)];
1247 printf(" Device Capabilities 2: 0x%08x\n", reg);
1248 printf(" Completion Timeout Ranges Supported: %u \n",
1249 (unsigned int)(reg & PCIE_DCAP2_COMPT_RANGE));
1250 onoff("Completion Timeout Disable Supported", reg,
1251 PCIE_DCAP2_COMPT_DIS);
1252 onoff("ARI Forwarding Supported", reg, PCIE_DCAP2_ARI_FWD);
1253 onoff("AtomicOp Routing Supported", reg, PCIE_DCAP2_ATOM_ROUT);
1254 onoff("32bit AtomicOp Completer Supported", reg, PCIE_DCAP2_32ATOM);
1255 onoff("64bit AtomicOp Completer Supported", reg, PCIE_DCAP2_64ATOM);
1256 onoff("128-bit CAS Completer Supported", reg, PCIE_DCAP2_128CAS);
1257 onoff("No RO-enabled PR-PR passing", reg, PCIE_DCAP2_NO_ROPR_PASS);
1258 onoff("LTR Mechanism Supported", reg, PCIE_DCAP2_LTR_MEC);
1259 printf(" TPH Completer Supported: %u\n",
1260 (unsigned int)(reg & PCIE_DCAP2_TPH_COMP) >> 12);
1261 printf(" OBFF Supported: ");
1262 switch ((reg & PCIE_DCAP2_OBFF) >> 18) {
1263 case 0x0:
1264 printf("Not supported\n");
1265 break;
1266 case 0x1:
1267 printf("Message only\n");
1268 break;
1269 case 0x2:
1270 printf("WAKE# only\n");
1271 break;
1272 case 0x3:
1273 printf("Both\n");
1274 break;
1275 }
1276 onoff("Extended Fmt Field Supported", reg, PCIE_DCAP2_EXTFMT_FLD);
1277 onoff("End-End TLP Prefix Supported", reg, PCIE_DCAP2_EETLP_PREF);
1278 printf(" Max End-End TLP Prefixes: %u\n",
1279 (unsigned int)(reg & PCIE_DCAP2_MAX_EETLP) >> 22);
1280
1281 /* Device Control 2 */
1282 reg = regs[o2i(capoff + PCIE_DCSR2)];
1283 printf(" Device Control 2: 0x%04x\n", reg & 0xffff);
1284 printf(" Completion Timeout Value: ");
1285 pci_print_pcie_compl_timeout(reg & PCIE_DCSR2_COMPT_VAL);
1286 if ((reg & PCIE_DCSR2_COMPT_DIS) != 0)
1287 printf(" Completion Timeout Disabled\n");
1288 if ((reg & PCIE_DCSR2_ARI_FWD) != 0)
1289 printf(" ARI Forwarding Enabled\n");
1290 if ((reg & PCIE_DCSR2_ATOM_REQ) != 0)
1291 printf(" AtomicOp Rquester Enabled\n");
1292 if ((reg & PCIE_DCSR2_ATOM_EBLK) != 0)
1293 printf(" AtomicOp Egress Blocking on\n");
1294 if ((reg & PCIE_DCSR2_IDO_REQ) != 0)
1295 printf(" IDO Request Enabled\n");
1296 if ((reg & PCIE_DCSR2_IDO_COMP) != 0)
1297 printf(" IDO Completion Enabled\n");
1298 if ((reg & PCIE_DCSR2_LTR_MEC) != 0)
1299 printf(" LTR Mechanism Enabled\n");
1300 printf(" OBFF: ");
1301 switch ((reg & PCIE_DCSR2_OBFF_EN) >> 13) {
1302 case 0x0:
1303 printf("Disabled\n");
1304 break;
1305 case 0x1:
1306 printf("Enabled with Message Signaling Variation A\n");
1307 break;
1308 case 0x2:
1309 printf("Enabled with Message Signaling Variation B\n");
1310 break;
1311 case 0x3:
1312 printf("Enabled using WAKE# signaling\n");
1313 break;
1314 }
1315 if ((reg & PCIE_DCSR2_EETLP) != 0)
1316 printf(" End-End TLP Prefix Blocking on\n");
1317
1318 if (check_link) {
1319 /* Link Capability 2 */
1320 reg = regs[o2i(capoff + PCIE_LCAP2)];
1321 printf(" Link Capabilities 2: 0x%08x\n", reg);
1322 val = (reg & PCIE_LCAP2_SUP_LNKSV) >> 1;
1323 printf(" Supported Link Speed Vector:");
1324 for (i = 0; i <= 2; i++) {
1325 if (((val >> i) & 0x01) != 0)
1326 printf(" %sGT/s", linkspeeds[i]);
1327 }
1328 printf("\n");
1329 onoff("Crosslink Supported", reg, PCIE_LCAP2_CROSSLNK);
1330
1331 /* Link Control 2 */
1332 reg = regs[o2i(capoff + PCIE_LCSR2)];
1333 printf(" Link Control 2: 0x%04x\n", reg & 0xffff);
1334 printf(" Target Link Speed: ");
1335 val = reg & PCIE_LCSR2_TGT_LSPEED;
1336 if (val < 1 || val > 3) {
1337 printf("unknown %u value\n", val);
1338 } else {
1339 printf("%sGT/s\n", linkspeeds[val - 1]);
1340 }
1341 if ((reg & PCIE_LCSR2_ENT_COMPL) != 0)
1342 printf(" Enter Compliance Enabled\n");
1343 if ((reg & PCIE_LCSR2_HW_AS_DIS) != 0)
1344 printf(" HW Autonomous Speed Disabled\n");
1345 if ((reg & PCIE_LCSR2_SEL_DEEMP) != 0)
1346 printf(" Selectable De-emphasis\n");
1347 printf(" Transmit Margin: %u\n",
1348 (unsigned int)(reg & PCIE_LCSR2_TX_MARGIN) >> 7);
1349 if ((reg & PCIE_LCSR2_EN_MCOMP) != 0)
1350 printf(" Enter Modified Compliance\n");
1351 if ((reg & PCIE_LCSR2_COMP_SOS) != 0)
1352 printf(" Compliance SOS\n");
1353 printf(" Compliance Present/De-emphasis: %u\n",
1354 (unsigned int)(reg & PCIE_LCSR2_COMP_DEEMP) >> 12);
1355
1356 /* Link Status 2 */
1357 if ((reg & PCIE_LCSR2_DEEMP_LVL) != 0)
1358 printf(" Current De-emphasis Level\n");
1359 if ((reg & PCIE_LCSR2_EQ_COMPL) != 0)
1360 printf(" Equalization Complete\n");
1361 if ((reg & PCIE_LCSR2_EQP1_SUC) != 0)
1362 printf(" Equalization Phase 1 Successful\n");
1363 if ((reg & PCIE_LCSR2_EQP2_SUC) != 0)
1364 printf(" Equalization Phase 2 Successful\n");
1365 if ((reg & PCIE_LCSR2_EQP3_SUC) != 0)
1366 printf(" Equalization Phase 3 Successful\n");
1367 if ((reg & PCIE_LCSR2_LNKEQ_REQ) != 0)
1368 printf(" Link Equalization Request\n");
1369 }
1370
1371 /* Slot Capability 2 */
1372 /* Slot Control 2 */
1373 /* Slot Status 2 */
1374 }
1375
1376 static const char *
1377 pci_conf_print_pcipm_cap_aux(uint16_t caps)
1378 {
1379 switch ((caps >> 6) & 7) {
1380 case 0: return "self-powered";
1381 case 1: return "55 mA";
1382 case 2: return "100 mA";
1383 case 3: return "160 mA";
1384 case 4: return "220 mA";
1385 case 5: return "270 mA";
1386 case 6: return "320 mA";
1387 case 7:
1388 default: return "375 mA";
1389 }
1390 }
1391
1392 static const char *
1393 pci_conf_print_pcipm_cap_pmrev(uint8_t val)
1394 {
1395 static const char unk[] = "unknown";
1396 static const char *pmrev[8] = {
1397 unk, "1.0", "1.1", "1.2", unk, unk, unk, unk
1398 };
1399 if (val > 7)
1400 return unk;
1401 return pmrev[val];
1402 }
1403
1404 static void
1405 pci_conf_print_pcipm_cap(const pcireg_t *regs, int capoff)
1406 {
1407 uint16_t caps, pmcsr;
1408 pcireg_t reg;
1409
1410 caps = regs[o2i(capoff)] >> PCI_PMCR_SHIFT;
1411 reg = regs[o2i(capoff + PCI_PMCSR)];
1412 pmcsr = reg & 0xffff;
1413
1414 printf("\n PCI Power Management Capabilities Register\n");
1415
1416 printf(" Capabilities register: 0x%04x\n", caps);
1417 printf(" Version: %s\n",
1418 pci_conf_print_pcipm_cap_pmrev(caps & PCI_PMCR_VERSION_MASK));
1419 onoff("PME# clock", caps, PCI_PMCR_PME_CLOCK);
1420 onoff("Device specific initialization", caps, PCI_PMCR_DSI);
1421 printf(" 3.3V auxiliary current: %s\n",
1422 pci_conf_print_pcipm_cap_aux(caps));
1423 onoff("D1 power management state support", caps, PCI_PMCR_D1SUPP);
1424 onoff("D2 power management state support", caps, PCI_PMCR_D2SUPP);
1425 printf(" PME# support: 0x%02x\n", caps >> 11);
1426
1427 printf(" Control/status register: 0x%04x\n", pmcsr);
1428 printf(" Power state: D%d\n", pmcsr & PCI_PMCSR_STATE_MASK);
1429 onoff("PCI Express reserved", (pmcsr >> 2), 1);
1430 onoff("No soft reset", (pmcsr >> 3), 1);
1431 printf(" PME# assertion: %sabled\n",
1432 (pmcsr & PCI_PMCSR_PME_EN) ? "en" : "dis");
1433 onoff("PME# status", pmcsr, PCI_PMCSR_PME_STS);
1434 printf(" Bridge Support Extensions register: 0x%02x\n",
1435 (reg >> 16) & 0xff);
1436 onoff("B2/B3 support", reg, PCI_PMCSR_B2B3_SUPPORT);
1437 onoff("Bus Power/Clock Control Enable", reg, PCI_PMCSR_BPCC_EN);
1438 printf(" Data register: 0x%02x\n", (reg >> 24) & 0xff);
1439
1440 }
1441
1442 static void
1443 pci_conf_print_msi_cap(const pcireg_t *regs, int capoff)
1444 {
1445 uint32_t ctl, mmc, mme;
1446
1447 regs += o2i(capoff);
1448 ctl = *regs++;
1449 mmc = __SHIFTOUT(ctl, PCI_MSI_CTL_MMC_MASK);
1450 mme = __SHIFTOUT(ctl, PCI_MSI_CTL_MME_MASK);
1451
1452 printf("\n PCI Message Signaled Interrupt\n");
1453
1454 printf(" Message Control register: 0x%04x\n", ctl >> 16);
1455 onoff("MSI Enabled", ctl, PCI_MSI_CTL_MSI_ENABLE);
1456 printf(" Multiple Message Capable: %s (%d vector%s)\n",
1457 mmc > 0 ? "yes" : "no", 1 << mmc, mmc > 0 ? "s" : "");
1458 printf(" Multiple Message Enabled: %s (%d vector%s)\n",
1459 mme > 0 ? "on" : "off", 1 << mme, mme > 0 ? "s" : "");
1460 onoff("64 Bit Address Capable", ctl, PCI_MSI_CTL_64BIT_ADDR);
1461 onoff("Per-Vector Masking Capable", ctl, PCI_MSI_CTL_PERVEC_MASK);
1462 printf(" Message Address %sregister: 0x%08x\n",
1463 ctl & PCI_MSI_CTL_64BIT_ADDR ? "(lower) " : "", *regs++);
1464 if (ctl & PCI_MSI_CTL_64BIT_ADDR) {
1465 printf(" Message Address %sregister: 0x%08x\n",
1466 "(upper) ", *regs++);
1467 }
1468 printf(" Message Data register: 0x%08x\n", *regs++);
1469 if (ctl & PCI_MSI_CTL_PERVEC_MASK) {
1470 printf(" Vector Mask register: 0x%08x\n", *regs++);
1471 printf(" Vector Pending register: 0x%08x\n", *regs++);
1472 }
1473 }
1474 static void
1475 pci_conf_print_caplist(
1476 #ifdef _KERNEL
1477 pci_chipset_tag_t pc, pcitag_t tag,
1478 #endif
1479 const pcireg_t *regs, int capoff)
1480 {
1481 int off;
1482 pcireg_t rval;
1483 int pcie_off = -1, pcipm_off = -1, msi_off = -1;
1484
1485 for (off = PCI_CAPLIST_PTR(regs[o2i(capoff)]);
1486 off != 0;
1487 off = PCI_CAPLIST_NEXT(regs[o2i(off)])) {
1488 rval = regs[o2i(off)];
1489 printf(" Capability register at 0x%02x\n", off);
1490
1491 printf(" type: 0x%02x (", PCI_CAPLIST_CAP(rval));
1492 switch (PCI_CAPLIST_CAP(rval)) {
1493 case PCI_CAP_RESERVED0:
1494 printf("reserved");
1495 break;
1496 case PCI_CAP_PWRMGMT:
1497 printf("Power Management, rev. %s",
1498 pci_conf_print_pcipm_cap_pmrev((rval >> 0) & 0x07));
1499 pcipm_off = off;
1500 break;
1501 case PCI_CAP_AGP:
1502 printf("AGP, rev. %d.%d",
1503 PCI_CAP_AGP_MAJOR(rval),
1504 PCI_CAP_AGP_MINOR(rval));
1505 break;
1506 case PCI_CAP_VPD:
1507 printf("VPD");
1508 break;
1509 case PCI_CAP_SLOTID:
1510 printf("SlotID");
1511 break;
1512 case PCI_CAP_MSI:
1513 printf("MSI");
1514 msi_off = off;
1515 break;
1516 case PCI_CAP_CPCI_HOTSWAP:
1517 printf("CompactPCI Hot-swapping");
1518 break;
1519 case PCI_CAP_PCIX:
1520 printf("PCI-X");
1521 break;
1522 case PCI_CAP_LDT:
1523 printf("LDT");
1524 break;
1525 case PCI_CAP_VENDSPEC:
1526 printf("Vendor-specific");
1527 break;
1528 case PCI_CAP_DEBUGPORT:
1529 printf("Debug Port");
1530 break;
1531 case PCI_CAP_CPCI_RSRCCTL:
1532 printf("CompactPCI Resource Control");
1533 break;
1534 case PCI_CAP_HOTPLUG:
1535 printf("Hot-Plug");
1536 break;
1537 case PCI_CAP_SUBVENDOR:
1538 printf("Sub Vendor ID");
1539 break;
1540 case PCI_CAP_AGP8:
1541 printf("AGP 8x");
1542 break;
1543 case PCI_CAP_SECURE:
1544 printf("Secure Device");
1545 break;
1546 case PCI_CAP_PCIEXPRESS:
1547 printf("PCI Express");
1548 pcie_off = off;
1549 break;
1550 case PCI_CAP_MSIX:
1551 printf("MSI-X");
1552 break;
1553 case PCI_CAP_SATA:
1554 printf("SATA");
1555 break;
1556 case PCI_CAP_PCIAF:
1557 printf("Advanced Features");
1558 break;
1559 default:
1560 printf("unknown");
1561 }
1562 printf(")\n");
1563 }
1564 if (msi_off != -1)
1565 pci_conf_print_msi_cap(regs, msi_off);
1566 if (pcipm_off != -1)
1567 pci_conf_print_pcipm_cap(regs, pcipm_off);
1568 if (pcie_off != -1)
1569 pci_conf_print_pcie_cap(regs, pcie_off);
1570 }
1571
1572 /* Print the Secondary Status Register. */
1573 static void
1574 pci_conf_print_ssr(pcireg_t rval)
1575 {
1576 pcireg_t devsel;
1577
1578 printf(" Secondary status register: 0x%04x\n", rval); /* XXX bits */
1579 onoff("66 MHz capable", rval, __BIT(5));
1580 onoff("User Definable Features (UDF) support", rval, __BIT(6));
1581 onoff("Fast back-to-back capable", rval, __BIT(7));
1582 onoff("Data parity error detected", rval, __BIT(8));
1583
1584 printf(" DEVSEL timing: ");
1585 devsel = __SHIFTOUT(rval, __BITS(10, 9));
1586 switch (devsel) {
1587 case 0:
1588 printf("fast");
1589 break;
1590 case 1:
1591 printf("medium");
1592 break;
1593 case 2:
1594 printf("slow");
1595 break;
1596 default:
1597 printf("unknown/reserved"); /* XXX */
1598 break;
1599 }
1600 printf(" (0x%x)\n", devsel);
1601
1602 onoff("Signalled target abort", rval, __BIT(11));
1603 onoff("Received target abort", rval, __BIT(12));
1604 onoff("Received master abort", rval, __BIT(13));
1605 onoff("Received system error", rval, __BIT(14));
1606 onoff("Detected parity error", rval, __BIT(15));
1607 }
1608
1609 static void
1610 pci_conf_print_type1(
1611 #ifdef _KERNEL
1612 pci_chipset_tag_t pc, pcitag_t tag,
1613 #endif
1614 const pcireg_t *regs
1615 #ifdef _KERNEL
1616 , int sizebars
1617 #endif
1618 )
1619 {
1620 int off, width;
1621 pcireg_t rval;
1622 uint32_t base, limit;
1623 uint32_t base_h, limit_h;
1624 uint64_t pbase, plimit;
1625 int use_upper;
1626
1627 /*
1628 * XXX these need to be printed in more detail, need to be
1629 * XXX checked against specs/docs, etc.
1630 *
1631 * This layout was cribbed from the TI PCI2030 PCI-to-PCI
1632 * Bridge chip documentation, and may not be correct with
1633 * respect to various standards. (XXX)
1634 */
1635
1636 for (off = 0x10; off < 0x18; off += width) {
1637 #ifdef _KERNEL
1638 width = pci_conf_print_bar(pc, tag, regs, off, NULL, sizebars);
1639 #else
1640 width = pci_conf_print_bar(regs, off, NULL);
1641 #endif
1642 }
1643
1644 rval = regs[o2i(PCI_BRIDGE_BUS_REG)];
1645 printf(" Primary bus number: 0x%02x\n",
1646 PCI_BRIDGE_BUS_PRIMARY(rval));
1647 printf(" Secondary bus number: 0x%02x\n",
1648 PCI_BRIDGE_BUS_SECONDARY(rval));
1649 printf(" Subordinate bus number: 0x%02x\n",
1650 PCI_BRIDGE_BUS_SUBORDINATE(rval));
1651 printf(" Secondary bus latency timer: 0x%02x\n",
1652 PCI_BRIDGE_BUS_SEC_LATTIMER(rval));
1653
1654 rval = regs[o2i(PCI_BRIDGE_STATIO_REG)];
1655 pci_conf_print_ssr(__SHIFTOUT(rval, __BITS(31, 16)));
1656
1657 /* I/O region */
1658 printf(" I/O region:\n");
1659 printf(" base register: 0x%02x\n", (rval >> 0) & 0xff);
1660 printf(" limit register: 0x%02x\n", (rval >> 8) & 0xff);
1661 if (PCI_BRIDGE_IO_32BITS(rval))
1662 use_upper = 1;
1663 else
1664 use_upper = 0;
1665 onoff("32bit I/O", rval, use_upper);
1666 base = (rval & PCI_BRIDGE_STATIO_IOBASE_MASK) << 8;
1667 limit = ((rval >> PCI_BRIDGE_STATIO_IOLIMIT_SHIFT)
1668 & PCI_BRIDGE_STATIO_IOLIMIT_MASK) << 8;
1669 limit |= 0x00000fff;
1670
1671 rval = regs[o2i(PCI_BRIDGE_IOHIGH_REG)];
1672 base_h = (rval >> 0) & 0xffff;
1673 limit_h = (rval >> 16) & 0xffff;
1674 printf(" base upper 16 bits register: 0x%04x\n", base_h);
1675 printf(" limit upper 16 bits register: 0x%04x\n", limit_h);
1676
1677 if (use_upper == 1) {
1678 base |= base_h << 16;
1679 limit |= limit_h << 16;
1680 }
1681 if (base < limit) {
1682 if (use_upper == 1)
1683 printf(" range: 0x%08x-0x%08x\n", base, limit);
1684 else
1685 printf(" range: 0x%04x-0x%04x\n", base, limit);
1686 }
1687
1688 /* Non-prefetchable memory region */
1689 rval = regs[o2i(PCI_BRIDGE_MEMORY_REG)];
1690 printf(" Memory region:\n");
1691 printf(" base register: 0x%04x\n",
1692 (rval >> 0) & 0xffff);
1693 printf(" limit register: 0x%04x\n",
1694 (rval >> 16) & 0xffff);
1695 base = ((rval >> PCI_BRIDGE_MEMORY_BASE_SHIFT)
1696 & PCI_BRIDGE_MEMORY_BASE_MASK) << 20;
1697 limit = (((rval >> PCI_BRIDGE_MEMORY_LIMIT_SHIFT)
1698 & PCI_BRIDGE_MEMORY_LIMIT_MASK) << 20) | 0x000fffff;
1699 if (base < limit)
1700 printf(" range: 0x%08x-0x%08x\n", base, limit);
1701
1702 /* Prefetchable memory region */
1703 rval = regs[o2i(PCI_BRIDGE_PREFETCHMEM_REG)];
1704 printf(" Prefetchable memory region:\n");
1705 printf(" base register: 0x%04x\n",
1706 (rval >> 0) & 0xffff);
1707 printf(" limit register: 0x%04x\n",
1708 (rval >> 16) & 0xffff);
1709 base_h = regs[o2i(PCI_BRIDGE_PREFETCHBASE32_REG)];
1710 limit_h = regs[o2i(PCI_BRIDGE_PREFETCHLIMIT32_REG)];
1711 printf(" base upper 32 bits register: 0x%08x\n",
1712 base_h);
1713 printf(" limit upper 32 bits register: 0x%08x\n",
1714 limit_h);
1715 if (PCI_BRIDGE_PREFETCHMEM_64BITS(rval))
1716 use_upper = 1;
1717 else
1718 use_upper = 0;
1719 onoff("64bit memory address", rval, use_upper);
1720 pbase = ((rval >> PCI_BRIDGE_PREFETCHMEM_BASE_SHIFT)
1721 & PCI_BRIDGE_PREFETCHMEM_BASE_MASK) << 20;
1722 plimit = (((rval >> PCI_BRIDGE_PREFETCHMEM_LIMIT_SHIFT)
1723 & PCI_BRIDGE_PREFETCHMEM_LIMIT_MASK) << 20) | 0x000fffff;
1724 if (use_upper == 1) {
1725 pbase |= (uint64_t)base_h << 32;
1726 plimit |= (uint64_t)limit_h << 32;
1727 }
1728 if (pbase < plimit) {
1729 if (use_upper == 1)
1730 printf(" range: 0x%016" PRIx64 "-0x%016" PRIx64 "\n",
1731 pbase, plimit);
1732 else
1733 printf(" range: 0x%08x-0x%08x\n",
1734 (uint32_t)pbase, (uint32_t)plimit);
1735 }
1736
1737 if (regs[o2i(PCI_COMMAND_STATUS_REG)] & PCI_STATUS_CAPLIST_SUPPORT)
1738 printf(" Capability list pointer: 0x%02x\n",
1739 PCI_CAPLIST_PTR(regs[o2i(PCI_CAPLISTPTR_REG)]));
1740 else
1741 printf(" Reserved @ 0x34: 0x%08x\n", regs[o2i(0x34)]);
1742
1743 /* XXX */
1744 printf(" Expansion ROM Base Address: 0x%08x\n", regs[o2i(0x38)]);
1745
1746 rval = regs[o2i(PCI_INTERRUPT_REG)];
1747 printf(" Interrupt line: 0x%02x\n",
1748 (rval >> 0) & 0xff);
1749 printf(" Interrupt pin: 0x%02x ",
1750 (rval >> 8) & 0xff);
1751 switch ((rval >> 8) & 0xff) {
1752 case PCI_INTERRUPT_PIN_NONE:
1753 printf("(none)");
1754 break;
1755 case PCI_INTERRUPT_PIN_A:
1756 printf("(pin A)");
1757 break;
1758 case PCI_INTERRUPT_PIN_B:
1759 printf("(pin B)");
1760 break;
1761 case PCI_INTERRUPT_PIN_C:
1762 printf("(pin C)");
1763 break;
1764 case PCI_INTERRUPT_PIN_D:
1765 printf("(pin D)");
1766 break;
1767 default:
1768 printf("(? ? ?)");
1769 break;
1770 }
1771 printf("\n");
1772 rval = (regs[o2i(PCI_BRIDGE_CONTROL_REG)] >> PCI_BRIDGE_CONTROL_SHIFT)
1773 & PCI_BRIDGE_CONTROL_MASK;
1774 printf(" Bridge control register: 0x%04x\n", rval); /* XXX bits */
1775 onoff("Parity error response", rval, 0x0001);
1776 onoff("Secondary SERR forwarding", rval, 0x0002);
1777 onoff("ISA enable", rval, 0x0004);
1778 onoff("VGA enable", rval, 0x0008);
1779 onoff("Master abort reporting", rval, 0x0020);
1780 onoff("Secondary bus reset", rval, 0x0040);
1781 onoff("Fast back-to-back capable", rval, 0x0080);
1782 }
1783
1784 static void
1785 pci_conf_print_type2(
1786 #ifdef _KERNEL
1787 pci_chipset_tag_t pc, pcitag_t tag,
1788 #endif
1789 const pcireg_t *regs
1790 #ifdef _KERNEL
1791 , int sizebars
1792 #endif
1793 )
1794 {
1795 pcireg_t rval;
1796
1797 /*
1798 * XXX these need to be printed in more detail, need to be
1799 * XXX checked against specs/docs, etc.
1800 *
1801 * This layout was cribbed from the TI PCI1420 PCI-to-CardBus
1802 * controller chip documentation, and may not be correct with
1803 * respect to various standards. (XXX)
1804 */
1805
1806 #ifdef _KERNEL
1807 pci_conf_print_bar(pc, tag, regs, 0x10,
1808 "CardBus socket/ExCA registers", sizebars);
1809 #else
1810 pci_conf_print_bar(regs, 0x10, "CardBus socket/ExCA registers");
1811 #endif
1812
1813 /* Capability list pointer and secondary status register */
1814 rval = regs[o2i(PCI_CARDBUS_CAPLISTPTR_REG)];
1815 if (regs[o2i(PCI_COMMAND_STATUS_REG)] & PCI_STATUS_CAPLIST_SUPPORT)
1816 printf(" Capability list pointer: 0x%02x\n",
1817 PCI_CAPLIST_PTR(rval));
1818 else
1819 printf(" Reserved @ 0x14: 0x%04" PRIxMAX "\n",
1820 __SHIFTOUT(rval, __BITS(15, 0)));
1821 pci_conf_print_ssr(__SHIFTOUT(rval, __BITS(31, 16)));
1822
1823 rval = regs[o2i(PCI_BRIDGE_BUS_REG)];
1824 printf(" PCI bus number: 0x%02x\n",
1825 (rval >> 0) & 0xff);
1826 printf(" CardBus bus number: 0x%02x\n",
1827 (rval >> 8) & 0xff);
1828 printf(" Subordinate bus number: 0x%02x\n",
1829 (rval >> 16) & 0xff);
1830 printf(" CardBus latency timer: 0x%02x\n",
1831 (rval >> 24) & 0xff);
1832
1833 /* XXX Print more prettily */
1834 printf(" CardBus memory region 0:\n");
1835 printf(" base register: 0x%08x\n", regs[o2i(0x1c)]);
1836 printf(" limit register: 0x%08x\n", regs[o2i(0x20)]);
1837 printf(" CardBus memory region 1:\n");
1838 printf(" base register: 0x%08x\n", regs[o2i(0x24)]);
1839 printf(" limit register: 0x%08x\n", regs[o2i(0x28)]);
1840 printf(" CardBus I/O region 0:\n");
1841 printf(" base register: 0x%08x\n", regs[o2i(0x2c)]);
1842 printf(" limit register: 0x%08x\n", regs[o2i(0x30)]);
1843 printf(" CardBus I/O region 1:\n");
1844 printf(" base register: 0x%08x\n", regs[o2i(0x34)]);
1845 printf(" limit register: 0x%08x\n", regs[o2i(0x38)]);
1846
1847 rval = regs[o2i(PCI_INTERRUPT_REG)];
1848 printf(" Interrupt line: 0x%02x\n",
1849 (rval >> 0) & 0xff);
1850 printf(" Interrupt pin: 0x%02x ",
1851 (rval >> 8) & 0xff);
1852 switch ((rval >> 8) & 0xff) {
1853 case PCI_INTERRUPT_PIN_NONE:
1854 printf("(none)");
1855 break;
1856 case PCI_INTERRUPT_PIN_A:
1857 printf("(pin A)");
1858 break;
1859 case PCI_INTERRUPT_PIN_B:
1860 printf("(pin B)");
1861 break;
1862 case PCI_INTERRUPT_PIN_C:
1863 printf("(pin C)");
1864 break;
1865 case PCI_INTERRUPT_PIN_D:
1866 printf("(pin D)");
1867 break;
1868 default:
1869 printf("(? ? ?)");
1870 break;
1871 }
1872 printf("\n");
1873 rval = (regs[o2i(0x3c)] >> 16) & 0xffff;
1874 printf(" Bridge control register: 0x%04x\n", rval);
1875 onoff("Parity error response", rval, __BIT(0));
1876 onoff("SERR# enable", rval, __BIT(1));
1877 onoff("ISA enable", rval, __BIT(2));
1878 onoff("VGA enable", rval, __BIT(3));
1879 onoff("Master abort mode", rval, __BIT(5));
1880 onoff("Secondary (CardBus) bus reset", rval, __BIT(6));
1881 onoff("Functional interrupts routed by ExCA registers", rval, __BIT(7));
1882 onoff("Memory window 0 prefetchable", rval, __BIT(8));
1883 onoff("Memory window 1 prefetchable", rval, __BIT(9));
1884 onoff("Write posting enable", rval, __BIT(10));
1885
1886 rval = regs[o2i(0x40)];
1887 printf(" Subsystem vendor ID: 0x%04x\n", PCI_VENDOR(rval));
1888 printf(" Subsystem ID: 0x%04x\n", PCI_PRODUCT(rval));
1889
1890 #ifdef _KERNEL
1891 pci_conf_print_bar(pc, tag, regs, 0x44, "legacy-mode registers",
1892 sizebars);
1893 #else
1894 pci_conf_print_bar(regs, 0x44, "legacy-mode registers");
1895 #endif
1896 }
1897
1898 void
1899 pci_conf_print(
1900 #ifdef _KERNEL
1901 pci_chipset_tag_t pc, pcitag_t tag,
1902 void (*printfn)(pci_chipset_tag_t, pcitag_t, const pcireg_t *)
1903 #else
1904 int pcifd, u_int bus, u_int dev, u_int func
1905 #endif
1906 )
1907 {
1908 pcireg_t regs[o2i(256)];
1909 int off, capoff, endoff, hdrtype;
1910 const char *typename;
1911 #ifdef _KERNEL
1912 void (*typeprintfn)(pci_chipset_tag_t, pcitag_t, const pcireg_t *, int);
1913 int sizebars;
1914 #else
1915 void (*typeprintfn)(const pcireg_t *);
1916 #endif
1917
1918 printf("PCI configuration registers:\n");
1919
1920 for (off = 0; off < 256; off += 4) {
1921 #ifdef _KERNEL
1922 regs[o2i(off)] = pci_conf_read(pc, tag, off);
1923 #else
1924 if (pcibus_conf_read(pcifd, bus, dev, func, off,
1925 ®s[o2i(off)]) == -1)
1926 regs[o2i(off)] = 0;
1927 #endif
1928 }
1929
1930 #ifdef _KERNEL
1931 sizebars = 1;
1932 if (PCI_CLASS(regs[o2i(PCI_CLASS_REG)]) == PCI_CLASS_BRIDGE &&
1933 PCI_SUBCLASS(regs[o2i(PCI_CLASS_REG)]) == PCI_SUBCLASS_BRIDGE_HOST)
1934 sizebars = 0;
1935 #endif
1936
1937 /* common header */
1938 printf(" Common header:\n");
1939 pci_conf_print_regs(regs, 0, 16);
1940
1941 printf("\n");
1942 #ifdef _KERNEL
1943 pci_conf_print_common(pc, tag, regs);
1944 #else
1945 pci_conf_print_common(regs);
1946 #endif
1947 printf("\n");
1948
1949 /* type-dependent header */
1950 hdrtype = PCI_HDRTYPE_TYPE(regs[o2i(PCI_BHLC_REG)]);
1951 switch (hdrtype) { /* XXX make a table, eventually */
1952 case 0:
1953 /* Standard device header */
1954 typename = "\"normal\" device";
1955 typeprintfn = &pci_conf_print_type0;
1956 capoff = PCI_CAPLISTPTR_REG;
1957 endoff = 64;
1958 break;
1959 case 1:
1960 /* PCI-PCI bridge header */
1961 typename = "PCI-PCI bridge";
1962 typeprintfn = &pci_conf_print_type1;
1963 capoff = PCI_CAPLISTPTR_REG;
1964 endoff = 64;
1965 break;
1966 case 2:
1967 /* PCI-CardBus bridge header */
1968 typename = "PCI-CardBus bridge";
1969 typeprintfn = &pci_conf_print_type2;
1970 capoff = PCI_CARDBUS_CAPLISTPTR_REG;
1971 endoff = 72;
1972 break;
1973 default:
1974 typename = NULL;
1975 typeprintfn = 0;
1976 capoff = -1;
1977 endoff = 64;
1978 break;
1979 }
1980 printf(" Type %d ", hdrtype);
1981 if (typename != NULL)
1982 printf("(%s) ", typename);
1983 printf("header:\n");
1984 pci_conf_print_regs(regs, 16, endoff);
1985 printf("\n");
1986 if (typeprintfn) {
1987 #ifdef _KERNEL
1988 (*typeprintfn)(pc, tag, regs, sizebars);
1989 #else
1990 (*typeprintfn)(regs);
1991 #endif
1992 } else
1993 printf(" Don't know how to pretty-print type %d header.\n",
1994 hdrtype);
1995 printf("\n");
1996
1997 /* capability list, if present */
1998 if ((regs[o2i(PCI_COMMAND_STATUS_REG)] & PCI_STATUS_CAPLIST_SUPPORT)
1999 && (capoff > 0)) {
2000 #ifdef _KERNEL
2001 pci_conf_print_caplist(pc, tag, regs, capoff);
2002 #else
2003 pci_conf_print_caplist(regs, capoff);
2004 #endif
2005 printf("\n");
2006 }
2007
2008 /* device-dependent header */
2009 printf(" Device-dependent header:\n");
2010 pci_conf_print_regs(regs, endoff, 256);
2011 printf("\n");
2012 #ifdef _KERNEL
2013 if (printfn)
2014 (*printfn)(pc, tag, regs);
2015 else
2016 printf(" Don't know how to pretty-print device-dependent header.\n");
2017 printf("\n");
2018 #endif /* _KERNEL */
2019 }
2020