From: Gabe Black Date: Thu, 15 Aug 2019 23:53:20 +0000 (-0700) Subject: mem: Make PortProxy use a delegate for a sendFunctional function. X-Git-Tag: v19.0.0.0~623 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9ad74b7d0c0f726e933f3589c69fedc945855e3c;p=gem5.git mem: Make PortProxy use a delegate for a sendFunctional function. The only part of the MaserPort the PortProxy uses is the sendFunctional function which is part of the functional protocol. Rather than require a MasterPort which comes along with a lot of other mechanisms, this change slightly adjusts the PortProxy to only require that function through the use of a delegate. That allows lots of flexibility in how the actual packet gets sent and what sends it. In cases where code constructs a PortProxy and passes its constructor an unbound MasterPort, the PortProxy will create a delegate to the sendFunctional method on its own. This should also make it easier for objects which don't have traditional gem5 style ports, for instance systemc models, to implement just the little bit of the protocol they need, rather than having to stub out a whole port class, most of which will be ignored. Change-Id: I234b42ce050f12313b551a61736186ddf2c9e2c7 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/20229 Maintainer: Gabe Black Reviewed-by: Gabe Black Tested-by: kokoro --- diff --git a/src/mem/fs_translating_port_proxy.cc b/src/mem/fs_translating_port_proxy.cc index 6a25d1121..d12af13af 100644 --- a/src/mem/fs_translating_port_proxy.cc +++ b/src/mem/fs_translating_port_proxy.cc @@ -60,8 +60,14 @@ FSTranslatingPortProxy::FSTranslatingPortProxy(ThreadContext *tc) { } -FSTranslatingPortProxy::FSTranslatingPortProxy(MasterPort &port, - unsigned int cacheLineSize) +FSTranslatingPortProxy::FSTranslatingPortProxy( + SendFunctionalFunc func, unsigned int cacheLineSize) + : PortProxy(func, cacheLineSize), _tc(NULL) +{ +} + +FSTranslatingPortProxy::FSTranslatingPortProxy( + MasterPort &port, unsigned int cacheLineSize) : PortProxy(port, cacheLineSize), _tc(NULL) { } diff --git a/src/mem/fs_translating_port_proxy.hh b/src/mem/fs_translating_port_proxy.hh index 410eb7d78..2ecd742bc 100644 --- a/src/mem/fs_translating_port_proxy.hh +++ b/src/mem/fs_translating_port_proxy.hh @@ -79,7 +79,10 @@ class FSTranslatingPortProxy : public PortProxy FSTranslatingPortProxy(ThreadContext* tc); - FSTranslatingPortProxy(MasterPort &port, unsigned int cacheLineSize); + FSTranslatingPortProxy(SendFunctionalFunc func, + unsigned int cacheLineSize); + FSTranslatingPortProxy(MasterPort &port, + unsigned int cacheLineSize); ~FSTranslatingPortProxy() {} diff --git a/src/mem/port_proxy.cc b/src/mem/port_proxy.cc index 60f79e375..b630d310a 100644 --- a/src/mem/port_proxy.cc +++ b/src/mem/port_proxy.cc @@ -53,7 +53,7 @@ PortProxy::readBlobPhys(Addr addr, Request::Flags flags, Packet pkt(req, MemCmd::ReadReq); pkt.dataStatic(static_cast(p)); - _port.sendFunctional(&pkt); + sendFunctional(&pkt); p = static_cast(p) + gen.size(); } } @@ -70,7 +70,7 @@ PortProxy::writeBlobPhys(Addr addr, Request::Flags flags, Packet pkt(req, MemCmd::WriteReq); pkt.dataStaticConst(static_cast(p)); - _port.sendFunctional(&pkt); + sendFunctional(&pkt); p = static_cast(p) + gen.size(); } } diff --git a/src/mem/port_proxy.hh b/src/mem/port_proxy.hh index 61a207146..31ac3e941 100644 --- a/src/mem/port_proxy.hh +++ b/src/mem/port_proxy.hh @@ -59,38 +59,53 @@ #ifndef __MEM_PORT_PROXY_HH__ #define __MEM_PORT_PROXY_HH__ +#include #include #include "mem/port.hh" #include "sim/byteswap.hh" /** - * This object is a proxy for a structural port, to be used for debug - * accesses. + * This object is a proxy for a port or other object which implements the + * functional response protocol, to be used for debug accesses. * * This proxy object is used when non structural entities * (e.g. thread contexts, object file loaders) need access to the * memory system. It calls the corresponding functions on the underlying - * structural port, and provides templatized convenience access functions. + * protocol, and provides templatized convenience access functions. * * The addresses are interpreted as physical addresses. * * @sa SETranslatingProxy * @sa FSTranslatingProxy */ -class PortProxy +class PortProxy : FunctionalRequestProtocol { - private: + public: + typedef std::function SendFunctionalFunc; - /** The actual physical port used by this proxy. */ - MasterPort &_port; + private: + SendFunctionalFunc sendFunctional; /** Granularity of any transactions issued through this proxy. */ const unsigned int _cacheLineSize; + void + recvFunctionalSnoop(PacketPtr pkt) override + { + // Since port proxies aren't anyone else's peer, they should never + // receive snoops. + panic("Port proxies should never receive snoops."); + } + public: - PortProxy(MasterPort &port, unsigned int cacheLineSize) : - _port(port), _cacheLineSize(cacheLineSize) + PortProxy(SendFunctionalFunc func, unsigned int cacheLineSize) : + sendFunctional(func), _cacheLineSize(cacheLineSize) + {} + PortProxy(const MasterPort &port, unsigned int cacheLineSize) : + sendFunctional([&port](PacketPtr pkt)->void { + port.sendFunctional(pkt); + }), _cacheLineSize(cacheLineSize) {} virtual ~PortProxy() { } diff --git a/src/mem/se_translating_port_proxy.cc b/src/mem/se_translating_port_proxy.cc index c5f38f1cd..94d2ab3d1 100644 --- a/src/mem/se_translating_port_proxy.cc +++ b/src/mem/se_translating_port_proxy.cc @@ -55,8 +55,13 @@ using namespace TheISA; -SETranslatingPortProxy::SETranslatingPortProxy(MasterPort& port, Process *p, - AllocType alloc) +SETranslatingPortProxy::SETranslatingPortProxy( + SendFunctionalFunc func, Process *p, AllocType alloc) + : PortProxy(func, p->system->cacheLineSize()), pTable(p->pTable), + process(p), allocating(alloc) +{ } +SETranslatingPortProxy::SETranslatingPortProxy(MasterPort &port, + Process *p, AllocType alloc) : PortProxy(port, p->system->cacheLineSize()), pTable(p->pTable), process(p), allocating(alloc) { } diff --git a/src/mem/se_translating_port_proxy.hh b/src/mem/se_translating_port_proxy.hh index 718e44a57..e32f1d0e3 100644 --- a/src/mem/se_translating_port_proxy.hh +++ b/src/mem/se_translating_port_proxy.hh @@ -80,7 +80,9 @@ class SETranslatingPortProxy : public PortProxy AllocType allocating; public: - SETranslatingPortProxy(MasterPort& port, Process* p, AllocType alloc); + SETranslatingPortProxy(SendFunctionalFunc func, + Process* p, AllocType alloc); + SETranslatingPortProxy(MasterPort &port, Process* p, AllocType alloc); ~SETranslatingPortProxy() {} void setPageTable(EmulationPageTable *p) { pTable = p; } diff --git a/src/mem/secure_port_proxy.hh b/src/mem/secure_port_proxy.hh index 9a2200c9e..5ce0c299a 100644 --- a/src/mem/secure_port_proxy.hh +++ b/src/mem/secure_port_proxy.hh @@ -70,8 +70,7 @@ class SecurePortProxy : public PortProxy { public: - SecurePortProxy(MasterPort &port, unsigned int cache_line_size) - : PortProxy(port, cache_line_size) {} + using PortProxy::PortProxy; bool tryReadBlob(Addr addr, void *p, int size) const override; bool tryWriteBlob(Addr addr, const void *p, int size) const override;