diff options
author | Gabe Black <gabeblack@google.com> | 2019-08-28 17:03:42 -0700 |
---|---|---|
committer | Gabe Black <gabeblack@google.com> | 2019-09-17 01:02:55 +0000 |
commit | fe15312aae8007967812350f8cdac9ad766dcff7 (patch) | |
tree | 1b0c0f803879d1e896d38ed9ac170ead353cd93f /src/systemc/tlm_bridge | |
parent | 59aed6f3bd400b0182cfcb3dc6cc820dfc49e2df (diff) | |
download | gem5-fe15312aae8007967812350f8cdac9ad766dcff7.tar.xz |
systemc: Expose the utility functions for payload->packet conversion.
These can be used anywhere someone needs to turn a packet into a
payload or vice-versa.
Change-Id: I26a1f134e6fbec81b230a2853cf79264e80bf2dc
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/20859
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Maintainer: Gabe Black <gabeblack@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Diffstat (limited to 'src/systemc/tlm_bridge')
-rw-r--r-- | src/systemc/tlm_bridge/gem5_to_tlm.hh | 2 | ||||
-rw-r--r-- | src/systemc/tlm_bridge/tlm_to_gem5.cc | 75 | ||||
-rw-r--r-- | src/systemc/tlm_bridge/tlm_to_gem5.hh | 3 |
3 files changed, 41 insertions, 39 deletions
diff --git a/src/systemc/tlm_bridge/gem5_to_tlm.hh b/src/systemc/tlm_bridge/gem5_to_tlm.hh index 182512a93..e9ec93569 100644 --- a/src/systemc/tlm_bridge/gem5_to_tlm.hh +++ b/src/systemc/tlm_bridge/gem5_to_tlm.hh @@ -78,6 +78,8 @@ namespace sc_gem5 { +tlm::tlm_generic_payload *packet2payload(PacketPtr packet); + class Gem5ToTlmBridgeBase : public sc_core::sc_module { protected: diff --git a/src/systemc/tlm_bridge/tlm_to_gem5.cc b/src/systemc/tlm_bridge/tlm_to_gem5.cc index d978aa648..ea6435726 100644 --- a/src/systemc/tlm_bridge/tlm_to_gem5.cc +++ b/src/systemc/tlm_bridge/tlm_to_gem5.cc @@ -69,6 +69,39 @@ namespace sc_gem5 { +PacketPtr +payload2packet(MasterID masterId, tlm::tlm_generic_payload &trans) +{ + MemCmd cmd; + + switch (trans.get_command()) { + case tlm::TLM_READ_COMMAND: + cmd = MemCmd::ReadReq; + break; + case tlm::TLM_WRITE_COMMAND: + cmd = MemCmd::WriteReq; + break; + case tlm::TLM_IGNORE_COMMAND: + return nullptr; + default: + SC_REPORT_FATAL("TlmToGem5Bridge", + "received transaction with unsupported command"); + } + + Request::Flags flags; + auto req = std::make_shared<Request>( + trans.get_address(), trans.get_data_length(), flags, masterId); + + /* + * Allocate a new Packet. The packet will be deleted when it returns from + * the gem5 world as a response. + */ + auto pkt = new Packet(req, cmd); + pkt->dataStatic(trans.get_data_ptr()); + + return pkt; +} + template <unsigned int BITWIDTH> void TlmToGem5Bridge<BITWIDTH>::sendEndReq(tlm::tlm_generic_payload &trans) @@ -126,7 +159,7 @@ TlmToGem5Bridge<BITWIDTH>::handleBeginReq(tlm::tlm_generic_payload &trans) extension->setPipeThrough(); pkt = extension->getPacket(); } else { - pkt = generatePacket(trans); + pkt = payload2packet(masterId, trans); } auto tlmSenderState = new TlmSenderState(trans); @@ -159,40 +192,6 @@ TlmToGem5Bridge<BITWIDTH>::handleEndResp(tlm::tlm_generic_payload &trans) } template <unsigned int BITWIDTH> -PacketPtr -TlmToGem5Bridge<BITWIDTH>::generatePacket(tlm::tlm_generic_payload &trans) -{ - MemCmd cmd; - - switch (trans.get_command()) { - case tlm::TLM_READ_COMMAND: - cmd = MemCmd::ReadReq; - break; - case tlm::TLM_WRITE_COMMAND: - cmd = MemCmd::WriteReq; - break; - case tlm::TLM_IGNORE_COMMAND: - return nullptr; - default: - SC_REPORT_FATAL("TlmToGem5Bridge", - "received transaction with unsupported command"); - } - - Request::Flags flags; - auto req = std::make_shared<Request>( - trans.get_address(), trans.get_data_length(), flags, masterId); - - /* - * Allocate a new Packet. The packet will be deleted when it returns from - * the gem5 world as a response. - */ - auto pkt = new Packet(req, cmd); - pkt->dataStatic(trans.get_data_ptr()); - - return pkt; -} - -template <unsigned int BITWIDTH> void TlmToGem5Bridge<BITWIDTH>::destroyPacket(PacketPtr pkt) { @@ -278,7 +277,7 @@ TlmToGem5Bridge<BITWIDTH>::b_transport(tlm::tlm_generic_payload &trans, extension->setPipeThrough(); pkt = extension->getPacket(); } else { - pkt = generatePacket(trans); + pkt = payload2packet(masterId, trans); } MemBackdoorPtr backdoor = nullptr; @@ -315,7 +314,7 @@ TlmToGem5Bridge<BITWIDTH>::transport_dbg(tlm::tlm_generic_payload &trans) extension->setPipeThrough(); bmp.sendFunctional(extension->getPacket()); } else { - auto pkt = generatePacket(trans); + auto pkt = payload2packet(masterId, trans); if (pkt) { bmp.sendFunctional(pkt); destroyPacket(pkt); @@ -341,7 +340,7 @@ TlmToGem5Bridge<BITWIDTH>::get_direct_mem_ptr(tlm::tlm_generic_payload &trans, extension->setPipeThrough(); pkt = extension->getPacket(); } else { - pkt = generatePacket(trans); + pkt = payload2packet(masterId, trans); pkt->req->setFlags(Request::NO_ACCESS); } diff --git a/src/systemc/tlm_bridge/tlm_to_gem5.hh b/src/systemc/tlm_bridge/tlm_to_gem5.hh index 82d3d103a..bcc90b972 100644 --- a/src/systemc/tlm_bridge/tlm_to_gem5.hh +++ b/src/systemc/tlm_bridge/tlm_to_gem5.hh @@ -80,6 +80,8 @@ class TlmToGem5BridgeBase : public sc_core::sc_module using sc_core::sc_module::sc_module; }; +PacketPtr payload2packet(tlm::tlm_generic_payload &trans); + template <unsigned int BITWIDTH> class TlmToGem5Bridge : public TlmToGem5BridgeBase { @@ -134,7 +136,6 @@ class TlmToGem5Bridge : public TlmToGem5BridgeBase void handleBeginReq(tlm::tlm_generic_payload &trans); void handleEndResp(tlm::tlm_generic_payload &trans); - PacketPtr generatePacket(tlm::tlm_generic_payload &trans); void destroyPacket(PacketPtr pkt); void checkTransaction(tlm::tlm_generic_payload &trans); |