summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNiclas Zeising <zeising@daemonic.se>2019-06-15 10:59:00 +0200
committerNiclas Zeising <zeising@daemonic.se>2019-07-10 18:56:23 +0200
commitb40f387048a5c7b280d0c83d3af9d34ceca7f4f8 (patch)
treed17652ecce43db893c3e3bc347329cebd21a330e /src
parentbaa4084474665e34a8d6a9bba0e97d9aa5dcd88a (diff)
freebsd_pci: Add has_kernel_driver function
Add a has_kernel_driver function to the FreeBSD libpciaccess functions. This uses the PCIOCATTACHED ioctl to check if a driver is attached to a specific PCI device. Idea taken from the FreeBSD system utility pciconf. Signed-off-by: Niclas Zeising <zeising@daemonic.se>
Diffstat (limited to 'src')
-rw-r--r--src/freebsd_pci.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/freebsd_pci.c b/src/freebsd_pci.c
index d140474..dc67895 100644
--- a/src/freebsd_pci.c
+++ b/src/freebsd_pci.c
@@ -584,6 +584,24 @@ pci_system_freebsd_destroy( void )
freebsd_pci_sys = NULL;
}
+static int
+pci_device_freebsd_has_kernel_driver( struct pci_device *dev )
+{
+ struct pci_io io;
+
+ io.pi_sel.pc_domain = dev->domain;
+ io.pi_sel.pc_bus = dev->bus;
+ io.pi_sel.pc_dev = dev->dev;
+ io.pi_sel.pc_func = dev->func;
+
+ if ( ioctl( freebsd_pci_sys->pcidev, PCIOCATTACHED, &io ) < 0 ) {
+ return 0;
+ }
+
+ /* if io.pi_data is 0, no driver is attached */
+ return io.pi_data == 0 ? 0 : 1;
+}
+
static struct pci_io_handle *
pci_device_freebsd_open_legacy_io( struct pci_io_handle *ret,
struct pci_device *dev, pciaddr_t base,
@@ -755,6 +773,7 @@ static const struct pci_system_methods freebsd_pci_methods = {
.read = pci_device_freebsd_read,
.write = pci_device_freebsd_write,
.fill_capabilities = pci_fill_capabilities_generic,
+ .has_kernel_driver = pci_device_freebsd_has_kernel_driver,
.open_device_io = pci_device_freebsd_open_io,
.open_legacy_io = pci_device_freebsd_open_legacy_io,
.close_io = pci_device_freebsd_close_io,