MOESI_hammer: Added full-bit directory support
[gem5.git] / src / mem / protocol / MESI_SCMP_bankdirectory-mem.sm
1
2 /*
3 * Copyright (c) 1999-2005 Mark D. Hill and David A. Wood
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 /*
31 * $Id: MOESI_CMP_token-dir.sm 1.6 05/01/19 15:48:35-06:00 mikem@royal16.cs.wisc.edu $
32 */
33
34
35 machine(Directory, "Token protocol") {
36
37 MessageBuffer requestToDir, network="From", virtual_network="2", ordered="false";
38 MessageBuffer responseToDir, network="From", virtual_network="3", ordered="false";
39 MessageBuffer responseFromDir, network="To", virtual_network="3", ordered="false";
40
41 // STATES
42 enumeration(State, desc="Directory states", default="Directory_State_I") {
43 // Base states
44 I, desc="Owner";
45 }
46
47 // Events
48 enumeration(Event, desc="Directory events") {
49 Fetch, desc="A GETX arrives";
50 Data, desc="A GETS arrives";
51 }
52
53 // TYPES
54
55 // DirectoryEntry
56 structure(Entry, desc="...") {
57 DataBlock DataBlk, desc="data for the block";
58 }
59
60 external_type(DirectoryMemory) {
61 Entry lookup(Address);
62 bool isPresent(Address);
63 }
64
65
66 // ** OBJECTS **
67
68 DirectoryMemory directory, constructor_hack="i";
69
70 State getState(Address addr) {
71 return State:I;
72 }
73
74 void setState(Address addr, State state) {
75 }
76
77 // ** OUT_PORTS **
78 out_port(responseNetwork_out, ResponseMsg, responseFromDir);
79
80 // ** IN_PORTS **
81
82 in_port(requestNetwork_in, RequestMsg, requestToDir) {
83 if (requestNetwork_in.isReady()) {
84 peek(requestNetwork_in, RequestMsg) {
85 assert(in_msg.Destination.isElement(machineID));
86 if (in_msg.Type == CoherenceRequestType:GETS) {
87 trigger(Event:Fetch, in_msg.Address);
88 } else if (in_msg.Type == CoherenceRequestType:GETX) {
89 trigger(Event:Fetch, in_msg.Address);
90 } else {
91 error("Invalid message");
92 }
93 }
94 }
95 }
96
97 in_port(responseNetwork_in, ResponseMsg, responseToDir) {
98 if (responseNetwork_in.isReady()) {
99 peek(responseNetwork_in, ResponseMsg) {
100 assert(in_msg.Destination.isElement(machineID));
101 if (in_msg.Type == CoherenceResponseType:MEMORY_DATA) {
102 trigger(Event:Data, in_msg.Address);
103 } else {
104 DEBUG_EXPR(in_msg.Type);
105 error("Invalid message");
106 }
107 }
108 }
109 }
110
111 // Actions
112 action(a_sendAck, "a", desc="Send ack to L2") {
113 peek(responseNetwork_in, ResponseMsg) {
114 enqueue(responseNetwork_out, ResponseMsg, latency="MEMORY_LATENCY") {
115 out_msg.Address := address;
116 out_msg.Type := CoherenceResponseType:MEMORY_ACK;
117 out_msg.Sender := machineID;
118 out_msg.Destination.add(in_msg.Sender);
119 out_msg.MessageSize := MessageSizeType:Response_Control;
120 }
121 }
122 }
123
124 action(d_sendData, "d", desc="Send data to requestor") {
125 peek(requestNetwork_in, RequestMsg) {
126 enqueue(responseNetwork_out, ResponseMsg, latency="MEMORY_LATENCY") {
127 out_msg.Address := address;
128 out_msg.Type := CoherenceResponseType:MEMORY_DATA;
129 out_msg.Sender := machineID;
130 out_msg.Destination.add(in_msg.Requestor);
131 out_msg.DataBlk := directory[in_msg.Address].DataBlk;
132 out_msg.Dirty := false;
133 out_msg.MessageSize := MessageSizeType:Response_Data;
134 }
135 }
136 }
137
138 action(j_popIncomingRequestQueue, "j", desc="Pop incoming request queue") {
139 requestNetwork_in.dequeue();
140 }
141
142 action(k_popIncomingResponseQueue, "k", desc="Pop incoming request queue") {
143 responseNetwork_in.dequeue();
144 }
145
146 action(m_writeDataToMemory, "m", desc="Write dirty writeback to memory") {
147 peek(responseNetwork_in, ResponseMsg) {
148 directory[in_msg.Address].DataBlk := in_msg.DataBlk;
149 DEBUG_EXPR(in_msg.Address);
150 DEBUG_EXPR(in_msg.DataBlk);
151 }
152 }
153
154 // TRANSITIONS
155
156 transition(I, Fetch) {
157 d_sendData;
158 j_popIncomingRequestQueue;
159 }
160
161 transition(I, Data) {
162 m_writeDataToMemory;
163 a_sendAck;
164 k_popIncomingResponseQueue;
165 }
166 }