packet.hh (3051:b4f73000973b) packet.hh (3074:e87fbe7941f8)
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 "mem/request.hh"
42#include "sim/host.hh"
43#include "sim/root.hh"
44#include <list>
45#include <cassert>
46
47struct Packet;
48typedef Packet* PacketPtr;
49typedef uint8_t* PacketDataPtr;
50typedef std::list<PacketPtr> PacketList;
51
52//Coherence Flags
53#define NACKED_LINE 1 << 0
54#define SATISFIED 1 << 1
55#define SHARED_LINE 1 << 2
56#define CACHE_LINE_FILL 1 << 3
57#define COMPRESSED 1 << 4
58#define NO_ALLOCATE 1 << 5
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 "mem/request.hh"
42#include "sim/host.hh"
43#include "sim/root.hh"
44#include <list>
45#include <cassert>
46
47struct Packet;
48typedef Packet* PacketPtr;
49typedef uint8_t* PacketDataPtr;
50typedef std::list<PacketPtr> PacketList;
51
52//Coherence Flags
53#define NACKED_LINE 1 << 0
54#define SATISFIED 1 << 1
55#define SHARED_LINE 1 << 2
56#define CACHE_LINE_FILL 1 << 3
57#define COMPRESSED 1 << 4
58#define NO_ALLOCATE 1 << 5
59#define SNOOP_COMMIT 1 << 6
59
60//For statistics we need max number of commands, hard code it at
61//20 for now. @todo fix later
62#define NUM_MEM_CMDS 1 << 9
63
64/**
65 * A Packet is used to encapsulate a transfer between two objects in
66 * the memory system (e.g., the L1 and L2 cache). (In contrast, a
67 * single Request travels all the way from the requester to the
68 * ultimate destination and back, possibly being conveyed by several
69 * different Packets along the way.)
70 */
71class Packet
72{
73 public:
74 /** Temporary FLAGS field until cache gets working, this should be in coherence/sender state. */
75 uint64_t flags;
76
77 private:
78 /** A pointer to the data being transfered. It can be differnt
79 * sizes at each level of the heirarchy so it belongs in the
80 * packet, not request. This may or may not be populated when a
81 * responder recieves the packet. If not populated it memory
82 * should be allocated.
83 */
84 PacketDataPtr data;
85
86 /** Is the data pointer set to a value that shouldn't be freed
87 * when the packet is destroyed? */
88 bool staticData;
89 /** The data pointer points to a value that should be freed when
90 * the packet is destroyed. */
91 bool dynamicData;
92 /** the data pointer points to an array (thus delete [] ) needs to
93 * be called on it rather than simply delete.*/
94 bool arrayData;
95
96
97 /** The address of the request. This address could be virtual or
98 * physical, depending on the system configuration. */
99 Addr addr;
100
101 /** The size of the request or transfer. */
102 int size;
103
104 /** Device address (e.g., bus ID) of the source of the
105 * transaction. The source is not responsible for setting this
106 * field; it is set implicitly by the interconnect when the
107 * packet * is first sent. */
108 short src;
109
110 /** Device address (e.g., bus ID) of the destination of the
111 * transaction. The special value Broadcast indicates that the
112 * packet should be routed based on its address. This field is
113 * initialized in the constructor and is thus always valid
114 * (unlike * addr, size, and src). */
115 short dest;
116
117 /** Are the 'addr' and 'size' fields valid? */
118 bool addrSizeValid;
119 /** Is the 'src' field valid? */
120 bool srcValid;
121
122
123 public:
124
125 /** Used to calculate latencies for each packet.*/
126 Tick time;
127
128 /** The special destination address indicating that the packet
129 * should be routed based on its address. */
130 static const short Broadcast = -1;
131
132 /** A pointer to the original request. */
133 RequestPtr req;
134
135 /** A virtual base opaque structure used to hold coherence-related
136 * state. A specific subclass would be derived from this to
137 * carry state specific to a particular coherence protocol. */
138 class CoherenceState {
139 public:
140 virtual ~CoherenceState() {}
141 };
142
143 /** This packet's coherence state. Caches should use
144 * dynamic_cast<> to cast to the state appropriate for the
145 * system's coherence protocol. */
146 CoherenceState *coherence;
147
148 /** A virtual base opaque structure used to hold state associated
149 * with the packet but specific to the sending device (e.g., an
150 * MSHR). A pointer to this state is returned in the packet's
151 * response so that the sender can quickly look up the state
152 * needed to process it. A specific subclass would be derived
153 * from this to carry state specific to a particular sending
154 * device. */
155 class SenderState {
156 public:
157 virtual ~SenderState() {}
158 };
159
160 /** This packet's sender state. Devices should use dynamic_cast<>
161 * to cast to the state appropriate to the sender. */
162 SenderState *senderState;
163
164 private:
165 /** List of command attributes. */
166 enum CommandAttribute
167 {
168 IsRead = 1 << 0,
169 IsWrite = 1 << 1,
170 IsPrefetch = 1 << 2,
171 IsInvalidate = 1 << 3,
172 IsRequest = 1 << 4,
173 IsResponse = 1 << 5,
174 NeedsResponse = 1 << 6,
175 IsSWPrefetch = 1 << 7,
176 IsHWPrefetch = 1 << 8
177 };
178
179 public:
180 /** List of all commands associated with a packet. */
181 enum Command
182 {
183 InvalidCmd = 0,
184 ReadReq = IsRead | IsRequest | NeedsResponse,
185 WriteReq = IsWrite | IsRequest | NeedsResponse,
186 WriteReqNoAck = IsWrite | IsRequest,
187 ReadResp = IsRead | IsResponse | NeedsResponse,
188 WriteResp = IsWrite | IsResponse | NeedsResponse,
189 Writeback = IsWrite | IsRequest,
190 SoftPFReq = IsRead | IsRequest | IsSWPrefetch | NeedsResponse,
191 HardPFReq = IsRead | IsRequest | IsHWPrefetch | NeedsResponse,
192 SoftPFResp = IsRead | IsResponse | IsSWPrefetch | NeedsResponse,
193 HardPFResp = IsRead | IsResponse | IsHWPrefetch | NeedsResponse,
194 InvalidateReq = IsInvalidate | IsRequest,
195 WriteInvalidateReq = IsWrite | IsInvalidate | IsRequest,
196 UpgradeReq = IsInvalidate | IsRequest | NeedsResponse,
197 UpgradeResp = IsInvalidate | IsResponse | NeedsResponse,
198 ReadExReq = IsRead | IsInvalidate | IsRequest | NeedsResponse,
199 ReadExResp = IsRead | IsInvalidate | IsResponse | NeedsResponse
200 };
201
202 /** Return the string name of the cmd field (for debugging and
203 * tracing). */
204 const std::string &cmdString() const;
205
206 /** Reutrn the string to a cmd given by idx. */
207 const std::string &cmdIdxToString(Command idx);
208
209 /** Return the index of this command. */
210 inline int cmdToIndex() const { return (int) cmd; }
211
212 /** The command field of the packet. */
213 Command cmd;
214
215 bool isRead() { return (cmd & IsRead) != 0; }
216 bool isWrite() { return (cmd & IsWrite) != 0; }
217 bool isRequest() { return (cmd & IsRequest) != 0; }
218 bool isResponse() { return (cmd & IsResponse) != 0; }
219 bool needsResponse() { return (cmd & NeedsResponse) != 0; }
220 bool isInvalidate() { return (cmd & IsInvalidate) != 0; }
221
222 bool isCacheFill() { return (flags & CACHE_LINE_FILL) != 0; }
223 bool isNoAllocate() { return (flags & NO_ALLOCATE) != 0; }
224 bool isCompressed() { return (flags & COMPRESSED) != 0; }
225
226 bool nic_pkt() { assert("Unimplemented\n" && 0); return false; }
227
228 /** Possible results of a packet's request. */
229 enum Result
230 {
231 Success,
232 BadAddress,
233 Nacked,
234 Unknown
235 };
236
237 /** The result of this packet's request. */
238 Result result;
239
240 /** Accessor function that returns the source index of the packet. */
241 short getSrc() const { assert(srcValid); return src; }
242 void setSrc(short _src) { src = _src; srcValid = true; }
243
244 /** Accessor function that returns the destination index of
245 the packet. */
246 short getDest() const { return dest; }
247 void setDest(short _dest) { dest = _dest; }
248
249 Addr getAddr() const { assert(addrSizeValid); return addr; }
250 int getSize() const { assert(addrSizeValid); return size; }
251 Addr getOffset(int blkSize) const { return addr & (Addr)(blkSize - 1); }
252
253 void addrOverride(Addr newAddr) { assert(addrSizeValid); addr = newAddr; }
254 void cmdOverride(Command newCmd) { cmd = newCmd; }
255
256 /** Constructor. Note that a Request object must be constructed
257 * first, but the Requests's physical address and size fields
258 * need not be valid. The command and destination addresses
259 * must be supplied. */
260 Packet(Request *_req, Command _cmd, short _dest)
261 : data(NULL), staticData(false), dynamicData(false), arrayData(false),
262 addr(_req->paddr), size(_req->size), dest(_dest),
263 addrSizeValid(_req->validPaddr),
264 srcValid(false),
265 req(_req), coherence(NULL), senderState(NULL), cmd(_cmd),
266 result(Unknown)
267 {
268 flags = 0;
269 time = curTick;
270 }
271
272 /** Alternate constructor if you are trying to create a packet with
273 * a request that is for a whole block, not the address from the req.
274 * this allows for overriding the size/addr of the req.*/
275 Packet(Request *_req, Command _cmd, short _dest, int _blkSize)
276 : data(NULL), staticData(false), dynamicData(false), arrayData(false),
277 addr(_req->paddr & ~(_blkSize - 1)), size(_blkSize),
278 dest(_dest),
279 addrSizeValid(_req->validPaddr), srcValid(false),
280 req(_req), coherence(NULL), senderState(NULL), cmd(_cmd),
281 result(Unknown)
282 {
283 flags = 0;
284 time = curTick;
285 }
286
287 /** Destructor. */
288 ~Packet()
289 { deleteData(); }
290
291 /** Reinitialize packet address and size from the associated
292 * Request object, and reset other fields that may have been
293 * modified by a previous transaction. Typically called when a
294 * statically allocated Request/Packet pair is reused for
295 * multiple transactions. */
296 void reinitFromRequest() {
297 assert(req->validPaddr);
298 addr = req->paddr;
299 size = req->size;
300 time = req->time;
301 addrSizeValid = true;
302 result = Unknown;
303 if (dynamicData) {
304 deleteData();
305 dynamicData = false;
306 arrayData = false;
307 }
308 }
309
310 /** Take a request packet and modify it in place to be suitable
311 * for returning as a response to that request. Used for timing
312 * accesses only. For atomic and functional accesses, the
313 * request packet is always implicitly passed back *without*
314 * modifying the command or destination fields, so this function
315 * should not be called. */
316 void makeTimingResponse() {
317 assert(needsResponse());
318 assert(isRequest());
319 int icmd = (int)cmd;
320 icmd &= ~(IsRequest);
321 icmd |= IsResponse;
322 cmd = (Command)icmd;
323 dest = src;
324 srcValid = false;
325 }
326
327 /** Take a request packet that has been returned as NACKED and modify it so
328 * that it can be sent out again. Only packets that need a response can be
329 * NACKED, so verify that that is true. */
330 void reinitNacked() {
331 assert(needsResponse() && result == Nacked);
332 dest = Broadcast;
333 result = Unknown;
334 }
335
336
337 /** Set the data pointer to the following value that should not be freed. */
338 template <typename T>
339 void dataStatic(T *p);
340
341 /** Set the data pointer to a value that should have delete [] called on it.
342 */
343 template <typename T>
344 void dataDynamicArray(T *p);
345
346 /** set the data pointer to a value that should have delete called on it. */
347 template <typename T>
348 void dataDynamic(T *p);
349
350 /** return the value of what is pointed to in the packet. */
351 template <typename T>
352 T get();
353
354 /** get a pointer to the data ptr. */
355 template <typename T>
356 T* getPtr();
357
358 /** set the value in the data pointer to v. */
359 template <typename T>
360 void set(T v);
361
362 /** delete the data pointed to in the data pointer. Ok to call to matter how
363 * data was allocted. */
364 void deleteData();
365
366 /** If there isn't data in the packet, allocate some. */
367 void allocate();
368
369 /** Do the packet modify the same addresses. */
370 bool intersect(Packet *p);
371};
372
373bool fixPacket(Packet *func, Packet *timing);
374#endif //__MEM_PACKET_HH
60
61//For statistics we need max number of commands, hard code it at
62//20 for now. @todo fix later
63#define NUM_MEM_CMDS 1 << 9
64
65/**
66 * A Packet is used to encapsulate a transfer between two objects in
67 * the memory system (e.g., the L1 and L2 cache). (In contrast, a
68 * single Request travels all the way from the requester to the
69 * ultimate destination and back, possibly being conveyed by several
70 * different Packets along the way.)
71 */
72class Packet
73{
74 public:
75 /** Temporary FLAGS field until cache gets working, this should be in coherence/sender state. */
76 uint64_t flags;
77
78 private:
79 /** A pointer to the data being transfered. It can be differnt
80 * sizes at each level of the heirarchy so it belongs in the
81 * packet, not request. This may or may not be populated when a
82 * responder recieves the packet. If not populated it memory
83 * should be allocated.
84 */
85 PacketDataPtr data;
86
87 /** Is the data pointer set to a value that shouldn't be freed
88 * when the packet is destroyed? */
89 bool staticData;
90 /** The data pointer points to a value that should be freed when
91 * the packet is destroyed. */
92 bool dynamicData;
93 /** the data pointer points to an array (thus delete [] ) needs to
94 * be called on it rather than simply delete.*/
95 bool arrayData;
96
97
98 /** The address of the request. This address could be virtual or
99 * physical, depending on the system configuration. */
100 Addr addr;
101
102 /** The size of the request or transfer. */
103 int size;
104
105 /** Device address (e.g., bus ID) of the source of the
106 * transaction. The source is not responsible for setting this
107 * field; it is set implicitly by the interconnect when the
108 * packet * is first sent. */
109 short src;
110
111 /** Device address (e.g., bus ID) of the destination of the
112 * transaction. The special value Broadcast indicates that the
113 * packet should be routed based on its address. This field is
114 * initialized in the constructor and is thus always valid
115 * (unlike * addr, size, and src). */
116 short dest;
117
118 /** Are the 'addr' and 'size' fields valid? */
119 bool addrSizeValid;
120 /** Is the 'src' field valid? */
121 bool srcValid;
122
123
124 public:
125
126 /** Used to calculate latencies for each packet.*/
127 Tick time;
128
129 /** The special destination address indicating that the packet
130 * should be routed based on its address. */
131 static const short Broadcast = -1;
132
133 /** A pointer to the original request. */
134 RequestPtr req;
135
136 /** A virtual base opaque structure used to hold coherence-related
137 * state. A specific subclass would be derived from this to
138 * carry state specific to a particular coherence protocol. */
139 class CoherenceState {
140 public:
141 virtual ~CoherenceState() {}
142 };
143
144 /** This packet's coherence state. Caches should use
145 * dynamic_cast<> to cast to the state appropriate for the
146 * system's coherence protocol. */
147 CoherenceState *coherence;
148
149 /** A virtual base opaque structure used to hold state associated
150 * with the packet but specific to the sending device (e.g., an
151 * MSHR). A pointer to this state is returned in the packet's
152 * response so that the sender can quickly look up the state
153 * needed to process it. A specific subclass would be derived
154 * from this to carry state specific to a particular sending
155 * device. */
156 class SenderState {
157 public:
158 virtual ~SenderState() {}
159 };
160
161 /** This packet's sender state. Devices should use dynamic_cast<>
162 * to cast to the state appropriate to the sender. */
163 SenderState *senderState;
164
165 private:
166 /** List of command attributes. */
167 enum CommandAttribute
168 {
169 IsRead = 1 << 0,
170 IsWrite = 1 << 1,
171 IsPrefetch = 1 << 2,
172 IsInvalidate = 1 << 3,
173 IsRequest = 1 << 4,
174 IsResponse = 1 << 5,
175 NeedsResponse = 1 << 6,
176 IsSWPrefetch = 1 << 7,
177 IsHWPrefetch = 1 << 8
178 };
179
180 public:
181 /** List of all commands associated with a packet. */
182 enum Command
183 {
184 InvalidCmd = 0,
185 ReadReq = IsRead | IsRequest | NeedsResponse,
186 WriteReq = IsWrite | IsRequest | NeedsResponse,
187 WriteReqNoAck = IsWrite | IsRequest,
188 ReadResp = IsRead | IsResponse | NeedsResponse,
189 WriteResp = IsWrite | IsResponse | NeedsResponse,
190 Writeback = IsWrite | IsRequest,
191 SoftPFReq = IsRead | IsRequest | IsSWPrefetch | NeedsResponse,
192 HardPFReq = IsRead | IsRequest | IsHWPrefetch | NeedsResponse,
193 SoftPFResp = IsRead | IsResponse | IsSWPrefetch | NeedsResponse,
194 HardPFResp = IsRead | IsResponse | IsHWPrefetch | NeedsResponse,
195 InvalidateReq = IsInvalidate | IsRequest,
196 WriteInvalidateReq = IsWrite | IsInvalidate | IsRequest,
197 UpgradeReq = IsInvalidate | IsRequest | NeedsResponse,
198 UpgradeResp = IsInvalidate | IsResponse | NeedsResponse,
199 ReadExReq = IsRead | IsInvalidate | IsRequest | NeedsResponse,
200 ReadExResp = IsRead | IsInvalidate | IsResponse | NeedsResponse
201 };
202
203 /** Return the string name of the cmd field (for debugging and
204 * tracing). */
205 const std::string &cmdString() const;
206
207 /** Reutrn the string to a cmd given by idx. */
208 const std::string &cmdIdxToString(Command idx);
209
210 /** Return the index of this command. */
211 inline int cmdToIndex() const { return (int) cmd; }
212
213 /** The command field of the packet. */
214 Command cmd;
215
216 bool isRead() { return (cmd & IsRead) != 0; }
217 bool isWrite() { return (cmd & IsWrite) != 0; }
218 bool isRequest() { return (cmd & IsRequest) != 0; }
219 bool isResponse() { return (cmd & IsResponse) != 0; }
220 bool needsResponse() { return (cmd & NeedsResponse) != 0; }
221 bool isInvalidate() { return (cmd & IsInvalidate) != 0; }
222
223 bool isCacheFill() { return (flags & CACHE_LINE_FILL) != 0; }
224 bool isNoAllocate() { return (flags & NO_ALLOCATE) != 0; }
225 bool isCompressed() { return (flags & COMPRESSED) != 0; }
226
227 bool nic_pkt() { assert("Unimplemented\n" && 0); return false; }
228
229 /** Possible results of a packet's request. */
230 enum Result
231 {
232 Success,
233 BadAddress,
234 Nacked,
235 Unknown
236 };
237
238 /** The result of this packet's request. */
239 Result result;
240
241 /** Accessor function that returns the source index of the packet. */
242 short getSrc() const { assert(srcValid); return src; }
243 void setSrc(short _src) { src = _src; srcValid = true; }
244
245 /** Accessor function that returns the destination index of
246 the packet. */
247 short getDest() const { return dest; }
248 void setDest(short _dest) { dest = _dest; }
249
250 Addr getAddr() const { assert(addrSizeValid); return addr; }
251 int getSize() const { assert(addrSizeValid); return size; }
252 Addr getOffset(int blkSize) const { return addr & (Addr)(blkSize - 1); }
253
254 void addrOverride(Addr newAddr) { assert(addrSizeValid); addr = newAddr; }
255 void cmdOverride(Command newCmd) { cmd = newCmd; }
256
257 /** Constructor. Note that a Request object must be constructed
258 * first, but the Requests's physical address and size fields
259 * need not be valid. The command and destination addresses
260 * must be supplied. */
261 Packet(Request *_req, Command _cmd, short _dest)
262 : data(NULL), staticData(false), dynamicData(false), arrayData(false),
263 addr(_req->paddr), size(_req->size), dest(_dest),
264 addrSizeValid(_req->validPaddr),
265 srcValid(false),
266 req(_req), coherence(NULL), senderState(NULL), cmd(_cmd),
267 result(Unknown)
268 {
269 flags = 0;
270 time = curTick;
271 }
272
273 /** Alternate constructor if you are trying to create a packet with
274 * a request that is for a whole block, not the address from the req.
275 * this allows for overriding the size/addr of the req.*/
276 Packet(Request *_req, Command _cmd, short _dest, int _blkSize)
277 : data(NULL), staticData(false), dynamicData(false), arrayData(false),
278 addr(_req->paddr & ~(_blkSize - 1)), size(_blkSize),
279 dest(_dest),
280 addrSizeValid(_req->validPaddr), srcValid(false),
281 req(_req), coherence(NULL), senderState(NULL), cmd(_cmd),
282 result(Unknown)
283 {
284 flags = 0;
285 time = curTick;
286 }
287
288 /** Destructor. */
289 ~Packet()
290 { deleteData(); }
291
292 /** Reinitialize packet address and size from the associated
293 * Request object, and reset other fields that may have been
294 * modified by a previous transaction. Typically called when a
295 * statically allocated Request/Packet pair is reused for
296 * multiple transactions. */
297 void reinitFromRequest() {
298 assert(req->validPaddr);
299 addr = req->paddr;
300 size = req->size;
301 time = req->time;
302 addrSizeValid = true;
303 result = Unknown;
304 if (dynamicData) {
305 deleteData();
306 dynamicData = false;
307 arrayData = false;
308 }
309 }
310
311 /** Take a request packet and modify it in place to be suitable
312 * for returning as a response to that request. Used for timing
313 * accesses only. For atomic and functional accesses, the
314 * request packet is always implicitly passed back *without*
315 * modifying the command or destination fields, so this function
316 * should not be called. */
317 void makeTimingResponse() {
318 assert(needsResponse());
319 assert(isRequest());
320 int icmd = (int)cmd;
321 icmd &= ~(IsRequest);
322 icmd |= IsResponse;
323 cmd = (Command)icmd;
324 dest = src;
325 srcValid = false;
326 }
327
328 /** Take a request packet that has been returned as NACKED and modify it so
329 * that it can be sent out again. Only packets that need a response can be
330 * NACKED, so verify that that is true. */
331 void reinitNacked() {
332 assert(needsResponse() && result == Nacked);
333 dest = Broadcast;
334 result = Unknown;
335 }
336
337
338 /** Set the data pointer to the following value that should not be freed. */
339 template <typename T>
340 void dataStatic(T *p);
341
342 /** Set the data pointer to a value that should have delete [] called on it.
343 */
344 template <typename T>
345 void dataDynamicArray(T *p);
346
347 /** set the data pointer to a value that should have delete called on it. */
348 template <typename T>
349 void dataDynamic(T *p);
350
351 /** return the value of what is pointed to in the packet. */
352 template <typename T>
353 T get();
354
355 /** get a pointer to the data ptr. */
356 template <typename T>
357 T* getPtr();
358
359 /** set the value in the data pointer to v. */
360 template <typename T>
361 void set(T v);
362
363 /** delete the data pointed to in the data pointer. Ok to call to matter how
364 * data was allocted. */
365 void deleteData();
366
367 /** If there isn't data in the packet, allocate some. */
368 void allocate();
369
370 /** Do the packet modify the same addresses. */
371 bool intersect(Packet *p);
372};
373
374bool fixPacket(Packet *func, Packet *timing);
375#endif //__MEM_PACKET_HH