1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-16 00:00:02 +01:00
VILLASnode/fpga/include/villas/memory_manager.hpp

99 lines
2.2 KiB
C++
Raw Normal View History

2018-01-30 15:11:29 +01:00
#pragma once
#include <cstdint>
#include <string>
2018-01-30 15:11:29 +01:00
#include "log.hpp"
#include "directed_graph.hpp"
namespace villas {
class Mapping : public graph::Edge {
friend class MemoryManager;
2018-01-30 15:11:29 +01:00
public:
// create mapping here (if needed)
Mapping() {}
// destroy mapping here (if needed)
virtual ~Mapping();
2018-01-30 15:11:29 +01:00
friend std::ostream&
operator<< (std::ostream& stream, const Mapping& mapping)
{
return stream << static_cast<const Edge&>(mapping) << " = "
<< std::hex
<< "(src=0x" << mapping.src
<< ", dest=0x" << mapping.dest
<< ", size=0x" << mapping.size
<< ")";
}
2018-01-30 15:11:29 +01:00
private:
uintptr_t src;
uintptr_t dest;
size_t size;
};
class AddressSpace : public graph::Vertex {
friend class MemoryManager;
public:
friend std::ostream&
operator<< (std::ostream& stream, const AddressSpace& addrSpace)
{
return stream << static_cast<const Vertex&>(addrSpace) << " = "
<< addrSpace.name;
}
2018-01-30 15:11:29 +01:00
private:
std::string name;
2018-01-30 15:11:29 +01:00
};
// is or has a graph
class MemoryManager {
private:
// This is a singleton, so private constructor
MemoryManager() :
memoryGraph("MemoryGraph") {}
// no copying or assigning
MemoryManager(const MemoryManager&) = delete;
MemoryManager& operator=(const MemoryManager&) = delete ;
using MemoryGraph = graph::DirectedGraph<AddressSpace, Mapping>;
2018-01-30 15:11:29 +01:00
public:
using AddressSpaceId = MemoryGraph::VertexIdentifier;
using MappingId = MemoryGraph::EdgeIdentifier;
static MemoryManager& get();
AddressSpaceId createAddressSpace(std::string name);
/// Create a default mapping
MappingId createMapping(uintptr_t src, uintptr_t dest, size_t size,
AddressSpaceId fromAddrSpace,
AddressSpaceId toAddrSpace);
/// Add a mapping
///
/// Can be used to derive from Mapping in order to implement custom
/// constructor/destructor.
MappingId addMapping(std::shared_ptr<Mapping> mapping,
AddressSpaceId fromAddrSpace,
AddressSpaceId toAddrSpace);
2018-01-30 15:11:29 +01:00
void dump()
{ memoryGraph.dump(); }
2018-01-30 15:11:29 +01:00
private:
MemoryGraph memoryGraph;
static MemoryManager* instance;
2018-01-30 15:11:29 +01:00
};
} // namespace villas