16#ifndef SIMICS_SYSTEMC_TLM2SIMICS_GASKET_H
17#define SIMICS_SYSTEMC_TLM2SIMICS_GASKET_H
21#include <tlm_utils/simple_target_socket.h>
61template<
unsigned int BUSWIDTH = 32,
62 typename TYPES = tlm::tlm_base_protocol_types>
66 const simics::ConfObjectRef &obj)
67 : simics_obj_(obj), socket_(
"target_socket"),
70 initiator_socket_(NULL) {
71 FATAL_ERROR_IF(!obj,
"Must provide a valid Simics object");
75 socket_.register_b_transport(
this, &Gasket::b_transport);
76 socket_.register_get_direct_mem_ptr(
this, &Gasket::get_direct_mem_ptr);
77 socket_.register_transport_dbg(
this, &Gasket::transport_dbg);
84 delete transaction_handler_;
88 template <
typename Socket>
91 initiator_socket_ = &sock;
98 delete transaction_handler_;
103 sc_dt::uint64 end_range) {
104 socket_->invalidate_direct_mem_ptr(start_range, end_range);
107 return initiator_socket_;
113 return transaction_handler_;
118 socket_.register_nb_transport_fw(
this, &Gasket::nb_transport_fw);
122 void execute_transaction(tlm::tlm_generic_payload &trans,
125 trans.set_response_status(tlm::TLM_OK_RESPONSE);
126 tlm::tlm_response_status status = tlm::TLM_INCOMPLETE_RESPONSE;
129 trans.set_extension(&nb_ext_);
138 trans.clear_extension(&nb_ext_);
144 if (trans.get_response_status() != status &&
145 status != tlm::TLM_OK_RESPONSE) {
146 const char *msg =
"Gasket transaction error";
148 case tlm::TLM_INCOMPLETE_RESPONSE: {
149 msg =
"Gasket did not attempt to execute the command";
152 case tlm::TLM_ADDRESS_ERROR_RESPONSE: {
153 msg =
"Gasket was unable to act on the address attribute, "
154 "or address out-of-range";
157 case tlm::TLM_COMMAND_ERROR_RESPONSE: {
158 msg =
"Gasket was unable to execute the command";
161 case tlm::TLM_BURST_ERROR_RESPONSE: {
162 msg =
"Gasket was unable to act on the data length or "
166 case tlm::TLM_BYTE_ENABLE_ERROR_RESPONSE: {
167 msg =
"Gasket was unable to act on the byte enable";
170 case tlm::TLM_GENERIC_ERROR_RESPONSE: {
176 SIM_LOG_SPEC_VIOLATION(1, simics_obj_, 0,
"%s", msg);
178 trans.set_response_status(status);
182 void b_transport(tlm::tlm_generic_payload &trans,
183 sc_core::sc_time &local_time_offset) {
184 if (trans.get_byte_enable_ptr() != NULL &&
191 if (local_time_offset.value() > 0) {
193 wait(local_time_offset);
195 local_time_offset = sc_core::SC_ZERO_TIME;
198 execute_transaction(trans,
false);
201 unsigned int transport_dbg(tlm::tlm_generic_payload &trans) {
202 ProcessStackHandler pstack(internal());
206 bool get_direct_mem_ptr(tlm::tlm_generic_payload &trans,
207 tlm::tlm_dmi &dmi_data) {
208 ProcessStackHandler pstack(internal());
214 virtual tlm::tlm_sync_enum nb_transport_fw(
215 tlm::tlm_generic_payload &trans,
216 tlm::tlm_phase &phase,
217 sc_core::sc_time &local_time_offset) {
218 if (phase == tlm::END_RESP) {
219 trans.set_response_status(tlm::TLM_OK_RESPONSE);
220 return tlm::TLM_COMPLETED;
223 if (phase != tlm::BEGIN_REQ) {
224 SIM_LOG_SPEC_VIOLATION(
226 "Gasket was unable to execute the command (invalid phase)");
227 trans.set_response_status(tlm::TLM_COMMAND_ERROR_RESPONSE);
229 return tlm::TLM_COMPLETED;
232 if (trans.get_byte_enable_ptr() != NULL &&
234 SIM_LOG_SPEC_VIOLATION(
236 "Gasket was unable to execute the command (byte enable)");
237 trans.set_response_status(tlm::TLM_BYTE_ENABLE_ERROR_RESPONSE);
239 return tlm::TLM_COMPLETED;
242 execute_transaction(trans,
true);
243 if (trans.get_response_status() == tlm::TLM_INCOMPLETE_RESPONSE) {
244 SIM_LOG_INFO(3, simics_obj_, 0,
"Gasket deferred the transaction");
245 return tlm::TLM_ACCEPTED;
247 return tlm::TLM_COMPLETED;
250 InternalInterface *internal() {
253 SIM_object_data(simics_obj_));
255 internal_ = adapter->internal();
261 simics::ConfObjectRef simics_obj_;
262 tlm_utils::simple_target_socket<Gasket, BUSWIDTH, TYPES> socket_;
265 TransactionHandlerInterface *transaction_handler_;
266 NullSimulation null_simulation_;
267 InternalInterface *internal_;
268 sc_core::sc_object *initiator_socket_;
270 NonBlockingTlmExtension nb_ext_;
Utility class that handles the context switching, using RAII methodology.
Definition: context.h:33
Definition: internal_interface.h:25
virtual ProcessStackInterface * process_stack()=0
The process stack helps maintain a LIFO order of function calls that cross the SystemC/Simics border,...
Definition: process_stack_interface.h:27
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:63
Gasket(sc_core::sc_module_name, const simics::ConfObjectRef &obj)
Definition: gasket.h:65
virtual void invalidate_direct_mem_ptr(sc_dt::uint64 start_range, sc_dt::uint64 end_range)
Calling this method will end up calling the same method on the target socket, that will forward the c...
Definition: gasket.h:102
std::string gasket_name() const override
Definition: gasket.h:109
virtual ~Gasket()
Definition: gasket.h:82
sc_core::sc_object * get_initiator_socket() const override
Definition: gasket.h:106
void bind(Socket &sock)
Definition: gasket.h:89
virtual void set_transaction_handler(TransactionHandlerInterface *transaction_handler)
Target object in Simics side receiving the TLM transaction.
Definition: gasket.h:95
void register_nb_transport_fw()
For gaskets support non-blocking transport, call this function to register the non-blocking transport...
Definition: gasket.h:117
void init(InternalInterface *internal)
Definition: gasket.h:79
TransactionHandlerInterface * transaction_handler() override
Definition: gasket.h:112
Utility class that counts the number of instances.
Definition: null_transaction_handler.h:33
ProcessStackHandler(const ProcessStackHandler &)=delete
ProcessStackHandler(InternalInterface *internal)
Definition: gasket.h:41
ProcessStackHandler & operator=(const ProcessStackHandler &)=delete
virtual ~ProcessStackHandler()
Definition: gasket.h:47
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:340