pci: refactor Linux pci_device_has_non_uio_driver()
Use /sys/bus/pci/devices/.../driver to determine which driver is loaded for a particular device. Change-Id: I5859a776e524033e1c6d6ec3796b7e11bdcf0bc4 Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
parent
040742359e
commit
fceb072b09
@ -96,39 +96,36 @@ pci_device_get_serial_number(struct pci_device *dev, char *sn, int len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
static int
|
int
|
||||||
pci_device_has_uio_driver(struct pci_device *dev)
|
pci_device_has_non_uio_driver(struct pci_device *dev)
|
||||||
{
|
{
|
||||||
struct dirent *e;
|
char linkname[SPDK_PCI_PATH_MAX];
|
||||||
DIR *dir;
|
char driver[SPDK_PCI_PATH_MAX];
|
||||||
char dirname[SPDK_PCI_PATH_MAX];
|
ssize_t driver_len;
|
||||||
|
char *driver_begin;
|
||||||
|
|
||||||
snprintf(dirname, sizeof(dirname),
|
snprintf(linkname, sizeof(linkname),
|
||||||
SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/uio",
|
SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/driver",
|
||||||
dev->domain, dev->bus, dev->dev, dev->func);
|
dev->domain, dev->bus, dev->dev, dev->func);
|
||||||
|
|
||||||
dir = opendir(dirname);
|
driver_len = readlink(linkname, driver, sizeof(driver));
|
||||||
if (!dir) {
|
|
||||||
snprintf(dirname, sizeof(dirname),
|
|
||||||
SYSFS_PCI_DEVICES "/" PCI_PRI_FMT,
|
|
||||||
dev->domain, dev->bus, dev->dev, dev->func);
|
|
||||||
dir = opendir(dirname);
|
|
||||||
if (!dir)
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
while ((e = readdir(dir)) != NULL) {
|
if (driver_len < 0 || driver_len >= SPDK_PCI_PATH_MAX) {
|
||||||
if (strncmp(e->d_name, "uio", 3) == 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
closedir(dir);
|
|
||||||
|
|
||||||
if (!e)
|
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
driver[driver_len] = '\0'; /* readlink() doesn't null terminate, so we have to */
|
||||||
|
|
||||||
|
driver_begin = strrchr(driver, '/');
|
||||||
|
if (driver_begin) {
|
||||||
|
/* Advance to the character after the slash */
|
||||||
|
driver_begin++;
|
||||||
|
} else {
|
||||||
|
/* This shouldn't normally happen - driver should be a relative path with slashes */
|
||||||
|
driver_begin = driver;
|
||||||
|
}
|
||||||
|
|
||||||
|
return strcmp(driver_begin, "uio_pci_generic") != 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -183,12 +180,6 @@ pci_device_has_non_uio_driver(struct pci_device *dev)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
int
|
|
||||||
pci_device_has_non_uio_driver(struct pci_device *dev)
|
|
||||||
{
|
|
||||||
return pci_device_has_kernel_driver(dev) && !pci_device_has_uio_driver(dev);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int
|
int
|
||||||
|
Loading…
Reference in New Issue
Block a user