gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
amdgpu_nbio.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023 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 
33 
34 #include "debug/AMDGPUDevice.hh"
36 #include "mem/packet_access.hh"
37 
38 namespace gem5
39 {
40 
42 {
43  // All read-before-write MMIOs go here
45 }
46 
47 void
49 {
50  gpuDevice = gpu_device;
51 }
52 
53 void
55 {
56  switch (offset) {
57  // This is a PCIe status register. At some point during driver init
58  // the driver checks that interrupts are enabled. This is only
59  // checked once, so if the MMIO trace does not exactly line up with
60  // what the driver is doing in gem5, this may still have the first
61  // bit zero causing driver to fail. Therefore, we always set this
62  // bit to one as there is no harm to do so.
64  {
65  uint32_t value = pkt->getLE<uint32_t>() | 0x1;
66  DPRINTF(AMDGPUDevice, "Marking interrupts enabled: %#lx\n", value);
67  pkt->setLE<uint32_t>(value);
68  }
69  break;
70  case AMDGPU_MM_DATA:
71  //pkt->setLE<uint32_t>(regs[mm_index_reg]);
72  pkt->setLE<uint32_t>(gpuDevice->getRegVal(mm_index_reg));
73  break;
79  pkt->setLE<uint32_t>(0x10001);
80  break;
86  pkt->setLE<uint32_t>(0x1);
87  break;
88  // PSP responds with bit 31 set when ready
90  pkt->setLE<uint32_t>(0x80000000);
91  break;
92  default:
93  if (triggered_reads.count(offset)) {
94  DPRINTF(AMDGPUDevice, "Found triggered read for %#x\n", offset);
95  pkt->setLE<uint32_t>(triggered_reads[offset]);
96  } else if (gpuDevice->haveRegVal(offset)) {
97  uint32_t reg_val = gpuDevice->getRegVal(offset);
98 
99  DPRINTF(AMDGPUDevice, "Reading value of %#lx from regs: %#lx\n",
100  offset, reg_val);
101 
102  pkt->setLE<uint32_t>(reg_val);
103  } else {
104  DPRINTF(AMDGPUDevice, "NBIO Unknown MMIO %#x (%#x)\n", offset,
105  pkt->getAddr());
106  }
107  break;
108  }
109 }
110 
111 void
113 {
114  if (offset == AMDGPU_MM_INDEX) {
115  assert(pkt->getSize() == 4);
117  pkt->getLE<uint32_t>());
118  } else if (offset == AMDGPU_MM_INDEX_HI) {
119  assert(pkt->getSize() == 4);
121  pkt->getLE<uint32_t>());
122  } else if (offset == AMDGPU_MM_DATA) {
123  DPRINTF(AMDGPUDevice, "MM write to reg %#lx data %#lx\n",
124  mm_index_reg, pkt->getLE<uint32_t>());
125  gpuDevice->setRegVal(AMDGPU_MM_DATA, pkt->getLE<uint32_t>());
126  } else if (offset == AMDGPU_MP0_SMN_C2PMSG_35) {
127  // See psp_v3_1_bootloader_load_sos in amdgpu driver code.
128  if (pkt->getLE<uint32_t>() == 0x10000) {
130  }
131  } else if (offset == AMDGPU_MP0_SMN_C2PMSG_64) {
133  0x80000000 + pkt->getLE<uint32_t>();
134  } else if (offset == AMDGPU_MP0_SMN_C2PMSG_69) {
135  // PSP ring low addr
136  psp_ring = insertBits(psp_ring, 31, 0, pkt->getLE<uint32_t>());
138  - gpuDevice->getVM().getSysAddrRangeLow() + 0xc;
139  } else if (offset == AMDGPU_MP0_SMN_C2PMSG_70) {
140  // PSP ring high addr
141  psp_ring = insertBits(psp_ring, 63, 32, pkt->getLE<uint32_t>());
143  - gpuDevice->getVM().getSysAddrRangeLow() + 0xc;
144  } else if (offset == AMDGPU_MP0_SMN_C2PMSG_71) {
145  // PSP ring size
146  psp_ring_size = pkt->getLE<uint32_t>();
147  }
148 }
149 
150 bool
152 {
153  if (offset == psp_ring_dev_addr) {
154  psp_ring_value++;
155  pkt->setUintX(psp_ring_value, ByteOrder::little);
156 
157  return true;
158  }
159 
160  return false;
161 }
162 
163 void
165 {
166  if (offset == psp_ring_listen_addr) {
167  DPRINTF(AMDGPUDevice, "Saw psp_ring_listen_addr with size %ld value "
168  "%ld\n", pkt->getSize(), pkt->getUintX(ByteOrder::little));
169 
170  /*
171  * In ROCm versions 4.x this packet is a 4 byte value. In ROCm 5.x
172  * the packet is 8 bytes and mapped as a system address which needs
173  * to be subtracted out to get the framebuffer address.
174  */
175  if (pkt->getSize() == 4) {
176  psp_ring_dev_addr = pkt->getLE<uint32_t>();
177  } else if (pkt->getSize() == 8) {
178  psp_ring_dev_addr = pkt->getUintX(ByteOrder::little)
180  } else {
181  panic("Invalid write size to psp_ring_listen_addr\n");
182  }
183 
184  DPRINTF(AMDGPUDevice, "Setting PSP ring device address to %#lx\n",
186  }
187 }
188 
189 } // namespace gem5
gem5::AMDGPUNbio::psp_ring_listen_addr
Addr psp_ring_listen_addr
Definition: amdgpu_nbio.hh:115
gem5::Packet::getUintX
uint64_t getUintX(ByteOrder endian) const
Get the data in the packet byte swapped from the specified endianness and zero-extended to 64 bits.
Definition: packet.cc:352
AMDGPU_MM_DATA
#define AMDGPU_MM_DATA
Definition: amdgpu_nbio.hh:58
MI200_INV_ENG17_ACK2
#define MI200_INV_ENG17_ACK2
Definition: amdgpu_nbio.hh:84
gem5::AMDGPUDevice::getVM
AMDGPUVM & getVM()
Definition: amdgpu_device.hh:180
gem5::AMDGPUNbio::readMMIO
void readMMIO(PacketPtr pkt, Addr offset)
Definition: amdgpu_nbio.cc:54
gem5::AMDGPUNbio::psp_ring_value
int psp_ring_value
Definition: amdgpu_nbio.hh:117
gem5::AMDGPUNbio::psp_ring_size
int psp_ring_size
Definition: amdgpu_nbio.hh:116
AMDGPU_MP0_SMN_C2PMSG_70
#define AMDGPU_MP0_SMN_C2PMSG_70
Definition: amdgpu_nbio.hh:66
gem5::AMDGPUNbio::psp_ring_dev_addr
Addr psp_ring_dev_addr
Definition: amdgpu_nbio.hh:114
AMDGPU_MP0_SMN_C2PMSG_64
#define AMDGPU_MP0_SMN_C2PMSG_64
Definition: amdgpu_nbio.hh:64
AMDGPU_MM_INDEX
#define AMDGPU_MM_INDEX
MMIO offsets for NBIO.
Definition: amdgpu_nbio.hh:56
AMDGPU_MM_INDEX_HI
#define AMDGPU_MM_INDEX_HI
Definition: amdgpu_nbio.hh:57
gem5::AMDGPUNbio::psp_ring
Addr psp_ring
Definition: amdgpu_nbio.hh:113
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:210
amdgpu_device.hh
gem5::Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
gem5::AMDGPUDevice::setRegVal
void setRegVal(uint32_t addr, uint32_t value)
Definition: amdgpu_device.cc:547
AMDGPU_PCIE_DATA_REG
#define AMDGPU_PCIE_DATA_REG
Definition: amdgpu_nbio.hh:59
gem5::AMDGPUNbio::setGPUDevice
void setGPUDevice(AMDGPUDevice *gpu_device)
Definition: amdgpu_nbio.cc:48
gem5::ArmISA::offset
Bitfield< 23, 0 > offset
Definition: types.hh:144
gem5::AMDGPUDevice
Device model for an AMD GPU.
Definition: amdgpu_device.hh:62
gem5::insertBits
constexpr T insertBits(T val, unsigned first, unsigned last, B bit_val)
Returns val with bits first to last set to the LSBs of bit_val.
Definition: bitfield.hh:182
gem5::AMDGPUNbio::AMDGPUNbio
AMDGPUNbio()
Definition: amdgpu_nbio.cc:41
VEGA10_INV_ENG17_SEM1
#define VEGA10_INV_ENG17_SEM1
Definition: amdgpu_nbio.hh:73
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::AMDGPUNbio::readFrame
bool readFrame(PacketPtr pkt, Addr offset)
Definition: amdgpu_nbio.cc:151
packet_access.hh
gem5::AMDGPUNbio::mm_index_reg
uint64_t mm_index_reg
Definition: amdgpu_nbio.hh:107
gem5::AMDGPUDevice::haveRegVal
bool haveRegVal(uint32_t addr)
Register value getter/setter.
Definition: amdgpu_device.cc:533
VEGA10_INV_ENG17_ACK1
#define VEGA10_INV_ENG17_ACK1
Definition: amdgpu_nbio.hh:71
amdgpu_nbio.hh
VEGA10_INV_ENG17_ACK2
#define VEGA10_INV_ENG17_ACK2
Definition: amdgpu_nbio.hh:72
AMDGPU_MP0_SMN_C2PMSG_35
#define AMDGPU_MP0_SMN_C2PMSG_35
Definition: amdgpu_nbio.hh:63
AMDGPU_MP0_SMN_C2PMSG_71
#define AMDGPU_MP0_SMN_C2PMSG_71
Definition: amdgpu_nbio.hh:67
MI100_INV_ENG17_ACK2
#define MI100_INV_ENG17_ACK2
Definition: amdgpu_nbio.hh:77
MI100_INV_ENG17_SEM3
#define MI100_INV_ENG17_SEM3
Definition: amdgpu_nbio.hh:81
MI100_INV_ENG17_SEM2
#define MI100_INV_ENG17_SEM2
Definition: amdgpu_nbio.hh:80
gem5::Packet::getLE
T getLE() const
Get the data in the packet byte swapped from little endian to host endian.
Definition: packet_access.hh:78
gem5::AMDGPUVM::getSysAddrRangeLow
Addr getSysAddrRangeLow()
Definition: amdgpu_vm.hh:226
AMDGPU_MP0_SMN_C2PMSG_81
#define AMDGPU_MP0_SMN_C2PMSG_81
Definition: amdgpu_nbio.hh:68
gem5::Packet::setLE
void setLE(T v)
Set the value in the data pointer to v as little endian.
Definition: packet_access.hh:108
gem5::AMDGPUDevice::getRegVal
uint32_t getRegVal(uint32_t addr)
Definition: amdgpu_device.cc:539
gem5::AMDGPUNbio::writeFrame
void writeFrame(PacketPtr pkt, Addr offset)
Definition: amdgpu_nbio.cc:164
MI200_INV_ENG17_SEM2
#define MI200_INV_ENG17_SEM2
Definition: amdgpu_nbio.hh:86
gem5::Packet::getAddr
Addr getAddr() const
Definition: packet.hh:807
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::AMDGPUNbio::writeMMIO
void writeMMIO(PacketPtr pkt, Addr offset)
Definition: amdgpu_nbio.cc:112
gem5::Packet::setUintX
void setUintX(uint64_t w, ByteOrder endian)
Set the value in the word w after truncating it to the length of the packet and then byteswapping it ...
Definition: packet.cc:361
VEGA10_INV_ENG17_SEM2
#define VEGA10_INV_ENG17_SEM2
Definition: amdgpu_nbio.hh:74
gem5::AMDGPUNbio::triggered_reads
std::unordered_map< uint32_t, uint32_t > triggered_reads
Definition: amdgpu_nbio.hh:108
gem5::Packet::getSize
unsigned getSize() const
Definition: packet.hh:817
gem5::AMDGPUNbio::gpuDevice
AMDGPUDevice * gpuDevice
Definition: amdgpu_nbio.hh:102
AMDGPU_MP0_SMN_C2PMSG_69
#define AMDGPU_MP0_SMN_C2PMSG_69
Definition: amdgpu_nbio.hh:65
MI100_INV_ENG17_ACK3
#define MI100_INV_ENG17_ACK3
Definition: amdgpu_nbio.hh:78
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:188

Generated on Sun Jul 30 2023 01:56:54 for gem5 by doxygen 1.8.17