/*- * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2024 NIKSUN, Inc. * * Written by Jake Freeland * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #include #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); #if __FreeBSD_version >= 1500063 printf("NUMA node: %d\n", dev->pd_numa_domain); printf("Reported length: %lu\n", dev->pc_reported_len); assert(dev->pc_reported_len == offsetof(struct pci_conf, pc_spare)); #endif } } while (pcio.status == PCI_GETCONF_MORE_DEVS); return 0; }