systemc: fix flexible conversion when reusing transactions

To make the all extension states correct, we still need to proceed the
plugins when reusing the transactions, since we don't know the detail of
the plugins.

Change-Id: I18acd64f54be4c82a0678b98e834ea9548de1f58
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/63871
Reviewed-by: Gabe Black <gabe.black@gmail.com>
Maintainer: Gabe Black <gabe.black@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
diff --git a/src/systemc/tlm_bridge/gem5_to_tlm.cc b/src/systemc/tlm_bridge/gem5_to_tlm.cc
index 6f17a8b..07e4821 100644
--- a/src/systemc/tlm_bridge/gem5_to_tlm.cc
+++ b/src/systemc/tlm_bridge/gem5_to_tlm.cc
@@ -112,7 +112,8 @@
  * gem5 packet to tlm payload. This can be useful when there exists a SystemC
  * extension that requires information in gem5 packet. For example, if a user
  * defined a SystemC extension the carries stream_id, the user may add a step
- * here to read stream_id out and set the extension properly.
+ * here to read stream_id out and set the extension properly. Steps should be
+ * idempotent.
  */
 void
 addPacketToPayloadConversionStep(PacketToPayloadConversionStep step)
@@ -140,6 +141,10 @@
         trans = &tlmSenderState->trans;
         trans->set_address(packet->getAddr());
         trans->acquire();
+        // Apply all conversion steps necessary in this specific setup.
+        for (auto &step : extraPacketToPayloadSteps) {
+            step(packet, *trans);
+        }
         return trans;
     }
 
diff --git a/src/systemc/tlm_bridge/tlm_to_gem5.cc b/src/systemc/tlm_bridge/tlm_to_gem5.cc
index 84907be..25da42b 100644
--- a/src/systemc/tlm_bridge/tlm_to_gem5.cc
+++ b/src/systemc/tlm_bridge/tlm_to_gem5.cc
@@ -89,7 +89,8 @@
  * tlm payload to gem5 packet. This can be useful when there exists a SystemC
  * extension that carries extra information. For example, SystemC user might
  * define an extension to store stream_id, the user may then add an extra step
- * to set the generated request's stream_id accordingly.
+ * to set the generated request's stream_id accordingly. Steps should be
+ * idempotent.
  */
 void
 addPayloadToPacketConversionStep(PayloadToPacketConversionStep step)
@@ -117,6 +118,10 @@
         auto pkt = extension->getPacket();
         // Sync the address which could have changed.
         pkt->setAddr(trans.get_address());
+        // Apply all conversion steps necessary in this specific setup.
+        for (auto &step : extraPayloadToPacketSteps) {
+            step(pkt, trans);
+        }
         return std::make_pair(pkt, false);
     }