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

Generated on Wed Sep 30 2020 14:02:16 for gem5 by doxygen 1.8.17