The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=ffcf5e356644252f2f6c89ba01057af45c216559
commit ffcf5e356644252f2f6c89ba01057af45c216559 Author: John Baldwin <[email protected]> AuthorDate: 2026-05-18 18:50:39 +0000 Commit: John Baldwin <[email protected]> CommitDate: 2026-05-18 18:50:39 +0000 pci: Add is_pci_device helper function This returns true if a given device is a PCI device (child of a PCI bus). Reviewed by: bz, kib Sponsored by: Chelsio Communications Differential Revision: https://reviews.freebsd.org/D56996 --- share/man/man9/Makefile | 3 ++- share/man/man9/pci.9 | 11 ++++++++++- sys/dev/pci/pci.c | 11 +++++++++++ sys/dev/pci/pcivar.h | 1 + 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/share/man/man9/Makefile b/share/man/man9/Makefile index fbb981891ce4..7044b6f1bb68 100644 --- a/share/man/man9/Makefile +++ b/share/man/man9/Makefile @@ -1803,7 +1803,8 @@ MLINKS+=osd.9 osd_call.9 \ osd.9 osd_set_reserved.9 MLINKS+=panic.9 vpanic.9 \ panic.9 KERNEL_PANICKED.9 -MLINKS+=pci.9 pci_alloc_msi.9 \ +MLINKS+=pci.9 is_pci_device.9 \ + pci.9 pci_alloc_msi.9 \ pci.9 pci_alloc_msix.9 \ pci.9 pci_clear_pme.9 \ pci.9 pci_disable_busmaster.9 \ diff --git a/share/man/man9/pci.9 b/share/man/man9/pci.9 index 871f69f887a6..4d69d3a4240f 100644 --- a/share/man/man9/pci.9 +++ b/share/man/man9/pci.9 @@ -23,11 +23,12 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd March 27, 2025 +.Dd May 18, 2026 .Dt PCI 9 .Os .Sh NAME .Nm pci , +.Nm is_pci_device , .Nm pci_alloc_msi , .Nm pci_alloc_msix , .Nm pci_clear_pme , @@ -80,6 +81,8 @@ .In sys/bus.h .In dev/pci/pcireg.h .In dev/pci/pcivar.h +.Ft bool +.Fn is_pci_device "device_t dev" .Ft int .Fn pci_alloc_msi "device_t dev" "int *count" .Ft int @@ -202,6 +205,12 @@ device information, device configuration, and message signaled interrupts. +.Pp +The +.Fn is_pci_device +function can be used to determine if +.Fa dev +is a PCI device. .Ss Raw Configuration Access The .Fn pci_read_config diff --git a/sys/dev/pci/pci.c b/sys/dev/pci/pci.c index b5a3012accd6..adf3daea66fd 100644 --- a/sys/dev/pci/pci.c +++ b/sys/dev/pci/pci.c @@ -6993,6 +6993,17 @@ pci_print_faulted_dev(void) } } +bool +is_pci_device(device_t dev) +{ + devclass_t pci_class; + + if (device_get_parent(dev) == NULL) + return (false); + pci_class = devclass_find("pci"); + return (device_get_devclass(device_get_parent(dev)) == pci_class); +} + #ifdef DDB DB_SHOW_COMMAND_FLAGS(pcierr, pci_print_faulted_dev_db, DB_CMD_MEMSAFE) { diff --git a/sys/dev/pci/pcivar.h b/sys/dev/pci/pcivar.h index 696e1c688c68..bcd4d2d35b54 100644 --- a/sys/dev/pci/pcivar.h +++ b/sys/dev/pci/pcivar.h @@ -676,6 +676,7 @@ pci_child_added(device_t dev) return (PCI_CHILD_ADDED(device_get_parent(dev), dev)); } +bool is_pci_device(device_t dev); device_t pci_find_bsf(uint8_t, uint8_t, uint8_t); device_t pci_find_dbsf(uint32_t, uint8_t, uint8_t, uint8_t); device_t pci_find_device(uint16_t, uint16_t);
