Commit b40f3870 authored by Niclas Zeising's avatar Niclas Zeising
Browse files

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's avatarNiclas Zeising <zeising@daemonic.se>
parent baa40844
......@@ -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,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment