From b40f387048a5c7b280d0c83d3af9d34ceca7f4f8 Mon Sep 17 00:00:00 2001 From: Niclas Zeising Date: Sat, 15 Jun 2019 10:59:00 +0200 Subject: 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 --- src/freebsd_pci.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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, -- cgit v1.2.1