gem5 [DEVELOP-FOR-25.1]
Loading...
Searching...
No Matches
amdgpu_device.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_DEVICE_HH__
33#define __DEV_AMDGPU_AMDGPU_DEVICE_HH__
34
35#include <map>
36
37#include "base/bitunion.hh"
45#include "dev/io_device.hh"
46#include "dev/pci/device.hh"
47#include "enums/GfxVersion.hh"
48#include "params/AMDGPUDevice.hh"
49
50namespace gem5
51{
52
54class SDMAEngine;
55class System;
56
66{
67 private:
71 void dispatchAccess(PacketPtr pkt, bool read);
72
81 void readFrame(PacketPtr pkt, Addr offset);
83 void readMMIO(PacketPtr pkt, Addr offset);
84
87 void writeMMIO(PacketPtr pkt, Addr offset);
88
92 std::unordered_map<uint32_t, DoorbellInfo> doorbells;
93 std::unordered_map<uint32_t, PacketPtr> pendingDoorbellPkts;
94
99 bool isROM(Addr addr) const { return romRange.contains(addr); }
100 void readROM(PacketPtr pkt);
101 void writeROM(PacketPtr pkt);
102
107
118
120 {
121 std::size_t operator()(const AddrRange& k) const
122 {
123 return k.start();
124 }
125 };
126 std::unordered_map<int, PM4PacketProcessor *> pm4PktProcs;
127 std::unordered_map<AddrRange, PM4PacketProcessor *,
129
130 // SDMAs mapped by doorbell offset
131 std::unordered_map<uint32_t, SDMAEngine *> sdmaEngs;
132 // SDMAs mapped by ID
133 std::unordered_map<uint32_t, SDMAEngine *> sdmaIds;
134 // SDMA ID to MMIO range
135 std::unordered_map<uint32_t, AddrRange> sdmaMmios;
136 // SDMA ID to function
137 typedef void (SDMAEngine::*sdmaFuncPtr)(uint32_t);
138 std::unordered_map<uint32_t, sdmaFuncPtr> sdmaFunc;
139
145
146 // VMIDs data structures
147 // map of pasids to vmids
148 std::unordered_map<uint16_t, uint16_t> idMap;
149 // map of doorbell offsets to vmids
150 std::unordered_map<Addr, uint16_t> doorbellVMIDMap;
151 // map of vmid to all queue ids using that vmid
152 std::unordered_map<uint16_t, std::set<int>> usedVMIDs;
153 // last vmid allocated by map_process PM4 packet
154 uint16_t _lastVMID;
155
156 /*
157 * Backing store for GPU memory / framebuffer / VRAM
158 */
160
161 /*
162 * For multiple GPUs, use system memory to read ROM.
163 */
165
166 /* Device information */
167 GfxVersion gfx_version = GfxVersion::gfx900;
168 const int gpuId;
170
171 protected:
175 Tick writeConfig(PacketPtr pkt) override;
176 Tick readConfig(PacketPtr pkt) override;
177
178 Tick readDevice(PacketPtr pkt) override;
179 Tick writeDevice(PacketPtr pkt) override;
180
181 public:
182 AMDGPUDevice(const AMDGPUDeviceParams &p);
183
187 void intrPost();
188
189 AddrRangeList getAddrRanges() const override;
190
194 void serialize(CheckpointOut &cp) const override;
195 void unserialize(CheckpointIn &cp) override;
196
201 SDMAEngine* getSDMAById(int id);
203 AMDGPUVM &getVM() { return gpuvm; }
205 GPUCommandProcessor* CP() { return cp; }
206
210 void setDoorbellType(uint32_t offset, QueueType qt, int ip_id = 0);
211 void unsetDoorbell(uint32_t offset);
212 void processPendingDoorbells(uint32_t offset);
214
219 uint32_t getRegVal(uint64_t addr);
220 void setRegVal(uint64_t addr, uint32_t value);
221
225 RequestorID vramRequestorId() { return gpuMemMgr->getRequestorID(); }
226
227 /* HW context stuff */
228 uint16_t lastVMID() { return _lastVMID; }
229 uint16_t allocateVMID(uint16_t pasid);
230 void deallocateVmid(uint16_t vmid);
231 void deallocatePasid(uint16_t pasid);
232 void deallocateAllQueues(bool unmap_static);
233 void mapDoorbellToVMID(Addr doorbell, uint16_t vmid);
234 uint16_t getVMID(Addr doorbell) { return doorbellVMIDMap[doorbell]; }
235 std::unordered_map<uint16_t, std::set<int>>& getUsedVMIDs();
236 void insertQId(uint16_t vmid, int id);
237
238 /* Device information */
239 GfxVersion getGfxVersion() const { return gfx_version; }
240 int
241 getGpuId() const
242 {
243 return gpuId;
244 }
245 Addr
247 {
248 return vramSize;
249 }
250};
251
252} // namespace gem5
253
254#endif // __DEV_AMDGPU_AMDGPU_DEVICE_HH__
void insertQId(uint16_t vmid, int id)
std::unordered_map< AddrRange, PM4PacketProcessor *, AddrRangeHasher > pm4Ranges
void deallocateAllQueues(bool unmap_static)
std::unordered_map< Addr, uint16_t > doorbellVMIDMap
std::unordered_map< uint16_t, uint16_t > idMap
void readMMIO(PacketPtr pkt, Addr offset)
void serialize(CheckpointOut &cp) const override
Checkpoint support.
void processPendingDoorbells(uint32_t offset)
AddrRangeList getAddrRanges() const override
Every PIO device is obliged to provide an implementation that returns the address ranges the device r...
void unserialize(CheckpointIn &cp) override
Unserialize an object.
void writeMMIO(PacketPtr pkt, Addr offset)
GPUCommandProcessor * cp
GfxVersion getGfxVersion() const
void setDoorbellType(uint32_t offset, QueueType qt, int ip_id=0)
Set handles to GPU blocks.
Tick writeDevice(PacketPtr pkt) override
Write to the PCI device.
void readROM(PacketPtr pkt)
AddrRange romRange
VGA ROM methods.
std::unordered_map< uint32_t, DoorbellInfo > doorbells
Structures to hold registers, doorbells, and some frame memory.
std::unordered_map< uint16_t, std::set< int > > & getUsedVMIDs()
bool isROM(Addr addr) const
void unsetDoorbell(uint32_t offset)
std::unordered_map< uint32_t, PacketPtr > pendingDoorbellPkts
void setRegVal(uint64_t addr, uint32_t value)
std::unordered_map< uint32_t, AddrRange > sdmaMmios
Tick readDevice(PacketPtr pkt) override
Read from the PCI device.
void(SDMAEngine::* sdmaFuncPtr)(uint32_t)
SDMAEngine * getSDMAEngine(Addr offset)
AMDGPUMemoryManager * gpuMemMgr
AMDGPUDevice(const AMDGPUDeviceParams &p)
void readDoorbell(PacketPtr pkt, Addr offset)
AMDGPUNbio nbio
Blocks of the GPU.
uint16_t getVMID(Addr doorbell)
Tick readConfig(PacketPtr pkt) override
Read from the PCI config space data that is stored locally.
std::unordered_map< uint32_t, sdmaFuncPtr > sdmaFunc
std::unordered_map< uint16_t, std::set< int > > usedVMIDs
AMDGPUInterruptHandler * deviceIH
Tick writeConfig(PacketPtr pkt) override
Methods inherited from PciEndpoint.
AMDGPUInterruptHandler * getIH()
Get handles to GPU blocks.
AMDMMIOReader mmioReader
MMIO reader to populate device registers map.
bool checkpoint_before_mmios
Initial checkpoint support variables.
void dispatchAccess(PacketPtr pkt, bool read)
Convert a PCI packet into a response.
uint32_t getRegVal(uint64_t addr)
Register value getter/setter.
void deallocateVmid(uint16_t vmid)
Addr getVRAMSize() const
void mapDoorbellToVMID(Addr doorbell, uint16_t vmid)
void intrPost()
Methods inherited from PciEndpoint.
void readFrame(PacketPtr pkt, Addr offset)
Helper methods to handle specific BAR read/writes.
void writeROM(PacketPtr pkt)
AMDGPUMemoryManager * getMemMgr()
void writeDoorbell(PacketPtr pkt, Addr offset)
RequestorID vramRequestorId()
Methods related to translations and system/device memory.
std::unordered_map< uint32_t, SDMAEngine * > sdmaIds
uint16_t allocateVMID(uint16_t pasid)
std::unordered_map< int, PM4PacketProcessor * > pm4PktProcs
void deallocatePasid(uint16_t pasid)
SDMAEngine * getSDMAById(int id)
void writeFrame(PacketPtr pkt, Addr offset)
void setSDMAEngine(Addr offset, SDMAEngine *eng)
memory::PhysicalMemory deviceMem
std::unordered_map< uint32_t, SDMAEngine * > sdmaEngs
GPUCommandProcessor * CP()
Handle MMIO reads/writes to register with "SMU" prefix.
Definition amdgpu_smu.hh:48
Helper class to read Linux kernel MMIO trace from amdgpu modprobes.
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
Definition addr_range.hh:82
Tick read(PacketPtr pkt) final
Final implementation of read access from PioDevice.
Definition device.cc:264
PciEndpoint(const PciEndpointParams &params)
Constructor for PCI Dev.
Definition device.cc:603
System DMA Engine class for AMD dGPU.
The physical memory encapsulates all memories in the system and provides basic functionality for acce...
Definition physical.hh:137
std::list< AddrRange > AddrRangeList
Convenience typedef for a collection of address ranges.
Definition addr_range.hh:64
Bitfield< 23, 0 > offset
Definition types.hh:144
Bitfield< 0 > p
Bitfield< 23 > k
Bitfield< 3 > addr
Definition types.hh:84
Copyright (c) 2024 Arm Limited 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
Bitfield< 10 > pasid
Definition x86_cpu.cc:129
uint64_t Tick
Tick count type.
Definition types.hh:58
uint16_t RequestorID
Definition request.hh:95
Packet * PacketPtr
std::size_t operator()(const AddrRange &k) const

Generated on Mon Oct 27 2025 04:13:01 for gem5 by doxygen 1.14.0