mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
pci: add function to get currently loaded kernel driver
This commit is contained in:
parent
bd4f547e97
commit
293f496db0
2 changed files with 23 additions and 1 deletions
|
@ -57,6 +57,9 @@ int pci_device_compare(const struct pci_device *d, const struct pci_device *f);
|
|||
|
||||
struct pci_device * pci_lookup_device(struct pci *p, struct pci_device *filter);
|
||||
|
||||
/** Get currently loaded driver for device */
|
||||
int pci_get_driver(struct pci_device *d, char *buf, size_t buflen);
|
||||
|
||||
/** Bind a new LKM to the PCI device */
|
||||
int pci_attach_driver(struct pci_device *d, const char *driver);
|
||||
|
||||
|
|
|
@ -254,10 +254,29 @@ struct pci_device * pci_lookup_device(struct pci *p, struct pci_device *f)
|
|||
return list_search(&p->devices, (cmp_cb_t) pci_device_compare, (void *) f);
|
||||
}
|
||||
|
||||
int pci_get_driver(struct pci_device *d, char *buf, size_t buflen)
|
||||
{
|
||||
int ret;
|
||||
char sysfs[1024], syml[1024];
|
||||
|
||||
snprintf(sysfs, sizeof(sysfs), "%s/bus/pci/devices/%04x:%02x:%02x.%x/driver", SYSFS_PATH,
|
||||
d->slot.domain, d->slot.bus, d->slot.device, d->slot.function);
|
||||
|
||||
ret = readlink(sysfs, syml, sizeof(syml));
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
char *driver = basename(syml);
|
||||
|
||||
strncpy(buf, driver, buflen);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pci_attach_driver(struct pci_device *d, const char *driver)
|
||||
{
|
||||
FILE *f;
|
||||
char fn[256];
|
||||
char fn[1024];
|
||||
|
||||
/* Add new ID to driver */
|
||||
snprintf(fn, sizeof(fn), "%s/bus/pci/drivers/%s/new_id", SYSFS_PATH, driver);
|
||||
|
|
Loading…
Add table
Reference in a new issue