16#ifndef SIMICS_SYSTEMC_TLM2SIMICS_GASKET_H
17#define SIMICS_SYSTEMC_TLM2SIMICS_GASKET_H
21#include <tlm_utils/simple_target_socket.h>
45template<
unsigned int BUSWIDTH = 32,
46 typename TYPES = tlm::tlm_base_protocol_types>
50 const simics::ConfObjectRef &obj)
51 : simics_obj_(obj), socket_(
"target_socket"),
54 initiator_socket_(NULL) {
55 FATAL_ERROR_IF(!obj,
"Must provide a valid Simics object");
59 socket_.register_b_transport(
this, &Gasket::b_transport);
60 socket_.register_get_direct_mem_ptr(
this, &Gasket::get_direct_mem_ptr);
61 socket_.register_transport_dbg(
this, &Gasket::transport_dbg);
68 delete transaction_handler_;
72 template <
typename Socket>
75 initiator_socket_ = &sock;
82 delete transaction_handler_;
87 sc_dt::uint64 end_range)
override {
88 socket_->invalidate_direct_mem_ptr(start_range, end_range);
91 return initiator_socket_;
97 return transaction_handler_;
102 socket_.register_nb_transport_fw(
this, &Gasket::nb_transport_fw);
106 void execute_transaction(tlm::tlm_generic_payload &trans,
109 trans.set_response_status(tlm::TLM_OK_RESPONSE);
110 tlm::tlm_response_status status = tlm::TLM_INCOMPLETE_RESPONSE;
113 trans.set_extension(&nb_ext_);
122 trans.clear_extension(&nb_ext_);
128 if (trans.get_response_status() != status &&
129 status != tlm::TLM_OK_RESPONSE) {
130 const char *msg =
"Gasket transaction error";
132 case tlm::TLM_INCOMPLETE_RESPONSE: {
133 msg =
"Gasket did not attempt to execute the command";
136 case tlm::TLM_ADDRESS_ERROR_RESPONSE: {
137 msg =
"Gasket was unable to act on the address attribute, "
138 "or address out-of-range";
141 case tlm::TLM_COMMAND_ERROR_RESPONSE: {
142 msg =
"Gasket was unable to execute the command";
145 case tlm::TLM_BURST_ERROR_RESPONSE: {
146 msg =
"Gasket was unable to act on the data length or "
150 case tlm::TLM_BYTE_ENABLE_ERROR_RESPONSE: {
151 msg =
"Gasket was unable to act on the byte enable";
154 case tlm::TLM_GENERIC_ERROR_RESPONSE: {
160 SIM_LOG_SPEC_VIOLATION(1, simics_obj_, 0,
"%s", msg);
162 trans.set_response_status(status);
166 void b_transport(tlm::tlm_generic_payload &trans,
167 sc_core::sc_time &local_time_offset) {
168 if (trans.get_byte_enable_ptr() != NULL &&
175 if (local_time_offset.value() > 0) {
177 wait(local_time_offset);
179 local_time_offset = sc_core::SC_ZERO_TIME;
182 execute_transaction(trans,
false);
185 unsigned int transport_dbg(tlm::tlm_generic_payload &trans) {
186 ProcessStackHandler pstack(internal());
190 bool get_direct_mem_ptr(tlm::tlm_generic_payload &trans,
191 tlm::tlm_dmi &dmi_data) {
192 ProcessStackHandler pstack(internal());
198 virtual tlm::tlm_sync_enum nb_transport_fw(
199 tlm::tlm_generic_payload &trans,
200 tlm::tlm_phase &phase,
201 sc_core::sc_time &local_time_offset) {
202 if (phase == tlm::END_RESP) {
203 trans.set_response_status(tlm::TLM_OK_RESPONSE);
204 return tlm::TLM_COMPLETED;
207 if (phase != tlm::BEGIN_REQ) {
208 SIM_LOG_SPEC_VIOLATION(
210 "Gasket was unable to execute the command (invalid phase)");
211 trans.set_response_status(tlm::TLM_COMMAND_ERROR_RESPONSE);
213 return tlm::TLM_COMPLETED;
216 if (trans.get_byte_enable_ptr() != NULL &&
218 SIM_LOG_SPEC_VIOLATION(
220 "Gasket was unable to execute the command (byte enable)");
221 trans.set_response_status(tlm::TLM_BYTE_ENABLE_ERROR_RESPONSE);
223 return tlm::TLM_COMPLETED;
226 execute_transaction(trans,
true);
227 if (trans.get_response_status() == tlm::TLM_INCOMPLETE_RESPONSE) {
228 SIM_LOG_INFO(3, simics_obj_, 0,
"Gasket deferred the transaction");
229 return tlm::TLM_ACCEPTED;
231 return tlm::TLM_COMPLETED;
234 InternalInterface *internal() {
236 Adapter *adapter = simics::from_obj<Adapter>(simics_obj_);
238 internal_ = adapter->internal();
244 simics::ConfObjectRef simics_obj_;
245 tlm_utils::simple_target_socket<Gasket, BUSWIDTH, TYPES> socket_;
248 TransactionHandlerInterface *transaction_handler_;
249 NullSimulation null_simulation_;
250 InternalInterface *internal_;
251 sc_core::sc_object *initiator_socket_;
253 NonBlockingTlmExtension nb_ext_;
Utility class that handles the context switching, using RAII methodology.
Definition: context.h:33
Definition: internal_interface.h:25
Definition: process_stack_handler.h:28
Interface used by tlm2simics gaskets, implemented by Gasket base class.
Definition: gasket_interface.h:30
Implements core functionality for receiving a TLM2 transaction over a socket.
Definition: gasket.h:47
Gasket(sc_core::sc_module_name, const simics::ConfObjectRef &obj)
Definition: gasket.h:49
void set_transaction_handler(TransactionHandlerInterface *transaction_handler) override
Target object in Simics side receiving the TLM transaction.
Definition: gasket.h:79
void invalidate_direct_mem_ptr(sc_dt::uint64 start_range, sc_dt::uint64 end_range) override
Calling this method will end up calling the same method on the target socket, that will forward the c...
Definition: gasket.h:86
std::string gasket_name() const override
Definition: gasket.h:93
virtual ~Gasket()
Definition: gasket.h:66
sc_core::sc_object * get_initiator_socket() const override
Definition: gasket.h:90
void bind(Socket &sock)
Definition: gasket.h:73
void register_nb_transport_fw()
For gaskets support non-blocking transport, call this function to register the non-blocking transport...
Definition: gasket.h:101
void init(InternalInterface *internal)
Definition: gasket.h:63
TransactionHandlerInterface * transaction_handler() override
Definition: gasket.h:96
Utility class that counts the number of instances.
Definition: null_transaction_handler.h:33
Interface used by Gasket, implemented by protocol specific transaction handlers.
Definition: transaction_handler_interface.h:36
virtual unsigned int debug_transaction(ConfObjectRef &simics_obj, tlm::tlm_generic_payload *trans)=0
virtual void update_dmi_allowed(ConfObjectRef &simics_obj, tlm::tlm_generic_payload *trans)=0
virtual bool byte_enable_supported(ConfObjectRef &simics_obj, tlm::tlm_generic_payload *trans)=0
virtual bool get_direct_mem_ptr(ConfObjectRef &simics_obj, tlm::tlm_generic_payload &trans, tlm::tlm_dmi &dmi_data)=0
virtual tlm::tlm_response_status simics_transaction(ConfObjectRef &simics_obj, tlm::tlm_generic_payload *trans)=0
AdapterNonCheckpointable Adapter
Definition: adapter.h:329