gem5 v24.0.0.0
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"
44#include "dev/io_device.hh"
45#include "dev/pci/device.hh"
46#include "enums/GfxVersion.hh"
47#include "params/AMDGPUDevice.hh"
48
49namespace gem5
50{
51
52class AMDGPUInterruptHandler;
53class SDMAEngine;
54
63class AMDGPUDevice : public PciDevice
64{
65 private:
69 void dispatchAccess(PacketPtr pkt, bool read);
70
79 void readFrame(PacketPtr pkt, Addr offset);
81 void readMMIO(PacketPtr pkt, Addr offset);
82
85 void writeMMIO(PacketPtr pkt, Addr offset);
86
90 std::unordered_map<uint32_t, DoorbellInfo> doorbells;
91 std::unordered_map<uint32_t, PacketPtr> pendingDoorbellPkts;
92
97 bool isROM(Addr addr) const { return romRange.contains(addr); }
98 void readROM(PacketPtr pkt);
99 void writeROM(PacketPtr pkt);
100
101 std::array<uint8_t, ROM_SIZE> rom;
102
107
117
119 {
120 std::size_t operator()(const AddrRange& k) const
121 {
122 return k.start();
123 }
124 };
125 std::unordered_map<int, PM4PacketProcessor *> pm4PktProcs;
126 std::unordered_map<AddrRange, PM4PacketProcessor *,
128
129 // SDMAs mapped by doorbell offset
130 std::unordered_map<uint32_t, SDMAEngine *> sdmaEngs;
131 // SDMAs mapped by ID
132 std::unordered_map<uint32_t, SDMAEngine *> sdmaIds;
133 // SDMA ID to MMIO range
134 std::unordered_map<uint32_t, AddrRange> sdmaMmios;
135 // SDMA ID to function
136 typedef void (SDMAEngine::*sdmaFuncPtr)(uint32_t);
137 std::unordered_map<uint32_t, sdmaFuncPtr> sdmaFunc;
138
144
145 // VMIDs data structures
146 // map of pasids to vmids
147 std::unordered_map<uint16_t, uint16_t> idMap;
148 // map of doorbell offsets to vmids
149 std::unordered_map<Addr, uint16_t> doorbellVMIDMap;
150 // map of vmid to all queue ids using that vmid
151 std::unordered_map<uint16_t, std::set<int>> usedVMIDs;
152 // last vmid allocated by map_process PM4 packet
153 uint16_t _lastVMID;
154
155 /*
156 * Backing store for GPU memory / framebuffer / VRAM
157 */
159
160 /* Device information */
161 GfxVersion gfx_version = GfxVersion::gfx900;
162
163 public:
164 AMDGPUDevice(const AMDGPUDeviceParams &p);
165
169 void intrPost();
170
171 Tick writeConfig(PacketPtr pkt) override;
172 Tick readConfig(PacketPtr pkt) override;
173
174 Tick read(PacketPtr pkt) override;
175 Tick write(PacketPtr pkt) override;
176
177 AddrRangeList getAddrRanges() const override;
178
182 void serialize(CheckpointOut &cp) const override;
183 void unserialize(CheckpointIn &cp) override;
184
189 SDMAEngine* getSDMAById(int id);
191 AMDGPUVM &getVM() { return gpuvm; }
193 GPUCommandProcessor* CP() { return cp; }
194
198 void setDoorbellType(uint32_t offset, QueueType qt, int ip_id = 0);
199 void unsetDoorbell(uint32_t offset);
200 void processPendingDoorbells(uint32_t offset);
202
207 uint32_t getRegVal(uint64_t addr);
208 void setRegVal(uint64_t addr, uint32_t value);
209
214
215 /* HW context stuff */
216 uint16_t lastVMID() { return _lastVMID; }
217 uint16_t allocateVMID(uint16_t pasid);
218 void deallocateVmid(uint16_t vmid);
219 void deallocatePasid(uint16_t pasid);
220 void deallocateAllQueues();
221 void mapDoorbellToVMID(Addr doorbell, uint16_t vmid);
222 uint16_t getVMID(Addr doorbell) { return doorbellVMIDMap[doorbell]; }
223 std::unordered_map<uint16_t, std::set<int>>& getUsedVMIDs();
224 void insertQId(uint16_t vmid, int id);
225
226 /* Device information */
227 GfxVersion getGfxVersion() const { return gfx_version; }
228};
229
230} // namespace gem5
231
232#endif // __DEV_AMDGPU_AMDGPU_DEVICE_HH__
Device model for an AMD GPU.
void insertQId(uint16_t vmid, int id)
std::unordered_map< AddrRange, PM4PacketProcessor *, AddrRangeHasher > pm4Ranges
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 write(PacketPtr pkt) override
Pure virtual function that the device must implement.
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()
std::array< uint8_t, ROM_SIZE > rom
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
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
Write to the PCI config space data that is stored locally.
AMDGPUInterruptHandler * getIH()
Get handles to GPU blocks.
AMDMMIOReader mmioReader
MMIO reader to populate device registers map.
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
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)
void mapDoorbellToVMID(Addr doorbell, uint16_t vmid)
void intrPost()
Methods inherited from PciDevice.
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()
RequestorID getRequestorID() const
Get the requestorID for the memory manager.
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
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
PCI device, base implementation is only config space.
Definition device.hh:270
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
bool contains(const Addr &a) const
Determine if the range contains an address.
Bitfield< 23, 0 > offset
Definition types.hh:144
Bitfield< 0 > p
Bitfield< 23 > k
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
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
std::size_t operator()(const AddrRange &k) const

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