-
Notifications
You must be signed in to change notification settings - Fork 0
/
cdmatrace.cpp
330 lines (279 loc) · 7.51 KB
/
cdmatrace.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
/*
* Copyright (c) 2014-2015 Dmitry Osipenko <digetx@gmail.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include <QColor>
#include <QTime>
#include <QtCore/qmath.h>
#include "cdmatrace.h"
#include "host1x_cmd_processor.h"
#include "tracecore.h"
#define DMA_START 0xA
#define DMA_STOP 0xB
void CdmaTrace::validateEntry(log_entry &entry)
{
switch (CMD_OPCODE(entry.data)) {
case SETCL:
{
setcl_op op = { .reg32 = entry.data };
if (m_class_id != op.class_id)
emit cdmaStarted(op.class_id);
m_class_id = op.class_id;
entry.class_id = 0;
return;
}
case INCR:
case NONINCR:
case MASK:
case IMM:
case RESTART:
case GATHER:
case EXTEND:
case CHDONE:
entry.class_id = m_class_id;
break;
default:
entry.invalid = true;
break;
}
entry.class_id = m_class_id;
}
void CdmaTrace::setLogPath(const QString ldir)
{
m_log.setLogFilePath(ldir + m_name + ".txt");
}
QString CdmaTrace::entryAsString(void *e) const
{
log_entry *entry = (CdmaTrace::log_entry*) e;
QTime mstime = QTime(0, 0).addMSecs(entry->time / 1000);
QString ret;
ret = mstime.toString("hh:mm:ss.zzz") +
QString().sprintf(".%03d\t", entry->time % 1000);
if (entry->class_id)
ret += QString().sprintf("Class 0x%02X ",entry-> class_id);
ret += CdmaTrace::opcodeName(CMD_OPCODE(entry->data)) + ": ";
ret += CdmaTrace::cmdParams(entry->data);
return ret;
}
void CdmaTrace::write_log(log_entry &entry)
{
bool log_is_full = m_log.write(entry);
emit layoutChanged();
if (log_is_full) {
emit itemInserted();
}
}
void CdmaTrace::trace(const u_int32_t &time, const u_int32_t &data, const bool &is_gather)
{
log_entry entry = {
.time = time,
.data = data,
.class_id = 0,
.is_gather = is_gather,
.invalid = false,
};
validateEntry(entry);
write_log(entry);
if (!m_update_stats_timer.isActive())
m_update_stats_timer.start(300);
m_access_nb++;
}
void CdmaTrace::updateStats(void)
{
setText(0, m_name + QString().sprintf(" (%lu)", m_access_nb));
m_log.flush();
}
int CdmaTrace::rowCount(const QModelIndex &) const
{
return m_log.size();
}
int CdmaTrace::columnCount(const QModelIndex &) const
{
return CdmaTrace::COLUMNS_NB;
}
QString CdmaTrace::opcodeName(u_int8_t opcode) const
{
switch (opcode) {
case SETCL:
return "SETCL";
case INCR:
return "INCR";
case NONINCR:
return "NONINCR";
case MASK:
return "MASK";
case IMM:
return "IMM";
case RESTART:
return "RESTART";
case GATHER:
return "GATHER";
case EXTEND:
return "EXTEND";
case CHDONE:
return "CHDONE";
default:
return QString().sprintf("0x%02X", opcode);
}
}
QString CdmaTrace::cmdParams(u_int32_t &data) const
{
switch ( CMD_OPCODE(data) ) {
case SETCL:
{
setcl_op op = { .reg32 = data };
return QString().sprintf("mask=0x%X class_id=0x%02X offset=0x%X",
op.mask, op.class_id, op.offset);
}
case INCR:
case NONINCR:
{
incr_op op = { .reg32 = data };
return QString().sprintf("count=%d offset=0x%X",
op.count, op.offset);
}
case MASK:
{
mask_op op = { .reg32 = data };
return QString().sprintf("mask=0x%X offset=0x%X",
op.mask, op.offset);
}
case IMM:
{
imm_op op = { .reg32 = data };
return QString().sprintf("immdata=0x%X offset=0x%X",
op.immdata, op.offset);
}
case GATHER:
{
gather_op op = { .reg32 = data };
return QString().sprintf("incrcount=%d insert=%d incr=%d offset=0x%X",
op.incrcount, op.insert, op.incr, op.offset);
}
case EXTEND:
{
extend_op op = { .reg32 = data };
switch (op.subop) {
case ACQUIRE_MLOCK:
return QString().sprintf("subop=ACQUIRE_MLOCK id=%d", op.value);
case RELEASE_MLOCK:
return QString().sprintf("subop=RELEASE_MLOCK id=%d", op.value);
default:
return QString().sprintf("value=0x%X subop=0x%X",
op.value, op.subop);
}
}
case RESTART:
{
restart_op op = { .reg32 = data };
return QString().sprintf("new_get=%d", op.offset);
}
case CHDONE:
return QString();
case START:
return "CDMA start";
case STOP:
return "CDMA stop";
default:
return QString().sprintf("0x%08X", data);
}
}
QVariant CdmaTrace::data(const QModelIndex &index, int role) const
{
log_entry entry;
QTime mstime;
Q_ASSERT(index.row() < m_log.size());
switch (role) {
case Qt::EditRole:
case Qt::DisplayRole:
{
entry = m_log.read( index.row() );
switch ( index.column() ) {
case CdmaTrace::CMD:
return opcodeName(CMD_OPCODE(entry.data));
case CdmaTrace::PARAMS:
return cmdParams(entry.data);
case CdmaTrace::CLASS_ID:
if (entry.class_id)
return QString().sprintf("0x%02X", entry.class_id);
break;
case CdmaTrace::TIME:
{
mstime = QTime(0, 0).addMSecs(entry.time / 1000);
return mstime.toString("hh:mm:ss.zzz") +
QString().sprintf(".%03d", entry.time % 1000);
}
default:
break;
}
break;
}
case Qt::BackgroundRole:
{
entry = m_log.read( index.row() );
if (entry.is_gather)
return QColor(200, 255, 200);
if ((entry.data >> 28) == DMA_START)
return QColor(255, 255, 150);
if ((entry.data >> 28) == DMA_STOP)
return QColor(150, 150, 255);
break;
}
default:
break;
}
return QVariant();
}
QVariant CdmaTrace::headerData(int section, Qt::Orientation, int role) const
{
switch (role) {
case Qt::DisplayRole:
switch (section) {
case CdmaTrace::CMD:
return "Command";
case CdmaTrace::CLASS_ID:
return "Class ID";
case CdmaTrace::PARAMS:
return "Params";
case CdmaTrace::TIME:
return "Time";
default:
break;
}
default:
break;
}
return QVariant();
}
int CdmaTrace::deviceType() const
{
return TraceDev::HOST1X_CDMA;
}
void CdmaTrace::ClearLog()
{
m_class_id = 0;
m_access_nb = 0;
m_log.clear();
updateStats();
emit layoutChanged();
}
bool CdmaTrace::is_valid(u_int32_t ch_id)
{
return ch_id == m_ch_id;
}
Qt::ItemFlags CdmaTrace::flags(const QModelIndex &index) const
{
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
}