diff --git a/fpga/lib/card.cpp b/fpga/lib/card.cpp index a03820e81..3d8dda65c 100644 --- a/fpga/lib/card.cpp +++ b/fpga/lib/card.cpp @@ -15,6 +15,22 @@ using namespace villas::fpga; Card::~Card() { + // Ensure IP destructors are called before memory is unmapped + ips.clear(); + + auto &mm = MemoryManager::get(); + + // Unmap all memory blocks + for (auto &mappedMemoryBlock : memoryBlocksMapped) { + auto translation = mm.getTranslation(addrSpaceIdDeviceToHost, mappedMemoryBlock); + + const uintptr_t iova = translation.getLocalAddr(0); + const size_t size = translation.getSize(); + + logger->debug("Unmap block {} at IOVA {:#x} of size {:#x}", + mappedMemoryBlock, iova, size); + vfioContainer->memoryUnmap(iova, size); + } } std::shared_ptr Card::lookupIp(const std::string &name) const diff --git a/fpga/lib/pcie_card.cpp b/fpga/lib/pcie_card.cpp index 0ff96e1eb..c75cc38f6 100644 --- a/fpga/lib/pcie_card.cpp +++ b/fpga/lib/pcie_card.cpp @@ -152,22 +152,7 @@ std::list> PCIeCardFactory::make(json_t *json, std::sh PCIeCard::~PCIeCard() { - // Ensure IP destructors are called before memory is unmapped - ips.clear(); - - auto &mm = MemoryManager::get(); - - // Unmap all memory blocks - for (auto &mappedMemoryBlock : memoryBlocksMapped) { - auto translation = mm.getTranslation(addrSpaceIdDeviceToHost, mappedMemoryBlock); - - const uintptr_t iova = translation.getLocalAddr(0); - const size_t size = translation.getSize(); - - logger->debug("Unmap block {} at IOVA {:#x} of size {:#x}", - mappedMemoryBlock, iova, size); - vfioContainer->memoryUnmap(iova, size); - } + } std::shared_ptr PCIeCard::lookupIp(const std::string &name) const