gem5 v23.0.0.1
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
38namespace gem5
39{
40
42{
43 // All read-before-write MMIOs go here
45}
46
47void
49{
50 gpuDevice = gpu_device;
51}
52
53void
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
111void
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>());
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>());
144 } else if (offset == AMDGPU_MP0_SMN_C2PMSG_71) {
145 // PSP ring size
146 psp_ring_size = pkt->getLE<uint32_t>();
147 }
148}
149
150bool
152{
153 if (offset == psp_ring_dev_addr) {
155 pkt->setUintX(psp_ring_value, ByteOrder::little);
156
157 return true;
158 }
159
160 return false;
161}
162
163void
165{
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
#define AMDGPU_MM_INDEX_HI
#define VEGA10_INV_ENG17_ACK2
#define VEGA10_INV_ENG17_ACK1
#define MI100_INV_ENG17_SEM2
#define AMDGPU_MP0_SMN_C2PMSG_81
#define AMDGPU_MP0_SMN_C2PMSG_71
#define AMDGPU_MP0_SMN_C2PMSG_64
#define MI100_INV_ENG17_ACK2
#define MI200_INV_ENG17_SEM2
#define AMDGPU_MP0_SMN_C2PMSG_35
#define AMDGPU_MM_INDEX
MMIO offsets for NBIO.
#define AMDGPU_PCIE_DATA_REG
#define VEGA10_INV_ENG17_SEM1
#define MI100_INV_ENG17_ACK3
#define MI100_INV_ENG17_SEM3
#define MI200_INV_ENG17_ACK2
#define AMDGPU_MP0_SMN_C2PMSG_69
#define AMDGPU_MM_DATA
#define VEGA10_INV_ENG17_SEM2
#define AMDGPU_MP0_SMN_C2PMSG_70
#define DPRINTF(x,...)
Definition trace.hh:210
Device model for an AMD GPU.
uint32_t getRegVal(uint32_t addr)
bool haveRegVal(uint32_t addr)
Register value getter/setter.
void setRegVal(uint32_t addr, uint32_t value)
void readMMIO(PacketPtr pkt, Addr offset)
std::unordered_map< uint32_t, uint32_t > triggered_reads
void writeMMIO(PacketPtr pkt, Addr offset)
bool readFrame(PacketPtr pkt, Addr offset)
uint64_t mm_index_reg
AMDGPUDevice * gpuDevice
void writeFrame(PacketPtr pkt, Addr offset)
void setGPUDevice(AMDGPUDevice *gpu_device)
Addr getSysAddrRangeLow()
Definition amdgpu_vm.hh:226
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
Addr getAddr() const
Definition packet.hh:807
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
void setLE(T v)
Set the value in the data pointer to v as little endian.
unsigned getSize() const
Definition packet.hh:817
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
T getLE() const
Get the data in the packet byte swapped from little endian to host endian.
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
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
Bitfield< 23, 0 > offset
Definition types.hh:144
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147

Generated on Mon Jul 10 2023 15:32:02 for gem5 by doxygen 1.9.7