packet.hh (4489:381fcb5b6c31) packet.hh (4610:97834b18a8b4)
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;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Ron Dreslinski
29 * Steve Reinhardt
30 * Ali Saidi
31 */
32
33/**
34 * @file
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
45#include "base/compiler.hh"
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;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Ron Dreslinski
29 * Steve Reinhardt
30 * Ali Saidi
31 */
32
33/**
34 * @file
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
45#include "base/compiler.hh"
46#include "base/fast_alloc.hh"
46#include "base/misc.hh"
47#include "mem/request.hh"
48#include "sim/host.hh"
49#include "sim/core.hh"
50
51
52struct Packet;
53typedef Packet *PacketPtr;
54typedef uint8_t* PacketDataPtr;
55typedef std::list<PacketPtr> PacketList;
56
57//Coherence Flags
58#define NACKED_LINE (1 << 0)
59#define SATISFIED (1 << 1)
60#define SHARED_LINE (1 << 2)
61#define CACHE_LINE_FILL (1 << 3)
62#define COMPRESSED (1 << 4)
63#define NO_ALLOCATE (1 << 5)
64#define SNOOP_COMMIT (1 << 6)
65
66
67class MemCmd
68{
69 public:
70
71 /** List of all commands associated with a packet. */
72 enum Command
73 {
74 InvalidCmd,
75 ReadReq,
76 WriteReq,
77 WriteReqNoAck,
78 ReadResp,
79 WriteResp,
80 Writeback,
81 SoftPFReq,
82 HardPFReq,
83 SoftPFResp,
84 HardPFResp,
85 InvalidateReq,
86 WriteInvalidateReq,
87 WriteInvalidateResp,
88 UpgradeReq,
89 ReadExReq,
90 ReadExResp,
91 SwapReq,
92 SwapResp,
93 NUM_MEM_CMDS
94 };
95
96 private:
97 /** List of command attributes. */
98 enum Attribute
99 {
100 IsRead,
101 IsWrite,
102 IsPrefetch,
103 IsInvalidate,
104 IsRequest,
105 IsResponse,
106 NeedsResponse,
107 IsSWPrefetch,
108 IsHWPrefetch,
109 IsUpgrade,
110 HasData,
111 IsReadWrite,
112 NUM_COMMAND_ATTRIBUTES
113 };
114
115 /** Structure that defines attributes and other data associated
116 * with a Command. */
117 struct CommandInfo {
118 /** Set of attribute flags. */
119 const std::bitset<NUM_COMMAND_ATTRIBUTES> attributes;
120 /** Corresponding response for requests; InvalidCmd if no
121 * response is applicable. */
122 const Command response;
123 /** String representation (for printing) */
124 const std::string str;
125 };
126
127 /** Array to map Command enum to associated info. */
128 static const CommandInfo commandInfo[];
129
130 private:
131
132 Command cmd;
133
134 bool testCmdAttrib(MemCmd::Attribute attrib) const {
135 return commandInfo[cmd].attributes[attrib] != 0;
136 }
137
138 public:
139
140 bool isRead() const { return testCmdAttrib(IsRead); }
141 bool isWrite() const { return testCmdAttrib(IsWrite); }
142 bool isRequest() const { return testCmdAttrib(IsRequest); }
143 bool isResponse() const { return testCmdAttrib(IsResponse); }
144 bool needsResponse() const { return testCmdAttrib(NeedsResponse); }
145 bool isInvalidate() const { return testCmdAttrib(IsInvalidate); }
146 bool hasData() const { return testCmdAttrib(HasData); }
147 bool isReadWrite() const { return testCmdAttrib(IsReadWrite); }
148
149 const Command responseCommand() const {
150 return commandInfo[cmd].response;
151 }
152
153 /** Return the string to a cmd given by idx. */
154 const std::string &toString() const {
155 return commandInfo[cmd].str;
156 }
157
158 int toInt() const { return (int)cmd; }
159
160 MemCmd(Command _cmd)
161 : cmd(_cmd)
162 { }
163
164 MemCmd(int _cmd)
165 : cmd((Command)_cmd)
166 { }
167
168 MemCmd()
169 : cmd(InvalidCmd)
170 { }
171
172 bool operator==(MemCmd c2) { return (cmd == c2.cmd); }
173 bool operator!=(MemCmd c2) { return (cmd != c2.cmd); }
174
175 friend class Packet;
176};
177
178/**
179 * A Packet is used to encapsulate a transfer between two objects in
180 * the memory system (e.g., the L1 and L2 cache). (In contrast, a
181 * single Request travels all the way from the requester to the
182 * ultimate destination and back, possibly being conveyed by several
183 * different Packets along the way.)
184 */
47#include "base/misc.hh"
48#include "mem/request.hh"
49#include "sim/host.hh"
50#include "sim/core.hh"
51
52
53struct Packet;
54typedef Packet *PacketPtr;
55typedef uint8_t* PacketDataPtr;
56typedef std::list<PacketPtr> PacketList;
57
58//Coherence Flags
59#define NACKED_LINE (1 << 0)
60#define SATISFIED (1 << 1)
61#define SHARED_LINE (1 << 2)
62#define CACHE_LINE_FILL (1 << 3)
63#define COMPRESSED (1 << 4)
64#define NO_ALLOCATE (1 << 5)
65#define SNOOP_COMMIT (1 << 6)
66
67
68class MemCmd
69{
70 public:
71
72 /** List of all commands associated with a packet. */
73 enum Command
74 {
75 InvalidCmd,
76 ReadReq,
77 WriteReq,
78 WriteReqNoAck,
79 ReadResp,
80 WriteResp,
81 Writeback,
82 SoftPFReq,
83 HardPFReq,
84 SoftPFResp,
85 HardPFResp,
86 InvalidateReq,
87 WriteInvalidateReq,
88 WriteInvalidateResp,
89 UpgradeReq,
90 ReadExReq,
91 ReadExResp,
92 SwapReq,
93 SwapResp,
94 NUM_MEM_CMDS
95 };
96
97 private:
98 /** List of command attributes. */
99 enum Attribute
100 {
101 IsRead,
102 IsWrite,
103 IsPrefetch,
104 IsInvalidate,
105 IsRequest,
106 IsResponse,
107 NeedsResponse,
108 IsSWPrefetch,
109 IsHWPrefetch,
110 IsUpgrade,
111 HasData,
112 IsReadWrite,
113 NUM_COMMAND_ATTRIBUTES
114 };
115
116 /** Structure that defines attributes and other data associated
117 * with a Command. */
118 struct CommandInfo {
119 /** Set of attribute flags. */
120 const std::bitset<NUM_COMMAND_ATTRIBUTES> attributes;
121 /** Corresponding response for requests; InvalidCmd if no
122 * response is applicable. */
123 const Command response;
124 /** String representation (for printing) */
125 const std::string str;
126 };
127
128 /** Array to map Command enum to associated info. */
129 static const CommandInfo commandInfo[];
130
131 private:
132
133 Command cmd;
134
135 bool testCmdAttrib(MemCmd::Attribute attrib) const {
136 return commandInfo[cmd].attributes[attrib] != 0;
137 }
138
139 public:
140
141 bool isRead() const { return testCmdAttrib(IsRead); }
142 bool isWrite() const { return testCmdAttrib(IsWrite); }
143 bool isRequest() const { return testCmdAttrib(IsRequest); }
144 bool isResponse() const { return testCmdAttrib(IsResponse); }
145 bool needsResponse() const { return testCmdAttrib(NeedsResponse); }
146 bool isInvalidate() const { return testCmdAttrib(IsInvalidate); }
147 bool hasData() const { return testCmdAttrib(HasData); }
148 bool isReadWrite() const { return testCmdAttrib(IsReadWrite); }
149
150 const Command responseCommand() const {
151 return commandInfo[cmd].response;
152 }
153
154 /** Return the string to a cmd given by idx. */
155 const std::string &toString() const {
156 return commandInfo[cmd].str;
157 }
158
159 int toInt() const { return (int)cmd; }
160
161 MemCmd(Command _cmd)
162 : cmd(_cmd)
163 { }
164
165 MemCmd(int _cmd)
166 : cmd((Command)_cmd)
167 { }
168
169 MemCmd()
170 : cmd(InvalidCmd)
171 { }
172
173 bool operator==(MemCmd c2) { return (cmd == c2.cmd); }
174 bool operator!=(MemCmd c2) { return (cmd != c2.cmd); }
175
176 friend class Packet;
177};
178
179/**
180 * A Packet is used to encapsulate a transfer between two objects in
181 * the memory system (e.g., the L1 and L2 cache). (In contrast, a
182 * single Request travels all the way from the requester to the
183 * ultimate destination and back, possibly being conveyed by several
184 * different Packets along the way.)
185 */
185class Packet
186class Packet : public FastAlloc
186{
187 public:
188
189 typedef MemCmd::Command Command;
190
191 /** Temporary FLAGS field until cache gets working, this should be in coherence/sender state. */
192 uint64_t flags;
193
194 private:
195 /** A pointer to the data being transfered. It can be differnt
196 * sizes at each level of the heirarchy so it belongs in the
197 * packet, not request. This may or may not be populated when a
198 * responder recieves the packet. If not populated it memory
199 * should be allocated.
200 */
201 PacketDataPtr data;
202
203 /** Is the data pointer set to a value that shouldn't be freed
204 * when the packet is destroyed? */
205 bool staticData;
206 /** The data pointer points to a value that should be freed when
207 * the packet is destroyed. */
208 bool dynamicData;
209 /** the data pointer points to an array (thus delete [] ) needs to
210 * be called on it rather than simply delete.*/
211 bool arrayData;
212
213 /** The address of the request. This address could be virtual or
214 * physical, depending on the system configuration. */
215 Addr addr;
216
217 /** The size of the request or transfer. */
218 int size;
219
220 /** Device address (e.g., bus ID) of the source of the
221 * transaction. The source is not responsible for setting this
222 * field; it is set implicitly by the interconnect when the
223 * packet is first sent. */
224 short src;
225
226 /** Device address (e.g., bus ID) of the destination of the
227 * transaction. The special value Broadcast indicates that the
228 * packet should be routed based on its address. This field is
229 * initialized in the constructor and is thus always valid
230 * (unlike * addr, size, and src). */
231 short dest;
232
233 /** Are the 'addr' and 'size' fields valid? */
234 bool addrSizeValid;
235 /** Is the 'src' field valid? */
236 bool srcValid;
237
238
239 public:
240
241 /** Used to calculate latencies for each packet.*/
242 Tick time;
243
244 /** The time at which the packet will be fully transmitted */
245 Tick finishTime;
246
247 /** The time at which the first chunk of the packet will be transmitted */
248 Tick firstWordTime;
249
250 /** The special destination address indicating that the packet
251 * should be routed based on its address. */
252 static const short Broadcast = -1;
253
254 /** A pointer to the original request. */
255 RequestPtr req;
256
257 /** A virtual base opaque structure used to hold coherence-related
258 * state. A specific subclass would be derived from this to
259 * carry state specific to a particular coherence protocol. */
187{
188 public:
189
190 typedef MemCmd::Command Command;
191
192 /** Temporary FLAGS field until cache gets working, this should be in coherence/sender state. */
193 uint64_t flags;
194
195 private:
196 /** A pointer to the data being transfered. It can be differnt
197 * sizes at each level of the heirarchy so it belongs in the
198 * packet, not request. This may or may not be populated when a
199 * responder recieves the packet. If not populated it memory
200 * should be allocated.
201 */
202 PacketDataPtr data;
203
204 /** Is the data pointer set to a value that shouldn't be freed
205 * when the packet is destroyed? */
206 bool staticData;
207 /** The data pointer points to a value that should be freed when
208 * the packet is destroyed. */
209 bool dynamicData;
210 /** the data pointer points to an array (thus delete [] ) needs to
211 * be called on it rather than simply delete.*/
212 bool arrayData;
213
214 /** The address of the request. This address could be virtual or
215 * physical, depending on the system configuration. */
216 Addr addr;
217
218 /** The size of the request or transfer. */
219 int size;
220
221 /** Device address (e.g., bus ID) of the source of the
222 * transaction. The source is not responsible for setting this
223 * field; it is set implicitly by the interconnect when the
224 * packet is first sent. */
225 short src;
226
227 /** Device address (e.g., bus ID) of the destination of the
228 * transaction. The special value Broadcast indicates that the
229 * packet should be routed based on its address. This field is
230 * initialized in the constructor and is thus always valid
231 * (unlike * addr, size, and src). */
232 short dest;
233
234 /** Are the 'addr' and 'size' fields valid? */
235 bool addrSizeValid;
236 /** Is the 'src' field valid? */
237 bool srcValid;
238
239
240 public:
241
242 /** Used to calculate latencies for each packet.*/
243 Tick time;
244
245 /** The time at which the packet will be fully transmitted */
246 Tick finishTime;
247
248 /** The time at which the first chunk of the packet will be transmitted */
249 Tick firstWordTime;
250
251 /** The special destination address indicating that the packet
252 * should be routed based on its address. */
253 static const short Broadcast = -1;
254
255 /** A pointer to the original request. */
256 RequestPtr req;
257
258 /** A virtual base opaque structure used to hold coherence-related
259 * state. A specific subclass would be derived from this to
260 * carry state specific to a particular coherence protocol. */
260 class CoherenceState {
261 class CoherenceState : public FastAlloc {
261 public:
262 virtual ~CoherenceState() {}
263 };
264
265 /** This packet's coherence state. Caches should use
266 * dynamic_cast<> to cast to the state appropriate for the
267 * system's coherence protocol. */
268 CoherenceState *coherence;
269
270 /** A virtual base opaque structure used to hold state associated
271 * with the packet but specific to the sending device (e.g., an
272 * MSHR). A pointer to this state is returned in the packet's
273 * response so that the sender can quickly look up the state
274 * needed to process it. A specific subclass would be derived
275 * from this to carry state specific to a particular sending
276 * device. */
262 public:
263 virtual ~CoherenceState() {}
264 };
265
266 /** This packet's coherence state. Caches should use
267 * dynamic_cast<> to cast to the state appropriate for the
268 * system's coherence protocol. */
269 CoherenceState *coherence;
270
271 /** A virtual base opaque structure used to hold state associated
272 * with the packet but specific to the sending device (e.g., an
273 * MSHR). A pointer to this state is returned in the packet's
274 * response so that the sender can quickly look up the state
275 * needed to process it. A specific subclass would be derived
276 * from this to carry state specific to a particular sending
277 * device. */
277 class SenderState {
278 class SenderState : public FastAlloc {
278 public:
279 virtual ~SenderState() {}
280 };
281
282 /** This packet's sender state. Devices should use dynamic_cast<>
283 * to cast to the state appropriate to the sender. */
284 SenderState *senderState;
285
286 public:
287
288 /** The command field of the packet. */
289 MemCmd cmd;
290
291 /** Return the string name of the cmd field (for debugging and
292 * tracing). */
293 const std::string &cmdString() const { return cmd.toString(); }
294
295 /** Return the index of this command. */
296 inline int cmdToIndex() const { return cmd.toInt(); }
297
298 public:
299
300 bool isRead() const { return cmd.isRead(); }
301 bool isWrite() const { return cmd.isWrite(); }
302 bool isRequest() const { return cmd.isRequest(); }
303 bool isResponse() const { return cmd.isResponse(); }
304 bool needsResponse() const { return cmd.needsResponse(); }
305 bool isInvalidate() const { return cmd.isInvalidate(); }
306 bool hasData() const { return cmd.hasData(); }
307 bool isReadWrite() const { return cmd.isReadWrite(); }
308
309 bool isCacheFill() const { return (flags & CACHE_LINE_FILL) != 0; }
310 bool isNoAllocate() const { return (flags & NO_ALLOCATE) != 0; }
311 bool isCompressed() const { return (flags & COMPRESSED) != 0; }
312
313 bool nic_pkt() { panic("Unimplemented"); M5_DUMMY_RETURN }
314
315 /** Possible results of a packet's request. */
316 enum Result
317 {
318 Success,
319 BadAddress,
320 Nacked,
321 Unknown
322 };
323
324 /** The result of this packet's request. */
325 Result result;
326
327 /** Accessor function that returns the source index of the packet. */
328 short getSrc() const { assert(srcValid); return src; }
329 void setSrc(short _src) { src = _src; srcValid = true; }
330
331 /** Accessor function that returns the destination index of
332 the packet. */
333 short getDest() const { return dest; }
334 void setDest(short _dest) { dest = _dest; }
335
336 Addr getAddr() const { assert(addrSizeValid); return addr; }
337 int getSize() const { assert(addrSizeValid); return size; }
338 Addr getOffset(int blkSize) const { return addr & (Addr)(blkSize - 1); }
339
340 void addrOverride(Addr newAddr) { assert(addrSizeValid); addr = newAddr; }
341 void cmdOverride(MemCmd newCmd) { cmd = newCmd; }
342
343 /** Constructor. Note that a Request object must be constructed
344 * first, but the Requests's physical address and size fields
345 * need not be valid. The command and destination addresses
346 * must be supplied. */
347 Packet(Request *_req, MemCmd _cmd, short _dest)
348 : data(NULL), staticData(false), dynamicData(false), arrayData(false),
349 addr(_req->paddr), size(_req->size), dest(_dest),
350 addrSizeValid(_req->validPaddr),
351 srcValid(false),
352 req(_req), coherence(NULL), senderState(NULL), cmd(_cmd),
353 result(Unknown)
354 {
355 flags = 0;
356 time = curTick;
357 }
358
359 /** Alternate constructor if you are trying to create a packet with
360 * a request that is for a whole block, not the address from the req.
361 * this allows for overriding the size/addr of the req.*/
362 Packet(Request *_req, MemCmd _cmd, short _dest, int _blkSize)
363 : data(NULL), staticData(false), dynamicData(false), arrayData(false),
364 addr(_req->paddr & ~(_blkSize - 1)), size(_blkSize),
365 dest(_dest),
366 addrSizeValid(_req->validPaddr), srcValid(false),
367 req(_req), coherence(NULL), senderState(NULL), cmd(_cmd),
368 result(Unknown)
369 {
370 flags = 0;
371 time = curTick;
372 }
373
374 /** Destructor. */
375 ~Packet()
376 { if (staticData || dynamicData) deleteData(); }
377
378 /** Reinitialize packet address and size from the associated
379 * Request object, and reset other fields that may have been
380 * modified by a previous transaction. Typically called when a
381 * statically allocated Request/Packet pair is reused for
382 * multiple transactions. */
383 void reinitFromRequest() {
384 assert(req->validPaddr);
385 flags = 0;
386 addr = req->paddr;
387 size = req->size;
388 time = req->time;
389 addrSizeValid = true;
390 result = Unknown;
391 if (dynamicData) {
392 deleteData();
393 dynamicData = false;
394 arrayData = false;
395 }
396 }
397
398 /** Take a request packet and modify it in place to be suitable
399 * for returning as a response to that request. Used for timing
400 * accesses only. For atomic and functional accesses, the
401 * request packet is always implicitly passed back *without*
402 * modifying the destination fields, so this function
403 * should not be called. */
404 void makeTimingResponse() {
405 assert(needsResponse());
406 assert(isRequest());
407 cmd = cmd.responseCommand();
408 dest = src;
409 srcValid = false;
410 }
411
412 /**
413 * Take a request packet and modify it in place to be suitable for
414 * returning as a response to that request.
415 */
416 void makeAtomicResponse()
417 {
418 assert(needsResponse());
419 assert(isRequest());
420 cmd = cmd.responseCommand();
421 }
422
423 /**
424 * Take a request packet that has been returned as NACKED and
425 * modify it so that it can be sent out again. Only packets that
426 * need a response can be NACKED, so verify that that is true.
427 */
428 void
429 reinitNacked()
430 {
431 assert(needsResponse() && result == Nacked);
432 dest = Broadcast;
433 result = Unknown;
434 }
435
436
437 /**
438 * Set the data pointer to the following value that should not be
439 * freed.
440 */
441 template <typename T>
442 void
443 dataStatic(T *p)
444 {
445 if(dynamicData)
446 dynamicData = false;
447 data = (PacketDataPtr)p;
448 staticData = true;
449 }
450
451 /**
452 * Set the data pointer to a value that should have delete []
453 * called on it.
454 */
455 template <typename T>
456 void
457 dataDynamicArray(T *p)
458 {
459 assert(!staticData && !dynamicData);
460 data = (PacketDataPtr)p;
461 dynamicData = true;
462 arrayData = true;
463 }
464
465 /**
466 * set the data pointer to a value that should have delete called
467 * on it.
468 */
469 template <typename T>
470 void
471 dataDynamic(T *p)
472 {
473 assert(!staticData && !dynamicData);
474 data = (PacketDataPtr)p;
475 dynamicData = true;
476 arrayData = false;
477 }
478
479 /** get a pointer to the data ptr. */
480 template <typename T>
481 T*
482 getPtr()
483 {
484 assert(staticData || dynamicData);
485 return (T*)data;
486 }
487
488 /** return the value of what is pointed to in the packet. */
489 template <typename T>
490 T get();
491
492 /** set the value in the data pointer to v. */
493 template <typename T>
494 void set(T v);
495
496 /**
497 * delete the data pointed to in the data pointer. Ok to call to
498 * matter how data was allocted.
499 */
500 void deleteData();
501
502 /** If there isn't data in the packet, allocate some. */
503 void allocate();
504
505 /** Do the packet modify the same addresses. */
506 bool intersect(PacketPtr p);
507};
508
509/** This function given a functional packet and a timing packet either
510 * satisfies the timing packet, or updates the timing packet to
511 * reflect the updated state in the timing packet. It returns if the
512 * functional packet should continue to traverse the memory hierarchy
513 * or not.
514 */
515bool fixPacket(PacketPtr func, PacketPtr timing);
516
517/** This function is a wrapper for the fixPacket field that toggles
518 * the hasData bit it is used when a response is waiting in the
519 * caches, but hasn't been marked as a response yet (so the fixPacket
520 * needs to get the correct value for the hasData)
521 */
522bool fixDelayedResponsePacket(PacketPtr func, PacketPtr timing);
523
524std::ostream & operator<<(std::ostream &o, const Packet &p);
525
526#endif //__MEM_PACKET_HH
279 public:
280 virtual ~SenderState() {}
281 };
282
283 /** This packet's sender state. Devices should use dynamic_cast<>
284 * to cast to the state appropriate to the sender. */
285 SenderState *senderState;
286
287 public:
288
289 /** The command field of the packet. */
290 MemCmd cmd;
291
292 /** Return the string name of the cmd field (for debugging and
293 * tracing). */
294 const std::string &cmdString() const { return cmd.toString(); }
295
296 /** Return the index of this command. */
297 inline int cmdToIndex() const { return cmd.toInt(); }
298
299 public:
300
301 bool isRead() const { return cmd.isRead(); }
302 bool isWrite() const { return cmd.isWrite(); }
303 bool isRequest() const { return cmd.isRequest(); }
304 bool isResponse() const { return cmd.isResponse(); }
305 bool needsResponse() const { return cmd.needsResponse(); }
306 bool isInvalidate() const { return cmd.isInvalidate(); }
307 bool hasData() const { return cmd.hasData(); }
308 bool isReadWrite() const { return cmd.isReadWrite(); }
309
310 bool isCacheFill() const { return (flags & CACHE_LINE_FILL) != 0; }
311 bool isNoAllocate() const { return (flags & NO_ALLOCATE) != 0; }
312 bool isCompressed() const { return (flags & COMPRESSED) != 0; }
313
314 bool nic_pkt() { panic("Unimplemented"); M5_DUMMY_RETURN }
315
316 /** Possible results of a packet's request. */
317 enum Result
318 {
319 Success,
320 BadAddress,
321 Nacked,
322 Unknown
323 };
324
325 /** The result of this packet's request. */
326 Result result;
327
328 /** Accessor function that returns the source index of the packet. */
329 short getSrc() const { assert(srcValid); return src; }
330 void setSrc(short _src) { src = _src; srcValid = true; }
331
332 /** Accessor function that returns the destination index of
333 the packet. */
334 short getDest() const { return dest; }
335 void setDest(short _dest) { dest = _dest; }
336
337 Addr getAddr() const { assert(addrSizeValid); return addr; }
338 int getSize() const { assert(addrSizeValid); return size; }
339 Addr getOffset(int blkSize) const { return addr & (Addr)(blkSize - 1); }
340
341 void addrOverride(Addr newAddr) { assert(addrSizeValid); addr = newAddr; }
342 void cmdOverride(MemCmd newCmd) { cmd = newCmd; }
343
344 /** Constructor. Note that a Request object must be constructed
345 * first, but the Requests's physical address and size fields
346 * need not be valid. The command and destination addresses
347 * must be supplied. */
348 Packet(Request *_req, MemCmd _cmd, short _dest)
349 : data(NULL), staticData(false), dynamicData(false), arrayData(false),
350 addr(_req->paddr), size(_req->size), dest(_dest),
351 addrSizeValid(_req->validPaddr),
352 srcValid(false),
353 req(_req), coherence(NULL), senderState(NULL), cmd(_cmd),
354 result(Unknown)
355 {
356 flags = 0;
357 time = curTick;
358 }
359
360 /** Alternate constructor if you are trying to create a packet with
361 * a request that is for a whole block, not the address from the req.
362 * this allows for overriding the size/addr of the req.*/
363 Packet(Request *_req, MemCmd _cmd, short _dest, int _blkSize)
364 : data(NULL), staticData(false), dynamicData(false), arrayData(false),
365 addr(_req->paddr & ~(_blkSize - 1)), size(_blkSize),
366 dest(_dest),
367 addrSizeValid(_req->validPaddr), srcValid(false),
368 req(_req), coherence(NULL), senderState(NULL), cmd(_cmd),
369 result(Unknown)
370 {
371 flags = 0;
372 time = curTick;
373 }
374
375 /** Destructor. */
376 ~Packet()
377 { if (staticData || dynamicData) deleteData(); }
378
379 /** Reinitialize packet address and size from the associated
380 * Request object, and reset other fields that may have been
381 * modified by a previous transaction. Typically called when a
382 * statically allocated Request/Packet pair is reused for
383 * multiple transactions. */
384 void reinitFromRequest() {
385 assert(req->validPaddr);
386 flags = 0;
387 addr = req->paddr;
388 size = req->size;
389 time = req->time;
390 addrSizeValid = true;
391 result = Unknown;
392 if (dynamicData) {
393 deleteData();
394 dynamicData = false;
395 arrayData = false;
396 }
397 }
398
399 /** Take a request packet and modify it in place to be suitable
400 * for returning as a response to that request. Used for timing
401 * accesses only. For atomic and functional accesses, the
402 * request packet is always implicitly passed back *without*
403 * modifying the destination fields, so this function
404 * should not be called. */
405 void makeTimingResponse() {
406 assert(needsResponse());
407 assert(isRequest());
408 cmd = cmd.responseCommand();
409 dest = src;
410 srcValid = false;
411 }
412
413 /**
414 * Take a request packet and modify it in place to be suitable for
415 * returning as a response to that request.
416 */
417 void makeAtomicResponse()
418 {
419 assert(needsResponse());
420 assert(isRequest());
421 cmd = cmd.responseCommand();
422 }
423
424 /**
425 * Take a request packet that has been returned as NACKED and
426 * modify it so that it can be sent out again. Only packets that
427 * need a response can be NACKED, so verify that that is true.
428 */
429 void
430 reinitNacked()
431 {
432 assert(needsResponse() && result == Nacked);
433 dest = Broadcast;
434 result = Unknown;
435 }
436
437
438 /**
439 * Set the data pointer to the following value that should not be
440 * freed.
441 */
442 template <typename T>
443 void
444 dataStatic(T *p)
445 {
446 if(dynamicData)
447 dynamicData = false;
448 data = (PacketDataPtr)p;
449 staticData = true;
450 }
451
452 /**
453 * Set the data pointer to a value that should have delete []
454 * called on it.
455 */
456 template <typename T>
457 void
458 dataDynamicArray(T *p)
459 {
460 assert(!staticData && !dynamicData);
461 data = (PacketDataPtr)p;
462 dynamicData = true;
463 arrayData = true;
464 }
465
466 /**
467 * set the data pointer to a value that should have delete called
468 * on it.
469 */
470 template <typename T>
471 void
472 dataDynamic(T *p)
473 {
474 assert(!staticData && !dynamicData);
475 data = (PacketDataPtr)p;
476 dynamicData = true;
477 arrayData = false;
478 }
479
480 /** get a pointer to the data ptr. */
481 template <typename T>
482 T*
483 getPtr()
484 {
485 assert(staticData || dynamicData);
486 return (T*)data;
487 }
488
489 /** return the value of what is pointed to in the packet. */
490 template <typename T>
491 T get();
492
493 /** set the value in the data pointer to v. */
494 template <typename T>
495 void set(T v);
496
497 /**
498 * delete the data pointed to in the data pointer. Ok to call to
499 * matter how data was allocted.
500 */
501 void deleteData();
502
503 /** If there isn't data in the packet, allocate some. */
504 void allocate();
505
506 /** Do the packet modify the same addresses. */
507 bool intersect(PacketPtr p);
508};
509
510/** This function given a functional packet and a timing packet either
511 * satisfies the timing packet, or updates the timing packet to
512 * reflect the updated state in the timing packet. It returns if the
513 * functional packet should continue to traverse the memory hierarchy
514 * or not.
515 */
516bool fixPacket(PacketPtr func, PacketPtr timing);
517
518/** This function is a wrapper for the fixPacket field that toggles
519 * the hasData bit it is used when a response is waiting in the
520 * caches, but hasn't been marked as a response yet (so the fixPacket
521 * needs to get the correct value for the hasData)
522 */
523bool fixDelayedResponsePacket(PacketPtr func, PacketPtr timing);
524
525std::ostream & operator<<(std::ostream &o, const Packet &p);
526
527#endif //__MEM_PACKET_HH