scc  2024.06
SystemC components library
tlm_recorder.cpp
1 /*******************************************************************************
2  * Copyright 2016-2022 MINRES Technologies GmbH
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *******************************************************************************/
16 
17 #ifndef SC_INCLUDE_DYNAMIC_PROCESSES
18 #define SC_INCLUDE_DYNAMIC_PROCESSES
19 #endif
20 #include "tlm_recorder.h"
21 #include "tlm_extension_recording_registry.h"
22 #include <tlm/scc/tlm_id.h>
23 
24 namespace tlm {
25 namespace scc {
26 namespace scv {
27 namespace {
28 const std::array<std::string, 3> cmd2char{{"READ", "WRITE", "IGNORE"}};
29 const std::array<std::string, 7> resp2char{
30  {"OK", "INCOMPLETE", "GENERIC_ERROR", "ADDRESS_ERROR", "COMMAND_ERROR", "BURST_ERROR", "BYTE_ENABLE_ERROR"}};
31 const std::array<std::string, 3> gp_option2char{{"MIN_PAYLOAD", "FULL_PAYLOAD", "FULL_PAYLOAD_ACCEPTED"}};
32 const std::array<std::string, 5> phase2char{{"UNINITIALIZED_PHASE", "BEGIN_REQ", "END_REQ", "BEGIN_RESP", "END_RESP"}};
33 const std::array<std::string, 4> dmi2char{{"DMI_ACCESS_NONE", "DMI_ACCESS_READ", "DMI_ACCESS_WRITE", "DMI_ACCESS_READ_WRITE"}};
34 const std::array<std::string, 3> sync2char{{"ACCEPTED", "UPDATED", "COMPLETED"}};
35 
36 } // namespace
37 void record(SCVNS scv_tr_handle& handle, tlm::tlm_generic_payload& o) {
38  handle.record_attribute("trans.ptr", reinterpret_cast<uintptr_t>(&o));
39  handle.record_attribute("trans.address", o.get_address());
40  handle.record_attribute("trans.cmd", cmd2char.at(o.get_command()));
41  handle.record_attribute("trans.data_ptr", o.get_data_ptr());
42  handle.record_attribute("trans.data_length", o.get_data_length());
43  handle.record_attribute("trans.response", resp2char.at(1 - o.get_response_status()));
44  handle.record_attribute("trans.dmi_allowed", o.is_dmi_allowed());
45  handle.record_attribute("trans.byte_enable", o.get_byte_enable_ptr());
46  handle.record_attribute("trans.byte_enable_length", o.get_byte_enable_length());
47  handle.record_attribute("trans.streaming_width", o.get_streaming_width());
48  handle.record_attribute("trans.gp_option", gp_option2char.at(o.get_gp_option()));
49  if(o.get_data_length() && o.get_data_length() < 9 && o.get_data_ptr()) {
50  uint64_t buf = 0;
51  memcpy(&buf, o.get_data_ptr(), o.get_data_length());
52  handle.record_attribute("trans.data_value", buf);
53  }
54 }
55 void record(SCVNS scv_tr_handle& handle, tlm::tlm_phase& o) {
56  unsigned id = o;
57  if(id < phase2char.size())
58  handle.record_attribute("phase", phase2char[id]);
59  else
60  handle.record_attribute("phase_id", id);
61 }
62 void record(SCVNS scv_tr_handle& handle, tlm::tlm_sync_enum o) { handle.record_attribute("tlm_sync", sync2char.at(o)); }
63 void record(SCVNS scv_tr_handle& handle, tlm::tlm_dmi& o) {
64  handle.record_attribute("trans.dmi_ptr", o.get_dmi_ptr());
65  handle.record_attribute("trans.start_address", o.get_start_address());
66  handle.record_attribute("trans.end_address", o.get_end_address());
67  handle.record_attribute("trans.granted_access", dmi2char.at(o.get_granted_access()));
68  handle.record_attribute("trans.read_latency", o.get_read_latency().to_string());
69  handle.record_attribute("trans.write_latency", o.get_write_latency().to_string());
70 }
71 
72 class tlm_id_ext_recording : public tlm_extensions_recording_if<tlm::tlm_base_protocol_types> {
73 
74  void recordBeginTx(SCVNS scv_tr_handle& handle, tlm::tlm_base_protocol_types::tlm_payload_type& trans) override {
75  if(auto ext = trans.get_extension<tlm_id_extension>()) {
76  handle.record_attribute("trans.uid", ext->id);
77  }
78  }
79 
80  void recordEndTx(SCVNS scv_tr_handle& handle, tlm::tlm_base_protocol_types::tlm_payload_type& trans) override {}
81 };
82 using namespace tlm::scc::scv;
83 #if defined(__GNUG__)
84 __attribute__((constructor))
85 #endif
86 bool register_extensions() {
87  tlm::scc::tlm_id_extension ext(nullptr); // NOLINT
89  return true; // NOLINT
90 }
91 bool registered = register_extensions();
92 
93 } // namespace scv
94 } // namespace scc
95 } // namespace tlm
The TLM transaction extensions recorder registry.
The TLM transaction extensions recorder interface.
SCC TLM utilities.
SCC SCV4TLM classes and functions.
SystemC TLM.
Definition: cxs_tlm.h:69