diff --git a/common/include/villas/kernel/vfio.hpp b/common/include/villas/kernel/vfio.hpp index 0b59fcf43..058374134 100644 --- a/common/include/villas/kernel/vfio.hpp +++ b/common/include/villas/kernel/vfio.hpp @@ -10,16 +10,16 @@ #define FPGA_PCI #if defined(FPGA_PLATFORM) - #define KERNEL_MODULE_VFIO +#define KERNEL_MODULE_VFIO #endif #if defined(FPGA_PCI) - #define KERNEL_MODULE_VFIO - #define KERNEL_MODULE_VFIO_PCI - #define KERNEL_MODULE_VFIO_IOMMU_TYPE1 +#define KERNEL_MODULE_VFIO +#define KERNEL_MODULE_VFIO_PCI +#define KERNEL_MODULE_VFIO_IOMMU_TYPE1 #endif -static constexpr const char* const requiredKernelModules[] = { +static constexpr const char *const requiredKernelModules[] = { #if defined(KERNEL_MODULE_VFIO) "vfio", #endif // KERNEL_MODULE_VFIO_PCI @@ -27,7 +27,7 @@ static constexpr const char* const requiredKernelModules[] = { #if defined(KERNEL_MODULE_VFIO_PCI) "vfio_pci", #endif // KERNEL_MODULE_VFIO_PCI - + #if defined(KERNEL_MODULE_VFIO_IOMMU_TYPE1) "vfio_iommu_type1" #endif // KERNEL_MODULE_VFIO_IOMMU_TYPE1 diff --git a/common/include/villas/kernel/vfio_device.hpp b/common/include/villas/kernel/vfio_device.hpp index 320f77e76..b94b26caf 100644 --- a/common/include/villas/kernel/vfio_device.hpp +++ b/common/include/villas/kernel/vfio_device.hpp @@ -38,10 +38,10 @@ public: bool reset(); - std::string getName() { return name; }; + std::string getName() { return name; }; - // Map a device memory region to the application address space (e.g. PCI BARs) - void* regionMap(size_t index); + // Map a device memory region to the application address space (e.g. PCI BARs) + void *regionMap(size_t index); // munmap() a region which has been mapped by vfio_map_region() bool regionUnmap(size_t index); diff --git a/common/include/villas/memory_manager.hpp b/common/include/villas/memory_manager.hpp index eaca7775f..0e514cc44 100644 --- a/common/include/villas/memory_manager.hpp +++ b/common/include/villas/memory_manager.hpp @@ -96,25 +96,20 @@ private: uintptr_t dest; // Base address in "to" address space size_t size; // Size of the mapping - friend std::ostream& - operator<< (std::ostream &stream, const Mapping &mapping) - { - return stream << static_cast(mapping) << " = " - << mapping.name - << std::hex - << " (src=0x" << mapping.src - << ", dest=0x" << mapping.dest - << ", size=0x" << mapping.size - << ")"; - } + friend std::ostream &operator<<(std::ostream &stream, + const Mapping &mapping) { + return stream << static_cast(mapping) << " = " + << mapping.name << std::hex << " (src=0x" << mapping.src + << ", dest=0x" << mapping.dest << ", size=0x" + << mapping.size << ")"; + } - std::string toString() - { - std::stringstream s; - s << *this; - return s.str(); - } - }; + std::string toString() { + std::stringstream s; + s << *this; + return s.str(); + } + }; // Custom vertex in memory graph representing an address space // diff --git a/common/lib/kernel/vfio_container.cpp b/common/lib/kernel/vfio_container.cpp index 53e5d3e3d..709b8ef51 100644 --- a/common/lib/kernel/vfio_container.cpp +++ b/common/lib/kernel/vfio_container.cpp @@ -31,10 +31,8 @@ #include #include -#include -#include -#include #include +#include #include #include @@ -67,21 +65,16 @@ static std::array construct_vfio_extension_str() { static std::array VFIO_EXTENSION_STR = construct_vfio_extension_str(); -Container::Container() : - fd(-1), - version(0), - extensions(), - iova_next(0), - hasIommu(false), - groups(), - log(logging.get("kernel:vfio:container")) -{ - for (const char* module : requiredKernelModules) { - if (kernel::loadModule(module) != 0) { - throw RuntimeError("Kernel module '{}' required but could not be loaded. " - "Please load manually!", module); - } - } +Container::Container() + : fd(-1), version(0), extensions(), iova_next(0), hasIommu(false), groups(), + log(logging.get("kernel:vfio:container")) { + for (const char *module : requiredKernelModules) { + if (kernel::loadModule(module) != 0) { + throw RuntimeError("Kernel module '{}' required but could not be loaded. " + "Please load manually!", + module); + } + } // Create a VFIO Container fd = open(VFIO_DEV, O_RDWR); diff --git a/common/lib/kernel/vfio_device.cpp b/common/lib/kernel/vfio_device.cpp index cdfb1f7ca..db08e0b99 100644 --- a/common/lib/kernel/vfio_device.cpp +++ b/common/lib/kernel/vfio_device.cpp @@ -75,22 +75,21 @@ Device::Device(const std::string &name, int groupFileDescriptor, log->debug("device info: flags: 0x{:x}, num_regions: {}, num_irqs: {}", info.flags, info.num_regions, info.num_irqs); - if (pci_device != 0) { - // device_info.num_region reports always 9 and includes a VGA region, which is only supported on - // certain device IDs. So for non-VGA devices VFIO_PCI_CONFIG_REGION_INDEX will be the highest - // region index. This is the config space. - info.num_regions = VFIO_PCI_CONFIG_REGION_INDEX + 1; - } else { info.num_regions = 1; } + // device_info.num_region reports always 9 and includes a VGA region, which is only supported on + // certain device IDs. So for non-VGA devices VFIO_PCI_CONFIG_REGION_INDEX will be the highest + // region index. This is the config space. + info.num_regions = + pci_device != 0 ? VFIO_PCI_CONFIG_REGION_INDEX + 1 : 1; // Reserve slots already so that we can use the []-operator for access irqs.resize(info.num_irqs); regions.resize(info.num_regions); mappings.resize(info.num_regions); - // Get device regions - for (size_t i = 0; i < info.num_regions; i++) { - struct vfio_region_info region; - memset(®ion, 0, sizeof (region)); + // Get device regions + for (size_t i = 0; i < info.num_regions; i++) { + struct vfio_region_info region; + memset(®ion, 0, sizeof(region)); region.argsz = sizeof(region); region.index = i; @@ -99,8 +98,10 @@ Device::Device(const std::string &name, int groupFileDescriptor, if (ret < 0) throw RuntimeError("Failed to get region {} of VFIO device: {}", i, name); - log->debug("region {} info: flags: 0x{:x}, cap_offset: 0x{:x}, size: 0x{:x}, offset: 0x{:x}", - region.index, region.flags, region.cap_offset, region.size, region.offset); + log->debug("region {} info: flags: 0x{:x}, cap_offset: 0x{:x}, size: " + "0x{:x}, offset: 0x{:x}", + region.index, region.flags, region.cap_offset, region.size, + region.offset); regions[i] = region; }