Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / verif / env / common / vera / classes / scanUtilsClass.vr
CommitLineData
86530b38
AT
1// ========== Copyright Header Begin ==========================================
2//
3// OpenSPARC T2 Processor File: scanUtilsClass.vr
4// Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved
5// 4150 Network Circle, Santa Clara, California 95054, U.S.A.
6//
7// * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8//
9// This program is free software; you can redistribute it and/or modify
10// it under the terms of the GNU General Public License as published by
11// the Free Software Foundation; version 2 of the License.
12//
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17//
18// You should have received a copy of the GNU General Public License
19// along with this program; if not, write to the Free Software
20// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21//
22// For the avoidance of doubt, and except that if any non-GPL license
23// choice is available it will apply instead, Sun elects to use only
24// the General Public License version 2 (GPLv2) at this time for any
25// software where a choice of GPL license versions is made
26// available with the language indicating that GPLv2 or any later version
27// may be used, or where a choice of which version of the GPL is applied is
28// otherwise unspecified.
29//
30// Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
31// CA 95054 USA or visit www.sun.com if you need additional information or
32// have any questions.
33//
34// ========== Copyright Header End ============================================
35#include <vera_defines.vrh>
36#include <std_display_class.vrh>
37#include <globals.vri>
38
39// TAP specific defines
40#include <systemTapDefines.vri>
41
42// jtag interface
43#include <systemTap.if.vri>
44#include <systemTapClass.vrh>
45#include <tcu_tasks.vrh>
46
47//extern SystemTap dft;
48
49extern "C" task PLI_InitFlopPliWithChaindef_vr(string topMod, integer scanCfg, integer asicGates, integer chainEnable);
50extern "C" function string PLI_JtagShiftExpData_vr(integer chain, string scanIn);
51extern "C" function string PLI_JtagShiftExpDataConcat_vr(string scanIn);
52extern "C" task PLI_JtagCheckExpData_vr(integer chain);
53
54#define CLASSNAME scanUtilities
55
56#define MFG_SCAN_CFG 0
57#define JTAG_SCAN_CHAINSEL_CFG 1
58#define JTAG_SCAN_CONCAT_CFG 2
59#define TT_SCAN_CFG 3
60
61
62#define MAX_SCAN_CHAINS 32
63#define MAX_SHIFT_COUNT 75000
64#define TT_FUNC_CLK_DEFAULT 2
65#define TT_MAX_CMP_CLKS 255
66#define TT_MAX_IO_CLKS 63
67#define MAX_WAIT_BEFORE_SCAN 100
68#define MAX_WAIT_BEFORE_TT 100
69#define MAX_WAIT_AFTER_TT 100
70#define MAX_NUM_OF_SHIFTS 50
71#define BITS_IN_SCAN_STRING 32
72
73class CLASSNAME extends SystemTap {
74 local string className = "scanUtilities";
75 local string topLevel = "tb_top.cpu";
76 local bit [31:0] chainEn;
77 local integer scanChainConfig;
78 local integer maxShift;
79 local integer asicGatesPresent;
80 local bit [31:0] scanInData;
81 local integer refModelEnabled;
82
83 task new (
84 StandardDisplay dbgIn,
85 integer refModEn=0,
86 bit [32:0] scanData=33'h100000000
87 );
88 function bit [31:0] getMfgChainEn();
89 function bit [5:0] getJtagChainEn();
90 function integer getMaxShiftCount();
91 function integer checkForAsicGates();
92 task setupChipForScanDump();
93 function integer tapJTAGSerscan (
94 integer shiftCount,
95 bit [5:0] chainSel,
96 integer scanOutChecking
97 );
98 function integer checkIfAsicCluster(
99 integer chain
100 );
101}
102
103
104/////////////////////////////////////////////////////////////////////////////
105task CLASSNAME::new(StandardDisplay dbgIn, integer refModEn=0, bit [32:0] scanData=33'h100000000) {
106 //tap_port = tap_bind;
107 //dbg = dbgIn;
108
109
110 //tap_state_reg = 4'bx;
111 //tap_port.$test_mode = 1'b0 soft async; // JTAG debug mode unless told to goto manufacturing test
112 //tap_port.$trst_n = 1'bx soft async;
113 //tap_port.$tdi = 1'bx soft async;
114 //tap_port.$tms = 1'b1 soft async;
115 //if (!get_plus_arg(CHECK, "noJtagTapReset")) {
116 //dbg.dispmon(dispmonScope, MON_INFO, "WARNING: systemTapClass.vr : skip calling TapResetType1() to reset TAP");
117 //// Toggle TRST_L 0 -> 1
118 //TapResetType1();
119 //}
120
121 super.new(dbgIn);
122 chainEn = 31'h00000000;
123 asicGatesPresent = 0;
124 scanChainConfig = JTAG_SCAN_CHAINSEL_CFG;
125
126 if (scanData[32]==1) {
127 scanInData = urandom();
128 }
129 else {
130 scanInData = scanData[31:0];
131 }
132
133 refModelEnabled = refModEn;
134}
135
136function bit [31:0] CLASSNAME::getMfgChainEn() {
137 if (get_plus_arg(CHECK, "chainsel=")) {
138 chainEn = get_plus_arg(HNUM, "chainsel=");
139 `PR_ALWAYS(className, MON_ALWAYS, psprintf("Chain Enable is: %0h\n", chainEn));
140 }
141 else {
142 `PR_ALWAYS(className, MON_ALWAYS, psprintf("Chain Enable is: %0h\n", chainEn));
143 }
144 getMfgChainEn = chainEn;
145}
146
147function bit [5:0] CLASSNAME::getJtagChainEn() {
148 chainEn[5] = 1'b1;
149 if (get_plus_arg(CHECK, "chainsel=")) {
150 chainEn[4:0] = get_plus_arg(NUM, "chainsel=");
151 scanChainConfig = JTAG_SCAN_CHAINSEL_CFG;
152 `PR_ALWAYS(className, MON_ALWAYS, psprintf("Chain Enable is: %d\n", chainEn));
153 }
154 else {
155 // concat all chains
156 chainEn[5] = 1'b0;
157 scanChainConfig = JTAG_SCAN_CONCAT_CFG;
158 `PR_ALWAYS(className, MON_ALWAYS, psprintf("No chain enable selected; scanning all chains concatonated\n"));
159 }
160 getJtagChainEn = chainEn;
161}
162
163function integer CLASSNAME::getMaxShiftCount() {
164 if (get_plus_arg(CHECK, "maxchain=")) {
165 maxShift = get_plus_arg(NUM, "maxchain=");
166 }
167 else
168 {
169 maxShift = MAX_SHIFT_COUNT;
170 }
171 `PR_ALWAYS(className, MON_ALWAYS ,psprintf("Maximum number of scan shifts is %d\n", maxShift));
172 getMaxShiftCount = maxShift;
173}
174
175function integer CLASSNAME::checkForAsicGates() {
176 if (get_plus_arg(CHECK, "asicGates")) {
177 asicGatesPresent = 1;
178 `PR_ALWAYS(className, MON_ALWAYS ,psprintf("Asic gates are present in model\n"));
179 }
180 checkForAsicGates = asicGatesPresent;
181}
182
183task CLASSNAME::setupChipForScanDump() {
184 if (asicGatesPresent) {
185 `PR_ALWAYS(className, MON_ALWAYS ,psprintf("Configuring pli to look for flops in the asic clusters"));
186 }
187 else {
188 `PR_ALWAYS(className, MON_ALWAYS ,psprintf("Pli will bypass asic clusters when looking for flops (rtl)"));
189 }
190
191 PLI_InitFlopPliWithChaindef_vr(topLevel, scanChainConfig, asicGatesPresent, chainEn);
192}
193
194function integer CLASSNAME::tapJTAGSerscan(integer shiftCount, bit [5:0] chainSel, integer scanOutChecking) {
195 integer patBitSel, chainTotal, i;
196 integer sawPattern;
197 string refModTdo;
198 bit [31:0] scanOutDataSeen;
199 bit [0:0] prevTdi;
200
201 `PR_ALWAYS(className, MON_ALWAYS, psprintf("Chain: %0d, Enabled: %01b \n", chainSel[4:0], chainSel[5]));
202 tapJTAGSerscan = 0;
203
204 patBitSel = 0;
205 chainTotal = 0;
206 scanOutDataSeen = BITS_IN_SCAN_STRING'b0;
207
208 `PR_ALWAYS(className, MON_ALWAYS, psprintf("Data pattern shifted in will be %d\n", scanInData));
209 if (refModelEnabled) `PR_ALWAYS(className, MON_ALWAYS, psprintf("Enabling scan chain reference model\n"));
210
211 // JTAG instructions to kick-off serscan
212 `PR_ALWAYS(className, MON_ALWAYS, psprintf("TapIRLoad of TAP_SCAN_SERIAL_SEL\n"));
213 void = dft.TapIRLoad(TAP_SCAN_SERIAL_SEL);
214 void = dft.TapDRLoad(dft.cnv2str(chainSel,6));
215 `PR_ALWAYS(className, MON_ALWAYS, psprintf("TapIRLoad of TAP_SCAN_SERIAL\n"));
216 void = dft.TapIRLoad(TAP_SCAN_SERIAL);
217 dft.TapGoto(TAP_SHIFT_DR);
218 `PR_ALWAYS(className, MON_ALWAYS, psprintf("Begin shifting...\n"));
219
220 sawPattern=0;
221 repeat(shiftCount)
222 {
223 dft.tap_port.$tdi = scanInData[patBitSel];
224
225 @(posedge dft.tap_port.$tck);
226
227 scanOutDataSeen[30:0] = scanOutDataSeen[31:1];
228 scanOutDataSeen[31] = dft.tap_port.$tdo;
229
230 if (refModelEnabled && chainTotal>0) {
231 `PR_ALWAYS(className, MON_ALWAYS, psprintf("Shifting Scan Chain Reference Model\n"));
232 if (chainSel[5]==1'b0) {
233 refModTdo = PLI_JtagShiftExpDataConcat_vr(dft.cnv2str(prevTdi,1));
234 }
235 else {
236 refModTdo = PLI_JtagShiftExpData_vr(chainSel[4:0], dft.cnv2str(prevTdi,1));
237 }
238
239 if (refModTdo != dft.BinToChar(scanOutDataSeen[31])) {
240 `PR_ERROR(className, MON_ERROR, psprintf("ERROR: tdo value from Scan Chain Reference Model did not match actual tdo value"));
241 `PR_ERROR(className, MON_ERROR, psprintf("Expected tdo value=%s, Actual tdo value=%s\n",
242 refModTdo, dft.BinToChar(scanOutDataSeen[31])));
243 }
244
245 `PR_ALWAYS(className, MON_ALWAYS, psprintf("Checking Scan Chain Reference Model\n"));
246 if (chainSel[5]==1'b0) {
247 PLI_JtagCheckExpData_vr(31);
248 }
249 else {
250 PLI_JtagCheckExpData_vr(chainSel[4:0]);
251 }
252 }
253
254 // save for reference model
255 prevTdi = scanInData[patBitSel];
256
257 patBitSel = (patBitSel+1) % BITS_IN_SCAN_STRING;
258 chainTotal++;
259 tapJTAGSerscan = chainTotal;
260
261 if ((chainTotal%500)==0)
262 {
263 `PR_ALWAYS(className, MON_ALWAYS, psprintf("Flops shifted=%d", chainTotal));
264 }
265
266 if (scanOutChecking)
267 {
268 if (scanOutDataSeen===scanInData)
269 {
270 sawPattern=1;
271 `PR_ALWAYS(className, MON_ALWAYS, psprintf("TDO saw pattern shifted into TDI (%BITS_IN_SCAN_STRINGb)", scanOutDataSeen));
272 `PR_ALWAYS(className, MON_ALWAYS, psprintf("Final flop count=%d\n", chainTotal));
273 break;
274 }
275 }
276 }
277
278 if (scanOutChecking)
279 {
280 if (!sawPattern)
281 {
282 `PR_ERROR(className, MON_ERR, psprintf("\nDiag Finished with ERRORs\n"
283 "FAILED: NO MATCH AFTER =%d cycles\n\n", chainTotal));
284 }
285 }
286
287
288 `PR_ALWAYS(className, MON_ALWAYS, psprintf("tapJTAGSerscan(): Done shifting\n"));
289
290 // Cannot count the final word shift
291 tapJTAGSerscan = (tapJTAGSerscan>BITS_IN_SCAN_STRING) ? tapJTAGSerscan-BITS_IN_SCAN_STRING : tapJTAGSerscan;
292
293 //void = dft.TapIRLoad(TAP_BYPASS_INST);
294 //dft.TapGoto(TAP_IDLE);
295 `PR_ALWAYS(className, MON_ALWAYS, psprintf("Done tapJTAGSerscan\n"));
296}
297
298
299/*
300task shiftScanChainModel(bit[5:0] chain_sel)
301{
302 StandardDisplay dbg;
303 string className = "shiftScanChainModel";
304
305 @(probe_if.jtag_instr);
306 while (probe_if.jtag_instr != 8'h80)
307 {
308 // wait until we see the TAP_SERSCAN instruction
309 @(probe_if.jtag_instr);
310 }
311
312 @(posedge probe_if.shift_dr_state);
313 @(negedge dft.tap_port.$tck); // no shift on first tck
314 while (probe_if.shift_dr_state==1)
315 {
316 @(negedge dft.tap_port.$tck);
317 dbg.dispmon(className, MON_ALWAYS, psprintf("shiftScanChainModel(): Shifting scan chain model\n"));
318 //if (chain_sel[5] == 1'b0) verilog_PLI_jtag_shift_exp_data_concat(dft.tap_port.$tdi);
319 PLI_JtagShiftExpData_vr(chain_sel[4:0], "1");
320
321 @(posedge dft.tap_port.$tck);
322 dbg.dispmon(className, MON_ALWAYS, psprintf("shiftScanChainModel(): Checking scan chain model\n"));
323 if (chain_sel[5] == 1'b0) PLI_JtagCheckExpData_vr(31);
324 else PLI_JtagCheckExpData_vr(chain_sel[4:0]);
325 }
326}
327*/
328
329function integer CLASSNAME::checkIfAsicCluster(integer chain) {
330 if ((chain==19) ||
331 (chain==21) ||
332 (chain==20) ||
333 (chain==28) ||
334 (chain==29) ||
335 (chain==30)) {
336 checkIfAsicCluster=1;
337 }
338 else {
339 checkIfAsicCluster=0;
340 }
341}
342
343