Home | History | Annotate | Line # | Download | only in pci
pci_subr.c revision 1.20
      1  1.20       cgd /*	$NetBSD: pci_subr.c,v 1.20 1997/03/19 19:38:46 cgd Exp $	*/
      2   1.3       cgd 
      3   1.1   mycroft /*
      4  1.13       cgd  * Copyright (c) 1995, 1996 Christopher G. Demetriou.  All rights reserved.
      5   1.1   mycroft  * Copyright (c) 1994 Charles Hannum.  All rights reserved.
      6   1.1   mycroft  *
      7   1.1   mycroft  * Redistribution and use in source and binary forms, with or without
      8   1.1   mycroft  * modification, are permitted provided that the following conditions
      9   1.1   mycroft  * are met:
     10   1.1   mycroft  * 1. Redistributions of source code must retain the above copyright
     11   1.1   mycroft  *    notice, this list of conditions and the following disclaimer.
     12   1.1   mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1   mycroft  *    notice, this list of conditions and the following disclaimer in the
     14   1.1   mycroft  *    documentation and/or other materials provided with the distribution.
     15   1.1   mycroft  * 3. All advertising materials mentioning features or use of this software
     16   1.1   mycroft  *    must display the following acknowledgement:
     17   1.1   mycroft  *	This product includes software developed by Charles Hannum.
     18   1.1   mycroft  * 4. The name of the author may not be used to endorse or promote products
     19   1.1   mycroft  *    derived from this software without specific prior written permission.
     20   1.1   mycroft  *
     21   1.1   mycroft  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22   1.1   mycroft  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23   1.1   mycroft  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24   1.1   mycroft  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25   1.1   mycroft  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26   1.1   mycroft  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27   1.1   mycroft  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28   1.1   mycroft  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29   1.1   mycroft  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30   1.1   mycroft  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31   1.1   mycroft  */
     32   1.1   mycroft 
     33   1.1   mycroft /*
     34  1.10       cgd  * PCI autoconfiguration support functions.
     35   1.1   mycroft  */
     36   1.1   mycroft 
     37   1.1   mycroft #include <sys/param.h>
     38  1.10       cgd #include <sys/systm.h>
     39   1.1   mycroft #include <sys/device.h>
     40   1.1   mycroft 
     41  1.10       cgd #include <dev/pci/pcireg.h>
     42   1.7       cgd #include <dev/pci/pcivar.h>
     43  1.10       cgd #ifdef PCIVERBOSE
     44  1.10       cgd #include <dev/pci/pcidevs.h>
     45  1.10       cgd #endif
     46  1.10       cgd 
     47  1.10       cgd /*
     48  1.10       cgd  * Descriptions of known PCI classes and subclasses.
     49  1.10       cgd  *
     50  1.10       cgd  * Subclasses are described in the same way as classes, but have a
     51  1.10       cgd  * NULL subclass pointer.
     52  1.10       cgd  */
     53  1.10       cgd struct pci_class {
     54  1.10       cgd 	char		*name;
     55  1.10       cgd 	int		val;		/* as wide as pci_{,sub}class_t */
     56  1.10       cgd 	struct pci_class *subclasses;
     57  1.10       cgd };
     58  1.10       cgd 
     59  1.10       cgd struct pci_class pci_subclass_prehistoric[] = {
     60  1.10       cgd 	{ "miscellaneous",	PCI_SUBCLASS_PREHISTORIC_MISC,		},
     61  1.10       cgd 	{ "VGA",		PCI_SUBCLASS_PREHISTORIC_VGA,		},
     62  1.10       cgd 	{ 0 }
     63  1.10       cgd };
     64  1.10       cgd 
     65  1.10       cgd struct pci_class pci_subclass_mass_storage[] = {
     66  1.10       cgd 	{ "SCSI",		PCI_SUBCLASS_MASS_STORAGE_SCSI,		},
     67  1.10       cgd 	{ "IDE",		PCI_SUBCLASS_MASS_STORAGE_IDE,		},
     68  1.10       cgd 	{ "floppy",		PCI_SUBCLASS_MASS_STORAGE_FLOPPY,	},
     69  1.10       cgd 	{ "IPI",		PCI_SUBCLASS_MASS_STORAGE_IPI,		},
     70  1.20       cgd 	{ "RAID",		PCI_SUBCLASS_MASS_STORAGE_RAID,		},
     71  1.10       cgd 	{ "miscellaneous",	PCI_SUBCLASS_MASS_STORAGE_MISC,		},
     72  1.10       cgd 	{ 0 },
     73  1.10       cgd };
     74  1.10       cgd 
     75  1.10       cgd struct pci_class pci_subclass_network[] = {
     76  1.10       cgd 	{ "ethernet",		PCI_SUBCLASS_NETWORK_ETHERNET,		},
     77  1.10       cgd 	{ "token ring",		PCI_SUBCLASS_NETWORK_TOKENRING,		},
     78  1.10       cgd 	{ "FDDI",		PCI_SUBCLASS_NETWORK_FDDI,		},
     79  1.20       cgd 	{ "ATM",		PCI_SUBCLASS_NETWORK_ATM,		},
     80  1.10       cgd 	{ "miscellaneous",	PCI_SUBCLASS_NETWORK_MISC,		},
     81  1.10       cgd 	{ 0 },
     82  1.10       cgd };
     83  1.10       cgd 
     84  1.10       cgd struct pci_class pci_subclass_display[] = {
     85  1.10       cgd 	{ "VGA",		PCI_SUBCLASS_DISPLAY_VGA,		},
     86  1.10       cgd 	{ "XGA",		PCI_SUBCLASS_DISPLAY_XGA,		},
     87  1.10       cgd 	{ "miscellaneous",	PCI_SUBCLASS_DISPLAY_MISC,		},
     88  1.10       cgd 	{ 0 },
     89  1.10       cgd };
     90  1.10       cgd 
     91  1.10       cgd struct pci_class pci_subclass_multimedia[] = {
     92  1.10       cgd 	{ "video",		PCI_SUBCLASS_MULTIMEDIA_VIDEO,		},
     93  1.10       cgd 	{ "audio",		PCI_SUBCLASS_MULTIMEDIA_AUDIO,		},
     94  1.10       cgd 	{ "miscellaneous",	PCI_SUBCLASS_MULTIMEDIA_MISC,		},
     95  1.10       cgd 	{ 0 },
     96  1.10       cgd };
     97  1.10       cgd 
     98  1.10       cgd struct pci_class pci_subclass_memory[] = {
     99  1.10       cgd 	{ "RAM",		PCI_SUBCLASS_MEMORY_RAM,		},
    100  1.10       cgd 	{ "flash",		PCI_SUBCLASS_MEMORY_FLASH,		},
    101  1.10       cgd 	{ "miscellaneous",	PCI_SUBCLASS_MEMORY_MISC,		},
    102  1.10       cgd 	{ 0 },
    103  1.10       cgd };
    104  1.10       cgd 
    105  1.10       cgd struct pci_class pci_subclass_bridge[] = {
    106  1.10       cgd 	{ "host",		PCI_SUBCLASS_BRIDGE_HOST,		},
    107  1.10       cgd 	{ "ISA",		PCI_SUBCLASS_BRIDGE_ISA,		},
    108  1.10       cgd 	{ "EISA",		PCI_SUBCLASS_BRIDGE_EISA,		},
    109  1.10       cgd 	{ "MicroChannel",	PCI_SUBCLASS_BRIDGE_MC,			},
    110  1.10       cgd 	{ "PCI",		PCI_SUBCLASS_BRIDGE_PCI,		},
    111  1.10       cgd 	{ "PCMCIA",		PCI_SUBCLASS_BRIDGE_PCMCIA,		},
    112  1.20       cgd 	{ "NuBus",		PCI_SUBCLASS_BRIDGE_NUBUS,		},
    113  1.20       cgd 	{ "CardBus",		PCI_SUBCLASS_BRIDGE_CARDBUS,		},
    114  1.10       cgd 	{ "miscellaneous",	PCI_SUBCLASS_BRIDGE_MISC,		},
    115  1.10       cgd 	{ 0 },
    116  1.10       cgd };
    117  1.10       cgd 
    118  1.20       cgd struct pci_class pci_subclass_communications[] = {
    119  1.20       cgd 	{ "serial",		PCI_SUBCLASS_COMMUNICATIONS_SERIAL,	},
    120  1.20       cgd 	{ "parallel",		PCI_SUBCLASS_COMMUNICATIONS_PARALLEL,	},
    121  1.20       cgd 	{ "miscellaneous",	PCI_SUBCLASS_COMMUNICATIONS_MISC,	},
    122  1.20       cgd 	{ 0 },
    123  1.20       cgd };
    124  1.20       cgd 
    125  1.20       cgd struct pci_class pci_subclass_system[] = {
    126  1.20       cgd 	{ "8259 PIC",		PCI_SUBCLASS_SYSTEM_PIC,		},
    127  1.20       cgd 	{ "8237 DMA",		PCI_SUBCLASS_SYSTEM_DMA,		},
    128  1.20       cgd 	{ "8254 timer",		PCI_SUBCLASS_SYSTEM_TIMER,		},
    129  1.20       cgd 	{ "RTC",		PCI_SUBCLASS_SYSTEM_RTC,		},
    130  1.20       cgd 	{ "miscellaneous",	PCI_SUBCLASS_SYSTEM_MISC,		},
    131  1.20       cgd 	{ 0 },
    132  1.20       cgd };
    133  1.20       cgd 
    134  1.20       cgd struct pci_class pci_subclass_input[] = {
    135  1.20       cgd 	{ "keyboard",		PCI_SUBCLASS_INPUT_KEYBOARD,		},
    136  1.20       cgd 	{ "digitizer",		PCI_SUBCLASS_INPUT_DIGITIZER,		},
    137  1.20       cgd 	{ "mouse",		PCI_SUBCLASS_INPUT_MOUSE,		},
    138  1.20       cgd 	{ "miscellaneous",	PCI_SUBCLASS_INPUT_MISC,		},
    139  1.20       cgd 	{ 0 },
    140  1.20       cgd };
    141  1.20       cgd 
    142  1.20       cgd struct pci_class pci_subclass_dock[] = {
    143  1.20       cgd 	{ "generic",		PCI_SUBCLASS_DOCK_GENERIC,		},
    144  1.20       cgd 	{ "miscellaneous",	PCI_SUBCLASS_DOCK_MISC,			},
    145  1.20       cgd 	{ 0 },
    146  1.20       cgd };
    147  1.20       cgd 
    148  1.20       cgd struct pci_class pci_subclass_processor[] = {
    149  1.20       cgd 	{ "386",		PCI_SUBCLASS_PROCESSOR_386,		},
    150  1.20       cgd 	{ "486",		PCI_SUBCLASS_PROCESSOR_486,		},
    151  1.20       cgd 	{ "Pentium",		PCI_SUBCLASS_PROCESSOR_PENTIUM,		},
    152  1.20       cgd 	{ "Alpha",		PCI_SUBCLASS_PROCESSOR_ALPHA,		},
    153  1.20       cgd 	{ "PowerPC",		PCI_SUBCLASS_PROCESSOR_POWERPC,		},
    154  1.20       cgd 	{ "Co-processor",	PCI_SUBCLASS_PROCESSOR_COPROC,		},
    155  1.20       cgd 	{ 0 },
    156  1.20       cgd };
    157  1.20       cgd 
    158  1.20       cgd struct pci_class pci_subclass_serialbus[] = {
    159  1.20       cgd 	{ "Firewire",		PCI_SUBCLASS_SERIALBUS_FIREWIRE,	},
    160  1.20       cgd 	{ "ACCESS.bus",		PCI_SUBCLASS_SERIALBUS_ACCESS,		},
    161  1.20       cgd 	{ "SSA",		PCI_SUBCLASS_SERIALBUS_SSA,		},
    162  1.20       cgd 	{ "USB",		PCI_SUBCLASS_SERIALBUS_USB,		},
    163  1.20       cgd 	{ "Fiber Channel",	PCI_SUBCLASS_SERIALBUS_FIBER,		},
    164  1.20       cgd 	{ 0 },
    165  1.20       cgd };
    166  1.20       cgd 
    167  1.10       cgd struct pci_class pci_class[] = {
    168  1.10       cgd 	{ "prehistoric",	PCI_CLASS_PREHISTORIC,
    169  1.10       cgd 	    pci_subclass_prehistoric,				},
    170  1.10       cgd 	{ "mass storage",	PCI_CLASS_MASS_STORAGE,
    171  1.10       cgd 	    pci_subclass_mass_storage,				},
    172  1.10       cgd 	{ "network",		PCI_CLASS_NETWORK,
    173  1.10       cgd 	    pci_subclass_network,				},
    174  1.10       cgd 	{ "display",		PCI_CLASS_DISPLAY,
    175  1.11       cgd 	    pci_subclass_display,				},
    176  1.10       cgd 	{ "multimedia",		PCI_CLASS_MULTIMEDIA,
    177  1.10       cgd 	    pci_subclass_multimedia,				},
    178  1.10       cgd 	{ "memory",		PCI_CLASS_MEMORY,
    179  1.10       cgd 	    pci_subclass_memory,				},
    180  1.10       cgd 	{ "bridge",		PCI_CLASS_BRIDGE,
    181  1.10       cgd 	    pci_subclass_bridge,				},
    182  1.20       cgd 	{ "communications",	PCI_CLASS_COMMUNICATIONS,
    183  1.20       cgd 	    pci_subclass_communications,			},
    184  1.20       cgd 	{ "system",		PCI_CLASS_SYSTEM,
    185  1.20       cgd 	    pci_subclass_system,				},
    186  1.20       cgd 	{ "input",		PCI_CLASS_INPUT,
    187  1.20       cgd 	    pci_subclass_input,					},
    188  1.20       cgd 	{ "dock",		PCI_CLASS_DOCK,
    189  1.20       cgd 	    pci_subclass_dock,					},
    190  1.20       cgd 	{ "processor",		PCI_CLASS_PROCESSOR,
    191  1.20       cgd 	    pci_subclass_processor,				},
    192  1.20       cgd 	{ "serial bus",		PCI_CLASS_SERIALBUS,
    193  1.20       cgd 	    pci_subclass_serialbus,				},
    194  1.10       cgd 	{ "undefined",		PCI_CLASS_UNDEFINED,
    195  1.10       cgd 	    0,							},
    196  1.10       cgd 	{ 0 },
    197  1.10       cgd };
    198  1.10       cgd 
    199  1.10       cgd #ifdef PCIVERBOSE
    200  1.10       cgd /*
    201  1.10       cgd  * Descriptions of of known vendors and devices ("products").
    202  1.10       cgd  */
    203  1.10       cgd struct pci_knowndev {
    204  1.10       cgd 	pci_vendor_id_t		vendor;
    205  1.10       cgd 	pci_product_id_t	product;
    206  1.10       cgd 	int			flags;
    207  1.10       cgd 	char			*vendorname, *productname;
    208  1.10       cgd };
    209  1.13       cgd #define	PCI_KNOWNDEV_NOPROD	0x01		/* match on vendor only */
    210  1.10       cgd 
    211  1.10       cgd #include <dev/pci/pcidevs_data.h>
    212  1.10       cgd #endif /* PCIVERBOSE */
    213  1.10       cgd 
    214  1.10       cgd void
    215  1.13       cgd pci_devinfo(id_reg, class_reg, showclass, cp)
    216  1.10       cgd 	pcireg_t id_reg, class_reg;
    217  1.13       cgd 	int showclass;
    218  1.10       cgd 	char *cp;
    219  1.10       cgd {
    220  1.10       cgd 	pci_vendor_id_t vendor;
    221  1.10       cgd 	pci_product_id_t product;
    222  1.10       cgd 	pci_class_t class;
    223  1.10       cgd 	pci_subclass_t subclass;
    224  1.10       cgd 	pci_interface_t interface;
    225  1.10       cgd 	pci_revision_t revision;
    226  1.10       cgd 	char *vendor_namep, *product_namep;
    227  1.10       cgd 	struct pci_class *classp, *subclassp;
    228  1.10       cgd #ifdef PCIVERBOSE
    229  1.10       cgd 	struct pci_knowndev *kdp;
    230  1.16       cgd 	const char *unmatched = "unknown ";
    231  1.15       cgd #else
    232  1.16       cgd 	const char *unmatched = "";
    233  1.10       cgd #endif
    234  1.10       cgd 
    235  1.10       cgd 	vendor = PCI_VENDOR(id_reg);
    236  1.10       cgd 	product = PCI_PRODUCT(id_reg);
    237  1.10       cgd 
    238  1.10       cgd 	class = PCI_CLASS(class_reg);
    239  1.10       cgd 	subclass = PCI_SUBCLASS(class_reg);
    240  1.10       cgd 	interface = PCI_INTERFACE(class_reg);
    241  1.10       cgd 	revision = PCI_REVISION(class_reg);
    242  1.10       cgd 
    243  1.10       cgd #ifdef PCIVERBOSE
    244  1.10       cgd 	kdp = pci_knowndevs;
    245  1.10       cgd         while (kdp->vendorname != NULL) {	/* all have vendor name */
    246  1.10       cgd                 if (kdp->vendor == vendor && (kdp->product == product ||
    247  1.10       cgd 		    (kdp->flags & PCI_KNOWNDEV_NOPROD) != 0))
    248  1.10       cgd                         break;
    249  1.10       cgd 		kdp++;
    250  1.10       cgd 	}
    251  1.13       cgd         if (kdp->vendorname == NULL)
    252  1.10       cgd 		vendor_namep = product_namep = NULL;
    253  1.13       cgd 	else {
    254  1.10       cgd 		vendor_namep = kdp->vendorname;
    255  1.10       cgd 		product_namep = (kdp->flags & PCI_KNOWNDEV_NOPROD) == 0 ?
    256  1.10       cgd 		    kdp->productname : NULL;
    257  1.10       cgd         }
    258  1.10       cgd #else /* PCIVERBOSE */
    259  1.10       cgd 	vendor_namep = product_namep = NULL;
    260  1.10       cgd #endif /* PCIVERBOSE */
    261  1.10       cgd 
    262  1.10       cgd 	classp = pci_class;
    263  1.10       cgd 	while (classp->name != NULL) {
    264  1.10       cgd 		if (class == classp->val)
    265  1.10       cgd 			break;
    266  1.10       cgd 		classp++;
    267  1.10       cgd 	}
    268  1.10       cgd 
    269  1.10       cgd 	subclassp = (classp->name != NULL) ? classp->subclasses : NULL;
    270  1.10       cgd 	while (subclassp && subclassp->name != NULL) {
    271  1.10       cgd 		if (subclass == subclassp->val)
    272  1.10       cgd 			break;
    273  1.10       cgd 		subclassp++;
    274  1.10       cgd 	}
    275  1.10       cgd 
    276  1.10       cgd 	if (vendor_namep == NULL)
    277  1.19  christos 		cp += sprintf(cp, "%svendor 0x%04x product 0x%04x",
    278  1.15       cgd 		    unmatched, vendor, product);
    279  1.10       cgd 	else if (product_namep != NULL)
    280  1.19  christos 		cp += sprintf(cp, "%s %s", vendor_namep, product_namep);
    281  1.10       cgd 	else
    282  1.20       cgd 		cp += sprintf(cp, "%s product 0x%04x",
    283  1.10       cgd 		    vendor_namep, product);
    284  1.13       cgd 	if (showclass) {
    285  1.19  christos 		cp += sprintf(cp, " (");
    286  1.13       cgd 		if (classp->name == NULL)
    287  1.20       cgd 			cp += sprintf(cp, "class 0x%02x, subclass 0x%02x",
    288  1.13       cgd 			    class, subclass);
    289  1.13       cgd 		else {
    290  1.13       cgd 			if (subclassp == NULL || subclassp->name == NULL)
    291  1.20       cgd 				cp += sprintf(cp,
    292  1.20       cgd 				    "%s subclass 0x%02x",
    293  1.20       cgd 				    classp->name, subclass);
    294  1.13       cgd 			else
    295  1.20       cgd 				cp += sprintf(cp, "%s %s",
    296  1.20       cgd 				    subclassp->name, classp->name);
    297  1.13       cgd 		}
    298  1.20       cgd 		if (interface != 0)
    299  1.20       cgd 			cp += sprintf(cp, ", interface 0x%02x", interface);
    300  1.20       cgd 		if (revision != 0)
    301  1.20       cgd 			cp += sprintf(cp, ", revision 0x%02x", revision);
    302  1.20       cgd 		cp += sprintf(cp, ")");
    303  1.13       cgd 	}
    304   1.1   mycroft }
    305