MESI_Two_Level-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, "MESI Two Level directory protocol")
3014184Sgabeblack@google.com : DirectoryMemory * directory;
3114184Sgabeblack@google.com   Cycles to_mem_ctrl_latency := 1;
3214184Sgabeblack@google.com   Cycles directory_latency := 6;
3314184Sgabeblack@google.com
3414184Sgabeblack@google.com   MessageBuffer * requestToDir, network="From", virtual_network="0",
3514184Sgabeblack@google.com        vnet_type="request";
3614184Sgabeblack@google.com   MessageBuffer * responseToDir, network="From", virtual_network="1",
3714184Sgabeblack@google.com        vnet_type="response";
3814184Sgabeblack@google.com   MessageBuffer * responseFromDir, network="To", virtual_network="1",
3914184Sgabeblack@google.com        vnet_type="response";
4014184Sgabeblack@google.com
4114184Sgabeblack@google.com   MessageBuffer * responseFromMemory;
4214184Sgabeblack@google.com{
4314184Sgabeblack@google.com  // STATES
4414184Sgabeblack@google.com  state_declaration(State, desc="Directory states", default="Directory_State_I") {
4514184Sgabeblack@google.com    // Base states
4614184Sgabeblack@google.com    I, AccessPermission:Read_Write, desc="dir is the owner and memory is up-to-date, all other copies are Invalid";
4714184Sgabeblack@google.com    ID, AccessPermission:Busy, desc="Intermediate state for DMA_READ when in I";
4814184Sgabeblack@google.com    ID_W, AccessPermission:Busy, desc="Intermediate state for DMA_WRITE when in I";
4914184Sgabeblack@google.com
5014184Sgabeblack@google.com    M, AccessPermission:Maybe_Stale, desc="memory copy may be stale, i.e. other modified copies may exist";
5114184Sgabeblack@google.com    IM, AccessPermission:Busy, desc="Intermediate State I>M";
5214184Sgabeblack@google.com    MI, AccessPermission:Busy, desc="Intermediate State M>I";
5314184Sgabeblack@google.com    M_DRD, AccessPermission:Busy, desc="Intermediate State when there is a dma read";
5414184Sgabeblack@google.com    M_DRDI, AccessPermission:Busy, desc="Intermediate State when there is a dma read";
5514184Sgabeblack@google.com    M_DWR, AccessPermission:Busy, desc="Intermediate State when there is a dma write";
5614184Sgabeblack@google.com    M_DWRI, AccessPermission:Busy, desc="Intermediate State when there is a dma write";
5714184Sgabeblack@google.com  }
5814184Sgabeblack@google.com
5914184Sgabeblack@google.com  // Events
6014184Sgabeblack@google.com  enumeration(Event, desc="Directory events") {
6114184Sgabeblack@google.com    Fetch, desc="A memory fetch arrives";
6214184Sgabeblack@google.com    Data, desc="writeback data arrives";
6314184Sgabeblack@google.com    Memory_Data, desc="Fetched data from memory arrives";
6414184Sgabeblack@google.com    Memory_Ack, desc="Writeback Ack from memory arrives";
6514184Sgabeblack@google.com//added by SS for dma
6614184Sgabeblack@google.com    DMA_READ, desc="A DMA Read memory request";
6714184Sgabeblack@google.com    DMA_WRITE, desc="A DMA Write memory request";
6814184Sgabeblack@google.com    CleanReplacement, desc="Clean Replacement in L2 cache";
6914184Sgabeblack@google.com
7014184Sgabeblack@google.com  }
7114184Sgabeblack@google.com
7214184Sgabeblack@google.com  // TYPES
7314184Sgabeblack@google.com
7414184Sgabeblack@google.com  // DirectoryEntry
7514184Sgabeblack@google.com  structure(Entry, desc="...", interface="AbstractEntry") {
7614184Sgabeblack@google.com    State DirectoryState,          desc="Directory state";
7714184Sgabeblack@google.com    MachineID Owner;
7814184Sgabeblack@google.com  }
7914184Sgabeblack@google.com
8014184Sgabeblack@google.com  // TBE entries for DMA requests
8114184Sgabeblack@google.com  structure(TBE, desc="TBE entries for outstanding DMA requests") {
8214184Sgabeblack@google.com    Addr PhysicalAddress, desc="physical address";
8314184Sgabeblack@google.com    State TBEState,        desc="Transient State";
8414184Sgabeblack@google.com    DataBlock DataBlk,     desc="Data to be written (DMA write only)";
8514184Sgabeblack@google.com    int Len,               desc="...";
8614184Sgabeblack@google.com    MachineID Requestor,   desc="The DMA engine that sent the request";
8714184Sgabeblack@google.com  }
8814184Sgabeblack@google.com
8914184Sgabeblack@google.com  structure(TBETable, external="yes") {
9014184Sgabeblack@google.com    TBE lookup(Addr);
9114184Sgabeblack@google.com    void allocate(Addr);
9214184Sgabeblack@google.com    void deallocate(Addr);
9314184Sgabeblack@google.com    bool isPresent(Addr);
9414184Sgabeblack@google.com    bool functionalRead(Packet *pkt);
9514184Sgabeblack@google.com    int functionalWrite(Packet *pkt);
9614184Sgabeblack@google.com  }
9714184Sgabeblack@google.com
9814184Sgabeblack@google.com
9914184Sgabeblack@google.com  // ** OBJECTS **
10014184Sgabeblack@google.com  TBETable TBEs, template="<Directory_TBE>", constructor="m_number_of_TBEs";
10114184Sgabeblack@google.com
10214184Sgabeblack@google.com  Tick clockEdge();
10314184Sgabeblack@google.com  Tick cyclesToTicks(Cycles c);
10414184Sgabeblack@google.com  void set_tbe(TBE tbe);
10514184Sgabeblack@google.com  void unset_tbe();
10614184Sgabeblack@google.com  void wakeUpBuffers(Addr a);
10714184Sgabeblack@google.com
10814184Sgabeblack@google.com  Entry getDirectoryEntry(Addr addr), return_by_pointer="yes" {
10914184Sgabeblack@google.com    Entry dir_entry := static_cast(Entry, "pointer", directory[addr]);
11014184Sgabeblack@google.com
11114184Sgabeblack@google.com    if (is_valid(dir_entry)) {
11214184Sgabeblack@google.com      return dir_entry;
11314184Sgabeblack@google.com    }
11414184Sgabeblack@google.com
11514184Sgabeblack@google.com    dir_entry :=  static_cast(Entry, "pointer",
11614184Sgabeblack@google.com                              directory.allocate(addr, new Entry));
11714184Sgabeblack@google.com    return dir_entry;
11814184Sgabeblack@google.com  }
11914184Sgabeblack@google.com
12014184Sgabeblack@google.com  State getState(TBE tbe, Addr addr) {
12114184Sgabeblack@google.com    if (is_valid(tbe)) {
12214184Sgabeblack@google.com      return tbe.TBEState;
12314184Sgabeblack@google.com    } else if (directory.isPresent(addr)) {
12414184Sgabeblack@google.com      return getDirectoryEntry(addr).DirectoryState;
12514184Sgabeblack@google.com    } else {
12614184Sgabeblack@google.com      return State:I;
12714184Sgabeblack@google.com    }
12814184Sgabeblack@google.com  }
12914184Sgabeblack@google.com
13014184Sgabeblack@google.com  void setState(TBE tbe, Addr addr, State state) {
13114184Sgabeblack@google.com    if (is_valid(tbe)) {
13214184Sgabeblack@google.com      tbe.TBEState := state;
13314184Sgabeblack@google.com    }
13414184Sgabeblack@google.com
13514184Sgabeblack@google.com    if (directory.isPresent(addr)) {
13614184Sgabeblack@google.com      getDirectoryEntry(addr).DirectoryState := state;
13714184Sgabeblack@google.com    }
13814184Sgabeblack@google.com  }
13914184Sgabeblack@google.com
14014184Sgabeblack@google.com  AccessPermission getAccessPermission(Addr addr) {
14114184Sgabeblack@google.com    TBE tbe := TBEs[addr];
14214184Sgabeblack@google.com    if(is_valid(tbe)) {
14314184Sgabeblack@google.com      DPRINTF(RubySlicc, "%s\n", Directory_State_to_permission(tbe.TBEState));
14414184Sgabeblack@google.com      return Directory_State_to_permission(tbe.TBEState);
14514184Sgabeblack@google.com    }
14614184Sgabeblack@google.com
14714184Sgabeblack@google.com    if(directory.isPresent(addr)) {
14814184Sgabeblack@google.com      DPRINTF(RubySlicc, "%s\n", Directory_State_to_permission(getDirectoryEntry(addr).DirectoryState));
14914184Sgabeblack@google.com      return Directory_State_to_permission(getDirectoryEntry(addr).DirectoryState);
15014184Sgabeblack@google.com    }
15114184Sgabeblack@google.com
15214184Sgabeblack@google.com    DPRINTF(RubySlicc, "%s\n", AccessPermission:NotPresent);
15314184Sgabeblack@google.com    return AccessPermission:NotPresent;
15414184Sgabeblack@google.com  }
15514184Sgabeblack@google.com
15614184Sgabeblack@google.com  void functionalRead(Addr addr, Packet *pkt) {
15714184Sgabeblack@google.com    TBE tbe := TBEs[addr];
15814184Sgabeblack@google.com    if(is_valid(tbe)) {
15914184Sgabeblack@google.com      testAndRead(addr, tbe.DataBlk, pkt);
16014184Sgabeblack@google.com    } else {
16114184Sgabeblack@google.com      functionalMemoryRead(pkt);
16214184Sgabeblack@google.com    }
16314184Sgabeblack@google.com  }
16414184Sgabeblack@google.com
16514184Sgabeblack@google.com  int functionalWrite(Addr addr, Packet *pkt) {
16614184Sgabeblack@google.com    int num_functional_writes := 0;
16714184Sgabeblack@google.com
16814184Sgabeblack@google.com    TBE tbe := TBEs[addr];
16914184Sgabeblack@google.com    if(is_valid(tbe)) {
17014184Sgabeblack@google.com      num_functional_writes := num_functional_writes +
17114184Sgabeblack@google.com        testAndWrite(addr, tbe.DataBlk, pkt);
17214184Sgabeblack@google.com    }
17314184Sgabeblack@google.com
17414184Sgabeblack@google.com    num_functional_writes := num_functional_writes + functionalMemoryWrite(pkt);
17514184Sgabeblack@google.com    return num_functional_writes;
17614184Sgabeblack@google.com  }
17714184Sgabeblack@google.com
17814184Sgabeblack@google.com  void setAccessPermission(Addr addr, State state) {
17914184Sgabeblack@google.com    if (directory.isPresent(addr)) {
18014184Sgabeblack@google.com      getDirectoryEntry(addr).changePermission(Directory_State_to_permission(state));
18114184Sgabeblack@google.com    }
18214184Sgabeblack@google.com  }
18314184Sgabeblack@google.com
18414184Sgabeblack@google.com  bool isGETRequest(CoherenceRequestType type) {
18514184Sgabeblack@google.com    return (type == CoherenceRequestType:GETS) ||
18614184Sgabeblack@google.com      (type == CoherenceRequestType:GET_INSTR) ||
18714184Sgabeblack@google.com      (type == CoherenceRequestType:GETX);
18814184Sgabeblack@google.com  }
18914184Sgabeblack@google.com
19014184Sgabeblack@google.com  // ** OUT_PORTS **
19114184Sgabeblack@google.com  out_port(responseNetwork_out, ResponseMsg, responseFromDir);
19214184Sgabeblack@google.com
19314184Sgabeblack@google.com  // ** IN_PORTS **
19414184Sgabeblack@google.com
19514184Sgabeblack@google.com  in_port(requestNetwork_in, RequestMsg, requestToDir, rank = 0) {
19614184Sgabeblack@google.com    if (requestNetwork_in.isReady(clockEdge())) {
19714184Sgabeblack@google.com      peek(requestNetwork_in, RequestMsg) {
19814184Sgabeblack@google.com        assert(in_msg.Destination.isElement(machineID));
19914184Sgabeblack@google.com        if (isGETRequest(in_msg.Type)) {
20014184Sgabeblack@google.com          trigger(Event:Fetch, in_msg.addr, TBEs[in_msg.addr]);
20114184Sgabeblack@google.com        } else if (in_msg.Type == CoherenceRequestType:DMA_READ) {
20214184Sgabeblack@google.com          trigger(Event:DMA_READ, makeLineAddress(in_msg.addr),
20314184Sgabeblack@google.com                  TBEs[makeLineAddress(in_msg.addr)]);
20414184Sgabeblack@google.com        } else if (in_msg.Type == CoherenceRequestType:DMA_WRITE) {
20514184Sgabeblack@google.com          trigger(Event:DMA_WRITE, makeLineAddress(in_msg.addr),
20614184Sgabeblack@google.com                  TBEs[makeLineAddress(in_msg.addr)]);
20714184Sgabeblack@google.com        } else {
20814184Sgabeblack@google.com          DPRINTF(RubySlicc, "%s\n", in_msg);
20914184Sgabeblack@google.com          error("Invalid message");
21014184Sgabeblack@google.com        }
21114184Sgabeblack@google.com      }
21214184Sgabeblack@google.com    }
21314184Sgabeblack@google.com  }
21414184Sgabeblack@google.com
21514184Sgabeblack@google.com  in_port(responseNetwork_in, ResponseMsg, responseToDir, rank = 1) {
21614184Sgabeblack@google.com    if (responseNetwork_in.isReady(clockEdge())) {
21714184Sgabeblack@google.com      peek(responseNetwork_in, ResponseMsg) {
21814184Sgabeblack@google.com        assert(in_msg.Destination.isElement(machineID));
21914184Sgabeblack@google.com        if (in_msg.Type == CoherenceResponseType:MEMORY_DATA) {
22014184Sgabeblack@google.com          trigger(Event:Data, in_msg.addr, TBEs[in_msg.addr]);
22114184Sgabeblack@google.com        } else if (in_msg.Type == CoherenceResponseType:ACK) {
22214184Sgabeblack@google.com          trigger(Event:CleanReplacement, in_msg.addr, TBEs[in_msg.addr]);
22314184Sgabeblack@google.com        } else {
22414184Sgabeblack@google.com          DPRINTF(RubySlicc, "%s\n", in_msg.Type);
22514184Sgabeblack@google.com          error("Invalid message");
22614184Sgabeblack@google.com        }
22714184Sgabeblack@google.com      }
22814184Sgabeblack@google.com    }
22914184Sgabeblack@google.com  }
23014184Sgabeblack@google.com
23114184Sgabeblack@google.com  // off-chip memory request/response is done
23214184Sgabeblack@google.com  in_port(memQueue_in, MemoryMsg, responseFromMemory, rank = 2) {
23314184Sgabeblack@google.com    if (memQueue_in.isReady(clockEdge())) {
23414184Sgabeblack@google.com      peek(memQueue_in, MemoryMsg) {
23514184Sgabeblack@google.com        if (in_msg.Type == MemoryRequestType:MEMORY_READ) {
23614184Sgabeblack@google.com          trigger(Event:Memory_Data, in_msg.addr, TBEs[in_msg.addr]);
23714184Sgabeblack@google.com        } else if (in_msg.Type == MemoryRequestType:MEMORY_WB) {
23814184Sgabeblack@google.com          trigger(Event:Memory_Ack, in_msg.addr, TBEs[in_msg.addr]);
23914184Sgabeblack@google.com        } else {
24014184Sgabeblack@google.com          DPRINTF(RubySlicc, "%s\n", in_msg.Type);
24114184Sgabeblack@google.com          error("Invalid message");
24214184Sgabeblack@google.com        }
24314184Sgabeblack@google.com      }
24414184Sgabeblack@google.com    }
24514184Sgabeblack@google.com  }
24614184Sgabeblack@google.com
24714184Sgabeblack@google.com
24814184Sgabeblack@google.com  // Actions
24914184Sgabeblack@google.com  action(a_sendAck, "a", desc="Send ack to L2") {
25014184Sgabeblack@google.com    peek(responseNetwork_in, ResponseMsg) {
25114184Sgabeblack@google.com      enqueue(responseNetwork_out, ResponseMsg, to_mem_ctrl_latency) {
25214184Sgabeblack@google.com        out_msg.addr := address;
25314184Sgabeblack@google.com        out_msg.Type := CoherenceResponseType:MEMORY_ACK;
25414184Sgabeblack@google.com        out_msg.Sender := machineID;
25514184Sgabeblack@google.com        out_msg.Destination.add(in_msg.Sender);
25614184Sgabeblack@google.com        out_msg.MessageSize := MessageSizeType:Response_Control;
25714184Sgabeblack@google.com      }
25814184Sgabeblack@google.com    }
25914184Sgabeblack@google.com  }
26014184Sgabeblack@google.com
26114184Sgabeblack@google.com  action(d_sendData, "d", desc="Send data to requestor") {
26214184Sgabeblack@google.com    peek(memQueue_in, MemoryMsg) {
26314184Sgabeblack@google.com      enqueue(responseNetwork_out, ResponseMsg, to_mem_ctrl_latency) {
26414184Sgabeblack@google.com        out_msg.addr := address;
26514184Sgabeblack@google.com        out_msg.Type := CoherenceResponseType:MEMORY_DATA;
26614184Sgabeblack@google.com        out_msg.Sender := machineID;
26714184Sgabeblack@google.com        out_msg.Destination.add(in_msg.OriginalRequestorMachId);
26814184Sgabeblack@google.com        out_msg.DataBlk := in_msg.DataBlk;
26914184Sgabeblack@google.com        out_msg.Dirty := false;
27014184Sgabeblack@google.com        out_msg.MessageSize := MessageSizeType:Response_Data;
27114184Sgabeblack@google.com
27214184Sgabeblack@google.com        Entry e := getDirectoryEntry(in_msg.addr);
27314184Sgabeblack@google.com        e.Owner := in_msg.OriginalRequestorMachId;
27414184Sgabeblack@google.com      }
27514184Sgabeblack@google.com    }
27614184Sgabeblack@google.com  }
27714184Sgabeblack@google.com
27814184Sgabeblack@google.com  // Actions
27914184Sgabeblack@google.com  action(aa_sendAck, "aa", desc="Send ack to L2") {
28014184Sgabeblack@google.com    peek(memQueue_in, MemoryMsg) {
28114184Sgabeblack@google.com      enqueue(responseNetwork_out, ResponseMsg, to_mem_ctrl_latency) {
28214184Sgabeblack@google.com        out_msg.addr := address;
28314184Sgabeblack@google.com        out_msg.Type := CoherenceResponseType:MEMORY_ACK;
28414184Sgabeblack@google.com        out_msg.Sender := machineID;
28514184Sgabeblack@google.com        out_msg.Destination.add(in_msg.OriginalRequestorMachId);
28614184Sgabeblack@google.com        out_msg.MessageSize := MessageSizeType:Response_Control;
28714184Sgabeblack@google.com      }
28814184Sgabeblack@google.com    }
28914184Sgabeblack@google.com  }
29014184Sgabeblack@google.com
29114184Sgabeblack@google.com  action(j_popIncomingRequestQueue, "j", desc="Pop incoming request queue") {
29214184Sgabeblack@google.com    requestNetwork_in.dequeue(clockEdge());
29314184Sgabeblack@google.com  }
29414184Sgabeblack@google.com
29514184Sgabeblack@google.com  action(k_popIncomingResponseQueue, "k", desc="Pop incoming request queue") {
29614184Sgabeblack@google.com    responseNetwork_in.dequeue(clockEdge());
29714184Sgabeblack@google.com  }
29814184Sgabeblack@google.com
29914184Sgabeblack@google.com  action(l_popMemQueue, "q", desc="Pop off-chip request queue") {
30014184Sgabeblack@google.com    memQueue_in.dequeue(clockEdge());
30114184Sgabeblack@google.com  }
30214184Sgabeblack@google.com
30314184Sgabeblack@google.com  action(kd_wakeUpDependents, "kd", desc="wake-up dependents") {
30414184Sgabeblack@google.com    wakeUpBuffers(address);
30514184Sgabeblack@google.com  }
30614184Sgabeblack@google.com
30714184Sgabeblack@google.com  action(qf_queueMemoryFetchRequest, "qf", desc="Queue off-chip fetch request") {
30814184Sgabeblack@google.com    peek(requestNetwork_in, RequestMsg) {
30914184Sgabeblack@google.com      queueMemoryRead(in_msg.Requestor, address, to_mem_ctrl_latency);
31014184Sgabeblack@google.com    }
31114184Sgabeblack@google.com  }
31214184Sgabeblack@google.com
31314184Sgabeblack@google.com  action(qw_queueMemoryWBRequest, "qw", desc="Queue off-chip writeback request") {
31414184Sgabeblack@google.com    peek(responseNetwork_in, ResponseMsg) {
31514184Sgabeblack@google.com      queueMemoryWrite(in_msg.Sender, address, to_mem_ctrl_latency,
31614184Sgabeblack@google.com                       in_msg.DataBlk);
31714184Sgabeblack@google.com    }
31814184Sgabeblack@google.com  }
31914184Sgabeblack@google.com
32014184Sgabeblack@google.com//added by SS for dma
32114184Sgabeblack@google.com  action(qf_queueMemoryFetchRequestDMA, "qfd", desc="Queue off-chip fetch request") {
32214184Sgabeblack@google.com    peek(requestNetwork_in, RequestMsg) {
32314184Sgabeblack@google.com      queueMemoryRead(in_msg.Requestor, address, to_mem_ctrl_latency);
32414184Sgabeblack@google.com    }
32514184Sgabeblack@google.com  }
32614184Sgabeblack@google.com
32714184Sgabeblack@google.com  action(p_popIncomingDMARequestQueue, "p", desc="Pop incoming DMA queue") {
32814184Sgabeblack@google.com    requestNetwork_in.dequeue(clockEdge());
32914184Sgabeblack@google.com  }
33014184Sgabeblack@google.com
33114184Sgabeblack@google.com  action(dr_sendDMAData, "dr", desc="Send Data to DMA controller from directory") {
33214184Sgabeblack@google.com    peek(memQueue_in, MemoryMsg) {
33314184Sgabeblack@google.com      enqueue(responseNetwork_out, ResponseMsg, to_mem_ctrl_latency) {
33414184Sgabeblack@google.com        assert(is_valid(tbe));
33514184Sgabeblack@google.com        out_msg.addr := address;
33614184Sgabeblack@google.com        out_msg.Type := CoherenceResponseType:DATA;
33714184Sgabeblack@google.com        out_msg.DataBlk := in_msg.DataBlk;   // we send the entire data block and rely on the dma controller to split it up if need be
33814184Sgabeblack@google.com        out_msg.Destination.add(tbe.Requestor);
33914184Sgabeblack@google.com        out_msg.MessageSize := MessageSizeType:Response_Data;
34014184Sgabeblack@google.com      }
34114184Sgabeblack@google.com    }
34214184Sgabeblack@google.com  }
34314184Sgabeblack@google.com
34414184Sgabeblack@google.com  action(qw_queueMemoryWBRequest_partial, "qwp",
34514184Sgabeblack@google.com         desc="Queue off-chip writeback request") {
34614184Sgabeblack@google.com    peek(requestNetwork_in, RequestMsg) {
34714184Sgabeblack@google.com      queueMemoryWritePartial(machineID, address, to_mem_ctrl_latency,
34814184Sgabeblack@google.com                              in_msg.DataBlk, in_msg.Len);
34914184Sgabeblack@google.com    }
35014184Sgabeblack@google.com  }
35114184Sgabeblack@google.com
35214184Sgabeblack@google.com  action(da_sendDMAAck, "da", desc="Send Ack to DMA controller") {
35314184Sgabeblack@google.com      enqueue(responseNetwork_out, ResponseMsg, to_mem_ctrl_latency) {
35414184Sgabeblack@google.com        assert(is_valid(tbe));
35514184Sgabeblack@google.com        out_msg.addr := address;
35614184Sgabeblack@google.com        out_msg.Type := CoherenceResponseType:ACK;
35714184Sgabeblack@google.com        out_msg.Destination.add(tbe.Requestor);
35814184Sgabeblack@google.com        out_msg.MessageSize := MessageSizeType:Writeback_Control;
35914184Sgabeblack@google.com      }
36014184Sgabeblack@google.com  }
36114184Sgabeblack@google.com
36214184Sgabeblack@google.com  action(z_stallAndWaitRequest, "z", desc="recycle request queue") {
36314184Sgabeblack@google.com    stall_and_wait(requestNetwork_in, address);
36414184Sgabeblack@google.com  }
36514184Sgabeblack@google.com
36614184Sgabeblack@google.com  action(zz_recycleDMAQueue, "zz", desc="recycle DMA queue") {
36714184Sgabeblack@google.com    requestNetwork_in.recycle(clockEdge(), cyclesToTicks(recycle_latency));
36814184Sgabeblack@google.com  }
36914184Sgabeblack@google.com
37014184Sgabeblack@google.com  action(inv_sendCacheInvalidate, "inv", desc="Invalidate a cache block") {
37114184Sgabeblack@google.com    peek(requestNetwork_in, RequestMsg) {
37214184Sgabeblack@google.com      enqueue(responseNetwork_out, ResponseMsg, directory_latency) {
37314184Sgabeblack@google.com        out_msg.addr := address;
37414184Sgabeblack@google.com        out_msg.Type := CoherenceResponseType:INV;
37514184Sgabeblack@google.com        out_msg.Sender := machineID;
37614184Sgabeblack@google.com        out_msg.Destination.add(getDirectoryEntry(address).Owner);
37714184Sgabeblack@google.com        out_msg.MessageSize := MessageSizeType:Response_Control;
37814184Sgabeblack@google.com      }
37914184Sgabeblack@google.com    }
38014184Sgabeblack@google.com  }
38114184Sgabeblack@google.com
38214184Sgabeblack@google.com
38314184Sgabeblack@google.com  action(drp_sendDMAData, "drp", desc="Send Data to DMA controller from incoming PUTX") {
38414184Sgabeblack@google.com    peek(responseNetwork_in, ResponseMsg) {
38514184Sgabeblack@google.com      enqueue(responseNetwork_out, ResponseMsg, to_mem_ctrl_latency) {
38614184Sgabeblack@google.com        assert(is_valid(tbe));
38714184Sgabeblack@google.com        out_msg.addr := address;
38814184Sgabeblack@google.com        out_msg.Type := CoherenceResponseType:DATA;
38914184Sgabeblack@google.com        out_msg.DataBlk := in_msg.DataBlk;   // we send the entire data block and rely on the dma controller to split it up if need be
39014184Sgabeblack@google.com        out_msg.Destination.add(tbe.Requestor);
39114184Sgabeblack@google.com        out_msg.MessageSize := MessageSizeType:Response_Data;
39214184Sgabeblack@google.com      }
39314184Sgabeblack@google.com    }
39414184Sgabeblack@google.com  }
39514184Sgabeblack@google.com
39614184Sgabeblack@google.com  action(v_allocateTBE, "v", desc="Allocate TBE") {
39714184Sgabeblack@google.com    peek(requestNetwork_in, RequestMsg) {
39814184Sgabeblack@google.com      TBEs.allocate(address);
39914184Sgabeblack@google.com      set_tbe(TBEs[address]);
40014184Sgabeblack@google.com      tbe.DataBlk := in_msg.DataBlk;
40114184Sgabeblack@google.com      tbe.PhysicalAddress := in_msg.addr;
40214184Sgabeblack@google.com      tbe.Len := in_msg.Len;
40314184Sgabeblack@google.com      tbe.Requestor := in_msg.Requestor;
40414184Sgabeblack@google.com    }
40514184Sgabeblack@google.com  }
40614184Sgabeblack@google.com
40714184Sgabeblack@google.com  action(qw_queueMemoryWBRequest_partialTBE, "qwt",
40814184Sgabeblack@google.com         desc="Queue off-chip writeback request") {
40914184Sgabeblack@google.com    peek(responseNetwork_in, ResponseMsg) {
41014184Sgabeblack@google.com      queueMemoryWritePartial(in_msg.Sender, tbe.PhysicalAddress,
41114184Sgabeblack@google.com                              to_mem_ctrl_latency, tbe.DataBlk, tbe.Len);
41214184Sgabeblack@google.com    }
41314184Sgabeblack@google.com  }
41414184Sgabeblack@google.com
41514184Sgabeblack@google.com  action(w_deallocateTBE, "w", desc="Deallocate TBE") {
41614184Sgabeblack@google.com    TBEs.deallocate(address);
41714184Sgabeblack@google.com    unset_tbe();
41814184Sgabeblack@google.com  }
41914184Sgabeblack@google.com
42014184Sgabeblack@google.com
42114184Sgabeblack@google.com  // TRANSITIONS
42214184Sgabeblack@google.com
42314184Sgabeblack@google.com  transition(I, Fetch, IM) {
42414184Sgabeblack@google.com    qf_queueMemoryFetchRequest;
42514184Sgabeblack@google.com    j_popIncomingRequestQueue;
42614184Sgabeblack@google.com  }
42714184Sgabeblack@google.com
42814184Sgabeblack@google.com  transition(M, Fetch) {
42914184Sgabeblack@google.com    inv_sendCacheInvalidate;
43014184Sgabeblack@google.com    z_stallAndWaitRequest;
43114184Sgabeblack@google.com  }
43214184Sgabeblack@google.com
43314184Sgabeblack@google.com  transition(IM, Memory_Data, M) {
43414184Sgabeblack@google.com    d_sendData;
43514184Sgabeblack@google.com    l_popMemQueue;
43614184Sgabeblack@google.com    kd_wakeUpDependents;
43714184Sgabeblack@google.com  }
43814184Sgabeblack@google.com//added by SS
43914184Sgabeblack@google.com  transition(M, CleanReplacement, I) {
44014184Sgabeblack@google.com    a_sendAck;
44114184Sgabeblack@google.com    k_popIncomingResponseQueue;
44214184Sgabeblack@google.com    kd_wakeUpDependents;
44314184Sgabeblack@google.com  }
44414184Sgabeblack@google.com
44514184Sgabeblack@google.com  transition(M, Data, MI) {
44614184Sgabeblack@google.com    qw_queueMemoryWBRequest;
44714184Sgabeblack@google.com    k_popIncomingResponseQueue;
44814184Sgabeblack@google.com  }
44914184Sgabeblack@google.com
45014184Sgabeblack@google.com  transition(MI, Memory_Ack, I) {
45114184Sgabeblack@google.com    aa_sendAck;
45214184Sgabeblack@google.com    l_popMemQueue;
45314184Sgabeblack@google.com    kd_wakeUpDependents;
45414184Sgabeblack@google.com  }
45514184Sgabeblack@google.com
45614184Sgabeblack@google.com
45714184Sgabeblack@google.com//added by SS for dma support
45814184Sgabeblack@google.com  transition(I, DMA_READ, ID) {
45914184Sgabeblack@google.com    v_allocateTBE;
46014184Sgabeblack@google.com    qf_queueMemoryFetchRequestDMA;
46114184Sgabeblack@google.com    j_popIncomingRequestQueue;
46214184Sgabeblack@google.com  }
46314184Sgabeblack@google.com
46414184Sgabeblack@google.com  transition(ID, Memory_Data, I) {
46514184Sgabeblack@google.com    dr_sendDMAData;
46614184Sgabeblack@google.com    w_deallocateTBE;
46714184Sgabeblack@google.com    l_popMemQueue;
46814184Sgabeblack@google.com    kd_wakeUpDependents;
46914184Sgabeblack@google.com  }
47014184Sgabeblack@google.com
47114184Sgabeblack@google.com  transition(I, DMA_WRITE, ID_W) {
47214184Sgabeblack@google.com    v_allocateTBE;
47314184Sgabeblack@google.com    qw_queueMemoryWBRequest_partial;
47414184Sgabeblack@google.com    j_popIncomingRequestQueue;
47514184Sgabeblack@google.com  }
47614184Sgabeblack@google.com
47714184Sgabeblack@google.com  transition(ID_W, Memory_Ack, I) {
47814184Sgabeblack@google.com    da_sendDMAAck;
47914184Sgabeblack@google.com    w_deallocateTBE;
48014184Sgabeblack@google.com    l_popMemQueue;
48114184Sgabeblack@google.com    kd_wakeUpDependents;
48214184Sgabeblack@google.com  }
48314184Sgabeblack@google.com
48414184Sgabeblack@google.com  transition({ID, ID_W, M_DRDI, M_DWRI, IM, MI}, {Fetch, Data} ) {
48514184Sgabeblack@google.com    z_stallAndWaitRequest;
48614184Sgabeblack@google.com  }
48714184Sgabeblack@google.com
48814184Sgabeblack@google.com  transition({ID, ID_W, M_DRD, M_DRDI, M_DWR, M_DWRI, IM, MI}, {DMA_WRITE, DMA_READ} ) {
48914184Sgabeblack@google.com    zz_recycleDMAQueue;
49014184Sgabeblack@google.com  }
49114184Sgabeblack@google.com
49214184Sgabeblack@google.com
49314184Sgabeblack@google.com  transition(M, DMA_READ, M_DRD) {
49414184Sgabeblack@google.com    v_allocateTBE;
49514184Sgabeblack@google.com    inv_sendCacheInvalidate;
49614184Sgabeblack@google.com    j_popIncomingRequestQueue;
49714184Sgabeblack@google.com  }
49814184Sgabeblack@google.com
49914184Sgabeblack@google.com  transition(M_DRD, Data, M_DRDI) {
50014184Sgabeblack@google.com    drp_sendDMAData;
50114184Sgabeblack@google.com    w_deallocateTBE;
50214184Sgabeblack@google.com    qw_queueMemoryWBRequest;
50314184Sgabeblack@google.com    k_popIncomingResponseQueue;
50414184Sgabeblack@google.com  }
50514184Sgabeblack@google.com
50614184Sgabeblack@google.com  transition(M_DRDI, Memory_Ack, I) {
50714184Sgabeblack@google.com    aa_sendAck;
50814184Sgabeblack@google.com    l_popMemQueue;
50914184Sgabeblack@google.com    kd_wakeUpDependents;
51014184Sgabeblack@google.com  }
51114184Sgabeblack@google.com
51214184Sgabeblack@google.com  transition(M, DMA_WRITE, M_DWR) {
51314184Sgabeblack@google.com    v_allocateTBE;
51414184Sgabeblack@google.com    inv_sendCacheInvalidate;
51514184Sgabeblack@google.com    j_popIncomingRequestQueue;
51614184Sgabeblack@google.com  }
51714184Sgabeblack@google.com
51814184Sgabeblack@google.com  transition(M_DWR, Data, M_DWRI) {
51914184Sgabeblack@google.com    qw_queueMemoryWBRequest_partialTBE;
52014184Sgabeblack@google.com    k_popIncomingResponseQueue;
52114184Sgabeblack@google.com  }
52214184Sgabeblack@google.com
52314184Sgabeblack@google.com  transition(M_DWRI, Memory_Ack, I) {
52414184Sgabeblack@google.com    aa_sendAck;
52514184Sgabeblack@google.com    da_sendDMAAck;
52614184Sgabeblack@google.com    w_deallocateTBE;
52714184Sgabeblack@google.com    l_popMemQueue;
52814184Sgabeblack@google.com    kd_wakeUpDependents;
52914184Sgabeblack@google.com  }
53014184Sgabeblack@google.com}
531