Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / design / sys / iop / dmu / rtl / dmu_mmu_tcb_tcc.v
CommitLineData
86530b38
AT
1// ========== Copyright Header Begin ==========================================
2//
3// OpenSPARC T2 Processor File: dmu_mmu_tcb_tcc.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 ============================================
35module dmu_mmu_tcb_tcc
36 (
37 clk, // clock
38 rst_l, // reset
39 crb2tcb_tag, // crb replacement tag
40 csr2tcb_cm, // csr cache mode
41 ptb2tcb_hit, // ptb physical tag hit
42 rcb2tcb_ack, // rcb acknowledge
43 tdc2tcc_ack, // tmc request
44 tdc2tcc_err, // tdc acknowledge
45 tmc2tcc_req, // tdc errors
46 tcb2crb_req, // crb request
47 tcb2csr_tcm, // csr tablewalk cache mode
48 tcb2csr_tip, // csr tablewalk in progress
49 tcb2ptb_sel, // ptb select
50 tcb2ptb_vld, // ptb valid
51 tcb2ptb_wa, // ptb write address
52 tcb2ptb_we, // ptb write enable
53 tcb2rcb_req, // rcb request
54 tcb2rcb_tag, // rcb tag
55 tcb2tdb_sel, // tdb select
56 tcb2tlb_tld, // tlb tag load
57 tcb2vtb_sel, // vtb select
58 tcb2vtb_vld, // vtb valid
59 tcb2vtb_wa, // vtb write address
60 tcb2vtb_we, // vtb write enable
61 tcc2tdc_cld, // tdc cache load
62 tcc2tdc_req, // tdc request
63 tcc2tdc_tag, // tdc replacement tag
64 tcc2tmc_ack, // tmc acknowledge
65 tcc2tmc_dbg, // tmc debug
66 tcc2tmc_vld // tmc valid
67 );
68
69// ----------------------------------------------------------------------------
70// Parameters
71// ----------------------------------------------------------------------------
72 parameter IDLE = 3'b000, // state machine states
73 LOAD = 3'b001,
74 RQST = 3'b010,
75 WAIT = 3'b011,
76 NVLD = 3'b100,
77 RTRY = 3'b101,
78 DONE = 3'b110,
79 DERR = 3'b111;
80
81// ----------------------------------------------------------------------------
82// Ports
83// ----------------------------------------------------------------------------
84 input clk;
85 input rst_l;
86
87 input [`FIRE_DLC_MMU_TAG_PTR_BITS] crb2tcb_tag;
88 input [`FIRE_DLC_MMU_CSR_CM_BITS] csr2tcb_cm;
89 input ptb2tcb_hit;
90 input rcb2tcb_ack;
91 input tmc2tcc_req;
92 input tdc2tcc_ack;
93 input tdc2tcc_err;
94
95 output tcb2crb_req;
96 output [`FIRE_DLC_MMU_CSR_CM_BITS] tcb2csr_tcm;
97 output tcb2csr_tip;
98 output tcb2ptb_sel;
99 output tcb2ptb_vld;
100 output [`FIRE_DLC_MMU_TAG_PTR_BITS] tcb2ptb_wa;
101 output tcb2ptb_we;
102 output tcb2rcb_req;
103 output [`FIRE_DLC_MMU_TAG_PTR_BITS] tcb2rcb_tag;
104 output tcb2tdb_sel;
105 output tcb2tlb_tld;
106 output tcb2vtb_sel;
107 output tcb2vtb_vld;
108 output [`FIRE_DLC_MMU_TAG_PTR_BITS] tcb2vtb_wa;
109 output tcb2vtb_we;
110 output tcc2tdc_cld;
111 output tcc2tdc_req;
112 output [`FIRE_DLC_MMU_TAG_PTR_BITS] tcc2tdc_tag;
113 output tcc2tmc_ack;
114 output [`FIRE_DBG_DATA_BITS] tcc2tmc_dbg;
115 output tcc2tmc_vld;
116
117// ----------------------------------------------------------------------------
118// Variables
119// ----------------------------------------------------------------------------
120 wire [`FIRE_DLC_MMU_CSR_CM_BITS] tcb2csr_tcm;
121 wire [`FIRE_DLC_MMU_TAG_PTR_BITS] tcb2ptb_wa, tcb2vtb_wa;
122 wire [`FIRE_DLC_MMU_TAG_PTR_BITS] tcb2rcb_tag, tcc2tdc_tag;
123 wire [`FIRE_DBG_DATA_BITS] tcc2tmc_dbg;
124
125 reg tcb2crb_req;
126 reg tcc2tdc_req;
127 reg tcc2tmc_ack;
128 reg hit;
129 reg req, nxt_req;
130 reg [2:0] state, nxt_state;
131 reg [`FIRE_DLC_MMU_TAG_PTR_BITS] tag;
132 reg tag_ld, tag_we;
133 reg [1:0] tcm, nxt_tcm;
134 reg tip, vld, set_vld, clr_vld;
135
136// ----------------------------------------------------------------------------
137// Zero In Checkers
138// ----------------------------------------------------------------------------
139
140 // 0in state_transition -var state -val IDLE -next LOAD
141 // 0in state_transition -var state -val LOAD -next RQST
142 // 0in state_transition -var state -val RQST -next WAIT
143 // 0in state_transition -var state -val WAIT -next NVLD RTRY DONE DERR
144 // 0in state_transition -var state -val NVLD -next RTRY DERR
145 // 0in state_transition -var state -val RTRY -next RQST
146 // 0in state_transition -var state -val DONE -next IDLE
147 // 0in state_transition -var state -val DERR -next IDLE
148
149// ----------------------------------------------------------------------------
150// Combinational
151// ----------------------------------------------------------------------------
152// valid hit
153 wire vld_hit = vld & ptb2tcb_hit;
154
155// next state
156 always @ (state or rcb2tcb_ack or tmc2tcc_req or
157 tdc2tcc_ack or tdc2tcc_err or req or vld_hit) begin
158 case (state) // synopsys parallel_case
159 IDLE : begin
160 case (tmc2tcc_req) // synopsys parallel_case
161 1'b0 : nxt_state = IDLE; // idle
162 1'b1 : nxt_state = LOAD; // request
163 endcase
164 end
165 LOAD : begin // load tags
166 nxt_state = RQST;
167 end
168 RQST : begin
169 case (req ^ rcb2tcb_ack) // synopsys parallel_case
170 1'b0 : nxt_state = WAIT; // acked
171 1'b1 : nxt_state = RQST; // wait for tcr ack
172 endcase
173 end
174 WAIT : begin
175 case ({tdc2tcc_ack, tdc2tcc_err, vld_hit}) // synopsys parallel_case
176 3'b000 : nxt_state = WAIT; // wait for tdc ack
177 3'b001 : nxt_state = NVLD; // tag hit, wait for tdc ack
178 3'b100 : nxt_state = DONE; // done
179 3'b101 : nxt_state = RTRY; // tag hit, retry
180 3'b110 : nxt_state = DERR; // data error
181 3'b111 : nxt_state = DERR; // data error
182 default : nxt_state = DERR; // data error
183 endcase
184 end
185 NVLD : begin
186 case ({tdc2tcc_ack, tdc2tcc_err, vld_hit}) // synopsys parallel_case
187 3'b000 : nxt_state = NVLD; // wait for tdc ack
188 3'b001 : nxt_state = NVLD; // tag hit, wait for tdc ack
189 3'b100 : nxt_state = RTRY; // done
190 3'b101 : nxt_state = RTRY; // tag hit, retry
191 3'b110 : nxt_state = DERR; // data error
192 3'b111 : nxt_state = DERR; // data error
193 default : nxt_state = DERR; // data error
194 endcase
195 end
196 RTRY : begin // retry request
197 nxt_state = RQST;
198 end
199 DONE : begin
200 nxt_state = IDLE;
201 end
202 DERR : begin
203 nxt_state = IDLE;
204 end
205 endcase
206 end
207
208// state machine outputs
209 always @ (state or csr2tcb_cm or rcb2tcb_ack or
210 hit or tcm or req or vld_hit) begin
211 tcb2crb_req = 0;
212 tcc2tdc_req = 0;
213 tcc2tmc_ack = 0;
214 nxt_req = req;
215 nxt_tcm = tcm;
216 clr_vld = 0;
217 set_vld = 0;
218 tag_ld = 0;
219 tag_we = 0;
220 tip = 0;
221 case (state) // synopsys parallel_case
222 IDLE : begin
223 nxt_tcm = csr2tcb_cm; // cache mode
224 clr_vld = vld_hit; // clear valid on valid hit
225 end
226 LOAD : begin
227 tcb2crb_req = &tcm; // request replacement tag
228 nxt_req = ~req; // tcr request
229 clr_vld = 1'b1; // clear valid
230 tag_ld = 1'b1; // load tags
231 tip = 1'b1; // tablewalk in progress
232 end
233 RQST : begin
234 tcb2crb_req = hit; // reset replacement tag
235 tcc2tdc_req = rcb2tcb_ack; // tdc request
236 set_vld = 1'b1; // set valid for crb reset
237 tag_we = &tcm; // write tags to set valid
238 tip = 1'b1; // tablewalk in progress
239 end
240 WAIT : begin
241 tcb2crb_req = hit; // reset replacement tag
242 tag_we = &tcm; // write tags to set valid
243 tip = 1'b1; // tablewalk in progress
244 end
245 NVLD : begin
246 tcb2crb_req = hit; // reset replacement tag
247 tag_we = &tcm; // write tags to set valid
248 tip = 1'b1; // tablewalk in progress
249 end
250 RTRY : begin
251 tcb2crb_req = hit; // reset replacement tag
252 nxt_req = ~req; // retry tcr request
253 tag_we = &tcm; // write tags to set valid
254 tip = 1'b1; // tablewalk in progress
255 end
256 DONE : begin
257 tcc2tmc_ack = 1'b1; // tmc ack
258 clr_vld = vld_hit; // clear valid on valid hit
259 tag_we = &tcm; // write tags for real
260 tip = 1'b1; // tablewalk in progress
261 end
262 DERR : begin
263 tcc2tmc_ack = 1'b1; // tmc ack
264 clr_vld = 1'b1; // clear valid
265 tag_we = &tcm; // write tags for real
266 tip = 1'b1; // tablewalk in progress
267 end
268
269 endcase
270 end
271
272// next hit
273 wire nxt_hit = &tcm & vld_hit & ~tag_ld;
274
275// next valid
276 wire nxt_vld = (vld | set_vld) & ~clr_vld;
277
278// tablewalk cache mode and in progress
279 assign tcb2csr_tcm = tcm;
280 wire tcb2csr_tip = tip;
281
282// ptb tag select, valid, write address and enable
283 wire tcb2ptb_sel = |tcm;
284 wire tcb2ptb_vld = nxt_vld;
285 assign tcb2ptb_wa = tag;
286 wire tcb2ptb_we = tag_we;
287
288// rcb request and tag
289 wire tcb2rcb_req = req;
290 assign tcb2rcb_tag = tag;
291
292// tdb tag select
293 wire tcb2tdb_sel = |tcm;
294
295// tlb tag load
296 wire tcb2tlb_tld = tag_ld | ~rst_l;
297
298// vtb tag select, valid, write address and enable
299 wire tcb2vtb_sel = |tcm;
300 wire tcb2vtb_vld = nxt_vld;
301 assign tcb2vtb_wa = tag;
302 wire tcb2vtb_we = tag_we;
303
304// tdc cache load and tag
305 wire tcc2tdc_cld = &tcm;
306 assign tcc2tdc_tag = tag;
307
308// tmc error and valid
309 wire tcc2tmc_vld = vld;
310
311// ----------------------------------------------------------------------------
312// Debug
313// ----------------------------------------------------------------------------
314 assign tcc2tmc_dbg = {state, vld, tcm, req, hit};
315
316// ----------------------------------------------------------------------------
317// Sequential
318// ----------------------------------------------------------------------------
319 always @ (posedge clk) begin
320 if (!rst_l) begin
321 hit <= 0;
322 req <= 0;
323 tcm <= 0;
324 vld <= 0;
325 state <= IDLE;
326 end
327 else begin
328 hit <= nxt_hit;
329 req <= nxt_req;
330 tcm <= nxt_tcm;
331 vld <= nxt_vld;
332 state <= nxt_state;
333 end
334 end
335
336 always @ (posedge clk) begin
337 if (!rst_l) begin
338 tag <= 0;
339 end
340 else if (tag_ld) begin
341 tag <= crb2tcb_tag;
342 end
343 end
344
345endmodule // dmu_mmu_tcb_tcc