gem5 v24.0.0.0
Loading...
Searching...
No Matches
amdgpu_vm.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 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 met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its
16 * contributors may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#ifndef __DEV_AMDGPU_AMDGPU_VM_HH__
33#define __DEV_AMDGPU_AMDGPU_VM_HH__
34
35#include <vector>
36
38#include "base/intmath.hh"
40#include "mem/packet.hh"
42#include "sim/serialize.hh"
43
54#define mmVM_INVALIDATE_ENG17_ACK 0x08c6
55#define mmVM_CONTEXT0_PAGE_TABLE_BASE_ADDR_LO32 0x08eb
56#define mmVM_CONTEXT0_PAGE_TABLE_BASE_ADDR_HI32 0x08ec
57#define mmVM_CONTEXT0_PAGE_TABLE_START_ADDR_LO32 0x090b
58#define mmVM_CONTEXT0_PAGE_TABLE_START_ADDR_HI32 0x090c
59#define mmVM_CONTEXT0_PAGE_TABLE_END_ADDR_LO32 0x092b
60#define mmVM_CONTEXT0_PAGE_TABLE_END_ADDR_HI32 0x092c
61
62#define mmMC_VM_FB_OFFSET 0x096b
63#define mmMC_VM_FB_LOCATION_BASE 0x0980
64#define mmMC_VM_FB_LOCATION_TOP 0x0981
65#define mmMC_VM_AGP_TOP 0x0982
66#define mmMC_VM_AGP_BOT 0x0983
67#define mmMC_VM_AGP_BASE 0x0984
68#define mmMC_VM_SYSTEM_APERTURE_LOW_ADDR 0x0985
69#define mmMC_VM_SYSTEM_APERTURE_HIGH_ADDR 0x0986
70
71#define mmMMHUB_VM_INVALIDATE_ENG17_SEM 0x06e2
72#define mmMMHUB_VM_INVALIDATE_ENG17_REQ 0x06f4
73#define mmMMHUB_VM_INVALIDATE_ENG17_ACK 0x0706
74#define mmMMHUB_VM_FB_LOCATION_BASE 0x082c
75#define mmMMHUB_VM_FB_LOCATION_TOP 0x082d
76
77#define VEGA10_FB_LOCATION_BASE 0x6a0b0
78#define VEGA10_FB_LOCATION_TOP 0x6a0b4
79
80#define MI100_MEM_SIZE_REG 0x0378c
81#define MI100_FB_LOCATION_BASE 0x6ac00
82#define MI100_FB_LOCATION_TOP 0x6ac04
83
84#define MI200_MEM_SIZE_REG 0x0378c
85#define MI200_FB_LOCATION_BASE 0x6b300
86#define MI200_FB_LOCATION_TOP 0x6b304
87
88// AMD GPUs support 16 different virtual address spaces
89static constexpr int AMDGPU_VM_COUNT = 16;
90
91// These apertures have a fixed page size
92static constexpr int AMDGPU_AGP_PAGE_SIZE = 4096;
93static constexpr int AMDGPU_GART_PAGE_SIZE = 4096;
94static constexpr int AMDGPU_MMHUB_PAGE_SIZE = 4096;
95
96// Vega page size can be any power of 2 between 4kB and 1GB.
97static constexpr int AMDGPU_USER_PAGE_SIZE = 4096;
98
99namespace gem5
100{
101
111
112class AMDGPUDevice;
113
114class AMDGPUVM : public Serializable
115{
116 private:
118
119 typedef struct GEM5_PACKED
120 {
121 // Page table addresses: from (Base + Start) to (End)
122 union
123 {
124 struct
125 {
126 uint32_t ptBaseL;
127 uint32_t ptBaseH;
128 };
130 };
131 union
132 {
133 struct
134 {
135 uint32_t ptStartL;
136 uint32_t ptStartH;
137 };
139 };
140 union
141 {
142 struct
143 {
144 uint32_t ptEndL;
145 uint32_t ptEndH;
146 };
148 };
150
162
165
166 // MMHUB aperture. These addresses mirror the framebuffer, so addresses
167 // can be calculated by subtracting the base address.
168 uint64_t mmhubBase = 0x0;
169 uint64_t mmhubTop = 0x0;
170
176
177 std::array<AddrRange, NUM_MMIO_RANGES> mmioRanges;
178
179 public:
180 AMDGPUVM();
181
182 void setGPUDevice(AMDGPUDevice *gpu_device) { gpuDevice = gpu_device; }
183
187 Addr gartBase();
191 Addr gartSize();
192
193 bool
195 {
196 return ((paddr >= gartBase()) && (paddr <= (gartBase() + gartSize())));
197 }
198
203 std::unordered_map<uint64_t, uint64_t> gartTable;
204
205 void readMMIO(PacketPtr pkt, Addr offset);
206 void writeMMIO(PacketPtr pkt, Addr offset);
207
211 bool
213 {
214 return ((vaddr >= vmContext0.agpBot) && (vaddr <= vmContext0.agpTop));
215 }
216
220
221 bool
223 {
224 return ((vaddr >= getMMHUBBase()) && (vaddr <= getMMHUBTop()));
225 }
226
229
232
233 bool
235 {
236 return ((vaddr >= vmContext0.fbBase) && (vaddr <= vmContext0.fbTop));
237 }
238
242
243 bool
245 {
246 return ((vaddr >= vmContext0.sysAddrL) &&
248 }
249
252
253 void setMMIOAperture(mmio_range_t mmio_aperture, AddrRange range);
255 AddrRange getMMIORange(mmio_range_t mmio_aperture);
256
257 // Getting mapped aperture base addresses
258 Addr
260 {
261 if (addr < gartBase()) {
262 warn_once("Accessing unsupported frame apperture!\n");
263 return ~0;
264 } else if (gartBase() <= addr && addr < (gartBase() + gartSize())) {
265 return gartBase();
266 } else {
267 warn_once("Accessing unsupported frame apperture!\n");
268 return ~0;
269 }
270
271 }
272
276 void
277 setPageTableBase(uint16_t vmid, Addr ptBase)
278 {
279 vmContexts[vmid].ptBase = ptBase;
280 }
281
282 Addr
283 getPageTableBase(uint16_t vmid)
284 {
285 assert(vmid > 0 && vmid < vmContexts.size());
286 return vmContexts[vmid].ptBase;
287 }
288
289 Addr
290 getPageTableStart(uint16_t vmid)
291 {
292 assert(vmid > 0 && vmid < vmContexts.size());
293 return vmContexts[vmid].ptStart;
294 }
295
300 void invalidateTLBs();
301
302
303 void serialize(CheckpointOut &cp) const override;
304 void unserialize(CheckpointIn &cp) override;
305
314 {
315 private:
317
318 void translate(Range &range) const override;
319
320 public:
324 };
325
327 {
328 private:
330
331 void translate(Range &range) const override;
332
333 public:
337 };
338
340 {
341 private:
343
344 void translate(Range &range) const override;
345
346 public:
350 };
351
353 {
354 private:
357 int vmid;
358
359 void translate(Range &range) const override;
360
361 public:
362 UserTranslationGen(AMDGPUVM *_vm, VegaISA::Walker *_walker, int _vmid,
364 : TranslationGen(vaddr, size), vm(_vm), walker(_walker),
365 vmid(_vmid)
366 {}
367 };
368};
369
370} // namespace gem5
371
372#endif // __DEV_AMDGPU_AMDGPU_VM_HH__
static constexpr int AMDGPU_VM_COUNT
Definition amdgpu_vm.hh:89
static constexpr int AMDGPU_MMHUB_PAGE_SIZE
Definition amdgpu_vm.hh:94
static constexpr int AMDGPU_GART_PAGE_SIZE
Definition amdgpu_vm.hh:93
static constexpr int AMDGPU_USER_PAGE_SIZE
Definition amdgpu_vm.hh:97
static constexpr int AMDGPU_AGP_PAGE_SIZE
Definition amdgpu_vm.hh:92
Device model for an AMD GPU.
Translation range generators.
Definition amdgpu_vm.hh:314
AGPTranslationGen(AMDGPUVM *_vm, Addr vaddr, Addr size)
Definition amdgpu_vm.hh:321
void translate(Range &range) const override
Subclasses implement this function to complete TranslationGen.
Definition amdgpu_vm.cc:315
void translate(Range &range) const override
Subclasses implement this function to complete TranslationGen.
Definition amdgpu_vm.cc:331
GARTTranslationGen(AMDGPUVM *_vm, Addr vaddr, Addr size)
Definition amdgpu_vm.hh:334
void translate(Range &range) const override
Subclasses implement this function to complete TranslationGen.
Definition amdgpu_vm.cc:367
MMHUBTranslationGen(AMDGPUVM *_vm, Addr vaddr, Addr size)
Definition amdgpu_vm.hh:347
UserTranslationGen(AMDGPUVM *_vm, VegaISA::Walker *_walker, int _vmid, Addr vaddr, Addr size)
Definition amdgpu_vm.hh:362
void translate(Range &range) const override
Subclasses implement this function to complete TranslationGen.
Definition amdgpu_vm.cc:383
uint64_t mmhubBase
Definition amdgpu_vm.hh:168
Addr getSysAddrRangeHigh()
Definition amdgpu_vm.hh:251
void setMMIOAperture(mmio_range_t mmio_aperture, AddrRange range)
Definition amdgpu_vm.cc:62
std::vector< AMDGPUVMContext > vmContexts
Definition amdgpu_vm.hh:164
std::array< AddrRange, NUM_MMIO_RANGES > mmioRanges
Definition amdgpu_vm.hh:177
void setMMHUBBase(Addr base)
Definition amdgpu_vm.hh:230
AddrRange getMMIORange(mmio_range_t mmio_aperture)
Definition amdgpu_vm.cc:68
void invalidateTLBs()
Definition amdgpu_vm.cc:204
struct gem5::AMDGPUVM::GEM5_PACKED AMDGPUVMContext
Addr getSysAddrRangeLow()
Definition amdgpu_vm.hh:250
std::unordered_map< uint64_t, uint64_t > gartTable
Copy of GART table.
Definition amdgpu_vm.hh:203
bool inAGP(Addr vaddr)
Methods for resolving apertures.
Definition amdgpu_vm.hh:212
std::vector< VegaISA::GpuTLB * > gpu_tlbs
List of TLBs associated with the GPU device.
Definition amdgpu_vm.hh:175
void readMMIO(PacketPtr pkt, Addr offset)
Definition amdgpu_vm.cc:99
Addr getMMHUBTop()
Definition amdgpu_vm.hh:228
const AddrRange & getMMIOAperture(Addr addr)
Definition amdgpu_vm.cc:74
gem5::AMDGPUVM::AMDGPUSysVMContext AMDGPUSysVMContext
Addr getFBOffset()
Definition amdgpu_vm.hh:241
void setGPUDevice(AMDGPUDevice *gpu_device)
Definition amdgpu_vm.hh:182
void writeMMIO(PacketPtr pkt, Addr offset)
Definition amdgpu_vm.cc:135
uint64_t mmhubTop
Definition amdgpu_vm.hh:169
bool inFB(Addr vaddr)
Definition amdgpu_vm.hh:234
Addr getFrameAperture(Addr addr)
Definition amdgpu_vm.hh:259
AMDGPUSysVMContext vmContext0
Definition amdgpu_vm.hh:163
void setPageTableBase(uint16_t vmid, Addr ptBase)
Page table base/start accessors for user VMIDs.
Definition amdgpu_vm.hh:277
Addr getMMHUBBase()
Definition amdgpu_vm.hh:227
AMDGPUDevice * gpuDevice
Definition amdgpu_vm.hh:117
Addr getPageTableBase(uint16_t vmid)
Definition amdgpu_vm.hh:283
Addr gartBase()
Return base address of GART table in framebuffer.
Definition amdgpu_vm.cc:87
Addr getPageTableStart(uint16_t vmid)
Definition amdgpu_vm.hh:290
bool inGARTRange(Addr paddr)
Definition amdgpu_vm.hh:194
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition amdgpu_vm.cc:265
bool inMMHUB(Addr vaddr)
Definition amdgpu_vm.hh:222
Addr gartSize()
Return size of GART in number of PTEs.
Definition amdgpu_vm.cc:93
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition amdgpu_vm.cc:214
Addr getAGPBase()
Definition amdgpu_vm.hh:219
void registerTLB(VegaISA::GpuTLB *tlb)
Control methods for TLBs associated with the GPU device.
Definition amdgpu_vm.cc:197
void setMMHUBTop(Addr top)
Definition amdgpu_vm.hh:231
bool inSys(Addr vaddr)
Definition amdgpu_vm.hh:244
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
Definition addr_range.hh:82
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
Basic support for object serialization.
Definition serialize.hh:170
TranslationGen is a base class for a generator object which returns information about address transla...
STL vector class.
Definition stl.hh:37
Definition test.h:63
#define warn_once(...)
Definition logging.hh:260
Bitfield< 23, 0 > offset
Definition types.hh:144
Bitfield< 59, 56 > tlb
Bitfield< 51, 12 > base
Definition pagetable.hh:141
Bitfield< 3 > addr
Definition types.hh:84
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
std::ostream CheckpointOut
Definition serialize.hh:66
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
mmio_range_t
Definition amdgpu_vm.hh:103
@ GRBM_MMIO_RANGE
Definition amdgpu_vm.hh:107
@ GFX_MMIO_RANGE
Definition amdgpu_vm.hh:106
@ IH_MMIO_RANGE
Definition amdgpu_vm.hh:108
@ MMHUB_MMIO_RANGE
Definition amdgpu_vm.hh:105
@ NUM_MMIO_RANGES
Definition amdgpu_vm.hh:109
@ NBIO_MMIO_RANGE
Definition amdgpu_vm.hh:104
Declaration of the Packet class.
This structure represents a single, contiguous translation, or carries information about whatever fau...

Generated on Tue Jun 18 2024 16:24:02 for gem5 by doxygen 1.11.0