scc  2024.06
SystemC components library
axi_ace_lwtr.cpp
1 /*
2  * Copyright 2020 Arteris IP
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 #include <axi/axi_tlm.h>
18 #include <tlm/scc/tlm_id.h>
19 #include <tlm/scc/scv/tlm_extension_recording_registry.h>
20 #include <tlm/scc/lwtr/lwtr4tlm2_extension_registry.h>
21 
22 namespace lwtr {
23 template <class Archive> void record(Archive &ar, tlm::scc::tlm_id_extension const& e) {ar & field("uid", e.id);}
24 template <class Archive> void record(Archive &ar, axi::axi3_extension const& e) {
25  ar & field("id", e.get_id());
26  ar & field("user[CTRL]", e.get_user(axi::common::id_type::CTRL));
27  ar & field("user[DATA]", e.get_user(axi::common::id_type::DATA));
28  ar & field("user[RESP]", e.get_user(axi::common::id_type::RESP));
29  ar & field("length", e.get_length());
30  ar & field("size", e.get_size());
31  ar & field("burst", to_char(e.get_burst()));
32  ar & field("prot", e.get_prot());
33  ar & field("exclusive", e.is_exclusive() ? "true" : "false");
34  ar & field("cache", e.get_cache());
35  ar & field("cache_bufferable", e.is_bufferable());
36  ar & field("cache_cacheable", e.is_cacheable());
37  ar & field("cache_read_alloc", e.is_read_allocate());
38  ar & field("cache_write_alloc", e.is_write_allocate());
39  ar & field("qos", e.get_qos());
40  ar & field("region", e.get_region());
41 }
42 
43 template <class Archive> void record(Archive &ar, axi::axi4_extension const& e) {
44  ar & field("id", e.get_id());
45  ar & field("user[CTRL]", e.get_user(axi::common::id_type::CTRL));
46  ar & field("user[DATA]", e.get_user(axi::common::id_type::DATA));
47  ar & field("user[RESP]", e.get_user(axi::common::id_type::RESP));
48  ar & field("length", e.get_length());
49  ar & field("size", e.get_size());
50  ar & field("burst", to_char(e.get_burst()));
51  ar & field("prot", e.get_prot());
52  ar & field("exclusive", e.is_exclusive() ? "true" : "false");
53  ar & field("cache", e.get_cache());
54  ar & field("cache_bufferable", e.is_bufferable());
55  ar & field("cache_modifiable", e.is_modifiable());
56  ar & field("cache_allocate", e.is_allocate());
57  ar & field("cache_other_alloc", e.is_other_allocate());
58  ar & field("qos", e.get_qos());
59  ar & field("region", e.get_region());
60 }
61 
62 template <class Archive> void record(Archive &ar, axi::ace_extension const& e) {
63  ar & field("id", e.get_id());
64  ar & field("user[CTRL]", e.get_user(axi::common::id_type::CTRL));
65  ar & field("user[DATA]", e.get_user(axi::common::id_type::DATA));
66  ar & field("user[RESP]", e.get_user(axi::common::id_type::RESP));
67  ar & field("length", e.get_length());
68  ar & field("size", e.get_size());
69  ar & field("burst", to_char(e.get_burst()));
70  ar & field("prot", e.get_prot());
71  ar & field("exclusive", e.is_exclusive() ? "true" : "false");
72  ar & field("cache", e.get_cache());
73  ar & field("cache_bufferable", e.is_bufferable());
74  ar & field("cache_modifiable", e.is_modifiable());
75  ar & field("cache_write_alloc", e.is_write_allocate());
76  ar & field("cache_read_alloc", e.is_read_allocate());
77  ar & field("qos", e.get_qos());
78  ar & field("region", e.get_region());
79  ar & field("domain", to_char(e.get_domain()));
80  ar & field("snoop", to_char(e.get_snoop()));
81  ar & field("barrier", to_char(e.get_barrier()));
82  ar & field("unique", e.get_unique());
83 }
84 
85 }
86 
87 namespace axi {
88 namespace lwtr {
89 namespace {
90 const std::array<std::string, 3> cmd2char{{"tlm::TLM_READ_COMMAND", "tlm::TLM_WRITE_COMMAND", "tlm::TLM_IGNORE_COMMAND"}};
91 const std::array<std::string, 7> resp2char{
92  {"tlm::TLM_OK_RESPONSE", "tlm::TLM_INCOMPLETE_RESPONSE", "tlm::TLM_GENERIC_ERROR_RESPONSE", "tlm::TLM_ADDRESS_ERROR_RESPONSE", "tlm::TLM_COMMAND_ERROR_RESPONSE", "tlm::TLM_BURST_ERROR_RESPONSE", "tlm::TLM_BYTE_ENABLE_ERROR_RESPONSE"}};
93 const std::array<std::string, 3> gp_option2char{{"tlm::TLM_MIN_PAYLOAD", "tlm::TLM_FULL_PAYLOAD", "tlm::TLM_FULL_PAYLOAD_ACCEPTED"}};
94 const std::array<std::string, 5> phase2char{{"tlm::UNINITIALIZED_PHASE", "tlm::BEGIN_REQ", "tlm::END_REQ", "tlm::BEGIN_RESP", "tlm::END_RESP"}};
95 const std::array<std::string, 4> dmi2char{
96  {"tlm::DMI_ACCESS_NONE", "tlm::DMI_ACCESS_READ", "tlm::DMI_ACCESS_WRITE", "tlm::DMI_ACCESS_READ_WRITE"}};
97 const std::array<std::string, 3> sync2char{{"tlm::TLM_ACCEPTED", "tlm::TLM_UPDATED", "tlm::TLM_COMPLETED"}};
98 } // namespace
99 
101  void recordBeginTx(::lwtr::tx_handle& handle, tlm::tlm_base_protocol_types::tlm_payload_type& trans) override {
102  if(auto* ext = trans.get_extension<tlm::scc::tlm_id_extension>())
103  handle.record_attribute("trans", *ext);
104  }
105  void recordEndTx(::lwtr::tx_handle& handle, tlm::tlm_base_protocol_types::tlm_payload_type& trans) override {
106  }
107 };
108 
110  void recordBeginTx(::lwtr::tx_handle& handle, axi_protocol_types::tlm_payload_type& trans) override {
111  if(auto* ext = trans.get_extension<axi3_extension>())
112  handle.record_attribute("trans.axi3", *ext);
113  }
114  void recordEndTx(::lwtr::tx_handle& handle, axi_protocol_types::tlm_payload_type& trans) override {
115  if(auto* ext = trans.get_extension<axi3_extension>())
116  handle.record_attribute("trans.axi3.resp", to_char(ext->get_resp()));
117  }
118 };
119 
121  void recordBeginTx(::lwtr::tx_handle& handle, axi_protocol_types::tlm_payload_type& trans) override {
122  if(auto* ext = trans.get_extension<axi4_extension>())
123  handle.record_attribute("trans.axi4", *ext);
124  }
125  void recordEndTx(::lwtr::tx_handle& handle, axi_protocol_types::tlm_payload_type& trans) override {
126  if(auto* ext = trans.get_extension<axi4_extension>())
127  handle.record_attribute("trans.axi4.resp", to_char(ext->get_resp()));
128  }
129 };
130 
132  void recordBeginTx(::lwtr::tx_handle& handle, axi_protocol_types::tlm_payload_type& trans) override {
133  if(auto* ext = trans.get_extension<ace_extension>())
134  handle.record_attribute("trans.ace", *ext);
135  }
136  void recordEndTx(::lwtr::tx_handle& handle, axi_protocol_types::tlm_payload_type& trans) override {
137  if(auto* ext = trans.get_extension<ace_extension>()) {
138  handle.record_attribute("trans.ace.resp", to_char(ext->get_resp()));
139  handle.record_attribute("trans.ace.cresp_PassDirty", ext->is_pass_dirty());
140  handle.record_attribute("trans.ace.cresp_IsShared", ext->is_shared());
141  handle.record_attribute("trans.ace.cresp_SnoopDataTransfer", ext->is_snoop_data_transfer());
142  handle.record_attribute("trans.ace.cresp_SnoopError", ext->is_snoop_error());
143  handle.record_attribute("trans.ace.cresp_SnoopWasUnique", ext->is_snoop_was_unique());
144  }
145  }
146 };
147 
148 //using namespace tlm::scc::scv;
149 #if defined(__GNUG__)
150 __attribute__((constructor))
151 #endif
152 bool register_extensions() {
153  tlm::scc::tlm_id_extension ext(nullptr); // NOLINT
155  ext.ID, new axi::lwtr::tlm_id_ext_recording()) ; // NOLINT
156  axi::axi3_extension ext3; // NOLINT
158  ext3.ID, new axi::lwtr::axi3_ext_recording()); // NOLINT
159  axi::axi4_extension ext4; // NOLINT
161  ext4.ID, new axi::lwtr::axi4_ext_recording()); // NOLINT
162  axi::ace_extension extace; // NOLINT
164  extace.ID, new axi::lwtr::ace_ext_recording()); // NOLINT
165  return true; // NOLINT
166 }
167 bool registered = register_extensions();
168 
169 } // namespace lwtr
170 } // namespace axi
The TLM transaction extensions recorder interface.
The TLM transaction extensions recorder registry.
const char * to_char(E t)
TLM2.0 components modeling AHB.
Definition: axi_initiator.h:30
const char * to_char(E t)
bool get_unique() const
get the AxUNIQUE value return the unique value
Definition: axi_tlm.h:1527
bar_e get_barrier() const
get the AxBAR value return the barrier value
Definition: axi_tlm.h:1523
snoop_e get_snoop() const
get the AxSNOOP value return the snoop value
Definition: axi_tlm.h:1519
domain_e get_domain() const
get the AxDOMAIN value return the domain value
Definition: axi_tlm.h:1515
bool is_bufferable() const
get the bufferable bit of AxCACHE (AxCACHE[0]) return the bufferable bit
Definition: axi_tlm.h:1340
bool is_read_allocate() const
get the read_allocate bit of AxCACHE (AxCACHE[3]) return the read_allocate bit
Definition: axi_tlm.h:1367
bool is_exclusive() const
get the exclusive bit of AxLOCK (AxLOCK[0]) return the exclusive bit
Definition: axi_tlm.h:1314
bool is_write_allocate() const
get the write_allocate bit of AxCACHE (AxCACHE[2]) return the write_allocate bit
Definition: axi_tlm.h:1358
bool is_cacheable() const
get the cacheable bit of AxCACHE (AxCACHE[1]) return the cacheable bit
Definition: axi_tlm.h:1349
bool is_modifiable() const
get the modifiable bit of AxCACHE (AxCACHE[1]) return the modifiable bit
Definition: axi_tlm.h:1389
bool is_allocate() const
get the write allocate/read other allocate bit of AxCACHE (AxCACHE[3]) return the write_other_allocat...
Definition: axi_tlm.h:1398
bool is_bufferable() const
get the bufferable bit of AxCACHE (AxCACHE[0]) return the bufferable bit
Definition: axi_tlm.h:1380
bool is_exclusive() const
get the exclusive bit of AxLOCK (AxLOCK[0]) return the exclusive bit
Definition: axi_tlm.h:1371
bool is_write_allocate() const
get the write allocate/read other allocate bit of AxCACHE (AxCACHE[3]) return the write_other_allocat...
Definition: axi_tlm.h:1425
bool is_read_allocate() const
get the read allocate/write other allocate bit of AxCACHE (AxCACHE[2]) return the read_other_allocate...
Definition: axi_tlm.h:1434
bool is_other_allocate() const
get the read allocate/write other allocate bit of AxCACHE (AxCACHE[2]) return the read_other_allocate...
Definition: axi_tlm.h:1407
unsigned int get_user(id_type chnl) const
Definition: axi_tlm.h:1303
unsigned int get_id() const
Definition: axi_tlm.h:1299
burst_e get_burst() const
get the AxBURST value,
Definition: axi_tlm.h:1465
uint8_t get_length() const
get the AxLEN value of the transaction, the value denotes the burst length - 1
Definition: axi_tlm.h:1454
uint8_t get_region() const
get the AxREGION value
Definition: axi_tlm.h:1504
uint8_t get_qos() const
get the AxQOS (quality of service) value
Definition: axi_tlm.h:1500
uint8_t get_cache() const
get the AxCACHE value as POD
Definition: axi_tlm.h:1511
uint8_t get_prot() const
set the AxPROT value as POD, only values from 0...7 are allowed
Definition: axi_tlm.h:1472
uint8_t get_size() const
set the AxSIZE value of the transaction
Definition: axi_tlm.h:1461