From 24782d4e1e02980a3b6e5c7760a4d74d40c7875f Mon Sep 17 00:00:00 2001 From: Pascal Bauer Date: Wed, 14 Aug 2024 17:58:14 +0200 Subject: [PATCH 1/5] Refactor: Move pci to devices/pci_device Signed-off-by: Pascal Bauer --- CODEOWNERS | 2 +- .../include/villas/kernel/{pci.hpp => devices/pci_device.hpp} | 0 common/include/villas/kernel/vfio_device.hpp | 2 +- common/lib/CMakeLists.txt | 2 +- common/lib/kernel/{pci.cpp => devices/pci_device.cpp} | 2 +- fpga/gpu/src/gpu.cpp | 2 +- fpga/include/villas/fpga/pcie_card.hpp | 2 +- fpga/lib/pcie_card.cpp | 2 +- 8 files changed, 7 insertions(+), 7 deletions(-) rename common/include/villas/kernel/{pci.hpp => devices/pci_device.hpp} (100%) rename common/lib/kernel/{pci.cpp => devices/pci_device.cpp} (99%) diff --git a/CODEOWNERS b/CODEOWNERS index ef7dc9ef1..4f88b8a27 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -35,5 +35,5 @@ fpga @n-eiling # VFIO related files /common/lib/kernel/pci.cpp @n-eiling /common/lib/kernel/vfi_*.cpp @n-eiling -/common/include/villas/kernel/pci.hpp @n-eiling +/common/include/villas/kernel/devices/pci_device.hpp @n-eiling /common/include/villas/kernel/vfio_*.hpp @n-eiling diff --git a/common/include/villas/kernel/pci.hpp b/common/include/villas/kernel/devices/pci_device.hpp similarity index 100% rename from common/include/villas/kernel/pci.hpp rename to common/include/villas/kernel/devices/pci_device.hpp diff --git a/common/include/villas/kernel/vfio_device.hpp b/common/include/villas/kernel/vfio_device.hpp index 9f8c51a7c..ce291bc27 100644 --- a/common/include/villas/kernel/vfio_device.hpp +++ b/common/include/villas/kernel/vfio_device.hpp @@ -19,7 +19,7 @@ #include #include -#include +#include #include namespace villas { diff --git a/common/lib/CMakeLists.txt b/common/lib/CMakeLists.txt index 7927fc0f4..116d786e6 100644 --- a/common/lib/CMakeLists.txt +++ b/common/lib/CMakeLists.txt @@ -39,7 +39,7 @@ endif() if(CMAKE_SYSTEM_NAME STREQUAL Linux) target_sources(villas-common PRIVATE - kernel/pci.cpp + kernel/devices/pci_device.cpp kernel/vfio_device.cpp kernel/vfio_group.cpp kernel/vfio_container.cpp diff --git a/common/lib/kernel/pci.cpp b/common/lib/kernel/devices/pci_device.cpp similarity index 99% rename from common/lib/kernel/pci.cpp rename to common/lib/kernel/devices/pci_device.cpp index c999f77e2..baf385072 100644 --- a/common/lib/kernel/pci.cpp +++ b/common/lib/kernel/devices/pci_device.cpp @@ -18,7 +18,7 @@ #include #include -#include +#include #include using namespace villas::kernel::pci; diff --git a/fpga/gpu/src/gpu.cpp b/fpga/gpu/src/gpu.cpp index f68d69265..f80a9521e 100644 --- a/fpga/gpu/src/gpu.cpp +++ b/fpga/gpu/src/gpu.cpp @@ -13,7 +13,7 @@ #include #include -#include +#include #include #include diff --git a/fpga/include/villas/fpga/pcie_card.hpp b/fpga/include/villas/fpga/pcie_card.hpp index f5368d399..d3ba2f54a 100644 --- a/fpga/include/villas/fpga/pcie_card.hpp +++ b/fpga/include/villas/fpga/pcie_card.hpp @@ -19,7 +19,7 @@ #include #include -#include +#include #include #include diff --git a/fpga/lib/pcie_card.cpp b/fpga/lib/pcie_card.cpp index e2669820c..f44026fd6 100644 --- a/fpga/lib/pcie_card.cpp +++ b/fpga/lib/pcie_card.cpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include From 1b5688b577b487480c988aa6a38a625b3c260863 Mon Sep 17 00:00:00 2001 From: Pascal Bauer Date: Wed, 14 Aug 2024 18:06:41 +0200 Subject: [PATCH 2/5] Refactor: rename pci class to pci_device Signed-off-by: Pascal Bauer --- .../villas/kernel/devices/pci_device.hpp | 14 +++++------ .../include/villas/kernel/vfio_container.hpp | 2 +- common/include/villas/kernel/vfio_device.hpp | 4 ++-- common/include/villas/kernel/vfio_group.hpp | 2 +- common/lib/kernel/devices/pci_device.cpp | 24 +++++++++---------- common/lib/kernel/vfio_container.cpp | 2 +- common/lib/kernel/vfio_device.cpp | 2 +- common/lib/kernel/vfio_group.cpp | 2 +- fpga/include/villas/fpga/pcie_card.hpp | 2 +- fpga/lib/pcie_card.cpp | 4 ++-- 10 files changed, 29 insertions(+), 29 deletions(-) diff --git a/common/include/villas/kernel/devices/pci_device.hpp b/common/include/villas/kernel/devices/pci_device.hpp index 8d792d7cc..e71fa4ecc 100644 --- a/common/include/villas/kernel/devices/pci_device.hpp +++ b/common/include/villas/kernel/devices/pci_device.hpp @@ -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 @@ class Device { std::ios_base::out) const; }; -class DeviceList : public std::list> { +class DeviceList : public std::list> { private: // Initialize Linux PCI handle. // @@ -122,7 +122,7 @@ class DeviceList : public std::list> { DeviceList::value_type lookupDevice(const Id &i); - DeviceList::value_type lookupDevice(const Device &f); + DeviceList::value_type lookupDevice(const PciDevice &f); }; } // namespace pci diff --git a/common/include/villas/kernel/vfio_container.hpp b/common/include/villas/kernel/vfio_container.hpp index 2e0ffaf97..fedb36436 100644 --- a/common/include/villas/kernel/vfio_container.hpp +++ b/common/include/villas/kernel/vfio_container.hpp @@ -49,7 +49,7 @@ class Container { std::shared_ptr getOrAttachGroup(int index); std::shared_ptr attachDevice(const std::string &name, int groupIndex); - std::shared_ptr attachDevice(pci::Device &pdev); + std::shared_ptr attachDevice(pci::PciDevice &pdev); // Map VM to an IOVA, which is accessible by devices in the container // diff --git a/common/include/villas/kernel/vfio_device.hpp b/common/include/villas/kernel/vfio_device.hpp index ce291bc27..a7805f6ad 100644 --- a/common/include/villas/kernel/vfio_device.hpp +++ b/common/include/villas/kernel/vfio_device.hpp @@ -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 @@ class Device { std::vector mappings; // libpci handle of the device - const kernel::pci::Device *pci_device; + const kernel::pci::PciDevice *pci_device; Logger log; }; diff --git a/common/include/villas/kernel/vfio_group.hpp b/common/include/villas/kernel/vfio_group.hpp index 7c4fca580..87b82901f 100644 --- a/common/include/villas/kernel/vfio_group.hpp +++ b/common/include/villas/kernel/vfio_group.hpp @@ -48,7 +48,7 @@ class Group { std::shared_ptr attachDevice(std::shared_ptr device); std::shared_ptr attachDevice(const std::string &name, - const kernel::pci::Device *pci_device = nullptr); + const kernel::pci::PciDevice *pci_device = nullptr); bool checkStatus(); void dump(); diff --git a/common/lib/kernel/devices/pci_device.cpp b/common/lib/kernel/devices/pci_device.cpp index baf385072..86f062114 100644 --- a/common/lib/kernel/devices/pci_device.cpp +++ b/common/lib/kernel/devices/pci_device.cpp @@ -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(id, slot)); + emplace_back(std::make_shared(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 Device::getRegions() const { +std::list PciDevice::getRegions() const { FILE *f; char sysfs[1024]; @@ -311,7 +311,7 @@ std::list 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(&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; diff --git a/common/lib/kernel/vfio_container.cpp b/common/lib/kernel/vfio_container.cpp index 7b67035f1..49d499a26 100644 --- a/common/lib/kernel/vfio_container.cpp +++ b/common/lib/kernel/vfio_container.cpp @@ -187,7 +187,7 @@ std::shared_ptr Container::attachDevice(const std::string &name, return device; } -std::shared_ptr Container::attachDevice(pci::Device &pdev) { +std::shared_ptr Container::attachDevice(pci::PciDevice &pdev) { int ret; char name[32], iommu_state[4]; static constexpr const char *kernelDriver = "vfio-pci"; diff --git a/common/lib/kernel/vfio_device.cpp b/common/lib/kernel/vfio_device.cpp index 160cff71d..601b4d47f 100644 --- a/common/lib/kernel/vfio_device.cpp +++ b/common/lib/kernel/vfio_device.cpp @@ -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")) { diff --git a/common/lib/kernel/vfio_group.cpp b/common/lib/kernel/vfio_group.cpp index 56591bb9f..7b01dea08 100644 --- a/common/lib/kernel/vfio_group.cpp +++ b/common/lib/kernel/vfio_group.cpp @@ -68,7 +68,7 @@ std::shared_ptr Group::attachDevice(std::shared_ptr device) { std::shared_ptr Group::attachDevice(const std::string &name, - const kernel::pci::Device *pci_device) { + const kernel::pci::PciDevice *pci_device) { auto device = std::make_shared(name, fd, pci_device); return attachDevice(device); } diff --git a/fpga/include/villas/fpga/pcie_card.hpp b/fpga/include/villas/fpga/pcie_card.hpp index d3ba2f54a..3aaaaf100 100644 --- a/fpga/include/villas/fpga/pcie_card.hpp +++ b/fpga/include/villas/fpga/pcie_card.hpp @@ -55,7 +55,7 @@ class PCIeCard : public Card { bool doReset; // Reset VILLASfpga during startup? int affinity; // Affinity for MSI interrupts - std::shared_ptr pdev; // PCI device handle + std::shared_ptr pdev; // PCI device handle protected: Logger getLogger() const { return villas::Log::get(name); } diff --git a/fpga/lib/pcie_card.cpp b/fpga/lib/pcie_card.cpp index f44026fd6..6a7f7b008 100644 --- a/fpga/lib/pcie_card.cpp +++ b/fpga/lib/pcie_card.cpp @@ -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 @@ -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); From a162f6ffc5477f5fa5fa7281b8afe29aee14f2fd Mon Sep 17 00:00:00 2001 From: Pascal Bauer Date: Wed, 14 Aug 2024 22:45:08 +0200 Subject: [PATCH 3/5] update codeowner Signed-off-by: Pascal Bauer --- CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CODEOWNERS b/CODEOWNERS index 4f88b8a27..2dec02cc1 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -35,5 +35,5 @@ fpga @n-eiling # VFIO related files /common/lib/kernel/pci.cpp @n-eiling /common/lib/kernel/vfi_*.cpp @n-eiling -/common/include/villas/kernel/devices/pci_device.hpp @n-eiling +/common/include/villas/kernel/devices/* @n-eiling /common/include/villas/kernel/vfio_*.hpp @n-eiling From df8c26c79da3c48deda243aa6cbc04d069a404c4 Mon Sep 17 00:00:00 2001 From: Pascal Bauer Date: Thu, 22 Aug 2024 14:17:13 +0200 Subject: [PATCH 4/5] refactor: rename DeviceList to PciDeviceList Signed-off-by: Pascal Bauer --- .../villas/kernel/devices/pci_device.hpp | 16 ++++++------- common/lib/kernel/devices/pci_device.cpp | 23 ++++++++++--------- fpga/lib/dma.cpp | 2 +- fpga/lib/pcie_card.cpp | 2 +- fpga/src/villas-fpga-ctrl.cpp | 2 +- fpga/src/villas-fpga-pipe.cpp | 2 +- fpga/tests/unit/fpga.cpp | 4 ++-- 7 files changed, 26 insertions(+), 25 deletions(-) diff --git a/common/include/villas/kernel/devices/pci_device.hpp b/common/include/villas/kernel/devices/pci_device.hpp index e71fa4ecc..3213fcd93 100644 --- a/common/include/villas/kernel/devices/pci_device.hpp +++ b/common/include/villas/kernel/devices/pci_device.hpp @@ -106,23 +106,23 @@ class PciDevice { std::ios_base::out) const; }; -class DeviceList : public std::list> { +class PciDeviceList : public std::list> { private: // Initialize Linux PCI handle. // // This search for all available PCI devices under /sys/bus/pci - DeviceList(); - DeviceList &operator=(const DeviceList &); - static DeviceList *instance; + PciDeviceList(); + PciDeviceList &operator=(const PciDeviceList &); + static PciDeviceList *instance; public: - static DeviceList *getInstance(); + static PciDeviceList *getInstance(); - DeviceList::value_type lookupDevice(const Slot &s); + PciDeviceList::value_type lookupDevice(const Slot &s); - DeviceList::value_type lookupDevice(const Id &i); + PciDeviceList::value_type lookupDevice(const Id &i); - DeviceList::value_type lookupDevice(const PciDevice &f); + PciDeviceList::value_type lookupDevice(const PciDevice &f); }; } // namespace pci diff --git a/common/lib/kernel/devices/pci_device.cpp b/common/lib/kernel/devices/pci_device.cpp index 86f062114..84748b161 100644 --- a/common/lib/kernel/devices/pci_device.cpp +++ b/common/lib/kernel/devices/pci_device.cpp @@ -25,16 +25,16 @@ using namespace villas::kernel::pci; #define PCI_BASE_ADDRESS_N(n) (PCI_BASE_ADDRESS_0 + sizeof(uint32_t) * (n)) -DeviceList *DeviceList::instance = nullptr; +PciDeviceList *PciDeviceList::instance = nullptr; -DeviceList *DeviceList::getInstance() { +PciDeviceList *PciDeviceList::getInstance() { if (instance == nullptr) { - instance = new DeviceList(); + instance = new PciDeviceList(); } return instance; }; -DeviceList::DeviceList() { +PciDeviceList::PciDeviceList() { struct dirent *e; DIR *dp; FILE *f; @@ -88,21 +88,22 @@ DeviceList::DeviceList() { closedir(dp); } -DeviceList::value_type DeviceList::lookupDevice(const Slot &s) { - return *std::find_if(begin(), end(), [s](const DeviceList::value_type &d) { +PciDeviceList::value_type PciDeviceList::lookupDevice(const Slot &s) { + return *std::find_if(begin(), end(), [s](const PciDeviceList::value_type &d) { return d->slot == s; }); } -DeviceList::value_type DeviceList::lookupDevice(const Id &i) { - return *std::find_if(begin(), end(), [i](const DeviceList::value_type &d) { +PciDeviceList::value_type PciDeviceList::lookupDevice(const Id &i) { + return *std::find_if(begin(), end(), [i](const PciDeviceList::value_type &d) { return d->id == i; }); } -DeviceList::value_type DeviceList::lookupDevice(const PciDevice &d) { - auto dev = std::find_if( - begin(), end(), [d](const DeviceList::value_type &e) { return *e == d; }); +PciDeviceList::value_type PciDeviceList::lookupDevice(const PciDevice &d) { + auto dev = + std::find_if(begin(), end(), + [d](const PciDeviceList::value_type &e) { return *e == d; }); return dev == end() ? value_type() : *dev; } diff --git a/fpga/lib/dma.cpp b/fpga/lib/dma.cpp index 309ac8d60..0a89ca8c5 100644 --- a/fpga/lib/dma.cpp +++ b/fpga/lib/dma.cpp @@ -21,7 +21,7 @@ using namespace villas; -static std::shared_ptr pciDevices; +static std::shared_ptr pciDevices; static auto logger = villas::Log::get("villasfpga_dma"); struct villasfpga_handle_t { diff --git a/fpga/lib/pcie_card.cpp b/fpga/lib/pcie_card.cpp index 6a7f7b008..eb51554d7 100644 --- a/fpga/lib/pcie_card.cpp +++ b/fpga/lib/pcie_card.cpp @@ -71,7 +71,7 @@ PCIeCardFactory::make(json_t *json_card, std::string card_name, filter.slot = kernel::pci::Slot(pci_slot); // Search for FPGA card - card->pdev = kernel::pci::DeviceList::getInstance()->lookupDevice(filter); + card->pdev = kernel::pci::PciDeviceList::getInstance()->lookupDevice(filter); if (!card->pdev) { logger->warn("Failed to find PCI device"); return nullptr; diff --git a/fpga/src/villas-fpga-ctrl.cpp b/fpga/src/villas-fpga-ctrl.cpp index 8cdd424d3..a58a9afb5 100644 --- a/fpga/src/villas-fpga-ctrl.cpp +++ b/fpga/src/villas-fpga-ctrl.cpp @@ -34,7 +34,7 @@ using namespace villas; -static std::shared_ptr pciDevices; +static std::shared_ptr pciDevices; static auto logger = villas::Log::get("ctrl"); void writeToDmaFromStdIn(std::shared_ptr dma) { diff --git a/fpga/src/villas-fpga-pipe.cpp b/fpga/src/villas-fpga-pipe.cpp index 66841ea61..0c0e9e79f 100644 --- a/fpga/src/villas-fpga-pipe.cpp +++ b/fpga/src/villas-fpga-pipe.cpp @@ -27,7 +27,7 @@ using namespace villas; -static std::shared_ptr pciDevices; +static std::shared_ptr pciDevices; static auto logger = villas::Log::get("streamer"); int main(int argc, char *argv[]) { diff --git a/fpga/tests/unit/fpga.cpp b/fpga/tests/unit/fpga.cpp index d6ad32478..ae096fda2 100644 --- a/fpga/tests/unit/fpga.cpp +++ b/fpga/tests/unit/fpga.cpp @@ -27,7 +27,7 @@ using namespace villas; -static kernel::pci::DeviceList *pciDevices; +static kernel::pci::PciDeviceList *pciDevices; FpgaState state; @@ -40,7 +40,7 @@ static void init() { plugin::registry->dump(); - pciDevices = kernel::pci::DeviceList::getInstance(); + pciDevices = kernel::pci::PciDeviceList::getInstance(); auto vfioContainer = std::make_shared(); From 38e1199b2834c340293e96f615b2e1132c8e7aed Mon Sep 17 00:00:00 2001 From: Pascal Bauer Date: Thu, 22 Aug 2024 14:37:22 +0200 Subject: [PATCH 5/5] Refactor: change namespace pci to devices Signed-off-by: Pascal Bauer --- common/include/villas/kernel/devices/pci_device.hpp | 4 ++-- common/include/villas/kernel/vfio_container.hpp | 2 +- common/include/villas/kernel/vfio_device.hpp | 4 ++-- common/include/villas/kernel/vfio_group.hpp | 2 +- common/lib/kernel/devices/pci_device.cpp | 2 +- common/lib/kernel/vfio_container.cpp | 2 +- common/lib/kernel/vfio_device.cpp | 2 +- common/lib/kernel/vfio_group.cpp | 2 +- fpga/include/villas/fpga/pcie_card.hpp | 2 +- fpga/lib/dma.cpp | 2 +- fpga/lib/pcie_card.cpp | 13 +++++++------ fpga/src/villas-fpga-ctrl.cpp | 2 +- fpga/src/villas-fpga-pipe.cpp | 2 +- fpga/tests/unit/fpga.cpp | 4 ++-- 14 files changed, 23 insertions(+), 22 deletions(-) diff --git a/common/include/villas/kernel/devices/pci_device.hpp b/common/include/villas/kernel/devices/pci_device.hpp index 3213fcd93..65794644b 100644 --- a/common/include/villas/kernel/devices/pci_device.hpp +++ b/common/include/villas/kernel/devices/pci_device.hpp @@ -17,7 +17,7 @@ namespace villas { namespace kernel { -namespace pci { +namespace devices { #define PCI_SLOT(devfn) (((devfn) >> 3) & 0x1f) #define PCI_FUNC(devfn) ((devfn) & 0x07) @@ -125,6 +125,6 @@ class PciDeviceList : public std::list> { PciDeviceList::value_type lookupDevice(const PciDevice &f); }; -} // namespace pci +} // namespace devices } // namespace kernel } // namespace villas diff --git a/common/include/villas/kernel/vfio_container.hpp b/common/include/villas/kernel/vfio_container.hpp index fedb36436..2165092da 100644 --- a/common/include/villas/kernel/vfio_container.hpp +++ b/common/include/villas/kernel/vfio_container.hpp @@ -49,7 +49,7 @@ class Container { std::shared_ptr getOrAttachGroup(int index); std::shared_ptr attachDevice(const std::string &name, int groupIndex); - std::shared_ptr attachDevice(pci::PciDevice &pdev); + std::shared_ptr attachDevice(devices::PciDevice &pdev); // Map VM to an IOVA, which is accessible by devices in the container // diff --git a/common/include/villas/kernel/vfio_device.hpp b/common/include/villas/kernel/vfio_device.hpp index a7805f6ad..fe9f8e3ef 100644 --- a/common/include/villas/kernel/vfio_device.hpp +++ b/common/include/villas/kernel/vfio_device.hpp @@ -29,7 +29,7 @@ namespace vfio { class Device { public: Device(const std::string &name, int groupFileDescriptor, - const kernel::pci::PciDevice *pci_device = nullptr); + const kernel::devices::PciDevice *pci_device = nullptr); ~Device(); // No copying allowed because we manage the vfio state in constructor and destructors @@ -89,7 +89,7 @@ class Device { std::vector mappings; // libpci handle of the device - const kernel::pci::PciDevice *pci_device; + const kernel::devices::PciDevice *pci_device; Logger log; }; diff --git a/common/include/villas/kernel/vfio_group.hpp b/common/include/villas/kernel/vfio_group.hpp index 87b82901f..5f990c46c 100644 --- a/common/include/villas/kernel/vfio_group.hpp +++ b/common/include/villas/kernel/vfio_group.hpp @@ -48,7 +48,7 @@ class Group { std::shared_ptr attachDevice(std::shared_ptr device); std::shared_ptr attachDevice(const std::string &name, - const kernel::pci::PciDevice *pci_device = nullptr); + const kernel::devices::PciDevice *pci_device = nullptr); bool checkStatus(); void dump(); diff --git a/common/lib/kernel/devices/pci_device.cpp b/common/lib/kernel/devices/pci_device.cpp index 84748b161..8d700ebfc 100644 --- a/common/lib/kernel/devices/pci_device.cpp +++ b/common/lib/kernel/devices/pci_device.cpp @@ -21,7 +21,7 @@ #include #include -using namespace villas::kernel::pci; +using namespace villas::kernel::devices; #define PCI_BASE_ADDRESS_N(n) (PCI_BASE_ADDRESS_0 + sizeof(uint32_t) * (n)) diff --git a/common/lib/kernel/vfio_container.cpp b/common/lib/kernel/vfio_container.cpp index 49d499a26..76923aa08 100644 --- a/common/lib/kernel/vfio_container.cpp +++ b/common/lib/kernel/vfio_container.cpp @@ -187,7 +187,7 @@ std::shared_ptr Container::attachDevice(const std::string &name, return device; } -std::shared_ptr Container::attachDevice(pci::PciDevice &pdev) { +std::shared_ptr Container::attachDevice(devices::PciDevice &pdev) { int ret; char name[32], iommu_state[4]; static constexpr const char *kernelDriver = "vfio-pci"; diff --git a/common/lib/kernel/vfio_device.cpp b/common/lib/kernel/vfio_device.cpp index 601b4d47f..ff70f3cb7 100644 --- a/common/lib/kernel/vfio_device.cpp +++ b/common/lib/kernel/vfio_device.cpp @@ -53,7 +53,7 @@ static const char *vfio_pci_irq_names[] = { }; Device::Device(const std::string &name, int groupFileDescriptor, - const kernel::pci::PciDevice *pci_device) + const kernel::devices::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")) { diff --git a/common/lib/kernel/vfio_group.cpp b/common/lib/kernel/vfio_group.cpp index 7b01dea08..512460c20 100644 --- a/common/lib/kernel/vfio_group.cpp +++ b/common/lib/kernel/vfio_group.cpp @@ -68,7 +68,7 @@ std::shared_ptr Group::attachDevice(std::shared_ptr device) { std::shared_ptr Group::attachDevice(const std::string &name, - const kernel::pci::PciDevice *pci_device) { + const kernel::devices::PciDevice *pci_device) { auto device = std::make_shared(name, fd, pci_device); return attachDevice(device); } diff --git a/fpga/include/villas/fpga/pcie_card.hpp b/fpga/include/villas/fpga/pcie_card.hpp index 3aaaaf100..aff1b23fb 100644 --- a/fpga/include/villas/fpga/pcie_card.hpp +++ b/fpga/include/villas/fpga/pcie_card.hpp @@ -55,7 +55,7 @@ class PCIeCard : public Card { bool doReset; // Reset VILLASfpga during startup? int affinity; // Affinity for MSI interrupts - std::shared_ptr pdev; // PCI device handle + std::shared_ptr pdev; // PCI device handle protected: Logger getLogger() const { return villas::Log::get(name); } diff --git a/fpga/lib/dma.cpp b/fpga/lib/dma.cpp index 0a89ca8c5..7ce10b2b5 100644 --- a/fpga/lib/dma.cpp +++ b/fpga/lib/dma.cpp @@ -21,7 +21,7 @@ using namespace villas; -static std::shared_ptr pciDevices; +static std::shared_ptr pciDevices; static auto logger = villas::Log::get("villasfpga_dma"); struct villasfpga_handle_t { diff --git a/fpga/lib/pcie_card.cpp b/fpga/lib/pcie_card.cpp index eb51554d7..7fc6ceb0a 100644 --- a/fpga/lib/pcie_card.cpp +++ b/fpga/lib/pcie_card.cpp @@ -24,8 +24,8 @@ using namespace villas::fpga; // Instantiate factory to register static PCIeCardFactory PCIeCardFactoryInstance; -static const kernel::pci::PciDevice - defaultFilter((kernel::pci::Id(FPGA_PCI_VID_XILINX, FPGA_PCI_PID_VFPGA))); +static const kernel::devices::PciDevice defaultFilter( + (kernel::devices::Id(FPGA_PCI_VID_XILINX, FPGA_PCI_PID_VFPGA))); std::shared_ptr PCIeCardFactory::make(json_t *json_card, std::string card_name, @@ -63,15 +63,16 @@ PCIeCardFactory::make(json_t *json_card, std::string card_name, card->doReset = do_reset != 0; card->polling = (polling != 0); - kernel::pci::PciDevice filter = defaultFilter; + kernel::devices::PciDevice filter = defaultFilter; if (pci_id) - filter.id = kernel::pci::Id(pci_id); + filter.id = kernel::devices::Id(pci_id); if (pci_slot) - filter.slot = kernel::pci::Slot(pci_slot); + filter.slot = kernel::devices::Slot(pci_slot); // Search for FPGA card - card->pdev = kernel::pci::PciDeviceList::getInstance()->lookupDevice(filter); + card->pdev = + kernel::devices::PciDeviceList::getInstance()->lookupDevice(filter); if (!card->pdev) { logger->warn("Failed to find PCI device"); return nullptr; diff --git a/fpga/src/villas-fpga-ctrl.cpp b/fpga/src/villas-fpga-ctrl.cpp index a58a9afb5..6232ac782 100644 --- a/fpga/src/villas-fpga-ctrl.cpp +++ b/fpga/src/villas-fpga-ctrl.cpp @@ -34,7 +34,7 @@ using namespace villas; -static std::shared_ptr pciDevices; +static std::shared_ptr pciDevices; static auto logger = villas::Log::get("ctrl"); void writeToDmaFromStdIn(std::shared_ptr dma) { diff --git a/fpga/src/villas-fpga-pipe.cpp b/fpga/src/villas-fpga-pipe.cpp index 0c0e9e79f..b059501c0 100644 --- a/fpga/src/villas-fpga-pipe.cpp +++ b/fpga/src/villas-fpga-pipe.cpp @@ -27,7 +27,7 @@ using namespace villas; -static std::shared_ptr pciDevices; +static std::shared_ptr pciDevices; static auto logger = villas::Log::get("streamer"); int main(int argc, char *argv[]) { diff --git a/fpga/tests/unit/fpga.cpp b/fpga/tests/unit/fpga.cpp index ae096fda2..587cc0264 100644 --- a/fpga/tests/unit/fpga.cpp +++ b/fpga/tests/unit/fpga.cpp @@ -27,7 +27,7 @@ using namespace villas; -static kernel::pci::PciDeviceList *pciDevices; +static kernel::devices::PciDeviceList *pciDevices; FpgaState state; @@ -40,7 +40,7 @@ static void init() { plugin::registry->dump(); - pciDevices = kernel::pci::PciDeviceList::getInstance(); + pciDevices = kernel::devices::PciDeviceList::getInstance(); auto vfioContainer = std::make_shared();