mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-30 00:00:11 +01:00
Refactor: rename pci class to pci_device
Signed-off-by: Pascal Bauer <pascal.bauer@rwth-aachen.de>
This commit is contained in:
parent
91b541943e
commit
975c02dc7d
10 changed files with 29 additions and 29 deletions
|
@ -58,15 +58,15 @@ struct Region {
|
||||||
unsigned long long flags;
|
unsigned long long flags;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Device {
|
class PciDevice {
|
||||||
public:
|
public:
|
||||||
Device(Id i, Slot s) : id(i), slot(s), log(Log::get("kernel:pci")) {}
|
PciDevice(Id i, Slot s) : id(i), slot(s), log(Log::get("kernel:pci")) {}
|
||||||
|
|
||||||
Device(Id i) : id(i), log(Log::get("kernel:pci")) {}
|
PciDevice(Id i) : id(i), log(Log::get("kernel:pci")) {}
|
||||||
|
|
||||||
Device(Slot s) : slot(s), log(Log::get("kernel:pci")) {}
|
PciDevice(Slot s) : slot(s), log(Log::get("kernel:pci")) {}
|
||||||
|
|
||||||
bool operator==(const Device &other);
|
bool operator==(const PciDevice &other);
|
||||||
|
|
||||||
// Get currently loaded driver for device
|
// Get currently loaded driver for device
|
||||||
std::string getDriver() const;
|
std::string getDriver() const;
|
||||||
|
@ -106,7 +106,7 @@ protected:
|
||||||
std::ios_base::out) const;
|
std::ios_base::out) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DeviceList : public std::list<std::shared_ptr<Device>> {
|
class DeviceList : public std::list<std::shared_ptr<PciDevice>> {
|
||||||
private:
|
private:
|
||||||
// Initialize Linux PCI handle.
|
// Initialize Linux PCI handle.
|
||||||
//
|
//
|
||||||
|
@ -122,7 +122,7 @@ public:
|
||||||
|
|
||||||
DeviceList::value_type lookupDevice(const Id &i);
|
DeviceList::value_type lookupDevice(const Id &i);
|
||||||
|
|
||||||
DeviceList::value_type lookupDevice(const Device &f);
|
DeviceList::value_type lookupDevice(const PciDevice &f);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace pci
|
} // namespace pci
|
||||||
|
|
|
@ -49,7 +49,7 @@ public:
|
||||||
std::shared_ptr<Group> getOrAttachGroup(int index);
|
std::shared_ptr<Group> getOrAttachGroup(int index);
|
||||||
|
|
||||||
std::shared_ptr<Device> attachDevice(const std::string &name, int groupIndex);
|
std::shared_ptr<Device> attachDevice(const std::string &name, int groupIndex);
|
||||||
std::shared_ptr<Device> attachDevice(pci::Device &pdev);
|
std::shared_ptr<Device> attachDevice(pci::PciDevice &pdev);
|
||||||
|
|
||||||
// Map VM to an IOVA, which is accessible by devices in the container
|
// Map VM to an IOVA, which is accessible by devices in the container
|
||||||
//
|
//
|
||||||
|
|
|
@ -29,7 +29,7 @@ namespace vfio {
|
||||||
class Device {
|
class Device {
|
||||||
public:
|
public:
|
||||||
Device(const std::string &name, int groupFileDescriptor,
|
Device(const std::string &name, int groupFileDescriptor,
|
||||||
const kernel::pci::Device *pci_device = nullptr);
|
const kernel::pci::PciDevice *pci_device = nullptr);
|
||||||
~Device();
|
~Device();
|
||||||
|
|
||||||
// No copying allowed because we manage the vfio state in constructor and destructors
|
// No copying allowed because we manage the vfio state in constructor and destructors
|
||||||
|
@ -89,7 +89,7 @@ private:
|
||||||
std::vector<void *> mappings;
|
std::vector<void *> mappings;
|
||||||
|
|
||||||
// libpci handle of the device
|
// libpci handle of the device
|
||||||
const kernel::pci::Device *pci_device;
|
const kernel::pci::PciDevice *pci_device;
|
||||||
|
|
||||||
Logger log;
|
Logger log;
|
||||||
};
|
};
|
||||||
|
|
|
@ -48,7 +48,7 @@ public:
|
||||||
std::shared_ptr<Device> attachDevice(std::shared_ptr<Device> device);
|
std::shared_ptr<Device> attachDevice(std::shared_ptr<Device> device);
|
||||||
std::shared_ptr<Device>
|
std::shared_ptr<Device>
|
||||||
attachDevice(const std::string &name,
|
attachDevice(const std::string &name,
|
||||||
const kernel::pci::Device *pci_device = nullptr);
|
const kernel::pci::PciDevice *pci_device = nullptr);
|
||||||
|
|
||||||
bool checkStatus();
|
bool checkStatus();
|
||||||
void dump();
|
void dump();
|
||||||
|
|
|
@ -82,7 +82,7 @@ DeviceList::DeviceList() {
|
||||||
if (ret != 4)
|
if (ret != 4)
|
||||||
throw RuntimeError("Failed to parse PCI slot number: {}", e->d_name);
|
throw RuntimeError("Failed to parse PCI slot number: {}", e->d_name);
|
||||||
|
|
||||||
emplace_back(std::make_shared<Device>(id, slot));
|
emplace_back(std::make_shared<PciDevice>(id, slot));
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(dp);
|
closedir(dp);
|
||||||
|
@ -100,7 +100,7 @@ DeviceList::value_type DeviceList::lookupDevice(const Id &i) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceList::value_type DeviceList::lookupDevice(const Device &d) {
|
DeviceList::value_type DeviceList::lookupDevice(const PciDevice &d) {
|
||||||
auto dev = std::find_if(
|
auto dev = std::find_if(
|
||||||
begin(), end(), [d](const DeviceList::value_type &e) { return *e == d; });
|
begin(), end(), [d](const DeviceList::value_type &e) { return *e == d; });
|
||||||
|
|
||||||
|
@ -247,11 +247,11 @@ bool Slot::operator==(const Slot &s) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Device::operator==(const Device &f) {
|
bool PciDevice::operator==(const PciDevice &f) {
|
||||||
return id == f.id && slot == f.slot;
|
return id == f.id && slot == f.slot;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<Region> Device::getRegions() const {
|
std::list<Region> PciDevice::getRegions() const {
|
||||||
FILE *f;
|
FILE *f;
|
||||||
char sysfs[1024];
|
char sysfs[1024];
|
||||||
|
|
||||||
|
@ -311,7 +311,7 @@ std::list<Region> Device::getRegions() const {
|
||||||
return regions;
|
return regions;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Device::getDriver() const {
|
std::string PciDevice::getDriver() const {
|
||||||
int ret;
|
int ret;
|
||||||
char sysfs[1024], syml[1024];
|
char sysfs[1024], syml[1024];
|
||||||
memset(syml, 0, sizeof(syml));
|
memset(syml, 0, sizeof(syml));
|
||||||
|
@ -331,7 +331,7 @@ std::string Device::getDriver() const {
|
||||||
return basename(syml);
|
return basename(syml);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Device::attachDriver(const std::string &driver) const {
|
bool PciDevice::attachDriver(const std::string &driver) const {
|
||||||
FILE *f;
|
FILE *f;
|
||||||
char fn[1024];
|
char fn[1024];
|
||||||
|
|
||||||
|
@ -363,7 +363,7 @@ bool Device::attachDriver(const std::string &driver) const {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Device::readHostBar(unsigned barNum) const {
|
uint32_t PciDevice::readHostBar(unsigned barNum) const {
|
||||||
auto file = openSysFs("resource", std::ios_base::in);
|
auto file = openSysFs("resource", std::ios_base::in);
|
||||||
|
|
||||||
std::string line;
|
std::string line;
|
||||||
|
@ -389,7 +389,7 @@ uint32_t Device::readHostBar(unsigned barNum) const {
|
||||||
return start;
|
return start;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::rewriteBar(unsigned barNum) {
|
void PciDevice::rewriteBar(unsigned barNum) {
|
||||||
auto hostBar = readHostBar(barNum);
|
auto hostBar = readHostBar(barNum);
|
||||||
auto configBar = readBar(barNum);
|
auto configBar = readBar(barNum);
|
||||||
|
|
||||||
|
@ -405,7 +405,7 @@ void Device::rewriteBar(unsigned barNum) {
|
||||||
writeBar(hostBar, barNum);
|
writeBar(hostBar, barNum);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Device::readBar(unsigned barNum) const {
|
uint32_t PciDevice::readBar(unsigned barNum) const {
|
||||||
uint32_t addr;
|
uint32_t addr;
|
||||||
auto file = openSysFs("config", std::ios_base::in);
|
auto file = openSysFs("config", std::ios_base::in);
|
||||||
|
|
||||||
|
@ -415,14 +415,14 @@ uint32_t Device::readBar(unsigned barNum) const {
|
||||||
return addr;
|
return addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::writeBar(uint32_t addr, unsigned barNum) {
|
void PciDevice::writeBar(uint32_t addr, unsigned barNum) {
|
||||||
auto file = openSysFs("config", std::ios_base::out);
|
auto file = openSysFs("config", std::ios_base::out);
|
||||||
|
|
||||||
file.seekp(PCI_BASE_ADDRESS_N(barNum));
|
file.seekp(PCI_BASE_ADDRESS_N(barNum));
|
||||||
file.write(reinterpret_cast<char *>(&addr), sizeof(addr));
|
file.write(reinterpret_cast<char *>(&addr), sizeof(addr));
|
||||||
}
|
}
|
||||||
|
|
||||||
int Device::getIommuGroup() const {
|
int PciDevice::getIommuGroup() const {
|
||||||
int ret;
|
int ret;
|
||||||
char *group;
|
char *group;
|
||||||
|
|
||||||
|
@ -443,7 +443,7 @@ int Device::getIommuGroup() const {
|
||||||
return atoi(group);
|
return atoi(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::fstream Device::openSysFs(const std::string &subPath,
|
std::fstream PciDevice::openSysFs(const std::string &subPath,
|
||||||
std::ios_base::openmode mode) const {
|
std::ios_base::openmode mode) const {
|
||||||
std::fstream file;
|
std::fstream file;
|
||||||
|
|
||||||
|
|
|
@ -187,7 +187,7 @@ std::shared_ptr<Device> Container::attachDevice(const std::string &name,
|
||||||
return device;
|
return device;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Device> Container::attachDevice(pci::Device &pdev) {
|
std::shared_ptr<Device> Container::attachDevice(pci::PciDevice &pdev) {
|
||||||
int ret;
|
int ret;
|
||||||
char name[32], iommu_state[4];
|
char name[32], iommu_state[4];
|
||||||
static constexpr const char *kernelDriver = "vfio-pci";
|
static constexpr const char *kernelDriver = "vfio-pci";
|
||||||
|
|
|
@ -53,7 +53,7 @@ static const char *vfio_pci_irq_names[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
Device::Device(const std::string &name, int groupFileDescriptor,
|
Device::Device(const std::string &name, int groupFileDescriptor,
|
||||||
const kernel::pci::Device *pci_device)
|
const kernel::pci::PciDevice *pci_device)
|
||||||
: name(name), fd(-1), attachedToGroup(false), groupFd(groupFileDescriptor),
|
: name(name), fd(-1), attachedToGroup(false), groupFd(groupFileDescriptor),
|
||||||
info(), irqs(), regions(), mappings(), pci_device(pci_device),
|
info(), irqs(), regions(), mappings(), pci_device(pci_device),
|
||||||
log(Log::get("kernel:vfio:device")) {
|
log(Log::get("kernel:vfio:device")) {
|
||||||
|
|
|
@ -68,7 +68,7 @@ std::shared_ptr<Device> Group::attachDevice(std::shared_ptr<Device> device) {
|
||||||
|
|
||||||
std::shared_ptr<Device>
|
std::shared_ptr<Device>
|
||||||
Group::attachDevice(const std::string &name,
|
Group::attachDevice(const std::string &name,
|
||||||
const kernel::pci::Device *pci_device) {
|
const kernel::pci::PciDevice *pci_device) {
|
||||||
auto device = std::make_shared<Device>(name, fd, pci_device);
|
auto device = std::make_shared<Device>(name, fd, pci_device);
|
||||||
return attachDevice(device);
|
return attachDevice(device);
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ public: // TODO: make this private
|
||||||
bool doReset; // Reset VILLASfpga during startup?
|
bool doReset; // Reset VILLASfpga during startup?
|
||||||
int affinity; // Affinity for MSI interrupts
|
int affinity; // Affinity for MSI interrupts
|
||||||
|
|
||||||
std::shared_ptr<kernel::pci::Device> pdev; // PCI device handle
|
std::shared_ptr<kernel::pci::PciDevice> pdev; // PCI device handle
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Logger getLogger() const { return villas::Log::get(name); }
|
Logger getLogger() const { return villas::Log::get(name); }
|
||||||
|
|
|
@ -24,7 +24,7 @@ using namespace villas::fpga;
|
||||||
// Instantiate factory to register
|
// Instantiate factory to register
|
||||||
static PCIeCardFactory PCIeCardFactoryInstance;
|
static PCIeCardFactory PCIeCardFactoryInstance;
|
||||||
|
|
||||||
static const kernel::pci::Device
|
static const kernel::pci::PciDevice
|
||||||
defaultFilter((kernel::pci::Id(FPGA_PCI_VID_XILINX, FPGA_PCI_PID_VFPGA)));
|
defaultFilter((kernel::pci::Id(FPGA_PCI_VID_XILINX, FPGA_PCI_PID_VFPGA)));
|
||||||
|
|
||||||
std::shared_ptr<PCIeCard>
|
std::shared_ptr<PCIeCard>
|
||||||
|
@ -63,7 +63,7 @@ PCIeCardFactory::make(json_t *json_card, std::string card_name,
|
||||||
card->doReset = do_reset != 0;
|
card->doReset = do_reset != 0;
|
||||||
card->polling = (polling != 0);
|
card->polling = (polling != 0);
|
||||||
|
|
||||||
kernel::pci::Device filter = defaultFilter;
|
kernel::pci::PciDevice filter = defaultFilter;
|
||||||
|
|
||||||
if (pci_id)
|
if (pci_id)
|
||||||
filter.id = kernel::pci::Id(pci_id);
|
filter.id = kernel::pci::Id(pci_id);
|
||||||
|
|
Loading…
Add table
Reference in a new issue