Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move singular vfio device requirement to PCIeCard #867

Merged
merged 1 commit into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion fpga/include/villas/fpga/card.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class Card {

std::string name; // The name of the FPGA card
std::shared_ptr<kernel::vfio::Container> vfioContainer;
std::shared_ptr<kernel::vfio::Device> vfioDevice;

// Slave address space ID to access the PCIe address space from the
// FPGA
Expand Down
3 changes: 3 additions & 0 deletions fpga/include/villas/fpga/ips/intc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <xilinx/xintc.h>

#include <villas/fpga/core.hpp>
#include <villas/kernel/vfio_device.hpp>

namespace villas {
namespace fpga {
Expand Down Expand Up @@ -40,6 +41,8 @@ class InterruptController : public Core {
private:
static constexpr char registerMemory[] = "reg0";

std::shared_ptr<villas::kernel::vfio::Device> vfioDevice = nullptr;

std::list<MemoryBlockName> getMemoryBlocks() const {
return {registerMemory};
}
Expand Down
1 change: 1 addition & 0 deletions fpga/include/villas/fpga/pcie_card.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class PCIeCard : public Card {
int affinity; // Affinity for MSI interrupts

std::shared_ptr<kernel::devices::PciDevice> pdev; // PCI device handle
std::shared_ptr<kernel::vfio::Device> vfioDevice;

protected:
Logger getLogger() const { return villas::Log::get(name); }
Expand Down
9 changes: 6 additions & 3 deletions fpga/lib/ips/intc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,20 @@ using namespace villas::fpga::ip;
InterruptController::~InterruptController() {}

bool InterruptController::stop() {
return card->vfioDevice->pciMsiDeinit(this->efds) > 0;
return this->vfioDevice->pciMsiDeinit(this->efds) > 0;
}

bool InterruptController::init() {
const uintptr_t base = getBaseAddr(registerMemory);

num_irqs = card->vfioDevice->pciMsiInit(efds);
PCIeCard *pciecard = dynamic_cast<PCIeCard *>(card);
this->vfioDevice = pciecard->vfioDevice;

num_irqs = this->vfioDevice->pciMsiInit(efds);
if (num_irqs < 0)
return false;

if (not card->vfioDevice->pciMsiFind(nos)) {
if (not this->vfioDevice->pciMsiFind(nos)) {
return false;
}

Expand Down
6 changes: 4 additions & 2 deletions fpga/lib/ips/pcie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@ bool AxiPciExpressBridge::init() {
// address space we can use for translation -> error
card->addrSpaceIdHostToDevice = busMasterInterfaces.at(getAxiInterfaceName());

PCIeCard *pciecard = dynamic_cast<PCIeCard *>(card);

// Map PCIe BAR0 via VFIO
const void *bar0_mapped =
card->vfioDevice->regionMap(VFIO_PCI_BAR0_REGION_INDEX);
pciecard->vfioDevice->regionMap(VFIO_PCI_BAR0_REGION_INDEX);
if (bar0_mapped == MAP_FAILED) {
logger->error("Failed to mmap() BAR0");
return false;
}

// Determine size of BAR0 region
const size_t bar0_size =
card->vfioDevice->regionGetSize(VFIO_PCI_BAR0_REGION_INDEX);
pciecard->vfioDevice->regionGetSize(VFIO_PCI_BAR0_REGION_INDEX);

// Create a mapping from process address space to the FPGA card via vfio
mm.createMapping(reinterpret_cast<uintptr_t>(bar0_mapped), 0, bar0_size,
Expand Down
4 changes: 3 additions & 1 deletion lib/nodes/fpga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <villas/fpga/ips/dino.hpp>
#include <villas/fpga/ips/register.hpp>
#include <villas/fpga/ips/switch.hpp>
#include <villas/fpga/pcie_card.hpp>
#include <villas/fpga/utils.hpp>

using namespace villas;
Expand Down Expand Up @@ -367,7 +368,8 @@ int FpgaNode::slowWrite(Sample *smps[], unsigned cnt) {

std::vector<int> FpgaNode::getPollFDs() {
if (!lowLatencyMode && card && !card->polling) {
return card->vfioDevice->getEventfdList();
std::shared_ptr<PCIeCard> pciecard = std::dynamic_pointer_cast<PCIeCard>(card);
return pciecard->vfioDevice->getEventfdList();
} else {
return {};
}
Expand Down