gem5  v21.1.0.2
instance_specific_extensions_int.h
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 #ifndef __SYSTEMC_EXT_TLM_UTILS_INSTANCE_SPECIFIC_EXTENSIONS_INT_H__
20 #define __SYSTEMC_EXT_TLM_UTILS_INSTANCE_SPECIFIC_EXTENSIONS_INT_H__
21 
22 #include <typeinfo>
23 #include <vector>
24 
25 #include "../tlm_core/2/generic_payload/array.hh"
26 
27 namespace tlm_utils
28 {
29 
30 class ispex_base;
31 class instance_specific_extension_accessor;
32 class instance_specific_extension_container;
33 class instance_specific_extension_carrier;
34 class instance_specific_extension_container_pool;
35 
36 } // namespace tlm_utils
37 
38 namespace tlm
39 {
40 
41 extern template class tlm_array<tlm_utils::ispex_base *>;
42 
43 } // namespace tlm
44 
45 namespace tlm_utils
46 {
47 
48 // The private extension base. Similar to normal extension base, but without
49 // clone and free.
51 {
53  void free() {} // Needed for explicit tlm_array instantiation.
54 
55  public:
56  virtual ~ispex_base() {}
57 
58  protected:
59  static unsigned int register_private_extension(const std::type_info &);
60 };
61 
62 // This thing is basically a snippet of the generic_payload.
63 // It contains all the extension specific code (the extension API so to speak)
64 // the differences are:
65 // - it calls back to its owner whenever a real (==non-NULL) extension gets
66 // set for the first time.
67 // - it calls back to its owner whenever a living (==non-NULL) extension gets
68 // cleared.
70 {
71  public:
73 
74  explicit
76  m_container(container)
77  {}
78 
79  template <typename T>
80  T *
82  {
83  return static_cast<T *>(set_extension(T::priv_id, ext));
84  }
85 
86  // Non-templatized version with manual index:
87  ispex_base *set_extension(unsigned int index, ispex_base *ext);
88 
89  // Check for an extension, ext will be nullptr if not present.
90  template <typename T>
91  void get_extension(T *& ext) const
92  {
93  ext = static_cast<T *>(get_extension(T::priv_id));
94  }
95  // Non-templatized version:
96  ispex_base *get_extension(unsigned int index) const;
97 
98  // Clear extension, the argument is needed to find the right index:
99  template <typename T>
100  void clear_extension(const T *)
101  {
102  clear_extension(T::priv_id);
103  }
104 
105  // Non-templatized version with manual index
106  void clear_extension(unsigned int index);
107 
108  // Make sure the extension array is large enough. Can be called once by
109  // an initiator module (before issuing the first transaction) to make
110  // sure that the extension array is of correct size. This is only needed
111  // if the initiator cannot guarantee that the generic payload object is
112  // allocated after C++ static construction time.
113  void resize_extensions();
114 
115  private:
118 };
119 
120 // This thing contains the vector of extensions per accessor
121 // which can be really large so this one should be pool allocated.
122 // Therefore it keeps a use_count of itself to automatically free itself.
123 // - to this end it provides callbacks to the extensions per accessor
124 // to increment and decrement the use_count.
126 {
131 
133 
136 
137  void resize();
138 
139  void inc_use_count();
140  void dec_use_count();
141 
142  static instance_specific_extension_container *create();
143  void attach_carrier(
144  instance_specific_extension_carrier *, void *txn, release_fn *);
145 
147  get_accessor(unsigned int index);
148 
151  unsigned int use_count;
152  void *m_txn;
153  release_fn *m_release_fn;
156 };
157 
158 // ----------------------------------------------------------------------------
159 
160 // This class 'hides' all the instance specific extension stuff from the user.
161 // They instantiates one of those (e.g. instance_specific_extension_accessor
162 // extAcc;) and can then access the private extensions.
163 // extAcc(txn).extensionAPIFnCall()
164 // where extensionAPIFnCall is set_extension, get_extension,
165 // clear_extension,...
167 {
168  public:
170 
171  // Implementation in instance_specific_extensions.h
172  template <typename T>
173  inline instance_specific_extensions_per_accessor &operator () (T &txn);
174 
175  protected:
176  template<typename T>
177  static void release_carrier(
179 
180  unsigned int m_index;
181 };
182 
183 } // namespace tlm_utils
184 
185 #endif /* __SYSTEMC_EXT_TLM_UTILS_INSTANCE_SPECIFIC_EXTENSIONS_INT_H__ */
gem5::MipsISA::index
Bitfield< 30, 0 > index
Definition: pra_constants.hh:47
tlm_utils::instance_specific_extensions_per_accessor::instance_specific_extensions_per_accessor
instance_specific_extensions_per_accessor(container_type *container)
Definition: instance_specific_extensions_int.h:75
tlm_utils::instance_specific_extensions_per_accessor::clear_extension
void clear_extension(const T *)
Definition: instance_specific_extensions_int.h:100
tlm_utils::instance_specific_extension_container::instance_specific_extension_container_pool
friend class instance_specific_extension_container_pool
Definition: instance_specific_extensions_int.h:129
std::vector
STL vector class.
Definition: stl.hh:37
tlm_utils::instance_specific_extension_container
Definition: instance_specific_extensions_int.h:125
tlm_utils::instance_specific_extension_container::m_txn
void * m_txn
Definition: instance_specific_extensions_int.h:152
tlm_utils::instance_specific_extension_container::instance_specific_extension_accessor
friend class instance_specific_extension_accessor
Definition: instance_specific_extensions_int.h:127
tlm_utils::instance_specific_extensions_per_accessor::set_extension
T * set_extension(T *ext)
Definition: instance_specific_extensions_int.h:81
tlm_utils::instance_specific_extension_container::next
instance_specific_extension_container * next
Definition: instance_specific_extensions_int.h:155
tlm_utils::ispex_base::free
void free()
Definition: instance_specific_extensions_int.h:53
tlm_utils::instance_specific_extensions_per_accessor::get_extension
void get_extension(T *&ext) const
Definition: instance_specific_extensions_int.h:91
tlm_utils::instance_specific_extension_container::m_ispex_per_accessor
std::vector< instance_specific_extensions_per_accessor * > m_ispex_per_accessor
Definition: instance_specific_extensions_int.h:150
tlm_utils::ispex_base::~ispex_base
virtual ~ispex_base()
Definition: instance_specific_extensions_int.h:56
tlm_utils::instance_specific_extensions_per_accessor::m_extensions
tlm::tlm_array< ispex_base * > m_extensions
Definition: instance_specific_extensions_int.h:116
tlm_utils::instance_specific_extension_container::instance_specific_extension_carrier
friend class instance_specific_extension_carrier
Definition: instance_specific_extensions_int.h:128
gem5::ArmISA::ext
Bitfield< 12 > ext
Definition: misc_types.hh:427
tlm
Definition: analysis_fifo.hh:27
tlm_utils::instance_specific_extension_carrier
Definition: instance_specific_extensions.h:92
tlm_utils::instance_specific_extensions_per_accessor::m_container
container_type * m_container
Definition: instance_specific_extensions_int.h:117
tlm_utils::instance_specific_extension_accessor
Definition: instance_specific_extensions_int.h:166
tlm_utils
Definition: convenience_socket_bases.h:29
tlm_utils::instance_specific_extension_container::release_fn
void release_fn(instance_specific_extension_carrier *, void *)
Definition: instance_specific_extensions_int.h:132
tlm_utils::instance_specific_extensions_per_accessor
Definition: instance_specific_extensions_int.h:69
tlm_utils::instance_specific_extension_container::use_count
unsigned int use_count
Definition: instance_specific_extensions_int.h:151
tlm_utils::instance_specific_extension_accessor::m_index
unsigned int m_index
Definition: instance_specific_extensions_int.h:180
tlm::tlm_array
Definition: array.hh:60
tlm_utils::instance_specific_extension_container::instance_specific_extensions_per_accessor
friend class instance_specific_extensions_per_accessor
Definition: instance_specific_extensions_int.h:130
tlm_utils::instance_specific_extension_container::m_carrier
instance_specific_extension_carrier * m_carrier
Definition: instance_specific_extensions_int.h:154
tlm_utils::ispex_base
Definition: instance_specific_extensions_int.h:50
tlm_utils::instance_specific_extension_container::m_release_fn
release_fn * m_release_fn
Definition: instance_specific_extensions_int.h:153
tlm_utils::instance_specific_extensions_per_accessor::container_type
instance_specific_extension_container container_type
Definition: instance_specific_extensions_int.h:72

Generated on Tue Sep 21 2021 12:25:56 for gem5 by doxygen 1.8.17