// ========== Copyright Header Begin ==========================================
// OpenSPARC T2 Processor File: dmu_imu_ors.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 ============================================
// Inputs from SCS sub-block
// Inputs from EQS sub-block
//############################################################################
//############################################################################
//------------------------------------------------------------------------
// Clock and Reset Signals
//------------------------------------------------------------------------
//------------------------------------------------------------------------
// Inputs to Out Record Sub-block
//------------------------------------------------------------------------
input [`FIRE_DLC_IOT_REC_WDTH-1:0] scs2ors_rcd;
input [`FIRE_DLC_IOT_ADDR_WDTH-1:0] eqs2ors_eq_addr;
//------------------------------------------------------------------------
//------------------------------------------------------------------------
output [`FIRE_DLC_IOT_REC_WDTH-1:0] im2rm_rcd;
//------------------------------------------------------------------------
//------------------------------------------------------------------------
input [2:0] dbg2ors_dbg_sel_a;
input [2:0] dbg2ors_dbg_sel_b;
output [`FIRE_DEBUG_WDTH-1:0] ors2dbg_dbg_a;
output [`FIRE_DEBUG_WDTH-1:0] ors2dbg_dbg_b;
//------------------------------------------------------------------------
//------------------------------------------------------------------------
output ors2ics_perf_eq_mondos;
output ors2ics_perf_mondos;
output ors2ics_perf_eq_wr;
//------------------------------------------------------------------------
//------------------------------------------------------------------------
//------------------------------------------------------------------------
//------------------------------------------------------------------------
//############################################################################
//############################################################################
//############################################################################
//############################################################################
//**************************************************
//**************************************************
//--------------------------
//--------------------------
wire [`FIRE_DLC_IOT_TYPE_WDTH-1:0] in_type;
wire [`FIRE_DLC_IOT_ADDR_WDTH-1:0] in_address;
//-------------------------------------
// Signal to look at EQ lookup results
//-------------------------------------
wire [`FIRE_DLC_IOT_ADDR_WDTH-1:0] out_address;
wire [`FIRE_DLC_IOT_TYPE_WDTH-1:0] out_type;
//**************************************************
// Registers that Are Not Flops
//**************************************************
//**************************************************
// Registers that Are Flops
//**************************************************
reg [`FIRE_DEBUG_WDTH-1:0] n_dbg_a;
reg [`FIRE_DEBUG_WDTH-1:0] n_dbg_b;
//-------------------------------------
//-------------------------------------
reg [`FIRE_DLC_IOT_REC_WDTH-1:0] im2rm_rcd;
reg [`FIRE_DEBUG_WDTH-1:0] dbg_a;
reg [`FIRE_DEBUG_WDTH-1:0] dbg_b;
//############################################################################
//############################################################################
// Need to make sure that EQS and SCS think record is an MSI or Message
//0in assert_together -leader scs_addr_insert -follower eqs_addr_insert -active (scs_addr_insert & scs2ors_rcd_sel)
//Check Address format comming from EQS
//----------------------------------------
// 63:19 - Base address - 61:17
// 12:6 - Tail pointer for EQ - 10:4
// 5:2 - All zero's - 3:0
//----------------------------------------
//0in maximum -var eqs2ors_eq_addr[16:11] -val 35
//############################################################################
//############################################################################
//--------------------------------
// Grab the Incomming Packet Type
//--------------------------------
assign in_type = scs2ors_rcd[`FIRE_DLC_IOT_TYPE_MSB:`FIRE_DLC_IOT_TYPE_LSB];
//----------------------------------
//Grab the Incomming Packet Address
//----------------------------------
assign in_address = scs2ors_rcd[`FIRE_DLC_IOT_ADDR_MSB:`FIRE_DLC_IOT_ADDR_LSB];
//**************************************************
//**************************************************
//--------------------------------
// Check to See if the packet is
//--------------------------------
assign pkt_is_msi = in_type[`FIRE_DLC_IMU_OTYPE_DECODE_2] &
!in_type[`FIRE_DLC_IMU_OTYPE_DECODE_1] &
!in_type[`FIRE_DLC_IMU_OTYPE_DECODE_0];
assign pkt_is_mes = !in_type[`FIRE_DLC_IMU_OTYPE_DECODE_2];
assign scs_addr_insert= pkt_is_msi | pkt_is_mes;
//--------------------------------
// Check to See if the EQS thinks
// an address should be inserted
//--------------------------------
assign eqs_addr_insert = eqs2ors_sel;
//--------------------------------
// Check to See if they both agree
// an address should be inserted
//--------------------------------
assign addr_insert = eqs_addr_insert & scs_addr_insert;
//--------------------------------
// Check to see if address is needed
// - if yes insert new addr
// - if no use old address
//--------------------------------
// if sun4v mode & eqs_ors_addr[61]=1 & addr_insert force addr[61] to 1 or if
// in sun4v mode and eqs_ors_addr[61] =0, the use the in_address[61] instead of the eqs2ors_eq_addr[61]
// thus use the pipeline value going to devtsb of bit 61 because this bit and the bus number
// are used in the devtsb lookup
//assign out_address = addr_insert ? eqs2ors_eq_addr : in_address;
assign out_address[61] = (
(csr_sun4v_en & addr_insert & pkt_is_mes) ? {1'b1} :
(csr_sun4v_en & addr_insert & pkt_is_msi & (eqs2ors_eq_addr[61]==1'b1)) ?
( (csr_sun4v_en & addr_insert & pkt_is_msi & (eqs2ors_eq_addr[61]==1'b0)) ?
(addr_insert ? eqs2ors_eq_addr[61] : in_address[61]) )
assign out_address[60:0] = (csr_sun4v_en & addr_insert & pkt_is_mes) ? {24'hfff800,eqs2ors_eq_addr[36:0]} :
addr_insert ? eqs2ors_eq_addr[60:0] : in_address[60:0]
//**************************************************
//*************************************************
//--------------------------------
// Use the upper bit of the EQ address
// to check if it is bypass mode or
// not. If set it is in by pass mode
// and need to be set to a 1.
// This chose 64 bit over 32 bit mode
//--------------------------------
assign out_addr_mode = eqs2ors_eq_addr[`FIRE_DLC_IOT_ADDR_WDTH-1];
assign out_type = addr_insert ? {in_type[6],out_addr_mode,in_type[4:0]} : in_type;
//-----------------------------------------------------
//-----------------------------------------------------
always @ (dbg2ors_dbg_sel_a or im2rm_rcd_enq or im2rm_rcd or scs2ors_rcd_sel or in_type or
pkt_is_msi or pkt_is_mes or scs_addr_insert or eqs_addr_insert or addr_insert)
case (dbg2ors_dbg_sel_a) // synopsys infer_mux
3'b000: n_dbg_a = {im2rm_rcd_enq, im2rm_rcd[`FIRE_DLC_IOT_TYPE_MSB:`FIRE_DLC_IOT_TYPE_LSB]};
3'b001: n_dbg_a = {scs2ors_rcd_sel, in_type[6:0]};
3'b010: n_dbg_a = {3'h0, pkt_is_msi, pkt_is_mes, scs_addr_insert, eqs_addr_insert, addr_insert};
always @ (dbg2ors_dbg_sel_b or im2rm_rcd_enq or im2rm_rcd or scs2ors_rcd_sel or in_type or
pkt_is_msi or pkt_is_mes or scs_addr_insert or eqs_addr_insert or addr_insert)
case (dbg2ors_dbg_sel_b) // synopsys infer_mux
3'b000: n_dbg_b = {im2rm_rcd_enq, im2rm_rcd[`FIRE_DLC_IOT_TYPE_MSB:`FIRE_DLC_IOT_TYPE_LSB]};
3'b001: n_dbg_b = {scs2ors_rcd_sel, in_type[6:0]};
3'b010: n_dbg_b = {3'h0, pkt_is_msi, pkt_is_mes, scs_addr_insert, eqs_addr_insert, addr_insert};
assign ors2dbg_dbg_a = dbg_a;
assign ors2dbg_dbg_b = dbg_b;
//-----------------------------------------------------
//-----------------------------------------------------
assign is_mondo_eq = (scs2ors_rcd[`FIRE_DLC_IOT_REQID_MSB-3:`FIRE_DLC_IOT_REQID_LSB+7] < 6'd60) &
(scs2ors_rcd[`FIRE_DLC_IOT_REQID_MSB-3:`FIRE_DLC_IOT_REQID_LSB+7] > 6'd23);
assign ors2ics_perf_eq_mondos = is_mondo_eq & out_type[`FIRE_DLC_IMU_OTYPE_DECODE_0] & scs2ors_rcd_sel;
assign ors2ics_perf_mondos = out_type[`FIRE_DLC_IMU_OTYPE_DECODE_0] & scs2ors_rcd_sel;
assign ors2ics_perf_msi = pkt_is_msi & scs2ors_rcd_sel;
assign ors2ics_perf_eq_wr = (pkt_is_msi | pkt_is_mes) & scs2ors_rcd_sel;
//------------------------------------------------------------------------
//------------------------------------------------------------------------
assign ors2dbg_idle = ~scs2ors_rcd_sel & ~im2rm_rcd_enq;
//############################################################################
//############################################################################
//-----------------------------------------------------------------------------
// Delay all of the In Record infomrtaion to keep in step with the pipeline.
//-----------------------------------------------------------------------------
begin // At reset reset all of them to zero.
im2rm_rcd <= {`FIRE_DLC_IOT_REC_WDTH{1'h0}};
im2rm_rcd <= {out_type,scs2ors_rcd[`FIRE_DLC_IOT_TC_MSB:`FIRE_DLC_IOT_DATA_LSB], out_address, scs2ors_rcd[`FIRE_DLC_IOT_DPTR_MSB:0]};
im2rm_rcd_enq <= scs2ors_rcd_sel;