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
This commit is contained in:
John Baldwin
2026-05-18 14:50:39 -04:00
parent 6a043d0814
commit ffcf5e3566
4 changed files with 24 additions and 2 deletions
+2 -1
View File
@@ -1803,7 +1803,8 @@ MLINKS+=osd.9 osd_call.9 \
osd.9 osd_set_reserved.9 osd.9 osd_set_reserved.9
MLINKS+=panic.9 vpanic.9 \ MLINKS+=panic.9 vpanic.9 \
panic.9 KERNEL_PANICKED.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_alloc_msix.9 \
pci.9 pci_clear_pme.9 \ pci.9 pci_clear_pme.9 \
pci.9 pci_disable_busmaster.9 \ pci.9 pci_disable_busmaster.9 \
+10 -1
View File
@@ -23,11 +23,12 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE. .\" SUCH DAMAGE.
.\" .\"
.Dd March 27, 2025 .Dd May 18, 2026
.Dt PCI 9 .Dt PCI 9
.Os .Os
.Sh NAME .Sh NAME
.Nm pci , .Nm pci ,
.Nm is_pci_device ,
.Nm pci_alloc_msi , .Nm pci_alloc_msi ,
.Nm pci_alloc_msix , .Nm pci_alloc_msix ,
.Nm pci_clear_pme , .Nm pci_clear_pme ,
@@ -80,6 +81,8 @@
.In sys/bus.h .In sys/bus.h
.In dev/pci/pcireg.h .In dev/pci/pcireg.h
.In dev/pci/pcivar.h .In dev/pci/pcivar.h
.Ft bool
.Fn is_pci_device "device_t dev"
.Ft int .Ft int
.Fn pci_alloc_msi "device_t dev" "int *count" .Fn pci_alloc_msi "device_t dev" "int *count"
.Ft int .Ft int
@@ -202,6 +205,12 @@ device information,
device configuration, device configuration,
and and
message signaled interrupts. 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 .Ss Raw Configuration Access
The The
.Fn pci_read_config .Fn pci_read_config
+11
View File
@@ -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 #ifdef DDB
DB_SHOW_COMMAND_FLAGS(pcierr, pci_print_faulted_dev_db, DB_CMD_MEMSAFE) DB_SHOW_COMMAND_FLAGS(pcierr, pci_print_faulted_dev_db, DB_CMD_MEMSAFE)
{ {
+1
View File
@@ -676,6 +676,7 @@ pci_child_added(device_t dev)
return (PCI_CHILD_ADDED(device_get_parent(dev), 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_bsf(uint8_t, uint8_t, uint8_t);
device_t pci_find_dbsf(uint32_t, 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); device_t pci_find_device(uint16_t, uint16_t);