bcp_util.h
14.4 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
/*************************************************************************
*
* File: bcp_util.h
*
* BCP utilities:
* xz value support
* memory backdoor support
* verilog message display
*
* NOTE:
* Whatever platform it is, bit 31 refer to MSB,
* and bit 0 refer to LSB of an integer.
* ntohl and htonl will take care of all endia convertion.
*
*/
#ifndef _BCP_UTILITY
#define _BCP_UTILITY
#include "iotest.h"
#define CHAR_TO_HEX(x) ( ((x)>='0' && (x)<='9')?((x) - '0'): \
((x)>='a' && (x)<='f')?((x) - 'a'+10): \
((x)>='A' && (x)<='F')?((x) - 'A'+10):0)
// BCP extension for memory backdoor/xz value support
// BCP request code extension
// bit 31: zero time operation (All backdoor access)
// bit 30: soft turn off ipc_mon
// bit 29-20 : Try to simplify verilog and PLI
// bit 29: need xz value combination (PLI only)
// bit 28: need xz value split(pass to responds)
// bit 27-24: # combined words
// bit 23-20: # split words
// bit 4: single r/w or block r/w
#define BCP_REQ_BLOCK_READ 0x00000003
#define BCP_REQ_BLOCK_WRITE 0x00000004
#define BD_REQ_DUMP 0x80001100
#define BD_REQ_SINGLE_READ 0x80001001
#define BD_REQ_SINGLE_WRITE 0x80001002
#define BD_REQ_BLOCK_READ 0x80001003
#define BD_REQ_BLOCK_WRITE 0x80001004
#define BD_REQ_SINGLE_SEARCH 0x80001086
#define BD_REQ_DISPLAY_MSG 0x80001087
#define BCP_SIM_TIME 0x80001501
#define SIM_TIME(x) bcp_time(x)
#define BCP_SET_RSP_TIMEOUT 0x80001505
#define BCP_GET_RSP_TIMEOUT 0x80001506
void bcp_set_rsp_timeout(int x);
int bcp_get_rsp_timeout();
#define BCP_SYSCLK_PERIOD 0x80001502
#define BCP_VCLK_PERIOD 0x80001503
#define BCP_SIM_MEM_INFO 0x80001500
#define BCP_MEM_ADDR_MASK 0x000000ff
#define BCP_MEM_DDR_MASK 0x0000ff00
#define BCP_9TH_BITS 0x80004800
int bcp_check_9th(int a1, int a2, int a3, int a4);
// Backdoor SI Local/Jctrl
#define BD_REQ_SI_CTRL 0x80001090
#define LOCAL_CTRL 0
#define JCTRL_1 1
#define JCTRL_2 2
#define JCTRL_3 3
#define LCTRL_XMOVE 0 //integer
#define LCTRL_YMOVE 1 //integer
#define LCTRL_JITTER 2 //integer
#define LCTRL_BUTTON 5 //bits [15:0]
/* Modified for Frank's change
#define LCTRL_TLOW 6 //integer
#define LCTRL_TXFER 7 //integer
#define LCTRL_THIGH 8 //integer
*/
#define LCTRL_TPULSE 6
#define LCTRL_TGLITCH 7
#define LCTRL_XGLITCH 9 //Bits [1:0]
#define LCTRL_YGLITCH 10 //Bits [1:0]
#define CTRL_ENALE 0 //LSB
#define CTRL_DIV 1 //Bits [3:0]
#define CTRL_TYPE_L 2 //Bits [7:0]
#define CTRL_TYPE_H 3 //Bits [7:0]
#define CTRL_STATUS 4 //Bits [7:0]
#define CTRL_BUTTON 5 //Bits [15:0]
#define CTRL_X 6 //Bits [7:0]
#define CTRL_Y 7 //Bits [7:0]
#define CTRL_RSP_RAND 8 //LSB
#define CTRL_COLLISION 9 //bits [3:0]
#define CTRL_FRAMEERR 10 //bits [5:0]
#define CTRL_RSP_ECHO 11 //LSB
#define CTRL_GLITCH_DETECT 12 //LSB
#define CTRL_RESET 13 //LSB
#define CTRL_MASTER 14 //LSB
#define CTRL_TX_SIZE 15 //Bits [7:0]
#define CTRL_TX_ON 16 //Bits [7:0]
#define CTRL_RX_LAST 17 //Bits [7:0]
#define CTRL_TX_DATA_0_7 18 // 8 packed 8 bit bytes
#define CTRL_TX_DATA_8_35 19 //28 packed 8 bit bytes
#define CTRL_READ_DATA 20 //32 packed 8 bit bytes
#define MJCTRL 4 // master controller
#define MJCTRL_ENALE 0 // enable (lsb)
#define MJCTRL_DIV 1 // clock divider [3:0]
#define MJCTRL_CMD 2 // command register [7:0]
#define MJCTRL_CTL 3 // control register [7:0]
#define MJCTRL_CMD0 0x00 // command 0
#define MJCTRL_CMD1 0x01 // command 1
#define MJCTRL_CMD255 0xff // command 255
#define BD_RD_SI_CTRL 0x800010a0
#define BD_RD_SI_CTRL_PKD 0x800010a1
#define CTRL_RX_SIZE 0 //Bits [7:0]
#define CTRL_RX_DATA_0_7 1 // 8 packed 8 bit bytes
#define CTRL_RX_DATA_8_35 2 //28 packed 8 bit bytes
#define MJCTRL_RX_DATA_3 3 //3 packed 8 bit bytes
#define MJCTRL_RX_DATA_4 4 //4 packed 8 bit bytes
#define BLK_2WORD 8
#define BLK_4WORD 16
#define BLK_8WORD 32
#define BCP_COMBINE_XZ 0x20000000
#define BCP_SPLIT_XZ 0x10000000
#define BCP_COMBINE_WORD(x) ( ((x) >> 24) & 0xf)
#define BCP_SPLIT_WORD(x) ( ((x) >> 20) & 0xf)
#define BCP_WORD_COMBINED(x) ( ((x) & 0xf) << 24)
#define BCP_WORD_SPLIT(x) ( ((x) & 0xf) << 20)
#define SINGLE_REQ_MASK 0x71100000
#define BLK_REQ_MASK 0x7ff00000
#define BD_SINGLE_REQ_MASk 0xf1100000
#define BD_BLK_REQ_MASK 0xfff00000
#define BLOCK_REQ(x) (((x)&0xf)==3 || ((x)&0xf)==4)
/* eliminate IPC messages */
#define BD_REQ_NO_IPC_MSG 0x40000000
#define OPEN_ALIVE_SOCKET 0x80004000
#define CLOSE_ALIVE_SOCKET 0x80004001
#define VI_SNOOP_ON 0x80004002
#define VI_SNOOP_OFF 0x80004003
#define GET_VI_TAB_FILE 0x80004004
#define READ_VI_TAB_FILE 0x80004005
/* Backdoor for RSP CTRACE TEST (0x800041xx)*/
/* Note: memory read is handled by bd_read72bits_mem */
/* Also make all SU/VU/DM trace as block req */
#define RSP_CTRACE_TEST_ON 0x80004100
#define RSP_CTRACE_TEST_NEXT 0x80004101
#define RSP_CTRACE_TEST_OFF 0x80004102
#define RSP_CTRACE_STATUS 0x80004105
#define RSP_CTRACE_DATA 0x80004104
#define RSP_IMEM_LOAD 0x80004103
#define RSP_DMEM_LOAD 0x80004107
#define BCP_USB_TEST_ON 0x80004200
#define BCP_LINESTATE 0x80004201
#define BCP_USB_OTG_DONE 0x80004202
#define BCP_USB_READ_DATA 0x80004210
#define BCP_USB_WRITE_DATA 0x80004211
#define BCP_USB_READ_STAT 0x80004212
#define BCP_USB_TERM_CTL 0x80004214
#define BCP_USB_HOST_CTL 0x80004216
#define BCP_USB_BIAS_CTL 0x80004218
#define BD_REQ_MM_PRESENT 0x80004300
#define BD_JTAG_WRITE 0x80004400
#define BD_JTAG_READ 0x80004401
#define BD_JTAG_ENABLE 0x80004402
#define BD_DBUG_DWRITE 0x80004500
#define BD_DBUG_DREAD 0x80004501
#define BD_DBUG_CWRITE 0x80004502
#define BD_DBUG_CREAD 0x80004503
#define BD_PIN_RESET 0x80004600
#define BD_CLOCK_MON_ENABLE 0x80004700
#define VR_TRACE_DEPTH 256
#ifdef LARGE_TRACE_BUFFER
#define SU_TRACE_DEPTH 100000
#define DM_TRACE_DEPTH 100000
#else
#define SU_TRACE_DEPTH 2048
#define DM_TRACE_DEPTH 2048
#endif
#define BD_ZERO_STAT 0x80005300
#define BD_DISP_STAT 0x80005301
int bcp_unit_clear_stat(int which, int a2, int a3, int a4);
int bcp_unit_disp_stat(int a1, int a2, int a3, int a4);
/* Verilog int contains data and xz two parts, to
compatible with PLI library.
data_part 0 1 1 0
xz_part 0 0 1 1
real_logic 0 1 x z
*/
typedef struct verlog_int {
unsigned int data_part;
unsigned int xz_part;
} V_INT, *PV_INT;
#define BCP_V_0 0
#define BCP_V_1 1
#define BCP_V_Z 2
#define BCP_V_X 3
int read_V_INT_bit(PV_INT pdata, int bit);
int set_V_INT_bit(PV_INT pdata, int bit, int v);
/* Verilog single/block read/write
To make backward compatible, we also define the similar
macro.
Far all new tests, please try to use those API as much as possible.
*/
#define BCP_STALL(x) bcp_stall(x)
#define V_IO_SREAD(addr, size, opts, pdata) v_io_sread(addr, size, opts, pdata)
#define V_IO_SREAD_BYTE(addr, opts, pdata) v_io_sread(addr, SIZE_1BYTE, opts, pdata)
#define V_IO_SREAD_HWORD(addr, opts, pdata) v_io_sread(addr, SIZE_2BYTE, opts, pdata)
#define V_IO_SREAD_WORD(addr, opts, pdata) v_io_sread(addr, SIZE_4BYTE, opts, pdata)
#define V_IO_SWRITE(addr,size, opts, pdata) v_io_swrite(addr, size,opts, pdata)
#define V_IO_SWRITE_BYTE(addr, opts, pdata) v_io_swrite(addr, SIZE_1BYTE,opts, pdata)
#define V_IO_SWRITE_HWORD(addr,opts, pdata) v_io_swrite(addr, SIZE_2BYTE,opts, pdata)
#define V_IO_SWRITE_WORD(addr, opts, pdata) v_io_swrite(addr, SIZE_4BYTE,opts, pdata)
#define V_IO_BREAD(addr, size, opts, pdata) v_io_bread( addr, size, opts, pdata)
#define V_IO_BWRITE(addr, size, opts, pdata) v_io_bwrite(addr, size, opts, pdata)
#define INVALID_PARAM -1
#define INVALID_REQ_SIZE -4
#define REQ_SOCKET_ERR -5
#define BCP_WRONG -6
#define BCP_MEM_INFO bcp_query_data(BCP_SIM_MEM_INFO);
int bcp_stall(int clks);
int bcp_time(unsigned long long *result);
int bcp_sysclk_period(unsigned int *result);
int bcp_vclk_period(unsigned int *result);
int bcp_query_data(int code);
int v_io_sread(unsigned int addr, unsigned int size,
unsigned int opts, PV_INT pdata);
int v_io_swrite(unsigned int addr, unsigned int size,
unsigned int opts, PV_INT pdata);
int v_io_bread(unsigned int addr, unsigned int size,
unsigned int opts, PV_INT pdata);
int v_io_bwrite(unsigned int addr, unsigned int size,
unsigned int opts, PV_INT pdata);
unsigned int bd_io_read(unsigned long addr);
void bd_io_write(unsigned long addr, unsigned int data);
#define BD_IO_READ(data) bd_io_read((data))
#define BD_IO_WRITE(addr, data) bd_io_write((addr), (data))
#define BD_V_IO_SREAD(addr,size, opts, pdata) bd_v_io_sread(addr, size, opts, pdata)
#define BD_V_IO_SREAD_BYTE(addr, opts, pdata) bd_v_io_sread(addr, SIZE_1BYTE, opts, pdata)
#define BD_V_IO_SREAD_HWORD(addr,opts, pdata) bd_v_io_sread(addr, SIZE_2BYTE, opts, pdata)
#define BD_V_IO_SREAD_WORD(addr, opts, pdata) bd_v_io_sread(addr, SIZE_4BYTE, opts, pdata)
#define BD_V_IO_SWRITE(addr, size,opts, pdata) bd_v_io_swrite(addr, size, opts, pdata)
#define BD_V_IO_SWRITE_BYTE(addr, opts, pdata) bd_v_io_swrite(addr, SIZE_1BYTE, opts, pdata)
#define BD_V_IO_SWRITE_HWORD(addr,opts, pdata) bd_v_io_swrite(addr, SIZE_2BYTE, opts, pdata)
#define BD_V_IO_SWRITE_WORD(addr, opts, pdata) bd_v_io_swrite(addr, SIZE_4BYTE, opts, pdata)
#define BD_V_IO_BREAD(addr, size, opts, pdata) bd_v_io_bread(addr, size, opts, pdata)
#define BD_V_IO_BWRITE(addr, size, opts, pdata) bd_v_io_bwrite(addr,size, opts, pdata)
int bd_v_io_sread(unsigned int addr, unsigned int size,
unsigned int opts, PV_INT pdata);
int bd_v_io_swrite(unsigned int addr, unsigned int size,
unsigned int opts, PV_INT pdata);
int bd_v_io_bread(unsigned int addr, unsigned int size,
unsigned int opts, PV_INT pdata);
int bd_v_io_bwrite(unsigned int addr, unsigned int size,
unsigned int opts, PV_INT pdata);
/* manipulte socket open/close */
int do_keep_alive_socket(int open);
/* only for debug purpose */
void linux_bd_io_search(unsigned long addr, vu_int data);
/* DV memory bckdoor function */
/* Detail see Frank's Memory DV interfaces */
#define MEM_ADDR_PATTERN 0x001
#define RAND_PATTERN 0x002
int bd_memory_fill_pattern(unsigned int addr, unsigned int size, int type);
int bd_memory_compare_pattern(unsigned int addr, unsigned int size, int type);
/* please remember file is store in big-endian format */
int bd_memory_read_file(char *fname, int offset, unsigned int addr, unsigned int size);
int bd_memory_write_file(char *fname, int offset, unsigned int addr, unsigned int size);
/* VBus monitor functions */
int set_vi_snoop(int enable);
int get_vi_tab_file(char *filename);
/* Deal with old RDRAM image */
#define BCP_MBYTE 1024*1024
#define RDRAM_2MBYTE 2*BCP_MBYTE
#define RDRAM_4MBYTE 4*BCP_MBYTE
/* rdram image bdoor functions */
int bd_memory_read_rdram(char *fname, int mem_size);
int bd_memory_write_rdram(char *fname, int mem_size);
/* rsp ctrace functions */
int set_rsp_ctrace(int enable, int single_step, int test_type);
int bd_read72bits_mem(char *fname);
int bd_check40bits_su(char *fname);
int bd_check256bits_vu(char *fname);
int bd_check160bits_dm(char *fname);
int verilog_dump(int on_off);
/* si backdoor functions */
int bd_si_ctrl_setup(int ctrl, int func, int data, int extra);
int bd_si_ctrl_rd(unsigned int *result, int bytes);
int bd_si_ctrl_wr_pkd(int ctrl, int func, unsigned char *data, int bytes);
int bd_si_ctrl_rd_pkd(int ctrl, int func, unsigned char *result, int bytes);
#define SI_MM_TX_DATA_SIZE 36
int bd_si_ctrl_set_mm_tx_data(unsigned char mm_tx_data[SI_MM_TX_DATA_SIZE]);
int displayMsg(char *msg);
/*
* Memory module backdoor
*/
int bd_mm_present(int not_present);
/*
* JTAG controler
*/
int bd_jtag_write(int data);
int bd_jtag_read();
int bd_jtag_enable(int enable);
/*
* Debug Port
*/
int bd_dbug_dwrite(int data) ;
int bd_dbug_cwrite(int data) ;
int bd_dbug_dread() ;
/*
* Pin reset
*/
int bd_pin_reset(void);
/*
* Clock monitor enable/disable
*/
int bd_clock_mon_enable(int enable);
/*
* Video encoder test data generation
*/
int write_luma_ramp(unsigned int addr, int length, int e1, int e2);
int write_color_bar(unsigned int addr, int length, int e1, int e2);
/*
* Do a pin reset
*/
void pin_reset();
/*
* BCP extended general register test
*/
int ext_mem_write(int addr, int data_part, int xz_part);
int ext_mem_read_comp(int addr, int data_part, int xz_part);
int ext_reg_test(unsigned int addr, unsigned int rw_bits,
unsigned int always_on, unsigned int always_off,
unsigned int x_bits, unsigned int bits_to_skip );
/*
* poll a register with timeout
*/
typedef struct {
/* struct passed to poll_timeout_info()
* "start", "end", and "duration" are set by poll_timeout_info().
* "limit" should be set by caller of poll_timeout_info
* values are in nanoseconds.
*/
unsigned int limit;
unsigned long long start;
unsigned long long end;
unsigned int duration;
} PollInfo;
typedef enum { Silent, Timeouts, AllPolls } PollVerbosity;
int
poll_timeout(int reg_addr, int bits, int cleared, PollVerbosity pv, unsigned int nanosec);
int
poll_timeout_info(int reg_addr, int bits, int cleared, PollVerbosity pv, PollInfo *t);
#endif