gem5 v24.0.0.0
Loading...
Searching...
No Matches
gp.hh
Go to the documentation of this file.
1/*****************************************************************************
2
3 Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4 more contributor license agreements. See the NOTICE file distributed
5 with this work for additional information regarding copyright ownership.
6 Accellera licenses this file to you under the Apache License, Version 2.0
7 (the "License"); you may not use this file except in compliance with the
8 License. You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15 implied. See the License for the specific language governing
16 permissions and limitations under the License.
17
18 *****************************************************************************/
19
20#ifndef __SYSTEMC_EXT_TLM_CORE_2_GENERIC_PAYLOAD_GP_HH__
21#define __SYSTEMC_EXT_TLM_CORE_2_GENERIC_PAYLOAD_GP_HH__
22
23#include <typeinfo> // std::type_info
24
25#include "../../../utils/sc_report_handler.hh" // sc_assert
26#include "array.hh"
27
28namespace tlm
29{
30
31class tlm_generic_payload;
32
34{
35 public:
36 virtual void free(tlm_generic_payload *) = 0;
37 virtual ~tlm_mm_interface() {}
38};
39
40//---------------------------------------------------------------------------
41// Classes and helpers for the extension mechanism
42//---------------------------------------------------------------------------
43// Helper function:
44unsigned int max_num_extensions();
45
46// This class can be used for storing pointers to the extension classes, used
47// in tlm_generic_payload:
49{
50 public:
51 virtual tlm_extension_base *clone() const = 0;
52 virtual void free() { delete this; }
53 virtual void copy_from(tlm_extension_base const &) = 0;
54 protected:
56 static unsigned int register_extension(const std::type_info &);
57};
58
59// Base class for all extension classes, derive your extension class in
60// the following way:
61// class my_extension : public tlm_extension<my_extension> { ...
62// This triggers proper extension registration during C++ static
63// contruction time. my_extension::ID will hold the unique index in the
64// tlm_generic_payload::m_extensions array.
65template <typename T>
67{
68 public:
69 virtual tlm_extension_base *clone() const = 0;
70 virtual void copy_from(tlm_extension_base const &ext) = 0;
71 virtual ~tlm_extension() {}
72 const static unsigned int ID;
73};
74
75template <typename T>
76const unsigned int tlm_extension<T>::ID =
78
79//---------------------------------------------------------------------------
80// enumeration types
81//---------------------------------------------------------------------------
88
99
106
107#define TLM_BYTE_DISABLED 0x0
108#define TLM_BYTE_ENABLED 0xff
109
110//---------------------------------------------------------------------------
111// The generic payload class:
112//---------------------------------------------------------------------------
113
114extern template class tlm_array<tlm_extension_base *>;
115
117{
118 public:
121
122 void
124 {
125 sc_assert(m_mm != 0);
126 m_ref_count++;
127 }
128
129 void
131 {
132 sc_assert(m_mm != 0 && m_ref_count > 0);
133 if (--m_ref_count == 0)
134 m_mm->free(this);
135 }
136
137 int get_ref_count() const { return m_ref_count; }
138
139 void set_mm(tlm_mm_interface *mm) { m_mm = mm; }
140 bool has_mm() const { return m_mm != 0; }
141
142 void reset();
143
144 private:
145 // Disabled copy ctor and assignment operator.
148
149 public:
150 // Non-virtual deep-copying of the object.
151 void deep_copy_from(const tlm_generic_payload &other);
152
153 // To update the state of the original generic payload from a deep copy.
154 // Assumes that "other" was created from the original by calling
155 // deep_copy_from Argument use_byte_enable_on_read determines whether to
156 // use or ignores byte enables when copying back the data array on a read
157 // command.
158
159 void update_original_from(const tlm_generic_payload &other,
160 bool use_byte_enable_on_read=true);
161
162 void update_extensions_from(const tlm_generic_payload &other);
163
164 // Free all extensions. Useful when reusing a cloned transaction that
165 // doesn't have memory manager. Normal and sticky extensions are freed and
166 // extension array cleared.
167 void free_all_extensions();
168
169 virtual ~tlm_generic_payload();
170
171 //----------------
172 // API (including setters & getters).
173 //---------------
174
175 // Command related method.
176 bool is_read() const { return (m_command == TLM_READ_COMMAND); }
177 void set_read() { m_command = TLM_READ_COMMAND; }
178 bool is_write() const { return (m_command == TLM_WRITE_COMMAND); }
179 void set_write() { m_command = TLM_WRITE_COMMAND; }
180 tlm_command get_command() const { return m_command; }
181 void set_command(const tlm_command command) { m_command = command; }
182
183 // Address related methods.
184 sc_dt::uint64 get_address() const { return m_address; }
185 void set_address(const sc_dt::uint64 address) { m_address = address; }
186
187 // Data related methods.
188 unsigned char *get_data_ptr() const { return m_data; }
189 void set_data_ptr(unsigned char *data) { m_data = data; }
190
191 // Transaction length (in bytes) related methods.
192 unsigned int get_data_length() const { return m_length; }
193 void set_data_length(const unsigned int length) { m_length = length; }
194
195 // Response status related methods.
196 bool is_response_ok() const { return (m_response_status > 0); }
197 bool is_response_error() const { return (m_response_status <= 0); }
200 {
201 return m_response_status;
202 }
203 void
205 {
206 m_response_status = response_status;
207 }
208 std::string get_response_string() const;
209
210 // Streaming related methods.
211 unsigned int get_streaming_width() const { return m_streaming_width; }
212 void
213 set_streaming_width(const unsigned int streaming_width)
214 {
215 m_streaming_width = streaming_width;
216 }
217
218 // Byte enable related methods.
219 unsigned char *get_byte_enable_ptr() const { return m_byte_enable; }
220 void
221 set_byte_enable_ptr(unsigned char *byte_enable)
222 {
223 m_byte_enable = byte_enable;
224 }
225 unsigned int
227 {
228 return m_byte_enable_length;
229 }
230 void
231 set_byte_enable_length(const unsigned int byte_enable_length)
232 {
233 m_byte_enable_length = byte_enable_length;
234 }
235
236 // This is the "DMI-hint" a slave can set this to true if it
237 // wants to indicate that a DMI request would be supported:
238 void
239 set_dmi_allowed(bool dmi_allowed)
240 {
241 m_dmi = dmi_allowed;
242 }
243 bool
245 {
246 return m_dmi;
247 }
248
249 // Use full set of attributes in DMI/debug?
250 tlm_gp_option get_gp_option() const { return m_gp_option; }
251 void set_gp_option(const tlm_gp_option gp_opt) { m_gp_option = gp_opt; }
252
253 private:
254 /* --------------------------------------------------------------------- */
255 /* Generic Payload attributes: */
256 /* --------------------------------------------------------------------- */
257 /* - m_command : Type of transaction. Three values supported: */
258 /* - TLM_WRITE_COMMAND */
259 /* - TLM_READ_COMMAND */
260 /* - TLM_IGNORE_COMMAND */
261 /* - m_address : Transaction base address (byte-addressing). */
262 /* - m_data : When m_command = TLM_WRITE_COMMAND contains a */
263 /* pointer to the data to be written in the target.*/
264 /* When m_command = TLM_READ_COMMAND contains a */
265 /* pointer where to copy the data read from the */
266 /* target. */
267 /* - m_length : Total number of bytes of the transaction. */
268 /* - m_response_status : This attribute indicates whether an error has */
269 /* occurred during the transaction. */
270 /* Values supported are: */
271 /* - TLM_OK_RESP */
272 /* - TLM_INCOMPLETE_RESP */
273 /* - TLM_GENERIC_ERROR_RESP */
274 /* - TLM_ADDRESS_ERROR_RESP */
275 /* - TLM_COMMAND_ERROR_RESP */
276 /* - TLM_BURST_ERROR_RESP */
277 /* - TLM_BYTE_ENABLE_ERROR_RESP */
278 /* */
279 /* - m_byte_enable : It can be used to create burst transfers where */
280 /* the address increment between each beat is greater */
281 /* than the word length of each beat, or to place */
282 /* words in selected byte lanes of a bus. */
283 /* - m_byte_enable_length : For a read or a write command, the target */
284 /* interpret the byte enable length attribute as the */
285 /* number of elements in the bytes enable array. */
286 /* - m_streaming_width : */
287 /* --------------------------------------------------------------------- */
288
291 unsigned char *m_data;
292 unsigned int m_length;
294 bool m_dmi;
295 unsigned char *m_byte_enable;
297 unsigned int m_streaming_width;
299
300 public:
301 /* --------------------------------------------------------------------- */
302 /* Dynamic extension mechanism: */
303 /* --------------------------------------------------------------------- */
304 /* The extension mechanism is intended to enable initiator modules to */
305 /* optionally and transparently add data fields to the */
306 /* tlm_generic_payload. Target modules are free to check for extensions */
307 /* and may or may not react to the data in the extension fields. The */
308 /* definition of the extensions' semantics is solely in the */
309 /* responsibility of the user. */
310 /* */
311 /* The following rules apply: */
312 /* */
313 /* - Every extension class must be derived from tlm_extension, e.g.: */
314 /* class my_extension : public tlm_extension<my_extension> { ... } */
315 /* */
316 /* - A tlm_generic_payload object should be constructed after C++ */
317 /* static initialization time. This way it is guaranteed that the */
318 /* extension array is of sufficient size to hold all possible */
319 /* extensions. Alternatively, the initiator module can enforce a valid */
320 /* extension array size by calling the resize_extensions() method */
321 /* once before the first transaction with the payload object is */
322 /* initiated. */
323 /* */
324 /* - Initiators should use the the set_extension(e) or clear_extension(e)*/
325 /* methods for manipulating the extension array. The type of the */
326 /* argument must be a pointer to the specific registered extension */
327 /* type (my_extension in the above example) and is used to */
328 /* automatically locate the appropriate index in the array. */
329 /* */
330 /* - Targets can check for a specific extension by calling */
331 /* get_extension(e). e will point to zero if the extension is not */
332 /* present. */
333 /* */
334 /* --------------------------------------------------------------------- */
335
336 // Stick the pointer to an extension into the vector, return the
337 // previous value:
338 template <typename T>
339 T *
341 {
342 return static_cast<T *>(set_extension(T::ID, ext));
343 }
344
345 // Non-templatized version with manual index:
346 tlm_extension_base *set_extension(
347 unsigned int index, tlm_extension_base *ext);
348
349 // Stick the pointer to an extension into the vector, return the
350 // previous value and schedule its release.
351 template <typename T>
352 T *
354 {
355 return static_cast<T *>(set_auto_extension(T::ID, ext));
356 }
357
358 // Non-templatized version with manual index:
359 tlm_extension_base *set_auto_extension(
360 unsigned int index, tlm_extension_base *ext);
361
362 // Check for an extension, ext will point to 0 if not present.
363 template <typename T>
364 void get_extension(T *& ext) const { ext = get_extension<T>(); }
365 template <typename T>
366 T *
368 {
369 return static_cast<T*>(get_extension(T::ID));
370 }
371 // Non-templatized version with manual index:
372 tlm_extension_base *get_extension(unsigned int index) const;
373
374 // This call just removes the extension from the txn but does not
375 // call free() or tells the MM to do so it return false if there was
376 // active MM so you are now in an unsafe situation recommended use:
377 // when 100% sure there is no MM.
378 template <typename T>
379 void clear_extension(const T *ext) { clear_extension<T>(); }
380
381 // This call just removes the extension from the txn but does not
382 // call free() or tells the MM to do so it return false if there was
383 // active MM so you are now in an unsafe situation recommended use: when
384 // 100% sure there is no MM.
385 template <typename T>
387
388 // This call removes the extension from the txn and does call free() or
389 // tells the MM to do so when the txn is finally done recommended use:
390 // when not sure there is no MM.
391 template <typename T>
392 void release_extension(T *ext)
393 {
394 release_extension<T>();
395 }
396
397 // This call removes the extension from the txn and does call free() or
398 // tells the MM to do so when the txn is finally done recommended use:
399 // when not sure there is no MM
400 template <typename T>
402 {
403 release_extension(T::ID);
404 }
405
406 private:
407 // Non-templatized version with manual index
408 void clear_extension(unsigned int index);
409 // Non-templatized version with manual index
410 void release_extension(unsigned int index);
411
412 public:
413 // Make sure the extension array is large enough. Can be called once by
414 // an initiator module (before issuing the first transaction) to make
415 // sure that the extension array is of correct size. This is only needed
416 // if the initiator cannot guarantee that the generic payload object is
417 // allocated after C++ static construction time.
418 void resize_extensions();
419
420 private:
423 unsigned int m_ref_count;
424};
425
426} // namespace tlm
427
428#endif /* __SYSTEMC_EXT_TLM_CORE_2_GENERIC_PAYLOAD_GP_HH__ */
const char data[]
Definition mm.h:9
static unsigned int register_extension(const std::type_info &)
Definition gp.cc:91
virtual void free()
Definition gp.hh:52
virtual tlm_extension_base * clone() const =0
virtual void copy_from(tlm_extension_base const &)=0
virtual ~tlm_extension_base()
Definition gp.hh:55
static const unsigned int ID
Definition gp.hh:72
virtual tlm_extension_base * clone() const =0
virtual ~tlm_extension()
Definition gp.hh:71
virtual void copy_from(tlm_extension_base const &ext)=0
tlm_command m_command
Definition gp.hh:290
void set_data_ptr(unsigned char *data)
Definition gp.hh:189
bool is_write() const
Definition gp.hh:178
void set_gp_option(const tlm_gp_option gp_opt)
Definition gp.hh:251
unsigned char * get_data_ptr() const
Definition gp.hh:188
T * set_auto_extension(T *ext)
Definition gp.hh:353
bool is_read() const
Definition gp.hh:176
void set_dmi_allowed(bool dmi_allowed)
Definition gp.hh:239
void set_response_status(const tlm_response_status response_status)
Definition gp.hh:204
void release_extension()
Definition gp.hh:401
void set_byte_enable_length(const unsigned int byte_enable_length)
Definition gp.hh:231
void set_address(const sc_dt::uint64 address)
Definition gp.hh:185
tlm_array< tlm_extension_base * > m_extensions
Definition gp.hh:421
tlm_gp_option get_gp_option() const
Definition gp.hh:250
unsigned char * get_byte_enable_ptr() const
Definition gp.hh:219
bool is_response_ok() const
Definition gp.hh:196
tlm_mm_interface * m_mm
Definition gp.hh:422
T * get_extension() const
Definition gp.hh:367
void set_command(const tlm_command command)
Definition gp.hh:181
void release_extension(T *ext)
Definition gp.hh:392
unsigned int m_streaming_width
Definition gp.hh:297
tlm_response_status m_response_status
Definition gp.hh:293
sc_dt::uint64 get_address() const
Definition gp.hh:184
unsigned int get_byte_enable_length() const
Definition gp.hh:226
tlm_response_status get_response_status() const
Definition gp.hh:199
void set_data_length(const unsigned int length)
Definition gp.hh:193
void get_extension(T *&ext) const
Definition gp.hh:364
unsigned char * m_byte_enable
Definition gp.hh:295
bool is_dmi_allowed() const
Definition gp.hh:244
sc_dt::uint64 m_address
Definition gp.hh:289
unsigned char * m_data
Definition gp.hh:291
bool has_mm() const
Definition gp.hh:140
unsigned int get_streaming_width() const
Definition gp.hh:211
unsigned int m_byte_enable_length
Definition gp.hh:296
unsigned int get_data_length() const
Definition gp.hh:192
tlm_generic_payload(const tlm_generic_payload &x)
tlm_command get_command() const
Definition gp.hh:180
void set_streaming_width(const unsigned int streaming_width)
Definition gp.hh:213
int get_ref_count() const
Definition gp.hh:137
unsigned int m_length
Definition gp.hh:292
unsigned int m_ref_count
Definition gp.hh:423
void clear_extension(const T *ext)
Definition gp.hh:379
tlm_gp_option m_gp_option
Definition gp.hh:298
T * set_extension(T *ext)
Definition gp.hh:340
void set_byte_enable_ptr(unsigned char *byte_enable)
Definition gp.hh:221
void set_mm(tlm_mm_interface *mm)
Definition gp.hh:139
bool is_response_error() const
Definition gp.hh:197
virtual void free(tlm_generic_payload *)=0
virtual ~tlm_mm_interface()
Definition gp.hh:37
uint64_t uint64
Definition sc_nbdefs.hh:172
tlm_gp_option
Definition gp.hh:101
@ TLM_MIN_PAYLOAD
Definition gp.hh:102
@ TLM_FULL_PAYLOAD_ACCEPTED
Definition gp.hh:104
@ TLM_FULL_PAYLOAD
Definition gp.hh:103
tlm_command
Definition gp.hh:83
@ TLM_READ_COMMAND
Definition gp.hh:84
@ TLM_IGNORE_COMMAND
Definition gp.hh:86
@ TLM_WRITE_COMMAND
Definition gp.hh:85
tlm_response_status
Definition gp.hh:90
@ TLM_ADDRESS_ERROR_RESPONSE
Definition gp.hh:94
@ TLM_OK_RESPONSE
Definition gp.hh:91
@ TLM_BURST_ERROR_RESPONSE
Definition gp.hh:96
@ TLM_BYTE_ENABLE_ERROR_RESPONSE
Definition gp.hh:97
@ TLM_GENERIC_ERROR_RESPONSE
Definition gp.hh:93
@ TLM_COMMAND_ERROR_RESPONSE
Definition gp.hh:95
@ TLM_INCOMPLETE_RESPONSE
Definition gp.hh:92
unsigned int max_num_extensions()
Definition gp.cc:85
#define sc_assert(expr)

Generated on Tue Jun 18 2024 16:24:07 for gem5 by doxygen 1.11.0