aboutsummaryrefslogtreecommitdiffstats
path: root/tools/libxl/libxl_pci.c
diff options
context:
space:
mode:
authorGianni Tedesco <gianni.tedesco@citrix.com>2010-07-29 18:49:47 +0100
committerGianni Tedesco <gianni.tedesco@citrix.com>2010-07-29 18:49:47 +0100
commita1d3c13679e97658c98d46c030bb9e2e3bd55e66 (patch)
tree7f14b9794417b7fa1d932bc32a022477018c2609 /tools/libxl/libxl_pci.c
parentc72acc065b1d3ef027b9b3e60a60e6ce282d52c6 (diff)
downloadxen-a1d3c13679e97658c98d46c030bb9e2e3bd55e66.tar.gz
xen-a1d3c13679e97658c98d46c030bb9e2e3bd55e66.tar.bz2
xen-a1d3c13679e97658c98d46c030bb9e2e3bd55e66.zip
libxl: Move libxl_device_pci_reset to libxl_pci.c
Signed-off-by: Gianni Tedesco <gianni.tedesco@citrix.com> Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
Diffstat (limited to 'tools/libxl/libxl_pci.c')
-rw-r--r--tools/libxl/libxl_pci.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c
index 76cef09bf5..3b2af3709e 100644
--- a/tools/libxl/libxl_pci.c
+++ b/tools/libxl/libxl_pci.c
@@ -536,3 +536,36 @@ int libxl_device_pci_init(libxl_device_pci *pcidev, unsigned int domain,
return 0;
}
+int libxl_device_pci_reset(libxl_ctx *ctx, unsigned int domain, unsigned int bus,
+ unsigned int dev, unsigned int func)
+{
+ char *reset = "/sys/bus/pci/drivers/pciback/do_flr";
+ int fd, rc;
+
+ fd = open(reset, O_WRONLY);
+ if (fd > 0) {
+ char *buf = libxl_sprintf(ctx, PCI_BDF, domain, bus, dev, func);
+ rc = write(fd, buf, strlen(buf));
+ if (rc < 0)
+ XL_LOG(ctx, XL_LOG_ERROR, "write to %s returned %d", reset, rc);
+ close(fd);
+ return rc < 0 ? rc : 0;
+ }
+ if (errno != ENOENT)
+ XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "Failed to access pciback path %s", reset);
+ reset = libxl_sprintf(ctx, "/sys/bus/pci/devices/"PCI_BDF"/reset", domain, bus, dev, func);
+ fd = open(reset, O_WRONLY);
+ if (fd > 0) {
+ rc = write(fd, "1", 1);
+ if (rc < 0)
+ XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "write to %s returned %d", reset, rc);
+ close(fd);
+ return rc < 0 ? rc : 0;
+ }
+ if (errno == ENOENT) {
+ XL_LOG(ctx, XL_LOG_ERROR, "The kernel doesn't support PCI device reset from sysfs");
+ } else {
+ XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "Failed to access reset path %s", reset);
+ }
+ return -1;
+}