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

Refactor: rename pci class to pci_device

Signed-off-by: Pascal Bauer <pascal.bauer@rwth-aachen.de>
This commit is contained in:
Pascal Bauer 2024-08-14 18:06:41 +02:00 committed by Niklas Eiling
parent 24782d4e1e
commit 1b5688b577
10 changed files with 29 additions and 29 deletions

View file

@ -58,15 +58,15 @@ struct Region {
unsigned long long flags;
};
class Device {
class PciDevice {
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
std::string getDriver() const;
@ -106,7 +106,7 @@ protected:
std::ios_base::out) const;
};
class DeviceList : public std::list<std::shared_ptr<Device>> {
class DeviceList : public std::list<std::shared_ptr<PciDevice>> {
private:
// Initialize Linux PCI handle.
//
@ -122,7 +122,7 @@ public:
DeviceList::value_type lookupDevice(const Id &i);
DeviceList::value_type lookupDevice(const Device &f);
DeviceList::value_type lookupDevice(const PciDevice &f);
};
} // namespace pci

View file

@ -49,7 +49,7 @@ public:
std::shared_ptr<Group> getOrAttachGroup(int index);
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
//

View file

@ -29,7 +29,7 @@ namespace vfio {
class Device {
public:
Device(const std::string &name, int groupFileDescriptor,
const kernel::pci::Device *pci_device = nullptr);
const kernel::pci::PciDevice *pci_device = nullptr);
~Device();
// No copying allowed because we manage the vfio state in constructor and destructors
@ -89,7 +89,7 @@ private:
std::vector<void *> mappings;
// libpci handle of the device
const kernel::pci::Device *pci_device;
const kernel::pci::PciDevice *pci_device;
Logger log;
};

View file

@ -48,7 +48,7 @@ public:
std::shared_ptr<Device> attachDevice(std::shared_ptr<Device> device);
std::shared_ptr<Device>
attachDevice(const std::string &name,
const kernel::pci::Device *pci_device = nullptr);
const kernel::pci::PciDevice *pci_device = nullptr);
bool checkStatus();
void dump();

View file

@ -82,7 +82,7 @@ DeviceList::DeviceList() {
if (ret != 4)
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);
@ -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(
begin(), end(), [d](const DeviceList::value_type &e) { return *e == d; });
@ -247,11 +247,11 @@ bool Slot::operator==(const Slot &s) {
return true;
}
bool Device::operator==(const Device &f) {
bool PciDevice::operator==(const PciDevice &f) {
return id == f.id && slot == f.slot;
}
std::list<Region> Device::getRegions() const {
std::list<Region> PciDevice::getRegions() const {
FILE *f;
char sysfs[1024];
@ -311,7 +311,7 @@ std::list<Region> Device::getRegions() const {
return regions;
}
std::string Device::getDriver() const {
std::string PciDevice::getDriver() const {
int ret;
char sysfs[1024], syml[1024];
memset(syml, 0, sizeof(syml));
@ -331,7 +331,7 @@ std::string Device::getDriver() const {
return basename(syml);
}
bool Device::attachDriver(const std::string &driver) const {
bool PciDevice::attachDriver(const std::string &driver) const {
FILE *f;
char fn[1024];
@ -363,7 +363,7 @@ bool Device::attachDriver(const std::string &driver) const {
return true;
}
uint32_t Device::readHostBar(unsigned barNum) const {
uint32_t PciDevice::readHostBar(unsigned barNum) const {
auto file = openSysFs("resource", std::ios_base::in);
std::string line;
@ -389,7 +389,7 @@ uint32_t Device::readHostBar(unsigned barNum) const {
return start;
}
void Device::rewriteBar(unsigned barNum) {
void PciDevice::rewriteBar(unsigned barNum) {
auto hostBar = readHostBar(barNum);
auto configBar = readBar(barNum);
@ -405,7 +405,7 @@ void Device::rewriteBar(unsigned barNum) {
writeBar(hostBar, barNum);
}
uint32_t Device::readBar(unsigned barNum) const {
uint32_t PciDevice::readBar(unsigned barNum) const {
uint32_t addr;
auto file = openSysFs("config", std::ios_base::in);
@ -415,14 +415,14 @@ uint32_t Device::readBar(unsigned barNum) const {
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);
file.seekp(PCI_BASE_ADDRESS_N(barNum));
file.write(reinterpret_cast<char *>(&addr), sizeof(addr));
}
int Device::getIommuGroup() const {
int PciDevice::getIommuGroup() const {
int ret;
char *group;
@ -443,7 +443,7 @@ int Device::getIommuGroup() const {
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::fstream file;

View file

@ -187,7 +187,7 @@ std::shared_ptr<Device> Container::attachDevice(const std::string &name,
return device;
}
std::shared_ptr<Device> Container::attachDevice(pci::Device &pdev) {
std::shared_ptr<Device> Container::attachDevice(pci::PciDevice &pdev) {
int ret;
char name[32], iommu_state[4];
static constexpr const char *kernelDriver = "vfio-pci";

View file

@ -53,7 +53,7 @@ static const char *vfio_pci_irq_names[] = {
};
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),
info(), irqs(), regions(), mappings(), pci_device(pci_device),
log(Log::get("kernel:vfio:device")) {

View file

@ -68,7 +68,7 @@ std::shared_ptr<Device> Group::attachDevice(std::shared_ptr<Device> device) {
std::shared_ptr<Device>
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);
return attachDevice(device);
}

View file

@ -55,7 +55,7 @@ public: // TODO: make this private
bool doReset; // Reset VILLASfpga during startup?
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:
Logger getLogger() const { return villas::Log::get(name); }

View file

@ -24,7 +24,7 @@ using namespace villas::fpga;
// Instantiate factory to register
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)));
std::shared_ptr<PCIeCard>
@ -63,7 +63,7 @@ PCIeCardFactory::make(json_t *json_card, std::string card_name,
card->doReset = do_reset != 0;
card->polling = (polling != 0);
kernel::pci::Device filter = defaultFilter;
kernel::pci::PciDevice filter = defaultFilter;
if (pci_id)
filter.id = kernel::pci::Id(pci_id);