Home | History | Annotate | Line # | Download | only in pci
pci_subr.c revision 1.78.2.3
      1  1.78.2.1  uebayasi /*	$NetBSD: pci_subr.c,v 1.78.2.3 2010/10/22 07:22:06 uebayasi Exp $	*/
      2       1.3       cgd 
      3       1.1   mycroft /*
      4      1.22   thorpej  * Copyright (c) 1997 Zubin D. Dittia.  All rights reserved.
      5      1.40       cgd  * Copyright (c) 1995, 1996, 1998, 2000
      6      1.26       cgd  *	Christopher G. Demetriou.  All rights reserved.
      7      1.30   mycroft  * Copyright (c) 1994 Charles M. Hannum.  All rights reserved.
      8       1.1   mycroft  *
      9       1.1   mycroft  * Redistribution and use in source and binary forms, with or without
     10       1.1   mycroft  * modification, are permitted provided that the following conditions
     11       1.1   mycroft  * are met:
     12       1.1   mycroft  * 1. Redistributions of source code must retain the above copyright
     13       1.1   mycroft  *    notice, this list of conditions and the following disclaimer.
     14       1.1   mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     15       1.1   mycroft  *    notice, this list of conditions and the following disclaimer in the
     16       1.1   mycroft  *    documentation and/or other materials provided with the distribution.
     17       1.1   mycroft  * 3. All advertising materials mentioning features or use of this software
     18       1.1   mycroft  *    must display the following acknowledgement:
     19      1.30   mycroft  *	This product includes software developed by Charles M. Hannum.
     20       1.1   mycroft  * 4. The name of the author may not be used to endorse or promote products
     21       1.1   mycroft  *    derived from this software without specific prior written permission.
     22       1.1   mycroft  *
     23       1.1   mycroft  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     24       1.1   mycroft  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     25       1.1   mycroft  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26       1.1   mycroft  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     27       1.1   mycroft  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     28       1.1   mycroft  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     29       1.1   mycroft  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     30       1.1   mycroft  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     31       1.1   mycroft  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     32       1.1   mycroft  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     33       1.1   mycroft  */
     34       1.1   mycroft 
     35       1.1   mycroft /*
     36      1.10       cgd  * PCI autoconfiguration support functions.
     37      1.45   thorpej  *
     38      1.45   thorpej  * Note: This file is also built into a userland library (libpci).
     39      1.45   thorpej  * Pay attention to this when you make modifications.
     40       1.1   mycroft  */
     41      1.47     lukem 
     42      1.47     lukem #include <sys/cdefs.h>
     43  1.78.2.1  uebayasi __KERNEL_RCSID(0, "$NetBSD: pci_subr.c,v 1.78.2.3 2010/10/22 07:22:06 uebayasi Exp $");
     44      1.21     enami 
     45      1.45   thorpej #ifdef _KERNEL_OPT
     46      1.35       cgd #include "opt_pci.h"
     47      1.45   thorpej #endif
     48       1.1   mycroft 
     49       1.1   mycroft #include <sys/param.h>
     50       1.1   mycroft 
     51      1.45   thorpej #ifdef _KERNEL
     52      1.62    simonb #include <sys/systm.h>
     53      1.73        ad #include <sys/intr.h>
     54  1.78.2.2  uebayasi #include <sys/module.h>
     55      1.45   thorpej #else
     56      1.45   thorpej #include <pci.h>
     57      1.72     joerg #include <stdbool.h>
     58      1.46     enami #include <stdio.h>
     59      1.45   thorpej #endif
     60      1.24   thorpej 
     61      1.10       cgd #include <dev/pci/pcireg.h>
     62      1.45   thorpej #ifdef _KERNEL
     63       1.7       cgd #include <dev/pci/pcivar.h>
     64      1.45   thorpej #endif
     65      1.10       cgd 
     66      1.10       cgd /*
     67      1.10       cgd  * Descriptions of known PCI classes and subclasses.
     68      1.10       cgd  *
     69      1.10       cgd  * Subclasses are described in the same way as classes, but have a
     70      1.10       cgd  * NULL subclass pointer.
     71      1.10       cgd  */
     72      1.10       cgd struct pci_class {
     73      1.44   thorpej 	const char	*name;
     74      1.10       cgd 	int		val;		/* as wide as pci_{,sub}class_t */
     75      1.42  jdolecek 	const struct pci_class *subclasses;
     76      1.10       cgd };
     77      1.10       cgd 
     78      1.61   thorpej static const struct pci_class pci_subclass_prehistoric[] = {
     79      1.65  christos 	{ "miscellaneous",	PCI_SUBCLASS_PREHISTORIC_MISC,	NULL,	},
     80      1.65  christos 	{ "VGA",		PCI_SUBCLASS_PREHISTORIC_VGA,	NULL,	},
     81      1.65  christos 	{ NULL,			0,				NULL,	},
     82      1.10       cgd };
     83      1.10       cgd 
     84      1.61   thorpej static const struct pci_class pci_subclass_mass_storage[] = {
     85      1.65  christos 	{ "SCSI",		PCI_SUBCLASS_MASS_STORAGE_SCSI,	NULL,	},
     86      1.65  christos 	{ "IDE",		PCI_SUBCLASS_MASS_STORAGE_IDE,	NULL,	},
     87      1.65  christos 	{ "floppy",		PCI_SUBCLASS_MASS_STORAGE_FLOPPY, NULL, },
     88      1.65  christos 	{ "IPI",		PCI_SUBCLASS_MASS_STORAGE_IPI,	NULL,	},
     89      1.65  christos 	{ "RAID",		PCI_SUBCLASS_MASS_STORAGE_RAID,	NULL,	},
     90      1.65  christos 	{ "ATA",		PCI_SUBCLASS_MASS_STORAGE_ATA,	NULL,	},
     91      1.65  christos 	{ "SATA",		PCI_SUBCLASS_MASS_STORAGE_SATA,	NULL,	},
     92      1.65  christos 	{ "SAS",		PCI_SUBCLASS_MASS_STORAGE_SAS,	NULL,	},
     93      1.65  christos 	{ "miscellaneous",	PCI_SUBCLASS_MASS_STORAGE_MISC,	NULL,	},
     94      1.65  christos 	{ NULL,			0,				NULL,	},
     95      1.10       cgd };
     96      1.10       cgd 
     97      1.61   thorpej static const struct pci_class pci_subclass_network[] = {
     98      1.65  christos 	{ "ethernet",		PCI_SUBCLASS_NETWORK_ETHERNET,	NULL,	},
     99      1.65  christos 	{ "token ring",		PCI_SUBCLASS_NETWORK_TOKENRING,	NULL,	},
    100      1.65  christos 	{ "FDDI",		PCI_SUBCLASS_NETWORK_FDDI,	NULL,	},
    101      1.65  christos 	{ "ATM",		PCI_SUBCLASS_NETWORK_ATM,	NULL,	},
    102      1.65  christos 	{ "ISDN",		PCI_SUBCLASS_NETWORK_ISDN,	NULL,	},
    103      1.65  christos 	{ "WorldFip",		PCI_SUBCLASS_NETWORK_WORLDFIP,	NULL,	},
    104      1.65  christos 	{ "PCMIG Multi Computing", PCI_SUBCLASS_NETWORK_PCIMGMULTICOMP, NULL, },
    105      1.65  christos 	{ "miscellaneous",	PCI_SUBCLASS_NETWORK_MISC,	NULL,	},
    106      1.65  christos 	{ NULL,			0,				NULL,	},
    107      1.10       cgd };
    108      1.10       cgd 
    109      1.61   thorpej static const struct pci_class pci_subclass_display[] = {
    110      1.65  christos 	{ "VGA",		PCI_SUBCLASS_DISPLAY_VGA,	NULL,	},
    111      1.65  christos 	{ "XGA",		PCI_SUBCLASS_DISPLAY_XGA,	NULL,	},
    112      1.65  christos 	{ "3D",			PCI_SUBCLASS_DISPLAY_3D,	NULL,	},
    113      1.65  christos 	{ "miscellaneous",	PCI_SUBCLASS_DISPLAY_MISC,	NULL,	},
    114      1.65  christos 	{ NULL,			0,				NULL,	},
    115      1.10       cgd };
    116      1.10       cgd 
    117      1.61   thorpej static const struct pci_class pci_subclass_multimedia[] = {
    118      1.65  christos 	{ "video",		PCI_SUBCLASS_MULTIMEDIA_VIDEO,	NULL,	},
    119      1.65  christos 	{ "audio",		PCI_SUBCLASS_MULTIMEDIA_AUDIO,	NULL,	},
    120      1.65  christos 	{ "telephony",		PCI_SUBCLASS_MULTIMEDIA_TELEPHONY, NULL,},
    121      1.65  christos 	{ "miscellaneous",	PCI_SUBCLASS_MULTIMEDIA_MISC,	NULL,	},
    122      1.65  christos 	{ NULL,			0,				NULL,	},
    123      1.10       cgd };
    124      1.10       cgd 
    125      1.61   thorpej static const struct pci_class pci_subclass_memory[] = {
    126      1.65  christos 	{ "RAM",		PCI_SUBCLASS_MEMORY_RAM,	NULL,	},
    127      1.65  christos 	{ "flash",		PCI_SUBCLASS_MEMORY_FLASH,	NULL,	},
    128      1.65  christos 	{ "miscellaneous",	PCI_SUBCLASS_MEMORY_MISC,	NULL,	},
    129      1.65  christos 	{ NULL,			0,				NULL,	},
    130      1.10       cgd };
    131      1.10       cgd 
    132      1.61   thorpej static const struct pci_class pci_subclass_bridge[] = {
    133      1.65  christos 	{ "host",		PCI_SUBCLASS_BRIDGE_HOST,	NULL,	},
    134      1.65  christos 	{ "ISA",		PCI_SUBCLASS_BRIDGE_ISA,	NULL,	},
    135      1.65  christos 	{ "EISA",		PCI_SUBCLASS_BRIDGE_EISA,	NULL,	},
    136      1.65  christos 	{ "MicroChannel",	PCI_SUBCLASS_BRIDGE_MC,		NULL,	},
    137      1.65  christos 	{ "PCI",		PCI_SUBCLASS_BRIDGE_PCI,	NULL,	},
    138      1.65  christos 	{ "PCMCIA",		PCI_SUBCLASS_BRIDGE_PCMCIA,	NULL,	},
    139      1.65  christos 	{ "NuBus",		PCI_SUBCLASS_BRIDGE_NUBUS,	NULL,	},
    140      1.65  christos 	{ "CardBus",		PCI_SUBCLASS_BRIDGE_CARDBUS,	NULL,	},
    141      1.65  christos 	{ "RACEway",		PCI_SUBCLASS_BRIDGE_RACEWAY,	NULL,	},
    142      1.65  christos 	{ "Semi-transparent PCI", PCI_SUBCLASS_BRIDGE_STPCI,	NULL,	},
    143      1.65  christos 	{ "InfiniBand",		PCI_SUBCLASS_BRIDGE_INFINIBAND,	NULL,	},
    144      1.65  christos 	{ "miscellaneous",	PCI_SUBCLASS_BRIDGE_MISC,	NULL,	},
    145      1.65  christos 	{ NULL,			0,				NULL,	},
    146      1.10       cgd };
    147      1.10       cgd 
    148      1.61   thorpej static const struct pci_class pci_subclass_communications[] = {
    149      1.65  christos 	{ "serial",		PCI_SUBCLASS_COMMUNICATIONS_SERIAL,	NULL, },
    150      1.65  christos 	{ "parallel",		PCI_SUBCLASS_COMMUNICATIONS_PARALLEL,	NULL, },
    151      1.65  christos 	{ "multi-port serial",	PCI_SUBCLASS_COMMUNICATIONS_MPSERIAL,	NULL, },
    152      1.65  christos 	{ "modem",		PCI_SUBCLASS_COMMUNICATIONS_MODEM,	NULL, },
    153      1.65  christos 	{ "GPIB",		PCI_SUBCLASS_COMMUNICATIONS_GPIB,	NULL, },
    154      1.65  christos 	{ "smartcard",		PCI_SUBCLASS_COMMUNICATIONS_SMARTCARD,	NULL, },
    155      1.65  christos 	{ "miscellaneous",	PCI_SUBCLASS_COMMUNICATIONS_MISC,	NULL, },
    156      1.65  christos 	{ NULL,			0,					NULL, },
    157      1.20       cgd };
    158      1.20       cgd 
    159      1.61   thorpej static const struct pci_class pci_subclass_system[] = {
    160      1.65  christos 	{ "interrupt",		PCI_SUBCLASS_SYSTEM_PIC,	NULL,	},
    161      1.65  christos 	{ "8237 DMA",		PCI_SUBCLASS_SYSTEM_DMA,	NULL,	},
    162      1.65  christos 	{ "8254 timer",		PCI_SUBCLASS_SYSTEM_TIMER,	NULL,	},
    163      1.65  christos 	{ "RTC",		PCI_SUBCLASS_SYSTEM_RTC,	NULL,	},
    164      1.65  christos 	{ "PCI Hot-Plug",	PCI_SUBCLASS_SYSTEM_PCIHOTPLUG, NULL,	},
    165      1.65  christos 	{ "SD Host Controller",	PCI_SUBCLASS_SYSTEM_SDHC,	NULL,	},
    166      1.65  christos 	{ "miscellaneous",	PCI_SUBCLASS_SYSTEM_MISC,	NULL,	},
    167      1.65  christos 	{ NULL,			0,				NULL,	},
    168      1.20       cgd };
    169      1.20       cgd 
    170      1.61   thorpej static const struct pci_class pci_subclass_input[] = {
    171      1.65  christos 	{ "keyboard",		PCI_SUBCLASS_INPUT_KEYBOARD,	NULL,	},
    172      1.65  christos 	{ "digitizer",		PCI_SUBCLASS_INPUT_DIGITIZER,	NULL,	},
    173      1.65  christos 	{ "mouse",		PCI_SUBCLASS_INPUT_MOUSE,	NULL,	},
    174      1.65  christos 	{ "scanner",		PCI_SUBCLASS_INPUT_SCANNER,	NULL,	},
    175      1.65  christos 	{ "game port",		PCI_SUBCLASS_INPUT_GAMEPORT,	NULL,	},
    176      1.65  christos 	{ "miscellaneous",	PCI_SUBCLASS_INPUT_MISC,	NULL,	},
    177      1.65  christos 	{ NULL,			0,				NULL,	},
    178      1.20       cgd };
    179      1.20       cgd 
    180      1.61   thorpej static const struct pci_class pci_subclass_dock[] = {
    181      1.65  christos 	{ "generic",		PCI_SUBCLASS_DOCK_GENERIC,	NULL,	},
    182      1.65  christos 	{ "miscellaneous",	PCI_SUBCLASS_DOCK_MISC,		NULL,	},
    183      1.65  christos 	{ NULL,			0,				NULL,	},
    184      1.20       cgd };
    185      1.20       cgd 
    186      1.61   thorpej static const struct pci_class pci_subclass_processor[] = {
    187      1.65  christos 	{ "386",		PCI_SUBCLASS_PROCESSOR_386,	NULL,	},
    188      1.65  christos 	{ "486",		PCI_SUBCLASS_PROCESSOR_486,	NULL,	},
    189      1.65  christos 	{ "Pentium",		PCI_SUBCLASS_PROCESSOR_PENTIUM, NULL,	},
    190      1.65  christos 	{ "Alpha",		PCI_SUBCLASS_PROCESSOR_ALPHA,	NULL,	},
    191      1.65  christos 	{ "PowerPC",		PCI_SUBCLASS_PROCESSOR_POWERPC, NULL,	},
    192      1.65  christos 	{ "MIPS",		PCI_SUBCLASS_PROCESSOR_MIPS,	NULL,	},
    193      1.65  christos 	{ "Co-processor",	PCI_SUBCLASS_PROCESSOR_COPROC,	NULL,	},
    194      1.65  christos 	{ NULL,			0,				NULL,	},
    195      1.20       cgd };
    196      1.20       cgd 
    197      1.61   thorpej static const struct pci_class pci_subclass_serialbus[] = {
    198      1.65  christos 	{ "Firewire",		PCI_SUBCLASS_SERIALBUS_FIREWIRE, NULL,	},
    199      1.65  christos 	{ "ACCESS.bus",		PCI_SUBCLASS_SERIALBUS_ACCESS,	NULL,	},
    200      1.65  christos 	{ "SSA",		PCI_SUBCLASS_SERIALBUS_SSA,	NULL,	},
    201      1.65  christos 	{ "USB",		PCI_SUBCLASS_SERIALBUS_USB,	NULL,	},
    202      1.32       cgd 	/* XXX Fiber Channel/_FIBRECHANNEL */
    203      1.65  christos 	{ "Fiber Channel",	PCI_SUBCLASS_SERIALBUS_FIBER,	NULL,	},
    204      1.65  christos 	{ "SMBus",		PCI_SUBCLASS_SERIALBUS_SMBUS,	NULL,	},
    205      1.65  christos 	{ "InfiniBand",		PCI_SUBCLASS_SERIALBUS_INFINIBAND, NULL,},
    206      1.65  christos 	{ "IPMI",		PCI_SUBCLASS_SERIALBUS_IPMI,	NULL,	},
    207      1.65  christos 	{ "SERCOS",		PCI_SUBCLASS_SERIALBUS_SERCOS,	NULL,	},
    208      1.65  christos 	{ "CANbus",		PCI_SUBCLASS_SERIALBUS_CANBUS,	NULL,	},
    209      1.65  christos 	{ NULL,			0,				NULL,	},
    210      1.32       cgd };
    211      1.32       cgd 
    212      1.61   thorpej static const struct pci_class pci_subclass_wireless[] = {
    213      1.65  christos 	{ "IrDA",		PCI_SUBCLASS_WIRELESS_IRDA,	NULL,	},
    214      1.65  christos 	{ "Consumer IR",	PCI_SUBCLASS_WIRELESS_CONSUMERIR, NULL,	},
    215      1.65  christos 	{ "RF",			PCI_SUBCLASS_WIRELESS_RF,	NULL,	},
    216      1.65  christos 	{ "bluetooth",		PCI_SUBCLASS_WIRELESS_BLUETOOTH, NULL,	},
    217      1.65  christos 	{ "broadband",		PCI_SUBCLASS_WIRELESS_BROADBAND, NULL,	},
    218      1.65  christos 	{ "802.11a (5 GHz)",	PCI_SUBCLASS_WIRELESS_802_11A,	NULL,	},
    219      1.65  christos 	{ "802.11b (2.4 GHz)",	PCI_SUBCLASS_WIRELESS_802_11B,	NULL,	},
    220      1.65  christos 	{ "miscellaneous",	PCI_SUBCLASS_WIRELESS_MISC,	NULL,	},
    221      1.65  christos 	{ NULL,			0,				NULL,	},
    222      1.32       cgd };
    223      1.32       cgd 
    224      1.61   thorpej static const struct pci_class pci_subclass_i2o[] = {
    225      1.65  christos 	{ "standard",		PCI_SUBCLASS_I2O_STANDARD,	NULL,	},
    226      1.65  christos 	{ NULL,			0,				NULL,	},
    227      1.32       cgd };
    228      1.32       cgd 
    229      1.61   thorpej static const struct pci_class pci_subclass_satcom[] = {
    230      1.65  christos 	{ "TV",			PCI_SUBCLASS_SATCOM_TV,	 	NULL,	},
    231      1.65  christos 	{ "audio",		PCI_SUBCLASS_SATCOM_AUDIO, 	NULL,	},
    232      1.65  christos 	{ "voice",		PCI_SUBCLASS_SATCOM_VOICE, 	NULL,	},
    233      1.65  christos 	{ "data",		PCI_SUBCLASS_SATCOM_DATA,	NULL,	},
    234      1.65  christos 	{ NULL,			0,				NULL,	},
    235      1.32       cgd };
    236      1.32       cgd 
    237      1.61   thorpej static const struct pci_class pci_subclass_crypto[] = {
    238      1.65  christos 	{ "network/computing",	PCI_SUBCLASS_CRYPTO_NETCOMP, 	NULL,	},
    239      1.65  christos 	{ "entertainment",	PCI_SUBCLASS_CRYPTO_ENTERTAINMENT, NULL,},
    240      1.65  christos 	{ "miscellaneous",	PCI_SUBCLASS_CRYPTO_MISC, 	NULL,	},
    241      1.65  christos 	{ NULL,			0,				NULL,	},
    242      1.32       cgd };
    243      1.32       cgd 
    244      1.61   thorpej static const struct pci_class pci_subclass_dasp[] = {
    245      1.65  christos 	{ "DPIO",		PCI_SUBCLASS_DASP_DPIO,		NULL,	},
    246      1.65  christos 	{ "Time and Frequency",	PCI_SUBCLASS_DASP_TIMEFREQ,	NULL,	},
    247      1.65  christos 	{ "synchronization",	PCI_SUBCLASS_DASP_SYNC,		NULL,	},
    248      1.65  christos 	{ "management",		PCI_SUBCLASS_DASP_MGMT,		NULL,	},
    249      1.65  christos 	{ "miscellaneous",	PCI_SUBCLASS_DASP_MISC,		NULL,	},
    250      1.65  christos 	{ NULL,			0,				NULL,	},
    251      1.20       cgd };
    252      1.20       cgd 
    253      1.61   thorpej static const struct pci_class pci_class[] = {
    254      1.10       cgd 	{ "prehistoric",	PCI_CLASS_PREHISTORIC,
    255      1.10       cgd 	    pci_subclass_prehistoric,				},
    256      1.10       cgd 	{ "mass storage",	PCI_CLASS_MASS_STORAGE,
    257      1.10       cgd 	    pci_subclass_mass_storage,				},
    258      1.10       cgd 	{ "network",		PCI_CLASS_NETWORK,
    259      1.10       cgd 	    pci_subclass_network,				},
    260      1.10       cgd 	{ "display",		PCI_CLASS_DISPLAY,
    261      1.11       cgd 	    pci_subclass_display,				},
    262      1.10       cgd 	{ "multimedia",		PCI_CLASS_MULTIMEDIA,
    263      1.10       cgd 	    pci_subclass_multimedia,				},
    264      1.10       cgd 	{ "memory",		PCI_CLASS_MEMORY,
    265      1.10       cgd 	    pci_subclass_memory,				},
    266      1.10       cgd 	{ "bridge",		PCI_CLASS_BRIDGE,
    267      1.10       cgd 	    pci_subclass_bridge,				},
    268      1.20       cgd 	{ "communications",	PCI_CLASS_COMMUNICATIONS,
    269      1.20       cgd 	    pci_subclass_communications,			},
    270      1.20       cgd 	{ "system",		PCI_CLASS_SYSTEM,
    271      1.20       cgd 	    pci_subclass_system,				},
    272      1.20       cgd 	{ "input",		PCI_CLASS_INPUT,
    273      1.20       cgd 	    pci_subclass_input,					},
    274      1.20       cgd 	{ "dock",		PCI_CLASS_DOCK,
    275      1.20       cgd 	    pci_subclass_dock,					},
    276      1.20       cgd 	{ "processor",		PCI_CLASS_PROCESSOR,
    277      1.20       cgd 	    pci_subclass_processor,				},
    278      1.20       cgd 	{ "serial bus",		PCI_CLASS_SERIALBUS,
    279      1.20       cgd 	    pci_subclass_serialbus,				},
    280      1.32       cgd 	{ "wireless",		PCI_CLASS_WIRELESS,
    281      1.32       cgd 	    pci_subclass_wireless,				},
    282      1.32       cgd 	{ "I2O",		PCI_CLASS_I2O,
    283      1.32       cgd 	    pci_subclass_i2o,					},
    284      1.32       cgd 	{ "satellite comm",	PCI_CLASS_SATCOM,
    285      1.32       cgd 	    pci_subclass_satcom,				},
    286      1.32       cgd 	{ "crypto",		PCI_CLASS_CRYPTO,
    287      1.32       cgd 	    pci_subclass_crypto,				},
    288      1.32       cgd 	{ "DASP",		PCI_CLASS_DASP,
    289      1.32       cgd 	    pci_subclass_dasp,					},
    290      1.10       cgd 	{ "undefined",		PCI_CLASS_UNDEFINED,
    291      1.65  christos 	    NULL,						},
    292      1.65  christos 	{ NULL,			0,
    293      1.65  christos 	    NULL,						},
    294      1.10       cgd };
    295      1.10       cgd 
    296  1.78.2.2  uebayasi void pci_load_verbose(void);
    297  1.78.2.2  uebayasi 
    298  1.78.2.2  uebayasi #if defined(_KERNEL)
    299      1.10       cgd /*
    300  1.78.2.2  uebayasi  * In kernel, these routines are provided and linked via the
    301  1.78.2.2  uebayasi  * pciverbose module.
    302      1.10       cgd  */
    303  1.78.2.2  uebayasi const char *pci_findvendor_stub(pcireg_t);
    304  1.78.2.2  uebayasi const char *pci_findproduct_stub(pcireg_t);
    305      1.10       cgd 
    306  1.78.2.2  uebayasi const char *(*pci_findvendor)(pcireg_t) = pci_findvendor_stub;
    307  1.78.2.2  uebayasi const char *(*pci_findproduct)(pcireg_t) = pci_findproduct_stub;
    308  1.78.2.2  uebayasi const char *pci_unmatched = "";
    309  1.78.2.2  uebayasi #else
    310  1.78.2.2  uebayasi /*
    311  1.78.2.2  uebayasi  * For userland we just set the vectors here.
    312  1.78.2.2  uebayasi  */
    313  1.78.2.2  uebayasi const char *(*pci_findvendor)(pcireg_t id_reg) = pci_findvendor_real;
    314  1.78.2.2  uebayasi const char *(*pci_findproduct)(pcireg_t id_reg) = pci_findproduct_real;
    315  1.78.2.2  uebayasi const char *pci_unmatched = "unmatched ";
    316      1.76      matt #endif
    317      1.76      matt 
    318  1.78.2.2  uebayasi int pciverbose_loaded = 0;
    319  1.78.2.2  uebayasi 
    320  1.78.2.2  uebayasi #if defined(_KERNEL)
    321  1.78.2.2  uebayasi /*
    322  1.78.2.2  uebayasi  * Routine to load the pciverbose kernel module as needed
    323  1.78.2.2  uebayasi  */
    324  1.78.2.2  uebayasi void pci_load_verbose(void)
    325  1.78.2.2  uebayasi {
    326  1.78.2.3  uebayasi 	if (pciverbose_loaded == 0)
    327  1.78.2.2  uebayasi 		module_autoload("pciverbose", MODULE_CLASS_MISC);
    328      1.76      matt }
    329      1.76      matt 
    330  1.78.2.2  uebayasi const char *pci_findvendor_stub(pcireg_t id_reg)
    331      1.29  augustss {
    332  1.78.2.2  uebayasi 	pci_load_verbose();
    333  1.78.2.2  uebayasi 	if (pciverbose_loaded)
    334  1.78.2.2  uebayasi 		return pci_findvendor(id_reg);
    335  1.78.2.2  uebayasi 	else
    336  1.78.2.2  uebayasi 		return NULL;
    337      1.59   mycroft }
    338      1.59   mycroft 
    339  1.78.2.2  uebayasi const char *pci_findproduct_stub(pcireg_t id_reg)
    340      1.59   mycroft {
    341  1.78.2.2  uebayasi 	pci_load_verbose();
    342  1.78.2.2  uebayasi 	if (pciverbose_loaded)
    343  1.78.2.2  uebayasi 		return pci_findproduct(id_reg);
    344  1.78.2.2  uebayasi 	else
    345  1.78.2.2  uebayasi 		return NULL;
    346      1.29  augustss }
    347  1.78.2.2  uebayasi #endif
    348      1.10       cgd 
    349      1.10       cgd void
    350      1.58    itojun pci_devinfo(pcireg_t id_reg, pcireg_t class_reg, int showclass, char *cp,
    351      1.58    itojun     size_t l)
    352      1.10       cgd {
    353      1.10       cgd 	pci_vendor_id_t vendor;
    354      1.10       cgd 	pci_product_id_t product;
    355      1.10       cgd 	pci_class_t class;
    356      1.10       cgd 	pci_subclass_t subclass;
    357      1.10       cgd 	pci_interface_t interface;
    358      1.10       cgd 	pci_revision_t revision;
    359  1.78.2.2  uebayasi 	const char *unmatched = pci_unmatched;
    360      1.59   mycroft 	const char *vendor_namep, *product_namep;
    361      1.42  jdolecek 	const struct pci_class *classp, *subclassp;
    362      1.58    itojun 	char *ep;
    363      1.58    itojun 
    364      1.58    itojun 	ep = cp + l;
    365      1.10       cgd 
    366      1.10       cgd 	vendor = PCI_VENDOR(id_reg);
    367      1.10       cgd 	product = PCI_PRODUCT(id_reg);
    368      1.10       cgd 
    369      1.10       cgd 	class = PCI_CLASS(class_reg);
    370      1.10       cgd 	subclass = PCI_SUBCLASS(class_reg);
    371      1.10       cgd 	interface = PCI_INTERFACE(class_reg);
    372      1.10       cgd 	revision = PCI_REVISION(class_reg);
    373      1.10       cgd 
    374      1.59   mycroft 	vendor_namep = pci_findvendor(id_reg);
    375      1.59   mycroft 	product_namep = pci_findproduct(id_reg);
    376      1.10       cgd 
    377      1.10       cgd 	classp = pci_class;
    378      1.10       cgd 	while (classp->name != NULL) {
    379      1.10       cgd 		if (class == classp->val)
    380      1.10       cgd 			break;
    381      1.10       cgd 		classp++;
    382      1.10       cgd 	}
    383      1.10       cgd 
    384      1.10       cgd 	subclassp = (classp->name != NULL) ? classp->subclasses : NULL;
    385      1.10       cgd 	while (subclassp && subclassp->name != NULL) {
    386      1.10       cgd 		if (subclass == subclassp->val)
    387      1.10       cgd 			break;
    388      1.10       cgd 		subclassp++;
    389      1.10       cgd 	}
    390      1.10       cgd 
    391      1.10       cgd 	if (vendor_namep == NULL)
    392      1.58    itojun 		cp += snprintf(cp, ep - cp, "%svendor 0x%04x product 0x%04x",
    393      1.15       cgd 		    unmatched, vendor, product);
    394      1.10       cgd 	else if (product_namep != NULL)
    395      1.58    itojun 		cp += snprintf(cp, ep - cp, "%s %s", vendor_namep,
    396      1.58    itojun 		    product_namep);
    397      1.10       cgd 	else
    398      1.58    itojun 		cp += snprintf(cp, ep - cp, "%s product 0x%04x",
    399      1.10       cgd 		    vendor_namep, product);
    400      1.13       cgd 	if (showclass) {
    401      1.58    itojun 		cp += snprintf(cp, ep - cp, " (");
    402      1.13       cgd 		if (classp->name == NULL)
    403      1.58    itojun 			cp += snprintf(cp, ep - cp,
    404      1.58    itojun 			    "class 0x%02x, subclass 0x%02x", class, subclass);
    405      1.13       cgd 		else {
    406      1.13       cgd 			if (subclassp == NULL || subclassp->name == NULL)
    407      1.58    itojun 				cp += snprintf(cp, ep - cp,
    408      1.78  drochner 				    "%s, subclass 0x%02x",
    409      1.20       cgd 				    classp->name, subclass);
    410      1.13       cgd 			else
    411      1.58    itojun 				cp += snprintf(cp, ep - cp, "%s %s",
    412      1.20       cgd 				    subclassp->name, classp->name);
    413      1.13       cgd 		}
    414      1.20       cgd 		if (interface != 0)
    415      1.58    itojun 			cp += snprintf(cp, ep - cp, ", interface 0x%02x",
    416      1.58    itojun 			    interface);
    417      1.20       cgd 		if (revision != 0)
    418      1.58    itojun 			cp += snprintf(cp, ep - cp, ", revision 0x%02x",
    419      1.58    itojun 			    revision);
    420      1.58    itojun 		cp += snprintf(cp, ep - cp, ")");
    421      1.13       cgd 	}
    422      1.22   thorpej }
    423      1.22   thorpej 
    424      1.22   thorpej /*
    425      1.22   thorpej  * Print out most of the PCI configuration registers.  Typically used
    426      1.22   thorpej  * in a device attach routine like this:
    427      1.22   thorpej  *
    428      1.22   thorpej  *	#ifdef MYDEV_DEBUG
    429      1.74    cegger  *		printf("%s: ", device_xname(&sc->sc_dev));
    430      1.43     enami  *		pci_conf_print(pa->pa_pc, pa->pa_tag, NULL);
    431      1.22   thorpej  *	#endif
    432      1.22   thorpej  */
    433      1.26       cgd 
    434      1.26       cgd #define	i2o(i)	((i) * 4)
    435      1.26       cgd #define	o2i(o)	((o) / 4)
    436      1.27       cgd #define	onoff(str, bit)							\
    437      1.27       cgd 	printf("      %s: %s\n", (str), (rval & (bit)) ? "on" : "off");
    438      1.26       cgd 
    439      1.26       cgd static void
    440      1.45   thorpej pci_conf_print_common(
    441      1.45   thorpej #ifdef _KERNEL
    442      1.71  christos     pci_chipset_tag_t pc, pcitag_t tag,
    443      1.45   thorpej #endif
    444      1.45   thorpej     const pcireg_t *regs)
    445      1.22   thorpej {
    446      1.59   mycroft 	const char *name;
    447      1.42  jdolecek 	const struct pci_class *classp, *subclassp;
    448      1.26       cgd 	pcireg_t rval;
    449      1.22   thorpej 
    450      1.26       cgd 	rval = regs[o2i(PCI_ID_REG)];
    451      1.59   mycroft 	name = pci_findvendor(rval);
    452      1.59   mycroft 	if (name)
    453      1.59   mycroft 		printf("    Vendor Name: %s (0x%04x)\n", name,
    454      1.26       cgd 		    PCI_VENDOR(rval));
    455      1.22   thorpej 	else
    456      1.26       cgd 		printf("    Vendor ID: 0x%04x\n", PCI_VENDOR(rval));
    457      1.59   mycroft 	name = pci_findproduct(rval);
    458      1.59   mycroft 	if (name)
    459      1.59   mycroft 		printf("    Device Name: %s (0x%04x)\n", name,
    460      1.26       cgd 		    PCI_PRODUCT(rval));
    461      1.22   thorpej 	else
    462      1.26       cgd 		printf("    Device ID: 0x%04x\n", PCI_PRODUCT(rval));
    463      1.22   thorpej 
    464      1.26       cgd 	rval = regs[o2i(PCI_COMMAND_STATUS_REG)];
    465      1.23  drochner 
    466      1.26       cgd 	printf("    Command register: 0x%04x\n", rval & 0xffff);
    467      1.26       cgd 	onoff("I/O space accesses", PCI_COMMAND_IO_ENABLE);
    468      1.26       cgd 	onoff("Memory space accesses", PCI_COMMAND_MEM_ENABLE);
    469      1.26       cgd 	onoff("Bus mastering", PCI_COMMAND_MASTER_ENABLE);
    470      1.26       cgd 	onoff("Special cycles", PCI_COMMAND_SPECIAL_ENABLE);
    471      1.26       cgd 	onoff("MWI transactions", PCI_COMMAND_INVALIDATE_ENABLE);
    472      1.26       cgd 	onoff("Palette snooping", PCI_COMMAND_PALETTE_ENABLE);
    473      1.26       cgd 	onoff("Parity error checking", PCI_COMMAND_PARITY_ENABLE);
    474      1.26       cgd 	onoff("Address/data stepping", PCI_COMMAND_STEPPING_ENABLE);
    475      1.26       cgd 	onoff("System error (SERR)", PCI_COMMAND_SERR_ENABLE);
    476      1.26       cgd 	onoff("Fast back-to-back transactions", PCI_COMMAND_BACKTOBACK_ENABLE);
    477      1.70  drochner 	onoff("Interrupt disable", PCI_COMMAND_INTERRUPT_DISABLE);
    478      1.26       cgd 
    479      1.26       cgd 	printf("    Status register: 0x%04x\n", (rval >> 16) & 0xffff);
    480      1.33    kleink 	onoff("Capability List support", PCI_STATUS_CAPLIST_SUPPORT);
    481      1.26       cgd 	onoff("66 MHz capable", PCI_STATUS_66MHZ_SUPPORT);
    482      1.26       cgd 	onoff("User Definable Features (UDF) support", PCI_STATUS_UDF_SUPPORT);
    483      1.26       cgd 	onoff("Fast back-to-back capable", PCI_STATUS_BACKTOBACK_SUPPORT);
    484      1.26       cgd 	onoff("Data parity error detected", PCI_STATUS_PARITY_ERROR);
    485      1.22   thorpej 
    486      1.26       cgd 	printf("      DEVSEL timing: ");
    487      1.22   thorpej 	switch (rval & PCI_STATUS_DEVSEL_MASK) {
    488      1.22   thorpej 	case PCI_STATUS_DEVSEL_FAST:
    489      1.22   thorpej 		printf("fast");
    490      1.22   thorpej 		break;
    491      1.22   thorpej 	case PCI_STATUS_DEVSEL_MEDIUM:
    492      1.22   thorpej 		printf("medium");
    493      1.22   thorpej 		break;
    494      1.22   thorpej 	case PCI_STATUS_DEVSEL_SLOW:
    495      1.22   thorpej 		printf("slow");
    496      1.22   thorpej 		break;
    497      1.26       cgd 	default:
    498      1.26       cgd 		printf("unknown/reserved");	/* XXX */
    499      1.26       cgd 		break;
    500      1.22   thorpej 	}
    501      1.26       cgd 	printf(" (0x%x)\n", (rval & PCI_STATUS_DEVSEL_MASK) >> 25);
    502      1.22   thorpej 
    503      1.26       cgd 	onoff("Slave signaled Target Abort", PCI_STATUS_TARGET_TARGET_ABORT);
    504      1.26       cgd 	onoff("Master received Target Abort", PCI_STATUS_MASTER_TARGET_ABORT);
    505      1.26       cgd 	onoff("Master received Master Abort", PCI_STATUS_MASTER_ABORT);
    506      1.26       cgd 	onoff("Asserted System Error (SERR)", PCI_STATUS_SPECIAL_ERROR);
    507      1.26       cgd 	onoff("Parity error detected", PCI_STATUS_PARITY_DETECT);
    508      1.22   thorpej 
    509      1.26       cgd 	rval = regs[o2i(PCI_CLASS_REG)];
    510      1.22   thorpej 	for (classp = pci_class; classp->name != NULL; classp++) {
    511      1.22   thorpej 		if (PCI_CLASS(rval) == classp->val)
    512      1.22   thorpej 			break;
    513      1.22   thorpej 	}
    514      1.22   thorpej 	subclassp = (classp->name != NULL) ? classp->subclasses : NULL;
    515      1.22   thorpej 	while (subclassp && subclassp->name != NULL) {
    516      1.22   thorpej 		if (PCI_SUBCLASS(rval) == subclassp->val)
    517      1.22   thorpej 			break;
    518      1.22   thorpej 		subclassp++;
    519      1.22   thorpej 	}
    520      1.22   thorpej 	if (classp->name != NULL) {
    521      1.26       cgd 		printf("    Class Name: %s (0x%02x)\n", classp->name,
    522      1.26       cgd 		    PCI_CLASS(rval));
    523      1.22   thorpej 		if (subclassp != NULL && subclassp->name != NULL)
    524      1.26       cgd 			printf("    Subclass Name: %s (0x%02x)\n",
    525      1.26       cgd 			    subclassp->name, PCI_SUBCLASS(rval));
    526      1.22   thorpej 		else
    527      1.26       cgd 			printf("    Subclass ID: 0x%02x\n", PCI_SUBCLASS(rval));
    528      1.22   thorpej 	} else {
    529      1.26       cgd 		printf("    Class ID: 0x%02x\n", PCI_CLASS(rval));
    530      1.26       cgd 		printf("    Subclass ID: 0x%02x\n", PCI_SUBCLASS(rval));
    531      1.22   thorpej 	}
    532      1.26       cgd 	printf("    Interface: 0x%02x\n", PCI_INTERFACE(rval));
    533      1.26       cgd 	printf("    Revision ID: 0x%02x\n", PCI_REVISION(rval));
    534      1.22   thorpej 
    535      1.26       cgd 	rval = regs[o2i(PCI_BHLC_REG)];
    536      1.26       cgd 	printf("    BIST: 0x%02x\n", PCI_BIST(rval));
    537      1.26       cgd 	printf("    Header Type: 0x%02x%s (0x%02x)\n", PCI_HDRTYPE_TYPE(rval),
    538      1.26       cgd 	    PCI_HDRTYPE_MULTIFN(rval) ? "+multifunction" : "",
    539      1.26       cgd 	    PCI_HDRTYPE(rval));
    540      1.26       cgd 	printf("    Latency Timer: 0x%02x\n", PCI_LATTIMER(rval));
    541      1.26       cgd 	printf("    Cache Line Size: 0x%02x\n", PCI_CACHELINE(rval));
    542      1.26       cgd }
    543      1.22   thorpej 
    544      1.37   nathanw static int
    545      1.45   thorpej pci_conf_print_bar(
    546      1.45   thorpej #ifdef _KERNEL
    547      1.45   thorpej     pci_chipset_tag_t pc, pcitag_t tag,
    548      1.45   thorpej #endif
    549      1.45   thorpej     const pcireg_t *regs, int reg, const char *name
    550      1.45   thorpej #ifdef _KERNEL
    551      1.45   thorpej     , int sizebar
    552      1.45   thorpej #endif
    553      1.45   thorpej     )
    554      1.26       cgd {
    555      1.45   thorpej 	int width;
    556      1.45   thorpej 	pcireg_t rval, rval64h;
    557      1.45   thorpej #ifdef _KERNEL
    558      1.45   thorpej 	int s;
    559      1.45   thorpej 	pcireg_t mask, mask64h;
    560      1.45   thorpej #endif
    561      1.45   thorpej 
    562      1.37   nathanw 	width = 4;
    563      1.22   thorpej 
    564      1.27       cgd 	/*
    565      1.27       cgd 	 * Section 6.2.5.1, `Address Maps', tells us that:
    566      1.27       cgd 	 *
    567      1.27       cgd 	 * 1) The builtin software should have already mapped the
    568      1.27       cgd 	 * device in a reasonable way.
    569      1.27       cgd 	 *
    570      1.27       cgd 	 * 2) A device which wants 2^n bytes of memory will hardwire
    571      1.27       cgd 	 * the bottom n bits of the address to 0.  As recommended,
    572      1.27       cgd 	 * we write all 1s and see what we get back.
    573      1.27       cgd 	 */
    574      1.45   thorpej 
    575      1.27       cgd 	rval = regs[o2i(reg)];
    576      1.45   thorpej 	if (PCI_MAPREG_TYPE(rval) == PCI_MAPREG_TYPE_MEM &&
    577      1.45   thorpej 	    PCI_MAPREG_MEM_TYPE(rval) == PCI_MAPREG_MEM_TYPE_64BIT) {
    578      1.45   thorpej 		rval64h = regs[o2i(reg + 4)];
    579      1.45   thorpej 		width = 8;
    580      1.45   thorpej 	} else
    581      1.45   thorpej 		rval64h = 0;
    582      1.45   thorpej 
    583      1.45   thorpej #ifdef _KERNEL
    584      1.38       cgd 	/* XXX don't size unknown memory type? */
    585      1.38       cgd 	if (rval != 0 && sizebar) {
    586      1.24   thorpej 		/*
    587      1.27       cgd 		 * The following sequence seems to make some devices
    588      1.27       cgd 		 * (e.g. host bus bridges, which don't normally
    589      1.27       cgd 		 * have their space mapped) very unhappy, to
    590      1.27       cgd 		 * the point of crashing the system.
    591      1.24   thorpej 		 *
    592      1.27       cgd 		 * Therefore, if the mapping register is zero to
    593      1.27       cgd 		 * start out with, don't bother trying.
    594      1.24   thorpej 		 */
    595      1.27       cgd 		s = splhigh();
    596      1.27       cgd 		pci_conf_write(pc, tag, reg, 0xffffffff);
    597      1.27       cgd 		mask = pci_conf_read(pc, tag, reg);
    598      1.27       cgd 		pci_conf_write(pc, tag, reg, rval);
    599      1.37   nathanw 		if (PCI_MAPREG_TYPE(rval) == PCI_MAPREG_TYPE_MEM &&
    600      1.37   nathanw 		    PCI_MAPREG_MEM_TYPE(rval) == PCI_MAPREG_MEM_TYPE_64BIT) {
    601      1.37   nathanw 			pci_conf_write(pc, tag, reg + 4, 0xffffffff);
    602      1.37   nathanw 			mask64h = pci_conf_read(pc, tag, reg + 4);
    603      1.37   nathanw 			pci_conf_write(pc, tag, reg + 4, rval64h);
    604      1.54       scw 		} else
    605      1.54       scw 			mask64h = 0;
    606      1.27       cgd 		splx(s);
    607      1.27       cgd 	} else
    608      1.54       scw 		mask = mask64h = 0;
    609      1.45   thorpej #endif /* _KERNEL */
    610      1.27       cgd 
    611      1.28       cgd 	printf("    Base address register at 0x%02x", reg);
    612      1.28       cgd 	if (name)
    613      1.28       cgd 		printf(" (%s)", name);
    614      1.28       cgd 	printf("\n      ");
    615      1.27       cgd 	if (rval == 0) {
    616      1.27       cgd 		printf("not implemented(?)\n");
    617      1.37   nathanw 		return width;
    618      1.60     perry 	}
    619      1.28       cgd 	printf("type: ");
    620      1.28       cgd 	if (PCI_MAPREG_TYPE(rval) == PCI_MAPREG_TYPE_MEM) {
    621      1.34  drochner 		const char *type, *prefetch;
    622      1.27       cgd 
    623      1.27       cgd 		switch (PCI_MAPREG_MEM_TYPE(rval)) {
    624      1.27       cgd 		case PCI_MAPREG_MEM_TYPE_32BIT:
    625      1.27       cgd 			type = "32-bit";
    626      1.27       cgd 			break;
    627      1.27       cgd 		case PCI_MAPREG_MEM_TYPE_32BIT_1M:
    628      1.27       cgd 			type = "32-bit-1M";
    629      1.27       cgd 			break;
    630      1.27       cgd 		case PCI_MAPREG_MEM_TYPE_64BIT:
    631      1.27       cgd 			type = "64-bit";
    632      1.27       cgd 			break;
    633      1.27       cgd 		default:
    634      1.27       cgd 			type = "unknown (XXX)";
    635      1.27       cgd 			break;
    636      1.22   thorpej 		}
    637      1.34  drochner 		if (PCI_MAPREG_MEM_PREFETCHABLE(rval))
    638      1.34  drochner 			prefetch = "";
    639      1.27       cgd 		else
    640      1.34  drochner 			prefetch = "non";
    641      1.34  drochner 		printf("%s %sprefetchable memory\n", type, prefetch);
    642      1.37   nathanw 		switch (PCI_MAPREG_MEM_TYPE(rval)) {
    643      1.37   nathanw 		case PCI_MAPREG_MEM_TYPE_64BIT:
    644      1.38       cgd 			printf("      base: 0x%016llx, ",
    645      1.37   nathanw 			    PCI_MAPREG_MEM64_ADDR(
    646      1.38       cgd 				((((long long) rval64h) << 32) | rval)));
    647      1.45   thorpej #ifdef _KERNEL
    648      1.38       cgd 			if (sizebar)
    649      1.38       cgd 				printf("size: 0x%016llx",
    650      1.38       cgd 				    PCI_MAPREG_MEM64_SIZE(
    651      1.38       cgd 				      ((((long long) mask64h) << 32) | mask)));
    652      1.38       cgd 			else
    653      1.45   thorpej #endif /* _KERNEL */
    654      1.38       cgd 				printf("not sized");
    655      1.38       cgd 			printf("\n");
    656      1.37   nathanw 			break;
    657      1.37   nathanw 		case PCI_MAPREG_MEM_TYPE_32BIT:
    658      1.37   nathanw 		case PCI_MAPREG_MEM_TYPE_32BIT_1M:
    659      1.37   nathanw 		default:
    660      1.38       cgd 			printf("      base: 0x%08x, ",
    661      1.38       cgd 			    PCI_MAPREG_MEM_ADDR(rval));
    662      1.45   thorpej #ifdef _KERNEL
    663      1.38       cgd 			if (sizebar)
    664      1.38       cgd 				printf("size: 0x%08x",
    665      1.38       cgd 				    PCI_MAPREG_MEM_SIZE(mask));
    666      1.38       cgd 			else
    667      1.45   thorpej #endif /* _KERNEL */
    668      1.38       cgd 				printf("not sized");
    669      1.38       cgd 			printf("\n");
    670      1.37   nathanw 			break;
    671      1.37   nathanw 		}
    672      1.27       cgd 	} else {
    673      1.45   thorpej #ifdef _KERNEL
    674      1.38       cgd 		if (sizebar)
    675      1.38       cgd 			printf("%d-bit ", mask & ~0x0000ffff ? 32 : 16);
    676      1.45   thorpej #endif /* _KERNEL */
    677      1.27       cgd 		printf("i/o\n");
    678      1.38       cgd 		printf("      base: 0x%08x, ", PCI_MAPREG_IO_ADDR(rval));
    679      1.45   thorpej #ifdef _KERNEL
    680      1.38       cgd 		if (sizebar)
    681      1.38       cgd 			printf("size: 0x%08x", PCI_MAPREG_IO_SIZE(mask));
    682      1.38       cgd 		else
    683      1.45   thorpej #endif /* _KERNEL */
    684      1.38       cgd 			printf("not sized");
    685      1.38       cgd 		printf("\n");
    686      1.22   thorpej 	}
    687      1.37   nathanw 
    688      1.37   nathanw 	return width;
    689      1.27       cgd }
    690      1.28       cgd 
    691      1.28       cgd static void
    692      1.44   thorpej pci_conf_print_regs(const pcireg_t *regs, int first, int pastlast)
    693      1.28       cgd {
    694      1.28       cgd 	int off, needaddr, neednl;
    695      1.28       cgd 
    696      1.28       cgd 	needaddr = 1;
    697      1.28       cgd 	neednl = 0;
    698      1.28       cgd 	for (off = first; off < pastlast; off += 4) {
    699      1.28       cgd 		if ((off % 16) == 0 || needaddr) {
    700      1.28       cgd 			printf("    0x%02x:", off);
    701      1.28       cgd 			needaddr = 0;
    702      1.28       cgd 		}
    703      1.28       cgd 		printf(" 0x%08x", regs[o2i(off)]);
    704      1.28       cgd 		neednl = 1;
    705      1.28       cgd 		if ((off % 16) == 12) {
    706      1.28       cgd 			printf("\n");
    707      1.28       cgd 			neednl = 0;
    708      1.28       cgd 		}
    709      1.28       cgd 	}
    710      1.28       cgd 	if (neednl)
    711      1.28       cgd 		printf("\n");
    712      1.28       cgd }
    713      1.28       cgd 
    714      1.27       cgd static void
    715      1.45   thorpej pci_conf_print_type0(
    716      1.45   thorpej #ifdef _KERNEL
    717      1.45   thorpej     pci_chipset_tag_t pc, pcitag_t tag,
    718      1.45   thorpej #endif
    719      1.45   thorpej     const pcireg_t *regs
    720      1.45   thorpej #ifdef _KERNEL
    721      1.45   thorpej     , int sizebars
    722      1.45   thorpej #endif
    723      1.45   thorpej     )
    724      1.27       cgd {
    725      1.37   nathanw 	int off, width;
    726      1.27       cgd 	pcireg_t rval;
    727      1.27       cgd 
    728      1.45   thorpej 	for (off = PCI_MAPREG_START; off < PCI_MAPREG_END; off += width) {
    729      1.45   thorpej #ifdef _KERNEL
    730      1.38       cgd 		width = pci_conf_print_bar(pc, tag, regs, off, NULL, sizebars);
    731      1.45   thorpej #else
    732      1.45   thorpej 		width = pci_conf_print_bar(regs, off, NULL);
    733      1.45   thorpej #endif
    734      1.45   thorpej 	}
    735      1.22   thorpej 
    736      1.26       cgd 	printf("    Cardbus CIS Pointer: 0x%08x\n", regs[o2i(0x28)]);
    737      1.22   thorpej 
    738      1.31  drochner 	rval = regs[o2i(PCI_SUBSYS_ID_REG)];
    739      1.26       cgd 	printf("    Subsystem vendor ID: 0x%04x\n", PCI_VENDOR(rval));
    740      1.26       cgd 	printf("    Subsystem ID: 0x%04x\n", PCI_PRODUCT(rval));
    741      1.26       cgd 
    742      1.26       cgd 	/* XXX */
    743      1.26       cgd 	printf("    Expansion ROM Base Address: 0x%08x\n", regs[o2i(0x30)]);
    744      1.33    kleink 
    745      1.33    kleink 	if (regs[o2i(PCI_COMMAND_STATUS_REG)] & PCI_STATUS_CAPLIST_SUPPORT)
    746      1.33    kleink 		printf("    Capability list pointer: 0x%02x\n",
    747      1.33    kleink 		    PCI_CAPLIST_PTR(regs[o2i(PCI_CAPLISTPTR_REG)]));
    748      1.33    kleink 	else
    749      1.33    kleink 		printf("    Reserved @ 0x34: 0x%08x\n", regs[o2i(0x34)]);
    750      1.33    kleink 
    751      1.26       cgd 	printf("    Reserved @ 0x38: 0x%08x\n", regs[o2i(0x38)]);
    752      1.26       cgd 
    753      1.26       cgd 	rval = regs[o2i(PCI_INTERRUPT_REG)];
    754      1.26       cgd 	printf("    Maximum Latency: 0x%02x\n", (rval >> 24) & 0xff);
    755      1.26       cgd 	printf("    Minimum Grant: 0x%02x\n", (rval >> 16) & 0xff);
    756      1.27       cgd 	printf("    Interrupt pin: 0x%02x ", PCI_INTERRUPT_PIN(rval));
    757      1.22   thorpej 	switch (PCI_INTERRUPT_PIN(rval)) {
    758      1.22   thorpej 	case PCI_INTERRUPT_PIN_NONE:
    759      1.27       cgd 		printf("(none)");
    760      1.22   thorpej 		break;
    761      1.22   thorpej 	case PCI_INTERRUPT_PIN_A:
    762      1.27       cgd 		printf("(pin A)");
    763      1.22   thorpej 		break;
    764      1.22   thorpej 	case PCI_INTERRUPT_PIN_B:
    765      1.27       cgd 		printf("(pin B)");
    766      1.22   thorpej 		break;
    767      1.22   thorpej 	case PCI_INTERRUPT_PIN_C:
    768      1.27       cgd 		printf("(pin C)");
    769      1.22   thorpej 		break;
    770      1.22   thorpej 	case PCI_INTERRUPT_PIN_D:
    771      1.27       cgd 		printf("(pin D)");
    772      1.27       cgd 		break;
    773      1.27       cgd 	default:
    774      1.36       mrg 		printf("(? ? ?)");
    775      1.22   thorpej 		break;
    776      1.22   thorpej 	}
    777      1.22   thorpej 	printf("\n");
    778      1.26       cgd 	printf("    Interrupt line: 0x%02x\n", PCI_INTERRUPT_LINE(rval));
    779      1.51  drochner }
    780      1.51  drochner 
    781      1.51  drochner static void
    782      1.72     joerg pci_conf_print_pcie_cap(const pcireg_t *regs, int capoff)
    783      1.72     joerg {
    784      1.72     joerg 	bool check_slot = false;
    785      1.72     joerg 
    786      1.72     joerg 	printf("\n  PCI Express Capabilities Register\n");
    787      1.72     joerg 	printf("    Capability version: %x\n",
    788      1.72     joerg 	    (unsigned int)((regs[o2i(capoff)] & 0x000f0000) >> 16));
    789      1.72     joerg 	printf("    Device type: ");
    790      1.72     joerg 	switch ((regs[o2i(capoff)] & 0x00f00000) >> 20) {
    791      1.72     joerg 	case 0x0:
    792      1.72     joerg 		printf("PCI Express Endpoint device\n");
    793      1.72     joerg 		break;
    794      1.72     joerg 	case 0x1:
    795      1.75  jmcneill 		printf("Legacy PCI Express Endpoint device\n");
    796      1.72     joerg 		break;
    797      1.72     joerg 	case 0x4:
    798      1.72     joerg 		printf("Root Port of PCI Express Root Complex\n");
    799      1.72     joerg 		check_slot = true;
    800      1.72     joerg 		break;
    801      1.72     joerg 	case 0x5:
    802      1.72     joerg 		printf("Upstream Port of PCI Express Switch\n");
    803      1.72     joerg 		break;
    804      1.72     joerg 	case 0x6:
    805      1.72     joerg 		printf("Downstream Port of PCI Express Switch\n");
    806      1.72     joerg 		check_slot = true;
    807      1.72     joerg 		break;
    808      1.72     joerg 	case 0x7:
    809      1.72     joerg 		printf("PCI Express to PCI/PCI-X Bridge\n");
    810      1.72     joerg 		break;
    811      1.72     joerg 	case 0x8:
    812      1.72     joerg 		printf("PCI/PCI-X to PCI Express Bridge\n");
    813      1.72     joerg 		break;
    814      1.72     joerg 	default:
    815      1.72     joerg 		printf("unknown\n");
    816      1.72     joerg 		break;
    817      1.72     joerg 	}
    818      1.72     joerg 	if (check_slot && (regs[o2i(capoff)] & 0x01000000) != 0)
    819      1.72     joerg 		printf("    Slot implemented\n");
    820      1.72     joerg 	printf("    Interrupt Message Number: %x\n",
    821      1.72     joerg 	    (unsigned int)((regs[o2i(capoff)] & 0x4e000000) >> 27));
    822      1.72     joerg 	if ((regs[o2i(capoff + 0x18)] & 0x07ff) != 0) {
    823      1.72     joerg 		printf("    Slot Control Register:\n");
    824      1.72     joerg 		if ((regs[o2i(capoff + 0x18)] & 0x0001) != 0)
    825      1.72     joerg 			printf("      Attention Button Pressed Enabled\n");
    826      1.72     joerg 		if ((regs[o2i(capoff + 0x18)] & 0x0002) != 0)
    827      1.72     joerg 			printf("      Power Fault Detected Enabled\n");
    828      1.72     joerg 		if ((regs[o2i(capoff + 0x18)] & 0x0004) != 0)
    829      1.72     joerg 			printf("      MRL Sensor Changed Enabled\n");
    830      1.72     joerg 		if ((regs[o2i(capoff + 0x18)] & 0x0008) != 0)
    831      1.72     joerg 			printf("      Presense Detected Changed Enabled\n");
    832      1.72     joerg 		if ((regs[o2i(capoff + 0x18)] & 0x0010) != 0)
    833      1.72     joerg 			printf("      Command Completed Interrupt Enabled\n");
    834      1.72     joerg 		if ((regs[o2i(capoff + 0x18)] & 0x0020) != 0)
    835      1.72     joerg 			printf("      Hot-Plug Interrupt Enabled\n");
    836      1.78  drochner 		printf("      Attention Indicator Control: ");
    837      1.78  drochner 		switch ((regs[o2i(capoff + 0x18)] & 0x00c0) >> 6) {
    838      1.72     joerg 		case 0x0:
    839      1.72     joerg 			printf("reserved\n");
    840      1.72     joerg 			break;
    841      1.72     joerg 		case 0x1:
    842      1.72     joerg 			printf("on\n");
    843      1.72     joerg 			break;
    844      1.72     joerg 		case 0x2:
    845      1.72     joerg 			printf("blink\n");
    846      1.72     joerg 			break;
    847      1.72     joerg 		case 0x3:
    848      1.72     joerg 			printf("off\n");
    849      1.72     joerg 			break;
    850      1.72     joerg 		}
    851      1.78  drochner 		printf("      Power Indicator Control: ");
    852      1.72     joerg 		switch ((regs[o2i(capoff + 0x18)] & 0x0300) >> 8) {
    853      1.72     joerg 		case 0x0:
    854      1.72     joerg 			printf("reserved\n");
    855      1.72     joerg 			break;
    856      1.72     joerg 		case 0x1:
    857      1.72     joerg 			printf("on\n");
    858      1.72     joerg 			break;
    859      1.72     joerg 		case 0x2:
    860      1.72     joerg 			printf("blink\n");
    861      1.72     joerg 			break;
    862      1.72     joerg 		case 0x3:
    863      1.72     joerg 			printf("off\n");
    864      1.72     joerg 			break;
    865      1.72     joerg 		}
    866      1.72     joerg 		printf("      Power Controller Control: ");
    867      1.72     joerg 		if ((regs[o2i(capoff + 0x18)] & 0x0400) != 0)
    868      1.72     joerg 			printf("off\n");
    869      1.72     joerg 		else
    870      1.72     joerg 			printf("on\n");
    871      1.72     joerg 	}
    872      1.72     joerg }
    873      1.72     joerg 
    874      1.77  jmcneill static const char *
    875      1.77  jmcneill pci_conf_print_pcipm_cap_aux(uint16_t caps)
    876      1.77  jmcneill {
    877      1.77  jmcneill 	switch ((caps >> 6) & 7) {
    878      1.77  jmcneill 	case 0:	return "self-powered";
    879      1.77  jmcneill 	case 1: return "55 mA";
    880      1.77  jmcneill 	case 2: return "100 mA";
    881      1.77  jmcneill 	case 3: return "160 mA";
    882      1.77  jmcneill 	case 4: return "220 mA";
    883      1.77  jmcneill 	case 5: return "270 mA";
    884      1.77  jmcneill 	case 6: return "320 mA";
    885      1.77  jmcneill 	case 7:
    886      1.77  jmcneill 	default: return "375 mA";
    887      1.77  jmcneill 	}
    888      1.77  jmcneill }
    889      1.77  jmcneill 
    890      1.77  jmcneill static const char *
    891      1.77  jmcneill pci_conf_print_pcipm_cap_pmrev(uint8_t val)
    892      1.77  jmcneill {
    893      1.77  jmcneill 	static const char unk[] = "unknown";
    894      1.77  jmcneill 	static const char *pmrev[8] = {
    895      1.77  jmcneill 		unk, "1.0", "1.1", "1.2", unk, unk, unk, unk
    896      1.77  jmcneill 	};
    897      1.77  jmcneill 	if (val > 7)
    898      1.77  jmcneill 		return unk;
    899      1.77  jmcneill 	return pmrev[val];
    900      1.77  jmcneill }
    901      1.77  jmcneill 
    902      1.77  jmcneill static void
    903      1.77  jmcneill pci_conf_print_pcipm_cap(const pcireg_t *regs, int capoff)
    904      1.77  jmcneill {
    905      1.77  jmcneill 	uint16_t caps, pmcsr;
    906      1.77  jmcneill 
    907      1.77  jmcneill 	caps = regs[o2i(capoff)] >> 16;
    908      1.77  jmcneill 	pmcsr = regs[o2i(capoff + 0x04)] & 0xffff;
    909      1.77  jmcneill 
    910      1.77  jmcneill 	printf("\n  PCI Power Management Capabilities Register\n");
    911      1.77  jmcneill 
    912      1.77  jmcneill 	printf("    Capabilities register: 0x%04x\n", caps);
    913      1.77  jmcneill 	printf("      Version: %s\n",
    914      1.77  jmcneill 	    pci_conf_print_pcipm_cap_pmrev(caps & 0x3));
    915      1.77  jmcneill 	printf("      PME# clock: %s\n", caps & 0x4 ? "on" : "off");
    916      1.77  jmcneill 	printf("      Device specific initialization: %s\n",
    917      1.77  jmcneill 	    caps & 0x20 ? "on" : "off");
    918      1.77  jmcneill 	printf("      3.3V auxiliary current: %s\n",
    919      1.77  jmcneill 	    pci_conf_print_pcipm_cap_aux(caps));
    920      1.77  jmcneill 	printf("      D1 power management state support: %s\n",
    921      1.77  jmcneill 	    (caps >> 9) & 1 ? "on" : "off");
    922      1.77  jmcneill 	printf("      D2 power management state support: %s\n",
    923      1.77  jmcneill 	    (caps >> 10) & 1 ? "on" : "off");
    924      1.77  jmcneill 	printf("      PME# support: 0x%02x\n", caps >> 11);
    925      1.77  jmcneill 
    926      1.77  jmcneill 	printf("    Control/status register: 0x%04x\n", pmcsr);
    927      1.77  jmcneill 	printf("      Power state: D%d\n", pmcsr & 3);
    928      1.77  jmcneill 	printf("      PCI Express reserved: %s\n",
    929      1.77  jmcneill 	    (pmcsr >> 2) & 1 ? "on" : "off");
    930      1.77  jmcneill 	printf("      No soft reset: %s\n", (pmcsr >> 3) & 1 ? "on" : "off");
    931      1.77  jmcneill 	printf("      PME# assertion %sabled\n",
    932      1.77  jmcneill 	    (pmcsr >> 8) & 1 ? "en" : "dis");
    933      1.77  jmcneill 	printf("      PME# status: %s\n", (pmcsr >> 15) ? "on" : "off");
    934      1.77  jmcneill }
    935      1.77  jmcneill 
    936      1.72     joerg static void
    937      1.51  drochner pci_conf_print_caplist(
    938      1.51  drochner #ifdef _KERNEL
    939      1.71  christos     pci_chipset_tag_t pc, pcitag_t tag,
    940      1.51  drochner #endif
    941      1.52  drochner     const pcireg_t *regs, int capoff)
    942      1.51  drochner {
    943      1.51  drochner 	int off;
    944      1.51  drochner 	pcireg_t rval;
    945      1.77  jmcneill 	int pcie_off = -1, pcipm_off = -1;
    946      1.33    kleink 
    947      1.52  drochner 	for (off = PCI_CAPLIST_PTR(regs[o2i(capoff)]);
    948      1.51  drochner 	     off != 0;
    949      1.51  drochner 	     off = PCI_CAPLIST_NEXT(regs[o2i(off)])) {
    950      1.51  drochner 		rval = regs[o2i(off)];
    951      1.51  drochner 		printf("  Capability register at 0x%02x\n", off);
    952      1.51  drochner 
    953      1.51  drochner 		printf("    type: 0x%02x (", PCI_CAPLIST_CAP(rval));
    954      1.51  drochner 		switch (PCI_CAPLIST_CAP(rval)) {
    955      1.51  drochner 		case PCI_CAP_RESERVED0:
    956      1.51  drochner 			printf("reserved");
    957      1.51  drochner 			break;
    958      1.51  drochner 		case PCI_CAP_PWRMGMT:
    959      1.64  drochner 			printf("Power Management, rev. %s",
    960      1.77  jmcneill 			    pci_conf_print_pcipm_cap_pmrev((rval >> 0) & 0x07));
    961      1.77  jmcneill 			pcipm_off = off;
    962      1.51  drochner 			break;
    963      1.51  drochner 		case PCI_CAP_AGP:
    964      1.51  drochner 			printf("AGP, rev. %d.%d",
    965      1.57     soren 				PCI_CAP_AGP_MAJOR(rval),
    966      1.57     soren 				PCI_CAP_AGP_MINOR(rval));
    967      1.51  drochner 			break;
    968      1.51  drochner 		case PCI_CAP_VPD:
    969      1.51  drochner 			printf("VPD");
    970      1.51  drochner 			break;
    971      1.51  drochner 		case PCI_CAP_SLOTID:
    972      1.51  drochner 			printf("SlotID");
    973      1.51  drochner 			break;
    974      1.51  drochner 		case PCI_CAP_MSI:
    975      1.51  drochner 			printf("MSI");
    976      1.51  drochner 			break;
    977      1.51  drochner 		case PCI_CAP_CPCI_HOTSWAP:
    978      1.51  drochner 			printf("CompactPCI Hot-swapping");
    979      1.51  drochner 			break;
    980      1.51  drochner 		case PCI_CAP_PCIX:
    981      1.51  drochner 			printf("PCI-X");
    982      1.51  drochner 			break;
    983      1.51  drochner 		case PCI_CAP_LDT:
    984      1.51  drochner 			printf("LDT");
    985      1.51  drochner 			break;
    986      1.51  drochner 		case PCI_CAP_VENDSPEC:
    987      1.51  drochner 			printf("Vendor-specific");
    988      1.51  drochner 			break;
    989      1.51  drochner 		case PCI_CAP_DEBUGPORT:
    990      1.51  drochner 			printf("Debug Port");
    991      1.51  drochner 			break;
    992      1.51  drochner 		case PCI_CAP_CPCI_RSRCCTL:
    993      1.51  drochner 			printf("CompactPCI Resource Control");
    994      1.51  drochner 			break;
    995      1.51  drochner 		case PCI_CAP_HOTPLUG:
    996      1.51  drochner 			printf("Hot-Plug");
    997      1.51  drochner 			break;
    998      1.51  drochner 		case PCI_CAP_AGP8:
    999      1.51  drochner 			printf("AGP 8x");
   1000      1.51  drochner 			break;
   1001      1.51  drochner 		case PCI_CAP_SECURE:
   1002      1.51  drochner 			printf("Secure Device");
   1003      1.51  drochner 			break;
   1004      1.51  drochner 		case PCI_CAP_PCIEXPRESS:
   1005      1.51  drochner 			printf("PCI Express");
   1006      1.72     joerg 			pcie_off = off;
   1007      1.51  drochner 			break;
   1008      1.51  drochner 		case PCI_CAP_MSIX:
   1009      1.51  drochner 			printf("MSI-X");
   1010      1.51  drochner 			break;
   1011      1.51  drochner 		default:
   1012      1.51  drochner 			printf("unknown");
   1013      1.33    kleink 		}
   1014      1.51  drochner 		printf(")\n");
   1015      1.33    kleink 	}
   1016      1.77  jmcneill 	if (pcipm_off != -1)
   1017      1.77  jmcneill 		pci_conf_print_pcipm_cap(regs, pcipm_off);
   1018      1.72     joerg 	if (pcie_off != -1)
   1019      1.72     joerg 		pci_conf_print_pcie_cap(regs, pcie_off);
   1020      1.26       cgd }
   1021      1.26       cgd 
   1022  1.78.2.1  uebayasi /* Print the Secondary Status Register. */
   1023  1.78.2.1  uebayasi static void
   1024  1.78.2.1  uebayasi pci_conf_print_ssr(pcireg_t rval)
   1025  1.78.2.1  uebayasi {
   1026  1.78.2.1  uebayasi 	pcireg_t devsel;
   1027  1.78.2.1  uebayasi 
   1028  1.78.2.1  uebayasi 	printf("    Secondary status register: 0x%04x\n", rval); /* XXX bits */
   1029  1.78.2.1  uebayasi 	onoff("66 MHz capable", __BIT(5));
   1030  1.78.2.1  uebayasi 	onoff("User Definable Features (UDF) support", __BIT(6));
   1031  1.78.2.1  uebayasi 	onoff("Fast back-to-back capable", __BIT(7));
   1032  1.78.2.1  uebayasi 	onoff("Data parity error detected", __BIT(8));
   1033  1.78.2.1  uebayasi 
   1034  1.78.2.1  uebayasi 	printf("      DEVSEL timing: ");
   1035  1.78.2.1  uebayasi 	devsel = __SHIFTOUT(rval, __BITS(10, 9));
   1036  1.78.2.1  uebayasi 	switch (devsel) {
   1037  1.78.2.1  uebayasi 	case 0:
   1038  1.78.2.1  uebayasi 		printf("fast");
   1039  1.78.2.1  uebayasi 		break;
   1040  1.78.2.1  uebayasi 	case 1:
   1041  1.78.2.1  uebayasi 		printf("medium");
   1042  1.78.2.1  uebayasi 		break;
   1043  1.78.2.1  uebayasi 	case 2:
   1044  1.78.2.1  uebayasi 		printf("slow");
   1045  1.78.2.1  uebayasi 		break;
   1046  1.78.2.1  uebayasi 	default:
   1047  1.78.2.1  uebayasi 		printf("unknown/reserved");	/* XXX */
   1048  1.78.2.1  uebayasi 		break;
   1049  1.78.2.1  uebayasi 	}
   1050  1.78.2.1  uebayasi 	printf(" (0x%x)\n", devsel);
   1051  1.78.2.1  uebayasi 
   1052  1.78.2.1  uebayasi 	onoff("Signalled target abort", __BIT(11));
   1053  1.78.2.1  uebayasi 	onoff("Received target abort", __BIT(12));
   1054  1.78.2.1  uebayasi 	onoff("Received master abort", __BIT(13));
   1055  1.78.2.1  uebayasi 	onoff("Received system error", __BIT(14));
   1056  1.78.2.1  uebayasi 	onoff("Detected parity error", __BIT(15));
   1057  1.78.2.1  uebayasi }
   1058  1.78.2.1  uebayasi 
   1059      1.27       cgd static void
   1060      1.45   thorpej pci_conf_print_type1(
   1061      1.45   thorpej #ifdef _KERNEL
   1062      1.45   thorpej     pci_chipset_tag_t pc, pcitag_t tag,
   1063      1.45   thorpej #endif
   1064      1.45   thorpej     const pcireg_t *regs
   1065      1.45   thorpej #ifdef _KERNEL
   1066      1.45   thorpej     , int sizebars
   1067      1.45   thorpej #endif
   1068      1.45   thorpej     )
   1069      1.27       cgd {
   1070      1.37   nathanw 	int off, width;
   1071      1.27       cgd 	pcireg_t rval;
   1072      1.27       cgd 
   1073      1.27       cgd 	/*
   1074      1.27       cgd 	 * XXX these need to be printed in more detail, need to be
   1075      1.27       cgd 	 * XXX checked against specs/docs, etc.
   1076      1.27       cgd 	 *
   1077      1.27       cgd 	 * This layout was cribbed from the TI PCI2030 PCI-to-PCI
   1078      1.27       cgd 	 * Bridge chip documentation, and may not be correct with
   1079      1.27       cgd 	 * respect to various standards. (XXX)
   1080      1.27       cgd 	 */
   1081      1.27       cgd 
   1082      1.45   thorpej 	for (off = 0x10; off < 0x18; off += width) {
   1083      1.45   thorpej #ifdef _KERNEL
   1084      1.38       cgd 		width = pci_conf_print_bar(pc, tag, regs, off, NULL, sizebars);
   1085      1.45   thorpej #else
   1086      1.45   thorpej 		width = pci_conf_print_bar(regs, off, NULL);
   1087      1.45   thorpej #endif
   1088      1.45   thorpej 	}
   1089      1.27       cgd 
   1090      1.27       cgd 	printf("    Primary bus number: 0x%02x\n",
   1091      1.27       cgd 	    (regs[o2i(0x18)] >> 0) & 0xff);
   1092      1.27       cgd 	printf("    Secondary bus number: 0x%02x\n",
   1093      1.27       cgd 	    (regs[o2i(0x18)] >> 8) & 0xff);
   1094      1.27       cgd 	printf("    Subordinate bus number: 0x%02x\n",
   1095      1.27       cgd 	    (regs[o2i(0x18)] >> 16) & 0xff);
   1096      1.27       cgd 	printf("    Secondary bus latency timer: 0x%02x\n",
   1097      1.27       cgd 	    (regs[o2i(0x18)] >> 24) & 0xff);
   1098      1.27       cgd 
   1099  1.78.2.1  uebayasi 	pci_conf_print_ssr(__SHIFTOUT(regs[o2i(0x1c)], __BITS(31, 16)));
   1100      1.27       cgd 
   1101      1.27       cgd 	/* XXX Print more prettily */
   1102      1.27       cgd 	printf("    I/O region:\n");
   1103      1.27       cgd 	printf("      base register:  0x%02x\n", (regs[o2i(0x1c)] >> 0) & 0xff);
   1104      1.27       cgd 	printf("      limit register: 0x%02x\n", (regs[o2i(0x1c)] >> 8) & 0xff);
   1105      1.27       cgd 	printf("      base upper 16 bits register:  0x%04x\n",
   1106      1.27       cgd 	    (regs[o2i(0x30)] >> 0) & 0xffff);
   1107      1.27       cgd 	printf("      limit upper 16 bits register: 0x%04x\n",
   1108      1.27       cgd 	    (regs[o2i(0x30)] >> 16) & 0xffff);
   1109      1.27       cgd 
   1110      1.27       cgd 	/* XXX Print more prettily */
   1111      1.27       cgd 	printf("    Memory region:\n");
   1112      1.27       cgd 	printf("      base register:  0x%04x\n",
   1113      1.27       cgd 	    (regs[o2i(0x20)] >> 0) & 0xffff);
   1114      1.27       cgd 	printf("      limit register: 0x%04x\n",
   1115      1.27       cgd 	    (regs[o2i(0x20)] >> 16) & 0xffff);
   1116      1.27       cgd 
   1117      1.27       cgd 	/* XXX Print more prettily */
   1118      1.27       cgd 	printf("    Prefetchable memory region:\n");
   1119      1.27       cgd 	printf("      base register:  0x%04x\n",
   1120      1.27       cgd 	    (regs[o2i(0x24)] >> 0) & 0xffff);
   1121      1.27       cgd 	printf("      limit register: 0x%04x\n",
   1122      1.27       cgd 	    (regs[o2i(0x24)] >> 16) & 0xffff);
   1123      1.27       cgd 	printf("      base upper 32 bits register:  0x%08x\n", regs[o2i(0x28)]);
   1124      1.27       cgd 	printf("      limit upper 32 bits register: 0x%08x\n", regs[o2i(0x2c)]);
   1125      1.27       cgd 
   1126      1.53  drochner 	if (regs[o2i(PCI_COMMAND_STATUS_REG)] & PCI_STATUS_CAPLIST_SUPPORT)
   1127      1.53  drochner 		printf("    Capability list pointer: 0x%02x\n",
   1128      1.53  drochner 		    PCI_CAPLIST_PTR(regs[o2i(PCI_CAPLISTPTR_REG)]));
   1129      1.53  drochner 	else
   1130      1.53  drochner 		printf("    Reserved @ 0x34: 0x%08x\n", regs[o2i(0x34)]);
   1131      1.53  drochner 
   1132      1.27       cgd 	/* XXX */
   1133      1.27       cgd 	printf("    Expansion ROM Base Address: 0x%08x\n", regs[o2i(0x38)]);
   1134      1.27       cgd 
   1135      1.27       cgd 	printf("    Interrupt line: 0x%02x\n",
   1136      1.27       cgd 	    (regs[o2i(0x3c)] >> 0) & 0xff);
   1137      1.27       cgd 	printf("    Interrupt pin: 0x%02x ",
   1138      1.27       cgd 	    (regs[o2i(0x3c)] >> 8) & 0xff);
   1139      1.27       cgd 	switch ((regs[o2i(0x3c)] >> 8) & 0xff) {
   1140      1.27       cgd 	case PCI_INTERRUPT_PIN_NONE:
   1141      1.27       cgd 		printf("(none)");
   1142      1.27       cgd 		break;
   1143      1.27       cgd 	case PCI_INTERRUPT_PIN_A:
   1144      1.27       cgd 		printf("(pin A)");
   1145      1.27       cgd 		break;
   1146      1.27       cgd 	case PCI_INTERRUPT_PIN_B:
   1147      1.27       cgd 		printf("(pin B)");
   1148      1.27       cgd 		break;
   1149      1.27       cgd 	case PCI_INTERRUPT_PIN_C:
   1150      1.27       cgd 		printf("(pin C)");
   1151      1.27       cgd 		break;
   1152      1.27       cgd 	case PCI_INTERRUPT_PIN_D:
   1153      1.27       cgd 		printf("(pin D)");
   1154      1.27       cgd 		break;
   1155      1.27       cgd 	default:
   1156      1.36       mrg 		printf("(? ? ?)");
   1157      1.27       cgd 		break;
   1158      1.27       cgd 	}
   1159      1.27       cgd 	printf("\n");
   1160      1.27       cgd 	rval = (regs[o2i(0x3c)] >> 16) & 0xffff;
   1161      1.27       cgd 	printf("    Bridge control register: 0x%04x\n", rval); /* XXX bits */
   1162      1.27       cgd 	onoff("Parity error response", 0x0001);
   1163      1.27       cgd 	onoff("Secondary SERR forwarding", 0x0002);
   1164      1.27       cgd 	onoff("ISA enable", 0x0004);
   1165      1.27       cgd 	onoff("VGA enable", 0x0008);
   1166      1.27       cgd 	onoff("Master abort reporting", 0x0020);
   1167      1.27       cgd 	onoff("Secondary bus reset", 0x0040);
   1168      1.27       cgd 	onoff("Fast back-to-back capable", 0x0080);
   1169      1.27       cgd }
   1170      1.27       cgd 
   1171      1.27       cgd static void
   1172      1.45   thorpej pci_conf_print_type2(
   1173      1.45   thorpej #ifdef _KERNEL
   1174      1.45   thorpej     pci_chipset_tag_t pc, pcitag_t tag,
   1175      1.45   thorpej #endif
   1176      1.45   thorpej     const pcireg_t *regs
   1177      1.45   thorpej #ifdef _KERNEL
   1178      1.45   thorpej     , int sizebars
   1179      1.45   thorpej #endif
   1180      1.45   thorpej     )
   1181      1.27       cgd {
   1182      1.27       cgd 	pcireg_t rval;
   1183      1.27       cgd 
   1184      1.27       cgd 	/*
   1185      1.27       cgd 	 * XXX these need to be printed in more detail, need to be
   1186      1.27       cgd 	 * XXX checked against specs/docs, etc.
   1187      1.27       cgd 	 *
   1188  1.78.2.1  uebayasi 	 * This layout was cribbed from the TI PCI1420 PCI-to-CardBus
   1189      1.27       cgd 	 * controller chip documentation, and may not be correct with
   1190      1.27       cgd 	 * respect to various standards. (XXX)
   1191      1.27       cgd 	 */
   1192      1.27       cgd 
   1193      1.45   thorpej #ifdef _KERNEL
   1194      1.28       cgd 	pci_conf_print_bar(pc, tag, regs, 0x10,
   1195      1.38       cgd 	    "CardBus socket/ExCA registers", sizebars);
   1196      1.45   thorpej #else
   1197      1.45   thorpej 	pci_conf_print_bar(regs, 0x10, "CardBus socket/ExCA registers");
   1198      1.45   thorpej #endif
   1199      1.27       cgd 
   1200      1.53  drochner 	if (regs[o2i(PCI_COMMAND_STATUS_REG)] & PCI_STATUS_CAPLIST_SUPPORT)
   1201      1.53  drochner 		printf("    Capability list pointer: 0x%02x\n",
   1202      1.53  drochner 		    PCI_CAPLIST_PTR(regs[o2i(PCI_CARDBUS_CAPLISTPTR_REG)]));
   1203      1.53  drochner 	else
   1204  1.78.2.1  uebayasi 		printf("    Reserved @ 0x14: 0x%04" PRIxMAX "\n",
   1205  1.78.2.1  uebayasi 		       __SHIFTOUT(regs[o2i(0x14)], __BITS(15, 0)));
   1206  1.78.2.1  uebayasi 	pci_conf_print_ssr(__SHIFTOUT(regs[o2i(0x14)], __BITS(31, 16)));
   1207      1.27       cgd 
   1208      1.27       cgd 	printf("    PCI bus number: 0x%02x\n",
   1209      1.27       cgd 	    (regs[o2i(0x18)] >> 0) & 0xff);
   1210      1.27       cgd 	printf("    CardBus bus number: 0x%02x\n",
   1211      1.27       cgd 	    (regs[o2i(0x18)] >> 8) & 0xff);
   1212      1.27       cgd 	printf("    Subordinate bus number: 0x%02x\n",
   1213      1.27       cgd 	    (regs[o2i(0x18)] >> 16) & 0xff);
   1214      1.27       cgd 	printf("    CardBus latency timer: 0x%02x\n",
   1215      1.27       cgd 	    (regs[o2i(0x18)] >> 24) & 0xff);
   1216      1.27       cgd 
   1217      1.27       cgd 	/* XXX Print more prettily */
   1218      1.27       cgd 	printf("    CardBus memory region 0:\n");
   1219      1.27       cgd 	printf("      base register:  0x%08x\n", regs[o2i(0x1c)]);
   1220      1.27       cgd 	printf("      limit register: 0x%08x\n", regs[o2i(0x20)]);
   1221      1.27       cgd 	printf("    CardBus memory region 1:\n");
   1222      1.27       cgd 	printf("      base register:  0x%08x\n", regs[o2i(0x24)]);
   1223      1.27       cgd 	printf("      limit register: 0x%08x\n", regs[o2i(0x28)]);
   1224      1.27       cgd 	printf("    CardBus I/O region 0:\n");
   1225      1.27       cgd 	printf("      base register:  0x%08x\n", regs[o2i(0x2c)]);
   1226      1.27       cgd 	printf("      limit register: 0x%08x\n", regs[o2i(0x30)]);
   1227      1.27       cgd 	printf("    CardBus I/O region 1:\n");
   1228      1.27       cgd 	printf("      base register:  0x%08x\n", regs[o2i(0x34)]);
   1229      1.27       cgd 	printf("      limit register: 0x%08x\n", regs[o2i(0x38)]);
   1230      1.27       cgd 
   1231      1.27       cgd 	printf("    Interrupt line: 0x%02x\n",
   1232      1.27       cgd 	    (regs[o2i(0x3c)] >> 0) & 0xff);
   1233      1.27       cgd 	printf("    Interrupt pin: 0x%02x ",
   1234      1.27       cgd 	    (regs[o2i(0x3c)] >> 8) & 0xff);
   1235      1.27       cgd 	switch ((regs[o2i(0x3c)] >> 8) & 0xff) {
   1236      1.27       cgd 	case PCI_INTERRUPT_PIN_NONE:
   1237      1.27       cgd 		printf("(none)");
   1238      1.27       cgd 		break;
   1239      1.27       cgd 	case PCI_INTERRUPT_PIN_A:
   1240      1.27       cgd 		printf("(pin A)");
   1241      1.27       cgd 		break;
   1242      1.27       cgd 	case PCI_INTERRUPT_PIN_B:
   1243      1.27       cgd 		printf("(pin B)");
   1244      1.27       cgd 		break;
   1245      1.27       cgd 	case PCI_INTERRUPT_PIN_C:
   1246      1.27       cgd 		printf("(pin C)");
   1247      1.27       cgd 		break;
   1248      1.27       cgd 	case PCI_INTERRUPT_PIN_D:
   1249      1.27       cgd 		printf("(pin D)");
   1250      1.27       cgd 		break;
   1251      1.27       cgd 	default:
   1252      1.36       mrg 		printf("(? ? ?)");
   1253      1.27       cgd 		break;
   1254      1.27       cgd 	}
   1255      1.27       cgd 	printf("\n");
   1256      1.27       cgd 	rval = (regs[o2i(0x3c)] >> 16) & 0xffff;
   1257      1.27       cgd 	printf("    Bridge control register: 0x%04x\n", rval);
   1258  1.78.2.1  uebayasi 	onoff("Parity error response", __BIT(0));
   1259  1.78.2.1  uebayasi 	onoff("SERR# enable", __BIT(1));
   1260  1.78.2.1  uebayasi 	onoff("ISA enable", __BIT(2));
   1261  1.78.2.1  uebayasi 	onoff("VGA enable", __BIT(3));
   1262  1.78.2.1  uebayasi 	onoff("Master abort mode", __BIT(5));
   1263  1.78.2.1  uebayasi 	onoff("Secondary (CardBus) bus reset", __BIT(6));
   1264  1.78.2.1  uebayasi 	onoff("Functional interrupts routed by ExCA registers", __BIT(7));
   1265  1.78.2.1  uebayasi 	onoff("Memory window 0 prefetchable", __BIT(8));
   1266  1.78.2.1  uebayasi 	onoff("Memory window 1 prefetchable", __BIT(9));
   1267  1.78.2.1  uebayasi 	onoff("Write posting enable", __BIT(10));
   1268      1.28       cgd 
   1269      1.28       cgd 	rval = regs[o2i(0x40)];
   1270      1.28       cgd 	printf("    Subsystem vendor ID: 0x%04x\n", PCI_VENDOR(rval));
   1271      1.28       cgd 	printf("    Subsystem ID: 0x%04x\n", PCI_PRODUCT(rval));
   1272      1.28       cgd 
   1273      1.45   thorpej #ifdef _KERNEL
   1274      1.38       cgd 	pci_conf_print_bar(pc, tag, regs, 0x44, "legacy-mode registers",
   1275      1.38       cgd 	    sizebars);
   1276      1.45   thorpej #else
   1277      1.45   thorpej 	pci_conf_print_bar(regs, 0x44, "legacy-mode registers");
   1278      1.45   thorpej #endif
   1279      1.27       cgd }
   1280      1.27       cgd 
   1281      1.26       cgd void
   1282      1.45   thorpej pci_conf_print(
   1283      1.45   thorpej #ifdef _KERNEL
   1284      1.45   thorpej     pci_chipset_tag_t pc, pcitag_t tag,
   1285      1.45   thorpej     void (*printfn)(pci_chipset_tag_t, pcitag_t, const pcireg_t *)
   1286      1.45   thorpej #else
   1287      1.45   thorpej     int pcifd, u_int bus, u_int dev, u_int func
   1288      1.45   thorpej #endif
   1289      1.45   thorpej     )
   1290      1.26       cgd {
   1291      1.26       cgd 	pcireg_t regs[o2i(256)];
   1292      1.52  drochner 	int off, capoff, endoff, hdrtype;
   1293      1.27       cgd 	const char *typename;
   1294      1.45   thorpej #ifdef _KERNEL
   1295      1.38       cgd 	void (*typeprintfn)(pci_chipset_tag_t, pcitag_t, const pcireg_t *, int);
   1296      1.38       cgd 	int sizebars;
   1297      1.45   thorpej #else
   1298      1.45   thorpej 	void (*typeprintfn)(const pcireg_t *);
   1299      1.45   thorpej #endif
   1300      1.26       cgd 
   1301      1.26       cgd 	printf("PCI configuration registers:\n");
   1302      1.26       cgd 
   1303      1.45   thorpej 	for (off = 0; off < 256; off += 4) {
   1304      1.45   thorpej #ifdef _KERNEL
   1305      1.26       cgd 		regs[o2i(off)] = pci_conf_read(pc, tag, off);
   1306      1.45   thorpej #else
   1307      1.45   thorpej 		if (pcibus_conf_read(pcifd, bus, dev, func, off,
   1308      1.45   thorpej 		    &regs[o2i(off)]) == -1)
   1309      1.45   thorpej 			regs[o2i(off)] = 0;
   1310      1.45   thorpej #endif
   1311      1.45   thorpej 	}
   1312      1.26       cgd 
   1313      1.45   thorpej #ifdef _KERNEL
   1314      1.38       cgd 	sizebars = 1;
   1315      1.38       cgd 	if (PCI_CLASS(regs[o2i(PCI_CLASS_REG)]) == PCI_CLASS_BRIDGE &&
   1316      1.38       cgd 	    PCI_SUBCLASS(regs[o2i(PCI_CLASS_REG)]) == PCI_SUBCLASS_BRIDGE_HOST)
   1317      1.38       cgd 		sizebars = 0;
   1318      1.45   thorpej #endif
   1319      1.38       cgd 
   1320      1.26       cgd 	/* common header */
   1321      1.26       cgd 	printf("  Common header:\n");
   1322      1.28       cgd 	pci_conf_print_regs(regs, 0, 16);
   1323      1.28       cgd 
   1324      1.26       cgd 	printf("\n");
   1325      1.45   thorpej #ifdef _KERNEL
   1326      1.26       cgd 	pci_conf_print_common(pc, tag, regs);
   1327      1.45   thorpej #else
   1328      1.45   thorpej 	pci_conf_print_common(regs);
   1329      1.45   thorpej #endif
   1330      1.26       cgd 	printf("\n");
   1331      1.26       cgd 
   1332      1.26       cgd 	/* type-dependent header */
   1333      1.26       cgd 	hdrtype = PCI_HDRTYPE_TYPE(regs[o2i(PCI_BHLC_REG)]);
   1334      1.26       cgd 	switch (hdrtype) {		/* XXX make a table, eventually */
   1335      1.26       cgd 	case 0:
   1336      1.27       cgd 		/* Standard device header */
   1337      1.27       cgd 		typename = "\"normal\" device";
   1338      1.27       cgd 		typeprintfn = &pci_conf_print_type0;
   1339      1.52  drochner 		capoff = PCI_CAPLISTPTR_REG;
   1340      1.28       cgd 		endoff = 64;
   1341      1.27       cgd 		break;
   1342      1.27       cgd 	case 1:
   1343      1.27       cgd 		/* PCI-PCI bridge header */
   1344      1.27       cgd 		typename = "PCI-PCI bridge";
   1345      1.26       cgd 		typeprintfn = &pci_conf_print_type1;
   1346      1.52  drochner 		capoff = PCI_CAPLISTPTR_REG;
   1347      1.28       cgd 		endoff = 64;
   1348      1.26       cgd 		break;
   1349      1.27       cgd 	case 2:
   1350      1.27       cgd 		/* PCI-CardBus bridge header */
   1351      1.27       cgd 		typename = "PCI-CardBus bridge";
   1352      1.27       cgd 		typeprintfn = &pci_conf_print_type2;
   1353      1.52  drochner 		capoff = PCI_CARDBUS_CAPLISTPTR_REG;
   1354      1.28       cgd 		endoff = 72;
   1355      1.27       cgd 		break;
   1356      1.26       cgd 	default:
   1357      1.27       cgd 		typename = NULL;
   1358      1.26       cgd 		typeprintfn = 0;
   1359      1.52  drochner 		capoff = -1;
   1360      1.28       cgd 		endoff = 64;
   1361      1.28       cgd 		break;
   1362      1.26       cgd 	}
   1363      1.27       cgd 	printf("  Type %d ", hdrtype);
   1364      1.27       cgd 	if (typename != NULL)
   1365      1.27       cgd 		printf("(%s) ", typename);
   1366      1.27       cgd 	printf("header:\n");
   1367      1.28       cgd 	pci_conf_print_regs(regs, 16, endoff);
   1368      1.27       cgd 	printf("\n");
   1369      1.45   thorpej 	if (typeprintfn) {
   1370      1.45   thorpej #ifdef _KERNEL
   1371      1.38       cgd 		(*typeprintfn)(pc, tag, regs, sizebars);
   1372      1.45   thorpej #else
   1373      1.45   thorpej 		(*typeprintfn)(regs);
   1374      1.45   thorpej #endif
   1375      1.45   thorpej 	} else
   1376      1.26       cgd 		printf("    Don't know how to pretty-print type %d header.\n",
   1377      1.26       cgd 		    hdrtype);
   1378      1.26       cgd 	printf("\n");
   1379      1.51  drochner 
   1380      1.55  jdolecek 	/* capability list, if present */
   1381      1.52  drochner 	if ((regs[o2i(PCI_COMMAND_STATUS_REG)] & PCI_STATUS_CAPLIST_SUPPORT)
   1382      1.52  drochner 		&& (capoff > 0)) {
   1383      1.51  drochner #ifdef _KERNEL
   1384      1.52  drochner 		pci_conf_print_caplist(pc, tag, regs, capoff);
   1385      1.51  drochner #else
   1386      1.52  drochner 		pci_conf_print_caplist(regs, capoff);
   1387      1.51  drochner #endif
   1388      1.51  drochner 		printf("\n");
   1389      1.51  drochner 	}
   1390      1.26       cgd 
   1391      1.26       cgd 	/* device-dependent header */
   1392      1.26       cgd 	printf("  Device-dependent header:\n");
   1393      1.28       cgd 	pci_conf_print_regs(regs, endoff, 256);
   1394      1.26       cgd 	printf("\n");
   1395      1.49   nathanw #ifdef _KERNEL
   1396      1.26       cgd 	if (printfn)
   1397      1.26       cgd 		(*printfn)(pc, tag, regs);
   1398      1.26       cgd 	else
   1399      1.26       cgd 		printf("    Don't know how to pretty-print device-dependent header.\n");
   1400      1.26       cgd 	printf("\n");
   1401      1.45   thorpej #endif /* _KERNEL */
   1402       1.1   mycroft }
   1403