#include #include #include #include #include #include #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; }