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