gem5  v22.0.0.2
vma.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2020 Advanced Micro Devices, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met: redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer;
9  * redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution;
12  * neither the name of the copyright holders nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef __SRC_MEM_VMA_HH__
30 #define __SRC_MEM_VMA_HH__
31 
32 #include <string>
33 
34 #include "base/addr_range.hh"
35 #include "base/trace.hh"
36 #include "base/types.hh"
37 #include "debug/Vma.hh"
39 
40 namespace gem5
41 {
42 
43 class VMA
44 {
45  class MappedFileBuffer;
46 
47  public:
48  VMA(AddrRange r, Addr page_bytes, const std::string& vma_name="anon",
49  int fd=-1, off_t off=0)
50  : _addrRange(r), _pageBytes(page_bytes), _vmaName(vma_name)
51  {
52  DPRINTF(Vma, "Creating vma start %#x len %llu end %#x\n",
53  r.start(), r.size(), r.end());
54 
55  if (fd != -1) {
56  _origHostBuf =
57  std::make_shared<MappedFileBuffer>(fd, r.size(), off);
58  _hostBuf = _origHostBuf->getBuffer();
59  _hostBufLen = _origHostBuf->getLength();
60  }
61 
62  sanityCheck();
63  }
64 
68  void
69  remap(Addr new_start)
70  {
71  _addrRange = AddrRange(new_start, new_start + _addrRange.size());
72 
73  DPRINTF(Vma, "Remapping vma start %#x end %#x\n", _addrRange.start(),
74  _addrRange.end());
75 
76  sanityCheck();
77  }
78 
83  bool hasHostBuf() const { return _origHostBuf != nullptr; }
84 
89  void fillMemPages(Addr start, Addr size, PortProxy &port) const;
90 
95  bool isStrictSuperset(const AddrRange &range) const;
96 
100  void sliceRegionRight(Addr slice_addr);
101 
105  void sliceRegionLeft(Addr slice_addr);
106 
107  const std::string& getName() { return _vmaName; }
108 
112  Addr size() { return _addrRange.size(); }
113  Addr start() { return _addrRange.start(); }
114  Addr end() { return _addrRange.end(); }
115 
116  bool
117  mergesWith(const AddrRange& r) const
118  {
119  return _addrRange.mergesWith(r);
120  }
121 
122  bool
123  intersects(const AddrRange& r) const
124  {
125  return _addrRange.intersects(r);
126  }
127 
128  bool
129  isSubset(const AddrRange& r) const
130  {
131  return _addrRange.isSubset(r);
132  }
133 
134  bool
135  contains(const Addr& a) const
136  {
137  return _addrRange.contains(a);
138  }
139 
140  private:
141  void sanityCheck();
142 
147 
152 
160  std::shared_ptr<MappedFileBuffer> _origHostBuf;
161 
165  void *_hostBuf;
166 
170  uint64_t _hostBufLen;
171 
178  std::string _vmaName;
179 
187  {
188  public:
189  MappedFileBuffer(int fd, size_t length, off_t offset);
191 
192  void *getBuffer() const { return _buffer; }
193  uint64_t getLength() const { return _length; }
194 
195  private:
196  void *_buffer; // Host buffer ptr
197  size_t _length; // Length of host ptr
198  };
199 };
200 
201 } // namespace gem5
202 
203 #endif // __SRC_MEM_VMA_HH__
gem5::VMA::_addrRange
AddrRange _addrRange
Address range for this virtual memory area.
Definition: vma.hh:146
gem5::AddrRange::start
Addr start() const
Get the start address of the range.
Definition: addr_range.hh:343
gem5::VMA::sanityCheck
void sanityCheck()
Definition: vma.cc:101
gem5::VMA::hasHostBuf
bool hasHostBuf() const
Check if the virtual memory area has an equivalent buffer on the host machine.
Definition: vma.hh:83
gem5::VMA::MappedFileBuffer::MappedFileBuffer
MappedFileBuffer(int fd, size_t length, off_t offset)
Definition: vma.cc:121
gem5::VMA::MappedFileBuffer
MappedFileBuffer is a wrapper around a region of host memory backed by a file.
Definition: vma.hh:186
gem5::ArmISA::fd
Bitfield< 14, 12 > fd
Definition: types.hh:150
gem5::VMA::_vmaName
std::string _vmaName
Human-readable name associated with the virtual memory area.
Definition: vma.hh:178
gem5::VMA::contains
bool contains(const Addr &a) const
Definition: vma.hh:135
gem5::AddrRange::contains
bool contains(const Addr &a) const
Determine if the range contains an address.
Definition: addr_range.hh:471
gem5::VMA::fillMemPages
void fillMemPages(Addr start, Addr size, PortProxy &port) const
Copy memory from a buffer which resides on the host machine into a section of memory on the target.
Definition: vma.cc:40
gem5::VMA::isSubset
bool isSubset(const AddrRange &r) const
Definition: vma.hh:129
gem5::ArmISA::a
Bitfield< 8 > a
Definition: misc_types.hh:66
gem5::VMA::_pageBytes
Addr _pageBytes
Number of bytes in an OS page.
Definition: vma.hh:151
gem5::AddrRange::intersects
bool intersects(const AddrRange &r) const
Determine if another range intersects this one, i.e.
Definition: addr_range.hh:408
gem5::VMA::end
Addr end()
Definition: vma.hh:114
gem5::VegaISA::r
Bitfield< 5 > r
Definition: pagetable.hh:60
gem5::VMA::MappedFileBuffer::_length
size_t _length
Definition: vma.hh:197
gem5::AddrRange::isSubset
bool isSubset(const AddrRange &r) const
Determine if this range is a subset of another range, i.e.
Definition: addr_range.hh:445
gem5::VMA::isStrictSuperset
bool isStrictSuperset(const AddrRange &range) const
Returns true if desired range exists within this virtual memory area and does not include the start a...
Definition: vma.cc:54
gem5::VMA::MappedFileBuffer::getBuffer
void * getBuffer() const
Definition: vma.hh:192
gem5::VMA
Definition: vma.hh:43
gem5::VMA::getName
const std::string & getName()
Definition: vma.hh:107
gem5::VMA::size
Addr size()
Defer AddrRange related calls to the AddrRange.
Definition: vma.hh:112
gem5::VMA::remap
void remap(Addr new_start)
Remap the virtual memory area starting at new_start.
Definition: vma.hh:69
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:186
gem5::VMA::intersects
bool intersects(const AddrRange &r) const
Definition: vma.hh:123
gem5::PortProxy
This object is a proxy for a port or other object which implements the functional response protocol,...
Definition: port_proxy.hh:86
gem5::VMA::mergesWith
bool mergesWith(const AddrRange &r) const
Definition: vma.hh:117
gem5::AddrRange::size
Addr size() const
Get the size of the address range.
Definition: addr_range.hh:326
gem5::ArmISA::offset
Bitfield< 23, 0 > offset
Definition: types.hh:144
gem5::AddrRange::end
Addr end() const
Get the end address of the range.
Definition: addr_range.hh:350
gem5::VMA::start
Addr start()
Definition: vma.hh:113
gem5::VMA::_hostBufLen
uint64_t _hostBufLen
Length of host buffer for this virtual memory area.
Definition: vma.hh:170
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::VMA::_hostBuf
void * _hostBuf
Host buffer ptr for this virtual memory area.
Definition: vma.hh:165
addr_range.hh
gem5::AddrRange::mergesWith
bool mergesWith(const AddrRange &r) const
Determine if another range merges with the current one, i.e.
Definition: addr_range.hh:391
gem5::VMA::VMA
VMA(AddrRange r, Addr page_bytes, const std::string &vma_name="anon", int fd=-1, off_t off=0)
Definition: vma.hh:48
gem5::VMA::sliceRegionLeft
void sliceRegionLeft(Addr slice_addr)
Remove the address range to the left of slice_addr.
Definition: vma.cc:76
gem5::VMA::MappedFileBuffer::~MappedFileBuffer
~MappedFileBuffer()
Definition: vma.cc:150
types.hh
gem5::VMA::_origHostBuf
std::shared_ptr< MappedFileBuffer > _origHostBuf
The host file backing will be chopped up and reassigned as pages are mapped, remapped,...
Definition: vma.hh:160
gem5::VMA::sliceRegionRight
void sliceRegionRight(Addr slice_addr)
Remove the address range to the right of slice_addr.
Definition: vma.cc:60
se_translating_port_proxy.hh
trace.hh
gem5::AddrRange
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
Definition: addr_range.hh:81
gem5::VMA::MappedFileBuffer::getLength
uint64_t getLength() const
Definition: vma.hh:193
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::VMA::MappedFileBuffer::_buffer
void * _buffer
Definition: vma.hh:196

Generated on Thu Jul 28 2022 13:32:37 for gem5 by doxygen 1.8.17