Home | History | Annotate | Line # | Download | only in pci
pci_subr.c revision 1.24
      1  1.24   thorpej /*	$NetBSD: pci_subr.c,v 1.24 1998/05/03 19:41:33 thorpej Exp $	*/
      2   1.3       cgd 
      3   1.1   mycroft /*
      4  1.22   thorpej  * Copyright (c) 1997 Zubin D. Dittia.  All rights reserved.
      5  1.13       cgd  * Copyright (c) 1995, 1996 Christopher G. Demetriou.  All rights reserved.
      6   1.1   mycroft  * Copyright (c) 1994 Charles Hannum.  All rights reserved.
      7   1.1   mycroft  *
      8   1.1   mycroft  * Redistribution and use in source and binary forms, with or without
      9   1.1   mycroft  * modification, are permitted provided that the following conditions
     10   1.1   mycroft  * are met:
     11   1.1   mycroft  * 1. Redistributions of source code must retain the above copyright
     12   1.1   mycroft  *    notice, this list of conditions and the following disclaimer.
     13   1.1   mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     14   1.1   mycroft  *    notice, this list of conditions and the following disclaimer in the
     15   1.1   mycroft  *    documentation and/or other materials provided with the distribution.
     16   1.1   mycroft  * 3. All advertising materials mentioning features or use of this software
     17   1.1   mycroft  *    must display the following acknowledgement:
     18   1.1   mycroft  *	This product includes software developed by Charles Hannum.
     19   1.1   mycroft  * 4. The name of the author may not be used to endorse or promote products
     20   1.1   mycroft  *    derived from this software without specific prior written permission.
     21   1.1   mycroft  *
     22   1.1   mycroft  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23   1.1   mycroft  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24   1.1   mycroft  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25   1.1   mycroft  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26   1.1   mycroft  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27   1.1   mycroft  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28   1.1   mycroft  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29   1.1   mycroft  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30   1.1   mycroft  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31   1.1   mycroft  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32   1.1   mycroft  */
     33   1.1   mycroft 
     34   1.1   mycroft /*
     35  1.10       cgd  * PCI autoconfiguration support functions.
     36   1.1   mycroft  */
     37  1.21     enami 
     38  1.21     enami #include "opt_pciverbose.h"
     39   1.1   mycroft 
     40   1.1   mycroft #include <sys/param.h>
     41  1.10       cgd #include <sys/systm.h>
     42   1.1   mycroft #include <sys/device.h>
     43   1.1   mycroft 
     44  1.24   thorpej #include <machine/intr.h>
     45  1.24   thorpej 
     46  1.10       cgd #include <dev/pci/pcireg.h>
     47   1.7       cgd #include <dev/pci/pcivar.h>
     48  1.10       cgd #ifdef PCIVERBOSE
     49  1.10       cgd #include <dev/pci/pcidevs.h>
     50  1.10       cgd #endif
     51  1.10       cgd 
     52  1.10       cgd /*
     53  1.10       cgd  * Descriptions of known PCI classes and subclasses.
     54  1.10       cgd  *
     55  1.10       cgd  * Subclasses are described in the same way as classes, but have a
     56  1.10       cgd  * NULL subclass pointer.
     57  1.10       cgd  */
     58  1.10       cgd struct pci_class {
     59  1.10       cgd 	char		*name;
     60  1.10       cgd 	int		val;		/* as wide as pci_{,sub}class_t */
     61  1.10       cgd 	struct pci_class *subclasses;
     62  1.10       cgd };
     63  1.10       cgd 
     64  1.10       cgd struct pci_class pci_subclass_prehistoric[] = {
     65  1.10       cgd 	{ "miscellaneous",	PCI_SUBCLASS_PREHISTORIC_MISC,		},
     66  1.10       cgd 	{ "VGA",		PCI_SUBCLASS_PREHISTORIC_VGA,		},
     67  1.10       cgd 	{ 0 }
     68  1.10       cgd };
     69  1.10       cgd 
     70  1.10       cgd struct pci_class pci_subclass_mass_storage[] = {
     71  1.10       cgd 	{ "SCSI",		PCI_SUBCLASS_MASS_STORAGE_SCSI,		},
     72  1.10       cgd 	{ "IDE",		PCI_SUBCLASS_MASS_STORAGE_IDE,		},
     73  1.10       cgd 	{ "floppy",		PCI_SUBCLASS_MASS_STORAGE_FLOPPY,	},
     74  1.10       cgd 	{ "IPI",		PCI_SUBCLASS_MASS_STORAGE_IPI,		},
     75  1.20       cgd 	{ "RAID",		PCI_SUBCLASS_MASS_STORAGE_RAID,		},
     76  1.10       cgd 	{ "miscellaneous",	PCI_SUBCLASS_MASS_STORAGE_MISC,		},
     77  1.10       cgd 	{ 0 },
     78  1.10       cgd };
     79  1.10       cgd 
     80  1.10       cgd struct pci_class pci_subclass_network[] = {
     81  1.10       cgd 	{ "ethernet",		PCI_SUBCLASS_NETWORK_ETHERNET,		},
     82  1.10       cgd 	{ "token ring",		PCI_SUBCLASS_NETWORK_TOKENRING,		},
     83  1.10       cgd 	{ "FDDI",		PCI_SUBCLASS_NETWORK_FDDI,		},
     84  1.20       cgd 	{ "ATM",		PCI_SUBCLASS_NETWORK_ATM,		},
     85  1.10       cgd 	{ "miscellaneous",	PCI_SUBCLASS_NETWORK_MISC,		},
     86  1.10       cgd 	{ 0 },
     87  1.10       cgd };
     88  1.10       cgd 
     89  1.10       cgd struct pci_class pci_subclass_display[] = {
     90  1.10       cgd 	{ "VGA",		PCI_SUBCLASS_DISPLAY_VGA,		},
     91  1.10       cgd 	{ "XGA",		PCI_SUBCLASS_DISPLAY_XGA,		},
     92  1.10       cgd 	{ "miscellaneous",	PCI_SUBCLASS_DISPLAY_MISC,		},
     93  1.10       cgd 	{ 0 },
     94  1.10       cgd };
     95  1.10       cgd 
     96  1.10       cgd struct pci_class pci_subclass_multimedia[] = {
     97  1.10       cgd 	{ "video",		PCI_SUBCLASS_MULTIMEDIA_VIDEO,		},
     98  1.10       cgd 	{ "audio",		PCI_SUBCLASS_MULTIMEDIA_AUDIO,		},
     99  1.10       cgd 	{ "miscellaneous",	PCI_SUBCLASS_MULTIMEDIA_MISC,		},
    100  1.10       cgd 	{ 0 },
    101  1.10       cgd };
    102  1.10       cgd 
    103  1.10       cgd struct pci_class pci_subclass_memory[] = {
    104  1.10       cgd 	{ "RAM",		PCI_SUBCLASS_MEMORY_RAM,		},
    105  1.10       cgd 	{ "flash",		PCI_SUBCLASS_MEMORY_FLASH,		},
    106  1.10       cgd 	{ "miscellaneous",	PCI_SUBCLASS_MEMORY_MISC,		},
    107  1.10       cgd 	{ 0 },
    108  1.10       cgd };
    109  1.10       cgd 
    110  1.10       cgd struct pci_class pci_subclass_bridge[] = {
    111  1.10       cgd 	{ "host",		PCI_SUBCLASS_BRIDGE_HOST,		},
    112  1.10       cgd 	{ "ISA",		PCI_SUBCLASS_BRIDGE_ISA,		},
    113  1.10       cgd 	{ "EISA",		PCI_SUBCLASS_BRIDGE_EISA,		},
    114  1.10       cgd 	{ "MicroChannel",	PCI_SUBCLASS_BRIDGE_MC,			},
    115  1.10       cgd 	{ "PCI",		PCI_SUBCLASS_BRIDGE_PCI,		},
    116  1.10       cgd 	{ "PCMCIA",		PCI_SUBCLASS_BRIDGE_PCMCIA,		},
    117  1.20       cgd 	{ "NuBus",		PCI_SUBCLASS_BRIDGE_NUBUS,		},
    118  1.20       cgd 	{ "CardBus",		PCI_SUBCLASS_BRIDGE_CARDBUS,		},
    119  1.10       cgd 	{ "miscellaneous",	PCI_SUBCLASS_BRIDGE_MISC,		},
    120  1.10       cgd 	{ 0 },
    121  1.10       cgd };
    122  1.10       cgd 
    123  1.20       cgd struct pci_class pci_subclass_communications[] = {
    124  1.20       cgd 	{ "serial",		PCI_SUBCLASS_COMMUNICATIONS_SERIAL,	},
    125  1.20       cgd 	{ "parallel",		PCI_SUBCLASS_COMMUNICATIONS_PARALLEL,	},
    126  1.20       cgd 	{ "miscellaneous",	PCI_SUBCLASS_COMMUNICATIONS_MISC,	},
    127  1.20       cgd 	{ 0 },
    128  1.20       cgd };
    129  1.20       cgd 
    130  1.20       cgd struct pci_class pci_subclass_system[] = {
    131  1.20       cgd 	{ "8259 PIC",		PCI_SUBCLASS_SYSTEM_PIC,		},
    132  1.20       cgd 	{ "8237 DMA",		PCI_SUBCLASS_SYSTEM_DMA,		},
    133  1.20       cgd 	{ "8254 timer",		PCI_SUBCLASS_SYSTEM_TIMER,		},
    134  1.20       cgd 	{ "RTC",		PCI_SUBCLASS_SYSTEM_RTC,		},
    135  1.20       cgd 	{ "miscellaneous",	PCI_SUBCLASS_SYSTEM_MISC,		},
    136  1.20       cgd 	{ 0 },
    137  1.20       cgd };
    138  1.20       cgd 
    139  1.20       cgd struct pci_class pci_subclass_input[] = {
    140  1.20       cgd 	{ "keyboard",		PCI_SUBCLASS_INPUT_KEYBOARD,		},
    141  1.20       cgd 	{ "digitizer",		PCI_SUBCLASS_INPUT_DIGITIZER,		},
    142  1.20       cgd 	{ "mouse",		PCI_SUBCLASS_INPUT_MOUSE,		},
    143  1.20       cgd 	{ "miscellaneous",	PCI_SUBCLASS_INPUT_MISC,		},
    144  1.20       cgd 	{ 0 },
    145  1.20       cgd };
    146  1.20       cgd 
    147  1.20       cgd struct pci_class pci_subclass_dock[] = {
    148  1.20       cgd 	{ "generic",		PCI_SUBCLASS_DOCK_GENERIC,		},
    149  1.20       cgd 	{ "miscellaneous",	PCI_SUBCLASS_DOCK_MISC,			},
    150  1.20       cgd 	{ 0 },
    151  1.20       cgd };
    152  1.20       cgd 
    153  1.20       cgd struct pci_class pci_subclass_processor[] = {
    154  1.20       cgd 	{ "386",		PCI_SUBCLASS_PROCESSOR_386,		},
    155  1.20       cgd 	{ "486",		PCI_SUBCLASS_PROCESSOR_486,		},
    156  1.20       cgd 	{ "Pentium",		PCI_SUBCLASS_PROCESSOR_PENTIUM,		},
    157  1.20       cgd 	{ "Alpha",		PCI_SUBCLASS_PROCESSOR_ALPHA,		},
    158  1.20       cgd 	{ "PowerPC",		PCI_SUBCLASS_PROCESSOR_POWERPC,		},
    159  1.20       cgd 	{ "Co-processor",	PCI_SUBCLASS_PROCESSOR_COPROC,		},
    160  1.20       cgd 	{ 0 },
    161  1.20       cgd };
    162  1.20       cgd 
    163  1.20       cgd struct pci_class pci_subclass_serialbus[] = {
    164  1.20       cgd 	{ "Firewire",		PCI_SUBCLASS_SERIALBUS_FIREWIRE,	},
    165  1.20       cgd 	{ "ACCESS.bus",		PCI_SUBCLASS_SERIALBUS_ACCESS,		},
    166  1.20       cgd 	{ "SSA",		PCI_SUBCLASS_SERIALBUS_SSA,		},
    167  1.20       cgd 	{ "USB",		PCI_SUBCLASS_SERIALBUS_USB,		},
    168  1.20       cgd 	{ "Fiber Channel",	PCI_SUBCLASS_SERIALBUS_FIBER,		},
    169  1.20       cgd 	{ 0 },
    170  1.20       cgd };
    171  1.20       cgd 
    172  1.10       cgd struct pci_class pci_class[] = {
    173  1.10       cgd 	{ "prehistoric",	PCI_CLASS_PREHISTORIC,
    174  1.10       cgd 	    pci_subclass_prehistoric,				},
    175  1.10       cgd 	{ "mass storage",	PCI_CLASS_MASS_STORAGE,
    176  1.10       cgd 	    pci_subclass_mass_storage,				},
    177  1.10       cgd 	{ "network",		PCI_CLASS_NETWORK,
    178  1.10       cgd 	    pci_subclass_network,				},
    179  1.10       cgd 	{ "display",		PCI_CLASS_DISPLAY,
    180  1.11       cgd 	    pci_subclass_display,				},
    181  1.10       cgd 	{ "multimedia",		PCI_CLASS_MULTIMEDIA,
    182  1.10       cgd 	    pci_subclass_multimedia,				},
    183  1.10       cgd 	{ "memory",		PCI_CLASS_MEMORY,
    184  1.10       cgd 	    pci_subclass_memory,				},
    185  1.10       cgd 	{ "bridge",		PCI_CLASS_BRIDGE,
    186  1.10       cgd 	    pci_subclass_bridge,				},
    187  1.20       cgd 	{ "communications",	PCI_CLASS_COMMUNICATIONS,
    188  1.20       cgd 	    pci_subclass_communications,			},
    189  1.20       cgd 	{ "system",		PCI_CLASS_SYSTEM,
    190  1.20       cgd 	    pci_subclass_system,				},
    191  1.20       cgd 	{ "input",		PCI_CLASS_INPUT,
    192  1.20       cgd 	    pci_subclass_input,					},
    193  1.20       cgd 	{ "dock",		PCI_CLASS_DOCK,
    194  1.20       cgd 	    pci_subclass_dock,					},
    195  1.20       cgd 	{ "processor",		PCI_CLASS_PROCESSOR,
    196  1.20       cgd 	    pci_subclass_processor,				},
    197  1.20       cgd 	{ "serial bus",		PCI_CLASS_SERIALBUS,
    198  1.20       cgd 	    pci_subclass_serialbus,				},
    199  1.10       cgd 	{ "undefined",		PCI_CLASS_UNDEFINED,
    200  1.10       cgd 	    0,							},
    201  1.10       cgd 	{ 0 },
    202  1.10       cgd };
    203  1.10       cgd 
    204  1.10       cgd #ifdef PCIVERBOSE
    205  1.10       cgd /*
    206  1.10       cgd  * Descriptions of of known vendors and devices ("products").
    207  1.10       cgd  */
    208  1.10       cgd struct pci_knowndev {
    209  1.10       cgd 	pci_vendor_id_t		vendor;
    210  1.10       cgd 	pci_product_id_t	product;
    211  1.10       cgd 	int			flags;
    212  1.10       cgd 	char			*vendorname, *productname;
    213  1.10       cgd };
    214  1.13       cgd #define	PCI_KNOWNDEV_NOPROD	0x01		/* match on vendor only */
    215  1.10       cgd 
    216  1.10       cgd #include <dev/pci/pcidevs_data.h>
    217  1.10       cgd #endif /* PCIVERBOSE */
    218  1.10       cgd 
    219  1.10       cgd void
    220  1.13       cgd pci_devinfo(id_reg, class_reg, showclass, cp)
    221  1.10       cgd 	pcireg_t id_reg, class_reg;
    222  1.13       cgd 	int showclass;
    223  1.10       cgd 	char *cp;
    224  1.10       cgd {
    225  1.10       cgd 	pci_vendor_id_t vendor;
    226  1.10       cgd 	pci_product_id_t product;
    227  1.10       cgd 	pci_class_t class;
    228  1.10       cgd 	pci_subclass_t subclass;
    229  1.10       cgd 	pci_interface_t interface;
    230  1.10       cgd 	pci_revision_t revision;
    231  1.10       cgd 	char *vendor_namep, *product_namep;
    232  1.10       cgd 	struct pci_class *classp, *subclassp;
    233  1.10       cgd #ifdef PCIVERBOSE
    234  1.10       cgd 	struct pci_knowndev *kdp;
    235  1.16       cgd 	const char *unmatched = "unknown ";
    236  1.15       cgd #else
    237  1.16       cgd 	const char *unmatched = "";
    238  1.10       cgd #endif
    239  1.10       cgd 
    240  1.10       cgd 	vendor = PCI_VENDOR(id_reg);
    241  1.10       cgd 	product = PCI_PRODUCT(id_reg);
    242  1.10       cgd 
    243  1.10       cgd 	class = PCI_CLASS(class_reg);
    244  1.10       cgd 	subclass = PCI_SUBCLASS(class_reg);
    245  1.10       cgd 	interface = PCI_INTERFACE(class_reg);
    246  1.10       cgd 	revision = PCI_REVISION(class_reg);
    247  1.10       cgd 
    248  1.10       cgd #ifdef PCIVERBOSE
    249  1.10       cgd 	kdp = pci_knowndevs;
    250  1.10       cgd         while (kdp->vendorname != NULL) {	/* all have vendor name */
    251  1.10       cgd                 if (kdp->vendor == vendor && (kdp->product == product ||
    252  1.10       cgd 		    (kdp->flags & PCI_KNOWNDEV_NOPROD) != 0))
    253  1.10       cgd                         break;
    254  1.10       cgd 		kdp++;
    255  1.10       cgd 	}
    256  1.13       cgd         if (kdp->vendorname == NULL)
    257  1.10       cgd 		vendor_namep = product_namep = NULL;
    258  1.13       cgd 	else {
    259  1.10       cgd 		vendor_namep = kdp->vendorname;
    260  1.10       cgd 		product_namep = (kdp->flags & PCI_KNOWNDEV_NOPROD) == 0 ?
    261  1.10       cgd 		    kdp->productname : NULL;
    262  1.10       cgd         }
    263  1.10       cgd #else /* PCIVERBOSE */
    264  1.10       cgd 	vendor_namep = product_namep = NULL;
    265  1.10       cgd #endif /* PCIVERBOSE */
    266  1.10       cgd 
    267  1.10       cgd 	classp = pci_class;
    268  1.10       cgd 	while (classp->name != NULL) {
    269  1.10       cgd 		if (class == classp->val)
    270  1.10       cgd 			break;
    271  1.10       cgd 		classp++;
    272  1.10       cgd 	}
    273  1.10       cgd 
    274  1.10       cgd 	subclassp = (classp->name != NULL) ? classp->subclasses : NULL;
    275  1.10       cgd 	while (subclassp && subclassp->name != NULL) {
    276  1.10       cgd 		if (subclass == subclassp->val)
    277  1.10       cgd 			break;
    278  1.10       cgd 		subclassp++;
    279  1.10       cgd 	}
    280  1.10       cgd 
    281  1.10       cgd 	if (vendor_namep == NULL)
    282  1.19  christos 		cp += sprintf(cp, "%svendor 0x%04x product 0x%04x",
    283  1.15       cgd 		    unmatched, vendor, product);
    284  1.10       cgd 	else if (product_namep != NULL)
    285  1.19  christos 		cp += sprintf(cp, "%s %s", vendor_namep, product_namep);
    286  1.10       cgd 	else
    287  1.20       cgd 		cp += sprintf(cp, "%s product 0x%04x",
    288  1.10       cgd 		    vendor_namep, product);
    289  1.13       cgd 	if (showclass) {
    290  1.19  christos 		cp += sprintf(cp, " (");
    291  1.13       cgd 		if (classp->name == NULL)
    292  1.20       cgd 			cp += sprintf(cp, "class 0x%02x, subclass 0x%02x",
    293  1.13       cgd 			    class, subclass);
    294  1.13       cgd 		else {
    295  1.13       cgd 			if (subclassp == NULL || subclassp->name == NULL)
    296  1.20       cgd 				cp += sprintf(cp,
    297  1.20       cgd 				    "%s subclass 0x%02x",
    298  1.20       cgd 				    classp->name, subclass);
    299  1.13       cgd 			else
    300  1.20       cgd 				cp += sprintf(cp, "%s %s",
    301  1.20       cgd 				    subclassp->name, classp->name);
    302  1.13       cgd 		}
    303  1.20       cgd 		if (interface != 0)
    304  1.20       cgd 			cp += sprintf(cp, ", interface 0x%02x", interface);
    305  1.20       cgd 		if (revision != 0)
    306  1.20       cgd 			cp += sprintf(cp, ", revision 0x%02x", revision);
    307  1.20       cgd 		cp += sprintf(cp, ")");
    308  1.13       cgd 	}
    309  1.22   thorpej }
    310  1.22   thorpej 
    311  1.22   thorpej /*
    312  1.22   thorpej  * Print out most of the PCI configuration registers.  Typically used
    313  1.22   thorpej  * in a device attach routine like this:
    314  1.22   thorpej  *
    315  1.22   thorpej  *	#ifdef MYDEV_DEBUG
    316  1.22   thorpej  *		printf("%s: ", sc->sc_dev.dv_xname);
    317  1.22   thorpej  *		pci_conf_print(pa->pa_pc, pa->pa_tag);
    318  1.22   thorpej  *	#endif
    319  1.22   thorpej  */
    320  1.22   thorpej void
    321  1.22   thorpej pci_conf_print(pc, tag)
    322  1.22   thorpej 	pci_chipset_tag_t pc;
    323  1.22   thorpej 	pcitag_t tag;
    324  1.22   thorpej {
    325  1.24   thorpej 	pcireg_t rval, mask;
    326  1.24   thorpej 	int reg, s;
    327  1.22   thorpej #ifdef PCIVERBOSE
    328  1.22   thorpej 	struct pci_knowndev *kdp;
    329  1.23  drochner 	static const char on_str[] = "ON", off_str[] = "OFF";
    330  1.22   thorpej #endif
    331  1.22   thorpej 	struct pci_class *classp, *subclassp;
    332  1.22   thorpej 
    333  1.22   thorpej 	printf("PCI configuration registers:\n");
    334  1.22   thorpej 
    335  1.22   thorpej 	rval = pci_conf_read(pc, tag, PCI_ID_REG);
    336  1.22   thorpej 
    337  1.22   thorpej #ifndef PCIVERBOSE
    338  1.22   thorpej 	printf("  Vendor ID: 0x%04x\n", PCI_VENDOR(rval));
    339  1.22   thorpej 	printf("  Device ID: 0x%04x\n", PCI_PRODUCT(rval));
    340  1.22   thorpej #else
    341  1.22   thorpej 	for (kdp = pci_knowndevs; kdp->vendorname != NULL; kdp++) {
    342  1.22   thorpej 		if (kdp->vendor == PCI_VENDOR(rval) &&
    343  1.22   thorpej 		    (kdp->product == PCI_PRODUCT(rval) ||
    344  1.22   thorpej 		    (kdp->flags & PCI_KNOWNDEV_NOPROD) != 0)) {
    345  1.22   thorpej 			break;
    346  1.22   thorpej 		}
    347  1.22   thorpej 	}
    348  1.22   thorpej 	if (kdp->vendorname != NULL)
    349  1.22   thorpej 		printf("  Vendor Name: %s\n", kdp->vendorname);
    350  1.22   thorpej 	else
    351  1.22   thorpej 		printf("  Vendor ID: 0x%04x\n", PCI_VENDOR(rval));
    352  1.22   thorpej 
    353  1.22   thorpej 	if (kdp->productname != NULL && (kdp->flags & PCI_KNOWNDEV_NOPROD) == 0)
    354  1.22   thorpej 		printf("  Device Name: %s\n", kdp->productname);
    355  1.22   thorpej 	else
    356  1.22   thorpej 		printf("  Device ID: 0x%04x\n", PCI_PRODUCT(rval));
    357  1.22   thorpej #endif /* PCIVERBOSE */
    358  1.22   thorpej 
    359  1.22   thorpej 	rval = pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG);
    360  1.22   thorpej 
    361  1.22   thorpej #ifndef PCIVERBOSE
    362  1.22   thorpej 	printf("  Command/Status Register: 0x%08x\n", rval);
    363  1.22   thorpej #else
    364  1.23  drochner 
    365  1.23  drochner #define	onoff(reg)	((rval & (reg)) ? on_str : off_str)
    366  1.22   thorpej 	printf("  Command Register:\n");
    367  1.22   thorpej 	printf("    I/O space accesses %s\n", onoff(PCI_COMMAND_IO_ENABLE));
    368  1.22   thorpej 	printf("    Mem space accesses %s\n", onoff(PCI_COMMAND_MEM_ENABLE));
    369  1.22   thorpej 	printf("    Bus mastering %s\n", onoff(PCI_COMMAND_MASTER_ENABLE));
    370  1.22   thorpej 	printf("    Special cycles %s\n", onoff(PCI_COMMAND_SPECIAL_ENABLE));
    371  1.22   thorpej 	printf("    MWI transactions %s\n",
    372  1.22   thorpej 	    onoff(PCI_COMMAND_INVALIDATE_ENABLE));
    373  1.22   thorpej 	printf("    Palette snooping %s\n", onoff(PCI_COMMAND_PALETTE_ENABLE));
    374  1.22   thorpej 	printf("    Parity error checking %s\n",
    375  1.22   thorpej 	    onoff(PCI_COMMAND_PARITY_ENABLE));
    376  1.22   thorpej 	printf("    Address/Data stepping %s\n",
    377  1.22   thorpej 	    onoff(PCI_COMMAND_STEPPING_ENABLE));
    378  1.22   thorpej 	printf("    System Error (SERR) %s\n", onoff(PCI_COMMAND_SERR_ENABLE));
    379  1.22   thorpej 	printf("    Fast back-to-back transactions %s\n",
    380  1.22   thorpej 	    onoff(PCI_COMMAND_BACKTOBACK_ENABLE));
    381  1.22   thorpej 	printf("  Status Register:\n");
    382  1.22   thorpej 	printf("    66 MHz capable %s\n", onoff(PCI_STATUS_66MHZ_SUPPORT));
    383  1.22   thorpej 	printf("    User Definable Features (UDF) support %s\n",
    384  1.22   thorpej 	    onoff(PCI_STATUS_UDF_SUPPORT));
    385  1.22   thorpej 	printf("    Fast back-to-back capable %s\n",
    386  1.22   thorpej 	    onoff(PCI_STATUS_BACKTOBACK_SUPPORT));
    387  1.22   thorpej 	printf("    Data parity error detected %s\n",
    388  1.22   thorpej 	    onoff(PCI_STATUS_PARITY_ERROR));
    389  1.22   thorpej 
    390  1.22   thorpej 	printf("    DEVSEL timing ");
    391  1.22   thorpej 	switch (rval & PCI_STATUS_DEVSEL_MASK) {
    392  1.22   thorpej 	case PCI_STATUS_DEVSEL_FAST:
    393  1.22   thorpej 		printf("fast");
    394  1.22   thorpej 		break;
    395  1.22   thorpej 	case PCI_STATUS_DEVSEL_MEDIUM:
    396  1.22   thorpej 		printf("medium");
    397  1.22   thorpej 		break;
    398  1.22   thorpej 	case PCI_STATUS_DEVSEL_SLOW:
    399  1.22   thorpej 		printf("slow");
    400  1.22   thorpej 		break;
    401  1.22   thorpej 	}
    402  1.22   thorpej 	printf("\n");
    403  1.22   thorpej 
    404  1.22   thorpej 	printf("    Slave signaled Target Abort %s\n",
    405  1.22   thorpej 	    onoff(PCI_STATUS_TARGET_TARGET_ABORT));
    406  1.22   thorpej 	printf("    Master received Target Abort %s\n",
    407  1.22   thorpej 	    onoff(PCI_STATUS_MASTER_TARGET_ABORT));
    408  1.22   thorpej 	printf("    Master received Master Abort %s\n",
    409  1.22   thorpej 	    onoff(PCI_STATUS_MASTER_ABORT));
    410  1.22   thorpej 	printf("    Asserted System Error (SERR) %s\n",
    411  1.22   thorpej 	    onoff(PCI_STATUS_SPECIAL_ERROR));
    412  1.22   thorpej 	printf("    Parity error detected %s\n",
    413  1.22   thorpej 	    onoff(PCI_STATUS_PARITY_DETECT));
    414  1.22   thorpej #endif /* PCIVERBOSE */
    415  1.22   thorpej 
    416  1.22   thorpej 	rval = pci_conf_read(pc, tag, PCI_CLASS_REG);
    417  1.22   thorpej 
    418  1.22   thorpej 	for (classp = pci_class; classp->name != NULL; classp++) {
    419  1.22   thorpej 		if (PCI_CLASS(rval) == classp->val)
    420  1.22   thorpej 			break;
    421  1.22   thorpej 	}
    422  1.22   thorpej 	subclassp = (classp->name != NULL) ? classp->subclasses : NULL;
    423  1.22   thorpej 	while (subclassp && subclassp->name != NULL) {
    424  1.22   thorpej 		if (PCI_SUBCLASS(rval) == subclassp->val)
    425  1.22   thorpej 			break;
    426  1.22   thorpej 		subclassp++;
    427  1.22   thorpej 	}
    428  1.22   thorpej 	if (classp->name != NULL) {
    429  1.22   thorpej 		printf("  Class Name: %s\n", classp->name);
    430  1.22   thorpej 		if (subclassp != NULL && subclassp->name != NULL)
    431  1.22   thorpej 			printf("  Subclass Name: %s\n", subclassp->name);
    432  1.22   thorpej 		else
    433  1.22   thorpej 			printf("  Subclass ID: 0x%02x\n", PCI_SUBCLASS(rval));
    434  1.22   thorpej 	} else {
    435  1.22   thorpej 		printf("  Class ID: 0x%02x\n", PCI_CLASS(rval));
    436  1.22   thorpej 		printf("  Subclass ID: 0x%02x\n", PCI_SUBCLASS(rval));
    437  1.22   thorpej 	}
    438  1.22   thorpej 	printf("  Interface: 0x%02x\n", PCI_INTERFACE(rval));
    439  1.22   thorpej 	printf("  Revision ID: 0x%02x\n", PCI_REVISION(rval));
    440  1.22   thorpej 
    441  1.22   thorpej 	rval = pci_conf_read(pc, tag, PCI_BHLC_REG);
    442  1.22   thorpej 
    443  1.22   thorpej 	printf("  BIST: 0x%02x\n", PCI_BIST(rval));
    444  1.22   thorpej 	printf("  Header Type: 0x%02x\n", PCI_HDRTYPE(rval));
    445  1.22   thorpej 	printf("  Latency Timer: 0x%02x\n", PCI_LATTIMER(rval));
    446  1.22   thorpej 	printf("  Cache Line Size: 0x%02x\n", PCI_CACHELINE(rval));
    447  1.22   thorpej 
    448  1.22   thorpej 	for (reg = PCI_MAPREG_START; reg < PCI_MAPREG_END; reg += 4) {
    449  1.24   thorpej 		/*
    450  1.24   thorpej 		 * Section 6.2.5.1, `Address Maps', tells us that:
    451  1.24   thorpej 		 *
    452  1.24   thorpej 		 * 1) The builtin software should have already mapped the
    453  1.24   thorpej 		 * device in a reasonable way.
    454  1.24   thorpej 		 *
    455  1.24   thorpej 		 * 2) A device which wants 2^n bytes of memory will hardwire
    456  1.24   thorpej 		 * the bottom n bits of the address to 0.  As recommended,
    457  1.24   thorpej 		 * we write all 1s and see what we get back.
    458  1.24   thorpej 		 */
    459  1.24   thorpej 		s = splhigh();
    460  1.22   thorpej 		rval = pci_conf_read(pc, tag, reg);
    461  1.24   thorpej 		pci_conf_write(pc, tag, reg, 0xffffffff);
    462  1.24   thorpej 		mask = pci_conf_read(pc, tag, reg);
    463  1.24   thorpej 		pci_conf_write(pc, tag, reg, rval);
    464  1.24   thorpej 		splx(s);
    465  1.24   thorpej 
    466  1.22   thorpej 		printf("  Mapping register 0x%02x\n", reg);
    467  1.22   thorpej 		if (PCI_MAPREG_TYPE(rval) == PCI_MAPREG_TYPE_MEM) {
    468  1.22   thorpej 			printf("    Base Address: 0x%08x, size 0x%08x, "
    469  1.22   thorpej 			    "type = mem", PCI_MAPREG_MEM_ADDR(rval),
    470  1.24   thorpej 			    PCI_MAPREG_MEM_SIZE(mask));
    471  1.22   thorpej 			switch (PCI_MAPREG_MEM_TYPE(rval)) {
    472  1.22   thorpej 			case PCI_MAPREG_MEM_TYPE_32BIT:
    473  1.22   thorpej 				printf(", 32-bit");
    474  1.22   thorpej 				break;
    475  1.22   thorpej 			case PCI_MAPREG_MEM_TYPE_32BIT_1M:
    476  1.22   thorpej 				printf(", 32-bit-1M");
    477  1.22   thorpej 				break;
    478  1.22   thorpej 			case PCI_MAPREG_MEM_TYPE_64BIT:
    479  1.22   thorpej 				printf(", 64-bit");
    480  1.22   thorpej 				break;
    481  1.22   thorpej 			}
    482  1.22   thorpej 			if (PCI_MAPREG_MEM_CACHEABLE(rval))
    483  1.22   thorpej 				printf(", cacheable");
    484  1.22   thorpej 			else
    485  1.22   thorpej 				printf(", not cacheable");
    486  1.22   thorpej 			printf("\n");
    487  1.22   thorpej 		} else {
    488  1.22   thorpej 			printf("    Base Address: 0x%08x, size 0x%08x, "
    489  1.22   thorpej 			    "type = i/o\n", PCI_MAPREG_IO_ADDR(rval),
    490  1.24   thorpej 			    PCI_MAPREG_IO_SIZE(mask));
    491  1.22   thorpej 		}
    492  1.22   thorpej 	}
    493  1.22   thorpej 
    494  1.22   thorpej 	rval = pci_conf_read(pc, tag, PCI_INTERRUPT_REG);
    495  1.22   thorpej 
    496  1.22   thorpej 	printf("  Maximum Latency: 0x%08x\n", (rval >> 24) & 0xff);
    497  1.22   thorpej 	printf("  Minimum Grant: 0x%08x\n", (rval >> 16) & 0xff);
    498  1.22   thorpej 	printf("  Interrupt pin: 0x%08x", PCI_INTERRUPT_PIN(rval));
    499  1.22   thorpej 	switch (PCI_INTERRUPT_PIN(rval)) {
    500  1.22   thorpej 	case PCI_INTERRUPT_PIN_NONE:
    501  1.22   thorpej 		printf(" (none)");
    502  1.22   thorpej 		break;
    503  1.22   thorpej 	case PCI_INTERRUPT_PIN_A:
    504  1.22   thorpej 		printf(" (pin A)");
    505  1.22   thorpej 		break;
    506  1.22   thorpej 	case PCI_INTERRUPT_PIN_B:
    507  1.22   thorpej 		printf(" (pin B)");
    508  1.22   thorpej 		break;
    509  1.22   thorpej 	case PCI_INTERRUPT_PIN_C:
    510  1.22   thorpej 		printf(" (pin C)");
    511  1.22   thorpej 		break;
    512  1.22   thorpej 	case PCI_INTERRUPT_PIN_D:
    513  1.22   thorpej 		printf(" (pin D)");
    514  1.22   thorpej 		break;
    515  1.22   thorpej 	}
    516  1.22   thorpej 	printf("\n");
    517  1.22   thorpej 	printf("  Interrupt line: 0x%08x\n", PCI_INTERRUPT_LINE(rval));
    518   1.1   mycroft }
    519