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