The branch stable/14 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=0603a7459fc1d04a0415af37fd5f45c2ef3f13dc
commit 0603a7459fc1d04a0415af37fd5f45c2ef3f13dc Author: John Baldwin <[email protected]> AuthorDate: 2026-05-18 18:50:39 +0000 Commit: John Baldwin <[email protected]> CommitDate: 2026-06-23 16:08:58 +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 (cherry picked from commit ffcf5e356644252f2f6c89ba01057af45c216559) --- 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 a0af571a4e9b..4e275e3099e9 100644 --- a/share/man/man9/Makefile +++ b/share/man/man9/Makefile @@ -1782,7 +1782,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 b01b51683b4f..3aacda94eaca 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 58fdbe1703f1..bf9797784362 100644 --- a/sys/dev/pci/pci.c +++ b/sys/dev/pci/pci.c @@ -6995,6 +6995,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 c69f2b1e09bd..9f8ca069af88 100644 --- a/sys/dev/pci/pcivar.h +++ b/sys/dev/pci/pcivar.h @@ -663,6 +663,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);
