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