2 * Copyright (c) 2007 Yahoo!, Inc.
4 * Written by: John Baldwin <jhb@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the author nor the names of any co-contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * $FreeBSD: src/usr.sbin/pciconf/cap.c,v 1.2.2.2.6.1 2009/04/15 03:14:26 kensmith Exp $
33 #include <sys/types.h>
37 #include <sys/agpio.h>
38 #include <sys/pciio.h>
40 #include <dev/agp/agpreg.h>
41 #include <bus/pci/pcireg.h>
46 cap_power(int fd
, struct pci_conf
*p
, uint8_t ptr
)
50 cap
= read_config(fd
, &p
->pc_sel
, ptr
+ PCIR_POWER_CAP
, 2);
51 status
= read_config(fd
, &p
->pc_sel
, ptr
+ PCIR_POWER_STATUS
, 2);
52 printf("powerspec %d supports D0%s%s D3 current D%d",
54 cap
& PCIM_PCAP_D1SUPP
? " D1" : "",
55 cap
& PCIM_PCAP_D2SUPP
? " D2" : "",
56 status
& PCIM_PSTAT_DMASK
);
60 cap_agp(int fd
, struct pci_conf
*p
, uint8_t ptr
)
62 uint32_t status
, command
;
64 status
= read_config(fd
, &p
->pc_sel
, ptr
+ AGP_STATUS
, 4);
65 command
= read_config(fd
, &p
->pc_sel
, ptr
+ AGP_CAPID
, 4);
67 if (AGP_MODE_GET_MODE_3(status
)) {
69 if (AGP_MODE_GET_RATE(status
) & AGP_MODE_V3_RATE_8x
)
71 if (AGP_MODE_GET_RATE(status
) & AGP_MODE_V3_RATE_4x
)
74 if (AGP_MODE_GET_RATE(status
) & AGP_MODE_V2_RATE_4x
)
76 if (AGP_MODE_GET_RATE(status
) & AGP_MODE_V2_RATE_2x
)
78 if (AGP_MODE_GET_RATE(status
) & AGP_MODE_V2_RATE_1x
)
81 if (AGP_MODE_GET_SBA(status
))
83 if (AGP_MODE_GET_AGP(command
)) {
84 printf("enabled at ");
85 if (AGP_MODE_GET_MODE_3(command
)) {
87 switch (AGP_MODE_GET_RATE(command
)) {
88 case AGP_MODE_V3_RATE_8x
:
91 case AGP_MODE_V3_RATE_4x
:
96 switch (AGP_MODE_GET_RATE(command
)) {
97 case AGP_MODE_V2_RATE_4x
:
100 case AGP_MODE_V2_RATE_2x
:
103 case AGP_MODE_V2_RATE_1x
:
107 if (AGP_MODE_GET_SBA(command
))
114 cap_vpd(int fd __unused
, struct pci_conf
*p __unused
, uint8_t ptr __unused
)
121 cap_msi(int fd
, struct pci_conf
*p
, uint8_t ptr
)
126 ctrl
= read_config(fd
, &p
->pc_sel
, ptr
+ PCIR_MSI_CTRL
, 2);
127 msgnum
= 1 << ((ctrl
& PCIM_MSICTRL_MMC_MASK
) >> 1);
128 printf("MSI supports %d message%s%s%s ", msgnum
,
129 (msgnum
== 1) ? "" : "s",
130 (ctrl
& PCIM_MSICTRL_64BIT
) ? ", 64 bit" : "",
131 (ctrl
& PCIM_MSICTRL_VECTOR
) ? ", vector masks" : "");
132 if (ctrl
& PCIM_MSICTRL_MSI_ENABLE
) {
133 msgnum
= 1 << ((ctrl
& PCIM_MSICTRL_MME_MASK
) >> 4);
134 printf("enabled with %d message%s", msgnum
,
135 (msgnum
== 1) ? "" : "s");
140 cap_pcix(int fd
, struct pci_conf
*p
, uint8_t ptr
)
143 int comma
, max_splits
= 0, max_burst_read
= 0;
145 status
= read_config(fd
, &p
->pc_sel
, ptr
+ PCIXR_STATUS
, 4);
147 if (status
& PCIXM_STATUS_64BIT
)
149 if ((p
->pc_hdr
& PCIM_HDRTYPE
) == 1)
153 if (status
& PCIXM_STATUS_133CAP
) {
154 printf("%s 133MHz", comma
? "," : "");
157 if (status
& PCIXM_STATUS_266CAP
) {
158 printf("%s 266MHz", comma
? "," : "");
161 if (status
& PCIXM_STATUS_533CAP
) {
162 printf("%s 533MHz", comma
? "," : "");
165 if ((p
->pc_hdr
& PCIM_HDRTYPE
) == 1)
167 switch (status
& PCIXM_STATUS_MAX_READ
) {
168 case PCIXM_STATUS_MAX_READ_512
:
169 max_burst_read
= 512;
171 case PCIXM_STATUS_MAX_READ_1024
:
172 max_burst_read
= 1024;
174 case PCIXM_STATUS_MAX_READ_2048
:
175 max_burst_read
= 2048;
177 case PCIXM_STATUS_MAX_READ_4096
:
178 max_burst_read
= 4096;
181 switch (status
& PCIXM_STATUS_MAX_SPLITS
) {
182 case PCIXM_STATUS_MAX_SPLITS_1
:
185 case PCIXM_STATUS_MAX_SPLITS_2
:
188 case PCIXM_STATUS_MAX_SPLITS_3
:
191 case PCIXM_STATUS_MAX_SPLITS_4
:
194 case PCIXM_STATUS_MAX_SPLITS_8
:
197 case PCIXM_STATUS_MAX_SPLITS_12
:
200 case PCIXM_STATUS_MAX_SPLITS_16
:
203 case PCIXM_STATUS_MAX_SPLITS_32
:
207 printf("%s %d burst read, %d split transaction%s", comma
? "," : "",
208 max_burst_read
, max_splits
, max_splits
== 1 ? "" : "s");
212 cap_ht(int fd
, struct pci_conf
*p
, uint8_t ptr
)
217 command
= read_config(fd
, &p
->pc_sel
, ptr
+ PCIR_HT_COMMAND
, 2);
219 if ((command
& 0xe000) == PCIM_HTCAP_SLAVE
)
221 else if ((command
& 0xe000) == PCIM_HTCAP_HOST
)
224 switch (command
& PCIM_HTCMD_CAP_MASK
) {
225 case PCIM_HTCAP_SWITCH
:
228 case PCIM_HTCAP_INTERRUPT
:
231 case PCIM_HTCAP_REVISION_ID
:
232 printf("revision ID");
234 case PCIM_HTCAP_UNITID_CLUMPING
:
235 printf("unit ID clumping");
237 case PCIM_HTCAP_EXT_CONFIG_SPACE
:
238 printf("extended config space");
240 case PCIM_HTCAP_ADDRESS_MAPPING
:
241 printf("address mapping");
243 case PCIM_HTCAP_MSI_MAPPING
:
244 printf("MSI %saddress window %s at 0x",
245 command
& PCIM_HTCMD_MSI_FIXED
? "fixed " : "",
246 command
& PCIM_HTCMD_MSI_ENABLE
? "enabled" :
248 if (command
& PCIM_HTCMD_MSI_FIXED
)
251 reg
= read_config(fd
, &p
->pc_sel
,
252 ptr
+ PCIR_HTMSI_ADDRESS_HI
, 4);
255 reg
= read_config(fd
, &p
->pc_sel
,
256 ptr
+ PCIR_HTMSI_ADDRESS_LO
, 4);
260 case PCIM_HTCAP_DIRECT_ROUTE
:
261 printf("direct route");
263 case PCIM_HTCAP_VCSET
:
266 case PCIM_HTCAP_RETRY_MODE
:
267 printf("retry mode");
269 case PCIM_HTCAP_X86_ENCODING
:
270 printf("X86 encoding");
273 printf("unknown %02x", command
);
279 cap_vendor(int fd
, struct pci_conf
*p
, uint8_t ptr
)
283 length
= read_config(fd
, &p
->pc_sel
, ptr
+ PCIR_VENDOR_LENGTH
, 1);
284 printf("vendor (length %d)", length
);
285 if (p
->pc_vendor
== 0x8086) {
289 version
= read_config(fd
, &p
->pc_sel
, ptr
+ PCIR_VENDOR_DATA
,
291 printf(" Intel cap %d version %d", version
>> 4, version
& 0xf);
292 if (version
>> 4 == 1 && length
== 12) {
293 /* Feature Detection */
298 fvec
= read_config(fd
, &p
->pc_sel
, ptr
+
299 PCIR_VENDOR_DATA
+ 5, 4);
300 printf("\n\t\t features:");
301 if (fvec
& (1 << 0)) {
305 fvec
= read_config(fd
, &p
->pc_sel
, ptr
+
306 PCIR_VENDOR_DATA
+ 1, 4);
307 if (fvec
& (1 << 21)) {
308 printf("%s Quick Resume", comma
? "," : "");
311 if (fvec
& (1 << 18)) {
312 printf("%s SATA RAID-5", comma
? "," : "");
315 if (fvec
& (1 << 9)) {
316 printf("%s Mobile", comma
? "," : "");
319 if (fvec
& (1 << 7)) {
320 printf("%s 6 PCI-e x1 slots", comma
? "," : "");
323 printf("%s 4 PCI-e x1 slots", comma
? "," : "");
326 if (fvec
& (1 << 5)) {
327 printf("%s SATA RAID-0/1/10", comma
? "," : "");
330 if (fvec
& (1 << 3)) {
331 printf("%s SATA AHCI", comma
? "," : "");
339 cap_debug(int fd
, struct pci_conf
*p
, uint8_t ptr
)
343 debug_port
= read_config(fd
, &p
->pc_sel
, ptr
+ PCIR_DEBUG_PORT
, 2);
344 printf("EHCI Debug Port at offset 0x%x in map 0x%x", debug_port
&
345 PCIM_DEBUG_PORT_OFFSET
, PCIR_BAR(debug_port
>> 13));
349 cap_subvendor(int fd
, struct pci_conf
*p
, uint8_t ptr
)
353 id
= read_config(fd
, &p
->pc_sel
, ptr
+ PCIR_SUBVENDCAP_ID
, 4);
354 printf("PCI Bridge card=0x%08x", id
);
358 cap_express(int fd
, struct pci_conf
*p
, uint8_t ptr
)
362 flags
= read_config(fd
, &p
->pc_sel
, ptr
+ PCIER_CAPABILITY
, 2);
363 printf("PCI-Express %d ", flags
& PCIEM_CAP_VER_MASK
);
364 switch (flags
& PCIEM_CAP_PORT_TYPE
) {
368 case PCIE_LEG_END_POINT
:
369 printf("legacy endpoint");
374 case PCIE_UP_STREAM_PORT
:
375 printf("upstream port");
377 case PCIE_DOWN_STREAM_PORT
:
378 printf("downstream port");
380 case PCIE_PCIE2PCI_BRIDGE
:
381 printf("PCI bridge");
384 printf("type %d", (flags
& PCIEM_CAP_PORT_TYPE
) >> 8);
390 cap_msix(int fd
, struct pci_conf
*p
, uint8_t ptr
)
394 int msgnum
, table_bar
, pba_bar
;
396 ctrl
= read_config(fd
, &p
->pc_sel
, ptr
+ PCIR_MSIX_CTRL
, 2);
397 msgnum
= (ctrl
& PCIM_MSIXCTRL_TABLE_SIZE
) + 1;
398 val
= read_config(fd
, &p
->pc_sel
, ptr
+ PCIR_MSIX_TABLE
, 4);
399 table_bar
= PCIR_BAR(val
& PCIM_MSIX_BIR_MASK
);
400 val
= read_config(fd
, &p
->pc_sel
, ptr
+ PCIR_MSIX_PBA
, 4);
401 pba_bar
= PCIR_BAR(val
& PCIM_MSIX_BIR_MASK
);
402 printf("MSI-X supports %d message%s ", msgnum
,
403 (msgnum
== 1) ? "" : "s");
404 if (table_bar
== pba_bar
)
405 printf("in map 0x%x", table_bar
);
407 printf("in maps 0x%x and 0x%x", table_bar
, pba_bar
);
408 if (ctrl
& PCIM_MSIXCTRL_MSIX_ENABLE
)
413 list_caps(int fd
, struct pci_conf
*p
)
418 /* Are capabilities present for this device? */
419 cmd
= read_config(fd
, &p
->pc_sel
, PCIR_STATUS
, 2);
420 if (!(cmd
& PCIM_STATUS_CAPPRESENT
))
423 switch (p
->pc_hdr
& PCIM_HDRTYPE
) {
429 ptr
= PCIR_CAP_PTR_2
;
432 errx(1, "list_caps: bad header type");
435 /* Walk the capability list. */
436 ptr
= read_config(fd
, &p
->pc_sel
, ptr
, 1);
437 while (ptr
!= 0 && ptr
!= 0xff) {
438 cap
= read_config(fd
, &p
->pc_sel
, ptr
+ PCICAP_ID
, 1);
439 printf(" cap %02x[%02x] = ", cap
, ptr
);
442 cap_power(fd
, p
, ptr
);
454 cap_pcix(fd
, p
, ptr
);
460 cap_vendor(fd
, p
, ptr
);
463 cap_debug(fd
, p
, ptr
);
466 cap_subvendor(fd
, p
, ptr
);
469 cap_express(fd
, p
, ptr
);
472 cap_msix(fd
, p
, ptr
);
479 ptr
= read_config(fd
, &p
->pc_sel
, ptr
+ PCICAP_NEXTPTR
, 1);