gem5  v22.1.0.0
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"
39 #include "dev/amdgpu/amdgpu_vm.hh"
42 #include "dev/io_device.hh"
43 #include "dev/pci/device.hh"
44 #include "params/AMDGPUDevice.hh"
45 
46 namespace gem5
47 {
48 
49 class AMDGPUInterruptHandler;
50 class SDMAEngine;
51 
60 class AMDGPUDevice : public PciDevice
61 {
62  private:
66  void dispatchAccess(PacketPtr pkt, bool read);
67 
76  void readFrame(PacketPtr pkt, Addr offset);
77  void readDoorbell(PacketPtr pkt, Addr offset);
78  void readMMIO(PacketPtr pkt, Addr offset);
79 
80  void writeFrame(PacketPtr pkt, Addr offset);
82  void writeMMIO(PacketPtr pkt, Addr offset);
83 
87  using GPURegMap = std::unordered_map<uint32_t, uint64_t>;
89  std::unordered_map<uint32_t, QueueType> doorbells;
90 
95  bool isROM(Addr addr) const { return romRange.contains(addr); }
96  void readROM(PacketPtr pkt);
97 
98  std::array<uint8_t, ROM_SIZE> rom;
99 
104 
113  std::unordered_map<uint32_t, SDMAEngine *> sdmaEngs;
116 
122 
123  // VMIDs data structures
124  // map of pasids to vmids
125  std::unordered_map<uint16_t, uint16_t> idMap;
126  // map of doorbell offsets to vmids
127  std::unordered_map<Addr, uint16_t> doorbellVMIDMap;
128  // map of vmid to all queue ids using that vmid
129  std::unordered_map<uint16_t, std::set<int>> usedVMIDs;
130  // last vmid allocated by map_process PM4 packet
131  uint16_t _lastVMID;
132 
133  /*
134  * Backing store for GPU memory / framebuffer / VRAM
135  */
137 
138  public:
139  AMDGPUDevice(const AMDGPUDeviceParams &p);
140 
144  void intrPost();
145 
146  Tick writeConfig(PacketPtr pkt) override;
147  Tick readConfig(PacketPtr pkt) override;
148 
149  Tick read(PacketPtr pkt) override;
150  Tick write(PacketPtr pkt) override;
151 
152  AddrRangeList getAddrRanges() const override;
153 
157  void serialize(CheckpointOut &cp) const override;
158  void unserialize(CheckpointIn &cp) override;
159 
164  SDMAEngine* getSDMAById(int id);
166  AMDGPUVM &getVM() { return gpuvm; }
168  GPUCommandProcessor* CP() { return cp; }
169 
173  void setDoorbellType(uint32_t offset, QueueType qt);
174  void setSDMAEngine(Addr offset, SDMAEngine *eng);
175 
180  uint32_t getRegVal(uint32_t addr);
181  void setRegVal(uint32_t addr, uint32_t value);
182 
187 
188  /* HW context stuff */
189  uint16_t lastVMID() { return _lastVMID; }
190  uint16_t allocateVMID(uint16_t pasid);
191  void deallocateVmid(uint16_t vmid);
192  void deallocatePasid(uint16_t pasid);
193  void deallocateAllQueues();
194  void mapDoorbellToVMID(Addr doorbell, uint16_t vmid);
195  uint16_t getVMID(Addr doorbell) { return doorbellVMIDMap[doorbell]; }
196  std::unordered_map<uint16_t, std::set<int>>& getUsedVMIDs();
197  void insertQId(uint16_t vmid, int id);
198 };
199 
200 } // namespace gem5
201 
202 #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)
Register value getter/setter.
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
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
SDMAEngine * sdma0
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
GPUCommandProcessor * CP()
AMDGPUMemoryManager * getMemMgr()
SDMAEngine * sdma1
SDMAEngine * getSDMAEngine(Addr offset)
AMDGPUMemoryManager * gpuMemMgr
Blocks of the GPU.
AMDGPUDevice(const AMDGPUDeviceParams &p)
void readDoorbell(PacketPtr pkt, Addr offset)
uint16_t getVMID(Addr doorbell)
Tick readConfig(PacketPtr pkt) override
Read from the PCI config space data that is stored locally.
std::unordered_map< uint16_t, std::set< int > > usedVMIDs
AMDGPUVM & getVM()
AMDGPUInterruptHandler * deviceIH
Tick writeConfig(PacketPtr pkt) override
Write to the PCI config space data that is stored locally.
AMDMMIOReader mmioReader
MMIO reader to populate device registers map.
AMDGPUInterruptHandler * getIH()
Get handles to GPU blocks.
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.
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 writeDoorbell(PacketPtr pkt, Addr offset)
RequestorID vramRequestorId()
Methods related to translations and system/device memory.
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
RequestorID getRequestorID() const
Get the requestorID for the memory manager.
Helper class to read Linux kernel MMIO trace from amdgpu modprobes.
Definition: mmio_reader.hh:63
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:294
PCI device, base implementation is only config space.
Definition: device.hh:270
System DMA Engine class for AMD dGPU.
Definition: sdma_engine.hh:48
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.
Definition: addr_range.hh:471
Bitfield< 23, 0 > offset
Definition: types.hh:144
Bitfield< 54 > p
Definition: pagetable.hh:70
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 Wed Dec 21 2022 10:22:32 for gem5 by doxygen 1.9.1