scc 2025.09
SystemC components library
tlm_gp_data.h
1/*******************************************************************************
2 * Copyright 2016, 2017, 2020 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 TLM_GP_DATA_H_
18#define TLM_GP_DATA_H_
19
20#include <assert.h>
21#include <tlm>
22
24namespace tlm {
26namespace scc {
28namespace scv {
29
30class tlm_gp_data {
31public:
32 //---------------
33 // Constructors
34 //---------------
35
36 explicit tlm_gp_data(tlm::tlm_generic_payload const& o)
37 : address(o.get_address())
38 , command(o.get_command())
39 , data(o.get_data_ptr())
40 , data_length(o.get_data_length())
41 , response_status(o.get_response_status())
42 , dmi_allowed(o.is_dmi_allowed())
43 , byte_enable(o.get_byte_enable_ptr())
44 , byte_enable_length(o.get_byte_enable_length())
45 , streaming_width(o.get_streaming_width())
46 , gp_option(o.get_gp_option())
47 , uid(reinterpret_cast<uintptr_t>(&o)) {}
48
49 tlm_gp_data() = default;
50
51 tlm_gp_data(tlm_gp_data const& x) = default;
52
53 tlm_gp_data(tlm_gp_data&& x) = default;
54
55 tlm_gp_data& operator=(tlm_gp_data const& x) = default;
56
57 tlm_gp_data& operator=(tlm_gp_data&& x) = default;
58
59 //--------------
60 // Destructor
61 //--------------
62 virtual ~tlm_gp_data() {}
63
64 void reset() {
65 // should the other members be reset too?
66 gp_option = tlm::TLM_MIN_PAYLOAD;
67 };
68
74 void update_generic_payload(tlm::tlm_generic_payload& other, bool transfer_ownership = false) {
75 other.set_command(command);
76 other.set_address(address);
77 other.set_data_length(data_length);
78 other.set_byte_enable_length(byte_enable_length);
79 other.set_streaming_width(streaming_width);
80 other.set_gp_option(gp_option);
81 other.set_dmi_allowed(dmi_allowed);
82 other.set_response_status(response_status);
83 if(transfer_ownership) {
84 other.set_byte_enable_ptr(byte_enable);
85 other.set_data_ptr(data);
86 byte_enable = nullptr;
87 data = nullptr;
88 }
89 }
90
91 std::string get_response_string() const {
92 switch(response_status) {
93 case tlm::TLM_OK_RESPONSE:
94 return "TLM_OK_RESPONSE";
95 case tlm::TLM_INCOMPLETE_RESPONSE:
96 return "TLM_INCOMPLETE_RESPONSE";
97 case tlm::TLM_GENERIC_ERROR_RESPONSE:
98 return "TLM_GENERIC_ERROR_RESPONSE";
99 case tlm::TLM_ADDRESS_ERROR_RESPONSE:
100 return "TLM_ADDRESS_ERROR_RESPONSE";
101 case tlm::TLM_COMMAND_ERROR_RESPONSE:
102 return "TLM_COMMAND_ERROR_RESPONSE";
103 case tlm::TLM_BURST_ERROR_RESPONSE:
104 return "TLM_BURST_ERROR_RESPONSE";
105 case tlm::TLM_BYTE_ENABLE_ERROR_RESPONSE:
106 return "TLM_BYTE_ENABLE_ERROR_RESPONSE";
107 }
108 return "TLM_UNKNOWN_RESPONSE";
109 }
110
111 uint64_t get_data_value() {
112 uint64_t buf = 0;
113 // FIXME: this is endianess dependent
114 for(size_t i = 0; i < data_length; i++)
115 buf += (*(data + i)) << i * 8;
116 return buf;
117 }
118 // attributes are public so that scv_extension mechanism works
119 sc_dt::uint64 address{0};
120 tlm::tlm_command command{tlm::TLM_IGNORE_COMMAND};
121 unsigned char* data{nullptr};
122 unsigned int data_length{0};
123 tlm::tlm_response_status response_status{tlm::TLM_INCOMPLETE_RESPONSE};
124 bool dmi_allowed{false};
125 unsigned char* byte_enable{nullptr};
126 unsigned int byte_enable_length{0};
127 unsigned int streaming_width{0};
128 tlm::tlm_gp_option gp_option{tlm::TLM_MIN_PAYLOAD};
129 uintptr_t uid{0};
130};
131
132class tlm_dmi_data {
133public:
134 tlm_dmi_data() = default;
135
136 tlm_dmi_data(tlm::tlm_dmi& dmi_data)
137 : dmi_ptr(dmi_data.get_dmi_ptr())
138 , dmi_start_address(dmi_data.get_start_address())
139 , dmi_end_address(dmi_data.get_end_address())
140 , dmi_access(dmi_data.get_granted_access())
141 , dmi_read_latency(dmi_data.get_read_latency().value())
142 , dmi_write_latency(dmi_data.get_write_latency().value()) {}
143 //--------------
144 // Destructor
145 //--------------
146 virtual ~tlm_dmi_data() {}
147
148 unsigned char* dmi_ptr{nullptr};
149 sc_dt::uint64 dmi_start_address{0};
150 sc_dt::uint64 dmi_end_address{0};
151 tlm::tlm_dmi::dmi_access_e dmi_access{tlm::tlm_dmi::DMI_ACCESS_NONE};
152 sc_dt::uint64 dmi_read_latency{0};
153 sc_dt::uint64 dmi_write_latency{0};
154};
155
156enum tlm_phase_enum {
157 UNINITIALIZED_PHASE = 0,
158 BEGIN_REQ = 1,
159 END_REQ,
160 BEGIN_RESP,
161 END_RESP,
162 CUSTOM1,
163 CUSTOM2,
164 CUSTOM3,
165 CUSTOM4,
166 CUSTOM5,
167 CUSTOM6
168};
169
170} // namespace scv
171} // namespace scc
172} // namespace tlm
173#endif /* TLM_GP_DATA_H_ */
void update_generic_payload(tlm::tlm_generic_payload &other, bool transfer_ownership=false)
Definition tlm_gp_data.h:74
SCC SCV4TLM classes and functions.
SCC TLM utilities.
Definition axis_tlm.h:56
SystemC TLM.
Definition dmi_mgr.h:19