Home | History | Annotate | Line # | Download | only in pci
pci_subr.c revision 1.234
      1 /*	$NetBSD: pci_subr.c,v 1.234 2021/12/28 09:16:05 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.234 2021/12/28 09:16:05 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 #include <sys/kmem.h>
     56 
     57 #define MALLOC(sz)	kmem_alloc(sz, KM_SLEEP)
     58 #define FREE(p, sz)	kmem_free(p, sz)
     59 
     60 #else
     61 #include <pci.h>
     62 #include <stdarg.h>
     63 #include <stdbool.h>
     64 #include <stdio.h>
     65 #include <stdlib.h>
     66 #include <string.h>
     67 
     68 #define MALLOC(sz)	malloc(sz)
     69 #define FREE(p, sz)	free(p)
     70 
     71 #endif
     72 
     73 #include <dev/pci/pcireg.h>
     74 #include <dev/pci/pcidevs.h>
     75 #ifdef _KERNEL
     76 #include <dev/pci/pcivar.h>
     77 #else
     78 #include <dev/pci/pci_verbose.h>
     79 #include <dev/pci/pcidevs_data.h>
     80 #endif
     81 
     82 static int pci_conf_find_cap(const pcireg_t *, unsigned int, int *);
     83 static int pci_conf_find_extcap(const pcireg_t *, unsigned int, int *);
     84 static void pci_conf_print_pcie_power(uint8_t, unsigned int);
     85 #define PCIREG_SHIFTOUT(a, b) ((pcireg_t)__SHIFTOUT((a), (b)))
     86 
     87 #ifdef _KERNEL
     88 /*
     89  * Common routines used to match a compatible device by its PCI ID code.
     90  */
     91 
     92 const struct device_compatible_entry *
     93 pci_compatible_lookup_id(pcireg_t const id,
     94     const struct device_compatible_entry *dce)
     95 {
     96 	return device_compatible_lookup_id(id, PCI_COMPAT_EOL_VALUE, dce);
     97 }
     98 
     99 const struct device_compatible_entry *
    100 pci_compatible_lookup(const struct pci_attach_args * const pa,
    101     const struct device_compatible_entry * const dce)
    102 {
    103 	return pci_compatible_lookup_id(pa->pa_id, dce);
    104 }
    105 
    106 const struct device_compatible_entry *
    107 pci_compatible_lookup_subsys(const struct pci_attach_args * const pa,
    108     const struct device_compatible_entry * const dce)
    109 {
    110 	const pcireg_t subsysid =
    111 	    pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_SUBSYS_ID_REG);
    112 
    113 	return pci_compatible_lookup_id(subsysid, dce);
    114 }
    115 
    116 int
    117 pci_compatible_match(const struct pci_attach_args * const pa,
    118     const struct device_compatible_entry * const dce)
    119 {
    120 	return pci_compatible_lookup(pa, dce) != NULL;
    121 }
    122 
    123 int
    124 pci_compatible_match_subsys(const struct pci_attach_args * const pa,
    125     const struct device_compatible_entry * const dce)
    126 {
    127 	return pci_compatible_lookup_subsys(pa, dce) != NULL;
    128 }
    129 #endif /* _KERNEL */
    130 
    131 /*
    132  * Descriptions of known PCI classes and subclasses.
    133  *
    134  * Subclasses are described in the same way as classes, but have a
    135  * NULL subclass pointer.
    136  */
    137 struct pci_class {
    138 	const char	*name;
    139 	u_int		val;		/* as wide as pci_{,sub}class_t */
    140 	const struct pci_class *subclasses;
    141 };
    142 
    143 /*
    144  * Class 0x00.
    145  * Before rev. 2.0.
    146  */
    147 static const struct pci_class pci_subclass_prehistoric[] = {
    148 	{ "miscellaneous",	PCI_SUBCLASS_PREHISTORIC_MISC,	NULL,	},
    149 	{ "VGA",		PCI_SUBCLASS_PREHISTORIC_VGA,	NULL,	},
    150 	{ NULL,			0,				NULL,	},
    151 };
    152 
    153 /*
    154  * Class 0x01.
    155  * Mass storage controller
    156  */
    157 
    158 /* ATA programming interface */
    159 static const struct pci_class pci_interface_ata[] = {
    160 	{ "with single DMA",	PCI_INTERFACE_ATA_SINGLEDMA,	NULL,	},
    161 	{ "with chained DMA",	PCI_INTERFACE_ATA_CHAINEDDMA,	NULL,	},
    162 	{ NULL,			0,				NULL,	},
    163 };
    164 
    165 /* SATA programming interface */
    166 static const struct pci_class pci_interface_sata[] = {
    167 	{ "vendor specific",	PCI_INTERFACE_SATA_VND,		NULL,	},
    168 	{ "AHCI 1.0",		PCI_INTERFACE_SATA_AHCI10,	NULL,	},
    169 	{ "Serial Storage Bus Interface", PCI_INTERFACE_SATA_SSBI, NULL, },
    170 	{ NULL,			0,				NULL,	},
    171 };
    172 
    173 /* Flash programming interface */
    174 static const struct pci_class pci_interface_nvm[] = {
    175 	{ "vendor specific",	PCI_INTERFACE_NVM_VND,		NULL,	},
    176 	{ "NVMHCI 1.0",		PCI_INTERFACE_NVM_NVMHCI10,	NULL,	},
    177 	{ "NVMe I/O",		PCI_INTERFACE_NVM_NVME_IO,	NULL,	},
    178 	{ "NVMe admin",		PCI_INTERFACE_NVM_NVME_ADMIN,	NULL,	},
    179 	{ NULL,			0,				NULL,	},
    180 };
    181 
    182 /* UFS programming interface */
    183 static const struct pci_class pci_interface_ufs[] = {
    184 	{ "vendor specific",	PCI_INTERFACE_UFS_VND,		NULL,	},
    185 	{ "UFSHCI",		PCI_INTERFACE_UFS_UFSHCI,	NULL,	},
    186 	{ NULL,			0,				NULL,	},
    187 };
    188 
    189 /* Subclasses */
    190 static const struct pci_class pci_subclass_mass_storage[] = {
    191 	{ "SCSI",		PCI_SUBCLASS_MASS_STORAGE_SCSI,	NULL,	},
    192 	{ "IDE",		PCI_SUBCLASS_MASS_STORAGE_IDE,	NULL,	},
    193 	{ "floppy",		PCI_SUBCLASS_MASS_STORAGE_FLOPPY, NULL, },
    194 	{ "IPI",		PCI_SUBCLASS_MASS_STORAGE_IPI,	NULL,	},
    195 	{ "RAID",		PCI_SUBCLASS_MASS_STORAGE_RAID,	NULL,	},
    196 	{ "ATA",		PCI_SUBCLASS_MASS_STORAGE_ATA,
    197 	  pci_interface_ata, },
    198 	{ "SATA",		PCI_SUBCLASS_MASS_STORAGE_SATA,
    199 	  pci_interface_sata, },
    200 	{ "SAS",		PCI_SUBCLASS_MASS_STORAGE_SAS,	NULL,	},
    201 	{ "Flash",		PCI_SUBCLASS_MASS_STORAGE_NVM,
    202 	  pci_interface_nvm,	},
    203 	{ "UFS",		PCI_SUBCLASS_MASS_STORAGE_UFS,
    204 	  pci_interface_ufs,	},
    205 	{ "miscellaneous",	PCI_SUBCLASS_MASS_STORAGE_MISC,	NULL,	},
    206 	{ NULL,			0,				NULL,	},
    207 };
    208 
    209 /*
    210  * Class 0x02.
    211  * Network controller.
    212  */
    213 static const struct pci_class pci_subclass_network[] = {
    214 	{ "ethernet",		PCI_SUBCLASS_NETWORK_ETHERNET,	NULL,	},
    215 	{ "token ring",		PCI_SUBCLASS_NETWORK_TOKENRING,	NULL,	},
    216 	{ "FDDI",		PCI_SUBCLASS_NETWORK_FDDI,	NULL,	},
    217 	{ "ATM",		PCI_SUBCLASS_NETWORK_ATM,	NULL,	},
    218 	{ "ISDN",		PCI_SUBCLASS_NETWORK_ISDN,	NULL,	},
    219 	{ "WorldFip",		PCI_SUBCLASS_NETWORK_WORLDFIP,	NULL,	},
    220 	{ "PCMIG Multi Computing", PCI_SUBCLASS_NETWORK_PCIMGMULTICOMP, NULL, },
    221 	{ "InfiniBand",		PCI_SUBCLASS_NETWORK_INFINIBAND, NULL, },
    222 	{ "Host fabric",	PCI_SUBCLASS_NETWORK_HFC,	NULL, },
    223 	{ "miscellaneous",	PCI_SUBCLASS_NETWORK_MISC,	NULL,	},
    224 	{ NULL,			0,				NULL,	},
    225 };
    226 
    227 /*
    228  * Class 0x03.
    229  * Display controller.
    230  */
    231 
    232 /* VGA programming interface */
    233 static const struct pci_class pci_interface_vga[] = {
    234 	{ "",			PCI_INTERFACE_VGA_VGA,		NULL,	},
    235 	{ "8514-compat",	PCI_INTERFACE_VGA_8514,		NULL,	},
    236 	{ NULL,			0,				NULL,	},
    237 };
    238 /* Subclasses */
    239 static const struct pci_class pci_subclass_display[] = {
    240 	{ "VGA",		PCI_SUBCLASS_DISPLAY_VGA,  pci_interface_vga,},
    241 	{ "XGA",		PCI_SUBCLASS_DISPLAY_XGA,	NULL,	},
    242 	{ "3D",			PCI_SUBCLASS_DISPLAY_3D,	NULL,	},
    243 	{ "miscellaneous",	PCI_SUBCLASS_DISPLAY_MISC,	NULL,	},
    244 	{ NULL,			0,				NULL,	},
    245 };
    246 
    247 /*
    248  * Class 0x04.
    249  * Multimedia device.
    250  */
    251 
    252 /* HD Audio programming interface */
    253 static const struct pci_class pci_interface_hda[] = {
    254 	{ "HD Audio 1.0",	PCI_INTERFACE_HDAUDIO,		NULL,	},
    255 	{ "HD Audio 1.0 + vendor ext",	PCI_INTERFACE_HDAUDIO_VND, NULL, },
    256 	{ NULL,			0,				NULL,	},
    257 };
    258 
    259 static const struct pci_class pci_subclass_multimedia[] = {
    260 	{ "video",		PCI_SUBCLASS_MULTIMEDIA_VIDEO,	NULL,	},
    261 	{ "audio",		PCI_SUBCLASS_MULTIMEDIA_AUDIO,	NULL,	},
    262 	{ "telephony",		PCI_SUBCLASS_MULTIMEDIA_TELEPHONY, NULL,},
    263 	{ "mixed mode",		PCI_SUBCLASS_MULTIMEDIA_HDAUDIO,
    264 	  pci_interface_hda, },
    265 	{ "miscellaneous",	PCI_SUBCLASS_MULTIMEDIA_MISC,	NULL,	},
    266 	{ NULL,			0,				NULL,	},
    267 };
    268 
    269 /*
    270  * Class 0x05.
    271  * Memory controller.
    272  */
    273 static const struct pci_class pci_subclass_memory[] = {
    274 	{ "RAM",		PCI_SUBCLASS_MEMORY_RAM,	NULL,	},
    275 	{ "flash",		PCI_SUBCLASS_MEMORY_FLASH,	NULL,	},
    276 	{ "miscellaneous",	PCI_SUBCLASS_MEMORY_MISC,	NULL,	},
    277 	{ NULL,			0,				NULL,	},
    278 };
    279 
    280 /*
    281  * Class 0x06.
    282  * Bridge device.
    283  */
    284 
    285 /* PCI bridge programming interface */
    286 static const struct pci_class pci_interface_pcibridge[] = {
    287 	{ "",			PCI_INTERFACE_BRIDGE_PCI_PCI,	NULL,	},
    288 	{ "subtractive decode",	PCI_INTERFACE_BRIDGE_PCI_SUBDEC, NULL,	},
    289 	{ NULL,			0,				NULL,	},
    290 };
    291 
    292 /* Semi-transparent PCI-to-PCI bridge programming interface */
    293 static const struct pci_class pci_interface_stpci[] = {
    294 	{ "primary side facing host",	PCI_INTERFACE_STPCI_PRIMARY, NULL, },
    295 	{ "secondary side facing host",	PCI_INTERFACE_STPCI_SECONDARY, NULL, },
    296 	{ NULL,			0,				NULL,	},
    297 };
    298 
    299 /* Advanced Switching programming interface */
    300 static const struct pci_class pci_interface_advsw[] = {
    301 	{ "custom interface",	PCI_INTERFACE_ADVSW_CUSTOM,	NULL, },
    302 	{ "ASI-SIG",		PCI_INTERFACE_ADVSW_ASISIG,	NULL, },
    303 	{ NULL,			0,				NULL,	},
    304 };
    305 
    306 /* Subclasses */
    307 static const struct pci_class pci_subclass_bridge[] = {
    308 	{ "host",		PCI_SUBCLASS_BRIDGE_HOST,	NULL,	},
    309 	{ "ISA",		PCI_SUBCLASS_BRIDGE_ISA,	NULL,	},
    310 	{ "EISA",		PCI_SUBCLASS_BRIDGE_EISA,	NULL,	},
    311 	{ "MicroChannel",	PCI_SUBCLASS_BRIDGE_MC,		NULL,	},
    312 	{ "PCI",		PCI_SUBCLASS_BRIDGE_PCI,
    313 	  pci_interface_pcibridge,	},
    314 	{ "PCMCIA",		PCI_SUBCLASS_BRIDGE_PCMCIA,	NULL,	},
    315 	{ "NuBus",		PCI_SUBCLASS_BRIDGE_NUBUS,	NULL,	},
    316 	{ "CardBus",		PCI_SUBCLASS_BRIDGE_CARDBUS,	NULL,	},
    317 	{ "RACEway",		PCI_SUBCLASS_BRIDGE_RACEWAY,	NULL,	},
    318 	{ "Semi-transparent PCI", PCI_SUBCLASS_BRIDGE_STPCI,
    319 	  pci_interface_stpci,	},
    320 	{ "InfiniBand",		PCI_SUBCLASS_BRIDGE_INFINIBAND,	NULL,	},
    321 	{ "advanced switching",	PCI_SUBCLASS_BRIDGE_ADVSW,
    322 	  pci_interface_advsw,	},
    323 	{ "miscellaneous",	PCI_SUBCLASS_BRIDGE_MISC,	NULL,	},
    324 	{ NULL,			0,				NULL,	},
    325 };
    326 
    327 /*
    328  * Class 0x07.
    329  * Simple communications controller.
    330  */
    331 
    332 /* Serial controller programming interface */
    333 static const struct pci_class pci_interface_serial[] = {
    334 	{ "generic XT-compat",	PCI_INTERFACE_SERIAL_XT,	NULL,	},
    335 	{ "16450-compat",	PCI_INTERFACE_SERIAL_16450,	NULL,	},
    336 	{ "16550-compat",	PCI_INTERFACE_SERIAL_16550,	NULL,	},
    337 	{ "16650-compat",	PCI_INTERFACE_SERIAL_16650,	NULL,	},
    338 	{ "16750-compat",	PCI_INTERFACE_SERIAL_16750,	NULL,	},
    339 	{ "16850-compat",	PCI_INTERFACE_SERIAL_16850,	NULL,	},
    340 	{ "16950-compat",	PCI_INTERFACE_SERIAL_16950,	NULL,	},
    341 	{ NULL,			0,				NULL,	},
    342 };
    343 
    344 /* Parallel controller programming interface */
    345 static const struct pci_class pci_interface_parallel[] = {
    346 	{ "",			PCI_INTERFACE_PARALLEL,			NULL,},
    347 	{ "bi-directional",	PCI_INTERFACE_PARALLEL_BIDIRECTIONAL,	NULL,},
    348 	{ "ECP 1.X-compat",	PCI_INTERFACE_PARALLEL_ECP1X,		NULL,},
    349 	{ "IEEE1284 controller", PCI_INTERFACE_PARALLEL_IEEE1284_CNTRL,	NULL,},
    350 	{ "IEEE1284 target",	PCI_INTERFACE_PARALLEL_IEEE1284_TGT,	NULL,},
    351 	{ NULL,			0,					NULL,},
    352 };
    353 
    354 /* Modem programming interface */
    355 static const struct pci_class pci_interface_modem[] = {
    356 	{ "",			PCI_INTERFACE_MODEM,			NULL,},
    357 	{ "Hayes&16450-compat",	PCI_INTERFACE_MODEM_HAYES16450,		NULL,},
    358 	{ "Hayes&16550-compat",	PCI_INTERFACE_MODEM_HAYES16550,		NULL,},
    359 	{ "Hayes&16650-compat",	PCI_INTERFACE_MODEM_HAYES16650,		NULL,},
    360 	{ "Hayes&16750-compat",	PCI_INTERFACE_MODEM_HAYES16750,		NULL,},
    361 	{ NULL,			0,					NULL,},
    362 };
    363 
    364 /* Subclasses */
    365 static const struct pci_class pci_subclass_communications[] = {
    366 	{ "serial",		PCI_SUBCLASS_COMMUNICATIONS_SERIAL,
    367 	  pci_interface_serial, },
    368 	{ "parallel",		PCI_SUBCLASS_COMMUNICATIONS_PARALLEL,
    369 	  pci_interface_parallel, },
    370 	{ "multi-port serial",	PCI_SUBCLASS_COMMUNICATIONS_MPSERIAL,	NULL,},
    371 	{ "modem",		PCI_SUBCLASS_COMMUNICATIONS_MODEM,
    372 	  pci_interface_modem, },
    373 	{ "GPIB",		PCI_SUBCLASS_COMMUNICATIONS_GPIB,	NULL,},
    374 	{ "smartcard",		PCI_SUBCLASS_COMMUNICATIONS_SMARTCARD,	NULL,},
    375 	{ "miscellaneous",	PCI_SUBCLASS_COMMUNICATIONS_MISC,	NULL,},
    376 	{ NULL,			0,					NULL,},
    377 };
    378 
    379 /*
    380  * Class 0x08.
    381  * Base system peripheral.
    382  */
    383 
    384 /* PIC programming interface */
    385 static const struct pci_class pci_interface_pic[] = {
    386 	{ "generic 8259",	PCI_INTERFACE_PIC_8259,		NULL,	},
    387 	{ "ISA PIC",		PCI_INTERFACE_PIC_ISA,		NULL,	},
    388 	{ "EISA PIC",		PCI_INTERFACE_PIC_EISA,		NULL,	},
    389 	{ "IO APIC",		PCI_INTERFACE_PIC_IOAPIC,	NULL,	},
    390 	{ "IO(x) APIC",		PCI_INTERFACE_PIC_IOXAPIC,	NULL,	},
    391 	{ NULL,			0,				NULL,	},
    392 };
    393 
    394 /* DMA programming interface */
    395 static const struct pci_class pci_interface_dma[] = {
    396 	{ "generic 8237",	PCI_INTERFACE_DMA_8237,		NULL,	},
    397 	{ "ISA",		PCI_INTERFACE_DMA_ISA,		NULL,	},
    398 	{ "EISA",		PCI_INTERFACE_DMA_EISA,		NULL,	},
    399 	{ NULL,			0,				NULL,	},
    400 };
    401 
    402 /* Timer programming interface */
    403 static const struct pci_class pci_interface_tmr[] = {
    404 	{ "generic 8254",	PCI_INTERFACE_TIMER_8254,	NULL,	},
    405 	{ "ISA",		PCI_INTERFACE_TIMER_ISA,	NULL,	},
    406 	{ "EISA",		PCI_INTERFACE_TIMER_EISA,	NULL,	},
    407 	{ "HPET",		PCI_INTERFACE_TIMER_HPET,	NULL,	},
    408 	{ NULL,			0,				NULL,	},
    409 };
    410 
    411 /* RTC programming interface */
    412 static const struct pci_class pci_interface_rtc[] = {
    413 	{ "generic",		PCI_INTERFACE_RTC_GENERIC,	NULL,	},
    414 	{ "ISA",		PCI_INTERFACE_RTC_ISA,		NULL,	},
    415 	{ NULL,			0,				NULL,	},
    416 };
    417 
    418 /* Subclasses */
    419 static const struct pci_class pci_subclass_system[] = {
    420 	{ "interrupt",		PCI_SUBCLASS_SYSTEM_PIC,   pci_interface_pic,},
    421 	{ "DMA",		PCI_SUBCLASS_SYSTEM_DMA,   pci_interface_dma,},
    422 	{ "timer",		PCI_SUBCLASS_SYSTEM_TIMER, pci_interface_tmr,},
    423 	{ "RTC",		PCI_SUBCLASS_SYSTEM_RTC,   pci_interface_rtc,},
    424 	{ "PCI Hot-Plug",	PCI_SUBCLASS_SYSTEM_PCIHOTPLUG, NULL,	},
    425 	{ "SD Host Controller",	PCI_SUBCLASS_SYSTEM_SDHC,	NULL,	},
    426 	{ "IOMMU",		PCI_SUBCLASS_SYSTEM_IOMMU,	NULL,	},
    427 	{ "Root Complex Event Collector", PCI_SUBCLASS_SYSTEM_RCEC, NULL, },
    428 	{ "miscellaneous",	PCI_SUBCLASS_SYSTEM_MISC,	NULL,	},
    429 	{ NULL,			0,				NULL,	},
    430 };
    431 
    432 /*
    433  * Class 0x09.
    434  * Input device.
    435  */
    436 
    437 /* Gameport programming interface */
    438 static const struct pci_class pci_interface_game[] = {
    439 	{ "generic",		PCI_INTERFACE_GAMEPORT_GENERIC,	NULL,	},
    440 	{ "legacy",		PCI_INTERFACE_GAMEPORT_LEGACY,	NULL,	},
    441 	{ NULL,			0,				NULL,	},
    442 };
    443 
    444 /* Subclasses */
    445 static const struct pci_class pci_subclass_input[] = {
    446 	{ "keyboard",		PCI_SUBCLASS_INPUT_KEYBOARD,	NULL,	},
    447 	{ "digitizer",		PCI_SUBCLASS_INPUT_DIGITIZER,	NULL,	},
    448 	{ "mouse",		PCI_SUBCLASS_INPUT_MOUSE,	NULL,	},
    449 	{ "scanner",		PCI_SUBCLASS_INPUT_SCANNER,	NULL,	},
    450 	{ "game port",		PCI_SUBCLASS_INPUT_GAMEPORT,
    451 	  pci_interface_game, },
    452 	{ "miscellaneous",	PCI_SUBCLASS_INPUT_MISC,	NULL,	},
    453 	{ NULL,			0,				NULL,	},
    454 };
    455 
    456 /*
    457  * Class 0x0a.
    458  * Docking station.
    459  */
    460 static const struct pci_class pci_subclass_dock[] = {
    461 	{ "generic",		PCI_SUBCLASS_DOCK_GENERIC,	NULL,	},
    462 	{ "miscellaneous",	PCI_SUBCLASS_DOCK_MISC,		NULL,	},
    463 	{ NULL,			0,				NULL,	},
    464 };
    465 
    466 /*
    467  * Class 0x0b.
    468  * Processor.
    469  */
    470 static const struct pci_class pci_subclass_processor[] = {
    471 	{ "386",		PCI_SUBCLASS_PROCESSOR_386,	NULL,	},
    472 	{ "486",		PCI_SUBCLASS_PROCESSOR_486,	NULL,	},
    473 	{ "Pentium",		PCI_SUBCLASS_PROCESSOR_PENTIUM, NULL,	},
    474 	{ "Alpha",		PCI_SUBCLASS_PROCESSOR_ALPHA,	NULL,	},
    475 	{ "PowerPC",		PCI_SUBCLASS_PROCESSOR_POWERPC, NULL,	},
    476 	{ "MIPS",		PCI_SUBCLASS_PROCESSOR_MIPS,	NULL,	},
    477 	{ "Co-processor",	PCI_SUBCLASS_PROCESSOR_COPROC,	NULL,	},
    478 	{ "miscellaneous",	PCI_SUBCLASS_PROCESSOR_MISC,	NULL,	},
    479 	{ NULL,			0,				NULL,	},
    480 };
    481 
    482 /*
    483  * Class 0x0c.
    484  * Serial bus controller.
    485  */
    486 
    487 /* IEEE1394 programming interface */
    488 static const struct pci_class pci_interface_ieee1394[] = {
    489 	{ "Firewire",		PCI_INTERFACE_IEEE1394_FIREWIRE,	NULL,},
    490 	{ "OpenHCI",		PCI_INTERFACE_IEEE1394_OPENHCI,		NULL,},
    491 	{ NULL,			0,					NULL,},
    492 };
    493 
    494 /* USB programming interface */
    495 static const struct pci_class pci_interface_usb[] = {
    496 	{ "UHCI",		PCI_INTERFACE_USB_UHCI,		NULL,	},
    497 	{ "OHCI",		PCI_INTERFACE_USB_OHCI,		NULL,	},
    498 	{ "EHCI",		PCI_INTERFACE_USB_EHCI,		NULL,	},
    499 	{ "xHCI",		PCI_INTERFACE_USB_XHCI,		NULL,	},
    500 	{ "USB4 HCI",		PCI_INTERFACE_USB_USB4HCI,	NULL,	},
    501 	{ "other HC",		PCI_INTERFACE_USB_OTHERHC,	NULL,	},
    502 	{ "device",		PCI_INTERFACE_USB_DEVICE,	NULL,	},
    503 	{ NULL,			0,				NULL,	},
    504 };
    505 
    506 /* IPMI programming interface */
    507 static const struct pci_class pci_interface_ipmi[] = {
    508 	{ "SMIC",		PCI_INTERFACE_IPMI_SMIC,	NULL,	},
    509 	{ "keyboard",		PCI_INTERFACE_IPMI_KBD,		NULL,	},
    510 	{ "block transfer",	PCI_INTERFACE_IPMI_BLOCKXFER,	NULL,	},
    511 	{ NULL,			0,				NULL,	},
    512 };
    513 
    514 /* Subclasses */
    515 static const struct pci_class pci_subclass_serialbus[] = {
    516 	{ "IEEE1394",		PCI_SUBCLASS_SERIALBUS_FIREWIRE,
    517 	  pci_interface_ieee1394, },
    518 	{ "ACCESS.bus",		PCI_SUBCLASS_SERIALBUS_ACCESS,	NULL,	},
    519 	{ "SSA",		PCI_SUBCLASS_SERIALBUS_SSA,	NULL,	},
    520 	{ "USB",		PCI_SUBCLASS_SERIALBUS_USB,
    521 	  pci_interface_usb, },
    522 	/* XXX Fiber Channel/_FIBRECHANNEL */
    523 	{ "Fiber Channel",	PCI_SUBCLASS_SERIALBUS_FIBER,	NULL,	},
    524 	{ "SMBus",		PCI_SUBCLASS_SERIALBUS_SMBUS,	NULL,	},
    525 	{ "InfiniBand",		PCI_SUBCLASS_SERIALBUS_INFINIBAND, NULL,},
    526 	{ "IPMI",		PCI_SUBCLASS_SERIALBUS_IPMI,
    527 	  pci_interface_ipmi, },
    528 	{ "SERCOS",		PCI_SUBCLASS_SERIALBUS_SERCOS,	NULL,	},
    529 	{ "CANbus",		PCI_SUBCLASS_SERIALBUS_CANBUS,	NULL,	},
    530 	{ "MIPI I3C",		PCI_SUBCLASS_SERIALBUS_MIPI_I3C, NULL,	},
    531 	{ "miscellaneous",	PCI_SUBCLASS_SERIALBUS_MISC,	NULL,	},
    532 	{ NULL,			0,				NULL,	},
    533 };
    534 
    535 /*
    536  * Class 0x0d.
    537  * Wireless Controller.
    538  */
    539 static const struct pci_class pci_subclass_wireless[] = {
    540 	{ "IrDA",		PCI_SUBCLASS_WIRELESS_IRDA,	NULL,	},
    541 	{ "Consumer IR",/*XXX*/	PCI_SUBCLASS_WIRELESS_CONSUMERIR, NULL,	},
    542 	{ "RF",			PCI_SUBCLASS_WIRELESS_RF,	NULL,	},
    543 	{ "bluetooth",		PCI_SUBCLASS_WIRELESS_BLUETOOTH, NULL,	},
    544 	{ "broadband",		PCI_SUBCLASS_WIRELESS_BROADBAND, NULL,	},
    545 	{ "802.11a (5 GHz)",	PCI_SUBCLASS_WIRELESS_802_11A,	NULL,	},
    546 	{ "802.11b (2.4 GHz)",	PCI_SUBCLASS_WIRELESS_802_11B,	NULL,	},
    547 	{ "Cellular",		PCI_SUBCLASS_WIRELESS_CELL,	NULL,	},
    548 	{ "Cellular + Ethernet", PCI_SUBCLASS_WIRELESS_CELL_E,	NULL,	},
    549 	{ "miscellaneous",	PCI_SUBCLASS_WIRELESS_MISC,	NULL,	},
    550 	{ NULL,			0,				NULL,	},
    551 };
    552 
    553 /*
    554  * Class 0x0e.
    555  * Intelligent IO controller.
    556  */
    557 
    558 /* Intelligent IO programming interface */
    559 static const struct pci_class pci_interface_i2o[] = {
    560 	{ "FIFO at offset 0x40", PCI_INTERFACE_I2O_FIFOAT40,	NULL,	},
    561 	{ NULL,			0,				NULL,	},
    562 };
    563 
    564 /* Subclasses */
    565 static const struct pci_class pci_subclass_i2o[] = {
    566 	{ "standard",		PCI_SUBCLASS_I2O_STANDARD, pci_interface_i2o,},
    567 	{ "miscellaneous",	PCI_SUBCLASS_I2O_MISC,		NULL,	},
    568 	{ NULL,			0,				NULL,	},
    569 };
    570 
    571 /*
    572  * Class 0x0f.
    573  * Satellite communication controller.
    574  */
    575 static const struct pci_class pci_subclass_satcom[] = {
    576 	{ "TV",			PCI_SUBCLASS_SATCOM_TV,		NULL,	},
    577 	{ "audio",		PCI_SUBCLASS_SATCOM_AUDIO,	NULL,	},
    578 	{ "voice",		PCI_SUBCLASS_SATCOM_VOICE,	NULL,	},
    579 	{ "data",		PCI_SUBCLASS_SATCOM_DATA,	NULL,	},
    580 	{ "miscellaneous",	PCI_SUBCLASS_SATCOM_MISC,	NULL,	},
    581 	{ NULL,			0,				NULL,	},
    582 };
    583 
    584 /*
    585  * Class 0x10.
    586  * Encryption/Decryption controller.
    587  */
    588 static const struct pci_class pci_subclass_crypto[] = {
    589 	{ "network/computing",	PCI_SUBCLASS_CRYPTO_NETCOMP,	NULL,	},
    590 	{ "entertainment",	PCI_SUBCLASS_CRYPTO_ENTERTAINMENT, NULL,},
    591 	{ "miscellaneous",	PCI_SUBCLASS_CRYPTO_MISC,	NULL,	},
    592 	{ NULL,			0,				NULL,	},
    593 };
    594 
    595 /*
    596  * Class 0x11.
    597  * Data aquuisition and signal processing controller.
    598  */
    599 static const struct pci_class pci_subclass_dasp[] = {
    600 	{ "DPIO",		PCI_SUBCLASS_DASP_DPIO,		NULL,	},
    601 	{ "performance counters", PCI_SUBCLASS_DASP_TIMEFREQ,	NULL,	},
    602 	{ "synchronization",	PCI_SUBCLASS_DASP_SYNC,		NULL,	},
    603 	{ "management",		PCI_SUBCLASS_DASP_MGMT,		NULL,	},
    604 	{ "miscellaneous",	PCI_SUBCLASS_DASP_MISC,		NULL,	},
    605 	{ NULL,			0,				NULL,	},
    606 };
    607 
    608 /* List of classes */
    609 static const struct pci_class pci_classes[] = {
    610 	{ "prehistoric",	PCI_CLASS_PREHISTORIC,
    611 	    pci_subclass_prehistoric,				},
    612 	{ "mass storage",	PCI_CLASS_MASS_STORAGE,
    613 	    pci_subclass_mass_storage,				},
    614 	{ "network",		PCI_CLASS_NETWORK,
    615 	    pci_subclass_network,				},
    616 	{ "display",		PCI_CLASS_DISPLAY,
    617 	    pci_subclass_display,				},
    618 	{ "multimedia",		PCI_CLASS_MULTIMEDIA,
    619 	    pci_subclass_multimedia,				},
    620 	{ "memory",		PCI_CLASS_MEMORY,
    621 	    pci_subclass_memory,				},
    622 	{ "bridge",		PCI_CLASS_BRIDGE,
    623 	    pci_subclass_bridge,				},
    624 	{ "communications",	PCI_CLASS_COMMUNICATIONS,
    625 	    pci_subclass_communications,			},
    626 	{ "system",		PCI_CLASS_SYSTEM,
    627 	    pci_subclass_system,				},
    628 	{ "input",		PCI_CLASS_INPUT,
    629 	    pci_subclass_input,					},
    630 	{ "dock",		PCI_CLASS_DOCK,
    631 	    pci_subclass_dock,					},
    632 	{ "processor",		PCI_CLASS_PROCESSOR,
    633 	    pci_subclass_processor,				},
    634 	{ "serial bus",		PCI_CLASS_SERIALBUS,
    635 	    pci_subclass_serialbus,				},
    636 	{ "wireless",		PCI_CLASS_WIRELESS,
    637 	    pci_subclass_wireless,				},
    638 	{ "I2O",		PCI_CLASS_I2O,
    639 	    pci_subclass_i2o,					},
    640 	{ "satellite comm",	PCI_CLASS_SATCOM,
    641 	    pci_subclass_satcom,				},
    642 	{ "crypto",		PCI_CLASS_CRYPTO,
    643 	    pci_subclass_crypto,				},
    644 	{ "DASP",		PCI_CLASS_DASP,
    645 	    pci_subclass_dasp,					},
    646 	{ "processing accelerators", PCI_CLASS_ACCEL,
    647 	    NULL,						},
    648 	{ "non-essential instrumentation", PCI_CLASS_INSTRUMENT,
    649 	    NULL,						},
    650 	{ "undefined",		PCI_CLASS_UNDEFINED,
    651 	    NULL,						},
    652 	{ NULL,			0,
    653 	    NULL,						},
    654 };
    655 
    656 DEV_VERBOSE_DEFINE(pci);
    657 
    658 /*
    659  * Append a formatted string to dest without writing more than len
    660  * characters (including the trailing NUL character).  dest and len
    661  * are updated for use in subsequent calls to snappendf().
    662  *
    663  * Returns 0 on success, a negative value if vnsprintf() fails, or
    664  * a positive value if the dest buffer would have overflowed.
    665  */
    666 
    667 static int __printflike(3, 4)
    668 snappendf(char **dest, size_t *len, const char * restrict fmt, ...)
    669 {
    670 	va_list	ap;
    671 	int count;
    672 
    673 	va_start(ap, fmt);
    674 	count = vsnprintf(*dest, *len, fmt, ap);
    675 	va_end(ap);
    676 
    677 	/* Let vsnprintf() errors bubble up to caller */
    678 	if (count < 0 || *len == 0)
    679 		return count;
    680 
    681 	/* Handle overflow */
    682 	if ((size_t)count >= *len) {
    683 		*dest += *len - 1;
    684 		*len = 1;
    685 		return 1;
    686 	}
    687 
    688 	/* Update dest & len to point at trailing NUL */
    689 	*dest += count;
    690 	*len -= count;
    691 
    692 	return 0;
    693 }
    694 
    695 void
    696 pci_devinfo(pcireg_t id_reg, pcireg_t class_reg, int showclass, char *cp,
    697     size_t l)
    698 {
    699 	pci_class_t class;
    700 	pci_subclass_t subclass;
    701 	pci_interface_t interface;
    702 	pci_revision_t revision;
    703 	char vendor[PCI_VENDORSTR_LEN], product[PCI_PRODUCTSTR_LEN];
    704 	const struct pci_class *classp, *subclassp, *interfacep;
    705 
    706 	class = PCI_CLASS(class_reg);
    707 	subclass = PCI_SUBCLASS(class_reg);
    708 	interface = PCI_INTERFACE(class_reg);
    709 	revision = PCI_REVISION(class_reg);
    710 
    711 	pci_findvendor(vendor, sizeof(vendor), PCI_VENDOR(id_reg));
    712 	pci_findproduct(product, sizeof(product), PCI_VENDOR(id_reg),
    713 	    PCI_PRODUCT(id_reg));
    714 
    715 	classp = pci_classes;
    716 	while (classp->name != NULL) {
    717 		if (class == classp->val)
    718 			break;
    719 		classp++;
    720 	}
    721 
    722 	subclassp = (classp->name != NULL) ? classp->subclasses : NULL;
    723 	while (subclassp && subclassp->name != NULL) {
    724 		if (subclass == subclassp->val)
    725 			break;
    726 		subclassp++;
    727 	}
    728 
    729 	interfacep = (subclassp && subclassp->name != NULL) ?
    730 	    subclassp->subclasses : NULL;
    731 	while (interfacep && interfacep->name != NULL) {
    732 		if (interface == interfacep->val)
    733 			break;
    734 		interfacep++;
    735 	}
    736 
    737 	(void)snappendf(&cp, &l, "%s %s", vendor, product);
    738 	if (showclass) {
    739 		(void)snappendf(&cp, &l, " (");
    740 		if (classp->name == NULL)
    741 			(void)snappendf(&cp, &l,
    742 			    "class 0x%02x, subclass 0x%02x",
    743 			    class, subclass);
    744 		else {
    745 			if (subclassp == NULL || subclassp->name == NULL)
    746 				(void)snappendf(&cp, &l,
    747 				    "%s, subclass 0x%02x",
    748 				    classp->name, subclass);
    749 			else
    750 				(void)snappendf(&cp, &l, "%s %s",
    751 				    subclassp->name, classp->name);
    752 		}
    753 		if ((interfacep == NULL) || (interfacep->name == NULL)) {
    754 			if (interface != 0)
    755 				(void)snappendf(&cp, &l, ", interface 0x%02x",
    756 				    interface);
    757 		} else if (strncmp(interfacep->name, "", 1) != 0)
    758 			(void)snappendf(&cp, &l, ", %s", interfacep->name);
    759 		if (revision != 0)
    760 			(void)snappendf(&cp, &l, ", revision 0x%02x", revision);
    761 		(void)snappendf(&cp, &l, ")");
    762 	}
    763 }
    764 
    765 #ifdef _KERNEL
    766 void
    767 pci_aprint_devinfo_fancy(const struct pci_attach_args *pa, const char *naive,
    768 			 const char *known, int addrev)
    769 {
    770 	char devinfo[256];
    771 
    772 	if (known) {
    773 		aprint_normal(": %s", known);
    774 		if (addrev)
    775 			aprint_normal(" (rev. 0x%02x)",
    776 				      PCI_REVISION(pa->pa_class));
    777 		aprint_normal("\n");
    778 	} else {
    779 		pci_devinfo(pa->pa_id, pa->pa_class, 0,
    780 			    devinfo, sizeof(devinfo));
    781 		aprint_normal(": %s (rev. 0x%02x)\n", devinfo,
    782 			      PCI_REVISION(pa->pa_class));
    783 	}
    784 	if (naive)
    785 		aprint_naive(": %s\n", naive);
    786 	else
    787 		aprint_naive("\n");
    788 }
    789 #endif
    790 
    791 /*
    792  * Print out most of the PCI configuration registers.  Typically used
    793  * in a device attach routine like this:
    794  *
    795  *	#ifdef MYDEV_DEBUG
    796  *		printf("%s: ", device_xname(sc->sc_dev));
    797  *		pci_conf_print(pa->pa_pc, pa->pa_tag, NULL);
    798  *	#endif
    799  */
    800 
    801 #define	i2o(i)	((i) * 4)
    802 #define	o2i(o)	((o) / 4)
    803 #define	onoff2(str, rval, bit, onstr, offstr)				\
    804 	/*CONSTCOND*/							\
    805 	printf("      %s: %s\n", (str), ((rval) & (bit)) ? onstr : offstr);
    806 #define	onoff(str, rval, bit)	onoff2(str, rval, bit, "on", "off")
    807 
    808 static void
    809 pci_conf_print_common(
    810 #ifdef _KERNEL
    811     pci_chipset_tag_t pc, pcitag_t tag,
    812 #endif
    813     const pcireg_t *regs)
    814 {
    815 	pci_class_t class;
    816 	pci_subclass_t subclass;
    817 	pci_interface_t interface;
    818 	pci_revision_t revision;
    819 	char vendor[PCI_VENDORSTR_LEN], product[PCI_PRODUCTSTR_LEN];
    820 	const struct pci_class *classp, *subclassp, *interfacep;
    821 	const char *name;
    822 	pcireg_t rval;
    823 	unsigned int num;
    824 
    825 	rval = regs[o2i(PCI_CLASS_REG)];
    826 	class = PCI_CLASS(rval);
    827 	subclass = PCI_SUBCLASS(rval);
    828 	interface = PCI_INTERFACE(rval);
    829 	revision = PCI_REVISION(rval);
    830 
    831 	rval = regs[o2i(PCI_ID_REG)];
    832 	name = pci_findvendor(vendor, sizeof(vendor), PCI_VENDOR(rval));
    833 	if (name)
    834 		printf("    Vendor Name: %s (0x%04x)\n", name,
    835 		    PCI_VENDOR(rval));
    836 	else
    837 		printf("    Vendor ID: 0x%04x\n", PCI_VENDOR(rval));
    838 	name = pci_findproduct(product, sizeof(product), PCI_VENDOR(rval),
    839 	    PCI_PRODUCT(rval));
    840 	if (name)
    841 		printf("    Device Name: %s (0x%04x)\n", name,
    842 		    PCI_PRODUCT(rval));
    843 	else
    844 		printf("    Device ID: 0x%04x\n", PCI_PRODUCT(rval));
    845 
    846 	rval = regs[o2i(PCI_COMMAND_STATUS_REG)];
    847 
    848 	printf("    Command register: 0x%04x\n", rval & 0xffff);
    849 	onoff("I/O space accesses", rval, PCI_COMMAND_IO_ENABLE);
    850 	onoff("Memory space accesses", rval, PCI_COMMAND_MEM_ENABLE);
    851 	onoff("Bus mastering", rval, PCI_COMMAND_MASTER_ENABLE);
    852 	onoff("Special cycles", rval, PCI_COMMAND_SPECIAL_ENABLE);
    853 	onoff("MWI transactions", rval, PCI_COMMAND_INVALIDATE_ENABLE);
    854 	onoff("Palette snooping", rval, PCI_COMMAND_PALETTE_ENABLE);
    855 	onoff("Parity error checking", rval, PCI_COMMAND_PARITY_ENABLE);
    856 	onoff("Address/data stepping", rval, PCI_COMMAND_STEPPING_ENABLE);
    857 	onoff("System error (SERR)", rval, PCI_COMMAND_SERR_ENABLE);
    858 	onoff("Fast back-to-back transactions", rval,
    859 	    PCI_COMMAND_BACKTOBACK_ENABLE);
    860 	onoff("Interrupt disable", rval, PCI_COMMAND_INTERRUPT_DISABLE);
    861 
    862 	printf("    Status register: 0x%04x\n", (rval >> 16) & 0xffff);
    863 	onoff("Immediate Readiness", rval, PCI_STATUS_IMMD_READNESS);
    864 	onoff2("Interrupt status", rval, PCI_STATUS_INT_STATUS, "active",
    865 	    "inactive");
    866 	onoff("Capability List support", rval, PCI_STATUS_CAPLIST_SUPPORT);
    867 	onoff("66 MHz capable", rval, PCI_STATUS_66MHZ_SUPPORT);
    868 	onoff("User Definable Features (UDF) support", rval,
    869 	    PCI_STATUS_UDF_SUPPORT);
    870 	onoff("Fast back-to-back capable", rval,
    871 	    PCI_STATUS_BACKTOBACK_SUPPORT);
    872 	onoff("Data parity error detected", rval, PCI_STATUS_PARITY_ERROR);
    873 
    874 	printf("      DEVSEL timing: ");
    875 	switch (rval & PCI_STATUS_DEVSEL_MASK) {
    876 	case PCI_STATUS_DEVSEL_FAST:
    877 		printf("fast");
    878 		break;
    879 	case PCI_STATUS_DEVSEL_MEDIUM:
    880 		printf("medium");
    881 		break;
    882 	case PCI_STATUS_DEVSEL_SLOW:
    883 		printf("slow");
    884 		break;
    885 	default:
    886 		printf("unknown/reserved");	/* XXX */
    887 		break;
    888 	}
    889 	printf(" (0x%x)\n", PCIREG_SHIFTOUT(rval, PCI_STATUS_DEVSEL_MASK));
    890 
    891 	onoff("Slave signaled Target Abort", rval,
    892 	    PCI_STATUS_TARGET_TARGET_ABORT);
    893 	onoff("Master received Target Abort", rval,
    894 	    PCI_STATUS_MASTER_TARGET_ABORT);
    895 	onoff("Master received Master Abort", rval, PCI_STATUS_MASTER_ABORT);
    896 	onoff("Asserted System Error (SERR)", rval, PCI_STATUS_SPECIAL_ERROR);
    897 	onoff("Parity error detected", rval, PCI_STATUS_PARITY_DETECT);
    898 
    899 	rval = regs[o2i(PCI_CLASS_REG)];
    900 	for (classp = pci_classes; classp->name != NULL; classp++) {
    901 		if (class == classp->val)
    902 			break;
    903 	}
    904 
    905 	/*
    906 	 * ECN: Change Root Complex Event Collector Class Code
    907 	 * Old RCEC has subclass 0x06. It's the same as IOMMU. Read the type
    908 	 * in PCIe extend capability to know whether it's RCEC or IOMMU.
    909 	 */
    910 	if ((class == PCI_CLASS_SYSTEM)
    911 	    && (subclass == PCI_SUBCLASS_SYSTEM_IOMMU)) {
    912 		int pcie_capoff;
    913 		pcireg_t reg;
    914 
    915 		if (pci_conf_find_cap(regs, PCI_CAP_PCIEXPRESS, &pcie_capoff)) {
    916 			reg = regs[o2i(pcie_capoff + PCIE_XCAP)];
    917 			if (PCIE_XCAP_TYPE(reg) == PCIE_XCAP_TYPE_RC_EVNTC)
    918 				subclass = PCI_SUBCLASS_SYSTEM_RCEC;
    919 		}
    920 	}
    921 	subclassp = (classp->name != NULL) ? classp->subclasses : NULL;
    922 	while (subclassp && subclassp->name != NULL) {
    923 		if (subclass == subclassp->val)
    924 			break;
    925 		subclassp++;
    926 	}
    927 
    928 	interfacep = (subclassp && subclassp->name != NULL) ?
    929 	    subclassp->subclasses : NULL;
    930 	while (interfacep && interfacep->name != NULL) {
    931 		if (interface == interfacep->val)
    932 			break;
    933 		interfacep++;
    934 	}
    935 
    936 	if (classp->name != NULL)
    937 		printf("    Class Name: %s (0x%02x)\n", classp->name, class);
    938 	else
    939 		printf("    Class ID: 0x%02x\n", class);
    940 	if (subclassp != NULL && subclassp->name != NULL)
    941 		printf("    Subclass Name: %s (0x%02x)\n",
    942 		    subclassp->name, PCI_SUBCLASS(rval));
    943 	else
    944 		printf("    Subclass ID: 0x%02x\n", PCI_SUBCLASS(rval));
    945 	if ((interfacep != NULL) && (interfacep->name != NULL)
    946 	    && (strncmp(interfacep->name, "", 1) != 0))
    947 		printf("    Interface Name: %s (0x%02x)\n",
    948 		    interfacep->name, interface);
    949 	else
    950 		printf("    Interface: 0x%02x\n", interface);
    951 	printf("    Revision ID: 0x%02x\n", revision);
    952 
    953 	rval = regs[o2i(PCI_BHLC_REG)];
    954 	printf("    BIST: 0x%02x\n", PCI_BIST(rval));
    955 	printf("    Header Type: 0x%02x%s (0x%02x)\n", PCI_HDRTYPE_TYPE(rval),
    956 	    PCI_HDRTYPE_MULTIFN(rval) ? "+multifunction" : "",
    957 	    PCI_HDRTYPE(rval));
    958 	printf("    Latency Timer: 0x%02x\n", PCI_LATTIMER(rval));
    959 	num = PCI_CACHELINE(rval);
    960 	printf("    Cache Line Size: %ubytes (0x%02x)\n", num * 4, num);
    961 }
    962 
    963 static int
    964 pci_conf_print_bar(
    965 #ifdef _KERNEL
    966     pci_chipset_tag_t pc, pcitag_t tag,
    967 #endif
    968     const pcireg_t *regs, int reg, const char *name)
    969 {
    970 	int width;
    971 	pcireg_t rval, rval64h;
    972 	bool ioen, memen;
    973 #ifdef _KERNEL
    974 	pcireg_t mask, mask64h = 0;
    975 #endif
    976 
    977 	rval = regs[o2i(PCI_COMMAND_STATUS_REG)];
    978 	ioen = rval & PCI_COMMAND_IO_ENABLE;
    979 	memen = rval & PCI_COMMAND_MEM_ENABLE;
    980 
    981 	width = 4;
    982 	/*
    983 	 * Section 6.2.5.1, `Address Maps', tells us that:
    984 	 *
    985 	 * 1) The builtin software should have already mapped the
    986 	 * device in a reasonable way.
    987 	 *
    988 	 * 2) A device which wants 2^n bytes of memory will hardwire
    989 	 * the bottom n bits of the address to 0.  As recommended,
    990 	 * we write all 1s and see what we get back.
    991 	 */
    992 
    993 	rval = regs[o2i(reg)];
    994 	if (PCI_MAPREG_TYPE(rval) == PCI_MAPREG_TYPE_MEM &&
    995 	    PCI_MAPREG_MEM_TYPE(rval) == PCI_MAPREG_MEM_TYPE_64BIT) {
    996 		rval64h = regs[o2i(reg + 4)];
    997 		width = 8;
    998 	} else
    999 		rval64h = 0;
   1000 
   1001 #ifdef _KERNEL
   1002 	if (rval != 0 && memen) {
   1003 		int s;
   1004 
   1005 		/*
   1006 		 * The following sequence seems to make some devices
   1007 		 * (e.g. host bus bridges, which don't normally
   1008 		 * have their space mapped) very unhappy, to
   1009 		 * the point of crashing the system.
   1010 		 *
   1011 		 * Therefore, if the mapping register is zero to
   1012 		 * start out with, don't bother trying.
   1013 		 */
   1014 		s = splhigh();
   1015 		pci_conf_write(pc, tag, reg, 0xffffffff);
   1016 		mask = pci_conf_read(pc, tag, reg);
   1017 		pci_conf_write(pc, tag, reg, rval);
   1018 		if (PCI_MAPREG_TYPE(rval) == PCI_MAPREG_TYPE_MEM &&
   1019 		    PCI_MAPREG_MEM_TYPE(rval) == PCI_MAPREG_MEM_TYPE_64BIT) {
   1020 			pci_conf_write(pc, tag, reg + 4, 0xffffffff);
   1021 			mask64h = pci_conf_read(pc, tag, reg + 4);
   1022 			pci_conf_write(pc, tag, reg + 4, rval64h);
   1023 		}
   1024 		splx(s);
   1025 	} else
   1026 		mask = mask64h = 0;
   1027 #endif /* _KERNEL */
   1028 
   1029 	printf("    Base address register at 0x%02x", reg);
   1030 	if (name)
   1031 		printf(" (%s)", name);
   1032 	printf("\n      ");
   1033 	if (rval == 0) {
   1034 		printf("not implemented\n");
   1035 		return width;
   1036 	}
   1037 	printf("type: ");
   1038 	if (PCI_MAPREG_TYPE(rval) == PCI_MAPREG_TYPE_MEM) {
   1039 		const char *type, *prefetch;
   1040 
   1041 		switch (PCI_MAPREG_MEM_TYPE(rval)) {
   1042 		case PCI_MAPREG_MEM_TYPE_32BIT:
   1043 			type = "32-bit";
   1044 			break;
   1045 		case PCI_MAPREG_MEM_TYPE_32BIT_1M:
   1046 			type = "32-bit-1M";
   1047 			break;
   1048 		case PCI_MAPREG_MEM_TYPE_64BIT:
   1049 			type = "64-bit";
   1050 			break;
   1051 		default:
   1052 			type = "unknown (XXX)";
   1053 			break;
   1054 		}
   1055 		if (PCI_MAPREG_MEM_PREFETCHABLE(rval))
   1056 			prefetch = "";
   1057 		else
   1058 			prefetch = "non";
   1059 		printf("%s %sprefetchable memory\n", type, prefetch);
   1060 		switch (PCI_MAPREG_MEM_TYPE(rval)) {
   1061 		case PCI_MAPREG_MEM_TYPE_64BIT:
   1062 			printf("      base: 0x%016llx",
   1063 			    PCI_MAPREG_MEM64_ADDR(
   1064 				((((long long) rval64h) << 32) | rval)));
   1065 			if (!memen)
   1066 				printf(", disabled");
   1067 			printf("\n");
   1068 #ifdef _KERNEL
   1069 			printf("      size: 0x%016llx\n",
   1070 			    PCI_MAPREG_MEM64_SIZE(
   1071 				    ((((long long) mask64h) << 32) | mask)));
   1072 #endif
   1073 			break;
   1074 		case PCI_MAPREG_MEM_TYPE_32BIT:
   1075 		case PCI_MAPREG_MEM_TYPE_32BIT_1M:
   1076 		default:
   1077 			printf("      base: 0x%08x",
   1078 			    PCI_MAPREG_MEM_ADDR(rval));
   1079 			if (!memen)
   1080 				printf(", disabled");
   1081 			printf("\n");
   1082 #ifdef _KERNEL
   1083 			printf("      size: 0x%08x\n",
   1084 			    PCI_MAPREG_MEM_SIZE(mask));
   1085 #endif
   1086 			break;
   1087 		}
   1088 	} else {
   1089 #ifdef _KERNEL
   1090 		if (ioen)
   1091 			printf("%d-bit ", mask & ~0x0000ffff ? 32 : 16);
   1092 #endif
   1093 		printf("I/O\n");
   1094 		printf("      base: 0x%08x", PCI_MAPREG_IO_ADDR(rval));
   1095 		if (!ioen)
   1096 			printf(", disabled");
   1097 		printf("\n");
   1098 #ifdef _KERNEL
   1099 		printf("      size: 0x%08x\n", PCI_MAPREG_IO_SIZE(mask));
   1100 #endif
   1101 	}
   1102 
   1103 	return width;
   1104 }
   1105 
   1106 static void
   1107 pci_conf_print_regs(const pcireg_t *regs, int first, int pastlast)
   1108 {
   1109 	int off, needaddr, neednl;
   1110 
   1111 	needaddr = 1;
   1112 	neednl = 0;
   1113 	for (off = first; off < pastlast; off += 4) {
   1114 		if ((off % 16) == 0 || needaddr) {
   1115 			printf("    0x%02x:", off);
   1116 			needaddr = 0;
   1117 		}
   1118 		printf(" 0x%08x", regs[o2i(off)]);
   1119 		neednl = 1;
   1120 		if ((off % 16) == 12) {
   1121 			printf("\n");
   1122 			neednl = 0;
   1123 		}
   1124 	}
   1125 	if (neednl)
   1126 		printf("\n");
   1127 }
   1128 
   1129 static const char *
   1130 pci_conf_print_agp_calcycle(uint8_t cal)
   1131 {
   1132 
   1133 	switch (cal) {
   1134 	case 0x0:
   1135 		return "4ms";
   1136 	case 0x1:
   1137 		return "16ms";
   1138 	case 0x2:
   1139 		return "64ms";
   1140 	case 0x3:
   1141 		return "256ms";
   1142 	case 0x7:
   1143 		return "Calibration Cycle Not Needed";
   1144 	default:
   1145 		return "(reserved)";
   1146 	}
   1147 }
   1148 
   1149 static void
   1150 pci_conf_print_agp_datarate(pcireg_t reg, bool isagp3)
   1151 {
   1152 	if (isagp3) {
   1153 		/* AGP 3.0 */
   1154 		if (reg & AGP_MODE_V3_RATE_4x)
   1155 			printf("x4");
   1156 		if (reg & AGP_MODE_V3_RATE_8x)
   1157 			printf("x8");
   1158 	} else {
   1159 		/* AGP 2.0 */
   1160 		if (reg & AGP_MODE_V2_RATE_1x)
   1161 			printf("x1");
   1162 		if (reg & AGP_MODE_V2_RATE_2x)
   1163 			printf("x2");
   1164 		if (reg & AGP_MODE_V2_RATE_4x)
   1165 			printf("x4");
   1166 	}
   1167 	printf("\n");
   1168 }
   1169 
   1170 static void
   1171 pci_conf_print_agp_cap(const pcireg_t *regs, int capoff)
   1172 {
   1173 	pcireg_t rval;
   1174 	bool isagp3;
   1175 
   1176 	printf("\n  AGP Capabilities Register\n");
   1177 
   1178 	rval = regs[o2i(capoff)];
   1179 	printf("    Revision: %d.%d\n",
   1180 	    PCI_CAP_AGP_MAJOR(rval), PCI_CAP_AGP_MINOR(rval));
   1181 
   1182 	rval = regs[o2i(capoff + PCI_AGP_STATUS)];
   1183 	printf("    Status register: 0x%04x\n", rval);
   1184 	printf("      RQ: %u\n",
   1185 	    PCIREG_SHIFTOUT(rval, AGP_MODE_RQ) + 1);
   1186 	printf("      ARQSZ: %u\n",
   1187 	    PCIREG_SHIFTOUT(rval, AGP_MODE_ARQSZ));
   1188 	printf("      CAL cycle: %s\n",
   1189 	       pci_conf_print_agp_calcycle(PCIREG_SHIFTOUT(rval, AGP_MODE_CAL)));
   1190 	onoff("SBA", rval, AGP_MODE_SBA);
   1191 	onoff("htrans#", rval, AGP_MODE_HTRANS);
   1192 	onoff("Over 4G", rval, AGP_MODE_4G);
   1193 	onoff("Fast Write", rval, AGP_MODE_FW);
   1194 	onoff("AGP 3.0 Mode", rval, AGP_MODE_MODE_3);
   1195 	isagp3 = rval & AGP_MODE_MODE_3;
   1196 	printf("      Data Rate Support: ");
   1197 	pci_conf_print_agp_datarate(rval, isagp3);
   1198 
   1199 	rval = regs[o2i(capoff + PCI_AGP_COMMAND)];
   1200 	printf("    Command register: 0x%08x\n", rval);
   1201 	printf("      PRQ: %u\n",
   1202 	    PCIREG_SHIFTOUT(rval, AGP_MODE_RQ) + 1);
   1203 	printf("      PARQSZ: %u\n",
   1204 	    PCIREG_SHIFTOUT(rval, AGP_MODE_ARQSZ));
   1205 	printf("      PCAL cycle: %s\n",
   1206 	       pci_conf_print_agp_calcycle(PCIREG_SHIFTOUT(rval, AGP_MODE_CAL)));
   1207 	onoff("SBA", rval, AGP_MODE_SBA);
   1208 	onoff("AGP", rval, AGP_MODE_AGP);
   1209 	onoff("Over 4G", rval, AGP_MODE_4G);
   1210 	onoff("Fast Write", rval, AGP_MODE_FW);
   1211 	if (isagp3) {
   1212 		printf("      Data Rate Enable: ");
   1213 		/*
   1214 		 * The Data Rate Enable bits are used only on 3.0 and the
   1215 		 * Command register has no AGP_MODE_MODE_3 bit, so pass the
   1216 		 * flag to print correctly.
   1217 		 */
   1218 		pci_conf_print_agp_datarate(rval, isagp3);
   1219 	}
   1220 }
   1221 
   1222 static const char *
   1223 pci_conf_print_pcipm_cap_aux(uint16_t caps)
   1224 {
   1225 
   1226 	switch ((caps >> 6) & 7) {
   1227 	case 0:	return "self-powered";
   1228 	case 1: return "55 mA";
   1229 	case 2: return "100 mA";
   1230 	case 3: return "160 mA";
   1231 	case 4: return "220 mA";
   1232 	case 5: return "270 mA";
   1233 	case 6: return "320 mA";
   1234 	case 7:
   1235 	default: return "375 mA";
   1236 	}
   1237 }
   1238 
   1239 static const char *
   1240 pci_conf_print_pcipm_cap_pmrev(uint8_t val)
   1241 {
   1242 	static const char unk[] = "unknown";
   1243 	static const char *pmrev[8] = {
   1244 		unk, "1.0", "1.1", "1.2", unk, unk, unk, unk
   1245 	};
   1246 	if (val > 7)
   1247 		return unk;
   1248 	return pmrev[val];
   1249 }
   1250 
   1251 static void
   1252 pci_conf_print_pcipm_cap(const pcireg_t *regs, int capoff)
   1253 {
   1254 	uint16_t caps, pmcsr;
   1255 
   1256 	caps = regs[o2i(capoff)] >> PCI_PMCR_SHIFT;
   1257 	pmcsr = regs[o2i(capoff + PCI_PMCSR)];
   1258 
   1259 	printf("\n  PCI Power Management Capabilities Register\n");
   1260 
   1261 	printf("    Capabilities register: 0x%04x\n", caps);
   1262 	printf("      Version: %s\n",
   1263 	    pci_conf_print_pcipm_cap_pmrev(caps & PCI_PMCR_VERSION_MASK));
   1264 	onoff("PME# clock", caps, PCI_PMCR_PME_CLOCK);
   1265 	onoff("Device specific initialization", caps, PCI_PMCR_DSI);
   1266 	printf("      3.3V auxiliary current: %s\n",
   1267 	    pci_conf_print_pcipm_cap_aux(caps));
   1268 	onoff("D1 power management state support", caps, PCI_PMCR_D1SUPP);
   1269 	onoff("D2 power management state support", caps, PCI_PMCR_D2SUPP);
   1270 	onoff("PME# support D0", caps, PCI_PMCR_PME_D0);
   1271 	onoff("PME# support D1", caps, PCI_PMCR_PME_D1);
   1272 	onoff("PME# support D2", caps, PCI_PMCR_PME_D2);
   1273 	onoff("PME# support D3 hot", caps, PCI_PMCR_PME_D3HOT);
   1274 	onoff("PME# support D3 cold", caps, PCI_PMCR_PME_D3COLD);
   1275 
   1276 	printf("    Control/status register: 0x%08x\n", pmcsr);
   1277 	printf("      Power state: D%d\n", pmcsr & PCI_PMCSR_STATE_MASK);
   1278 	onoff("PCI Express reserved", (pmcsr >> 2), 1);
   1279 	onoff("No soft reset", pmcsr, PCI_PMCSR_NO_SOFTRST);
   1280 	printf("      PME# assertion: %sabled\n",
   1281 	    (pmcsr & PCI_PMCSR_PME_EN) ? "en" : "dis");
   1282 	printf("      Data Select: %d\n",
   1283 	    PCIREG_SHIFTOUT(pmcsr, PCI_PMCSR_DATASEL_MASK));
   1284 	printf("      Data Scale: %d\n",
   1285 	    PCIREG_SHIFTOUT(pmcsr, PCI_PMCSR_DATASCL_MASK));
   1286 	onoff("PME# status", pmcsr, PCI_PMCSR_PME_STS);
   1287 	printf("    Bridge Support Extensions register: 0x%02x\n",
   1288 	    (pmcsr >> 16) & 0xff);
   1289 	onoff("B2/B3 support", pmcsr, PCI_PMCSR_B2B3_SUPPORT);
   1290 	onoff("Bus Power/Clock Control Enable", pmcsr, PCI_PMCSR_BPCC_EN);
   1291 	printf("    Data register: 0x%02x\n",
   1292 	       PCIREG_SHIFTOUT(pmcsr, PCI_PMCSR_DATA));
   1293 }
   1294 
   1295 /* XXX pci_conf_print_vpd_cap */
   1296 /* XXX pci_conf_print_slotid_cap */
   1297 
   1298 static void
   1299 pci_conf_print_msi_cap(const pcireg_t *regs, int capoff)
   1300 {
   1301 	uint32_t ctl, mmc, mme;
   1302 
   1303 	regs += o2i(capoff);
   1304 	ctl = *regs++;
   1305 	mmc = PCIREG_SHIFTOUT(ctl, PCI_MSI_CTL_MMC_MASK);
   1306 	mme = PCIREG_SHIFTOUT(ctl, PCI_MSI_CTL_MME_MASK);
   1307 
   1308 	printf("\n  PCI Message Signaled Interrupt\n");
   1309 
   1310 	printf("    Message Control register: 0x%04x\n", ctl >> 16);
   1311 	onoff("MSI Enabled", ctl, PCI_MSI_CTL_MSI_ENABLE);
   1312 	printf("      Multiple Message Capable: %s (%d vector%s)\n",
   1313 	    mmc > 0 ? "yes" : "no", 1 << mmc, mmc > 0 ? "s" : "");
   1314 	printf("      Multiple Message Enabled: %s (%d vector%s)\n",
   1315 	    mme > 0 ? "on" : "off", 1 << mme, mme > 0 ? "s" : "");
   1316 	onoff("64 Bit Address Capable", ctl, PCI_MSI_CTL_64BIT_ADDR);
   1317 	onoff("Per-Vector Masking Capable", ctl, PCI_MSI_CTL_PERVEC_MASK);
   1318 	onoff("Extended Message Data Capable", ctl, PCI_MSI_CTL_EXTMDATA_CAP);
   1319 	onoff("Extended Message Data Enable", ctl, PCI_MSI_CTL_EXTMDATA_EN);
   1320 	printf("    Message Address %sregister: 0x%08x\n",
   1321 	    ctl & PCI_MSI_CTL_64BIT_ADDR ? "(lower) " : "", *regs++);
   1322 	if (ctl & PCI_MSI_CTL_64BIT_ADDR) {
   1323 		printf("    Message Address %sregister: 0x%08x\n",
   1324 		    "(upper) ", *regs++);
   1325 	}
   1326 	printf("    Message Data register: ");
   1327 	if (ctl & PCI_MSI_CTL_EXTMDATA_CAP)
   1328 		printf("0x%08x\n", *regs);
   1329 	else
   1330 		printf("0x%04x\n", *regs & 0xffff);
   1331 	regs++;
   1332 	if (ctl & PCI_MSI_CTL_PERVEC_MASK) {
   1333 		printf("    Vector Mask register: 0x%08x\n", *regs++);
   1334 		printf("    Vector Pending register: 0x%08x\n", *regs++);
   1335 	}
   1336 }
   1337 
   1338 /* XXX pci_conf_print_cpci_hostwap_cap */
   1339 
   1340 /*
   1341  * For both command register and status register.
   1342  * The argument "idx" is index number (0 to 7).
   1343  */
   1344 static int
   1345 pcix_split_trans(unsigned int idx)
   1346 {
   1347 	static int table[8] = {
   1348 		1, 2, 3, 4, 8, 12, 16, 32
   1349 	};
   1350 
   1351 	if (idx >= __arraycount(table))
   1352 		return -1;
   1353 	return table[idx];
   1354 }
   1355 
   1356 static void
   1357 pci_conf_print_pcix_cap_2ndbusmode(int num)
   1358 {
   1359 	const char *maxfreq, *maxperiod;
   1360 
   1361 	printf("      Mode: ");
   1362 	if (num <= 0x07)
   1363 		printf("PCI-X Mode 1\n");
   1364 	else if (num <= 0x0b)
   1365 		printf("PCI-X 266 (Mode 2)\n");
   1366 	else
   1367 		printf("PCI-X 533 (Mode 2)\n");
   1368 
   1369 	printf("      Error protection: %s\n", (num <= 3) ? "parity" : "ECC");
   1370 	switch (num & 0x03) {
   1371 	default:
   1372 	case 0:
   1373 		maxfreq = "N/A";
   1374 		maxperiod = "N/A";
   1375 		break;
   1376 	case 1:
   1377 		maxfreq = "66MHz";
   1378 		maxperiod = "15ns";
   1379 		break;
   1380 	case 2:
   1381 		maxfreq = "100MHz";
   1382 		maxperiod = "10ns";
   1383 		break;
   1384 	case 3:
   1385 		maxfreq = "133MHz";
   1386 		maxperiod = "7.5ns";
   1387 		break;
   1388 	}
   1389 	printf("      Max Clock Freq: %s\n", maxfreq);
   1390 	printf("      Min Clock Period: %s\n", maxperiod);
   1391 }
   1392 
   1393 static void
   1394 pci_conf_print_pcix_cap(const pcireg_t *regs, int capoff)
   1395 {
   1396 	pcireg_t reg;
   1397 	int isbridge;
   1398 	int i;
   1399 
   1400 	isbridge = (PCI_HDRTYPE_TYPE(regs[o2i(PCI_BHLC_REG)])
   1401 	    & PCI_HDRTYPE_PPB) != 0 ? 1 : 0;
   1402 	printf("\n  PCI-X %s Capabilities Register\n",
   1403 	    isbridge ? "Bridge" : "Non-bridge");
   1404 
   1405 	reg = regs[o2i(capoff)];
   1406 	if (isbridge != 0) {
   1407 		printf("    Secondary status register: 0x%04x\n",
   1408 		    (reg & 0xffff0000) >> 16);
   1409 		onoff("64bit device", reg, PCIX_STATUS_64BIT);
   1410 		onoff("133MHz capable", reg, PCIX_STATUS_133);
   1411 		onoff("Split completion discarded", reg, PCIX_STATUS_SPLDISC);
   1412 		onoff("Unexpected split completion", reg, PCIX_STATUS_SPLUNEX);
   1413 		onoff("Split completion overrun", reg, PCIX_BRIDGE_ST_SPLOVRN);
   1414 		onoff("Split request delayed", reg, PCIX_BRIDGE_ST_SPLRQDL);
   1415 		pci_conf_print_pcix_cap_2ndbusmode(
   1416 			PCIREG_SHIFTOUT(reg, PCIX_BRIDGE_2NDST_CLKF));
   1417 		printf("      Version: 0x%x\n",
   1418 		    (reg & PCIX_BRIDGE_2NDST_VER_MASK)
   1419 		    >> PCIX_BRIDGE_2NDST_VER_SHIFT);
   1420 		onoff("266MHz capable", reg, PCIX_BRIDGE_ST_266);
   1421 		onoff("533MHz capable", reg, PCIX_BRIDGE_ST_533);
   1422 	} else {
   1423 		printf("    Command register: 0x%04x\n",
   1424 		    (reg & 0xffff0000) >> 16);
   1425 		onoff("Data Parity Error Recovery", reg,
   1426 		    PCIX_CMD_PERR_RECOVER);
   1427 		onoff("Enable Relaxed Ordering", reg, PCIX_CMD_RELAXED_ORDER);
   1428 		printf("      Maximum Burst Read Count: %u\n",
   1429 		    PCIX_CMD_BYTECNT(reg));
   1430 		printf("      Maximum Split Transactions: %d\n",
   1431 		    pcix_split_trans((reg & PCIX_CMD_SPLTRANS_MASK)
   1432 			>> PCIX_CMD_SPLTRANS_SHIFT));
   1433 	}
   1434 	reg = regs[o2i(capoff+PCIX_STATUS)]; /* Or PCIX_BRIDGE_PRI_STATUS */
   1435 	printf("    %sStatus register: 0x%08x\n",
   1436 	    isbridge ? "Bridge " : "", reg);
   1437 	printf("      Function: %d\n", PCIX_STATUS_FN(reg));
   1438 	printf("      Device: %d\n", PCIX_STATUS_DEV(reg));
   1439 	printf("      Bus: %d\n", PCIX_STATUS_BUS(reg));
   1440 	onoff("64bit device", reg, PCIX_STATUS_64BIT);
   1441 	onoff("133MHz capable", reg, PCIX_STATUS_133);
   1442 	onoff("Split completion discarded", reg, PCIX_STATUS_SPLDISC);
   1443 	onoff("Unexpected split completion", reg, PCIX_STATUS_SPLUNEX);
   1444 	if (isbridge != 0) {
   1445 		onoff("Split completion overrun", reg, PCIX_BRIDGE_ST_SPLOVRN);
   1446 		onoff("Split request delayed", reg, PCIX_BRIDGE_ST_SPLRQDL);
   1447 	} else {
   1448 		onoff2("Device Complexity", reg, PCIX_STATUS_DEVCPLX,
   1449 		    "bridge device", "simple device");
   1450 		printf("      Designed max memory read byte count: %d\n",
   1451 		    512 << ((reg & PCIX_STATUS_MAXB_MASK)
   1452 			>> PCIX_STATUS_MAXB_SHIFT));
   1453 		printf("      Designed max outstanding split transaction: %d\n",
   1454 		    pcix_split_trans((reg & PCIX_STATUS_MAXST_MASK)
   1455 			>> PCIX_STATUS_MAXST_SHIFT));
   1456 		printf("      MAX cumulative Read Size: %u\n",
   1457 		    8 << ((reg & 0x1c000000) >> PCIX_STATUS_MAXRS_SHIFT));
   1458 		onoff("Received split completion error", reg,
   1459 		    PCIX_STATUS_SCERR);
   1460 	}
   1461 	onoff("266MHz capable", reg, PCIX_STATUS_266);
   1462 	onoff("533MHz capable", reg, PCIX_STATUS_533);
   1463 
   1464 	if (isbridge == 0)
   1465 		return;
   1466 
   1467 	/* Only for bridge */
   1468 	for (i = 0; i < 2; i++) {
   1469 		reg = regs[o2i(capoff + PCIX_BRIDGE_UP_STCR + (4 * i))];
   1470 		printf("    %s split transaction control register: 0x%08x\n",
   1471 		    (i == 0) ? "Upstream" : "Downstream", reg);
   1472 		printf("      Capacity: %d\n", reg & PCIX_BRIDGE_STCAP);
   1473 		printf("      Commitment Limit: %d\n",
   1474 		    (reg & PCIX_BRIDGE_STCLIM) >> PCIX_BRIDGE_STCLIM_SHIFT);
   1475 	}
   1476 }
   1477 
   1478 /* pci_conf_print_ht_slave_cap */
   1479 /* pci_conf_print_ht_host_cap */
   1480 /* pci_conf_print_ht_switch_cap */
   1481 /* pci_conf_print_ht_intr_cap */
   1482 /* pci_conf_print_ht_revid_cap */
   1483 /* pci_conf_print_ht_unitid_cap */
   1484 /* pci_conf_print_ht_extcnf_cap */
   1485 /* pci_conf_print_ht_addrmap_cap */
   1486 /* pci_conf_print_ht_msimap_cap */
   1487 
   1488 static void
   1489 pci_conf_print_ht_msimap_cap(const pcireg_t *regs, int capoff)
   1490 {
   1491 	pcireg_t val;
   1492 	uint32_t lo, hi;
   1493 
   1494 	/*
   1495 	 * Print the rest of the command register bits. Others are
   1496 	 * printed in pci_conf_print_ht_cap().
   1497 	 */
   1498 	val = regs[o2i(capoff + PCI_HT_CMD)];
   1499 	onoff("Enable", val, PCI_HT_MSI_ENABLED);
   1500 	onoff("Fixed", val, PCI_HT_MSI_FIXED);
   1501 
   1502 	lo = regs[o2i(capoff + PCI_HT_MSI_ADDR_LO)];
   1503 	hi = regs[o2i(capoff + PCI_HT_MSI_ADDR_HI)];
   1504 	printf("    Address Low register: 0x%08x\n", lo);
   1505 	printf("    Address high register: 0x%08x\n", hi);
   1506 	printf("      Address: 0x%016" PRIx64 "\n",
   1507 	    (uint64_t)hi << 32 | (lo & PCI_HT_MSI_ADDR_LO_MASK));
   1508 }
   1509 
   1510 /* pci_conf_print_ht_droute_cap */
   1511 /* pci_conf_print_ht_vcset_cap */
   1512 /* pci_conf_print_ht_retry_cap */
   1513 /* pci_conf_print_ht_x86enc_cap */
   1514 /* pci_conf_print_ht_gen3_cap */
   1515 /* pci_conf_print_ht_fle_cap */
   1516 /* pci_conf_print_ht_pm_cap */
   1517 /* pci_conf_print_ht_hnc_cap */
   1518 
   1519 static const struct ht_types {
   1520 	pcireg_t cap;
   1521 	const char *name;
   1522 	void (*printfunc)(const pcireg_t *, int);
   1523 } ht_captab[] = {
   1524 	{PCI_HT_CAP_SLAVE,	"Slave or Primary Interface", NULL },
   1525 	{PCI_HT_CAP_HOST,	"Host or Secondary Interface", NULL },
   1526 	{PCI_HT_CAP_SWITCH,	"Switch", NULL },
   1527 	{PCI_HT_CAP_INTERRUPT,	"Interrupt Discovery and Configuration", NULL},
   1528 	{PCI_HT_CAP_REVID,	"Revision ID",	NULL },
   1529 	{PCI_HT_CAP_UNITID_CLUMP, "UnitID Clumping",	NULL },
   1530 	{PCI_HT_CAP_EXTCNFSPACE, "Extended Configuration Space Access",	NULL },
   1531 	{PCI_HT_CAP_ADDRMAP,	"Address Mapping",	NULL },
   1532 	{PCI_HT_CAP_MSIMAP,	"MSI Mapping",	pci_conf_print_ht_msimap_cap },
   1533 	{PCI_HT_CAP_DIRECTROUTE, "Direct Route",	NULL },
   1534 	{PCI_HT_CAP_VCSET,	"VCSet",	NULL },
   1535 	{PCI_HT_CAP_RETRYMODE,	"Retry Mode",	NULL },
   1536 	{PCI_HT_CAP_X86ENCODE,	"X86 Encoding",	NULL },
   1537 	{PCI_HT_CAP_GEN3,	"Gen3",	NULL },
   1538 	{PCI_HT_CAP_FLE,	"Function-Level Extension",	NULL },
   1539 	{PCI_HT_CAP_PM,		"Power Management",	NULL },
   1540 	{PCI_HT_CAP_HIGHNODECNT, "High Node Count",	NULL },
   1541 };
   1542 
   1543 static void
   1544 pci_conf_print_ht_cap(const pcireg_t *regs, int capoff)
   1545 {
   1546 	pcireg_t val, foundcap;
   1547 	unsigned int off;
   1548 
   1549 	val = regs[o2i(capoff + PCI_HT_CMD)];
   1550 
   1551 	printf("\n  HyperTransport Capability Register at 0x%02x\n", capoff);
   1552 
   1553 	printf("    Command register: 0x%04x\n", val >> 16);
   1554 	foundcap = PCI_HT_CAP(val);
   1555 	for (off = 0; off < __arraycount(ht_captab); off++) {
   1556 		if (ht_captab[off].cap == foundcap)
   1557 			break;
   1558 	}
   1559 	printf("      Capability Type: 0x%02x ", foundcap);
   1560 	if (off >= __arraycount(ht_captab)) {
   1561 		printf("(unknown)\n");
   1562 		return;
   1563 	}
   1564 	printf("(%s)\n", ht_captab[off].name);
   1565 	if (ht_captab[off].printfunc != NULL)
   1566 		ht_captab[off].printfunc(regs, capoff);
   1567 }
   1568 
   1569 static void
   1570 pci_conf_print_vendspec_cap(const pcireg_t *regs, int capoff)
   1571 {
   1572 	uint16_t caps;
   1573 
   1574 	caps = regs[o2i(capoff)] >> PCI_VENDORSPECIFIC_SHIFT;
   1575 
   1576 	printf("\n  PCI Vendor Specific Capabilities Register\n");
   1577 	printf("    Capabilities length: 0x%02x\n", caps & 0xff);
   1578 }
   1579 
   1580 static void
   1581 pci_conf_print_debugport_cap(const pcireg_t *regs, int capoff)
   1582 {
   1583 	pcireg_t val;
   1584 
   1585 	val = regs[o2i(capoff + PCI_DEBUG_BASER)];
   1586 
   1587 	printf("\n  Debugport Capability Register\n");
   1588 	printf("    Debug base Register: 0x%04x\n",
   1589 	    val >> PCI_DEBUG_BASER_SHIFT);
   1590 	printf("      port offset: 0x%04x\n",
   1591 	    (val & PCI_DEBUG_PORTOFF_MASK) >> PCI_DEBUG_PORTOFF_SHIFT);
   1592 	printf("      BAR number: %u\n",
   1593 	    (val & PCI_DEBUG_BARNUM_MASK) >> PCI_DEBUG_BARNUM_SHIFT);
   1594 }
   1595 
   1596 /* XXX pci_conf_print_cpci_rsrcctl_cap */
   1597 /* XXX pci_conf_print_hotplug_cap */
   1598 
   1599 static void
   1600 pci_conf_print_subsystem_cap(const pcireg_t *regs, int capoff)
   1601 {
   1602 	pcireg_t reg;
   1603 
   1604 	reg = regs[o2i(capoff + PCI_CAP_SUBSYS_ID)];
   1605 
   1606 	printf("\n  Subsystem ID Capability Register\n");
   1607 	printf("    Subsystem ID: 0x%08x\n", reg);
   1608 }
   1609 
   1610 /* XXX pci_conf_print_agp8_cap */
   1611 static void
   1612 pci_conf_print_secure_cap(const pcireg_t *regs, int capoff)
   1613 {
   1614 	pcireg_t reg, reg2, val;
   1615 	bool havemisc1;
   1616 
   1617 	printf("\n  Secure Capability Register\n");
   1618 	reg = regs[o2i(capoff + PCI_SECURE_CAP)];
   1619 	printf("    Capability Register: 0x%04x\n", reg >> 16);
   1620 	val = PCIREG_SHIFTOUT(reg, PCI_SECURE_CAP_TYPE);
   1621 	printf("      Capability block type: ");
   1622 	/* I know IOMMU Only */
   1623 	if (val == PCI_SECURE_CAP_TYPE_IOMMU)
   1624 		printf("IOMMU\n");
   1625 	else {
   1626 		printf("0x%x(unknown)\n", val);
   1627 		return;
   1628 	}
   1629 
   1630 	val = PCIREG_SHIFTOUT(reg, PCI_SECURE_CAP_REV);
   1631 	printf("      Capability revision: 0x%02x ", val);
   1632 	if (val == PCI_SECURE_CAP_REV_IOMMU)
   1633 		printf("(IOMMU)\n");
   1634 	else {
   1635 		printf("(unknown)\n");
   1636 		return;
   1637 	}
   1638 	onoff("IOTLB support", reg, PCI_SECURE_CAP_IOTLBSUP);
   1639 	onoff("HyperTransport tunnel translation support", reg,
   1640 	    PCI_SECURE_CAP_HTTUNNEL);
   1641 	onoff("Not present table entries cached", reg, PCI_SECURE_CAP_NPCACHE);
   1642 	onoff("IOMMU Extended Feature Register support", reg,
   1643 	    PCI_SECURE_CAP_EFRSUP);
   1644 	onoff("IOMMU Miscellaneous Information Register 1", reg,
   1645 	    PCI_SECURE_CAP_EXT);
   1646 	havemisc1 = reg & PCI_SECURE_CAP_EXT;
   1647 
   1648 	reg = regs[o2i(capoff + PCI_SECURE_IOMMU_BAL)];
   1649 	printf("    Base Address Low Register: 0x%08x\n", reg);
   1650 	onoff("Enable", reg, PCI_SECURE_IOMMU_BAL_EN);
   1651 	reg2 = regs[o2i(capoff + PCI_SECURE_IOMMU_BAH)];
   1652 	printf("    Base Address High Register: 0x%08x\n", reg2);
   1653 	printf("      Base Address: 0x%016" PRIx64 "\n",
   1654 	    ((uint64_t)reg2 << 32)
   1655 	    | (reg & (PCI_SECURE_IOMMU_BAL_H | PCI_SECURE_IOMMU_BAL_L)));
   1656 
   1657 	reg = regs[o2i(capoff + PCI_SECURE_IOMMU_RANGE)];
   1658 	printf("    IOMMU Range Register: 0x%08x\n", reg);
   1659 	printf("      HyperTransport UnitID: 0x%02x\n",
   1660 	    PCIREG_SHIFTOUT(reg, PCI_SECURE_IOMMU_RANGE_UNITID));
   1661 	onoff("Range valid", reg, PCI_SECURE_IOMMU_RANGE_RNGVALID);
   1662 	printf("      Device range bus number: 0x%02x\n",
   1663 	    PCIREG_SHIFTOUT(reg, PCI_SECURE_IOMMU_RANGE_BUSNUM));
   1664 	printf("      First device: 0x%04x\n",
   1665 	    PCIREG_SHIFTOUT(reg, PCI_SECURE_IOMMU_RANGE_FIRSTDEV));
   1666 	printf("      Last device: 0x%04x\n",
   1667 	    PCIREG_SHIFTOUT(reg, PCI_SECURE_IOMMU_RANGE_LASTDEV));
   1668 
   1669 	reg = regs[o2i(capoff + PCI_SECURE_IOMMU_MISC0)];
   1670 	printf("    Miscellaneous Information Register 0: 0x%08x\n", reg);
   1671 	printf("      MSI Message number: 0x%02x\n",
   1672 	    PCIREG_SHIFTOUT(reg, PCI_SECURE_IOMMU_MISC0_MSINUM));
   1673 	val = PCIREG_SHIFTOUT(reg, PCI_SECURE_IOMMU_MISC0_GVASIZE);
   1674 	printf("      Guest Virtual Address size: ");
   1675 	if (val == PCI_SECURE_IOMMU_MISC0_GVASIZE_48B)
   1676 		printf("48bits\n");
   1677 	else
   1678 		printf("0x%x(unknown)\n", val);
   1679 	val = PCIREG_SHIFTOUT(reg, PCI_SECURE_IOMMU_MISC0_PASIZE);
   1680 	printf("      Physical Address size: %dbits\n", val);
   1681 	val = PCIREG_SHIFTOUT(reg, PCI_SECURE_IOMMU_MISC0_VASIZE);
   1682 	printf("      Virtual Address size: %dbits\n", val);
   1683 	onoff("ATS response address range reserved", reg,
   1684 	    PCI_SECURE_IOMMU_MISC0_ATSRESV);
   1685 	printf("      Peripheral Page Request MSI Message number: 0x%02x\n",
   1686 	    PCIREG_SHIFTOUT(reg, PCI_SECURE_IOMMU_MISC0_MISNPPR));
   1687 
   1688 	if (!havemisc1)
   1689 		return;
   1690 
   1691 	reg = regs[o2i(capoff + PCI_SECURE_IOMMU_MISC1)];
   1692 	printf("    Miscellaneous Information Register 1: 0x%08x\n", reg);
   1693 	printf("      MSI Message number (GA): 0x%02x\n",
   1694 	    PCIREG_SHIFTOUT(reg, PCI_SECURE_IOMMU_MISC1_MSINUM));
   1695 }
   1696 
   1697 static void
   1698 pci_print_pcie_L0s_latency(uint32_t val)
   1699 {
   1700 
   1701 	switch (val) {
   1702 	case 0x0:
   1703 		printf("Less than 64ns\n");
   1704 		break;
   1705 	case 0x1:
   1706 	case 0x2:
   1707 	case 0x3:
   1708 		printf("%dns to less than %dns\n", 32 << val, 32 << (val + 1));
   1709 		break;
   1710 	case 0x4:
   1711 		printf("512ns to less than 1us\n");
   1712 		break;
   1713 	case 0x5:
   1714 		printf("1us to less than 2us\n");
   1715 		break;
   1716 	case 0x6:
   1717 		printf("2us - 4us\n");
   1718 		break;
   1719 	case 0x7:
   1720 		printf("More than 4us\n");
   1721 		break;
   1722 	}
   1723 }
   1724 
   1725 static void
   1726 pci_print_pcie_L1_latency(uint32_t val)
   1727 {
   1728 
   1729 	switch (val) {
   1730 	case 0x0:
   1731 		printf("Less than 1us\n");
   1732 		break;
   1733 	case 0x6:
   1734 		printf("32us - 64us\n");
   1735 		break;
   1736 	case 0x7:
   1737 		printf("More than 64us\n");
   1738 		break;
   1739 	default:
   1740 		printf("%dus to less than %dus\n", 1 << (val - 1), 1 << val);
   1741 		break;
   1742 	}
   1743 }
   1744 
   1745 static void
   1746 pci_print_pcie_compl_timeout(uint32_t val)
   1747 {
   1748 
   1749 	switch (val) {
   1750 	case 0x0:
   1751 		printf("50us to 50ms\n");
   1752 		break;
   1753 	case 0x5:
   1754 		printf("16ms to 55ms\n");
   1755 		break;
   1756 	case 0x6:
   1757 		printf("65ms to 210ms\n");
   1758 		break;
   1759 	case 0x9:
   1760 		printf("260ms to 900ms\n");
   1761 		break;
   1762 	case 0xa:
   1763 		printf("1s to 3.5s\n");
   1764 		break;
   1765 	default:
   1766 		printf("unknown %u value\n", val);
   1767 		break;
   1768 	}
   1769 }
   1770 
   1771 static const char * const pcie_linkspeeds[] = {
   1772 	"2.5", "5.0", "8.0", "16.0", "32.0"
   1773 };
   1774 
   1775 /*
   1776  * Print link speed. This function is used for the following register bits:
   1777  *   Maximum Link Speed in LCAP
   1778  *   Current Link Speed in LCSR
   1779  *   Target Link Speed in LCSR2
   1780  * All of above bitfield's values start from 1.
   1781  * For LCSR2, 0 is allowed for a device which supports 2.5GT/s only (and
   1782  * this check also works for devices which compliant to versions of the base
   1783  * specification prior to 3.0.
   1784  */
   1785 static void
   1786 pci_print_pcie_linkspeed(int regnum, pcireg_t val)
   1787 {
   1788 
   1789 	if ((regnum == PCIE_LCSR2) && (val == 0))
   1790 		printf("2.5GT/s\n");
   1791 	else if ((val < 1) || (val > __arraycount(pcie_linkspeeds)))
   1792 		printf("unknown value (%u)\n", val);
   1793 	else
   1794 		printf("%sGT/s\n", pcie_linkspeeds[val - 1]);
   1795 }
   1796 
   1797 /*
   1798  * Print link speed "vector".
   1799  * This function is used for the following register bits:
   1800  *   Supported Link Speeds Vector in LCAP2
   1801  *   Lower SKP OS Generation Supported Speed Vector  in LCAP2
   1802  *   Lower SKP OS Reception Supported Speed Vector in LCAP2
   1803  *   Enable Lower SKP OS Generation Vector in LCTL3
   1804  * All of above bitfield's values start from 0.
   1805  */
   1806 static void
   1807 pci_print_pcie_linkspeedvector(pcireg_t val)
   1808 {
   1809 	unsigned int i;
   1810 
   1811 	/* Start from 0 */
   1812 	for (i = 0; i < 16; i++)
   1813 		if (((val >> i) & 0x01) != 0) {
   1814 			if (i >= __arraycount(pcie_linkspeeds))
   1815 				printf(" unknown vector (0x%x)", 1 << i);
   1816 			else
   1817 				printf(" %sGT/s", pcie_linkspeeds[i]);
   1818 		}
   1819 }
   1820 
   1821 static void
   1822 pci_print_pcie_link_deemphasis(pcireg_t val)
   1823 {
   1824 	switch (val) {
   1825 	case 0:
   1826 		printf("-6dB");
   1827 		break;
   1828 	case 1:
   1829 		printf("-3.5dB");
   1830 		break;
   1831 	default:
   1832 		printf("(reserved value)");
   1833 	}
   1834 }
   1835 
   1836 static const struct _pcie_link_compliance_preset_deemphasis {
   1837 	const char *preshoot;
   1838 	const char *deemphasis;
   1839 } pcie_link_compliance_preset_deemphasis[] = {
   1840 	{ "0.0",	"-6.0+-1.5" },	/* P0 */
   1841 	{ "0.0",	"-3.5+-1" },	/* P1 */
   1842 	{ "0.0",	"-4.4+-1.5" },	/* P2 */
   1843 	{ "0.0",	"-2.5+-1" },	/* P3 */
   1844 	{ "0.0",	"0.0" },	/* P4 */
   1845 	{ "1.9+-1",	"0.0" },	/* P5 */
   1846 	{ "2.5+-1",	"0.0" },	/* P6 */
   1847 	{ "3.5+-1",	"-6.0+-1.5" },	/* P7 */
   1848 	{ "3.5+-1",	"-3.5+-1" },	/* P8 */
   1849 	{ "3.5+-1",	"0.0" },	/* P9 */
   1850 	{ "0.0",	NULL }		/* P10 */
   1851 };
   1852 
   1853 static void
   1854 pci_print_pcie_link_compliance_preset_deemphasis(pcireg_t val)
   1855 {
   1856 	const char *deemphasis;
   1857 
   1858 	if (val >= __arraycount(pcie_link_compliance_preset_deemphasis)) {
   1859 		printf("unknown value (0x%hhx)", val);
   1860 		return;
   1861 	}
   1862 
   1863 	printf("Preshoot %sdB",
   1864 	    pcie_link_compliance_preset_deemphasis[val].preshoot);
   1865 	deemphasis = pcie_link_compliance_preset_deemphasis[val].deemphasis;
   1866 
   1867 	if (deemphasis != NULL)
   1868 		printf(", De-emphasis %sdB", deemphasis);
   1869 }
   1870 
   1871 static void
   1872 pci_conf_print_pcie_cap(const pcireg_t *regs, int capoff)
   1873 {
   1874 	pcireg_t reg; /* for each register */
   1875 	pcireg_t val; /* for each bitfield */
   1876 	bool check_slot = false;
   1877 	unsigned int pcie_devtype;
   1878 	bool check_upstreamport = false;
   1879 	unsigned int pciever;
   1880 	unsigned int i;
   1881 
   1882 	printf("\n  PCI Express Capabilities Register\n");
   1883 	/* Capability Register */
   1884 	reg = regs[o2i(capoff)];
   1885 	printf("    Capability register: 0x%04x\n", reg >> 16);
   1886 	pciever = (unsigned int)(PCIE_XCAP_VER(reg));
   1887 	printf("      Capability version: %u\n", pciever);
   1888 	printf("      Device type: ");
   1889 	pcie_devtype = PCIE_XCAP_TYPE(reg);
   1890 	switch (pcie_devtype) {
   1891 	case PCIE_XCAP_TYPE_PCIE_DEV:	/* 0x0 */
   1892 		printf("PCI Express Endpoint device\n");
   1893 		check_upstreamport = true;
   1894 		break;
   1895 	case PCIE_XCAP_TYPE_PCI_DEV:	/* 0x1 */
   1896 		printf("Legacy PCI Express Endpoint device\n");
   1897 		check_upstreamport = true;
   1898 		break;
   1899 	case PCIE_XCAP_TYPE_RP:		/* 0x4 */
   1900 		printf("Root Port of PCI Express Root Complex\n");
   1901 		check_slot = true;
   1902 		break;
   1903 	case PCIE_XCAP_TYPE_UP:		/* 0x5 */
   1904 		printf("Upstream Port of PCI Express Switch\n");
   1905 		check_upstreamport = true;
   1906 		break;
   1907 	case PCIE_XCAP_TYPE_DOWN:	/* 0x6 */
   1908 		printf("Downstream Port of PCI Express Switch\n");
   1909 		check_slot = true;
   1910 		break;
   1911 	case PCIE_XCAP_TYPE_PCIE2PCI:	/* 0x7 */
   1912 		printf("PCI Express to PCI/PCI-X Bridge\n");
   1913 		check_upstreamport = true;
   1914 		break;
   1915 	case PCIE_XCAP_TYPE_PCI2PCIE:	/* 0x8 */
   1916 		printf("PCI/PCI-X to PCI Express Bridge\n");
   1917 		/* Upstream port is not PCIe */
   1918 		check_slot = true;
   1919 		break;
   1920 	case PCIE_XCAP_TYPE_RCIEP:	/* 0x9 */
   1921 		printf("Root Complex Integrated Endpoint\n");
   1922 		break;
   1923 	case PCIE_XCAP_TYPE_RC_EVNTC:	/* 0xa */
   1924 		printf("Root Complex Event Collector\n");
   1925 		break;
   1926 	default:
   1927 		printf("unknown\n");
   1928 		break;
   1929 	}
   1930 	onoff("Slot implemented", reg, PCIE_XCAP_SI);
   1931 	printf("      Interrupt Message Number: 0x%02x\n",
   1932 	    PCIREG_SHIFTOUT(reg, PCIE_XCAP_IRQ));
   1933 
   1934 	/* Device Capability Register */
   1935 	reg = regs[o2i(capoff + PCIE_DCAP)];
   1936 	printf("    Device Capabilities Register: 0x%08x\n", reg);
   1937 	printf("      Max Payload Size Supported: %u bytes max\n",
   1938 	    128 << (unsigned int)(reg & PCIE_DCAP_MAX_PAYLOAD));
   1939 	printf("      Phantom Functions Supported: ");
   1940 	switch (PCIREG_SHIFTOUT(reg, PCIE_DCAP_PHANTOM_FUNCS)) {
   1941 	case 0x0:
   1942 		printf("not available\n");
   1943 		break;
   1944 	case 0x1:
   1945 		printf("MSB\n");
   1946 		break;
   1947 	case 0x2:
   1948 		printf("two MSB\n");
   1949 		break;
   1950 	case 0x3:
   1951 		printf("All three bits\n");
   1952 		break;
   1953 	}
   1954 	printf("      Extended Tag Field Supported: %dbit\n",
   1955 	    (reg & PCIE_DCAP_EXT_TAG_FIELD) == 0 ? 5 : 8);
   1956 	printf("      Endpoint L0 Acceptable Latency: ");
   1957 	pci_print_pcie_L0s_latency(PCIREG_SHIFTOUT(reg, PCIE_DCAP_L0S_LATENCY));
   1958 	printf("      Endpoint L1 Acceptable Latency: ");
   1959 	pci_print_pcie_L1_latency(PCIREG_SHIFTOUT(reg, PCIE_DCAP_L1_LATENCY));
   1960 	onoff("Attention Button Present", reg, PCIE_DCAP_ATTN_BUTTON);
   1961 	onoff("Attention Indicator Present", reg, PCIE_DCAP_ATTN_IND);
   1962 	onoff("Power Indicator Present", reg, PCIE_DCAP_PWR_IND);
   1963 	onoff("Role-Based Error Report", reg, PCIE_DCAP_ROLE_ERR_RPT);
   1964 	if (check_upstreamport) {
   1965 		printf("      Captured Slot Power Limit: ");
   1966 		pci_conf_print_pcie_power(
   1967 			PCIREG_SHIFTOUT(reg, PCIE_DCAP_SLOT_PWR_LIM_VAL),
   1968 			PCIREG_SHIFTOUT(reg, PCIE_DCAP_SLOT_PWR_LIM_SCALE));
   1969 	}
   1970 	onoff("Function-Level Reset Capability", reg, PCIE_DCAP_FLR);
   1971 
   1972 	/* Device Control Register */
   1973 	reg = regs[o2i(capoff + PCIE_DCSR)];
   1974 	printf("    Device Control Register: 0x%04x\n", reg & 0xffff);
   1975 	onoff("Correctable Error Reporting Enable", reg,
   1976 	    PCIE_DCSR_ENA_COR_ERR);
   1977 	onoff("Non Fatal Error Reporting Enable", reg, PCIE_DCSR_ENA_NFER);
   1978 	onoff("Fatal Error Reporting Enable", reg, PCIE_DCSR_ENA_FER);
   1979 	onoff("Unsupported Request Reporting Enable", reg, PCIE_DCSR_ENA_URR);
   1980 	onoff("Enable Relaxed Ordering", reg, PCIE_DCSR_ENA_RELAX_ORD);
   1981 	printf("      Max Payload Size: %d byte\n",
   1982 	    128 << PCIREG_SHIFTOUT(reg, PCIE_DCSR_MAX_PAYLOAD));
   1983 	onoff("Extended Tag Field Enable", reg, PCIE_DCSR_EXT_TAG_FIELD);
   1984 	onoff("Phantom Functions Enable", reg, PCIE_DCSR_PHANTOM_FUNCS);
   1985 	onoff("Aux Power PM Enable", reg, PCIE_DCSR_AUX_POWER_PM);
   1986 	onoff("Enable No Snoop", reg, PCIE_DCSR_ENA_NO_SNOOP);
   1987 	printf("      Max Read Request Size: %d byte\n",
   1988 	    128 << PCIREG_SHIFTOUT(reg, PCIE_DCSR_MAX_READ_REQ));
   1989 	if (pcie_devtype == PCIE_XCAP_TYPE_PCIE2PCI)
   1990 		onoff("Bridge Config Retry Enable", reg,
   1991 		    PCIE_DCSR_BRDG_CFG_RETRY);
   1992 
   1993 	/* Device Status Register */
   1994 	reg = regs[o2i(capoff + PCIE_DCSR)];
   1995 	printf("    Device Status Register: 0x%04x\n", reg >> 16);
   1996 	onoff("Correctable Error Detected", reg, PCIE_DCSR_CED);
   1997 	onoff("Non Fatal Error Detected", reg, PCIE_DCSR_NFED);
   1998 	onoff("Fatal Error Detected", reg, PCIE_DCSR_FED);
   1999 	onoff("Unsupported Request Detected", reg, PCIE_DCSR_URD);
   2000 	onoff("Aux Power Detected", reg, PCIE_DCSR_AUX_PWR);
   2001 	onoff("Transaction Pending", reg, PCIE_DCSR_TRANSACTION_PND);
   2002 	onoff("Emergency Power Reduction Detected", reg, PCIE_DCSR_EMGPWRREDD);
   2003 
   2004 	if (PCIE_HAS_LINKREGS(pcie_devtype)) {
   2005 		/* Link Capability Register */
   2006 		reg = regs[o2i(capoff + PCIE_LCAP)];
   2007 		printf("    Link Capabilities Register: 0x%08x\n", reg);
   2008 		printf("      Maximum Link Speed: ");
   2009 		pci_print_pcie_linkspeed(PCIE_LCAP, reg & PCIE_LCAP_MAX_SPEED);
   2010 		printf("      Maximum Link Width: x%u lanes\n",
   2011 		    PCIREG_SHIFTOUT(reg, PCIE_LCAP_MAX_WIDTH));
   2012 		printf("      Active State PM Support: ");
   2013 		switch (PCIREG_SHIFTOUT(reg, PCIE_LCAP_ASPM)) {
   2014 		case 0x0:
   2015 			printf("No ASPM support\n");
   2016 			break;
   2017 		case 0x1:
   2018 			printf("L0s supported\n");
   2019 			break;
   2020 		case 0x2:
   2021 			printf("L1 supported\n");
   2022 			break;
   2023 		case 0x3:
   2024 			printf("L0s and L1 supported\n");
   2025 			break;
   2026 		}
   2027 		printf("      L0 Exit Latency: ");
   2028 		pci_print_pcie_L0s_latency(PCIREG_SHIFTOUT(reg,PCIE_LCAP_L0S_EXIT));
   2029 		printf("      L1 Exit Latency: ");
   2030 		pci_print_pcie_L1_latency(PCIREG_SHIFTOUT(reg, PCIE_LCAP_L1_EXIT));
   2031 		printf("      Port Number: %u\n",
   2032 		    PCIREG_SHIFTOUT(reg, PCIE_LCAP_PORT));
   2033 		onoff("Clock Power Management", reg, PCIE_LCAP_CLOCK_PM);
   2034 		onoff("Surprise Down Error Report", reg,
   2035 		    PCIE_LCAP_SURPRISE_DOWN);
   2036 		onoff("Data Link Layer Link Active", reg, PCIE_LCAP_DL_ACTIVE);
   2037 		onoff("Link BW Notification Capable", reg,
   2038 			PCIE_LCAP_LINK_BW_NOTIFY);
   2039 		onoff("ASPM Optionally Compliance", reg,
   2040 		    PCIE_LCAP_ASPM_COMPLIANCE);
   2041 
   2042 		/* Link Control Register */
   2043 		reg = regs[o2i(capoff + PCIE_LCSR)];
   2044 		printf("    Link Control Register: 0x%04x\n", reg & 0xffff);
   2045 		printf("      Active State PM Control: ");
   2046 		switch (reg & (PCIE_LCSR_ASPM_L1 | PCIE_LCSR_ASPM_L0S)) {
   2047 		case 0:
   2048 			printf("disabled\n");
   2049 			break;
   2050 		case 1:
   2051 			printf("L0s Entry Enabled\n");
   2052 			break;
   2053 		case 2:
   2054 			printf("L1 Entry Enabled\n");
   2055 			break;
   2056 		case 3:
   2057 			printf("L0s and L1 Entry Enabled\n");
   2058 			break;
   2059 		}
   2060 		onoff2("Read Completion Boundary Control", reg, PCIE_LCSR_RCB,
   2061 		    "128bytes", "64bytes");
   2062 		onoff("Link Disable", reg, PCIE_LCSR_LINK_DIS);
   2063 		onoff("Retrain Link", reg, PCIE_LCSR_RETRAIN);
   2064 		onoff("Common Clock Configuration", reg, PCIE_LCSR_COMCLKCFG);
   2065 		onoff("Extended Synch", reg, PCIE_LCSR_EXTNDSYNC);
   2066 		onoff("Enable Clock Power Management", reg, PCIE_LCSR_ENCLKPM);
   2067 		onoff("Hardware Autonomous Width Disable", reg,PCIE_LCSR_HAWD);
   2068 		onoff("Link Bandwidth Management Interrupt Enable", reg,
   2069 		    PCIE_LCSR_LBMIE);
   2070 		onoff("Link Autonomous Bandwidth Interrupt Enable", reg,
   2071 		    PCIE_LCSR_LABIE);
   2072 		printf("      DRS Signaling Control: ");
   2073 		switch (PCIREG_SHIFTOUT(reg, PCIE_LCSR_DRSSGNL)) {
   2074 		case 0:
   2075 			printf("not reported\n");
   2076 			break;
   2077 		case 1:
   2078 			printf("Interrupt Enabled\n");
   2079 			break;
   2080 		case 2:
   2081 			printf("DRS to FRS Signaling Enabled\n");
   2082 			break;
   2083 		default:
   2084 			printf("reserved\n");
   2085 			break;
   2086 		}
   2087 
   2088 		/* Link Status Register */
   2089 		reg = regs[o2i(capoff + PCIE_LCSR)];
   2090 		printf("    Link Status Register: 0x%04x\n", reg >> 16);
   2091 		printf("      Negotiated Link Speed: ");
   2092 		pci_print_pcie_linkspeed(PCIE_LCSR,
   2093 		    PCIREG_SHIFTOUT(reg, PCIE_LCSR_LINKSPEED));
   2094 		printf("      Negotiated Link Width: x%u lanes\n",
   2095 		    PCIREG_SHIFTOUT(reg, PCIE_LCSR_NLW));
   2096 		onoff("Training Error", reg, PCIE_LCSR_LINKTRAIN_ERR);
   2097 		onoff("Link Training", reg, PCIE_LCSR_LINKTRAIN);
   2098 		onoff("Slot Clock Configuration", reg, PCIE_LCSR_SLOTCLKCFG);
   2099 		onoff("Data Link Layer Link Active", reg, PCIE_LCSR_DLACTIVE);
   2100 		onoff("Link Bandwidth Management Status", reg,
   2101 		    PCIE_LCSR_LINK_BW_MGMT);
   2102 		onoff("Link Autonomous Bandwidth Status", reg,
   2103 		    PCIE_LCSR_LINK_AUTO_BW);
   2104 	}
   2105 
   2106 	if (check_slot == true) {
   2107 		pcireg_t slcap;
   2108 
   2109 		/* Slot Capability Register */
   2110 		slcap = reg = regs[o2i(capoff + PCIE_SLCAP)];
   2111 		printf("    Slot Capability Register: 0x%08x\n", reg);
   2112 		onoff("Attention Button Present", reg, PCIE_SLCAP_ABP);
   2113 		onoff("Power Controller Present", reg, PCIE_SLCAP_PCP);
   2114 		onoff("MRL Sensor Present", reg, PCIE_SLCAP_MSP);
   2115 		onoff("Attention Indicator Present", reg, PCIE_SLCAP_AIP);
   2116 		onoff("Power Indicator Present", reg, PCIE_SLCAP_PIP);
   2117 		onoff("Hot-Plug Surprise", reg, PCIE_SLCAP_HPS);
   2118 		onoff("Hot-Plug Capable", reg, PCIE_SLCAP_HPC);
   2119 		printf("      Slot Power Limit Value: ");
   2120 		pci_conf_print_pcie_power(PCIREG_SHIFTOUT(reg, PCIE_SLCAP_SPLV),
   2121 		    PCIREG_SHIFTOUT(reg, PCIE_SLCAP_SPLS));
   2122 		onoff("Electromechanical Interlock Present", reg,
   2123 		    PCIE_SLCAP_EIP);
   2124 		onoff("No Command Completed Support", reg, PCIE_SLCAP_NCCS);
   2125 		printf("      Physical Slot Number: %d\n",
   2126 		    (unsigned int)(reg & PCIE_SLCAP_PSN) >> 19);
   2127 
   2128 		/* Slot Control Register */
   2129 		reg = regs[o2i(capoff + PCIE_SLCSR)];
   2130 		printf("    Slot Control Register: 0x%04x\n", reg & 0xffff);
   2131 		onoff("Attention Button Pressed Enabled", reg, PCIE_SLCSR_ABE);
   2132 		onoff("Power Fault Detected Enabled", reg, PCIE_SLCSR_PFE);
   2133 		onoff("MRL Sensor Changed Enabled", reg, PCIE_SLCSR_MSE);
   2134 		onoff("Presence Detect Changed Enabled", reg, PCIE_SLCSR_PDE);
   2135 		onoff("Command Completed Interrupt Enabled", reg,
   2136 		    PCIE_SLCSR_CCE);
   2137 		onoff("Hot-Plug Interrupt Enabled", reg, PCIE_SLCSR_HPE);
   2138 		/*
   2139 		 * For Attention Indicator Control and Power Indicator Control,
   2140 		 * it's allowed to be a read only value 0 if corresponding
   2141 		 * capability register bit is 0.
   2142 		 */
   2143 		if (slcap & PCIE_SLCAP_AIP) {
   2144 			printf("      Attention Indicator Control: ");
   2145 			switch ((reg & PCIE_SLCSR_AIC) >> 6) {
   2146 			case 0x0:
   2147 				printf("reserved\n");
   2148 				break;
   2149 			case PCIE_SLCSR_IND_ON:
   2150 				printf("on\n");
   2151 				break;
   2152 			case PCIE_SLCSR_IND_BLINK:
   2153 				printf("blink\n");
   2154 				break;
   2155 			case PCIE_SLCSR_IND_OFF:
   2156 				printf("off\n");
   2157 				break;
   2158 			}
   2159 		}
   2160 		if (slcap & PCIE_SLCAP_PIP) {
   2161 			printf("      Power Indicator Control: ");
   2162 			switch ((reg & PCIE_SLCSR_PIC) >> 8) {
   2163 			case 0x0:
   2164 				printf("reserved\n");
   2165 				break;
   2166 			case PCIE_SLCSR_IND_ON:
   2167 				printf("on\n");
   2168 				break;
   2169 			case PCIE_SLCSR_IND_BLINK:
   2170 				printf("blink\n");
   2171 				break;
   2172 			case PCIE_SLCSR_IND_OFF:
   2173 				printf("off\n");
   2174 				break;
   2175 			}
   2176 		}
   2177 		printf("      Power Controller Control: Power %s\n",
   2178 		    reg & PCIE_SLCSR_PCC ? "off" : "on");
   2179 		onoff("Electromechanical Interlock Control",
   2180 		    reg, PCIE_SLCSR_EIC);
   2181 		onoff("Data Link Layer State Changed Enable", reg,
   2182 		    PCIE_SLCSR_DLLSCE);
   2183 		onoff("Auto Slot Power Limit Disable", reg,
   2184 		    PCIE_SLCSR_AUTOSPLDIS);
   2185 
   2186 		/* Slot Status Register */
   2187 		printf("    Slot Status Register: 0x%04x\n", reg >> 16);
   2188 		onoff("Attention Button Pressed", reg, PCIE_SLCSR_ABP);
   2189 		onoff("Power Fault Detected", reg, PCIE_SLCSR_PFD);
   2190 		onoff("MRL Sensor Changed", reg, PCIE_SLCSR_MSC);
   2191 		onoff("Presence Detect Changed", reg, PCIE_SLCSR_PDC);
   2192 		onoff("Command Completed", reg, PCIE_SLCSR_CC);
   2193 		onoff("MRL Open", reg, PCIE_SLCSR_MS);
   2194 		onoff("Card Present in slot", reg, PCIE_SLCSR_PDS);
   2195 		onoff("Electromechanical Interlock engaged", reg,
   2196 		    PCIE_SLCSR_EIS);
   2197 		onoff("Data Link Layer State Changed", reg, PCIE_SLCSR_LACS);
   2198 	}
   2199 
   2200 	if (PCIE_HAS_ROOTREGS(pcie_devtype)) {
   2201 		/* Root Control Register */
   2202 		reg = regs[o2i(capoff + PCIE_RCR)];
   2203 		printf("    Root Control Register: 0x%04x\n", reg & 0xffff);
   2204 		onoff("SERR on Correctable Error Enable", reg,
   2205 		    PCIE_RCR_SERR_CER);
   2206 		onoff("SERR on Non-Fatal Error Enable", reg,
   2207 		    PCIE_RCR_SERR_NFER);
   2208 		onoff("SERR on Fatal Error Enable", reg, PCIE_RCR_SERR_FER);
   2209 		onoff("PME Interrupt Enable", reg, PCIE_RCR_PME_IE);
   2210 		onoff("CRS Software Visibility Enable", reg, PCIE_RCR_CRS_SVE);
   2211 
   2212 		/* Root Capability Register */
   2213 		printf("    Root Capability Register: 0x%04x\n",
   2214 		    reg >> 16);
   2215 		onoff("CRS Software Visibility", reg, PCIE_RCR_CRS_SV);
   2216 
   2217 		/* Root Status Register */
   2218 		reg = regs[o2i(capoff + PCIE_RSR)];
   2219 		printf("    Root Status Register: 0x%08x\n", reg);
   2220 		printf("      PME Requester ID: 0x%04x\n",
   2221 		    (unsigned int)(reg & PCIE_RSR_PME_REQESTER));
   2222 		onoff("PME was asserted", reg, PCIE_RSR_PME_STAT);
   2223 		onoff("another PME is pending", reg, PCIE_RSR_PME_PEND);
   2224 	}
   2225 
   2226 	/* PCIe DW9 to DW14 is for PCIe 2.0 and newer */
   2227 	if (pciever < 2)
   2228 		return;
   2229 
   2230 	/* Device Capabilities 2 */
   2231 	reg = regs[o2i(capoff + PCIE_DCAP2)];
   2232 	printf("    Device Capabilities 2: 0x%08x\n", reg);
   2233 	printf("      Completion Timeout Ranges Supported: ");
   2234 	val = reg & PCIE_DCAP2_COMPT_RANGE;
   2235 	switch (val) {
   2236 	case 0:
   2237 		printf("not supported\n");
   2238 		break;
   2239 	default:
   2240 		for (i = 0; i <= 3; i++) {
   2241 			if (((val >> i) & 0x01) != 0)
   2242 				printf("%c", 'A' + i);
   2243 		}
   2244 		printf("\n");
   2245 	}
   2246 	onoff("Completion Timeout Disable Supported", reg,
   2247 	    PCIE_DCAP2_COMPT_DIS);
   2248 	onoff("ARI Forwarding Supported", reg, PCIE_DCAP2_ARI_FWD);
   2249 	onoff("AtomicOp Routing Supported", reg, PCIE_DCAP2_ATOM_ROUT);
   2250 	onoff("32bit AtomicOp Completer Supported", reg, PCIE_DCAP2_32ATOM);
   2251 	onoff("64bit AtomicOp Completer Supported", reg, PCIE_DCAP2_64ATOM);
   2252 	onoff("128-bit CAS Completer Supported", reg, PCIE_DCAP2_128CAS);
   2253 	onoff("No RO-enabled PR-PR passing", reg, PCIE_DCAP2_NO_ROPR_PASS);
   2254 	onoff("LTR Mechanism Supported", reg, PCIE_DCAP2_LTR_MEC);
   2255 	printf("      TPH Completer Supported: ");
   2256 	switch (PCIREG_SHIFTOUT(reg, PCIE_DCAP2_TPH_COMP)) {
   2257 	case 0:
   2258 		printf("Not supported\n");
   2259 		break;
   2260 	case 1:
   2261 		printf("TPH\n");
   2262 		break;
   2263 	case 3:
   2264 		printf("TPH and Extended TPH\n");
   2265 		break;
   2266 	default:
   2267 		printf("(reserved value)\n");
   2268 		break;
   2269 	}
   2270 	printf("      LN System CLS: ");
   2271 	switch (PCIREG_SHIFTOUT(reg, PCIE_DCAP2_LNSYSCLS)) {
   2272 	case 0x0:
   2273 		printf("Not supported or not in effect\n");
   2274 		break;
   2275 	case 0x1:
   2276 		printf("64byte cachelines in effect\n");
   2277 		break;
   2278 	case 0x2:
   2279 		printf("128byte cachelines in effect\n");
   2280 		break;
   2281 	case 0x3:
   2282 		printf("Reserved\n");
   2283 		break;
   2284 	}
   2285 	onoff("10-bit Tag Completer Supported", reg, PCIE_DCAP2_TBT_COMP);
   2286 	onoff("10-bit Tag Requester Supported", reg, PCIE_DCAP2_TBT_REQ);
   2287 	printf("      OBFF Supported: ");
   2288 	switch (PCIREG_SHIFTOUT(reg, PCIE_DCAP2_OBFF)) {
   2289 	case 0x0:
   2290 		printf("Not supported\n");
   2291 		break;
   2292 	case 0x1:
   2293 		printf("Message only\n");
   2294 		break;
   2295 	case 0x2:
   2296 		printf("WAKE# only\n");
   2297 		break;
   2298 	case 0x3:
   2299 		printf("Both\n");
   2300 		break;
   2301 	}
   2302 	onoff("Extended Fmt Field Supported", reg, PCIE_DCAP2_EXTFMT_FLD);
   2303 	onoff("End-End TLP Prefix Supported", reg, PCIE_DCAP2_EETLP_PREF);
   2304 	val = PCIREG_SHIFTOUT(reg, PCIE_DCAP2_MAX_EETLP);
   2305 	printf("      Max End-End TLP Prefixes: %u\n", (val == 0) ? 4 : val);
   2306 	printf("      Emergency Power Reduction Supported: ");
   2307 	switch (PCIREG_SHIFTOUT(reg, PCIE_DCAP2_EMGPWRRED)) {
   2308 	case 0x0:
   2309 		printf("Not supported\n");
   2310 		break;
   2311 	case 0x1:
   2312 		printf("Device Specific mechanism\n");
   2313 		break;
   2314 	case 0x2:
   2315 		printf("Form Factor spec or Device Specific mechanism\n");
   2316 		break;
   2317 	case 0x3:
   2318 		printf("Reserved\n");
   2319 		break;
   2320 	}
   2321 	onoff("Emergency Power Reduction Initialization Required", reg,
   2322 	    PCIE_DCAP2_EMGPWRRED_INI);
   2323 	onoff("FRS Supported", reg, PCIE_DCAP2_FRS);
   2324 
   2325 	/* Device Control 2 */
   2326 	reg = regs[o2i(capoff + PCIE_DCSR2)];
   2327 	printf("    Device Control 2: 0x%04x\n", reg & 0xffff);
   2328 	printf("      Completion Timeout Value: ");
   2329 	pci_print_pcie_compl_timeout(reg & PCIE_DCSR2_COMPT_VAL);
   2330 	onoff("Completion Timeout Disabled", reg, PCIE_DCSR2_COMPT_DIS);
   2331 	onoff("ARI Forwarding Enabled", reg, PCIE_DCSR2_ARI_FWD);
   2332 	onoff("AtomicOp Requester Enabled", reg, PCIE_DCSR2_ATOM_REQ);
   2333 	onoff("AtomicOp Egress Blocking", reg, PCIE_DCSR2_ATOM_EBLK);
   2334 	onoff("IDO Request Enabled", reg, PCIE_DCSR2_IDO_REQ);
   2335 	onoff("IDO Completion Enabled", reg, PCIE_DCSR2_IDO_COMP);
   2336 	onoff("LTR Mechanism Enabled", reg, PCIE_DCSR2_LTR_MEC);
   2337 	onoff("Emergency Power Reduction Request", reg,
   2338 	    PCIE_DCSR2_EMGPWRRED_REQ);
   2339 	onoff("10-bit Tag Requester Enabled", reg, PCIE_DCSR2_TBT_REQ);
   2340 	printf("      OBFF: ");
   2341 	switch (PCIREG_SHIFTOUT(reg, PCIE_DCSR2_OBFF_EN)) {
   2342 	case 0x0:
   2343 		printf("Disabled\n");
   2344 		break;
   2345 	case 0x1:
   2346 		printf("Enabled with Message Signaling Variation A\n");
   2347 		break;
   2348 	case 0x2:
   2349 		printf("Enabled with Message Signaling Variation B\n");
   2350 		break;
   2351 	case 0x3:
   2352 		printf("Enabled using WAKE# signaling\n");
   2353 		break;
   2354 	}
   2355 	onoff("End-End TLP Prefix Blocking on", reg, PCIE_DCSR2_EETLP);
   2356 
   2357 	if (PCIE_HAS_LINKREGS(pcie_devtype)) {
   2358 		bool drs_supported = false;
   2359 
   2360 		/* Link Capability 2 */
   2361 		reg = regs[o2i(capoff + PCIE_LCAP2)];
   2362 		/* If the vector is 0, LCAP2 is not implemented */
   2363 		if ((reg & PCIE_LCAP2_SUP_LNKSV) != 0) {
   2364 			printf("    Link Capabilities 2: 0x%08x\n", reg);
   2365 			printf("      Supported Link Speeds Vector:");
   2366 			pci_print_pcie_linkspeedvector(
   2367 				PCIREG_SHIFTOUT(reg, PCIE_LCAP2_SUP_LNKSV));
   2368 			printf("\n");
   2369 			onoff("Crosslink Supported", reg, PCIE_LCAP2_CROSSLNK);
   2370 			printf("      "
   2371 			    "Lower SKP OS Generation Supported Speed Vector:");
   2372 			pci_print_pcie_linkspeedvector(
   2373 				PCIREG_SHIFTOUT(reg, PCIE_LCAP2_LOWSKPOS_GENSUPPSV));
   2374 			printf("\n");
   2375 			printf("      "
   2376 			    "Lower SKP OS Reception Supported Speed Vector:");
   2377 			pci_print_pcie_linkspeedvector(
   2378 				PCIREG_SHIFTOUT(reg, PCIE_LCAP2_LOWSKPOS_RECSUPPSV));
   2379 			printf("\n");
   2380 			onoff("Retimer Presence Detect Supported", reg,
   2381 			    PCIE_LCAP2_RETIMERPD);
   2382 			onoff("DRS Supported", reg, PCIE_LCAP2_DRS);
   2383 			drs_supported = (reg & PCIE_LCAP2_DRS) ? true : false;
   2384 		}
   2385 
   2386 		/* Link Control 2 */
   2387 		reg = regs[o2i(capoff + PCIE_LCSR2)];
   2388 		/* If the vector is 0, LCAP2 is not implemented */
   2389 		printf("    Link Control 2: 0x%04x\n", reg & 0xffff);
   2390 		printf("      Target Link Speed: ");
   2391 		pci_print_pcie_linkspeed(PCIE_LCSR2,
   2392 		    PCIREG_SHIFTOUT(reg, PCIE_LCSR2_TGT_LSPEED));
   2393 		onoff("Enter Compliance Enabled", reg, PCIE_LCSR2_ENT_COMPL);
   2394 		onoff("HW Autonomous Speed Disabled", reg,
   2395 		    PCIE_LCSR2_HW_AS_DIS);
   2396 		printf("      Selectable De-emphasis: ");
   2397 		pci_print_pcie_link_deemphasis(
   2398 			PCIREG_SHIFTOUT(reg, PCIE_LCSR2_SEL_DEEMP));
   2399 		printf("\n");
   2400 		printf("      Transmit Margin: %u\n",
   2401 		    PCIREG_SHIFTOUT(reg,  PCIE_LCSR2_TX_MARGIN));
   2402 		onoff("Enter Modified Compliance", reg, PCIE_LCSR2_EN_MCOMP);
   2403 		onoff("Compliance SOS", reg, PCIE_LCSR2_COMP_SOS);
   2404 		printf("      Compliance Preset/De-emphasis: ");
   2405 		pci_print_pcie_link_compliance_preset_deemphasis(
   2406 			PCIREG_SHIFTOUT(reg, PCIE_LCSR2_COMP_DEEMP));
   2407 		printf("\n");
   2408 
   2409 		/* Link Status 2 */
   2410 		printf("    Link Status 2: 0x%04x\n", (reg >> 16) & 0xffff);
   2411 		printf("      Current De-emphasis Level: ");
   2412 		pci_print_pcie_link_deemphasis(
   2413 			PCIREG_SHIFTOUT(reg, PCIE_LCSR2_DEEMP_LVL));
   2414 		printf("\n");
   2415 		onoff("Equalization Complete", reg, PCIE_LCSR2_EQ_COMPL);
   2416 		onoff("Equalization Phase 1 Successful", reg,
   2417 		    PCIE_LCSR2_EQP1_SUC);
   2418 		onoff("Equalization Phase 2 Successful", reg,
   2419 		    PCIE_LCSR2_EQP2_SUC);
   2420 		onoff("Equalization Phase 3 Successful", reg,
   2421 		    PCIE_LCSR2_EQP3_SUC);
   2422 		onoff("Link Equalization Request", reg, PCIE_LCSR2_LNKEQ_REQ);
   2423 		onoff("Retimer Presence Detected", reg, PCIE_LCSR2_RETIMERPD);
   2424 		if (drs_supported) {
   2425 			printf("      Downstream Component Presence: ");
   2426 			switch (PCIREG_SHIFTOUT(reg, PCIE_LCSR2_DSCOMPN)) {
   2427 			case PCIE_DSCOMPN_DOWN_NOTDETERM:
   2428 				printf("Link Down - Presence Not"
   2429 				    " Determined\n");
   2430 				break;
   2431 			case PCIE_DSCOMPN_DOWN_NOTPRES:
   2432 				printf("Link Down - Component Not Present\n");
   2433 				break;
   2434 			case PCIE_DSCOMPN_DOWN_PRES:
   2435 				printf("Link Down - Component Present\n");
   2436 				break;
   2437 			case PCIE_DSCOMPN_UP_PRES:
   2438 				printf("Link Up - Component Present\n");
   2439 				break;
   2440 			case PCIE_DSCOMPN_UP_PRES_DRS:
   2441 				printf("Link Up - Component Present and DRS"
   2442 				    " received\n");
   2443 				break;
   2444 			default:
   2445 				printf("reserved\n");
   2446 				break;
   2447 			}
   2448 			onoff("DRS Message Received", reg, PCIE_LCSR2_DRSRCV);
   2449 		}
   2450 	}
   2451 
   2452 	/* Slot Capability 2 */
   2453 	/* Slot Control 2 */
   2454 	/* Slot Status 2 */
   2455 }
   2456 
   2457 static void
   2458 pci_conf_print_msix_cap(const pcireg_t *regs, int capoff)
   2459 {
   2460 	pcireg_t reg;
   2461 
   2462 	printf("\n  MSI-X Capability Register\n");
   2463 
   2464 	reg = regs[o2i(capoff + PCI_MSIX_CTL)];
   2465 	printf("    Message Control register: 0x%04x\n",
   2466 	    (reg >> 16) & 0xff);
   2467 	printf("      Table Size: %d\n", PCI_MSIX_CTL_TBLSIZE(reg));
   2468 	onoff("Function Mask", reg, PCI_MSIX_CTL_FUNCMASK);
   2469 	onoff("MSI-X Enable", reg, PCI_MSIX_CTL_ENABLE);
   2470 	reg = regs[o2i(capoff + PCI_MSIX_TBLOFFSET)];
   2471 	printf("    Table offset register: 0x%08x\n", reg);
   2472 	printf("      Table offset: 0x%08x\n",
   2473 	    (pcireg_t)(reg & PCI_MSIX_TBLOFFSET_MASK));
   2474 	printf("      BIR: 0x%x\n", (pcireg_t)(reg & PCI_MSIX_TBLBIR_MASK));
   2475 	reg = regs[o2i(capoff + PCI_MSIX_PBAOFFSET)];
   2476 	printf("    Pending bit array register: 0x%08x\n", reg);
   2477 	printf("      Pending bit array offset: 0x%08x\n",
   2478 	    (pcireg_t)(reg & PCI_MSIX_PBAOFFSET_MASK));
   2479 	printf("      BIR: 0x%x\n", (pcireg_t)(reg & PCI_MSIX_PBABIR_MASK));
   2480 }
   2481 
   2482 static void
   2483 pci_conf_print_sata_cap(const pcireg_t *regs, int capoff)
   2484 {
   2485 	pcireg_t reg;
   2486 
   2487 	printf("\n  Serial ATA Capability Register\n");
   2488 
   2489 	reg = regs[o2i(capoff + PCI_SATA_REV)];
   2490 	printf("    Revision register: 0x%04x\n", (reg >> 16) & 0xff);
   2491 	printf("      Revision: %u.%u\n",
   2492 	    PCIREG_SHIFTOUT(reg, PCI_SATA_REV_MAJOR),
   2493 	    PCIREG_SHIFTOUT(reg, PCI_SATA_REV_MINOR));
   2494 
   2495 	reg = regs[o2i(capoff + PCI_SATA_BAR)];
   2496 
   2497 	printf("    BAR Register: 0x%08x\n", reg);
   2498 	printf("      Register location: ");
   2499 	if ((reg & PCI_SATA_BAR_SPEC) == PCI_SATA_BAR_INCONF)
   2500 		printf("in config space\n");
   2501 	else {
   2502 		printf("BAR %d\n", (int)PCI_SATA_BAR_NUM(reg));
   2503 		printf("      BAR offset: 0x%08x\n",
   2504 		    PCIREG_SHIFTOUT(reg, PCI_SATA_BAR_OFFSET) * 4);
   2505 	}
   2506 }
   2507 
   2508 static void
   2509 pci_conf_print_pciaf_cap(const pcireg_t *regs, int capoff)
   2510 {
   2511 	pcireg_t reg;
   2512 
   2513 	printf("\n  Advanced Features Capability Register\n");
   2514 
   2515 	reg = regs[o2i(capoff + PCI_AFCAPR)];
   2516 	printf("    AF Capabilities register: 0x%02x\n", (reg >> 24) & 0xff);
   2517 	printf("    AF Structure Length: 0x%02x\n",
   2518 	    PCIREG_SHIFTOUT(reg, PCI_AF_LENGTH));
   2519 	onoff("Transaction Pending", reg, PCI_AF_TP_CAP);
   2520 	onoff("Function Level Reset", reg, PCI_AF_FLR_CAP);
   2521 	reg = regs[o2i(capoff + PCI_AFCSR)];
   2522 	printf("    AF Control register: 0x%02x\n", reg & 0xff);
   2523 	/*
   2524 	 * Only PCI_AFCR_INITIATE_FLR is a member of the AF control register
   2525 	 * and it's always 0 on read
   2526 	 */
   2527 	printf("    AF Status register: 0x%02x\n", (reg >> 8) & 0xff);
   2528 	onoff("Transaction Pending", reg, PCI_AFSR_TP);
   2529 }
   2530 
   2531 static void
   2532 pci_conf_print_ea_cap_prop(unsigned int prop)
   2533 {
   2534 
   2535 	switch (prop) {
   2536 	case PCI_EA_PROP_MEM_NONPREF:
   2537 		printf("Memory Space, Non-Prefetchable\n");
   2538 		break;
   2539 	case PCI_EA_PROP_MEM_PREF:
   2540 		printf("Memory Space, Prefetchable\n");
   2541 		break;
   2542 	case PCI_EA_PROP_IO:
   2543 		printf("I/O Space\n");
   2544 		break;
   2545 	case PCI_EA_PROP_VF_MEM_NONPREF:
   2546 		printf("Resorce for VF use, Memory Space, Non-Prefetchable\n");
   2547 		break;
   2548 	case PCI_EA_PROP_VF_MEM_PREF:
   2549 		printf("Resorce for VF use, Memory Space, Prefetch\n");
   2550 		break;
   2551 	case PCI_EA_PROP_BB_MEM_NONPREF:
   2552 		printf("Behind the Bridge, Memory Space, Non-Pref\n");
   2553 		break;
   2554 	case PCI_EA_PROP_BB_MEM_PREF:
   2555 		printf("Behind the Bridge, Memory Space. Prefetchable\n");
   2556 		break;
   2557 	case PCI_EA_PROP_BB_IO:
   2558 		printf("Behind Bridge, I/O Space\n");
   2559 		break;
   2560 	case PCI_EA_PROP_MEM_UNAVAIL:
   2561 		printf("Memory Space Unavailable\n");
   2562 		break;
   2563 	case PCI_EA_PROP_IO_UNAVAIL:
   2564 		printf("IO Space Unavailable\n");
   2565 		break;
   2566 	case PCI_EA_PROP_UNAVAIL:
   2567 		printf("Entry Unavailable for use\n");
   2568 		break;
   2569 	default:
   2570 		printf("Reserved\n");
   2571 		break;
   2572 	}
   2573 }
   2574 
   2575 static void
   2576 pci_conf_print_ea_cap(const pcireg_t *regs, int capoff)
   2577 {
   2578 	pcireg_t reg, reg2;
   2579 	unsigned int entries, entoff, i;
   2580 
   2581 	printf("\n  Enhanced Allocation Capability Register\n");
   2582 
   2583 	reg = regs[o2i(capoff + PCI_EA_CAP1)];
   2584 	printf("    EA Num Entries register: 0x%04x\n", reg >> 16);
   2585 	entries = PCIREG_SHIFTOUT(reg, PCI_EA_CAP1_NUMENTRIES);
   2586 	printf("      EA Num Entries: %u\n", entries);
   2587 
   2588 	/* Type 1 only */
   2589 	if (PCI_HDRTYPE_TYPE(regs[o2i(PCI_BHLC_REG)]) == PCI_HDRTYPE_PPB) {
   2590 		reg = regs[o2i(capoff + PCI_EA_CAP2)];
   2591 		printf("    EA Capability Second register: 0x%08x\n", reg);
   2592 		printf("      Fixed Secondary Bus Number: %hhu\n",
   2593 		    (uint8_t)PCIREG_SHIFTOUT(reg, PCI_EA_CAP2_SECONDARY));
   2594 		printf("      Fixed Subordinate Bus Number: %hhu\n",
   2595 		    (uint8_t)PCIREG_SHIFTOUT(reg, PCI_EA_CAP2_SUBORDINATE));
   2596 		entoff = capoff + 8;
   2597 	} else
   2598 		entoff = capoff + 4;
   2599 
   2600 	for (i = 0; i < entries; i++) {
   2601 		uint64_t base, offset;
   2602 		bool baseis64, offsetis64;
   2603 		unsigned int bei, entry_size;
   2604 
   2605 		printf("    Entry %u:\n", i);
   2606 		/* The first DW */
   2607 		reg = regs[o2i(entoff)];
   2608 		printf("      The first register: 0x%08x\n", reg);
   2609 		entry_size = PCIREG_SHIFTOUT(reg, PCI_EA_ES);
   2610 		printf("        Entry size: %u\n", entry_size);
   2611 		printf("        BAR Equivalent Indicator: ");
   2612 		bei = PCIREG_SHIFTOUT(reg, PCI_EA_BEI);
   2613 		switch (bei) {
   2614 		case PCI_EA_BEI_BAR0:
   2615 		case PCI_EA_BEI_BAR1:
   2616 		case PCI_EA_BEI_BAR2:
   2617 		case PCI_EA_BEI_BAR3:
   2618 		case PCI_EA_BEI_BAR4:
   2619 		case PCI_EA_BEI_BAR5:
   2620 			printf("BAR %u\n", bei - PCI_EA_BEI_BAR0);
   2621 			break;
   2622 		case PCI_EA_BEI_BEHIND:
   2623 			printf("Behind the function\n");
   2624 			break;
   2625 		case PCI_EA_BEI_NOTIND:
   2626 			printf("Not Indicated\n");
   2627 			break;
   2628 		case PCI_EA_BEI_EXPROM:
   2629 			printf("Expansion ROM\n");
   2630 			break;
   2631 		case PCI_EA_BEI_VFBAR0:
   2632 		case PCI_EA_BEI_VFBAR1:
   2633 		case PCI_EA_BEI_VFBAR2:
   2634 		case PCI_EA_BEI_VFBAR3:
   2635 		case PCI_EA_BEI_VFBAR4:
   2636 		case PCI_EA_BEI_VFBAR5:
   2637 			printf("VF BAR %u\n", bei - PCI_EA_BEI_VFBAR0);
   2638 			break;
   2639 		case PCI_EA_BEI_RESERVED:
   2640 		default:
   2641 			printf("Reserved\n");
   2642 			break;
   2643 		}
   2644 
   2645 		printf("      Primary Properties: ");
   2646 		pci_conf_print_ea_cap_prop(PCIREG_SHIFTOUT(reg, PCI_EA_PP));
   2647 		printf("      Secondary Properties: ");
   2648 		pci_conf_print_ea_cap_prop(PCIREG_SHIFTOUT(reg, PCI_EA_SP));
   2649 		onoff("Writable", reg, PCI_EA_W);
   2650 		onoff("Enable for this entry", reg, PCI_EA_E);
   2651 
   2652 		if (entry_size == 0) {
   2653 			entoff += 4;
   2654 			continue;
   2655 		}
   2656 
   2657 		/* Base addr */
   2658 		reg = regs[o2i(entoff + 4)];
   2659 		base = reg & PCI_EA_LOWMASK;
   2660 		baseis64 = reg & PCI_EA_BASEMAXOFFSET_64BIT;
   2661 		printf("      Base Address Register Low: 0x%08x\n", reg);
   2662 		if (baseis64) {
   2663 			/* 64bit */
   2664 			reg2 = regs[o2i(entoff + 12)];
   2665 			printf("      Base Address Register high: 0x%08x\n",
   2666 			    reg2);
   2667 			base |= (uint64_t)reg2 << 32;
   2668 		}
   2669 
   2670 		/* Offset addr */
   2671 		reg = regs[o2i(entoff + 8)];
   2672 		offset = reg & PCI_EA_LOWMASK;
   2673 		offsetis64 = reg & PCI_EA_BASEMAXOFFSET_64BIT;
   2674 		printf("      Max Offset Register Low: 0x%08x\n", reg);
   2675 		if (offsetis64) {
   2676 			/* 64bit */
   2677 			reg2 = regs[o2i(entoff + (baseis64 ? 16 : 12))];
   2678 			printf("      Max Offset Register high: 0x%08x\n",
   2679 			    reg2);
   2680 			offset |= (uint64_t)reg2 << 32;
   2681 		}
   2682 
   2683 		printf("        range: 0x%016" PRIx64 "-0x%016" PRIx64
   2684 			    "\n", base, base + offset);
   2685 
   2686 		entoff += 4 + (4 * entry_size);
   2687 	}
   2688 }
   2689 
   2690 /* XXX pci_conf_print_fpb_cap */
   2691 
   2692 static struct {
   2693 	pcireg_t cap;
   2694 	const char *name;
   2695 	void (*printfunc)(const pcireg_t *, int);
   2696 } pci_captab[] = {
   2697 	{ PCI_CAP_RESERVED0,	"reserved",	NULL },
   2698 	{ PCI_CAP_PWRMGMT,	"Power Management", pci_conf_print_pcipm_cap },
   2699 	{ PCI_CAP_AGP,		"AGP",		pci_conf_print_agp_cap },
   2700 	{ PCI_CAP_VPD,		"VPD",		NULL },
   2701 	{ PCI_CAP_SLOTID,	"SlotID",	NULL },
   2702 	{ PCI_CAP_MSI,		"MSI",		pci_conf_print_msi_cap },
   2703 	{ PCI_CAP_CPCI_HOTSWAP,	"CompactPCI Hot-swapping", NULL },
   2704 	{ PCI_CAP_PCIX,		"PCI-X",	pci_conf_print_pcix_cap },
   2705 	{ PCI_CAP_LDT,		"HyperTransport", pci_conf_print_ht_cap },
   2706 	{ PCI_CAP_VENDSPEC,	"Vendor-specific",
   2707 	  pci_conf_print_vendspec_cap },
   2708 	{ PCI_CAP_DEBUGPORT,	"Debug Port",	pci_conf_print_debugport_cap },
   2709 	{ PCI_CAP_CPCI_RSRCCTL, "CompactPCI Resource Control", NULL },
   2710 	{ PCI_CAP_HOTPLUG,	"Hot-Plug",	NULL },
   2711 	{ PCI_CAP_SUBVENDOR,	"Subsystem vendor ID",
   2712 	  pci_conf_print_subsystem_cap },
   2713 	{ PCI_CAP_AGP8,		"AGP 8x",	NULL },
   2714 	{ PCI_CAP_SECURE,	"Secure Device", pci_conf_print_secure_cap },
   2715 	{ PCI_CAP_PCIEXPRESS,	"PCI Express",	pci_conf_print_pcie_cap },
   2716 	{ PCI_CAP_MSIX,		"MSI-X",	pci_conf_print_msix_cap },
   2717 	{ PCI_CAP_SATA,		"SATA",		pci_conf_print_sata_cap },
   2718 	{ PCI_CAP_PCIAF,	"Advanced Features", pci_conf_print_pciaf_cap},
   2719 	{ PCI_CAP_EA,		"Enhanced Allocation", pci_conf_print_ea_cap },
   2720 	{ PCI_CAP_FPB,		"Flattening Portal Bridge", NULL }
   2721 };
   2722 
   2723 static int
   2724 pci_conf_find_cap(const pcireg_t *regs, unsigned int capid, int *offsetp)
   2725 {
   2726 	pcireg_t rval;
   2727 	unsigned int capptr;
   2728 	int off;
   2729 
   2730 	if (!(regs[o2i(PCI_COMMAND_STATUS_REG)] & PCI_STATUS_CAPLIST_SUPPORT))
   2731 		return 0;
   2732 
   2733 	/* Determine the Capability List Pointer register to start with. */
   2734 	switch (PCI_HDRTYPE_TYPE(regs[o2i(PCI_BHLC_REG)])) {
   2735 	case 0:	/* standard device header */
   2736 	case 1: /* PCI-PCI bridge header */
   2737 		capptr = PCI_CAPLISTPTR_REG;
   2738 		break;
   2739 	case 2:	/* PCI-CardBus Bridge header */
   2740 		capptr = PCI_CARDBUS_CAPLISTPTR_REG;
   2741 		break;
   2742 	default:
   2743 		return 0;
   2744 	}
   2745 
   2746 	for (off = PCI_CAPLIST_PTR(regs[o2i(capptr)]);
   2747 	     off != 0; off = PCI_CAPLIST_NEXT(rval)) {
   2748 		rval = regs[o2i(off)];
   2749 		if (capid == PCI_CAPLIST_CAP(rval)) {
   2750 			if (offsetp != NULL)
   2751 				*offsetp = off;
   2752 			return 1;
   2753 		}
   2754 	}
   2755 	return 0;
   2756 }
   2757 
   2758 static void
   2759 pci_conf_print_caplist(
   2760 #ifdef _KERNEL
   2761     pci_chipset_tag_t pc, pcitag_t tag,
   2762 #endif
   2763     const pcireg_t *regs, int capoff)
   2764 {
   2765 	int off;
   2766 	pcireg_t foundcap;
   2767 	pcireg_t rval;
   2768 	bool foundtable[__arraycount(pci_captab)];
   2769 	unsigned int i;
   2770 
   2771 	/* Clear table */
   2772 	for (i = 0; i < __arraycount(pci_captab); i++)
   2773 		foundtable[i] = false;
   2774 
   2775 	/* Print capability register's offset and the type first */
   2776 	for (off = PCI_CAPLIST_PTR(regs[o2i(capoff)]);
   2777 	     off != 0; off = PCI_CAPLIST_NEXT(regs[o2i(off)])) {
   2778 		rval = regs[o2i(off)];
   2779 		printf("  Capability register at 0x%02x\n", off);
   2780 
   2781 		printf("    type: 0x%02x (", PCI_CAPLIST_CAP(rval));
   2782 		foundcap = PCI_CAPLIST_CAP(rval);
   2783 		if (foundcap < __arraycount(pci_captab)) {
   2784 			printf("%s)\n", pci_captab[foundcap].name);
   2785 			/* Mark as found */
   2786 			foundtable[foundcap] = true;
   2787 		} else
   2788 			printf("unknown)\n");
   2789 	}
   2790 
   2791 	/*
   2792 	 * And then, print the detail of each capability registers
   2793 	 * in capability value's order.
   2794 	 */
   2795 	for (i = 0; i < __arraycount(pci_captab); i++) {
   2796 		if (foundtable[i] == false)
   2797 			continue;
   2798 
   2799 		/*
   2800 		 * The type was found. Search capability list again and
   2801 		 * print all capabilities that the capability type is
   2802 		 * the same. This is required because some capabilities
   2803 		 * appear multiple times (e.g. HyperTransport capability).
   2804 		 */
   2805 		for (off = PCI_CAPLIST_PTR(regs[o2i(capoff)]);
   2806 		     off != 0; off = PCI_CAPLIST_NEXT(regs[o2i(off)])) {
   2807 			rval = regs[o2i(off)];
   2808 			if ((PCI_CAPLIST_CAP(rval) == i)
   2809 			    && (pci_captab[i].printfunc != NULL))
   2810 				pci_captab[i].printfunc(regs, off);
   2811 		}
   2812 	}
   2813 }
   2814 
   2815 /* Extended Capability */
   2816 
   2817 static void
   2818 pci_conf_print_aer_cap_uc(pcireg_t reg)
   2819 {
   2820 
   2821 	onoff("Undefined", reg, PCI_AER_UC_UNDEFINED);
   2822 	onoff("Data Link Protocol Error", reg, PCI_AER_UC_DL_PROTOCOL_ERROR);
   2823 	onoff("Surprise Down Error", reg, PCI_AER_UC_SURPRISE_DOWN_ERROR);
   2824 	onoff("Poisoned TLP Received", reg, PCI_AER_UC_POISONED_TLP);
   2825 	onoff("Flow Control Protocol Error", reg, PCI_AER_UC_FC_PROTOCOL_ERROR);
   2826 	onoff("Completion Timeout", reg, PCI_AER_UC_COMPLETION_TIMEOUT);
   2827 	onoff("Completer Abort", reg, PCI_AER_UC_COMPLETER_ABORT);
   2828 	onoff("Unexpected Completion", reg, PCI_AER_UC_UNEXPECTED_COMPLETION);
   2829 	onoff("Receiver Overflow", reg, PCI_AER_UC_RECEIVER_OVERFLOW);
   2830 	onoff("Malformed TLP", reg, PCI_AER_UC_MALFORMED_TLP);
   2831 	onoff("ECRC Error", reg, PCI_AER_UC_ECRC_ERROR);
   2832 	onoff("Unsupported Request Error", reg,
   2833 	    PCI_AER_UC_UNSUPPORTED_REQUEST_ERROR);
   2834 	onoff("ACS Violation", reg, PCI_AER_UC_ACS_VIOLATION);
   2835 	onoff("Uncorrectable Internal Error", reg, PCI_AER_UC_INTERNAL_ERROR);
   2836 	onoff("MC Blocked TLP", reg, PCI_AER_UC_MC_BLOCKED_TLP);
   2837 	onoff("AtomicOp Egress BLK", reg, PCI_AER_UC_ATOMIC_OP_EGRESS_BLOCKED);
   2838 	onoff("TLP Prefix Blocked Error", reg,
   2839 	    PCI_AER_UC_TLP_PREFIX_BLOCKED_ERROR);
   2840 	onoff("Poisoned TLP Egress Blocked", reg,
   2841 	    PCI_AER_UC_POISONTLP_EGRESS_BLOCKED);
   2842 }
   2843 
   2844 static void
   2845 pci_conf_print_aer_cap_cor(pcireg_t reg)
   2846 {
   2847 
   2848 	onoff("Receiver Error", reg, PCI_AER_COR_RECEIVER_ERROR);
   2849 	onoff("Bad TLP", reg, PCI_AER_COR_BAD_TLP);
   2850 	onoff("Bad DLLP", reg, PCI_AER_COR_BAD_DLLP);
   2851 	onoff("REPLAY_NUM Rollover", reg, PCI_AER_COR_REPLAY_NUM_ROLLOVER);
   2852 	onoff("Replay Timer Timeout", reg, PCI_AER_COR_REPLAY_TIMER_TIMEOUT);
   2853 	onoff("Advisory Non-Fatal Error", reg, PCI_AER_COR_ADVISORY_NF_ERROR);
   2854 	onoff("Corrected Internal Error", reg, PCI_AER_COR_INTERNAL_ERROR);
   2855 	onoff("Header Log Overflow", reg, PCI_AER_COR_HEADER_LOG_OVERFLOW);
   2856 }
   2857 
   2858 static void
   2859 pci_conf_print_aer_cap_control(pcireg_t reg, bool *tlp_prefix_log)
   2860 {
   2861 
   2862 	printf("      First Error Pointer: 0x%04x\n",
   2863 	    PCIREG_SHIFTOUT(reg, PCI_AER_FIRST_ERROR_PTR));
   2864 	onoff("ECRC Generation Capable", reg, PCI_AER_ECRC_GEN_CAPABLE);
   2865 	onoff("ECRC Generation Enable", reg, PCI_AER_ECRC_GEN_ENABLE);
   2866 	onoff("ECRC Check Capable", reg, PCI_AER_ECRC_CHECK_CAPABLE);
   2867 	onoff("ECRC Check Enable", reg, PCI_AER_ECRC_CHECK_ENABLE);
   2868 	onoff("Multiple Header Recording Capable", reg,
   2869 	    PCI_AER_MULT_HDR_CAPABLE);
   2870 	onoff("Multiple Header Recording Enable", reg,PCI_AER_MULT_HDR_ENABLE);
   2871 	onoff("Completion Timeout Prefix/Header Log Capable", reg,
   2872 	    PCI_AER_COMPTOUTPRFXHDRLOG_CAP);
   2873 
   2874 	/* This bit is RsvdP if the End-End TLP Prefix Supported bit is Clear */
   2875 	if (!tlp_prefix_log)
   2876 		return;
   2877 	onoff("TLP Prefix Log Present", reg, PCI_AER_TLP_PREFIX_LOG_PRESENT);
   2878 	*tlp_prefix_log = (reg & PCI_AER_TLP_PREFIX_LOG_PRESENT) ? true : false;
   2879 }
   2880 
   2881 static void
   2882 pci_conf_print_aer_cap_rooterr_cmd(pcireg_t reg)
   2883 {
   2884 
   2885 	onoff("Correctable Error Reporting Enable", reg,
   2886 	    PCI_AER_ROOTERR_COR_ENABLE);
   2887 	onoff("Non-Fatal Error Reporting Enable", reg,
   2888 	    PCI_AER_ROOTERR_NF_ENABLE);
   2889 	onoff("Fatal Error Reporting Enable", reg, PCI_AER_ROOTERR_F_ENABLE);
   2890 }
   2891 
   2892 static void
   2893 pci_conf_print_aer_cap_rooterr_status(pcireg_t reg)
   2894 {
   2895 
   2896 	onoff("ERR_COR Received", reg, PCI_AER_ROOTERR_COR_ERR);
   2897 	onoff("Multiple ERR_COR Received", reg, PCI_AER_ROOTERR_MULTI_COR_ERR);
   2898 	onoff("ERR_FATAL/NONFATAL_ERR Received", reg, PCI_AER_ROOTERR_UC_ERR);
   2899 	onoff("Multiple ERR_FATAL/NONFATAL_ERR Received", reg,
   2900 	    PCI_AER_ROOTERR_MULTI_UC_ERR);
   2901 	onoff("First Uncorrectable Fatal", reg,PCI_AER_ROOTERR_FIRST_UC_FATAL);
   2902 	onoff("Non-Fatal Error Messages Received", reg,PCI_AER_ROOTERR_NF_ERR);
   2903 	onoff("Fatal Error Messages Received", reg, PCI_AER_ROOTERR_F_ERR);
   2904 	printf("      Advanced Error Interrupt Message Number: 0x%02x\n",
   2905 	    PCIREG_SHIFTOUT(reg, PCI_AER_ROOTERR_INT_MESSAGE));
   2906 }
   2907 
   2908 static void
   2909 pci_conf_print_aer_cap_errsrc_id(pcireg_t reg)
   2910 {
   2911 
   2912 	printf("      Correctable Source ID: 0x%04x\n",
   2913 	    PCIREG_SHIFTOUT(reg, PCI_AER_ERRSRC_ID_ERR_COR));
   2914 	printf("      ERR_FATAL/NONFATAL Source ID: 0x%04x\n",
   2915 	    PCIREG_SHIFTOUT(reg, PCI_AER_ERRSRC_ID_ERR_UC));
   2916 }
   2917 
   2918 static void
   2919 pci_conf_print_aer_cap(const pcireg_t *regs, int extcapoff)
   2920 {
   2921 	pcireg_t reg;
   2922 	int pcie_capoff;
   2923 	int pcie_devtype = -1;
   2924 	bool tlp_prefix_log = false;
   2925 
   2926 	if (pci_conf_find_cap(regs, PCI_CAP_PCIEXPRESS, &pcie_capoff)) {
   2927 		reg = regs[o2i(pcie_capoff)];
   2928 		pcie_devtype = PCIE_XCAP_TYPE(reg);
   2929 		/* PCIe DW9 to DW14 is for PCIe 2.0 and newer */
   2930 		if (PCIREG_SHIFTOUT(reg, PCIE_XCAP_VER_MASK) >= 2) {
   2931 			reg = regs[o2i(pcie_capoff + PCIE_DCAP2)];
   2932 			/* End-End TLP Prefix Supported */
   2933 			if (reg & PCIE_DCAP2_EETLP_PREF) {
   2934 				tlp_prefix_log = true;
   2935 			}
   2936 		}
   2937 	}
   2938 
   2939 	printf("\n  Advanced Error Reporting Register\n");
   2940 
   2941 	reg = regs[o2i(extcapoff + PCI_AER_UC_STATUS)];
   2942 	printf("    Uncorrectable Error Status register: 0x%08x\n", reg);
   2943 	pci_conf_print_aer_cap_uc(reg);
   2944 	reg = regs[o2i(extcapoff + PCI_AER_UC_MASK)];
   2945 	printf("    Uncorrectable Error Mask register: 0x%08x\n", reg);
   2946 	pci_conf_print_aer_cap_uc(reg);
   2947 	reg = regs[o2i(extcapoff + PCI_AER_UC_SEVERITY)];
   2948 	printf("    Uncorrectable Error Severity register: 0x%08x\n", reg);
   2949 	pci_conf_print_aer_cap_uc(reg);
   2950 
   2951 	reg = regs[o2i(extcapoff + PCI_AER_COR_STATUS)];
   2952 	printf("    Correctable Error Status register: 0x%08x\n", reg);
   2953 	pci_conf_print_aer_cap_cor(reg);
   2954 	reg = regs[o2i(extcapoff + PCI_AER_COR_MASK)];
   2955 	printf("    Correctable Error Mask register: 0x%08x\n", reg);
   2956 	pci_conf_print_aer_cap_cor(reg);
   2957 
   2958 	reg = regs[o2i(extcapoff + PCI_AER_CAP_CONTROL)];
   2959 	printf("    Advanced Error Capabilities and Control register: 0x%08x\n",
   2960 	    reg);
   2961 	pci_conf_print_aer_cap_control(reg, &tlp_prefix_log);
   2962 	reg = regs[o2i(extcapoff + PCI_AER_HEADER_LOG)];
   2963 	printf("    Header Log register:\n");
   2964 	pci_conf_print_regs(regs, extcapoff + PCI_AER_HEADER_LOG,
   2965 	    extcapoff + PCI_AER_ROOTERR_CMD);
   2966 
   2967 	switch (pcie_devtype) {
   2968 	case PCIE_XCAP_TYPE_RP:	/* Root Port of PCI Express Root Complex */
   2969 	case PCIE_XCAP_TYPE_RC_EVNTC:	/* Root Complex Event Collector */
   2970 		reg = regs[o2i(extcapoff + PCI_AER_ROOTERR_CMD)];
   2971 		printf("    Root Error Command register: 0x%08x\n", reg);
   2972 		pci_conf_print_aer_cap_rooterr_cmd(reg);
   2973 		reg = regs[o2i(extcapoff + PCI_AER_ROOTERR_STATUS)];
   2974 		printf("    Root Error Status register: 0x%08x\n", reg);
   2975 		pci_conf_print_aer_cap_rooterr_status(reg);
   2976 
   2977 		reg = regs[o2i(extcapoff + PCI_AER_ERRSRC_ID)];
   2978 		printf("    Error Source Identification register: 0x%08x\n",
   2979 		    reg);
   2980 		pci_conf_print_aer_cap_errsrc_id(reg);
   2981 		break;
   2982 	}
   2983 
   2984 	if (tlp_prefix_log) {
   2985 		reg = regs[o2i(extcapoff + PCI_AER_TLP_PREFIX_LOG)];
   2986 		printf("    TLP Prefix Log register: 0x%08x\n", reg);
   2987 	}
   2988 }
   2989 
   2990 /*
   2991  * Helper function to print the arbitration phase register.
   2992  *
   2993  * phases: Number of phases in the arbitration tables.
   2994  * arbsize: Number of bits in each phase.
   2995  * indent: Add more two spaces if it's true.
   2996  */
   2997 static void
   2998 pci_conf_print_vc_cap_arbtab(const pcireg_t *regs, int off, const char *name,
   2999     const int phases, int arbsize, bool indent)
   3000 {
   3001 	pcireg_t reg;
   3002 	int num_per_reg = 32 / arbsize;
   3003 	int i, j;
   3004 
   3005 	printf("%s    %s Arbitration Table:\n", indent ? "  " : "", name);
   3006 	for (i = 0; i < phases; i += num_per_reg) {
   3007 		reg = regs[o2i(off + (sizeof(uint32_t) * (i / num_per_reg)))];
   3008 		for (j = 0; j < num_per_reg; j++) {
   3009 			printf("%s      Phase[%d]: 0x%x\n", indent ? "  " : "",
   3010 			    i + j,
   3011 			    (uint32_t)(reg & __BITS(arbsize - 1, 0)));
   3012 			reg >>= arbsize;
   3013 		}
   3014 	}
   3015 }
   3016 
   3017 /* For VC, bit 4-7 are reserved. For Port, bit 6-7 are reserved */
   3018 static const int arb_phases[8] = {0, 32, 64, 128, 128, 256, 0, 0 };
   3019 
   3020 static void
   3021 pci_conf_print_vc_cap(const pcireg_t *regs, int extcapoff)
   3022 {
   3023 	pcireg_t reg, n;
   3024 	int arbtab, parbsize;
   3025 	pcireg_t arbsel;
   3026 	int i, count;
   3027 
   3028 	printf("\n  Virtual Channel Register\n");
   3029 	reg = regs[o2i(extcapoff + PCI_VC_CAP1)];
   3030 	printf("    Port VC Capability register 1: 0x%08x\n", reg);
   3031 	count = PCIREG_SHIFTOUT(reg, PCI_VC_CAP1_EXT_COUNT);
   3032 	printf("      Extended VC Count: %d\n", count);
   3033 	n = PCIREG_SHIFTOUT(reg, PCI_VC_CAP1_LOWPRI_EXT_COUNT);
   3034 	printf("      Low Priority Extended VC Count: %u\n", n);
   3035 	n = PCIREG_SHIFTOUT(reg, PCI_VC_CAP1_REFCLK);
   3036 	printf("      Reference Clock: %s\n",
   3037 	    (n == PCI_VC_CAP1_REFCLK_100NS) ? "100ns" : "unknown");
   3038 	parbsize = 1 << PCIREG_SHIFTOUT(reg, PCI_VC_CAP1_PORT_ARB_TABLE_SIZE);
   3039 	printf("      Port Arbitration Table Entry Size: %dbit\n", parbsize);
   3040 
   3041 	reg = regs[o2i(extcapoff + PCI_VC_CAP2)];
   3042 	printf("    Port VC Capability register 2: 0x%08x\n", reg);
   3043 	onoff("Hardware fixed arbitration scheme",
   3044 	    reg, PCI_VC_CAP2_ARB_CAP_HW_FIXED_SCHEME);
   3045 	onoff("WRR arbitration with 32 phases",
   3046 	    reg, PCI_VC_CAP2_ARB_CAP_WRR_32);
   3047 	onoff("WRR arbitration with 64 phases",
   3048 	    reg, PCI_VC_CAP2_ARB_CAP_WRR_64);
   3049 	onoff("WRR arbitration with 128 phases",
   3050 	    reg, PCI_VC_CAP2_ARB_CAP_WRR_128);
   3051 	arbtab = PCIREG_SHIFTOUT(reg, PCI_VC_CAP2_ARB_TABLE_OFFSET);
   3052 	printf("      VC Arbitration Table Offset: 0x%x\n", arbtab);
   3053 
   3054 	reg = regs[o2i(extcapoff + PCI_VC_CONTROL)] & 0xffff;
   3055 	printf("    Port VC Control register: 0x%04x\n", reg);
   3056 	arbsel = PCIREG_SHIFTOUT(reg, PCI_VC_CONTROL_VC_ARB_SELECT);
   3057 	printf("      VC Arbitration Select: 0x%x\n", arbsel);
   3058 
   3059 	reg = regs[o2i(extcapoff + PCI_VC_STATUS)] >> 16;
   3060 	printf("    Port VC Status register: 0x%04x\n", reg);
   3061 	onoff("VC Arbitration Table Status",
   3062 	    reg, PCI_VC_STATUS_LOAD_VC_ARB_TABLE);
   3063 
   3064 	if ((arbtab != 0) && (arbsel != 0))
   3065 		pci_conf_print_vc_cap_arbtab(regs, extcapoff + (arbtab * 16),
   3066 		    "VC", arb_phases[arbsel], 4, false);
   3067 
   3068 	for (i = 0; i < count + 1; i++) {
   3069 		reg = regs[o2i(extcapoff + PCI_VC_RESOURCE_CAP(i))];
   3070 		printf("    VC number %d\n", i);
   3071 		printf("      VC Resource Capability Register: 0x%08x\n", reg);
   3072 		onoff("  Non-configurable Hardware fixed arbitration scheme",
   3073 		    reg, PCI_VC_RESOURCE_CAP_PORT_ARB_CAP_HW_FIXED_SCHEME);
   3074 		onoff("  WRR arbitration with 32 phases",
   3075 		    reg, PCI_VC_RESOURCE_CAP_PORT_ARB_CAP_WRR_32);
   3076 		onoff("  WRR arbitration with 64 phases",
   3077 		    reg, PCI_VC_RESOURCE_CAP_PORT_ARB_CAP_WRR_64);
   3078 		onoff("  WRR arbitration with 128 phases",
   3079 		    reg, PCI_VC_RESOURCE_CAP_PORT_ARB_CAP_WRR_128);
   3080 		onoff("  Time-based WRR arbitration with 128 phases",
   3081 		    reg, PCI_VC_RESOURCE_CAP_PORT_ARB_CAP_TWRR_128);
   3082 		onoff("  WRR arbitration with 256 phases",
   3083 		    reg, PCI_VC_RESOURCE_CAP_PORT_ARB_CAP_WRR_256);
   3084 		onoff("  Advanced Packet Switching",
   3085 		    reg, PCI_VC_RESOURCE_CAP_ADV_PKT_SWITCH);
   3086 		onoff("  Reject Snoop Transaction",
   3087 		    reg, PCI_VC_RESOURCE_CAP_REJCT_SNOOP_TRANS);
   3088 		n = PCIREG_SHIFTOUT(reg, PCI_VC_RESOURCE_CAP_MAX_TIME_SLOTS) + 1;
   3089 		printf("        Maximum Time Slots: %d\n", n);
   3090 		arbtab = PCIREG_SHIFTOUT(reg,
   3091 		    PCI_VC_RESOURCE_CAP_PORT_ARB_TABLE_OFFSET);
   3092 		printf("        Port Arbitration Table offset: 0x%02x\n",
   3093 		    arbtab);
   3094 
   3095 		reg = regs[o2i(extcapoff + PCI_VC_RESOURCE_CTL(i))];
   3096 		printf("      VC Resource Control Register: 0x%08x\n", reg);
   3097 		printf("        TC/VC Map: 0x%02x\n",
   3098 		    PCIREG_SHIFTOUT(reg, PCI_VC_RESOURCE_CTL_TCVC_MAP));
   3099 		/*
   3100 		 * The load Port Arbitration Table bit is used to update
   3101 		 * the Port Arbitration logic and it's always 0 on read, so
   3102 		 * we don't print it.
   3103 		 */
   3104 		arbsel = PCIREG_SHIFTOUT(reg, PCI_VC_RESOURCE_CTL_PORT_ARB_SELECT);
   3105 		printf("        Port Arbitration Select: 0x%x\n", arbsel);
   3106 		n = PCIREG_SHIFTOUT(reg, PCI_VC_RESOURCE_CTL_VC_ID);
   3107 		printf("        VC ID: %d\n", n);
   3108 		onoff("  VC Enable", reg, PCI_VC_RESOURCE_CTL_VC_ENABLE);
   3109 
   3110 		reg = regs[o2i(extcapoff + PCI_VC_RESOURCE_STA(i))] >> 16;
   3111 		printf("      VC Resource Status Register: 0x%08x\n", reg);
   3112 		onoff("  Port Arbitration Table Status",
   3113 		    reg, PCI_VC_RESOURCE_STA_PORT_ARB_TABLE);
   3114 		onoff("  VC Negotiation Pending",
   3115 		    reg, PCI_VC_RESOURCE_STA_VC_NEG_PENDING);
   3116 
   3117 		if ((arbtab != 0) && (arbsel != 0))
   3118 			pci_conf_print_vc_cap_arbtab(regs,
   3119 			    extcapoff + (arbtab * 16),
   3120 			    "Port", arb_phases[arbsel], parbsize, true);
   3121 	}
   3122 }
   3123 
   3124 /*
   3125  * Print Power limit. This encoding is the same among the following registers:
   3126  *  - The Captured Slot Power Limit in the PCIe Device Capability Register.
   3127  *  - The Slot Power Limit in the PCIe Slot Capability Register.
   3128  *  - The Base Power in the Data register of Power Budgeting capability.
   3129  */
   3130 static void
   3131 pci_conf_print_pcie_power(uint8_t base, unsigned int scale)
   3132 {
   3133 	unsigned int sdiv = 1;
   3134 
   3135 	if ((scale == 0) && (base > 0xef)) {
   3136 		const char *s;
   3137 
   3138 		switch (base) {
   3139 		case 0xf0:
   3140 			s = "239W < x <= 250W";
   3141 			break;
   3142 		case 0xf1:
   3143 			s = "250W < x <= 275W";
   3144 			break;
   3145 		case 0xf2:
   3146 			s = "275W < x <= 300W";
   3147 			break;
   3148 		default:
   3149 			s = "reserved for greater than 300W";
   3150 			break;
   3151 		}
   3152 		printf("%s\n", s);
   3153 		return;
   3154 	}
   3155 
   3156 	for (unsigned int i = scale; i > 0; i--)
   3157 		sdiv *= 10;
   3158 
   3159 	printf("%u", base / sdiv);
   3160 
   3161 	if (scale != 0) {
   3162 		printf(".%u", base % sdiv);
   3163 	}
   3164 	printf ("W\n");
   3165 	return;
   3166 }
   3167 
   3168 static const char *
   3169 pci_conf_print_pwrbdgt_type(uint8_t reg)
   3170 {
   3171 
   3172 	switch (reg) {
   3173 	case 0x00:
   3174 		return "PME Aux";
   3175 	case 0x01:
   3176 		return "Auxilary";
   3177 	case 0x02:
   3178 		return "Idle";
   3179 	case 0x03:
   3180 		return "Sustained";
   3181 	case 0x04:
   3182 		return "Sustained (Emergency Power Reduction)";
   3183 	case 0x05:
   3184 		return "Maximum (Emergency Power Reduction)";
   3185 	case 0x07:
   3186 		return "Maximum";
   3187 	default:
   3188 		return "Unknown";
   3189 	}
   3190 }
   3191 
   3192 static const char *
   3193 pci_conf_print_pwrbdgt_pwrrail(uint8_t reg)
   3194 {
   3195 
   3196 	switch (reg) {
   3197 	case 0x00:
   3198 		return "Power(12V)";
   3199 	case 0x01:
   3200 		return "Power(3.3V)";
   3201 	case 0x02:
   3202 		return "Power(1.5V or 1.8V)";
   3203 	case 0x07:
   3204 		return "Thermal";
   3205 	default:
   3206 		return "Unknown";
   3207 	}
   3208 }
   3209 
   3210 static void
   3211 pci_conf_print_pwrbdgt_cap(const pcireg_t *regs, int extcapoff)
   3212 {
   3213 	pcireg_t reg;
   3214 
   3215 	printf("\n  Power Budgeting\n");
   3216 
   3217 	reg = regs[o2i(extcapoff + PCI_PWRBDGT_DSEL)];
   3218 	printf("    Data Select register: 0x%08x\n", reg);
   3219 
   3220 	reg = regs[o2i(extcapoff + PCI_PWRBDGT_DATA)];
   3221 	printf("    Data register: 0x%08x\n", reg);
   3222 	printf("      Base Power: ");
   3223 	pci_conf_print_pcie_power(
   3224 	    PCIREG_SHIFTOUT(reg, PCI_PWRBDGT_DATA_BASEPWR),
   3225 	    PCIREG_SHIFTOUT(reg, PCI_PWRBDGT_DATA_SCALE));
   3226 	printf("      PM Sub State: 0x%hhx\n",
   3227 	    (uint8_t)PCIREG_SHIFTOUT(reg, PCI_PWRBDGT_PM_SUBSTAT));
   3228 	printf("      PM State: D%u\n",
   3229 	    PCIREG_SHIFTOUT(reg, PCI_PWRBDGT_PM_STAT));
   3230 	printf("      Type: %s\n",
   3231 	    pci_conf_print_pwrbdgt_type(
   3232 		    (uint8_t)(PCIREG_SHIFTOUT(reg, PCI_PWRBDGT_TYPE))));
   3233 	printf("      Power Rail: %s\n",
   3234 	    pci_conf_print_pwrbdgt_pwrrail(
   3235 		    (uint8_t)(PCIREG_SHIFTOUT(reg, PCI_PWRBDGT_PWRRAIL))));
   3236 
   3237 	reg = regs[o2i(extcapoff + PCI_PWRBDGT_CAP)];
   3238 	printf("    Power Budget Capability register: 0x%08x\n", reg);
   3239 	onoff("System Allocated",
   3240 	    reg, PCI_PWRBDGT_CAP_SYSALLOC);
   3241 }
   3242 
   3243 static const char *
   3244 pci_conf_print_rclink_dcl_cap_elmtype(unsigned char type)
   3245 {
   3246 
   3247 	switch (type) {
   3248 	case 0x00:
   3249 		return "Configuration Space Element";
   3250 	case 0x01:
   3251 		return "System Egress Port or internal sink (memory)";
   3252 	case 0x02:
   3253 		return "Internal Root Complex Link";
   3254 	default:
   3255 		return "Unknown";
   3256 	}
   3257 }
   3258 
   3259 static void
   3260 pci_conf_print_rclink_dcl_cap(const pcireg_t *regs, int extcapoff)
   3261 {
   3262 	pcireg_t reg;
   3263 	unsigned char nent, linktype;
   3264 	int i;
   3265 
   3266 	printf("\n  Root Complex Link Declaration\n");
   3267 
   3268 	reg = regs[o2i(extcapoff + PCI_RCLINK_DCL_ESDESC)];
   3269 	printf("    Element Self Description Register: 0x%08x\n", reg);
   3270 	printf("      Element Type: %s\n",
   3271 	    pci_conf_print_rclink_dcl_cap_elmtype((unsigned char)reg));
   3272 	nent = PCIREG_SHIFTOUT(reg, PCI_RCLINK_DCL_ESDESC_NUMLINKENT);
   3273 	printf("      Number of Link Entries: %hhu\n", nent);
   3274 	printf("      Component ID: %hhu\n",
   3275 	    (uint8_t)PCIREG_SHIFTOUT(reg, PCI_RCLINK_DCL_ESDESC_COMPID));
   3276 	printf("      Port Number: %hhu\n",
   3277 	    (uint8_t)PCIREG_SHIFTOUT(reg, PCI_RCLINK_DCL_ESDESC_PORTNUM));
   3278 	for (i = 0; i < nent; i++) {
   3279 		reg = regs[o2i(extcapoff + PCI_RCLINK_DCL_LINKDESC(i))];
   3280 		printf("    Link Entry %d:\n", i + 1);
   3281 		printf("      Link Description Register: 0x%08x\n", reg);
   3282 		onoff("  Link Valid", reg, PCI_RCLINK_DCL_LINKDESC_LVALID);
   3283 		linktype = reg & PCI_RCLINK_DCL_LINKDESC_LTYPE;
   3284 		onoff2("  Link Type", reg, PCI_RCLINK_DCL_LINKDESC_LTYPE,
   3285 		    "Configuration Space", "Memory-Mapped Space");
   3286 		onoff("  Associated RCRB Header", reg,
   3287 		    PCI_RCLINK_DCL_LINKDESC_ARCRBH);
   3288 		printf("        Target Component ID: %hhu\n",
   3289 		    (uint8_t)PCIREG_SHIFTOUT(reg,
   3290 		    PCI_RCLINK_DCL_LINKDESC_TCOMPID));
   3291 		printf("        Target Port Number: %hhu\n",
   3292 		    (uint8_t)PCIREG_SHIFTOUT(reg,
   3293 		    PCI_RCLINK_DCL_LINKDESC_TPNUM));
   3294 
   3295 		if (linktype == 0) {
   3296 			/* Memory-Mapped Space */
   3297 			reg = regs[o2i(extcapoff
   3298 				    + PCI_RCLINK_DCL_LINKADDR_LT0_LO(i))];
   3299 			printf("      Link Address Low Register: 0x%08x\n",
   3300 			    reg);
   3301 			reg = regs[o2i(extcapoff
   3302 				    + PCI_RCLINK_DCL_LINKADDR_LT0_HI(i))];
   3303 			printf("      Link Address High Register: 0x%08x\n",
   3304 			    reg);
   3305 		} else {
   3306 			unsigned int nb;
   3307 			pcireg_t lo, hi;
   3308 
   3309 			/* Configuration Space */
   3310 			lo = regs[o2i(extcapoff
   3311 				    + PCI_RCLINK_DCL_LINKADDR_LT1_LO(i))];
   3312 			printf("      Configuration Space Low Register: "
   3313 			    "0x%08x\n", lo);
   3314 			hi = regs[o2i(extcapoff
   3315 				    + PCI_RCLINK_DCL_LINKADDR_LT1_HI(i))];
   3316 			printf("      Configuration Space High Register: "
   3317 			    "0x%08x\n", hi);
   3318 			nb = PCIREG_SHIFTOUT(lo, PCI_RCLINK_DCL_LINKADDR_LT1_N);
   3319 			printf("        N: %u\n", nb);
   3320 			printf("        Func: %hhu\n",
   3321 			    (uint8_t)PCIREG_SHIFTOUT(lo,
   3322 			    PCI_RCLINK_DCL_LINKADDR_LT1_FUNC));
   3323 			printf("        Dev: %hhu\n",
   3324 			    (uint8_t)PCIREG_SHIFTOUT(lo,
   3325 			    PCI_RCLINK_DCL_LINKADDR_LT1_DEV));
   3326 			printf("        Bus: %hhu\n",
   3327 			    (uint8_t)PCIREG_SHIFTOUT(lo,
   3328 			    PCI_RCLINK_DCL_LINKADDR_LT1_BUS(nb)));
   3329 			lo &= PCI_RCLINK_DCL_LINKADDR_LT1_BAL(i);
   3330 			printf("        Configuration Space Base Address: "
   3331 			    "0x%016" PRIx64 "\n", ((uint64_t)hi << 32) + lo);
   3332 		}
   3333 	}
   3334 }
   3335 
   3336 /* XXX pci_conf_print_rclink_ctl_cap */
   3337 
   3338 static void
   3339 pci_conf_print_rcec_assoc_cap(const pcireg_t *regs, int extcapoff)
   3340 {
   3341 	pcireg_t reg;
   3342 
   3343 	printf("\n  Root Complex Event Collector Association\n");
   3344 
   3345 	reg = regs[o2i(extcapoff + PCI_RCEC_ASSOC_ASSOCBITMAP)];
   3346 	printf("    Association Bitmap for Root Complex Integrated Devices:"
   3347 	    " 0x%08x\n", reg);
   3348 
   3349 	if (PCI_EXTCAPLIST_VERSION(regs[o2i(extcapoff)]) >= 2) {
   3350 		reg = regs[o2i(extcapoff + PCI_RCEC_ASSOC_ASSOCBUSNUM)];
   3351 		printf("    RCEC Associated Bus Numbers register: 0x%08x\n",
   3352 		    reg);
   3353 		printf("      RCEC Next Bus: %u\n",
   3354 		    PCIREG_SHIFTOUT(reg,
   3355 			PCI_RCEC_ASSOCBUSNUM_RCECNEXT));
   3356 		printf("      RCEC Last Bus: %u\n",
   3357 		    PCIREG_SHIFTOUT(reg,
   3358 			PCI_RCEC_ASSOCBUSNUM_RCECLAST));
   3359 	}
   3360 }
   3361 
   3362 /* XXX pci_conf_print_mfvc_cap */
   3363 /* XXX pci_conf_print_vc2_cap */
   3364 /* XXX pci_conf_print_rcrb_cap */
   3365 /* XXX pci_conf_print_vendor_cap */
   3366 /* XXX pci_conf_print_cac_cap */
   3367 
   3368 static void
   3369 pci_conf_print_acs_cap(const pcireg_t *regs, int extcapoff)
   3370 {
   3371 	pcireg_t reg, cap, ctl;
   3372 	unsigned int size, i;
   3373 
   3374 	printf("\n  Access Control Services\n");
   3375 
   3376 	reg = regs[o2i(extcapoff + PCI_ACS_CAP)];
   3377 	cap = reg & 0xffff;
   3378 	ctl = reg >> 16;
   3379 	printf("    ACS Capability register: 0x%08x\n", cap);
   3380 	onoff("ACS Source Validation", cap, PCI_ACS_CAP_V);
   3381 	onoff("ACS Transaction Blocking", cap, PCI_ACS_CAP_B);
   3382 	onoff("ACS P2P Request Redirect", cap, PCI_ACS_CAP_R);
   3383 	onoff("ACS P2P Completion Redirect", cap, PCI_ACS_CAP_C);
   3384 	onoff("ACS Upstream Forwarding", cap, PCI_ACS_CAP_U);
   3385 	onoff("ACS Egress Control", cap, PCI_ACS_CAP_E);
   3386 	onoff("ACS Direct Translated P2P", cap, PCI_ACS_CAP_T);
   3387 	size = PCIREG_SHIFTOUT(cap, PCI_ACS_CAP_ECVSIZE);
   3388 	if (size == 0)
   3389 		size = 256;
   3390 	printf("      Egress Control Vector Size: %u\n", size);
   3391 	printf("    ACS Control register: 0x%08x\n", ctl);
   3392 	onoff("ACS Source Validation Enable", ctl, PCI_ACS_CTL_V);
   3393 	onoff("ACS Transaction Blocking Enable", ctl, PCI_ACS_CTL_B);
   3394 	onoff("ACS P2P Request Redirect Enable", ctl, PCI_ACS_CTL_R);
   3395 	onoff("ACS P2P Completion Redirect Enable", ctl, PCI_ACS_CTL_C);
   3396 	onoff("ACS Upstream Forwarding Enable", ctl, PCI_ACS_CTL_U);
   3397 	onoff("ACS Egress Control Enable", ctl, PCI_ACS_CTL_E);
   3398 	onoff("ACS Direct Translated P2P Enable", ctl, PCI_ACS_CTL_T);
   3399 
   3400 	/*
   3401 	 * If the P2P Egress Control Capability bit is 0, ignore the Egress
   3402 	 * Control vector.
   3403 	 */
   3404 	if ((cap & PCI_ACS_CAP_E) == 0)
   3405 		return;
   3406 	for (i = 0; i < size; i += 32)
   3407 		printf("    Egress Control Vector [%u..%u]: 0x%08x\n", i + 31,
   3408 		    i, regs[o2i(extcapoff + PCI_ACS_ECV + (i / 32) * 4 )]);
   3409 }
   3410 
   3411 static void
   3412 pci_conf_print_ari_cap(const pcireg_t *regs, int extcapoff)
   3413 {
   3414 	pcireg_t reg, cap, ctl;
   3415 
   3416 	printf("\n  Alternative Routing-ID Interpretation Register\n");
   3417 
   3418 	reg = regs[o2i(extcapoff + PCI_ARI_CAP)];
   3419 	cap = reg & 0xffff;
   3420 	ctl = reg >> 16;
   3421 	printf("    Capability register: 0x%08x\n", cap);
   3422 	onoff("MVFC Function Groups Capability", reg, PCI_ARI_CAP_M);
   3423 	onoff("ACS Function Groups Capability", reg, PCI_ARI_CAP_A);
   3424 	printf("      Next Function Number: %u\n",
   3425 	    PCIREG_SHIFTOUT(reg, PCI_ARI_CAP_NXTFN));
   3426 	printf("    Control register: 0x%08x\n", ctl);
   3427 	onoff("MVFC Function Groups Enable", reg, PCI_ARI_CTL_M);
   3428 	onoff("ACS Function Groups Enable", reg, PCI_ARI_CTL_A);
   3429 	printf("      Function Group: %u\n",
   3430 	    PCIREG_SHIFTOUT(reg, PCI_ARI_CTL_FUNCGRP));
   3431 }
   3432 
   3433 static void
   3434 pci_conf_print_ats_cap(const pcireg_t *regs, int extcapoff)
   3435 {
   3436 	pcireg_t reg, cap, ctl;
   3437 	unsigned int num;
   3438 
   3439 	printf("\n  Address Translation Services\n");
   3440 
   3441 	reg = regs[o2i(extcapoff + PCI_ARI_CAP)];
   3442 	cap = reg & 0xffff;
   3443 	ctl = reg >> 16;
   3444 	printf("    Capability register: 0x%04x\n", cap);
   3445 	num = PCIREG_SHIFTOUT(reg, PCI_ATS_CAP_INVQDEPTH);
   3446 	if (num == 0)
   3447 		num = 32;
   3448 	printf("      Invalidate Queue Depth: %u\n", num);
   3449 	onoff("Page Aligned Request", reg, PCI_ATS_CAP_PALIGNREQ);
   3450 	onoff("Global Invalidate", reg, PCI_ATS_CAP_GLOBALINVL);
   3451 	onoff("Relaxed Ordering", reg, PCI_ATS_CAP_RELAXORD);
   3452 
   3453 	printf("    Control register: 0x%04x\n", ctl);
   3454 	printf("      Smallest Translation Unit: %u\n",
   3455 	    PCIREG_SHIFTOUT(reg, PCI_ATS_CTL_STU));
   3456 	onoff("Enable", reg, PCI_ATS_CTL_EN);
   3457 }
   3458 
   3459 static void
   3460 pci_conf_print_sernum_cap(const pcireg_t *regs, int extcapoff)
   3461 {
   3462 	pcireg_t lo, hi;
   3463 
   3464 	printf("\n  Device Serial Number Register\n");
   3465 
   3466 	lo = regs[o2i(extcapoff + PCI_SERIAL_LOW)];
   3467 	hi = regs[o2i(extcapoff + PCI_SERIAL_HIGH)];
   3468 	printf("    Serial Number: %02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x\n",
   3469 	    hi >> 24, (hi >> 16) & 0xff, (hi >> 8) & 0xff, hi & 0xff,
   3470 	    lo >> 24, (lo >> 16) & 0xff, (lo >> 8) & 0xff, lo & 0xff);
   3471 }
   3472 
   3473 static void
   3474 pci_conf_print_sriov_cap(const pcireg_t *regs, int extcapoff)
   3475 {
   3476 	char buf[sizeof("99999 MB")];
   3477 	pcireg_t reg;
   3478 	pcireg_t total_vfs;
   3479 	int i;
   3480 	bool first;
   3481 
   3482 	printf("\n  Single Root IO Virtualization Register\n");
   3483 
   3484 	reg = regs[o2i(extcapoff + PCI_SRIOV_CAP)];
   3485 	printf("    Capabilities register: 0x%08x\n", reg);
   3486 	onoff("VF Migration Capable", reg, PCI_SRIOV_CAP_VF_MIGRATION);
   3487 	onoff("ARI Capable Hierarchy Preserved", reg,
   3488 	    PCI_SRIOV_CAP_ARI_CAP_HIER_PRESERVED);
   3489 	if (reg & PCI_SRIOV_CAP_VF_MIGRATION) {
   3490 		printf("      VF Migration Interrupt Message Number: 0x%03x\n",
   3491 		    PCIREG_SHIFTOUT(reg, PCI_SRIOV_CAP_VF_MIGRATION_INTMSG_N));
   3492 	}
   3493 
   3494 	reg = regs[o2i(extcapoff + PCI_SRIOV_CTL)] & 0xffff;
   3495 	printf("    Control register: 0x%04x\n", reg);
   3496 	onoff("VF Enable", reg, PCI_SRIOV_CTL_VF_ENABLE);
   3497 	onoff("VF Migration Enable", reg, PCI_SRIOV_CTL_VF_MIGRATION_SUPPORT);
   3498 	onoff("VF Migration Interrupt Enable", reg,
   3499 	    PCI_SRIOV_CTL_VF_MIGRATION_INT_ENABLE);
   3500 	onoff("VF Memory Space Enable", reg, PCI_SRIOV_CTL_VF_MSE);
   3501 	onoff("ARI Capable Hierarchy", reg, PCI_SRIOV_CTL_ARI_CAP_HIER);
   3502 
   3503 	reg = regs[o2i(extcapoff + PCI_SRIOV_STA)] >> 16;
   3504 	printf("    Status register: 0x%04x\n", reg);
   3505 	onoff("VF Migration Status", reg, PCI_SRIOV_STA_VF_MIGRATION);
   3506 
   3507 	reg = regs[o2i(extcapoff + PCI_SRIOV_INITIAL_VFS)] & 0xffff;
   3508 	printf("    InitialVFs register: 0x%04x\n", reg);
   3509 	total_vfs = reg = regs[o2i(extcapoff + PCI_SRIOV_TOTAL_VFS)] >> 16;
   3510 	printf("    TotalVFs register: 0x%04x\n", reg);
   3511 	reg = regs[o2i(extcapoff + PCI_SRIOV_NUM_VFS)] & 0xffff;
   3512 	printf("    NumVFs register: 0x%04x\n", reg);
   3513 
   3514 	reg = regs[o2i(extcapoff + PCI_SRIOV_FUNC_DEP_LINK)] >> 16;
   3515 	printf("    Function Dependency Link register: 0x%04x\n", reg);
   3516 
   3517 	reg = regs[o2i(extcapoff + PCI_SRIOV_VF_OFF)] & 0xffff;
   3518 	printf("    First VF Offset register: 0x%04x\n", reg);
   3519 	reg = regs[o2i(extcapoff + PCI_SRIOV_VF_STRIDE)] >> 16;
   3520 	printf("    VF Stride register: 0x%04x\n", reg);
   3521 	reg = regs[o2i(extcapoff + PCI_SRIOV_VF_DID)] >> 16;
   3522 	printf("    Device ID: 0x%04x\n", reg);
   3523 
   3524 	reg = regs[o2i(extcapoff + PCI_SRIOV_PAGE_CAP)];
   3525 	printf("    Supported Page Sizes register: 0x%08x\n", reg);
   3526 	printf("      Supported Page Size:");
   3527 	for (i = 0, first = true; i < 32; i++) {
   3528 		if (reg & __BIT(i)) {
   3529 #ifdef _KERNEL
   3530 			format_bytes(buf, sizeof(buf), 1LL << (i + 12));
   3531 #else
   3532 			humanize_number(buf, sizeof(buf), 1LL << (i + 12), "B",
   3533 			    HN_AUTOSCALE, 0);
   3534 #endif
   3535 			printf("%s %s", first ? "" : ",", buf);
   3536 			first = false;
   3537 		}
   3538 	}
   3539 	printf("\n");
   3540 
   3541 	reg = regs[o2i(extcapoff + PCI_SRIOV_PAGE_SIZE)];
   3542 	printf("    System Page Sizes register: 0x%08x\n", reg);
   3543 	printf("      Page Size: ");
   3544 	if (reg != 0) {
   3545 		int bitpos = ffs(reg) -1;
   3546 
   3547 		/* Assume only one bit is set. */
   3548 #ifdef _KERNEL
   3549 		format_bytes(buf, sizeof(buf), 1LL << (bitpos + 12));
   3550 #else
   3551 		humanize_number(buf, sizeof(buf), 1LL << (bitpos + 12),
   3552 		    "B", HN_AUTOSCALE, 0);
   3553 #endif
   3554 		printf("%s", buf);
   3555 	} else {
   3556 		printf("unknown");
   3557 	}
   3558 	printf("\n");
   3559 
   3560 	for (i = 0; i < 6; i++) {
   3561 		reg = regs[o2i(extcapoff + PCI_SRIOV_BAR(i))];
   3562 		printf("    VF BAR%d register: 0x%08x\n", i, reg);
   3563 	}
   3564 
   3565 	if (total_vfs > 0) {
   3566 		reg = regs[o2i(extcapoff + PCI_SRIOV_VF_MIG_STA_AR)];
   3567 		printf("    VF Migration State Array Offset register: 0x%08x\n",
   3568 		    reg);
   3569 		printf("      VF Migration State Offset: 0x%08x\n",
   3570 		    PCIREG_SHIFTOUT(reg, PCI_SRIOV_VF_MIG_STA_OFFSET));
   3571 		i = PCIREG_SHIFTOUT(reg, PCI_SRIOV_VF_MIG_STA_BIR);
   3572 		printf("      VF Migration State BIR: ");
   3573 		if (i >= 0 && i <= 5) {
   3574 			printf("BAR%d", i);
   3575 		} else {
   3576 			printf("unknown BAR (%d)", i);
   3577 		}
   3578 		printf("\n");
   3579 	}
   3580 }
   3581 
   3582 /* XXX pci_conf_print_mriov_cap */
   3583 
   3584 static void
   3585 pci_conf_print_multicast_cap(const pcireg_t *regs, int extcapoff)
   3586 {
   3587 	pcireg_t reg, cap, ctl;
   3588 	pcireg_t regl, regh;
   3589 	uint64_t addr;
   3590 	int n;
   3591 
   3592 	printf("\n  Multicast\n");
   3593 
   3594 	reg = regs[o2i(extcapoff + PCI_MCAST_CTL)];
   3595 	cap = reg & 0xffff;
   3596 	ctl = reg >> 16;
   3597 	printf("    Capability Register: 0x%04x\n", cap);
   3598 	printf("      Max Group: %u\n",
   3599 	    (pcireg_t)(reg & PCI_MCAST_CAP_MAXGRP) + 1);
   3600 
   3601 	/* Endpoint Only */
   3602 	n = PCIREG_SHIFTOUT(reg, PCI_MCAST_CAP_WINSIZEREQ);
   3603 	if (n > 0)
   3604 		printf("      Window Size Requested: %d\n", 1 << (n - 1));
   3605 
   3606 	onoff("ECRC Regeneration Supported", reg, PCI_MCAST_CAP_ECRCREGEN);
   3607 
   3608 	printf("    Control Register: 0x%04x\n", ctl);
   3609 	printf("      Num Group: %u\n",
   3610 	    PCIREG_SHIFTOUT(reg, PCI_MCAST_CTL_NUMGRP) + 1);
   3611 	onoff("Enable", reg, PCI_MCAST_CTL_ENA);
   3612 
   3613 	regl = regs[o2i(extcapoff + PCI_MCAST_BARL)];
   3614 	regh = regs[o2i(extcapoff + PCI_MCAST_BARH)];
   3615 	printf("    Base Address Register 0: 0x%08x\n", regl);
   3616 	printf("    Base Address Register 1: 0x%08x\n", regh);
   3617 	printf("      Index Position: %u\n",
   3618 	    (unsigned int)(regl & PCI_MCAST_BARL_INDPOS));
   3619 	addr = ((uint64_t)regh << 32) | (regl & PCI_MCAST_BARL_ADDR);
   3620 	printf("      Base Address: 0x%016" PRIx64 "\n", addr);
   3621 
   3622 	regl = regs[o2i(extcapoff + PCI_MCAST_RECVL)];
   3623 	regh = regs[o2i(extcapoff + PCI_MCAST_RECVH)];
   3624 	printf("    Receive Register 0: 0x%08x\n", regl);
   3625 	printf("    Receive Register 1: 0x%08x\n", regh);
   3626 
   3627 	regl = regs[o2i(extcapoff + PCI_MCAST_BLOCKALLL)];
   3628 	regh = regs[o2i(extcapoff + PCI_MCAST_BLOCKALLH)];
   3629 	printf("    Block All Register 0: 0x%08x\n", regl);
   3630 	printf("    Block All Register 1: 0x%08x\n", regh);
   3631 
   3632 	regl = regs[o2i(extcapoff + PCI_MCAST_BLOCKUNTRNSL)];
   3633 	regh = regs[o2i(extcapoff + PCI_MCAST_BLOCKUNTRNSH)];
   3634 	printf("    Block Untranslated Register 0: 0x%08x\n", regl);
   3635 	printf("    Block Untranslated Register 1: 0x%08x\n", regh);
   3636 
   3637 	regl = regs[o2i(extcapoff + PCI_MCAST_OVERLAYL)];
   3638 	regh = regs[o2i(extcapoff + PCI_MCAST_OVERLAYH)];
   3639 	printf("    Overlay BAR 0: 0x%08x\n", regl);
   3640 	printf("    Overlay BAR 1: 0x%08x\n", regh);
   3641 
   3642 	n = regl & PCI_MCAST_OVERLAYL_SIZE;
   3643 	printf("      Overlay Size: ");
   3644 	if (n >= 6)
   3645 		printf("%d\n", n);
   3646 	else
   3647 		printf("off\n");
   3648 	addr = ((uint64_t)regh << 32) | (regl & PCI_MCAST_OVERLAYL_ADDR);
   3649 	printf("      Overlay BAR: 0x%016" PRIx64 "\n", addr);
   3650 }
   3651 
   3652 static void
   3653 pci_conf_print_page_req_cap(const pcireg_t *regs, int extcapoff)
   3654 {
   3655 	pcireg_t reg, ctl, sta;
   3656 
   3657 	printf("\n  Page Request\n");
   3658 
   3659 	reg = regs[o2i(extcapoff + PCI_PAGE_REQ_CTL)];
   3660 	ctl = reg & 0xffff;
   3661 	sta = reg >> 16;
   3662 	printf("    Control Register: 0x%04x\n", ctl);
   3663 	onoff("Enable", reg, PCI_PAGE_REQ_CTL_E);
   3664 	onoff("Reset", reg, PCI_PAGE_REQ_CTL_R);
   3665 
   3666 	printf("    Status Register: 0x%04x\n", sta);
   3667 	onoff("Response Failure", reg, PCI_PAGE_REQ_STA_RF);
   3668 	onoff("Unexpected Page Request Group Index", reg,
   3669 	    PCI_PAGE_REQ_STA_UPRGI);
   3670 	onoff("Stopped", reg, PCI_PAGE_REQ_STA_S);
   3671 	onoff("PRG Response PASID Required", reg, PCI_PAGE_REQ_STA_PASIDR);
   3672 
   3673 	reg = regs[o2i(extcapoff + PCI_PAGE_REQ_OUTSTCAPA)];
   3674 	printf("    Outstanding Page Request Capacity: %u\n", reg);
   3675 	reg = regs[o2i(extcapoff + PCI_PAGE_REQ_OUTSTALLOC)];
   3676 	printf("    Outstanding Page Request Allocation: %u\n", reg);
   3677 }
   3678 
   3679 /* XXX pci_conf_print_amd_cap */
   3680 
   3681 #define MEM_PBUFSIZE	sizeof("999GB")
   3682 
   3683 static void
   3684 pci_conf_print_resizbar_cap(const pcireg_t *regs, int extcapoff)
   3685 {
   3686 	pcireg_t cap, ctl;
   3687 	unsigned int bars, i, n;
   3688 	char pbuf[MEM_PBUFSIZE];
   3689 
   3690 	printf("\n  Resizable BAR\n");
   3691 
   3692 	/* Get Number of Resizable BARs */
   3693 	ctl = regs[o2i(extcapoff + PCI_RESIZBAR_CTL(0))];
   3694 	bars = PCIREG_SHIFTOUT(ctl, PCI_RESIZBAR_CTL_NUMBAR);
   3695 	printf("    Number of Resizable BARs: ");
   3696 	if (bars <= 6)
   3697 		printf("%u\n", bars);
   3698 	else {
   3699 		printf("incorrect (%u)\n", bars);
   3700 		return;
   3701 	}
   3702 
   3703 	for (n = 0; n < 6; n++) {
   3704 		cap = regs[o2i(extcapoff + PCI_RESIZBAR_CAP(n))];
   3705 		printf("    Capability register(%u): 0x%08x\n", n, cap);
   3706 		if ((cap & PCI_RESIZBAR_CAP_SIZEMASK) == 0)
   3707 			continue; /* Not Used */
   3708 		printf("      Acceptable BAR sizes:");
   3709 		for (i = 4; i <= 23; i++) {
   3710 			if ((cap & (1 << i)) != 0) {
   3711 				humanize_number(pbuf, MEM_PBUFSIZE,
   3712 				    (int64_t)1024 * 1024 << (i - 4), "B",
   3713 #ifdef _KERNEL
   3714 				    1);
   3715 #else
   3716 				    HN_AUTOSCALE, HN_NOSPACE);
   3717 #endif
   3718 				printf(" %s", pbuf);
   3719 			}
   3720 		}
   3721 		printf("\n");
   3722 
   3723 		ctl = regs[o2i(extcapoff + PCI_RESIZBAR_CTL(n))];
   3724 		printf("    Control register(%u): 0x%08x\n", n, ctl);
   3725 		printf("      BAR Index: %u\n",
   3726 		    PCIREG_SHIFTOUT(ctl, PCI_RESIZBAR_CTL_BARIDX));
   3727 		humanize_number(pbuf, MEM_PBUFSIZE,
   3728 		    (int64_t)1024 * 1024
   3729 		    << PCIREG_SHIFTOUT(ctl, PCI_RESIZBAR_CTL_BARSIZ),
   3730 		    "B",
   3731 #ifdef _KERNEL
   3732 		    1);
   3733 #else
   3734 		    HN_AUTOSCALE, HN_NOSPACE);
   3735 #endif
   3736 		printf("      BAR Size: %s\n", pbuf);
   3737 	}
   3738 }
   3739 
   3740 static void
   3741 pci_conf_print_dpa_cap(const pcireg_t *regs, int extcapoff)
   3742 {
   3743 	pcireg_t reg;
   3744 	unsigned int substmax, i;
   3745 
   3746 	printf("\n  Dynamic Power Allocation\n");
   3747 
   3748 	reg = regs[o2i(extcapoff + PCI_DPA_CAP)];
   3749 	printf("    Capability register: 0x%08x\n", reg);
   3750 	substmax = PCIREG_SHIFTOUT(reg, PCI_DPA_CAP_SUBSTMAX);
   3751 	printf("      Substate Max: %u\n", substmax);
   3752 	printf("      Transition Latency Unit: ");
   3753 	switch (PCIREG_SHIFTOUT(reg, PCI_DPA_CAP_TLUINT)) {
   3754 	case 0:
   3755 		printf("1ms\n");
   3756 		break;
   3757 	case 1:
   3758 		printf("10ms\n");
   3759 		break;
   3760 	case 2:
   3761 		printf("100ms\n");
   3762 		break;
   3763 	default:
   3764 		printf("reserved\n");
   3765 		break;
   3766 	}
   3767 	printf("      Power Allocation Scale: ");
   3768 	switch (PCIREG_SHIFTOUT(reg, PCI_DPA_CAP_PAS)) {
   3769 	case 0:
   3770 		printf("10.0x\n");
   3771 		break;
   3772 	case 1:
   3773 		printf("1.0x\n");
   3774 		break;
   3775 	case 2:
   3776 		printf("0.1x\n");
   3777 		break;
   3778 	case 3:
   3779 		printf("0.01x\n");
   3780 		break;
   3781 	}
   3782 	printf("      Transition Latency Value 0: %u\n",
   3783 	    PCIREG_SHIFTOUT(reg, PCI_DPA_CAP_XLCY0));
   3784 	printf("      Transition Latency Value 1: %u\n",
   3785 	    PCIREG_SHIFTOUT(reg, PCI_DPA_CAP_XLCY1));
   3786 
   3787 	reg = regs[o2i(extcapoff + PCI_DPA_LATIND)];
   3788 	printf("    Latency Indicator register: 0x%08x\n", reg);
   3789 
   3790 	reg = regs[o2i(extcapoff + PCI_DPA_CS)];
   3791 	printf("    Status register: 0x%04x\n", reg & 0xffff);
   3792 	printf("      Substate Status: 0x%02x\n",
   3793 	    PCIREG_SHIFTOUT(reg, PCI_DPA_CS_SUBSTSTAT));
   3794 	onoff("Substate Control Enabled", reg, PCI_DPA_CS_SUBSTCTLEN);
   3795 	printf("    Control register: 0x%04x\n", reg >> 16);
   3796 	printf("      Substate Control: 0x%02x\n",
   3797 	    PCIREG_SHIFTOUT(reg, PCI_DPA_CS_SUBSTCTL));
   3798 
   3799 	for (i = 0; i <= substmax; i++)
   3800 		printf("    Substate Power Allocation register %d: 0x%02x\n",
   3801 		    i, (regs[PCI_DPA_PWRALLOC + (i / 4)] >> (i % 4) & 0xff));
   3802 }
   3803 
   3804 static const char *
   3805 pci_conf_print_tph_req_cap_sttabloc(uint8_t val)
   3806 {
   3807 
   3808 	switch (val) {
   3809 	case PCI_TPH_REQ_STTBLLOC_NONE:
   3810 		return "Not Present";
   3811 	case PCI_TPH_REQ_STTBLLOC_TPHREQ:
   3812 		return "in the TPH Requester Capability Structure";
   3813 	case PCI_TPH_REQ_STTBLLOC_MSIX:
   3814 		return "in the MSI-X Table";
   3815 	default:
   3816 		return "Unknown";
   3817 	}
   3818 }
   3819 
   3820 static void
   3821 pci_conf_print_tph_req_cap(const pcireg_t *regs, int extcapoff)
   3822 {
   3823 	pcireg_t reg;
   3824 	int size = 0, i, j;
   3825 	uint8_t sttbloc;
   3826 
   3827 	printf("\n  TPH Requester Extended Capability\n");
   3828 
   3829 	reg = regs[o2i(extcapoff + PCI_TPH_REQ_CAP)];
   3830 	printf("    TPH Requester Capabililty register: 0x%08x\n", reg);
   3831 	onoff("No ST Mode Supported", reg, PCI_TPH_REQ_CAP_NOST);
   3832 	onoff("Interrupt Vector Mode Supported", reg, PCI_TPH_REQ_CAP_INTVEC);
   3833 	onoff("Device Specific Mode Supported", reg, PCI_TPH_REQ_CAP_DEVSPEC);
   3834 	onoff("Extend TPH Requester Supported", reg, PCI_TPH_REQ_CAP_XTPHREQ);
   3835 	sttbloc = PCIREG_SHIFTOUT(reg, PCI_TPH_REQ_CAP_STTBLLOC);
   3836 	printf("      ST Table Location: %s\n",
   3837 	    pci_conf_print_tph_req_cap_sttabloc(sttbloc));
   3838 	if (sttbloc == PCI_TPH_REQ_STTBLLOC_TPHREQ) {
   3839 		size = PCIREG_SHIFTOUT(reg, PCI_TPH_REQ_CAP_STTBLSIZ) + 1;
   3840 		printf("      ST Table Size: %d\n", size);
   3841 	}
   3842 
   3843 	reg = regs[o2i(extcapoff + PCI_TPH_REQ_CTL)];
   3844 	printf("    TPH Requester Control register: 0x%08x\n", reg);
   3845 	printf("      ST Mode Select: ");
   3846 	switch (PCIREG_SHIFTOUT(reg, PCI_TPH_REQ_CTL_STSEL)) {
   3847 	case PCI_TPH_REQ_CTL_STSEL_NO:
   3848 		printf("No ST Mode\n");
   3849 		break;
   3850 	case PCI_TPH_REQ_CTL_STSEL_IV:
   3851 		printf("Interrupt Vector Mode\n");
   3852 		break;
   3853 	case PCI_TPH_REQ_CTL_STSEL_DS:
   3854 		printf("Device Specific Mode\n");
   3855 		break;
   3856 	default:
   3857 		printf("(reserved value)\n");
   3858 		break;
   3859 	}
   3860 	printf("      TPH Requester Enable: ");
   3861 	switch (PCIREG_SHIFTOUT(reg, PCI_TPH_REQ_CTL_TPHREQEN)) {
   3862 	case PCI_TPH_REQ_CTL_TPHREQEN_NO: /* 0x0 */
   3863 		printf("Not permitted\n");
   3864 		break;
   3865 	case PCI_TPH_REQ_CTL_TPHREQEN_TPH:
   3866 		printf("TPH and not Extended TPH\n");
   3867 		break;
   3868 	case PCI_TPH_REQ_CTL_TPHREQEN_ETPH:
   3869 		printf("TPH and Extended TPH");
   3870 		break;
   3871 	default:
   3872 		printf("(reserved value)\n");
   3873 		break;
   3874 	}
   3875 
   3876 	if (sttbloc != PCI_TPH_REQ_STTBLLOC_TPHREQ)
   3877 		return;
   3878 
   3879 	for (i = 0; i < size ; i += 2) {
   3880 		reg = regs[o2i(extcapoff + PCI_TPH_REQ_STTBL + i / 2)];
   3881 		for (j = 0; j < 2 ; j++) {
   3882 			uint32_t entry = reg;
   3883 
   3884 			if (j != 0)
   3885 				entry >>= 16;
   3886 			entry &= 0xffff;
   3887 			printf("    TPH ST Table Entry (%d): 0x%04"PRIx32"\n",
   3888 			    i + j, entry);
   3889 		}
   3890 	}
   3891 }
   3892 
   3893 static void
   3894 pci_conf_print_ltr_cap(const pcireg_t *regs, int extcapoff)
   3895 {
   3896 	pcireg_t reg;
   3897 
   3898 	printf("\n  Latency Tolerance Reporting\n");
   3899 	reg = regs[o2i(extcapoff + PCI_LTR_MAXSNOOPLAT)];
   3900 	printf("    Max Snoop Latency Register: 0x%04x\n", reg & 0xffff);
   3901 	printf("      Max Snoop Latency: %juns\n",
   3902 	    (uintmax_t)(PCIREG_SHIFTOUT(reg, PCI_LTR_MAXSNOOPLAT_VAL)
   3903 	    * PCI_LTR_SCALETONS(PCIREG_SHIFTOUT(reg, PCI_LTR_MAXSNOOPLAT_SCALE))));
   3904 	printf("    Max No-Snoop Latency Register: 0x%04x\n", reg >> 16);
   3905 	printf("      Max No-Snoop Latency: %juns\n",
   3906 	    (uintmax_t)(PCIREG_SHIFTOUT(reg, PCI_LTR_MAXNOSNOOPLAT_VAL)
   3907 	    * PCI_LTR_SCALETONS(PCIREG_SHIFTOUT(reg, PCI_LTR_MAXNOSNOOPLAT_SCALE))));
   3908 }
   3909 
   3910 static void
   3911 pci_conf_print_sec_pcie_cap(const pcireg_t *regs, int extcapoff)
   3912 {
   3913 	int pcie_capoff;
   3914 	pcireg_t reg;
   3915 	int i, maxlinkwidth;
   3916 
   3917 	printf("\n  Secondary PCI Express Register\n");
   3918 
   3919 	reg = regs[o2i(extcapoff + PCI_SECPCIE_LCTL3)];
   3920 	printf("    Link Control 3 register: 0x%08x\n", reg);
   3921 	onoff("Perform Equalization", reg, PCI_SECPCIE_LCTL3_PERFEQ);
   3922 	onoff("Link Equalization Request Interrupt Enable",
   3923 	    reg, PCI_SECPCIE_LCTL3_LINKEQREQ_IE);
   3924 	printf("      Enable Lower SKP OS Generation Vector:");
   3925 	pci_print_pcie_linkspeedvector(
   3926 		PCIREG_SHIFTOUT(reg, PCI_SECPCIE_LCTL3_ELSKPOSGENV));
   3927 	printf("\n");
   3928 
   3929 	reg = regs[o2i(extcapoff + PCI_SECPCIE_LANEERR_STA)];
   3930 	printf("    Lane Error Status register: 0x%08x\n", reg);
   3931 
   3932 	/* Get Max Link Width */
   3933 	if (pci_conf_find_cap(regs, PCI_CAP_PCIEXPRESS, &pcie_capoff)) {
   3934 		reg = regs[o2i(pcie_capoff + PCIE_LCAP)];
   3935 		maxlinkwidth = PCIREG_SHIFTOUT(reg, PCIE_LCAP_MAX_WIDTH);
   3936 	} else {
   3937 		printf("error: failed to get PCIe capability\n");
   3938 		return;
   3939 	}
   3940 	for (i = 0; i < maxlinkwidth; i++) {
   3941 		reg = regs[o2i(extcapoff + PCI_SECPCIE_EQCTL(i))];
   3942 		if (i % 2 != 0)
   3943 			reg >>= 16;
   3944 		else
   3945 			reg &= 0xffff;
   3946 		printf("    Equalization Control Register (Link %d): 0x%04x\n",
   3947 		    i, reg);
   3948 		printf("      Downstream Port Transmit Preset: 0x%x\n",
   3949 		    PCIREG_SHIFTOUT(reg,
   3950 			PCI_SECPCIE_EQCTL_DP_XMIT_PRESET));
   3951 		printf("      Downstream Port Receive Hint: 0x%x\n",
   3952 		    PCIREG_SHIFTOUT(reg, PCI_SECPCIE_EQCTL_DP_RCV_HINT));
   3953 		printf("      Upstream Port Transmit Preset: 0x%x\n",
   3954 		    PCIREG_SHIFTOUT(reg,
   3955 			PCI_SECPCIE_EQCTL_UP_XMIT_PRESET));
   3956 		printf("      Upstream Port Receive Hint: 0x%x\n",
   3957 		    PCIREG_SHIFTOUT(reg, PCI_SECPCIE_EQCTL_UP_RCV_HINT));
   3958 	}
   3959 }
   3960 
   3961 /* XXX pci_conf_print_pmux_cap */
   3962 
   3963 static void
   3964 pci_conf_print_pasid_cap(const pcireg_t *regs, int extcapoff)
   3965 {
   3966 	pcireg_t reg, cap, ctl;
   3967 	unsigned int num;
   3968 
   3969 	printf("\n  Process Address Space ID\n");
   3970 
   3971 	reg = regs[o2i(extcapoff + PCI_PASID_CAP)];
   3972 	cap = reg & 0xffff;
   3973 	ctl = reg >> 16;
   3974 	printf("    PASID Capability Register: 0x%04x\n", cap);
   3975 	onoff("Execute Permission Supported", reg, PCI_PASID_CAP_XPERM);
   3976 	onoff("Privileged Mode Supported", reg, PCI_PASID_CAP_PRIVMODE);
   3977 	num = (1 << PCIREG_SHIFTOUT(reg, PCI_PASID_CAP_MAXPASIDW)) - 1;
   3978 	printf("      Max PASID Width: %u\n", num);
   3979 
   3980 	printf("    PASID Control Register: 0x%04x\n", ctl);
   3981 	onoff("PASID Enable", reg, PCI_PASID_CTL_PASID_EN);
   3982 	onoff("Execute Permission Enable", reg, PCI_PASID_CTL_XPERM_EN);
   3983 	onoff("Privileged Mode Enable", reg, PCI_PASID_CTL_PRIVMODE_EN);
   3984 }
   3985 
   3986 static void
   3987 pci_conf_print_lnr_cap(const pcireg_t *regs, int extcapoff)
   3988 {
   3989 	pcireg_t reg, cap, ctl;
   3990 	unsigned int num;
   3991 
   3992 	printf("\n  LN Requester\n");
   3993 
   3994 	reg = regs[o2i(extcapoff + PCI_LNR_CAP)];
   3995 	cap = reg & 0xffff;
   3996 	ctl = reg >> 16;
   3997 	printf("    LNR Capability register: 0x%04x\n", cap);
   3998 	onoff("LNR-64 Supported", reg, PCI_LNR_CAP_64);
   3999 	onoff("LNR-128 Supported", reg, PCI_LNR_CAP_128);
   4000 	num = 1 << PCIREG_SHIFTOUT(reg, PCI_LNR_CAP_REGISTMAX);
   4001 	printf("      LNR Registration MAX: %u\n", num);
   4002 
   4003 	printf("    LNR Control register: 0x%04x\n", ctl);
   4004 	onoff("LNR Enable", reg, PCI_LNR_CTL_EN);
   4005 	onoff("LNR CLS", reg, PCI_LNR_CTL_CLS);
   4006 	num = 1 << PCIREG_SHIFTOUT(reg, PCI_LNR_CTL_REGISTLIM);
   4007 	printf("      LNR Registration Limit: %u\n", num);
   4008 }
   4009 
   4010 static void
   4011 pci_conf_print_dpc_pio(pcireg_t r)
   4012 {
   4013 	onoff("Cfg Request received UR Completion", r,PCI_DPC_RPPIO_CFGUR_CPL);
   4014 	onoff("Cfg Request received CA Completion", r,PCI_DPC_RPPIO_CFGCA_CPL);
   4015 	onoff("Cfg Request Completion Timeout", r, PCI_DPC_RPPIO_CFG_CTO);
   4016 	onoff("I/O Request received UR Completion", r, PCI_DPC_RPPIO_IOUR_CPL);
   4017 	onoff("I/O Request received CA Completion", r, PCI_DPC_RPPIO_IOCA_CPL);
   4018 	onoff("I/O Request Completion Timeout", r, PCI_DPC_RPPIO_IO_CTO);
   4019 	onoff("Mem Request received UR Completion", r,PCI_DPC_RPPIO_MEMUR_CPL);
   4020 	onoff("Mem Request received CA Completion", r,PCI_DPC_RPPIO_MEMCA_CPL);
   4021 	onoff("Mem Request Completion Timeout", r, PCI_DPC_RPPIO_MEM_CTO);
   4022 }
   4023 
   4024 static void
   4025 pci_conf_print_dpc_cap(const pcireg_t *regs, int extcapoff)
   4026 {
   4027 	pcireg_t reg, cap, ctl, stat, errsrc;
   4028 	const char *trigstr;
   4029 	bool rpext;
   4030 
   4031 	printf("\n  Downstream Port Containment\n");
   4032 
   4033 	reg = regs[o2i(extcapoff + PCI_DPC_CCR)];
   4034 	cap = reg & 0xffff;
   4035 	ctl = reg >> 16;
   4036 	rpext = (reg & PCI_DPCCAP_RPEXT) ? true : false;
   4037 	printf("    DPC Capability register: 0x%04x\n", cap);
   4038 	printf("      DPC Interrupt Message Number: %02x\n",
   4039 	    (unsigned int)(cap & PCI_DPCCAP_IMSGN));
   4040 	onoff("RP Extensions for DPC", reg, PCI_DPCCAP_RPEXT);
   4041 	onoff("Poisoned TLP Egress Blocking Supported", reg,
   4042 	    PCI_DPCCAP_POISONTLPEB);
   4043 	onoff("DPC Software Triggering Supported", reg, PCI_DPCCAP_SWTRIG);
   4044 	printf("      RP PIO Log Size: %u\n",
   4045 	    PCIREG_SHIFTOUT(reg, PCI_DPCCAP_RPPIOLOGSZ));
   4046 	onoff("DL_Active ERR_COR Signaling Supported", reg,
   4047 	    PCI_DPCCAP_DLACTECORS);
   4048 	printf("    DPC Control register: 0x%04x\n", ctl);
   4049 	switch (PCIREG_SHIFTOUT(reg, PCI_DPCCTL_TIRGEN)) {
   4050 	case 0:
   4051 		trigstr = "disabled";
   4052 		break;
   4053 	case 1:
   4054 		trigstr = "enabled(ERR_FATAL)";
   4055 		break;
   4056 	case 2:
   4057 		trigstr = "enabled(ERR_NONFATAL or ERR_FATAL)";
   4058 		break;
   4059 	default:
   4060 		trigstr = "(reserverd)";
   4061 		break;
   4062 	}
   4063 	printf("      DPC Trigger Enable: %s\n", trigstr);
   4064 	printf("      DPC Completion Control: %s Completion Status\n",
   4065 	    (reg & PCI_DPCCTL_COMPCTL)
   4066 	    ? "Unsupported Request(UR)" : "Completer Abort(CA)");
   4067 	onoff("DPC Interrupt Enable", reg, PCI_DPCCTL_IE);
   4068 	onoff("DPC ERR_COR Enable", reg, PCI_DPCCTL_ERRCOREN);
   4069 	onoff("Poisoned TLP Egress Blocking Enable", reg,
   4070 	    PCI_DPCCTL_POISONTLPEB);
   4071 	onoff("DPC Software Trigger", reg, PCI_DPCCTL_SWTRIG);
   4072 	onoff("DL_Active ERR_COR Enable", reg, PCI_DPCCTL_DLACTECOR);
   4073 
   4074 	reg = regs[o2i(extcapoff + PCI_DPC_STATESID)];
   4075 	stat = reg & 0xffff;
   4076 	errsrc = reg >> 16;
   4077 	printf("    DPC Status register: 0x%04x\n", stat);
   4078 	onoff("DPC Trigger Status", reg, PCI_DPCSTAT_TSTAT);
   4079 	switch (PCIREG_SHIFTOUT(reg, PCI_DPCSTAT_TREASON)) {
   4080 	case 0:
   4081 		trigstr = "an unmasked uncorrectable error";
   4082 		break;
   4083 	case 1:
   4084 		trigstr = "receiving an ERR_NONFATAL";
   4085 		break;
   4086 	case 2:
   4087 		trigstr = "receiving an ERR_FATAL";
   4088 		break;
   4089 	case 3:
   4090 		trigstr = "DPC Trigger Reason Extension field";
   4091 		break;
   4092 	}
   4093 	printf("      DPC Trigger Reason: Due to %s\n", trigstr);
   4094 	onoff("DPC Interrupt Status", reg, PCI_DPCSTAT_ISTAT);
   4095 	if (rpext)
   4096 		onoff("DPC RP Busy", reg, PCI_DPCSTAT_RPBUSY);
   4097 	switch (PCIREG_SHIFTOUT(reg, PCI_DPCSTAT_TREASON)) {
   4098 	case 0:
   4099 		trigstr = "Due to RP PIO error";
   4100 		break;
   4101 	case 1:
   4102 		trigstr = "Due to the DPC Software trigger bit";
   4103 		break;
   4104 	default:
   4105 		trigstr = "(reserved)";
   4106 		break;
   4107 	}
   4108 	printf("      DPC Trigger Reason Extension: %s\n", trigstr);
   4109 	if (rpext)
   4110 		printf("      RP PIO First Error Pointer: 0x%02x\n",
   4111 		    PCIREG_SHIFTOUT(reg, PCI_DPCSTAT_RPPIOFEP));
   4112 	printf("    DPC Error Source ID register: 0x%04x\n", errsrc);
   4113 
   4114 	if (!rpext)
   4115 		return;
   4116 	/*
   4117 	 * All of the following registers are implemented by a device which has
   4118 	 * RP Extensions for DPC
   4119 	 */
   4120 
   4121 	reg = regs[o2i(extcapoff + PCI_DPC_RPPIO_STAT)];
   4122 	printf("    RP PIO Status Register: 0x%08x\n", reg);
   4123 	pci_conf_print_dpc_pio(reg);
   4124 
   4125 	reg = regs[o2i(extcapoff + PCI_DPC_RPPIO_MASK)];
   4126 	printf("    RP PIO Mask Register: 0x%08x\n", reg);
   4127 	pci_conf_print_dpc_pio(reg);
   4128 
   4129 	reg = regs[o2i(extcapoff + PCI_DPC_RPPIO_SEVE)];
   4130 	printf("    RP PIO Severity Register: 0x%08x\n", reg);
   4131 	pci_conf_print_dpc_pio(reg);
   4132 
   4133 	reg = regs[o2i(extcapoff + PCI_DPC_RPPIO_SYSERR)];
   4134 	printf("    RP PIO SysError Register: 0x%08x\n", reg);
   4135 	pci_conf_print_dpc_pio(reg);
   4136 
   4137 	reg = regs[o2i(extcapoff + PCI_DPC_RPPIO_EXCPT)];
   4138 	printf("    RP PIO Exception Register: 0x%08x\n", reg);
   4139 	pci_conf_print_dpc_pio(reg);
   4140 
   4141 	printf("    RP PIO Header Log Register: start from 0x%03x\n",
   4142 	    extcapoff + PCI_DPC_RPPIO_HLOG);
   4143 	printf("    RP PIO ImpSpec Log Register: start from 0x%03x\n",
   4144 	    extcapoff + PCI_DPC_RPPIO_IMPSLOG);
   4145 	printf("    RP PIO TLP Prefix Log Register: start from 0x%03x\n",
   4146 	    extcapoff + PCI_DPC_RPPIO_TLPPLOG);
   4147 }
   4148 
   4149 
   4150 static int
   4151 pci_conf_l1pm_cap_tposcale(unsigned char scale)
   4152 {
   4153 
   4154 	/* Return scale in us */
   4155 	switch (scale) {
   4156 	case 0x0:
   4157 		return 2;
   4158 	case 0x1:
   4159 		return 10;
   4160 	case 0x2:
   4161 		return 100;
   4162 	default:
   4163 		return -1;
   4164 	}
   4165 }
   4166 
   4167 static void
   4168 pci_conf_print_l1pm_cap(const pcireg_t *regs, int extcapoff)
   4169 {
   4170 	pcireg_t reg;
   4171 	int scale, val;
   4172 	int pcie_capoff;
   4173 
   4174 	printf("\n  L1 PM Substates\n");
   4175 
   4176 	reg = regs[o2i(extcapoff + PCI_L1PM_CAP)];
   4177 	printf("    L1 PM Substates Capability register: 0x%08x\n", reg);
   4178 	onoff("PCI-PM L1.2 Supported", reg, PCI_L1PM_CAP_PCIPM12);
   4179 	onoff("PCI-PM L1.1 Supported", reg, PCI_L1PM_CAP_PCIPM11);
   4180 	onoff("ASPM L1.2 Supported", reg, PCI_L1PM_CAP_ASPM12);
   4181 	onoff("ASPM L1.1 Supported", reg, PCI_L1PM_CAP_ASPM11);
   4182 	onoff("L1 PM Substates Supported", reg, PCI_L1PM_CAP_L1PM);
   4183 	/* The Link Activation Supported bit is only for Downstream Port */
   4184 	if (pci_conf_find_cap(regs, PCI_CAP_PCIEXPRESS, &pcie_capoff)) {
   4185 		uint32_t t = regs[o2i(pcie_capoff)];
   4186 
   4187 		if ((t == PCIE_XCAP_TYPE_RP) || (t == PCIE_XCAP_TYPE_DOWN))
   4188 			onoff("Link Activation Supported", reg,
   4189 			    PCI_L1PM_CAP_LA);
   4190 	}
   4191 	printf("      Port Common Mode Restore Time: %uus\n",
   4192 	    PCIREG_SHIFTOUT(reg, PCI_L1PM_CAP_PCMRT));
   4193 	scale = pci_conf_l1pm_cap_tposcale(
   4194 	    PCIREG_SHIFTOUT(reg, PCI_L1PM_CAP_PTPOSCALE));
   4195 	val = PCIREG_SHIFTOUT(reg, PCI_L1PM_CAP_PTPOVAL);
   4196 	printf("      Port T_POWER_ON: ");
   4197 	if (scale == -1)
   4198 		printf("unknown\n");
   4199 	else
   4200 		printf("%dus\n", val * scale);
   4201 
   4202 	reg = regs[o2i(extcapoff + PCI_L1PM_CTL1)];
   4203 	printf("    L1 PM Substates Control register 1: 0x%08x\n", reg);
   4204 	onoff("PCI-PM L1.2 Enable", reg, PCI_L1PM_CTL1_PCIPM12_EN);
   4205 	onoff("PCI-PM L1.1 Enable", reg, PCI_L1PM_CTL1_PCIPM11_EN);
   4206 	onoff("ASPM L1.2 Enable", reg, PCI_L1PM_CTL1_ASPM12_EN);
   4207 	onoff("ASPM L1.1 Enable", reg, PCI_L1PM_CTL1_ASPM11_EN);
   4208 	onoff("Link Activation Interrupt Enable", reg, PCI_L1PM_CTL1_LAIE);
   4209 	onoff("Link Activation Control", reg, PCI_L1PM_CTL1_LA);
   4210 	printf("      Common Mode Restore Time: %uus\n",
   4211 	    PCIREG_SHIFTOUT(reg, PCI_L1PM_CTL1_CMRT));
   4212 	scale = PCI_LTR_SCALETONS(PCIREG_SHIFTOUT(reg, PCI_L1PM_CTL1_LTRTHSCALE));
   4213 	val = PCIREG_SHIFTOUT(reg, PCI_L1PM_CTL1_LTRTHVAL);
   4214 	printf("      LTR L1.2 THRESHOLD: %dus\n", val * scale);
   4215 
   4216 	reg = regs[o2i(extcapoff + PCI_L1PM_CTL2)];
   4217 	printf("    L1 PM Substates Control register 2: 0x%08x\n", reg);
   4218 	scale = pci_conf_l1pm_cap_tposcale(
   4219 		PCIREG_SHIFTOUT(reg, PCI_L1PM_CTL2_TPOSCALE));
   4220 	val = PCIREG_SHIFTOUT(reg, PCI_L1PM_CTL2_TPOVAL);
   4221 	printf("      T_POWER_ON: ");
   4222 	if (scale == -1)
   4223 		printf("unknown\n");
   4224 	else
   4225 		printf("%dus\n", val * scale);
   4226 
   4227 	if (PCI_EXTCAPLIST_VERSION(regs[o2i(extcapoff)]) >= 2) {
   4228 		reg = regs[o2i(extcapoff + PCI_L1PM_CTL2)];
   4229 		printf("    L1 PM Substates Status register: 0x%08x\n", reg);
   4230 		onoff("Link Activation Status", reg, PCI_L1PM_STAT_LA);
   4231 	}
   4232 }
   4233 
   4234 static void
   4235 pci_conf_print_ptm_cap(const pcireg_t *regs, int extcapoff)
   4236 {
   4237 	pcireg_t reg;
   4238 	uint32_t val;
   4239 
   4240 	printf("\n  Precision Time Measurement\n");
   4241 
   4242 	reg = regs[o2i(extcapoff + PCI_PTM_CAP)];
   4243 	printf("    PTM Capability register: 0x%08x\n", reg);
   4244 	onoff("PTM Requester Capable", reg, PCI_PTM_CAP_REQ);
   4245 	onoff("PTM Responder Capable", reg, PCI_PTM_CAP_RESP);
   4246 	onoff("PTM Root Capable", reg, PCI_PTM_CAP_ROOT);
   4247 	printf("      Local Clock Granularity: ");
   4248 	val = PCIREG_SHIFTOUT(reg, PCI_PTM_CAP_LCLCLKGRNL);
   4249 	switch (val) {
   4250 	case 0:
   4251 		printf("Not implemented\n");
   4252 		break;
   4253 	case 0xffff:
   4254 		printf("> 254ns\n");
   4255 		break;
   4256 	default:
   4257 		printf("%uns\n", val);
   4258 		break;
   4259 	}
   4260 
   4261 	reg = regs[o2i(extcapoff + PCI_PTM_CTL)];
   4262 	printf("    PTM Control register: 0x%08x\n", reg);
   4263 	onoff("PTM Enable", reg, PCI_PTM_CTL_EN);
   4264 	onoff("Root Select", reg, PCI_PTM_CTL_ROOTSEL);
   4265 	printf("      Effective Granularity: ");
   4266 	val = PCIREG_SHIFTOUT(reg, PCI_PTM_CTL_EFCTGRNL);
   4267 	switch (val) {
   4268 	case 0:
   4269 		printf("Unknown\n");
   4270 		break;
   4271 	case 0xffff:
   4272 		printf("> 254ns\n");
   4273 		break;
   4274 	default:
   4275 		printf("%uns\n", val);
   4276 		break;
   4277 	}
   4278 }
   4279 
   4280 /* XXX pci_conf_print_mpcie_cap */
   4281 /* XXX pci_conf_print_frsq_cap */
   4282 /* XXX pci_conf_print_rtr_cap */
   4283 /* XXX pci_conf_print_desigvndsp_cap */
   4284 /* XXX pci_conf_print_vf_resizbar_cap */
   4285 
   4286 static void
   4287 pci_conf_print_dlf_cap(const pcireg_t *regs, int extcapoff)
   4288 {
   4289 	pcireg_t reg;
   4290 
   4291 	printf("\n  Data link Feature Register\n");
   4292 	reg = regs[o2i(extcapoff + PCI_DLF_CAP)];
   4293 	printf("    Capability register: 0x%08x\n", reg);
   4294 	onoff("Scaled Flow Control", reg, PCI_DLF_LFEAT_SCLFCTL);
   4295 	onoff("DLF Exchange enable", reg, PCI_DLF_CAP_XCHG);
   4296 
   4297 	reg = regs[o2i(extcapoff + PCI_DLF_STAT)];
   4298 	printf("    Status register: 0x%08x\n", reg);
   4299 	onoff("Scaled Flow Control", reg, PCI_DLF_LFEAT_SCLFCTL);
   4300 	onoff("Remote DLF supported Valid", reg, PCI_DLF_STAT_RMTVALID);
   4301 }
   4302 
   4303 /* XXX pci_conf_print_hierarchyid_cap */
   4304 /* XXX pci_conf_print_npem_cap */
   4305 
   4306 #undef	MS
   4307 #undef	SM
   4308 #undef	RW
   4309 
   4310 static struct {
   4311 	pcireg_t cap;
   4312 	const char *name;
   4313 	void (*printfunc)(const pcireg_t *, int);
   4314 } pci_extcaptab[] = {
   4315 	{ 0,			"reserved",
   4316 	  NULL },
   4317 	{ PCI_EXTCAP_AER,	"Advanced Error Reporting",
   4318 	  pci_conf_print_aer_cap },
   4319 	{ PCI_EXTCAP_VC,	"Virtual Channel",
   4320 	  pci_conf_print_vc_cap },
   4321 	{ PCI_EXTCAP_SERNUM,	"Device Serial Number",
   4322 	  pci_conf_print_sernum_cap },
   4323 	{ PCI_EXTCAP_PWRBDGT,	"Power Budgeting",
   4324 	  pci_conf_print_pwrbdgt_cap },
   4325 	{ PCI_EXTCAP_RCLINK_DCL,"Root Complex Link Declaration",
   4326 	  pci_conf_print_rclink_dcl_cap },
   4327 	{ PCI_EXTCAP_RCLINK_CTL,"Root Complex Internal Link Control",
   4328 	  NULL },
   4329 	{ PCI_EXTCAP_RCEC_ASSOC,"Root Complex Event Collector Association",
   4330 	  pci_conf_print_rcec_assoc_cap },
   4331 	{ PCI_EXTCAP_MFVC,	"Multi-Function Virtual Channel",
   4332 	  NULL },
   4333 	{ PCI_EXTCAP_VC2,	"Virtual Channel",
   4334 	  NULL },
   4335 	{ PCI_EXTCAP_RCRB,	"RCRB Header",
   4336 	  NULL },
   4337 	{ PCI_EXTCAP_VENDOR,	"Vendor Unique",
   4338 	  NULL },
   4339 	{ PCI_EXTCAP_CAC,	"Configuration Access Correction",
   4340 	  NULL },
   4341 	{ PCI_EXTCAP_ACS,	"Access Control Services",
   4342 	  pci_conf_print_acs_cap },
   4343 	{ PCI_EXTCAP_ARI,	"Alternative Routing-ID Interpretation",
   4344 	  pci_conf_print_ari_cap },
   4345 	{ PCI_EXTCAP_ATS,	"Address Translation Services",
   4346 	  pci_conf_print_ats_cap },
   4347 	{ PCI_EXTCAP_SRIOV,	"Single Root IO Virtualization",
   4348 	  pci_conf_print_sriov_cap },
   4349 	{ PCI_EXTCAP_MRIOV,	"Multiple Root IO Virtualization",
   4350 	  NULL },
   4351 	{ PCI_EXTCAP_MCAST,	"Multicast",
   4352 	  pci_conf_print_multicast_cap },
   4353 	{ PCI_EXTCAP_PAGE_REQ,	"Page Request",
   4354 	  pci_conf_print_page_req_cap },
   4355 	{ PCI_EXTCAP_AMD,	"Reserved for AMD",
   4356 	  NULL },
   4357 	{ PCI_EXTCAP_RESIZBAR,	"Resizable BAR",
   4358 	  pci_conf_print_resizbar_cap },
   4359 	{ PCI_EXTCAP_DPA,	"Dynamic Power Allocation",
   4360 	  pci_conf_print_dpa_cap },
   4361 	{ PCI_EXTCAP_TPH_REQ,	"TPH Requester",
   4362 	  pci_conf_print_tph_req_cap },
   4363 	{ PCI_EXTCAP_LTR,	"Latency Tolerance Reporting",
   4364 	  pci_conf_print_ltr_cap },
   4365 	{ PCI_EXTCAP_SEC_PCIE,	"Secondary PCI Express",
   4366 	  pci_conf_print_sec_pcie_cap },
   4367 	{ PCI_EXTCAP_PMUX,	"Protocol Multiplexing",
   4368 	  NULL },
   4369 	{ PCI_EXTCAP_PASID,	"Process Address Space ID",
   4370 	  pci_conf_print_pasid_cap },
   4371 	{ PCI_EXTCAP_LNR,	"LN Requester",
   4372 	  pci_conf_print_lnr_cap },
   4373 	{ PCI_EXTCAP_DPC,	"Downstream Port Containment",
   4374 	  pci_conf_print_dpc_cap },
   4375 	{ PCI_EXTCAP_L1PM,	"L1 PM Substates",
   4376 	  pci_conf_print_l1pm_cap },
   4377 	{ PCI_EXTCAP_PTM,	"Precision Time Measurement",
   4378 	  pci_conf_print_ptm_cap },
   4379 	{ PCI_EXTCAP_MPCIE,	"M-PCIe",
   4380 	  NULL },
   4381 	{ PCI_EXTCAP_FRSQ,	"Function Reading Status Queueing",
   4382 	  NULL },
   4383 	{ PCI_EXTCAP_RTR,	"Readiness Time Reporting",
   4384 	  NULL },
   4385 	{ PCI_EXTCAP_DESIGVNDSP, "Designated Vendor-Specific",
   4386 	  NULL },
   4387 	{ PCI_EXTCAP_VF_RESIZBAR, "VF Resizable BARs",
   4388 	  NULL },
   4389 	{ PCI_EXTCAP_DLF,	"Data link Feature", pci_conf_print_dlf_cap },
   4390 	{ PCI_EXTCAP_PYSLAY_16GT, "Physical Layer 16.0 GT/s", NULL },
   4391 	{ PCI_EXTCAP_LMR,	"Lane Margining at the Receiver", NULL },
   4392 	{ PCI_EXTCAP_HIERARCHYID, "Hierarchy ID",
   4393 	  NULL },
   4394 	{ PCI_EXTCAP_NPEM,	"Native PCIe Enclosure Management",
   4395 	  NULL },
   4396 };
   4397 
   4398 static int
   4399 pci_conf_find_extcap(const pcireg_t *regs, unsigned int capid, int *offsetp)
   4400 {
   4401 	int off;
   4402 	pcireg_t rval;
   4403 
   4404 	for (off = PCI_EXTCAPLIST_BASE;
   4405 	     off != 0;
   4406 	     off = PCI_EXTCAPLIST_NEXT(rval)) {
   4407 		rval = regs[o2i(off)];
   4408 		if (capid == PCI_EXTCAPLIST_CAP(rval)) {
   4409 			if (offsetp != NULL)
   4410 				*offsetp = off;
   4411 			return 1;
   4412 		}
   4413 	}
   4414 	return 0;
   4415 }
   4416 
   4417 static void
   4418 pci_conf_print_extcaplist(
   4419 #ifdef _KERNEL
   4420     pci_chipset_tag_t pc, pcitag_t tag,
   4421 #endif
   4422     const pcireg_t *regs)
   4423 {
   4424 	int off;
   4425 	pcireg_t foundcap;
   4426 	pcireg_t rval;
   4427 	bool foundtable[__arraycount(pci_extcaptab)];
   4428 	unsigned int i;
   4429 
   4430 	/* Check Extended capability structure */
   4431 	off = PCI_EXTCAPLIST_BASE;
   4432 	rval = regs[o2i(off)];
   4433 	if (rval == 0xffffffff || rval == 0)
   4434 		return;
   4435 
   4436 	/* Clear table */
   4437 	for (i = 0; i < __arraycount(pci_extcaptab); i++)
   4438 		foundtable[i] = false;
   4439 
   4440 	/* Print extended capability register's offset and the type first */
   4441 	for (;;) {
   4442 		printf("  Extended Capability Register at 0x%02x\n", off);
   4443 
   4444 		foundcap = PCI_EXTCAPLIST_CAP(rval);
   4445 		printf("    type: 0x%04x (", foundcap);
   4446 		if (foundcap < __arraycount(pci_extcaptab)) {
   4447 			printf("%s)\n", pci_extcaptab[foundcap].name);
   4448 			/* Mark as found */
   4449 			foundtable[foundcap] = true;
   4450 		} else
   4451 			printf("unknown)\n");
   4452 		printf("    version: %d\n", PCI_EXTCAPLIST_VERSION(rval));
   4453 
   4454 		off = PCI_EXTCAPLIST_NEXT(rval);
   4455 		if (off == 0)
   4456 			break;
   4457 		else if (off <= PCI_CONF_SIZE) {
   4458 			printf("    next pointer: 0x%03x (incorrect)\n", off);
   4459 			return;
   4460 		}
   4461 		rval = regs[o2i(off)];
   4462 	}
   4463 
   4464 	/*
   4465 	 * And then, print the detail of each capability registers
   4466 	 * in capability value's order.
   4467 	 */
   4468 	for (i = 0; i < __arraycount(pci_extcaptab); i++) {
   4469 		if (foundtable[i] == false)
   4470 			continue;
   4471 
   4472 		/*
   4473 		 * The type was found. Search capability list again and
   4474 		 * print all capabilities that the capability type is
   4475 		 * the same.
   4476 		 */
   4477 		if (pci_conf_find_extcap(regs, i, &off) == 0)
   4478 			continue;
   4479 		rval = regs[o2i(off)];
   4480 		if ((PCI_EXTCAPLIST_VERSION(rval) <= 0)
   4481 		    || (pci_extcaptab[i].printfunc == NULL))
   4482 			continue;
   4483 
   4484 		pci_extcaptab[i].printfunc(regs, off);
   4485 
   4486 	}
   4487 }
   4488 
   4489 /* Print the Secondary Status Register. */
   4490 static void
   4491 pci_conf_print_ssr(pcireg_t rval)
   4492 {
   4493 	pcireg_t devsel;
   4494 
   4495 	printf("    Secondary status register: 0x%04x\n", rval); /* XXX bits */
   4496 	onoff("66 MHz capable", rval, __BIT(5));
   4497 	onoff("User Definable Features (UDF) support", rval, __BIT(6));
   4498 	onoff("Fast back-to-back capable", rval, __BIT(7));
   4499 	onoff("Data parity error detected", rval, __BIT(8));
   4500 
   4501 	printf("      DEVSEL timing: ");
   4502 	devsel = PCIREG_SHIFTOUT(rval, __BITS(10, 9));
   4503 	switch (devsel) {
   4504 	case 0:
   4505 		printf("fast");
   4506 		break;
   4507 	case 1:
   4508 		printf("medium");
   4509 		break;
   4510 	case 2:
   4511 		printf("slow");
   4512 		break;
   4513 	default:
   4514 		printf("unknown/reserved");	/* XXX */
   4515 		break;
   4516 	}
   4517 	printf(" (0x%x)\n", devsel);
   4518 
   4519 	onoff("Signalled target abort", rval, __BIT(11));
   4520 	onoff("Received target abort", rval, __BIT(12));
   4521 	onoff("Received master abort", rval, __BIT(13));
   4522 	onoff("Received system error", rval, __BIT(14));
   4523 	onoff("Detected parity error", rval, __BIT(15));
   4524 }
   4525 
   4526 static void
   4527 pci_conf_print_type0(
   4528 #ifdef _KERNEL
   4529     pci_chipset_tag_t pc, pcitag_t tag,
   4530 #endif
   4531     const pcireg_t *regs)
   4532 {
   4533 	int off, width;
   4534 	pcireg_t rval;
   4535 	const char *str;
   4536 
   4537 	for (off = PCI_MAPREG_START; off < PCI_MAPREG_END; off += width) {
   4538 #ifdef _KERNEL
   4539 		width = pci_conf_print_bar(pc, tag, regs, off, NULL);
   4540 #else
   4541 		width = pci_conf_print_bar(regs, off, NULL);
   4542 #endif
   4543 	}
   4544 
   4545 	printf("    Cardbus CIS Pointer: 0x%08x\n",
   4546 	    regs[o2i(PCI_CARDBUS_CIS_REG)]);
   4547 
   4548 	rval = regs[o2i(PCI_SUBSYS_ID_REG)];
   4549 	printf("    Subsystem vendor ID: 0x%04x\n", PCI_VENDOR(rval));
   4550 	printf("    Subsystem ID: 0x%04x\n", PCI_PRODUCT(rval));
   4551 
   4552 	rval = regs[o2i(PCI_MAPREG_ROM)];
   4553 	printf("    Expansion ROM Base Address Register: 0x%08x\n", rval);
   4554 	printf("      base: 0x%08x\n", (uint32_t)PCI_MAPREG_ROM_ADDR(rval));
   4555 	onoff("Expansion ROM Enable", rval, PCI_MAPREG_ROM_ENABLE);
   4556 	printf("      Validation Status: ");
   4557 	switch (PCIREG_SHIFTOUT(rval, PCI_MAPREG_ROM_VALID_STAT)) {
   4558 	case PCI_MAPREG_ROM_VSTAT_NOTSUPP:
   4559 		str = "Validation not supported";
   4560 		break;
   4561 	case PCI_MAPREG_ROM_VSTAT_INPROG:
   4562 		str = "Validation in Progress";
   4563 		break;
   4564 	case PCI_MAPREG_ROM_VSTAT_VPASS:
   4565 		str = "Validation Pass. "
   4566 		    "Valid contents, trust test was not performed";
   4567 		break;
   4568 	case PCI_MAPREG_ROM_VSTAT_VPASSTRUST:
   4569 		str = "Validation Pass. Valid and trusted contents";
   4570 		break;
   4571 	case PCI_MAPREG_ROM_VSTAT_VFAIL:
   4572 		str = "Validation Fail. Invalid contents";
   4573 		break;
   4574 	case PCI_MAPREG_ROM_VSTAT_VFAILUNTRUST:
   4575 		str = "Validation Fail. Valid but untrusted contents";
   4576 		break;
   4577 	case PCI_MAPREG_ROM_VSTAT_WPASS:
   4578 		str = "Warning Pass. Validation passed with warning. "
   4579 		    "Valid contents, trust test was not performed";
   4580 		break;
   4581 	case PCI_MAPREG_ROM_VSTAT_WPASSTRUST:
   4582 		str = "Warning Pass. Validation passed with warning. "
   4583 		    "Valid and trusted contents";
   4584 		break;
   4585 	}
   4586 	printf("%s\n", str);
   4587 	printf("      Validation Details: 0x%x\n",
   4588 	    PCIREG_SHIFTOUT(rval, PCI_MAPREG_ROM_VALID_DETAIL));
   4589 
   4590 	if (regs[o2i(PCI_COMMAND_STATUS_REG)] & PCI_STATUS_CAPLIST_SUPPORT)
   4591 		printf("    Capability list pointer: 0x%02x\n",
   4592 		    PCI_CAPLIST_PTR(regs[o2i(PCI_CAPLISTPTR_REG)]));
   4593 	else
   4594 		printf("    Reserved @ 0x34: 0x%08x\n", regs[o2i(0x34)]);
   4595 
   4596 	printf("    Reserved @ 0x38: 0x%08x\n", regs[o2i(0x38)]);
   4597 
   4598 	rval = regs[o2i(PCI_INTERRUPT_REG)];
   4599 	printf("    Maximum Latency: 0x%02x\n", PCI_MAX_LAT(rval));
   4600 	printf("    Minimum Grant: 0x%02x\n", PCI_MIN_GNT(rval));
   4601 	printf("    Interrupt pin: 0x%02x ", PCI_INTERRUPT_PIN(rval));
   4602 	switch (PCI_INTERRUPT_PIN(rval)) {
   4603 	case PCI_INTERRUPT_PIN_NONE:
   4604 		printf("(none)");
   4605 		break;
   4606 	case PCI_INTERRUPT_PIN_A:
   4607 		printf("(pin A)");
   4608 		break;
   4609 	case PCI_INTERRUPT_PIN_B:
   4610 		printf("(pin B)");
   4611 		break;
   4612 	case PCI_INTERRUPT_PIN_C:
   4613 		printf("(pin C)");
   4614 		break;
   4615 	case PCI_INTERRUPT_PIN_D:
   4616 		printf("(pin D)");
   4617 		break;
   4618 	default:
   4619 		printf("(? ? ?)");
   4620 		break;
   4621 	}
   4622 	printf("\n");
   4623 	printf("    Interrupt line: 0x%02x\n", PCI_INTERRUPT_LINE(rval));
   4624 }
   4625 
   4626 static void
   4627 pci_conf_print_type1(
   4628 #ifdef _KERNEL
   4629     pci_chipset_tag_t pc, pcitag_t tag,
   4630 #endif
   4631     const pcireg_t *regs)
   4632 {
   4633 	int off, width;
   4634 	pcireg_t rval, csreg;
   4635 	uint32_t base, limit;
   4636 	uint32_t base_h, limit_h;
   4637 	uint64_t pbase, plimit;
   4638 	int use_upper;
   4639 
   4640 	/*
   4641 	 * This layout was cribbed from the TI PCI2030 PCI-to-PCI
   4642 	 * Bridge chip documentation, and may not be correct with
   4643 	 * respect to various standards. (XXX)
   4644 	 */
   4645 
   4646 	for (off = 0x10; off < 0x18; off += width) {
   4647 #ifdef _KERNEL
   4648 		width = pci_conf_print_bar(pc, tag, regs, off, NULL);
   4649 #else
   4650 		width = pci_conf_print_bar(regs, off, NULL);
   4651 #endif
   4652 	}
   4653 
   4654 	rval = regs[o2i(PCI_BRIDGE_BUS_REG)];
   4655 	printf("    Primary bus number: 0x%02x\n",
   4656 	    PCI_BRIDGE_BUS_NUM_PRIMARY(rval));
   4657 	printf("    Secondary bus number: 0x%02x\n",
   4658 	    PCI_BRIDGE_BUS_NUM_SECONDARY(rval));
   4659 	printf("    Subordinate bus number: 0x%02x\n",
   4660 	    PCI_BRIDGE_BUS_NUM_SUBORDINATE(rval));
   4661 	printf("    Secondary bus latency timer: 0x%02x\n",
   4662 	    PCI_BRIDGE_BUS_SEC_LATTIMER_VAL(rval));
   4663 
   4664 	rval = regs[o2i(PCI_BRIDGE_STATIO_REG)];
   4665 	pci_conf_print_ssr(PCIREG_SHIFTOUT(rval, __BITS(31, 16)));
   4666 
   4667 	/* I/O region */
   4668 	printf("    I/O region:\n");
   4669 	printf("      base register:  0x%02x\n", (rval >> 0) & 0xff);
   4670 	printf("      limit register: 0x%02x\n", (rval >> 8) & 0xff);
   4671 	if (PCI_BRIDGE_IO_32BITS(rval))
   4672 		use_upper = 1;
   4673 	else
   4674 		use_upper = 0;
   4675 	onoff("32bit I/O", rval, use_upper);
   4676 	base = PCI_BRIDGE_STATIO_IOBASE_ADDR(rval);
   4677 	limit = PCI_BRIDGE_STATIO_IOLIMIT_ADDR(rval);
   4678 
   4679 	rval = regs[o2i(PCI_BRIDGE_IOHIGH_REG)];
   4680 	base_h = PCIREG_SHIFTOUT(rval, PCI_BRIDGE_IOHIGH_BASE);
   4681 	limit_h = PCIREG_SHIFTOUT(rval, PCI_BRIDGE_IOHIGH_LIMIT);
   4682 	printf("      base upper 16 bits register:  0x%04x\n", base_h);
   4683 	printf("      limit upper 16 bits register: 0x%04x\n", limit_h);
   4684 
   4685 	if (use_upper == 1) {
   4686 		base |= base_h << 16;
   4687 		limit |= limit_h << 16;
   4688 	}
   4689 	if (base < limit) {
   4690 		if (use_upper == 1)
   4691 			printf("      range: 0x%08x-0x%08x\n", base, limit);
   4692 		else
   4693 			printf("      range: 0x%04x-0x%04x\n", base, limit);
   4694 	} else
   4695 		printf("      range:  not set\n");
   4696 
   4697 	/* Non-prefetchable memory region */
   4698 	rval = regs[o2i(PCI_BRIDGE_MEMORY_REG)];
   4699 	printf("    Memory region:\n");
   4700 	printf("      base register:  0x%04hx\n",
   4701 	    (uint16_t)PCIREG_SHIFTOUT(rval, PCI_BRIDGE_MEMORY_BASE));
   4702 	printf("      limit register: 0x%04hx\n",
   4703 	    (uint16_t)PCIREG_SHIFTOUT(rval, PCI_BRIDGE_MEMORY_LIMIT));
   4704 	base = PCI_BRIDGE_MEMORY_BASE_ADDR(rval);
   4705 	limit = PCI_BRIDGE_MEMORY_LIMIT_ADDR(rval);
   4706 	if (base < limit)
   4707 		printf("      range: 0x%08x-0x%08x\n", base, limit);
   4708 	else
   4709 		printf("      range: not set\n");
   4710 
   4711 	/* Prefetchable memory region */
   4712 	rval = regs[o2i(PCI_BRIDGE_PREFETCHMEM_REG)];
   4713 	printf("    Prefetchable memory region:\n");
   4714 	printf("      base register:  0x%04x\n",
   4715 	    (rval >> 0) & 0xffff);
   4716 	printf("      limit register: 0x%04x\n",
   4717 	    (rval >> 16) & 0xffff);
   4718 	base_h = regs[o2i(PCI_BRIDGE_PREFETCHBASEUP32_REG)];
   4719 	limit_h = regs[o2i(PCI_BRIDGE_PREFETCHLIMITUP32_REG)];
   4720 	printf("      base upper 32 bits register:  0x%08x\n",
   4721 	    base_h);
   4722 	printf("      limit upper 32 bits register: 0x%08x\n",
   4723 	    limit_h);
   4724 	if (PCI_BRIDGE_PREFETCHMEM_64BITS(rval))
   4725 		use_upper = 1;
   4726 	else
   4727 		use_upper = 0;
   4728 	onoff("64bit memory address", rval, use_upper);
   4729 	pbase = PCI_BRIDGE_PREFETCHMEM_BASE_ADDR(rval);
   4730 	plimit = PCI_BRIDGE_PREFETCHMEM_LIMIT_ADDR(rval);
   4731 	if (use_upper == 1) {
   4732 		pbase |= (uint64_t)base_h << 32;
   4733 		plimit |= (uint64_t)limit_h << 32;
   4734 	}
   4735 	if (pbase < plimit) {
   4736 		if (use_upper == 1)
   4737 			printf("      range: 0x%016" PRIx64 "-0x%016" PRIx64
   4738 			    "\n", pbase, plimit);
   4739 		else
   4740 			printf("      range: 0x%08x-0x%08x\n",
   4741 			    (uint32_t)pbase, (uint32_t)plimit);
   4742 	} else
   4743 		printf("      range: not set\n");
   4744 
   4745 	csreg = regs[o2i(PCI_COMMAND_STATUS_REG)];
   4746 	if (csreg & PCI_STATUS_CAPLIST_SUPPORT)
   4747 		printf("    Capability list pointer: 0x%02x\n",
   4748 		    PCI_CAPLIST_PTR(regs[o2i(PCI_CAPLISTPTR_REG)]));
   4749 	else
   4750 		printf("    Reserved @ 0x34: 0x%08x\n", regs[o2i(0x34)]);
   4751 
   4752 	printf("    Expansion ROM Base Address: 0x%08x\n",
   4753 	    regs[o2i(PCI_BRIDGE_EXPROMADDR_REG)]);
   4754 
   4755 	rval = regs[o2i(PCI_INTERRUPT_REG)];
   4756 	printf("    Interrupt line: 0x%02x\n",
   4757 	    (rval >> 0) & 0xff);
   4758 	printf("    Interrupt pin: 0x%02x ",
   4759 	    (rval >> 8) & 0xff);
   4760 	switch ((rval >> 8) & 0xff) {
   4761 	case PCI_INTERRUPT_PIN_NONE:
   4762 		printf("(none)");
   4763 		break;
   4764 	case PCI_INTERRUPT_PIN_A:
   4765 		printf("(pin A)");
   4766 		break;
   4767 	case PCI_INTERRUPT_PIN_B:
   4768 		printf("(pin B)");
   4769 		break;
   4770 	case PCI_INTERRUPT_PIN_C:
   4771 		printf("(pin C)");
   4772 		break;
   4773 	case PCI_INTERRUPT_PIN_D:
   4774 		printf("(pin D)");
   4775 		break;
   4776 	default:
   4777 		printf("(? ? ?)");
   4778 		break;
   4779 	}
   4780 	printf("\n");
   4781 	rval = regs[o2i(PCI_BRIDGE_CONTROL_REG)];
   4782 	printf("    Bridge control register: 0x%04hx\n",
   4783 	    (uint16_t)PCIREG_SHIFTOUT(rval, PCI_BRIDGE_CONTROL));
   4784 	onoff("Parity error response", rval, PCI_BRIDGE_CONTROL_PERE);
   4785 	onoff("Secondary SERR forwarding", rval, PCI_BRIDGE_CONTROL_SERR);
   4786 	onoff("ISA enable", rval, PCI_BRIDGE_CONTROL_ISA);
   4787 	onoff("VGA enable", rval, PCI_BRIDGE_CONTROL_VGA);
   4788 	/*
   4789 	 * VGA 16bit decode bit has meaning if the VGA enable bit or the
   4790 	 * VGA Palette Snoop Enable bit is set.
   4791 	 */
   4792 	if (((rval & PCI_BRIDGE_CONTROL_VGA) != 0)
   4793 	    || ((csreg & PCI_COMMAND_PALETTE_ENABLE) != 0))
   4794 		onoff("VGA 16bit enable", rval, PCI_BRIDGE_CONTROL_VGA16);
   4795 	onoff("Master abort reporting", rval, PCI_BRIDGE_CONTROL_MABRT);
   4796 	onoff("Secondary bus reset", rval, PCI_BRIDGE_CONTROL_SECBR);
   4797 	onoff("Fast back-to-back enable", rval, PCI_BRIDGE_CONTROL_SECFASTB2B);
   4798 	onoff("Primary Discard Timer", rval,
   4799 	    PCI_BRIDGE_CONTROL_PRI_DISC_TIMER);
   4800 	onoff("Secondary Discard Timer",
   4801 	    rval, PCI_BRIDGE_CONTROL_SEC_DISC_TIMER);
   4802 	onoff("Discard Timer Status", rval,
   4803 	    PCI_BRIDGE_CONTROL_DISC_TIMER_STAT);
   4804 	onoff("Discard Timer SERR# Enable", rval,
   4805 	    PCI_BRIDGE_CONTROL_DISC_TIMER_SERR);
   4806 }
   4807 
   4808 static void
   4809 pci_conf_print_type2(
   4810 #ifdef _KERNEL
   4811     pci_chipset_tag_t pc, pcitag_t tag,
   4812 #endif
   4813     const pcireg_t *regs)
   4814 {
   4815 	pcireg_t rval;
   4816 
   4817 	/*
   4818 	 * XXX these need to be printed in more detail, need to be
   4819 	 * XXX checked against specs/docs, etc.
   4820 	 *
   4821 	 * This layout was cribbed from the TI PCI1420 PCI-to-CardBus
   4822 	 * controller chip documentation, and may not be correct with
   4823 	 * respect to various standards. (XXX)
   4824 	 */
   4825 
   4826 #ifdef _KERNEL
   4827 	pci_conf_print_bar(pc, tag, regs, 0x10,
   4828 	    "CardBus socket/ExCA registers");
   4829 #else
   4830 	pci_conf_print_bar(regs, 0x10, "CardBus socket/ExCA registers");
   4831 #endif
   4832 
   4833 	/* Capability list pointer and secondary status register */
   4834 	rval = regs[o2i(PCI_CARDBUS_CAPLISTPTR_REG)];
   4835 	if (regs[o2i(PCI_COMMAND_STATUS_REG)] & PCI_STATUS_CAPLIST_SUPPORT)
   4836 		printf("    Capability list pointer: 0x%02x\n",
   4837 		    PCI_CAPLIST_PTR(rval));
   4838 	else
   4839 		printf("    Reserved @ 0x14: 0x%04x\n",
   4840 		       PCIREG_SHIFTOUT(rval, __BITS(15, 0)));
   4841 	pci_conf_print_ssr(PCIREG_SHIFTOUT(rval, __BITS(31, 16)));
   4842 
   4843 	rval = regs[o2i(PCI_BRIDGE_BUS_REG)];
   4844 	printf("    PCI bus number: 0x%02x\n",
   4845 	    (rval >> 0) & 0xff);
   4846 	printf("    CardBus bus number: 0x%02x\n",
   4847 	    (rval >> 8) & 0xff);
   4848 	printf("    Subordinate bus number: 0x%02x\n",
   4849 	    (rval >> 16) & 0xff);
   4850 	printf("    CardBus latency timer: 0x%02x\n",
   4851 	    (rval >> 24) & 0xff);
   4852 
   4853 	/* XXX Print more prettily */
   4854 	printf("    CardBus memory region 0:\n");
   4855 	printf("      base register:  0x%08x\n", regs[o2i(0x1c)]);
   4856 	printf("      limit register: 0x%08x\n", regs[o2i(0x20)]);
   4857 	printf("    CardBus memory region 1:\n");
   4858 	printf("      base register:  0x%08x\n", regs[o2i(0x24)]);
   4859 	printf("      limit register: 0x%08x\n", regs[o2i(0x28)]);
   4860 	printf("    CardBus I/O region 0:\n");
   4861 	printf("      base register:  0x%08x\n", regs[o2i(0x2c)]);
   4862 	printf("      limit register: 0x%08x\n", regs[o2i(0x30)]);
   4863 	printf("    CardBus I/O region 1:\n");
   4864 	printf("      base register:  0x%08x\n", regs[o2i(0x34)]);
   4865 	printf("      limit register: 0x%08x\n", regs[o2i(0x38)]);
   4866 
   4867 	rval = regs[o2i(PCI_INTERRUPT_REG)];
   4868 	printf("    Interrupt line: 0x%02x\n",
   4869 	    (rval >> 0) & 0xff);
   4870 	printf("    Interrupt pin: 0x%02x ",
   4871 	    (rval >> 8) & 0xff);
   4872 	switch ((rval >> 8) & 0xff) {
   4873 	case PCI_INTERRUPT_PIN_NONE:
   4874 		printf("(none)");
   4875 		break;
   4876 	case PCI_INTERRUPT_PIN_A:
   4877 		printf("(pin A)");
   4878 		break;
   4879 	case PCI_INTERRUPT_PIN_B:
   4880 		printf("(pin B)");
   4881 		break;
   4882 	case PCI_INTERRUPT_PIN_C:
   4883 		printf("(pin C)");
   4884 		break;
   4885 	case PCI_INTERRUPT_PIN_D:
   4886 		printf("(pin D)");
   4887 		break;
   4888 	default:
   4889 		printf("(? ? ?)");
   4890 		break;
   4891 	}
   4892 	printf("\n");
   4893 	rval = (regs[o2i(PCI_BRIDGE_CONTROL_REG)] >> 16) & 0xffff;
   4894 	printf("    Bridge control register: 0x%04x\n", rval);
   4895 	onoff("Parity error response", rval, __BIT(0));
   4896 	onoff("SERR# enable", rval, __BIT(1));
   4897 	onoff("ISA enable", rval, __BIT(2));
   4898 	onoff("VGA enable", rval, __BIT(3));
   4899 	onoff("Master abort mode", rval, __BIT(5));
   4900 	onoff("Secondary (CardBus) bus reset", rval, __BIT(6));
   4901 	onoff("Functional interrupts routed by ExCA registers", rval,
   4902 	    __BIT(7));
   4903 	onoff("Memory window 0 prefetchable", rval, __BIT(8));
   4904 	onoff("Memory window 1 prefetchable", rval, __BIT(9));
   4905 	onoff("Write posting enable", rval, __BIT(10));
   4906 
   4907 	rval = regs[o2i(0x40)];
   4908 	printf("    Subsystem vendor ID: 0x%04x\n", PCI_VENDOR(rval));
   4909 	printf("    Subsystem ID: 0x%04x\n", PCI_PRODUCT(rval));
   4910 
   4911 #ifdef _KERNEL
   4912 	pci_conf_print_bar(pc, tag, regs, 0x44, "legacy-mode registers");
   4913 #else
   4914 	pci_conf_print_bar(regs, 0x44, "legacy-mode registers");
   4915 #endif
   4916 }
   4917 
   4918 void
   4919 pci_conf_print(
   4920 #ifdef _KERNEL
   4921     pci_chipset_tag_t pc, pcitag_t tag,
   4922     void (*printfn)(pci_chipset_tag_t, pcitag_t, const pcireg_t *)
   4923 #else
   4924     int pcifd, u_int bus, u_int dev, u_int func
   4925 #endif
   4926     )
   4927 {
   4928 	pcireg_t *regs;
   4929 	int off, capoff, endoff, hdrtype;
   4930 	const char *type_name;
   4931 #ifdef _KERNEL
   4932 	void (*type_printfn)(pci_chipset_tag_t, pcitag_t, const pcireg_t *);
   4933 #else
   4934 	void (*type_printfn)(const pcireg_t *);
   4935 #endif
   4936 
   4937 	regs = MALLOC(PCI_EXTCONF_SIZE);
   4938 
   4939 	printf("PCI configuration registers:\n");
   4940 
   4941 	for (off = 0; off < PCI_EXTCONF_SIZE; off += 4) {
   4942 #ifdef _KERNEL
   4943 		regs[o2i(off)] = pci_conf_read(pc, tag, off);
   4944 #else
   4945 		if (pcibus_conf_read(pcifd, bus, dev, func, off,
   4946 		    &regs[o2i(off)]) == -1)
   4947 			regs[o2i(off)] = 0;
   4948 #endif
   4949 	}
   4950 
   4951 	/* common header */
   4952 	printf("  Common header:\n");
   4953 	pci_conf_print_regs(regs, 0, 16);
   4954 
   4955 	printf("\n");
   4956 #ifdef _KERNEL
   4957 	pci_conf_print_common(pc, tag, regs);
   4958 #else
   4959 	pci_conf_print_common(regs);
   4960 #endif
   4961 	printf("\n");
   4962 
   4963 	/* type-dependent header */
   4964 	hdrtype = PCI_HDRTYPE_TYPE(regs[o2i(PCI_BHLC_REG)]);
   4965 	switch (hdrtype) {		/* XXX make a table, eventually */
   4966 	case 0:
   4967 		/* Standard device header */
   4968 		type_name = "\"normal\" device";
   4969 		type_printfn = &pci_conf_print_type0;
   4970 		capoff = PCI_CAPLISTPTR_REG;
   4971 		endoff = 64;
   4972 		break;
   4973 	case 1:
   4974 		/* PCI-PCI bridge header */
   4975 		type_name = "PCI-PCI bridge";
   4976 		type_printfn = &pci_conf_print_type1;
   4977 		capoff = PCI_CAPLISTPTR_REG;
   4978 		endoff = 64;
   4979 		break;
   4980 	case 2:
   4981 		/* PCI-CardBus bridge header */
   4982 		type_name = "PCI-CardBus bridge";
   4983 		type_printfn = &pci_conf_print_type2;
   4984 		capoff = PCI_CARDBUS_CAPLISTPTR_REG;
   4985 		endoff = 72;
   4986 		break;
   4987 	default:
   4988 		type_name = NULL;
   4989 		type_printfn = 0;
   4990 		capoff = -1;
   4991 		endoff = 64;
   4992 		break;
   4993 	}
   4994 	printf("  Type %d ", hdrtype);
   4995 	if (type_name != NULL)
   4996 		printf("(%s) ", type_name);
   4997 	printf("header:\n");
   4998 	pci_conf_print_regs(regs, 16, endoff);
   4999 	printf("\n");
   5000 	if (type_printfn) {
   5001 #ifdef _KERNEL
   5002 		(*type_printfn)(pc, tag, regs);
   5003 #else
   5004 		(*type_printfn)(regs);
   5005 #endif
   5006 	} else
   5007 		printf("    Don't know how to pretty-print type %d header.\n",
   5008 		    hdrtype);
   5009 	printf("\n");
   5010 
   5011 	/* capability list, if present */
   5012 	if ((regs[o2i(PCI_COMMAND_STATUS_REG)] & PCI_STATUS_CAPLIST_SUPPORT)
   5013 		&& (capoff > 0)) {
   5014 #ifdef _KERNEL
   5015 		pci_conf_print_caplist(pc, tag, regs, capoff);
   5016 #else
   5017 		pci_conf_print_caplist(regs, capoff);
   5018 #endif
   5019 		printf("\n");
   5020 	}
   5021 
   5022 	/* device-dependent header */
   5023 	printf("  Device-dependent header:\n");
   5024 	pci_conf_print_regs(regs, endoff, PCI_CONF_SIZE);
   5025 #ifdef _KERNEL
   5026 	printf("\n");
   5027 	if (printfn)
   5028 		(*printfn)(pc, tag, regs);
   5029 	else
   5030 		printf("    Don't know how to pretty-print device-dependent header.\n");
   5031 #endif /* _KERNEL */
   5032 
   5033 	if (regs[o2i(PCI_EXTCAPLIST_BASE)] == 0xffffffff ||
   5034 	    regs[o2i(PCI_EXTCAPLIST_BASE)] == 0)
   5035 		goto out;
   5036 
   5037 	printf("\n");
   5038 #ifdef _KERNEL
   5039 	pci_conf_print_extcaplist(pc, tag, regs);
   5040 #else
   5041 	pci_conf_print_extcaplist(regs);
   5042 #endif
   5043 	printf("\n");
   5044 
   5045 	/* Extended Configuration Space, if present */
   5046 	printf("  Extended Configuration Space:\n");
   5047 	pci_conf_print_regs(regs, PCI_EXTCAPLIST_BASE, PCI_EXTCONF_SIZE);
   5048 
   5049 out:
   5050 	FREE(regs, PCI_EXTCONF_SIZE);
   5051 }
   5052