gem5  v22.1.0.0
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"
41 #include "mem/translation_gen.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 // AMD GPUs support 16 different virtual address spaces
78 static constexpr int AMDGPU_VM_COUNT = 16;
79 
80 // These apertures have a fixed page size
81 static constexpr int AMDGPU_AGP_PAGE_SIZE = 4096;
82 static constexpr int AMDGPU_GART_PAGE_SIZE = 4096;
83 static constexpr int AMDGPU_MMHUB_PAGE_SIZE = 4096;
84 
85 // Vega page size can be any power of 2 between 4kB and 1GB.
86 static constexpr int AMDGPU_USER_PAGE_SIZE = 4096;
87 
88 namespace gem5
89 {
90 
91 class AMDGPUVM : public Serializable
92 {
93  private:
94  typedef struct GEM5_PACKED
95  {
96  // Page table addresses: from (Base + Start) to (End)
97  union
98  {
99  struct
100  {
101  uint32_t ptBaseL;
102  uint32_t ptBaseH;
103  };
105  };
106  union
107  {
108  struct
109  {
110  uint32_t ptStartL;
111  uint32_t ptStartH;
112  };
114  };
115  union
116  {
117  struct
118  {
119  uint32_t ptEndL;
120  uint32_t ptEndH;
121  };
123  };
125 
127  {
137 
140 
141  // MMHUB aperture. These addresses mirror the framebuffer, so addresses
142  // can be calculated by subtracting the base address.
143  uint64_t mmhubBase = 0x0;
144  uint64_t mmhubTop = 0x0;
145 
151 
152  public:
153  AMDGPUVM();
154 
158  Addr gartBase();
162  Addr gartSize();
163 
168  std::unordered_map<uint64_t, uint64_t> gartTable;
169 
170  void readMMIO(PacketPtr pkt, Addr offset);
171  void writeMMIO(PacketPtr pkt, Addr offset);
172 
176  bool
178  {
179  return ((vaddr >= vmContext0.agpBot) && (vaddr <= vmContext0.agpTop));
180  }
181 
185 
186  bool
188  {
189  return ((vaddr >= getMMHUBBase()) && (vaddr <= getMMHUBTop()));
190  }
191 
193  Addr getMMHUBTop() { return mmhubTop; }
194 
195  bool
197  {
198  return ((vaddr >= vmContext0.fbBase) && (vaddr <= vmContext0.fbTop));
199  }
200 
204 
205  bool
207  {
208  return ((vaddr >= vmContext0.sysAddrL) &&
209  (vaddr <= vmContext0.sysAddrH));
210  }
211 
214 
215  Addr
217  {
218  // Aperture ranges:
219  // NBIO 0x0 - 0x4280
220  // IH 0x4280 - 0x4980
221  // SDMA0 0x4980 - 0x5180
222  // SDMA1 0x5180 - 0x5980
223  // GRBM 0x8000 - 0xD000
224  // GFX 0x28000 - 0x3F000
225  // MMHUB 0x68000 - 0x6a120
226 
227  if (IH_BASE <= addr && addr < IH_BASE + IH_SIZE)
228  return IH_BASE;
229  else if (SDMA0_BASE <= addr && addr < SDMA0_BASE + SDMA_SIZE)
230  return SDMA0_BASE;
231  else if (SDMA1_BASE <= addr && addr < SDMA1_BASE + SDMA_SIZE)
232  return SDMA1_BASE;
233  else if (GRBM_BASE <= addr && addr < GRBM_BASE + GRBM_SIZE)
234  return GRBM_BASE;
235  else if (GFX_BASE <= addr && addr < GFX_BASE + GFX_SIZE)
236  return GFX_BASE;
237  else if (MMHUB_BASE <= addr && addr < MMHUB_BASE + MMHUB_SIZE)
238  return MMHUB_BASE;
239  else {
240  warn_once("Accessing unsupported MMIO aperture! Assuming NBIO\n");
241  return NBIO_BASE;
242  }
243 
244  }
245 
246  // Gettig mapped aperture base addresses
247  Addr
249  {
250  if (addr < gartBase()) {
251  warn_once("Accessing unsupported frame apperture!\n");
252  return ~0;
253  } else if (gartBase() <= addr && addr < (gartBase() + gartSize())) {
254  return gartBase();
255  } else {
256  warn_once("Accessing unsupported frame apperture!\n");
257  return ~0;
258  }
259 
260  }
261 
265  void
266  setPageTableBase(uint16_t vmid, Addr ptBase)
267  {
268  vmContexts[vmid].ptBase = ptBase;
269  }
270 
271  Addr
272  getPageTableBase(uint16_t vmid)
273  {
274  assert(vmid > 0 && vmid < vmContexts.size());
275  return vmContexts[vmid].ptBase;
276  }
277 
278  Addr
279  getPageTableStart(uint16_t vmid)
280  {
281  assert(vmid > 0 && vmid < vmContexts.size());
282  return vmContexts[vmid].ptStart;
283  }
284 
289  void invalidateTLBs();
290 
291 
292  void serialize(CheckpointOut &cp) const override;
293  void unserialize(CheckpointIn &cp) override;
294 
303  {
304  private:
306 
307  void translate(Range &range) const override;
308 
309  public:
311  : TranslationGen(vaddr, size), vm(_vm)
312  {}
313  };
314 
316  {
317  private:
319 
320  void translate(Range &range) const override;
321 
322  public:
324  : TranslationGen(vaddr, size), vm(_vm)
325  {}
326  };
327 
329  {
330  private:
332 
333  void translate(Range &range) const override;
334 
335  public:
337  : TranslationGen(vaddr, size), vm(_vm)
338  {}
339  };
340 
342  {
343  private:
346  int vmid;
347 
348  void translate(Range &range) const override;
349 
350  public:
351  UserTranslationGen(AMDGPUVM *_vm, VegaISA::Walker *_walker, int _vmid,
352  Addr vaddr, Addr size)
353  : TranslationGen(vaddr, size), vm(_vm), walker(_walker),
354  vmid(_vmid)
355  {}
356  };
357 };
358 
359 } // namespace gem5
360 
361 #endif // __DEV_AMDGPU_AMDGPU_VM_HH__
static constexpr int AMDGPU_VM_COUNT
Definition: amdgpu_vm.hh:78
static constexpr int AMDGPU_MMHUB_PAGE_SIZE
Definition: amdgpu_vm.hh:83
static constexpr int AMDGPU_GART_PAGE_SIZE
Definition: amdgpu_vm.hh:82
static constexpr int AMDGPU_USER_PAGE_SIZE
Definition: amdgpu_vm.hh:86
static constexpr int AMDGPU_AGP_PAGE_SIZE
Definition: amdgpu_vm.hh:81
Translation range generators.
Definition: amdgpu_vm.hh:303
AGPTranslationGen(AMDGPUVM *_vm, Addr vaddr, Addr size)
Definition: amdgpu_vm.hh:310
void translate(Range &range) const override
Subclasses implement this function to complete TranslationGen.
Definition: amdgpu_vm.cc:258
void translate(Range &range) const override
Subclasses implement this function to complete TranslationGen.
Definition: amdgpu_vm.cc:274
GARTTranslationGen(AMDGPUVM *_vm, Addr vaddr, Addr size)
Definition: amdgpu_vm.hh:323
void translate(Range &range) const override
Subclasses implement this function to complete TranslationGen.
Definition: amdgpu_vm.cc:310
MMHUBTranslationGen(AMDGPUVM *_vm, Addr vaddr, Addr size)
Definition: amdgpu_vm.hh:336
UserTranslationGen(AMDGPUVM *_vm, VegaISA::Walker *_walker, int _vmid, Addr vaddr, Addr size)
Definition: amdgpu_vm.hh:351
void translate(Range &range) const override
Subclasses implement this function to complete TranslationGen.
Definition: amdgpu_vm.cc:326
uint64_t mmhubBase
Definition: amdgpu_vm.hh:143
Addr getSysAddrRangeHigh()
Definition: amdgpu_vm.hh:213
std::vector< AMDGPUVMContext > vmContexts
Definition: amdgpu_vm.hh:139
Addr getFBBase()
Definition: amdgpu_vm.hh:201
void invalidateTLBs()
Definition: amdgpu_vm.cc:174
Addr getAGPBot()
Definition: amdgpu_vm.hh:182
Addr getFBTop()
Definition: amdgpu_vm.hh:202
struct gem5::AMDGPUVM::GEM5_PACKED AMDGPUVMContext
Addr getSysAddrRangeLow()
Definition: amdgpu_vm.hh:212
std::unordered_map< uint64_t, uint64_t > gartTable
Copy of GART table.
Definition: amdgpu_vm.hh:168
bool inAGP(Addr vaddr)
Methods for resolving apertures.
Definition: amdgpu_vm.hh:177
std::vector< VegaISA::GpuTLB * > gpu_tlbs
List of TLBs associated with the GPU device.
Definition: amdgpu_vm.hh:150
void readMMIO(PacketPtr pkt, Addr offset)
Definition: amdgpu_vm.cc:69
Addr getMMHUBTop()
Definition: amdgpu_vm.hh:193
Addr getAGPTop()
Definition: amdgpu_vm.hh:183
gem5::AMDGPUVM::AMDGPUSysVMContext AMDGPUSysVMContext
Addr getMmioAperture(Addr addr)
Definition: amdgpu_vm.hh:216
Addr getFBOffset()
Definition: amdgpu_vm.hh:203
void writeMMIO(PacketPtr pkt, Addr offset)
Definition: amdgpu_vm.cc:105
uint64_t mmhubTop
Definition: amdgpu_vm.hh:144
bool inFB(Addr vaddr)
Definition: amdgpu_vm.hh:196
Addr getFrameAperture(Addr addr)
Definition: amdgpu_vm.hh:248
AMDGPUSysVMContext vmContext0
Definition: amdgpu_vm.hh:138
void setPageTableBase(uint16_t vmid, Addr ptBase)
Page table base/start accessors for user VMIDs.
Definition: amdgpu_vm.hh:266
Addr getMMHUBBase()
Definition: amdgpu_vm.hh:192
Addr getPageTableBase(uint16_t vmid)
Definition: amdgpu_vm.hh:272
Addr gartBase()
Return base address of GART table in framebuffer.
Definition: amdgpu_vm.cc:57
Addr getPageTableStart(uint16_t vmid)
Definition: amdgpu_vm.hh:279
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: amdgpu_vm.cc:219
bool inMMHUB(Addr vaddr)
Definition: amdgpu_vm.hh:187
Addr gartSize()
Return size of GART in number of PTEs.
Definition: amdgpu_vm.cc:63
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: amdgpu_vm.cc:184
Addr getAGPBase()
Definition: amdgpu_vm.hh:184
void registerTLB(VegaISA::GpuTLB *tlb)
Control methods for TLBs associated with the GPU device.
Definition: amdgpu_vm.cc:167
bool inSys(Addr vaddr)
Definition: amdgpu_vm.hh:206
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
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
#define warn_once(...)
Definition: logging.hh:250
Bitfield< 23, 0 > offset
Definition: types.hh:144
Bitfield< 59, 56 > tlb
Definition: misc_types.hh:92
Bitfield< 3 > addr
Definition: types.hh:84
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
static constexpr uint32_t MMHUB_SIZE
static constexpr uint32_t SDMA_SIZE
static constexpr uint32_t GFX_BASE
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
static constexpr uint32_t MMHUB_BASE
static constexpr uint32_t SDMA0_BASE
static constexpr uint32_t GRBM_BASE
static constexpr uint32_t SDMA1_BASE
static constexpr uint32_t IH_BASE
static constexpr uint32_t GRBM_SIZE
static constexpr uint32_t NBIO_BASE
static constexpr uint32_t GFX_SIZE
static constexpr uint32_t IH_SIZE
Declaration of the Packet class.
This structure represents a single, contiguous translation, or carries information about whatever fau...

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