// ========== Copyright Header Begin ==========================================
// OpenSPARC T2 Processor File: dmu_imu_gcs_gc_fsm.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 ============================================
module dmu_imu_gcs_gc_fsm (
// Interface for Arbiter and Incomming Mondo Requests
// Interface for Group Controller Arbiter
// Interface for Mondo Reply Status
// Interface for Interrupt Retry Timer
// Interface for Static Value for group controller 0-3
//############################################################################
//############################################################################
//------------------------------------------------------------------------
// Clock and Reset Signals
//------------------------------------------------------------------------
//-----------------------------------------------------
// Interface for Arbiter and Incomming Mondo Requests
//-----------------------------------------------------
input [63:0] int_req_vec; //Incomming Mondo Requests for 64 to 1
input [63:0] int_winner_vec; //Incomming Mondo winner from local 64 to 1 mondo arbiter
output update_winner; //Last mondo winner, serves as input into local mondo arbiter
//-----------------------------------------------------
// Interface for Group Controller Arbiter
//-----------------------------------------------------
output gcs_req; // Request to group controller arbiter
output [5:0] gcs_ino; // INO for requesting mondo
input gcs_gnt; // Acknowldge for Request signal
//-----------------------------------------------------
// Interface for Mondo Reply Status
//-----------------------------------------------------
input rss2gcs_rply; // Reply type from RSS ack =1 nack =0
input [1:0] rss2gcs_id; // Group controller ID for response
input rss2gcs_valid; // Valid signal to validate respose
//-----------------------------------------------------
// Interface for Interrupt Retry Timer
//-----------------------------------------------------
output timer_start; // Signal to start retry timer
input timer_done; // SIgnal showing the retry timer is done
//-----------------------------------------------------
// Interface for Static Value for group controller 0-3
//-----------------------------------------------------
input [1:0] static_gc_id; // Id for group controller
//-----------------------------------------------------
//-----------------------------------------------------
output [`FIRE_DEBUG_WDTH-1:0] fsm_dbg;
//############################################################################
//############################################################################
parameter ARB_REQ = 2'b01;
parameter W_4_REPLY = 2'b10;
//############################################################################
//############################################################################
//------------------------
//------------------------
//-------------------------
// Regs that are NOT flops
//-------------------------
//------------------------
//------------------------
//############################################################################
//############################################################################
//---------------------------------------------------------------------
// REQ / ACK Interface Checkers
//---------------------------------------------------------------------
//0in req_ack -req gcs_req -ack gcs_gnt -req_until_ack -new_req_after_ack -max_ack 1
//---------------------------------------------------------------------
// Known and Constant Checkers
//---------------------------------------------------------------------
//0in known_driven -var gcs_ino -active gcs_req
//0in constant -var gcs_ino -active gcs_req
//---------------------------------------------------------------------
// State Machine Checkers
//---------------------------------------------------------------------
//0in state_transition -var state -val IDLE -next ARB_REQ
//0in state_transition -var state -val ARB_REQ -next W_4_REPLY
//0in state_transition -var state -val W_4_REPLY -next ARB_REQ RETRY IDLE
//0in state_transition -var state -val RETRY -next ARB_REQ
//############################################################################
//############################################################################
//----------------------------------------------------------------------
// This function takes as an input a 64 bit vector with one bit set to
// 1 and encodes the bit number into a 6 bit binary number
// For Example on a 8 bit vector
// Last interrupt vector = 00001000
//-----------------------------------------------------------------------
for (i=7'd0; i<=7'd63; i=i+7'd1)
if (vec[i[5:0]]) enc_vec = i[5:0];
//$display($time,": Ecoded value for vec = %0b is %0b\n",vec, enc_vec);
//############################################################################
//############################################################################
//-------------------------------------------------------------------------
// We have a transaction which needs to be done
//-------------------------------------------------------------------------
assign mondo_needed = |int_req_vec;
//-------------------------------------------------------------------------
// Decode reply status bus to detrmin if we have received and ACK or NACK
//-------------------------------------------------------------------------
assign mondo_ack = rss2gcs_valid & rss2gcs_rply & (static_gc_id == rss2gcs_id);
assign mondo_nack = rss2gcs_valid & ~rss2gcs_rply & (static_gc_id == rss2gcs_id);
//-------------------------------------------------------------------------
// Assign the output values
//-------------------------------------------------------------------------
assign gcs_req = (state == ARB_REQ); // Only doing a request to gc arbiter in the ARB_REQ state
assign gcs_ino = encode(int_winner_vec); // Take last winner and encode to 6 bit value
//-------------------------------------------------------------------------
// Start the Timer on NACKS
//-------------------------------------------------------------------------
assign timer_start = (state == W_4_REPLY) & mondo_nack; // Only start counter when get a Nack
assign update_winner = ((state == IDLE) & (mondo_needed)) |
((state == W_4_REPLY) & (mondo_needed) & mondo_ack);
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
assign fsm_dbg = {state[1:0], mondo_ack, mondo_nack, timer_done, gcs_req, gcs_gnt, mondo_needed};
//##########################################################################
//############################################################################
//-----------------------------------------------------------------------
// Next State Logic, Assign nest state to current state
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
always @(state or mondo_needed or gcs_gnt or mondo_ack or mondo_nack or timer_done )
case (state) // synopsys parallel_case full_case
//********************************************************
// - Wait here until the arbiter has a mondo which needs
// - Do not update the last winner
// -If it has a mondo which needs servicing use the arb
// winner as the one to req for
// - Update the last winner
//********************************************************
if (mondo_needed) // If there is at least one interrupt thats needs servicing
else // If there is no interrupts that needs servicing
//********************************************************
// - Wait here until the req gets a grant from the gc arb
// - Do not update the last winner
//********************************************************
if (gcs_gnt) // If get granted by main 4 to 1 arbiter go to W_4_REPLY
n_state = ARB_REQ; // If still not granted wait here
//********************************************************
// - Wait here until we get a response from the CPU
// - see if we have any more reqs waiting
// - if yes ARB again and update last winner
// - if no go to IDLE, no update
// - If we get a nack we need to retry
//********************************************************
if (mondo_ack) // if get ACK back from CPU check if more are waiting
if (mondo_needed) // ACK and more waiting
else // ACK and no more waiting
else if (mondo_nack) // if get NACK back from CPU
//********************************************************
// - Wait here until the timer expires
// - Do not update the last winner
// - Need to send this one again
//********************************************************
if (timer_done) // If get timer done
n_state = RETRY; // If still no timer response wait here