1 /* $NetBSD: pci_subr.c,v 1.123 2014/05/30 05:04:21 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.123 2014/05/30 05:04:21 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 1121 /* 1122 * For both command register and status register. 1123 * The argument "idx" is index number (0 to 7). 1124 */ 1125 static int 1126 pcix_split_trans(unsigned int idx) 1127 { 1128 static int table[8] = { 1129 1, 2, 3, 4, 8, 12, 16, 32 1130 }; 1131 1132 if (idx >= __arraycount(table)) 1133 return -1; 1134 return table[idx]; 1135 } 1136 1137 static void 1138 pci_conf_print_pcix_cap(const pcireg_t *regs, int capoff) 1139 { 1140 pcireg_t reg; 1141 int isbridge; 1142 int i; 1143 1144 isbridge = (PCI_HDRTYPE_TYPE(regs[o2i(PCI_BHLC_REG)]) 1145 & PCI_HDRTYPE_PPB) != 0 ? 1 : 0; 1146 printf("\n PCI-X %s Capabilities Register\n", 1147 isbridge ? "Bridge" : "Non-bridge"); 1148 1149 reg = regs[o2i(capoff)]; 1150 if (isbridge != 0) { 1151 printf(" Secondary status register: 0x%04x\n", 1152 (reg & 0xffff0000) >> 16); 1153 onoff("64bit device", reg, PCIX_STATUS_64BIT); 1154 onoff("133MHz capable", reg, PCIX_STATUS_133); 1155 onoff("Split completion discarded", reg, PCIX_STATUS_SPLDISC); 1156 onoff("Unexpected split completion", reg, PCIX_STATUS_SPLUNEX); 1157 onoff("Split completion overrun", reg, PCIX_BRIDGE_ST_SPLOVRN); 1158 onoff("Split request delayed", reg, PCIX_BRIDGE_ST_SPLRQDL); 1159 printf(" Secondary clock frequency: 0x%x\n", 1160 (reg & PCIX_BRIDGE_2NDST_CLKF) 1161 >> PCIX_BRIDGE_2NDST_CLKF_SHIFT); 1162 printf(" Version: 0x%x\n", 1163 (reg & PCIX_BRIDGE_2NDST_VER_MASK) 1164 >> PCIX_BRIDGE_2NDST_VER_SHIFT); 1165 onoff("266MHz capable", reg, PCIX_BRIDGE_ST_266); 1166 onoff("533MHz capable", reg, PCIX_BRIDGE_ST_533); 1167 } else { 1168 printf(" Command register: 0x%04x\n", 1169 (reg & 0xffff0000) >> 16); 1170 onoff("Data Parity Error Recovery", reg, 1171 PCIX_CMD_PERR_RECOVER); 1172 onoff("Enable Relaxed Ordering", reg, PCIX_CMD_RELAXED_ORDER); 1173 printf(" Maximum Burst Read Count: %u\n", 1174 PCIX_CMD_BYTECNT(reg)); 1175 printf(" Maximum Split Transactions: %d\n", 1176 pcix_split_trans((reg & PCIX_CMD_SPLTRANS_MASK) 1177 >> PCIX_CMD_SPLTRANS_SHIFT)); 1178 } 1179 reg = regs[o2i(capoff+PCIX_STATUS)]; /* Or PCIX_BRIDGE_PRI_STATUS */ 1180 printf(" %sStatus register: 0x%08x\n", 1181 isbridge ? "Bridge " : "", reg); 1182 printf(" Function: %d\n", PCIX_STATUS_FN(reg)); 1183 printf(" Device: %d\n", PCIX_STATUS_DEV(reg)); 1184 printf(" Bus: %d\n", PCIX_STATUS_BUS(reg)); 1185 onoff("64bit device", reg, PCIX_STATUS_64BIT); 1186 onoff("133MHz capable", reg, PCIX_STATUS_133); 1187 onoff("Split completion discarded", reg, PCIX_STATUS_SPLDISC); 1188 onoff("Unexpected split completion", reg, PCIX_STATUS_SPLUNEX); 1189 if (isbridge != 0) { 1190 onoff("Split completion overrun", reg, PCIX_BRIDGE_ST_SPLOVRN); 1191 onoff("Split request delayed", reg, PCIX_BRIDGE_ST_SPLRQDL); 1192 } else { 1193 onoff2("Device Complexity", reg, PCIX_STATUS_DEVCPLX, 1194 "bridge device", "simple device"); 1195 printf(" Designed max memory read byte count: %d\n", 1196 512 << ((reg & PCIX_STATUS_MAXB_MASK) 1197 >> PCIX_STATUS_MAXB_SHIFT)); 1198 printf(" Designed max outstanding split transaction: %d\n", 1199 pcix_split_trans((reg & PCIX_STATUS_MAXST_MASK) 1200 >> PCIX_STATUS_MAXST_SHIFT)); 1201 printf(" MAX cumulative Read Size: %u\n", 1202 8 << ((reg & 0x1c000000) >> PCIX_STATUS_MAXRS_SHIFT)); 1203 onoff("Received split completion error", reg, 1204 PCIX_STATUS_SCERR); 1205 } 1206 onoff("266MHz capable", reg, PCIX_STATUS_266); 1207 onoff("533MHz capable", reg, PCIX_STATUS_533); 1208 1209 if (isbridge == 0) 1210 return; 1211 1212 /* Only for bridge */ 1213 for (i = 0; i < 2; i++) { 1214 reg = regs[o2i(capoff+PCIX_BRIDGE_UP_STCR + (4 * i))]; 1215 printf(" %s split transaction control register: 0x%08x\n", 1216 (i == 0) ? "Upstream" : "Downstream", reg); 1217 printf(" Capacity: %d\n", reg & PCIX_BRIDGE_STCAP); 1218 printf(" Commitment Limit: %d\n", 1219 (reg & PCIX_BRIDGE_STCLIM) >> PCIX_BRIDGE_STCLIM_SHIFT); 1220 } 1221 } 1222 1223 /* XXX pci_conf_print_ldt_cap */ 1224 1225 static void 1226 pci_conf_print_vendspec_cap(const pcireg_t *regs, int capoff) 1227 { 1228 uint16_t caps; 1229 1230 caps = regs[o2i(capoff)] >> PCI_VENDORSPECIFIC_SHIFT; 1231 1232 printf("\n PCI Vendor Specific Capabilities Register\n"); 1233 printf(" Capabilities length: 0x%02x\n", caps & 0xff); 1234 } 1235 1236 static void 1237 pci_conf_print_debugport_cap(const pcireg_t *regs, int capoff) 1238 { 1239 pcireg_t val; 1240 1241 val = regs[o2i(capoff + PCI_DEBUG_BASER)]; 1242 1243 printf("\n Debugport Capability Register\n"); 1244 printf(" Debug base Register: 0x%04x\n", 1245 val >> PCI_DEBUG_BASER_SHIFT); 1246 printf(" port offset: 0x%04x\n", 1247 (val & PCI_DEBUG_PORTOFF_MASK) >> PCI_DEBUG_PORTOFF_SHIFT); 1248 printf(" BAR number: %u\n", 1249 (val & PCI_DEBUG_BARNUM_MASK) >> PCI_DEBUG_BARNUM_SHIFT); 1250 } 1251 1252 /* XXX pci_conf_print_cpci_rsrcctl_cap */ 1253 /* XXX pci_conf_print_hotplug_cap */ 1254 1255 static void 1256 pci_conf_print_subsystem_cap(const pcireg_t *regs, int capoff) 1257 { 1258 pcireg_t reg; 1259 1260 reg = regs[o2i(capoff + PCI_CAP_SUBSYS_ID)]; 1261 1262 printf("\n Subsystem ID Capability Register\n"); 1263 printf(" Subsystem ID : 0x%08x\n", reg); 1264 } 1265 1266 /* XXX pci_conf_print_agp8_cap */ 1267 /* XXX pci_conf_print_secure_cap */ 1268 1269 static void 1270 pci_print_pcie_L0s_latency(uint32_t val) 1271 { 1272 1273 switch (val) { 1274 case 0x0: 1275 printf("Less than 64ns\n"); 1276 break; 1277 case 0x1: 1278 case 0x2: 1279 case 0x3: 1280 printf("%dns to less than %dns\n", 32 << val, 32 << (val + 1)); 1281 break; 1282 case 0x4: 1283 printf("512ns to less than 1us\n"); 1284 break; 1285 case 0x5: 1286 printf("1us to less than 2us\n"); 1287 break; 1288 case 0x6: 1289 printf("2us - 4us\n"); 1290 break; 1291 case 0x7: 1292 printf("More than 4us\n"); 1293 break; 1294 } 1295 } 1296 1297 static void 1298 pci_print_pcie_L1_latency(uint32_t val) 1299 { 1300 1301 switch (val) { 1302 case 0x0: 1303 printf("Less than 1us\n"); 1304 break; 1305 case 0x6: 1306 printf("32us - 64us\n"); 1307 break; 1308 case 0x7: 1309 printf("More than 64us\n"); 1310 break; 1311 default: 1312 printf("%dus to less than %dus\n", 1 << (val - 1), 1 << val); 1313 break; 1314 } 1315 } 1316 1317 static void 1318 pci_print_pcie_compl_timeout(uint32_t val) 1319 { 1320 1321 switch (val) { 1322 case 0x0: 1323 printf("50us to 50ms\n"); 1324 break; 1325 case 0x5: 1326 printf("16ms to 55ms\n"); 1327 break; 1328 case 0x6: 1329 printf("65ms to 210ms\n"); 1330 break; 1331 case 0x9: 1332 printf("260ms to 900ms\n"); 1333 break; 1334 case 0xa: 1335 printf("1s to 3.5s\n"); 1336 break; 1337 default: 1338 printf("unknown %u value\n", val); 1339 break; 1340 } 1341 } 1342 1343 static void 1344 pci_conf_print_pcie_cap(const pcireg_t *regs, int capoff) 1345 { 1346 pcireg_t reg; /* for each register */ 1347 pcireg_t val; /* for each bitfield */ 1348 bool check_link = false; 1349 bool check_slot = false; 1350 bool check_rootport = false; 1351 unsigned int pciever; 1352 static const char * const linkspeeds[] = {"2.5", "5.0", "8.0"}; 1353 int i; 1354 1355 printf("\n PCI Express Capabilities Register\n"); 1356 /* Capability Register */ 1357 reg = regs[o2i(capoff)]; 1358 printf(" Capability register: %04x\n", reg >> 16); 1359 pciever = (unsigned int)((reg & 0x000f0000) >> 16); 1360 printf(" Capability version: %u\n", pciever); 1361 printf(" Device type: "); 1362 switch ((reg & 0x00f00000) >> 20) { 1363 case 0x0: 1364 printf("PCI Express Endpoint device\n"); 1365 check_link = true; 1366 break; 1367 case 0x1: 1368 printf("Legacy PCI Express Endpoint device\n"); 1369 check_link = true; 1370 break; 1371 case 0x4: 1372 printf("Root Port of PCI Express Root Complex\n"); 1373 check_link = true; 1374 check_slot = true; 1375 check_rootport = true; 1376 break; 1377 case 0x5: 1378 printf("Upstream Port of PCI Express Switch\n"); 1379 break; 1380 case 0x6: 1381 printf("Downstream Port of PCI Express Switch\n"); 1382 check_slot = true; 1383 check_rootport = true; 1384 break; 1385 case 0x7: 1386 printf("PCI Express to PCI/PCI-X Bridge\n"); 1387 break; 1388 case 0x8: 1389 printf("PCI/PCI-X to PCI Express Bridge\n"); 1390 break; 1391 case 0x9: 1392 printf("Root Complex Integrated Endpoint\n"); 1393 break; 1394 case 0xa: 1395 check_rootport = true; 1396 printf("Root Complex Event Collector\n"); 1397 break; 1398 default: 1399 printf("unknown\n"); 1400 break; 1401 } 1402 if (check_slot && (reg & PCIE_XCAP_SI) != 0) 1403 printf(" Slot implemented\n"); 1404 printf(" Interrupt Message Number: %x\n", 1405 (unsigned int)((reg & PCIE_XCAP_IRQ) >> 27)); 1406 1407 /* Device Capability Register */ 1408 reg = regs[o2i(capoff + PCIE_DCAP)]; 1409 printf(" Device Capabilities Register: 0x%08x\n", reg); 1410 printf(" Max Payload Size Supported: %u bytes max\n", 1411 128 << (unsigned int)(reg & PCIE_DCAP_MAX_PAYLOAD)); 1412 printf(" Phantom Functions Supported: "); 1413 switch ((reg & PCIE_DCAP_PHANTOM_FUNCS) >> 3) { 1414 case 0x0: 1415 printf("not available\n"); 1416 break; 1417 case 0x1: 1418 printf("MSB\n"); 1419 break; 1420 case 0x2: 1421 printf("two MSB\n"); 1422 break; 1423 case 0x3: 1424 printf("All three bits\n"); 1425 break; 1426 } 1427 printf(" Extended Tag Field Supported: %dbit\n", 1428 (reg & PCIE_DCAP_EXT_TAG_FIELD) == 0 ? 5 : 8); 1429 printf(" Endpoint L0 Acceptable Latency: "); 1430 pci_print_pcie_L0s_latency((reg & PCIE_DCAP_L0S_LATENCY) >> 6); 1431 printf(" Endpoint L1 Acceptable Latency: "); 1432 pci_print_pcie_L1_latency((reg & PCIE_DCAP_L1_LATENCY) >> 9); 1433 onoff("Attention Button Present", reg, PCIE_DCAP_ATTN_BUTTON); 1434 onoff("Attention Indicator Present", reg, PCIE_DCAP_ATTN_IND); 1435 onoff("Power Indicator Present", reg, PCIE_DCAP_PWR_IND); 1436 onoff("Role-Based Error Report", reg, PCIE_DCAP_ROLE_ERR_RPT); 1437 printf(" Captured Slot Power Limit Value: %d\n", 1438 (unsigned int)(reg & PCIE_DCAP_SLOT_PWR_LIM_VAL) >> 18); 1439 printf(" Captured Slot Power Limit Scale: %d\n", 1440 (unsigned int)(reg & PCIE_DCAP_SLOT_PWR_LIM_SCALE) >> 26); 1441 onoff("Function-Level Reset Capability", reg, PCIE_DCAP_FLR); 1442 1443 /* Device Control Register */ 1444 reg = regs[o2i(capoff + PCIE_DCSR)]; 1445 printf(" Device Control Register: 0x%04x\n", reg & 0xffff); 1446 onoff("Correctable Error Reporting Enable", reg, 1447 PCIE_DCSR_ENA_COR_ERR); 1448 onoff("Non Fatal Error Reporting Enable", reg, PCIE_DCSR_ENA_NFER); 1449 onoff("Fatal Error Reporting Enable", reg, PCIE_DCSR_ENA_FER); 1450 onoff("Unsupported Request Reporting Enable", reg, PCIE_DCSR_ENA_URR); 1451 onoff("Enable Relaxed Ordering", reg, PCIE_DCSR_ENA_RELAX_ORD); 1452 printf(" Max Payload Size: %d byte\n", 1453 128 << (((unsigned int)(reg & PCIE_DCSR_MAX_PAYLOAD) >> 5))); 1454 onoff("Extended Tag Field Enable", reg, PCIE_DCSR_EXT_TAG_FIELD); 1455 onoff("Phantom Functions Enable", reg, PCIE_DCSR_PHANTOM_FUNCS); 1456 onoff("Aux Power PM Enable", reg, PCIE_DCSR_AUX_POWER_PM); 1457 onoff("Enable No Snoop", reg, PCIE_DCSR_ENA_NO_SNOOP); 1458 printf(" Max Read Request Size: %d byte\n", 1459 128 << ((unsigned int)(reg & PCIE_DCSR_MAX_READ_REQ) >> 12)); 1460 1461 /* Device Status Register */ 1462 reg = regs[o2i(capoff + PCIE_DCSR)]; 1463 printf(" Device Status Register: 0x%04x\n", reg >> 16); 1464 onoff("Correctable Error Detected", reg, PCIE_DCSR_CED); 1465 onoff("Non Fatal Error Detected", reg, PCIE_DCSR_NFED); 1466 onoff("Fatal Error Detected", reg, PCIE_DCSR_FED); 1467 onoff("Unsupported Request Detected", reg, PCIE_DCSR_URD); 1468 onoff("Aux Power Detected", reg, PCIE_DCSR_AUX_PWR); 1469 onoff("Transaction Pending", reg, PCIE_DCSR_TRANSACTION_PND); 1470 1471 if (check_link) { 1472 /* Link Capability Register */ 1473 reg = regs[o2i(capoff + PCIE_LCAP)]; 1474 printf(" Link Capabilities Register: 0x%08x\n", reg); 1475 printf(" Maximum Link Speed: "); 1476 val = reg & PCIE_LCAP_MAX_SPEED; 1477 if (val < 1 || val > 3) { 1478 printf("unknown %u value\n", val); 1479 } else { 1480 printf("%sGT/s\n", linkspeeds[val - 1]); 1481 } 1482 printf(" Maximum Link Width: x%u lanes\n", 1483 (unsigned int)(reg & PCIE_LCAP_MAX_WIDTH) >> 4); 1484 printf(" Active State PM Support: "); 1485 val = (reg & PCIE_LCAP_ASPM) >> 10; 1486 switch (val) { 1487 case 0x1: 1488 printf("L0s Entry supported\n"); 1489 break; 1490 case 0x3: 1491 printf("L0s and L1 supported\n"); 1492 break; 1493 default: 1494 printf("Reserved value\n"); 1495 break; 1496 } 1497 printf(" L0 Exit Latency: "); 1498 pci_print_pcie_L0s_latency((reg & PCIE_LCAP_L0S_EXIT) >> 12); 1499 printf(" L1 Exit Latency: "); 1500 pci_print_pcie_L1_latency((reg & PCIE_LCAP_L1_EXIT) >> 15); 1501 printf(" Port Number: %u\n", reg >> 24); 1502 onoff("Clock Power Management", reg, PCIE_LCAP_CLOCK_PM); 1503 onoff("Surprise Down Error Report", reg, 1504 PCIE_LCAP_SURPRISE_DOWN); 1505 onoff("Data Link Layer Link Active", reg, PCIE_LCAP_DL_ACTIVE); 1506 onoff("Link BW Notification Capable", reg, 1507 PCIE_LCAP_LINK_BW_NOTIFY); 1508 onoff("ASPM Optionally Compliance", reg, 1509 PCIE_LCAP_ASPM_COMPLIANCE); 1510 1511 /* Link Control Register */ 1512 reg = regs[o2i(capoff + PCIE_LCSR)]; 1513 printf(" Link Control Register: 0x%04x\n", reg & 0xffff); 1514 printf(" Active State PM Control: "); 1515 val = reg & (PCIE_LCSR_ASPM_L1 | PCIE_LCSR_ASPM_L0S); 1516 switch (val) { 1517 case 0: 1518 printf("disabled\n"); 1519 break; 1520 case 1: 1521 printf("L0s Entry Enabled\n"); 1522 break; 1523 case 2: 1524 printf("L1 Entry Enabled\n"); 1525 break; 1526 case 3: 1527 printf("L0s and L1 Entry Enabled\n"); 1528 break; 1529 } 1530 onoff2("Read Completion Boundary Control", reg, PCIE_LCSR_RCB, 1531 "128bytes", "64bytes"); 1532 onoff("Link Disable", reg, PCIE_LCSR_LINK_DIS); 1533 onoff("Retrain Link", reg, PCIE_LCSR_RETRAIN); 1534 onoff("Common Clock Configuration", reg, PCIE_LCSR_COMCLKCFG); 1535 onoff("Extended Synch", reg, PCIE_LCSR_EXTNDSYNC); 1536 onoff("Enable Clock Power Management", reg, PCIE_LCSR_ENCLKPM); 1537 onoff("Hardware Autonomous Width Disable", reg, 1538 PCIE_LCSR_HAWD); 1539 onoff("Link Bandwidth Management Interrupt Enable", reg, 1540 PCIE_LCSR_LBMIE); 1541 onoff("Link Autonomous Bandwidth Interrupt Enable", reg, 1542 PCIE_LCSR_LABIE); 1543 1544 /* Link Status Register */ 1545 reg = regs[o2i(capoff + PCIE_LCSR)]; 1546 printf(" Link Status Register: 0x%04x\n", reg >> 16); 1547 printf(" Negotiated Link Speed: "); 1548 if (((reg >> 16) & 0x000f) < 1 || 1549 ((reg >> 16) & 0x000f) > 3) { 1550 printf("unknown %u value\n", 1551 (unsigned int)(reg & PCIE_LCSR_LINKSPEED) >> 16); 1552 } else { 1553 printf("%sGT/s\n", 1554 linkspeeds[((reg & PCIE_LCSR_LINKSPEED) >> 16)-1]); 1555 } 1556 printf(" Negotiated Link Width: x%u lanes\n", 1557 (reg >> 20) & 0x003f); 1558 onoff("Training Error", reg, PCIE_LCSR_LINKTRAIN_ERR); 1559 onoff("Link Training", reg, PCIE_LCSR_LINKTRAIN); 1560 onoff("Slot Clock Configuration", reg, PCIE_LCSR_SLOTCLKCFG); 1561 onoff("Data Link Layer Link Active", reg, PCIE_LCSR_DLACTIVE); 1562 onoff("Link Bandwidth Management Status", reg, 1563 PCIE_LCSR_LINK_BW_MGMT); 1564 onoff("Link Autonomous Bandwidth Status", reg, 1565 PCIE_LCSR_LINK_AUTO_BW); 1566 } 1567 1568 if (check_slot == true) { 1569 /* Slot Capability Register */ 1570 reg = regs[o2i(capoff + PCIE_SLCAP)]; 1571 printf(" Slot Capability Register: %08x\n", reg); 1572 onoff("Attention Button Present", reg, PCIE_SLCAP_ABP); 1573 onoff("Power Controller Present", reg, PCIE_SLCAP_PCP); 1574 onoff("MRL Sensor Present", reg, PCIE_SLCAP_MSP); 1575 onoff("Attention Indicator Present", reg, PCIE_SLCAP_AIP); 1576 onoff("Power Indicator Present", reg, PCIE_SLCAP_PIP); 1577 onoff("Hot-Plug Surprise", reg, PCIE_SLCAP_HPS); 1578 onoff("Hot-Plug Capable", reg, PCIE_SLCAP_HPC); 1579 printf(" Slot Power Limit Value: %d\n", 1580 (unsigned int)(reg & PCIE_SLCAP_SPLV) >> 7); 1581 printf(" Slot Power Limit Scale: %d\n", 1582 (unsigned int)(reg & PCIE_SLCAP_SPLS) >> 15); 1583 onoff("Electromechanical Interlock Present", reg, 1584 PCIE_SLCAP_EIP); 1585 onoff("No Command Completed Support", reg, PCIE_SLCAP_NCCS); 1586 printf(" Physical Slot Number: %d\n", 1587 (unsigned int)(reg & PCIE_SLCAP_PSN) >> 19); 1588 1589 /* Slot Control Register */ 1590 reg = regs[o2i(capoff + PCIE_SLCSR)]; 1591 printf(" Slot Control Register: %04x\n", reg & 0xffff); 1592 onoff("Attention Button Pressed Enabled", reg, PCIE_SLCSR_ABE); 1593 onoff("Power Fault Detected Enabled", reg, PCIE_SLCSR_PFE); 1594 onoff("MRL Sensor Changed Enabled", reg, PCIE_SLCSR_MSE); 1595 onoff("Presense Detect Changed Enabled", reg, PCIE_SLCSR_PDE); 1596 onoff("Command Completed Interrupt Enabled", reg, 1597 PCIE_SLCSR_CCE); 1598 onoff("Hot-Plug Interrupt Enabled", reg, PCIE_SLCSR_HPE); 1599 printf(" Attention Indicator Control: "); 1600 switch ((reg & PCIE_SLCSR_AIC) >> 6) { 1601 case 0x0: 1602 printf("reserved\n"); 1603 break; 1604 case 0x1: 1605 printf("on\n"); 1606 break; 1607 case 0x2: 1608 printf("blink\n"); 1609 break; 1610 case 0x3: 1611 printf("off\n"); 1612 break; 1613 } 1614 printf(" Power Indicator Control: "); 1615 switch ((reg & PCIE_SLCSR_PIC) >> 8) { 1616 case 0x0: 1617 printf("reserved\n"); 1618 break; 1619 case 0x1: 1620 printf("on\n"); 1621 break; 1622 case 0x2: 1623 printf("blink\n"); 1624 break; 1625 case 0x3: 1626 printf("off\n"); 1627 break; 1628 } 1629 onoff("Power Controller Control", reg, PCIE_SLCSR_PCC); 1630 onoff("Electromechanical Interlock Control", 1631 reg, PCIE_SLCSR_EIC); 1632 onoff("Data Link Layer State Changed Enable", reg, 1633 PCIE_SLCSR_DLLSCE); 1634 1635 /* Slot Status Register */ 1636 printf(" Slot Status Register: %04x\n", reg >> 16); 1637 onoff("Attention Button Pressed", reg, PCIE_SLCSR_ABP); 1638 onoff("Power Fault Detected", reg, PCIE_SLCSR_PFD); 1639 onoff("MRL Sensor Changed", reg, PCIE_SLCSR_MSC); 1640 onoff("Presense Detect Changed", reg, PCIE_SLCSR_PDC); 1641 onoff("Command Completed", reg, PCIE_SLCSR_CC); 1642 onoff("MRL Open", reg, PCIE_SLCSR_MS); 1643 onoff("Card Present in slot", reg, PCIE_SLCSR_PDS); 1644 onoff("Electromechanical Interlock engaged", reg, 1645 PCIE_SLCSR_EIS); 1646 onoff("Data Link Layer State Changed", reg, PCIE_SLCSR_LACS); 1647 } 1648 1649 if (check_rootport == true) { 1650 /* Root Control Register */ 1651 reg = regs[o2i(capoff + PCIE_RCR)]; 1652 printf(" Root Control Register: %04x\n", reg & 0xffff); 1653 onoff("SERR on Correctable Error Enable", reg, 1654 PCIE_RCR_SERR_CER); 1655 onoff("SERR on Non-Fatal Error Enable", reg, 1656 PCIE_RCR_SERR_NFER); 1657 onoff("SERR on Fatal Error Enable", reg, PCIE_RCR_SERR_FER); 1658 onoff("PME Interrupt Enable", reg, PCIE_RCR_PME_IE); 1659 onoff("CRS Software Visibility Enable", reg, PCIE_RCR_CRS_SVE); 1660 1661 /* Root Capability Register */ 1662 printf(" Root Capability Register: %04x\n", 1663 reg >> 16); 1664 1665 /* Root Status Register */ 1666 reg = regs[o2i(capoff + PCIE_RSR)]; 1667 printf(" Root Status Register: %08x\n", reg); 1668 printf(" PME Requester ID: %04x\n", 1669 (unsigned int)(reg & PCIE_RSR_PME_REQESTER)); 1670 onoff("PME was asserted", reg, PCIE_RSR_PME_STAT); 1671 onoff("another PME is pending", reg, PCIE_RSR_PME_PEND); 1672 } 1673 1674 /* PCIe DW9 to DW14 is for PCIe 2.0 and newer */ 1675 if (pciever < 2) 1676 return; 1677 1678 /* Device Capabilities 2 */ 1679 reg = regs[o2i(capoff + PCIE_DCAP2)]; 1680 printf(" Device Capabilities 2: 0x%08x\n", reg); 1681 printf(" Completion Timeout Ranges Supported: %u \n", 1682 (unsigned int)(reg & PCIE_DCAP2_COMPT_RANGE)); 1683 onoff("Completion Timeout Disable Supported", reg, 1684 PCIE_DCAP2_COMPT_DIS); 1685 onoff("ARI Forwarding Supported", reg, PCIE_DCAP2_ARI_FWD); 1686 onoff("AtomicOp Routing Supported", reg, PCIE_DCAP2_ATOM_ROUT); 1687 onoff("32bit AtomicOp Completer Supported", reg, PCIE_DCAP2_32ATOM); 1688 onoff("64bit AtomicOp Completer Supported", reg, PCIE_DCAP2_64ATOM); 1689 onoff("128-bit CAS Completer Supported", reg, PCIE_DCAP2_128CAS); 1690 onoff("No RO-enabled PR-PR passing", reg, PCIE_DCAP2_NO_ROPR_PASS); 1691 onoff("LTR Mechanism Supported", reg, PCIE_DCAP2_LTR_MEC); 1692 printf(" TPH Completer Supported: %u\n", 1693 (unsigned int)(reg & PCIE_DCAP2_TPH_COMP) >> 12); 1694 printf(" OBFF Supported: "); 1695 switch ((reg & PCIE_DCAP2_OBFF) >> 18) { 1696 case 0x0: 1697 printf("Not supported\n"); 1698 break; 1699 case 0x1: 1700 printf("Message only\n"); 1701 break; 1702 case 0x2: 1703 printf("WAKE# only\n"); 1704 break; 1705 case 0x3: 1706 printf("Both\n"); 1707 break; 1708 } 1709 onoff("Extended Fmt Field Supported", reg, PCIE_DCAP2_EXTFMT_FLD); 1710 onoff("End-End TLP Prefix Supported", reg, PCIE_DCAP2_EETLP_PREF); 1711 printf(" Max End-End TLP Prefixes: %u\n", 1712 (unsigned int)(reg & PCIE_DCAP2_MAX_EETLP) >> 22); 1713 1714 /* Device Control 2 */ 1715 reg = regs[o2i(capoff + PCIE_DCSR2)]; 1716 printf(" Device Control 2: 0x%04x\n", reg & 0xffff); 1717 printf(" Completion Timeout Value: "); 1718 pci_print_pcie_compl_timeout(reg & PCIE_DCSR2_COMPT_VAL); 1719 onoff("Completion Timeout Disabled", reg, PCIE_DCSR2_COMPT_DIS); 1720 onoff("ARI Forwarding Enabled", reg, PCIE_DCSR2_ARI_FWD); 1721 onoff("AtomicOp Rquester Enabled", reg, PCIE_DCSR2_ATOM_REQ); 1722 onoff("AtomicOp Egress Blocking", reg, PCIE_DCSR2_ATOM_EBLK); 1723 onoff("IDO Request Enabled", reg, PCIE_DCSR2_IDO_REQ); 1724 onoff("IDO Completion Enabled", reg, PCIE_DCSR2_IDO_COMP); 1725 onoff("LTR Mechanism Enabled", reg, PCIE_DCSR2_LTR_MEC); 1726 printf(" OBFF: "); 1727 switch ((reg & PCIE_DCSR2_OBFF_EN) >> 13) { 1728 case 0x0: 1729 printf("Disabled\n"); 1730 break; 1731 case 0x1: 1732 printf("Enabled with Message Signaling Variation A\n"); 1733 break; 1734 case 0x2: 1735 printf("Enabled with Message Signaling Variation B\n"); 1736 break; 1737 case 0x3: 1738 printf("Enabled using WAKE# signaling\n"); 1739 break; 1740 } 1741 onoff("End-End TLP Prefix Blocking on", reg, PCIE_DCSR2_EETLP); 1742 1743 if (check_link) { 1744 /* Link Capability 2 */ 1745 reg = regs[o2i(capoff + PCIE_LCAP2)]; 1746 printf(" Link Capabilities 2: 0x%08x\n", reg); 1747 val = (reg & PCIE_LCAP2_SUP_LNKSV) >> 1; 1748 printf(" Supported Link Speed Vector:"); 1749 for (i = 0; i <= 2; i++) { 1750 if (((val >> i) & 0x01) != 0) 1751 printf(" %sGT/s", linkspeeds[i]); 1752 } 1753 printf("\n"); 1754 onoff("Crosslink Supported", reg, PCIE_LCAP2_CROSSLNK); 1755 1756 /* Link Control 2 */ 1757 reg = regs[o2i(capoff + PCIE_LCSR2)]; 1758 printf(" Link Control 2: 0x%04x\n", reg & 0xffff); 1759 printf(" Target Link Speed: "); 1760 val = reg & PCIE_LCSR2_TGT_LSPEED; 1761 if (val < 1 || val > 3) 1762 printf("unknown %u value\n", val); 1763 else 1764 printf("%sGT/s\n", linkspeeds[val - 1]); 1765 onoff("Enter Compliance Enabled", reg, PCIE_LCSR2_ENT_COMPL); 1766 onoff("HW Autonomous Speed Disabled", reg, 1767 PCIE_LCSR2_HW_AS_DIS); 1768 onoff("Selectable De-emphasis", reg, PCIE_LCSR2_SEL_DEEMP); 1769 printf(" Transmit Margin: %u\n", 1770 (unsigned int)(reg & PCIE_LCSR2_TX_MARGIN) >> 7); 1771 onoff("Enter Modified Compliance", reg, PCIE_LCSR2_EN_MCOMP); 1772 onoff("Compliance SOS", reg, PCIE_LCSR2_COMP_SOS); 1773 printf(" Compliance Present/De-emphasis: %u\n", 1774 (unsigned int)(reg & PCIE_LCSR2_COMP_DEEMP) >> 12); 1775 1776 /* Link Status 2 */ 1777 printf(" Link Status 2: 0x%04x\n", (reg >> 16) & 0xffff); 1778 onoff("Current De-emphasis Level", reg, PCIE_LCSR2_DEEMP_LVL); 1779 onoff("Equalization Complete", reg, PCIE_LCSR2_EQ_COMPL); 1780 onoff("Equalization Phase 1 Successful", reg, 1781 PCIE_LCSR2_EQP1_SUC); 1782 onoff("Equalization Phase 2 Successful", reg, 1783 PCIE_LCSR2_EQP2_SUC); 1784 onoff("Equalization Phase 3 Successful", reg, 1785 PCIE_LCSR2_EQP3_SUC); 1786 onoff("Link Equalization Request", reg, PCIE_LCSR2_LNKEQ_REQ); 1787 } 1788 1789 /* Slot Capability 2 */ 1790 /* Slot Control 2 */ 1791 /* Slot Status 2 */ 1792 } 1793 1794 static void 1795 pci_conf_print_msix_cap(const pcireg_t *regs, int capoff) 1796 { 1797 pcireg_t reg; 1798 1799 printf("\n MSI-X Capability Register\n"); 1800 1801 reg = regs[o2i(capoff + PCI_MSIX_CTL)]; 1802 printf(" Message Control register: 0x%04x\n", 1803 (reg >> 16) & 0xff); 1804 printf(" Table Size: %d\n",PCI_MSIX_CTL_TBLSIZE(reg)); 1805 onoff("Function Mask", reg, PCI_MSIX_CTL_FUNCMASK); 1806 onoff("MSI-X Enable", reg, PCI_MSIX_CTL_ENABLE); 1807 reg = regs[o2i(capoff + PCI_MSIX_TBLOFFSET)]; 1808 printf(" Table offset register: 0x%08x\n", reg); 1809 printf(" Table offset: %08x\n", reg & PCI_MSIX_TBLOFFSET_MASK); 1810 printf(" BIR: 0x%x\n", reg & PCI_MSIX_TBLBIR_MASK); 1811 reg = regs[o2i(capoff + PCI_MSIX_PBAOFFSET)]; 1812 printf(" Pending bit array register: 0x%08x\n", reg); 1813 printf(" Pending bit array offset: %08x\n", 1814 reg & PCI_MSIX_PBAOFFSET_MASK); 1815 printf(" BIR: 0x%x\n", reg & PCI_MSIX_PBABIR_MASK); 1816 } 1817 1818 /* XXX pci_conf_print_sata_cap */ 1819 static void 1820 pci_conf_print_pciaf_cap(const pcireg_t *regs, int capoff) 1821 { 1822 pcireg_t reg; 1823 1824 printf("\n Advanced Features Capability Register\n"); 1825 1826 reg = regs[o2i(capoff + PCI_AFCAPR)]; 1827 printf(" AF Capabilities register: 0x%02x\n", (reg >> 24) & 0xff); 1828 onoff("Transaction Pending", reg, PCI_AF_TP_CAP); 1829 onoff("Function Level Reset", reg, PCI_AF_FLR_CAP); 1830 reg = regs[o2i(capoff + PCI_AFCSR)]; 1831 printf(" AF Control register: 0x%02x\n", reg & 0xff); 1832 /* 1833 * Only PCI_AFCR_INITIATE_FLR is a member of the AF control register 1834 * and it's always 0 on read 1835 */ 1836 printf(" AF Status register: 0x%02x\n", (reg >> 8) & 0xff); 1837 onoff("Transaction Pending", reg, PCI_AFSR_TP); 1838 } 1839 1840 static void 1841 pci_conf_print_caplist( 1842 #ifdef _KERNEL 1843 pci_chipset_tag_t pc, pcitag_t tag, 1844 #endif 1845 const pcireg_t *regs, int capoff) 1846 { 1847 int off; 1848 pcireg_t rval; 1849 int pcie_off = -1, pcipm_off = -1, msi_off = -1, pcix_off = -1; 1850 int vendspec_off = -1, msix_off = -1; 1851 int debugport_off = -1, subsystem_off = -1, pciaf_off = -1; 1852 1853 for (off = PCI_CAPLIST_PTR(regs[o2i(capoff)]); 1854 off != 0; 1855 off = PCI_CAPLIST_NEXT(regs[o2i(off)])) { 1856 rval = regs[o2i(off)]; 1857 printf(" Capability register at 0x%02x\n", off); 1858 1859 printf(" type: 0x%02x (", PCI_CAPLIST_CAP(rval)); 1860 switch (PCI_CAPLIST_CAP(rval)) { 1861 case PCI_CAP_RESERVED0: 1862 printf("reserved"); 1863 break; 1864 case PCI_CAP_PWRMGMT: 1865 printf("Power Management, rev. %s", 1866 pci_conf_print_pcipm_cap_pmrev( 1867 (rval >> 0) & 0x07)); 1868 pcipm_off = off; 1869 break; 1870 case PCI_CAP_AGP: 1871 printf("AGP, rev. %d.%d", 1872 PCI_CAP_AGP_MAJOR(rval), 1873 PCI_CAP_AGP_MINOR(rval)); 1874 break; 1875 case PCI_CAP_VPD: 1876 printf("VPD"); 1877 break; 1878 case PCI_CAP_SLOTID: 1879 printf("SlotID"); 1880 break; 1881 case PCI_CAP_MSI: 1882 printf("MSI"); 1883 msi_off = off; 1884 break; 1885 case PCI_CAP_CPCI_HOTSWAP: 1886 printf("CompactPCI Hot-swapping"); 1887 break; 1888 case PCI_CAP_PCIX: 1889 pcix_off = off; 1890 printf("PCI-X"); 1891 break; 1892 case PCI_CAP_LDT: 1893 printf("LDT"); 1894 break; 1895 case PCI_CAP_VENDSPEC: 1896 vendspec_off = off; 1897 printf("Vendor-specific"); 1898 break; 1899 case PCI_CAP_DEBUGPORT: 1900 printf("Debug Port"); 1901 debugport_off = off; 1902 break; 1903 case PCI_CAP_CPCI_RSRCCTL: 1904 printf("CompactPCI Resource Control"); 1905 break; 1906 case PCI_CAP_HOTPLUG: 1907 printf("Hot-Plug"); 1908 break; 1909 case PCI_CAP_SUBVENDOR: 1910 printf("Subsystem ID"); 1911 subsystem_off = off; 1912 break; 1913 case PCI_CAP_AGP8: 1914 printf("AGP 8x"); 1915 break; 1916 case PCI_CAP_SECURE: 1917 printf("Secure Device"); 1918 break; 1919 case PCI_CAP_PCIEXPRESS: 1920 printf("PCI Express"); 1921 pcie_off = off; 1922 break; 1923 case PCI_CAP_MSIX: 1924 printf("MSI-X"); 1925 msix_off = off; 1926 break; 1927 case PCI_CAP_SATA: 1928 printf("SATA"); 1929 break; 1930 case PCI_CAP_PCIAF: 1931 printf("Advanced Features"); 1932 pciaf_off = off; 1933 break; 1934 default: 1935 printf("unknown"); 1936 } 1937 printf(")\n"); 1938 } 1939 if (pcipm_off != -1) 1940 pci_conf_print_pcipm_cap(regs, pcipm_off); 1941 /* XXX AGP */ 1942 /* XXX VPD */ 1943 /* XXX SLOTID */ 1944 if (msi_off != -1) 1945 pci_conf_print_msi_cap(regs, msi_off); 1946 /* XXX CPCI_HOTSWAP */ 1947 if (pcix_off != -1) 1948 pci_conf_print_pcix_cap(regs, pcix_off); 1949 /* XXX LDT */ 1950 if (vendspec_off != -1) 1951 pci_conf_print_vendspec_cap(regs, vendspec_off); 1952 if (debugport_off != -1) 1953 pci_conf_print_debugport_cap(regs, debugport_off); 1954 /* XXX CPCI_RSRCCTL */ 1955 /* XXX HOTPLUG */ 1956 if (subsystem_off != -1) 1957 pci_conf_print_subsystem_cap(regs, subsystem_off); 1958 /* XXX AGP8 */ 1959 /* XXX SECURE */ 1960 if (pcie_off != -1) 1961 pci_conf_print_pcie_cap(regs, pcie_off); 1962 if (msix_off != -1) 1963 pci_conf_print_msix_cap(regs, msix_off); 1964 /* XXX SATA */ 1965 if (pciaf_off != -1) 1966 pci_conf_print_pciaf_cap(regs, pciaf_off); 1967 } 1968 1969 /* Print the Secondary Status Register. */ 1970 static void 1971 pci_conf_print_ssr(pcireg_t rval) 1972 { 1973 pcireg_t devsel; 1974 1975 printf(" Secondary status register: 0x%04x\n", rval); /* XXX bits */ 1976 onoff("66 MHz capable", rval, __BIT(5)); 1977 onoff("User Definable Features (UDF) support", rval, __BIT(6)); 1978 onoff("Fast back-to-back capable", rval, __BIT(7)); 1979 onoff("Data parity error detected", rval, __BIT(8)); 1980 1981 printf(" DEVSEL timing: "); 1982 devsel = __SHIFTOUT(rval, __BITS(10, 9)); 1983 switch (devsel) { 1984 case 0: 1985 printf("fast"); 1986 break; 1987 case 1: 1988 printf("medium"); 1989 break; 1990 case 2: 1991 printf("slow"); 1992 break; 1993 default: 1994 printf("unknown/reserved"); /* XXX */ 1995 break; 1996 } 1997 printf(" (0x%x)\n", devsel); 1998 1999 onoff("Signalled target abort", rval, __BIT(11)); 2000 onoff("Received target abort", rval, __BIT(12)); 2001 onoff("Received master abort", rval, __BIT(13)); 2002 onoff("Received system error", rval, __BIT(14)); 2003 onoff("Detected parity error", rval, __BIT(15)); 2004 } 2005 2006 static void 2007 pci_conf_print_type0( 2008 #ifdef _KERNEL 2009 pci_chipset_tag_t pc, pcitag_t tag, 2010 #endif 2011 const pcireg_t *regs 2012 #ifdef _KERNEL 2013 , int sizebars 2014 #endif 2015 ) 2016 { 2017 int off, width; 2018 pcireg_t rval; 2019 2020 for (off = PCI_MAPREG_START; off < PCI_MAPREG_END; off += width) { 2021 #ifdef _KERNEL 2022 width = pci_conf_print_bar(pc, tag, regs, off, NULL, sizebars); 2023 #else 2024 width = pci_conf_print_bar(regs, off, NULL); 2025 #endif 2026 } 2027 2028 printf(" Cardbus CIS Pointer: 0x%08x\n", regs[o2i(0x28)]); 2029 2030 rval = regs[o2i(PCI_SUBSYS_ID_REG)]; 2031 printf(" Subsystem vendor ID: 0x%04x\n", PCI_VENDOR(rval)); 2032 printf(" Subsystem ID: 0x%04x\n", PCI_PRODUCT(rval)); 2033 2034 /* XXX */ 2035 printf(" Expansion ROM Base Address: 0x%08x\n", regs[o2i(0x30)]); 2036 2037 if (regs[o2i(PCI_COMMAND_STATUS_REG)] & PCI_STATUS_CAPLIST_SUPPORT) 2038 printf(" Capability list pointer: 0x%02x\n", 2039 PCI_CAPLIST_PTR(regs[o2i(PCI_CAPLISTPTR_REG)])); 2040 else 2041 printf(" Reserved @ 0x34: 0x%08x\n", regs[o2i(0x34)]); 2042 2043 printf(" Reserved @ 0x38: 0x%08x\n", regs[o2i(0x38)]); 2044 2045 rval = regs[o2i(PCI_INTERRUPT_REG)]; 2046 printf(" Maximum Latency: 0x%02x\n", (rval >> 24) & 0xff); 2047 printf(" Minimum Grant: 0x%02x\n", (rval >> 16) & 0xff); 2048 printf(" Interrupt pin: 0x%02x ", PCI_INTERRUPT_PIN(rval)); 2049 switch (PCI_INTERRUPT_PIN(rval)) { 2050 case PCI_INTERRUPT_PIN_NONE: 2051 printf("(none)"); 2052 break; 2053 case PCI_INTERRUPT_PIN_A: 2054 printf("(pin A)"); 2055 break; 2056 case PCI_INTERRUPT_PIN_B: 2057 printf("(pin B)"); 2058 break; 2059 case PCI_INTERRUPT_PIN_C: 2060 printf("(pin C)"); 2061 break; 2062 case PCI_INTERRUPT_PIN_D: 2063 printf("(pin D)"); 2064 break; 2065 default: 2066 printf("(? ? ?)"); 2067 break; 2068 } 2069 printf("\n"); 2070 printf(" Interrupt line: 0x%02x\n", PCI_INTERRUPT_LINE(rval)); 2071 } 2072 2073 static void 2074 pci_conf_print_type1( 2075 #ifdef _KERNEL 2076 pci_chipset_tag_t pc, pcitag_t tag, 2077 #endif 2078 const pcireg_t *regs 2079 #ifdef _KERNEL 2080 , int sizebars 2081 #endif 2082 ) 2083 { 2084 int off, width; 2085 pcireg_t rval; 2086 uint32_t base, limit; 2087 uint32_t base_h, limit_h; 2088 uint64_t pbase, plimit; 2089 int use_upper; 2090 2091 /* 2092 * This layout was cribbed from the TI PCI2030 PCI-to-PCI 2093 * Bridge chip documentation, and may not be correct with 2094 * respect to various standards. (XXX) 2095 */ 2096 2097 for (off = 0x10; off < 0x18; off += width) { 2098 #ifdef _KERNEL 2099 width = pci_conf_print_bar(pc, tag, regs, off, NULL, sizebars); 2100 #else 2101 width = pci_conf_print_bar(regs, off, NULL); 2102 #endif 2103 } 2104 2105 rval = regs[o2i(PCI_BRIDGE_BUS_REG)]; 2106 printf(" Primary bus number: 0x%02x\n", 2107 PCI_BRIDGE_BUS_PRIMARY(rval)); 2108 printf(" Secondary bus number: 0x%02x\n", 2109 PCI_BRIDGE_BUS_SECONDARY(rval)); 2110 printf(" Subordinate bus number: 0x%02x\n", 2111 PCI_BRIDGE_BUS_SUBORDINATE(rval)); 2112 printf(" Secondary bus latency timer: 0x%02x\n", 2113 PCI_BRIDGE_BUS_SEC_LATTIMER(rval)); 2114 2115 rval = regs[o2i(PCI_BRIDGE_STATIO_REG)]; 2116 pci_conf_print_ssr(__SHIFTOUT(rval, __BITS(31, 16))); 2117 2118 /* I/O region */ 2119 printf(" I/O region:\n"); 2120 printf(" base register: 0x%02x\n", (rval >> 0) & 0xff); 2121 printf(" limit register: 0x%02x\n", (rval >> 8) & 0xff); 2122 if (PCI_BRIDGE_IO_32BITS(rval)) 2123 use_upper = 1; 2124 else 2125 use_upper = 0; 2126 onoff("32bit I/O", rval, use_upper); 2127 base = (rval & PCI_BRIDGE_STATIO_IOBASE_MASK) << 8; 2128 limit = ((rval >> PCI_BRIDGE_STATIO_IOLIMIT_SHIFT) 2129 & PCI_BRIDGE_STATIO_IOLIMIT_MASK) << 8; 2130 limit |= 0x00000fff; 2131 2132 rval = regs[o2i(PCI_BRIDGE_IOHIGH_REG)]; 2133 base_h = (rval >> 0) & 0xffff; 2134 limit_h = (rval >> 16) & 0xffff; 2135 printf(" base upper 16 bits register: 0x%04x\n", base_h); 2136 printf(" limit upper 16 bits register: 0x%04x\n", limit_h); 2137 2138 if (use_upper == 1) { 2139 base |= base_h << 16; 2140 limit |= limit_h << 16; 2141 } 2142 if (base < limit) { 2143 if (use_upper == 1) 2144 printf(" range: 0x%08x-0x%08x\n", base, limit); 2145 else 2146 printf(" range: 0x%04x-0x%04x\n", base, limit); 2147 } else 2148 printf(" range: not set\n"); 2149 2150 /* Non-prefetchable memory region */ 2151 rval = regs[o2i(PCI_BRIDGE_MEMORY_REG)]; 2152 printf(" Memory region:\n"); 2153 printf(" base register: 0x%04x\n", 2154 (rval >> 0) & 0xffff); 2155 printf(" limit register: 0x%04x\n", 2156 (rval >> 16) & 0xffff); 2157 base = ((rval >> PCI_BRIDGE_MEMORY_BASE_SHIFT) 2158 & PCI_BRIDGE_MEMORY_BASE_MASK) << 20; 2159 limit = (((rval >> PCI_BRIDGE_MEMORY_LIMIT_SHIFT) 2160 & PCI_BRIDGE_MEMORY_LIMIT_MASK) << 20) | 0x000fffff; 2161 if (base < limit) 2162 printf(" range: 0x%08x-0x%08x\n", base, limit); 2163 else 2164 printf(" range: not set\n"); 2165 2166 /* Prefetchable memory region */ 2167 rval = regs[o2i(PCI_BRIDGE_PREFETCHMEM_REG)]; 2168 printf(" Prefetchable memory region:\n"); 2169 printf(" base register: 0x%04x\n", 2170 (rval >> 0) & 0xffff); 2171 printf(" limit register: 0x%04x\n", 2172 (rval >> 16) & 0xffff); 2173 base_h = regs[o2i(PCI_BRIDGE_PREFETCHBASE32_REG)]; 2174 limit_h = regs[o2i(PCI_BRIDGE_PREFETCHLIMIT32_REG)]; 2175 printf(" base upper 32 bits register: 0x%08x\n", 2176 base_h); 2177 printf(" limit upper 32 bits register: 0x%08x\n", 2178 limit_h); 2179 if (PCI_BRIDGE_PREFETCHMEM_64BITS(rval)) 2180 use_upper = 1; 2181 else 2182 use_upper = 0; 2183 onoff("64bit memory address", rval, use_upper); 2184 pbase = ((rval >> PCI_BRIDGE_PREFETCHMEM_BASE_SHIFT) 2185 & PCI_BRIDGE_PREFETCHMEM_BASE_MASK) << 20; 2186 plimit = (((rval >> PCI_BRIDGE_PREFETCHMEM_LIMIT_SHIFT) 2187 & PCI_BRIDGE_PREFETCHMEM_LIMIT_MASK) << 20) | 0x000fffff; 2188 if (use_upper == 1) { 2189 pbase |= (uint64_t)base_h << 32; 2190 plimit |= (uint64_t)limit_h << 32; 2191 } 2192 if (pbase < plimit) { 2193 if (use_upper == 1) 2194 printf(" range: 0x%016" PRIx64 "-0x%016" PRIx64 2195 "\n", pbase, plimit); 2196 else 2197 printf(" range: 0x%08x-0x%08x\n", 2198 (uint32_t)pbase, (uint32_t)plimit); 2199 } else 2200 printf(" range: not set\n"); 2201 2202 if (regs[o2i(PCI_COMMAND_STATUS_REG)] & PCI_STATUS_CAPLIST_SUPPORT) 2203 printf(" Capability list pointer: 0x%02x\n", 2204 PCI_CAPLIST_PTR(regs[o2i(PCI_CAPLISTPTR_REG)])); 2205 else 2206 printf(" Reserved @ 0x34: 0x%08x\n", regs[o2i(0x34)]); 2207 2208 /* XXX */ 2209 printf(" Expansion ROM Base Address: 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(PCI_BRIDGE_CONTROL_REG)] >> PCI_BRIDGE_CONTROL_SHIFT) 2238 & PCI_BRIDGE_CONTROL_MASK; 2239 printf(" Bridge control register: 0x%04x\n", rval); /* XXX bits */ 2240 onoff("Parity error response", rval, 0x0001); 2241 onoff("Secondary SERR forwarding", rval, 0x0002); 2242 onoff("ISA enable", rval, 0x0004); 2243 onoff("VGA enable", rval, 0x0008); 2244 onoff("Master abort reporting", rval, 0x0020); 2245 onoff("Secondary bus reset", rval, 0x0040); 2246 onoff("Fast back-to-back capable", rval, 0x0080); 2247 } 2248 2249 static void 2250 pci_conf_print_type2( 2251 #ifdef _KERNEL 2252 pci_chipset_tag_t pc, pcitag_t tag, 2253 #endif 2254 const pcireg_t *regs 2255 #ifdef _KERNEL 2256 , int sizebars 2257 #endif 2258 ) 2259 { 2260 pcireg_t rval; 2261 2262 /* 2263 * XXX these need to be printed in more detail, need to be 2264 * XXX checked against specs/docs, etc. 2265 * 2266 * This layout was cribbed from the TI PCI1420 PCI-to-CardBus 2267 * controller chip documentation, and may not be correct with 2268 * respect to various standards. (XXX) 2269 */ 2270 2271 #ifdef _KERNEL 2272 pci_conf_print_bar(pc, tag, regs, 0x10, 2273 "CardBus socket/ExCA registers", sizebars); 2274 #else 2275 pci_conf_print_bar(regs, 0x10, "CardBus socket/ExCA registers"); 2276 #endif 2277 2278 /* Capability list pointer and secondary status register */ 2279 rval = regs[o2i(PCI_CARDBUS_CAPLISTPTR_REG)]; 2280 if (regs[o2i(PCI_COMMAND_STATUS_REG)] & PCI_STATUS_CAPLIST_SUPPORT) 2281 printf(" Capability list pointer: 0x%02x\n", 2282 PCI_CAPLIST_PTR(rval)); 2283 else 2284 printf(" Reserved @ 0x14: 0x%04" PRIxMAX "\n", 2285 __SHIFTOUT(rval, __BITS(15, 0))); 2286 pci_conf_print_ssr(__SHIFTOUT(rval, __BITS(31, 16))); 2287 2288 rval = regs[o2i(PCI_BRIDGE_BUS_REG)]; 2289 printf(" PCI bus number: 0x%02x\n", 2290 (rval >> 0) & 0xff); 2291 printf(" CardBus bus number: 0x%02x\n", 2292 (rval >> 8) & 0xff); 2293 printf(" Subordinate bus number: 0x%02x\n", 2294 (rval >> 16) & 0xff); 2295 printf(" CardBus latency timer: 0x%02x\n", 2296 (rval >> 24) & 0xff); 2297 2298 /* XXX Print more prettily */ 2299 printf(" CardBus memory region 0:\n"); 2300 printf(" base register: 0x%08x\n", regs[o2i(0x1c)]); 2301 printf(" limit register: 0x%08x\n", regs[o2i(0x20)]); 2302 printf(" CardBus memory region 1:\n"); 2303 printf(" base register: 0x%08x\n", regs[o2i(0x24)]); 2304 printf(" limit register: 0x%08x\n", regs[o2i(0x28)]); 2305 printf(" CardBus I/O region 0:\n"); 2306 printf(" base register: 0x%08x\n", regs[o2i(0x2c)]); 2307 printf(" limit register: 0x%08x\n", regs[o2i(0x30)]); 2308 printf(" CardBus I/O region 1:\n"); 2309 printf(" base register: 0x%08x\n", regs[o2i(0x34)]); 2310 printf(" limit register: 0x%08x\n", regs[o2i(0x38)]); 2311 2312 rval = regs[o2i(PCI_INTERRUPT_REG)]; 2313 printf(" Interrupt line: 0x%02x\n", 2314 (rval >> 0) & 0xff); 2315 printf(" Interrupt pin: 0x%02x ", 2316 (rval >> 8) & 0xff); 2317 switch ((rval >> 8) & 0xff) { 2318 case PCI_INTERRUPT_PIN_NONE: 2319 printf("(none)"); 2320 break; 2321 case PCI_INTERRUPT_PIN_A: 2322 printf("(pin A)"); 2323 break; 2324 case PCI_INTERRUPT_PIN_B: 2325 printf("(pin B)"); 2326 break; 2327 case PCI_INTERRUPT_PIN_C: 2328 printf("(pin C)"); 2329 break; 2330 case PCI_INTERRUPT_PIN_D: 2331 printf("(pin D)"); 2332 break; 2333 default: 2334 printf("(? ? ?)"); 2335 break; 2336 } 2337 printf("\n"); 2338 rval = (regs[o2i(0x3c)] >> 16) & 0xffff; 2339 printf(" Bridge control register: 0x%04x\n", rval); 2340 onoff("Parity error response", rval, __BIT(0)); 2341 onoff("SERR# enable", rval, __BIT(1)); 2342 onoff("ISA enable", rval, __BIT(2)); 2343 onoff("VGA enable", rval, __BIT(3)); 2344 onoff("Master abort mode", rval, __BIT(5)); 2345 onoff("Secondary (CardBus) bus reset", rval, __BIT(6)); 2346 onoff("Functional interrupts routed by ExCA registers", rval, 2347 __BIT(7)); 2348 onoff("Memory window 0 prefetchable", rval, __BIT(8)); 2349 onoff("Memory window 1 prefetchable", rval, __BIT(9)); 2350 onoff("Write posting enable", rval, __BIT(10)); 2351 2352 rval = regs[o2i(0x40)]; 2353 printf(" Subsystem vendor ID: 0x%04x\n", PCI_VENDOR(rval)); 2354 printf(" Subsystem ID: 0x%04x\n", PCI_PRODUCT(rval)); 2355 2356 #ifdef _KERNEL 2357 pci_conf_print_bar(pc, tag, regs, 0x44, "legacy-mode registers", 2358 sizebars); 2359 #else 2360 pci_conf_print_bar(regs, 0x44, "legacy-mode registers"); 2361 #endif 2362 } 2363 2364 void 2365 pci_conf_print( 2366 #ifdef _KERNEL 2367 pci_chipset_tag_t pc, pcitag_t tag, 2368 void (*printfn)(pci_chipset_tag_t, pcitag_t, const pcireg_t *) 2369 #else 2370 int pcifd, u_int bus, u_int dev, u_int func 2371 #endif 2372 ) 2373 { 2374 pcireg_t regs[o2i(256)]; 2375 int off, capoff, endoff, hdrtype; 2376 const char *typename; 2377 #ifdef _KERNEL 2378 void (*typeprintfn)(pci_chipset_tag_t, pcitag_t, const pcireg_t *, 2379 int); 2380 int sizebars; 2381 #else 2382 void (*typeprintfn)(const pcireg_t *); 2383 #endif 2384 2385 printf("PCI configuration registers:\n"); 2386 2387 for (off = 0; off < 256; off += 4) { 2388 #ifdef _KERNEL 2389 regs[o2i(off)] = pci_conf_read(pc, tag, off); 2390 #else 2391 if (pcibus_conf_read(pcifd, bus, dev, func, off, 2392 ®s[o2i(off)]) == -1) 2393 regs[o2i(off)] = 0; 2394 #endif 2395 } 2396 2397 #ifdef _KERNEL 2398 sizebars = 1; 2399 if (PCI_CLASS(regs[o2i(PCI_CLASS_REG)]) == PCI_CLASS_BRIDGE && 2400 PCI_SUBCLASS(regs[o2i(PCI_CLASS_REG)]) == PCI_SUBCLASS_BRIDGE_HOST) 2401 sizebars = 0; 2402 #endif 2403 2404 /* common header */ 2405 printf(" Common header:\n"); 2406 pci_conf_print_regs(regs, 0, 16); 2407 2408 printf("\n"); 2409 #ifdef _KERNEL 2410 pci_conf_print_common(pc, tag, regs); 2411 #else 2412 pci_conf_print_common(regs); 2413 #endif 2414 printf("\n"); 2415 2416 /* type-dependent header */ 2417 hdrtype = PCI_HDRTYPE_TYPE(regs[o2i(PCI_BHLC_REG)]); 2418 switch (hdrtype) { /* XXX make a table, eventually */ 2419 case 0: 2420 /* Standard device header */ 2421 typename = "\"normal\" device"; 2422 typeprintfn = &pci_conf_print_type0; 2423 capoff = PCI_CAPLISTPTR_REG; 2424 endoff = 64; 2425 break; 2426 case 1: 2427 /* PCI-PCI bridge header */ 2428 typename = "PCI-PCI bridge"; 2429 typeprintfn = &pci_conf_print_type1; 2430 capoff = PCI_CAPLISTPTR_REG; 2431 endoff = 64; 2432 break; 2433 case 2: 2434 /* PCI-CardBus bridge header */ 2435 typename = "PCI-CardBus bridge"; 2436 typeprintfn = &pci_conf_print_type2; 2437 capoff = PCI_CARDBUS_CAPLISTPTR_REG; 2438 endoff = 72; 2439 break; 2440 default: 2441 typename = NULL; 2442 typeprintfn = 0; 2443 capoff = -1; 2444 endoff = 64; 2445 break; 2446 } 2447 printf(" Type %d ", hdrtype); 2448 if (typename != NULL) 2449 printf("(%s) ", typename); 2450 printf("header:\n"); 2451 pci_conf_print_regs(regs, 16, endoff); 2452 printf("\n"); 2453 if (typeprintfn) { 2454 #ifdef _KERNEL 2455 (*typeprintfn)(pc, tag, regs, sizebars); 2456 #else 2457 (*typeprintfn)(regs); 2458 #endif 2459 } else 2460 printf(" Don't know how to pretty-print type %d header.\n", 2461 hdrtype); 2462 printf("\n"); 2463 2464 /* capability list, if present */ 2465 if ((regs[o2i(PCI_COMMAND_STATUS_REG)] & PCI_STATUS_CAPLIST_SUPPORT) 2466 && (capoff > 0)) { 2467 #ifdef _KERNEL 2468 pci_conf_print_caplist(pc, tag, regs, capoff); 2469 #else 2470 pci_conf_print_caplist(regs, capoff); 2471 #endif 2472 printf("\n"); 2473 } 2474 2475 /* device-dependent header */ 2476 printf(" Device-dependent header:\n"); 2477 pci_conf_print_regs(regs, endoff, 256); 2478 printf("\n"); 2479 #ifdef _KERNEL 2480 if (printfn) 2481 (*printfn)(pc, tag, regs); 2482 else 2483 printf(" Don't know how to pretty-print device-dependent header.\n"); 2484 printf("\n"); 2485 #endif /* _KERNEL */ 2486 } 2487