summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMoritz Fischer <moritzf@google.com>2021-03-08 12:02:33 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2022-08-11 21:49:26 +0000
commit361356b08003f5e3c606e16eeb6a17fe02ff2726 (patch)
treed76b2ed596f90a146169dd45fc162b0cd634ea99 /src
parenta8abf913ad6b60492ef7b6ae512c4f879604a6a7 (diff)
Add pci_device_disable() function
This implements a pci_device_disable() function, currently only for the linux_sysfs() backend. This mirrors the implementation for pci_device_enable() Signed-off-by: Moritz Fischer <moritzf@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/common_interface.c10
-rw-r--r--src/linux_sysfs.c15
-rw-r--r--src/pciaccess_private.h1
3 files changed, 24 insertions, 2 deletions
diff --git a/src/common_interface.c b/src/common_interface.c
index a4439b6..6dbaa6b 100644
--- a/src/common_interface.c
+++ b/src/common_interface.c
@@ -676,6 +676,16 @@ pci_device_enable(struct pci_device *dev)
pci_sys->methods->enable(dev);
}
+void
+pci_device_disable(struct pci_device *dev)
+{
+ if (dev == NULL)
+ return;
+
+ if (pci_sys->methods->disable)
+ pci_sys->methods->disable(dev);
+}
+
/**
* Map the legacy memory space for the PCI domain containing \c dev.
*
diff --git a/src/linux_sysfs.c b/src/linux_sysfs.c
index 1b4051b..d62f48c 100644
--- a/src/linux_sysfs.c
+++ b/src/linux_sysfs.c
@@ -742,7 +742,7 @@ pci_device_linux_sysfs_unmap_range(struct pci_device *dev,
return err;
}
-static void pci_device_linux_sysfs_enable(struct pci_device *dev)
+static void pci_device_linux_sysfs_set_enable(struct pci_device *dev, int enable)
{
char name[256];
int fd;
@@ -758,10 +758,20 @@ static void pci_device_linux_sysfs_enable(struct pci_device *dev)
if (fd == -1)
return;
- write( fd, "1", 1 );
+ write( fd, enable ? "1" : "0" , 1 );
close(fd);
}
+static void pci_device_linux_sysfs_enable(struct pci_device *dev)
+{
+ return pci_device_linux_sysfs_set_enable(dev, 1);
+}
+
+static void pci_device_linux_sysfs_disable(struct pci_device *dev)
+{
+ return pci_device_linux_sysfs_set_enable(dev, 0);
+}
+
static int pci_device_linux_sysfs_boot_vga(struct pci_device *dev)
{
char name[256];
@@ -1042,6 +1052,7 @@ static const struct pci_system_methods linux_sysfs_methods = {
.fill_capabilities = pci_fill_capabilities_generic,
.enable = pci_device_linux_sysfs_enable,
+ .disable = pci_device_linux_sysfs_disable,
.boot_vga = pci_device_linux_sysfs_boot_vga,
.has_kernel_driver = pci_device_linux_sysfs_has_kernel_driver,
diff --git a/src/pciaccess_private.h b/src/pciaccess_private.h
index d3b68d4..be5d15d 100644
--- a/src/pciaccess_private.h
+++ b/src/pciaccess_private.h
@@ -76,6 +76,7 @@ struct pci_system_methods {
int (*fill_capabilities)( struct pci_device * dev );
void (*enable)( struct pci_device *dev );
+ void (*disable)( struct pci_device *dev );
int (*boot_vga)( struct pci_device *dev );
int (*has_kernel_driver)( struct pci_device *dev );
struct pci_io_handle *(*open_device_io)( struct pci_io_handle *handle,