gem5 v23.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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"
43#include "dev/io_device.hh"
44#include "dev/pci/device.hh"
45#include "enums/GfxVersion.hh"
46#include "params/AMDGPUDevice.hh"
47
48namespace gem5
49{
50
51class AMDGPUInterruptHandler;
52class SDMAEngine;
53
62class AMDGPUDevice : public PciDevice
63{
64 private:
68 void dispatchAccess(PacketPtr pkt, bool read);
69
78 void readFrame(PacketPtr pkt, Addr offset);
80 void readMMIO(PacketPtr pkt, Addr offset);
81
84 void writeMMIO(PacketPtr pkt, Addr offset);
85
89 using GPURegMap = std::unordered_map<uint32_t, uint64_t>;
91 std::unordered_map<uint32_t, QueueType> doorbells;
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
118 // SDMAs mapped by doorbell offset
119 std::unordered_map<uint32_t, SDMAEngine *> sdmaEngs;
120 // SDMAs mapped by ID
121 std::unordered_map<uint32_t, SDMAEngine *> sdmaIds;
122 // SDMA ID to MMIO range
123 std::unordered_map<uint32_t, AddrRange> sdmaMmios;
124 // SDMA ID to function
125 typedef void (SDMAEngine::*sdmaFuncPtr)(uint32_t);
126 std::unordered_map<uint32_t, sdmaFuncPtr> sdmaFunc;
127
133
134 // VMIDs data structures
135 // map of pasids to vmids
136 std::unordered_map<uint16_t, uint16_t> idMap;
137 // map of doorbell offsets to vmids
138 std::unordered_map<Addr, uint16_t> doorbellVMIDMap;
139 // map of vmid to all queue ids using that vmid
140 std::unordered_map<uint16_t, std::set<int>> usedVMIDs;
141 // last vmid allocated by map_process PM4 packet
142 uint16_t _lastVMID;
143
144 /*
145 * Backing store for GPU memory / framebuffer / VRAM
146 */
148
149 /* Device information */
150 GfxVersion gfx_version = GfxVersion::gfx900;
151
152 public:
153 AMDGPUDevice(const AMDGPUDeviceParams &p);
154
158 void intrPost();
159
160 Tick writeConfig(PacketPtr pkt) override;
161 Tick readConfig(PacketPtr pkt) override;
162
163 Tick read(PacketPtr pkt) override;
164 Tick write(PacketPtr pkt) override;
165
166 AddrRangeList getAddrRanges() const override;
167
171 void serialize(CheckpointOut &cp) const override;
172 void unserialize(CheckpointIn &cp) override;
173
178 SDMAEngine* getSDMAById(int id);
180 AMDGPUVM &getVM() { return gpuvm; }
182 GPUCommandProcessor* CP() { return cp; }
183
187 void setDoorbellType(uint32_t offset, QueueType qt);
189
194 bool haveRegVal(uint32_t addr);
195 uint32_t getRegVal(uint32_t addr);
196 void setRegVal(uint32_t addr, uint32_t value);
197
202
203 /* HW context stuff */
204 uint16_t lastVMID() { return _lastVMID; }
205 uint16_t allocateVMID(uint16_t pasid);
206 void deallocateVmid(uint16_t vmid);
207 void deallocatePasid(uint16_t pasid);
208 void deallocateAllQueues();
209 void mapDoorbellToVMID(Addr doorbell, uint16_t vmid);
210 uint16_t getVMID(Addr doorbell) { return doorbellVMIDMap[doorbell]; }
211 std::unordered_map<uint16_t, std::set<int>>& getUsedVMIDs();
212 void insertQId(uint16_t vmid, int id);
213
214 /* Device information */
215 GfxVersion getGfxVersion() const { return gfx_version; }
216};
217
218} // namespace gem5
219
220#endif // __DEV_AMDGPU_AMDGPU_DEVICE_HH__
Device model for an AMD GPU.
void insertQId(uint16_t vmid, int id)
uint32_t getRegVal(uint32_t addr)
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.
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
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
PM4PacketProcessor * pm4PktProc
void setDoorbellType(uint32_t offset, QueueType qt)
Set handles to GPU blocks.
void readROM(PacketPtr pkt)
AddrRange romRange
VGA ROM methods.
std::unordered_map< uint16_t, std::set< int > > & getUsedVMIDs()
std::array< uint8_t, ROM_SIZE > rom
bool isROM(Addr addr) const
std::unordered_map< uint32_t, AddrRange > sdmaMmios
void(SDMAEngine::* sdmaFuncPtr)(uint32_t)
SDMAEngine * getSDMAEngine(Addr offset)
AMDGPUMemoryManager * gpuMemMgr
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.
bool haveRegVal(uint32_t addr)
Register value getter/setter.
void dispatchAccess(PacketPtr pkt, bool read)
Convert a PCI packet into a response.
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
void setRegVal(uint32_t addr, uint32_t value)
uint16_t allocateVMID(uint16_t pasid)
std::unordered_map< uint32_t, uint64_t > GPURegMap
Structures to hold registers, doorbells, and some frame memory.
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, QueueType > doorbells
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< 3 > addr
Definition types.hh:84
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
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
uint64_t Tick
Tick count type.
Definition types.hh:58
uint16_t RequestorID
Definition request.hh:95

Generated on Mon Jul 10 2023 14:24:30 for gem5 by doxygen 1.9.7