Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / design / sys / iop / niu / rtl / niu_ipp_lib.v
CommitLineData
86530b38
AT
1// ========== Copyright Header Begin ==========================================
2//
3// OpenSPARC T2 Processor File: niu_ipp_lib.v
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/*********************************************************
36***********************************************************
37
38 Project : Vega
39
40 File name : niu_ipp_lib.v
41
42 Module(s) name : niu_ipp_lib
43 Original: : ipp_lib.v main.11, label:
44
45 Parent modules : ipp.v
46
47 Child modules :
48
49 Author's name : Jonathan Shen, George Chu
50
51 Date : Oct. 2001
52
53 Description : lib files
54
55 Synthesis Notes:
56
57 Modification History:
58
59 Date Description
60 ---- -----------
61
62************************************************************
63***********************************************************/
64
65module ipp_FD1(D, CP, Q);
66input D;
67input CP;
68output Q;
69
70reg state;
71
72assign Q = state;
73
74always @(posedge CP)
75 begin
76 state <= D;
77 end
78
79endmodule // ipp_FD1
80
81
82/***********************************
83 * ipp_RegDff
84 ***********************************/
85module ipp_RegDff (din, clk, qout);
86
87parameter dwidth = 32;
88input clk;
89input [dwidth-1:0] din;
90output [dwidth-1:0] qout;
91
92reg [dwidth-1:0] qout;
93
94always @ (posedge clk)
95 qout <= din;
96
97
98endmodule // ipp_RegDff
99
100
101//*****************************
102// Register ipp_xREG
103//*****************************
104module ipp_xREG (din, clk, en, reset, qout);
105
106parameter dwidth = 32;
107input clk, en, reset;
108input [dwidth-1:0] din;
109output [dwidth-1:0] qout;
110
111reg [dwidth-1:0] qout;
112
113always @ (posedge clk)
114 if (reset)
115 qout <= 0;
116 else if (en)
117 qout <= din;
118 else
119 qout <= qout;
120endmodule // end of ipp_xREG
121
122
123//*****************************
124// Register ipp_RAC_Plus1_Reg
125//*****************************
126module ipp_RAC_Plus1_Reg (clk, reset, iInc, iAutoClrEn, iMaxValue,
127 iLoad, iLoadValue, oDout, oMaxValueReached);
128
129parameter dwidth = 21;
130input clk,reset; // global signals
131input iInc; // Count Enable
132input iAutoClrEn;
133input [dwidth-1:0] iMaxValue; // compared value
134input iLoad;
135input [dwidth-1:0] iLoadValue; // compared value
136output[dwidth-1:0] oDout;
137output oMaxValueReached;
138
139reg [dwidth-1:0] oDout;
140wire oMaxValueReached = (oDout == iMaxValue);
141
142always @ (posedge clk)
143 if (reset | iAutoClrEn)
144 oDout <= 0;
145 else if (oMaxValueReached)
146 oDout <= oDout; // Stay at max value.
147 else if (iInc)
148 oDout <= oDout + 1;
149 else if (iLoad)
150 oDout <= iLoadValue;
151 else
152 oDout <= oDout; // Hold the value.
153
154
155endmodule // end of ipp_RAC_Plus1_Reg
156
157
158/************************************
159* Rising edge pulse gen
160*************************************/
161module ipp_puls_gen (reset, clk, signal_in, puls_out);
162
163input reset, clk, signal_in;
164output puls_out;
165
166reg Q;
167
168always @ (posedge clk)
169if (reset)
170 Q <= 0;
171else
172 Q <= signal_in;
173
174wire Qb = ~Q;
175
176wire puls_out = signal_in & Qb;
177
178endmodule
179
180
181/************************************
182* Falling edge pulse gen
183*************************************/
184module ipp_falling_edge_puls_gen (reset, clk, signal_in, puls_out);
185
186input reset, clk, signal_in;
187output puls_out;
188
189reg Q;
190
191always @ (posedge clk)
192if (reset)
193 Q <= 0;
194else
195 Q <= signal_in;
196
197wire puls_out = ~signal_in & Q;
198
199endmodule
200
201
202//*****************************
203// ipp_PlsGen2
204//*****************************
205module ipp_PlsGen2 (sig_in, clk, lead, trail);
206input sig_in, clk;
207output lead, trail;
208
209wire sig_in, sig_out;
210wire lead, trail;
211
212ipp_FD1 sig_out_FD1(.D(sig_in),.CP(clk),.Q(sig_out));
213
214assign lead = sig_in & ~sig_out;
215assign trail = ~sig_in & sig_out;
216
217endmodule // ipp_PlsGen2
218
219
220//*****************************
221// Reset Set Flip Flop
222//*****************************
223module ipp_RSFF (reset, clk, set, rst, Q);
224
225input reset, clk, set, rst;
226output Q;
227
228reg Q;
229
230always @ (posedge clk)
231if (reset)
232 Q <= 0;
233else
234 casex({set, rst})
235 2'b00: Q <= Q;
236 2'bx1: Q <= 0;
237 2'b10: Q <= 1;
238 endcase
239
240endmodule // end of Reset Set Flip Flop
241
242
243//*****************************
244// Register ipp_RAC_FF
245//*****************************
246module ipp_RAC_FF (clk, reset, set, rst,
247 load, load_data, dout);
248
249input clk, reset; // global signals
250input set, rst;
251input load;
252input load_data; // compared value
253output dout;
254
255reg dout;
256
257always @ (posedge clk)
258 if (reset | rst)
259 dout <= 0;
260 else if (set)
261 dout <= 1;
262 else if (load)
263 dout <= load_data;
264 else
265 dout <= dout;
266
267endmodule // ipp_RAC_FF
268
269
270/****************************************************************
271* ipp_phase_sm2: Use this state machine to count phases.
272*****************************************************************/
273module ipp_phase_sm2 (clk, reset, valid, rx_tag,
274 rd_eop, rd_status, cur_state);
275
276input clk;
277input reset;
278input valid;
279input [1:0] rx_tag;
280
281output [1:0] rd_eop;
282output [1:0] rd_status;
283output [1:0] cur_state;
284
285reg [1:0] cur_state, nex_state;
286reg [1:0] rd_eop;
287reg [1:0] rd_status;
288
289parameter StIdle = 2'b00;
290parameter StWait1stTag = 2'b01;
291parameter StWait2ndTag = 2'b10;
292
293
294// Comb part
295always @ (valid or rx_tag or cur_state)
296 begin
297 rd_eop = 0;
298 rd_status = 0;
299 nex_state = 0;
300
301 case (cur_state) // synopsys parallel_case full_case
302 StIdle: // 'h0
303 if (valid)
304 nex_state = StWait1stTag; // 'h1
305 else
306 nex_state = cur_state; // 'h0
307
308 StWait1stTag: // 'h1
309 casex (rx_tag[1:0])
310 2'b00:
311 nex_state = cur_state; // 'h1
312 2'b01:
313 begin
314 nex_state = StIdle; // 'h0
315// $display("ERROR: MAC status is ahead of end of packet at simtime = %d", $time);
316 end
317 2'b10:
318 begin
319 nex_state = StWait2ndTag; // 'h2
320 rd_eop = 2'b10;
321 rd_status = 2'b0;
322 end
323 2'b11:
324 begin
325 nex_state = StIdle; // 'h0
326 rd_eop = 2'b11;
327 rd_status = 2'b11;
328 end
329 endcase
330
331 StWait2ndTag: // 'h2
332 casex (rx_tag[0])
333 1'b0:
334 nex_state = cur_state; // 'h2
335 1'b1: begin
336 rd_eop = 2'b0;
337 rd_status = 2'b01;
338 nex_state = StIdle; // 'h0
339 end
340 endcase
341/*
342 if (rx_tag[1:0] == 2'b01)
343 begin
344 rd_eop = 2'b0;
345 rd_status = 2'b01;
346 nex_state = StIdle; // 'h0
347 end
348 else
349 nex_state = cur_state; // 'h2
350*/
351 default:
352 nex_state = StIdle;
353 endcase // end major endcase
354 end // end of comb part
355
356// Seq part
357always @ (posedge clk)
358 if (reset)
359 cur_state <= 2'b0;
360 else
361 cur_state <= nex_state;
362
363
364endmodule // end of ipp_phase_sm2
365
366
367module ipp_spare(di, reset, clk, qo);
368input di;
369input reset;
370input clk;
371output qo;
372
373wire qo;
374
375 ipp_reg_r_1 ipp_reg_r_1_dum (.di(di), .rs(reset), .ck(clk), .qo(qo));
376
377endmodule // ipp_spare
378
379
380// =====================================================================
381// This is a FSM for controlling IPP_EN
382// Original: : ipp_en_rst_fsm in ipp.v main.70, label: IPP_VERIF_1.84
383
384module niu_ipp_en_rst_fsm (clk, reset, ipp_enable,
385 wr_ipp_en_bit0, mac_stat, IFG,
386 rst_ipp_en, ipp_en_rst_fsm_curstate);
387
388input clk, reset;
389input ipp_enable;
390input wr_ipp_en_bit0;
391input mac_stat;
392input IFG;
393
394output rst_ipp_en;
395output [1:0] ipp_en_rst_fsm_curstate;
396
397reg [1:0] cur_state;
398reg [1:0] nex_state;
399reg rst_ipp_en;
400
401wire [1:0] ipp_en_rst_fsm_curstate = cur_state[1:0];
402
403parameter
404 StIdle = 2'h0,
405 StIppEn1 = 2'h1,
406 StIppEn2 = 2'h2,
407 StDly1 = 2'h3;
408
409always @(cur_state or ipp_enable or wr_ipp_en_bit0 or mac_stat or IFG)
410 begin
411 rst_ipp_en = 1'b0;
412 nex_state = 2'b0;
413
414 casex(cur_state) // synopsys parallel_case full_case
415 StIdle:
416 begin
417 if (ipp_enable)
418 nex_state = StIppEn1;
419 else
420 nex_state = cur_state;
421 end
422
423 StIppEn1:
424 casex ({wr_ipp_en_bit0, IFG})
425 2'b0x: nex_state = cur_state;
426 2'b10: nex_state = StIppEn2;
427 2'b11: begin
428 nex_state = StDly1;
429 rst_ipp_en = 1'b1;
430 end
431 endcase
432
433 StIppEn2:
434 begin
435 if (mac_stat)
436 begin
437 rst_ipp_en = 1'b1;
438 nex_state = StDly1;
439 end
440 else
441 nex_state = cur_state;
442 end
443
444 StDly1:
445 nex_state = StIdle;
446
447 endcase
448 end
449
450always @(posedge clk)
451 if (reset)
452 cur_state <= 2'h0;
453 else
454 cur_state <= nex_state;
455
456endmodule
457
458// =====================================================================
459module ipp_reg_r_1 (di, rs, ck, qo);
460input di;
461input rs;
462input ck;
463output qo;
464
465reg qo;
466
467 always @(posedge ck)
468 begin
469 if (rs)
470 qo <= #1 1'h0;
471 else
472 qo <= #1 di;
473 end
474
475endmodule
476
477
478module ipp_reg_r_2 (di, rs, ck, qo);
479input [1:0] di;
480input rs;
481input ck;
482output [1:0] qo;
483
484reg [1:0] qo;
485
486 always @(posedge ck)
487 begin
488 if (rs)
489 qo <= #1 2'h0;
490 else
491 qo <= #1 di[1:0];
492 end
493
494endmodule
495
496
497module ipp_reg_r_10 (di, rs, ck, qo);
498input [9:0] di;
499input rs;
500input ck;
501output [9:0] qo;
502
503reg [9:0] qo;
504
505 always @(posedge ck)
506 begin
507 if (rs)
508 qo <= #1 10'h0;
509 else
510 qo <= #1 di[9:0];
511 end
512
513endmodule
514
515
516module ipp_reg_r_11 (di, rs, ck, qo);
517input [10:0] di;
518input rs;
519input ck;
520output [10:0] qo;
521
522reg [10:0] qo;
523
524 always @(posedge ck)
525 begin
526 if (rs)
527 qo <= #1 11'h0;
528 else
529 qo <= #1 di[10:0];
530 end
531
532endmodule
533
534
535module ipp_reg_r_12 (di, rs, ck, qo);
536input [11:0] di;
537input rs;
538input ck;
539output [11:0] qo;
540
541reg [11:0] qo;
542
543 always @(posedge ck)
544 begin
545 if (rs)
546 qo <= #1 12'h0;
547 else
548 qo <= #1 di[11:0];
549 end
550
551endmodule
552
553
554module ipp_reg_r_16 (di, rs, ck, qo);
555input [15:0] di;
556input rs;
557input ck;
558output [15:0] qo;
559
560reg [15:0] qo;
561
562 always @(posedge ck)
563 begin
564 if (rs)
565 qo <= #1 16'h0;
566 else
567 qo <= #1 di[15:0];
568 end
569
570endmodule
571
572
573module ipp_reg_r_128 (di, rs, ck, qo);
574input [127:0] di;
575input rs;
576input ck;
577output [127:0] qo;
578
579reg [127:0] qo;
580
581 always @(posedge ck)
582 begin
583 if (rs)
584 qo <= #1 128'h0;
585 else
586 qo <= #1 di[127:0];
587 end
588
589endmodule
590
591
592module ipp_reg_r_130 (di, rs, ck, qo);
593input [129:0] di;
594input rs;
595input ck;
596output [129:0] qo;
597
598reg [129:0] qo;
599
600 always @(posedge ck)
601 begin
602 if (rs)
603 qo <= #1 130'h0;
604 else
605 qo <= #1 di[129:0];
606 end
607
608endmodule
609
610
611module ipp_reg_w_r_32 (di, wr, rs, ck, qo);
612input [31:0] di;
613input wr;
614input rs;
615input ck;
616output [31:0] qo;
617
618reg [31:0] qo;
619
620 always @(posedge ck)
621 begin
622 if (rs)
623 qo <= #1 32'h0;
624 else if (wr)
625 qo <= #1 di[31:0];
626 else
627 qo <= #1 qo[31:0];
628 end
629
630endmodule
631
632
633module ipp_reg_w_s_17 (di, wr, rs, ck, qo);
634input [16:0] di;
635input wr;
636input rs;
637input ck;
638output [16:0] qo;
639
640reg [16:0] qo;
641
642 always @(posedge ck)
643 begin
644 if (rs)
645 qo <= #1 17'h1_ffff;
646 else if (wr)
647 qo <= #1 di[16:0];
648 else
649 qo <= #1 qo[16:0];
650 end
651
652endmodule
653
654
655module ipp_reg_w_sti_r_rac_1 (di, wr, rs, rac, ck, qo);
656input di;
657input wr;
658input rs;
659input rac;
660input ck;
661output qo;
662
663reg qo;
664reg wrote;
665
666 always @(posedge ck)
667 begin
668 if (rs || rac) begin
669 qo <= #1 1'h0;
670 wrote <= #1 1'h0;
671 end
672 else if (wr && !wrote) begin
673 qo <= #1 di;
674 wrote <= #1 1'h1;
675 end
676 else begin
677 qo <= #1 qo;
678 wrote <= #1 wrote;
679 end
680 end
681
682endmodule
683
684
685module ipp_reg_w_sti_r_rac_5 (di, wr, rs, rac, ck, qo);
686input [4:0] di;
687input wr;
688input rs;
689input rac;
690input ck;
691output [4:0] qo;
692
693reg [4:0] qo;
694reg wrote;
695
696 always @(posedge ck)
697 begin
698 if (rs || rac) begin
699 qo <= #1 5'h0;
700 wrote <= #1 1'h0;
701 end
702 else if (wr && !wrote) begin
703 qo <= #1 di[4:0];
704 wrote <= #1 1'h1;
705 end
706 else begin
707 qo <= #1 qo[4:0];
708 wrote <= #1 wrote;
709 end
710 end
711
712endmodule
713
714
715module ipp_reg_w_sti_r_rac_6 (di, wr, rs, rac, ck, qo);
716input [5:0] di;
717input wr;
718input rs;
719input rac;
720input ck;
721output [5:0] qo;
722
723reg [5:0] qo;
724reg wrote;
725
726 always @(posedge ck)
727 begin
728 if (rs || rac) begin
729 qo <= #1 6'h0;
730 wrote <= #1 1'h0;
731 end
732 else if (wr && !wrote) begin
733 qo <= #1 di[5:0];
734 wrote <= #1 1'h1;
735 end
736 else begin
737 qo <= #1 qo[5:0];
738 wrote <= #1 wrote;
739 end
740 end
741
742endmodule
743
744
745module ipp_reg_w_sti_r_rac_11 (di, wr, rs, rac, ck, qo);
746input [10:0] di;
747input wr;
748input rs;
749input rac;
750input ck;
751output [10:0] qo;
752
753reg [10:0] qo;
754reg wrote;
755
756 always @(posedge ck)
757 begin
758 if (rs || rac) begin
759 qo <= #1 11'h0;
760 wrote <= #1 1'h0;
761 end
762 else if (wr && !wrote) begin
763 qo <= #1 di[10:0];
764 wrote <= #1 1'h1;
765 end
766 else begin
767 qo <= #1 qo[10:0];
768 wrote <= #1 wrote;
769 end
770 end
771
772endmodule
773
774
775module ipp_reg_w_sti_r_rac_12 (di, wr, rs, rac, ck, qo);
776input [11:0] di;
777input wr;
778input rs;
779input rac;
780input ck;
781output [11:0] qo;
782
783reg [11:0] qo;
784reg wrote;
785
786 always @(posedge ck)
787 begin
788 if (rs || rac) begin
789 qo <= #1 12'h0;
790 wrote <= #1 1'h0;
791 end
792 else if (wr && !wrote) begin
793 qo <= #1 di[11:0];
794 wrote <= #1 1'h1;
795 end
796 else begin
797 qo <= #1 qo[11:0];
798 wrote <= #1 wrote;
799 end
800 end
801
802endmodule
803
804
805module ipp_reg_w_sti_r_rac_16 (di, wr, rs, rac, ck, qo);
806input [15:0] di;
807input wr;
808input rs;
809input rac;
810input ck;
811output [15:0] qo;
812
813reg [15:0] qo;
814reg wrote;
815
816 always @(posedge ck)
817 begin
818 if (rs || rac) begin
819 qo <= #1 16'h0;
820 wrote <= #1 1'h0;
821 end
822 else if (wr && !wrote) begin
823 qo <= #1 di[15:0];
824 wrote <= #1 1'h1;
825 end
826 else begin
827 qo <= #1 qo[15:0];
828 wrote <= #1 wrote;
829 end
830 end
831
832endmodule
833
834
835module niu_ipp_reset_blk (reset_l, clk, reset);
836
837input reset_l;
838input clk;
839output reset;
840
841reg reset;
842
843wire reset_p = !reset_l;
844
845 always @(posedge clk)
846 reset <= #1 reset_p;
847
848endmodule
849
850