Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / verif / model / systemc / niu / niu_ncu_interface.cpp
CommitLineData
86530b38
AT
1// ========== Copyright Header Begin ==========================================
2//
3// OpenSPARC T2 Processor File: niu_ncu_interface.cpp
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// ========== Copyright Header Begin ==========================================
36//
37// OpenSPARC T2 Processor File: niu_ncu_interface.cpp
38// Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved
39// 4150 Network Circle, Santa Clara, California 95054, U.S.A.
40//
41// * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
42//
43// This program is free software; you can redistribute it and/or modify
44// it under the terms of the GNU General Public License as published by
45// the Free Software Foundation; version 2 of the License.
46//
47// This program is distributed in the hope that it will be useful,
48// but WITHOUT ANY WARRANTY; without even the implied warranty of
49// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50// GNU General Public License for more details.
51//
52// You should have received a copy of the GNU General Public License
53// along with this program; if not, write to the Free Software
54// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
55//
56// For the avoidance of doubt, and except that if any non-GPL license
57// choice is available it will apply instead, Sun elects to use only
58// the General Public License version 2 (GPLv2) at this time for any
59// software where a choice of GPL license versions is made
60// available with the language indicating that GPLv2 or any later version
61// may be used, or where a choice of which version of the GPL is applied is
62// otherwise unspecified.
63//
64// Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
65// CA 95054 USA or visit www.sun.com if you need additional information or
66// have any questions.
67//
68// ========== Copyright Header End ============================================
69#include <systemc.h>
70
71#include "niu_ncu_interface.h"
72#include "sharedmem.h"
73
74extern "C" void vcs_atexit(void(*pfun)(int code));
75
76sharedmem *shmem = NULL;
77
78niu_ncu_interface::niu_ncu_interface(sc_module_name) {
79 SC_METHOD(ncu_interface);
80 sensitive << clk.pos();
81
82 ncu_niu_vld_d = false;
83 ncu_niu_stall_d = false;
84 niu_ncu_stall_d = false;
85 ncu_word = 0;
86 niu_word = 0;
87 niu_int_word = 0;
88 reset = 1;
89}
90
91void niu_ncu_interface::ncu_interface() {
92 if(reset) {
93 niu_rd.write(false);
94 niu_rd_addr.write(0);
95 niu_rd_data.write(0);
96 niu_ncu_stall.write(false);
97 reset = 0;
98 }
99
100
101//When an interrupt is received from NIU, send it to NCU
102 if(shmem) {
103 unsigned int data;
104 shmem->receiveInterrupt(data);
105 if(data) {
106 niu_interrupt.range(63,57) = 0;
107 niu_interrupt.range(56,51) = 0;
108 niu_interrupt.range(50,19) = 0;
109 niu_interrupt.range(18,10) = data & 0x1ff;
110 niu_interrupt.range(9,7) = 0;
111 niu_interrupt.range(6,4) = 0;
112 niu_interrupt.range(3,0) = "1000";
113 niu_int_word = 3;
114 }
115 }
116
117 if(niu_int_word > 1) {
118 niu_ncu_vld.write(true);
119 switch(niu_int_word) {
120 case 3: niu_ncu_data.write(niu_data.get_word(0)); break;
121 case 2: niu_ncu_data.write(niu_data.get_word(1)); break;
122 }
123 niu_int_word--;
124 } else if(niu_int_word == 1) {
125 niu_ncu_vld.write(false);
126 niu_int_word--;
127 }
128
129//When the response to ncu is ready, send it to NCU
130//Total of 5 cycles; 4 x 32-bits + 1 idle cycle
131 if(niu_word > 1) {
132 niu_ncu_vld.write(true);
133 switch(niu_word) {
134 case 5: niu_ncu_data.write(niu_data.get_word(0)); break;
135 case 4: niu_ncu_data.write(niu_data.get_word(1)); break;
136 case 3: niu_ncu_data.write(niu_data.get_word(2)); break;
137 case 2: niu_ncu_data.write(niu_data.get_word(3));
138 niu_rd.write(true);
139 niu_rd_addr.write(niu_data.range(41,15));
140 niu_rd_data.write(niu_data.range(127,64));
141 break;
142 }
143 niu_word--;
144 } else if(niu_word == 1) {
145 niu_ncu_vld.write(false);
146 niu_rd.write(false);
147 niu_word--;
148 }
149
150//When ncu_niu_vld deasserts, the request is complete
151//Send the request to the niu model, and wait for the response
152 if(!ncu_niu_vld.read() && ncu_niu_vld_d) {
153 unsigned long int mem[4];
154 for(int i=0;i<4;i++) mem[i] = ncu_data.get_word(i);
155
156 shmem->deliver_ncu_req(mem, 16);
157 //shmem->receive_niu_res(mem, 16);
158
159 for(int i=0;i<4;i++) {
160 niu_data.set_word(i, mem[i]);
161 niu_data.set_cword(i, 0); //no x or z
162 }
163 if(ncu_data.range(3,0) == "0100") {
164 niu_data.range(3,0) = "0001";
165 niu_word = 5;
166 }
167 }
168
169//Process the request from NCU to NIU
170//A complete request takes 4 cycles, each with 32-bit data
171 if(!ncu_niu_vld.read()) {
172 ncu_word = 0;
173 ncu_data = 0;
174 } else {
175 if(!niu_ncu_stall_d) {
176 switch(ncu_word) {
177 case 0: ncu_data.range(31,0) = ncu_niu_data.read(); break;
178 case 1: ncu_data.range(63,32) = ncu_niu_data.read(); break;
179 case 2: ncu_data.range(95,64) = ncu_niu_data.read(); break;
180 case 3: ncu_data.range(127,96) = ncu_niu_data.read(); break;
181 }
182 ncu_word++;
183 }
184 }
185
186//Delay ncu_niu_stall, niu_ncu_stall, and ncu_niu_vld signals for a cycle
187 ncu_niu_stall_d = ncu_niu_stall.read();
188 niu_ncu_stall_d = niu_ncu_stall.read();
189 ncu_niu_vld_d = ncu_niu_vld.read();
190}
191
192
193