systemc: Expose the utility functions for payload->packet conversion.
authorGabe Black <gabeblack@google.com>
Thu, 29 Aug 2019 00:03:42 +0000 (17:03 -0700)
committerGabe Black <gabeblack@google.com>
Tue, 17 Sep 2019 01:02:55 +0000 (01:02 +0000)
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>
src/systemc/tlm_bridge/gem5_to_tlm.hh
src/systemc/tlm_bridge/tlm_to_gem5.cc
src/systemc/tlm_bridge/tlm_to_gem5.hh

index 182512a933b8856469bd47ab2bf6bae9402966ad..e9ec935696e211fe6c9160cccbd9248410f9ef4e 100644 (file)
@@ -78,6 +78,8 @@
 namespace sc_gem5
 {
 
+tlm::tlm_generic_payload *packet2payload(PacketPtr packet);
+
 class Gem5ToTlmBridgeBase : public sc_core::sc_module
 {
   protected:
index d978aa648c5c856928f5fa7cd51f1ddf2bf2b463..ea6435726fad533b3b942ae731ffdd14258171a0 100644 (file)
 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);
@@ -158,40 +191,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);
     }
 
index 82d3d103aab705a37a33181e350ae6ba3ee76bab..bcc90b9722497125a5dbd91042d720ea89c06205 100644 (file)
@@ -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);