Home | History | Annotate | Line # | Download | only in pci
pci_subr.c revision 1.15
      1  1.15      cgd /*	$NetBSD: pci_subr.c,v 1.15 1996/03/02 01:07:47 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.10      cgd 	{ "miscellaneous",	PCI_SUBCLASS_MASS_STORAGE_MISC,		},
     71  1.10      cgd 	{ 0 },
     72  1.10      cgd };
     73  1.10      cgd 
     74  1.10      cgd struct pci_class pci_subclass_network[] = {
     75  1.10      cgd 	{ "ethernet",		PCI_SUBCLASS_NETWORK_ETHERNET,		},
     76  1.10      cgd 	{ "token ring",		PCI_SUBCLASS_NETWORK_TOKENRING,		},
     77  1.10      cgd 	{ "FDDI",		PCI_SUBCLASS_NETWORK_FDDI,		},
     78  1.10      cgd 	{ "miscellaneous",	PCI_SUBCLASS_NETWORK_MISC,		},
     79  1.10      cgd 	{ 0 },
     80  1.10      cgd };
     81  1.10      cgd 
     82  1.10      cgd struct pci_class pci_subclass_display[] = {
     83  1.10      cgd 	{ "VGA",		PCI_SUBCLASS_DISPLAY_VGA,		},
     84  1.10      cgd 	{ "XGA",		PCI_SUBCLASS_DISPLAY_XGA,		},
     85  1.10      cgd 	{ "miscellaneous",	PCI_SUBCLASS_DISPLAY_MISC,		},
     86  1.10      cgd 	{ 0 },
     87  1.10      cgd };
     88  1.10      cgd 
     89  1.10      cgd struct pci_class pci_subclass_multimedia[] = {
     90  1.10      cgd 	{ "video",		PCI_SUBCLASS_MULTIMEDIA_VIDEO,		},
     91  1.10      cgd 	{ "audio",		PCI_SUBCLASS_MULTIMEDIA_AUDIO,		},
     92  1.10      cgd 	{ "miscellaneous",	PCI_SUBCLASS_MULTIMEDIA_MISC,		},
     93  1.10      cgd 	{ 0 },
     94  1.10      cgd };
     95  1.10      cgd 
     96  1.10      cgd struct pci_class pci_subclass_memory[] = {
     97  1.10      cgd 	{ "RAM",		PCI_SUBCLASS_MEMORY_RAM,		},
     98  1.10      cgd 	{ "flash",		PCI_SUBCLASS_MEMORY_FLASH,		},
     99  1.10      cgd 	{ "miscellaneous",	PCI_SUBCLASS_MEMORY_MISC,		},
    100  1.10      cgd 	{ 0 },
    101  1.10      cgd };
    102  1.10      cgd 
    103  1.10      cgd struct pci_class pci_subclass_bridge[] = {
    104  1.10      cgd 	{ "host",		PCI_SUBCLASS_BRIDGE_HOST,		},
    105  1.10      cgd 	{ "ISA",		PCI_SUBCLASS_BRIDGE_ISA,		},
    106  1.10      cgd 	{ "EISA",		PCI_SUBCLASS_BRIDGE_EISA,		},
    107  1.10      cgd 	{ "MicroChannel",	PCI_SUBCLASS_BRIDGE_MC,			},
    108  1.10      cgd 	{ "PCI",		PCI_SUBCLASS_BRIDGE_PCI,		},
    109  1.10      cgd 	{ "PCMCIA",		PCI_SUBCLASS_BRIDGE_PCMCIA,		},
    110  1.10      cgd 	{ "miscellaneous",	PCI_SUBCLASS_BRIDGE_MISC,		},
    111  1.10      cgd 	{ 0 },
    112  1.10      cgd };
    113  1.10      cgd 
    114  1.10      cgd struct pci_class pci_class[] = {
    115  1.10      cgd 	{ "prehistoric",	PCI_CLASS_PREHISTORIC,
    116  1.10      cgd 	    pci_subclass_prehistoric,				},
    117  1.10      cgd 	{ "mass storage",	PCI_CLASS_MASS_STORAGE,
    118  1.10      cgd 	    pci_subclass_mass_storage,				},
    119  1.10      cgd 	{ "network",		PCI_CLASS_NETWORK,
    120  1.10      cgd 	    pci_subclass_network,				},
    121  1.10      cgd 	{ "display",		PCI_CLASS_DISPLAY,
    122  1.11      cgd 	    pci_subclass_display,				},
    123  1.10      cgd 	{ "multimedia",		PCI_CLASS_MULTIMEDIA,
    124  1.10      cgd 	    pci_subclass_multimedia,				},
    125  1.10      cgd 	{ "memory",		PCI_CLASS_MEMORY,
    126  1.10      cgd 	    pci_subclass_memory,				},
    127  1.10      cgd 	{ "bridge",		PCI_CLASS_BRIDGE,
    128  1.10      cgd 	    pci_subclass_bridge,				},
    129  1.10      cgd 	{ "undefined",		PCI_CLASS_UNDEFINED,
    130  1.10      cgd 	    0,							},
    131  1.10      cgd 	{ 0 },
    132  1.10      cgd };
    133  1.10      cgd 
    134  1.10      cgd #ifdef PCIVERBOSE
    135  1.10      cgd /*
    136  1.10      cgd  * Descriptions of of known vendors and devices ("products").
    137  1.10      cgd  */
    138  1.10      cgd struct pci_knowndev {
    139  1.10      cgd 	pci_vendor_id_t		vendor;
    140  1.10      cgd 	pci_product_id_t	product;
    141  1.10      cgd 	int			flags;
    142  1.10      cgd 	char			*vendorname, *productname;
    143  1.10      cgd };
    144  1.13      cgd #define	PCI_KNOWNDEV_NOPROD	0x01		/* match on vendor only */
    145  1.10      cgd 
    146  1.10      cgd #include <dev/pci/pcidevs_data.h>
    147  1.10      cgd #endif /* PCIVERBOSE */
    148  1.10      cgd 
    149  1.10      cgd void
    150  1.13      cgd pci_devinfo(id_reg, class_reg, showclass, cp)
    151  1.10      cgd 	pcireg_t id_reg, class_reg;
    152  1.13      cgd 	int showclass;
    153  1.10      cgd 	char *cp;
    154  1.10      cgd {
    155  1.10      cgd 	pci_vendor_id_t vendor;
    156  1.10      cgd 	pci_product_id_t product;
    157  1.10      cgd 	pci_class_t class;
    158  1.10      cgd 	pci_subclass_t subclass;
    159  1.10      cgd 	pci_interface_t interface;
    160  1.10      cgd 	pci_revision_t revision;
    161  1.10      cgd 	char *vendor_namep, *product_namep;
    162  1.10      cgd 	struct pci_class *classp, *subclassp;
    163  1.10      cgd #ifdef PCIVERBOSE
    164  1.10      cgd 	struct pci_knowndev *kdp;
    165  1.15      cgd         const char *unmatched = "unknown ";
    166  1.15      cgd #else
    167  1.15      cgd         const char *unmatched = "";
    168  1.10      cgd #endif
    169  1.10      cgd 
    170  1.10      cgd 	vendor = PCI_VENDOR(id_reg);
    171  1.10      cgd 	product = PCI_PRODUCT(id_reg);
    172  1.10      cgd 
    173  1.10      cgd 	class = PCI_CLASS(class_reg);
    174  1.10      cgd 	subclass = PCI_SUBCLASS(class_reg);
    175  1.10      cgd 	interface = PCI_INTERFACE(class_reg);
    176  1.10      cgd 	revision = PCI_REVISION(class_reg);
    177  1.10      cgd 
    178  1.10      cgd #ifdef PCIVERBOSE
    179  1.10      cgd 	kdp = pci_knowndevs;
    180  1.10      cgd         while (kdp->vendorname != NULL) {	/* all have vendor name */
    181  1.10      cgd                 if (kdp->vendor == vendor && (kdp->product == product ||
    182  1.10      cgd 		    (kdp->flags & PCI_KNOWNDEV_NOPROD) != 0))
    183  1.10      cgd                         break;
    184  1.10      cgd 		kdp++;
    185  1.10      cgd 	}
    186  1.13      cgd         if (kdp->vendorname == NULL)
    187  1.10      cgd 		vendor_namep = product_namep = NULL;
    188  1.13      cgd 	else {
    189  1.10      cgd 		vendor_namep = kdp->vendorname;
    190  1.10      cgd 		product_namep = (kdp->flags & PCI_KNOWNDEV_NOPROD) == 0 ?
    191  1.10      cgd 		    kdp->productname : NULL;
    192  1.10      cgd         }
    193  1.10      cgd #else /* PCIVERBOSE */
    194  1.10      cgd 	vendor_namep = product_namep = NULL;
    195  1.10      cgd #endif /* PCIVERBOSE */
    196  1.10      cgd 
    197  1.10      cgd 	classp = pci_class;
    198  1.10      cgd 	while (classp->name != NULL) {
    199  1.10      cgd 		if (class == classp->val)
    200  1.10      cgd 			break;
    201  1.10      cgd 		classp++;
    202  1.10      cgd 	}
    203  1.10      cgd 
    204  1.10      cgd 	subclassp = (classp->name != NULL) ? classp->subclasses : NULL;
    205  1.10      cgd 	while (subclassp && subclassp->name != NULL) {
    206  1.10      cgd 		if (subclass == subclassp->val)
    207  1.10      cgd 			break;
    208  1.10      cgd 		subclassp++;
    209  1.10      cgd 	}
    210  1.10      cgd 
    211  1.10      cgd 	if (vendor_namep == NULL)
    212  1.15      cgd 		cp += sprintf(cp, "%svendor/product: 0x%04x/0x%04x",
    213  1.15      cgd 		    unmatched, vendor, product);
    214  1.10      cgd 	else if (product_namep != NULL)
    215  1.10      cgd 		cp += sprintf(cp, "%s %s", vendor_namep, product_namep);
    216  1.10      cgd 	else
    217  1.10      cgd 		cp += sprintf(cp, "vendor: %s, unknown product: 0x%x",
    218  1.10      cgd 		    vendor_namep, product);
    219  1.13      cgd 	if (showclass) {
    220  1.13      cgd 		cp += sprintf(cp, " (");
    221  1.13      cgd 		if (classp->name == NULL)
    222  1.13      cgd 			cp += sprintf(cp,
    223  1.13      cgd 			    "unknown class/subclass: 0x%02x/0x%02x",
    224  1.13      cgd 			    class, subclass);
    225  1.13      cgd 		else {
    226  1.13      cgd 			cp += sprintf(cp, "class: %s, ", classp->name);
    227  1.13      cgd 			if (subclassp == NULL || subclassp->name == NULL)
    228  1.13      cgd 				cp += sprintf(cp, "unknown subclass: 0x%02x",
    229  1.13      cgd 				    subclass);
    230  1.13      cgd 			else
    231  1.13      cgd 				cp += sprintf(cp, "subclass: %s",
    232  1.13      cgd 				    subclassp->name);
    233  1.13      cgd 		}
    234  1.10      cgd #if 0 /* not very useful */
    235  1.13      cgd 		cp += sprintf(cp, ", interface: 0x%02x", interface);
    236  1.10      cgd #endif
    237  1.13      cgd 		cp += sprintf(cp, ", revision: 0x%02x)", revision);
    238  1.13      cgd 	}
    239   1.1  mycroft }
    240