MOESI_CMP_token-dir.sm revision 14184
114184Sgabeblack@google.com/*
214184Sgabeblack@google.com * Copyright (c) 1999-2013 Mark D. Hill and David A. Wood
314184Sgabeblack@google.com * All rights reserved.
414184Sgabeblack@google.com *
514184Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
614184Sgabeblack@google.com * modification, are permitted provided that the following conditions are
714184Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
814184Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
914184Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
1014184Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1114184Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1214184Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1314184Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1414184Sgabeblack@google.com * this software without specific prior written permission.
1514184Sgabeblack@google.com *
1614184Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1714184Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1814184Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1914184Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2014184Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2114184Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2214184Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2314184Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2414184Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2514184Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2614184Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2714184Sgabeblack@google.com */
2814184Sgabeblack@google.com
2914184Sgabeblack@google.commachine(MachineType:Directory, "Token protocol")
3014184Sgabeblack@google.com : DirectoryMemory * directory;
3114184Sgabeblack@google.com   int l2_select_num_bits;
3214184Sgabeblack@google.com   Cycles directory_latency := 5;
3314184Sgabeblack@google.com   bool distributed_persistent := "True";
3414184Sgabeblack@google.com   Cycles fixed_timeout_latency := 100;
3514184Sgabeblack@google.com   Cycles reissue_wakeup_latency := 10;
3614184Sgabeblack@google.com   Cycles to_memory_controller_latency := 1;
3714184Sgabeblack@google.com
3814184Sgabeblack@google.com   // Message Queues from dir to other controllers / network
3914184Sgabeblack@google.com   MessageBuffer * dmaResponseFromDir, network="To", virtual_network="5",
4014184Sgabeblack@google.com        vnet_type="response";
4114184Sgabeblack@google.com
4214184Sgabeblack@google.com   MessageBuffer * responseFromDir, network="To", virtual_network="4",
4314184Sgabeblack@google.com        vnet_type="response";
4414184Sgabeblack@google.com
4514184Sgabeblack@google.com   MessageBuffer * persistentFromDir, network="To", virtual_network="3",
4614184Sgabeblack@google.com        vnet_type="persistent";
4714184Sgabeblack@google.com
4814184Sgabeblack@google.com   MessageBuffer * requestFromDir, network="To", virtual_network="1",
4914184Sgabeblack@google.com        vnet_type="request";
5014184Sgabeblack@google.com 
5114184Sgabeblack@google.com   // Message Queues to dir from other controllers / network
5214184Sgabeblack@google.com   MessageBuffer * responseToDir, network="From", virtual_network="4",
5314184Sgabeblack@google.com        vnet_type="response";
5414184Sgabeblack@google.com
5514184Sgabeblack@google.com   MessageBuffer * persistentToDir, network="From", virtual_network="3",
5614184Sgabeblack@google.com        vnet_type="persistent";
5714184Sgabeblack@google.com   
5814184Sgabeblack@google.com   MessageBuffer * requestToDir, network="From", virtual_network="2",
5914184Sgabeblack@google.com        vnet_type="request";
6014184Sgabeblack@google.com   
6114184Sgabeblack@google.com   MessageBuffer * dmaRequestToDir, network="From", virtual_network="0",
6214184Sgabeblack@google.com        vnet_type="request";
6314184Sgabeblack@google.com
6414184Sgabeblack@google.com   MessageBuffer * responseFromMemory;
6514184Sgabeblack@google.com{
6614184Sgabeblack@google.com  // STATES
6714184Sgabeblack@google.com  state_declaration(State, desc="Directory states", default="Directory_State_O") {
6814184Sgabeblack@google.com    // Base states
6914184Sgabeblack@google.com    O, AccessPermission:Read_Only, desc="Owner, memory has valid data, but not necessarily all the tokens";
7014184Sgabeblack@google.com    NO, AccessPermission:Maybe_Stale, desc="Not Owner";
7114184Sgabeblack@google.com    L, AccessPermission:Busy, desc="Locked";
7214184Sgabeblack@google.com
7314184Sgabeblack@google.com    // Memory wait states - can block all messages including persistent requests
7414184Sgabeblack@google.com    O_W, AccessPermission:Busy, desc="transitioning to Owner, waiting for memory write";
7514184Sgabeblack@google.com    L_O_W, AccessPermission:Busy, desc="transitioning to Locked, waiting for memory read, could eventually return to O";
7614184Sgabeblack@google.com    L_NO_W, AccessPermission:Busy, desc="transitioning to Locked, waiting for memory read, eventually return to NO";
7714184Sgabeblack@google.com    DR_L_W, AccessPermission:Busy, desc="transitioning to Locked underneath a DMA read, waiting for memory data";
7814184Sgabeblack@google.com    DW_L_W, AccessPermission:Busy, desc="transitioning to Locked underneath a DMA write, waiting for memory ack";
7914184Sgabeblack@google.com    NO_W, AccessPermission:Busy, desc="transitioning to Not Owner, waiting for memory read";
8014184Sgabeblack@google.com    O_DW_W, AccessPermission:Busy, desc="transitioning to Owner, waiting for memory before DMA ack";
8114184Sgabeblack@google.com    O_DR_W, AccessPermission:Busy, desc="transitioning to Owner, waiting for memory before DMA data";
8214184Sgabeblack@google.com
8314184Sgabeblack@google.com    // DMA request transient states - must respond to persistent requests
8414184Sgabeblack@google.com    O_DW, AccessPermission:Busy, desc="issued GETX for DMA write, waiting for all tokens";
8514184Sgabeblack@google.com    NO_DW, AccessPermission:Busy, desc="issued GETX for DMA write, waiting for all tokens";
8614184Sgabeblack@google.com    NO_DR, AccessPermission:Busy, desc="issued GETS for DMA read, waiting for data";
8714184Sgabeblack@google.com
8814184Sgabeblack@google.com    // DMA request in progress - competing with a CPU persistent request
8914184Sgabeblack@google.com    DW_L, AccessPermission:Busy, desc="issued GETX for DMA write, CPU persistent request must complete first";
9014184Sgabeblack@google.com    DR_L, AccessPermission:Busy, desc="issued GETS for DMA read, CPU persistent request must complete first";
9114184Sgabeblack@google.com
9214184Sgabeblack@google.com  }
9314184Sgabeblack@google.com
9414184Sgabeblack@google.com  // Events
9514184Sgabeblack@google.com  enumeration(Event, desc="Directory events") {
9614184Sgabeblack@google.com    GETX, desc="A GETX arrives";
9714184Sgabeblack@google.com    GETS, desc="A GETS arrives";
9814184Sgabeblack@google.com    Lockdown, desc="A lockdown request arrives";
9914184Sgabeblack@google.com    Unlockdown, desc="An un-lockdown request arrives";
10014184Sgabeblack@google.com    Own_Lock_or_Unlock, desc="own lock or unlock";
10114184Sgabeblack@google.com    Own_Lock_or_Unlock_Tokens, desc="own lock or unlock with tokens";
10214184Sgabeblack@google.com    Data_Owner, desc="Data arrive";
10314184Sgabeblack@google.com    Data_All_Tokens, desc="Data and all tokens";
10414184Sgabeblack@google.com    Ack_Owner, desc="Owner token arrived without data because it was clean";
10514184Sgabeblack@google.com    Ack_Owner_All_Tokens, desc="All tokens including owner arrived without data because it was clean";
10614184Sgabeblack@google.com    Tokens, desc="Tokens arrive";
10714184Sgabeblack@google.com    Ack_All_Tokens, desc="All_Tokens arrive";
10814184Sgabeblack@google.com    Request_Timeout, desc="A DMA request has timed out";
10914184Sgabeblack@google.com
11014184Sgabeblack@google.com    // Memory Controller
11114184Sgabeblack@google.com    Memory_Data, desc="Fetched data from memory arrives";
11214184Sgabeblack@google.com    Memory_Ack, desc="Writeback Ack from memory arrives";
11314184Sgabeblack@google.com
11414184Sgabeblack@google.com    // DMA requests
11514184Sgabeblack@google.com    DMA_READ, desc="A DMA Read memory request";
11614184Sgabeblack@google.com    DMA_WRITE, desc="A DMA Write memory request";
11714184Sgabeblack@google.com    DMA_WRITE_All_Tokens, desc="A DMA Write memory request, directory has all tokens";
11814184Sgabeblack@google.com  }
11914184Sgabeblack@google.com
12014184Sgabeblack@google.com  // TYPES
12114184Sgabeblack@google.com
12214184Sgabeblack@google.com  // DirectoryEntry
12314184Sgabeblack@google.com  structure(Entry, desc="...", interface="AbstractEntry") {
12414184Sgabeblack@google.com    State DirectoryState,          desc="Directory state";
12514184Sgabeblack@google.com    int Tokens, default="max_tokens()", desc="Number of tokens for the line we're holding";
12614184Sgabeblack@google.com
12714184Sgabeblack@google.com    // The following state is provided to allow for bandwidth
12814184Sgabeblack@google.com    // efficient directory-like operation.  However all of this state
12914184Sgabeblack@google.com    // is 'soft state' that does not need to be correct (as long as
13014184Sgabeblack@google.com    // you're eventually willing to resort to broadcast.)
13114184Sgabeblack@google.com
13214184Sgabeblack@google.com    Set Owner,                     desc="Probable Owner of the line.  More accurately, the set of processors who need to see a GetS or GetO.  We use a Set for convenience, but only one bit is set at a time.";
13314184Sgabeblack@google.com    Set Sharers,                   desc="Probable sharers of the line.  More accurately, the set of processors who need to see a GetX";
13414184Sgabeblack@google.com  }
13514184Sgabeblack@google.com
13614184Sgabeblack@google.com  structure(PersistentTable, external="yes") {
13714184Sgabeblack@google.com    void persistentRequestLock(Addr, MachineID, AccessType);
13814184Sgabeblack@google.com    void persistentRequestUnlock(Addr, MachineID);
13914184Sgabeblack@google.com    bool okToIssueStarving(Addr, MachineID);
14014184Sgabeblack@google.com    MachineID findSmallest(Addr);
14114184Sgabeblack@google.com    AccessType typeOfSmallest(Addr);
14214184Sgabeblack@google.com    void markEntries(Addr);
14314184Sgabeblack@google.com    bool isLocked(Addr);
14414184Sgabeblack@google.com    int countStarvingForAddress(Addr);
14514184Sgabeblack@google.com    int countReadStarvingForAddress(Addr);
14614184Sgabeblack@google.com  }
14714184Sgabeblack@google.com
14814184Sgabeblack@google.com  // TBE entries for DMA requests
14914184Sgabeblack@google.com  structure(TBE, desc="TBE entries for outstanding DMA requests") {
15014184Sgabeblack@google.com    Addr PhysicalAddress, desc="physical address";
15114184Sgabeblack@google.com    State TBEState,        desc="Transient State";
15214184Sgabeblack@google.com    DataBlock DataBlk,     desc="Current view of the associated address range";
15314184Sgabeblack@google.com    int Len,               desc="...";
15414184Sgabeblack@google.com    MachineID DmaRequestor, desc="DMA requestor";
15514184Sgabeblack@google.com    bool WentPersistent,   desc="Did the DMA request require a persistent request";
15614184Sgabeblack@google.com  }
15714184Sgabeblack@google.com
15814184Sgabeblack@google.com  structure(TBETable, external="yes") {
15914184Sgabeblack@google.com    TBE lookup(Addr);
16014184Sgabeblack@google.com    void allocate(Addr);
16114184Sgabeblack@google.com    void deallocate(Addr);
16214184Sgabeblack@google.com    bool isPresent(Addr);
16314184Sgabeblack@google.com  }
16414184Sgabeblack@google.com
16514184Sgabeblack@google.com  // ** OBJECTS **
16614184Sgabeblack@google.com
16714184Sgabeblack@google.com  PersistentTable persistentTable;
16814184Sgabeblack@google.com  TimerTable reissueTimerTable;
16914184Sgabeblack@google.com
17014184Sgabeblack@google.com  TBETable TBEs, template="<Directory_TBE>", constructor="m_number_of_TBEs";
17114184Sgabeblack@google.com
17214184Sgabeblack@google.com  bool starving, default="false";
17314184Sgabeblack@google.com  int l2_select_low_bit, default="RubySystem::getBlockSizeBits()";
17414184Sgabeblack@google.com
17514184Sgabeblack@google.com  Tick clockEdge();
17614184Sgabeblack@google.com  Tick clockEdge(Cycles c);
17714184Sgabeblack@google.com  Tick cyclesToTicks(Cycles c);
17814184Sgabeblack@google.com  void set_tbe(TBE b);
17914184Sgabeblack@google.com  void unset_tbe();
18014184Sgabeblack@google.com  MachineID mapAddressToMachine(Addr addr, MachineType mtype);
18114184Sgabeblack@google.com
18214184Sgabeblack@google.com  Entry getDirectoryEntry(Addr addr), return_by_pointer="yes" {
18314184Sgabeblack@google.com    Entry dir_entry := static_cast(Entry, "pointer", directory[addr]);
18414184Sgabeblack@google.com
18514184Sgabeblack@google.com    if (is_valid(dir_entry)) {
18614184Sgabeblack@google.com      return dir_entry;
18714184Sgabeblack@google.com    }
18814184Sgabeblack@google.com
18914184Sgabeblack@google.com    dir_entry :=  static_cast(Entry, "pointer",
19014184Sgabeblack@google.com                              directory.allocate(addr, new Entry));
19114184Sgabeblack@google.com    return dir_entry;
19214184Sgabeblack@google.com  }
19314184Sgabeblack@google.com
19414184Sgabeblack@google.com  State getState(TBE tbe, Addr addr) {
19514184Sgabeblack@google.com    if (is_valid(tbe)) {
19614184Sgabeblack@google.com      return tbe.TBEState;
19714184Sgabeblack@google.com    } else {
19814184Sgabeblack@google.com      return getDirectoryEntry(addr).DirectoryState;
19914184Sgabeblack@google.com    }
20014184Sgabeblack@google.com  }
20114184Sgabeblack@google.com
20214184Sgabeblack@google.com  void setState(TBE tbe, Addr addr, State state) {
20314184Sgabeblack@google.com    if (is_valid(tbe)) {
20414184Sgabeblack@google.com      tbe.TBEState := state;
20514184Sgabeblack@google.com    }
20614184Sgabeblack@google.com    getDirectoryEntry(addr).DirectoryState := state;
20714184Sgabeblack@google.com
20814184Sgabeblack@google.com    if (state == State:L || state == State:DW_L || state == State:DR_L) {
20914184Sgabeblack@google.com      assert(getDirectoryEntry(addr).Tokens == 0);
21014184Sgabeblack@google.com    }
21114184Sgabeblack@google.com
21214184Sgabeblack@google.com    // We have one or zero owners
21314184Sgabeblack@google.com    assert((getDirectoryEntry(addr).Owner.count() == 0) || (getDirectoryEntry(addr).Owner.count() == 1));
21414184Sgabeblack@google.com
21514184Sgabeblack@google.com    // Make sure the token count is in range
21614184Sgabeblack@google.com    assert(getDirectoryEntry(addr).Tokens >= 0);
21714184Sgabeblack@google.com    assert(getDirectoryEntry(addr).Tokens <= max_tokens());
21814184Sgabeblack@google.com
21914184Sgabeblack@google.com    if (state == State:O || state == State:O_W || state == State:O_DW) {
22014184Sgabeblack@google.com      assert(getDirectoryEntry(addr).Tokens >= 1); // Must have at least one token
22114184Sgabeblack@google.com      // assert(getDirectoryEntry(addr).Tokens >= (max_tokens() / 2)); // Only mostly true; this might not always hold
22214184Sgabeblack@google.com    }
22314184Sgabeblack@google.com  }
22414184Sgabeblack@google.com
22514184Sgabeblack@google.com  AccessPermission getAccessPermission(Addr addr) {
22614184Sgabeblack@google.com    TBE tbe := TBEs[addr];
22714184Sgabeblack@google.com    if(is_valid(tbe)) {
22814184Sgabeblack@google.com      return Directory_State_to_permission(tbe.TBEState);
22914184Sgabeblack@google.com    }
23014184Sgabeblack@google.com
23114184Sgabeblack@google.com    if (directory.isPresent(addr)) {
23214184Sgabeblack@google.com      DPRINTF(RubySlicc, "%s\n", Directory_State_to_permission(getDirectoryEntry(addr).DirectoryState));
23314184Sgabeblack@google.com      return Directory_State_to_permission(getDirectoryEntry(addr).DirectoryState);
23414184Sgabeblack@google.com    }
23514184Sgabeblack@google.com
23614184Sgabeblack@google.com    DPRINTF(RubySlicc, "AccessPermission_NotPresent\n");
23714184Sgabeblack@google.com    return AccessPermission:NotPresent;
23814184Sgabeblack@google.com  }
23914184Sgabeblack@google.com
24014184Sgabeblack@google.com  void setAccessPermission(Addr addr, State state) {
24114184Sgabeblack@google.com    getDirectoryEntry(addr).changePermission(Directory_State_to_permission(state));
24214184Sgabeblack@google.com  }
24314184Sgabeblack@google.com
24414184Sgabeblack@google.com  bool okToIssueStarving(Addr addr, MachineID machinID) {
24514184Sgabeblack@google.com    return persistentTable.okToIssueStarving(addr, machineID);
24614184Sgabeblack@google.com  }
24714184Sgabeblack@google.com
24814184Sgabeblack@google.com  void markPersistentEntries(Addr addr) {
24914184Sgabeblack@google.com    persistentTable.markEntries(addr);
25014184Sgabeblack@google.com  }
25114184Sgabeblack@google.com
25214184Sgabeblack@google.com  void functionalRead(Addr addr, Packet *pkt) {
25314184Sgabeblack@google.com    TBE tbe := TBEs[addr];
25414184Sgabeblack@google.com    if(is_valid(tbe)) {
25514184Sgabeblack@google.com      testAndRead(addr, tbe.DataBlk, pkt);
25614184Sgabeblack@google.com    } else {
25714184Sgabeblack@google.com      functionalMemoryRead(pkt);
25814184Sgabeblack@google.com    }
25914184Sgabeblack@google.com  }
26014184Sgabeblack@google.com
26114184Sgabeblack@google.com  int functionalWrite(Addr addr, Packet *pkt) {
26214184Sgabeblack@google.com    int num_functional_writes := 0;
26314184Sgabeblack@google.com
26414184Sgabeblack@google.com    TBE tbe := TBEs[addr];
26514184Sgabeblack@google.com    if(is_valid(tbe)) {
26614184Sgabeblack@google.com      num_functional_writes := num_functional_writes +
26714184Sgabeblack@google.com            testAndWrite(addr, tbe.DataBlk, pkt);
26814184Sgabeblack@google.com    }
26914184Sgabeblack@google.com
27014184Sgabeblack@google.com    num_functional_writes := num_functional_writes + functionalMemoryWrite(pkt);
27114184Sgabeblack@google.com    return num_functional_writes;
27214184Sgabeblack@google.com  }
27314184Sgabeblack@google.com
27414184Sgabeblack@google.com  // ** OUT_PORTS **
27514184Sgabeblack@google.com  out_port(responseNetwork_out, ResponseMsg, responseFromDir);
27614184Sgabeblack@google.com  out_port(persistentNetwork_out, PersistentMsg, persistentFromDir);
27714184Sgabeblack@google.com  out_port(requestNetwork_out, RequestMsg, requestFromDir);
27814184Sgabeblack@google.com  out_port(dmaResponseNetwork_out, DMAResponseMsg, dmaResponseFromDir);
27914184Sgabeblack@google.com
28014184Sgabeblack@google.com  // ** IN_PORTS **
28114184Sgabeblack@google.com  // off-chip memory request/response is done
28214184Sgabeblack@google.com  in_port(memQueue_in, MemoryMsg, responseFromMemory) {
28314184Sgabeblack@google.com    if (memQueue_in.isReady(clockEdge())) {
28414184Sgabeblack@google.com      peek(memQueue_in, MemoryMsg) {
28514184Sgabeblack@google.com        if (in_msg.Type == MemoryRequestType:MEMORY_READ) {
28614184Sgabeblack@google.com          trigger(Event:Memory_Data, in_msg.addr, TBEs[in_msg.addr]);
28714184Sgabeblack@google.com        } else if (in_msg.Type == MemoryRequestType:MEMORY_WB) {
28814184Sgabeblack@google.com          trigger(Event:Memory_Ack, in_msg.addr, TBEs[in_msg.addr]);
28914184Sgabeblack@google.com        } else {
29014184Sgabeblack@google.com          DPRINTF(RubySlicc, "%s\n", in_msg.Type);
29114184Sgabeblack@google.com          error("Invalid message");
29214184Sgabeblack@google.com        }
29314184Sgabeblack@google.com      }
29414184Sgabeblack@google.com    }
29514184Sgabeblack@google.com  }
29614184Sgabeblack@google.com
29714184Sgabeblack@google.com  // Reissue Timer
29814184Sgabeblack@google.com  in_port(reissueTimerTable_in, Addr, reissueTimerTable) {
29914184Sgabeblack@google.com    Tick current_time := clockEdge();
30014184Sgabeblack@google.com    if (reissueTimerTable_in.isReady(current_time)) {
30114184Sgabeblack@google.com      Addr addr := reissueTimerTable.nextAddress();
30214184Sgabeblack@google.com      trigger(Event:Request_Timeout, addr, TBEs.lookup(addr));
30314184Sgabeblack@google.com    }
30414184Sgabeblack@google.com  }
30514184Sgabeblack@google.com
30614184Sgabeblack@google.com  in_port(responseNetwork_in, ResponseMsg, responseToDir) {
30714184Sgabeblack@google.com    if (responseNetwork_in.isReady(clockEdge())) {
30814184Sgabeblack@google.com      peek(responseNetwork_in, ResponseMsg) {
30914184Sgabeblack@google.com        assert(in_msg.Destination.isElement(machineID));
31014184Sgabeblack@google.com        if (getDirectoryEntry(in_msg.addr).Tokens + in_msg.Tokens == max_tokens()) {
31114184Sgabeblack@google.com          if ((in_msg.Type == CoherenceResponseType:DATA_OWNER) ||
31214184Sgabeblack@google.com              (in_msg.Type == CoherenceResponseType:DATA_SHARED)) {
31314184Sgabeblack@google.com            trigger(Event:Data_All_Tokens, in_msg.addr,
31414184Sgabeblack@google.com                    TBEs[in_msg.addr]);
31514184Sgabeblack@google.com          } else if (in_msg.Type == CoherenceResponseType:ACK_OWNER) {
31614184Sgabeblack@google.com            trigger(Event:Ack_Owner_All_Tokens, in_msg.addr,
31714184Sgabeblack@google.com                    TBEs[in_msg.addr]);
31814184Sgabeblack@google.com          } else if (in_msg.Type == CoherenceResponseType:ACK) {
31914184Sgabeblack@google.com            trigger(Event:Ack_All_Tokens, in_msg.addr,
32014184Sgabeblack@google.com                    TBEs[in_msg.addr]);
32114184Sgabeblack@google.com          } else {
32214184Sgabeblack@google.com            DPRINTF(RubySlicc, "%s\n", in_msg.Type);
32314184Sgabeblack@google.com            error("Invalid message");
32414184Sgabeblack@google.com          }
32514184Sgabeblack@google.com        } else {
32614184Sgabeblack@google.com          if (in_msg.Type == CoherenceResponseType:DATA_OWNER) {
32714184Sgabeblack@google.com            trigger(Event:Data_Owner, in_msg.addr,
32814184Sgabeblack@google.com                    TBEs[in_msg.addr]);
32914184Sgabeblack@google.com          } else if ((in_msg.Type == CoherenceResponseType:ACK) ||
33014184Sgabeblack@google.com                     (in_msg.Type == CoherenceResponseType:DATA_SHARED)) {
33114184Sgabeblack@google.com            trigger(Event:Tokens, in_msg.addr,
33214184Sgabeblack@google.com                    TBEs[in_msg.addr]);
33314184Sgabeblack@google.com          } else if (in_msg.Type == CoherenceResponseType:ACK_OWNER) {
33414184Sgabeblack@google.com            trigger(Event:Ack_Owner, in_msg.addr,
33514184Sgabeblack@google.com                    TBEs[in_msg.addr]);
33614184Sgabeblack@google.com          } else {
33714184Sgabeblack@google.com            DPRINTF(RubySlicc, "%s\n", in_msg.Type);
33814184Sgabeblack@google.com            error("Invalid message");
33914184Sgabeblack@google.com          }
34014184Sgabeblack@google.com        }
34114184Sgabeblack@google.com      }
34214184Sgabeblack@google.com    }
34314184Sgabeblack@google.com  }
34414184Sgabeblack@google.com
34514184Sgabeblack@google.com  in_port(persistentNetwork_in, PersistentMsg, persistentToDir) {
34614184Sgabeblack@google.com    if (persistentNetwork_in.isReady(clockEdge())) {
34714184Sgabeblack@google.com      peek(persistentNetwork_in, PersistentMsg) {
34814184Sgabeblack@google.com        assert(in_msg.Destination.isElement(machineID));
34914184Sgabeblack@google.com
35014184Sgabeblack@google.com        if (distributed_persistent) {
35114184Sgabeblack@google.com          // Apply the lockdown or unlockdown message to the table
35214184Sgabeblack@google.com          if (in_msg.Type == PersistentRequestType:GETX_PERSISTENT) {
35314184Sgabeblack@google.com            persistentTable.persistentRequestLock(in_msg.addr, in_msg.Requestor, AccessType:Write);
35414184Sgabeblack@google.com          } else if (in_msg.Type == PersistentRequestType:GETS_PERSISTENT) {
35514184Sgabeblack@google.com            persistentTable.persistentRequestLock(in_msg.addr, in_msg.Requestor, AccessType:Read);
35614184Sgabeblack@google.com          } else if (in_msg.Type == PersistentRequestType:DEACTIVATE_PERSISTENT) {
35714184Sgabeblack@google.com            persistentTable.persistentRequestUnlock(in_msg.addr, in_msg.Requestor);
35814184Sgabeblack@google.com          } else {
35914184Sgabeblack@google.com            error("Invalid message");
36014184Sgabeblack@google.com          }
36114184Sgabeblack@google.com
36214184Sgabeblack@google.com          // React to the message based on the current state of the table
36314184Sgabeblack@google.com          if (persistentTable.isLocked(in_msg.addr)) {
36414184Sgabeblack@google.com            if (persistentTable.findSmallest(in_msg.addr) == machineID) {
36514184Sgabeblack@google.com              if (getDirectoryEntry(in_msg.addr).Tokens > 0) {
36614184Sgabeblack@google.com                trigger(Event:Own_Lock_or_Unlock_Tokens, in_msg.addr,
36714184Sgabeblack@google.com                        TBEs[in_msg.addr]);
36814184Sgabeblack@google.com              } else {
36914184Sgabeblack@google.com                trigger(Event:Own_Lock_or_Unlock, in_msg.addr,
37014184Sgabeblack@google.com                        TBEs[in_msg.addr]);
37114184Sgabeblack@google.com              }
37214184Sgabeblack@google.com            } else {
37314184Sgabeblack@google.com              // locked
37414184Sgabeblack@google.com              trigger(Event:Lockdown, in_msg.addr, TBEs[in_msg.addr]);
37514184Sgabeblack@google.com            }
37614184Sgabeblack@google.com          } else {
37714184Sgabeblack@google.com            // unlocked
37814184Sgabeblack@google.com            trigger(Event:Unlockdown, in_msg.addr, TBEs[in_msg.addr]);
37914184Sgabeblack@google.com          }
38014184Sgabeblack@google.com        }
38114184Sgabeblack@google.com        else {
38214184Sgabeblack@google.com          if (persistentTable.findSmallest(in_msg.addr) == machineID) {
38314184Sgabeblack@google.com              if (getDirectoryEntry(in_msg.addr).Tokens > 0) {
38414184Sgabeblack@google.com                trigger(Event:Own_Lock_or_Unlock_Tokens, in_msg.addr,
38514184Sgabeblack@google.com                        TBEs[in_msg.addr]);
38614184Sgabeblack@google.com              } else {
38714184Sgabeblack@google.com                trigger(Event:Own_Lock_or_Unlock, in_msg.addr,
38814184Sgabeblack@google.com                        TBEs[in_msg.addr]);
38914184Sgabeblack@google.com              }
39014184Sgabeblack@google.com          } else if (in_msg.Type == PersistentRequestType:GETX_PERSISTENT) {
39114184Sgabeblack@google.com            // locked
39214184Sgabeblack@google.com            trigger(Event:Lockdown, in_msg.addr, TBEs[in_msg.addr]);
39314184Sgabeblack@google.com          } else if (in_msg.Type == PersistentRequestType:GETS_PERSISTENT) {
39414184Sgabeblack@google.com            // locked
39514184Sgabeblack@google.com            trigger(Event:Lockdown, in_msg.addr, TBEs[in_msg.addr]);
39614184Sgabeblack@google.com          } else if (in_msg.Type == PersistentRequestType:DEACTIVATE_PERSISTENT) {
39714184Sgabeblack@google.com            // unlocked
39814184Sgabeblack@google.com            trigger(Event:Unlockdown, in_msg.addr, TBEs[in_msg.addr]);
39914184Sgabeblack@google.com          } else {
40014184Sgabeblack@google.com            error("Invalid message");
40114184Sgabeblack@google.com          }
40214184Sgabeblack@google.com        }
40314184Sgabeblack@google.com      }
40414184Sgabeblack@google.com    }
40514184Sgabeblack@google.com  }
40614184Sgabeblack@google.com
40714184Sgabeblack@google.com  in_port(requestNetwork_in, RequestMsg, requestToDir) {
40814184Sgabeblack@google.com    if (requestNetwork_in.isReady(clockEdge())) {
40914184Sgabeblack@google.com      peek(requestNetwork_in, RequestMsg) {
41014184Sgabeblack@google.com        assert(in_msg.Destination.isElement(machineID));
41114184Sgabeblack@google.com        if (in_msg.Type == CoherenceRequestType:GETS) {
41214184Sgabeblack@google.com          trigger(Event:GETS, in_msg.addr, TBEs[in_msg.addr]);
41314184Sgabeblack@google.com        } else if (in_msg.Type == CoherenceRequestType:GETX) {
41414184Sgabeblack@google.com          trigger(Event:GETX, in_msg.addr, TBEs[in_msg.addr]);
41514184Sgabeblack@google.com        } else {
41614184Sgabeblack@google.com          error("Invalid message");
41714184Sgabeblack@google.com        }
41814184Sgabeblack@google.com      }
41914184Sgabeblack@google.com    }
42014184Sgabeblack@google.com  }
42114184Sgabeblack@google.com
42214184Sgabeblack@google.com  in_port(dmaRequestQueue_in, DMARequestMsg, dmaRequestToDir) {
42314184Sgabeblack@google.com    if (dmaRequestQueue_in.isReady(clockEdge())) {
42414184Sgabeblack@google.com      peek(dmaRequestQueue_in, DMARequestMsg) {
42514184Sgabeblack@google.com        if (in_msg.Type == DMARequestType:READ) {
42614184Sgabeblack@google.com          trigger(Event:DMA_READ, in_msg.LineAddress, TBEs[in_msg.LineAddress]);
42714184Sgabeblack@google.com        } else if (in_msg.Type == DMARequestType:WRITE) {
42814184Sgabeblack@google.com          if (getDirectoryEntry(in_msg.LineAddress).Tokens == max_tokens()) {
42914184Sgabeblack@google.com            trigger(Event:DMA_WRITE_All_Tokens, in_msg.LineAddress,
43014184Sgabeblack@google.com                    TBEs[in_msg.LineAddress]);
43114184Sgabeblack@google.com          } else {
43214184Sgabeblack@google.com            trigger(Event:DMA_WRITE, in_msg.LineAddress,
43314184Sgabeblack@google.com                    TBEs[in_msg.LineAddress]);
43414184Sgabeblack@google.com          }
43514184Sgabeblack@google.com        } else {
43614184Sgabeblack@google.com          error("Invalid message");
43714184Sgabeblack@google.com        }
43814184Sgabeblack@google.com      }
43914184Sgabeblack@google.com    }
44014184Sgabeblack@google.com  }
44114184Sgabeblack@google.com
44214184Sgabeblack@google.com  // Actions
44314184Sgabeblack@google.com
44414184Sgabeblack@google.com  action(a_sendTokens, "a", desc="Send tokens to requestor") {
44514184Sgabeblack@google.com    // Only send a message if we have tokens to send
44614184Sgabeblack@google.com    if (getDirectoryEntry(address).Tokens > 0) {
44714184Sgabeblack@google.com      peek(requestNetwork_in, RequestMsg) {
44814184Sgabeblack@google.com        enqueue(responseNetwork_out, ResponseMsg, directory_latency) {// FIXME?
44914184Sgabeblack@google.com          out_msg.addr := address;
45014184Sgabeblack@google.com          out_msg.Type := CoherenceResponseType:ACK;
45114184Sgabeblack@google.com          out_msg.Sender := machineID;
45214184Sgabeblack@google.com          out_msg.Destination.add(in_msg.Requestor);
45314184Sgabeblack@google.com          out_msg.Tokens := getDirectoryEntry(in_msg.addr).Tokens;
45414184Sgabeblack@google.com          out_msg.MessageSize := MessageSizeType:Response_Control;
45514184Sgabeblack@google.com        }
45614184Sgabeblack@google.com      }
45714184Sgabeblack@google.com      getDirectoryEntry(address).Tokens := 0;
45814184Sgabeblack@google.com    }
45914184Sgabeblack@google.com  }
46014184Sgabeblack@google.com
46114184Sgabeblack@google.com  action(px_tryIssuingPersistentGETXRequest, "px", desc="...") {
46214184Sgabeblack@google.com    if (okToIssueStarving(address, machineID) && (starving == false)) {
46314184Sgabeblack@google.com      enqueue(persistentNetwork_out, PersistentMsg, 1) {
46414184Sgabeblack@google.com        out_msg.addr := address;
46514184Sgabeblack@google.com        out_msg.Type := PersistentRequestType:GETX_PERSISTENT;
46614184Sgabeblack@google.com        out_msg.Requestor := machineID;
46714184Sgabeblack@google.com        out_msg.Destination.broadcast(MachineType:L1Cache);
46814184Sgabeblack@google.com
46914184Sgabeblack@google.com        //
47014184Sgabeblack@google.com        // Currently the configuration system limits the system to only one
47114184Sgabeblack@google.com        // chip.  Therefore, if we assume one shared L2 cache, then only one
47214184Sgabeblack@google.com        // pertinent L2 cache exist.
47314184Sgabeblack@google.com        //
47414184Sgabeblack@google.com        //out_msg.Destination.addNetDest(getAllPertinentL2Banks(address));
47514184Sgabeblack@google.com
47614184Sgabeblack@google.com        out_msg.Destination.add(mapAddressToRange(address,
47714184Sgabeblack@google.com                                  MachineType:L2Cache, l2_select_low_bit,
47814184Sgabeblack@google.com                                  l2_select_num_bits, intToID(0)));
47914184Sgabeblack@google.com
48014184Sgabeblack@google.com        out_msg.Destination.add(mapAddressToMachine(address, MachineType:Directory));
48114184Sgabeblack@google.com        out_msg.MessageSize := MessageSizeType:Persistent_Control;
48214184Sgabeblack@google.com        out_msg.Prefetch := PrefetchBit:No;
48314184Sgabeblack@google.com        out_msg.AccessMode := RubyAccessMode:Supervisor;
48414184Sgabeblack@google.com      }
48514184Sgabeblack@google.com      markPersistentEntries(address);
48614184Sgabeblack@google.com      starving := true;
48714184Sgabeblack@google.com
48814184Sgabeblack@google.com      tbe.WentPersistent := true;
48914184Sgabeblack@google.com
49014184Sgabeblack@google.com      // Do not schedule a wakeup, a persistent requests will always complete
49114184Sgabeblack@google.com    } else {
49214184Sgabeblack@google.com
49314184Sgabeblack@google.com      // We'd like to issue a persistent request, but are not allowed
49414184Sgabeblack@google.com      // to issue a P.R. right now.  This, we do not increment the
49514184Sgabeblack@google.com      // IssueCount.
49614184Sgabeblack@google.com
49714184Sgabeblack@google.com      // Set a wakeup timer
49814184Sgabeblack@google.com      reissueTimerTable.set(address, clockEdge(reissue_wakeup_latency));
49914184Sgabeblack@google.com    }
50014184Sgabeblack@google.com  }
50114184Sgabeblack@google.com
50214184Sgabeblack@google.com  action(bw_broadcastWrite, "bw", desc="Broadcast GETX if we need tokens") {
50314184Sgabeblack@google.com    peek(dmaRequestQueue_in, DMARequestMsg) {
50414184Sgabeblack@google.com      //
50514184Sgabeblack@google.com      // Assser that we only send message if we don't already have all the tokens
50614184Sgabeblack@google.com      //
50714184Sgabeblack@google.com      assert(getDirectoryEntry(address).Tokens != max_tokens());
50814184Sgabeblack@google.com      enqueue(requestNetwork_out, RequestMsg, 1) {
50914184Sgabeblack@google.com        out_msg.addr := address;
51014184Sgabeblack@google.com        out_msg.Type := CoherenceRequestType:GETX;
51114184Sgabeblack@google.com        out_msg.Requestor := machineID;
51214184Sgabeblack@google.com
51314184Sgabeblack@google.com        //
51414184Sgabeblack@google.com        // Since only one chip, assuming all L1 caches are local
51514184Sgabeblack@google.com        //
51614184Sgabeblack@google.com        out_msg.Destination.broadcast(MachineType:L1Cache);
51714184Sgabeblack@google.com        out_msg.Destination.add(mapAddressToRange(address,
51814184Sgabeblack@google.com                                  MachineType:L2Cache, l2_select_low_bit,
51914184Sgabeblack@google.com                                  l2_select_num_bits, intToID(0)));
52014184Sgabeblack@google.com
52114184Sgabeblack@google.com        out_msg.RetryNum := 0;
52214184Sgabeblack@google.com        out_msg.MessageSize := MessageSizeType:Broadcast_Control;
52314184Sgabeblack@google.com        out_msg.Prefetch := PrefetchBit:No;
52414184Sgabeblack@google.com        out_msg.AccessMode := RubyAccessMode:Supervisor;
52514184Sgabeblack@google.com      }
52614184Sgabeblack@google.com    }
52714184Sgabeblack@google.com  }
52814184Sgabeblack@google.com
52914184Sgabeblack@google.com  action(ps_tryIssuingPersistentGETSRequest, "ps", desc="...") {
53014184Sgabeblack@google.com    if (okToIssueStarving(address, machineID) && (starving == false)) {
53114184Sgabeblack@google.com      enqueue(persistentNetwork_out, PersistentMsg, 1) {
53214184Sgabeblack@google.com        out_msg.addr := address;
53314184Sgabeblack@google.com        out_msg.Type := PersistentRequestType:GETS_PERSISTENT;
53414184Sgabeblack@google.com        out_msg.Requestor := machineID;
53514184Sgabeblack@google.com        out_msg.Destination.broadcast(MachineType:L1Cache);
53614184Sgabeblack@google.com
53714184Sgabeblack@google.com        //
53814184Sgabeblack@google.com        // Currently the configuration system limits the system to only one
53914184Sgabeblack@google.com        // chip.  Therefore, if we assume one shared L2 cache, then only one
54014184Sgabeblack@google.com        // pertinent L2 cache exist.
54114184Sgabeblack@google.com        //
54214184Sgabeblack@google.com        //out_msg.Destination.addNetDest(getAllPertinentL2Banks(address));
54314184Sgabeblack@google.com
54414184Sgabeblack@google.com        out_msg.Destination.add(mapAddressToRange(address,
54514184Sgabeblack@google.com                                  MachineType:L2Cache, l2_select_low_bit,
54614184Sgabeblack@google.com                                  l2_select_num_bits, intToID(0)));
54714184Sgabeblack@google.com
54814184Sgabeblack@google.com        out_msg.Destination.add(mapAddressToMachine(address, MachineType:Directory));
54914184Sgabeblack@google.com        out_msg.MessageSize := MessageSizeType:Persistent_Control;
55014184Sgabeblack@google.com        out_msg.Prefetch := PrefetchBit:No;
55114184Sgabeblack@google.com        out_msg.AccessMode := RubyAccessMode:Supervisor;
55214184Sgabeblack@google.com      }
55314184Sgabeblack@google.com      markPersistentEntries(address);
55414184Sgabeblack@google.com      starving := true;
55514184Sgabeblack@google.com
55614184Sgabeblack@google.com      tbe.WentPersistent := true;
55714184Sgabeblack@google.com
55814184Sgabeblack@google.com      // Do not schedule a wakeup, a persistent requests will always complete
55914184Sgabeblack@google.com    } else {
56014184Sgabeblack@google.com
56114184Sgabeblack@google.com      // We'd like to issue a persistent request, but are not allowed
56214184Sgabeblack@google.com      // to issue a P.R. right now.  This, we do not increment the
56314184Sgabeblack@google.com      // IssueCount.
56414184Sgabeblack@google.com
56514184Sgabeblack@google.com      // Set a wakeup timer
56614184Sgabeblack@google.com      reissueTimerTable.set(address, clockEdge(reissue_wakeup_latency));
56714184Sgabeblack@google.com    }
56814184Sgabeblack@google.com  }
56914184Sgabeblack@google.com
57014184Sgabeblack@google.com  action(br_broadcastRead, "br", desc="Broadcast GETS for data") {
57114184Sgabeblack@google.com    peek(dmaRequestQueue_in, DMARequestMsg) {
57214184Sgabeblack@google.com      enqueue(requestNetwork_out, RequestMsg, 1) {
57314184Sgabeblack@google.com        out_msg.addr := address;
57414184Sgabeblack@google.com        out_msg.Type := CoherenceRequestType:GETS;
57514184Sgabeblack@google.com        out_msg.Requestor := machineID;
57614184Sgabeblack@google.com
57714184Sgabeblack@google.com        //
57814184Sgabeblack@google.com        // Since only one chip, assuming all L1 caches are local
57914184Sgabeblack@google.com        //
58014184Sgabeblack@google.com        out_msg.Destination.broadcast(MachineType:L1Cache);
58114184Sgabeblack@google.com        out_msg.Destination.add(mapAddressToRange(address,
58214184Sgabeblack@google.com                                  MachineType:L2Cache, l2_select_low_bit,
58314184Sgabeblack@google.com                                  l2_select_num_bits, intToID(0)));
58414184Sgabeblack@google.com
58514184Sgabeblack@google.com        out_msg.RetryNum := 0;
58614184Sgabeblack@google.com        out_msg.MessageSize := MessageSizeType:Broadcast_Control;
58714184Sgabeblack@google.com        out_msg.Prefetch := PrefetchBit:No;
58814184Sgabeblack@google.com        out_msg.AccessMode := RubyAccessMode:Supervisor;
58914184Sgabeblack@google.com      }
59014184Sgabeblack@google.com    }
59114184Sgabeblack@google.com  }
59214184Sgabeblack@google.com
59314184Sgabeblack@google.com  action(aa_sendTokensToStarver, "\a", desc="Send tokens to starver") {
59414184Sgabeblack@google.com    // Only send a message if we have tokens to send
59514184Sgabeblack@google.com    if (getDirectoryEntry(address).Tokens > 0) {
59614184Sgabeblack@google.com      enqueue(responseNetwork_out, ResponseMsg, directory_latency) {// FIXME?
59714184Sgabeblack@google.com        out_msg.addr := address;
59814184Sgabeblack@google.com        out_msg.Type := CoherenceResponseType:ACK;
59914184Sgabeblack@google.com        out_msg.Sender := machineID;
60014184Sgabeblack@google.com        out_msg.Destination.add(persistentTable.findSmallest(address));
60114184Sgabeblack@google.com        out_msg.Tokens := getDirectoryEntry(address).Tokens;
60214184Sgabeblack@google.com        out_msg.MessageSize := MessageSizeType:Response_Control;
60314184Sgabeblack@google.com      }
60414184Sgabeblack@google.com      getDirectoryEntry(address).Tokens := 0;
60514184Sgabeblack@google.com    }
60614184Sgabeblack@google.com  }
60714184Sgabeblack@google.com
60814184Sgabeblack@google.com  action(d_sendMemoryDataWithAllTokens, "d", desc="Send data and tokens to requestor") {
60914184Sgabeblack@google.com    peek(memQueue_in, MemoryMsg) {
61014184Sgabeblack@google.com      enqueue(responseNetwork_out, ResponseMsg, 1) {
61114184Sgabeblack@google.com        out_msg.addr := address;
61214184Sgabeblack@google.com        out_msg.Type := CoherenceResponseType:DATA_OWNER;
61314184Sgabeblack@google.com        out_msg.Sender := machineID;
61414184Sgabeblack@google.com        out_msg.Destination.add(in_msg.OriginalRequestorMachId);
61514184Sgabeblack@google.com        assert(getDirectoryEntry(address).Tokens > 0);
61614184Sgabeblack@google.com        out_msg.Tokens := getDirectoryEntry(in_msg.addr).Tokens;
61714184Sgabeblack@google.com        out_msg.DataBlk := in_msg.DataBlk;
61814184Sgabeblack@google.com        out_msg.Dirty := false;
61914184Sgabeblack@google.com        out_msg.MessageSize := MessageSizeType:Response_Data;
62014184Sgabeblack@google.com      }
62114184Sgabeblack@google.com    }
62214184Sgabeblack@google.com    getDirectoryEntry(address).Tokens := 0;
62314184Sgabeblack@google.com  }
62414184Sgabeblack@google.com
62514184Sgabeblack@google.com  action(dd_sendMemDataToStarver, "\d", desc="Send data and tokens to starver") {
62614184Sgabeblack@google.com    peek(memQueue_in, MemoryMsg) {
62714184Sgabeblack@google.com      enqueue(responseNetwork_out, ResponseMsg, 1) {
62814184Sgabeblack@google.com        out_msg.addr := address;
62914184Sgabeblack@google.com        out_msg.Type := CoherenceResponseType:DATA_OWNER;
63014184Sgabeblack@google.com        out_msg.Sender := machineID;
63114184Sgabeblack@google.com        out_msg.Destination.add(persistentTable.findSmallest(address));
63214184Sgabeblack@google.com        assert(getDirectoryEntry(address).Tokens > 0);
63314184Sgabeblack@google.com        out_msg.Tokens := getDirectoryEntry(address).Tokens;
63414184Sgabeblack@google.com        out_msg.DataBlk := in_msg.DataBlk;
63514184Sgabeblack@google.com        out_msg.Dirty := false;
63614184Sgabeblack@google.com        out_msg.MessageSize := MessageSizeType:Response_Data;
63714184Sgabeblack@google.com      }
63814184Sgabeblack@google.com    }
63914184Sgabeblack@google.com    getDirectoryEntry(address).Tokens := 0;
64014184Sgabeblack@google.com  }
64114184Sgabeblack@google.com
64214184Sgabeblack@google.com  action(de_sendTbeDataToStarver, "de", desc="Send data and tokens to starver") {
64314184Sgabeblack@google.com    enqueue(responseNetwork_out, ResponseMsg, 1) {
64414184Sgabeblack@google.com      out_msg.addr := address;
64514184Sgabeblack@google.com      out_msg.Type := CoherenceResponseType:DATA_OWNER;
64614184Sgabeblack@google.com      out_msg.Sender := machineID;
64714184Sgabeblack@google.com      out_msg.Destination.add(persistentTable.findSmallest(address));
64814184Sgabeblack@google.com      assert(getDirectoryEntry(address).Tokens > 0);
64914184Sgabeblack@google.com      out_msg.Tokens := getDirectoryEntry(address).Tokens;
65014184Sgabeblack@google.com      out_msg.DataBlk := tbe.DataBlk;
65114184Sgabeblack@google.com      out_msg.Dirty := false;
65214184Sgabeblack@google.com      out_msg.MessageSize := MessageSizeType:Response_Data;
65314184Sgabeblack@google.com    }
65414184Sgabeblack@google.com    getDirectoryEntry(address).Tokens := 0;
65514184Sgabeblack@google.com  }
65614184Sgabeblack@google.com
65714184Sgabeblack@google.com  action(qf_queueMemoryFetchRequest, "qf", desc="Queue off-chip fetch request") {
65814184Sgabeblack@google.com    peek(requestNetwork_in, RequestMsg) {
65914184Sgabeblack@google.com      queueMemoryRead(in_msg.Requestor, address, to_memory_controller_latency);
66014184Sgabeblack@google.com    }
66114184Sgabeblack@google.com  }
66214184Sgabeblack@google.com
66314184Sgabeblack@google.com  action(qp_queueMemoryForPersistent, "qp", desc="Queue off-chip fetch request") {
66414184Sgabeblack@google.com    queueMemoryRead(persistentTable.findSmallest(address), address,
66514184Sgabeblack@google.com                    to_memory_controller_latency);
66614184Sgabeblack@google.com  }
66714184Sgabeblack@google.com
66814184Sgabeblack@google.com  action(fd_memoryDma, "fd", desc="Queue off-chip fetch request") {
66914184Sgabeblack@google.com    peek(dmaRequestQueue_in, DMARequestMsg) {
67014184Sgabeblack@google.com      queueMemoryRead(in_msg.Requestor, address, to_memory_controller_latency);
67114184Sgabeblack@google.com    }
67214184Sgabeblack@google.com  }
67314184Sgabeblack@google.com
67414184Sgabeblack@google.com  action(lq_queueMemoryWbRequest, "lq", desc="Write data to memory") {
67514184Sgabeblack@google.com    peek(responseNetwork_in, ResponseMsg) {
67614184Sgabeblack@google.com      queueMemoryWrite(in_msg.Sender, address, to_memory_controller_latency,
67714184Sgabeblack@google.com                       in_msg.DataBlk);
67814184Sgabeblack@google.com    }
67914184Sgabeblack@google.com  }
68014184Sgabeblack@google.com
68114184Sgabeblack@google.com  action(ld_queueMemoryDmaWriteFromTbe, "ld", desc="Write DMA data to memory") {
68214184Sgabeblack@google.com    queueMemoryWritePartial(tbe.DmaRequestor, address,
68314184Sgabeblack@google.com                            to_memory_controller_latency, tbe.DataBlk,
68414184Sgabeblack@google.com                            tbe.Len);
68514184Sgabeblack@google.com  }
68614184Sgabeblack@google.com
68714184Sgabeblack@google.com  action(lr_queueMemoryDmaReadWriteback, "lr",
68814184Sgabeblack@google.com         desc="Write DMA data from read to memory") {
68914184Sgabeblack@google.com    peek(responseNetwork_in, ResponseMsg) {
69014184Sgabeblack@google.com      queueMemoryWrite(machineID, address, to_memory_controller_latency,
69114184Sgabeblack@google.com                       in_msg.DataBlk);
69214184Sgabeblack@google.com    }
69314184Sgabeblack@google.com  }
69414184Sgabeblack@google.com
69514184Sgabeblack@google.com  action(vd_allocateDmaRequestInTBE, "vd", desc="Record Data in TBE") {
69614184Sgabeblack@google.com    peek(dmaRequestQueue_in, DMARequestMsg) {
69714184Sgabeblack@google.com      TBEs.allocate(address);
69814184Sgabeblack@google.com      set_tbe(TBEs[address]);
69914184Sgabeblack@google.com      tbe.DataBlk := in_msg.DataBlk;
70014184Sgabeblack@google.com      tbe.PhysicalAddress := in_msg.PhysicalAddress;
70114184Sgabeblack@google.com      tbe.Len := in_msg.Len;
70214184Sgabeblack@google.com      tbe.DmaRequestor := in_msg.Requestor;
70314184Sgabeblack@google.com      tbe.WentPersistent := false;
70414184Sgabeblack@google.com    }
70514184Sgabeblack@google.com  }
70614184Sgabeblack@google.com
70714184Sgabeblack@google.com  action(s_deallocateTBE, "s", desc="Deallocate TBE") {
70814184Sgabeblack@google.com
70914184Sgabeblack@google.com    if (tbe.WentPersistent) {
71014184Sgabeblack@google.com      assert(starving);
71114184Sgabeblack@google.com
71214184Sgabeblack@google.com      enqueue(persistentNetwork_out, PersistentMsg, 1) {
71314184Sgabeblack@google.com        out_msg.addr := address;
71414184Sgabeblack@google.com        out_msg.Type := PersistentRequestType:DEACTIVATE_PERSISTENT;
71514184Sgabeblack@google.com        out_msg.Requestor := machineID;
71614184Sgabeblack@google.com        out_msg.Destination.broadcast(MachineType:L1Cache);
71714184Sgabeblack@google.com
71814184Sgabeblack@google.com        //
71914184Sgabeblack@google.com        // Currently the configuration system limits the system to only one
72014184Sgabeblack@google.com        // chip.  Therefore, if we assume one shared L2 cache, then only one
72114184Sgabeblack@google.com        // pertinent L2 cache exist.
72214184Sgabeblack@google.com        //
72314184Sgabeblack@google.com        //out_msg.Destination.addNetDest(getAllPertinentL2Banks(address));
72414184Sgabeblack@google.com
72514184Sgabeblack@google.com        out_msg.Destination.add(mapAddressToRange(address,
72614184Sgabeblack@google.com                                  MachineType:L2Cache, l2_select_low_bit,
72714184Sgabeblack@google.com                                  l2_select_num_bits, intToID(0)));
72814184Sgabeblack@google.com
72914184Sgabeblack@google.com        out_msg.Destination.add(mapAddressToMachine(address, MachineType:Directory));
73014184Sgabeblack@google.com        out_msg.MessageSize := MessageSizeType:Persistent_Control;
73114184Sgabeblack@google.com      }
73214184Sgabeblack@google.com      starving := false;
73314184Sgabeblack@google.com    }
73414184Sgabeblack@google.com
73514184Sgabeblack@google.com    TBEs.deallocate(address);
73614184Sgabeblack@google.com    unset_tbe();
73714184Sgabeblack@google.com  }
73814184Sgabeblack@google.com
73914184Sgabeblack@google.com  action(rd_recordDataInTbe, "rd", desc="Record data in TBE") {
74014184Sgabeblack@google.com    peek(responseNetwork_in, ResponseMsg) {
74114184Sgabeblack@google.com      DataBlock DataBlk := tbe.DataBlk;
74214184Sgabeblack@google.com      tbe.DataBlk := in_msg.DataBlk;
74314184Sgabeblack@google.com      tbe.DataBlk.copyPartial(DataBlk, getOffset(tbe.PhysicalAddress),
74414184Sgabeblack@google.com                              tbe.Len);
74514184Sgabeblack@google.com    }
74614184Sgabeblack@google.com  }
74714184Sgabeblack@google.com
74814184Sgabeblack@google.com  action(f_incrementTokens, "f", desc="Increment the number of tokens we're tracking") {
74914184Sgabeblack@google.com    peek(responseNetwork_in, ResponseMsg) {
75014184Sgabeblack@google.com      assert(in_msg.Tokens >= 1);
75114184Sgabeblack@google.com      getDirectoryEntry(address).Tokens := getDirectoryEntry(address).Tokens + in_msg.Tokens;
75214184Sgabeblack@google.com    }
75314184Sgabeblack@google.com  }
75414184Sgabeblack@google.com
75514184Sgabeblack@google.com  action(aat_assertAllTokens, "aat", desc="assert that we have all tokens") {
75614184Sgabeblack@google.com    assert(getDirectoryEntry(address).Tokens == max_tokens());
75714184Sgabeblack@google.com  }
75814184Sgabeblack@google.com
75914184Sgabeblack@google.com  action(j_popIncomingRequestQueue, "j", desc="Pop incoming request queue") {
76014184Sgabeblack@google.com    requestNetwork_in.dequeue(clockEdge());
76114184Sgabeblack@google.com  }
76214184Sgabeblack@google.com
76314184Sgabeblack@google.com  action(z_recycleRequest, "z", desc="Recycle the request queue") {
76414184Sgabeblack@google.com    requestNetwork_in.recycle(clockEdge(), cyclesToTicks(recycle_latency));
76514184Sgabeblack@google.com  }
76614184Sgabeblack@google.com
76714184Sgabeblack@google.com  action(k_popIncomingResponseQueue, "k", desc="Pop incoming response queue") {
76814184Sgabeblack@google.com    responseNetwork_in.dequeue(clockEdge());
76914184Sgabeblack@google.com  }
77014184Sgabeblack@google.com
77114184Sgabeblack@google.com  action(kz_recycleResponse, "kz", desc="Recycle incoming response queue") {
77214184Sgabeblack@google.com    responseNetwork_in.recycle(clockEdge(), cyclesToTicks(recycle_latency));
77314184Sgabeblack@google.com  }
77414184Sgabeblack@google.com
77514184Sgabeblack@google.com  action(l_popIncomingPersistentQueue, "l", desc="Pop incoming persistent queue") {
77614184Sgabeblack@google.com    persistentNetwork_in.dequeue(clockEdge());
77714184Sgabeblack@google.com  }
77814184Sgabeblack@google.com
77914184Sgabeblack@google.com  action(p_popDmaRequestQueue, "pd", desc="pop dma request queue") {
78014184Sgabeblack@google.com    dmaRequestQueue_in.dequeue(clockEdge());
78114184Sgabeblack@google.com  }
78214184Sgabeblack@google.com
78314184Sgabeblack@google.com  action(y_recycleDmaRequestQueue, "y", desc="recycle dma request queue") {
78414184Sgabeblack@google.com    dmaRequestQueue_in.recycle(clockEdge(), cyclesToTicks(recycle_latency));
78514184Sgabeblack@google.com  }
78614184Sgabeblack@google.com
78714184Sgabeblack@google.com  action(l_popMemQueue, "q", desc="Pop off-chip request queue") {
78814184Sgabeblack@google.com    memQueue_in.dequeue(clockEdge());
78914184Sgabeblack@google.com  }
79014184Sgabeblack@google.com
79114184Sgabeblack@google.com  action(r_bounceResponse, "r", desc="Bounce response to starving processor") {
79214184Sgabeblack@google.com    peek(responseNetwork_in, ResponseMsg) {
79314184Sgabeblack@google.com      enqueue(responseNetwork_out, ResponseMsg, 1) {
79414184Sgabeblack@google.com        out_msg.addr := address;
79514184Sgabeblack@google.com        out_msg.Type := in_msg.Type;
79614184Sgabeblack@google.com        out_msg.Sender := machineID;
79714184Sgabeblack@google.com        out_msg.Destination.add(persistentTable.findSmallest(address));
79814184Sgabeblack@google.com        out_msg.Tokens := in_msg.Tokens;
79914184Sgabeblack@google.com        out_msg.MessageSize := in_msg.MessageSize;
80014184Sgabeblack@google.com        out_msg.DataBlk := in_msg.DataBlk;
80114184Sgabeblack@google.com        out_msg.Dirty := in_msg.Dirty;
80214184Sgabeblack@google.com      }
80314184Sgabeblack@google.com    }
80414184Sgabeblack@google.com  }
80514184Sgabeblack@google.com
80614184Sgabeblack@google.com  action(rs_resetScheduleTimeout, "rs", desc="Reschedule Schedule Timeout") {
80714184Sgabeblack@google.com    //
80814184Sgabeblack@google.com    // currently only support a fixed timeout latency
80914184Sgabeblack@google.com    //
81014184Sgabeblack@google.com    if (reissueTimerTable.isSet(address)) {
81114184Sgabeblack@google.com      reissueTimerTable.unset(address);
81214184Sgabeblack@google.com      reissueTimerTable.set(address, clockEdge(fixed_timeout_latency));
81314184Sgabeblack@google.com    }
81414184Sgabeblack@google.com  }
81514184Sgabeblack@google.com
81614184Sgabeblack@google.com  action(st_scheduleTimeout, "st", desc="Schedule Timeout") {
81714184Sgabeblack@google.com    //
81814184Sgabeblack@google.com    // currently only support a fixed timeout latency
81914184Sgabeblack@google.com    //
82014184Sgabeblack@google.com    reissueTimerTable.set(address, clockEdge(fixed_timeout_latency));
82114184Sgabeblack@google.com  }
82214184Sgabeblack@google.com
82314184Sgabeblack@google.com  action(ut_unsetReissueTimer, "ut", desc="Unset reissue timer.") {
82414184Sgabeblack@google.com    if (reissueTimerTable.isSet(address)) {
82514184Sgabeblack@google.com      reissueTimerTable.unset(address);
82614184Sgabeblack@google.com    }
82714184Sgabeblack@google.com  }
82814184Sgabeblack@google.com
82914184Sgabeblack@google.com  action(bd_bounceDatalessOwnerToken, "bd", desc="Bounce clean owner token to starving processor") {
83014184Sgabeblack@google.com    peek(responseNetwork_in, ResponseMsg) {
83114184Sgabeblack@google.com      assert(in_msg.Type == CoherenceResponseType:ACK_OWNER);
83214184Sgabeblack@google.com      assert(in_msg.Dirty == false);
83314184Sgabeblack@google.com      assert(in_msg.MessageSize == MessageSizeType:Writeback_Control);
83414184Sgabeblack@google.com
83514184Sgabeblack@google.com      // Bounce the message, but "re-associate" the data and the owner
83614184Sgabeblack@google.com      // token.  In essence we're converting an ACK_OWNER message to a
83714184Sgabeblack@google.com      // DATA_OWNER message, keeping the number of tokens the same.
83814184Sgabeblack@google.com      enqueue(responseNetwork_out, ResponseMsg, 1) {
83914184Sgabeblack@google.com        out_msg.addr := address;
84014184Sgabeblack@google.com        out_msg.Type := CoherenceResponseType:DATA_OWNER;
84114184Sgabeblack@google.com        out_msg.Sender := machineID;
84214184Sgabeblack@google.com        out_msg.Destination.add(persistentTable.findSmallest(address));
84314184Sgabeblack@google.com        out_msg.Tokens := in_msg.Tokens;
84414184Sgabeblack@google.com        out_msg.Dirty := in_msg.Dirty;
84514184Sgabeblack@google.com        out_msg.MessageSize := MessageSizeType:Response_Data;
84614184Sgabeblack@google.com      }
84714184Sgabeblack@google.com    }
84814184Sgabeblack@google.com  }
84914184Sgabeblack@google.com
85014184Sgabeblack@google.com  action(da_sendDmaAck, "da", desc="Send Ack to DMA controller") {
85114184Sgabeblack@google.com    enqueue(dmaResponseNetwork_out, DMAResponseMsg, 1) {
85214184Sgabeblack@google.com      out_msg.PhysicalAddress := address;
85314184Sgabeblack@google.com      out_msg.LineAddress := address;
85414184Sgabeblack@google.com      out_msg.Type := DMAResponseType:ACK;
85514184Sgabeblack@google.com      out_msg.Destination.add(tbe.DmaRequestor);
85614184Sgabeblack@google.com      out_msg.MessageSize := MessageSizeType:Writeback_Control;
85714184Sgabeblack@google.com    }
85814184Sgabeblack@google.com  }
85914184Sgabeblack@google.com
86014184Sgabeblack@google.com  action(dm_sendMemoryDataToDma, "dm", desc="Send Data to DMA controller from memory") {
86114184Sgabeblack@google.com    peek(memQueue_in, MemoryMsg) {
86214184Sgabeblack@google.com      enqueue(dmaResponseNetwork_out, DMAResponseMsg, 1) {
86314184Sgabeblack@google.com        out_msg.PhysicalAddress := address;
86414184Sgabeblack@google.com        out_msg.LineAddress := address;
86514184Sgabeblack@google.com        out_msg.Type := DMAResponseType:DATA;
86614184Sgabeblack@google.com        //
86714184Sgabeblack@google.com        // we send the entire data block and rely on the dma controller to
86814184Sgabeblack@google.com        // split it up if need be
86914184Sgabeblack@google.com        //
87014184Sgabeblack@google.com        out_msg.DataBlk := in_msg.DataBlk;
87114184Sgabeblack@google.com        out_msg.Destination.add(tbe.DmaRequestor);
87214184Sgabeblack@google.com        out_msg.MessageSize := MessageSizeType:Response_Data;
87314184Sgabeblack@google.com      }
87414184Sgabeblack@google.com    }
87514184Sgabeblack@google.com  }
87614184Sgabeblack@google.com
87714184Sgabeblack@google.com  action(dd_sendDmaData, "dd", desc="Send Data to DMA controller") {
87814184Sgabeblack@google.com    peek(responseNetwork_in, ResponseMsg) {
87914184Sgabeblack@google.com      enqueue(dmaResponseNetwork_out, DMAResponseMsg, 1) {
88014184Sgabeblack@google.com        out_msg.PhysicalAddress := address;
88114184Sgabeblack@google.com        out_msg.LineAddress := address;
88214184Sgabeblack@google.com        out_msg.Type := DMAResponseType:DATA;
88314184Sgabeblack@google.com        //
88414184Sgabeblack@google.com        // we send the entire data block and rely on the dma controller to
88514184Sgabeblack@google.com        // split it up if need be
88614184Sgabeblack@google.com        //
88714184Sgabeblack@google.com        out_msg.DataBlk := in_msg.DataBlk;
88814184Sgabeblack@google.com        out_msg.Destination.add(tbe.DmaRequestor);
88914184Sgabeblack@google.com        out_msg.MessageSize := MessageSizeType:Response_Data;
89014184Sgabeblack@google.com      }
89114184Sgabeblack@google.com    }
89214184Sgabeblack@google.com  }
89314184Sgabeblack@google.com
89414184Sgabeblack@google.com  // TRANSITIONS
89514184Sgabeblack@google.com
89614184Sgabeblack@google.com  //
89714184Sgabeblack@google.com  // Trans. from base state O
89814184Sgabeblack@google.com  // the directory has valid data
89914184Sgabeblack@google.com  //
90014184Sgabeblack@google.com  transition(O, GETX, NO_W) {
90114184Sgabeblack@google.com    qf_queueMemoryFetchRequest;
90214184Sgabeblack@google.com    j_popIncomingRequestQueue;
90314184Sgabeblack@google.com  }
90414184Sgabeblack@google.com
90514184Sgabeblack@google.com  transition(O, DMA_WRITE, O_DW) {
90614184Sgabeblack@google.com    vd_allocateDmaRequestInTBE;
90714184Sgabeblack@google.com    bw_broadcastWrite;
90814184Sgabeblack@google.com    st_scheduleTimeout;
90914184Sgabeblack@google.com    p_popDmaRequestQueue;
91014184Sgabeblack@google.com  }
91114184Sgabeblack@google.com
91214184Sgabeblack@google.com  transition(O, DMA_WRITE_All_Tokens, O_DW_W) {
91314184Sgabeblack@google.com    vd_allocateDmaRequestInTBE;
91414184Sgabeblack@google.com    ld_queueMemoryDmaWriteFromTbe;
91514184Sgabeblack@google.com    p_popDmaRequestQueue;
91614184Sgabeblack@google.com  }
91714184Sgabeblack@google.com
91814184Sgabeblack@google.com  transition(O, GETS, NO_W) {
91914184Sgabeblack@google.com    qf_queueMemoryFetchRequest;
92014184Sgabeblack@google.com    j_popIncomingRequestQueue;
92114184Sgabeblack@google.com  }
92214184Sgabeblack@google.com
92314184Sgabeblack@google.com  transition(O, DMA_READ, O_DR_W) {
92414184Sgabeblack@google.com    vd_allocateDmaRequestInTBE;
92514184Sgabeblack@google.com    fd_memoryDma;
92614184Sgabeblack@google.com    st_scheduleTimeout;
92714184Sgabeblack@google.com    p_popDmaRequestQueue;
92814184Sgabeblack@google.com  }
92914184Sgabeblack@google.com
93014184Sgabeblack@google.com  transition(O, Lockdown, L_O_W) {
93114184Sgabeblack@google.com    qp_queueMemoryForPersistent;
93214184Sgabeblack@google.com    l_popIncomingPersistentQueue;
93314184Sgabeblack@google.com  }
93414184Sgabeblack@google.com
93514184Sgabeblack@google.com  transition(O, {Tokens, Ack_All_Tokens}) {
93614184Sgabeblack@google.com    f_incrementTokens;
93714184Sgabeblack@google.com    k_popIncomingResponseQueue;
93814184Sgabeblack@google.com  }
93914184Sgabeblack@google.com
94014184Sgabeblack@google.com  transition(O, {Data_Owner, Data_All_Tokens}) {
94114184Sgabeblack@google.com    f_incrementTokens;
94214184Sgabeblack@google.com    k_popIncomingResponseQueue;
94314184Sgabeblack@google.com  }
94414184Sgabeblack@google.com
94514184Sgabeblack@google.com  transition({O, NO}, Unlockdown) {
94614184Sgabeblack@google.com    l_popIncomingPersistentQueue;
94714184Sgabeblack@google.com  }
94814184Sgabeblack@google.com
94914184Sgabeblack@google.com  //
95014184Sgabeblack@google.com  // transitioning to Owner, waiting for memory before DMA ack
95114184Sgabeblack@google.com  // All other events should recycle/stall
95214184Sgabeblack@google.com  //
95314184Sgabeblack@google.com  transition(O_DR_W, Memory_Data, O) {
95414184Sgabeblack@google.com    dm_sendMemoryDataToDma;
95514184Sgabeblack@google.com    ut_unsetReissueTimer;
95614184Sgabeblack@google.com    s_deallocateTBE;
95714184Sgabeblack@google.com    l_popMemQueue;
95814184Sgabeblack@google.com  }
95914184Sgabeblack@google.com
96014184Sgabeblack@google.com  //
96114184Sgabeblack@google.com  // issued GETX for DMA write, waiting for all tokens
96214184Sgabeblack@google.com  //
96314184Sgabeblack@google.com  transition(O_DW, Request_Timeout) {
96414184Sgabeblack@google.com    ut_unsetReissueTimer;
96514184Sgabeblack@google.com    px_tryIssuingPersistentGETXRequest;
96614184Sgabeblack@google.com  }
96714184Sgabeblack@google.com
96814184Sgabeblack@google.com  transition(O_DW, Tokens) {
96914184Sgabeblack@google.com    f_incrementTokens;
97014184Sgabeblack@google.com    k_popIncomingResponseQueue;
97114184Sgabeblack@google.com  }
97214184Sgabeblack@google.com
97314184Sgabeblack@google.com  transition(O_DW, Data_Owner) {
97414184Sgabeblack@google.com    f_incrementTokens;
97514184Sgabeblack@google.com    rd_recordDataInTbe;
97614184Sgabeblack@google.com    k_popIncomingResponseQueue;
97714184Sgabeblack@google.com  }
97814184Sgabeblack@google.com
97914184Sgabeblack@google.com  transition(O_DW, Ack_Owner) {
98014184Sgabeblack@google.com    f_incrementTokens;
98114184Sgabeblack@google.com    k_popIncomingResponseQueue;
98214184Sgabeblack@google.com  }
98314184Sgabeblack@google.com
98414184Sgabeblack@google.com  transition(O_DW, Lockdown, DW_L) {
98514184Sgabeblack@google.com    de_sendTbeDataToStarver;
98614184Sgabeblack@google.com    l_popIncomingPersistentQueue;
98714184Sgabeblack@google.com  }
98814184Sgabeblack@google.com
98914184Sgabeblack@google.com  transition({NO_DW, O_DW}, Data_All_Tokens, O_DW_W) {
99014184Sgabeblack@google.com    f_incrementTokens;
99114184Sgabeblack@google.com    rd_recordDataInTbe;
99214184Sgabeblack@google.com    ld_queueMemoryDmaWriteFromTbe;
99314184Sgabeblack@google.com    ut_unsetReissueTimer;
99414184Sgabeblack@google.com    k_popIncomingResponseQueue;
99514184Sgabeblack@google.com  }
99614184Sgabeblack@google.com
99714184Sgabeblack@google.com  transition(O_DW, Ack_All_Tokens, O_DW_W) {
99814184Sgabeblack@google.com    f_incrementTokens;
99914184Sgabeblack@google.com    ld_queueMemoryDmaWriteFromTbe;
100014184Sgabeblack@google.com    ut_unsetReissueTimer;
100114184Sgabeblack@google.com    k_popIncomingResponseQueue;
100214184Sgabeblack@google.com  }
100314184Sgabeblack@google.com
100414184Sgabeblack@google.com  transition(O_DW, Ack_Owner_All_Tokens, O_DW_W) {
100514184Sgabeblack@google.com    f_incrementTokens;
100614184Sgabeblack@google.com    ld_queueMemoryDmaWriteFromTbe;
100714184Sgabeblack@google.com    ut_unsetReissueTimer;
100814184Sgabeblack@google.com    k_popIncomingResponseQueue;
100914184Sgabeblack@google.com  }
101014184Sgabeblack@google.com
101114184Sgabeblack@google.com  transition(O_DW_W, Memory_Ack, O) {
101214184Sgabeblack@google.com    da_sendDmaAck;
101314184Sgabeblack@google.com    s_deallocateTBE;
101414184Sgabeblack@google.com    l_popMemQueue;
101514184Sgabeblack@google.com  }
101614184Sgabeblack@google.com
101714184Sgabeblack@google.com  //
101814184Sgabeblack@google.com  // Trans. from NO
101914184Sgabeblack@google.com  // The direcotry does not have valid data, but may have some tokens
102014184Sgabeblack@google.com  //
102114184Sgabeblack@google.com  transition(NO, GETX) {
102214184Sgabeblack@google.com    a_sendTokens;
102314184Sgabeblack@google.com    j_popIncomingRequestQueue;
102414184Sgabeblack@google.com  }
102514184Sgabeblack@google.com
102614184Sgabeblack@google.com  transition(NO, DMA_WRITE, NO_DW) {
102714184Sgabeblack@google.com    vd_allocateDmaRequestInTBE;
102814184Sgabeblack@google.com    bw_broadcastWrite;
102914184Sgabeblack@google.com    st_scheduleTimeout;
103014184Sgabeblack@google.com    p_popDmaRequestQueue;
103114184Sgabeblack@google.com  }
103214184Sgabeblack@google.com
103314184Sgabeblack@google.com  transition(NO, GETS) {
103414184Sgabeblack@google.com    j_popIncomingRequestQueue;
103514184Sgabeblack@google.com  }
103614184Sgabeblack@google.com
103714184Sgabeblack@google.com  transition(NO, DMA_READ, NO_DR) {
103814184Sgabeblack@google.com    vd_allocateDmaRequestInTBE;
103914184Sgabeblack@google.com    br_broadcastRead;
104014184Sgabeblack@google.com    st_scheduleTimeout;
104114184Sgabeblack@google.com    p_popDmaRequestQueue;
104214184Sgabeblack@google.com  }
104314184Sgabeblack@google.com
104414184Sgabeblack@google.com  transition(NO, Lockdown, L) {
104514184Sgabeblack@google.com    aa_sendTokensToStarver;
104614184Sgabeblack@google.com    l_popIncomingPersistentQueue;
104714184Sgabeblack@google.com  }
104814184Sgabeblack@google.com
104914184Sgabeblack@google.com  transition(NO, {Data_Owner, Data_All_Tokens}, O_W) {
105014184Sgabeblack@google.com    f_incrementTokens;
105114184Sgabeblack@google.com    lq_queueMemoryWbRequest;
105214184Sgabeblack@google.com    k_popIncomingResponseQueue;
105314184Sgabeblack@google.com  }
105414184Sgabeblack@google.com
105514184Sgabeblack@google.com  transition(NO, {Ack_Owner, Ack_Owner_All_Tokens}, O) {
105614184Sgabeblack@google.com    f_incrementTokens;
105714184Sgabeblack@google.com    k_popIncomingResponseQueue;
105814184Sgabeblack@google.com  }
105914184Sgabeblack@google.com
106014184Sgabeblack@google.com  transition(NO, Tokens) {
106114184Sgabeblack@google.com    f_incrementTokens;
106214184Sgabeblack@google.com    k_popIncomingResponseQueue;
106314184Sgabeblack@google.com  }
106414184Sgabeblack@google.com
106514184Sgabeblack@google.com  transition(NO_W, Memory_Data, NO) {
106614184Sgabeblack@google.com    d_sendMemoryDataWithAllTokens;
106714184Sgabeblack@google.com    l_popMemQueue;
106814184Sgabeblack@google.com  }
106914184Sgabeblack@google.com
107014184Sgabeblack@google.com  // Trans. from NO_DW
107114184Sgabeblack@google.com  transition(NO_DW, Request_Timeout) {
107214184Sgabeblack@google.com    ut_unsetReissueTimer;
107314184Sgabeblack@google.com    px_tryIssuingPersistentGETXRequest;
107414184Sgabeblack@google.com  }
107514184Sgabeblack@google.com
107614184Sgabeblack@google.com  transition(NO_DW, Lockdown, DW_L) {
107714184Sgabeblack@google.com    aa_sendTokensToStarver;
107814184Sgabeblack@google.com    l_popIncomingPersistentQueue;
107914184Sgabeblack@google.com  }
108014184Sgabeblack@google.com
108114184Sgabeblack@google.com  // Note: NO_DW, Data_All_Tokens transition is combined with O_DW
108214184Sgabeblack@google.com  // Note: NO_DW should not receive the action Ack_All_Tokens because the
108314184Sgabeblack@google.com  // directory does not have valid data
108414184Sgabeblack@google.com
108514184Sgabeblack@google.com  transition(NO_DW, Data_Owner, O_DW) {
108614184Sgabeblack@google.com    f_incrementTokens;
108714184Sgabeblack@google.com    rd_recordDataInTbe;
108814184Sgabeblack@google.com    k_popIncomingResponseQueue;
108914184Sgabeblack@google.com  }
109014184Sgabeblack@google.com
109114184Sgabeblack@google.com  transition({NO_DW, NO_DR}, Tokens) {
109214184Sgabeblack@google.com    f_incrementTokens;
109314184Sgabeblack@google.com    k_popIncomingResponseQueue;
109414184Sgabeblack@google.com  }
109514184Sgabeblack@google.com
109614184Sgabeblack@google.com  // Trans. from NO_DR
109714184Sgabeblack@google.com  transition(NO_DR, Request_Timeout) {
109814184Sgabeblack@google.com    ut_unsetReissueTimer;
109914184Sgabeblack@google.com    ps_tryIssuingPersistentGETSRequest;
110014184Sgabeblack@google.com  }
110114184Sgabeblack@google.com
110214184Sgabeblack@google.com  transition(NO_DR, Lockdown, DR_L) {
110314184Sgabeblack@google.com    aa_sendTokensToStarver;
110414184Sgabeblack@google.com    l_popIncomingPersistentQueue;
110514184Sgabeblack@google.com  }
110614184Sgabeblack@google.com
110714184Sgabeblack@google.com  transition(NO_DR, {Data_Owner, Data_All_Tokens}, O_W) {
110814184Sgabeblack@google.com    f_incrementTokens;
110914184Sgabeblack@google.com    dd_sendDmaData;
111014184Sgabeblack@google.com    lr_queueMemoryDmaReadWriteback;
111114184Sgabeblack@google.com    ut_unsetReissueTimer;
111214184Sgabeblack@google.com    s_deallocateTBE;
111314184Sgabeblack@google.com    k_popIncomingResponseQueue;
111414184Sgabeblack@google.com  }
111514184Sgabeblack@google.com
111614184Sgabeblack@google.com  // Trans. from L
111714184Sgabeblack@google.com  transition({L, DW_L, DR_L}, {GETX, GETS}) {
111814184Sgabeblack@google.com    j_popIncomingRequestQueue;
111914184Sgabeblack@google.com  }
112014184Sgabeblack@google.com
112114184Sgabeblack@google.com  transition({L, DW_L, DR_L, L_O_W, L_NO_W, DR_L_W, DW_L_W}, Lockdown) {
112214184Sgabeblack@google.com    l_popIncomingPersistentQueue;
112314184Sgabeblack@google.com  }
112414184Sgabeblack@google.com
112514184Sgabeblack@google.com  //
112614184Sgabeblack@google.com  // Received data for lockdown blocks
112714184Sgabeblack@google.com  // For blocks with outstanding dma requests to them
112814184Sgabeblack@google.com  // ...we could change this to write the data to memory and send it cleanly
112914184Sgabeblack@google.com  // ...we could also proactively complete our DMA requests
113014184Sgabeblack@google.com  // However, to keep my mind from spinning out-of-control, we won't for now :)
113114184Sgabeblack@google.com  //
113214184Sgabeblack@google.com  transition({DW_L, DR_L, L}, {Data_Owner, Data_All_Tokens}) {
113314184Sgabeblack@google.com    r_bounceResponse;
113414184Sgabeblack@google.com    k_popIncomingResponseQueue;
113514184Sgabeblack@google.com  }
113614184Sgabeblack@google.com
113714184Sgabeblack@google.com  transition({DW_L, DR_L, L}, Tokens) {
113814184Sgabeblack@google.com    r_bounceResponse;
113914184Sgabeblack@google.com    k_popIncomingResponseQueue;
114014184Sgabeblack@google.com  }
114114184Sgabeblack@google.com
114214184Sgabeblack@google.com  transition({DW_L, DR_L}, {Ack_Owner_All_Tokens, Ack_Owner}) {
114314184Sgabeblack@google.com    bd_bounceDatalessOwnerToken;
114414184Sgabeblack@google.com    k_popIncomingResponseQueue;
114514184Sgabeblack@google.com  }
114614184Sgabeblack@google.com
114714184Sgabeblack@google.com  transition(L, {Ack_Owner_All_Tokens, Ack_Owner}, L_O_W) {
114814184Sgabeblack@google.com    f_incrementTokens;
114914184Sgabeblack@google.com    qp_queueMemoryForPersistent;
115014184Sgabeblack@google.com    k_popIncomingResponseQueue;
115114184Sgabeblack@google.com  }
115214184Sgabeblack@google.com
115314184Sgabeblack@google.com  transition(L, {Unlockdown, Own_Lock_or_Unlock}, NO) {
115414184Sgabeblack@google.com    l_popIncomingPersistentQueue;
115514184Sgabeblack@google.com  }
115614184Sgabeblack@google.com
115714184Sgabeblack@google.com  transition(L, Own_Lock_or_Unlock_Tokens, O) {
115814184Sgabeblack@google.com    l_popIncomingPersistentQueue;
115914184Sgabeblack@google.com  }
116014184Sgabeblack@google.com
116114184Sgabeblack@google.com  transition({L_NO_W, L_O_W}, Memory_Data, L) {
116214184Sgabeblack@google.com    dd_sendMemDataToStarver;
116314184Sgabeblack@google.com    l_popMemQueue;
116414184Sgabeblack@google.com  }
116514184Sgabeblack@google.com
116614184Sgabeblack@google.com  transition(L_O_W, Memory_Ack) {
116714184Sgabeblack@google.com    qp_queueMemoryForPersistent;
116814184Sgabeblack@google.com    l_popMemQueue;
116914184Sgabeblack@google.com  }
117014184Sgabeblack@google.com
117114184Sgabeblack@google.com  transition(L_O_W, {Unlockdown, Own_Lock_or_Unlock, Own_Lock_or_Unlock_Tokens}, O_W) {
117214184Sgabeblack@google.com    l_popIncomingPersistentQueue;
117314184Sgabeblack@google.com  }
117414184Sgabeblack@google.com
117514184Sgabeblack@google.com  transition(L_NO_W, {Unlockdown, Own_Lock_or_Unlock, Own_Lock_or_Unlock_Tokens}, NO_W) {
117614184Sgabeblack@google.com    l_popIncomingPersistentQueue;
117714184Sgabeblack@google.com  }
117814184Sgabeblack@google.com
117914184Sgabeblack@google.com  transition(DR_L_W, Memory_Data, DR_L) {
118014184Sgabeblack@google.com    dd_sendMemDataToStarver;
118114184Sgabeblack@google.com    l_popMemQueue;
118214184Sgabeblack@google.com  }
118314184Sgabeblack@google.com
118414184Sgabeblack@google.com  transition(DW_L_W, Memory_Ack, L) {
118514184Sgabeblack@google.com    aat_assertAllTokens;
118614184Sgabeblack@google.com    da_sendDmaAck;
118714184Sgabeblack@google.com    s_deallocateTBE;
118814184Sgabeblack@google.com    dd_sendMemDataToStarver;
118914184Sgabeblack@google.com    l_popMemQueue;
119014184Sgabeblack@google.com  }
119114184Sgabeblack@google.com
119214184Sgabeblack@google.com  transition(DW_L, {Unlockdown, Own_Lock_or_Unlock, Own_Lock_or_Unlock_Tokens}, NO_DW) {
119314184Sgabeblack@google.com    l_popIncomingPersistentQueue;
119414184Sgabeblack@google.com  }
119514184Sgabeblack@google.com
119614184Sgabeblack@google.com  transition(DR_L_W, {Unlockdown, Own_Lock_or_Unlock, Own_Lock_or_Unlock_Tokens}, O_DR_W) {
119714184Sgabeblack@google.com    l_popIncomingPersistentQueue;
119814184Sgabeblack@google.com  }
119914184Sgabeblack@google.com
120014184Sgabeblack@google.com  transition(DW_L_W, {Unlockdown, Own_Lock_or_Unlock, Own_Lock_or_Unlock_Tokens}, O_DW_W) {
120114184Sgabeblack@google.com    l_popIncomingPersistentQueue;
120214184Sgabeblack@google.com  }
120314184Sgabeblack@google.com
120414184Sgabeblack@google.com  transition({DW_L, DR_L_W, DW_L_W}, Request_Timeout) {
120514184Sgabeblack@google.com    ut_unsetReissueTimer;
120614184Sgabeblack@google.com    px_tryIssuingPersistentGETXRequest;
120714184Sgabeblack@google.com  }
120814184Sgabeblack@google.com
120914184Sgabeblack@google.com  transition(DR_L, {Unlockdown, Own_Lock_or_Unlock, Own_Lock_or_Unlock_Tokens}, NO_DR) {
121014184Sgabeblack@google.com    l_popIncomingPersistentQueue;
121114184Sgabeblack@google.com  }
121214184Sgabeblack@google.com
121314184Sgabeblack@google.com  transition(DR_L, Request_Timeout) {
121414184Sgabeblack@google.com    ut_unsetReissueTimer;
121514184Sgabeblack@google.com    ps_tryIssuingPersistentGETSRequest;
121614184Sgabeblack@google.com  }
121714184Sgabeblack@google.com
121814184Sgabeblack@google.com  //
121914184Sgabeblack@google.com  // The O_W + Memory_Data > O transistion is confusing, but it can happen if a
122014184Sgabeblack@google.com  // presistent request is issued and resolve before memory returns with data
122114184Sgabeblack@google.com  //
122214184Sgabeblack@google.com  transition(O_W, {Memory_Ack, Memory_Data}, O) {
122314184Sgabeblack@google.com    l_popMemQueue;
122414184Sgabeblack@google.com  }
122514184Sgabeblack@google.com
122614184Sgabeblack@google.com  transition({O, NO}, {Own_Lock_or_Unlock, Own_Lock_or_Unlock_Tokens}) {
122714184Sgabeblack@google.com    l_popIncomingPersistentQueue;
122814184Sgabeblack@google.com  }
122914184Sgabeblack@google.com
123014184Sgabeblack@google.com  // Blocked states
123114184Sgabeblack@google.com  transition({NO_W, O_W, L_O_W, L_NO_W, DR_L_W, DW_L_W, O_DW_W, O_DR_W, O_DW, NO_DW, NO_DR}, {GETX, GETS}) {
123214184Sgabeblack@google.com    z_recycleRequest;
123314184Sgabeblack@google.com  }
123414184Sgabeblack@google.com
123514184Sgabeblack@google.com  transition({NO_W, O_W, L_O_W, L_NO_W, DR_L_W, DW_L_W, O_DW_W, O_DR_W, O_DW, NO_DW, NO_DR, L, DW_L, DR_L}, {DMA_READ, DMA_WRITE, DMA_WRITE_All_Tokens}) {
123614184Sgabeblack@google.com    y_recycleDmaRequestQueue;
123714184Sgabeblack@google.com  }
123814184Sgabeblack@google.com
123914184Sgabeblack@google.com  transition({NO_W, O_W, L_O_W, L_NO_W, DR_L_W, DW_L_W, O_DW_W, O_DR_W}, {Data_Owner, Ack_Owner, Tokens, Data_All_Tokens, Ack_All_Tokens}) {
124014184Sgabeblack@google.com    kz_recycleResponse;
124114184Sgabeblack@google.com  }
124214184Sgabeblack@google.com
124314184Sgabeblack@google.com  //
124414184Sgabeblack@google.com  // If we receive a request timeout while waiting for memory, it is likely that
124514184Sgabeblack@google.com  // the request will be satisfied and issuing a presistent request will do us
124614184Sgabeblack@google.com  // no good.  Just wait.
124714184Sgabeblack@google.com  //
124814184Sgabeblack@google.com  transition({O_DW_W, O_DR_W}, Request_Timeout) {
124914184Sgabeblack@google.com    rs_resetScheduleTimeout;
125014184Sgabeblack@google.com  }
125114184Sgabeblack@google.com
125214184Sgabeblack@google.com  transition(NO_W, Lockdown, L_NO_W) {
125314184Sgabeblack@google.com    l_popIncomingPersistentQueue;
125414184Sgabeblack@google.com  }
125514184Sgabeblack@google.com
125614184Sgabeblack@google.com  transition(O_W, Lockdown, L_O_W) {
125714184Sgabeblack@google.com    l_popIncomingPersistentQueue;
125814184Sgabeblack@google.com  }
125914184Sgabeblack@google.com
126014184Sgabeblack@google.com  transition(O_DR_W, Lockdown, DR_L_W) {
126114184Sgabeblack@google.com    l_popIncomingPersistentQueue;
126214184Sgabeblack@google.com  }
126314184Sgabeblack@google.com
126414184Sgabeblack@google.com  transition(O_DW_W, Lockdown, DW_L_W) {
126514184Sgabeblack@google.com    l_popIncomingPersistentQueue;
126614184Sgabeblack@google.com  }
126714184Sgabeblack@google.com
126814184Sgabeblack@google.com  transition({NO_W, O_W, O_DR_W, O_DW_W, O_DW, NO_DR, NO_DW}, {Unlockdown, Own_Lock_or_Unlock, Own_Lock_or_Unlock_Tokens}) {
126914184Sgabeblack@google.com    l_popIncomingPersistentQueue;
127014184Sgabeblack@google.com  }
127114184Sgabeblack@google.com}
1272