Skip to content

Commit

Permalink
refactor: rename DeviceList to PciDeviceList
Browse files Browse the repository at this point in the history
Signed-off-by: Pascal Bauer <[email protected]>
  • Loading branch information
IgnoreWarnings authored and n-eiling committed Aug 29, 2024
1 parent a162f6f commit df8c26c
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 25 deletions.
16 changes: 8 additions & 8 deletions common/include/villas/kernel/devices/pci_device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,23 +106,23 @@ class PciDevice {
std::ios_base::out) const;
};

class DeviceList : public std::list<std::shared_ptr<PciDevice>> {
class PciDeviceList : public std::list<std::shared_ptr<PciDevice>> {
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
Expand Down
23 changes: 12 additions & 11 deletions common/lib/kernel/devices/pci_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion fpga/lib/dma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

using namespace villas;

static std::shared_ptr<kernel::pci::DeviceList> pciDevices;
static std::shared_ptr<kernel::pci::PciDeviceList> pciDevices;
static auto logger = villas::Log::get("villasfpga_dma");

struct villasfpga_handle_t {
Expand Down
2 changes: 1 addition & 1 deletion fpga/lib/pcie_card.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion fpga/src/villas-fpga-ctrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

using namespace villas;

static std::shared_ptr<kernel::pci::DeviceList> pciDevices;
static std::shared_ptr<kernel::pci::PciDeviceList> pciDevices;
static auto logger = villas::Log::get("ctrl");

void writeToDmaFromStdIn(std::shared_ptr<villas::fpga::ip::Dma> dma) {
Expand Down
2 changes: 1 addition & 1 deletion fpga/src/villas-fpga-pipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

using namespace villas;

static std::shared_ptr<kernel::pci::DeviceList> pciDevices;
static std::shared_ptr<kernel::pci::PciDeviceList> pciDevices;
static auto logger = villas::Log::get("streamer");

int main(int argc, char *argv[]) {
Expand Down
4 changes: 2 additions & 2 deletions fpga/tests/unit/fpga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

using namespace villas;

static kernel::pci::DeviceList *pciDevices;
static kernel::pci::PciDeviceList *pciDevices;

FpgaState state;

Expand All @@ -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<kernel::vfio::Container>();

Expand Down

0 comments on commit df8c26c

Please sign in to comment.