Wed Jan 27 05:00:16 2021 UTC ()
Introduce autoconfiguration helpers based around device_compatible_entry:
- pci_compatible_match(): matches against the PCI ID.
- pci_compatible_match_subsys(): matches against PCI SUBSYS ID.
- pci_compatible_lookup(): look up entry by PCI ID.
- pci_compatible_lookup_subsys(): look up entry by PCI SUBSYS ID.
- pci_compatible_lookup_id(): look up entry by an arbitrary ID using the
  PCI ID code conventions.

- Define PCI_COMPAT_EOL as a compat data array sentinel.


(thorpej)
diff -r1.224 -r1.225 src/sys/dev/pci/pci_subr.c
diff -r1.113 -r1.114 src/sys/dev/pci/pcivar.h

cvs diff -r1.224 -r1.225 src/sys/dev/pci/pci_subr.c (switch to unified diff)

--- src/sys/dev/pci/pci_subr.c 2020/05/30 10:43:46 1.224
+++ src/sys/dev/pci/pci_subr.c 2021/01/27 05:00:15 1.225
@@ -1,1085 +1,1129 @@ @@ -1,1085 +1,1129 @@
1/* $NetBSD: pci_subr.c,v 1.224 2020/05/30 10:43:46 jdolecek Exp $ */ 1/* $NetBSD: pci_subr.c,v 1.225 2021/01/27 05:00:15 thorpej Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1997 Zubin D. Dittia. All rights reserved. 4 * Copyright (c) 1997 Zubin D. Dittia. All rights reserved.
5 * Copyright (c) 1995, 1996, 1998, 2000 5 * Copyright (c) 1995, 1996, 1998, 2000
6 * Christopher G. Demetriou. All rights reserved. 6 * Christopher G. Demetriou. All rights reserved.
7 * Copyright (c) 1994 Charles M. Hannum. All rights reserved. 7 * Copyright (c) 1994 Charles M. Hannum. All rights reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the 15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution. 16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software 17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement: 18 * must display the following acknowledgement:
19 * This product includes software developed by Charles M. Hannum. 19 * This product includes software developed by Charles M. Hannum.
20 * 4. The name of the author may not be used to endorse or promote products 20 * 4. The name of the author may not be used to endorse or promote products
21 * derived from this software without specific prior written permission. 21 * derived from this software without specific prior written permission.
22 * 22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */ 33 */
34 34
35/* 35/*
36 * PCI autoconfiguration support functions. 36 * PCI autoconfiguration support functions.
37 * 37 *
38 * Note: This file is also built into a userland library (libpci). 38 * Note: This file is also built into a userland library (libpci).
39 * Pay attention to this when you make modifications. 39 * Pay attention to this when you make modifications.
40 */ 40 */
41 41
42#include <sys/cdefs.h> 42#include <sys/cdefs.h>
43__KERNEL_RCSID(0, "$NetBSD: pci_subr.c,v 1.224 2020/05/30 10:43:46 jdolecek Exp $"); 43__KERNEL_RCSID(0, "$NetBSD: pci_subr.c,v 1.225 2021/01/27 05:00:15 thorpej Exp $");
44 44
45#ifdef _KERNEL_OPT 45#ifdef _KERNEL_OPT
46#include "opt_pci.h" 46#include "opt_pci.h"
47#endif 47#endif
48 48
49#include <sys/param.h> 49#include <sys/param.h>
50 50
51#ifdef _KERNEL 51#ifdef _KERNEL
52#include <sys/systm.h> 52#include <sys/systm.h>
53#include <sys/intr.h> 53#include <sys/intr.h>
54#include <sys/module.h> 54#include <sys/module.h>
55#include <sys/kmem.h> 55#include <sys/kmem.h>
56 56
57#define MALLOC(sz) kmem_alloc(sz, KM_SLEEP) 57#define MALLOC(sz) kmem_alloc(sz, KM_SLEEP)
58#define FREE(p, sz) kmem_free(p, sz) 58#define FREE(p, sz) kmem_free(p, sz)
59 59
60#else 60#else
61#include <pci.h> 61#include <pci.h>
62#include <stdarg.h> 62#include <stdarg.h>
63#include <stdbool.h> 63#include <stdbool.h>
64#include <stdio.h> 64#include <stdio.h>
65#include <stdlib.h> 65#include <stdlib.h>
66#include <string.h> 66#include <string.h>
67 67
68#define MALLOC(sz) malloc(sz) 68#define MALLOC(sz) malloc(sz)
69#define FREE(p, sz) free(p) 69#define FREE(p, sz) free(p)
70 70
71#endif 71#endif
72 72
73#include <dev/pci/pcireg.h> 73#include <dev/pci/pcireg.h>
74#ifdef _KERNEL 74#ifdef _KERNEL
75#include <dev/pci/pcivar.h> 75#include <dev/pci/pcivar.h>
76#else 76#else
77#include <dev/pci/pci_verbose.h> 77#include <dev/pci/pci_verbose.h>
78#include <dev/pci/pcidevs.h> 78#include <dev/pci/pcidevs.h>
79#include <dev/pci/pcidevs_data.h> 79#include <dev/pci/pcidevs_data.h>
80#endif 80#endif
81 81
82static int pci_conf_find_cap(const pcireg_t *, unsigned int, int *); 82static int pci_conf_find_cap(const pcireg_t *, unsigned int, int *);
83static int pci_conf_find_extcap(const pcireg_t *, unsigned int, int *); 83static int pci_conf_find_extcap(const pcireg_t *, unsigned int, int *);
84static void pci_conf_print_pcie_power(uint8_t, unsigned int); 84static void pci_conf_print_pcie_power(uint8_t, unsigned int);
85#define PCIREG_SHIFTOUT(a, b) ((pcireg_t)__SHIFTOUT((a), (b))) 85#define PCIREG_SHIFTOUT(a, b) ((pcireg_t)__SHIFTOUT((a), (b)))
86 86
 87#ifdef _KERNEL
 88/*
 89 * Common routines used to match a compatible device by its PCI ID code.
 90 */
 91
 92const struct device_compatible_entry *
 93pci_compatible_lookup_id(pcireg_t const id,
 94 const struct device_compatible_entry *dce)
 95{
 96 return device_compatible_lookup_id(id, PCI_COMPAT_EOL_VALUE, dce);
 97}
 98
 99const struct device_compatible_entry *
 100pci_compatible_lookup(const struct pci_attach_args * const pa,
 101 const struct device_compatible_entry * const dce)
 102{
 103 return pci_compatible_lookup_id(pa->pa_id, dce);
 104}
 105
 106const struct device_compatible_entry *
 107pci_compatible_lookup_subsys(const struct pci_attach_args * const pa,
 108 const struct device_compatible_entry * const dce)
 109{
 110 const pcireg_t subsysid =
 111 pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_SUBSYS_ID_REG);
 112
 113 return pci_compatible_lookup_id(subsysid, dce);
 114}
 115
 116int
 117pci_compatible_match(const struct pci_attach_args * const pa,
 118 const struct device_compatible_entry * const dce)
 119{
 120 return pci_compatible_lookup(pa, dce) != NULL;
 121}
 122
 123int
 124pci_compatible_match_subsys(const struct pci_attach_args * const pa,
 125 const struct device_compatible_entry * const dce)
 126{
 127 return pci_compatible_lookup_subsys(pa, dce) != NULL;
 128}
 129#endif /* _KERNEL */
 130
87/* 131/*
88 * Descriptions of known PCI classes and subclasses. 132 * Descriptions of known PCI classes and subclasses.
89 * 133 *
90 * Subclasses are described in the same way as classes, but have a 134 * Subclasses are described in the same way as classes, but have a
91 * NULL subclass pointer. 135 * NULL subclass pointer.
92 */ 136 */
93struct pci_class { 137struct pci_class {
94 const char *name; 138 const char *name;
95 u_int val; /* as wide as pci_{,sub}class_t */ 139 u_int val; /* as wide as pci_{,sub}class_t */
96 const struct pci_class *subclasses; 140 const struct pci_class *subclasses;
97}; 141};
98 142
99/* 143/*
100 * Class 0x00. 144 * Class 0x00.
101 * Before rev. 2.0. 145 * Before rev. 2.0.
102 */ 146 */
103static const struct pci_class pci_subclass_prehistoric[] = { 147static const struct pci_class pci_subclass_prehistoric[] = {
104 { "miscellaneous", PCI_SUBCLASS_PREHISTORIC_MISC, NULL, }, 148 { "miscellaneous", PCI_SUBCLASS_PREHISTORIC_MISC, NULL, },
105 { "VGA", PCI_SUBCLASS_PREHISTORIC_VGA, NULL, }, 149 { "VGA", PCI_SUBCLASS_PREHISTORIC_VGA, NULL, },
106 { NULL, 0, NULL, }, 150 { NULL, 0, NULL, },
107}; 151};
108 152
109/* 153/*
110 * Class 0x01. 154 * Class 0x01.
111 * Mass storage controller 155 * Mass storage controller
112 */ 156 */
113 157
114/* ATA programming interface */ 158/* ATA programming interface */
115static const struct pci_class pci_interface_ata[] = { 159static const struct pci_class pci_interface_ata[] = {
116 { "with single DMA", PCI_INTERFACE_ATA_SINGLEDMA, NULL, }, 160 { "with single DMA", PCI_INTERFACE_ATA_SINGLEDMA, NULL, },
117 { "with chained DMA", PCI_INTERFACE_ATA_CHAINEDDMA, NULL, }, 161 { "with chained DMA", PCI_INTERFACE_ATA_CHAINEDDMA, NULL, },
118 { NULL, 0, NULL, }, 162 { NULL, 0, NULL, },
119}; 163};
120 164
121/* SATA programming interface */ 165/* SATA programming interface */
122static const struct pci_class pci_interface_sata[] = { 166static const struct pci_class pci_interface_sata[] = {
123 { "vendor specific", PCI_INTERFACE_SATA_VND, NULL, }, 167 { "vendor specific", PCI_INTERFACE_SATA_VND, NULL, },
124 { "AHCI 1.0", PCI_INTERFACE_SATA_AHCI10, NULL, }, 168 { "AHCI 1.0", PCI_INTERFACE_SATA_AHCI10, NULL, },
125 { "Serial Storage Bus Interface", PCI_INTERFACE_SATA_SSBI, NULL, }, 169 { "Serial Storage Bus Interface", PCI_INTERFACE_SATA_SSBI, NULL, },
126 { NULL, 0, NULL, }, 170 { NULL, 0, NULL, },
127}; 171};
128 172
129/* Flash programming interface */ 173/* Flash programming interface */
130static const struct pci_class pci_interface_nvm[] = { 174static const struct pci_class pci_interface_nvm[] = {
131 { "vendor specific", PCI_INTERFACE_NVM_VND, NULL, }, 175 { "vendor specific", PCI_INTERFACE_NVM_VND, NULL, },
132 { "NVMHCI 1.0", PCI_INTERFACE_NVM_NVMHCI10, NULL, }, 176 { "NVMHCI 1.0", PCI_INTERFACE_NVM_NVMHCI10, NULL, },
133 { "NVMe", PCI_INTERFACE_NVM_NVME, NULL, }, 177 { "NVMe", PCI_INTERFACE_NVM_NVME, NULL, },
134 { NULL, 0, NULL, }, 178 { NULL, 0, NULL, },
135}; 179};
136 180
137/* Subclasses */ 181/* Subclasses */
138static const struct pci_class pci_subclass_mass_storage[] = { 182static const struct pci_class pci_subclass_mass_storage[] = {
139 { "SCSI", PCI_SUBCLASS_MASS_STORAGE_SCSI, NULL, }, 183 { "SCSI", PCI_SUBCLASS_MASS_STORAGE_SCSI, NULL, },
140 { "IDE", PCI_SUBCLASS_MASS_STORAGE_IDE, NULL, }, 184 { "IDE", PCI_SUBCLASS_MASS_STORAGE_IDE, NULL, },
141 { "floppy", PCI_SUBCLASS_MASS_STORAGE_FLOPPY, NULL, }, 185 { "floppy", PCI_SUBCLASS_MASS_STORAGE_FLOPPY, NULL, },
142 { "IPI", PCI_SUBCLASS_MASS_STORAGE_IPI, NULL, }, 186 { "IPI", PCI_SUBCLASS_MASS_STORAGE_IPI, NULL, },
143 { "RAID", PCI_SUBCLASS_MASS_STORAGE_RAID, NULL, }, 187 { "RAID", PCI_SUBCLASS_MASS_STORAGE_RAID, NULL, },
144 { "ATA", PCI_SUBCLASS_MASS_STORAGE_ATA, 188 { "ATA", PCI_SUBCLASS_MASS_STORAGE_ATA,
145 pci_interface_ata, }, 189 pci_interface_ata, },
146 { "SATA", PCI_SUBCLASS_MASS_STORAGE_SATA, 190 { "SATA", PCI_SUBCLASS_MASS_STORAGE_SATA,
147 pci_interface_sata, }, 191 pci_interface_sata, },
148 { "SAS", PCI_SUBCLASS_MASS_STORAGE_SAS, NULL, }, 192 { "SAS", PCI_SUBCLASS_MASS_STORAGE_SAS, NULL, },
149 { "Flash", PCI_SUBCLASS_MASS_STORAGE_NVM, 193 { "Flash", PCI_SUBCLASS_MASS_STORAGE_NVM,
150 pci_interface_nvm, }, 194 pci_interface_nvm, },
151 { "miscellaneous", PCI_SUBCLASS_MASS_STORAGE_MISC, NULL, }, 195 { "miscellaneous", PCI_SUBCLASS_MASS_STORAGE_MISC, NULL, },
152 { NULL, 0, NULL, }, 196 { NULL, 0, NULL, },
153}; 197};
154 198
155/* 199/*
156 * Class 0x02. 200 * Class 0x02.
157 * Network controller. 201 * Network controller.
158 */ 202 */
159static const struct pci_class pci_subclass_network[] = { 203static const struct pci_class pci_subclass_network[] = {
160 { "ethernet", PCI_SUBCLASS_NETWORK_ETHERNET, NULL, }, 204 { "ethernet", PCI_SUBCLASS_NETWORK_ETHERNET, NULL, },
161 { "token ring", PCI_SUBCLASS_NETWORK_TOKENRING, NULL, }, 205 { "token ring", PCI_SUBCLASS_NETWORK_TOKENRING, NULL, },
162 { "FDDI", PCI_SUBCLASS_NETWORK_FDDI, NULL, }, 206 { "FDDI", PCI_SUBCLASS_NETWORK_FDDI, NULL, },
163 { "ATM", PCI_SUBCLASS_NETWORK_ATM, NULL, }, 207 { "ATM", PCI_SUBCLASS_NETWORK_ATM, NULL, },
164 { "ISDN", PCI_SUBCLASS_NETWORK_ISDN, NULL, }, 208 { "ISDN", PCI_SUBCLASS_NETWORK_ISDN, NULL, },
165 { "WorldFip", PCI_SUBCLASS_NETWORK_WORLDFIP, NULL, }, 209 { "WorldFip", PCI_SUBCLASS_NETWORK_WORLDFIP, NULL, },
166 { "PCMIG Multi Computing", PCI_SUBCLASS_NETWORK_PCIMGMULTICOMP, NULL, }, 210 { "PCMIG Multi Computing", PCI_SUBCLASS_NETWORK_PCIMGMULTICOMP, NULL, },
167 { "miscellaneous", PCI_SUBCLASS_NETWORK_MISC, NULL, }, 211 { "miscellaneous", PCI_SUBCLASS_NETWORK_MISC, NULL, },
168 { NULL, 0, NULL, }, 212 { NULL, 0, NULL, },
169}; 213};
170 214
171/* 215/*
172 * Class 0x03. 216 * Class 0x03.
173 * Display controller. 217 * Display controller.
174 */ 218 */
175 219
176/* VGA programming interface */ 220/* VGA programming interface */
177static const struct pci_class pci_interface_vga[] = { 221static const struct pci_class pci_interface_vga[] = {
178 { "", PCI_INTERFACE_VGA_VGA, NULL, }, 222 { "", PCI_INTERFACE_VGA_VGA, NULL, },
179 { "8514-compat", PCI_INTERFACE_VGA_8514, NULL, }, 223 { "8514-compat", PCI_INTERFACE_VGA_8514, NULL, },
180 { NULL, 0, NULL, }, 224 { NULL, 0, NULL, },
181}; 225};
182/* Subclasses */ 226/* Subclasses */
183static const struct pci_class pci_subclass_display[] = { 227static const struct pci_class pci_subclass_display[] = {
184 { "VGA", PCI_SUBCLASS_DISPLAY_VGA, pci_interface_vga,}, 228 { "VGA", PCI_SUBCLASS_DISPLAY_VGA, pci_interface_vga,},
185 { "XGA", PCI_SUBCLASS_DISPLAY_XGA, NULL, }, 229 { "XGA", PCI_SUBCLASS_DISPLAY_XGA, NULL, },
186 { "3D", PCI_SUBCLASS_DISPLAY_3D, NULL, }, 230 { "3D", PCI_SUBCLASS_DISPLAY_3D, NULL, },
187 { "miscellaneous", PCI_SUBCLASS_DISPLAY_MISC, NULL, }, 231 { "miscellaneous", PCI_SUBCLASS_DISPLAY_MISC, NULL, },
188 { NULL, 0, NULL, }, 232 { NULL, 0, NULL, },
189}; 233};
190 234
191/* 235/*
192 * Class 0x04. 236 * Class 0x04.
193 * Multimedia device. 237 * Multimedia device.
194 */ 238 */
195static const struct pci_class pci_subclass_multimedia[] = { 239static const struct pci_class pci_subclass_multimedia[] = {
196 { "video", PCI_SUBCLASS_MULTIMEDIA_VIDEO, NULL, }, 240 { "video", PCI_SUBCLASS_MULTIMEDIA_VIDEO, NULL, },
197 { "audio", PCI_SUBCLASS_MULTIMEDIA_AUDIO, NULL, }, 241 { "audio", PCI_SUBCLASS_MULTIMEDIA_AUDIO, NULL, },
198 { "telephony", PCI_SUBCLASS_MULTIMEDIA_TELEPHONY, NULL,}, 242 { "telephony", PCI_SUBCLASS_MULTIMEDIA_TELEPHONY, NULL,},
199 { "mixed mode", PCI_SUBCLASS_MULTIMEDIA_HDAUDIO, NULL, }, 243 { "mixed mode", PCI_SUBCLASS_MULTIMEDIA_HDAUDIO, NULL, },
200 { "miscellaneous", PCI_SUBCLASS_MULTIMEDIA_MISC, NULL, }, 244 { "miscellaneous", PCI_SUBCLASS_MULTIMEDIA_MISC, NULL, },
201 { NULL, 0, NULL, }, 245 { NULL, 0, NULL, },
202}; 246};
203 247
204/* 248/*
205 * Class 0x05. 249 * Class 0x05.
206 * Memory controller. 250 * Memory controller.
207 */ 251 */
208static const struct pci_class pci_subclass_memory[] = { 252static const struct pci_class pci_subclass_memory[] = {
209 { "RAM", PCI_SUBCLASS_MEMORY_RAM, NULL, }, 253 { "RAM", PCI_SUBCLASS_MEMORY_RAM, NULL, },
210 { "flash", PCI_SUBCLASS_MEMORY_FLASH, NULL, }, 254 { "flash", PCI_SUBCLASS_MEMORY_FLASH, NULL, },
211 { "miscellaneous", PCI_SUBCLASS_MEMORY_MISC, NULL, }, 255 { "miscellaneous", PCI_SUBCLASS_MEMORY_MISC, NULL, },
212 { NULL, 0, NULL, }, 256 { NULL, 0, NULL, },
213}; 257};
214 258
215/* 259/*
216 * Class 0x06. 260 * Class 0x06.
217 * Bridge device. 261 * Bridge device.
218 */ 262 */
219 263
220/* PCI bridge programming interface */ 264/* PCI bridge programming interface */
221static const struct pci_class pci_interface_pcibridge[] = { 265static const struct pci_class pci_interface_pcibridge[] = {
222 { "", PCI_INTERFACE_BRIDGE_PCI_PCI, NULL, }, 266 { "", PCI_INTERFACE_BRIDGE_PCI_PCI, NULL, },
223 { "subtractive decode", PCI_INTERFACE_BRIDGE_PCI_SUBDEC, NULL, }, 267 { "subtractive decode", PCI_INTERFACE_BRIDGE_PCI_SUBDEC, NULL, },
224 { NULL, 0, NULL, }, 268 { NULL, 0, NULL, },
225}; 269};
226 270
227/* Semi-transparent PCI-to-PCI bridge programming interface */ 271/* Semi-transparent PCI-to-PCI bridge programming interface */
228static const struct pci_class pci_interface_stpci[] = { 272static const struct pci_class pci_interface_stpci[] = {
229 { "primary side facing host", PCI_INTERFACE_STPCI_PRIMARY, NULL, }, 273 { "primary side facing host", PCI_INTERFACE_STPCI_PRIMARY, NULL, },
230 { "secondary side facing host", PCI_INTERFACE_STPCI_SECONDARY, NULL, }, 274 { "secondary side facing host", PCI_INTERFACE_STPCI_SECONDARY, NULL, },
231 { NULL, 0, NULL, }, 275 { NULL, 0, NULL, },
232}; 276};
233 277
234/* Advanced Switching programming interface */ 278/* Advanced Switching programming interface */
235static const struct pci_class pci_interface_advsw[] = { 279static const struct pci_class pci_interface_advsw[] = {
236 { "custom interface", PCI_INTERFACE_ADVSW_CUSTOM, NULL, }, 280 { "custom interface", PCI_INTERFACE_ADVSW_CUSTOM, NULL, },
237 { "ASI-SIG", PCI_INTERFACE_ADVSW_ASISIG, NULL, }, 281 { "ASI-SIG", PCI_INTERFACE_ADVSW_ASISIG, NULL, },
238 { NULL, 0, NULL, }, 282 { NULL, 0, NULL, },
239}; 283};
240 284
241/* Subclasses */ 285/* Subclasses */
242static const struct pci_class pci_subclass_bridge[] = { 286static const struct pci_class pci_subclass_bridge[] = {
243 { "host", PCI_SUBCLASS_BRIDGE_HOST, NULL, }, 287 { "host", PCI_SUBCLASS_BRIDGE_HOST, NULL, },
244 { "ISA", PCI_SUBCLASS_BRIDGE_ISA, NULL, }, 288 { "ISA", PCI_SUBCLASS_BRIDGE_ISA, NULL, },
245 { "EISA", PCI_SUBCLASS_BRIDGE_EISA, NULL, }, 289 { "EISA", PCI_SUBCLASS_BRIDGE_EISA, NULL, },
246 { "MicroChannel", PCI_SUBCLASS_BRIDGE_MC, NULL, }, 290 { "MicroChannel", PCI_SUBCLASS_BRIDGE_MC, NULL, },
247 { "PCI", PCI_SUBCLASS_BRIDGE_PCI, 291 { "PCI", PCI_SUBCLASS_BRIDGE_PCI,
248 pci_interface_pcibridge, }, 292 pci_interface_pcibridge, },
249 { "PCMCIA", PCI_SUBCLASS_BRIDGE_PCMCIA, NULL, }, 293 { "PCMCIA", PCI_SUBCLASS_BRIDGE_PCMCIA, NULL, },
250 { "NuBus", PCI_SUBCLASS_BRIDGE_NUBUS, NULL, }, 294 { "NuBus", PCI_SUBCLASS_BRIDGE_NUBUS, NULL, },
251 { "CardBus", PCI_SUBCLASS_BRIDGE_CARDBUS, NULL, }, 295 { "CardBus", PCI_SUBCLASS_BRIDGE_CARDBUS, NULL, },
252 { "RACEway", PCI_SUBCLASS_BRIDGE_RACEWAY, NULL, }, 296 { "RACEway", PCI_SUBCLASS_BRIDGE_RACEWAY, NULL, },
253 { "Semi-transparent PCI", PCI_SUBCLASS_BRIDGE_STPCI, 297 { "Semi-transparent PCI", PCI_SUBCLASS_BRIDGE_STPCI,
254 pci_interface_stpci, }, 298 pci_interface_stpci, },
255 { "InfiniBand", PCI_SUBCLASS_BRIDGE_INFINIBAND, NULL, }, 299 { "InfiniBand", PCI_SUBCLASS_BRIDGE_INFINIBAND, NULL, },
256 { "advanced switching", PCI_SUBCLASS_BRIDGE_ADVSW, 300 { "advanced switching", PCI_SUBCLASS_BRIDGE_ADVSW,
257 pci_interface_advsw, }, 301 pci_interface_advsw, },
258 { "miscellaneous", PCI_SUBCLASS_BRIDGE_MISC, NULL, }, 302 { "miscellaneous", PCI_SUBCLASS_BRIDGE_MISC, NULL, },
259 { NULL, 0, NULL, }, 303 { NULL, 0, NULL, },
260}; 304};
261 305
262/* 306/*
263 * Class 0x07. 307 * Class 0x07.
264 * Simple communications controller. 308 * Simple communications controller.
265 */ 309 */
266 310
267/* Serial controller programming interface */ 311/* Serial controller programming interface */
268static const struct pci_class pci_interface_serial[] = { 312static const struct pci_class pci_interface_serial[] = {
269 { "generic XT-compat", PCI_INTERFACE_SERIAL_XT, NULL, }, 313 { "generic XT-compat", PCI_INTERFACE_SERIAL_XT, NULL, },
270 { "16450-compat", PCI_INTERFACE_SERIAL_16450, NULL, }, 314 { "16450-compat", PCI_INTERFACE_SERIAL_16450, NULL, },
271 { "16550-compat", PCI_INTERFACE_SERIAL_16550, NULL, }, 315 { "16550-compat", PCI_INTERFACE_SERIAL_16550, NULL, },
272 { "16650-compat", PCI_INTERFACE_SERIAL_16650, NULL, }, 316 { "16650-compat", PCI_INTERFACE_SERIAL_16650, NULL, },
273 { "16750-compat", PCI_INTERFACE_SERIAL_16750, NULL, }, 317 { "16750-compat", PCI_INTERFACE_SERIAL_16750, NULL, },
274 { "16850-compat", PCI_INTERFACE_SERIAL_16850, NULL, }, 318 { "16850-compat", PCI_INTERFACE_SERIAL_16850, NULL, },
275 { "16950-compat", PCI_INTERFACE_SERIAL_16950, NULL, }, 319 { "16950-compat", PCI_INTERFACE_SERIAL_16950, NULL, },
276 { NULL, 0, NULL, }, 320 { NULL, 0, NULL, },
277}; 321};
278 322
279/* Parallel controller programming interface */ 323/* Parallel controller programming interface */
280static const struct pci_class pci_interface_parallel[] = { 324static const struct pci_class pci_interface_parallel[] = {
281 { "", PCI_INTERFACE_PARALLEL, NULL,}, 325 { "", PCI_INTERFACE_PARALLEL, NULL,},
282 { "bi-directional", PCI_INTERFACE_PARALLEL_BIDIRECTIONAL, NULL,}, 326 { "bi-directional", PCI_INTERFACE_PARALLEL_BIDIRECTIONAL, NULL,},
283 { "ECP 1.X-compat", PCI_INTERFACE_PARALLEL_ECP1X, NULL,}, 327 { "ECP 1.X-compat", PCI_INTERFACE_PARALLEL_ECP1X, NULL,},
284 { "IEEE1284 controller", PCI_INTERFACE_PARALLEL_IEEE1284_CNTRL, NULL,}, 328 { "IEEE1284 controller", PCI_INTERFACE_PARALLEL_IEEE1284_CNTRL, NULL,},
285 { "IEEE1284 target", PCI_INTERFACE_PARALLEL_IEEE1284_TGT, NULL,}, 329 { "IEEE1284 target", PCI_INTERFACE_PARALLEL_IEEE1284_TGT, NULL,},
286 { NULL, 0, NULL,}, 330 { NULL, 0, NULL,},
287}; 331};
288 332
289/* Modem programming interface */ 333/* Modem programming interface */
290static const struct pci_class pci_interface_modem[] = { 334static const struct pci_class pci_interface_modem[] = {
291 { "", PCI_INTERFACE_MODEM, NULL,}, 335 { "", PCI_INTERFACE_MODEM, NULL,},
292 { "Hayes&16450-compat", PCI_INTERFACE_MODEM_HAYES16450, NULL,}, 336 { "Hayes&16450-compat", PCI_INTERFACE_MODEM_HAYES16450, NULL,},
293 { "Hayes&16550-compat", PCI_INTERFACE_MODEM_HAYES16550, NULL,}, 337 { "Hayes&16550-compat", PCI_INTERFACE_MODEM_HAYES16550, NULL,},
294 { "Hayes&16650-compat", PCI_INTERFACE_MODEM_HAYES16650, NULL,}, 338 { "Hayes&16650-compat", PCI_INTERFACE_MODEM_HAYES16650, NULL,},
295 { "Hayes&16750-compat", PCI_INTERFACE_MODEM_HAYES16750, NULL,}, 339 { "Hayes&16750-compat", PCI_INTERFACE_MODEM_HAYES16750, NULL,},
296 { NULL, 0, NULL,}, 340 { NULL, 0, NULL,},
297}; 341};
298 342
299/* Subclasses */ 343/* Subclasses */
300static const struct pci_class pci_subclass_communications[] = { 344static const struct pci_class pci_subclass_communications[] = {
301 { "serial", PCI_SUBCLASS_COMMUNICATIONS_SERIAL, 345 { "serial", PCI_SUBCLASS_COMMUNICATIONS_SERIAL,
302 pci_interface_serial, }, 346 pci_interface_serial, },
303 { "parallel", PCI_SUBCLASS_COMMUNICATIONS_PARALLEL, 347 { "parallel", PCI_SUBCLASS_COMMUNICATIONS_PARALLEL,
304 pci_interface_parallel, }, 348 pci_interface_parallel, },
305 { "multi-port serial", PCI_SUBCLASS_COMMUNICATIONS_MPSERIAL, NULL,}, 349 { "multi-port serial", PCI_SUBCLASS_COMMUNICATIONS_MPSERIAL, NULL,},
306 { "modem", PCI_SUBCLASS_COMMUNICATIONS_MODEM, 350 { "modem", PCI_SUBCLASS_COMMUNICATIONS_MODEM,
307 pci_interface_modem, }, 351 pci_interface_modem, },
308 { "GPIB", PCI_SUBCLASS_COMMUNICATIONS_GPIB, NULL,}, 352 { "GPIB", PCI_SUBCLASS_COMMUNICATIONS_GPIB, NULL,},
309 { "smartcard", PCI_SUBCLASS_COMMUNICATIONS_SMARTCARD, NULL,}, 353 { "smartcard", PCI_SUBCLASS_COMMUNICATIONS_SMARTCARD, NULL,},
310 { "miscellaneous", PCI_SUBCLASS_COMMUNICATIONS_MISC, NULL,}, 354 { "miscellaneous", PCI_SUBCLASS_COMMUNICATIONS_MISC, NULL,},
311 { NULL, 0, NULL,}, 355 { NULL, 0, NULL,},
312}; 356};
313 357
314/* 358/*
315 * Class 0x08. 359 * Class 0x08.
316 * Base system peripheral. 360 * Base system peripheral.
317 */ 361 */
318 362
319/* PIC programming interface */ 363/* PIC programming interface */
320static const struct pci_class pci_interface_pic[] = { 364static const struct pci_class pci_interface_pic[] = {
321 { "generic 8259", PCI_INTERFACE_PIC_8259, NULL, }, 365 { "generic 8259", PCI_INTERFACE_PIC_8259, NULL, },
322 { "ISA PIC", PCI_INTERFACE_PIC_ISA, NULL, }, 366 { "ISA PIC", PCI_INTERFACE_PIC_ISA, NULL, },
323 { "EISA PIC", PCI_INTERFACE_PIC_EISA, NULL, }, 367 { "EISA PIC", PCI_INTERFACE_PIC_EISA, NULL, },
324 { "IO APIC", PCI_INTERFACE_PIC_IOAPIC, NULL, }, 368 { "IO APIC", PCI_INTERFACE_PIC_IOAPIC, NULL, },
325 { "IO(x) APIC", PCI_INTERFACE_PIC_IOXAPIC, NULL, }, 369 { "IO(x) APIC", PCI_INTERFACE_PIC_IOXAPIC, NULL, },
326 { NULL, 0, NULL, }, 370 { NULL, 0, NULL, },
327}; 371};
328 372
329/* DMA programming interface */ 373/* DMA programming interface */
330static const struct pci_class pci_interface_dma[] = { 374static const struct pci_class pci_interface_dma[] = {
331 { "generic 8237", PCI_INTERFACE_DMA_8237, NULL, }, 375 { "generic 8237", PCI_INTERFACE_DMA_8237, NULL, },
332 { "ISA", PCI_INTERFACE_DMA_ISA, NULL, }, 376 { "ISA", PCI_INTERFACE_DMA_ISA, NULL, },
333 { "EISA", PCI_INTERFACE_DMA_EISA, NULL, }, 377 { "EISA", PCI_INTERFACE_DMA_EISA, NULL, },
334 { NULL, 0, NULL, }, 378 { NULL, 0, NULL, },
335}; 379};
336 380
337/* Timer programming interface */ 381/* Timer programming interface */
338static const struct pci_class pci_interface_tmr[] = { 382static const struct pci_class pci_interface_tmr[] = {
339 { "generic 8254", PCI_INTERFACE_TIMER_8254, NULL, }, 383 { "generic 8254", PCI_INTERFACE_TIMER_8254, NULL, },
340 { "ISA", PCI_INTERFACE_TIMER_ISA, NULL, }, 384 { "ISA", PCI_INTERFACE_TIMER_ISA, NULL, },
341 { "EISA", PCI_INTERFACE_TIMER_EISA, NULL, }, 385 { "EISA", PCI_INTERFACE_TIMER_EISA, NULL, },
342 { "HPET", PCI_INTERFACE_TIMER_HPET, NULL, }, 386 { "HPET", PCI_INTERFACE_TIMER_HPET, NULL, },
343 { NULL, 0, NULL, }, 387 { NULL, 0, NULL, },
344}; 388};
345 389
346/* RTC programming interface */ 390/* RTC programming interface */
347static const struct pci_class pci_interface_rtc[] = { 391static const struct pci_class pci_interface_rtc[] = {
348 { "generic", PCI_INTERFACE_RTC_GENERIC, NULL, }, 392 { "generic", PCI_INTERFACE_RTC_GENERIC, NULL, },
349 { "ISA", PCI_INTERFACE_RTC_ISA, NULL, }, 393 { "ISA", PCI_INTERFACE_RTC_ISA, NULL, },
350 { NULL, 0, NULL, }, 394 { NULL, 0, NULL, },
351}; 395};
352 396
353/* Subclasses */ 397/* Subclasses */
354static const struct pci_class pci_subclass_system[] = { 398static const struct pci_class pci_subclass_system[] = {
355 { "interrupt", PCI_SUBCLASS_SYSTEM_PIC, pci_interface_pic,}, 399 { "interrupt", PCI_SUBCLASS_SYSTEM_PIC, pci_interface_pic,},
356 { "DMA", PCI_SUBCLASS_SYSTEM_DMA, pci_interface_dma,}, 400 { "DMA", PCI_SUBCLASS_SYSTEM_DMA, pci_interface_dma,},
357 { "timer", PCI_SUBCLASS_SYSTEM_TIMER, pci_interface_tmr,}, 401 { "timer", PCI_SUBCLASS_SYSTEM_TIMER, pci_interface_tmr,},
358 { "RTC", PCI_SUBCLASS_SYSTEM_RTC, pci_interface_rtc,}, 402 { "RTC", PCI_SUBCLASS_SYSTEM_RTC, pci_interface_rtc,},
359 { "PCI Hot-Plug", PCI_SUBCLASS_SYSTEM_PCIHOTPLUG, NULL, }, 403 { "PCI Hot-Plug", PCI_SUBCLASS_SYSTEM_PCIHOTPLUG, NULL, },
360 { "SD Host Controller", PCI_SUBCLASS_SYSTEM_SDHC, NULL, }, 404 { "SD Host Controller", PCI_SUBCLASS_SYSTEM_SDHC, NULL, },
361 { "IOMMU", PCI_SUBCLASS_SYSTEM_IOMMU, NULL, }, 405 { "IOMMU", PCI_SUBCLASS_SYSTEM_IOMMU, NULL, },
362 { "Root Complex Event Collector", PCI_SUBCLASS_SYSTEM_RCEC, NULL, }, 406 { "Root Complex Event Collector", PCI_SUBCLASS_SYSTEM_RCEC, NULL, },
363 { "miscellaneous", PCI_SUBCLASS_SYSTEM_MISC, NULL, }, 407 { "miscellaneous", PCI_SUBCLASS_SYSTEM_MISC, NULL, },
364 { NULL, 0, NULL, }, 408 { NULL, 0, NULL, },
365}; 409};
366 410
367/* 411/*
368 * Class 0x09. 412 * Class 0x09.
369 * Input device. 413 * Input device.
370 */ 414 */
371 415
372/* Gameport programming interface */ 416/* Gameport programming interface */
373static const struct pci_class pci_interface_game[] = { 417static const struct pci_class pci_interface_game[] = {
374 { "generic", PCI_INTERFACE_GAMEPORT_GENERIC, NULL, }, 418 { "generic", PCI_INTERFACE_GAMEPORT_GENERIC, NULL, },
375 { "legacy", PCI_INTERFACE_GAMEPORT_LEGACY, NULL, }, 419 { "legacy", PCI_INTERFACE_GAMEPORT_LEGACY, NULL, },
376 { NULL, 0, NULL, }, 420 { NULL, 0, NULL, },
377}; 421};
378 422
379/* Subclasses */ 423/* Subclasses */
380static const struct pci_class pci_subclass_input[] = { 424static const struct pci_class pci_subclass_input[] = {
381 { "keyboard", PCI_SUBCLASS_INPUT_KEYBOARD, NULL, }, 425 { "keyboard", PCI_SUBCLASS_INPUT_KEYBOARD, NULL, },
382 { "digitizer", PCI_SUBCLASS_INPUT_DIGITIZER, NULL, }, 426 { "digitizer", PCI_SUBCLASS_INPUT_DIGITIZER, NULL, },
383 { "mouse", PCI_SUBCLASS_INPUT_MOUSE, NULL, }, 427 { "mouse", PCI_SUBCLASS_INPUT_MOUSE, NULL, },
384 { "scanner", PCI_SUBCLASS_INPUT_SCANNER, NULL, }, 428 { "scanner", PCI_SUBCLASS_INPUT_SCANNER, NULL, },
385 { "game port", PCI_SUBCLASS_INPUT_GAMEPORT, 429 { "game port", PCI_SUBCLASS_INPUT_GAMEPORT,
386 pci_interface_game, }, 430 pci_interface_game, },
387 { "miscellaneous", PCI_SUBCLASS_INPUT_MISC, NULL, }, 431 { "miscellaneous", PCI_SUBCLASS_INPUT_MISC, NULL, },
388 { NULL, 0, NULL, }, 432 { NULL, 0, NULL, },
389}; 433};
390 434
391/* 435/*
392 * Class 0x0a. 436 * Class 0x0a.
393 * Docking station. 437 * Docking station.
394 */ 438 */
395static const struct pci_class pci_subclass_dock[] = { 439static const struct pci_class pci_subclass_dock[] = {
396 { "generic", PCI_SUBCLASS_DOCK_GENERIC, NULL, }, 440 { "generic", PCI_SUBCLASS_DOCK_GENERIC, NULL, },
397 { "miscellaneous", PCI_SUBCLASS_DOCK_MISC, NULL, }, 441 { "miscellaneous", PCI_SUBCLASS_DOCK_MISC, NULL, },
398 { NULL, 0, NULL, }, 442 { NULL, 0, NULL, },
399}; 443};
400 444
401/* 445/*
402 * Class 0x0b. 446 * Class 0x0b.
403 * Processor. 447 * Processor.
404 */ 448 */
405static const struct pci_class pci_subclass_processor[] = { 449static const struct pci_class pci_subclass_processor[] = {
406 { "386", PCI_SUBCLASS_PROCESSOR_386, NULL, }, 450 { "386", PCI_SUBCLASS_PROCESSOR_386, NULL, },
407 { "486", PCI_SUBCLASS_PROCESSOR_486, NULL, }, 451 { "486", PCI_SUBCLASS_PROCESSOR_486, NULL, },
408 { "Pentium", PCI_SUBCLASS_PROCESSOR_PENTIUM, NULL, }, 452 { "Pentium", PCI_SUBCLASS_PROCESSOR_PENTIUM, NULL, },
409 { "Alpha", PCI_SUBCLASS_PROCESSOR_ALPHA, NULL, }, 453 { "Alpha", PCI_SUBCLASS_PROCESSOR_ALPHA, NULL, },
410 { "PowerPC", PCI_SUBCLASS_PROCESSOR_POWERPC, NULL, }, 454 { "PowerPC", PCI_SUBCLASS_PROCESSOR_POWERPC, NULL, },
411 { "MIPS", PCI_SUBCLASS_PROCESSOR_MIPS, NULL, }, 455 { "MIPS", PCI_SUBCLASS_PROCESSOR_MIPS, NULL, },
412 { "Co-processor", PCI_SUBCLASS_PROCESSOR_COPROC, NULL, }, 456 { "Co-processor", PCI_SUBCLASS_PROCESSOR_COPROC, NULL, },
413 { "miscellaneous", PCI_SUBCLASS_PROCESSOR_MISC, NULL, }, 457 { "miscellaneous", PCI_SUBCLASS_PROCESSOR_MISC, NULL, },
414 { NULL, 0, NULL, }, 458 { NULL, 0, NULL, },
415}; 459};
416 460
417/* 461/*
418 * Class 0x0c. 462 * Class 0x0c.
419 * Serial bus controller. 463 * Serial bus controller.
420 */ 464 */
421 465
422/* IEEE1394 programming interface */ 466/* IEEE1394 programming interface */
423static const struct pci_class pci_interface_ieee1394[] = { 467static const struct pci_class pci_interface_ieee1394[] = {
424 { "Firewire", PCI_INTERFACE_IEEE1394_FIREWIRE, NULL,}, 468 { "Firewire", PCI_INTERFACE_IEEE1394_FIREWIRE, NULL,},
425 { "OpenHCI", PCI_INTERFACE_IEEE1394_OPENHCI, NULL,}, 469 { "OpenHCI", PCI_INTERFACE_IEEE1394_OPENHCI, NULL,},
426 { NULL, 0, NULL,}, 470 { NULL, 0, NULL,},
427}; 471};
428 472
429/* USB programming interface */ 473/* USB programming interface */
430static const struct pci_class pci_interface_usb[] = { 474static const struct pci_class pci_interface_usb[] = {
431 { "UHCI", PCI_INTERFACE_USB_UHCI, NULL, }, 475 { "UHCI", PCI_INTERFACE_USB_UHCI, NULL, },
432 { "OHCI", PCI_INTERFACE_USB_OHCI, NULL, }, 476 { "OHCI", PCI_INTERFACE_USB_OHCI, NULL, },
433 { "EHCI", PCI_INTERFACE_USB_EHCI, NULL, }, 477 { "EHCI", PCI_INTERFACE_USB_EHCI, NULL, },
434 { "xHCI", PCI_INTERFACE_USB_XHCI, NULL, }, 478 { "xHCI", PCI_INTERFACE_USB_XHCI, NULL, },
435 { "other HC", PCI_INTERFACE_USB_OTHERHC, NULL, }, 479 { "other HC", PCI_INTERFACE_USB_OTHERHC, NULL, },
436 { "device", PCI_INTERFACE_USB_DEVICE, NULL, }, 480 { "device", PCI_INTERFACE_USB_DEVICE, NULL, },
437 { NULL, 0, NULL, }, 481 { NULL, 0, NULL, },
438}; 482};
439 483
440/* IPMI programming interface */ 484/* IPMI programming interface */
441static const struct pci_class pci_interface_ipmi[] = { 485static const struct pci_class pci_interface_ipmi[] = {
442 { "SMIC", PCI_INTERFACE_IPMI_SMIC, NULL, }, 486 { "SMIC", PCI_INTERFACE_IPMI_SMIC, NULL, },
443 { "keyboard", PCI_INTERFACE_IPMI_KBD, NULL, }, 487 { "keyboard", PCI_INTERFACE_IPMI_KBD, NULL, },
444 { "block transfer", PCI_INTERFACE_IPMI_BLOCKXFER, NULL, }, 488 { "block transfer", PCI_INTERFACE_IPMI_BLOCKXFER, NULL, },
445 { NULL, 0, NULL, }, 489 { NULL, 0, NULL, },
446}; 490};
447 491
448/* Subclasses */ 492/* Subclasses */
449static const struct pci_class pci_subclass_serialbus[] = { 493static const struct pci_class pci_subclass_serialbus[] = {
450 { "IEEE1394", PCI_SUBCLASS_SERIALBUS_FIREWIRE, 494 { "IEEE1394", PCI_SUBCLASS_SERIALBUS_FIREWIRE,
451 pci_interface_ieee1394, }, 495 pci_interface_ieee1394, },
452 { "ACCESS.bus", PCI_SUBCLASS_SERIALBUS_ACCESS, NULL, }, 496 { "ACCESS.bus", PCI_SUBCLASS_SERIALBUS_ACCESS, NULL, },
453 { "SSA", PCI_SUBCLASS_SERIALBUS_SSA, NULL, }, 497 { "SSA", PCI_SUBCLASS_SERIALBUS_SSA, NULL, },
454 { "USB", PCI_SUBCLASS_SERIALBUS_USB, 498 { "USB", PCI_SUBCLASS_SERIALBUS_USB,
455 pci_interface_usb, }, 499 pci_interface_usb, },
456 /* XXX Fiber Channel/_FIBRECHANNEL */ 500 /* XXX Fiber Channel/_FIBRECHANNEL */
457 { "Fiber Channel", PCI_SUBCLASS_SERIALBUS_FIBER, NULL, }, 501 { "Fiber Channel", PCI_SUBCLASS_SERIALBUS_FIBER, NULL, },
458 { "SMBus", PCI_SUBCLASS_SERIALBUS_SMBUS, NULL, }, 502 { "SMBus", PCI_SUBCLASS_SERIALBUS_SMBUS, NULL, },
459 { "InfiniBand", PCI_SUBCLASS_SERIALBUS_INFINIBAND, NULL,}, 503 { "InfiniBand", PCI_SUBCLASS_SERIALBUS_INFINIBAND, NULL,},
460 { "IPMI", PCI_SUBCLASS_SERIALBUS_IPMI, 504 { "IPMI", PCI_SUBCLASS_SERIALBUS_IPMI,
461 pci_interface_ipmi, }, 505 pci_interface_ipmi, },
462 { "SERCOS", PCI_SUBCLASS_SERIALBUS_SERCOS, NULL, }, 506 { "SERCOS", PCI_SUBCLASS_SERIALBUS_SERCOS, NULL, },
463 { "CANbus", PCI_SUBCLASS_SERIALBUS_CANBUS, NULL, }, 507 { "CANbus", PCI_SUBCLASS_SERIALBUS_CANBUS, NULL, },
464 { "miscellaneous", PCI_SUBCLASS_SERIALBUS_MISC, NULL, }, 508 { "miscellaneous", PCI_SUBCLASS_SERIALBUS_MISC, NULL, },
465 { NULL, 0, NULL, }, 509 { NULL, 0, NULL, },
466}; 510};
467 511
468/* 512/*
469 * Class 0x0d. 513 * Class 0x0d.
470 * Wireless Controller. 514 * Wireless Controller.
471 */ 515 */
472static const struct pci_class pci_subclass_wireless[] = { 516static const struct pci_class pci_subclass_wireless[] = {
473 { "IrDA", PCI_SUBCLASS_WIRELESS_IRDA, NULL, }, 517 { "IrDA", PCI_SUBCLASS_WIRELESS_IRDA, NULL, },
474 { "Consumer IR",/*XXX*/ PCI_SUBCLASS_WIRELESS_CONSUMERIR, NULL, }, 518 { "Consumer IR",/*XXX*/ PCI_SUBCLASS_WIRELESS_CONSUMERIR, NULL, },
475 { "RF", PCI_SUBCLASS_WIRELESS_RF, NULL, }, 519 { "RF", PCI_SUBCLASS_WIRELESS_RF, NULL, },
476 { "bluetooth", PCI_SUBCLASS_WIRELESS_BLUETOOTH, NULL, }, 520 { "bluetooth", PCI_SUBCLASS_WIRELESS_BLUETOOTH, NULL, },
477 { "broadband", PCI_SUBCLASS_WIRELESS_BROADBAND, NULL, }, 521 { "broadband", PCI_SUBCLASS_WIRELESS_BROADBAND, NULL, },
478 { "802.11a (5 GHz)", PCI_SUBCLASS_WIRELESS_802_11A, NULL, }, 522 { "802.11a (5 GHz)", PCI_SUBCLASS_WIRELESS_802_11A, NULL, },
479 { "802.11b (2.4 GHz)", PCI_SUBCLASS_WIRELESS_802_11B, NULL, }, 523 { "802.11b (2.4 GHz)", PCI_SUBCLASS_WIRELESS_802_11B, NULL, },
480 { "miscellaneous", PCI_SUBCLASS_WIRELESS_MISC, NULL, }, 524 { "miscellaneous", PCI_SUBCLASS_WIRELESS_MISC, NULL, },
481 { NULL, 0, NULL, }, 525 { NULL, 0, NULL, },
482}; 526};
483 527
484/* 528/*
485 * Class 0x0e. 529 * Class 0x0e.
486 * Intelligent IO controller. 530 * Intelligent IO controller.
487 */ 531 */
488 532
489/* Intelligent IO programming interface */ 533/* Intelligent IO programming interface */
490static const struct pci_class pci_interface_i2o[] = { 534static const struct pci_class pci_interface_i2o[] = {
491 { "FIFO at offset 0x40", PCI_INTERFACE_I2O_FIFOAT40, NULL, }, 535 { "FIFO at offset 0x40", PCI_INTERFACE_I2O_FIFOAT40, NULL, },
492 { NULL, 0, NULL, }, 536 { NULL, 0, NULL, },
493}; 537};
494 538
495/* Subclasses */ 539/* Subclasses */
496static const struct pci_class pci_subclass_i2o[] = { 540static const struct pci_class pci_subclass_i2o[] = {
497 { "standard", PCI_SUBCLASS_I2O_STANDARD, pci_interface_i2o,}, 541 { "standard", PCI_SUBCLASS_I2O_STANDARD, pci_interface_i2o,},
498 { "miscellaneous", PCI_SUBCLASS_I2O_MISC, NULL, }, 542 { "miscellaneous", PCI_SUBCLASS_I2O_MISC, NULL, },
499 { NULL, 0, NULL, }, 543 { NULL, 0, NULL, },
500}; 544};
501 545
502/* 546/*
503 * Class 0x0f. 547 * Class 0x0f.
504 * Satellite communication controller. 548 * Satellite communication controller.
505 */ 549 */
506static const struct pci_class pci_subclass_satcom[] = { 550static const struct pci_class pci_subclass_satcom[] = {
507 { "TV", PCI_SUBCLASS_SATCOM_TV, NULL, }, 551 { "TV", PCI_SUBCLASS_SATCOM_TV, NULL, },
508 { "audio", PCI_SUBCLASS_SATCOM_AUDIO, NULL, }, 552 { "audio", PCI_SUBCLASS_SATCOM_AUDIO, NULL, },
509 { "voice", PCI_SUBCLASS_SATCOM_VOICE, NULL, }, 553 { "voice", PCI_SUBCLASS_SATCOM_VOICE, NULL, },
510 { "data", PCI_SUBCLASS_SATCOM_DATA, NULL, }, 554 { "data", PCI_SUBCLASS_SATCOM_DATA, NULL, },
511 { "miscellaneous", PCI_SUBCLASS_SATCOM_MISC, NULL, }, 555 { "miscellaneous", PCI_SUBCLASS_SATCOM_MISC, NULL, },
512 { NULL, 0, NULL, }, 556 { NULL, 0, NULL, },
513}; 557};
514 558
515/* 559/*
516 * Class 0x10. 560 * Class 0x10.
517 * Encryption/Decryption controller. 561 * Encryption/Decryption controller.
518 */ 562 */
519static const struct pci_class pci_subclass_crypto[] = { 563static const struct pci_class pci_subclass_crypto[] = {
520 { "network/computing", PCI_SUBCLASS_CRYPTO_NETCOMP, NULL, }, 564 { "network/computing", PCI_SUBCLASS_CRYPTO_NETCOMP, NULL, },
521 { "entertainment", PCI_SUBCLASS_CRYPTO_ENTERTAINMENT, NULL,}, 565 { "entertainment", PCI_SUBCLASS_CRYPTO_ENTERTAINMENT, NULL,},
522 { "miscellaneous", PCI_SUBCLASS_CRYPTO_MISC, NULL, }, 566 { "miscellaneous", PCI_SUBCLASS_CRYPTO_MISC, NULL, },
523 { NULL, 0, NULL, }, 567 { NULL, 0, NULL, },
524}; 568};
525 569
526/* 570/*
527 * Class 0x11. 571 * Class 0x11.
528 * Data aquuisition and signal processing controller. 572 * Data aquuisition and signal processing controller.
529 */ 573 */
530static const struct pci_class pci_subclass_dasp[] = { 574static const struct pci_class pci_subclass_dasp[] = {
531 { "DPIO", PCI_SUBCLASS_DASP_DPIO, NULL, }, 575 { "DPIO", PCI_SUBCLASS_DASP_DPIO, NULL, },
532 { "performance counters", PCI_SUBCLASS_DASP_TIMEFREQ, NULL, }, 576 { "performance counters", PCI_SUBCLASS_DASP_TIMEFREQ, NULL, },
533 { "synchronization", PCI_SUBCLASS_DASP_SYNC, NULL, }, 577 { "synchronization", PCI_SUBCLASS_DASP_SYNC, NULL, },
534 { "management", PCI_SUBCLASS_DASP_MGMT, NULL, }, 578 { "management", PCI_SUBCLASS_DASP_MGMT, NULL, },
535 { "miscellaneous", PCI_SUBCLASS_DASP_MISC, NULL, }, 579 { "miscellaneous", PCI_SUBCLASS_DASP_MISC, NULL, },
536 { NULL, 0, NULL, }, 580 { NULL, 0, NULL, },
537}; 581};
538 582
539/* List of classes */ 583/* List of classes */
540static const struct pci_class pci_classes[] = { 584static const struct pci_class pci_classes[] = {
541 { "prehistoric", PCI_CLASS_PREHISTORIC, 585 { "prehistoric", PCI_CLASS_PREHISTORIC,
542 pci_subclass_prehistoric, }, 586 pci_subclass_prehistoric, },
543 { "mass storage", PCI_CLASS_MASS_STORAGE, 587 { "mass storage", PCI_CLASS_MASS_STORAGE,
544 pci_subclass_mass_storage, }, 588 pci_subclass_mass_storage, },
545 { "network", PCI_CLASS_NETWORK, 589 { "network", PCI_CLASS_NETWORK,
546 pci_subclass_network, }, 590 pci_subclass_network, },
547 { "display", PCI_CLASS_DISPLAY, 591 { "display", PCI_CLASS_DISPLAY,
548 pci_subclass_display, }, 592 pci_subclass_display, },
549 { "multimedia", PCI_CLASS_MULTIMEDIA, 593 { "multimedia", PCI_CLASS_MULTIMEDIA,
550 pci_subclass_multimedia, }, 594 pci_subclass_multimedia, },
551 { "memory", PCI_CLASS_MEMORY, 595 { "memory", PCI_CLASS_MEMORY,
552 pci_subclass_memory, }, 596 pci_subclass_memory, },
553 { "bridge", PCI_CLASS_BRIDGE, 597 { "bridge", PCI_CLASS_BRIDGE,
554 pci_subclass_bridge, }, 598 pci_subclass_bridge, },
555 { "communications", PCI_CLASS_COMMUNICATIONS, 599 { "communications", PCI_CLASS_COMMUNICATIONS,
556 pci_subclass_communications, }, 600 pci_subclass_communications, },
557 { "system", PCI_CLASS_SYSTEM, 601 { "system", PCI_CLASS_SYSTEM,
558 pci_subclass_system, }, 602 pci_subclass_system, },
559 { "input", PCI_CLASS_INPUT, 603 { "input", PCI_CLASS_INPUT,
560 pci_subclass_input, }, 604 pci_subclass_input, },
561 { "dock", PCI_CLASS_DOCK, 605 { "dock", PCI_CLASS_DOCK,
562 pci_subclass_dock, }, 606 pci_subclass_dock, },
563 { "processor", PCI_CLASS_PROCESSOR, 607 { "processor", PCI_CLASS_PROCESSOR,
564 pci_subclass_processor, }, 608 pci_subclass_processor, },
565 { "serial bus", PCI_CLASS_SERIALBUS, 609 { "serial bus", PCI_CLASS_SERIALBUS,
566 pci_subclass_serialbus, }, 610 pci_subclass_serialbus, },
567 { "wireless", PCI_CLASS_WIRELESS, 611 { "wireless", PCI_CLASS_WIRELESS,
568 pci_subclass_wireless, }, 612 pci_subclass_wireless, },
569 { "I2O", PCI_CLASS_I2O, 613 { "I2O", PCI_CLASS_I2O,
570 pci_subclass_i2o, }, 614 pci_subclass_i2o, },
571 { "satellite comm", PCI_CLASS_SATCOM, 615 { "satellite comm", PCI_CLASS_SATCOM,
572 pci_subclass_satcom, }, 616 pci_subclass_satcom, },
573 { "crypto", PCI_CLASS_CRYPTO, 617 { "crypto", PCI_CLASS_CRYPTO,
574 pci_subclass_crypto, }, 618 pci_subclass_crypto, },
575 { "DASP", PCI_CLASS_DASP, 619 { "DASP", PCI_CLASS_DASP,
576 pci_subclass_dasp, }, 620 pci_subclass_dasp, },
577 { "processing accelerators", PCI_CLASS_ACCEL, 621 { "processing accelerators", PCI_CLASS_ACCEL,
578 NULL, }, 622 NULL, },
579 { "non-essential instrumentation", PCI_CLASS_INSTRUMENT, 623 { "non-essential instrumentation", PCI_CLASS_INSTRUMENT,
580 NULL, }, 624 NULL, },
581 { "undefined", PCI_CLASS_UNDEFINED, 625 { "undefined", PCI_CLASS_UNDEFINED,
582 NULL, }, 626 NULL, },
583 { NULL, 0, 627 { NULL, 0,
584 NULL, }, 628 NULL, },
585}; 629};
586 630
587DEV_VERBOSE_DEFINE(pci); 631DEV_VERBOSE_DEFINE(pci);
588 632
589/* 633/*
590 * Append a formatted string to dest without writing more than len 634 * Append a formatted string to dest without writing more than len
591 * characters (including the trailing NUL character). dest and len 635 * characters (including the trailing NUL character). dest and len
592 * are updated for use in subsequent calls to snappendf(). 636 * are updated for use in subsequent calls to snappendf().
593 * 637 *
594 * Returns 0 on success, a negative value if vnsprintf() fails, or 638 * Returns 0 on success, a negative value if vnsprintf() fails, or
595 * a positive value if the dest buffer would have overflowed. 639 * a positive value if the dest buffer would have overflowed.
596 */ 640 */
597 641
598static int __printflike(3, 4) 642static int __printflike(3, 4)
599snappendf(char **dest, size_t *len, const char * restrict fmt, ...) 643snappendf(char **dest, size_t *len, const char * restrict fmt, ...)
600{ 644{
601 va_list ap; 645 va_list ap;
602 int count; 646 int count;
603 647
604 va_start(ap, fmt); 648 va_start(ap, fmt);
605 count = vsnprintf(*dest, *len, fmt, ap); 649 count = vsnprintf(*dest, *len, fmt, ap);
606 va_end(ap); 650 va_end(ap);
607 651
608 /* Let vsnprintf() errors bubble up to caller */ 652 /* Let vsnprintf() errors bubble up to caller */
609 if (count < 0 || *len == 0) 653 if (count < 0 || *len == 0)
610 return count; 654 return count;
611 655
612 /* Handle overflow */ 656 /* Handle overflow */
613 if ((size_t)count >= *len) { 657 if ((size_t)count >= *len) {
614 *dest += *len - 1; 658 *dest += *len - 1;
615 *len = 1; 659 *len = 1;
616 return 1; 660 return 1;
617 } 661 }
618 662
619 /* Update dest & len to point at trailing NUL */ 663 /* Update dest & len to point at trailing NUL */
620 *dest += count; 664 *dest += count;
621 *len -= count; 665 *len -= count;
622 666
623 return 0; 667 return 0;
624} 668}
625 669
626void 670void
627pci_devinfo(pcireg_t id_reg, pcireg_t class_reg, int showclass, char *cp, 671pci_devinfo(pcireg_t id_reg, pcireg_t class_reg, int showclass, char *cp,
628 size_t l) 672 size_t l)
629{ 673{
630 pci_class_t class; 674 pci_class_t class;
631 pci_subclass_t subclass; 675 pci_subclass_t subclass;
632 pci_interface_t interface; 676 pci_interface_t interface;
633 pci_revision_t revision; 677 pci_revision_t revision;
634 char vendor[PCI_VENDORSTR_LEN], product[PCI_PRODUCTSTR_LEN]; 678 char vendor[PCI_VENDORSTR_LEN], product[PCI_PRODUCTSTR_LEN];
635 const struct pci_class *classp, *subclassp, *interfacep; 679 const struct pci_class *classp, *subclassp, *interfacep;
636 680
637 class = PCI_CLASS(class_reg); 681 class = PCI_CLASS(class_reg);
638 subclass = PCI_SUBCLASS(class_reg); 682 subclass = PCI_SUBCLASS(class_reg);
639 interface = PCI_INTERFACE(class_reg); 683 interface = PCI_INTERFACE(class_reg);
640 revision = PCI_REVISION(class_reg); 684 revision = PCI_REVISION(class_reg);
641 685
642 pci_findvendor(vendor, sizeof(vendor), PCI_VENDOR(id_reg)); 686 pci_findvendor(vendor, sizeof(vendor), PCI_VENDOR(id_reg));
643 pci_findproduct(product, sizeof(product), PCI_VENDOR(id_reg), 687 pci_findproduct(product, sizeof(product), PCI_VENDOR(id_reg),
644 PCI_PRODUCT(id_reg)); 688 PCI_PRODUCT(id_reg));
645 689
646 classp = pci_classes; 690 classp = pci_classes;
647 while (classp->name != NULL) { 691 while (classp->name != NULL) {
648 if (class == classp->val) 692 if (class == classp->val)
649 break; 693 break;
650 classp++; 694 classp++;
651 } 695 }
652 696
653 subclassp = (classp->name != NULL) ? classp->subclasses : NULL; 697 subclassp = (classp->name != NULL) ? classp->subclasses : NULL;
654 while (subclassp && subclassp->name != NULL) { 698 while (subclassp && subclassp->name != NULL) {
655 if (subclass == subclassp->val) 699 if (subclass == subclassp->val)
656 break; 700 break;
657 subclassp++; 701 subclassp++;
658 } 702 }
659 703
660 interfacep = (subclassp && subclassp->name != NULL) ? 704 interfacep = (subclassp && subclassp->name != NULL) ?
661 subclassp->subclasses : NULL; 705 subclassp->subclasses : NULL;
662 while (interfacep && interfacep->name != NULL) { 706 while (interfacep && interfacep->name != NULL) {
663 if (interface == interfacep->val) 707 if (interface == interfacep->val)
664 break; 708 break;
665 interfacep++; 709 interfacep++;
666 } 710 }
667 711
668 (void)snappendf(&cp, &l, "%s %s", vendor, product); 712 (void)snappendf(&cp, &l, "%s %s", vendor, product);
669 if (showclass) { 713 if (showclass) {
670 (void)snappendf(&cp, &l, " ("); 714 (void)snappendf(&cp, &l, " (");
671 if (classp->name == NULL) 715 if (classp->name == NULL)
672 (void)snappendf(&cp, &l, 716 (void)snappendf(&cp, &l,
673 "class 0x%02x, subclass 0x%02x", 717 "class 0x%02x, subclass 0x%02x",
674 class, subclass); 718 class, subclass);
675 else { 719 else {
676 if (subclassp == NULL || subclassp->name == NULL) 720 if (subclassp == NULL || subclassp->name == NULL)
677 (void)snappendf(&cp, &l, 721 (void)snappendf(&cp, &l,
678 "%s, subclass 0x%02x", 722 "%s, subclass 0x%02x",
679 classp->name, subclass); 723 classp->name, subclass);
680 else 724 else
681 (void)snappendf(&cp, &l, "%s %s", 725 (void)snappendf(&cp, &l, "%s %s",
682 subclassp->name, classp->name); 726 subclassp->name, classp->name);
683 } 727 }
684 if ((interfacep == NULL) || (interfacep->name == NULL)) { 728 if ((interfacep == NULL) || (interfacep->name == NULL)) {
685 if (interface != 0) 729 if (interface != 0)
686 (void)snappendf(&cp, &l, ", interface 0x%02x", 730 (void)snappendf(&cp, &l, ", interface 0x%02x",
687 interface); 731 interface);
688 } else if (strncmp(interfacep->name, "", 1) != 0) 732 } else if (strncmp(interfacep->name, "", 1) != 0)
689 (void)snappendf(&cp, &l, ", %s", interfacep->name); 733 (void)snappendf(&cp, &l, ", %s", interfacep->name);
690 if (revision != 0) 734 if (revision != 0)
691 (void)snappendf(&cp, &l, ", revision 0x%02x", revision); 735 (void)snappendf(&cp, &l, ", revision 0x%02x", revision);
692 (void)snappendf(&cp, &l, ")"); 736 (void)snappendf(&cp, &l, ")");
693 } 737 }
694} 738}
695 739
696#ifdef _KERNEL 740#ifdef _KERNEL
697void 741void
698pci_aprint_devinfo_fancy(const struct pci_attach_args *pa, const char *naive, 742pci_aprint_devinfo_fancy(const struct pci_attach_args *pa, const char *naive,
699 const char *known, int addrev) 743 const char *known, int addrev)
700{ 744{
701 char devinfo[256]; 745 char devinfo[256];
702 746
703 if (known) { 747 if (known) {
704 aprint_normal(": %s", known); 748 aprint_normal(": %s", known);
705 if (addrev) 749 if (addrev)
706 aprint_normal(" (rev. 0x%02x)", 750 aprint_normal(" (rev. 0x%02x)",
707 PCI_REVISION(pa->pa_class)); 751 PCI_REVISION(pa->pa_class));
708 aprint_normal("\n"); 752 aprint_normal("\n");
709 } else { 753 } else {
710 pci_devinfo(pa->pa_id, pa->pa_class, 0, 754 pci_devinfo(pa->pa_id, pa->pa_class, 0,
711 devinfo, sizeof(devinfo)); 755 devinfo, sizeof(devinfo));
712 aprint_normal(": %s (rev. 0x%02x)\n", devinfo, 756 aprint_normal(": %s (rev. 0x%02x)\n", devinfo,
713 PCI_REVISION(pa->pa_class)); 757 PCI_REVISION(pa->pa_class));
714 } 758 }
715 if (naive) 759 if (naive)
716 aprint_naive(": %s\n", naive); 760 aprint_naive(": %s\n", naive);
717 else 761 else
718 aprint_naive("\n"); 762 aprint_naive("\n");
719} 763}
720#endif 764#endif
721 765
722/* 766/*
723 * Print out most of the PCI configuration registers. Typically used 767 * Print out most of the PCI configuration registers. Typically used
724 * in a device attach routine like this: 768 * in a device attach routine like this:
725 * 769 *
726 * #ifdef MYDEV_DEBUG 770 * #ifdef MYDEV_DEBUG
727 * printf("%s: ", device_xname(sc->sc_dev)); 771 * printf("%s: ", device_xname(sc->sc_dev));
728 * pci_conf_print(pa->pa_pc, pa->pa_tag, NULL); 772 * pci_conf_print(pa->pa_pc, pa->pa_tag, NULL);
729 * #endif 773 * #endif
730 */ 774 */
731 775
732#define i2o(i) ((i) * 4) 776#define i2o(i) ((i) * 4)
733#define o2i(o) ((o) / 4) 777#define o2i(o) ((o) / 4)
734#define onoff2(str, rval, bit, onstr, offstr) \ 778#define onoff2(str, rval, bit, onstr, offstr) \
735 /*CONSTCOND*/ \ 779 /*CONSTCOND*/ \
736 printf(" %s: %s\n", (str), ((rval) & (bit)) ? onstr : offstr); 780 printf(" %s: %s\n", (str), ((rval) & (bit)) ? onstr : offstr);
737#define onoff(str, rval, bit) onoff2(str, rval, bit, "on", "off") 781#define onoff(str, rval, bit) onoff2(str, rval, bit, "on", "off")
738 782
739static void 783static void
740pci_conf_print_common( 784pci_conf_print_common(
741#ifdef _KERNEL 785#ifdef _KERNEL
742 pci_chipset_tag_t pc, pcitag_t tag, 786 pci_chipset_tag_t pc, pcitag_t tag,
743#endif 787#endif
744 const pcireg_t *regs) 788 const pcireg_t *regs)
745{ 789{
746 pci_class_t class; 790 pci_class_t class;
747 pci_subclass_t subclass; 791 pci_subclass_t subclass;
748 pci_interface_t interface; 792 pci_interface_t interface;
749 pci_revision_t revision; 793 pci_revision_t revision;
750 char vendor[PCI_VENDORSTR_LEN], product[PCI_PRODUCTSTR_LEN]; 794 char vendor[PCI_VENDORSTR_LEN], product[PCI_PRODUCTSTR_LEN];
751 const struct pci_class *classp, *subclassp, *interfacep; 795 const struct pci_class *classp, *subclassp, *interfacep;
752 const char *name; 796 const char *name;
753 pcireg_t rval; 797 pcireg_t rval;
754 unsigned int num; 798 unsigned int num;
755 799
756 rval = regs[o2i(PCI_CLASS_REG)]; 800 rval = regs[o2i(PCI_CLASS_REG)];
757 class = PCI_CLASS(rval); 801 class = PCI_CLASS(rval);
758 subclass = PCI_SUBCLASS(rval); 802 subclass = PCI_SUBCLASS(rval);
759 interface = PCI_INTERFACE(rval); 803 interface = PCI_INTERFACE(rval);
760 revision = PCI_REVISION(rval); 804 revision = PCI_REVISION(rval);
761 805
762 rval = regs[o2i(PCI_ID_REG)]; 806 rval = regs[o2i(PCI_ID_REG)];
763 name = pci_findvendor(vendor, sizeof(vendor), PCI_VENDOR(rval)); 807 name = pci_findvendor(vendor, sizeof(vendor), PCI_VENDOR(rval));
764 if (name) 808 if (name)
765 printf(" Vendor Name: %s (0x%04x)\n", name, 809 printf(" Vendor Name: %s (0x%04x)\n", name,
766 PCI_VENDOR(rval)); 810 PCI_VENDOR(rval));
767 else 811 else
768 printf(" Vendor ID: 0x%04x\n", PCI_VENDOR(rval)); 812 printf(" Vendor ID: 0x%04x\n", PCI_VENDOR(rval));
769 name = pci_findproduct(product, sizeof(product), PCI_VENDOR(rval), 813 name = pci_findproduct(product, sizeof(product), PCI_VENDOR(rval),
770 PCI_PRODUCT(rval)); 814 PCI_PRODUCT(rval));
771 if (name) 815 if (name)
772 printf(" Device Name: %s (0x%04x)\n", name, 816 printf(" Device Name: %s (0x%04x)\n", name,
773 PCI_PRODUCT(rval)); 817 PCI_PRODUCT(rval));
774 else 818 else
775 printf(" Device ID: 0x%04x\n", PCI_PRODUCT(rval)); 819 printf(" Device ID: 0x%04x\n", PCI_PRODUCT(rval));
776 820
777 rval = regs[o2i(PCI_COMMAND_STATUS_REG)]; 821 rval = regs[o2i(PCI_COMMAND_STATUS_REG)];
778 822
779 printf(" Command register: 0x%04x\n", rval & 0xffff); 823 printf(" Command register: 0x%04x\n", rval & 0xffff);
780 onoff("I/O space accesses", rval, PCI_COMMAND_IO_ENABLE); 824 onoff("I/O space accesses", rval, PCI_COMMAND_IO_ENABLE);
781 onoff("Memory space accesses", rval, PCI_COMMAND_MEM_ENABLE); 825 onoff("Memory space accesses", rval, PCI_COMMAND_MEM_ENABLE);
782 onoff("Bus mastering", rval, PCI_COMMAND_MASTER_ENABLE); 826 onoff("Bus mastering", rval, PCI_COMMAND_MASTER_ENABLE);
783 onoff("Special cycles", rval, PCI_COMMAND_SPECIAL_ENABLE); 827 onoff("Special cycles", rval, PCI_COMMAND_SPECIAL_ENABLE);
784 onoff("MWI transactions", rval, PCI_COMMAND_INVALIDATE_ENABLE); 828 onoff("MWI transactions", rval, PCI_COMMAND_INVALIDATE_ENABLE);
785 onoff("Palette snooping", rval, PCI_COMMAND_PALETTE_ENABLE); 829 onoff("Palette snooping", rval, PCI_COMMAND_PALETTE_ENABLE);
786 onoff("Parity error checking", rval, PCI_COMMAND_PARITY_ENABLE); 830 onoff("Parity error checking", rval, PCI_COMMAND_PARITY_ENABLE);
787 onoff("Address/data stepping", rval, PCI_COMMAND_STEPPING_ENABLE); 831 onoff("Address/data stepping", rval, PCI_COMMAND_STEPPING_ENABLE);
788 onoff("System error (SERR)", rval, PCI_COMMAND_SERR_ENABLE); 832 onoff("System error (SERR)", rval, PCI_COMMAND_SERR_ENABLE);
789 onoff("Fast back-to-back transactions", rval, 833 onoff("Fast back-to-back transactions", rval,
790 PCI_COMMAND_BACKTOBACK_ENABLE); 834 PCI_COMMAND_BACKTOBACK_ENABLE);
791 onoff("Interrupt disable", rval, PCI_COMMAND_INTERRUPT_DISABLE); 835 onoff("Interrupt disable", rval, PCI_COMMAND_INTERRUPT_DISABLE);
792 836
793 printf(" Status register: 0x%04x\n", (rval >> 16) & 0xffff); 837 printf(" Status register: 0x%04x\n", (rval >> 16) & 0xffff);
794 onoff("Immediate Readiness", rval, PCI_STATUS_IMMD_READNESS); 838 onoff("Immediate Readiness", rval, PCI_STATUS_IMMD_READNESS);
795 onoff2("Interrupt status", rval, PCI_STATUS_INT_STATUS, "active", 839 onoff2("Interrupt status", rval, PCI_STATUS_INT_STATUS, "active",
796 "inactive"); 840 "inactive");
797 onoff("Capability List support", rval, PCI_STATUS_CAPLIST_SUPPORT); 841 onoff("Capability List support", rval, PCI_STATUS_CAPLIST_SUPPORT);
798 onoff("66 MHz capable", rval, PCI_STATUS_66MHZ_SUPPORT); 842 onoff("66 MHz capable", rval, PCI_STATUS_66MHZ_SUPPORT);
799 onoff("User Definable Features (UDF) support", rval, 843 onoff("User Definable Features (UDF) support", rval,
800 PCI_STATUS_UDF_SUPPORT); 844 PCI_STATUS_UDF_SUPPORT);
801 onoff("Fast back-to-back capable", rval, 845 onoff("Fast back-to-back capable", rval,
802 PCI_STATUS_BACKTOBACK_SUPPORT); 846 PCI_STATUS_BACKTOBACK_SUPPORT);
803 onoff("Data parity error detected", rval, PCI_STATUS_PARITY_ERROR); 847 onoff("Data parity error detected", rval, PCI_STATUS_PARITY_ERROR);
804 848
805 printf(" DEVSEL timing: "); 849 printf(" DEVSEL timing: ");
806 switch (rval & PCI_STATUS_DEVSEL_MASK) { 850 switch (rval & PCI_STATUS_DEVSEL_MASK) {
807 case PCI_STATUS_DEVSEL_FAST: 851 case PCI_STATUS_DEVSEL_FAST:
808 printf("fast"); 852 printf("fast");
809 break; 853 break;
810 case PCI_STATUS_DEVSEL_MEDIUM: 854 case PCI_STATUS_DEVSEL_MEDIUM:
811 printf("medium"); 855 printf("medium");
812 break; 856 break;
813 case PCI_STATUS_DEVSEL_SLOW: 857 case PCI_STATUS_DEVSEL_SLOW:
814 printf("slow"); 858 printf("slow");
815 break; 859 break;
816 default: 860 default:
817 printf("unknown/reserved"); /* XXX */ 861 printf("unknown/reserved"); /* XXX */
818 break; 862 break;
819 } 863 }
820 printf(" (0x%x)\n", PCIREG_SHIFTOUT(rval, PCI_STATUS_DEVSEL_MASK)); 864 printf(" (0x%x)\n", PCIREG_SHIFTOUT(rval, PCI_STATUS_DEVSEL_MASK));
821 865
822 onoff("Slave signaled Target Abort", rval, 866 onoff("Slave signaled Target Abort", rval,
823 PCI_STATUS_TARGET_TARGET_ABORT); 867 PCI_STATUS_TARGET_TARGET_ABORT);
824 onoff("Master received Target Abort", rval, 868 onoff("Master received Target Abort", rval,
825 PCI_STATUS_MASTER_TARGET_ABORT); 869 PCI_STATUS_MASTER_TARGET_ABORT);
826 onoff("Master received Master Abort", rval, PCI_STATUS_MASTER_ABORT); 870 onoff("Master received Master Abort", rval, PCI_STATUS_MASTER_ABORT);
827 onoff("Asserted System Error (SERR)", rval, PCI_STATUS_SPECIAL_ERROR); 871 onoff("Asserted System Error (SERR)", rval, PCI_STATUS_SPECIAL_ERROR);
828 onoff("Parity error detected", rval, PCI_STATUS_PARITY_DETECT); 872 onoff("Parity error detected", rval, PCI_STATUS_PARITY_DETECT);
829 873
830 rval = regs[o2i(PCI_CLASS_REG)]; 874 rval = regs[o2i(PCI_CLASS_REG)];
831 for (classp = pci_classes; classp->name != NULL; classp++) { 875 for (classp = pci_classes; classp->name != NULL; classp++) {
832 if (class == classp->val) 876 if (class == classp->val)
833 break; 877 break;
834 } 878 }
835 879
836 /* 880 /*
837 * ECN: Change Root Complex Event Collector Class Code 881 * ECN: Change Root Complex Event Collector Class Code
838 * Old RCEC has subclass 0x06. It's the same as IOMMU. Read the type 882 * Old RCEC has subclass 0x06. It's the same as IOMMU. Read the type
839 * in PCIe extend capability to know whether it's RCEC or IOMMU. 883 * in PCIe extend capability to know whether it's RCEC or IOMMU.
840 */ 884 */
841 if ((class == PCI_CLASS_SYSTEM) 885 if ((class == PCI_CLASS_SYSTEM)
842 && (subclass == PCI_SUBCLASS_SYSTEM_IOMMU)) { 886 && (subclass == PCI_SUBCLASS_SYSTEM_IOMMU)) {
843 int pcie_capoff; 887 int pcie_capoff;
844 pcireg_t reg; 888 pcireg_t reg;
845 889
846 if (pci_conf_find_cap(regs, PCI_CAP_PCIEXPRESS, &pcie_capoff)) { 890 if (pci_conf_find_cap(regs, PCI_CAP_PCIEXPRESS, &pcie_capoff)) {
847 reg = regs[o2i(pcie_capoff + PCIE_XCAP)]; 891 reg = regs[o2i(pcie_capoff + PCIE_XCAP)];
848 if (PCIE_XCAP_TYPE(reg) == PCIE_XCAP_TYPE_ROOT_EVNTC) 892 if (PCIE_XCAP_TYPE(reg) == PCIE_XCAP_TYPE_ROOT_EVNTC)
849 subclass = PCI_SUBCLASS_SYSTEM_RCEC; 893 subclass = PCI_SUBCLASS_SYSTEM_RCEC;
850 } 894 }
851 } 895 }
852 subclassp = (classp->name != NULL) ? classp->subclasses : NULL; 896 subclassp = (classp->name != NULL) ? classp->subclasses : NULL;
853 while (subclassp && subclassp->name != NULL) { 897 while (subclassp && subclassp->name != NULL) {
854 if (subclass == subclassp->val) 898 if (subclass == subclassp->val)
855 break; 899 break;
856 subclassp++; 900 subclassp++;
857 } 901 }
858 902
859 interfacep = (subclassp && subclassp->name != NULL) ? 903 interfacep = (subclassp && subclassp->name != NULL) ?
860 subclassp->subclasses : NULL; 904 subclassp->subclasses : NULL;
861 while (interfacep && interfacep->name != NULL) { 905 while (interfacep && interfacep->name != NULL) {
862 if (interface == interfacep->val) 906 if (interface == interfacep->val)
863 break; 907 break;
864 interfacep++; 908 interfacep++;
865 } 909 }
866 910
867 if (classp->name != NULL) 911 if (classp->name != NULL)
868 printf(" Class Name: %s (0x%02x)\n", classp->name, class); 912 printf(" Class Name: %s (0x%02x)\n", classp->name, class);
869 else 913 else
870 printf(" Class ID: 0x%02x\n", class); 914 printf(" Class ID: 0x%02x\n", class);
871 if (subclassp != NULL && subclassp->name != NULL) 915 if (subclassp != NULL && subclassp->name != NULL)
872 printf(" Subclass Name: %s (0x%02x)\n", 916 printf(" Subclass Name: %s (0x%02x)\n",
873 subclassp->name, PCI_SUBCLASS(rval)); 917 subclassp->name, PCI_SUBCLASS(rval));
874 else 918 else
875 printf(" Subclass ID: 0x%02x\n", PCI_SUBCLASS(rval)); 919 printf(" Subclass ID: 0x%02x\n", PCI_SUBCLASS(rval));
876 if ((interfacep != NULL) && (interfacep->name != NULL) 920 if ((interfacep != NULL) && (interfacep->name != NULL)
877 && (strncmp(interfacep->name, "", 1) != 0)) 921 && (strncmp(interfacep->name, "", 1) != 0))
878 printf(" Interface Name: %s (0x%02x)\n", 922 printf(" Interface Name: %s (0x%02x)\n",
879 interfacep->name, interface); 923 interfacep->name, interface);
880 else 924 else
881 printf(" Interface: 0x%02x\n", interface); 925 printf(" Interface: 0x%02x\n", interface);
882 printf(" Revision ID: 0x%02x\n", revision); 926 printf(" Revision ID: 0x%02x\n", revision);
883 927
884 rval = regs[o2i(PCI_BHLC_REG)]; 928 rval = regs[o2i(PCI_BHLC_REG)];
885 printf(" BIST: 0x%02x\n", PCI_BIST(rval)); 929 printf(" BIST: 0x%02x\n", PCI_BIST(rval));
886 printf(" Header Type: 0x%02x%s (0x%02x)\n", PCI_HDRTYPE_TYPE(rval), 930 printf(" Header Type: 0x%02x%s (0x%02x)\n", PCI_HDRTYPE_TYPE(rval),
887 PCI_HDRTYPE_MULTIFN(rval) ? "+multifunction" : "", 931 PCI_HDRTYPE_MULTIFN(rval) ? "+multifunction" : "",
888 PCI_HDRTYPE(rval)); 932 PCI_HDRTYPE(rval));
889 printf(" Latency Timer: 0x%02x\n", PCI_LATTIMER(rval)); 933 printf(" Latency Timer: 0x%02x\n", PCI_LATTIMER(rval));
890 num = PCI_CACHELINE(rval); 934 num = PCI_CACHELINE(rval);
891 printf(" Cache Line Size: %ubytes (0x%02x)\n", num * 4, num); 935 printf(" Cache Line Size: %ubytes (0x%02x)\n", num * 4, num);
892} 936}
893 937
894static int 938static int
895pci_conf_print_bar( 939pci_conf_print_bar(
896#ifdef _KERNEL 940#ifdef _KERNEL
897 pci_chipset_tag_t pc, pcitag_t tag, 941 pci_chipset_tag_t pc, pcitag_t tag,
898#endif 942#endif
899 const pcireg_t *regs, int reg, const char *name) 943 const pcireg_t *regs, int reg, const char *name)
900{ 944{
901 int width; 945 int width;
902 pcireg_t rval, rval64h; 946 pcireg_t rval, rval64h;
903 bool ioen, memen; 947 bool ioen, memen;
904#ifdef _KERNEL 948#ifdef _KERNEL
905 pcireg_t mask, mask64h = 0; 949 pcireg_t mask, mask64h = 0;
906#endif 950#endif
907 951
908 rval = regs[o2i(PCI_COMMAND_STATUS_REG)]; 952 rval = regs[o2i(PCI_COMMAND_STATUS_REG)];
909 ioen = rval & PCI_COMMAND_IO_ENABLE; 953 ioen = rval & PCI_COMMAND_IO_ENABLE;
910 memen = rval & PCI_COMMAND_MEM_ENABLE; 954 memen = rval & PCI_COMMAND_MEM_ENABLE;
911 955
912 width = 4; 956 width = 4;
913 /* 957 /*
914 * Section 6.2.5.1, `Address Maps', tells us that: 958 * Section 6.2.5.1, `Address Maps', tells us that:
915 * 959 *
916 * 1) The builtin software should have already mapped the 960 * 1) The builtin software should have already mapped the
917 * device in a reasonable way. 961 * device in a reasonable way.
918 * 962 *
919 * 2) A device which wants 2^n bytes of memory will hardwire 963 * 2) A device which wants 2^n bytes of memory will hardwire
920 * the bottom n bits of the address to 0. As recommended, 964 * the bottom n bits of the address to 0. As recommended,
921 * we write all 1s and see what we get back. 965 * we write all 1s and see what we get back.
922 */ 966 */
923 967
924 rval = regs[o2i(reg)]; 968 rval = regs[o2i(reg)];
925 if (PCI_MAPREG_TYPE(rval) == PCI_MAPREG_TYPE_MEM && 969 if (PCI_MAPREG_TYPE(rval) == PCI_MAPREG_TYPE_MEM &&
926 PCI_MAPREG_MEM_TYPE(rval) == PCI_MAPREG_MEM_TYPE_64BIT) { 970 PCI_MAPREG_MEM_TYPE(rval) == PCI_MAPREG_MEM_TYPE_64BIT) {
927 rval64h = regs[o2i(reg + 4)]; 971 rval64h = regs[o2i(reg + 4)];
928 width = 8; 972 width = 8;
929 } else 973 } else
930 rval64h = 0; 974 rval64h = 0;
931 975
932#ifdef _KERNEL 976#ifdef _KERNEL
933 if (rval != 0 && memen) { 977 if (rval != 0 && memen) {
934 int s; 978 int s;
935 979
936 /* 980 /*
937 * The following sequence seems to make some devices 981 * The following sequence seems to make some devices
938 * (e.g. host bus bridges, which don't normally 982 * (e.g. host bus bridges, which don't normally
939 * have their space mapped) very unhappy, to 983 * have their space mapped) very unhappy, to
940 * the point of crashing the system. 984 * the point of crashing the system.
941 * 985 *
942 * Therefore, if the mapping register is zero to 986 * Therefore, if the mapping register is zero to
943 * start out with, don't bother trying. 987 * start out with, don't bother trying.
944 */ 988 */
945 s = splhigh(); 989 s = splhigh();
946 pci_conf_write(pc, tag, reg, 0xffffffff); 990 pci_conf_write(pc, tag, reg, 0xffffffff);
947 mask = pci_conf_read(pc, tag, reg); 991 mask = pci_conf_read(pc, tag, reg);
948 pci_conf_write(pc, tag, reg, rval); 992 pci_conf_write(pc, tag, reg, rval);
949 if (PCI_MAPREG_TYPE(rval) == PCI_MAPREG_TYPE_MEM && 993 if (PCI_MAPREG_TYPE(rval) == PCI_MAPREG_TYPE_MEM &&
950 PCI_MAPREG_MEM_TYPE(rval) == PCI_MAPREG_MEM_TYPE_64BIT) { 994 PCI_MAPREG_MEM_TYPE(rval) == PCI_MAPREG_MEM_TYPE_64BIT) {
951 pci_conf_write(pc, tag, reg + 4, 0xffffffff); 995 pci_conf_write(pc, tag, reg + 4, 0xffffffff);
952 mask64h = pci_conf_read(pc, tag, reg + 4); 996 mask64h = pci_conf_read(pc, tag, reg + 4);
953 pci_conf_write(pc, tag, reg + 4, rval64h); 997 pci_conf_write(pc, tag, reg + 4, rval64h);
954 } 998 }
955 splx(s); 999 splx(s);
956 } else 1000 } else
957 mask = mask64h = 0; 1001 mask = mask64h = 0;
958#endif /* _KERNEL */ 1002#endif /* _KERNEL */
959 1003
960 printf(" Base address register at 0x%02x", reg); 1004 printf(" Base address register at 0x%02x", reg);
961 if (name) 1005 if (name)
962 printf(" (%s)", name); 1006 printf(" (%s)", name);
963 printf("\n "); 1007 printf("\n ");
964 if (rval == 0) { 1008 if (rval == 0) {
965 printf("not implemented\n"); 1009 printf("not implemented\n");
966 return width; 1010 return width;
967 } 1011 }
968 printf("type: "); 1012 printf("type: ");
969 if (PCI_MAPREG_TYPE(rval) == PCI_MAPREG_TYPE_MEM) { 1013 if (PCI_MAPREG_TYPE(rval) == PCI_MAPREG_TYPE_MEM) {
970 const char *type, *prefetch; 1014 const char *type, *prefetch;
971 1015
972 switch (PCI_MAPREG_MEM_TYPE(rval)) { 1016 switch (PCI_MAPREG_MEM_TYPE(rval)) {
973 case PCI_MAPREG_MEM_TYPE_32BIT: 1017 case PCI_MAPREG_MEM_TYPE_32BIT:
974 type = "32-bit"; 1018 type = "32-bit";
975 break; 1019 break;
976 case PCI_MAPREG_MEM_TYPE_32BIT_1M: 1020 case PCI_MAPREG_MEM_TYPE_32BIT_1M:
977 type = "32-bit-1M"; 1021 type = "32-bit-1M";
978 break; 1022 break;
979 case PCI_MAPREG_MEM_TYPE_64BIT: 1023 case PCI_MAPREG_MEM_TYPE_64BIT:
980 type = "64-bit"; 1024 type = "64-bit";
981 break; 1025 break;
982 default: 1026 default:
983 type = "unknown (XXX)"; 1027 type = "unknown (XXX)";
984 break; 1028 break;
985 } 1029 }
986 if (PCI_MAPREG_MEM_PREFETCHABLE(rval)) 1030 if (PCI_MAPREG_MEM_PREFETCHABLE(rval))
987 prefetch = ""; 1031 prefetch = "";
988 else 1032 else
989 prefetch = "non"; 1033 prefetch = "non";
990 printf("%s %sprefetchable memory\n", type, prefetch); 1034 printf("%s %sprefetchable memory\n", type, prefetch);
991 switch (PCI_MAPREG_MEM_TYPE(rval)) { 1035 switch (PCI_MAPREG_MEM_TYPE(rval)) {
992 case PCI_MAPREG_MEM_TYPE_64BIT: 1036 case PCI_MAPREG_MEM_TYPE_64BIT:
993 printf(" base: 0x%016llx", 1037 printf(" base: 0x%016llx",
994 PCI_MAPREG_MEM64_ADDR( 1038 PCI_MAPREG_MEM64_ADDR(
995 ((((long long) rval64h) << 32) | rval))); 1039 ((((long long) rval64h) << 32) | rval)));
996 if (!memen) 1040 if (!memen)
997 printf(", disabled"); 1041 printf(", disabled");
998 printf("\n"); 1042 printf("\n");
999#ifdef _KERNEL 1043#ifdef _KERNEL
1000 printf(" size: 0x%016llx\n", 1044 printf(" size: 0x%016llx\n",
1001 PCI_MAPREG_MEM64_SIZE( 1045 PCI_MAPREG_MEM64_SIZE(
1002 ((((long long) mask64h) << 32) | mask))); 1046 ((((long long) mask64h) << 32) | mask)));
1003#endif 1047#endif
1004 break; 1048 break;
1005 case PCI_MAPREG_MEM_TYPE_32BIT: 1049 case PCI_MAPREG_MEM_TYPE_32BIT:
1006 case PCI_MAPREG_MEM_TYPE_32BIT_1M: 1050 case PCI_MAPREG_MEM_TYPE_32BIT_1M:
1007 default: 1051 default:
1008 printf(" base: 0x%08x", 1052 printf(" base: 0x%08x",
1009 PCI_MAPREG_MEM_ADDR(rval)); 1053 PCI_MAPREG_MEM_ADDR(rval));
1010 if (!memen) 1054 if (!memen)
1011 printf(", disabled"); 1055 printf(", disabled");
1012 printf("\n"); 1056 printf("\n");
1013#ifdef _KERNEL 1057#ifdef _KERNEL
1014 printf(" size: 0x%08x\n", 1058 printf(" size: 0x%08x\n",
1015 PCI_MAPREG_MEM_SIZE(mask)); 1059 PCI_MAPREG_MEM_SIZE(mask));
1016#endif 1060#endif
1017 break; 1061 break;
1018 } 1062 }
1019 } else { 1063 } else {
1020#ifdef _KERNEL 1064#ifdef _KERNEL
1021 if (ioen) 1065 if (ioen)
1022 printf("%d-bit ", mask & ~0x0000ffff ? 32 : 16); 1066 printf("%d-bit ", mask & ~0x0000ffff ? 32 : 16);
1023#endif 1067#endif
1024 printf("I/O\n"); 1068 printf("I/O\n");
1025 printf(" base: 0x%08x", PCI_MAPREG_IO_ADDR(rval)); 1069 printf(" base: 0x%08x", PCI_MAPREG_IO_ADDR(rval));
1026 if (!ioen) 1070 if (!ioen)
1027 printf(", disabled"); 1071 printf(", disabled");
1028 printf("\n"); 1072 printf("\n");
1029#ifdef _KERNEL 1073#ifdef _KERNEL
1030 printf(" size: 0x%08x\n", PCI_MAPREG_IO_SIZE(mask)); 1074 printf(" size: 0x%08x\n", PCI_MAPREG_IO_SIZE(mask));
1031#endif 1075#endif
1032 } 1076 }
1033 1077
1034 return width; 1078 return width;
1035} 1079}
1036 1080
1037static void 1081static void
1038pci_conf_print_regs(const pcireg_t *regs, int first, int pastlast) 1082pci_conf_print_regs(const pcireg_t *regs, int first, int pastlast)
1039{ 1083{
1040 int off, needaddr, neednl; 1084 int off, needaddr, neednl;
1041 1085
1042 needaddr = 1; 1086 needaddr = 1;
1043 neednl = 0; 1087 neednl = 0;
1044 for (off = first; off < pastlast; off += 4) { 1088 for (off = first; off < pastlast; off += 4) {
1045 if ((off % 16) == 0 || needaddr) { 1089 if ((off % 16) == 0 || needaddr) {
1046 printf(" 0x%02x:", off); 1090 printf(" 0x%02x:", off);
1047 needaddr = 0; 1091 needaddr = 0;
1048 } 1092 }
1049 printf(" 0x%08x", regs[o2i(off)]); 1093 printf(" 0x%08x", regs[o2i(off)]);
1050 neednl = 1; 1094 neednl = 1;
1051 if ((off % 16) == 12) { 1095 if ((off % 16) == 12) {
1052 printf("\n"); 1096 printf("\n");
1053 neednl = 0; 1097 neednl = 0;
1054 } 1098 }
1055 } 1099 }
1056 if (neednl) 1100 if (neednl)
1057 printf("\n"); 1101 printf("\n");
1058} 1102}
1059 1103
1060static const char * 1104static const char *
1061pci_conf_print_agp_calcycle(uint8_t cal) 1105pci_conf_print_agp_calcycle(uint8_t cal)
1062{ 1106{
1063 1107
1064 switch (cal) { 1108 switch (cal) {
1065 case 0x0: 1109 case 0x0:
1066 return "4ms"; 1110 return "4ms";
1067 case 0x1: 1111 case 0x1:
1068 return "16ms"; 1112 return "16ms";
1069 case 0x2: 1113 case 0x2:
1070 return "64ms"; 1114 return "64ms";
1071 case 0x3: 1115 case 0x3:
1072 return "256ms"; 1116 return "256ms";
1073 case 0x7: 1117 case 0x7:
1074 return "Calibration Cycle Not Needed"; 1118 return "Calibration Cycle Not Needed";
1075 default: 1119 default:
1076 return "(reserved)"; 1120 return "(reserved)";
1077 } 1121 }
1078} 1122}
1079 1123
1080static void 1124static void
1081pci_conf_print_agp_datarate(pcireg_t reg, bool isagp3) 1125pci_conf_print_agp_datarate(pcireg_t reg, bool isagp3)
1082{ 1126{
1083 if (isagp3) { 1127 if (isagp3) {
1084 /* AGP 3.0 */ 1128 /* AGP 3.0 */
1085 if (reg & AGP_MODE_V3_RATE_4x) 1129 if (reg & AGP_MODE_V3_RATE_4x)

cvs diff -r1.113 -r1.114 src/sys/dev/pci/pcivar.h (switch to unified diff)

--- src/sys/dev/pci/pcivar.h 2018/12/01 01:23:24 1.113
+++ src/sys/dev/pci/pcivar.h 2021/01/27 05:00:16 1.114
@@ -1,427 +1,443 @@ @@ -1,427 +1,443 @@
1/* $NetBSD: pcivar.h,v 1.113 2018/12/01 01:23:24 msaitoh Exp $ */ 1/* $NetBSD: pcivar.h,v 1.114 2021/01/27 05:00:16 thorpej Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996, 1997 Christopher G. Demetriou. All rights reserved. 4 * Copyright (c) 1996, 1997 Christopher G. Demetriou. All rights reserved.
5 * Copyright (c) 1994 Charles M. Hannum. All rights reserved. 5 * Copyright (c) 1994 Charles M. Hannum. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software 15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement: 16 * must display the following acknowledgement:
17 * This product includes software developed by Charles M. Hannum. 17 * This product includes software developed by Charles M. Hannum.
18 * 4. The name of the author may not be used to endorse or promote products 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. 19 * derived from this software without specific prior written permission.
20 * 20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 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 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 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 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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 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. 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */ 31 */
32 32
33#ifndef _DEV_PCI_PCIVAR_H_ 33#ifndef _DEV_PCI_PCIVAR_H_
34#define _DEV_PCI_PCIVAR_H_ 34#define _DEV_PCI_PCIVAR_H_
35 35
36/* 36/*
37 * Definitions for PCI autoconfiguration. 37 * Definitions for PCI autoconfiguration.
38 * 38 *
39 * This file describes types and functions which are used for PCI 39 * This file describes types and functions which are used for PCI
40 * configuration. Some of this information is machine-specific, and is 40 * configuration. Some of this information is machine-specific, and is
41 * provided by pci_machdep.h. 41 * provided by pci_machdep.h.
42 */ 42 */
43 43
44#include <sys/device.h> 44#include <sys/device.h>
45#include <sys/pmf.h> 45#include <sys/pmf.h>
46#include <sys/bus.h> 46#include <sys/bus.h>
47#include <dev/pci/pcireg.h> 47#include <dev/pci/pcireg.h>
48#include <dev/pci/pci_verbose.h> 48#include <dev/pci/pci_verbose.h>
49 49
50/* 50/*
51 * Structures and definitions needed by the machine-dependent header. 51 * Structures and definitions needed by the machine-dependent header.
52 */ 52 */
53struct pcibus_attach_args; 53struct pcibus_attach_args;
54struct pci_attach_args; 54struct pci_attach_args;
55struct pci_softc; 55struct pci_softc;
56 56
57#ifdef _KERNEL 57#ifdef _KERNEL
58/* 58/*
59 * Machine-dependent definitions. 59 * Machine-dependent definitions.
60 */ 60 */
61#include <machine/pci_machdep.h> 61#include <machine/pci_machdep.h>
62 62
63enum pci_override_idx { 63enum pci_override_idx {
64 PCI_OVERRIDE_CONF_READ = __BIT(0) 64 PCI_OVERRIDE_CONF_READ = __BIT(0)
65 , PCI_OVERRIDE_CONF_WRITE = __BIT(1) 65 , PCI_OVERRIDE_CONF_WRITE = __BIT(1)
66 , PCI_OVERRIDE_INTR_MAP = __BIT(2) 66 , PCI_OVERRIDE_INTR_MAP = __BIT(2)
67 , PCI_OVERRIDE_INTR_STRING = __BIT(3) 67 , PCI_OVERRIDE_INTR_STRING = __BIT(3)
68 , PCI_OVERRIDE_INTR_EVCNT = __BIT(4) 68 , PCI_OVERRIDE_INTR_EVCNT = __BIT(4)
69 , PCI_OVERRIDE_INTR_ESTABLISH = __BIT(5) 69 , PCI_OVERRIDE_INTR_ESTABLISH = __BIT(5)
70 , PCI_OVERRIDE_INTR_DISESTABLISH = __BIT(6) 70 , PCI_OVERRIDE_INTR_DISESTABLISH = __BIT(6)
71 , PCI_OVERRIDE_MAKE_TAG = __BIT(7) 71 , PCI_OVERRIDE_MAKE_TAG = __BIT(7)
72 , PCI_OVERRIDE_DECOMPOSE_TAG = __BIT(8) 72 , PCI_OVERRIDE_DECOMPOSE_TAG = __BIT(8)
73}; 73};
74 74
75/* Only add new fields to the end of this structure! */ 75/* Only add new fields to the end of this structure! */
76struct pci_overrides { 76struct pci_overrides {
77 pcireg_t (*ov_conf_read)(void *, pci_chipset_tag_t, pcitag_t, int); 77 pcireg_t (*ov_conf_read)(void *, pci_chipset_tag_t, pcitag_t, int);
78 void (*ov_conf_write)(void *, pci_chipset_tag_t, pcitag_t, int, 78 void (*ov_conf_write)(void *, pci_chipset_tag_t, pcitag_t, int,
79 pcireg_t); 79 pcireg_t);
80 int (*ov_intr_map)(void *, const struct pci_attach_args *, 80 int (*ov_intr_map)(void *, const struct pci_attach_args *,
81 pci_intr_handle_t *); 81 pci_intr_handle_t *);
82 const char *(*ov_intr_string)(void *, pci_chipset_tag_t, 82 const char *(*ov_intr_string)(void *, pci_chipset_tag_t,
83 pci_intr_handle_t, char *, size_t); 83 pci_intr_handle_t, char *, size_t);
84 const struct evcnt *(*ov_intr_evcnt)(void *, pci_chipset_tag_t, 84 const struct evcnt *(*ov_intr_evcnt)(void *, pci_chipset_tag_t,
85 pci_intr_handle_t); 85 pci_intr_handle_t);
86 void *(*ov_intr_establish)(void *, pci_chipset_tag_t, pci_intr_handle_t, 86 void *(*ov_intr_establish)(void *, pci_chipset_tag_t, pci_intr_handle_t,
87 int, int (*)(void *), void *); 87 int, int (*)(void *), void *);
88 void (*ov_intr_disestablish)(void *, pci_chipset_tag_t, void *); 88 void (*ov_intr_disestablish)(void *, pci_chipset_tag_t, void *);
89 pcitag_t (*ov_make_tag)(void *, pci_chipset_tag_t, int, int, int); 89 pcitag_t (*ov_make_tag)(void *, pci_chipset_tag_t, int, int, int);
90 void (*ov_decompose_tag)(void *, pci_chipset_tag_t, pcitag_t, 90 void (*ov_decompose_tag)(void *, pci_chipset_tag_t, pcitag_t,
91 int *, int *, int *); 91 int *, int *, int *);
92}; 92};
93 93
94/* 94/*
95 * PCI bus attach arguments. 95 * PCI bus attach arguments.
96 */ 96 */
97struct pcibus_attach_args { 97struct pcibus_attach_args {
98 char *_pba_busname; /* XXX placeholder */ 98 char *_pba_busname; /* XXX placeholder */
99 bus_space_tag_t pba_iot; /* pci i/o space tag */ 99 bus_space_tag_t pba_iot; /* pci i/o space tag */
100 bus_space_tag_t pba_memt; /* pci mem space tag */ 100 bus_space_tag_t pba_memt; /* pci mem space tag */
101 bus_dma_tag_t pba_dmat; /* DMA tag */ 101 bus_dma_tag_t pba_dmat; /* DMA tag */
102 bus_dma_tag_t pba_dmat64; /* DMA tag */ 102 bus_dma_tag_t pba_dmat64; /* DMA tag */
103 pci_chipset_tag_t pba_pc; 103 pci_chipset_tag_t pba_pc;
104 int pba_flags; /* flags; see below */ 104 int pba_flags; /* flags; see below */
105 105
106 int pba_bus; /* PCI bus number */ 106 int pba_bus; /* PCI bus number */
107 int pba_sub; /* pba_bus >= pba_sub: no 107 int pba_sub; /* pba_bus >= pba_sub: no
108 * buses are subordinate to 108 * buses are subordinate to
109 * pba_bus. 109 * pba_bus.
110 * 110 *
111 * pba_bus < pba_sub: buses 111 * pba_bus < pba_sub: buses
112 * [pba_bus + 1, pba_sub] are 112 * [pba_bus + 1, pba_sub] are
113 * subordinate to pba_bus. 113 * subordinate to pba_bus.
114 */ 114 */
115 115
116 /* 116 /*
117 * Pointer to the pcitag of our parent bridge. If there is no 117 * Pointer to the pcitag of our parent bridge. If there is no
118 * parent bridge, then we assume we are a root bus. 118 * parent bridge, then we assume we are a root bus.
119 */ 119 */
120 pcitag_t *pba_bridgetag; 120 pcitag_t *pba_bridgetag;
121 121
122 /* 122 /*
123 * Interrupt swizzling information. These fields 123 * Interrupt swizzling information. These fields
124 * are only used by secondary busses. 124 * are only used by secondary busses.
125 */ 125 */
126 u_int pba_intrswiz; /* how to swizzle pins */ 126 u_int pba_intrswiz; /* how to swizzle pins */
127 pcitag_t pba_intrtag; /* intr. appears to come from here */ 127 pcitag_t pba_intrtag; /* intr. appears to come from here */
128}; 128};
129 129
130/* 130/*
131 * This is used by <machine/pci_machdep.h> to access the pba_pc member. It 131 * This is used by <machine/pci_machdep.h> to access the pba_pc member. It
132 * can't use it directly since pcibus_attach_args has yet to be defined. 132 * can't use it directly since pcibus_attach_args has yet to be defined.
133 */ 133 */
134static __inline pci_chipset_tag_t 134static __inline pci_chipset_tag_t
135pcibus_attach_args_pc(struct pcibus_attach_args *pba) 135pcibus_attach_args_pc(struct pcibus_attach_args *pba)
136{ 136{
137 return pba->pba_pc; 137 return pba->pba_pc;
138} 138}
139 139
140/* 140/*
141 * PCI device attach arguments. 141 * PCI device attach arguments.
142 */ 142 */
143struct pci_attach_args { 143struct pci_attach_args {
144 bus_space_tag_t pa_iot; /* pci i/o space tag */ 144 bus_space_tag_t pa_iot; /* pci i/o space tag */
145 bus_space_tag_t pa_memt; /* pci mem space tag */ 145 bus_space_tag_t pa_memt; /* pci mem space tag */
146 bus_dma_tag_t pa_dmat; /* DMA tag */ 146 bus_dma_tag_t pa_dmat; /* DMA tag */
147 bus_dma_tag_t pa_dmat64; /* DMA tag */ 147 bus_dma_tag_t pa_dmat64; /* DMA tag */
148 pci_chipset_tag_t pa_pc; 148 pci_chipset_tag_t pa_pc;
149 int pa_flags; /* flags; see below */ 149 int pa_flags; /* flags; see below */
150 150
151 u_int pa_bus; 151 u_int pa_bus;
152 u_int pa_device; 152 u_int pa_device;
153 u_int pa_function; 153 u_int pa_function;
154 pcitag_t pa_tag; 154 pcitag_t pa_tag;
155 pcireg_t pa_id, pa_class; 155 pcireg_t pa_id, pa_class;
156 156
157 /* 157 /*
158 * Interrupt information. 158 * Interrupt information.
159 * 159 *
160 * "Intrline" is used on systems whose firmware puts 160 * "Intrline" is used on systems whose firmware puts
161 * the right routing data into the line register in 161 * the right routing data into the line register in
162 * configuration space. The rest are used on systems 162 * configuration space. The rest are used on systems
163 * that do not. 163 * that do not.
164 */ 164 */
165 u_int pa_intrswiz; /* how to swizzle pins if ppb */ 165 u_int pa_intrswiz; /* how to swizzle pins if ppb */
166 pcitag_t pa_intrtag; /* intr. appears to come from here */ 166 pcitag_t pa_intrtag; /* intr. appears to come from here */
167 pci_intr_pin_t pa_intrpin; /* intr. appears on this pin */ 167 pci_intr_pin_t pa_intrpin; /* intr. appears on this pin */
168 pci_intr_line_t pa_intrline; /* intr. routing information */ 168 pci_intr_line_t pa_intrline; /* intr. routing information */
169 pci_intr_pin_t pa_rawintrpin; /* unswizzled pin */ 169 pci_intr_pin_t pa_rawintrpin; /* unswizzled pin */
170}; 170};
171 171
172/* 172/*
173 * This is used by <machine/pci_machdep.h> to access the pa_pc member. It 173 * This is used by <machine/pci_machdep.h> to access the pa_pc member. It
174 * can't use it directly since pci_attach_args has yet to be defined. 174 * can't use it directly since pci_attach_args has yet to be defined.
175 */ 175 */
176static __inline pci_chipset_tag_t 176static __inline pci_chipset_tag_t
177pci_attach_args_pc(const struct pci_attach_args *pa) 177pci_attach_args_pc(const struct pci_attach_args *pa)
178{ 178{
179 return pa->pa_pc; 179 return pa->pa_pc;
180} 180}
181 181
182/* 182/*
183 * Flags given in the bus and device attachment args. 183 * Flags given in the bus and device attachment args.
184 */ 184 */
185#define PCI_FLAGS_IO_OKAY 0x01 /* I/O space is okay */ 185#define PCI_FLAGS_IO_OKAY 0x01 /* I/O space is okay */
186#define PCI_FLAGS_MEM_OKAY 0x02 /* memory space is okay */ 186#define PCI_FLAGS_MEM_OKAY 0x02 /* memory space is okay */
187#define PCI_FLAGS_MRL_OKAY 0x04 /* Memory Read Line okay */ 187#define PCI_FLAGS_MRL_OKAY 0x04 /* Memory Read Line okay */
188#define PCI_FLAGS_MRM_OKAY 0x08 /* Memory Read Multiple okay */ 188#define PCI_FLAGS_MRM_OKAY 0x08 /* Memory Read Multiple okay */
189#define PCI_FLAGS_MWI_OKAY 0x10 /* Memory Write and Invalidate 189#define PCI_FLAGS_MWI_OKAY 0x10 /* Memory Write and Invalidate
190 okay */ 190 okay */
191#define PCI_FLAGS_MSI_OKAY 0x20 /* Message Signaled Interrupts 191#define PCI_FLAGS_MSI_OKAY 0x20 /* Message Signaled Interrupts
192 okay */ 192 okay */
193#define PCI_FLAGS_MSIX_OKAY 0x40 /* Message Signaled Interrupts 193#define PCI_FLAGS_MSIX_OKAY 0x40 /* Message Signaled Interrupts
194 (Extended) okay */ 194 (Extended) okay */
195 195
196/* 196/*
197 * PCI device 'quirks'. 197 * PCI device 'quirks'.
198 * 198 *
199 * In general strange behaviour which can be handled by a driver (e.g. 199 * In general strange behaviour which can be handled by a driver (e.g.
200 * a bridge's inability to pass a type of access correctly) should be. 200 * a bridge's inability to pass a type of access correctly) should be.
201 * The quirks table should only contain information which impacts 201 * The quirks table should only contain information which impacts
202 * the operation of the MI PCI code and which can't be pushed lower 202 * the operation of the MI PCI code and which can't be pushed lower
203 * (e.g. because it's unacceptable to require a driver to be present 203 * (e.g. because it's unacceptable to require a driver to be present
204 * for the information to be known). 204 * for the information to be known).
205 */ 205 */
206struct pci_quirkdata { 206struct pci_quirkdata {
207 pci_vendor_id_t vendor; /* Vendor ID */ 207 pci_vendor_id_t vendor; /* Vendor ID */
208 pci_product_id_t product; /* Product ID */ 208 pci_product_id_t product; /* Product ID */
209 int quirks; /* quirks; see below */ 209 int quirks; /* quirks; see below */
210}; 210};
211#define PCI_QUIRK_MULTIFUNCTION __BIT(0) 211#define PCI_QUIRK_MULTIFUNCTION __BIT(0)
212#define PCI_QUIRK_MONOFUNCTION __BIT(1) 212#define PCI_QUIRK_MONOFUNCTION __BIT(1)
213#define PCI_QUIRK_SKIP_FUNC(n) (4 << n) 213#define PCI_QUIRK_SKIP_FUNC(n) (4 << n)
214#define PCI_QUIRK_SKIP_FUNC0 PCI_QUIRK_SKIP_FUNC(0) 214#define PCI_QUIRK_SKIP_FUNC0 PCI_QUIRK_SKIP_FUNC(0)
215#define PCI_QUIRK_SKIP_FUNC1 PCI_QUIRK_SKIP_FUNC(1) 215#define PCI_QUIRK_SKIP_FUNC1 PCI_QUIRK_SKIP_FUNC(1)
216#define PCI_QUIRK_SKIP_FUNC2 PCI_QUIRK_SKIP_FUNC(2) 216#define PCI_QUIRK_SKIP_FUNC2 PCI_QUIRK_SKIP_FUNC(2)
217#define PCI_QUIRK_SKIP_FUNC3 PCI_QUIRK_SKIP_FUNC(3) 217#define PCI_QUIRK_SKIP_FUNC3 PCI_QUIRK_SKIP_FUNC(3)
218#define PCI_QUIRK_SKIP_FUNC4 PCI_QUIRK_SKIP_FUNC(4) 218#define PCI_QUIRK_SKIP_FUNC4 PCI_QUIRK_SKIP_FUNC(4)
219#define PCI_QUIRK_SKIP_FUNC5 PCI_QUIRK_SKIP_FUNC(5) 219#define PCI_QUIRK_SKIP_FUNC5 PCI_QUIRK_SKIP_FUNC(5)
220#define PCI_QUIRK_SKIP_FUNC6 PCI_QUIRK_SKIP_FUNC(6) 220#define PCI_QUIRK_SKIP_FUNC6 PCI_QUIRK_SKIP_FUNC(6)
221#define PCI_QUIRK_SKIP_FUNC7 PCI_QUIRK_SKIP_FUNC(7) 221#define PCI_QUIRK_SKIP_FUNC7 PCI_QUIRK_SKIP_FUNC(7)
222#define PCI_QUIRK_HASEXTCNF __BIT(10) 222#define PCI_QUIRK_HASEXTCNF __BIT(10)
223#define PCI_QUIRK_NOEXTCNF __BIT(11) 223#define PCI_QUIRK_NOEXTCNF __BIT(11)
224 224
225struct pci_conf_state { 225struct pci_conf_state {
226 pcireg_t reg[16]; 226 pcireg_t reg[16];
227 227
228 /* For PCI-X */ 228 /* For PCI-X */
229 pcireg_t x_csr; /* Upper 16bits. Lower 16bits are read only */ 229 pcireg_t x_csr; /* Upper 16bits. Lower 16bits are read only */
230 230
231 /* For PCIe */ 231 /* For PCIe */
232 uint16_t e_dcr; 232 uint16_t e_dcr;
233 uint16_t e_lcr; 233 uint16_t e_lcr;
234 uint16_t e_slcr; 234 uint16_t e_slcr;
235 uint16_t e_rcr; 235 uint16_t e_rcr;
236 uint16_t e_dcr2; 236 uint16_t e_dcr2;
237 uint16_t e_lcr2; 237 uint16_t e_lcr2;
238 238
239 /* For MSI */ 239 /* For MSI */
240 pcireg_t msi_ctl; /* Upper 16bits. Lower 16bits are read only */ 240 pcireg_t msi_ctl; /* Upper 16bits. Lower 16bits are read only */
241 pcireg_t msi_maddr; 241 pcireg_t msi_maddr;
242 pcireg_t msi_maddr64_hi; 242 pcireg_t msi_maddr64_hi;
243 pcireg_t msi_mdata; 243 pcireg_t msi_mdata;
244 pcireg_t msi_mask; 244 pcireg_t msi_mask;
245 245
246 /* For MSI-X */ 246 /* For MSI-X */
247 pcireg_t msix_ctl; /* Upper 16bits. Lower 16bits are read only */ 247 pcireg_t msix_ctl; /* Upper 16bits. Lower 16bits are read only */
248}; 248};
249 249
250struct pci_range { 250struct pci_range {
251 bus_addr_t r_offset; 251 bus_addr_t r_offset;
252 bus_size_t r_size; 252 bus_size_t r_size;
253 int r_flags; 253 int r_flags;
254}; 254};
255 255
256struct pci_child { 256struct pci_child {
257 device_t c_dev; 257 device_t c_dev;
258 bool c_psok; 258 bool c_psok;
259 pcireg_t c_powerstate; 259 pcireg_t c_powerstate;
260 struct pci_conf_state c_conf; 260 struct pci_conf_state c_conf;
261 struct pci_range c_range[8]; 261 struct pci_range c_range[8];
262}; 262};
263 263
264struct pci_softc { 264struct pci_softc {
265 device_t sc_dev; 265 device_t sc_dev;
266 bus_space_tag_t sc_iot, sc_memt; 266 bus_space_tag_t sc_iot, sc_memt;
267 bus_dma_tag_t sc_dmat; 267 bus_dma_tag_t sc_dmat;
268 bus_dma_tag_t sc_dmat64; 268 bus_dma_tag_t sc_dmat64;
269 pci_chipset_tag_t sc_pc; 269 pci_chipset_tag_t sc_pc;
270 int sc_bus, sc_maxndevs; 270 int sc_bus, sc_maxndevs;
271 pcitag_t *sc_bridgetag; 271 pcitag_t *sc_bridgetag;
272 u_int sc_intrswiz; 272 u_int sc_intrswiz;
273 pcitag_t sc_intrtag; 273 pcitag_t sc_intrtag;
274 int sc_flags; 274 int sc_flags;
275 /* accounting of child devices */ 275 /* accounting of child devices */
276 struct pci_child sc_devices[32*8]; 276 struct pci_child sc_devices[32*8];
277#define PCI_SC_DEVICESC(d, f) sc_devices[(d) * 8 + (f)] 277#define PCI_SC_DEVICESC(d, f) sc_devices[(d) * 8 + (f)]
278}; 278};
279 279
280extern struct cfdriver pci_cd; 280extern struct cfdriver pci_cd;
281 281
282extern bool pci_mapreg_map_enable_decode; 282extern bool pci_mapreg_map_enable_decode;
283 283
284int pcibusprint(void *, const char *); 284int pcibusprint(void *, const char *);
285 285
286/* 286/*
287 * Configuration space access and utility functions. (Note that most, 287 * Configuration space access and utility functions. (Note that most,
288 * e.g. make_tag, conf_read, conf_write are declared by pci_machdep.h.) 288 * e.g. make_tag, conf_read, conf_write are declared by pci_machdep.h.)
289 */ 289 */
290int pci_mapreg_probe(pci_chipset_tag_t, pcitag_t, int, pcireg_t *); 290int pci_mapreg_probe(pci_chipset_tag_t, pcitag_t, int, pcireg_t *);
291pcireg_t pci_mapreg_type(pci_chipset_tag_t, pcitag_t, int); 291pcireg_t pci_mapreg_type(pci_chipset_tag_t, pcitag_t, int);
292int pci_mapreg_info(pci_chipset_tag_t, pcitag_t, int, pcireg_t, 292int pci_mapreg_info(pci_chipset_tag_t, pcitag_t, int, pcireg_t,
293 bus_addr_t *, bus_size_t *, int *); 293 bus_addr_t *, bus_size_t *, int *);
294int pci_mapreg_map(const struct pci_attach_args *, int, pcireg_t, int, 294int pci_mapreg_map(const struct pci_attach_args *, int, pcireg_t, int,
295 bus_space_tag_t *, bus_space_handle_t *, bus_addr_t *, 295 bus_space_tag_t *, bus_space_handle_t *, bus_addr_t *,
296 bus_size_t *); 296 bus_size_t *);
297int pci_mapreg_submap(const struct pci_attach_args *, int, pcireg_t, int, 297int pci_mapreg_submap(const struct pci_attach_args *, int, pcireg_t, int,
298 bus_size_t, bus_size_t, bus_space_tag_t *, bus_space_handle_t *,  298 bus_size_t, bus_size_t, bus_space_tag_t *, bus_space_handle_t *,
299 bus_addr_t *, bus_size_t *); 299 bus_addr_t *, bus_size_t *);
300 300
301 
302int pci_find_rom(const struct pci_attach_args *, bus_space_tag_t, 301int pci_find_rom(const struct pci_attach_args *, bus_space_tag_t,
303 bus_space_handle_t, bus_size_t, 302 bus_space_handle_t, bus_size_t,
304 int, bus_space_handle_t *, bus_size_t *); 303 int, bus_space_handle_t *, bus_size_t *);
305 304
306int pci_get_capability(pci_chipset_tag_t, pcitag_t, int, int *, pcireg_t *); 305int pci_get_capability(pci_chipset_tag_t, pcitag_t, int, int *, pcireg_t *);
307int pci_get_ht_capability(pci_chipset_tag_t, pcitag_t, int, int *, 306int pci_get_ht_capability(pci_chipset_tag_t, pcitag_t, int, int *,
308 pcireg_t *); 307 pcireg_t *);
309int pci_get_ext_capability(pci_chipset_tag_t, pcitag_t, int, int *, 308int pci_get_ext_capability(pci_chipset_tag_t, pcitag_t, int, int *,
310 pcireg_t *); 309 pcireg_t *);
311 310
312int pci_msi_count(pci_chipset_tag_t, pcitag_t); 311int pci_msi_count(pci_chipset_tag_t, pcitag_t);
313int pci_msix_count(pci_chipset_tag_t, pcitag_t); 312int pci_msix_count(pci_chipset_tag_t, pcitag_t);
314 313
315/* 314/*
316 * Helper functions for autoconfiguration. 315 * Helper functions for autoconfiguration.
317 */ 316 */
 317
 318#define PCI_COMPAT_EOL_VALUE (0xffffffffU)
 319#define PCI_COMPAT_EOL { .id = PCI_COMPAT_EOL_VALUE }
 320
 321const struct device_compatible_entry *
 322 pci_compatible_lookup_id(pcireg_t,
 323 const struct device_compatible_entry *);
 324const struct device_compatible_entry *
 325 pci_compatible_lookup(const struct pci_attach_args *,
 326 const struct device_compatible_entry *);
 327int pci_compatible_match(const struct pci_attach_args *,
 328 const struct device_compatible_entry *);
 329const struct device_compatible_entry *
 330 pci_compatible_lookup_subsys(const struct pci_attach_args *,
 331 const struct device_compatible_entry *);
 332int pci_compatible_match_subsys(const struct pci_attach_args *,
 333 const struct device_compatible_entry *);
318#ifndef PCI_MACHDEP_ENUMERATE_BUS 334#ifndef PCI_MACHDEP_ENUMERATE_BUS
319int pci_enumerate_bus(struct pci_softc *, const int *, 335int pci_enumerate_bus(struct pci_softc *, const int *,
320 int (*)(const struct pci_attach_args *), struct pci_attach_args *); 336 int (*)(const struct pci_attach_args *), struct pci_attach_args *);
321#endif 337#endif
322int pci_probe_device(struct pci_softc *, pcitag_t tag, 338int pci_probe_device(struct pci_softc *, pcitag_t tag,
323 int (*)(const struct pci_attach_args *), 339 int (*)(const struct pci_attach_args *),
324 struct pci_attach_args *); 340 struct pci_attach_args *);
325void pci_devinfo(pcireg_t, pcireg_t, int, char *, size_t); 341void pci_devinfo(pcireg_t, pcireg_t, int, char *, size_t);
326void pci_aprint_devinfo_fancy(const struct pci_attach_args *, 342void pci_aprint_devinfo_fancy(const struct pci_attach_args *,
327 const char *, const char *, int); 343 const char *, const char *, int);
328#define pci_aprint_devinfo(pap, naive) \ 344#define pci_aprint_devinfo(pap, naive) \
329 pci_aprint_devinfo_fancy(pap, naive, NULL, 0); 345 pci_aprint_devinfo_fancy(pap, naive, NULL, 0);
330void pci_conf_print(pci_chipset_tag_t, pcitag_t, 346void pci_conf_print(pci_chipset_tag_t, pcitag_t,
331 void (*)(pci_chipset_tag_t, pcitag_t, const pcireg_t *)); 347 void (*)(pci_chipset_tag_t, pcitag_t, const pcireg_t *));
332const struct pci_quirkdata * 348const struct pci_quirkdata *
333 pci_lookup_quirkdata(pci_vendor_id_t, pci_product_id_t); 349 pci_lookup_quirkdata(pci_vendor_id_t, pci_product_id_t);
334 350
335/* 351/*
336 * Helper functions for user access to the PCI bus. 352 * Helper functions for user access to the PCI bus.
337 */ 353 */
338struct proc; 354struct proc;
339int pci_devioctl(pci_chipset_tag_t, pcitag_t, u_long, void *, 355int pci_devioctl(pci_chipset_tag_t, pcitag_t, u_long, void *,
340 int flag, struct lwp *); 356 int flag, struct lwp *);
341 357
342/* 358/*
343 * Power Management (PCI 2.2) 359 * Power Management (PCI 2.2)
344 */ 360 */
345 361
346#define PCI_PWR_D0 0 362#define PCI_PWR_D0 0
347#define PCI_PWR_D1 1 363#define PCI_PWR_D1 1
348#define PCI_PWR_D2 2 364#define PCI_PWR_D2 2
349#define PCI_PWR_D3 3 365#define PCI_PWR_D3 3
350int pci_powerstate(pci_chipset_tag_t, pcitag_t, const int *, int *); 366int pci_powerstate(pci_chipset_tag_t, pcitag_t, const int *, int *);
351 367
352/* 368/*
353 * Vital Product Data (PCI 2.2) 369 * Vital Product Data (PCI 2.2)
354 */ 370 */
355int pci_vpd_read(pci_chipset_tag_t, pcitag_t, int, int, pcireg_t *); 371int pci_vpd_read(pci_chipset_tag_t, pcitag_t, int, int, pcireg_t *);
356int pci_vpd_write(pci_chipset_tag_t, pcitag_t, int, int, pcireg_t *); 372int pci_vpd_write(pci_chipset_tag_t, pcitag_t, int, int, pcireg_t *);
357 373
358/* 374/*
359 * Misc. 375 * Misc.
360 */ 376 */
361int pci_find_device(struct pci_attach_args *pa, 377int pci_find_device(struct pci_attach_args *pa,
362 int (*match)(const struct pci_attach_args *)); 378 int (*match)(const struct pci_attach_args *));
363int pci_dma64_available(const struct pci_attach_args *); 379int pci_dma64_available(const struct pci_attach_args *);
364void pci_conf_capture(pci_chipset_tag_t, pcitag_t, struct pci_conf_state *); 380void pci_conf_capture(pci_chipset_tag_t, pcitag_t, struct pci_conf_state *);
365void pci_conf_restore(pci_chipset_tag_t, pcitag_t, struct pci_conf_state *); 381void pci_conf_restore(pci_chipset_tag_t, pcitag_t, struct pci_conf_state *);
366int pci_get_powerstate(pci_chipset_tag_t, pcitag_t, pcireg_t *); 382int pci_get_powerstate(pci_chipset_tag_t, pcitag_t, pcireg_t *);
367int pci_set_powerstate(pci_chipset_tag_t, pcitag_t, pcireg_t); 383int pci_set_powerstate(pci_chipset_tag_t, pcitag_t, pcireg_t);
368int pci_activate(pci_chipset_tag_t, pcitag_t, device_t, 384int pci_activate(pci_chipset_tag_t, pcitag_t, device_t,
369 int (*)(pci_chipset_tag_t, pcitag_t, device_t, pcireg_t)); 385 int (*)(pci_chipset_tag_t, pcitag_t, device_t, pcireg_t));
370int pci_activate_null(pci_chipset_tag_t, pcitag_t, device_t, pcireg_t); 386int pci_activate_null(pci_chipset_tag_t, pcitag_t, device_t, pcireg_t);
371int pci_chipset_tag_create(pci_chipset_tag_t, uint64_t, 387int pci_chipset_tag_create(pci_chipset_tag_t, uint64_t,
372 const struct pci_overrides *, 388 const struct pci_overrides *,
373 void *, pci_chipset_tag_t *); 389 void *, pci_chipset_tag_t *);
374void pci_chipset_tag_destroy(pci_chipset_tag_t); 390void pci_chipset_tag_destroy(pci_chipset_tag_t);
375int pci_bus_devorder(pci_chipset_tag_t, int, uint8_t *, int); 391int pci_bus_devorder(pci_chipset_tag_t, int, uint8_t *, int);
376void *pci_intr_establish_xname(pci_chipset_tag_t, pci_intr_handle_t, 392void *pci_intr_establish_xname(pci_chipset_tag_t, pci_intr_handle_t,
377 int, int (*)(void *), void *, const char *); 393 int, int (*)(void *), void *, const char *);
378#ifndef __HAVE_PCI_MSI_MSIX 394#ifndef __HAVE_PCI_MSI_MSIX
379typedef enum { 395typedef enum {
380 PCI_INTR_TYPE_INTX = 0, 396 PCI_INTR_TYPE_INTX = 0,
381 PCI_INTR_TYPE_MSI, 397 PCI_INTR_TYPE_MSI,
382 PCI_INTR_TYPE_MSIX, 398 PCI_INTR_TYPE_MSIX,
383 PCI_INTR_TYPE_SIZE, 399 PCI_INTR_TYPE_SIZE,
384} pci_intr_type_t; 400} pci_intr_type_t;
385 401
386pci_intr_type_t 402pci_intr_type_t
387 pci_intr_type(pci_chipset_tag_t, pci_intr_handle_t); 403 pci_intr_type(pci_chipset_tag_t, pci_intr_handle_t);
388int pci_intr_alloc(const struct pci_attach_args *, pci_intr_handle_t **, 404int pci_intr_alloc(const struct pci_attach_args *, pci_intr_handle_t **,
389 int *, pci_intr_type_t); 405 int *, pci_intr_type_t);
390void pci_intr_release(pci_chipset_tag_t, pci_intr_handle_t *, int); 406void pci_intr_release(pci_chipset_tag_t, pci_intr_handle_t *, int);
391int pci_intx_alloc(const struct pci_attach_args *, pci_intr_handle_t **); 407int pci_intx_alloc(const struct pci_attach_args *, pci_intr_handle_t **);
392int pci_msi_alloc(const struct pci_attach_args *, pci_intr_handle_t **, 408int pci_msi_alloc(const struct pci_attach_args *, pci_intr_handle_t **,
393 int *); 409 int *);
394int pci_msi_alloc_exact(const struct pci_attach_args *, 410int pci_msi_alloc_exact(const struct pci_attach_args *,
395 pci_intr_handle_t **, int); 411 pci_intr_handle_t **, int);
396int pci_msix_alloc(const struct pci_attach_args *, pci_intr_handle_t **, 412int pci_msix_alloc(const struct pci_attach_args *, pci_intr_handle_t **,
397 int *); 413 int *);
398int pci_msix_alloc_exact(const struct pci_attach_args *, 414int pci_msix_alloc_exact(const struct pci_attach_args *,
399 pci_intr_handle_t **, int); 415 pci_intr_handle_t **, int);
400int pci_msix_alloc_map(const struct pci_attach_args *, pci_intr_handle_t **, 416int pci_msix_alloc_map(const struct pci_attach_args *, pci_intr_handle_t **,
401 u_int *, int); 417 u_int *, int);
402#endif 418#endif
403 419
404/* 420/*
405 * Device abstraction for inheritance by elanpci(4), for example. 421 * Device abstraction for inheritance by elanpci(4), for example.
406 */ 422 */
407int pcimatch(device_t, cfdata_t, void *); 423int pcimatch(device_t, cfdata_t, void *);
408void pciattach(device_t, device_t, void *); 424void pciattach(device_t, device_t, void *);
409int pcidetach(device_t, int); 425int pcidetach(device_t, int);
410void pcidevdetached(device_t, device_t); 426void pcidevdetached(device_t, device_t);
411int pcirescan(device_t, const char *, const int *); 427int pcirescan(device_t, const char *, const int *);
412 428
413/* 429/*
414 * Interrupts. 430 * Interrupts.
415 */ 431 */
416#define PCI_INTR_MPSAFE 1 432#define PCI_INTR_MPSAFE 1
417 433
418int pci_intr_setattr(pci_chipset_tag_t, pci_intr_handle_t *, int, uint64_t); 434int pci_intr_setattr(pci_chipset_tag_t, pci_intr_handle_t *, int, uint64_t);
419 435
420/* 436/*
421 * Local constants 437 * Local constants
422 */ 438 */
423#define PCI_INTRSTR_LEN 64 439#define PCI_INTRSTR_LEN 64
424 440
425#endif /* _KERNEL */ 441#endif /* _KERNEL */
426 442
427#endif /* _DEV_PCI_PCIVAR_H_ */ 443#endif /* _DEV_PCI_PCIVAR_H_ */