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