Skip to content

Commit 7f79208

Browse files
IgnoreWarningsn-eiling
authored andcommitted
refactor: move single vfio device requirement to pciecard.
Signed-off-by: Pascal Bauer <[email protected]>
1 parent 3bcf557 commit 7f79208

File tree

6 files changed

+17
-7
lines changed

6 files changed

+17
-7
lines changed

fpga/include/villas/fpga/card.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class Card {
2525

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

3029
// Slave address space ID to access the PCIe address space from the
3130
// FPGA

fpga/include/villas/fpga/ips/intc.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <xilinx/xintc.h>
1212

1313
#include <villas/fpga/core.hpp>
14+
#include <villas/kernel/vfio_device.hpp>
1415

1516
namespace villas {
1617
namespace fpga {
@@ -40,6 +41,8 @@ class InterruptController : public Core {
4041
private:
4142
static constexpr char registerMemory[] = "reg0";
4243

44+
std::shared_ptr<villas::kernel::vfio::Device> vfioDevice = nullptr;
45+
4346
std::list<MemoryBlockName> getMemoryBlocks() const {
4447
return {registerMemory};
4548
}

fpga/include/villas/fpga/pcie_card.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class PCIeCard : public Card {
5656
int affinity; // Affinity for MSI interrupts
5757

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

6061
protected:
6162
Logger getLogger() const { return villas::Log::get(name); }

fpga/lib/ips/intc.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,20 @@ using namespace villas::fpga::ip;
2222
InterruptController::~InterruptController() {}
2323

2424
bool InterruptController::stop() {
25-
return card->vfioDevice->pciMsiDeinit(this->efds) > 0;
25+
return this->vfioDevice->pciMsiDeinit(this->efds) > 0;
2626
}
2727

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

31-
num_irqs = card->vfioDevice->pciMsiInit(efds);
31+
PCIeCard *pciecard = dynamic_cast<PCIeCard *>(card);
32+
this->vfioDevice = pciecard->vfioDevice;
33+
34+
num_irqs = this->vfioDevice->pciMsiInit(efds);
3235
if (num_irqs < 0)
3336
return false;
3437

35-
if (not card->vfioDevice->pciMsiFind(nos)) {
38+
if (not this->vfioDevice->pciMsiFind(nos)) {
3639
return false;
3740
}
3841

fpga/lib/ips/pcie.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,19 @@ bool AxiPciExpressBridge::init() {
2424
// address space we can use for translation -> error
2525
card->addrSpaceIdHostToDevice = busMasterInterfaces.at(getAxiInterfaceName());
2626

27+
PCIeCard *pciecard = dynamic_cast<PCIeCard *>(card);
28+
2729
// Map PCIe BAR0 via VFIO
2830
const void *bar0_mapped =
29-
card->vfioDevice->regionMap(VFIO_PCI_BAR0_REGION_INDEX);
31+
pciecard->vfioDevice->regionMap(VFIO_PCI_BAR0_REGION_INDEX);
3032
if (bar0_mapped == MAP_FAILED) {
3133
logger->error("Failed to mmap() BAR0");
3234
return false;
3335
}
3436

3537
// Determine size of BAR0 region
3638
const size_t bar0_size =
37-
card->vfioDevice->regionGetSize(VFIO_PCI_BAR0_REGION_INDEX);
39+
pciecard->vfioDevice->regionGetSize(VFIO_PCI_BAR0_REGION_INDEX);
3840

3941
// Create a mapping from process address space to the FPGA card via vfio
4042
mm.createMapping(reinterpret_cast<uintptr_t>(bar0_mapped), 0, bar0_size,

lib/nodes/fpga.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <villas/fpga/ips/dino.hpp>
2424
#include <villas/fpga/ips/register.hpp>
2525
#include <villas/fpga/ips/switch.hpp>
26+
#include <villas/fpga/pcie_card.hpp>
2627
#include <villas/fpga/utils.hpp>
2728

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

368369
std::vector<int> FpgaNode::getPollFDs() {
369370
if (!lowLatencyMode && card && !card->polling) {
370-
return card->vfioDevice->getEventfdList();
371+
std::shared_ptr<PCIeCard> pciecard = std::dynamic_pointer_cast<PCIeCard>(card);
372+
return pciecard->vfioDevice->getEventfdList();
371373
} else {
372374
return {};
373375
}

0 commit comments

Comments
 (0)