gem5  v20.1.0.0
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 class VMA
41 {
42  class MappedFileBuffer;
43 
44  public:
45  VMA(AddrRange r, Addr page_bytes, const std::string& vma_name="anon",
46  int fd=-1, off_t off=0)
47  : _addrRange(r), _pageBytes(page_bytes), _vmaName(vma_name)
48  {
49  DPRINTF(Vma, "Creating vma start %#x len %llu end %#x\n",
50  r.start(), r.size(), r.end());
51 
52  if (fd != -1) {
53  _origHostBuf =
54  std::make_shared<MappedFileBuffer>(fd, r.size(), off);
55  _hostBuf = _origHostBuf->getBuffer();
56  _hostBufLen = _origHostBuf->getLength();
57  }
58 
59  sanityCheck();
60  }
61 
65  void
66  remap(Addr new_start)
67  {
68  _addrRange = AddrRange(new_start, new_start + _addrRange.size());
69 
70  DPRINTF(Vma, "Remapping vma start %#x end %#x\n", _addrRange.start(),
71  _addrRange.end());
72 
73  sanityCheck();
74  }
75 
80  bool hasHostBuf() const { return _origHostBuf != nullptr; }
81 
86  void fillMemPages(Addr start, Addr size, PortProxy &port) const;
87 
92  bool isStrictSuperset(const AddrRange &range) const;
93 
97  void sliceRegionRight(Addr slice_addr);
98 
102  void sliceRegionLeft(Addr slice_addr);
103 
104  const std::string& getName() { return _vmaName; }
105 
109  Addr size() { return _addrRange.size(); }
110  Addr start() { return _addrRange.start(); }
111  Addr end() { return _addrRange.end(); }
112 
113  bool
114  mergesWith(const AddrRange& r) const
115  {
116  return _addrRange.mergesWith(r);
117  }
118 
119  bool
120  intersects(const AddrRange& r) const
121  {
122  return _addrRange.intersects(r);
123  }
124 
125  bool
126  isSubset(const AddrRange& r) const
127  {
128  return _addrRange.isSubset(r);
129  }
130 
131  bool
132  contains(const Addr& a) const
133  {
134  return _addrRange.contains(a);
135  }
136 
137  private:
138  void sanityCheck();
139 
144 
149 
157  std::shared_ptr<MappedFileBuffer> _origHostBuf;
158 
162  void *_hostBuf;
163 
167  uint64_t _hostBufLen;
168 
175  std::string _vmaName;
176 
184  {
185  public:
186  MappedFileBuffer(int fd, size_t length, off_t offset);
188 
189  void *getBuffer() const { return _buffer; }
190  uint64_t getLength() const { return _length; }
191 
192  private:
193  void *_buffer; // Host buffer ptr
194  size_t _length; // Length of host ptr
195  };
196 };
197 
198 #endif // __SRC_MEM_VMA_HH__
VMA::contains
bool contains(const Addr &a) const
Definition: vma.hh:132
length
uint8_t length
Definition: inet.hh:422
VMA::sanityCheck
void sanityCheck()
Definition: vma.cc:99
VMA::end
Addr end()
Definition: vma.hh:111
VMA::MappedFileBuffer::getBuffer
void * getBuffer() const
Definition: vma.hh:189
VMA::MappedFileBuffer::getLength
uint64_t getLength() const
Definition: vma.hh:190
VMA::sliceRegionLeft
void sliceRegionLeft(Addr slice_addr)
Remove the address range to the left of slice_addr.
Definition: vma.cc:74
ArmISA::fd
Bitfield< 14, 12 > fd
Definition: types.hh:159
VMA::remap
void remap(Addr new_start)
Remap the virtual memory area starting at new_start.
Definition: vma.hh:66
VMA::MappedFileBuffer::~MappedFileBuffer
~MappedFileBuffer()
Definition: vma.cc:148
AddrRange::contains
bool contains(const Addr &a) const
Determine if the range contains an address.
Definition: addr_range.hh:435
AddrRange::end
Addr end() const
Get the end address of the range.
Definition: addr_range.hh:321
VMA::_hostBufLen
uint64_t _hostBufLen
Length of host buffer for this virtual memory area.
Definition: vma.hh:167
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:157
VMA
Definition: vma.hh:40
VMA::sliceRegionRight
void sliceRegionRight(Addr slice_addr)
Remove the address range to the right of slice_addr.
Definition: vma.cc:58
VMA::VMA
VMA(AddrRange r, Addr page_bytes, const std::string &vma_name="anon", int fd=-1, off_t off=0)
Definition: vma.hh:45
VMA::hasHostBuf
bool hasHostBuf() const
Check if the virtual memory area has an equivalent buffer on the host machine.
Definition: vma.hh:80
VMA::_hostBuf
void * _hostBuf
Host buffer ptr for this virtual memory area.
Definition: vma.hh:162
VMA::mergesWith
bool mergesWith(const AddrRange &r) const
Definition: vma.hh:114
VMA::isSubset
bool isSubset(const AddrRange &r) const
Definition: vma.hh:126
ArmISA::a
Bitfield< 8 > a
Definition: miscregs_types.hh:62
VMA::_vmaName
std::string _vmaName
Human-readable name associated with the virtual memory area.
Definition: vma.hh:175
AddrRange
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
Definition: addr_range.hh:68
VMA::size
Addr size()
Defer AddrRange related calls to the AddrRange.
Definition: vma.hh:109
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
VMA::MappedFileBuffer
MappedFileBuffer is a wrapper around a region of host memory backed by a file.
Definition: vma.hh:183
MipsISA::r
r
Definition: pra_constants.hh:95
VMA::MappedFileBuffer::_length
size_t _length
Definition: vma.hh:194
AddrRange::intersects
bool intersects(const AddrRange &r) const
Determine if another range intersects this one, i.e.
Definition: addr_range.hh:376
VMA::MappedFileBuffer::_buffer
void * _buffer
Definition: vma.hh:193
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
addr_range.hh
VMA::getName
const std::string & getName()
Definition: vma.hh:104
PortProxy
This object is a proxy for a port or other object which implements the functional response protocol,...
Definition: port_proxy.hh:80
AddrRange::start
Addr start() const
Get the start address of the range.
Definition: addr_range.hh:314
VMA::_addrRange
AddrRange _addrRange
Address range for this virtual memory area.
Definition: vma.hh:143
types.hh
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:52
VMA::MappedFileBuffer::MappedFileBuffer
MappedFileBuffer(int fd, size_t length, off_t offset)
Definition: vma.cc:119
AddrRange::mergesWith
bool mergesWith(const AddrRange &r) const
Determine if another range merges with the current one, i.e.
Definition: addr_range.hh:360
VMA::start
Addr start()
Definition: vma.hh:110
se_translating_port_proxy.hh
trace.hh
AddrRange::isSubset
bool isSubset(const AddrRange &r) const
Determine if this range is a subset of another range, i.e.
Definition: addr_range.hh:410
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:38
VMA::intersects
bool intersects(const AddrRange &r) const
Definition: vma.hh:120
AddrRange::size
Addr size() const
Get the size of the address range.
Definition: addr_range.hh:297
VMA::_pageBytes
Addr _pageBytes
Number of bytes in an OS page.
Definition: vma.hh:148
ArmISA::offset
Bitfield< 23, 0 > offset
Definition: types.hh:153

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