Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Feature/vfio platform #88

Draft
wants to merge 93 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
61be22f
card draft
IgnoreWarnings Feb 9, 2023
7ac4423
investigation
IgnoreWarnings Feb 9, 2023
3072fb3
improved investigation
IgnoreWarnings Feb 9, 2023
c44fc78
added Test
IgnoreWarnings Feb 9, 2023
6a7113f
added comment
IgnoreWarnings Feb 10, 2023
1b9a059
added format file to gitignore
IgnoreWarnings Feb 10, 2023
52fcc64
change submodule branch
IgnoreWarnings Feb 10, 2023
e92c825
added warnings coreguidlines
IgnoreWarnings Feb 10, 2023
7242dea
new vfio test
IgnoreWarnings Feb 24, 2023
d055141
fixed syntax
IgnoreWarnings Feb 24, 2023
9e718d1
revert pipe
IgnoreWarnings Feb 24, 2023
0162b3f
platform test to own file
IgnoreWarnings Feb 24, 2023
cd6ce67
added missing var
IgnoreWarnings Mar 10, 2023
48cabfe
added vfio bind script
IgnoreWarnings Mar 10, 2023
05ef8d8
removed faulty error handling
IgnoreWarnings Mar 10, 2023
dd36342
changed order
IgnoreWarnings Mar 14, 2023
70f6aca
add vfioDevice
IgnoreWarnings Mar 14, 2023
cf7624e
changed method to attachDevice
IgnoreWarnings Mar 14, 2023
adb870e
manual approach
IgnoreWarnings Mar 14, 2023
af56313
added platform factory
IgnoreWarnings Mar 23, 2023
57a519a
update gitignore
IgnoreWarnings Mar 30, 2023
5adf891
moved platform test to target
IgnoreWarnings Apr 2, 2023
9d1a1c4
read write
IgnoreWarnings Apr 11, 2023
648b56d
moved members back to parent class
Apr 20, 2023
be9ddc2
fixe platform make
Apr 21, 2023
2179139
add zynq ip
Jul 20, 2023
0a082de
add zynq to init order
Jul 20, 2023
28f7133
set local var
Jul 20, 2023
d90c983
set log level
Jul 20, 2023
78741d6
move connect to constructor
Aug 9, 2023
1e16011
replace list with vec
Sep 5, 2023
b6c9ad1
fix debug print message
Sep 5, 2023
f847775
remove comments and refactor
Sep 5, 2023
e5226e2
new mapping strategy per vfio device
Sep 5, 2023
db34fa3
update submodule common
Sep 5, 2023
0798ac4
update submodule
Sep 5, 2023
e438553
move attribute vfio device to pcie_card
Sep 13, 2023
8a4601f
move edge production from ip zynwq to platform card
Sep 13, 2023
fc93437
move print to graph
Sep 13, 2023
9f8b198
warnings treated as warnings
Sep 13, 2023
99615cc
change submodule branch
Sep 20, 2023
367438c
load module
Sep 27, 2023
afd7c13
change edge name
Oct 10, 2023
a3f9f96
hardcoded edges
Oct 12, 2023
1dc821c
fix mem size
Oct 12, 2023
9b66879
add addrSpace Name Dev to host
Oct 26, 2023
5effd1b
script to bind devices
Nov 7, 2023
28551f6
remove debug message
Nov 7, 2023
45b9ee2
change fpga id
Nov 7, 2023
f4f07b1
change card name
Nov 7, 2023
48d9368
module loading as parameter
Nov 7, 2023
af20f79
draft: auto generate edges
Nov 9, 2023
00b9cfd
add copyright
Nov 9, 2023
33a1f21
change edge name
Nov 9, 2023
6bdc22f
override mapMemoryBlock
Nov 15, 2023
b83f5ef
update gitignore
Nov 21, 2023
93d9203
remove comment
Nov 21, 2023
4e10e2f
make facotry use card class
Dec 6, 2023
49350f8
add parser class
Dec 6, 2023
5d110c4
fix missing include guard
Dec 6, 2023
dbab8c9
rename card parser
Dec 6, 2023
f1861ef
add ip loader class
Dec 6, 2023
d352175
rename imports
Dec 6, 2023
febbbb0
move vfio ip connection to method
Dec 7, 2023
2161839
keep hardcoded connections
Dec 7, 2023
b220719
device tree name to value
Dec 11, 2023
38eba77
launch platform bin
Dec 12, 2023
fa0fe31
fix binding script
Dec 13, 2023
fd6402d
new write test
Dec 13, 2023
898c0f2
split device tree name
Jan 11, 2024
dff94e2
fix memsize
Jan 11, 2024
991d88a
git ignore: fix cache folder
Jan 11, 2024
957378e
fix rebase
Jan 24, 2024
67605ec
add virtual to IntrerruptController methods
Feb 1, 2024
0fbf5a0
add Interrupt Controller for Platform
Feb 1, 2024
e0c147c
add default Interrupt Controller to dma
Feb 1, 2024
877fd5f
fix interrupt number
Feb 1, 2024
835928e
fix interrupts
Feb 1, 2024
32db7d9
move var to branch where it is needed
Feb 1, 2024
7cfeaad
update read and write from std
Feb 1, 2024
1e218d1
make interrupt controller properties protected
Feb 15, 2024
dcd4b33
override intc init
Feb 15, 2024
bd8d458
fix init intc
Feb 15, 2024
fd9c8d1
implement efds in platform_intc
Feb 15, 2024
49b98ad
fix main
Feb 15, 2024
5dfe9b4
fix double init
Feb 15, 2024
c2822f7
change loglevel trace
Feb 15, 2024
27ada7f
git: remove tracked cache files
Feb 21, 2024
a0c97d4
removed dma hardcoded position
Feb 22, 2024
7c7cc00
remove unused code
Feb 22, 2024
5063fe3
fix addrSpaceIdToHost
Feb 28, 2024
a34814b
optimize condition
Feb 28, 2024
3a7f670
add translation from SG
Feb 29, 2024
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ build/
*.so
*.user
graph.dot

.clang-format
.cache/
miob/
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ test:cppcheck:
--error-exitcode=1
--quiet
--inline-suppr
--enable=warning,performance,portability,information,missingInclude
--enable=cppcoreguidelines,warning,performance,portability,information,missingInclude
--std=c++11
--suppress=noValidConfiguration
-I include
Expand Down
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/src/villas-fpga-ctrl",
"program": "${workspaceFolder}/build/src/platform",
"args": [
"-c", "${workspaceFolder}/etc/fpgas.json", "--connect", "\"2<->stdout\""
],
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)

# Several CMake settings/defaults
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")

if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
set(TOPLEVEL_PROJECT ON)
Expand Down
2 changes: 1 addition & 1 deletion common
2 changes: 1 addition & 1 deletion etc/fpgas.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"fpgas": {
"vc707": {
"zcu106": {
"id": "10ee:7021",
"slot": "0000:88:00.0",
"do_reset": true,
Expand Down
7 changes: 4 additions & 3 deletions include/villas/fpga/card.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class Card
{
public:
bool polling;

std::string name; // The name of the FPGA card
bool doReset; // Reset VILLASfpga during startup?
int affinity; // Affinity for MSI interrupts
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 All @@ -52,6 +52,7 @@ class Card
std::map<MemoryManager::AddressSpaceId, std::shared_ptr<MemoryBlock>> memoryBlocksMapped;

Logger logger;

};

} // namespace fpga
Expand Down
42 changes: 42 additions & 0 deletions include/villas/fpga/card_parser.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once

#include "villas/exceptions.hpp"
#include "villas/log.hpp"
#include <jansson.h>
#include <spdlog/logger.h>

class CardParser {
public:
std::shared_ptr<spdlog::logger> logger;

json_t *json_ips = nullptr;
json_t *json_paths = nullptr;
const char *pci_slot = nullptr;
const char *pci_id = nullptr;
int do_reset = 0;
int affinity = 0;
int polling = 0;
json_t *devices = nullptr;
std::vector<std::string> device_names;

CardParser(json_t *json_card) : logger(villas::logging.get("CardParser")) {
json_error_t err;
int ret = json_unpack_ex(
json_card, &err, 0,
"{ s: o, s?: i, s?: b, s?: s, s?: s, s?: b, s?: o, s?: o }", "ips",
&json_ips, "affinity", &affinity, "do_reset", &do_reset, "slot",
&pci_slot, "id", &pci_id, "polling", &polling, "paths", &json_paths,
"devices", &devices);

if (ret != 0)
throw villas::ConfigError(json_card, err, "", "Failed to parse card");

// devices array parsing
size_t index;
json_t *value;
json_array_foreach(devices, index, value) {
auto str = json_string_value(value);
device_names.push_back(str);
}
}
};
44 changes: 44 additions & 0 deletions include/villas/fpga/ip_loader.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#pragma once

#include "villas/exceptions.hpp"
#include "villas/log.hpp"
#include <filesystem>
#include <jansson.h>
#include <spdlog/logger.h>

using villas::ConfigError;

class IpLoader {
public:
std::shared_ptr<spdlog::logger> logger;


IpLoader(json_t* json_ips, const std::filesystem::path& searchPath): logger(villas::logging.get("IpParser")) {
// Load IPs from a separate json file
if (!json_is_string(json_ips)) {
logger->debug("FPGA IP cores config item is not a string.");
throw ConfigError(json_ips, "node-config-fpga-ips",
"FPGA IP cores config item is not a string.");
}
if (!searchPath.empty()) {
std::filesystem::path json_ips_path =
searchPath / json_string_value(json_ips);
logger->debug("searching for FPGA IP cors config at {}", json_ips_path);
json_ips = json_load_file(json_ips_path.c_str(), 0, nullptr);
}
if (json_ips == nullptr) {
json_ips =
json_load_file(json_string_value(json_ips), 0, nullptr);
logger->debug("searching for FPGA IP cors config at {}",
json_string_value(json_ips));
if (json_ips == nullptr) {
throw ConfigError(json_ips, "node-config-fpga-ips",
"Failed to find FPGA IP cores config");
}
}

if (not json_is_object(json_ips))
throw ConfigError(json_ips, "node-config-fpga-ips",
"FPGA IP core list must be an object!");
}
};
14 changes: 7 additions & 7 deletions include/villas/fpga/ips/intc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,25 @@ class InterruptController : public Core {
virtual
bool init() override;

bool enableInterrupt(IrqMaskType mask, bool polling);
bool enableInterrupt(IrqPort irq, bool polling)
virtual bool enableInterrupt(IrqMaskType mask, bool polling);
virtual bool enableInterrupt(IrqPort irq, bool polling)
{
return enableInterrupt(1 << irq.num, polling);
}

bool disableInterrupt(IrqMaskType mask);
bool disableInterrupt(IrqPort irq)
virtual bool disableInterrupt(IrqMaskType mask);
virtual bool disableInterrupt(IrqPort irq)
{
return disableInterrupt(1 << irq.num);
}

int waitForInterrupt(int irq);
int waitForInterrupt(IrqPort irq)
virtual int waitForInterrupt(int irq);
virtual int waitForInterrupt(IrqPort irq)
{
return waitForInterrupt(irq.num);
}

private:
protected:

static constexpr char registerMemory[] = "reg0";

Expand Down
13 changes: 13 additions & 0 deletions include/villas/fpga/ips/platform_intc.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <villas/fpga/ips/intc.hpp>

class PlatformInterruptController
: public villas::fpga::ip::InterruptController {
public:
bool init() override;

bool enableInterrupt(InterruptController::IrqMaskType mask,
bool polling) override;
bool enableInterrupt(IrqPort irq, bool polling) override;
};
78 changes: 78 additions & 0 deletions include/villas/fpga/ips/zynq.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/** Zynq VFIO connector node
*
* Author: Pascal Bauer <[email protected]>
* SPDX-FileCopyrightText: 2017 Steffen Vogel <[email protected]>
* SPDX-License-Identifier: Apache-2.0
*********************************************************************************/

#pragma once

#include <xilinx/xaxis_switch.h>

#include <villas/fpga/node.hpp>

namespace villas {
namespace fpga {
namespace ip {

class Zynq : public Core {
public:
friend class ZynqFactory;

virtual
bool init() override;

private:
static constexpr char axiInterface[] = "M_AXI";
static constexpr char pcieMemory[] = "BAR0";

struct AxiBar {
uintptr_t base;
size_t size;
uintptr_t translation;
};

struct PciBar {
uintptr_t translation;
};

std::map<std::string, AxiBar> axiToPcieTranslations;
std::map<std::string, PciBar> pcieToAxiTranslations;
};

class ZynqFactory : CoreFactory {

public:
virtual
std::string getName() const
{
return "pcie";
}

virtual
std::string getDescription() const
{
return "Custom platform vfio connector";
}

private:
virtual
Vlnv getCompatibleVlnv() const
{
return Vlnv("xilinx.com:ip:zynq_ultra_ps_e:");
}

// Create a concrete IP instance
Core* make() const
{
return new Zynq;
};

protected:
virtual
void parse(Core &, json_t *) override;
};

} /* namespace ip */
} /* namespace fpga */
} /* namespace villas */
14 changes: 8 additions & 6 deletions include/villas/fpga/pcie_card.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ class PCIeCard : public Card {
{ }

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::vfio::Device> vfioDevice; //? Only used by intc

std::shared_ptr<kernel::pci::Device> pdev; // PCI device handle

protected:
Logger getLogger() const { return villas::logging.get(name); }
protected:
Logger
getLogger() const
{
return villas::logging.get(name);
}
};

class PCIeCardFactory : public plugin::Plugin {
Expand Down
44 changes: 44 additions & 0 deletions include/villas/fpga/platform_card.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Author: Pascal Henry Bauer <[email protected]>
* Based on the work of: Steffen Vogel <[email protected]> and Daniel Krebs <[email protected]>
*
* SPDX-FileCopyrightText: 2017 Institute for Automation of Complex Power Systems, EONERC
* SPDX-License-Identifier: Apache-2.0
*********************************************************************************/

#pragma once

#include <villas/fpga/card.hpp>
#include <filesystem>
#include <vector>

namespace villas {
namespace fpga {

class PlatformCard : public Card
{
public:
PlatformCard(std::shared_ptr<kernel::vfio::Container> vfioContainer,
std::vector<std::string> device_names);

~PlatformCard(){};

std::vector<std::shared_ptr<kernel::vfio::Device>> devices;

void connectVFIOtoIPS();
bool mapMemoryBlock(const std::shared_ptr<MemoryBlock> block) override;

private:

};

class PlatformCardFactory
{
public:
static std::list<std::shared_ptr<Card>> make(json_t *json,
std::shared_ptr<kernel::vfio::Container> vc,
const std::filesystem::path& searchPath);
};

} /* namespace fpga */
} /* namespace villas */
3 changes: 3 additions & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set(SOURCES
vlnv.cpp
card.cpp
pcie_card.cpp
platform_card.cpp
core.cpp
node.cpp
utils.cpp
Expand All @@ -23,10 +24,12 @@ set(SOURCES
ips/gpio.cpp
ips/intc.cpp
ips/pcie.cpp
ips/platform_intc.cpp
ips/rtds.cpp
ips/switch.cpp
ips/timer.cpp
ips/i2c.cpp
ips/zynq.cpp

ips/rtds2gpu/rtds2gpu.cpp
ips/rtds2gpu/xrtds2gpu.c
Expand Down
Loading