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

Add support for FPGAs connected via the vfio-platform driver #783

Draft
wants to merge 99 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
babe80f
add device interface
IgnoreWarnings Aug 24, 2024
d312e37
add driver interface
IgnoreWarnings Aug 24, 2024
adeaa9d
add generic driver
IgnoreWarnings Aug 24, 2024
dca4d4c
add utils
IgnoreWarnings Aug 24, 2024
9d6b81b
add platform device
IgnoreWarnings Aug 24, 2024
d65910a
add IpDevice
IgnoreWarnings Aug 24, 2024
abc56a9
add new classes to cmake
IgnoreWarnings Aug 24, 2024
9b1524f
fix generic driver header
IgnoreWarnings Aug 24, 2024
10e6aee
cmake move drivers to linux section
IgnoreWarnings Aug 30, 2024
ce8aa3f
remove duplicate public
IgnoreWarnings Aug 30, 2024
2357122
delete default comnstructor
IgnoreWarnings Aug 30, 2024
0c270c5
formatting
IgnoreWarnings Aug 30, 2024
46065f3
use filename()
IgnoreWarnings Aug 30, 2024
6e7c9c6
cleanup code
IgnoreWarnings Sep 4, 2024
80d7942
Refactor: move device utility functions to villas util
IgnoreWarnings Sep 23, 2024
9ac5cd6
update device description
IgnoreWarnings Sep 23, 2024
1f9e5c4
format comment
IgnoreWarnings Sep 24, 2024
ffbdcf5
Update comments
IgnoreWarnings Sep 24, 2024
eeb56f4
remove comment
IgnoreWarnings Sep 24, 2024
1f19e42
Use villas exception
IgnoreWarnings Sep 25, 2024
43e267a
remove dead header
IgnoreWarnings Oct 6, 2024
270acd0
Update comment
IgnoreWarnings Oct 9, 2024
87a2372
Use std::filestytem
IgnoreWarnings Oct 9, 2024
ff00747
fix read names in directory method
IgnoreWarnings Oct 9, 2024
486877e
add . at end of comment
IgnoreWarnings Oct 10, 2024
5a48e38
edit driver comment
IgnoreWarnings Oct 11, 2024
ca2715d
rename GenericDriver to LinuxDriver
IgnoreWarnings Oct 11, 2024
e945a9e
rename generic_driver to linux_driver
IgnoreWarnings Oct 11, 2024
51eaea3
update driver comment
IgnoreWarnings Oct 11, 2024
fadb14c
initial commit
IgnoreWarnings Aug 23, 2024
ae3ab18
Driver Interface
IgnoreWarnings Aug 23, 2024
3659225
fix broken includes
IgnoreWarnings Aug 23, 2024
0400f19
remove unused code
IgnoreWarnings Aug 23, 2024
1f9d7d5
rename Platform driver to GenericDriver
IgnoreWarnings Aug 23, 2024
b229d7c
inherit from device interface
IgnoreWarnings Aug 23, 2024
ec3da8d
implement driver()
IgnoreWarnings Aug 23, 2024
4772060
implement iommu_group
IgnoreWarnings Aug 23, 2024
2bfccaa
implement name
IgnoreWarnings Aug 23, 2024
56b2d69
removed unused code
IgnoreWarnings Aug 23, 2024
cac2e89
format
IgnoreWarnings Aug 24, 2024
d054b9a
implement override_path
IgnoreWarnings Aug 24, 2024
8e21811
implement path
IgnoreWarnings Aug 24, 2024
97d35e4
format
IgnoreWarnings Aug 24, 2024
04f8c92
implement probe
IgnoreWarnings Aug 24, 2024
6f6fe52
remove semicolon
IgnoreWarnings Aug 24, 2024
795a565
add include
IgnoreWarnings Aug 24, 2024
09eac47
adjust to new interface
IgnoreWarnings Aug 24, 2024
45f3533
update namespace
IgnoreWarnings Oct 6, 2024
2b98171
adjust utils to refactor
IgnoreWarnings Oct 6, 2024
a41e30e
apply driver refactor
IgnoreWarnings Oct 11, 2024
9847b79
add miob conf
IgnoreWarnings Aug 26, 2024
949f904
update gitignore
IgnoreWarnings Aug 26, 2024
cbefe28
add zynq ip
IgnoreWarnings Aug 26, 2024
a95dbea
add bitstreams
IgnoreWarnings Aug 26, 2024
b38096e
add platform interrupt
IgnoreWarnings Aug 26, 2024
95dc3b1
add card parser
IgnoreWarnings Aug 26, 2024
fafbd37
add json parser
IgnoreWarnings Aug 26, 2024
15075d5
add connect to vfio
IgnoreWarnings Aug 26, 2024
ec228c4
add to vfio pcie
IgnoreWarnings Aug 26, 2024
e8e578e
add ip_device reader
IgnoreWarnings Aug 26, 2024
43ab911
add device ip matcher
IgnoreWarnings Aug 26, 2024
66f5001
add platform card
IgnoreWarnings Aug 26, 2024
b654e0f
add to cmake
IgnoreWarnings Aug 26, 2024
096a0cf
add to utils
IgnoreWarnings Aug 26, 2024
50b3368
adjust to driver rework
IgnoreWarnings Aug 26, 2024
639cff5
change copy to direct initialization
IgnoreWarnings Aug 30, 2024
0fc165e
update comment
IgnoreWarnings Sep 6, 2024
27dc6f3
refactor ip_device_reader
IgnoreWarnings Sep 6, 2024
e73f536
remove blank line
IgnoreWarnings Sep 6, 2024
037e0f8
refactor
IgnoreWarnings Sep 6, 2024
1cda643
format file
IgnoreWarnings Sep 20, 2024
cc325d3
platform irq draft
IgnoreWarnings Sep 20, 2024
14a8c67
change to absolute path
IgnoreWarnings Sep 20, 2024
aee7786
platform intc
IgnoreWarnings Sep 20, 2024
48fbfbe
addIrq method
IgnoreWarnings Sep 20, 2024
bca8ec0
add ignored ips
IgnoreWarnings Sep 25, 2024
7bcc8ec
Format comment
IgnoreWarnings Sep 25, 2024
fd54ce7
fix namespace
IgnoreWarnings Oct 6, 2024
0b4a72d
fix header
IgnoreWarnings Oct 6, 2024
b94c6cd
change zynq name
IgnoreWarnings Oct 6, 2024
4752b08
fix addrSpaceIdToHost
IgnoreWarnings Oct 10, 2024
f27fc62
apply refactor
IgnoreWarnings Oct 21, 2024
2514bc2
remove dead code
IgnoreWarnings Oct 23, 2024
0766e83
remove dead code
IgnoreWarnings Oct 23, 2024
ad4f5f0
update description
IgnoreWarnings Oct 23, 2024
7dff004
remove unused members
IgnoreWarnings Oct 23, 2024
fbae427
use instance name
IgnoreWarnings Oct 23, 2024
e7484d0
add todo
IgnoreWarnings Oct 30, 2024
dfa68d3
try to use aurora
IgnoreWarnings Oct 30, 2024
dc9a097
add lookup ips
IgnoreWarnings Oct 31, 2024
d41726c
change codebasepath
IgnoreWarnings Nov 4, 2024
6af126b
fix lookup ips
IgnoreWarnings Nov 4, 2024
302fd63
fix irq number
IgnoreWarnings Nov 14, 2024
2ca7c29
add interrupt description
IgnoreWarnings Nov 14, 2024
15c3a88
add get id method
IgnoreWarnings Nov 14, 2024
87e1e7a
uncomment ignored ips
IgnoreWarnings Nov 14, 2024
27e8866
remove unused imports
IgnoreWarnings Nov 14, 2024
9b8300a
fix comment
IgnoreWarnings Nov 14, 2024
482df53
remove exception
IgnoreWarnings Nov 14, 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ compile_commands.json

python/dist/
python/.eggs/
python/villas/node/villas_pb2.py

# YouCompleteMe
.ycm_extra_conf.py
Expand Down
33 changes: 33 additions & 0 deletions common/include/villas/kernel/devices/device.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* Interface for Linux/Unix devices.
*
* Author: Pascal Bauer <[email protected]>
*
* SPDX-FileCopyrightText: 2023-2024 Pascal Bauer <[email protected]>
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <filesystem>
#include <optional>
#include <villas/kernel/devices/driver.hpp>

namespace villas {
namespace kernel {
namespace devices {

class Device {
public:
virtual ~Device(){};

virtual std::optional<std::unique_ptr<Driver>> driver() const = 0;
virtual std::optional<int> iommu_group() const = 0;
virtual std::string name() const = 0;
virtual std::filesystem::path override_path() const = 0;
virtual std::filesystem::path path() const = 0;
virtual void probe() const = 0;
};

} // namespace devices
} // namespace kernel
} // namespace villas
39 changes: 39 additions & 0 deletions common/include/villas/kernel/devices/device_ip_matcher.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* Devicematcher
*
* Author: Pascal Bauer <[email protected]>
*
* SPDX-FileCopyrightText: 2023-2024 Pascal Bauer <[email protected]>
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <villas/fpga/core.hpp>
#include <villas/kernel/devices/ip_device.hpp>

class DeviceIpMatcher {
private:
std::vector<villas::kernel::devices::IpDevice> devices;
std::list<std::shared_ptr<villas::fpga::ip::Core>> ips;

public:
DeviceIpMatcher(std::vector<villas::kernel::devices::IpDevice> devices,
std::list<std::shared_ptr<villas::fpga::ip::Core>> ips)
: devices(devices), ips(ips) {}

std::vector<std::pair<std::shared_ptr<villas::fpga::ip::Core>,
villas::kernel::devices::IpDevice>>
match() const {
std::vector<std::pair<std::shared_ptr<villas::fpga::ip::Core>,
villas::kernel::devices::IpDevice>>
pairs;
for (auto device : devices) {
for (auto ip : ips) {
if (ip->getBaseaddr() == device.addr()) {
pairs.push_back(std::make_pair(ip, device));
}
}
}
return pairs;
}
};
29 changes: 29 additions & 0 deletions common/include/villas/kernel/devices/driver.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* Interface for device drivers. OS/platform independend.
* Implemented for Linux/Unix drivers in linux_driver.hpp
*
* Author: Pascal Bauer <[email protected]>
*
* SPDX-FileCopyrightText: 2023-2024 Pascal Bauer <[email protected]>
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

namespace villas {
namespace kernel {
namespace devices {

class Device;

class Driver {
public:
virtual void attach(const Device &device) const = 0;
virtual void bind(const Device &device) const = 0;
virtual std::string name() const = 0;
virtual void override(const Device &device) const = 0;
virtual void unbind(const Device &device) const = 0;
};

} // namespace devices
} // namespace kernel
} // namespace villas
35 changes: 35 additions & 0 deletions common/include/villas/kernel/devices/ip_device.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* IpDevice: Linux/Unix device which represents an IP component of a FPGA.
*
* Author: Pascal Bauer <[email protected]>
*
* SPDX-FileCopyrightText: 2023-2024 Pascal Bauer <[email protected]>
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <filesystem>
#include <villas/kernel/devices/platform_device.hpp>

namespace villas {
namespace kernel {
namespace devices {

class IpDevice : public PlatformDevice {
public:
static IpDevice from(const std::filesystem::path unsafe_path);
static bool is_path_valid(const std::filesystem::path unsafe_path);

private:
IpDevice() = delete;
IpDevice(const std::filesystem::path valid_path) //! Dont allow unvalidated paths
: PlatformDevice(valid_path){};

public:
size_t addr() const;
std::string ip_name() const;
};

} // namespace devices
} // namespace kernel
} // namespace villas
37 changes: 37 additions & 0 deletions common/include/villas/kernel/devices/ip_device_reader.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* Devicetree reader for IpDevices
*
* Author: Pascal Bauer <[email protected]>
*
* SPDX-FileCopyrightText: 2023-2024 Pascal Bauer <[email protected]>
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <stdexcept>
#include <vector>
#include <filesystem>

#include <villas/kernel/devices/ip_device.hpp>
#include <villas/utils.hpp>

class IpDeviceReader {
public:
std::vector<villas::kernel::devices::IpDevice>
read(std::filesystem::path devices_directory) const {
std::vector<villas::kernel::devices::IpDevice> devices;

const std::vector<std::string> devicetree_names =
villas::utils::read_names_in_directory(devices_directory);
for (auto devicetree_name : devicetree_names) {
auto path_to_device =
devices_directory / std::filesystem::path(devicetree_name);
try {
auto device = villas::kernel::devices::IpDevice::from(path_to_device);
devices.push_back(device);
} catch (std::runtime_error &e) {
}
}
return devices;
}
};
52 changes: 52 additions & 0 deletions common/include/villas/kernel/devices/linux_driver.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* Implementation of driver interface for Linux/Unix based operation system drivers.
*
* Author: Pascal Bauer <[email protected]>
*
* SPDX-FileCopyrightText: 2023-2024 Pascal Bauer <[email protected]>
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <filesystem>
#include <fstream>
#include <iostream>
#include <villas/kernel/devices/driver.hpp>

namespace villas {
namespace kernel {
namespace devices {

class LinuxDriver : public Driver {
private:
static constexpr char BIND_DEFAULT[] = "bind";
static constexpr char UNBIND_DEFAULT[] = "unbind";

public:
const std::filesystem::path path;

private:
const std::filesystem::path bind_path;
const std::filesystem::path unbind_path;

public:
LinuxDriver(const std::filesystem::path path)
: LinuxDriver(path, path / std::filesystem::path(BIND_DEFAULT),
path / std::filesystem::path(UNBIND_DEFAULT)){};

LinuxDriver(const std::filesystem::path path,
const std::filesystem::path bind_path,
const std::filesystem::path unbind_path)
: path(path), bind_path(bind_path), unbind_path(unbind_path){};

public:
void attach(const Device &device) const override;
void bind(const Device &device) const override;
std::string name() const override;
void override(const Device &device) const override;
void unbind(const Device &device) const override;
};

} // namespace devices
} // namespace kernel
} // namespace villas
20 changes: 14 additions & 6 deletions common/include/villas/kernel/devices/pci_device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

#include <villas/log.hpp>

#include <villas/kernel/devices/device.hpp>

namespace villas {
namespace kernel {
namespace devices {
Expand Down Expand Up @@ -58,7 +60,11 @@ struct Region {
unsigned long long flags;
};

class PciDevice {
class PciDevice : public Device {
private:
static constexpr char PROBE_DEFAULT[] = "/sys/bus/pci/drivers_probe";
static constexpr char OVERRIDE_DEFAULT[] = "driver_override";

public:
PciDevice(Id i, Slot s) : id(i), slot(s), log(Log::get("kernel:pci")) {}

Expand All @@ -68,15 +74,17 @@ class PciDevice {

bool operator==(const PciDevice &other);

// Get currently loaded driver for device
std::string getDriver() const;
// Implement device interface
std::optional<std::unique_ptr<Driver>> driver() const override;
std::optional<int> iommu_group() const override;
std::string name() const override;
std::filesystem::path override_path() const override;
std::filesystem::path path() const override;
void probe() const override;

// Bind a new LKM to the PCI device
bool attachDriver(const std::string &driver) const;

// Return the IOMMU group of this PCI device or -1 if the device is not in a group
int getIommuGroup() const;

std::list<Region> getRegions() const;

// Write 32-bit BAR value from to the PCI configuration space
Expand Down
51 changes: 51 additions & 0 deletions common/include/villas/kernel/devices/platform_device.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* Platform Device: Platform bus based Linux/Unix device.
*
* Author: Pascal Bauer <[email protected]>
*
* SPDX-FileCopyrightText: 2023-2024 Pascal Bauer <[email protected]>
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <filesystem>
#include <villas/kernel/devices/device.hpp>
#include <villas/kernel/devices/driver.hpp>

namespace villas {
namespace kernel {
namespace devices {

class PlatformDevice : public Device {
private:
static constexpr char PROBE_DEFAULT[] = "/sys/bus/platform/drivers_probe";
static constexpr char OVERRIDE_DEFAULT[] = "driver_override";

private:
const std::filesystem::path m_path;
const std::filesystem::path m_probe_path;
const std::filesystem::path m_override_path;

public:
PlatformDevice(const std::filesystem::path path)
: PlatformDevice(path, std::filesystem::path(PROBE_DEFAULT),
path / std::filesystem::path(OVERRIDE_DEFAULT)){};

PlatformDevice(const std::filesystem::path path,
const std::filesystem::path probe_path,
const std::filesystem::path override_path)
: m_path(path), m_probe_path(probe_path),
m_override_path(override_path){};

// Implement device interface
std::optional<std::unique_ptr<Driver>> driver() const override;
std::optional<int> iommu_group() const override;
std::string name() const override;
std::filesystem::path override_path() const override;
std::filesystem::path path() const override;
void probe() const override;
};

} // namespace devices
} // namespace kernel
} // namespace villas
2 changes: 2 additions & 0 deletions common/include/villas/kernel/vfio_device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class Device {
// Get the size of a device memory region
size_t regionGetSize(size_t index);

int platformInterruptInit(int efds[32]);

// Enable memory accesses and bus mastering for PCI device
bool pciEnable();

Expand Down
4 changes: 4 additions & 0 deletions common/include/villas/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <list>
#include <string>
#include <vector>
#include <filesystem>

#include <cassert>
#include <cstdint>
Expand Down Expand Up @@ -211,6 +212,9 @@ template <class... Ts> struct overloaded : Ts... {
// explicit deduction guide (not needed as of C++20)
template <class... Ts> overloaded(Ts...) -> overloaded<Ts...>;

void write_to_file(std::string data, const std::filesystem::path file);
std::vector<std::string> read_names_in_directory(const std::filesystem::path &directory);

namespace base64 {

using byte = std::uint8_t;
Expand Down
3 changes: 3 additions & 0 deletions common/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ endif()

if(CMAKE_SYSTEM_NAME STREQUAL Linux)
target_sources(villas-common PRIVATE
kernel/devices/ip_device.cpp
kernel/devices/linux_driver.cpp
kernel/devices/pci_device.cpp
kernel/devices/platform_device.cpp
kernel/vfio_device.cpp
kernel/vfio_group.cpp
kernel/vfio_container.cpp
Expand Down
Loading