-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhtm_setup.c
More file actions
364 lines (320 loc) · 10.7 KB
/
htm_setup.c
File metadata and controls
364 lines (320 loc) · 10.7 KB
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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <inttypes.h>
#include "xscom.h"
#include "htm.h"
#define ERR(fmt...) do { fprintf(stderr, fmt); fflush(stderr); } while(0)
#define DBG(fmt...) do { if (verbose) printf(fmt); } while(0)
#define MAX_TIMEOUT 5
#define QUEUE_SIZE 16
#define MEG 0x100000
uint64_t parse_mem_size(uint64_t i_memsize, bool *i_use_small_mem)
{
uint64_t memsize;
*i_use_small_mem=false;
char buf[20];
memsize = i_memsize / MEG;
if (memsize < 1024){
snprintf(buf, sizeof buf, "%"PRIu64, memsize);
strcat(buf,"M");
DBG("memsize %s\n",buf);
}else{
memsize = memsize / 1024;
snprintf(buf, sizeof buf, "%"PRIu64, memsize);
strcat(buf,"G");
}
if (strcasecmp(buf, "16M") == 0) {memsize = HTM_512M_OR_16M;*i_use_small_mem=true;}
else if (strcasecmp(buf, "32M") == 0) {memsize = HTM_512M_OR_16M;*i_use_small_mem=true;}
else if (strcasecmp(buf, "32M") == 0) {memsize = HTM_1G_OR_32M;*i_use_small_mem=true;}
else if (strcasecmp(buf, "64M") == 0) {memsize = HTM_2G_OR_64M;*i_use_small_mem=true;}
else if (strcasecmp(buf, "128M") == 0) {memsize = HTM_4G_OR_128M;*i_use_small_mem=true;}
else if (strcasecmp(buf, "256M") == 0) {memsize = HTM_8G_OR_256M;*i_use_small_mem=true;}
else if (strcasecmp(buf, "512M") == 0) {memsize = HTM_512M_OR_16M;}
else if (strcasecmp(buf, "1G") == 0) {memsize = HTM_1G_OR_32M;}
else if (strcasecmp(buf, "2G") == 0) {memsize = HTM_2G_OR_64M;}
else if (strcasecmp(buf, "4G") == 0) {memsize = HTM_4G_OR_128M;}
else if (strcasecmp(buf, "8G") == 0) {memsize = HTM_8G_OR_256M;}
else if (strcasecmp(buf, "16G") == 0) {memsize = HTM_16G_OR_512M;}
else if (strcasecmp(buf, "32G") == 0) {memsize = HTM_32G_OR_1G;}
else if (strcasecmp(buf, "64G") == 0) {memsize = HTM_64G_OR_2G;}
else if (strcasecmp(buf, "128G") == 0) {memsize = HTM_128G_OR_4G;}
else if (strcasecmp(buf, "256G") == 0) {memsize = HTM_256G_OR_8G;}
else {
fprintf(stderr, "Failed to find a valid memory configuration for %s \n",buf);
exit(1);
}
return memsize;
}
int wait_until_ready(uint32_t i_target, int i_htm_type)
{
int rc, timer;
uint64_t data=0;
timer=0;
do {
rc=htm_read_xscom(i_target, HTM_STAT, i_htm_type, &data);
if (rc) {
ERR("xscom HTM_MEM read failed, rc=%d\n", rc);
return -1;
}
timer++;
sleep(1);
if(timer == MAX_TIMEOUT){
ERR("Timed out waiting for HTM_STAT_READY");
return -1;
}
printf("DATA RECEIVED %lx \n", data);
} while(!(data & HTM_STAT_READY));
printf("Congratulations, HTM has reached ready state\n");
return 0;
}
int set_htm_mem(uint32_t i_target, int i_htm_type, uint64_t i_mem_base, uint64_t i_mem_size, bool i_use_small_mem_size)
{
/* Prepare to set HTM_MEM register */
int rc;
uint64_t data;
printf("Target is still %d \n", i_htm_type);
/*First we need to ensure HTM_MEM_ALLOC=0*/
rc=htm_read_xscom(i_target, HTM_MEM, i_htm_type, &data);
if (rc) {
ERR("1xscom HTM_MEM read failed, rc=%d\n", rc);
return -1;
}
/* initially set HTM_MEM_ALLOC to 0. The transition to 1 will notify
htm that the trace memory information has been updated */
data &= ~HTM_MEM_ALLOC;
rc=htm_write_xscom(i_target, HTM_MEM, i_htm_type, data);
if (rc) {
ERR("1xscom HTM_MEM write failed, rc=%d\n", rc);
return -1;
}
data = 0;
/* Read scom back after setting the HTM_MEM_ALLOC off */
rc=htm_read_xscom(i_target, HTM_MEM, i_htm_type, &data);
if (rc) {
ERR("2xscom HTM_MEM read failed, rc=%d\n", rc);
return -1;
}
if (i_use_small_mem_size){
/* rc=htm_read_xscom(i_ex_target, HTM_MEM, i_htm_type, &data);*/
DBG("Using Small Memory \n");
data |= HTM_MEM_SIZE_SMALL;
} else {
DBG("Using Large Memory \n");}
data = SETFIELD(HTM_MEM_BASE, data, (i_mem_base>>24));
data = SETFIELD(HTM_MEM_SIZE, data, i_mem_size);
data |= HTM_MEM_ALLOC;
rc=htm_write_xscom(i_target, HTM_MEM, i_htm_type, data);
if (rc) {
ERR("xscom HTM_MEM write failed, rc=%d\n", rc);
return -1;
}
rc=htm_read_xscom(i_target, HTM_MEM, i_htm_type, &data);
if (rc) {
ERR("xscom HTM_MEM read failed, rc=%d\n", rc);
return -1;
}
/* printf("After it all HTM_MEM is %"PRIx64"\n",data);*/
return 0;
}
int update_mcs_regs(uint32_t i_target, uint32_t reserve_queue)
{
int rc;
uint64_t data;
uint32_t cpu_id = i_target >> 4;
rc=xscom_read(i_target, MCS4_MCFGPQ, &data);
if (data & MCS_VALID){
/* Set number of CL's to reserve */
printf("MCS4 is valid and ready to go\n");
rc=xscom_read(cpu_id, MCS4_MCMODE, &data);
if (rc) {
ERR("xscom MCS4_MCMODE read failed, rc=%d\n", rc);
return -1;
}
data = SETFIELD(MCS_BUFFER,data,reserve_queue);
rc=xscom_write(cpu_id, MCS4_MCMODE, data);
if (rc) {
ERR("xscom MCS4_MCMODE write failed, rc=%d\n", rc);
return -1;
}
/*Disable timeout in memory controller */
rc=xscom_read(cpu_id, MCS4_FIRMASK, &data);
if (rc) {
ERR("xscom MCS4_FIRMASK read failed, rc=%d\n", rc);
return -1;
}
data |= MCS_FIRMASK_DISABLE_TIMEOUT;
rc=xscom_write(cpu_id, MCS4_FIRMASK, data);
if (rc) {
ERR("xscom MCS4_FIRMASK read failed, rc=%d\n", rc);
return -1;
}
}
rc=xscom_read(i_target, MCS5_MCFGPQ, &data);
if (data & MCS_VALID){
printf("MCS5 is valid and ready to go\n");
/* Set number of CL's to reserve */
rc=xscom_read(i_target, MCS5_MCMODE, &data);
if (rc) {
ERR("xscom MCS5_MCMODE read failed, rc=%d\n", rc);
return -1;
}
data = SETFIELD(MCS_BUFFER,data,reserve_queue);
rc=xscom_write(i_target, MCS5_MCMODE, data);
if (rc) {
ERR("xscom MCS5_MCMODE write failed, rc=%d\n", rc);
return -1;
}
/*Disable timeout in memory controller */
rc=xscom_read(i_target, MCS5_FIRMASK, &data);
if (rc) {
ERR("xscom MCS5_FIRMASK read failed, rc=%d\n", rc);
return -1;
}
data |= MCS_FIRMASK_DISABLE_TIMEOUT;
rc=xscom_write(i_target, MCS5_FIRMASK, data);
if (rc) {
ERR("xscom MCS5_FIRMASK write failed, rc=%d\n", rc);
return -1;
}
}
rc=xscom_read(i_target, MCS6_MCFGPQ, &data);
if (data & MCS_VALID){
printf("MCS6 is valid and ready to go\n");
/* Set number of CL's to reserve */
rc=xscom_read(i_target, MCS6_MCMODE, &data);
if (rc) {
ERR("xscom MCS6_MCMODE read failed, rc=%d\n", rc);
return -1;
}
data = SETFIELD(MCS_BUFFER,data,reserve_queue);
rc=xscom_write(i_target, MCS6_MCMODE, data);
if (rc) {
ERR("xscom MCS6_MCMODE write failed, rc=%d\n", rc);
return -1;
}
/*Disable timeout in memory controller */
rc=xscom_read(i_target, MCS6_FIRMASK, &data);
if (rc) {
ERR("xscom MCS6_FIRMASK read failed, rc=%d\n", rc);
return -1;
}
data |= MCS_FIRMASK_DISABLE_TIMEOUT;
rc=xscom_write(i_target, MCS6_FIRMASK, data);
if (rc) {
ERR("xscom MCS6_FIRMASK write failed, rc=%d\n", rc);
return -1;
}
}
rc=xscom_read(i_target, MCS7_MCFGPQ, &data);
if (data & MCS_VALID){
printf("MCS7 is valid and ready to go\n");
/* Set number of CL's to reserve */
rc=xscom_read(i_target, MCS7_MCMODE, &data);
if (rc) {
ERR("xscom MCS7_MCMODE read failed, rc=%d\n", rc);
return -1;
}
data = SETFIELD(MCS_BUFFER,data,reserve_queue);
rc=xscom_write(i_target, MCS7_MCMODE, data);
if (rc) {
ERR("xscom MCS7_MCMODE write failed, rc=%d\n", rc);
return -1;
}
/*Disable timeout in memory controller */
rc=xscom_read(i_target, MCS7_FIRMASK, &data);
if (rc) {
ERR("xscom MCS7_FIRMASK read failed, rc=%d\n", rc);
return -1;
}
data |= MCS_FIRMASK_DISABLE_TIMEOUT;
rc=xscom_write(i_target, MCS7_FIRMASK, data);
if (rc) {
ERR("xscom MCS7_FIRMASK write failed, rc=%d\n", rc);
return -1;
}
}
return 0;
}
int htm_setup(struct htm_args i_args)
{
/*int htm_setup(uint32_t i_ex_target, int i_htm_type, bool i_nowrap, bool i_precise)
{*/
int rc;
uint64_t data, mem_size, mem_base, mod_mem_size;
uint64_t target_reg;
bool use_small_mem_size;
mem_size = get_mem_size(i_args.target);
mod_mem_size = parse_mem_size(mem_size, &use_small_mem_size);
mem_base = get_mem_start(i_args.target);
rc=htm_read_xscom(i_args.target, HTM_STAT, i_args.htm_type, &data);
if(!(data & HTM_STAT_COMPLETE) && !(data & HTM_STAT_REPAIR) && (data))
{
printf("Huge error, data not in complete, repair, or blank state\n");
exit(1);
}
/* printf("You're lucky, we're ready to proceed\n");*/
/* Prepare to set HTM_MEM register */
data = 0;
/* Setup MCS buffer reservation for HTM */
update_mcs_regs(i_args.target,8);
rc = set_htm_mem(i_args.target, i_args.htm_type, mem_base, mod_mem_size, use_small_mem_size);
/* start with clean slate */
data = 0;
if(!i_args.nowrap){
/* Enable wrap mode */
data |= HTM_MODE_WRAP_MODE;
}
/* Software enable of htm trace */
data |= HTM_MODE_TRACE_ENABLE;
if (i_args.htm_type == HTM_LLAT){
data = SETFIELD(HTM_MODE_CONTENT_SEL, data, HTM_MODE_CONTENT_SEL_CHTM_LLAT);
data = SETFIELD(HTM_MODE_CAPTURE, data, 0b001000000);
rc=htm_write_xscom(i_args.target, HTM_MODE, i_args.htm_type, data);
data = 0;
data |= HTM_MODE_TRACE_ENABLE;
target_reg = 0x10010C0A + ((i_args.target & 0xf)*CORE_MULTIPLIER);
printf("we are targetting %lx with %lx \n",target_reg, data);
rc=xscom_write((i_args.target>>4), target_reg, data);
} else if (i_args.htm_type == HTM_FABRIC){
/* Set Trace mode to use fabric */
data = SETFIELD(HTM_MODE_CONTENT_SEL, data, HTM_MODE_CONTENT_SEL_NHTM_FABRIC);
data = SETFIELD(HTM_MODE_CAPTURE, data, 0b010000000);
if(i_args.precise)
data |= HTM_MODE_PRECISE_MODE;
rc=htm_write_xscom(i_args.target, HTM_MODE, i_args.htm_type, data);
if (rc) {
ERR("xscom HTM_MODE write failed, rc=%d\n", rc);
return -1;
}
/* IS NEST Filtering Supported yet? */
rc=htm_read_xscom(i_args.target, NHTM_FILT, i_args.htm_type, &data);
data = SETFIELD(HTM_FILT, data, 0xfffff);
rc=htm_write_xscom(i_args.target, NHTM_FILT, i_args.htm_type, data);
/* TODO: pervasive misc is off by default make a flag*/
rc=htm_read_xscom(i_args.target, NHTM_TTYPE_FILT, i_args.htm_type, &data);
data = SETFIELD(HTM_TTYPE_MASK, data, 0xff);
data = SETFIELD(HTM_TSIZE_MASK, data, 0xff);
/*data |= HTM_TTYPE_INVERT;
data = SETFIELD(HTM_TTYPE_PAT, data, 0b110001);
data = SETFIELD(HTM_TSIZE_PAT, data, 0b1000000);*/
rc=htm_write_xscom(i_args.target, NHTM_TTYPE_FILT, i_args.htm_type, data);
if (rc) {
ERR("xscom HTM_MODE write failed, rc=%d\n", rc);
return -1;
}
}
rc=htm_reset(i_args.target, i_args.htm_type);
if (rc) {
ERR("HTM TRIGGER RESET failed, rc=%d\n", rc);
return -1;
}
wait_until_ready(i_args.target, i_args.htm_type);
/*Reset trigget in HTM_TRIG */
return 0;
}