gem5  v22.0.0.1
translation_gen.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2021 Google, Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met: redistributions of source code must retain the above copyright
7  * notice, this list of conditions and the following disclaimer;
8  * redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution;
11  * neither the name of the copyright holders nor the names of its
12  * contributors may be used to endorse or promote products derived from
13  * this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef __MEM_TRANSLATION_GEN_HH__
29 #define __MEM_TRANSLATION_GEN_HH__
30 
31 #include <iterator>
32 #include <memory>
33 
34 #include "base/logging.hh"
35 #include "base/types.hh"
36 
37 namespace gem5
38 {
39 
40 class TranslationGenConstIterator;
41 
61 {
62  public:
68  struct Range
69  {
71  Addr size = 0;
72 
73  Addr paddr = 0;
75  };
76 
77  protected:
94  virtual void translate(Range &range) const = 0;
95 
98 
99  public:
106  TranslationGen(Addr new_start, Addr new_size) :
107  _start(new_start), _size(new_size)
108  {}
109  virtual ~TranslationGen() {}
110 
111  Addr start() const { return _start; }
112  Addr size() const { return _size; }
113 
123 
124  inline const_iterator begin() const;
125  inline const_iterator end() const;
126 };
127 
128 using TranslationGenPtr = std::unique_ptr<TranslationGen>;
129 
141 {
142  private:
144  const TranslationGen *gen = nullptr;
145  bool end = true;
146 
147  friend class TranslationGen;
148 
150  void
152  {
153  current.paddr = 0;
154  // Set the size to however much is left, aka the maximum.
155  current.size = gen->size() - (current.vaddr - gen->start());
156 
157  if (current.size == 0) {
158  // Transform into the end iterator.
159  end = true;
160  current.vaddr = 0;
161  gen = nullptr;
162  } else {
164  }
165  }
166 
171  current{start}, gen(parent), end(false)
172  {
173  update();
174  }
175 
176  public:
178  using reference = const value_type &;
179  using pointer = const value_type *;
180  using iterator_category = std::forward_iterator_tag;
181 
183  current(other.current), gen(other.gen)
184  {}
185 
188  {
189  gen = other.gen;
190  current = other.current;
191  return *this;
192  }
193 
195  pointer operator->() { return &current; }
196 
213  {
214  panic_if(end, "Can't increment end iterator.");
215  assert(gen);
216 
217  if (current.fault == NoFault) {
218  // If the last translation was successful, move forward.
220  } else {
221  // If not, clear out the fault and try again, assuming the
222  // caller has fixed whatever the problem was.
224  }
225 
226  update();
227 
228  return *this;
229  }
230 
233  {
234  const auto orig(*this);
235  ++*this;
236  return orig;
237  }
238 
239  bool
241  {
242  return other.gen == gen && other.current.vaddr == current.vaddr;
243  }
244 
245  bool
247  {
248  return !(*this == other);
249  }
250 };
251 
252 TranslationGenConstIterator
254 {
255  return const_iterator(this, start());
256 }
257 
260 {
261  return const_iterator();
262 }
263 
264 } // namespace gem5
265 
266 #endif // __MEM_TRANSLATION_GEN_HH__
gem5::TranslationGen::size
Addr size() const
Definition: translation_gen.hh:112
gem5::TranslationGen::Range::size
Addr size
Definition: translation_gen.hh:71
gem5::NoFault
constexpr decltype(nullptr) NoFault
Definition: types.hh:253
gem5::TranslationGen::TranslationGenConstIterator
friend class TranslationGenConstIterator
A const iterator class is provided so this generator can be used in a range based for loop.
Definition: translation_gen.hh:121
gem5::TranslationGen::start
Addr start() const
Definition: translation_gen.hh:111
gem5::TranslationGenConstIterator::operator!=
bool operator!=(const TranslationGenConstIterator &other) const
Definition: translation_gen.hh:246
gem5::TranslationGenConstIterator
An iterator for pulling "Range" instances out of a TranslationGen.
Definition: translation_gen.hh:140
gem5::TranslationGen::Range::vaddr
Addr vaddr
Definition: translation_gen.hh:70
gem5::TranslationGenConstIterator::operator*
reference operator*()
Definition: translation_gen.hh:194
gem5::TranslationGen::translate
virtual void translate(Range &range) const =0
Subclasses implement this function to complete TranslationGen.
gem5::TranslationGen::Range::paddr
Addr paddr
Definition: translation_gen.hh:73
gem5::TranslationGenConstIterator::end
bool end
Definition: translation_gen.hh:145
gem5::TranslationGenConstIterator::current
TranslationGen::Range current
Definition: translation_gen.hh:143
gem5::TranslationGenConstIterator::TranslationGenConstIterator
TranslationGenConstIterator(const TranslationGen *parent, Addr start)
Construct a valid new iterator and set it's starting conditions.
Definition: translation_gen.hh:170
gem5::TranslationGen::_start
Addr _start
Definition: translation_gen.hh:96
gem5::TranslationGen::Range
This structure represents a single, contiguous translation, or carries information about whatever fau...
Definition: translation_gen.hh:68
gem5::TranslationGen::_size
Addr _size
Definition: translation_gen.hh:97
gem5::TranslationGenConstIterator::iterator_category
std::forward_iterator_tag iterator_category
Definition: translation_gen.hh:180
gem5::TranslationGenConstIterator::operator++
TranslationGenConstIterator operator++(int)
Definition: translation_gen.hh:232
gem5::TranslationGen::~TranslationGen
virtual ~TranslationGen()
Definition: translation_gen.hh:109
gem5::TranslationGen::TranslationGen
TranslationGen(Addr new_start, Addr new_size)
The starting virtual address and the size of the entire region being translated.
Definition: translation_gen.hh:106
gem5::Fault
std::shared_ptr< FaultBase > Fault
Definition: types.hh:248
gem5::TranslationGen::Range::fault
Fault fault
Definition: translation_gen.hh:74
gem5::TranslationGen::const_iterator
TranslationGenConstIterator const_iterator
Definition: translation_gen.hh:122
gem5::TranslationGen::end
const_iterator end() const
Definition: translation_gen.hh:259
gem5::TranslationGenConstIterator::operator==
bool operator==(const TranslationGenConstIterator &other) const
Definition: translation_gen.hh:240
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::TranslationGenConstIterator::gen
const TranslationGen * gen
Definition: translation_gen.hh:144
gem5::TranslationGen
TranslationGen is a base class for a generator object which returns information about address transla...
Definition: translation_gen.hh:60
panic_if
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:204
gem5::TranslationGenConstIterator::TranslationGenConstIterator
TranslationGenConstIterator(const TranslationGenConstIterator &other)
Definition: translation_gen.hh:182
types.hh
logging.hh
gem5::TranslationGenConstIterator::operator++
TranslationGenConstIterator & operator++()
The increment operator, which is the main work horse of this class.
Definition: translation_gen.hh:212
gem5::TranslationGenConstIterator::operator->
pointer operator->()
Definition: translation_gen.hh:195
gem5::TranslationGen::begin
const_iterator begin() const
Definition: translation_gen.hh:253
gem5::TranslationGenConstIterator::operator=
TranslationGenConstIterator & operator=(const TranslationGenConstIterator &other)
Definition: translation_gen.hh:187
gem5::TranslationGenConstIterator::update
void update()
Use the vaddr of the "current" Range to update its other fields.
Definition: translation_gen.hh:151
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::TranslationGenConstIterator::TranslationGenConstIterator
TranslationGenConstIterator()
Construct a blank iterator, used by end().
Definition: translation_gen.hh:168
gem5::TranslationGenPtr
std::unique_ptr< TranslationGen > TranslationGenPtr
Definition: translation_gen.hh:128

Generated on Sat Jun 18 2022 08:12:30 for gem5 by doxygen 1.8.17