From ae2bd2a41d5a447e0871f23dcea14d89f72e3ad0 Mon Sep 17 00:00:00 2001 From: Daniel Krebs Date: Fri, 13 Apr 2018 15:24:20 +0200 Subject: [PATCH] lib/ip: alias type for memory block name and cache addres space IDs in IP --- fpga/include/villas/fpga/ip.hpp | 18 ++++++++++++++---- fpga/include/villas/fpga/ips/dma.hpp | 2 +- fpga/include/villas/fpga/ips/fifo.hpp | 2 +- fpga/include/villas/fpga/ips/intc.hpp | 2 +- fpga/include/villas/fpga/ips/switch.hpp | 2 +- fpga/include/villas/fpga/ips/timer.hpp | 2 +- fpga/lib/ip.cpp | 5 ++++- 7 files changed, 23 insertions(+), 10 deletions(-) diff --git a/fpga/include/villas/fpga/ip.hpp b/fpga/include/villas/fpga/ip.hpp index 28f9e14f6..f565aa4a2 100644 --- a/fpga/include/villas/fpga/ip.hpp +++ b/fpga/include/villas/fpga/ip.hpp @@ -127,8 +127,11 @@ public: virtual void dump(); protected: + /// Key-type for accessing maps addressTranslations and slaveAddressSpaces + using MemoryBlockName = std::string; + /// Each IP can declare via this function which memory blocks it requires - virtual std::list + virtual std::list getMemoryBlocks() const { return {}; } @@ -177,11 +180,15 @@ public: protected: uintptr_t - getBaseAddr(const std::string& block) const + getBaseAddr(const MemoryBlockName& block) const { return getLocalAddr(block, 0); } uintptr_t - getLocalAddr(const std::string& block, uintptr_t address) const; + getLocalAddr(const MemoryBlockName& block, uintptr_t address) const; + + MemoryManager::AddressSpaceId + getAddressSpaceId(const MemoryBlockName& block) const + { return slaveAddressSpaces.at(block); } InterruptController* getInterruptController(const std::string& interruptName) const; @@ -206,7 +213,10 @@ protected: std::map irqs; /// Cached translations from the process address space to each memory block - std::map addressTranslations; + std::map addressTranslations; + + /// Lookup for IP's slave address spaces (= memory blocks) + std::map slaveAddressSpaces; /// AXI bus master interfaces to access memory somewhere std::map busMasterInterfaces; diff --git a/fpga/include/villas/fpga/ips/dma.hpp b/fpga/include/villas/fpga/ips/dma.hpp index b5cd34f51..41a1fe115 100644 --- a/fpga/include/villas/fpga/ips/dma.hpp +++ b/fpga/include/villas/fpga/ips/dma.hpp @@ -84,7 +84,7 @@ private: // optional Scatter-Gather interface to access descriptors static constexpr char sgInterface[] = "M_AXI_SG"; - std::list getMemoryBlocks() const + std::list getMemoryBlocks() const { return { registerMemory }; } XAxiDma xDma; diff --git a/fpga/include/villas/fpga/ips/fifo.hpp b/fpga/include/villas/fpga/ips/fifo.hpp index 9d8528237..82fc3156a 100644 --- a/fpga/include/villas/fpga/ips/fifo.hpp +++ b/fpga/include/villas/fpga/ips/fifo.hpp @@ -54,7 +54,7 @@ private: static constexpr char axi4Memory[] = "Mem1"; static constexpr char irqName[] = "interrupt"; - std::list getMemoryBlocks() const + std::list getMemoryBlocks() const { return { registerMemory, axi4Memory }; } XLlFifo xFifo; diff --git a/fpga/include/villas/fpga/ips/intc.hpp b/fpga/include/villas/fpga/ips/intc.hpp index 7ccef8038..d8d3e5f86 100644 --- a/fpga/include/villas/fpga/ips/intc.hpp +++ b/fpga/include/villas/fpga/ips/intc.hpp @@ -64,7 +64,7 @@ private: static constexpr char registerMemory[] = "Reg"; - std::list getMemoryBlocks() const + std::list getMemoryBlocks() const { return { registerMemory }; } diff --git a/fpga/include/villas/fpga/ips/switch.hpp b/fpga/include/villas/fpga/ips/switch.hpp index 796cab711..587ae4b70 100644 --- a/fpga/include/villas/fpga/ips/switch.hpp +++ b/fpga/include/villas/fpga/ips/switch.hpp @@ -58,7 +58,7 @@ private: static constexpr char registerMemory[] = "Reg"; - std::list getMemoryBlocks() const + std::list getMemoryBlocks() const { return { registerMemory }; } struct Path { diff --git a/fpga/include/villas/fpga/ips/timer.hpp b/fpga/include/villas/fpga/ips/timer.hpp index 56231069b..fcf4d75ea 100644 --- a/fpga/include/villas/fpga/ips/timer.hpp +++ b/fpga/include/villas/fpga/ips/timer.hpp @@ -63,7 +63,7 @@ public: private: - std::list getMemoryBlocks() const + std::list getMemoryBlocks() const { return { registerMemory }; } static constexpr char irqName[] = "generateout0"; diff --git a/fpga/lib/ip.cpp b/fpga/lib/ip.cpp index d1d2d33a6..63cffdebc 100644 --- a/fpga/lib/ip.cpp +++ b/fpga/lib/ip.cpp @@ -281,6 +281,9 @@ IpCoreFactory::make(PCIeCard* card, json_t *json_ips) const auto addrSpaceId = MemoryManager::get().findAddressSpace(addrSpaceName); + // ... and save it in IP + ip->slaveAddressSpaces.emplace(memoryBlock, addrSpaceId); + // get the translation to the address space const auto& translation = MemoryManager::get().getTranslationFromProcess(addrSpaceId); @@ -341,7 +344,7 @@ IpCoreFactory::lookup(const Vlnv &vlnv) uintptr_t -IpCore::getLocalAddr(const std::string& block, uintptr_t address) const +IpCore::getLocalAddr(const MemoryBlockName& block, uintptr_t address) const { // throws exception if block not present auto& translation = addressTranslations.at(block);