gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  off_t getFileMappingOffset() const
109  {
110  return hasHostBuf() ? _origHostBuf->getOffset() : 0;
111  }
112 
116  Addr size() { return _addrRange.size(); }
117  Addr start() { return _addrRange.start(); }
118  Addr end() { return _addrRange.end(); }
119 
120  bool
121  mergesWith(const AddrRange& r) const
122  {
123  return _addrRange.mergesWith(r);
124  }
125 
126  bool
127  intersects(const AddrRange& r) const
128  {
129  return _addrRange.intersects(r);
130  }
131 
132  bool
133  isSubset(const AddrRange& r) const
134  {
135  return _addrRange.isSubset(r);
136  }
137 
138  bool
139  contains(const Addr& a) const
140  {
141  return _addrRange.contains(a);
142  }
143 
144  private:
145  void sanityCheck();
146 
151 
156 
164  std::shared_ptr<MappedFileBuffer> _origHostBuf;
165 
169  void *_hostBuf;
170 
174  uint64_t _hostBufLen;
175 
182  std::string _vmaName;
183 
191  {
192  public:
193  MappedFileBuffer(int fd, size_t length, off_t offset);
195 
196  void *getBuffer() const { return _buffer; }
197  uint64_t getLength() const { return _length; }
198  off_t getOffset() const { return _offset; }
199 
200  private:
201  void *_buffer; // Host buffer ptr
202  size_t _length; // Length of host ptr
203  off_t _offset; // Offset in file at which mapping starts
204  };
205 };
206 
207 } // namespace gem5
208 
209 #endif // __SRC_MEM_VMA_HH__
gem5::VMA::getFileMappingOffset
off_t getFileMappingOffset() const
Definition: vma.hh:108
gem5::VMA::_addrRange
AddrRange _addrRange
Address range for this virtual memory area.
Definition: vma.hh:150
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:190
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:182
gem5::VMA::contains
bool contains(const Addr &a) const
Definition: vma.hh:139
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:133
gem5::VMA::MappedFileBuffer::getOffset
off_t getOffset() const
Definition: vma.hh:198
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:155
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:118
gem5::VegaISA::r
Bitfield< 5 > r
Definition: pagetable.hh:60
gem5::VMA::MappedFileBuffer::_length
size_t _length
Definition: vma.hh:202
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:196
gem5::VMA::MappedFileBuffer::_offset
off_t _offset
Definition: vma.hh:203
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:116
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:210
gem5::VMA::intersects
bool intersects(const AddrRange &r) const
Definition: vma.hh:127
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:121
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:117
gem5::VMA::_hostBufLen
uint64_t _hostBufLen
Length of host buffer for this virtual memory area.
Definition: vma.hh:174
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:169
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:164
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:197
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:201

Generated on Sun Jul 30 2023 01:57:00 for gem5 by doxygen 1.8.17