gem5  v22.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 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__
#define DPRINTF(x,...)
Definition: trace.hh:186
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
Definition: addr_range.hh:82
This object is a proxy for a port or other object which implements the functional response protocol,...
Definition: port_proxy.hh:87
MappedFileBuffer is a wrapper around a region of host memory backed by a file.
Definition: vma.hh:187
uint64_t getLength() const
Definition: vma.hh:193
MappedFileBuffer(int fd, size_t length, off_t offset)
Definition: vma.cc:121
void * getBuffer() const
Definition: vma.hh:192
Definition: vma.hh:44
Addr size()
Defer AddrRange related calls to the AddrRange.
Definition: vma.hh:112
Addr _pageBytes
Number of bytes in an OS page.
Definition: vma.hh:151
const std::string & getName()
Definition: vma.hh:107
Addr end()
Definition: vma.hh:114
void sliceRegionLeft(Addr slice_addr)
Remove the address range to the left of slice_addr.
Definition: vma.cc:76
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
uint64_t _hostBufLen
Length of host buffer for this virtual memory area.
Definition: vma.hh:170
void remap(Addr new_start)
Remap the virtual memory area starting at new_start.
Definition: vma.hh:69
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
AddrRange _addrRange
Address range for this virtual memory area.
Definition: vma.hh:146
void sanityCheck()
Definition: vma.cc:101
std::string _vmaName
Human-readable name associated with the virtual memory area.
Definition: vma.hh:178
void * _hostBuf
Host buffer ptr for this virtual memory area.
Definition: vma.hh:165
std::shared_ptr< MappedFileBuffer > _origHostBuf
The host file backing will be chopped up and reassigned as pages are mapped, remapped,...
Definition: vma.hh:160
VMA(AddrRange r, Addr page_bytes, const std::string &vma_name="anon", int fd=-1, off_t off=0)
Definition: vma.hh:48
Addr start()
Definition: vma.hh:113
bool contains(const Addr &a) const
Definition: vma.hh:135
bool mergesWith(const AddrRange &r) const
Definition: vma.hh:117
bool hasHostBuf() const
Check if the virtual memory area has an equivalent buffer on the host machine.
Definition: vma.hh:83
void sliceRegionRight(Addr slice_addr)
Remove the address range to the right of slice_addr.
Definition: vma.cc:60
bool intersects(const AddrRange &r) const
Definition: vma.hh:123
bool isSubset(const AddrRange &r) const
Definition: vma.hh:129
bool isSubset(const AddrRange &r) const
Determine if this range is a subset of another range, i.e.
Definition: addr_range.hh:445
bool contains(const Addr &a) const
Determine if the range contains an address.
Definition: addr_range.hh:471
bool intersects(const AddrRange &r) const
Determine if another range intersects this one, i.e.
Definition: addr_range.hh:408
Addr end() const
Get the end address of the range.
Definition: addr_range.hh:350
bool mergesWith(const AddrRange &r) const
Determine if another range merges with the current one, i.e.
Definition: addr_range.hh:391
Addr start() const
Get the start address of the range.
Definition: addr_range.hh:343
Addr size() const
Get the size of the address range.
Definition: addr_range.hh:326
Bitfield< 14, 12 > fd
Definition: types.hh:150
Bitfield< 23, 0 > offset
Definition: types.hh:144
Bitfield< 8 > a
Definition: misc_types.hh:66
Bitfield< 5 > r
Definition: pagetable.hh:60
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147

Generated on Wed Dec 21 2022 10:22:40 for gem5 by doxygen 1.9.1