114184Sgabeblack@google.com/*
214184Sgabeblack@google.com * Copyright (c) 2011-2015 Advanced Micro Devices, Inc.
314184Sgabeblack@google.com * All rights reserved.
414184Sgabeblack@google.com *
514184Sgabeblack@google.com * For use for simulation and test purposes only
614184Sgabeblack@google.com *
714184Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
814184Sgabeblack@google.com * modification, are permitted provided that the following conditions are met:
914184Sgabeblack@google.com *
1014184Sgabeblack@google.com * 1. Redistributions of source code must retain the above copyright notice,
1114184Sgabeblack@google.com * this list of conditions and the following disclaimer.
1214184Sgabeblack@google.com *
1314184Sgabeblack@google.com * 2. Redistributions in binary form must reproduce the above copyright notice,
1414184Sgabeblack@google.com * this list of conditions and the following disclaimer in the documentation
1514184Sgabeblack@google.com * and/or other materials provided with the distribution.
1614184Sgabeblack@google.com *
1714184Sgabeblack@google.com * 3. Neither the name of the copyright holder nor the names of its
1814184Sgabeblack@google.com * contributors may be used to endorse or promote products derived from this
1914184Sgabeblack@google.com * software without specific prior written permission.
2014184Sgabeblack@google.com *
2114184Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2214184Sgabeblack@google.com * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2314184Sgabeblack@google.com * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2414184Sgabeblack@google.com * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
2514184Sgabeblack@google.com * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2614184Sgabeblack@google.com * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2714184Sgabeblack@google.com * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2814184Sgabeblack@google.com * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2914184Sgabeblack@google.com * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3014184Sgabeblack@google.com * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3114184Sgabeblack@google.com * POSSIBILITY OF SUCH DAMAGE.
3214184Sgabeblack@google.com *
3314184Sgabeblack@google.com * Authors: Lisa Hsu
3414184Sgabeblack@google.com */
3514184Sgabeblack@google.com
3614184Sgabeblack@google.commachine(MachineType:SQC, "GPU SQC (L1 I Cache)")
3714184Sgabeblack@google.com : Sequencer* sequencer;
3814184Sgabeblack@google.com   CacheMemory * L1cache;
3914184Sgabeblack@google.com   int TCC_select_num_bits;
4014184Sgabeblack@google.com   Cycles issue_latency := 80;  // time to send data down to TCC
4114184Sgabeblack@google.com   Cycles l2_hit_latency := 18;
4214184Sgabeblack@google.com
4314184Sgabeblack@google.com  MessageBuffer * requestFromSQC, network="To", virtual_network="1", vnet_type="request";
4414184Sgabeblack@google.com  MessageBuffer * responseFromSQC, network="To", virtual_network="3", vnet_type="response";
4514184Sgabeblack@google.com  MessageBuffer * unblockFromCore, network="To", virtual_network="5", vnet_type="unblock";
4614184Sgabeblack@google.com
4714184Sgabeblack@google.com  MessageBuffer * probeToSQC, network="From", virtual_network="1", vnet_type="request";
4814184Sgabeblack@google.com  MessageBuffer * responseToSQC, network="From", virtual_network="3", vnet_type="response";
4914184Sgabeblack@google.com
5014184Sgabeblack@google.com  MessageBuffer * mandatoryQueue;
5114184Sgabeblack@google.com{
5214184Sgabeblack@google.com  state_declaration(State, desc="SQC Cache States", default="SQC_State_I") {
5314184Sgabeblack@google.com    I, AccessPermission:Invalid, desc="Invalid";
5414184Sgabeblack@google.com    S, AccessPermission:Read_Only, desc="Shared";
5514184Sgabeblack@google.com
5614184Sgabeblack@google.com    I_S, AccessPermission:Busy, desc="Invalid, issued RdBlkS, have not seen response yet";
5714184Sgabeblack@google.com    S_I, AccessPermission:Read_Only, desc="L1 replacement, waiting for clean WB ack";
5814184Sgabeblack@google.com    I_C, AccessPermission:Invalid, desc="Invalid, waiting for WBAck from TCCdir for canceled WB";
5914184Sgabeblack@google.com  }
6014184Sgabeblack@google.com
6114184Sgabeblack@google.com  enumeration(Event, desc="SQC Events") {
6214184Sgabeblack@google.com    // Core initiated
6314184Sgabeblack@google.com    Fetch,          desc="Fetch";
6414184Sgabeblack@google.com
6514184Sgabeblack@google.com    //TCC initiated
6614184Sgabeblack@google.com    TCC_AckS,        desc="TCC Ack to Core Request";
6714184Sgabeblack@google.com    TCC_AckWB,       desc="TCC Ack for WB";
6814184Sgabeblack@google.com    TCC_NackWB,       desc="TCC Nack for WB";
6914184Sgabeblack@google.com
7014184Sgabeblack@google.com    // Mem sys initiated
7114184Sgabeblack@google.com    Repl,           desc="Replacing block from cache";
7214184Sgabeblack@google.com
7314184Sgabeblack@google.com    // Probe Events
7414184Sgabeblack@google.com    PrbInvData,         desc="probe, return M data";
7514184Sgabeblack@google.com    PrbInv,             desc="probe, no need for data";
7614184Sgabeblack@google.com    PrbShrData,         desc="probe downgrade, return data";
7714184Sgabeblack@google.com  }
7814184Sgabeblack@google.com
7914184Sgabeblack@google.com  enumeration(RequestType, desc="To communicate stats from transitions to recordStats") {
8014184Sgabeblack@google.com    DataArrayRead,    desc="Read the data array";
8114184Sgabeblack@google.com    DataArrayWrite,   desc="Write the data array";
8214184Sgabeblack@google.com    TagArrayRead,     desc="Read the data array";
8314184Sgabeblack@google.com    TagArrayWrite,    desc="Write the data array";
8414184Sgabeblack@google.com  }
8514184Sgabeblack@google.com
8614184Sgabeblack@google.com
8714184Sgabeblack@google.com  structure(Entry, desc="...", interface="AbstractCacheEntry") {
8814184Sgabeblack@google.com    State CacheState,           desc="cache state";
8914184Sgabeblack@google.com    bool Dirty,                 desc="Is the data dirty (diff than memory)?";
9014184Sgabeblack@google.com    DataBlock DataBlk,          desc="data for the block";
9114184Sgabeblack@google.com    bool FromL2, default="false", desc="block just moved from L2";
9214184Sgabeblack@google.com  }
9314184Sgabeblack@google.com
9414184Sgabeblack@google.com  structure(TBE, desc="...") {
9514184Sgabeblack@google.com    State TBEState,             desc="Transient state";
9614184Sgabeblack@google.com    DataBlock DataBlk,       desc="data for the block, required for concurrent writebacks";
9714184Sgabeblack@google.com    bool Dirty,              desc="Is the data dirty (different than memory)?";
9814184Sgabeblack@google.com    int NumPendingMsgs,      desc="Number of acks/data messages that this processor is waiting for";
9914184Sgabeblack@google.com    bool Shared,             desc="Victim hit by shared probe";
10014184Sgabeblack@google.com   }
10114184Sgabeblack@google.com
10214184Sgabeblack@google.com  structure(TBETable, external="yes") {
10314184Sgabeblack@google.com    TBE lookup(Addr);
10414184Sgabeblack@google.com    void allocate(Addr);
10514184Sgabeblack@google.com    void deallocate(Addr);
10614184Sgabeblack@google.com    bool isPresent(Addr);
10714184Sgabeblack@google.com  }
10814184Sgabeblack@google.com
10914184Sgabeblack@google.com  TBETable TBEs, template="<SQC_TBE>", constructor="m_number_of_TBEs";
11014184Sgabeblack@google.com  int TCC_select_low_bit, default="RubySystem::getBlockSizeBits()";
11114184Sgabeblack@google.com
11214184Sgabeblack@google.com  Tick clockEdge();
11314184Sgabeblack@google.com  Tick cyclesToTicks(Cycles c);
11414184Sgabeblack@google.com
11514184Sgabeblack@google.com  void set_cache_entry(AbstractCacheEntry b);
11614184Sgabeblack@google.com  void unset_cache_entry();
11714184Sgabeblack@google.com  void set_tbe(TBE b);
11814184Sgabeblack@google.com  void unset_tbe();
11914184Sgabeblack@google.com  void wakeUpAllBuffers();
12014184Sgabeblack@google.com  void wakeUpBuffers(Addr a);
12114184Sgabeblack@google.com  Cycles curCycle();
12214184Sgabeblack@google.com
12314184Sgabeblack@google.com  // Internal functions
12414184Sgabeblack@google.com  Entry getCacheEntry(Addr address), return_by_pointer="yes" {
12514184Sgabeblack@google.com    Entry cache_entry := static_cast(Entry, "pointer", L1cache.lookup(address));
12614184Sgabeblack@google.com    return cache_entry;
12714184Sgabeblack@google.com  }
12814184Sgabeblack@google.com
12914184Sgabeblack@google.com  DataBlock getDataBlock(Addr addr), return_by_ref="yes" {
13014184Sgabeblack@google.com    TBE tbe := TBEs.lookup(addr);
13114184Sgabeblack@google.com    if(is_valid(tbe)) {
13214184Sgabeblack@google.com      return tbe.DataBlk;
13314184Sgabeblack@google.com    } else {
13414184Sgabeblack@google.com      return getCacheEntry(addr).DataBlk;
13514184Sgabeblack@google.com    }
13614184Sgabeblack@google.com  }
13714184Sgabeblack@google.com
13814184Sgabeblack@google.com  State getState(TBE tbe, Entry cache_entry, Addr addr) {
13914184Sgabeblack@google.com    if(is_valid(tbe)) {
14014184Sgabeblack@google.com      return tbe.TBEState;
14114184Sgabeblack@google.com    } else if (is_valid(cache_entry)) {
14214184Sgabeblack@google.com      return cache_entry.CacheState;
14314184Sgabeblack@google.com    }
14414184Sgabeblack@google.com    return State:I;
14514184Sgabeblack@google.com  }
14614184Sgabeblack@google.com
14714184Sgabeblack@google.com  void setState(TBE tbe, Entry cache_entry, Addr addr, State state) {
14814184Sgabeblack@google.com    if (is_valid(tbe)) {
14914184Sgabeblack@google.com      tbe.TBEState := state;
15014184Sgabeblack@google.com    }
15114184Sgabeblack@google.com
15214184Sgabeblack@google.com    if (is_valid(cache_entry)) {
15314184Sgabeblack@google.com      cache_entry.CacheState := state;
15414184Sgabeblack@google.com    }
15514184Sgabeblack@google.com  }
15614184Sgabeblack@google.com
15714184Sgabeblack@google.com  AccessPermission getAccessPermission(Addr addr) {
15814184Sgabeblack@google.com    TBE tbe := TBEs.lookup(addr);
15914184Sgabeblack@google.com    if(is_valid(tbe)) {
16014184Sgabeblack@google.com      return SQC_State_to_permission(tbe.TBEState);
16114184Sgabeblack@google.com    }
16214184Sgabeblack@google.com
16314184Sgabeblack@google.com    Entry cache_entry := getCacheEntry(addr);
16414184Sgabeblack@google.com    if(is_valid(cache_entry)) {
16514184Sgabeblack@google.com      return SQC_State_to_permission(cache_entry.CacheState);
16614184Sgabeblack@google.com    }
16714184Sgabeblack@google.com
16814184Sgabeblack@google.com    return AccessPermission:NotPresent;
16914184Sgabeblack@google.com  }
17014184Sgabeblack@google.com
17114184Sgabeblack@google.com  void setAccessPermission(Entry cache_entry, Addr addr, State state) {
17214184Sgabeblack@google.com    if (is_valid(cache_entry)) {
17314184Sgabeblack@google.com      cache_entry.changePermission(SQC_State_to_permission(state));
17414184Sgabeblack@google.com    }
17514184Sgabeblack@google.com  }
17614184Sgabeblack@google.com
17714184Sgabeblack@google.com  void functionalRead(Addr addr, Packet *pkt) {
17814184Sgabeblack@google.com    TBE tbe := TBEs.lookup(addr);
17914184Sgabeblack@google.com    if(is_valid(tbe)) {
18014184Sgabeblack@google.com      testAndRead(addr, tbe.DataBlk, pkt);
18114184Sgabeblack@google.com    } else {
18214184Sgabeblack@google.com      functionalMemoryRead(pkt);
18314184Sgabeblack@google.com    }
18414184Sgabeblack@google.com  }
18514184Sgabeblack@google.com
18614184Sgabeblack@google.com  int functionalWrite(Addr addr, Packet *pkt) {
18714184Sgabeblack@google.com    int num_functional_writes := 0;
18814184Sgabeblack@google.com
18914184Sgabeblack@google.com    TBE tbe := TBEs.lookup(addr);
19014184Sgabeblack@google.com    if(is_valid(tbe)) {
19114184Sgabeblack@google.com      num_functional_writes := num_functional_writes +
19214184Sgabeblack@google.com            testAndWrite(addr, tbe.DataBlk, pkt);
19314184Sgabeblack@google.com    }
19414184Sgabeblack@google.com
19514184Sgabeblack@google.com    num_functional_writes := num_functional_writes + functionalMemoryWrite(pkt);
19614184Sgabeblack@google.com    return num_functional_writes;
19714184Sgabeblack@google.com  }
19814184Sgabeblack@google.com
19914184Sgabeblack@google.com  void recordRequestType(RequestType request_type, Addr addr) {
20014184Sgabeblack@google.com    if (request_type == RequestType:DataArrayRead) {
20114184Sgabeblack@google.com        L1cache.recordRequestType(CacheRequestType:DataArrayRead, addr);
20214184Sgabeblack@google.com    } else if (request_type == RequestType:DataArrayWrite) {
20314184Sgabeblack@google.com        L1cache.recordRequestType(CacheRequestType:DataArrayWrite, addr);
20414184Sgabeblack@google.com    } else if (request_type == RequestType:TagArrayRead) {
20514184Sgabeblack@google.com        L1cache.recordRequestType(CacheRequestType:TagArrayRead, addr);
20614184Sgabeblack@google.com    } else if (request_type == RequestType:TagArrayWrite) {
20714184Sgabeblack@google.com        L1cache.recordRequestType(CacheRequestType:TagArrayWrite, addr);
20814184Sgabeblack@google.com    }
20914184Sgabeblack@google.com  }
21014184Sgabeblack@google.com
21114184Sgabeblack@google.com  bool checkResourceAvailable(RequestType request_type, Addr addr) {
21214184Sgabeblack@google.com    if (request_type == RequestType:DataArrayRead) {
21314184Sgabeblack@google.com      return L1cache.checkResourceAvailable(CacheResourceType:DataArray, addr);
21414184Sgabeblack@google.com    } else if (request_type == RequestType:DataArrayWrite) {
21514184Sgabeblack@google.com      return L1cache.checkResourceAvailable(CacheResourceType:DataArray, addr);
21614184Sgabeblack@google.com    } else if (request_type == RequestType:TagArrayRead) {
21714184Sgabeblack@google.com      return L1cache.checkResourceAvailable(CacheResourceType:TagArray, addr);
21814184Sgabeblack@google.com    } else if (request_type == RequestType:TagArrayWrite) {
21914184Sgabeblack@google.com      return L1cache.checkResourceAvailable(CacheResourceType:TagArray, addr);
22014184Sgabeblack@google.com    } else {
22114184Sgabeblack@google.com      error("Invalid RequestType type in checkResourceAvailable");
22214184Sgabeblack@google.com      return true;
22314184Sgabeblack@google.com    }
22414184Sgabeblack@google.com  }
22514184Sgabeblack@google.com
22614184Sgabeblack@google.com  // Out Ports
22714184Sgabeblack@google.com
22814184Sgabeblack@google.com  out_port(requestNetwork_out, CPURequestMsg, requestFromSQC);
22914184Sgabeblack@google.com  out_port(responseNetwork_out, ResponseMsg, responseFromSQC);
23014184Sgabeblack@google.com  out_port(unblockNetwork_out, UnblockMsg, unblockFromCore);
23114184Sgabeblack@google.com
23214184Sgabeblack@google.com  // In Ports
23314184Sgabeblack@google.com
23414184Sgabeblack@google.com  in_port(probeNetwork_in, TDProbeRequestMsg, probeToSQC) {
23514184Sgabeblack@google.com    if (probeNetwork_in.isReady(clockEdge())) {
23614184Sgabeblack@google.com      peek(probeNetwork_in, TDProbeRequestMsg, block_on="addr") {
23714184Sgabeblack@google.com        Entry cache_entry := getCacheEntry(in_msg.addr);
23814184Sgabeblack@google.com        TBE tbe := TBEs.lookup(in_msg.addr);
23914184Sgabeblack@google.com
24014184Sgabeblack@google.com        if (in_msg.Type == ProbeRequestType:PrbInv) {
24114184Sgabeblack@google.com          if (in_msg.ReturnData) {
24214184Sgabeblack@google.com            trigger(Event:PrbInvData, in_msg.addr, cache_entry, tbe);
24314184Sgabeblack@google.com          } else {
24414184Sgabeblack@google.com            trigger(Event:PrbInv, in_msg.addr, cache_entry, tbe);
24514184Sgabeblack@google.com          }
24614184Sgabeblack@google.com        } else if (in_msg.Type == ProbeRequestType:PrbDowngrade) {
24714184Sgabeblack@google.com          assert(in_msg.ReturnData);
24814184Sgabeblack@google.com          trigger(Event:PrbShrData, in_msg.addr, cache_entry, tbe);
24914184Sgabeblack@google.com        }
25014184Sgabeblack@google.com      }
25114184Sgabeblack@google.com    }
25214184Sgabeblack@google.com  }
25314184Sgabeblack@google.com
25414184Sgabeblack@google.com  in_port(responseToSQC_in, ResponseMsg, responseToSQC) {
25514184Sgabeblack@google.com    if (responseToSQC_in.isReady(clockEdge())) {
25614184Sgabeblack@google.com      peek(responseToSQC_in, ResponseMsg, block_on="addr") {
25714184Sgabeblack@google.com
25814184Sgabeblack@google.com        Entry cache_entry := getCacheEntry(in_msg.addr);
25914184Sgabeblack@google.com        TBE tbe := TBEs.lookup(in_msg.addr);
26014184Sgabeblack@google.com
26114184Sgabeblack@google.com        if (in_msg.Type == CoherenceResponseType:TDSysResp) {
26214184Sgabeblack@google.com          if (in_msg.State == CoherenceState:Shared) {
26314184Sgabeblack@google.com            trigger(Event:TCC_AckS, in_msg.addr, cache_entry, tbe);
26414184Sgabeblack@google.com          } else {
26514184Sgabeblack@google.com            error("SQC should not receive TDSysResp other than CoherenceState:Shared");
26614184Sgabeblack@google.com          }
26714184Sgabeblack@google.com        } else if (in_msg.Type == CoherenceResponseType:TDSysWBAck) {
26814184Sgabeblack@google.com          trigger(Event:TCC_AckWB, in_msg.addr, cache_entry, tbe);
26914184Sgabeblack@google.com        } else if (in_msg.Type == CoherenceResponseType:TDSysWBNack) {
27014184Sgabeblack@google.com          trigger(Event:TCC_NackWB, in_msg.addr, cache_entry, tbe);
27114184Sgabeblack@google.com        } else {
27214184Sgabeblack@google.com          error("Unexpected Response Message to Core");
27314184Sgabeblack@google.com        }
27414184Sgabeblack@google.com      }
27514184Sgabeblack@google.com    }
27614184Sgabeblack@google.com  }
27714184Sgabeblack@google.com
27814184Sgabeblack@google.com  in_port(mandatoryQueue_in, RubyRequest, mandatoryQueue, desc="...") {
27914184Sgabeblack@google.com    if (mandatoryQueue_in.isReady(clockEdge())) {
28014184Sgabeblack@google.com      peek(mandatoryQueue_in, RubyRequest, block_on="LineAddress") {
28114184Sgabeblack@google.com        Entry cache_entry := getCacheEntry(in_msg.LineAddress);
28214184Sgabeblack@google.com        TBE tbe := TBEs.lookup(in_msg.LineAddress);
28314184Sgabeblack@google.com
28414184Sgabeblack@google.com        assert(in_msg.Type == RubyRequestType:IFETCH);
28514184Sgabeblack@google.com        if (is_valid(cache_entry) || L1cache.cacheAvail(in_msg.LineAddress)) {
28614184Sgabeblack@google.com          trigger(Event:Fetch, in_msg.LineAddress, cache_entry, tbe);
28714184Sgabeblack@google.com        } else {
28814184Sgabeblack@google.com          Addr victim := L1cache.cacheProbe(in_msg.LineAddress);
28914184Sgabeblack@google.com          trigger(Event:Repl, victim, getCacheEntry(victim), TBEs.lookup(victim));
29014184Sgabeblack@google.com        }
29114184Sgabeblack@google.com      }
29214184Sgabeblack@google.com    }
29314184Sgabeblack@google.com  }
29414184Sgabeblack@google.com
29514184Sgabeblack@google.com  // Actions
29614184Sgabeblack@google.com
29714184Sgabeblack@google.com  action(ic_invCache, "ic", desc="invalidate cache") {
29814184Sgabeblack@google.com    if(is_valid(cache_entry)) {
29914184Sgabeblack@google.com      L1cache.deallocate(address);
30014184Sgabeblack@google.com    }
30114184Sgabeblack@google.com    unset_cache_entry();
30214184Sgabeblack@google.com  }
30314184Sgabeblack@google.com
30414184Sgabeblack@google.com  action(nS_issueRdBlkS, "nS", desc="Issue RdBlkS") {
30514184Sgabeblack@google.com    enqueue(requestNetwork_out, CPURequestMsg, issue_latency) {
30614184Sgabeblack@google.com      out_msg.addr := address;
30714184Sgabeblack@google.com      out_msg.Type := CoherenceRequestType:RdBlkS;
30814184Sgabeblack@google.com      out_msg.Requestor := machineID;
30914184Sgabeblack@google.com      out_msg.Destination.add(mapAddressToRange(address,MachineType:TCCdir,
31014184Sgabeblack@google.com                              TCC_select_low_bit, TCC_select_num_bits));
31114184Sgabeblack@google.com      out_msg.MessageSize := MessageSizeType:Request_Control;
31214184Sgabeblack@google.com      out_msg.InitialRequestTime := curCycle();
31314184Sgabeblack@google.com    }
31414184Sgabeblack@google.com  }
31514184Sgabeblack@google.com
31614184Sgabeblack@google.com  action(vc_victim, "vc", desc="Victimize E/S Data") {
31714184Sgabeblack@google.com    enqueue(requestNetwork_out, CPURequestMsg, issue_latency) {
31814184Sgabeblack@google.com      out_msg.addr := address;
31914184Sgabeblack@google.com      out_msg.Requestor := machineID;
32014184Sgabeblack@google.com      out_msg.Destination.add(mapAddressToRange(address,MachineType:TCCdir,
32114184Sgabeblack@google.com                              TCC_select_low_bit, TCC_select_num_bits));
32214184Sgabeblack@google.com      out_msg.MessageSize := MessageSizeType:Request_Control;
32314184Sgabeblack@google.com      out_msg.Type := CoherenceRequestType:VicClean;
32414184Sgabeblack@google.com      out_msg.InitialRequestTime := curCycle();
32514184Sgabeblack@google.com      if (cache_entry.CacheState == State:S) {
32614184Sgabeblack@google.com        out_msg.Shared := true;
32714184Sgabeblack@google.com      } else {
32814184Sgabeblack@google.com        out_msg.Shared := false;
32914184Sgabeblack@google.com      }
33014184Sgabeblack@google.com      out_msg.InitialRequestTime := curCycle();
33114184Sgabeblack@google.com    }
33214184Sgabeblack@google.com  }
33314184Sgabeblack@google.com
33414184Sgabeblack@google.com  action(a_allocate, "a", desc="allocate block") {
33514184Sgabeblack@google.com    if (is_invalid(cache_entry)) {
33614184Sgabeblack@google.com      set_cache_entry(L1cache.allocate(address, new Entry));
33714184Sgabeblack@google.com    }
33814184Sgabeblack@google.com  }
33914184Sgabeblack@google.com
34014184Sgabeblack@google.com  action(t_allocateTBE, "t", desc="allocate TBE Entry") {
34114184Sgabeblack@google.com    check_allocate(TBEs);
34214184Sgabeblack@google.com    assert(is_valid(cache_entry));
34314184Sgabeblack@google.com    TBEs.allocate(address);
34414184Sgabeblack@google.com    set_tbe(TBEs.lookup(address));
34514184Sgabeblack@google.com    tbe.DataBlk := cache_entry.DataBlk;  // Data only used for WBs
34614184Sgabeblack@google.com    tbe.Dirty := cache_entry.Dirty;
34714184Sgabeblack@google.com    tbe.Shared := false;
34814184Sgabeblack@google.com  }
34914184Sgabeblack@google.com
35014184Sgabeblack@google.com  action(d_deallocateTBE, "d", desc="Deallocate TBE") {
35114184Sgabeblack@google.com    TBEs.deallocate(address);
35214184Sgabeblack@google.com    unset_tbe();
35314184Sgabeblack@google.com  }
35414184Sgabeblack@google.com
35514184Sgabeblack@google.com  action(p_popMandatoryQueue, "pm", desc="Pop Mandatory Queue") {
35614184Sgabeblack@google.com    mandatoryQueue_in.dequeue(clockEdge());
35714184Sgabeblack@google.com  }
35814184Sgabeblack@google.com
35914184Sgabeblack@google.com  action(pr_popResponseQueue, "pr", desc="Pop Response Queue") {
36014184Sgabeblack@google.com    responseToSQC_in.dequeue(clockEdge());
36114184Sgabeblack@google.com  }
36214184Sgabeblack@google.com
36314184Sgabeblack@google.com  action(pp_popProbeQueue, "pp", desc="pop probe queue") {
36414184Sgabeblack@google.com    probeNetwork_in.dequeue(clockEdge());
36514184Sgabeblack@google.com  }
36614184Sgabeblack@google.com
36714184Sgabeblack@google.com  action(l_loadDone, "l", desc="local load done") {
36814184Sgabeblack@google.com    assert(is_valid(cache_entry));
36914184Sgabeblack@google.com    sequencer.readCallback(address, cache_entry.DataBlk,
37014184Sgabeblack@google.com                           false, MachineType:L1Cache);
37114184Sgabeblack@google.com    APPEND_TRANSITION_COMMENT(cache_entry.DataBlk);
37214184Sgabeblack@google.com  }
37314184Sgabeblack@google.com
37414184Sgabeblack@google.com  action(xl_loadDone, "xl", desc="remote load done") {
37514184Sgabeblack@google.com    peek(responseToSQC_in, ResponseMsg) {
37614184Sgabeblack@google.com      assert(is_valid(cache_entry));
37714184Sgabeblack@google.com      sequencer.readCallback(address,
37814184Sgabeblack@google.com                             cache_entry.DataBlk,
37914184Sgabeblack@google.com                             false,
38014184Sgabeblack@google.com                             machineIDToMachineType(in_msg.Sender),
38114184Sgabeblack@google.com                             in_msg.InitialRequestTime,
38214184Sgabeblack@google.com                             in_msg.ForwardRequestTime,
38314184Sgabeblack@google.com                             in_msg.ProbeRequestStartTime);
38414184Sgabeblack@google.com      APPEND_TRANSITION_COMMENT(cache_entry.DataBlk);
38514184Sgabeblack@google.com    }
38614184Sgabeblack@google.com  }
38714184Sgabeblack@google.com
38814184Sgabeblack@google.com  action(w_writeCache, "w", desc="write data to cache") {
38914184Sgabeblack@google.com    peek(responseToSQC_in, ResponseMsg) {
39014184Sgabeblack@google.com      assert(is_valid(cache_entry));
39114184Sgabeblack@google.com      cache_entry.DataBlk := in_msg.DataBlk;
39214184Sgabeblack@google.com      cache_entry.Dirty := in_msg.Dirty;
39314184Sgabeblack@google.com    }
39414184Sgabeblack@google.com  }
39514184Sgabeblack@google.com
39614184Sgabeblack@google.com  action(ss_sendStaleNotification, "ss", desc="stale data; nothing to writeback") {
39714184Sgabeblack@google.com    peek(responseToSQC_in, ResponseMsg) {
39814184Sgabeblack@google.com      enqueue(responseNetwork_out, ResponseMsg, issue_latency) {
39914184Sgabeblack@google.com        out_msg.addr := address;
40014184Sgabeblack@google.com        out_msg.Type := CoherenceResponseType:StaleNotif;
40114184Sgabeblack@google.com        out_msg.Sender := machineID;
40214184Sgabeblack@google.com        out_msg.Destination.add(mapAddressToRange(address,MachineType:TCC,
40314184Sgabeblack@google.com                                TCC_select_low_bit, TCC_select_num_bits));
40414184Sgabeblack@google.com        out_msg.MessageSize := MessageSizeType:Response_Control;
40514184Sgabeblack@google.com        DPRINTF(RubySlicc, "%s\n", out_msg);
40614184Sgabeblack@google.com      }
40714184Sgabeblack@google.com    }
40814184Sgabeblack@google.com  }
40914184Sgabeblack@google.com
41014184Sgabeblack@google.com  action(wb_data, "wb", desc="write back data") {
41114184Sgabeblack@google.com    peek(responseToSQC_in, ResponseMsg) {
41214184Sgabeblack@google.com      enqueue(responseNetwork_out, ResponseMsg, issue_latency) {
41314184Sgabeblack@google.com        out_msg.addr := address;
41414184Sgabeblack@google.com        out_msg.Type := CoherenceResponseType:CPUData;
41514184Sgabeblack@google.com        out_msg.Sender := machineID;
41614184Sgabeblack@google.com        out_msg.Destination.add(mapAddressToRange(address,MachineType:TCC,
41714184Sgabeblack@google.com                                TCC_select_low_bit, TCC_select_num_bits));
41814184Sgabeblack@google.com        out_msg.DataBlk := tbe.DataBlk;
41914184Sgabeblack@google.com        out_msg.Dirty := tbe.Dirty;
42014184Sgabeblack@google.com        if (tbe.Shared) {
42114184Sgabeblack@google.com          out_msg.NbReqShared := true;
42214184Sgabeblack@google.com        } else {
42314184Sgabeblack@google.com          out_msg.NbReqShared := false;
42414184Sgabeblack@google.com        }
42514184Sgabeblack@google.com        out_msg.State := CoherenceState:Shared; // faux info
42614184Sgabeblack@google.com        out_msg.MessageSize := MessageSizeType:Writeback_Data;
42714184Sgabeblack@google.com        DPRINTF(RubySlicc, "%s\n", out_msg);
42814184Sgabeblack@google.com      }
42914184Sgabeblack@google.com    }
43014184Sgabeblack@google.com  }
43114184Sgabeblack@google.com
43214184Sgabeblack@google.com  action(pi_sendProbeResponseInv, "pi", desc="send probe ack inv, no data") {
43314184Sgabeblack@google.com    enqueue(responseNetwork_out, ResponseMsg, issue_latency) {
43414184Sgabeblack@google.com      out_msg.addr := address;
43514184Sgabeblack@google.com      out_msg.Type := CoherenceResponseType:CPUPrbResp;  // L3 and CPUs respond in same way to probes
43614184Sgabeblack@google.com      out_msg.Sender := machineID;
43714184Sgabeblack@google.com      // will this always be ok? probably not for multisocket
43814184Sgabeblack@google.com      out_msg.Destination.add(mapAddressToRange(address,MachineType:TCCdir,
43914184Sgabeblack@google.com                              TCC_select_low_bit, TCC_select_num_bits));
44014184Sgabeblack@google.com      out_msg.Dirty := false;
44114184Sgabeblack@google.com      out_msg.Hit := false;
44214184Sgabeblack@google.com      out_msg.Ntsl := true;
44314184Sgabeblack@google.com      out_msg.State := CoherenceState:NA;
44414184Sgabeblack@google.com      out_msg.MessageSize := MessageSizeType:Response_Control;
44514184Sgabeblack@google.com    }
44614184Sgabeblack@google.com  }
44714184Sgabeblack@google.com
44814184Sgabeblack@google.com  action(pim_sendProbeResponseInvMs, "pim", desc="send probe ack inv, no data") {
44914184Sgabeblack@google.com    enqueue(responseNetwork_out, ResponseMsg, issue_latency) {
45014184Sgabeblack@google.com      out_msg.addr := address;
45114184Sgabeblack@google.com      out_msg.Type := CoherenceResponseType:CPUPrbResp;  // L3 and CPUs respond in same way to probes
45214184Sgabeblack@google.com      out_msg.Sender := machineID;
45314184Sgabeblack@google.com      // will this always be ok? probably not for multisocket
45414184Sgabeblack@google.com      out_msg.Destination.add(mapAddressToRange(address,MachineType:TCCdir,
45514184Sgabeblack@google.com                              TCC_select_low_bit, TCC_select_num_bits));
45614184Sgabeblack@google.com      out_msg.Dirty := false;
45714184Sgabeblack@google.com      out_msg.Ntsl := true;
45814184Sgabeblack@google.com      out_msg.Hit := false;
45914184Sgabeblack@google.com      out_msg.State := CoherenceState:NA;
46014184Sgabeblack@google.com      out_msg.MessageSize := MessageSizeType:Response_Control;
46114184Sgabeblack@google.com    }
46214184Sgabeblack@google.com  }
46314184Sgabeblack@google.com
46414184Sgabeblack@google.com  action(prm_sendProbeResponseMiss, "prm", desc="send probe ack PrbShrData, no data") {
46514184Sgabeblack@google.com    enqueue(responseNetwork_out, ResponseMsg, issue_latency) {
46614184Sgabeblack@google.com      out_msg.addr := address;
46714184Sgabeblack@google.com      out_msg.Type := CoherenceResponseType:CPUPrbResp;  // L3 and CPUs respond in same way to probes
46814184Sgabeblack@google.com      out_msg.Sender := machineID;
46914184Sgabeblack@google.com      // will this always be ok? probably not for multisocket
47014184Sgabeblack@google.com      out_msg.Destination.add(mapAddressToRange(address,MachineType:TCCdir,
47114184Sgabeblack@google.com                              TCC_select_low_bit, TCC_select_num_bits));
47214184Sgabeblack@google.com      out_msg.Dirty := false;  // only true if sending back data i think
47314184Sgabeblack@google.com      out_msg.Hit := false;
47414184Sgabeblack@google.com      out_msg.Ntsl := false;
47514184Sgabeblack@google.com      out_msg.State := CoherenceState:NA;
47614184Sgabeblack@google.com      out_msg.MessageSize := MessageSizeType:Response_Control;
47714184Sgabeblack@google.com    }
47814184Sgabeblack@google.com  }
47914184Sgabeblack@google.com
48014184Sgabeblack@google.com  action(pd_sendProbeResponseData, "pd", desc="send probe ack, with data") {
48114184Sgabeblack@google.com    enqueue(responseNetwork_out, ResponseMsg, issue_latency) {
48214184Sgabeblack@google.com      assert(is_valid(cache_entry) || is_valid(tbe));
48314184Sgabeblack@google.com      out_msg.addr := address;
48414184Sgabeblack@google.com      out_msg.Type := CoherenceResponseType:CPUPrbResp;
48514184Sgabeblack@google.com      out_msg.Sender := machineID;
48614184Sgabeblack@google.com      // will this always be ok? probably not for multisocket
48714184Sgabeblack@google.com      out_msg.Destination.add(mapAddressToRange(address,MachineType:TCCdir,
48814184Sgabeblack@google.com                              TCC_select_low_bit, TCC_select_num_bits));
48914184Sgabeblack@google.com      out_msg.DataBlk := getDataBlock(address);
49014184Sgabeblack@google.com      if (is_valid(tbe)) {
49114184Sgabeblack@google.com        out_msg.Dirty := tbe.Dirty;
49214184Sgabeblack@google.com      } else {
49314184Sgabeblack@google.com        out_msg.Dirty := cache_entry.Dirty;
49414184Sgabeblack@google.com      }
49514184Sgabeblack@google.com      out_msg.Hit := true;
49614184Sgabeblack@google.com      out_msg.State := CoherenceState:NA;
49714184Sgabeblack@google.com      out_msg.MessageSize := MessageSizeType:Response_Data;
49814184Sgabeblack@google.com    }
49914184Sgabeblack@google.com  }
50014184Sgabeblack@google.com
50114184Sgabeblack@google.com  action(pdm_sendProbeResponseDataMs, "pdm", desc="send probe ack, with data") {
50214184Sgabeblack@google.com    enqueue(responseNetwork_out, ResponseMsg, issue_latency) {
50314184Sgabeblack@google.com      assert(is_valid(cache_entry) || is_valid(tbe));
50414184Sgabeblack@google.com      assert(is_valid(cache_entry));
50514184Sgabeblack@google.com      out_msg.addr := address;
50614184Sgabeblack@google.com      out_msg.Type := CoherenceResponseType:CPUPrbResp;
50714184Sgabeblack@google.com      out_msg.Sender := machineID;
50814184Sgabeblack@google.com      // will this always be ok? probably not for multisocket
50914184Sgabeblack@google.com      out_msg.Destination.add(mapAddressToRange(address,MachineType:TCCdir,
51014184Sgabeblack@google.com                              TCC_select_low_bit, TCC_select_num_bits));
51114184Sgabeblack@google.com      out_msg.DataBlk := getDataBlock(address);
51214184Sgabeblack@google.com      if (is_valid(tbe)) {
51314184Sgabeblack@google.com        out_msg.Dirty := tbe.Dirty;
51414184Sgabeblack@google.com      } else {
51514184Sgabeblack@google.com        out_msg.Dirty := cache_entry.Dirty;
51614184Sgabeblack@google.com      }
51714184Sgabeblack@google.com      out_msg.Hit := true;
51814184Sgabeblack@google.com      out_msg.State := CoherenceState:NA;
51914184Sgabeblack@google.com      out_msg.MessageSize := MessageSizeType:Response_Data;
52014184Sgabeblack@google.com    }
52114184Sgabeblack@google.com  }
52214184Sgabeblack@google.com
52314184Sgabeblack@google.com  action(sf_setSharedFlip, "sf", desc="hit by shared probe, status may be different") {
52414184Sgabeblack@google.com    assert(is_valid(tbe));
52514184Sgabeblack@google.com    tbe.Shared := true;
52614184Sgabeblack@google.com  }
52714184Sgabeblack@google.com
52814184Sgabeblack@google.com  action(uu_sendUnblock, "uu", desc="state changed, unblock") {
52914184Sgabeblack@google.com    enqueue(unblockNetwork_out, UnblockMsg, issue_latency) {
53014184Sgabeblack@google.com      out_msg.addr := address;
53114184Sgabeblack@google.com      out_msg.Sender := machineID;
53214184Sgabeblack@google.com      out_msg.Destination.add(mapAddressToRange(address,MachineType:TCCdir,
53314184Sgabeblack@google.com                              TCC_select_low_bit, TCC_select_num_bits));
53414184Sgabeblack@google.com      out_msg.MessageSize := MessageSizeType:Unblock_Control;
53514184Sgabeblack@google.com      DPRINTF(RubySlicc, "%s\n", out_msg);
53614184Sgabeblack@google.com    }
53714184Sgabeblack@google.com  }
53814184Sgabeblack@google.com
53914184Sgabeblack@google.com  action(yy_recycleProbeQueue, "yy", desc="recycle probe queue") {
54014184Sgabeblack@google.com    probeNetwork_in.recycle(clockEdge(), cyclesToTicks(recycle_latency));
54114184Sgabeblack@google.com  }
54214184Sgabeblack@google.com
54314184Sgabeblack@google.com  action(zz_recycleMandatoryQueue, "\z", desc="recycle mandatory queue") {
54414184Sgabeblack@google.com    mandatoryQueue_in.recycle(clockEdge(), cyclesToTicks(recycle_latency));
54514184Sgabeblack@google.com  }
54614184Sgabeblack@google.com
54714184Sgabeblack@google.com  // Transitions
54814184Sgabeblack@google.com
54914184Sgabeblack@google.com  // transitions from base
55014184Sgabeblack@google.com  transition(I, Fetch, I_S) {TagArrayRead, TagArrayWrite} {
55114184Sgabeblack@google.com    a_allocate;
55214184Sgabeblack@google.com    nS_issueRdBlkS;
55314184Sgabeblack@google.com    p_popMandatoryQueue;
55414184Sgabeblack@google.com  }
55514184Sgabeblack@google.com
55614184Sgabeblack@google.com  // simple hit transitions
55714184Sgabeblack@google.com  transition(S, Fetch) {TagArrayRead, DataArrayRead} {
55814184Sgabeblack@google.com    l_loadDone;
55914184Sgabeblack@google.com    p_popMandatoryQueue;
56014184Sgabeblack@google.com  }
56114184Sgabeblack@google.com
56214184Sgabeblack@google.com  // recycles from transients
56314184Sgabeblack@google.com  transition({I_S, S_I, I_C}, {Fetch, Repl}) {} {
56414184Sgabeblack@google.com    zz_recycleMandatoryQueue;
56514184Sgabeblack@google.com  }
56614184Sgabeblack@google.com
56714184Sgabeblack@google.com  transition(S, Repl, S_I) {TagArrayRead} {
56814184Sgabeblack@google.com    t_allocateTBE;
56914184Sgabeblack@google.com    vc_victim;
57014184Sgabeblack@google.com    ic_invCache;
57114184Sgabeblack@google.com  }
57214184Sgabeblack@google.com
57314184Sgabeblack@google.com  // TCC event
57414184Sgabeblack@google.com  transition(I_S, TCC_AckS, S) {DataArrayRead, DataArrayWrite} {
57514184Sgabeblack@google.com    w_writeCache;
57614184Sgabeblack@google.com    xl_loadDone;
57714184Sgabeblack@google.com    uu_sendUnblock;
57814184Sgabeblack@google.com    pr_popResponseQueue;
57914184Sgabeblack@google.com  }
58014184Sgabeblack@google.com
58114184Sgabeblack@google.com  transition(S_I, TCC_NackWB, I){TagArrayWrite} {
58214184Sgabeblack@google.com    d_deallocateTBE;
58314184Sgabeblack@google.com    pr_popResponseQueue;
58414184Sgabeblack@google.com  }
58514184Sgabeblack@google.com
58614184Sgabeblack@google.com  transition(S_I, TCC_AckWB, I) {TagArrayWrite} {
58714184Sgabeblack@google.com    wb_data;
58814184Sgabeblack@google.com    d_deallocateTBE;
58914184Sgabeblack@google.com    pr_popResponseQueue;
59014184Sgabeblack@google.com  }
59114184Sgabeblack@google.com
59214184Sgabeblack@google.com  transition(I_C, TCC_AckWB, I){TagArrayWrite} {
59314184Sgabeblack@google.com    ss_sendStaleNotification;
59414184Sgabeblack@google.com    d_deallocateTBE;
59514184Sgabeblack@google.com    pr_popResponseQueue;
59614184Sgabeblack@google.com  }
59714184Sgabeblack@google.com
59814184Sgabeblack@google.com  transition(I_C, TCC_NackWB, I) {TagArrayWrite} {
59914184Sgabeblack@google.com    d_deallocateTBE;
60014184Sgabeblack@google.com    pr_popResponseQueue;
60114184Sgabeblack@google.com  }
60214184Sgabeblack@google.com
60314184Sgabeblack@google.com  // Probe transitions
60414184Sgabeblack@google.com  transition({S, I}, PrbInvData, I) {TagArrayRead, TagArrayWrite} {
60514184Sgabeblack@google.com    pd_sendProbeResponseData;
60614184Sgabeblack@google.com    ic_invCache;
60714184Sgabeblack@google.com    pp_popProbeQueue;
60814184Sgabeblack@google.com  }
60914184Sgabeblack@google.com
61014184Sgabeblack@google.com  transition(I_C, PrbInvData, I_C) {
61114184Sgabeblack@google.com    pi_sendProbeResponseInv;
61214184Sgabeblack@google.com    ic_invCache;
61314184Sgabeblack@google.com    pp_popProbeQueue;
61414184Sgabeblack@google.com  }
61514184Sgabeblack@google.com
61614184Sgabeblack@google.com  transition({S, I}, PrbInv, I) {TagArrayRead, TagArrayWrite} {
61714184Sgabeblack@google.com    pi_sendProbeResponseInv;
61814184Sgabeblack@google.com    ic_invCache;
61914184Sgabeblack@google.com    pp_popProbeQueue;
62014184Sgabeblack@google.com  }
62114184Sgabeblack@google.com
62214184Sgabeblack@google.com  transition({S}, PrbShrData, S) {DataArrayRead} {
62314184Sgabeblack@google.com    pd_sendProbeResponseData;
62414184Sgabeblack@google.com    pp_popProbeQueue;
62514184Sgabeblack@google.com  }
62614184Sgabeblack@google.com
62714184Sgabeblack@google.com  transition({I, I_C}, PrbShrData) {TagArrayRead} {
62814184Sgabeblack@google.com    prm_sendProbeResponseMiss;
62914184Sgabeblack@google.com    pp_popProbeQueue;
63014184Sgabeblack@google.com  }
63114184Sgabeblack@google.com
63214184Sgabeblack@google.com  transition(I_C, PrbInv, I_C){
63314184Sgabeblack@google.com    pi_sendProbeResponseInv;
63414184Sgabeblack@google.com    ic_invCache;
63514184Sgabeblack@google.com    pp_popProbeQueue;
63614184Sgabeblack@google.com  }
63714184Sgabeblack@google.com
63814184Sgabeblack@google.com  transition(I_S, {PrbInv, PrbInvData}) {} {
63914184Sgabeblack@google.com    pi_sendProbeResponseInv;
64014184Sgabeblack@google.com    ic_invCache;
64114184Sgabeblack@google.com    a_allocate;  // but make sure there is room for incoming data when it arrives
64214184Sgabeblack@google.com    pp_popProbeQueue;
64314184Sgabeblack@google.com  }
64414184Sgabeblack@google.com
64514184Sgabeblack@google.com  transition(I_S, PrbShrData) {} {
64614184Sgabeblack@google.com    prm_sendProbeResponseMiss;
64714184Sgabeblack@google.com    pp_popProbeQueue;
64814184Sgabeblack@google.com  }
64914184Sgabeblack@google.com
65014184Sgabeblack@google.com  transition(S_I, PrbInvData, I_C) {TagArrayWrite} {
65114184Sgabeblack@google.com    pi_sendProbeResponseInv;
65214184Sgabeblack@google.com    ic_invCache;
65314184Sgabeblack@google.com    pp_popProbeQueue;
65414184Sgabeblack@google.com  }
65514184Sgabeblack@google.com
65614184Sgabeblack@google.com  transition(S_I, PrbInv, I_C) {TagArrayWrite} {
65714184Sgabeblack@google.com    pi_sendProbeResponseInv;
65814184Sgabeblack@google.com    ic_invCache;
65914184Sgabeblack@google.com    pp_popProbeQueue;
66014184Sgabeblack@google.com  }
66114184Sgabeblack@google.com
66214184Sgabeblack@google.com  transition(S_I, PrbShrData) {DataArrayRead} {
66314184Sgabeblack@google.com    pd_sendProbeResponseData;
66414184Sgabeblack@google.com    sf_setSharedFlip;
66514184Sgabeblack@google.com    pp_popProbeQueue;
66614184Sgabeblack@google.com  }
66714184Sgabeblack@google.com}
668