packet.hh (4022:c422464ca16e) packet.hh (4024:9eada81a030b)
1/*
2 * Copyright (c) 2006 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 26 unchanged lines hidden (view full) ---

35 * Declaration of the Packet class.
36 */
37
38#ifndef __MEM_PACKET_HH__
39#define __MEM_PACKET_HH__
40
41#include <cassert>
42#include <list>
1/*
2 * Copyright (c) 2006 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 26 unchanged lines hidden (view full) ---

35 * Declaration of the Packet class.
36 */
37
38#ifndef __MEM_PACKET_HH__
39#define __MEM_PACKET_HH__
40
41#include <cassert>
42#include <list>
43#include <bitset>
44
43
44#include "base/compiler.hh"
45#include "base/misc.hh"
46#include "mem/request.hh"
47#include "sim/host.hh"
48#include "sim/root.hh"
49
50
51struct Packet;
52typedef Packet *PacketPtr;

--- 4 unchanged lines hidden (view full) ---

57#define NACKED_LINE (1 << 0)
58#define SATISFIED (1 << 1)
59#define SHARED_LINE (1 << 2)
60#define CACHE_LINE_FILL (1 << 3)
61#define COMPRESSED (1 << 4)
62#define NO_ALLOCATE (1 << 5)
63#define SNOOP_COMMIT (1 << 6)
64
45#include "base/misc.hh"
46#include "mem/request.hh"
47#include "sim/host.hh"
48#include "sim/root.hh"
49
50
51struct Packet;
52typedef Packet *PacketPtr;

--- 4 unchanged lines hidden (view full) ---

57#define NACKED_LINE (1 << 0)
58#define SATISFIED (1 << 1)
59#define SHARED_LINE (1 << 2)
60#define CACHE_LINE_FILL (1 << 3)
61#define COMPRESSED (1 << 4)
62#define NO_ALLOCATE (1 << 5)
63#define SNOOP_COMMIT (1 << 6)
64
65
66class MemCmd
67{
68 public:
69
70 /** List of all commands associated with a packet. */
71 enum Command
72 {
73 InvalidCmd,
74 ReadReq,
75 WriteReq,
76 WriteReqNoAck,
77 ReadResp,
78 WriteResp,
79 Writeback,
80 SoftPFReq,
81 HardPFReq,
82 SoftPFResp,
83 HardPFResp,
84 InvalidateReq,
85 WriteInvalidateReq,
86 WriteInvalidateResp,
87 UpgradeReq,
88 ReadExReq,
89 ReadExResp,
90 NUM_MEM_CMDS
91 };
92
93 private:
94 /** List of command attributes. */
95 enum Attribute
96 {
97 IsRead,
98 IsWrite,
99 IsPrefetch,
100 IsInvalidate,
101 IsRequest,
102 IsResponse,
103 NeedsResponse,
104 IsSWPrefetch,
105 IsHWPrefetch,
106 IsUpgrade,
107 HasData,
108 NUM_COMMAND_ATTRIBUTES
109 };
110
111 /** Structure that defines attributes and other data associated
112 * with a Command. */
113 struct CommandInfo {
114 /** Set of attribute flags. */
115 const std::bitset<NUM_COMMAND_ATTRIBUTES> attributes;
116 /** Corresponding response for requests; InvalidCmd if no
117 * response is applicable. */
118 const Command response;
119 /** String representation (for printing) */
120 const std::string str;
121 };
122
123 /** Array to map Command enum to associated info. */
124 static const CommandInfo commandInfo[];
125
126 private:
127
128 Command cmd;
129
130 bool testCmdAttrib(MemCmd::Attribute attrib) const {
131 return commandInfo[cmd].attributes[attrib] != 0;
132 }
133
134 public:
135
136 bool isRead() const { return testCmdAttrib(IsRead); }
137 bool isWrite() const { return testCmdAttrib(IsWrite); }
138 bool isRequest() const { return testCmdAttrib(IsRequest); }
139 bool isResponse() const { return testCmdAttrib(IsResponse); }
140 bool needsResponse() const { return testCmdAttrib(NeedsResponse); }
141 bool isInvalidate() const { return testCmdAttrib(IsInvalidate); }
142 bool hasData() const { return testCmdAttrib(HasData); }
143
144 const Command responseCommand() const {
145 return commandInfo[cmd].response;
146 }
147
148 /** Return the string to a cmd given by idx. */
149 const std::string &toString() const {
150 return commandInfo[cmd].str;
151 }
152
153 int toInt() const { return (int)cmd; }
154
155 MemCmd(Command _cmd)
156 : cmd(_cmd)
157 { }
158
159 MemCmd(int _cmd)
160 : cmd((Command)_cmd)
161 { }
162
163 MemCmd()
164 : cmd(InvalidCmd)
165 { }
166
167 bool operator==(MemCmd c2) { return (cmd == c2.cmd); }
168 bool operator!=(MemCmd c2) { return (cmd != c2.cmd); }
169
170 friend class Packet;
171};
172
65//for now. @todo fix later
66#define NUM_MEM_CMDS (1 << 11)
173/**
174 * A Packet is used to encapsulate a transfer between two objects in
175 * the memory system (e.g., the L1 and L2 cache). (In contrast, a
176 * single Request travels all the way from the requester to the
177 * ultimate destination and back, possibly being conveyed by several
178 * different Packets along the way.)
179 */
180class Packet
181{
182 public:
67/**
68 * A Packet is used to encapsulate a transfer between two objects in
69 * the memory system (e.g., the L1 and L2 cache). (In contrast, a
70 * single Request travels all the way from the requester to the
71 * ultimate destination and back, possibly being conveyed by several
72 * different Packets along the way.)
73 */
74class Packet
75{
76 public:
183
184 typedef MemCmd::Command Command;
185
186 /** Temporary FLAGS field until cache gets working, this should be in coherence/sender state. */
187 uint64_t flags;
188
189 private:
190 /** A pointer to the data being transfered. It can be differnt
191 * sizes at each level of the heirarchy so it belongs in the
192 * packet, not request. This may or may not be populated when a
193 * responder recieves the packet. If not populated it memory

--- 79 unchanged lines hidden (view full) ---

273 public:
274 virtual ~SenderState() {}
275 };
276
277 /** This packet's sender state. Devices should use dynamic_cast<>
278 * to cast to the state appropriate to the sender. */
279 SenderState *senderState;
280
77 /** Temporary FLAGS field until cache gets working, this should be in coherence/sender state. */
78 uint64_t flags;
79
80 private:
81 /** A pointer to the data being transfered. It can be differnt
82 * sizes at each level of the heirarchy so it belongs in the
83 * packet, not request. This may or may not be populated when a
84 * responder recieves the packet. If not populated it memory

--- 79 unchanged lines hidden (view full) ---

164 public:
165 virtual ~SenderState() {}
166 };
167
168 /** This packet's sender state. Devices should use dynamic_cast<>
169 * to cast to the state appropriate to the sender. */
170 SenderState *senderState;
171
172 private:
173 /** List of command attributes. */
174 // If you add a new CommandAttribute, make sure to increase NUM_MEM_CMDS
175 // as well.
176 enum CommandAttribute
177 {
178 IsRead = 1 << 0,
179 IsWrite = 1 << 1,
180 IsPrefetch = 1 << 2,
181 IsInvalidate = 1 << 3,
182 IsRequest = 1 << 4,
183 IsResponse = 1 << 5,
184 NeedsResponse = 1 << 6,
185 IsSWPrefetch = 1 << 7,
186 IsHWPrefetch = 1 << 8,
187 IsUpgrade = 1 << 9,
188 HasData = 1 << 10
189 };
190
281 public:
191 public:
192 /** List of all commands associated with a packet. */
193 enum Command
194 {
195 InvalidCmd = 0,
196 ReadReq = IsRead | IsRequest | NeedsResponse,
197 WriteReq = IsWrite | IsRequest | NeedsResponse | HasData,
198 WriteReqNoAck = IsWrite | IsRequest | HasData,
199 ReadResp = IsRead | IsResponse | NeedsResponse | HasData,
200 WriteResp = IsWrite | IsResponse | NeedsResponse,
201 Writeback = IsWrite | IsRequest | HasData,
202 SoftPFReq = IsRead | IsRequest | IsSWPrefetch | NeedsResponse,
203 HardPFReq = IsRead | IsRequest | IsHWPrefetch | NeedsResponse,
204 SoftPFResp = IsRead | IsResponse | IsSWPrefetch
205 | NeedsResponse | HasData,
206 HardPFResp = IsRead | IsResponse | IsHWPrefetch
207 | NeedsResponse | HasData,
208 InvalidateReq = IsInvalidate | IsRequest,
209 WriteInvalidateReq = IsWrite | IsInvalidate | IsRequest
210 | HasData | NeedsResponse,
211 WriteInvalidateResp = IsWrite | IsInvalidate | IsRequest
212 | NeedsResponse | IsResponse,
213 UpgradeReq = IsInvalidate | IsRequest | IsUpgrade,
214 ReadExReq = IsRead | IsInvalidate | IsRequest | NeedsResponse,
215 ReadExResp = IsRead | IsInvalidate | IsResponse
216 | NeedsResponse | HasData
217 };
282
218
283 /** The command field of the packet. */
284 MemCmd cmd;
285
286 /** Return the string name of the cmd field (for debugging and
287 * tracing). */
219 /** Return the string name of the cmd field (for debugging and
220 * tracing). */
288 const std::string &cmdString() const { return cmd.toString(); }
221 const std::string &cmdString() const;
289
222
223 /** Reutrn the string to a cmd given by idx. */
224 const std::string &cmdIdxToString(Command idx);
225
290 /** Return the index of this command. */
226 /** Return the index of this command. */
291 inline int cmdToIndex() const { return cmd.toInt(); }
227 inline int cmdToIndex() const { return (int) cmd; }
292
228
293 public:
229 /** The command field of the packet. */
230 Command cmd;
294
231
295 bool isRead() const { return cmd.isRead(); }
296 bool isWrite() const { return cmd.isWrite(); }
297 bool isRequest() const { return cmd.isRequest(); }
298 bool isResponse() const { return cmd.isResponse(); }
299 bool needsResponse() const { return cmd.needsResponse(); }
300 bool isInvalidate() const { return cmd.isInvalidate(); }
301 bool hasData() const { return cmd.hasData(); }
232 bool isRead() const { return (cmd & IsRead) != 0; }
233 bool isWrite() const { return (cmd & IsWrite) != 0; }
234 bool isRequest() const { return (cmd & IsRequest) != 0; }
235 bool isResponse() const { return (cmd & IsResponse) != 0; }
236 bool needsResponse() const { return (cmd & NeedsResponse) != 0; }
237 bool isInvalidate() const { return (cmd & IsInvalidate) != 0; }
238 bool hasData() const { return (cmd & HasData) != 0; }
302
303 bool isCacheFill() const { return (flags & CACHE_LINE_FILL) != 0; }
304 bool isNoAllocate() const { return (flags & NO_ALLOCATE) != 0; }
305 bool isCompressed() const { return (flags & COMPRESSED) != 0; }
306
307 bool nic_pkt() { panic("Unimplemented"); M5_DUMMY_RETURN }
308
309 /** Possible results of a packet's request. */

--- 17 unchanged lines hidden (view full) ---

327 short getDest() const { return dest; }
328 void setDest(short _dest) { dest = _dest; }
329
330 Addr getAddr() const { assert(addrSizeValid); return addr; }
331 int getSize() const { assert(addrSizeValid); return size; }
332 Addr getOffset(int blkSize) const { return addr & (Addr)(blkSize - 1); }
333
334 void addrOverride(Addr newAddr) { assert(addrSizeValid); addr = newAddr; }
239
240 bool isCacheFill() const { return (flags & CACHE_LINE_FILL) != 0; }
241 bool isNoAllocate() const { return (flags & NO_ALLOCATE) != 0; }
242 bool isCompressed() const { return (flags & COMPRESSED) != 0; }
243
244 bool nic_pkt() { panic("Unimplemented"); M5_DUMMY_RETURN }
245
246 /** Possible results of a packet's request. */

--- 17 unchanged lines hidden (view full) ---

264 short getDest() const { return dest; }
265 void setDest(short _dest) { dest = _dest; }
266
267 Addr getAddr() const { assert(addrSizeValid); return addr; }
268 int getSize() const { assert(addrSizeValid); return size; }
269 Addr getOffset(int blkSize) const { return addr & (Addr)(blkSize - 1); }
270
271 void addrOverride(Addr newAddr) { assert(addrSizeValid); addr = newAddr; }
335 void cmdOverride(MemCmd newCmd) { cmd = newCmd; }
272 void cmdOverride(Command newCmd) { cmd = newCmd; }
336
337 /** Constructor. Note that a Request object must be constructed
338 * first, but the Requests's physical address and size fields
339 * need not be valid. The command and destination addresses
340 * must be supplied. */
273
274 /** Constructor. Note that a Request object must be constructed
275 * first, but the Requests's physical address and size fields
276 * need not be valid. The command and destination addresses
277 * must be supplied. */
341 Packet(Request *_req, MemCmd _cmd, short _dest)
278 Packet(Request *_req, Command _cmd, short _dest)
342 : data(NULL), staticData(false), dynamicData(false), arrayData(false),
343 addr(_req->paddr), size(_req->size), dest(_dest),
344 addrSizeValid(_req->validPaddr),
345 srcValid(false),
346 req(_req), coherence(NULL), senderState(NULL), cmd(_cmd),
347 result(Unknown)
348 {
349 flags = 0;
350 time = curTick;
351 }
352
353 /** Alternate constructor if you are trying to create a packet with
354 * a request that is for a whole block, not the address from the req.
355 * this allows for overriding the size/addr of the req.*/
279 : data(NULL), staticData(false), dynamicData(false), arrayData(false),
280 addr(_req->paddr), size(_req->size), dest(_dest),
281 addrSizeValid(_req->validPaddr),
282 srcValid(false),
283 req(_req), coherence(NULL), senderState(NULL), cmd(_cmd),
284 result(Unknown)
285 {
286 flags = 0;
287 time = curTick;
288 }
289
290 /** Alternate constructor if you are trying to create a packet with
291 * a request that is for a whole block, not the address from the req.
292 * this allows for overriding the size/addr of the req.*/
356 Packet(Request *_req, MemCmd _cmd, short _dest, int _blkSize)
293 Packet(Request *_req, Command _cmd, short _dest, int _blkSize)
357 : data(NULL), staticData(false), dynamicData(false), arrayData(false),
358 addr(_req->paddr & ~(_blkSize - 1)), size(_blkSize),
359 dest(_dest),
360 addrSizeValid(_req->validPaddr), srcValid(false),
361 req(_req), coherence(NULL), senderState(NULL), cmd(_cmd),
362 result(Unknown)
363 {
364 flags = 0;

--- 28 unchanged lines hidden (view full) ---

393 * for returning as a response to that request. Used for timing
394 * accesses only. For atomic and functional accesses, the
395 * request packet is always implicitly passed back *without*
396 * modifying the destination fields, so this function
397 * should not be called. */
398 void makeTimingResponse() {
399 assert(needsResponse());
400 assert(isRequest());
294 : data(NULL), staticData(false), dynamicData(false), arrayData(false),
295 addr(_req->paddr & ~(_blkSize - 1)), size(_blkSize),
296 dest(_dest),
297 addrSizeValid(_req->validPaddr), srcValid(false),
298 req(_req), coherence(NULL), senderState(NULL), cmd(_cmd),
299 result(Unknown)
300 {
301 flags = 0;

--- 28 unchanged lines hidden (view full) ---

330 * for returning as a response to that request. Used for timing
331 * accesses only. For atomic and functional accesses, the
332 * request packet is always implicitly passed back *without*
333 * modifying the destination fields, so this function
334 * should not be called. */
335 void makeTimingResponse() {
336 assert(needsResponse());
337 assert(isRequest());
401 cmd = cmd.responseCommand();
338 int icmd = (int)cmd;
339 icmd &= ~(IsRequest);
340 icmd |= IsResponse;
341 if (isRead())
342 icmd |= HasData;
343 if (isWrite())
344 icmd &= ~HasData;
345 cmd = (Command)icmd;
402 dest = src;
403 srcValid = false;
404 }
405
346 dest = src;
347 srcValid = false;
348 }
349
350
351 void toggleData() {
352 int icmd = (int)cmd;
353 icmd ^= HasData;
354 cmd = (Command)icmd;
355 }
356
406 /**
407 * Take a request packet and modify it in place to be suitable for
408 * returning as a response to that request.
409 */
410 void makeAtomicResponse()
411 {
412 assert(needsResponse());
413 assert(isRequest());
357 /**
358 * Take a request packet and modify it in place to be suitable for
359 * returning as a response to that request.
360 */
361 void makeAtomicResponse()
362 {
363 assert(needsResponse());
364 assert(isRequest());
414 cmd = cmd.responseCommand();
365 int icmd = (int)cmd;
366 icmd &= ~(IsRequest);
367 icmd |= IsResponse;
368 if (isRead())
369 icmd |= HasData;
370 if (isWrite())
371 icmd &= ~HasData;
372 cmd = (Command)icmd;
415 }
416
417 /**
418 * Take a request packet that has been returned as NACKED and
419 * modify it so that it can be sent out again. Only packets that
420 * need a response can be NACKED, so verify that that is true.
421 */
422 void

--- 96 unchanged lines hidden ---
373 }
374
375 /**
376 * Take a request packet that has been returned as NACKED and
377 * modify it so that it can be sent out again. Only packets that
378 * need a response can be NACKED, so verify that that is true.
379 */
380 void

--- 96 unchanged lines hidden ---