iosim.html
29.6 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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Mozilla/4.72 [en] (X11; U; Linux 2.2.14-5.0 i686) [Netscape]">
<title>Iosim DV Environment</title>
</head>
<body>
<center>
<h2>
IOSIM DV Environment</h2></center>
<h3>
<b> </b>IOSIM Component</h3>
<img SRC="iosim.gif" ALT="" height=557 width=1141>
<p><font size=+1>1. IOSIM Test</font>
<p> Test itself, you can write it in .tst file
format(you can use tst2c to convert your tst file into "C" file later)
or write in "C".
<p> The ".tst" file format:
<br> command
[parameters]
<br> The line
which starts is not command will be treat as comments(not runable),
to make less confusion and later extension, plese use "//" at the beginning
of the each comment line.
<p> The common used commands
are:
<p> <b>s <stall cycles></b>
<br>
Ask bcp to move forward certain cycles.
<br>
In "C", BCP_STALL(stall_cycles);
<p> <b> t #id
parameter0 -3</b>
<br>
call the test function according to given id(which is defined as function
table in iotestcmd.c) with given four paramters.
<br>
The prototype of test function is int Test_name(int, int, int, int).
<br>
In "C", Test_name(p1, p2, p3, p4); <i><font size=-1>/* return
-1 if test fail */</font></i>
<p> <b> k 0/1</b>
<br>
Keep/Close persist socket connections.
<br>
Persist socket connect will save socket setup overhead times, so if you
do a lot of IOs with simulator, please use persistent connection.
<br>
Please remember to close it when test is done or switching between tests.
<br>
In "C", do_keep_alive_socket(1/0);
<p> <b> d string</b>
<br>
Ask simulator to display any message(<64 byte) for debugging purpose.
<br>
In "C", displayMsg("message body");
<p> <b>dump 0/1</b>
<br>
Turn on/off verilog dump
<p> <b> q</b>
<br>
Stop simulator, in "C", IoCmd(REQ_QUIT, 0).
<br>
<p><font size=+1>2. Test APIs</font>
<p> In theory, we can write tests only based on
atomic APIs, but it is very hard if we do not have loop/condition mechanisms.
Test APIs are routines written in "C" to call atomic APIs to achieve certain
functions.
<p><font size=+1>2.1 General Test APIs</font>
<p> Those APIs cab be used for testing
different components.
<p> <b><a href="#InitDDR">InitDDR(
)</a></b>
<br>
Initialize DDR memory controller.
<p> <b><a href="#register_test">register_test(
)</a></b>
<br> General
register test.
<br> If you
use .tst file, test id is 202.
<br> Note :
<br>
This test might not fit all registers.
<br>
For example, SP_STATUS(0x4040010),
<br>
but you still can use it to test bit from 2 to 31,
<br>
then use MemWriteRead or MemReadCompMask to test bit 0 and 1.
<p> <a href="#MemRead">MemRead(
)</a>
<br>
Memory/register/sram read(From RCP).
<br>
.tst id is: 100
<p> <a href="#MemReadCompare">MemReadCompare(
)</a>
<br>
Memory/register/sram read and comparison. (From RCP)
<br>
.tst id is: 101
<p> <a href="#MemWrite">MemWrite(
)</a>
<br>
Memory/reg/sram write. (From RCP)
<br>
.tst id is: 102
<p> <a href="#MemWriteRead">MemWriteRead(
)</a>
<br>
Memory/reg/sram write, read back and compare. (From RCP)
<br>
.tst id is: 103
<p> <a href="#MemReadCompMask">MemReadCompMask()</a>
<br>
Memory read and compare with given mask. (From RCP)
<br>
.tst id is: 108
<p> More will be add here. (some
from old RCP)
<p><font size=+1>2.2 Specific Test APIs</font>
<p> Those APIs are written for specific
components. For examples, AiDmaTests for AI component only.
<p><font size=+1>3. Atomic API</font>
<p> You are highly recommended to use those functions
to build your tests.
<p> The most common ones are:
<br> (a) <b><a href="#IO_READ">IO_READ( ) </a>
& <a href="#IO_WRITE">IO_WRITE( )</a></b>
<br> Read or write a single
word(4 bytes) into memory or register. Please note, those API will
handle endian(as integer) for you.
<p> (b) <b><a href="#SIM_TIME">SIM_TIME( )</a></b>
<br> Get simulator uptime
in ns. You might need this for timeout function or debug.
<p> (c) <b><a href="#BD_IO_READ">BD_IO_READ( )</a>
& <a href="#BD_IO_WRITE">BD_IO_WRITE( )</a></b>
<br> Backdoor memory read/write
a single word(4 bytes)
<p> (d) <b><a href="#BCP_STALL">BCP_STALL( )</a></b>
<br> Let BCP move
forward the given system clks.
<p> (e) <b><a href="#CHECK_INTERRUPT">CHECK_INTERRUPT</a></b>
<br>
Return interrupt info at last i/o operation.
<p> (f) <b><a href="#_TRACE">_TRACE( )</a></b>
<br>
Iosim trace functions.
<p> If you want to handle x/z, you can use the following
functions:
<br>
V_IO_SREAD_BYTE( ), V_IO_SREAD_HWORD( ) and V_IO_SREAD_WORD( )
<br>
V_IO_SWRITE_BYTE( ), V_IO_SWRITE_HWORD, V_IO_SWRITE_WORD( )
<br>
with prefix BD, it will change to backdoor memory access functions.
<br> To handle x,z, a new data structure is introduced,
<br> <i><font size=-1>struct {</font></i>
<br><i><font size=-1> int
data_part, xz_part;</font></i>
<br><i><font size=-1> } V_INT, *PV_INT;</font></i>
<table BORDER COLS=3 WIDTH="200" NOSAVE >
<tr>
<td>
<center>data_part</center>
</td>
<td>xz_part</td>
<td>
<div align=right>Result</div>
</td>
</tr>
<tr>
<td>
<div align=right>0</div>
</td>
<td>
<div align=right>0</div>
</td>
<td>
<div align=right>0</div>
</td>
</tr>
<tr>
<td>
<div align=right>1</div>
</td>
<td>
<div align=right>0</div>
</td>
<td>
<div align=right>1</div>
</td>
</tr>
<tr>
<td>
<div align=right>0</div>
</td>
<td>
<div align=right>1</div>
</td>
<td>
<div align=right>z</div>
</td>
</tr>
<tr>
<td>
<div align=right>1</div>
</td>
<td>
<div align=right>1</div>
</td>
<td>
<div align=right>x</div>
</td>
</tr>
</table>
<p> There are also block read/write functions if you
have to read/write big chunk of data(Say, > 64Kbytes <current less than
1sec via backdoor single I/O>).
<br> V_IO_BREAD( ), V_IO_BWRITE( ), BD_V_IO_BREAD( )
and BD_V_IO_BWRITE( )
<p> <font size=+1>4. PLI function</font>
<p> In general, you do not need to worry about
those APIs unless you want to change ipc mechanism.
<p><font size=+1>5. Misc</font>
<p><font size=+1> 5.1 <a NAME="General Rule"></a>General
Rule</font>
<p> *
If the test failed, return -1. (.tst file request)
<br>
Please also use _TRACE(DERROR, ...) to report error
<br>
* All new component test (like pi, si, usb, etc) should be in directory(iosim/src/test_name)
as Andy suggested.
<br>
* Please use _TRACE as log mechanism.
<br>
I will port all others(like fprintf(stderr...) in all existing tests.
<br>
* If Error occur, please write "ERROR" in log file.
<br>
After test is done, grep ERROR or Failed(.tst generated) to make sure all
test are passed.
<p><font size=+1>Reference:</font>
<p><a NAME="_TRACE"></a><b>_TRACE</b>
<br>Macro _TRACE(type, code)
<br>Description:
<br> If certain type is set,
execute the code.
<br> In general, the code will
be fprintf(LogFp, ...)
<br>Header file: trace.h
<br>Parameter:
<br> type -- trace type
<br>
<font size=-1>DALL
(0xFFFFFFFF) : All debug
types</font>
<br><font size=-1>
DERROR(0x00000001): Error tracing</font>
<br><font size=-1>
DREAD(0x00000002 ):
Read tracing</font>
<br><font size=-1>
DWRITE(0x00000004): Write tracing</font>
<br><font size=-1>
DSIGNAL(0x00000008): Signal tracing</font>
<br><font size=-1>
DINST(0x00000010):
Instruction tracing</font>
<br><font size=-1>
DREGS(0x00000020 ):
Register tracing</font>
<br><font size=-1>
DLOG (0x00000040):
Log tracing</font>
<br><font size=-1>
DTRANS (0x00000080) IO
R/W tracing</font>
<br><font size=-1>
DSTATUS(0x00000100) Status tracing</font>
<br><font size=-1>
DCOMPARE(0x00000200) Data compare tracing */</font>
<br> code -- "C" code
<br>Note:
<br> If you use .tst file, specify
"-d trace_type(hex) -l logfile".
<br> In "C", set global varible:
<br>
Dflags --- Your trace type
<br>
LogFp = fopen("your log file name here", "w");
<br> If you do not specify log
file, it will output to stderr.
<p>Examples:
<br> <font size=-1>if (timeout)</font>
<br> <font size=-1>_TRACE(DERROR,
fprintf(LogFp, "ERROR: BCP timeout"));</font>
<p><font size=-1> dma_addr =
IO_READ(Address_of_DMA_current);</font>
<br><font size=-1> _TRACE(DCOMPARE,
fprintf(LogFp, "Info: current dma addr=%x", dma_current));</font>
<p><a NAME="BCP_STALL"></a><b>BCP_STALL</b>
<br>Macro: BCP_STALL(cycles)
<br>Description: Let simulator move forward given cycles.
<br>Header file: bcp_util.h
<br>Paramter: number of BB cycles
<br>Examples:
<br><i><font size=-1>
/* write to memory in x36 mode, backdoor read back in x64 mode */</font></i>
<br><font size=-1> IO_WRITE(0x00000000,
0xbabecafe);</font>
<br><font size=-1> BCP_STALL(10);
/* stall to wait for writing is done */</font>
<br><font size=-1> ret = BD_IO_READ(0x01000000);</font>
<br><font size=-1> if (ret !=
0xbabecafe) /* Error occured*/</font>
<p><a NAME="BD_IO_READ"></a><b>BD_IO_READ</b>
<br>macro: BD_IO_READ( address)
<br>Description:
<br> Read data at given memory
address via memory backdoor.
<br>Header file: bcp_util.h
<br>Parameter:
<br> address --- BB memory space.
(x36/x64 mode)
<br>Examples:
<br> <i> <font size=-1>/*
write to memory in x36 mode, backdoor read back in x64 mode */</font></i>
<br><font size=-1> IO_WRITE(0x00000000,
0xbabecafe);</font>
<br><font size=-1> BCP_STALL(10);
/* stall to wait for writing is done */</font>
<br><font size=-1> ret = BD_IO_READ(0x01000000);</font>
<br><font size=-1> if (ret !=
0xbabecafe) /* Error occured*/</font>
<p><a NAME="BD_IO_WRITE"></a><b>BD_IO_WRITE</b>
<br>macro: BD_IO_WRITE( address, data)
<br>Description:
<br> Write data to given memory
address via memory backdoor.
<br>Header file: bcp_util.h
<br>Parameter:
<br> address --- BB memory space.
(x36/x64 mode)
<br> data
--- writing data
<br>Examples:
<br> <i> <font size=-1>/*
write to memory in x64 mode via backdoor, then read back */</font></i>
<br><font size=-1> BD_IO_WRITE(0x010000000,
0xbabecafe);</font>
<br><font size=-1> ret = BD_IO_READ(0x00000000);</font>
<br><font size=-1> if (ret !=
0xbabecafe) /* Error occured*/</font>
<p><a NAME="CHECK_INTERRUPT"></a><b>CHECK_INTERRUPT</b>
<br>Macro: CHECK_INTERRUPT
<br>Description:
<br> BB interrupt at last ipc call.
<br> Bit 5 : NMI
<br> Bits 4-0: BB interrupts
<br>Examples:
<br> <font size=-1>int i, int_l, j;</font>
<p><font size=-1> <i>/* checkout interrupt
info every interval or timeout*/</i></font>
<br><font size=-1> for (i=j=1; i<timeout; i+=interval,
j++) {</font>
<br><font size=-1> int_l = CHECK_INTERRUPT;</font>
<br><font size=-1> if (int_l
& 0x02) return 1;</font>
<br><font size=-1> bcp_stall(interval);</font>
<br><font size=-1> if (j % 250
== 0 ) displayMsg("* Wait for interrupt *");</font>
<br><font size=-1> }</font>
<p><a NAME="InitDDR"></a><b>InitDDR</b>
<br>Function: int InitDDR(int, int, int, int)
<br>Description:
<br> Initialize DDR memory controller
<br>Header file: bcptest.h
<br>Parameter: not used
<br>Return: 0
<br>Examples:
<br> <font size=-1>InitDDR(0, 0, 0, 0);</font>
<p><a NAME="IO_READ"></a><b>IO_READ</b>
<br>Macro: IO_READ( address)
<br>Description:
<br> Read data at given memory
address,register or sram .
<br>Header file: iomap.h
<br>Parameter:
<br> address --- BB memory map
space
<br>Examples:
<br> <i> <font size=-1>/*
write to memory in x36 mode, then read back in x64 mode */</font></i>
<br><font size=-1> IO_WRITE(0x00000000,
0xbabecafe);</font>
<br><font size=-1> ret = IO_READ(0x01000000);</font>
<br><font size=-1> if (ret !=
0xbabecafe) /* Error occured*/</font>
<p><a NAME="IO_WRITE"></a><b>IO_WRITE</b>
<br>macro: IO_WRITE( address, data)
<br>Description:
<br> Write data to given memory
address/register/sram.
<br>Header file: bcp_util.h
<br>Parameter:
<br> address --- BB memory map
space.
<br> data
--- writing data
<br>Examples:
<br> <i> <font size=-1>/*
write to memory in x64 mode via backdoor, then read back */</font></i>
<br><font size=-1> IO_WRITE(0x010000000,
0xbabecafe);</font>
<br><font size=-1> ret = IO_READ(0x00000000);</font>
<br><font size=-1> if (ret !=
0xbabecafe) /* Error occured*/</font>
<p><a NAME="MemRead"></a><b>MemRead</b>
<br>Function:
<br> int MemRead(int addr, int a2, int a3, int a4);
<br>Description:
<br> call IO_READ to read data from reg/memory/sram.
<br>Header file:
<br> iotest.h
<br>Paramter:
<br> addr --- BB memory map space.
<br> a2, a3, a4 --- extra
<br>Return 1
<br>Example:
<br><font size=-1> /* in .tst
<i>t
100 00000004 00000000 00000000 0000000 */</i></font>
<br><font size=-1> MemRead(0x4,
0, 0, 0);</font>
<p><a NAME="MemReadCompMask"></a><b>MemReadCompMask</b>
<br>Function:
<br> int MemReadCompMask(int addr, int data, int mask,
int failExpected);
<br>Description:
<br> call IO_READ to read data from reg/memory/sram and
compare it with data.
<br>Header file:
<br> iotest.h
<br>Paramter:
<br> addr --- BB memory map space.
<br> data --- Expect data
<br> mask --- Compare mask
<br> failExpected --- supposed
to fail?
<br>Return -1 if failed(mismatch(&mask) && failExpect==0).
<br>Example:
<br><font size=-1> /* in .tst
<i>t
108 04040010 00000000 00000001 0000000 */</i></font>
<br><i><font size=-1> /* Read
Sp status and compare only on bit 0 */</font></i>
<br><font size=-1> MemReadCompMask(0x4040010,
0, 1, 0);</font>
<br><font size=-1> </font>
<br><a NAME="MemReadCompare"></a><b>MemReadCompare</b>
<br>Function:
<br> int MemReadCompare(int addr, int data, int a3, int
failExpected);
<br>Description:
<br> call IO_READ to read data from reg/memory/sram and
compare it with data.
<br>Header file:
<br> iotest.h
<br>Paramter:
<br> addr --- BB memory map space.
<br> data --- Expect data
<br> a3 --- extra
<br> failExpected --- supposed
to fail?
<br>Return -1 if failed(mismatch & failExpect==0).
<br>Example:
<br><font size=-1> /* in .tst
<i>t
101 00000004 0000ffff 00000000 0000000 */</i></font>
<br><i><font size=-1> /* Read
memory 4, and check if it equal 0xffff */</font></i>
<br><font size=-1> MemReadCompare(0x4,
0xffff, 0, 0);</font>
<br><font size=-1> </font>
<br><a NAME="MemWrite"></a><b>MemWrite</b>
<br>Function:
<br> int MemWrite(int addr, int data, int a3, int a4);
<br>Description:
<br> call IO_WRITE to write data into reg/memory/sram.
<br>Header file:
<br> iotest.h
<br>Paramter:
<br> addr --- BB memory map space.
<br> data --- data
<br> a3, a4--- extra
<br>Return 1
<br>Example:
<br><font size=-1> /* in .tst
<i>t
102 00000004 0000ffff 00000000 0000000 */</i></font>
<br><i><font size=-1> /* write 0xffff
into memory 4 */</font></i>
<br><font size=-1> MemWrite(0x4, 0xffff,
0, 0);</font><b></b>
<p><a NAME="MemWriteRead"></a><b>MemWriteRead</b>
<br>Function:
<br> int MemWriteRead(int addr,
int data, int exp, int failExpected)
<br>Description:
<br> Memory/reg/sram write, read back
and compare.
<br>Header file:
<br> iotest.h
<br>Paramter:
<br> addr --- BB memory map space.
<br> data --- data write to memory/reg/sram
<br> exp --- expect
read back data
<br> failExpected --- supposed
to fail?
<br>Return -1 if failed(mismatch & failExpect==0).
<br>Example:
<br><font size=-1> /* in .tst
<i>t
103 00000004 0000ffff 0000ffff 0000000 */</i></font>
<br><i><font size=-1> /* write/read
0xfffff to/from memory 4, and check if it equal 0xffff */</font></i>
<br><font size=-1> MemReadCompare(0x4,
0xffff, 0xffff, 0);</font>
<br>
<br> <font size=-1>/* <i>t 103 04040010 00000001
00000000 00000000</i></font>
<br><i><font size=-1>
Clear halt bit in SP then check , then check if it cleared.</font></i>
<br><i><font size=-1>
t 103 04040010 00000001 00000001 00000001</font></i>
<br><i><font size=-1>
The same but expect failure.</font></i>
<br><i><font size=-1>
t 103 04040010 00000002 00000001 00000000</font></i>
<br><i><font size=-1>
Set halt bit, then check if halt get set.</font></i>
<br><i><font size=-1>
Those tests at reset time, otherwise you should use MemReadCompMask</font></i>
<br><font size=-1> */</font>
<br><font size=-1>
MemReadCompare(0x4040010, 1, 0, 0);</font>
<br><font size=-1>
MemReadCompare(0x4040010, 1, 1, 1);</font>
<br><font size=-1>
MemReadCompare(0x4040010, 2, 1, 0);</font>
<br>
<br><a NAME="register_test"></a><b>register_test</b>
<br>Function: int register_test(int addr, int rw_mask, int ronly_mask,
int extra)
<br>Description:
<br> Register test.
<br> * Walk through bit from
0 to 31
<br>
if rw_mask of this bit is set, write 0,1 to it, then read back, and check
if they are the same.
<br>
if ronly_mask is set, read this register to old_v(only read once),
write 0,1 to it, then read back, and check if it equals to the same bit
in old_v.
<br> * put the random number
in this register, check if
<br>
(write_data & rw_mask ) == (read_data & rw_mask)
<br>
(read_data & ronly_mask) == (old_v & ronly_mask)
<br>Header file: bcptest.h
<br>Parameters:
<br> addr --- BB register address
<br> rw_mask --- read/write bit mask
<br> ronly_mask --- read only bit mask
<br> extra --- not used
<br>Return:
<br> -1 if failed.
<p>Examples:
<br> <font size=-1>.tst file</font>
<br><font size=-1> t 202 4001000 FFFFFFFF 00000000
00000000</font>
<br><font size=-1> t 202 4080004 00000003
00FFFFFC 00000000</font>
<p> <font size=-1>In "C" file:</font>
<br><font size=-1> register_test(0x4001000, 0xffffffff,
0, 0);</font>
<br><font size=-1> register_test(0x4080004, 3,
0x00fffffc, 0);</font>
<p><a NAME="SIM_TIME"></a><b>SIM_TIME</b>
<br>Macro: SIM_TIME(ns_pointer)
<br>Description:
<br> Store current simulator uptime(in ns) into ns_pointer
<br>Header file: bcp_util.h
<br>Parameters:
<br> ns_pointer : long long pointer
<br>Return: 0
<br>Examples:
<br> <i><font size=-1>/* delay 8000 ns */</font></i>
<br><font size=-1> long long st, end;</font>
<p><font size=-1> SIM_TIME(&st);</font>
<br><font size=-1> while (1) {</font>
<br><font size=-1> SIM_TIME(&end);</font>
<br><font size=-1> if ((end-st)
> 8000) break;</font>
<br><font size=-1> BCP_STALL(1);</font>
<br><font size=-1> }</font>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
</body>
</html>