// ========== Copyright Header Begin ==========================================
// OpenSPARC T2 Processor File: dmu_mmu_tcb_tcc.v
// Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved
// 4150 Network Circle, Santa Clara, California 95054, U.S.A.
// * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 2 of the License.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// For the avoidance of doubt, and except that if any non-GPL license
// choice is available it will apply instead, Sun elects to use only
// the General Public License version 2 (GPLv2) at this time for any
// software where a choice of GPL license versions is made
// available with the language indicating that GPLv2 or any later version
// may be used, or where a choice of which version of the GPL is applied is
// otherwise unspecified.
// Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
// CA 95054 USA or visit www.sun.com if you need additional information or
// ========== Copyright Header End ============================================
crb2tcb_tag, // crb replacement tag
csr2tcb_cm, // csr cache mode
ptb2tcb_hit, // ptb physical tag hit
rcb2tcb_ack, // rcb acknowledge
tdc2tcc_ack, // tmc request
tdc2tcc_err, // tdc acknowledge
tmc2tcc_req, // tdc errors
tcb2crb_req, // crb request
tcb2csr_tcm, // csr tablewalk cache mode
tcb2csr_tip, // csr tablewalk in progress
tcb2ptb_sel, // ptb select
tcb2ptb_vld, // ptb valid
tcb2ptb_wa, // ptb write address
tcb2ptb_we, // ptb write enable
tcb2rcb_req, // rcb request
tcb2tdb_sel, // tdb select
tcb2tlb_tld, // tlb tag load
tcb2vtb_sel, // vtb select
tcb2vtb_vld, // vtb valid
tcb2vtb_wa, // vtb write address
tcb2vtb_we, // vtb write enable
tcc2tdc_cld, // tdc cache load
tcc2tdc_req, // tdc request
tcc2tdc_tag, // tdc replacement tag
tcc2tmc_ack, // tmc acknowledge
tcc2tmc_dbg, // tmc debug
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
parameter IDLE = 3'b000, // state machine states
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
input [`FIRE_DLC_MMU_TAG_PTR_BITS] crb2tcb_tag;
input [`FIRE_DLC_MMU_CSR_CM_BITS] csr2tcb_cm;
output [`FIRE_DLC_MMU_CSR_CM_BITS] tcb2csr_tcm;
output [`FIRE_DLC_MMU_TAG_PTR_BITS] tcb2ptb_wa;
output [`FIRE_DLC_MMU_TAG_PTR_BITS] tcb2rcb_tag;
output [`FIRE_DLC_MMU_TAG_PTR_BITS] tcb2vtb_wa;
output [`FIRE_DLC_MMU_TAG_PTR_BITS] tcc2tdc_tag;
output [`FIRE_DBG_DATA_BITS] tcc2tmc_dbg;
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
wire [`FIRE_DLC_MMU_CSR_CM_BITS] tcb2csr_tcm;
wire [`FIRE_DLC_MMU_TAG_PTR_BITS] tcb2ptb_wa, tcb2vtb_wa;
wire [`FIRE_DLC_MMU_TAG_PTR_BITS] tcb2rcb_tag, tcc2tdc_tag;
wire [`FIRE_DBG_DATA_BITS] tcc2tmc_dbg;
reg [2:0] state, nxt_state;
reg [`FIRE_DLC_MMU_TAG_PTR_BITS] tag;
reg tip, vld, set_vld, clr_vld;
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// 0in state_transition -var state -val IDLE -next LOAD
// 0in state_transition -var state -val LOAD -next RQST
// 0in state_transition -var state -val RQST -next WAIT
// 0in state_transition -var state -val WAIT -next NVLD RTRY DONE DERR
// 0in state_transition -var state -val NVLD -next RTRY DERR
// 0in state_transition -var state -val RTRY -next RQST
// 0in state_transition -var state -val DONE -next IDLE
// 0in state_transition -var state -val DERR -next IDLE
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
wire vld_hit = vld & ptb2tcb_hit;
always @ (state or rcb2tcb_ack or tmc2tcc_req or
tdc2tcc_ack or tdc2tcc_err or req or vld_hit) begin
case (state) // synopsys parallel_case
case (tmc2tcc_req) // synopsys parallel_case
1'b0 : nxt_state = IDLE; // idle
1'b1 : nxt_state = LOAD; // request
LOAD : begin // load tags
case (req ^ rcb2tcb_ack) // synopsys parallel_case
1'b0 : nxt_state = WAIT; // acked
1'b1 : nxt_state = RQST; // wait for tcr ack
case ({tdc2tcc_ack, tdc2tcc_err, vld_hit}) // synopsys parallel_case
3'b000 : nxt_state = WAIT; // wait for tdc ack
3'b001 : nxt_state = NVLD; // tag hit, wait for tdc ack
3'b100 : nxt_state = DONE; // done
3'b101 : nxt_state = RTRY; // tag hit, retry
3'b110 : nxt_state = DERR; // data error
3'b111 : nxt_state = DERR; // data error
default : nxt_state = DERR; // data error
case ({tdc2tcc_ack, tdc2tcc_err, vld_hit}) // synopsys parallel_case
3'b000 : nxt_state = NVLD; // wait for tdc ack
3'b001 : nxt_state = NVLD; // tag hit, wait for tdc ack
3'b100 : nxt_state = RTRY; // done
3'b101 : nxt_state = RTRY; // tag hit, retry
3'b110 : nxt_state = DERR; // data error
3'b111 : nxt_state = DERR; // data error
default : nxt_state = DERR; // data error
RTRY : begin // retry request
always @ (state or csr2tcb_cm or rcb2tcb_ack or
hit or tcm or req or vld_hit) begin
case (state) // synopsys parallel_case
nxt_tcm = csr2tcb_cm; // cache mode
clr_vld = vld_hit; // clear valid on valid hit
tcb2crb_req = &tcm; // request replacement tag
nxt_req = ~req; // tcr request
clr_vld = 1'b1; // clear valid
tag_ld = 1'b1; // load tags
tip = 1'b1; // tablewalk in progress
tcb2crb_req = hit; // reset replacement tag
tcc2tdc_req = rcb2tcb_ack; // tdc request
set_vld = 1'b1; // set valid for crb reset
tag_we = &tcm; // write tags to set valid
tip = 1'b1; // tablewalk in progress
tcb2crb_req = hit; // reset replacement tag
tag_we = &tcm; // write tags to set valid
tip = 1'b1; // tablewalk in progress
tcb2crb_req = hit; // reset replacement tag
tag_we = &tcm; // write tags to set valid
tip = 1'b1; // tablewalk in progress
tcb2crb_req = hit; // reset replacement tag
nxt_req = ~req; // retry tcr request
tag_we = &tcm; // write tags to set valid
tip = 1'b1; // tablewalk in progress
tcc2tmc_ack = 1'b1; // tmc ack
clr_vld = vld_hit; // clear valid on valid hit
tag_we = &tcm; // write tags for real
tip = 1'b1; // tablewalk in progress
tcc2tmc_ack = 1'b1; // tmc ack
clr_vld = 1'b1; // clear valid
tag_we = &tcm; // write tags for real
tip = 1'b1; // tablewalk in progress
wire nxt_hit = &tcm & vld_hit & ~tag_ld;
wire nxt_vld = (vld | set_vld) & ~clr_vld;
// tablewalk cache mode and in progress
assign tcb2csr_tcm = tcm;
// ptb tag select, valid, write address and enable
wire tcb2ptb_vld = nxt_vld;
wire tcb2ptb_we = tag_we;
assign tcb2rcb_tag = tag;
wire tcb2tlb_tld = tag_ld | ~rst_l;
// vtb tag select, valid, write address and enable
wire tcb2vtb_vld = nxt_vld;
wire tcb2vtb_we = tag_we;
// tdc cache load and tag
assign tcc2tdc_tag = tag;
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
assign tcc2tmc_dbg = {state, vld, tcm, req, hit};
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
always @ (posedge clk) begin
always @ (posedge clk) begin
endmodule // dmu_mmu_tcb_tcc