gem5 [DEVELOP-FOR-25.0]
Loading...
Searching...
No Matches
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
40namespace gem5
41{
42
43class 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) {
57 std::make_shared<MappedFileBuffer>(fd, r.size(), off);
58 _hostBuf = _origHostBuf->getBuffer();
59 _hostBufLen = _origHostBuf->getLength();
60 }
61
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
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; }
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__
#define DPRINTF(x,...)
Definition trace.hh:209
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:191
uint64_t getLength() const
Definition vma.hh:197
void * getBuffer() const
Definition vma.hh:196
off_t getOffset() const
Definition vma.hh:198
MappedFileBuffer(int fd, size_t length, off_t offset)
Definition vma.cc:121
Addr size()
Defer AddrRange related calls to the AddrRange.
Definition vma.hh:116
Addr _pageBytes
Number of bytes in an OS page.
Definition vma.hh:155
Addr end()
Definition vma.hh:118
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
off_t getFileMappingOffset() const
Definition vma.hh:108
uint64_t _hostBufLen
Length of host buffer for this virtual memory area.
Definition vma.hh:174
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:150
void sanityCheck()
Definition vma.cc:101
std::string _vmaName
Human-readable name associated with the virtual memory area.
Definition vma.hh:182
void * _hostBuf
Host buffer ptr for this virtual memory area.
Definition vma.hh:169
std::shared_ptr< MappedFileBuffer > _origHostBuf
The host file backing will be chopped up and reassigned as pages are mapped, remapped,...
Definition vma.hh:164
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:117
bool contains(const Addr &a) const
Definition vma.hh:139
const std::string & getName()
Definition vma.hh:107
bool mergesWith(const AddrRange &r) const
Definition vma.hh:121
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:127
bool isSubset(const AddrRange &r) const
Definition vma.hh:133
Bitfield< 14, 12 > fd
Definition types.hh:150
Bitfield< 23, 0 > offset
Definition types.hh:144
Bitfield< 8 > a
Definition misc_types.hh:66
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147

Generated on Mon May 26 2025 09:19:13 for gem5 by doxygen 1.13.2