Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F89600673
PCIOCGETCONF Test
No One
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
jfree
Jul 29 2024, 10:36 PM
2024-07-29 22:36:42 (UTC+0)
Size
1 KB
Referenced Files
None
Subscribers
None
PCIOCGETCONF Test
View Options
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/pciio.h>
#include <err.h>
#include <fcntl.h>
#include <stdio.h>
#define PCI_CHARDEV "/dev/pci"
#define PCI_VENDOR_INTEL 0x8086
/* Find all intel devices on the PCI bus and report info about them. */
int
main(void) {
struct pci_conf_io pcio = { };
struct pci_conf devs[16];
struct pci_match_conf pmc;
int pcifd;
pcifd = open(PCI_CHARDEV, O_RDWR);
if (pcifd < 0)
err(1, "Failed to open " PCI_CHARDEV);
pmc.pc_vendor = 0x8086; /* Intel */
pmc.flags = PCI_GETCONF_MATCH_VENDOR;
pcio.pat_buf_len = sizeof(pmc);
pcio.num_patterns = 1;
pcio.patterns = &pmc;
pcio.match_buf_len = sizeof(devs);
pcio.matches = devs;
restart:
pcio.offset = 0;
pcio.generation = 0;
do {
if (ioctl(pcifd, PCIOCGETCONF, &pcio) < 0)
err(1, "PCIOCGETCONF ioctl failed");
if (pcio.status == PCI_GETCONF_LIST_CHANGED)
goto restart;
else if (pcio.status == PCI_GETCONF_ERROR)
errx(1, "PCI_GETCONF_ERROR detected");
for (int i = 0; i < pcio.num_matches; ++i) {
struct pci_conf *dev = devs + i;
printf("--- Device %d ---\n", i);
printf("DBDF: %u:%u:%u.%u\n", dev->pc_sel.pc_domain,
dev->pc_sel.pc_bus, dev->pc_sel.pc_dev,
dev->pc_sel.pc_func);
printf("header type: %u\n", dev->pc_hdr);
printf("subvendor: %u\n", dev->pc_subvendor);
printf("subdevice: %u\n", dev->pc_subdevice);
printf("vendor: %u\n", dev->pc_vendor);
printf("device: %u\n", dev->pc_device);
printf("class: %u\n", dev->pc_class);
printf("subclass: %u\n", dev->pc_subclass);
printf("progif: %u\n", dev->pc_progif);
printf("revid: %u\n", dev->pc_revid);
printf("driver: %s\n", dev->pd_name);
printf("unit: %lu\n", dev->pd_unit);
printf("NUMA node: %d\n\n", dev->pd_numa_domain);
}
} while (pcio.status == PCI_GETCONF_MORE_DEVS);
return 0;
}
File Metadata
Details
Attached
Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
10655071
Default Alt Text
PCIOCGETCONF Test (1 KB)
Attached To
Mode
P644 PCIOCGETCONF Test
Attached
Detach File
Event Timeline
Log In to Comment