1 /* $NetBSD: pci_subr.c,v 1.133 2014/11/24 07:53:43 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.133 2014/11/24 07:53:43 msaitoh Exp $"); 44 45 #ifdef _KERNEL_OPT 46 #include "opt_pci.h" 47 #endif 48 49 #include <sys/param.h> 50 51 #ifdef _KERNEL 52 #include <sys/systm.h> 53 #include <sys/intr.h> 54 #include <sys/module.h> 55 #else 56 #include <pci.h> 57 #include <stdbool.h> 58 #include <stdio.h> 59 #include <string.h> 60 #endif 61 62 #include <dev/pci/pcireg.h> 63 #ifdef _KERNEL 64 #include <dev/pci/pcivar.h> 65 #else 66 #include <dev/pci/pci_verbose.h> 67 #include <dev/pci/pcidevs.h> 68 #include <dev/pci/pcidevs_data.h> 69 #endif 70 71 /* 72 * Descriptions of known PCI classes and subclasses. 73 * 74 * Subclasses are described in the same way as classes, but have a 75 * NULL subclass pointer. 76 */ 77 struct pci_class { 78 const char *name; 79 u_int val; /* as wide as pci_{,sub}class_t */ 80 const struct pci_class *subclasses; 81 }; 82 83 /* 84 * Class 0x00. 85 * Before rev. 2.0. 86 */ 87 static const struct pci_class pci_subclass_prehistoric[] = { 88 { "miscellaneous", PCI_SUBCLASS_PREHISTORIC_MISC, NULL, }, 89 { "VGA", PCI_SUBCLASS_PREHISTORIC_VGA, NULL, }, 90 { NULL, 0, NULL, }, 91 }; 92 93 /* 94 * Class 0x01. 95 * Mass storage controller 96 */ 97 98 /* ATA programming interface */ 99 static const struct pci_class pci_interface_ata[] = { 100 { "with single DMA", PCI_INTERFACE_ATA_SINGLEDMA, NULL, }, 101 { "with chained DMA", PCI_INTERFACE_ATA_CHAINEDDMA, NULL, }, 102 { NULL, 0, NULL, }, 103 }; 104 105 /* SATA programming interface */ 106 static const struct pci_class pci_interface_sata[] = { 107 { "vendor specific", PCI_INTERFACE_SATA_VND, NULL, }, 108 { "AHCI 1.0", PCI_INTERFACE_SATA_AHCI10, NULL, }, 109 { "Serial Storage Bus Interface", PCI_INTERFACE_SATA_SSBI, NULL, }, 110 { NULL, 0, NULL, }, 111 }; 112 113 /* Flash programming interface */ 114 static const struct pci_class pci_interface_nvm[] = { 115 { "vendor specific", PCI_INTERFACE_NVM_VND, NULL, }, 116 { "NVMHCI 1.0", PCI_INTERFACE_NVM_NVMHCI10, NULL, }, 117 { NULL, 0, NULL, }, 118 }; 119 120 /* Subclasses */ 121 static const struct pci_class pci_subclass_mass_storage[] = { 122 { "SCSI", PCI_SUBCLASS_MASS_STORAGE_SCSI, NULL, }, 123 { "IDE", PCI_SUBCLASS_MASS_STORAGE_IDE, NULL, }, 124 { "floppy", PCI_SUBCLASS_MASS_STORAGE_FLOPPY, NULL, }, 125 { "IPI", PCI_SUBCLASS_MASS_STORAGE_IPI, NULL, }, 126 { "RAID", PCI_SUBCLASS_MASS_STORAGE_RAID, NULL, }, 127 { "ATA", PCI_SUBCLASS_MASS_STORAGE_ATA, 128 pci_interface_ata, }, 129 { "SATA", PCI_SUBCLASS_MASS_STORAGE_SATA, 130 pci_interface_sata, }, 131 { "SAS", PCI_SUBCLASS_MASS_STORAGE_SAS, NULL, }, 132 { "Flash", PCI_SUBCLASS_MASS_STORAGE_NVM, 133 pci_interface_nvm, }, 134 { "miscellaneous", PCI_SUBCLASS_MASS_STORAGE_MISC, NULL, }, 135 { NULL, 0, NULL, }, 136 }; 137 138 /* 139 * Class 0x02. 140 * Network controller. 141 */ 142 static const struct pci_class pci_subclass_network[] = { 143 { "ethernet", PCI_SUBCLASS_NETWORK_ETHERNET, NULL, }, 144 { "token ring", PCI_SUBCLASS_NETWORK_TOKENRING, NULL, }, 145 { "FDDI", PCI_SUBCLASS_NETWORK_FDDI, NULL, }, 146 { "ATM", PCI_SUBCLASS_NETWORK_ATM, NULL, }, 147 { "ISDN", PCI_SUBCLASS_NETWORK_ISDN, NULL, }, 148 { "WorldFip", PCI_SUBCLASS_NETWORK_WORLDFIP, NULL, }, 149 { "PCMIG Multi Computing", PCI_SUBCLASS_NETWORK_PCIMGMULTICOMP, NULL, }, 150 { "miscellaneous", PCI_SUBCLASS_NETWORK_MISC, NULL, }, 151 { NULL, 0, NULL, }, 152 }; 153 154 /* 155 * Class 0x03. 156 * Display controller. 157 */ 158 159 /* VGA programming interface */ 160 static const struct pci_class pci_interface_vga[] = { 161 { "", PCI_INTERFACE_VGA_VGA, NULL, }, 162 { "8514-compat", PCI_INTERFACE_VGA_8514, NULL, }, 163 { NULL, 0, NULL, }, 164 }; 165 /* Subclasses */ 166 static const struct pci_class pci_subclass_display[] = { 167 { "VGA", PCI_SUBCLASS_DISPLAY_VGA, pci_interface_vga,}, 168 { "XGA", PCI_SUBCLASS_DISPLAY_XGA, NULL, }, 169 { "3D", PCI_SUBCLASS_DISPLAY_3D, NULL, }, 170 { "miscellaneous", PCI_SUBCLASS_DISPLAY_MISC, NULL, }, 171 { NULL, 0, NULL, }, 172 }; 173 174 /* 175 * Class 0x04. 176 * Multimedia device. 177 */ 178 static const struct pci_class pci_subclass_multimedia[] = { 179 { "video", PCI_SUBCLASS_MULTIMEDIA_VIDEO, NULL, }, 180 { "audio", PCI_SUBCLASS_MULTIMEDIA_AUDIO, NULL, }, 181 { "telephony", PCI_SUBCLASS_MULTIMEDIA_TELEPHONY, NULL,}, 182 { "mixed mode", PCI_SUBCLASS_MULTIMEDIA_HDAUDIO, NULL, }, 183 { "miscellaneous", PCI_SUBCLASS_MULTIMEDIA_MISC, NULL, }, 184 { NULL, 0, NULL, }, 185 }; 186 187 /* 188 * Class 0x05. 189 * Memory controller. 190 */ 191 static const struct pci_class pci_subclass_memory[] = { 192 { "RAM", PCI_SUBCLASS_MEMORY_RAM, NULL, }, 193 { "flash", PCI_SUBCLASS_MEMORY_FLASH, NULL, }, 194 { "miscellaneous", PCI_SUBCLASS_MEMORY_MISC, NULL, }, 195 { NULL, 0, NULL, }, 196 }; 197 198 /* 199 * Class 0x06. 200 * Bridge device. 201 */ 202 203 /* PCI bridge programming interface */ 204 static const struct pci_class pci_interface_pcibridge[] = { 205 { "", PCI_INTERFACE_BRIDGE_PCI_PCI, NULL, }, 206 { "subtractive decode", PCI_INTERFACE_BRIDGE_PCI_SUBDEC, NULL, }, 207 { NULL, 0, NULL, }, 208 }; 209 210 /* Semi-transparent PCI-to-PCI bridge programming interface */ 211 static const struct pci_class pci_interface_stpci[] = { 212 { "primary side facing host", PCI_INTERFACE_STPCI_PRIMARY, NULL, }, 213 { "secondary side facing host", PCI_INTERFACE_STPCI_SECONDARY, NULL, }, 214 { NULL, 0, NULL, }, 215 }; 216 217 /* Advanced Switching programming interface */ 218 static const struct pci_class pci_interface_advsw[] = { 219 { "custom interface", PCI_INTERFACE_ADVSW_CUSTOM, NULL, }, 220 { "ASI-SIG", PCI_INTERFACE_ADVSW_ASISIG, NULL, }, 221 { NULL, 0, NULL, }, 222 }; 223 224 /* Subclasses */ 225 static const struct pci_class pci_subclass_bridge[] = { 226 { "host", PCI_SUBCLASS_BRIDGE_HOST, NULL, }, 227 { "ISA", PCI_SUBCLASS_BRIDGE_ISA, NULL, }, 228 { "EISA", PCI_SUBCLASS_BRIDGE_EISA, NULL, }, 229 { "MicroChannel", PCI_SUBCLASS_BRIDGE_MC, NULL, }, 230 { "PCI", PCI_SUBCLASS_BRIDGE_PCI, 231 pci_interface_pcibridge, }, 232 { "PCMCIA", PCI_SUBCLASS_BRIDGE_PCMCIA, NULL, }, 233 { "NuBus", PCI_SUBCLASS_BRIDGE_NUBUS, NULL, }, 234 { "CardBus", PCI_SUBCLASS_BRIDGE_CARDBUS, NULL, }, 235 { "RACEway", PCI_SUBCLASS_BRIDGE_RACEWAY, NULL, }, 236 { "Semi-transparent PCI", PCI_SUBCLASS_BRIDGE_STPCI, 237 pci_interface_stpci, }, 238 { "InfiniBand", PCI_SUBCLASS_BRIDGE_INFINIBAND, NULL, }, 239 { "advanced switching", PCI_SUBCLASS_BRIDGE_ADVSW, 240 pci_interface_advsw, }, 241 { "miscellaneous", PCI_SUBCLASS_BRIDGE_MISC, NULL, }, 242 { NULL, 0, NULL, }, 243 }; 244 245 /* 246 * Class 0x07. 247 * Simple communications controller. 248 */ 249 250 /* Serial controller programming interface */ 251 static const struct pci_class pci_interface_serial[] = { 252 { "generic XT-compat", PCI_INTERFACE_SERIAL_XT, NULL, }, 253 { "16450-compat", PCI_INTERFACE_SERIAL_16450, NULL, }, 254 { "16550-compat", PCI_INTERFACE_SERIAL_16550, NULL, }, 255 { "16650-compat", PCI_INTERFACE_SERIAL_16650, NULL, }, 256 { "16750-compat", PCI_INTERFACE_SERIAL_16750, NULL, }, 257 { "16850-compat", PCI_INTERFACE_SERIAL_16850, NULL, }, 258 { "16950-compat", PCI_INTERFACE_SERIAL_16950, NULL, }, 259 { NULL, 0, NULL, }, 260 }; 261 262 /* Parallel controller programming interface */ 263 static const struct pci_class pci_interface_parallel[] = { 264 { "", PCI_INTERFACE_PARALLEL, NULL,}, 265 { "bi-directional", PCI_INTERFACE_PARALLEL_BIDIRECTIONAL, NULL,}, 266 { "ECP 1.X-compat", PCI_INTERFACE_PARALLEL_ECP1X, NULL,}, 267 { "IEEE1284 controller", PCI_INTERFACE_PARALLEL_IEEE1284_CNTRL, NULL,}, 268 { "IEEE1284 target", PCI_INTERFACE_PARALLEL_IEEE1284_TGT, NULL,}, 269 { NULL, 0, NULL,}, 270 }; 271 272 /* Modem programming interface */ 273 static const struct pci_class pci_interface_modem[] = { 274 { "", PCI_INTERFACE_MODEM, NULL,}, 275 { "Hayes&16450-compat", PCI_INTERFACE_MODEM_HAYES16450, NULL,}, 276 { "Hayes&16550-compat", PCI_INTERFACE_MODEM_HAYES16550, NULL,}, 277 { "Hayes&16650-compat", PCI_INTERFACE_MODEM_HAYES16650, NULL,}, 278 { "Hayes&16750-compat", PCI_INTERFACE_MODEM_HAYES16750, NULL,}, 279 { NULL, 0, NULL,}, 280 }; 281 282 /* Subclasses */ 283 static const struct pci_class pci_subclass_communications[] = { 284 { "serial", PCI_SUBCLASS_COMMUNICATIONS_SERIAL, 285 pci_interface_serial, }, 286 { "parallel", PCI_SUBCLASS_COMMUNICATIONS_PARALLEL, 287 pci_interface_parallel, }, 288 { "multi-port serial", PCI_SUBCLASS_COMMUNICATIONS_MPSERIAL, NULL,}, 289 { "modem", PCI_SUBCLASS_COMMUNICATIONS_MODEM, 290 pci_interface_modem, }, 291 { "GPIB", PCI_SUBCLASS_COMMUNICATIONS_GPIB, NULL,}, 292 { "smartcard", PCI_SUBCLASS_COMMUNICATIONS_SMARTCARD, NULL,}, 293 { "miscellaneous", PCI_SUBCLASS_COMMUNICATIONS_MISC, NULL,}, 294 { NULL, 0, NULL,}, 295 }; 296 297 /* 298 * Class 0x08. 299 * Base system peripheral. 300 */ 301 302 /* PIC programming interface */ 303 static const struct pci_class pci_interface_pic[] = { 304 { "generic 8259", PCI_INTERFACE_PIC_8259, NULL, }, 305 { "ISA PIC", PCI_INTERFACE_PIC_ISA, NULL, }, 306 { "EISA PIC", PCI_INTERFACE_PIC_EISA, NULL, }, 307 { "IO APIC", PCI_INTERFACE_PIC_IOAPIC, NULL, }, 308 { "IO(x) APIC", PCI_INTERFACE_PIC_IOXAPIC, NULL, }, 309 { NULL, 0, NULL, }, 310 }; 311 312 /* DMA programming interface */ 313 static const struct pci_class pci_interface_dma[] = { 314 { "generic 8237", PCI_INTERFACE_DMA_8237, NULL, }, 315 { "ISA", PCI_INTERFACE_DMA_ISA, NULL, }, 316 { "EISA", PCI_INTERFACE_DMA_EISA, NULL, }, 317 { NULL, 0, NULL, }, 318 }; 319 320 /* Timer programming interface */ 321 static const struct pci_class pci_interface_tmr[] = { 322 { "generic 8254", PCI_INTERFACE_TIMER_8254, NULL, }, 323 { "ISA", PCI_INTERFACE_TIMER_ISA, NULL, }, 324 { "EISA", PCI_INTERFACE_TIMER_EISA, NULL, }, 325 { "HPET", PCI_INTERFACE_TIMER_HPET, NULL, }, 326 { NULL, 0, NULL, }, 327 }; 328 329 /* RTC programming interface */ 330 static const struct pci_class pci_interface_rtc[] = { 331 { "generic", PCI_INTERFACE_RTC_GENERIC, NULL, }, 332 { "ISA", PCI_INTERFACE_RTC_ISA, NULL, }, 333 { NULL, 0, NULL, }, 334 }; 335 336 /* Subclasses */ 337 static const struct pci_class pci_subclass_system[] = { 338 { "interrupt", PCI_SUBCLASS_SYSTEM_PIC, pci_interface_pic,}, 339 { "DMA", PCI_SUBCLASS_SYSTEM_DMA, pci_interface_dma,}, 340 { "timer", PCI_SUBCLASS_SYSTEM_TIMER, pci_interface_tmr,}, 341 { "RTC", PCI_SUBCLASS_SYSTEM_RTC, pci_interface_rtc,}, 342 { "PCI Hot-Plug", PCI_SUBCLASS_SYSTEM_PCIHOTPLUG, NULL, }, 343 { "SD Host Controller", PCI_SUBCLASS_SYSTEM_SDHC, NULL, }, 344 { "IOMMU", PCI_SUBCLASS_SYSTEM_IOMMU, NULL, }, 345 { "Root Complex Event Collector", PCI_SUBCLASS_SYSTEM_RCEC, NULL, }, 346 { "miscellaneous", PCI_SUBCLASS_SYSTEM_MISC, NULL, }, 347 { NULL, 0, NULL, }, 348 }; 349 350 /* 351 * Class 0x09. 352 * Input device. 353 */ 354 355 /* Gameport programming interface */ 356 static const struct pci_class pci_interface_game[] = { 357 { "generic", PCI_INTERFACE_GAMEPORT_GENERIC, NULL, }, 358 { "legacy", PCI_INTERFACE_GAMEPORT_LEGACY, NULL, }, 359 { NULL, 0, NULL, }, 360 }; 361 362 /* Subclasses */ 363 static const struct pci_class pci_subclass_input[] = { 364 { "keyboard", PCI_SUBCLASS_INPUT_KEYBOARD, NULL, }, 365 { "digitizer", PCI_SUBCLASS_INPUT_DIGITIZER, NULL, }, 366 { "mouse", PCI_SUBCLASS_INPUT_MOUSE, NULL, }, 367 { "scanner", PCI_SUBCLASS_INPUT_SCANNER, NULL, }, 368 { "game port", PCI_SUBCLASS_INPUT_GAMEPORT, 369 pci_interface_game, }, 370 { "miscellaneous", PCI_SUBCLASS_INPUT_MISC, NULL, }, 371 { NULL, 0, NULL, }, 372 }; 373 374 /* 375 * Class 0x0a. 376 * Docking station. 377 */ 378 static const struct pci_class pci_subclass_dock[] = { 379 { "generic", PCI_SUBCLASS_DOCK_GENERIC, NULL, }, 380 { "miscellaneous", PCI_SUBCLASS_DOCK_MISC, NULL, }, 381 { NULL, 0, NULL, }, 382 }; 383 384 /* 385 * Class 0x0b. 386 * Processor. 387 */ 388 static const struct pci_class pci_subclass_processor[] = { 389 { "386", PCI_SUBCLASS_PROCESSOR_386, NULL, }, 390 { "486", PCI_SUBCLASS_PROCESSOR_486, NULL, }, 391 { "Pentium", PCI_SUBCLASS_PROCESSOR_PENTIUM, NULL, }, 392 { "Alpha", PCI_SUBCLASS_PROCESSOR_ALPHA, NULL, }, 393 { "PowerPC", PCI_SUBCLASS_PROCESSOR_POWERPC, NULL, }, 394 { "MIPS", PCI_SUBCLASS_PROCESSOR_MIPS, NULL, }, 395 { "Co-processor", PCI_SUBCLASS_PROCESSOR_COPROC, NULL, }, 396 { "miscellaneous", PCI_SUBCLASS_PROCESSOR_MISC, NULL, }, 397 { NULL, 0, NULL, }, 398 }; 399 400 /* 401 * Class 0x0c. 402 * Serial bus controller. 403 */ 404 405 /* IEEE1394 programming interface */ 406 static const struct pci_class pci_interface_ieee1394[] = { 407 { "Firewire", PCI_INTERFACE_IEEE1394_FIREWIRE, NULL,}, 408 { "OpenHCI", PCI_INTERFACE_IEEE1394_OPENHCI, NULL,}, 409 { NULL, 0, NULL,}, 410 }; 411 412 /* USB programming interface */ 413 static const struct pci_class pci_interface_usb[] = { 414 { "UHCI", PCI_INTERFACE_USB_UHCI, NULL, }, 415 { "OHCI", PCI_INTERFACE_USB_OHCI, NULL, }, 416 { "EHCI", PCI_INTERFACE_USB_EHCI, NULL, }, 417 { "xHCI", PCI_INTERFACE_USB_XHCI, NULL, }, 418 { "other HC", PCI_INTERFACE_USB_OTHERHC, NULL, }, 419 { "device", PCI_INTERFACE_USB_DEVICE, NULL, }, 420 { NULL, 0, NULL, }, 421 }; 422 423 /* IPMI programming interface */ 424 static const struct pci_class pci_interface_ipmi[] = { 425 { "SMIC", PCI_INTERFACE_IPMI_SMIC, NULL,}, 426 { "keyboard", PCI_INTERFACE_IPMI_KBD, NULL,}, 427 { "block transfer", PCI_INTERFACE_IPMI_BLOCKXFER, NULL,}, 428 { NULL, 0, NULL,}, 429 }; 430 431 /* Subclasses */ 432 static const struct pci_class pci_subclass_serialbus[] = { 433 { "IEEE1394", PCI_SUBCLASS_SERIALBUS_FIREWIRE, 434 pci_interface_ieee1394, }, 435 { "ACCESS.bus", PCI_SUBCLASS_SERIALBUS_ACCESS, NULL, }, 436 { "SSA", PCI_SUBCLASS_SERIALBUS_SSA, NULL, }, 437 { "USB", PCI_SUBCLASS_SERIALBUS_USB, 438 pci_interface_usb, }, 439 /* XXX Fiber Channel/_FIBRECHANNEL */ 440 { "Fiber Channel", PCI_SUBCLASS_SERIALBUS_FIBER, NULL, }, 441 { "SMBus", PCI_SUBCLASS_SERIALBUS_SMBUS, NULL, }, 442 { "InfiniBand", PCI_SUBCLASS_SERIALBUS_INFINIBAND, NULL,}, 443 { "IPMI", PCI_SUBCLASS_SERIALBUS_IPMI, 444 pci_interface_ipmi, }, 445 { "SERCOS", PCI_SUBCLASS_SERIALBUS_SERCOS, NULL, }, 446 { "CANbus", PCI_SUBCLASS_SERIALBUS_CANBUS, NULL, }, 447 { "miscellaneous", PCI_SUBCLASS_SERIALBUS_MISC, NULL, }, 448 { NULL, 0, NULL, }, 449 }; 450 451 /* 452 * Class 0x0d. 453 * Wireless Controller. 454 */ 455 static const struct pci_class pci_subclass_wireless[] = { 456 { "IrDA", PCI_SUBCLASS_WIRELESS_IRDA, NULL, }, 457 { "Consumer IR",/*XXX*/ PCI_SUBCLASS_WIRELESS_CONSUMERIR, NULL, }, 458 { "RF", PCI_SUBCLASS_WIRELESS_RF, NULL, }, 459 { "bluetooth", PCI_SUBCLASS_WIRELESS_BLUETOOTH, NULL, }, 460 { "broadband", PCI_SUBCLASS_WIRELESS_BROADBAND, NULL, }, 461 { "802.11a (5 GHz)", PCI_SUBCLASS_WIRELESS_802_11A, NULL, }, 462 { "802.11b (2.4 GHz)", PCI_SUBCLASS_WIRELESS_802_11B, NULL, }, 463 { "miscellaneous", PCI_SUBCLASS_WIRELESS_MISC, NULL, }, 464 { NULL, 0, NULL, }, 465 }; 466 467 /* 468 * Class 0x0e. 469 * Intelligent IO controller. 470 */ 471 472 /* Intelligent IO programming interface */ 473 static const struct pci_class pci_interface_i2o[] = { 474 { "FIFO at offset 0x40", PCI_INTERFACE_I2O_FIFOAT40, NULL,}, 475 { NULL, 0, NULL,}, 476 }; 477 478 /* Subclasses */ 479 static const struct pci_class pci_subclass_i2o[] = { 480 { "standard", PCI_SUBCLASS_I2O_STANDARD, pci_interface_i2o,}, 481 { "miscellaneous", PCI_SUBCLASS_I2O_MISC, NULL, }, 482 { NULL, 0, NULL, }, 483 }; 484 485 /* 486 * Class 0x0f. 487 * Satellite communication controller. 488 */ 489 static const struct pci_class pci_subclass_satcom[] = { 490 { "TV", PCI_SUBCLASS_SATCOM_TV, NULL, }, 491 { "audio", PCI_SUBCLASS_SATCOM_AUDIO, NULL, }, 492 { "voice", PCI_SUBCLASS_SATCOM_VOICE, NULL, }, 493 { "data", PCI_SUBCLASS_SATCOM_DATA, NULL, }, 494 { "miscellaneous", PCI_SUBCLASS_SATCOM_MISC, NULL, }, 495 { NULL, 0, NULL, }, 496 }; 497 498 /* 499 * Class 0x10. 500 * Encryption/Decryption controller. 501 */ 502 static const struct pci_class pci_subclass_crypto[] = { 503 { "network/computing", PCI_SUBCLASS_CRYPTO_NETCOMP, NULL, }, 504 { "entertainment", PCI_SUBCLASS_CRYPTO_ENTERTAINMENT, NULL,}, 505 { "miscellaneous", PCI_SUBCLASS_CRYPTO_MISC, NULL, }, 506 { NULL, 0, NULL, }, 507 }; 508 509 /* 510 * Class 0x11. 511 * Data aquuisition and signal processing controller. 512 */ 513 static const struct pci_class pci_subclass_dasp[] = { 514 { "DPIO", PCI_SUBCLASS_DASP_DPIO, NULL, }, 515 { "performance counters", PCI_SUBCLASS_DASP_TIMEFREQ, NULL, }, 516 { "synchronization", PCI_SUBCLASS_DASP_SYNC, NULL, }, 517 { "management", PCI_SUBCLASS_DASP_MGMT, NULL, }, 518 { "miscellaneous", PCI_SUBCLASS_DASP_MISC, NULL, }, 519 { NULL, 0, NULL, }, 520 }; 521 522 /* List of classes */ 523 static const struct pci_class pci_class[] = { 524 { "prehistoric", PCI_CLASS_PREHISTORIC, 525 pci_subclass_prehistoric, }, 526 { "mass storage", PCI_CLASS_MASS_STORAGE, 527 pci_subclass_mass_storage, }, 528 { "network", PCI_CLASS_NETWORK, 529 pci_subclass_network, }, 530 { "display", PCI_CLASS_DISPLAY, 531 pci_subclass_display, }, 532 { "multimedia", PCI_CLASS_MULTIMEDIA, 533 pci_subclass_multimedia, }, 534 { "memory", PCI_CLASS_MEMORY, 535 pci_subclass_memory, }, 536 { "bridge", PCI_CLASS_BRIDGE, 537 pci_subclass_bridge, }, 538 { "communications", PCI_CLASS_COMMUNICATIONS, 539 pci_subclass_communications, }, 540 { "system", PCI_CLASS_SYSTEM, 541 pci_subclass_system, }, 542 { "input", PCI_CLASS_INPUT, 543 pci_subclass_input, }, 544 { "dock", PCI_CLASS_DOCK, 545 pci_subclass_dock, }, 546 { "processor", PCI_CLASS_PROCESSOR, 547 pci_subclass_processor, }, 548 { "serial bus", PCI_CLASS_SERIALBUS, 549 pci_subclass_serialbus, }, 550 { "wireless", PCI_CLASS_WIRELESS, 551 pci_subclass_wireless, }, 552 { "I2O", PCI_CLASS_I2O, 553 pci_subclass_i2o, }, 554 { "satellite comm", PCI_CLASS_SATCOM, 555 pci_subclass_satcom, }, 556 { "crypto", PCI_CLASS_CRYPTO, 557 pci_subclass_crypto, }, 558 { "DASP", PCI_CLASS_DASP, 559 pci_subclass_dasp, }, 560 { "undefined", PCI_CLASS_UNDEFINED, 561 NULL, }, 562 { NULL, 0, 563 NULL, }, 564 }; 565 566 DEV_VERBOSE_DEFINE(pci); 567 568 void 569 pci_devinfo(pcireg_t id_reg, pcireg_t class_reg, int showclass, char *cp, 570 size_t l) 571 { 572 pci_class_t pciclass; 573 pci_subclass_t subclass; 574 pci_interface_t interface; 575 pci_revision_t revision; 576 char vendor[PCI_VENDORSTR_LEN], product[PCI_PRODUCTSTR_LEN]; 577 const struct pci_class *classp, *subclassp, *interfacep; 578 char *ep; 579 580 ep = cp + l; 581 582 pciclass = PCI_CLASS(class_reg); 583 subclass = PCI_SUBCLASS(class_reg); 584 interface = PCI_INTERFACE(class_reg); 585 revision = PCI_REVISION(class_reg); 586 587 pci_findvendor(vendor, sizeof(vendor), PCI_VENDOR(id_reg)); 588 pci_findproduct(product, sizeof(product), PCI_VENDOR(id_reg), 589 PCI_PRODUCT(id_reg)); 590 591 classp = pci_class; 592 while (classp->name != NULL) { 593 if (pciclass == classp->val) 594 break; 595 classp++; 596 } 597 598 subclassp = (classp->name != NULL) ? classp->subclasses : NULL; 599 while (subclassp && subclassp->name != NULL) { 600 if (subclass == subclassp->val) 601 break; 602 subclassp++; 603 } 604 605 interfacep = (subclassp && subclassp->name != NULL) ? 606 subclassp->subclasses : NULL; 607 while (interfacep && interfacep->name != NULL) { 608 if (interface == interfacep->val) 609 break; 610 interfacep++; 611 } 612 613 cp += snprintf(cp, ep - cp, "%s %s", vendor, product); 614 if (showclass) { 615 cp += snprintf(cp, ep - cp, " ("); 616 if (classp->name == NULL) 617 cp += snprintf(cp, ep - cp, 618 "class 0x%02x, subclass 0x%02x", pciclass, subclass); 619 else { 620 if (subclassp == NULL || subclassp->name == NULL) 621 cp += snprintf(cp, ep - cp, 622 "%s, subclass 0x%02x", 623 classp->name, subclass); 624 else 625 cp += snprintf(cp, ep - cp, "%s %s", 626 subclassp->name, classp->name); 627 } 628 if ((interfacep == NULL) || (interfacep->name == NULL)) { 629 if (interface != 0) 630 cp += snprintf(cp, ep - cp, 631 ", interface 0x%02x", interface); 632 } else if (strncmp(interfacep->name, "", 1) != 0) 633 cp += snprintf(cp, ep - cp, ", %s", 634 interfacep->name); 635 if (revision != 0) 636 cp += snprintf(cp, ep - cp, ", revision 0x%02x", 637 revision); 638 cp += snprintf(cp, ep - cp, ")"); 639 } 640 } 641 642 #ifdef _KERNEL 643 void 644 pci_aprint_devinfo_fancy(const struct pci_attach_args *pa, const char *naive, 645 const char *known, int addrev) 646 { 647 char devinfo[256]; 648 649 if (known) { 650 aprint_normal(": %s", known); 651 if (addrev) 652 aprint_normal(" (rev. 0x%02x)", 653 PCI_REVISION(pa->pa_class)); 654 aprint_normal("\n"); 655 } else { 656 pci_devinfo(pa->pa_id, pa->pa_class, 0, 657 devinfo, sizeof(devinfo)); 658 aprint_normal(": %s (rev. 0x%02x)\n", devinfo, 659 PCI_REVISION(pa->pa_class)); 660 } 661 if (naive) 662 aprint_naive(": %s\n", naive); 663 else 664 aprint_naive("\n"); 665 } 666 #endif 667 668 /* 669 * Print out most of the PCI configuration registers. Typically used 670 * in a device attach routine like this: 671 * 672 * #ifdef MYDEV_DEBUG 673 * printf("%s: ", device_xname(sc->sc_dev)); 674 * pci_conf_print(pa->pa_pc, pa->pa_tag, NULL); 675 * #endif 676 */ 677 678 #define i2o(i) ((i) * 4) 679 #define o2i(o) ((o) / 4) 680 #define onoff2(str, rval, bit, onstr, offstr) \ 681 printf(" %s: %s\n", (str), ((rval) & (bit)) ? onstr : offstr); 682 #define onoff(str, rval, bit) onoff2(str, rval, bit, "on", "off") 683 684 static void 685 pci_conf_print_common( 686 #ifdef _KERNEL 687 pci_chipset_tag_t pc, pcitag_t tag, 688 #endif 689 const pcireg_t *regs) 690 { 691 const char *name; 692 const struct pci_class *classp, *subclassp; 693 char vendor[PCI_VENDORSTR_LEN]; 694 char product[PCI_PRODUCTSTR_LEN]; 695 pcireg_t rval; 696 unsigned int num; 697 698 rval = regs[o2i(PCI_ID_REG)]; 699 name = pci_findvendor(vendor, sizeof(vendor), PCI_VENDOR(rval)); 700 if (name) 701 printf(" Vendor Name: %s (0x%04x)\n", name, 702 PCI_VENDOR(rval)); 703 else 704 printf(" Vendor ID: 0x%04x\n", PCI_VENDOR(rval)); 705 name = pci_findproduct(product, sizeof(product), PCI_VENDOR(rval), 706 PCI_PRODUCT(rval)); 707 if (name) 708 printf(" Device Name: %s (0x%04x)\n", name, 709 PCI_PRODUCT(rval)); 710 else 711 printf(" Device ID: 0x%04x\n", PCI_PRODUCT(rval)); 712 713 rval = regs[o2i(PCI_COMMAND_STATUS_REG)]; 714 715 printf(" Command register: 0x%04x\n", rval & 0xffff); 716 onoff("I/O space accesses", rval, PCI_COMMAND_IO_ENABLE); 717 onoff("Memory space accesses", rval, PCI_COMMAND_MEM_ENABLE); 718 onoff("Bus mastering", rval, PCI_COMMAND_MASTER_ENABLE); 719 onoff("Special cycles", rval, PCI_COMMAND_SPECIAL_ENABLE); 720 onoff("MWI transactions", rval, PCI_COMMAND_INVALIDATE_ENABLE); 721 onoff("Palette snooping", rval, PCI_COMMAND_PALETTE_ENABLE); 722 onoff("Parity error checking", rval, PCI_COMMAND_PARITY_ENABLE); 723 onoff("Address/data stepping", rval, PCI_COMMAND_STEPPING_ENABLE); 724 onoff("System error (SERR)", rval, PCI_COMMAND_SERR_ENABLE); 725 onoff("Fast back-to-back transactions", rval, 726 PCI_COMMAND_BACKTOBACK_ENABLE); 727 onoff("Interrupt disable", rval, PCI_COMMAND_INTERRUPT_DISABLE); 728 729 printf(" Status register: 0x%04x\n", (rval >> 16) & 0xffff); 730 onoff2("Interrupt status", rval, PCI_STATUS_INT_STATUS, "active", 731 "inactive"); 732 onoff("Capability List support", rval, PCI_STATUS_CAPLIST_SUPPORT); 733 onoff("66 MHz capable", rval, PCI_STATUS_66MHZ_SUPPORT); 734 onoff("User Definable Features (UDF) support", rval, 735 PCI_STATUS_UDF_SUPPORT); 736 onoff("Fast back-to-back capable", rval, 737 PCI_STATUS_BACKTOBACK_SUPPORT); 738 onoff("Data parity error detected", rval, PCI_STATUS_PARITY_ERROR); 739 740 printf(" DEVSEL timing: "); 741 switch (rval & PCI_STATUS_DEVSEL_MASK) { 742 case PCI_STATUS_DEVSEL_FAST: 743 printf("fast"); 744 break; 745 case PCI_STATUS_DEVSEL_MEDIUM: 746 printf("medium"); 747 break; 748 case PCI_STATUS_DEVSEL_SLOW: 749 printf("slow"); 750 break; 751 default: 752 printf("unknown/reserved"); /* XXX */ 753 break; 754 } 755 printf(" (0x%x)\n", (rval & PCI_STATUS_DEVSEL_MASK) >> 25); 756 757 onoff("Slave signaled Target Abort", rval, 758 PCI_STATUS_TARGET_TARGET_ABORT); 759 onoff("Master received Target Abort", rval, 760 PCI_STATUS_MASTER_TARGET_ABORT); 761 onoff("Master received Master Abort", rval, PCI_STATUS_MASTER_ABORT); 762 onoff("Asserted System Error (SERR)", rval, PCI_STATUS_SPECIAL_ERROR); 763 onoff("Parity error detected", rval, PCI_STATUS_PARITY_DETECT); 764 765 rval = regs[o2i(PCI_CLASS_REG)]; 766 for (classp = pci_class; classp->name != NULL; classp++) { 767 if (PCI_CLASS(rval) == classp->val) 768 break; 769 } 770 subclassp = (classp->name != NULL) ? classp->subclasses : NULL; 771 while (subclassp && subclassp->name != NULL) { 772 if (PCI_SUBCLASS(rval) == subclassp->val) 773 break; 774 subclassp++; 775 } 776 if (classp->name != NULL) { 777 printf(" Class Name: %s (0x%02x)\n", classp->name, 778 PCI_CLASS(rval)); 779 if (subclassp != NULL && subclassp->name != NULL) 780 printf(" Subclass Name: %s (0x%02x)\n", 781 subclassp->name, PCI_SUBCLASS(rval)); 782 else 783 printf(" Subclass ID: 0x%02x\n", 784 PCI_SUBCLASS(rval)); 785 } else { 786 printf(" Class ID: 0x%02x\n", PCI_CLASS(rval)); 787 printf(" Subclass ID: 0x%02x\n", PCI_SUBCLASS(rval)); 788 } 789 printf(" Interface: 0x%02x\n", PCI_INTERFACE(rval)); 790 printf(" Revision ID: 0x%02x\n", PCI_REVISION(rval)); 791 792 rval = regs[o2i(PCI_BHLC_REG)]; 793 printf(" BIST: 0x%02x\n", PCI_BIST(rval)); 794 printf(" Header Type: 0x%02x%s (0x%02x)\n", PCI_HDRTYPE_TYPE(rval), 795 PCI_HDRTYPE_MULTIFN(rval) ? "+multifunction" : "", 796 PCI_HDRTYPE(rval)); 797 printf(" Latency Timer: 0x%02x\n", PCI_LATTIMER(rval)); 798 num = PCI_CACHELINE(rval); 799 printf(" Cache Line Size: %ubytes (0x%02x)\n", num * 4, num); 800 } 801 802 static int 803 pci_conf_print_bar( 804 #ifdef _KERNEL 805 pci_chipset_tag_t pc, pcitag_t tag, 806 #endif 807 const pcireg_t *regs, int reg, const char *name 808 #ifdef _KERNEL 809 , int sizebar 810 #endif 811 ) 812 { 813 int width; 814 pcireg_t rval, rval64h; 815 #ifdef _KERNEL 816 int s; 817 pcireg_t mask, mask64h; 818 #endif 819 820 width = 4; 821 822 /* 823 * Section 6.2.5.1, `Address Maps', tells us that: 824 * 825 * 1) The builtin software should have already mapped the 826 * device in a reasonable way. 827 * 828 * 2) A device which wants 2^n bytes of memory will hardwire 829 * the bottom n bits of the address to 0. As recommended, 830 * we write all 1s and see what we get back. 831 */ 832 833 rval = regs[o2i(reg)]; 834 if (PCI_MAPREG_TYPE(rval) == PCI_MAPREG_TYPE_MEM && 835 PCI_MAPREG_MEM_TYPE(rval) == PCI_MAPREG_MEM_TYPE_64BIT) { 836 rval64h = regs[o2i(reg + 4)]; 837 width = 8; 838 } else 839 rval64h = 0; 840 841 #ifdef _KERNEL 842 /* XXX don't size unknown memory type? */ 843 if (rval != 0 && sizebar) { 844 /* 845 * The following sequence seems to make some devices 846 * (e.g. host bus bridges, which don't normally 847 * have their space mapped) very unhappy, to 848 * the point of crashing the system. 849 * 850 * Therefore, if the mapping register is zero to 851 * start out with, don't bother trying. 852 */ 853 s = splhigh(); 854 pci_conf_write(pc, tag, reg, 0xffffffff); 855 mask = pci_conf_read(pc, tag, reg); 856 pci_conf_write(pc, tag, reg, rval); 857 if (PCI_MAPREG_TYPE(rval) == PCI_MAPREG_TYPE_MEM && 858 PCI_MAPREG_MEM_TYPE(rval) == PCI_MAPREG_MEM_TYPE_64BIT) { 859 pci_conf_write(pc, tag, reg + 4, 0xffffffff); 860 mask64h = pci_conf_read(pc, tag, reg + 4); 861 pci_conf_write(pc, tag, reg + 4, rval64h); 862 } else 863 mask64h = 0; 864 splx(s); 865 } else 866 mask = mask64h = 0; 867 #endif /* _KERNEL */ 868 869 printf(" Base address register at 0x%02x", reg); 870 if (name) 871 printf(" (%s)", name); 872 printf("\n "); 873 if (rval == 0) { 874 printf("not implemented(?)\n"); 875 return width; 876 } 877 printf("type: "); 878 if (PCI_MAPREG_TYPE(rval) == PCI_MAPREG_TYPE_MEM) { 879 const char *type, *prefetch; 880 881 switch (PCI_MAPREG_MEM_TYPE(rval)) { 882 case PCI_MAPREG_MEM_TYPE_32BIT: 883 type = "32-bit"; 884 break; 885 case PCI_MAPREG_MEM_TYPE_32BIT_1M: 886 type = "32-bit-1M"; 887 break; 888 case PCI_MAPREG_MEM_TYPE_64BIT: 889 type = "64-bit"; 890 break; 891 default: 892 type = "unknown (XXX)"; 893 break; 894 } 895 if (PCI_MAPREG_MEM_PREFETCHABLE(rval)) 896 prefetch = ""; 897 else 898 prefetch = "non"; 899 printf("%s %sprefetchable memory\n", type, prefetch); 900 switch (PCI_MAPREG_MEM_TYPE(rval)) { 901 case PCI_MAPREG_MEM_TYPE_64BIT: 902 printf(" base: 0x%016llx, ", 903 PCI_MAPREG_MEM64_ADDR( 904 ((((long long) rval64h) << 32) | rval))); 905 #ifdef _KERNEL 906 if (sizebar) 907 printf("size: 0x%016llx", 908 PCI_MAPREG_MEM64_SIZE( 909 ((((long long) mask64h) << 32) | mask))); 910 else 911 #endif /* _KERNEL */ 912 printf("not sized"); 913 printf("\n"); 914 break; 915 case PCI_MAPREG_MEM_TYPE_32BIT: 916 case PCI_MAPREG_MEM_TYPE_32BIT_1M: 917 default: 918 printf(" base: 0x%08x, ", 919 PCI_MAPREG_MEM_ADDR(rval)); 920 #ifdef _KERNEL 921 if (sizebar) 922 printf("size: 0x%08x", 923 PCI_MAPREG_MEM_SIZE(mask)); 924 else 925 #endif /* _KERNEL */ 926 printf("not sized"); 927 printf("\n"); 928 break; 929 } 930 } else { 931 #ifdef _KERNEL 932 if (sizebar) 933 printf("%d-bit ", mask & ~0x0000ffff ? 32 : 16); 934 #endif /* _KERNEL */ 935 printf("i/o\n"); 936 printf(" base: 0x%08x, ", PCI_MAPREG_IO_ADDR(rval)); 937 #ifdef _KERNEL 938 if (sizebar) 939 printf("size: 0x%08x", PCI_MAPREG_IO_SIZE(mask)); 940 else 941 #endif /* _KERNEL */ 942 printf("not sized"); 943 printf("\n"); 944 } 945 946 return width; 947 } 948 949 static void 950 pci_conf_print_regs(const pcireg_t *regs, int first, int pastlast) 951 { 952 int off, needaddr, neednl; 953 954 needaddr = 1; 955 neednl = 0; 956 for (off = first; off < pastlast; off += 4) { 957 if ((off % 16) == 0 || needaddr) { 958 printf(" 0x%02x:", off); 959 needaddr = 0; 960 } 961 printf(" 0x%08x", regs[o2i(off)]); 962 neednl = 1; 963 if ((off % 16) == 12) { 964 printf("\n"); 965 neednl = 0; 966 } 967 } 968 if (neednl) 969 printf("\n"); 970 } 971 972 static void 973 pci_conf_print_agp_cap(const pcireg_t *regs, int capoff) 974 { 975 pcireg_t rval; 976 977 printf("\n AGP Capabilities Register\n"); 978 979 rval = regs[o2i(capoff)]; 980 printf(" Revision: %d.%d\n", 981 PCI_CAP_AGP_MAJOR(rval), PCI_CAP_AGP_MINOR(rval)); 982 983 /* XXX need more */ 984 } 985 986 static const char * 987 pci_conf_print_pcipm_cap_aux(uint16_t caps) 988 { 989 990 switch ((caps >> 6) & 7) { 991 case 0: return "self-powered"; 992 case 1: return "55 mA"; 993 case 2: return "100 mA"; 994 case 3: return "160 mA"; 995 case 4: return "220 mA"; 996 case 5: return "270 mA"; 997 case 6: return "320 mA"; 998 case 7: 999 default: return "375 mA"; 1000 } 1001 } 1002 1003 static const char * 1004 pci_conf_print_pcipm_cap_pmrev(uint8_t val) 1005 { 1006 static const char unk[] = "unknown"; 1007 static const char *pmrev[8] = { 1008 unk, "1.0", "1.1", "1.2", unk, unk, unk, unk 1009 }; 1010 if (val > 7) 1011 return unk; 1012 return pmrev[val]; 1013 } 1014 1015 static void 1016 pci_conf_print_pcipm_cap(const pcireg_t *regs, int capoff) 1017 { 1018 uint16_t caps, pmcsr; 1019 pcireg_t reg; 1020 1021 caps = regs[o2i(capoff)] >> PCI_PMCR_SHIFT; 1022 reg = regs[o2i(capoff + PCI_PMCSR)]; 1023 pmcsr = reg & 0xffff; 1024 1025 printf("\n PCI Power Management Capabilities Register\n"); 1026 1027 printf(" Capabilities register: 0x%04x\n", caps); 1028 printf(" Version: %s\n", 1029 pci_conf_print_pcipm_cap_pmrev(caps & PCI_PMCR_VERSION_MASK)); 1030 onoff("PME# clock", caps, PCI_PMCR_PME_CLOCK); 1031 onoff("Device specific initialization", caps, PCI_PMCR_DSI); 1032 printf(" 3.3V auxiliary current: %s\n", 1033 pci_conf_print_pcipm_cap_aux(caps)); 1034 onoff("D1 power management state support", caps, PCI_PMCR_D1SUPP); 1035 onoff("D2 power management state support", caps, PCI_PMCR_D2SUPP); 1036 onoff("PME# support D0", caps, PCI_PMCR_PME_D0); 1037 onoff("PME# support D1", caps, PCI_PMCR_PME_D1); 1038 onoff("PME# support D2", caps, PCI_PMCR_PME_D2); 1039 onoff("PME# support D3 hot", caps, PCI_PMCR_PME_D3HOT); 1040 onoff("PME# support D3 cold", caps, PCI_PMCR_PME_D3COLD); 1041 1042 printf(" Control/status register: 0x%04x\n", pmcsr); 1043 printf(" Power state: D%d\n", pmcsr & PCI_PMCSR_STATE_MASK); 1044 onoff("PCI Express reserved", (pmcsr >> 2), 1); 1045 onoff("No soft reset", pmcsr, PCI_PMCSR_NO_SOFTRST); 1046 printf(" PME# assertion: %sabled\n", 1047 (pmcsr & PCI_PMCSR_PME_EN) ? "en" : "dis"); 1048 onoff("PME# status", pmcsr, PCI_PMCSR_PME_STS); 1049 printf(" Bridge Support Extensions register: 0x%02x\n", 1050 (reg >> 16) & 0xff); 1051 onoff("B2/B3 support", reg, PCI_PMCSR_B2B3_SUPPORT); 1052 onoff("Bus Power/Clock Control Enable", reg, PCI_PMCSR_BPCC_EN); 1053 printf(" Data register: 0x%02x\n", (reg >> 24) & 0xff); 1054 1055 } 1056 1057 /* XXX pci_conf_print_vpd_cap */ 1058 /* XXX pci_conf_print_slotid_cap */ 1059 1060 static void 1061 pci_conf_print_msi_cap(const pcireg_t *regs, int capoff) 1062 { 1063 uint32_t ctl, mmc, mme; 1064 1065 regs += o2i(capoff); 1066 ctl = *regs++; 1067 mmc = __SHIFTOUT(ctl, PCI_MSI_CTL_MMC_MASK); 1068 mme = __SHIFTOUT(ctl, PCI_MSI_CTL_MME_MASK); 1069 1070 printf("\n PCI Message Signaled Interrupt\n"); 1071 1072 printf(" Message Control register: 0x%04x\n", ctl >> 16); 1073 onoff("MSI Enabled", ctl, PCI_MSI_CTL_MSI_ENABLE); 1074 printf(" Multiple Message Capable: %s (%d vector%s)\n", 1075 mmc > 0 ? "yes" : "no", 1 << mmc, mmc > 0 ? "s" : ""); 1076 printf(" Multiple Message Enabled: %s (%d vector%s)\n", 1077 mme > 0 ? "on" : "off", 1 << mme, mme > 0 ? "s" : ""); 1078 onoff("64 Bit Address Capable", ctl, PCI_MSI_CTL_64BIT_ADDR); 1079 onoff("Per-Vector Masking Capable", ctl, PCI_MSI_CTL_PERVEC_MASK); 1080 printf(" Message Address %sregister: 0x%08x\n", 1081 ctl & PCI_MSI_CTL_64BIT_ADDR ? "(lower) " : "", *regs++); 1082 if (ctl & PCI_MSI_CTL_64BIT_ADDR) { 1083 printf(" Message Address %sregister: 0x%08x\n", 1084 "(upper) ", *regs++); 1085 } 1086 printf(" Message Data register: 0x%08x\n", *regs++); 1087 if (ctl & PCI_MSI_CTL_PERVEC_MASK) { 1088 printf(" Vector Mask register: 0x%08x\n", *regs++); 1089 printf(" Vector Pending register: 0x%08x\n", *regs++); 1090 } 1091 } 1092 1093 /* XXX pci_conf_print_cpci_hostwap_cap */ 1094 1095 /* 1096 * For both command register and status register. 1097 * The argument "idx" is index number (0 to 7). 1098 */ 1099 static int 1100 pcix_split_trans(unsigned int idx) 1101 { 1102 static int table[8] = { 1103 1, 2, 3, 4, 8, 12, 16, 32 1104 }; 1105 1106 if (idx >= __arraycount(table)) 1107 return -1; 1108 return table[idx]; 1109 } 1110 1111 static void 1112 pci_conf_print_pcix_cap(const pcireg_t *regs, int capoff) 1113 { 1114 pcireg_t reg; 1115 int isbridge; 1116 int i; 1117 1118 isbridge = (PCI_HDRTYPE_TYPE(regs[o2i(PCI_BHLC_REG)]) 1119 & PCI_HDRTYPE_PPB) != 0 ? 1 : 0; 1120 printf("\n PCI-X %s Capabilities Register\n", 1121 isbridge ? "Bridge" : "Non-bridge"); 1122 1123 reg = regs[o2i(capoff)]; 1124 if (isbridge != 0) { 1125 printf(" Secondary status register: 0x%04x\n", 1126 (reg & 0xffff0000) >> 16); 1127 onoff("64bit device", reg, PCIX_STATUS_64BIT); 1128 onoff("133MHz capable", reg, PCIX_STATUS_133); 1129 onoff("Split completion discarded", reg, PCIX_STATUS_SPLDISC); 1130 onoff("Unexpected split completion", reg, PCIX_STATUS_SPLUNEX); 1131 onoff("Split completion overrun", reg, PCIX_BRIDGE_ST_SPLOVRN); 1132 onoff("Split request delayed", reg, PCIX_BRIDGE_ST_SPLRQDL); 1133 printf(" Secondary clock frequency: 0x%x\n", 1134 (reg & PCIX_BRIDGE_2NDST_CLKF) 1135 >> PCIX_BRIDGE_2NDST_CLKF_SHIFT); 1136 printf(" Version: 0x%x\n", 1137 (reg & PCIX_BRIDGE_2NDST_VER_MASK) 1138 >> PCIX_BRIDGE_2NDST_VER_SHIFT); 1139 onoff("266MHz capable", reg, PCIX_BRIDGE_ST_266); 1140 onoff("533MHz capable", reg, PCIX_BRIDGE_ST_533); 1141 } else { 1142 printf(" Command register: 0x%04x\n", 1143 (reg & 0xffff0000) >> 16); 1144 onoff("Data Parity Error Recovery", reg, 1145 PCIX_CMD_PERR_RECOVER); 1146 onoff("Enable Relaxed Ordering", reg, PCIX_CMD_RELAXED_ORDER); 1147 printf(" Maximum Burst Read Count: %u\n", 1148 PCIX_CMD_BYTECNT(reg)); 1149 printf(" Maximum Split Transactions: %d\n", 1150 pcix_split_trans((reg & PCIX_CMD_SPLTRANS_MASK) 1151 >> PCIX_CMD_SPLTRANS_SHIFT)); 1152 } 1153 reg = regs[o2i(capoff+PCIX_STATUS)]; /* Or PCIX_BRIDGE_PRI_STATUS */ 1154 printf(" %sStatus register: 0x%08x\n", 1155 isbridge ? "Bridge " : "", reg); 1156 printf(" Function: %d\n", PCIX_STATUS_FN(reg)); 1157 printf(" Device: %d\n", PCIX_STATUS_DEV(reg)); 1158 printf(" Bus: %d\n", PCIX_STATUS_BUS(reg)); 1159 onoff("64bit device", reg, PCIX_STATUS_64BIT); 1160 onoff("133MHz capable", reg, PCIX_STATUS_133); 1161 onoff("Split completion discarded", reg, PCIX_STATUS_SPLDISC); 1162 onoff("Unexpected split completion", reg, PCIX_STATUS_SPLUNEX); 1163 if (isbridge != 0) { 1164 onoff("Split completion overrun", reg, PCIX_BRIDGE_ST_SPLOVRN); 1165 onoff("Split request delayed", reg, PCIX_BRIDGE_ST_SPLRQDL); 1166 } else { 1167 onoff2("Device Complexity", reg, PCIX_STATUS_DEVCPLX, 1168 "bridge device", "simple device"); 1169 printf(" Designed max memory read byte count: %d\n", 1170 512 << ((reg & PCIX_STATUS_MAXB_MASK) 1171 >> PCIX_STATUS_MAXB_SHIFT)); 1172 printf(" Designed max outstanding split transaction: %d\n", 1173 pcix_split_trans((reg & PCIX_STATUS_MAXST_MASK) 1174 >> PCIX_STATUS_MAXST_SHIFT)); 1175 printf(" MAX cumulative Read Size: %u\n", 1176 8 << ((reg & 0x1c000000) >> PCIX_STATUS_MAXRS_SHIFT)); 1177 onoff("Received split completion error", reg, 1178 PCIX_STATUS_SCERR); 1179 } 1180 onoff("266MHz capable", reg, PCIX_STATUS_266); 1181 onoff("533MHz capable", reg, PCIX_STATUS_533); 1182 1183 if (isbridge == 0) 1184 return; 1185 1186 /* Only for bridge */ 1187 for (i = 0; i < 2; i++) { 1188 reg = regs[o2i(capoff+PCIX_BRIDGE_UP_STCR + (4 * i))]; 1189 printf(" %s split transaction control register: 0x%08x\n", 1190 (i == 0) ? "Upstream" : "Downstream", reg); 1191 printf(" Capacity: %d\n", reg & PCIX_BRIDGE_STCAP); 1192 printf(" Commitment Limit: %d\n", 1193 (reg & PCIX_BRIDGE_STCLIM) >> PCIX_BRIDGE_STCLIM_SHIFT); 1194 } 1195 } 1196 1197 /* XXX pci_conf_print_ldt_cap */ 1198 1199 static void 1200 pci_conf_print_vendspec_cap(const pcireg_t *regs, int capoff) 1201 { 1202 uint16_t caps; 1203 1204 caps = regs[o2i(capoff)] >> PCI_VENDORSPECIFIC_SHIFT; 1205 1206 printf("\n PCI Vendor Specific Capabilities Register\n"); 1207 printf(" Capabilities length: 0x%02x\n", caps & 0xff); 1208 } 1209 1210 static void 1211 pci_conf_print_debugport_cap(const pcireg_t *regs, int capoff) 1212 { 1213 pcireg_t val; 1214 1215 val = regs[o2i(capoff + PCI_DEBUG_BASER)]; 1216 1217 printf("\n Debugport Capability Register\n"); 1218 printf(" Debug base Register: 0x%04x\n", 1219 val >> PCI_DEBUG_BASER_SHIFT); 1220 printf(" port offset: 0x%04x\n", 1221 (val & PCI_DEBUG_PORTOFF_MASK) >> PCI_DEBUG_PORTOFF_SHIFT); 1222 printf(" BAR number: %u\n", 1223 (val & PCI_DEBUG_BARNUM_MASK) >> PCI_DEBUG_BARNUM_SHIFT); 1224 } 1225 1226 /* XXX pci_conf_print_cpci_rsrcctl_cap */ 1227 /* XXX pci_conf_print_hotplug_cap */ 1228 1229 static void 1230 pci_conf_print_subsystem_cap(const pcireg_t *regs, int capoff) 1231 { 1232 pcireg_t reg; 1233 1234 reg = regs[o2i(capoff + PCI_CAP_SUBSYS_ID)]; 1235 1236 printf("\n Subsystem ID Capability Register\n"); 1237 printf(" Subsystem ID : 0x%08x\n", reg); 1238 } 1239 1240 /* XXX pci_conf_print_agp8_cap */ 1241 /* XXX pci_conf_print_secure_cap */ 1242 1243 static void 1244 pci_print_pcie_L0s_latency(uint32_t val) 1245 { 1246 1247 switch (val) { 1248 case 0x0: 1249 printf("Less than 64ns\n"); 1250 break; 1251 case 0x1: 1252 case 0x2: 1253 case 0x3: 1254 printf("%dns to less than %dns\n", 32 << val, 32 << (val + 1)); 1255 break; 1256 case 0x4: 1257 printf("512ns to less than 1us\n"); 1258 break; 1259 case 0x5: 1260 printf("1us to less than 2us\n"); 1261 break; 1262 case 0x6: 1263 printf("2us - 4us\n"); 1264 break; 1265 case 0x7: 1266 printf("More than 4us\n"); 1267 break; 1268 } 1269 } 1270 1271 static void 1272 pci_print_pcie_L1_latency(uint32_t val) 1273 { 1274 1275 switch (val) { 1276 case 0x0: 1277 printf("Less than 1us\n"); 1278 break; 1279 case 0x6: 1280 printf("32us - 64us\n"); 1281 break; 1282 case 0x7: 1283 printf("More than 64us\n"); 1284 break; 1285 default: 1286 printf("%dus to less than %dus\n", 1 << (val - 1), 1 << val); 1287 break; 1288 } 1289 } 1290 1291 static void 1292 pci_print_pcie_compl_timeout(uint32_t val) 1293 { 1294 1295 switch (val) { 1296 case 0x0: 1297 printf("50us to 50ms\n"); 1298 break; 1299 case 0x5: 1300 printf("16ms to 55ms\n"); 1301 break; 1302 case 0x6: 1303 printf("65ms to 210ms\n"); 1304 break; 1305 case 0x9: 1306 printf("260ms to 900ms\n"); 1307 break; 1308 case 0xa: 1309 printf("1s to 3.5s\n"); 1310 break; 1311 default: 1312 printf("unknown %u value\n", val); 1313 break; 1314 } 1315 } 1316 1317 static void 1318 pci_conf_print_pcie_cap(const pcireg_t *regs, int capoff) 1319 { 1320 pcireg_t reg; /* for each register */ 1321 pcireg_t val; /* for each bitfield */ 1322 bool check_link = false; 1323 bool check_slot = false; 1324 bool check_rootport = false; 1325 unsigned int pciever; 1326 static const char * const linkspeeds[] = {"2.5", "5.0", "8.0"}; 1327 int i; 1328 1329 printf("\n PCI Express Capabilities Register\n"); 1330 /* Capability Register */ 1331 reg = regs[o2i(capoff)]; 1332 printf(" Capability register: %04x\n", reg >> 16); 1333 pciever = (unsigned int)((reg & 0x000f0000) >> 16); 1334 printf(" Capability version: %u\n", pciever); 1335 printf(" Device type: "); 1336 switch ((reg & 0x00f00000) >> 20) { 1337 case 0x0: 1338 printf("PCI Express Endpoint device\n"); 1339 check_link = true; 1340 break; 1341 case 0x1: 1342 printf("Legacy PCI Express Endpoint device\n"); 1343 check_link = true; 1344 break; 1345 case 0x4: 1346 printf("Root Port of PCI Express Root Complex\n"); 1347 check_link = true; 1348 check_slot = true; 1349 check_rootport = true; 1350 break; 1351 case 0x5: 1352 printf("Upstream Port of PCI Express Switch\n"); 1353 break; 1354 case 0x6: 1355 printf("Downstream Port of PCI Express Switch\n"); 1356 check_slot = true; 1357 check_rootport = true; 1358 break; 1359 case 0x7: 1360 printf("PCI Express to PCI/PCI-X Bridge\n"); 1361 break; 1362 case 0x8: 1363 printf("PCI/PCI-X to PCI Express Bridge\n"); 1364 break; 1365 case 0x9: 1366 printf("Root Complex Integrated Endpoint\n"); 1367 break; 1368 case 0xa: 1369 check_rootport = true; 1370 printf("Root Complex Event Collector\n"); 1371 break; 1372 default: 1373 printf("unknown\n"); 1374 break; 1375 } 1376 onoff("Slot implemented", reg, PCIE_XCAP_SI); 1377 printf(" Interrupt Message Number: %x\n", 1378 (unsigned int)((reg & PCIE_XCAP_IRQ) >> 27)); 1379 1380 /* Device Capability Register */ 1381 reg = regs[o2i(capoff + PCIE_DCAP)]; 1382 printf(" Device Capabilities Register: 0x%08x\n", reg); 1383 printf(" Max Payload Size Supported: %u bytes max\n", 1384 128 << (unsigned int)(reg & PCIE_DCAP_MAX_PAYLOAD)); 1385 printf(" Phantom Functions Supported: "); 1386 switch ((reg & PCIE_DCAP_PHANTOM_FUNCS) >> 3) { 1387 case 0x0: 1388 printf("not available\n"); 1389 break; 1390 case 0x1: 1391 printf("MSB\n"); 1392 break; 1393 case 0x2: 1394 printf("two MSB\n"); 1395 break; 1396 case 0x3: 1397 printf("All three bits\n"); 1398 break; 1399 } 1400 printf(" Extended Tag Field Supported: %dbit\n", 1401 (reg & PCIE_DCAP_EXT_TAG_FIELD) == 0 ? 5 : 8); 1402 printf(" Endpoint L0 Acceptable Latency: "); 1403 pci_print_pcie_L0s_latency((reg & PCIE_DCAP_L0S_LATENCY) >> 6); 1404 printf(" Endpoint L1 Acceptable Latency: "); 1405 pci_print_pcie_L1_latency((reg & PCIE_DCAP_L1_LATENCY) >> 9); 1406 onoff("Attention Button Present", reg, PCIE_DCAP_ATTN_BUTTON); 1407 onoff("Attention Indicator Present", reg, PCIE_DCAP_ATTN_IND); 1408 onoff("Power Indicator Present", reg, PCIE_DCAP_PWR_IND); 1409 onoff("Role-Based Error Report", reg, PCIE_DCAP_ROLE_ERR_RPT); 1410 printf(" Captured Slot Power Limit Value: %d\n", 1411 (unsigned int)(reg & PCIE_DCAP_SLOT_PWR_LIM_VAL) >> 18); 1412 printf(" Captured Slot Power Limit Scale: %d\n", 1413 (unsigned int)(reg & PCIE_DCAP_SLOT_PWR_LIM_SCALE) >> 26); 1414 onoff("Function-Level Reset Capability", reg, PCIE_DCAP_FLR); 1415 1416 /* Device Control Register */ 1417 reg = regs[o2i(capoff + PCIE_DCSR)]; 1418 printf(" Device Control Register: 0x%04x\n", reg & 0xffff); 1419 onoff("Correctable Error Reporting Enable", reg, 1420 PCIE_DCSR_ENA_COR_ERR); 1421 onoff("Non Fatal Error Reporting Enable", reg, PCIE_DCSR_ENA_NFER); 1422 onoff("Fatal Error Reporting Enable", reg, PCIE_DCSR_ENA_FER); 1423 onoff("Unsupported Request Reporting Enable", reg, PCIE_DCSR_ENA_URR); 1424 onoff("Enable Relaxed Ordering", reg, PCIE_DCSR_ENA_RELAX_ORD); 1425 printf(" Max Payload Size: %d byte\n", 1426 128 << (((unsigned int)(reg & PCIE_DCSR_MAX_PAYLOAD) >> 5))); 1427 onoff("Extended Tag Field Enable", reg, PCIE_DCSR_EXT_TAG_FIELD); 1428 onoff("Phantom Functions Enable", reg, PCIE_DCSR_PHANTOM_FUNCS); 1429 onoff("Aux Power PM Enable", reg, PCIE_DCSR_AUX_POWER_PM); 1430 onoff("Enable No Snoop", reg, PCIE_DCSR_ENA_NO_SNOOP); 1431 printf(" Max Read Request Size: %d byte\n", 1432 128 << ((unsigned int)(reg & PCIE_DCSR_MAX_READ_REQ) >> 12)); 1433 1434 /* Device Status Register */ 1435 reg = regs[o2i(capoff + PCIE_DCSR)]; 1436 printf(" Device Status Register: 0x%04x\n", reg >> 16); 1437 onoff("Correctable Error Detected", reg, PCIE_DCSR_CED); 1438 onoff("Non Fatal Error Detected", reg, PCIE_DCSR_NFED); 1439 onoff("Fatal Error Detected", reg, PCIE_DCSR_FED); 1440 onoff("Unsupported Request Detected", reg, PCIE_DCSR_URD); 1441 onoff("Aux Power Detected", reg, PCIE_DCSR_AUX_PWR); 1442 onoff("Transaction Pending", reg, PCIE_DCSR_TRANSACTION_PND); 1443 1444 if (check_link) { 1445 /* Link Capability Register */ 1446 reg = regs[o2i(capoff + PCIE_LCAP)]; 1447 printf(" Link Capabilities Register: 0x%08x\n", reg); 1448 printf(" Maximum Link Speed: "); 1449 val = reg & PCIE_LCAP_MAX_SPEED; 1450 if (val < 1 || val > 3) { 1451 printf("unknown %u value\n", val); 1452 } else { 1453 printf("%sGT/s\n", linkspeeds[val - 1]); 1454 } 1455 printf(" Maximum Link Width: x%u lanes\n", 1456 (unsigned int)(reg & PCIE_LCAP_MAX_WIDTH) >> 4); 1457 printf(" Active State PM Support: "); 1458 val = (reg & PCIE_LCAP_ASPM) >> 10; 1459 switch (val) { 1460 case 0x1: 1461 printf("L0s Entry supported\n"); 1462 break; 1463 case 0x3: 1464 printf("L0s and L1 supported\n"); 1465 break; 1466 default: 1467 printf("Reserved value\n"); 1468 break; 1469 } 1470 printf(" L0 Exit Latency: "); 1471 pci_print_pcie_L0s_latency((reg & PCIE_LCAP_L0S_EXIT) >> 12); 1472 printf(" L1 Exit Latency: "); 1473 pci_print_pcie_L1_latency((reg & PCIE_LCAP_L1_EXIT) >> 15); 1474 printf(" Port Number: %u\n", reg >> 24); 1475 onoff("Clock Power Management", reg, PCIE_LCAP_CLOCK_PM); 1476 onoff("Surprise Down Error Report", reg, 1477 PCIE_LCAP_SURPRISE_DOWN); 1478 onoff("Data Link Layer Link Active", reg, PCIE_LCAP_DL_ACTIVE); 1479 onoff("Link BW Notification Capable", reg, 1480 PCIE_LCAP_LINK_BW_NOTIFY); 1481 onoff("ASPM Optionally Compliance", reg, 1482 PCIE_LCAP_ASPM_COMPLIANCE); 1483 1484 /* Link Control Register */ 1485 reg = regs[o2i(capoff + PCIE_LCSR)]; 1486 printf(" Link Control Register: 0x%04x\n", reg & 0xffff); 1487 printf(" Active State PM Control: "); 1488 val = reg & (PCIE_LCSR_ASPM_L1 | PCIE_LCSR_ASPM_L0S); 1489 switch (val) { 1490 case 0: 1491 printf("disabled\n"); 1492 break; 1493 case 1: 1494 printf("L0s Entry Enabled\n"); 1495 break; 1496 case 2: 1497 printf("L1 Entry Enabled\n"); 1498 break; 1499 case 3: 1500 printf("L0s and L1 Entry Enabled\n"); 1501 break; 1502 } 1503 onoff2("Read Completion Boundary Control", reg, PCIE_LCSR_RCB, 1504 "128bytes", "64bytes"); 1505 onoff("Link Disable", reg, PCIE_LCSR_LINK_DIS); 1506 onoff("Retrain Link", reg, PCIE_LCSR_RETRAIN); 1507 onoff("Common Clock Configuration", reg, PCIE_LCSR_COMCLKCFG); 1508 onoff("Extended Synch", reg, PCIE_LCSR_EXTNDSYNC); 1509 onoff("Enable Clock Power Management", reg, PCIE_LCSR_ENCLKPM); 1510 onoff("Hardware Autonomous Width Disable", reg, 1511 PCIE_LCSR_HAWD); 1512 onoff("Link Bandwidth Management Interrupt Enable", reg, 1513 PCIE_LCSR_LBMIE); 1514 onoff("Link Autonomous Bandwidth Interrupt Enable", reg, 1515 PCIE_LCSR_LABIE); 1516 1517 /* Link Status Register */ 1518 reg = regs[o2i(capoff + PCIE_LCSR)]; 1519 printf(" Link Status Register: 0x%04x\n", reg >> 16); 1520 printf(" Negotiated Link Speed: "); 1521 if (((reg >> 16) & 0x000f) < 1 || 1522 ((reg >> 16) & 0x000f) > 3) { 1523 printf("unknown %u value\n", 1524 (unsigned int)(reg & PCIE_LCSR_LINKSPEED) >> 16); 1525 } else { 1526 printf("%sGT/s\n", 1527 linkspeeds[((reg & PCIE_LCSR_LINKSPEED) >> 16)-1]); 1528 } 1529 printf(" Negotiated Link Width: x%u lanes\n", 1530 (reg >> 20) & 0x003f); 1531 onoff("Training Error", reg, PCIE_LCSR_LINKTRAIN_ERR); 1532 onoff("Link Training", reg, PCIE_LCSR_LINKTRAIN); 1533 onoff("Slot Clock Configuration", reg, PCIE_LCSR_SLOTCLKCFG); 1534 onoff("Data Link Layer Link Active", reg, PCIE_LCSR_DLACTIVE); 1535 onoff("Link Bandwidth Management Status", reg, 1536 PCIE_LCSR_LINK_BW_MGMT); 1537 onoff("Link Autonomous Bandwidth Status", reg, 1538 PCIE_LCSR_LINK_AUTO_BW); 1539 } 1540 1541 if (check_slot == true) { 1542 /* Slot Capability Register */ 1543 reg = regs[o2i(capoff + PCIE_SLCAP)]; 1544 printf(" Slot Capability Register: %08x\n", reg); 1545 onoff("Attention Button Present", reg, PCIE_SLCAP_ABP); 1546 onoff("Power Controller Present", reg, PCIE_SLCAP_PCP); 1547 onoff("MRL Sensor Present", reg, PCIE_SLCAP_MSP); 1548 onoff("Attention Indicator Present", reg, PCIE_SLCAP_AIP); 1549 onoff("Power Indicator Present", reg, PCIE_SLCAP_PIP); 1550 onoff("Hot-Plug Surprise", reg, PCIE_SLCAP_HPS); 1551 onoff("Hot-Plug Capable", reg, PCIE_SLCAP_HPC); 1552 printf(" Slot Power Limit Value: %d\n", 1553 (unsigned int)(reg & PCIE_SLCAP_SPLV) >> 7); 1554 printf(" Slot Power Limit Scale: %d\n", 1555 (unsigned int)(reg & PCIE_SLCAP_SPLS) >> 15); 1556 onoff("Electromechanical Interlock Present", reg, 1557 PCIE_SLCAP_EIP); 1558 onoff("No Command Completed Support", reg, PCIE_SLCAP_NCCS); 1559 printf(" Physical Slot Number: %d\n", 1560 (unsigned int)(reg & PCIE_SLCAP_PSN) >> 19); 1561 1562 /* Slot Control Register */ 1563 reg = regs[o2i(capoff + PCIE_SLCSR)]; 1564 printf(" Slot Control Register: %04x\n", reg & 0xffff); 1565 onoff("Attention Button Pressed Enabled", reg, PCIE_SLCSR_ABE); 1566 onoff("Power Fault Detected Enabled", reg, PCIE_SLCSR_PFE); 1567 onoff("MRL Sensor Changed Enabled", reg, PCIE_SLCSR_MSE); 1568 onoff("Presense Detect Changed Enabled", reg, PCIE_SLCSR_PDE); 1569 onoff("Command Completed Interrupt Enabled", reg, 1570 PCIE_SLCSR_CCE); 1571 onoff("Hot-Plug Interrupt Enabled", reg, PCIE_SLCSR_HPE); 1572 printf(" Attention Indicator Control: "); 1573 switch ((reg & PCIE_SLCSR_AIC) >> 6) { 1574 case 0x0: 1575 printf("reserved\n"); 1576 break; 1577 case 0x1: 1578 printf("on\n"); 1579 break; 1580 case 0x2: 1581 printf("blink\n"); 1582 break; 1583 case 0x3: 1584 printf("off\n"); 1585 break; 1586 } 1587 printf(" Power Indicator Control: "); 1588 switch ((reg & PCIE_SLCSR_PIC) >> 8) { 1589 case 0x0: 1590 printf("reserved\n"); 1591 break; 1592 case 0x1: 1593 printf("on\n"); 1594 break; 1595 case 0x2: 1596 printf("blink\n"); 1597 break; 1598 case 0x3: 1599 printf("off\n"); 1600 break; 1601 } 1602 onoff("Power Controller Control", reg, PCIE_SLCSR_PCC); 1603 onoff("Electromechanical Interlock Control", 1604 reg, PCIE_SLCSR_EIC); 1605 onoff("Data Link Layer State Changed Enable", reg, 1606 PCIE_SLCSR_DLLSCE); 1607 1608 /* Slot Status Register */ 1609 printf(" Slot Status Register: %04x\n", reg >> 16); 1610 onoff("Attention Button Pressed", reg, PCIE_SLCSR_ABP); 1611 onoff("Power Fault Detected", reg, PCIE_SLCSR_PFD); 1612 onoff("MRL Sensor Changed", reg, PCIE_SLCSR_MSC); 1613 onoff("Presense Detect Changed", reg, PCIE_SLCSR_PDC); 1614 onoff("Command Completed", reg, PCIE_SLCSR_CC); 1615 onoff("MRL Open", reg, PCIE_SLCSR_MS); 1616 onoff("Card Present in slot", reg, PCIE_SLCSR_PDS); 1617 onoff("Electromechanical Interlock engaged", reg, 1618 PCIE_SLCSR_EIS); 1619 onoff("Data Link Layer State Changed", reg, PCIE_SLCSR_LACS); 1620 } 1621 1622 if (check_rootport == true) { 1623 /* Root Control Register */ 1624 reg = regs[o2i(capoff + PCIE_RCR)]; 1625 printf(" Root Control Register: %04x\n", reg & 0xffff); 1626 onoff("SERR on Correctable Error Enable", reg, 1627 PCIE_RCR_SERR_CER); 1628 onoff("SERR on Non-Fatal Error Enable", reg, 1629 PCIE_RCR_SERR_NFER); 1630 onoff("SERR on Fatal Error Enable", reg, PCIE_RCR_SERR_FER); 1631 onoff("PME Interrupt Enable", reg, PCIE_RCR_PME_IE); 1632 onoff("CRS Software Visibility Enable", reg, PCIE_RCR_CRS_SVE); 1633 1634 /* Root Capability Register */ 1635 printf(" Root Capability Register: %04x\n", 1636 reg >> 16); 1637 onoff("CRS Software Visibility", reg, PCIE_RCR_CRS_SV); 1638 1639 /* Root Status Register */ 1640 reg = regs[o2i(capoff + PCIE_RSR)]; 1641 printf(" Root Status Register: %08x\n", reg); 1642 printf(" PME Requester ID: %04x\n", 1643 (unsigned int)(reg & PCIE_RSR_PME_REQESTER)); 1644 onoff("PME was asserted", reg, PCIE_RSR_PME_STAT); 1645 onoff("another PME is pending", reg, PCIE_RSR_PME_PEND); 1646 } 1647 1648 /* PCIe DW9 to DW14 is for PCIe 2.0 and newer */ 1649 if (pciever < 2) 1650 return; 1651 1652 /* Device Capabilities 2 */ 1653 reg = regs[o2i(capoff + PCIE_DCAP2)]; 1654 printf(" Device Capabilities 2: 0x%08x\n", reg); 1655 printf(" Completion Timeout Ranges Supported: %u \n", 1656 (unsigned int)(reg & PCIE_DCAP2_COMPT_RANGE)); 1657 onoff("Completion Timeout Disable Supported", reg, 1658 PCIE_DCAP2_COMPT_DIS); 1659 onoff("ARI Forwarding Supported", reg, PCIE_DCAP2_ARI_FWD); 1660 onoff("AtomicOp Routing Supported", reg, PCIE_DCAP2_ATOM_ROUT); 1661 onoff("32bit AtomicOp Completer Supported", reg, PCIE_DCAP2_32ATOM); 1662 onoff("64bit AtomicOp Completer Supported", reg, PCIE_DCAP2_64ATOM); 1663 onoff("128-bit CAS Completer Supported", reg, PCIE_DCAP2_128CAS); 1664 onoff("No RO-enabled PR-PR passing", reg, PCIE_DCAP2_NO_ROPR_PASS); 1665 onoff("LTR Mechanism Supported", reg, PCIE_DCAP2_LTR_MEC); 1666 printf(" TPH Completer Supported: %u\n", 1667 (unsigned int)(reg & PCIE_DCAP2_TPH_COMP) >> 12); 1668 printf(" OBFF Supported: "); 1669 switch ((reg & PCIE_DCAP2_OBFF) >> 18) { 1670 case 0x0: 1671 printf("Not supported\n"); 1672 break; 1673 case 0x1: 1674 printf("Message only\n"); 1675 break; 1676 case 0x2: 1677 printf("WAKE# only\n"); 1678 break; 1679 case 0x3: 1680 printf("Both\n"); 1681 break; 1682 } 1683 onoff("Extended Fmt Field Supported", reg, PCIE_DCAP2_EXTFMT_FLD); 1684 onoff("End-End TLP Prefix Supported", reg, PCIE_DCAP2_EETLP_PREF); 1685 printf(" Max End-End TLP Prefixes: %u\n", 1686 (unsigned int)(reg & PCIE_DCAP2_MAX_EETLP) >> 22); 1687 1688 /* Device Control 2 */ 1689 reg = regs[o2i(capoff + PCIE_DCSR2)]; 1690 printf(" Device Control 2: 0x%04x\n", reg & 0xffff); 1691 printf(" Completion Timeout Value: "); 1692 pci_print_pcie_compl_timeout(reg & PCIE_DCSR2_COMPT_VAL); 1693 onoff("Completion Timeout Disabled", reg, PCIE_DCSR2_COMPT_DIS); 1694 onoff("ARI Forwarding Enabled", reg, PCIE_DCSR2_ARI_FWD); 1695 onoff("AtomicOp Rquester Enabled", reg, PCIE_DCSR2_ATOM_REQ); 1696 onoff("AtomicOp Egress Blocking", reg, PCIE_DCSR2_ATOM_EBLK); 1697 onoff("IDO Request Enabled", reg, PCIE_DCSR2_IDO_REQ); 1698 onoff("IDO Completion Enabled", reg, PCIE_DCSR2_IDO_COMP); 1699 onoff("LTR Mechanism Enabled", reg, PCIE_DCSR2_LTR_MEC); 1700 printf(" OBFF: "); 1701 switch ((reg & PCIE_DCSR2_OBFF_EN) >> 13) { 1702 case 0x0: 1703 printf("Disabled\n"); 1704 break; 1705 case 0x1: 1706 printf("Enabled with Message Signaling Variation A\n"); 1707 break; 1708 case 0x2: 1709 printf("Enabled with Message Signaling Variation B\n"); 1710 break; 1711 case 0x3: 1712 printf("Enabled using WAKE# signaling\n"); 1713 break; 1714 } 1715 onoff("End-End TLP Prefix Blocking on", reg, PCIE_DCSR2_EETLP); 1716 1717 if (check_link) { 1718 /* Link Capability 2 */ 1719 reg = regs[o2i(capoff + PCIE_LCAP2)]; 1720 printf(" Link Capabilities 2: 0x%08x\n", reg); 1721 val = (reg & PCIE_LCAP2_SUP_LNKSV) >> 1; 1722 printf(" Supported Link Speed Vector:"); 1723 for (i = 0; i <= 2; i++) { 1724 if (((val >> i) & 0x01) != 0) 1725 printf(" %sGT/s", linkspeeds[i]); 1726 } 1727 printf("\n"); 1728 onoff("Crosslink Supported", reg, PCIE_LCAP2_CROSSLNK); 1729 1730 /* Link Control 2 */ 1731 reg = regs[o2i(capoff + PCIE_LCSR2)]; 1732 printf(" Link Control 2: 0x%04x\n", reg & 0xffff); 1733 printf(" Target Link Speed: "); 1734 val = reg & PCIE_LCSR2_TGT_LSPEED; 1735 if (val < 1 || val > 3) 1736 printf("unknown %u value\n", val); 1737 else 1738 printf("%sGT/s\n", linkspeeds[val - 1]); 1739 onoff("Enter Compliance Enabled", reg, PCIE_LCSR2_ENT_COMPL); 1740 onoff("HW Autonomous Speed Disabled", reg, 1741 PCIE_LCSR2_HW_AS_DIS); 1742 onoff("Selectable De-emphasis", reg, PCIE_LCSR2_SEL_DEEMP); 1743 printf(" Transmit Margin: %u\n", 1744 (unsigned int)(reg & PCIE_LCSR2_TX_MARGIN) >> 7); 1745 onoff("Enter Modified Compliance", reg, PCIE_LCSR2_EN_MCOMP); 1746 onoff("Compliance SOS", reg, PCIE_LCSR2_COMP_SOS); 1747 printf(" Compliance Present/De-emphasis: %u\n", 1748 (unsigned int)(reg & PCIE_LCSR2_COMP_DEEMP) >> 12); 1749 1750 /* Link Status 2 */ 1751 printf(" Link Status 2: 0x%04x\n", (reg >> 16) & 0xffff); 1752 onoff("Current De-emphasis Level", reg, PCIE_LCSR2_DEEMP_LVL); 1753 onoff("Equalization Complete", reg, PCIE_LCSR2_EQ_COMPL); 1754 onoff("Equalization Phase 1 Successful", reg, 1755 PCIE_LCSR2_EQP1_SUC); 1756 onoff("Equalization Phase 2 Successful", reg, 1757 PCIE_LCSR2_EQP2_SUC); 1758 onoff("Equalization Phase 3 Successful", reg, 1759 PCIE_LCSR2_EQP3_SUC); 1760 onoff("Link Equalization Request", reg, PCIE_LCSR2_LNKEQ_REQ); 1761 } 1762 1763 /* Slot Capability 2 */ 1764 /* Slot Control 2 */ 1765 /* Slot Status 2 */ 1766 } 1767 1768 static void 1769 pci_conf_print_msix_cap(const pcireg_t *regs, int capoff) 1770 { 1771 pcireg_t reg; 1772 1773 printf("\n MSI-X Capability Register\n"); 1774 1775 reg = regs[o2i(capoff + PCI_MSIX_CTL)]; 1776 printf(" Message Control register: 0x%04x\n", 1777 (reg >> 16) & 0xff); 1778 printf(" Table Size: %d\n",PCI_MSIX_CTL_TBLSIZE(reg)); 1779 onoff("Function Mask", reg, PCI_MSIX_CTL_FUNCMASK); 1780 onoff("MSI-X Enable", reg, PCI_MSIX_CTL_ENABLE); 1781 reg = regs[o2i(capoff + PCI_MSIX_TBLOFFSET)]; 1782 printf(" Table offset register: 0x%08x\n", reg); 1783 printf(" Table offset: %08x\n", reg & PCI_MSIX_TBLOFFSET_MASK); 1784 printf(" BIR: 0x%x\n", reg & PCI_MSIX_TBLBIR_MASK); 1785 reg = regs[o2i(capoff + PCI_MSIX_PBAOFFSET)]; 1786 printf(" Pending bit array register: 0x%08x\n", reg); 1787 printf(" Pending bit array offset: %08x\n", 1788 reg & PCI_MSIX_PBAOFFSET_MASK); 1789 printf(" BIR: 0x%x\n", reg & PCI_MSIX_PBABIR_MASK); 1790 } 1791 1792 /* XXX pci_conf_print_sata_cap */ 1793 static void 1794 pci_conf_print_pciaf_cap(const pcireg_t *regs, int capoff) 1795 { 1796 pcireg_t reg; 1797 1798 printf("\n Advanced Features Capability Register\n"); 1799 1800 reg = regs[o2i(capoff + PCI_AFCAPR)]; 1801 printf(" AF Capabilities register: 0x%02x\n", (reg >> 24) & 0xff); 1802 onoff("Transaction Pending", reg, PCI_AF_TP_CAP); 1803 onoff("Function Level Reset", reg, PCI_AF_FLR_CAP); 1804 reg = regs[o2i(capoff + PCI_AFCSR)]; 1805 printf(" AF Control register: 0x%02x\n", reg & 0xff); 1806 /* 1807 * Only PCI_AFCR_INITIATE_FLR is a member of the AF control register 1808 * and it's always 0 on read 1809 */ 1810 printf(" AF Status register: 0x%02x\n", (reg >> 8) & 0xff); 1811 onoff("Transaction Pending", reg, PCI_AFSR_TP); 1812 } 1813 1814 static struct { 1815 pcireg_t cap; 1816 const char *name; 1817 void (*printfunc)(const pcireg_t *, int); 1818 } pci_captab[] = { 1819 { PCI_CAP_RESERVED0, "reserved", NULL }, 1820 { PCI_CAP_PWRMGMT, "Power Management", pci_conf_print_pcipm_cap }, 1821 { PCI_CAP_AGP, "AGP", pci_conf_print_agp_cap }, 1822 { PCI_CAP_VPD, "VPD", NULL }, 1823 { PCI_CAP_SLOTID, "SlotID", NULL }, 1824 { PCI_CAP_MSI, "MSI", pci_conf_print_msi_cap }, 1825 { PCI_CAP_CPCI_HOTSWAP, "CompactPCI Hot-swapping", NULL }, 1826 { PCI_CAP_PCIX, "PCI-X", pci_conf_print_pcix_cap }, 1827 { PCI_CAP_LDT, "HyperTransport", NULL }, 1828 { PCI_CAP_VENDSPEC, "Vendor-specific", 1829 pci_conf_print_vendspec_cap }, 1830 { PCI_CAP_DEBUGPORT, "Debug Port", pci_conf_print_debugport_cap }, 1831 { PCI_CAP_CPCI_RSRCCTL, "CompactPCI Resource Control", NULL }, 1832 { PCI_CAP_HOTPLUG, "Hot-Plug", NULL }, 1833 { PCI_CAP_SUBVENDOR, "Subsystem vendor ID", 1834 pci_conf_print_subsystem_cap }, 1835 { PCI_CAP_AGP8, "AGP 8x", NULL }, 1836 { PCI_CAP_SECURE, "Secure Device", NULL }, 1837 { PCI_CAP_PCIEXPRESS, "PCI Express", pci_conf_print_pcie_cap }, 1838 { PCI_CAP_MSIX, "MSI-X", pci_conf_print_msix_cap }, 1839 { PCI_CAP_SATA, "SATA", NULL }, 1840 { PCI_CAP_PCIAF, "Advanced Features", pci_conf_print_pciaf_cap } 1841 }; 1842 1843 static void 1844 pci_conf_print_caplist( 1845 #ifdef _KERNEL 1846 pci_chipset_tag_t pc, pcitag_t tag, 1847 #endif 1848 const pcireg_t *regs, int capoff) 1849 { 1850 int off; 1851 pcireg_t foundcap; 1852 pcireg_t rval; 1853 bool foundtable[__arraycount(pci_captab)]; 1854 unsigned int i; 1855 1856 /* Clear table */ 1857 for (i = 0; i < __arraycount(pci_captab); i++) 1858 foundtable[i] = false; 1859 1860 /* Print capability register's offset and the type first */ 1861 for (off = PCI_CAPLIST_PTR(regs[o2i(capoff)]); 1862 off != 0; 1863 off = PCI_CAPLIST_NEXT(regs[o2i(off)])) { 1864 rval = regs[o2i(off)]; 1865 printf(" Capability register at 0x%02x\n", off); 1866 1867 printf(" type: 0x%02x (", PCI_CAPLIST_CAP(rval)); 1868 foundcap = PCI_CAPLIST_CAP(rval); 1869 if (foundcap < __arraycount(pci_captab)) { 1870 printf("%s)\n", pci_captab[foundcap].name); 1871 /* Mark as found */ 1872 foundtable[foundcap] = true; 1873 } else 1874 printf("unknown)\n"); 1875 } 1876 1877 /* 1878 * And then, print the detail of each capability registers 1879 * in capability value's order. 1880 */ 1881 for (i = 0; i < __arraycount(pci_captab); i++) { 1882 if (foundtable[i] == false) 1883 continue; 1884 1885 /* 1886 * The type was found. Search capability list again and 1887 * print all capabilities that the capabiliy type is 1888 * the same. This is required because some capabilities 1889 * appear multiple times (e.g. HyperTransport capability). 1890 */ 1891 for (off = PCI_CAPLIST_PTR(regs[o2i(capoff)]); 1892 off != 0; 1893 off = PCI_CAPLIST_NEXT(regs[o2i(off)])) { 1894 rval = regs[o2i(off)]; 1895 foundcap = PCI_CAPLIST_CAP(rval); 1896 if ((i == foundcap) 1897 && (pci_captab[foundcap].printfunc != NULL)) 1898 pci_captab[foundcap].printfunc(regs, off); 1899 } 1900 } 1901 } 1902 1903 /* Print the Secondary Status Register. */ 1904 static void 1905 pci_conf_print_ssr(pcireg_t rval) 1906 { 1907 pcireg_t devsel; 1908 1909 printf(" Secondary status register: 0x%04x\n", rval); /* XXX bits */ 1910 onoff("66 MHz capable", rval, __BIT(5)); 1911 onoff("User Definable Features (UDF) support", rval, __BIT(6)); 1912 onoff("Fast back-to-back capable", rval, __BIT(7)); 1913 onoff("Data parity error detected", rval, __BIT(8)); 1914 1915 printf(" DEVSEL timing: "); 1916 devsel = __SHIFTOUT(rval, __BITS(10, 9)); 1917 switch (devsel) { 1918 case 0: 1919 printf("fast"); 1920 break; 1921 case 1: 1922 printf("medium"); 1923 break; 1924 case 2: 1925 printf("slow"); 1926 break; 1927 default: 1928 printf("unknown/reserved"); /* XXX */ 1929 break; 1930 } 1931 printf(" (0x%x)\n", devsel); 1932 1933 onoff("Signalled target abort", rval, __BIT(11)); 1934 onoff("Received target abort", rval, __BIT(12)); 1935 onoff("Received master abort", rval, __BIT(13)); 1936 onoff("Received system error", rval, __BIT(14)); 1937 onoff("Detected parity error", rval, __BIT(15)); 1938 } 1939 1940 static void 1941 pci_conf_print_type0( 1942 #ifdef _KERNEL 1943 pci_chipset_tag_t pc, pcitag_t tag, 1944 #endif 1945 const pcireg_t *regs 1946 #ifdef _KERNEL 1947 , int sizebars 1948 #endif 1949 ) 1950 { 1951 int off, width; 1952 pcireg_t rval; 1953 1954 for (off = PCI_MAPREG_START; off < PCI_MAPREG_END; off += width) { 1955 #ifdef _KERNEL 1956 width = pci_conf_print_bar(pc, tag, regs, off, NULL, sizebars); 1957 #else 1958 width = pci_conf_print_bar(regs, off, NULL); 1959 #endif 1960 } 1961 1962 printf(" Cardbus CIS Pointer: 0x%08x\n", regs[o2i(0x28)]); 1963 1964 rval = regs[o2i(PCI_SUBSYS_ID_REG)]; 1965 printf(" Subsystem vendor ID: 0x%04x\n", PCI_VENDOR(rval)); 1966 printf(" Subsystem ID: 0x%04x\n", PCI_PRODUCT(rval)); 1967 1968 /* XXX */ 1969 printf(" Expansion ROM Base Address: 0x%08x\n", regs[o2i(0x30)]); 1970 1971 if (regs[o2i(PCI_COMMAND_STATUS_REG)] & PCI_STATUS_CAPLIST_SUPPORT) 1972 printf(" Capability list pointer: 0x%02x\n", 1973 PCI_CAPLIST_PTR(regs[o2i(PCI_CAPLISTPTR_REG)])); 1974 else 1975 printf(" Reserved @ 0x34: 0x%08x\n", regs[o2i(0x34)]); 1976 1977 printf(" Reserved @ 0x38: 0x%08x\n", regs[o2i(0x38)]); 1978 1979 rval = regs[o2i(PCI_INTERRUPT_REG)]; 1980 printf(" Maximum Latency: 0x%02x\n", (rval >> 24) & 0xff); 1981 printf(" Minimum Grant: 0x%02x\n", (rval >> 16) & 0xff); 1982 printf(" Interrupt pin: 0x%02x ", PCI_INTERRUPT_PIN(rval)); 1983 switch (PCI_INTERRUPT_PIN(rval)) { 1984 case PCI_INTERRUPT_PIN_NONE: 1985 printf("(none)"); 1986 break; 1987 case PCI_INTERRUPT_PIN_A: 1988 printf("(pin A)"); 1989 break; 1990 case PCI_INTERRUPT_PIN_B: 1991 printf("(pin B)"); 1992 break; 1993 case PCI_INTERRUPT_PIN_C: 1994 printf("(pin C)"); 1995 break; 1996 case PCI_INTERRUPT_PIN_D: 1997 printf("(pin D)"); 1998 break; 1999 default: 2000 printf("(? ? ?)"); 2001 break; 2002 } 2003 printf("\n"); 2004 printf(" Interrupt line: 0x%02x\n", PCI_INTERRUPT_LINE(rval)); 2005 } 2006 2007 static void 2008 pci_conf_print_type1( 2009 #ifdef _KERNEL 2010 pci_chipset_tag_t pc, pcitag_t tag, 2011 #endif 2012 const pcireg_t *regs 2013 #ifdef _KERNEL 2014 , int sizebars 2015 #endif 2016 ) 2017 { 2018 int off, width; 2019 pcireg_t rval; 2020 uint32_t base, limit; 2021 uint32_t base_h, limit_h; 2022 uint64_t pbase, plimit; 2023 int use_upper; 2024 2025 /* 2026 * This layout was cribbed from the TI PCI2030 PCI-to-PCI 2027 * Bridge chip documentation, and may not be correct with 2028 * respect to various standards. (XXX) 2029 */ 2030 2031 for (off = 0x10; off < 0x18; off += width) { 2032 #ifdef _KERNEL 2033 width = pci_conf_print_bar(pc, tag, regs, off, NULL, sizebars); 2034 #else 2035 width = pci_conf_print_bar(regs, off, NULL); 2036 #endif 2037 } 2038 2039 rval = regs[o2i(PCI_BRIDGE_BUS_REG)]; 2040 printf(" Primary bus number: 0x%02x\n", 2041 PCI_BRIDGE_BUS_PRIMARY(rval)); 2042 printf(" Secondary bus number: 0x%02x\n", 2043 PCI_BRIDGE_BUS_SECONDARY(rval)); 2044 printf(" Subordinate bus number: 0x%02x\n", 2045 PCI_BRIDGE_BUS_SUBORDINATE(rval)); 2046 printf(" Secondary bus latency timer: 0x%02x\n", 2047 PCI_BRIDGE_BUS_SEC_LATTIMER(rval)); 2048 2049 rval = regs[o2i(PCI_BRIDGE_STATIO_REG)]; 2050 pci_conf_print_ssr(__SHIFTOUT(rval, __BITS(31, 16))); 2051 2052 /* I/O region */ 2053 printf(" I/O region:\n"); 2054 printf(" base register: 0x%02x\n", (rval >> 0) & 0xff); 2055 printf(" limit register: 0x%02x\n", (rval >> 8) & 0xff); 2056 if (PCI_BRIDGE_IO_32BITS(rval)) 2057 use_upper = 1; 2058 else 2059 use_upper = 0; 2060 onoff("32bit I/O", rval, use_upper); 2061 base = (rval & PCI_BRIDGE_STATIO_IOBASE_MASK) << 8; 2062 limit = ((rval >> PCI_BRIDGE_STATIO_IOLIMIT_SHIFT) 2063 & PCI_BRIDGE_STATIO_IOLIMIT_MASK) << 8; 2064 limit |= 0x00000fff; 2065 2066 rval = regs[o2i(PCI_BRIDGE_IOHIGH_REG)]; 2067 base_h = (rval >> 0) & 0xffff; 2068 limit_h = (rval >> 16) & 0xffff; 2069 printf(" base upper 16 bits register: 0x%04x\n", base_h); 2070 printf(" limit upper 16 bits register: 0x%04x\n", limit_h); 2071 2072 if (use_upper == 1) { 2073 base |= base_h << 16; 2074 limit |= limit_h << 16; 2075 } 2076 if (base < limit) { 2077 if (use_upper == 1) 2078 printf(" range: 0x%08x-0x%08x\n", base, limit); 2079 else 2080 printf(" range: 0x%04x-0x%04x\n", base, limit); 2081 } else 2082 printf(" range: not set\n"); 2083 2084 /* Non-prefetchable memory region */ 2085 rval = regs[o2i(PCI_BRIDGE_MEMORY_REG)]; 2086 printf(" Memory region:\n"); 2087 printf(" base register: 0x%04x\n", 2088 (rval >> 0) & 0xffff); 2089 printf(" limit register: 0x%04x\n", 2090 (rval >> 16) & 0xffff); 2091 base = ((rval >> PCI_BRIDGE_MEMORY_BASE_SHIFT) 2092 & PCI_BRIDGE_MEMORY_BASE_MASK) << 20; 2093 limit = (((rval >> PCI_BRIDGE_MEMORY_LIMIT_SHIFT) 2094 & PCI_BRIDGE_MEMORY_LIMIT_MASK) << 20) | 0x000fffff; 2095 if (base < limit) 2096 printf(" range: 0x%08x-0x%08x\n", base, limit); 2097 else 2098 printf(" range: not set\n"); 2099 2100 /* Prefetchable memory region */ 2101 rval = regs[o2i(PCI_BRIDGE_PREFETCHMEM_REG)]; 2102 printf(" Prefetchable memory region:\n"); 2103 printf(" base register: 0x%04x\n", 2104 (rval >> 0) & 0xffff); 2105 printf(" limit register: 0x%04x\n", 2106 (rval >> 16) & 0xffff); 2107 base_h = regs[o2i(PCI_BRIDGE_PREFETCHBASE32_REG)]; 2108 limit_h = regs[o2i(PCI_BRIDGE_PREFETCHLIMIT32_REG)]; 2109 printf(" base upper 32 bits register: 0x%08x\n", 2110 base_h); 2111 printf(" limit upper 32 bits register: 0x%08x\n", 2112 limit_h); 2113 if (PCI_BRIDGE_PREFETCHMEM_64BITS(rval)) 2114 use_upper = 1; 2115 else 2116 use_upper = 0; 2117 onoff("64bit memory address", rval, use_upper); 2118 pbase = ((rval >> PCI_BRIDGE_PREFETCHMEM_BASE_SHIFT) 2119 & PCI_BRIDGE_PREFETCHMEM_BASE_MASK) << 20; 2120 plimit = (((rval >> PCI_BRIDGE_PREFETCHMEM_LIMIT_SHIFT) 2121 & PCI_BRIDGE_PREFETCHMEM_LIMIT_MASK) << 20) | 0x000fffff; 2122 if (use_upper == 1) { 2123 pbase |= (uint64_t)base_h << 32; 2124 plimit |= (uint64_t)limit_h << 32; 2125 } 2126 if (pbase < plimit) { 2127 if (use_upper == 1) 2128 printf(" range: 0x%016" PRIx64 "-0x%016" PRIx64 2129 "\n", pbase, plimit); 2130 else 2131 printf(" range: 0x%08x-0x%08x\n", 2132 (uint32_t)pbase, (uint32_t)plimit); 2133 } else 2134 printf(" range: not set\n"); 2135 2136 if (regs[o2i(PCI_COMMAND_STATUS_REG)] & PCI_STATUS_CAPLIST_SUPPORT) 2137 printf(" Capability list pointer: 0x%02x\n", 2138 PCI_CAPLIST_PTR(regs[o2i(PCI_CAPLISTPTR_REG)])); 2139 else 2140 printf(" Reserved @ 0x34: 0x%08x\n", regs[o2i(0x34)]); 2141 2142 /* XXX */ 2143 printf(" Expansion ROM Base Address: 0x%08x\n", regs[o2i(0x38)]); 2144 2145 rval = regs[o2i(PCI_INTERRUPT_REG)]; 2146 printf(" Interrupt line: 0x%02x\n", 2147 (rval >> 0) & 0xff); 2148 printf(" Interrupt pin: 0x%02x ", 2149 (rval >> 8) & 0xff); 2150 switch ((rval >> 8) & 0xff) { 2151 case PCI_INTERRUPT_PIN_NONE: 2152 printf("(none)"); 2153 break; 2154 case PCI_INTERRUPT_PIN_A: 2155 printf("(pin A)"); 2156 break; 2157 case PCI_INTERRUPT_PIN_B: 2158 printf("(pin B)"); 2159 break; 2160 case PCI_INTERRUPT_PIN_C: 2161 printf("(pin C)"); 2162 break; 2163 case PCI_INTERRUPT_PIN_D: 2164 printf("(pin D)"); 2165 break; 2166 default: 2167 printf("(? ? ?)"); 2168 break; 2169 } 2170 printf("\n"); 2171 rval = (regs[o2i(PCI_BRIDGE_CONTROL_REG)] >> PCI_BRIDGE_CONTROL_SHIFT) 2172 & PCI_BRIDGE_CONTROL_MASK; 2173 printf(" Bridge control register: 0x%04x\n", rval); /* XXX bits */ 2174 onoff("Parity error response", rval, 0x0001); 2175 onoff("Secondary SERR forwarding", rval, 0x0002); 2176 onoff("ISA enable", rval, 0x0004); 2177 onoff("VGA enable", rval, 0x0008); 2178 onoff("Master abort reporting", rval, 0x0020); 2179 onoff("Secondary bus reset", rval, 0x0040); 2180 onoff("Fast back-to-back capable", rval, 0x0080); 2181 } 2182 2183 static void 2184 pci_conf_print_type2( 2185 #ifdef _KERNEL 2186 pci_chipset_tag_t pc, pcitag_t tag, 2187 #endif 2188 const pcireg_t *regs 2189 #ifdef _KERNEL 2190 , int sizebars 2191 #endif 2192 ) 2193 { 2194 pcireg_t rval; 2195 2196 /* 2197 * XXX these need to be printed in more detail, need to be 2198 * XXX checked against specs/docs, etc. 2199 * 2200 * This layout was cribbed from the TI PCI1420 PCI-to-CardBus 2201 * controller chip documentation, and may not be correct with 2202 * respect to various standards. (XXX) 2203 */ 2204 2205 #ifdef _KERNEL 2206 pci_conf_print_bar(pc, tag, regs, 0x10, 2207 "CardBus socket/ExCA registers", sizebars); 2208 #else 2209 pci_conf_print_bar(regs, 0x10, "CardBus socket/ExCA registers"); 2210 #endif 2211 2212 /* Capability list pointer and secondary status register */ 2213 rval = regs[o2i(PCI_CARDBUS_CAPLISTPTR_REG)]; 2214 if (regs[o2i(PCI_COMMAND_STATUS_REG)] & PCI_STATUS_CAPLIST_SUPPORT) 2215 printf(" Capability list pointer: 0x%02x\n", 2216 PCI_CAPLIST_PTR(rval)); 2217 else 2218 printf(" Reserved @ 0x14: 0x%04" PRIxMAX "\n", 2219 __SHIFTOUT(rval, __BITS(15, 0))); 2220 pci_conf_print_ssr(__SHIFTOUT(rval, __BITS(31, 16))); 2221 2222 rval = regs[o2i(PCI_BRIDGE_BUS_REG)]; 2223 printf(" PCI bus number: 0x%02x\n", 2224 (rval >> 0) & 0xff); 2225 printf(" CardBus bus number: 0x%02x\n", 2226 (rval >> 8) & 0xff); 2227 printf(" Subordinate bus number: 0x%02x\n", 2228 (rval >> 16) & 0xff); 2229 printf(" CardBus latency timer: 0x%02x\n", 2230 (rval >> 24) & 0xff); 2231 2232 /* XXX Print more prettily */ 2233 printf(" CardBus memory region 0:\n"); 2234 printf(" base register: 0x%08x\n", regs[o2i(0x1c)]); 2235 printf(" limit register: 0x%08x\n", regs[o2i(0x20)]); 2236 printf(" CardBus memory region 1:\n"); 2237 printf(" base register: 0x%08x\n", regs[o2i(0x24)]); 2238 printf(" limit register: 0x%08x\n", regs[o2i(0x28)]); 2239 printf(" CardBus I/O region 0:\n"); 2240 printf(" base register: 0x%08x\n", regs[o2i(0x2c)]); 2241 printf(" limit register: 0x%08x\n", regs[o2i(0x30)]); 2242 printf(" CardBus I/O region 1:\n"); 2243 printf(" base register: 0x%08x\n", regs[o2i(0x34)]); 2244 printf(" limit register: 0x%08x\n", regs[o2i(0x38)]); 2245 2246 rval = regs[o2i(PCI_INTERRUPT_REG)]; 2247 printf(" Interrupt line: 0x%02x\n", 2248 (rval >> 0) & 0xff); 2249 printf(" Interrupt pin: 0x%02x ", 2250 (rval >> 8) & 0xff); 2251 switch ((rval >> 8) & 0xff) { 2252 case PCI_INTERRUPT_PIN_NONE: 2253 printf("(none)"); 2254 break; 2255 case PCI_INTERRUPT_PIN_A: 2256 printf("(pin A)"); 2257 break; 2258 case PCI_INTERRUPT_PIN_B: 2259 printf("(pin B)"); 2260 break; 2261 case PCI_INTERRUPT_PIN_C: 2262 printf("(pin C)"); 2263 break; 2264 case PCI_INTERRUPT_PIN_D: 2265 printf("(pin D)"); 2266 break; 2267 default: 2268 printf("(? ? ?)"); 2269 break; 2270 } 2271 printf("\n"); 2272 rval = (regs[o2i(0x3c)] >> 16) & 0xffff; 2273 printf(" Bridge control register: 0x%04x\n", rval); 2274 onoff("Parity error response", rval, __BIT(0)); 2275 onoff("SERR# enable", rval, __BIT(1)); 2276 onoff("ISA enable", rval, __BIT(2)); 2277 onoff("VGA enable", rval, __BIT(3)); 2278 onoff("Master abort mode", rval, __BIT(5)); 2279 onoff("Secondary (CardBus) bus reset", rval, __BIT(6)); 2280 onoff("Functional interrupts routed by ExCA registers", rval, 2281 __BIT(7)); 2282 onoff("Memory window 0 prefetchable", rval, __BIT(8)); 2283 onoff("Memory window 1 prefetchable", rval, __BIT(9)); 2284 onoff("Write posting enable", rval, __BIT(10)); 2285 2286 rval = regs[o2i(0x40)]; 2287 printf(" Subsystem vendor ID: 0x%04x\n", PCI_VENDOR(rval)); 2288 printf(" Subsystem ID: 0x%04x\n", PCI_PRODUCT(rval)); 2289 2290 #ifdef _KERNEL 2291 pci_conf_print_bar(pc, tag, regs, 0x44, "legacy-mode registers", 2292 sizebars); 2293 #else 2294 pci_conf_print_bar(regs, 0x44, "legacy-mode registers"); 2295 #endif 2296 } 2297 2298 void 2299 pci_conf_print( 2300 #ifdef _KERNEL 2301 pci_chipset_tag_t pc, pcitag_t tag, 2302 void (*printfn)(pci_chipset_tag_t, pcitag_t, const pcireg_t *) 2303 #else 2304 int pcifd, u_int bus, u_int dev, u_int func 2305 #endif 2306 ) 2307 { 2308 pcireg_t regs[o2i(256)]; 2309 int off, capoff, endoff, hdrtype; 2310 const char *type_name; 2311 #ifdef _KERNEL 2312 void (*type_printfn)(pci_chipset_tag_t, pcitag_t, const pcireg_t *, 2313 int); 2314 int sizebars; 2315 #else 2316 void (*type_printfn)(const pcireg_t *); 2317 #endif 2318 2319 printf("PCI configuration registers:\n"); 2320 2321 for (off = 0; off < 256; off += 4) { 2322 #ifdef _KERNEL 2323 regs[o2i(off)] = pci_conf_read(pc, tag, off); 2324 #else 2325 if (pcibus_conf_read(pcifd, bus, dev, func, off, 2326 ®s[o2i(off)]) == -1) 2327 regs[o2i(off)] = 0; 2328 #endif 2329 } 2330 2331 #ifdef _KERNEL 2332 sizebars = 1; 2333 if (PCI_CLASS(regs[o2i(PCI_CLASS_REG)]) == PCI_CLASS_BRIDGE && 2334 PCI_SUBCLASS(regs[o2i(PCI_CLASS_REG)]) == PCI_SUBCLASS_BRIDGE_HOST) 2335 sizebars = 0; 2336 #endif 2337 2338 /* common header */ 2339 printf(" Common header:\n"); 2340 pci_conf_print_regs(regs, 0, 16); 2341 2342 printf("\n"); 2343 #ifdef _KERNEL 2344 pci_conf_print_common(pc, tag, regs); 2345 #else 2346 pci_conf_print_common(regs); 2347 #endif 2348 printf("\n"); 2349 2350 /* type-dependent header */ 2351 hdrtype = PCI_HDRTYPE_TYPE(regs[o2i(PCI_BHLC_REG)]); 2352 switch (hdrtype) { /* XXX make a table, eventually */ 2353 case 0: 2354 /* Standard device header */ 2355 type_name = "\"normal\" device"; 2356 type_printfn = &pci_conf_print_type0; 2357 capoff = PCI_CAPLISTPTR_REG; 2358 endoff = 64; 2359 break; 2360 case 1: 2361 /* PCI-PCI bridge header */ 2362 type_name = "PCI-PCI bridge"; 2363 type_printfn = &pci_conf_print_type1; 2364 capoff = PCI_CAPLISTPTR_REG; 2365 endoff = 64; 2366 break; 2367 case 2: 2368 /* PCI-CardBus bridge header */ 2369 type_name = "PCI-CardBus bridge"; 2370 type_printfn = &pci_conf_print_type2; 2371 capoff = PCI_CARDBUS_CAPLISTPTR_REG; 2372 endoff = 72; 2373 break; 2374 default: 2375 type_name = NULL; 2376 type_printfn = 0; 2377 capoff = -1; 2378 endoff = 64; 2379 break; 2380 } 2381 printf(" Type %d ", hdrtype); 2382 if (type_name != NULL) 2383 printf("(%s) ", type_name); 2384 printf("header:\n"); 2385 pci_conf_print_regs(regs, 16, endoff); 2386 printf("\n"); 2387 if (type_printfn) { 2388 #ifdef _KERNEL 2389 (*type_printfn)(pc, tag, regs, sizebars); 2390 #else 2391 (*type_printfn)(regs); 2392 #endif 2393 } else 2394 printf(" Don't know how to pretty-print type %d header.\n", 2395 hdrtype); 2396 printf("\n"); 2397 2398 /* capability list, if present */ 2399 if ((regs[o2i(PCI_COMMAND_STATUS_REG)] & PCI_STATUS_CAPLIST_SUPPORT) 2400 && (capoff > 0)) { 2401 #ifdef _KERNEL 2402 pci_conf_print_caplist(pc, tag, regs, capoff); 2403 #else 2404 pci_conf_print_caplist(regs, capoff); 2405 #endif 2406 printf("\n"); 2407 } 2408 2409 /* device-dependent header */ 2410 printf(" Device-dependent header:\n"); 2411 pci_conf_print_regs(regs, endoff, 256); 2412 printf("\n"); 2413 #ifdef _KERNEL 2414 if (printfn) 2415 (*printfn)(pc, tag, regs); 2416 else 2417 printf(" Don't know how to pretty-print device-dependent header.\n"); 2418 printf("\n"); 2419 #endif /* _KERNEL */ 2420 } 2421