From fe15312aae8007967812350f8cdac9ad766dcff7 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Wed, 28 Aug 2019 17:03:42 -0700 Subject: [PATCH] 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 Maintainer: Gabe Black Tested-by: kokoro --- src/systemc/tlm_bridge/gem5_to_tlm.hh | 2 + src/systemc/tlm_bridge/tlm_to_gem5.cc | 75 +++++++++++++-------------- 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( + 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 void TlmToGem5Bridge::sendEndReq(tlm::tlm_generic_payload &trans) @@ -126,7 +159,7 @@ TlmToGem5Bridge::handleBeginReq(tlm::tlm_generic_payload &trans) extension->setPipeThrough(); pkt = extension->getPacket(); } else { - pkt = generatePacket(trans); + pkt = payload2packet(masterId, trans); } auto tlmSenderState = new TlmSenderState(trans); @@ -158,40 +191,6 @@ TlmToGem5Bridge::handleEndResp(tlm::tlm_generic_payload &trans) } } -template -PacketPtr -TlmToGem5Bridge::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( - 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 void TlmToGem5Bridge::destroyPacket(PacketPtr pkt) @@ -278,7 +277,7 @@ TlmToGem5Bridge::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::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::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 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); -- 2.30.2