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