1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

implement driver()

Signed-off-by: Pascal Bauer <pascal.bauer@rwth-aachen.de>
This commit is contained in:
Pascal Bauer 2024-08-23 20:38:25 +02:00 committed by Niklas Eiling
parent b5f5e51bee
commit c4d414c2af
2 changed files with 8 additions and 6 deletions

View file

@ -70,8 +70,8 @@ public:
bool operator==(const PciDevice &other);
// Get currently loaded driver for device
std::string getDriver() const;
// Implement device interface
std::optional<std::unique_ptr<Driver>> driver() const override;
// Bind a new LKM to the PCI device
bool attachDriver(const std::string &driver) const;

View file

@ -18,6 +18,7 @@
#include <villas/config.hpp>
#include <villas/exceptions.hpp>
#include <villas/kernel/devices/generic_driver.hpp>
#include <villas/kernel/devices/pci_device.hpp>
#include <villas/utils.hpp>
@ -311,8 +312,7 @@ std::list<Region> PciDevice::getRegions() const {
return regions;
}
std::string PciDevice::getDriver() const {
std::optional<std::unique_ptr<Driver>> PciDevice::driver() const {
int ret;
char sysfs[1024], syml[1024];
memset(syml, 0, sizeof(syml));
@ -323,13 +323,15 @@ std::string PciDevice::getDriver() const {
struct stat st;
ret = stat(sysfs, &st);
if (ret)
return "";
return std::nullopt;
ret = readlink(sysfs, syml, sizeof(syml));
if (ret < 0)
throw SystemError("Failed to follow link: {}", sysfs);
return basename(syml);
auto driver = std::make_optional(std::make_unique<GenericDriver>(
"/sys/bus/pci/drivers/" + std::string(basename(syml))));
return driver;
}
bool PciDevice::attachDriver(const std::string &driver) const {