gem5 v24.0.0.0
Loading...
Searching...
No Matches
mmio_reader.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_MMIO_READER_HH__
33#define __DEV_AMDGPU_MMIO_READER_HH__
34
35#include <cstdint>
36#include <list>
37#include <string>
38#include <tuple>
39#include <unordered_map>
40#include <vector>
41
42#include "base/logging.hh"
43#include "mem/packet.hh"
44
45namespace gem5
46{
47
63{
64 private:
70 const uint64_t BAR0 = 0x2400000000;
71 const uint64_t BAR2 = 0x2200000000;
72 const uint32_t BAR5 = 0xecf00000;
73 const uint32_t ROM = 0xc0000;
74
75 /* Sizes based on Vega Frontier Edition */
76 const uint64_t BAR0_SIZE = 0x400000000; // 16GB
77 const uint64_t BAR2_SIZE = 0x200000; // 2MB
78 const uint32_t BAR5_SIZE = 0x80000; // 512kB
79 const uint32_t ROM_SIZE = 0x20000; // 128kB
80
90 /* trace_entry containing (3), (4), and (5). */
91 typedef std::tuple<uint64_t, std::tuple<char, uint64_t>> trace_entry_t;
92
93 /* Trace entries are recorded as a list for each offset in a given BAR. */
94 typedef std::unordered_map<uint32_t, std::list<trace_entry_t>> trace_BAR_t;
95
96 /* There are 7 BARs (BAR0-BAR5 + expansion ROM) */
98
99 /* Indexes used to print driver loading progress. */
100 uint64_t trace_index = 0;
101 uint64_t trace_final_index = 0;
102 uint64_t trace_cur_index = 0;
103
104 /* An entry in the MMIO trace. */
106 {
107 char event;
108 uint16_t size;
109 uint16_t bar;
110 uint64_t addr;
111 uint64_t data;
112 uint64_t index;
114
115 /* Lines in the MMIO trace we care about begin with R, W, or UNKNOWN. */
116 bool
117 traceIsRead(std::vector <std::string> tokens) const
118 {
119 return tokens[0] == "R";
120 }
121
122 bool
123 traceIsWrite(std::vector <std::string> tokens) const
124 {
125 return tokens[0] == "W";
126 }
127
128 bool
129 traceIsUnknown(std::vector <std::string> tokens) const
130 {
131 return tokens[0] == "UNKNOWN";
132 }
133
134 /* Checks if this line of trace is W/R/UNKNOWN */
135 bool
136 isIO(std::vector <std::string> tokens) const
137 {
138 return tokens[0] == "R" || tokens[0] == "W" || tokens[0] == "UNKNOWN";
139 }
140
141 /* Checks if this line of trace is in a BAR we care about (0, 2, 5) */
142 bool
143 isRelevant(std::vector <std::string> tokens)
144 {
145 uint64_t addr = strtoull(tokens[4].c_str(), nullptr, 16);
146 uint16_t bar = traceGetBAR(addr);
147 return (bar == 0 || bar == 2 || bar == 5);
148 }
149
150 uint8_t
152 {
153 if (BAR0 <= addr && addr < (BAR0 + BAR0_SIZE)) {
154 return 0;
155 } else if (BAR2 <= addr && addr < (BAR2 + BAR2_SIZE)) {
156 return 2;
157 } else if (BAR5 <= addr && addr < (BAR5 + BAR5_SIZE)) {
158 return 5;
159 } else if (ROM <= addr && addr < (ROM + ROM_SIZE)) {
160 return 6;
161 } else {
162 return -1;
163 }
164 }
165
166 uint64_t
168 {
169 if (addr >= BAR0 && addr < (BAR0 + BAR0_SIZE)) {
170 return addr - BAR0;
171 } else if (addr >= BAR2 && addr < (BAR2 + BAR2_SIZE)) {
172 return addr - BAR2;
173 } else if (addr >= BAR5 && addr < (BAR5 + BAR5_SIZE)) {
174 return addr - BAR5;
175 } else if (addr >= ROM && addr < (ROM + ROM_SIZE)) {
176 return addr - ROM;
177 } else {
178 panic("Can't find offset for the address in MMIO trace!");
179 }
180 }
181
182 void
183 traceParseTokens(std::vector <std::string> tokens)
184 {
185 if (traceIsRead(tokens) || traceIsWrite(tokens)) {
186 mtrace.event = traceIsRead(tokens) ? 'R' : 'W';
187 mtrace.size = strtoul(tokens[1].c_str(), nullptr, 10);
188 mtrace.addr = strtoull(tokens[4].c_str(), nullptr, 16);
189 mtrace.data = strtoull(tokens[5].c_str(), nullptr, 16);
190 }
191 else if (traceIsUnknown(tokens)) {
192 mtrace.event = 'U';
193 mtrace.size = 0;
194 mtrace.addr = strtoull(tokens[3].c_str(), nullptr, 16);
195 mtrace.data = 0;
196 }
198
200 trace_index++;
201 }
202
203 void
205 {
206 trace_entry_t trace_entry;
207 trace_entry = std::make_tuple(mtrace.index,
208 std::make_tuple(mtrace.event, mtrace.data));
209
210 uint16_t barnum = mtrace.bar;
211 uint64_t offset = traceGetOffset(mtrace.addr);
212
213 trace_BARs[barnum][offset].push_back(trace_entry);
214 }
215
216 public:
219
226 void readMMIOTrace(std::string trace_file);
227
236 void readFromTrace(PacketPtr pkt, int barnum, Addr offset);
237
247 void writeFromTrace(PacketPtr pkt, int barnum, Addr offset);
248};
249
250} // namespace gem5
251
252#endif // __DEV_AMDGPU_MMIO_READER_HH__
Helper class to read Linux kernel MMIO trace from amdgpu modprobes.
void readMMIOTrace(std::string trace_file)
Read an MMIO trace gathered from a real system and place the MMIO values read and written into the MM...
void writeFromTrace(PacketPtr pkt, int barnum, Addr offset)
Get the next MMIO write from the trace file to an offset in a BAR and compare the value with the data...
std::tuple< uint64_t, std::tuple< char, uint64_t > > trace_entry_t
The information we want from each relevant line of trace are: (1) The BAR number where the accessed a...
const uint32_t BAR5_SIZE
const uint64_t BAR2
const uint64_t BAR0
These are the BAR values from the system where the trace is collected.
void readFromTrace(PacketPtr pkt, int barnum, Addr offset)
Get the next MMIO read from the trace file to an offset in a BAR and write the value to the packet pr...
bool isIO(std::vector< std::string > tokens) const
trace_BAR_t trace_BARs[6]
const uint32_t ROM
bool traceIsUnknown(std::vector< std::string > tokens) const
const uint64_t BAR0_SIZE
bool traceIsWrite(std::vector< std::string > tokens) const
bool isRelevant(std::vector< std::string > tokens)
uint8_t traceGetBAR(uint64_t addr)
bool traceIsRead(std::vector< std::string > tokens) const
void traceParseTokens(std::vector< std::string > tokens)
const uint64_t BAR2_SIZE
struct gem5::AMDMMIOReader::MmioTrace mtrace
std::unordered_map< uint32_t, std::list< trace_entry_t > > trace_BAR_t
const uint32_t BAR5
uint64_t traceGetOffset(uint64_t addr)
const uint32_t ROM_SIZE
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
Bitfield< 23, 0 > offset
Definition types.hh:144
Bitfield< 3 > addr
Definition types.hh:84
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
Declaration of the Packet class.

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