pci_subr.c revision 1.118 1 /* $NetBSD: pci_subr.c,v 1.118 2014/05/24 18:06: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.118 2014/05/24 18:06: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->name != NULL) ? subclassp->subclasses : NULL;
641 while (interfacep && interfacep->name != NULL) {
642 if (interface == interfacep->val)
643 break;
644 interfacep++;
645 }
646
647 if (vendor_namep == NULL)
648 cp += snprintf(cp, ep - cp, "%svendor 0x%04x product 0x%04x",
649 unmatched, vendor, product);
650 else if (product_namep != NULL)
651 cp += snprintf(cp, ep - cp, "%s %s", vendor_namep,
652 product_namep);
653 else
654 cp += snprintf(cp, ep - cp, "%s product 0x%04x",
655 vendor_namep, product);
656 if (showclass) {
657 cp += snprintf(cp, ep - cp, " (");
658 if (classp->name == NULL)
659 cp += snprintf(cp, ep - cp,
660 "class 0x%02x, subclass 0x%02x", class, subclass);
661 else {
662 if (subclassp == NULL || subclassp->name == NULL)
663 cp += snprintf(cp, ep - cp,
664 "%s, subclass 0x%02x",
665 classp->name, subclass);
666 else
667 cp += snprintf(cp, ep - cp, "%s %s",
668 subclassp->name, classp->name);
669 }
670 if ((interfacep == NULL) || (interfacep->name == NULL)) {
671 if (interface != 0)
672 cp += snprintf(cp, ep - cp,
673 ", interface 0x%02x", interface);
674 } else if (strncmp(interfacep->name, "", 1) != 0)
675 cp += snprintf(cp, ep - cp, ", %s",
676 interfacep->name);
677 if (revision != 0)
678 cp += snprintf(cp, ep - cp, ", revision 0x%02x",
679 revision);
680 cp += snprintf(cp, ep - cp, ")");
681 }
682 }
683
684 #ifdef _KERNEL
685 void
686 pci_aprint_devinfo_fancy(const struct pci_attach_args *pa, const char *naive,
687 const char *known, int addrev)
688 {
689 char devinfo[256];
690
691 if (known) {
692 aprint_normal(": %s", known);
693 if (addrev)
694 aprint_normal(" (rev. 0x%02x)",
695 PCI_REVISION(pa->pa_class));
696 aprint_normal("\n");
697 } else {
698 pci_devinfo(pa->pa_id, pa->pa_class, 0,
699 devinfo, sizeof(devinfo));
700 aprint_normal(": %s (rev. 0x%02x)\n", devinfo,
701 PCI_REVISION(pa->pa_class));
702 }
703 if (naive)
704 aprint_naive(": %s\n", naive);
705 else
706 aprint_naive("\n");
707 }
708 #endif
709
710 /*
711 * Print out most of the PCI configuration registers. Typically used
712 * in a device attach routine like this:
713 *
714 * #ifdef MYDEV_DEBUG
715 * printf("%s: ", device_xname(sc->sc_dev));
716 * pci_conf_print(pa->pa_pc, pa->pa_tag, NULL);
717 * #endif
718 */
719
720 #define i2o(i) ((i) * 4)
721 #define o2i(o) ((o) / 4)
722 #define onoff2(str, rval, bit, onstr, offstr) \
723 printf(" %s: %s\n", (str), ((rval) & (bit)) ? onstr : offstr);
724 #define onoff(str, rval, bit) onoff2(str, rval, bit, "on", "off")
725
726 static void
727 pci_conf_print_common(
728 #ifdef _KERNEL
729 pci_chipset_tag_t pc, pcitag_t tag,
730 #endif
731 const pcireg_t *regs)
732 {
733 const char *name;
734 const struct pci_class *classp, *subclassp;
735 pcireg_t rval;
736 unsigned int num;
737
738 rval = regs[o2i(PCI_ID_REG)];
739 name = pci_findvendor(rval);
740 if (name)
741 printf(" Vendor Name: %s (0x%04x)\n", name,
742 PCI_VENDOR(rval));
743 else
744 printf(" Vendor ID: 0x%04x\n", PCI_VENDOR(rval));
745 name = pci_findproduct(rval);
746 if (name)
747 printf(" Device Name: %s (0x%04x)\n", name,
748 PCI_PRODUCT(rval));
749 else
750 printf(" Device ID: 0x%04x\n", PCI_PRODUCT(rval));
751
752 rval = regs[o2i(PCI_COMMAND_STATUS_REG)];
753
754 printf(" Command register: 0x%04x\n", rval & 0xffff);
755 onoff("I/O space accesses", rval, PCI_COMMAND_IO_ENABLE);
756 onoff("Memory space accesses", rval, PCI_COMMAND_MEM_ENABLE);
757 onoff("Bus mastering", rval, PCI_COMMAND_MASTER_ENABLE);
758 onoff("Special cycles", rval, PCI_COMMAND_SPECIAL_ENABLE);
759 onoff("MWI transactions", rval, PCI_COMMAND_INVALIDATE_ENABLE);
760 onoff("Palette snooping", rval, PCI_COMMAND_PALETTE_ENABLE);
761 onoff("Parity error checking", rval, PCI_COMMAND_PARITY_ENABLE);
762 onoff("Address/data stepping", rval, PCI_COMMAND_STEPPING_ENABLE);
763 onoff("System error (SERR)", rval, PCI_COMMAND_SERR_ENABLE);
764 onoff("Fast back-to-back transactions", rval,
765 PCI_COMMAND_BACKTOBACK_ENABLE);
766 onoff("Interrupt disable", rval, PCI_COMMAND_INTERRUPT_DISABLE);
767
768 printf(" Status register: 0x%04x\n", (rval >> 16) & 0xffff);
769 onoff2("Interrupt status", rval, PCI_STATUS_INT_STATUS, "active",
770 "inactive");
771 onoff("Capability List support", rval, PCI_STATUS_CAPLIST_SUPPORT);
772 onoff("66 MHz capable", rval, PCI_STATUS_66MHZ_SUPPORT);
773 onoff("User Definable Features (UDF) support", rval,
774 PCI_STATUS_UDF_SUPPORT);
775 onoff("Fast back-to-back capable", rval,
776 PCI_STATUS_BACKTOBACK_SUPPORT);
777 onoff("Data parity error detected", rval, PCI_STATUS_PARITY_ERROR);
778
779 printf(" DEVSEL timing: ");
780 switch (rval & PCI_STATUS_DEVSEL_MASK) {
781 case PCI_STATUS_DEVSEL_FAST:
782 printf("fast");
783 break;
784 case PCI_STATUS_DEVSEL_MEDIUM:
785 printf("medium");
786 break;
787 case PCI_STATUS_DEVSEL_SLOW:
788 printf("slow");
789 break;
790 default:
791 printf("unknown/reserved"); /* XXX */
792 break;
793 }
794 printf(" (0x%x)\n", (rval & PCI_STATUS_DEVSEL_MASK) >> 25);
795
796 onoff("Slave signaled Target Abort", rval,
797 PCI_STATUS_TARGET_TARGET_ABORT);
798 onoff("Master received Target Abort", rval,
799 PCI_STATUS_MASTER_TARGET_ABORT);
800 onoff("Master received Master Abort", rval, PCI_STATUS_MASTER_ABORT);
801 onoff("Asserted System Error (SERR)", rval, PCI_STATUS_SPECIAL_ERROR);
802 onoff("Parity error detected", rval, PCI_STATUS_PARITY_DETECT);
803
804 rval = regs[o2i(PCI_CLASS_REG)];
805 for (classp = pci_class; classp->name != NULL; classp++) {
806 if (PCI_CLASS(rval) == classp->val)
807 break;
808 }
809 subclassp = (classp->name != NULL) ? classp->subclasses : NULL;
810 while (subclassp && subclassp->name != NULL) {
811 if (PCI_SUBCLASS(rval) == subclassp->val)
812 break;
813 subclassp++;
814 }
815 if (classp->name != NULL) {
816 printf(" Class Name: %s (0x%02x)\n", classp->name,
817 PCI_CLASS(rval));
818 if (subclassp != NULL && subclassp->name != NULL)
819 printf(" Subclass Name: %s (0x%02x)\n",
820 subclassp->name, PCI_SUBCLASS(rval));
821 else
822 printf(" Subclass ID: 0x%02x\n",
823 PCI_SUBCLASS(rval));
824 } else {
825 printf(" Class ID: 0x%02x\n", PCI_CLASS(rval));
826 printf(" Subclass ID: 0x%02x\n", PCI_SUBCLASS(rval));
827 }
828 printf(" Interface: 0x%02x\n", PCI_INTERFACE(rval));
829 printf(" Revision ID: 0x%02x\n", PCI_REVISION(rval));
830
831 rval = regs[o2i(PCI_BHLC_REG)];
832 printf(" BIST: 0x%02x\n", PCI_BIST(rval));
833 printf(" Header Type: 0x%02x%s (0x%02x)\n", PCI_HDRTYPE_TYPE(rval),
834 PCI_HDRTYPE_MULTIFN(rval) ? "+multifunction" : "",
835 PCI_HDRTYPE(rval));
836 printf(" Latency Timer: 0x%02x\n", PCI_LATTIMER(rval));
837 num = PCI_CACHELINE(rval);
838 printf(" Cache Line Size: %ubytes (0x%02x)\n", num * 4, num);
839 }
840
841 static int
842 pci_conf_print_bar(
843 #ifdef _KERNEL
844 pci_chipset_tag_t pc, pcitag_t tag,
845 #endif
846 const pcireg_t *regs, int reg, const char *name
847 #ifdef _KERNEL
848 , int sizebar
849 #endif
850 )
851 {
852 int width;
853 pcireg_t rval, rval64h;
854 #ifdef _KERNEL
855 int s;
856 pcireg_t mask, mask64h;
857 #endif
858
859 width = 4;
860
861 /*
862 * Section 6.2.5.1, `Address Maps', tells us that:
863 *
864 * 1) The builtin software should have already mapped the
865 * device in a reasonable way.
866 *
867 * 2) A device which wants 2^n bytes of memory will hardwire
868 * the bottom n bits of the address to 0. As recommended,
869 * we write all 1s and see what we get back.
870 */
871
872 rval = regs[o2i(reg)];
873 if (PCI_MAPREG_TYPE(rval) == PCI_MAPREG_TYPE_MEM &&
874 PCI_MAPREG_MEM_TYPE(rval) == PCI_MAPREG_MEM_TYPE_64BIT) {
875 rval64h = regs[o2i(reg + 4)];
876 width = 8;
877 } else
878 rval64h = 0;
879
880 #ifdef _KERNEL
881 /* XXX don't size unknown memory type? */
882 if (rval != 0 && sizebar) {
883 /*
884 * The following sequence seems to make some devices
885 * (e.g. host bus bridges, which don't normally
886 * have their space mapped) very unhappy, to
887 * the point of crashing the system.
888 *
889 * Therefore, if the mapping register is zero to
890 * start out with, don't bother trying.
891 */
892 s = splhigh();
893 pci_conf_write(pc, tag, reg, 0xffffffff);
894 mask = pci_conf_read(pc, tag, reg);
895 pci_conf_write(pc, tag, reg, rval);
896 if (PCI_MAPREG_TYPE(rval) == PCI_MAPREG_TYPE_MEM &&
897 PCI_MAPREG_MEM_TYPE(rval) == PCI_MAPREG_MEM_TYPE_64BIT) {
898 pci_conf_write(pc, tag, reg + 4, 0xffffffff);
899 mask64h = pci_conf_read(pc, tag, reg + 4);
900 pci_conf_write(pc, tag, reg + 4, rval64h);
901 } else
902 mask64h = 0;
903 splx(s);
904 } else
905 mask = mask64h = 0;
906 #endif /* _KERNEL */
907
908 printf(" Base address register at 0x%02x", reg);
909 if (name)
910 printf(" (%s)", name);
911 printf("\n ");
912 if (rval == 0) {
913 printf("not implemented(?)\n");
914 return width;
915 }
916 printf("type: ");
917 if (PCI_MAPREG_TYPE(rval) == PCI_MAPREG_TYPE_MEM) {
918 const char *type, *prefetch;
919
920 switch (PCI_MAPREG_MEM_TYPE(rval)) {
921 case PCI_MAPREG_MEM_TYPE_32BIT:
922 type = "32-bit";
923 break;
924 case PCI_MAPREG_MEM_TYPE_32BIT_1M:
925 type = "32-bit-1M";
926 break;
927 case PCI_MAPREG_MEM_TYPE_64BIT:
928 type = "64-bit";
929 break;
930 default:
931 type = "unknown (XXX)";
932 break;
933 }
934 if (PCI_MAPREG_MEM_PREFETCHABLE(rval))
935 prefetch = "";
936 else
937 prefetch = "non";
938 printf("%s %sprefetchable memory\n", type, prefetch);
939 switch (PCI_MAPREG_MEM_TYPE(rval)) {
940 case PCI_MAPREG_MEM_TYPE_64BIT:
941 printf(" base: 0x%016llx, ",
942 PCI_MAPREG_MEM64_ADDR(
943 ((((long long) rval64h) << 32) | rval)));
944 #ifdef _KERNEL
945 if (sizebar)
946 printf("size: 0x%016llx",
947 PCI_MAPREG_MEM64_SIZE(
948 ((((long long) mask64h) << 32) | mask)));
949 else
950 #endif /* _KERNEL */
951 printf("not sized");
952 printf("\n");
953 break;
954 case PCI_MAPREG_MEM_TYPE_32BIT:
955 case PCI_MAPREG_MEM_TYPE_32BIT_1M:
956 default:
957 printf(" base: 0x%08x, ",
958 PCI_MAPREG_MEM_ADDR(rval));
959 #ifdef _KERNEL
960 if (sizebar)
961 printf("size: 0x%08x",
962 PCI_MAPREG_MEM_SIZE(mask));
963 else
964 #endif /* _KERNEL */
965 printf("not sized");
966 printf("\n");
967 break;
968 }
969 } else {
970 #ifdef _KERNEL
971 if (sizebar)
972 printf("%d-bit ", mask & ~0x0000ffff ? 32 : 16);
973 #endif /* _KERNEL */
974 printf("i/o\n");
975 printf(" base: 0x%08x, ", PCI_MAPREG_IO_ADDR(rval));
976 #ifdef _KERNEL
977 if (sizebar)
978 printf("size: 0x%08x", PCI_MAPREG_IO_SIZE(mask));
979 else
980 #endif /* _KERNEL */
981 printf("not sized");
982 printf("\n");
983 }
984
985 return width;
986 }
987
988 static void
989 pci_conf_print_regs(const pcireg_t *regs, int first, int pastlast)
990 {
991 int off, needaddr, neednl;
992
993 needaddr = 1;
994 neednl = 0;
995 for (off = first; off < pastlast; off += 4) {
996 if ((off % 16) == 0 || needaddr) {
997 printf(" 0x%02x:", off);
998 needaddr = 0;
999 }
1000 printf(" 0x%08x", regs[o2i(off)]);
1001 neednl = 1;
1002 if ((off % 16) == 12) {
1003 printf("\n");
1004 neednl = 0;
1005 }
1006 }
1007 if (neednl)
1008 printf("\n");
1009 }
1010
1011 static const char *
1012 pci_conf_print_pcipm_cap_aux(uint16_t caps)
1013 {
1014
1015 switch ((caps >> 6) & 7) {
1016 case 0: return "self-powered";
1017 case 1: return "55 mA";
1018 case 2: return "100 mA";
1019 case 3: return "160 mA";
1020 case 4: return "220 mA";
1021 case 5: return "270 mA";
1022 case 6: return "320 mA";
1023 case 7:
1024 default: return "375 mA";
1025 }
1026 }
1027
1028 static const char *
1029 pci_conf_print_pcipm_cap_pmrev(uint8_t val)
1030 {
1031 static const char unk[] = "unknown";
1032 static const char *pmrev[8] = {
1033 unk, "1.0", "1.1", "1.2", unk, unk, unk, unk
1034 };
1035 if (val > 7)
1036 return unk;
1037 return pmrev[val];
1038 }
1039
1040 static void
1041 pci_conf_print_pcipm_cap(const pcireg_t *regs, int capoff)
1042 {
1043 uint16_t caps, pmcsr;
1044 pcireg_t reg;
1045
1046 caps = regs[o2i(capoff)] >> PCI_PMCR_SHIFT;
1047 reg = regs[o2i(capoff + PCI_PMCSR)];
1048 pmcsr = reg & 0xffff;
1049
1050 printf("\n PCI Power Management Capabilities Register\n");
1051
1052 printf(" Capabilities register: 0x%04x\n", caps);
1053 printf(" Version: %s\n",
1054 pci_conf_print_pcipm_cap_pmrev(caps & PCI_PMCR_VERSION_MASK));
1055 onoff("PME# clock", caps, PCI_PMCR_PME_CLOCK);
1056 onoff("Device specific initialization", caps, PCI_PMCR_DSI);
1057 printf(" 3.3V auxiliary current: %s\n",
1058 pci_conf_print_pcipm_cap_aux(caps));
1059 onoff("D1 power management state support", caps, PCI_PMCR_D1SUPP);
1060 onoff("D2 power management state support", caps, PCI_PMCR_D2SUPP);
1061 onoff("PME# support D0", caps, PCI_PMCR_PME_D0);
1062 onoff("PME# support D1", caps, PCI_PMCR_PME_D1);
1063 onoff("PME# support D2", caps, PCI_PMCR_PME_D2);
1064 onoff("PME# support D3 hot", caps, PCI_PMCR_PME_D3HOT);
1065 onoff("PME# support D3 cold", caps, PCI_PMCR_PME_D3COLD);
1066
1067 printf(" Control/status register: 0x%04x\n", pmcsr);
1068 printf(" Power state: D%d\n", pmcsr & PCI_PMCSR_STATE_MASK);
1069 onoff("PCI Express reserved", (pmcsr >> 2), 1);
1070 onoff("No soft reset", pmcsr, PCI_PMCSR_NO_SOFTRST);
1071 printf(" PME# assertion: %sabled\n",
1072 (pmcsr & PCI_PMCSR_PME_EN) ? "en" : "dis");
1073 onoff("PME# status", pmcsr, PCI_PMCSR_PME_STS);
1074 printf(" Bridge Support Extensions register: 0x%02x\n",
1075 (reg >> 16) & 0xff);
1076 onoff("B2/B3 support", reg, PCI_PMCSR_B2B3_SUPPORT);
1077 onoff("Bus Power/Clock Control Enable", reg, PCI_PMCSR_BPCC_EN);
1078 printf(" Data register: 0x%02x\n", (reg >> 24) & 0xff);
1079
1080 }
1081
1082 /* XXX pci_conf_print_vpd_cap */
1083 /* XXX pci_conf_print_slotid_cap */
1084
1085 static void
1086 pci_conf_print_msi_cap(const pcireg_t *regs, int capoff)
1087 {
1088 uint32_t ctl, mmc, mme;
1089
1090 regs += o2i(capoff);
1091 ctl = *regs++;
1092 mmc = __SHIFTOUT(ctl, PCI_MSI_CTL_MMC_MASK);
1093 mme = __SHIFTOUT(ctl, PCI_MSI_CTL_MME_MASK);
1094
1095 printf("\n PCI Message Signaled Interrupt\n");
1096
1097 printf(" Message Control register: 0x%04x\n", ctl >> 16);
1098 onoff("MSI Enabled", ctl, PCI_MSI_CTL_MSI_ENABLE);
1099 printf(" Multiple Message Capable: %s (%d vector%s)\n",
1100 mmc > 0 ? "yes" : "no", 1 << mmc, mmc > 0 ? "s" : "");
1101 printf(" Multiple Message Enabled: %s (%d vector%s)\n",
1102 mme > 0 ? "on" : "off", 1 << mme, mme > 0 ? "s" : "");
1103 onoff("64 Bit Address Capable", ctl, PCI_MSI_CTL_64BIT_ADDR);
1104 onoff("Per-Vector Masking Capable", ctl, PCI_MSI_CTL_PERVEC_MASK);
1105 printf(" Message Address %sregister: 0x%08x\n",
1106 ctl & PCI_MSI_CTL_64BIT_ADDR ? "(lower) " : "", *regs++);
1107 if (ctl & PCI_MSI_CTL_64BIT_ADDR) {
1108 printf(" Message Address %sregister: 0x%08x\n",
1109 "(upper) ", *regs++);
1110 }
1111 printf(" Message Data register: 0x%08x\n", *regs++);
1112 if (ctl & PCI_MSI_CTL_PERVEC_MASK) {
1113 printf(" Vector Mask register: 0x%08x\n", *regs++);
1114 printf(" Vector Pending register: 0x%08x\n", *regs++);
1115 }
1116 }
1117
1118 /* XXX pci_conf_print_cpci_hostwap_cap */
1119 /* XXX pci_conf_print_pcix_cap */
1120 /* XXX pci_conf_print_ldt_cap */
1121 /* XXX pci_conf_print_vendspec_cap */
1122
1123 static void
1124 pci_conf_print_vendspec_cap(const pcireg_t *regs, int capoff)
1125 {
1126 uint16_t caps;
1127
1128 caps = regs[o2i(capoff)] >> PCI_VENDORSPECIFIC_SHIFT;
1129
1130 printf("\n PCI Vendor Specific Capabilities Register\n");
1131 printf(" Capabilities length: 0x%02x\n", caps & 0xff);
1132 }
1133
1134 static void
1135 pci_conf_print_debugport_cap(const pcireg_t *regs, int capoff)
1136 {
1137 pcireg_t val;
1138
1139 val = regs[o2i(capoff + PCI_DEBUG_BASER)];
1140
1141 printf("\n Debugport Capability Register\n");
1142 printf(" Debug base Register: 0x%04x\n",
1143 val >> PCI_DEBUG_BASER_SHIFT);
1144 printf(" port offset: 0x%04x\n",
1145 (val & PCI_DEBUG_PORTOFF_MASK) >> PCI_DEBUG_PORTOFF_SHIFT);
1146 printf(" BAR number: %u\n",
1147 (val & PCI_DEBUG_BARNUM_MASK) >> PCI_DEBUG_BARNUM_SHIFT);
1148 }
1149
1150 /* XXX pci_conf_print_cpci_rsrcctl_cap */
1151 /* XXX pci_conf_print_hotplug_cap */
1152
1153 static void
1154 pci_conf_print_subsystem_cap(const pcireg_t *regs, int capoff)
1155 {
1156 pcireg_t reg;
1157
1158 reg = regs[o2i(capoff + PCI_CAP_SUBSYS_ID)];
1159
1160 printf("\n Subsystem ID Capability Register\n");
1161 printf(" Subsystem ID : 0x%08x\n", reg);
1162 }
1163
1164 /* XXX pci_conf_print_agp8_cap */
1165 /* XXX pci_conf_print_secure_cap */
1166
1167 static void
1168 pci_print_pcie_L0s_latency(uint32_t val)
1169 {
1170
1171 switch (val) {
1172 case 0x0:
1173 printf("Less than 64ns\n");
1174 break;
1175 case 0x1:
1176 case 0x2:
1177 case 0x3:
1178 printf("%dns to less than %dns\n", 32 << val, 32 << (val + 1));
1179 break;
1180 case 0x4:
1181 printf("512ns to less than 1us\n");
1182 break;
1183 case 0x5:
1184 printf("1us to less than 2us\n");
1185 break;
1186 case 0x6:
1187 printf("2us - 4us\n");
1188 break;
1189 case 0x7:
1190 printf("More than 4us\n");
1191 break;
1192 }
1193 }
1194
1195 static void
1196 pci_print_pcie_L1_latency(uint32_t val)
1197 {
1198
1199 switch (val) {
1200 case 0x0:
1201 printf("Less than 1us\n");
1202 break;
1203 case 0x6:
1204 printf("32us - 64us\n");
1205 break;
1206 case 0x7:
1207 printf("More than 64us\n");
1208 break;
1209 default:
1210 printf("%dus to less than %dus\n", 1 << (val - 1), 1 << val);
1211 break;
1212 }
1213 }
1214
1215 static void
1216 pci_print_pcie_compl_timeout(uint32_t val)
1217 {
1218
1219 switch (val) {
1220 case 0x0:
1221 printf("50us to 50ms\n");
1222 break;
1223 case 0x5:
1224 printf("16ms to 55ms\n");
1225 break;
1226 case 0x6:
1227 printf("65ms to 210ms\n");
1228 break;
1229 case 0x9:
1230 printf("260ms to 900ms\n");
1231 break;
1232 case 0xa:
1233 printf("1s to 3.5s\n");
1234 break;
1235 default:
1236 printf("unknown %u value\n", val);
1237 break;
1238 }
1239 }
1240
1241 static void
1242 pci_conf_print_pcie_cap(const pcireg_t *regs, int capoff)
1243 {
1244 pcireg_t reg; /* for each register */
1245 pcireg_t val; /* for each bitfield */
1246 bool check_link = false;
1247 bool check_slot = false;
1248 bool check_rootport = false;
1249 unsigned int pciever;
1250 static const char * const linkspeeds[] = {"2.5", "5.0", "8.0"};
1251 int i;
1252
1253 printf("\n PCI Express Capabilities Register\n");
1254 /* Capability Register */
1255 reg = regs[o2i(capoff)];
1256 printf(" Capability register: %04x\n", reg >> 16);
1257 pciever = (unsigned int)((reg & 0x000f0000) >> 16);
1258 printf(" Capability version: %u\n", pciever);
1259 printf(" Device type: ");
1260 switch ((reg & 0x00f00000) >> 20) {
1261 case 0x0:
1262 printf("PCI Express Endpoint device\n");
1263 check_link = true;
1264 break;
1265 case 0x1:
1266 printf("Legacy PCI Express Endpoint device\n");
1267 check_link = true;
1268 break;
1269 case 0x4:
1270 printf("Root Port of PCI Express Root Complex\n");
1271 check_link = true;
1272 check_slot = true;
1273 check_rootport = true;
1274 break;
1275 case 0x5:
1276 printf("Upstream Port of PCI Express Switch\n");
1277 break;
1278 case 0x6:
1279 printf("Downstream Port of PCI Express Switch\n");
1280 check_slot = true;
1281 check_rootport = true;
1282 break;
1283 case 0x7:
1284 printf("PCI Express to PCI/PCI-X Bridge\n");
1285 break;
1286 case 0x8:
1287 printf("PCI/PCI-X to PCI Express Bridge\n");
1288 break;
1289 case 0x9:
1290 printf("Root Complex Integrated Endpoint\n");
1291 break;
1292 case 0xa:
1293 check_rootport = true;
1294 printf("Root Complex Event Collector\n");
1295 break;
1296 default:
1297 printf("unknown\n");
1298 break;
1299 }
1300 if (check_slot && (reg & PCIE_XCAP_SI) != 0)
1301 printf(" Slot implemented\n");
1302 printf(" Interrupt Message Number: %x\n",
1303 (unsigned int)((reg & PCIE_XCAP_IRQ) >> 27));
1304
1305 /* Device Capability Register */
1306 reg = regs[o2i(capoff + PCIE_DCAP)];
1307 printf(" Device Capabilities Register: 0x%08x\n", reg);
1308 printf(" Max Payload Size Supported: %u bytes max\n",
1309 128 << (unsigned int)(reg & PCIE_DCAP_MAX_PAYLOAD));
1310 printf(" Phantom Functions Supported: ");
1311 switch ((reg & PCIE_DCAP_PHANTOM_FUNCS) >> 3) {
1312 case 0x0:
1313 printf("not available\n");
1314 break;
1315 case 0x1:
1316 printf("MSB\n");
1317 break;
1318 case 0x2:
1319 printf("two MSB\n");
1320 break;
1321 case 0x3:
1322 printf("All three bits\n");
1323 break;
1324 }
1325 printf(" Extended Tag Field Supported: %dbit\n",
1326 (reg & PCIE_DCAP_EXT_TAG_FIELD) == 0 ? 5 : 8);
1327 printf(" Endpoint L0 Acceptable Latency: ");
1328 pci_print_pcie_L0s_latency((reg & PCIE_DCAP_L0S_LATENCY) >> 6);
1329 printf(" Endpoint L1 Acceptable Latency: ");
1330 pci_print_pcie_L1_latency((reg & PCIE_DCAP_L1_LATENCY) >> 9);
1331 onoff("Attention Button Present:", reg, PCIE_DCAP_ATTN_BUTTON);
1332 onoff("Attention Indicator Present:", reg, PCIE_DCAP_ATTN_IND);
1333 onoff("Power Indicator Present", reg, PCIE_DCAP_PWR_IND);
1334 onoff("Role-Based Error Report", reg, PCIE_DCAP_ROLE_ERR_RPT);
1335 printf(" Captured Slot Power Limit Value: %d\n",
1336 (unsigned int)(reg & PCIE_DCAP_SLOT_PWR_LIM_VAL) >> 18);
1337 printf(" Captured Slot Power Limit Scale: %d\n",
1338 (unsigned int)(reg & PCIE_DCAP_SLOT_PWR_LIM_SCALE) >> 26);
1339 onoff("Function-Level Reset Capability", reg, PCIE_DCAP_FLR);
1340
1341 /* Device Control Register */
1342 reg = regs[o2i(capoff + PCIE_DCSR)];
1343 printf(" Device Control Register: 0x%04x\n", reg & 0xffff);
1344 onoff("Correctable Error Reporting Enable", reg,
1345 PCIE_DCSR_ENA_COR_ERR);
1346 onoff("Non Fatal Error Reporting Enable", reg, PCIE_DCSR_ENA_NFER);
1347 onoff("Fatal Error Reporting Enable", reg, PCIE_DCSR_ENA_FER);
1348 onoff("Unsupported Request Reporting Enable", reg, PCIE_DCSR_ENA_URR);
1349 onoff("Enable Relaxed Ordering", reg, PCIE_DCSR_ENA_RELAX_ORD);
1350 printf(" Max Payload Size: %d byte\n",
1351 128 << (((unsigned int)(reg & PCIE_DCSR_MAX_PAYLOAD) >> 5)));
1352 onoff("Extended Tag Field Enable", reg, PCIE_DCSR_EXT_TAG_FIELD);
1353 onoff("Phantom Functions Enable", reg, PCIE_DCSR_PHANTOM_FUNCS);
1354 onoff("Aux Power PM Enable", reg, PCIE_DCSR_AUX_POWER_PM);
1355 onoff("Enable No Snoop", reg, PCIE_DCSR_ENA_NO_SNOOP);
1356 printf(" Max Read Request Size: %d byte\n",
1357 128 << ((unsigned int)(reg & PCIE_DCSR_MAX_READ_REQ) >> 12));
1358
1359 /* Device Status Register */
1360 reg = regs[o2i(capoff + PCIE_DCSR)];
1361 printf(" Device Status Register: 0x%04x\n", reg >> 16);
1362 onoff("Correctable Error Detected", reg, PCIE_DCSR_CED);
1363 onoff("Non Fatal Error Detected", reg, PCIE_DCSR_NFED);
1364 onoff("Fatal Error Detected", reg, PCIE_DCSR_FED);
1365 onoff("Unsupported Request Detected", reg, PCIE_DCSR_URD);
1366 onoff("Aux Power Detected", reg, PCIE_DCSR_AUX_PWR);
1367 onoff("Transaction Pending", reg, PCIE_DCSR_TRANSACTION_PND);
1368
1369 if (check_link) {
1370 /* Link Capability Register */
1371 reg = regs[o2i(capoff + PCIE_LCAP)];
1372 printf(" Link Capabilities Register: 0x%08x\n", reg);
1373 printf(" Maximum Link Speed: ");
1374 val = reg & PCIE_LCAP_MAX_SPEED;
1375 if (val < 1 || val > 3) {
1376 printf("unknown %u value\n", val);
1377 } else {
1378 printf("%sGT/s\n", linkspeeds[val - 1]);
1379 }
1380 printf(" Maximum Link Width: x%u lanes\n",
1381 (unsigned int)(reg & PCIE_LCAP_MAX_WIDTH) >> 4);
1382 printf(" Active State PM Support: ");
1383 val = (reg & PCIE_LCAP_ASPM) >> 10;
1384 switch (val) {
1385 case 0x1:
1386 printf("L0s Entry supported\n");
1387 break;
1388 case 0x3:
1389 printf("L0s and L1 supported\n");
1390 break;
1391 default:
1392 printf("Reserved value\n");
1393 break;
1394 }
1395 printf(" L0 Exit Latency: ");
1396 pci_print_pcie_L0s_latency((reg & PCIE_LCAP_L0S_EXIT) >> 12);
1397 printf(" L1 Exit Latency: ");
1398 pci_print_pcie_L1_latency((reg & PCIE_LCAP_L1_EXIT) >> 15);
1399 printf(" Port Number: %u\n", reg >> 24);
1400 onoff("Clock Power Management", reg, PCIE_LCAP_CLOCK_PM);
1401 onoff("Surprise Down Error Report", reg,
1402 PCIE_LCAP_SURPRISE_DOWN);
1403 onoff("Data Link Layer Link Active", reg, PCIE_LCAP_DL_ACTIVE);
1404 onoff("Link BW Notification Capable", reg,
1405 PCIE_LCAP_LINK_BW_NOTIFY);
1406 onoff("ASPM Optionally Compliance", reg,
1407 PCIE_LCAP_ASPM_COMPLIANCE);
1408
1409 /* Link Control Register */
1410 reg = regs[o2i(capoff + PCIE_LCSR)];
1411 printf(" Link Control Register: 0x%04x\n", reg & 0xffff);
1412 printf(" Active State PM Control: ");
1413 val = reg & (PCIE_LCSR_ASPM_L1 | PCIE_LCSR_ASPM_L0S);
1414 switch (val) {
1415 case 0:
1416 printf("disabled\n");
1417 break;
1418 case 1:
1419 printf("L0s Entry Enabled\n");
1420 break;
1421 case 2:
1422 printf("L1 Entry Enabled\n");
1423 break;
1424 case 3:
1425 printf("L0s and L1 Entry Enabled\n");
1426 break;
1427 }
1428 onoff2("Read Completion Boundary Control", reg, PCIE_LCSR_RCB,
1429 "128bytes", "64bytes");
1430 onoff("Link Disable", reg, PCIE_LCSR_LINK_DIS);
1431 onoff("Retrain Link", reg, PCIE_LCSR_RETRAIN);
1432 onoff("Common Clock Configuration", reg, PCIE_LCSR_COMCLKCFG);
1433 onoff("Extended Synch", reg, PCIE_LCSR_EXTNDSYNC);
1434 onoff("Enable Clock Power Management", reg, PCIE_LCSR_ENCLKPM);
1435 onoff("Hardware Autonomous Width Disable", reg,
1436 PCIE_LCSR_HAWD);
1437 onoff("Link Bandwidth Management Interrupt Enable", reg,
1438 PCIE_LCSR_LBMIE);
1439 onoff("Link Autonomous Bandwidth Interrupt Enable", reg,
1440 PCIE_LCSR_LABIE);
1441
1442 /* Link Status Register */
1443 reg = regs[o2i(capoff + PCIE_LCSR)];
1444 printf(" Link Status Register: 0x%04x\n", reg >> 16);
1445 printf(" Negotiated Link Speed: ");
1446 if (((reg >> 16) & 0x000f) < 1 ||
1447 ((reg >> 16) & 0x000f) > 3) {
1448 printf("unknown %u value\n",
1449 (unsigned int)(reg & PCIE_LCSR_LINKSPEED) >> 16);
1450 } else {
1451 printf("%sGT/s\n",
1452 linkspeeds[((reg & PCIE_LCSR_LINKSPEED) >> 16) - 1]);
1453 }
1454 printf(" Negotiated Link Width: x%u lanes\n",
1455 (reg >> 20) & 0x003f);
1456 onoff("Training Error", reg, PCIE_LCSR_LINKTRAIN_ERR);
1457 onoff("Link Training", reg, PCIE_LCSR_LINKTRAIN);
1458 onoff("Slot Clock Configuration", reg, PCIE_LCSR_SLOTCLKCFG);
1459 onoff("Data Link Layer Link Active", reg, PCIE_LCSR_DLACTIVE);
1460 onoff("Link Bandwidth Management Status", reg,
1461 PCIE_LCSR_LINK_BW_MGMT);
1462 onoff("Link Autonomous Bandwidth Status", reg,
1463 PCIE_LCSR_LINK_AUTO_BW);
1464 }
1465
1466 if (check_slot == true) {
1467 /* Slot Capability Register */
1468 reg = regs[o2i(capoff + PCIE_SLCAP)];
1469 printf(" Slot Capability Register: %08x\n", reg);
1470 onoff("Attention Button Present", reg, PCIE_SLCAP_ABP);
1471 onoff("Power Controller Present", reg, PCIE_SLCAP_PCP);
1472 onoff("MRL Sensor Present", reg, PCIE_SLCAP_MSP);
1473 onoff("Attention Indicator Present", reg, PCIE_SLCAP_AIP);
1474 onoff("Power Indicator Present", reg, PCIE_SLCAP_PIP);
1475 onoff("Hot-Plug Surprise", reg, PCIE_SLCAP_HPS);
1476 onoff("Hot-Plug Capable", reg, PCIE_SLCAP_HPC);
1477 printf(" Slot Power Limit Value: %d\n",
1478 (unsigned int)(reg & PCIE_SLCAP_SPLV) >> 7);
1479 printf(" Slot Power Limit Scale: %d\n",
1480 (unsigned int)(reg & PCIE_SLCAP_SPLS) >> 15);
1481 onoff("Electromechanical Interlock Present", reg,
1482 PCIE_SLCAP_EIP);
1483 onoff("No Command Completed Support", reg, PCIE_SLCAP_NCCS);
1484 printf(" Physical Slot Number: %d\n",
1485 (unsigned int)(reg & PCIE_SLCAP_PSN) >> 19);
1486
1487 /* Slot Control Register */
1488 reg = regs[o2i(capoff + PCIE_SLCSR)];
1489 printf(" Slot Control Register: %04x\n", reg & 0xffff);
1490 onoff("Attention Button Pressed Enabled", reg, PCIE_SLCSR_ABE);
1491 onoff("Power Fault Detected Enabled", reg, PCIE_SLCSR_PFE);
1492 onoff("MRL Sensor Changed Enabled", reg, PCIE_SLCSR_MSE);
1493 onoff("Presense Detect Changed Enabled", reg, PCIE_SLCSR_PDE);
1494 onoff("Command Completed Interrupt Enabled", reg,
1495 PCIE_SLCSR_CCE);
1496 onoff("Hot-Plug Interrupt Enabled", reg, PCIE_SLCSR_HPE);
1497 printf(" Attention Indicator Control: ");
1498 switch ((reg & PCIE_SLCSR_AIC) >> 6) {
1499 case 0x0:
1500 printf("reserved\n");
1501 break;
1502 case 0x1:
1503 printf("on\n");
1504 break;
1505 case 0x2:
1506 printf("blink\n");
1507 break;
1508 case 0x3:
1509 printf("off\n");
1510 break;
1511 }
1512 printf(" Power Indicator Control: ");
1513 switch ((reg & PCIE_SLCSR_PIC) >> 8) {
1514 case 0x0:
1515 printf("reserved\n");
1516 break;
1517 case 0x1:
1518 printf("on\n");
1519 break;
1520 case 0x2:
1521 printf("blink\n");
1522 break;
1523 case 0x3:
1524 printf("off\n");
1525 break;
1526 }
1527 onoff("Power Controller Control", reg, PCIE_SLCSR_PCC);
1528 onoff("Electromechanical Interlock Control",
1529 reg, PCIE_SLCSR_EIC);
1530 onoff("Data Link Layer State Changed Enable", reg,
1531 PCIE_SLCSR_DLLSCE);
1532
1533 /* Slot Status Register */
1534 printf(" Slot Status Register: %04x\n", reg >> 16);
1535 onoff("Attention Button Pressed", reg, PCIE_SLCSR_ABP);
1536 onoff("Power Fault Detected", reg, PCIE_SLCSR_PFD);
1537 onoff("MRL Sensor Changed", reg, PCIE_SLCSR_MSC);
1538 onoff("Presense Detect Changed", reg, PCIE_SLCSR_PDC);
1539 onoff("Command Completed", reg, PCIE_SLCSR_CC);
1540 onoff("MRL Open", reg, PCIE_SLCSR_MS);
1541 onoff("Card Present in slot", reg, PCIE_SLCSR_PDS);
1542 onoff("Electromechanical Interlock engaged", reg,
1543 PCIE_SLCSR_EIS);
1544 onoff("Data Link Layer State Changed", reg, PCIE_SLCSR_LACS);
1545 }
1546
1547 if (check_rootport == true) {
1548 /* Root Control Register */
1549 reg = regs[o2i(capoff + PCIE_RCR)];
1550 printf(" Root Control Register: %04x\n", reg & 0xffff);
1551 onoff("SERR on Correctable Error Enable", reg,
1552 PCIE_RCR_SERR_CER);
1553 onoff("SERR on Non-Fatal Error Enable", reg,
1554 PCIE_RCR_SERR_NFER);
1555 onoff("SERR on Fatal Error Enable", reg, PCIE_RCR_SERR_FER);
1556 onoff("PME Interrupt Enable", reg, PCIE_RCR_PME_IE);
1557 onoff("CRS Software Visibility Enable", reg, PCIE_RCR_CRS_SVE);
1558
1559 /* Root Capability Register */
1560 printf(" Root Capability Register: %04x\n",
1561 reg >> 16);
1562
1563 /* Root Status Register */
1564 reg = regs[o2i(capoff + PCIE_RSR)];
1565 printf(" Root Status Register: %08x\n", reg);
1566 printf(" PME Requester ID: %04x\n",
1567 (unsigned int)(reg & PCIE_RSR_PME_REQESTER));
1568 onoff("PME was asserted", reg, PCIE_RSR_PME_STAT);
1569 onoff("another PME is pending", reg, PCIE_RSR_PME_PEND);
1570 }
1571
1572 /* PCIe DW9 to DW14 is for PCIe 2.0 and newer */
1573 if (pciever < 2)
1574 return;
1575
1576 /* Device Capabilities 2 */
1577 reg = regs[o2i(capoff + PCIE_DCAP2)];
1578 printf(" Device Capabilities 2: 0x%08x\n", reg);
1579 printf(" Completion Timeout Ranges Supported: %u \n",
1580 (unsigned int)(reg & PCIE_DCAP2_COMPT_RANGE));
1581 onoff("Completion Timeout Disable Supported", reg,
1582 PCIE_DCAP2_COMPT_DIS);
1583 onoff("ARI Forwarding Supported", reg, PCIE_DCAP2_ARI_FWD);
1584 onoff("AtomicOp Routing Supported", reg, PCIE_DCAP2_ATOM_ROUT);
1585 onoff("32bit AtomicOp Completer Supported", reg, PCIE_DCAP2_32ATOM);
1586 onoff("64bit AtomicOp Completer Supported", reg, PCIE_DCAP2_64ATOM);
1587 onoff("128-bit CAS Completer Supported", reg, PCIE_DCAP2_128CAS);
1588 onoff("No RO-enabled PR-PR passing", reg, PCIE_DCAP2_NO_ROPR_PASS);
1589 onoff("LTR Mechanism Supported", reg, PCIE_DCAP2_LTR_MEC);
1590 printf(" TPH Completer Supported: %u\n",
1591 (unsigned int)(reg & PCIE_DCAP2_TPH_COMP) >> 12);
1592 printf(" OBFF Supported: ");
1593 switch ((reg & PCIE_DCAP2_OBFF) >> 18) {
1594 case 0x0:
1595 printf("Not supported\n");
1596 break;
1597 case 0x1:
1598 printf("Message only\n");
1599 break;
1600 case 0x2:
1601 printf("WAKE# only\n");
1602 break;
1603 case 0x3:
1604 printf("Both\n");
1605 break;
1606 }
1607 onoff("Extended Fmt Field Supported", reg, PCIE_DCAP2_EXTFMT_FLD);
1608 onoff("End-End TLP Prefix Supported", reg, PCIE_DCAP2_EETLP_PREF);
1609 printf(" Max End-End TLP Prefixes: %u\n",
1610 (unsigned int)(reg & PCIE_DCAP2_MAX_EETLP) >> 22);
1611
1612 /* Device Control 2 */
1613 reg = regs[o2i(capoff + PCIE_DCSR2)];
1614 printf(" Device Control 2: 0x%04x\n", reg & 0xffff);
1615 printf(" Completion Timeout Value: ");
1616 pci_print_pcie_compl_timeout(reg & PCIE_DCSR2_COMPT_VAL);
1617 onoff("Completion Timeout Disabled", reg, PCIE_DCSR2_COMPT_DIS);
1618 onoff("ARI Forwarding Enabled", reg, PCIE_DCSR2_ARI_FWD);
1619 onoff("AtomicOp Rquester Enabled", reg, PCIE_DCSR2_ATOM_REQ);
1620 onoff("AtomicOp Egress Blocking", reg, PCIE_DCSR2_ATOM_EBLK);
1621 onoff("IDO Request Enabled", reg, PCIE_DCSR2_IDO_REQ);
1622 onoff("IDO Completion Enabled", reg, PCIE_DCSR2_IDO_COMP);
1623 onoff("LTR Mechanism Enabled", reg, PCIE_DCSR2_LTR_MEC);
1624 printf(" OBFF: ");
1625 switch ((reg & PCIE_DCSR2_OBFF_EN) >> 13) {
1626 case 0x0:
1627 printf("Disabled\n");
1628 break;
1629 case 0x1:
1630 printf("Enabled with Message Signaling Variation A\n");
1631 break;
1632 case 0x2:
1633 printf("Enabled with Message Signaling Variation B\n");
1634 break;
1635 case 0x3:
1636 printf("Enabled using WAKE# signaling\n");
1637 break;
1638 }
1639 onoff("End-End TLP Prefix Blocking on", reg, PCIE_DCSR2_EETLP);
1640
1641 if (check_link) {
1642 /* Link Capability 2 */
1643 reg = regs[o2i(capoff + PCIE_LCAP2)];
1644 printf(" Link Capabilities 2: 0x%08x\n", reg);
1645 val = (reg & PCIE_LCAP2_SUP_LNKSV) >> 1;
1646 printf(" Supported Link Speed Vector:");
1647 for (i = 0; i <= 2; i++) {
1648 if (((val >> i) & 0x01) != 0)
1649 printf(" %sGT/s", linkspeeds[i]);
1650 }
1651 printf("\n");
1652 onoff("Crosslink Supported", reg, PCIE_LCAP2_CROSSLNK);
1653
1654 /* Link Control 2 */
1655 reg = regs[o2i(capoff + PCIE_LCSR2)];
1656 printf(" Link Control 2: 0x%04x\n", reg & 0xffff);
1657 printf(" Target Link Speed: ");
1658 val = reg & PCIE_LCSR2_TGT_LSPEED;
1659 if (val < 1 || val > 3)
1660 printf("unknown %u value\n", val);
1661 else
1662 printf("%sGT/s\n", linkspeeds[val - 1]);
1663 onoff("Enter Compliance Enabled", reg, PCIE_LCSR2_ENT_COMPL);
1664 onoff("HW Autonomous Speed Disabled", reg,
1665 PCIE_LCSR2_HW_AS_DIS);
1666 onoff("Selectable De-emphasis", reg, PCIE_LCSR2_SEL_DEEMP);
1667 printf(" Transmit Margin: %u\n",
1668 (unsigned int)(reg & PCIE_LCSR2_TX_MARGIN) >> 7);
1669 onoff("Enter Modified Compliance", reg, PCIE_LCSR2_EN_MCOMP);
1670 onoff("Compliance SOS", reg, PCIE_LCSR2_COMP_SOS);
1671 printf(" Compliance Present/De-emphasis: %u\n",
1672 (unsigned int)(reg & PCIE_LCSR2_COMP_DEEMP) >> 12);
1673
1674 /* Link Status 2 */
1675 printf(" Link Status 2: 0x%04x\n", (reg >> 16) & 0xffff);
1676 onoff("Current De-emphasis Level", reg, PCIE_LCSR2_DEEMP_LVL);
1677 onoff("Equalization Complete", reg, PCIE_LCSR2_EQ_COMPL);
1678 onoff("Equalization Phase 1 Successful", reg,
1679 PCIE_LCSR2_EQP1_SUC);
1680 onoff("Equalization Phase 2 Successful", reg,
1681 PCIE_LCSR2_EQP2_SUC);
1682 onoff("Equalization Phase 3 Successful", reg,
1683 PCIE_LCSR2_EQP3_SUC);
1684 onoff("Link Equalization Request", reg, PCIE_LCSR2_LNKEQ_REQ);
1685 }
1686
1687 /* Slot Capability 2 */
1688 /* Slot Control 2 */
1689 /* Slot Status 2 */
1690 }
1691
1692 /* XXX pci_conf_print_msix_cap */
1693 /* XXX pci_conf_print_sata_cap */
1694 static void
1695 pci_conf_print_pciaf_cap(const pcireg_t *regs, int capoff)
1696 {
1697 pcireg_t reg;
1698
1699 printf("\n Advanced Features Capability Register\n");
1700
1701 reg = regs[o2i(capoff + PCI_AFCAPR)];
1702 printf(" AF Capabilities register: 0x%02x\n", (reg >> 24) & 0xff);
1703 onoff("Transaction Pending", reg, PCI_AF_TP_CAP);
1704 onoff("Function Level Reset", reg, PCI_AF_FLR_CAP);
1705 reg = regs[o2i(capoff + PCI_AFCSR)];
1706 printf(" AF Control register: 0x%02x\n", reg & 0xff);
1707 /*
1708 * Only PCI_AFCR_INITIATE_FLR is a member of the AF control register
1709 * and it's always 0 on read
1710 */
1711 printf(" AF Status register: 0x%02x\n", (reg >> 8) & 0xff);
1712 onoff("Transaction Pending", reg, PCI_AFSR_TP);
1713 }
1714
1715 static void
1716 pci_conf_print_caplist(
1717 #ifdef _KERNEL
1718 pci_chipset_tag_t pc, pcitag_t tag,
1719 #endif
1720 const pcireg_t *regs, int capoff)
1721 {
1722 int off;
1723 pcireg_t rval;
1724 int pcie_off = -1, pcipm_off = -1, msi_off = -1, vendspec_off = -1;
1725 int debugport_off = -1, subsystem_off = -1, pciaf_off = -1;
1726
1727 for (off = PCI_CAPLIST_PTR(regs[o2i(capoff)]);
1728 off != 0;
1729 off = PCI_CAPLIST_NEXT(regs[o2i(off)])) {
1730 rval = regs[o2i(off)];
1731 printf(" Capability register at 0x%02x\n", off);
1732
1733 printf(" type: 0x%02x (", PCI_CAPLIST_CAP(rval));
1734 switch (PCI_CAPLIST_CAP(rval)) {
1735 case PCI_CAP_RESERVED0:
1736 printf("reserved");
1737 break;
1738 case PCI_CAP_PWRMGMT:
1739 printf("Power Management, rev. %s",
1740 pci_conf_print_pcipm_cap_pmrev((rval >> 0) & 0x07));
1741 pcipm_off = off;
1742 break;
1743 case PCI_CAP_AGP:
1744 printf("AGP, rev. %d.%d",
1745 PCI_CAP_AGP_MAJOR(rval),
1746 PCI_CAP_AGP_MINOR(rval));
1747 break;
1748 case PCI_CAP_VPD:
1749 printf("VPD");
1750 break;
1751 case PCI_CAP_SLOTID:
1752 printf("SlotID");
1753 break;
1754 case PCI_CAP_MSI:
1755 printf("MSI");
1756 msi_off = off;
1757 break;
1758 case PCI_CAP_CPCI_HOTSWAP:
1759 printf("CompactPCI Hot-swapping");
1760 break;
1761 case PCI_CAP_PCIX:
1762 printf("PCI-X");
1763 break;
1764 case PCI_CAP_LDT:
1765 printf("LDT");
1766 break;
1767 case PCI_CAP_VENDSPEC:
1768 vendspec_off = off;
1769 printf("Vendor-specific");
1770 break;
1771 case PCI_CAP_DEBUGPORT:
1772 printf("Debug Port");
1773 debugport_off = off;
1774 break;
1775 case PCI_CAP_CPCI_RSRCCTL:
1776 printf("CompactPCI Resource Control");
1777 break;
1778 case PCI_CAP_HOTPLUG:
1779 printf("Hot-Plug");
1780 break;
1781 case PCI_CAP_SUBVENDOR:
1782 printf("Subsystem ID");
1783 subsystem_off = off;
1784 break;
1785 case PCI_CAP_AGP8:
1786 printf("AGP 8x");
1787 break;
1788 case PCI_CAP_SECURE:
1789 printf("Secure Device");
1790 break;
1791 case PCI_CAP_PCIEXPRESS:
1792 printf("PCI Express");
1793 pcie_off = off;
1794 break;
1795 case PCI_CAP_MSIX:
1796 printf("MSI-X");
1797 break;
1798 case PCI_CAP_SATA:
1799 printf("SATA");
1800 break;
1801 case PCI_CAP_PCIAF:
1802 printf("Advanced Features");
1803 pciaf_off = off;
1804 break;
1805 default:
1806 printf("unknown");
1807 }
1808 printf(")\n");
1809 }
1810 if (pcipm_off != -1)
1811 pci_conf_print_pcipm_cap(regs, pcipm_off);
1812 /* XXX AGP */
1813 /* XXX VPD */
1814 /* XXX SLOTID */
1815 if (msi_off != -1)
1816 pci_conf_print_msi_cap(regs, msi_off);
1817 /* XXX CPCI_HOTSWAP */
1818 /* XXX PCIX */
1819 /* XXX LDT */
1820 if (vendspec_off != -1)
1821 pci_conf_print_vendspec_cap(regs, vendspec_off);
1822 if (debugport_off != -1)
1823 pci_conf_print_debugport_cap(regs, debugport_off);
1824 /* XXX CPCI_RSRCCTL */
1825 /* XXX HOTPLUG */
1826 if (subsystem_off != -1)
1827 pci_conf_print_subsystem_cap(regs, subsystem_off);
1828 /* XXX AGP8 */
1829 /* XXX SECURE */
1830 if (pcie_off != -1)
1831 pci_conf_print_pcie_cap(regs, pcie_off);
1832 /* XXX MSIX */
1833 /* XXX SATA */
1834 if (pciaf_off != -1)
1835 pci_conf_print_pciaf_cap(regs, pciaf_off);
1836 }
1837
1838 /* Print the Secondary Status Register. */
1839 static void
1840 pci_conf_print_ssr(pcireg_t rval)
1841 {
1842 pcireg_t devsel;
1843
1844 printf(" Secondary status register: 0x%04x\n", rval); /* XXX bits */
1845 onoff("66 MHz capable", rval, __BIT(5));
1846 onoff("User Definable Features (UDF) support", rval, __BIT(6));
1847 onoff("Fast back-to-back capable", rval, __BIT(7));
1848 onoff("Data parity error detected", rval, __BIT(8));
1849
1850 printf(" DEVSEL timing: ");
1851 devsel = __SHIFTOUT(rval, __BITS(10, 9));
1852 switch (devsel) {
1853 case 0:
1854 printf("fast");
1855 break;
1856 case 1:
1857 printf("medium");
1858 break;
1859 case 2:
1860 printf("slow");
1861 break;
1862 default:
1863 printf("unknown/reserved"); /* XXX */
1864 break;
1865 }
1866 printf(" (0x%x)\n", devsel);
1867
1868 onoff("Signalled target abort", rval, __BIT(11));
1869 onoff("Received target abort", rval, __BIT(12));
1870 onoff("Received master abort", rval, __BIT(13));
1871 onoff("Received system error", rval, __BIT(14));
1872 onoff("Detected parity error", rval, __BIT(15));
1873 }
1874
1875 static void
1876 pci_conf_print_type0(
1877 #ifdef _KERNEL
1878 pci_chipset_tag_t pc, pcitag_t tag,
1879 #endif
1880 const pcireg_t *regs
1881 #ifdef _KERNEL
1882 , int sizebars
1883 #endif
1884 )
1885 {
1886 int off, width;
1887 pcireg_t rval;
1888
1889 for (off = PCI_MAPREG_START; off < PCI_MAPREG_END; off += width) {
1890 #ifdef _KERNEL
1891 width = pci_conf_print_bar(pc, tag, regs, off, NULL, sizebars);
1892 #else
1893 width = pci_conf_print_bar(regs, off, NULL);
1894 #endif
1895 }
1896
1897 printf(" Cardbus CIS Pointer: 0x%08x\n", regs[o2i(0x28)]);
1898
1899 rval = regs[o2i(PCI_SUBSYS_ID_REG)];
1900 printf(" Subsystem vendor ID: 0x%04x\n", PCI_VENDOR(rval));
1901 printf(" Subsystem ID: 0x%04x\n", PCI_PRODUCT(rval));
1902
1903 /* XXX */
1904 printf(" Expansion ROM Base Address: 0x%08x\n", regs[o2i(0x30)]);
1905
1906 if (regs[o2i(PCI_COMMAND_STATUS_REG)] & PCI_STATUS_CAPLIST_SUPPORT)
1907 printf(" Capability list pointer: 0x%02x\n",
1908 PCI_CAPLIST_PTR(regs[o2i(PCI_CAPLISTPTR_REG)]));
1909 else
1910 printf(" Reserved @ 0x34: 0x%08x\n", regs[o2i(0x34)]);
1911
1912 printf(" Reserved @ 0x38: 0x%08x\n", regs[o2i(0x38)]);
1913
1914 rval = regs[o2i(PCI_INTERRUPT_REG)];
1915 printf(" Maximum Latency: 0x%02x\n", (rval >> 24) & 0xff);
1916 printf(" Minimum Grant: 0x%02x\n", (rval >> 16) & 0xff);
1917 printf(" Interrupt pin: 0x%02x ", PCI_INTERRUPT_PIN(rval));
1918 switch (PCI_INTERRUPT_PIN(rval)) {
1919 case PCI_INTERRUPT_PIN_NONE:
1920 printf("(none)");
1921 break;
1922 case PCI_INTERRUPT_PIN_A:
1923 printf("(pin A)");
1924 break;
1925 case PCI_INTERRUPT_PIN_B:
1926 printf("(pin B)");
1927 break;
1928 case PCI_INTERRUPT_PIN_C:
1929 printf("(pin C)");
1930 break;
1931 case PCI_INTERRUPT_PIN_D:
1932 printf("(pin D)");
1933 break;
1934 default:
1935 printf("(? ? ?)");
1936 break;
1937 }
1938 printf("\n");
1939 printf(" Interrupt line: 0x%02x\n", PCI_INTERRUPT_LINE(rval));
1940 }
1941
1942 static void
1943 pci_conf_print_type1(
1944 #ifdef _KERNEL
1945 pci_chipset_tag_t pc, pcitag_t tag,
1946 #endif
1947 const pcireg_t *regs
1948 #ifdef _KERNEL
1949 , int sizebars
1950 #endif
1951 )
1952 {
1953 int off, width;
1954 pcireg_t rval;
1955 uint32_t base, limit;
1956 uint32_t base_h, limit_h;
1957 uint64_t pbase, plimit;
1958 int use_upper;
1959
1960 /*
1961 * XXX these need to be printed in more detail, need to be
1962 * XXX checked against specs/docs, etc.
1963 *
1964 * This layout was cribbed from the TI PCI2030 PCI-to-PCI
1965 * Bridge chip documentation, and may not be correct with
1966 * respect to various standards. (XXX)
1967 */
1968
1969 for (off = 0x10; off < 0x18; off += width) {
1970 #ifdef _KERNEL
1971 width = pci_conf_print_bar(pc, tag, regs, off, NULL, sizebars);
1972 #else
1973 width = pci_conf_print_bar(regs, off, NULL);
1974 #endif
1975 }
1976
1977 rval = regs[o2i(PCI_BRIDGE_BUS_REG)];
1978 printf(" Primary bus number: 0x%02x\n",
1979 PCI_BRIDGE_BUS_PRIMARY(rval));
1980 printf(" Secondary bus number: 0x%02x\n",
1981 PCI_BRIDGE_BUS_SECONDARY(rval));
1982 printf(" Subordinate bus number: 0x%02x\n",
1983 PCI_BRIDGE_BUS_SUBORDINATE(rval));
1984 printf(" Secondary bus latency timer: 0x%02x\n",
1985 PCI_BRIDGE_BUS_SEC_LATTIMER(rval));
1986
1987 rval = regs[o2i(PCI_BRIDGE_STATIO_REG)];
1988 pci_conf_print_ssr(__SHIFTOUT(rval, __BITS(31, 16)));
1989
1990 /* I/O region */
1991 printf(" I/O region:\n");
1992 printf(" base register: 0x%02x\n", (rval >> 0) & 0xff);
1993 printf(" limit register: 0x%02x\n", (rval >> 8) & 0xff);
1994 if (PCI_BRIDGE_IO_32BITS(rval))
1995 use_upper = 1;
1996 else
1997 use_upper = 0;
1998 onoff("32bit I/O", rval, use_upper);
1999 base = (rval & PCI_BRIDGE_STATIO_IOBASE_MASK) << 8;
2000 limit = ((rval >> PCI_BRIDGE_STATIO_IOLIMIT_SHIFT)
2001 & PCI_BRIDGE_STATIO_IOLIMIT_MASK) << 8;
2002 limit |= 0x00000fff;
2003
2004 rval = regs[o2i(PCI_BRIDGE_IOHIGH_REG)];
2005 base_h = (rval >> 0) & 0xffff;
2006 limit_h = (rval >> 16) & 0xffff;
2007 printf(" base upper 16 bits register: 0x%04x\n", base_h);
2008 printf(" limit upper 16 bits register: 0x%04x\n", limit_h);
2009
2010 if (use_upper == 1) {
2011 base |= base_h << 16;
2012 limit |= limit_h << 16;
2013 }
2014 if (base < limit) {
2015 if (use_upper == 1)
2016 printf(" range: 0x%08x-0x%08x\n", base, limit);
2017 else
2018 printf(" range: 0x%04x-0x%04x\n", base, limit);
2019 }
2020
2021 /* Non-prefetchable memory region */
2022 rval = regs[o2i(PCI_BRIDGE_MEMORY_REG)];
2023 printf(" Memory region:\n");
2024 printf(" base register: 0x%04x\n",
2025 (rval >> 0) & 0xffff);
2026 printf(" limit register: 0x%04x\n",
2027 (rval >> 16) & 0xffff);
2028 base = ((rval >> PCI_BRIDGE_MEMORY_BASE_SHIFT)
2029 & PCI_BRIDGE_MEMORY_BASE_MASK) << 20;
2030 limit = (((rval >> PCI_BRIDGE_MEMORY_LIMIT_SHIFT)
2031 & PCI_BRIDGE_MEMORY_LIMIT_MASK) << 20) | 0x000fffff;
2032 if (base < limit)
2033 printf(" range: 0x%08x-0x%08x\n", base, limit);
2034
2035 /* Prefetchable memory region */
2036 rval = regs[o2i(PCI_BRIDGE_PREFETCHMEM_REG)];
2037 printf(" Prefetchable memory region:\n");
2038 printf(" base register: 0x%04x\n",
2039 (rval >> 0) & 0xffff);
2040 printf(" limit register: 0x%04x\n",
2041 (rval >> 16) & 0xffff);
2042 base_h = regs[o2i(PCI_BRIDGE_PREFETCHBASE32_REG)];
2043 limit_h = regs[o2i(PCI_BRIDGE_PREFETCHLIMIT32_REG)];
2044 printf(" base upper 32 bits register: 0x%08x\n",
2045 base_h);
2046 printf(" limit upper 32 bits register: 0x%08x\n",
2047 limit_h);
2048 if (PCI_BRIDGE_PREFETCHMEM_64BITS(rval))
2049 use_upper = 1;
2050 else
2051 use_upper = 0;
2052 onoff("64bit memory address", rval, use_upper);
2053 pbase = ((rval >> PCI_BRIDGE_PREFETCHMEM_BASE_SHIFT)
2054 & PCI_BRIDGE_PREFETCHMEM_BASE_MASK) << 20;
2055 plimit = (((rval >> PCI_BRIDGE_PREFETCHMEM_LIMIT_SHIFT)
2056 & PCI_BRIDGE_PREFETCHMEM_LIMIT_MASK) << 20) | 0x000fffff;
2057 if (use_upper == 1) {
2058 pbase |= (uint64_t)base_h << 32;
2059 plimit |= (uint64_t)limit_h << 32;
2060 }
2061 if (pbase < plimit) {
2062 if (use_upper == 1)
2063 printf(" range: 0x%016" PRIx64 "-0x%016" PRIx64
2064 "\n", pbase, plimit);
2065 else
2066 printf(" range: 0x%08x-0x%08x\n",
2067 (uint32_t)pbase, (uint32_t)plimit);
2068 }
2069
2070 if (regs[o2i(PCI_COMMAND_STATUS_REG)] & PCI_STATUS_CAPLIST_SUPPORT)
2071 printf(" Capability list pointer: 0x%02x\n",
2072 PCI_CAPLIST_PTR(regs[o2i(PCI_CAPLISTPTR_REG)]));
2073 else
2074 printf(" Reserved @ 0x34: 0x%08x\n", regs[o2i(0x34)]);
2075
2076 /* XXX */
2077 printf(" Expansion ROM Base Address: 0x%08x\n", regs[o2i(0x38)]);
2078
2079 rval = regs[o2i(PCI_INTERRUPT_REG)];
2080 printf(" Interrupt line: 0x%02x\n",
2081 (rval >> 0) & 0xff);
2082 printf(" Interrupt pin: 0x%02x ",
2083 (rval >> 8) & 0xff);
2084 switch ((rval >> 8) & 0xff) {
2085 case PCI_INTERRUPT_PIN_NONE:
2086 printf("(none)");
2087 break;
2088 case PCI_INTERRUPT_PIN_A:
2089 printf("(pin A)");
2090 break;
2091 case PCI_INTERRUPT_PIN_B:
2092 printf("(pin B)");
2093 break;
2094 case PCI_INTERRUPT_PIN_C:
2095 printf("(pin C)");
2096 break;
2097 case PCI_INTERRUPT_PIN_D:
2098 printf("(pin D)");
2099 break;
2100 default:
2101 printf("(? ? ?)");
2102 break;
2103 }
2104 printf("\n");
2105 rval = (regs[o2i(PCI_BRIDGE_CONTROL_REG)] >> PCI_BRIDGE_CONTROL_SHIFT)
2106 & PCI_BRIDGE_CONTROL_MASK;
2107 printf(" Bridge control register: 0x%04x\n", rval); /* XXX bits */
2108 onoff("Parity error response", rval, 0x0001);
2109 onoff("Secondary SERR forwarding", rval, 0x0002);
2110 onoff("ISA enable", rval, 0x0004);
2111 onoff("VGA enable", rval, 0x0008);
2112 onoff("Master abort reporting", rval, 0x0020);
2113 onoff("Secondary bus reset", rval, 0x0040);
2114 onoff("Fast back-to-back capable", rval, 0x0080);
2115 }
2116
2117 static void
2118 pci_conf_print_type2(
2119 #ifdef _KERNEL
2120 pci_chipset_tag_t pc, pcitag_t tag,
2121 #endif
2122 const pcireg_t *regs
2123 #ifdef _KERNEL
2124 , int sizebars
2125 #endif
2126 )
2127 {
2128 pcireg_t rval;
2129
2130 /*
2131 * XXX these need to be printed in more detail, need to be
2132 * XXX checked against specs/docs, etc.
2133 *
2134 * This layout was cribbed from the TI PCI1420 PCI-to-CardBus
2135 * controller chip documentation, and may not be correct with
2136 * respect to various standards. (XXX)
2137 */
2138
2139 #ifdef _KERNEL
2140 pci_conf_print_bar(pc, tag, regs, 0x10,
2141 "CardBus socket/ExCA registers", sizebars);
2142 #else
2143 pci_conf_print_bar(regs, 0x10, "CardBus socket/ExCA registers");
2144 #endif
2145
2146 /* Capability list pointer and secondary status register */
2147 rval = regs[o2i(PCI_CARDBUS_CAPLISTPTR_REG)];
2148 if (regs[o2i(PCI_COMMAND_STATUS_REG)] & PCI_STATUS_CAPLIST_SUPPORT)
2149 printf(" Capability list pointer: 0x%02x\n",
2150 PCI_CAPLIST_PTR(rval));
2151 else
2152 printf(" Reserved @ 0x14: 0x%04" PRIxMAX "\n",
2153 __SHIFTOUT(rval, __BITS(15, 0)));
2154 pci_conf_print_ssr(__SHIFTOUT(rval, __BITS(31, 16)));
2155
2156 rval = regs[o2i(PCI_BRIDGE_BUS_REG)];
2157 printf(" PCI bus number: 0x%02x\n",
2158 (rval >> 0) & 0xff);
2159 printf(" CardBus bus number: 0x%02x\n",
2160 (rval >> 8) & 0xff);
2161 printf(" Subordinate bus number: 0x%02x\n",
2162 (rval >> 16) & 0xff);
2163 printf(" CardBus latency timer: 0x%02x\n",
2164 (rval >> 24) & 0xff);
2165
2166 /* XXX Print more prettily */
2167 printf(" CardBus memory region 0:\n");
2168 printf(" base register: 0x%08x\n", regs[o2i(0x1c)]);
2169 printf(" limit register: 0x%08x\n", regs[o2i(0x20)]);
2170 printf(" CardBus memory region 1:\n");
2171 printf(" base register: 0x%08x\n", regs[o2i(0x24)]);
2172 printf(" limit register: 0x%08x\n", regs[o2i(0x28)]);
2173 printf(" CardBus I/O region 0:\n");
2174 printf(" base register: 0x%08x\n", regs[o2i(0x2c)]);
2175 printf(" limit register: 0x%08x\n", regs[o2i(0x30)]);
2176 printf(" CardBus I/O region 1:\n");
2177 printf(" base register: 0x%08x\n", regs[o2i(0x34)]);
2178 printf(" limit register: 0x%08x\n", regs[o2i(0x38)]);
2179
2180 rval = regs[o2i(PCI_INTERRUPT_REG)];
2181 printf(" Interrupt line: 0x%02x\n",
2182 (rval >> 0) & 0xff);
2183 printf(" Interrupt pin: 0x%02x ",
2184 (rval >> 8) & 0xff);
2185 switch ((rval >> 8) & 0xff) {
2186 case PCI_INTERRUPT_PIN_NONE:
2187 printf("(none)");
2188 break;
2189 case PCI_INTERRUPT_PIN_A:
2190 printf("(pin A)");
2191 break;
2192 case PCI_INTERRUPT_PIN_B:
2193 printf("(pin B)");
2194 break;
2195 case PCI_INTERRUPT_PIN_C:
2196 printf("(pin C)");
2197 break;
2198 case PCI_INTERRUPT_PIN_D:
2199 printf("(pin D)");
2200 break;
2201 default:
2202 printf("(? ? ?)");
2203 break;
2204 }
2205 printf("\n");
2206 rval = (regs[o2i(0x3c)] >> 16) & 0xffff;
2207 printf(" Bridge control register: 0x%04x\n", rval);
2208 onoff("Parity error response", rval, __BIT(0));
2209 onoff("SERR# enable", rval, __BIT(1));
2210 onoff("ISA enable", rval, __BIT(2));
2211 onoff("VGA enable", rval, __BIT(3));
2212 onoff("Master abort mode", rval, __BIT(5));
2213 onoff("Secondary (CardBus) bus reset", rval, __BIT(6));
2214 onoff("Functional interrupts routed by ExCA registers", rval,
2215 __BIT(7));
2216 onoff("Memory window 0 prefetchable", rval, __BIT(8));
2217 onoff("Memory window 1 prefetchable", rval, __BIT(9));
2218 onoff("Write posting enable", rval, __BIT(10));
2219
2220 rval = regs[o2i(0x40)];
2221 printf(" Subsystem vendor ID: 0x%04x\n", PCI_VENDOR(rval));
2222 printf(" Subsystem ID: 0x%04x\n", PCI_PRODUCT(rval));
2223
2224 #ifdef _KERNEL
2225 pci_conf_print_bar(pc, tag, regs, 0x44, "legacy-mode registers",
2226 sizebars);
2227 #else
2228 pci_conf_print_bar(regs, 0x44, "legacy-mode registers");
2229 #endif
2230 }
2231
2232 void
2233 pci_conf_print(
2234 #ifdef _KERNEL
2235 pci_chipset_tag_t pc, pcitag_t tag,
2236 void (*printfn)(pci_chipset_tag_t, pcitag_t, const pcireg_t *)
2237 #else
2238 int pcifd, u_int bus, u_int dev, u_int func
2239 #endif
2240 )
2241 {
2242 pcireg_t regs[o2i(256)];
2243 int off, capoff, endoff, hdrtype;
2244 const char *typename;
2245 #ifdef _KERNEL
2246 void (*typeprintfn)(pci_chipset_tag_t, pcitag_t, const pcireg_t *, int);
2247 int sizebars;
2248 #else
2249 void (*typeprintfn)(const pcireg_t *);
2250 #endif
2251
2252 printf("PCI configuration registers:\n");
2253
2254 for (off = 0; off < 256; off += 4) {
2255 #ifdef _KERNEL
2256 regs[o2i(off)] = pci_conf_read(pc, tag, off);
2257 #else
2258 if (pcibus_conf_read(pcifd, bus, dev, func, off,
2259 ®s[o2i(off)]) == -1)
2260 regs[o2i(off)] = 0;
2261 #endif
2262 }
2263
2264 #ifdef _KERNEL
2265 sizebars = 1;
2266 if (PCI_CLASS(regs[o2i(PCI_CLASS_REG)]) == PCI_CLASS_BRIDGE &&
2267 PCI_SUBCLASS(regs[o2i(PCI_CLASS_REG)]) == PCI_SUBCLASS_BRIDGE_HOST)
2268 sizebars = 0;
2269 #endif
2270
2271 /* common header */
2272 printf(" Common header:\n");
2273 pci_conf_print_regs(regs, 0, 16);
2274
2275 printf("\n");
2276 #ifdef _KERNEL
2277 pci_conf_print_common(pc, tag, regs);
2278 #else
2279 pci_conf_print_common(regs);
2280 #endif
2281 printf("\n");
2282
2283 /* type-dependent header */
2284 hdrtype = PCI_HDRTYPE_TYPE(regs[o2i(PCI_BHLC_REG)]);
2285 switch (hdrtype) { /* XXX make a table, eventually */
2286 case 0:
2287 /* Standard device header */
2288 typename = "\"normal\" device";
2289 typeprintfn = &pci_conf_print_type0;
2290 capoff = PCI_CAPLISTPTR_REG;
2291 endoff = 64;
2292 break;
2293 case 1:
2294 /* PCI-PCI bridge header */
2295 typename = "PCI-PCI bridge";
2296 typeprintfn = &pci_conf_print_type1;
2297 capoff = PCI_CAPLISTPTR_REG;
2298 endoff = 64;
2299 break;
2300 case 2:
2301 /* PCI-CardBus bridge header */
2302 typename = "PCI-CardBus bridge";
2303 typeprintfn = &pci_conf_print_type2;
2304 capoff = PCI_CARDBUS_CAPLISTPTR_REG;
2305 endoff = 72;
2306 break;
2307 default:
2308 typename = NULL;
2309 typeprintfn = 0;
2310 capoff = -1;
2311 endoff = 64;
2312 break;
2313 }
2314 printf(" Type %d ", hdrtype);
2315 if (typename != NULL)
2316 printf("(%s) ", typename);
2317 printf("header:\n");
2318 pci_conf_print_regs(regs, 16, endoff);
2319 printf("\n");
2320 if (typeprintfn) {
2321 #ifdef _KERNEL
2322 (*typeprintfn)(pc, tag, regs, sizebars);
2323 #else
2324 (*typeprintfn)(regs);
2325 #endif
2326 } else
2327 printf(" Don't know how to pretty-print type %d header.\n",
2328 hdrtype);
2329 printf("\n");
2330
2331 /* capability list, if present */
2332 if ((regs[o2i(PCI_COMMAND_STATUS_REG)] & PCI_STATUS_CAPLIST_SUPPORT)
2333 && (capoff > 0)) {
2334 #ifdef _KERNEL
2335 pci_conf_print_caplist(pc, tag, regs, capoff);
2336 #else
2337 pci_conf_print_caplist(regs, capoff);
2338 #endif
2339 printf("\n");
2340 }
2341
2342 /* device-dependent header */
2343 printf(" Device-dependent header:\n");
2344 pci_conf_print_regs(regs, endoff, 256);
2345 printf("\n");
2346 #ifdef _KERNEL
2347 if (printfn)
2348 (*printfn)(pc, tag, regs);
2349 else
2350 printf(" Don't know how to pretty-print device-dependent header.\n");
2351 printf("\n");
2352 #endif /* _KERNEL */
2353 }
2354