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>
| 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 46struct Packet; 47typedef Packet* PacketPtr; 48typedef uint8_t* PacketDataPtr; 49typedef std::list<PacketPtr> PacketList; 50 51//Coherence Flags 52#define NACKED_LINE 1 << 0 53#define SATISFIED 1 << 1 54#define SHARED_LINE 1 << 2 55#define CACHE_LINE_FILL 1 << 3 56#define COMPRESSED 1 << 4 57#define NO_ALLOCATE 1 << 5 58 59//For statistics we need max number of commands, hard code it at 60//20 for now. @todo fix later 61#define NUM_MEM_CMDS 1 << 9 62 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 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 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 enum CommandAttribute 166 { 167 IsRead = 1 << 0, 168 IsWrite = 1 << 1, 169 IsPrefetch = 1 << 2, 170 IsInvalidate = 1 << 3, 171 IsRequest = 1 << 4, 172 IsResponse = 1 << 5, 173 NeedsResponse = 1 << 6, 174 IsSWPrefetch = 1 << 7, 175 IsHWPrefetch = 1 << 8 176 }; 177 178 public: 179 /** List of all commands associated with a packet. */ 180 enum Command 181 { 182 InvalidCmd = 0, 183 ReadReq = IsRead | IsRequest | NeedsResponse, 184 WriteReq = IsWrite | IsRequest | NeedsResponse, 185 WriteReqNoAck = IsWrite | IsRequest, 186 ReadResp = IsRead | IsResponse | NeedsResponse, 187 WriteResp = IsWrite | IsResponse | NeedsResponse, 188 Writeback = IsWrite | IsRequest, 189 SoftPFReq = IsRead | IsRequest | IsSWPrefetch | NeedsResponse, 190 HardPFReq = IsRead | IsRequest | IsHWPrefetch | NeedsResponse, 191 SoftPFResp = IsRead | IsResponse | IsSWPrefetch | NeedsResponse, 192 HardPFResp = IsRead | IsResponse | IsHWPrefetch | NeedsResponse, 193 InvalidateReq = IsInvalidate | IsRequest, 194 WriteInvalidateReq = IsWrite | IsInvalidate | IsRequest, 195 UpgradeReq = IsInvalidate | IsRequest | NeedsResponse, 196 UpgradeResp = IsInvalidate | IsResponse | NeedsResponse, 197 ReadExReq = IsRead | IsInvalidate | IsRequest | NeedsResponse, 198 ReadExResp = IsRead | IsInvalidate | IsResponse | NeedsResponse 199 }; 200 201 /** Return the string name of the cmd field (for debugging and 202 * tracing). */ 203 const std::string &cmdString() const; 204 205 /** Reutrn the string to a cmd given by idx. */ 206 const std::string &cmdIdxToString(Command idx); 207 208 /** Return the index of this command. */ 209 inline int cmdToIndex() const { return (int) cmd; } 210 211 /** The command field of the packet. */ 212 Command cmd; 213 214 bool isRead() { return (cmd & IsRead) != 0; } 215 bool isWrite() { return (cmd & IsWrite) != 0; } 216 bool isRequest() { return (cmd & IsRequest) != 0; } 217 bool isResponse() { return (cmd & IsResponse) != 0; } 218 bool needsResponse() { return (cmd & NeedsResponse) != 0; } 219 bool isInvalidate() { return (cmd * IsInvalidate) != 0; } 220 221 bool isCacheFill() { return (flags & CACHE_LINE_FILL) != 0; } 222 bool isNoAllocate() { return (flags & NO_ALLOCATE) != 0; } 223 bool isCompressed() { return (flags & COMPRESSED) != 0; } 224 225 bool nic_pkt() { assert("Unimplemented\n" && 0); } 226 227 /** Possible results of a packet's request. */ 228 enum Result 229 { 230 Success, 231 BadAddress, 232 Nacked, 233 Unknown 234 }; 235 236 /** The result of this packet's request. */ 237 Result result; 238 239 /** Accessor function that returns the source index of the packet. */ 240 short getSrc() const { assert(srcValid); return src; } 241 void setSrc(short _src) { src = _src; srcValid = true; } 242 243 /** Accessor function that returns the destination index of 244 the packet. */ 245 short getDest() const { return dest; } 246 void setDest(short _dest) { dest = _dest; } 247 248 Addr getAddr() const { assert(addrSizeValid); return addr; } 249 int getSize() const { assert(addrSizeValid); return size; } 250 Addr getOffset(int blkSize) const { return addr & (Addr)(blkSize - 1); } 251 252 void addrOverride(Addr newAddr) { assert(addrSizeValid); addr = newAddr; } 253 void cmdOverride(Command newCmd) { cmd = newCmd; } 254 255 /** Constructor. Note that a Request object must be constructed 256 * first, but the Requests's physical address and size fields 257 * need not be valid. The command and destination addresses 258 * must be supplied. */ 259 Packet(Request *_req, Command _cmd, short _dest) 260 : data(NULL), staticData(false), dynamicData(false), arrayData(false), 261 addr(_req->paddr), size(_req->size), dest(_dest), 262 addrSizeValid(_req->validPaddr), 263 srcValid(false), 264 req(_req), coherence(NULL), senderState(NULL), cmd(_cmd), 265 result(Unknown) 266 { 267 flags = 0; 268 } 269 270 /** Alternate constructor if you are trying to create a packet with 271 * a request that is for a whole block, not the address from the req. 272 * this allows for overriding the size/addr of the req.*/ 273 Packet(Request *_req, Command _cmd, short _dest, int _blkSize) 274 : data(NULL), staticData(false), dynamicData(false), arrayData(false), 275 addr(_req->paddr & ~(_blkSize - 1)), size(_blkSize), 276 dest(_dest), 277 addrSizeValid(_req->validPaddr), srcValid(false), 278 req(_req), coherence(NULL), senderState(NULL), cmd(_cmd), 279 result(Unknown) 280 { 281 flags = 0; 282 } 283 284 /** Destructor. */ 285 ~Packet() 286 { deleteData(); } 287 288 /** Reinitialize packet address and size from the associated 289 * Request object, and reset other fields that may have been 290 * modified by a previous transaction. Typically called when a 291 * statically allocated Request/Packet pair is reused for 292 * multiple transactions. */ 293 void reinitFromRequest() { 294 assert(req->validPaddr); 295 addr = req->paddr; 296 size = req->size; 297 addrSizeValid = true; 298 result = Unknown; 299 if (dynamicData) { 300 deleteData(); 301 dynamicData = false; 302 arrayData = false; 303 } 304 } 305 306 /** Take a request packet and modify it in place to be suitable 307 * for returning as a response to that request. Used for timing 308 * accesses only. For atomic and functional accesses, the 309 * request packet is always implicitly passed back *without* 310 * modifying the command or destination fields, so this function 311 * should not be called. */ 312 void makeTimingResponse() { 313 assert(needsResponse()); 314 assert(isRequest()); 315 int icmd = (int)cmd; 316 icmd &= ~(IsRequest); 317 icmd |= IsResponse; 318 cmd = (Command)icmd; 319 dest = src; 320 srcValid = false; 321 } 322 323 /** Take a request packet that has been returned as NACKED and modify it so 324 * that it can be sent out again. Only packets that need a response can be 325 * NACKED, so verify that that is true. */ 326 void reinitNacked() { 327 assert(needsResponse() && result == Nacked); 328 dest = Broadcast; 329 result = Unknown; 330 } 331 332 333 /** Set the data pointer to the following value that should not be freed. */ 334 template <typename T> 335 void dataStatic(T *p); 336 337 /** Set the data pointer to a value that should have delete [] called on it. 338 */ 339 template <typename T> 340 void dataDynamicArray(T *p); 341 342 /** set the data pointer to a value that should have delete called on it. */ 343 template <typename T> 344 void dataDynamic(T *p); 345 346 /** return the value of what is pointed to in the packet. */ 347 template <typename T> 348 T get(); 349 350 /** get a pointer to the data ptr. */ 351 template <typename T> 352 T* getPtr(); 353 354 /** set the value in the data pointer to v. */ 355 template <typename T> 356 void set(T v); 357 358 /** delete the data pointed to in the data pointer. Ok to call to matter how 359 * data was allocted. */ 360 void deleteData(); 361 362 /** If there isn't data in the packet, allocate some. */ 363 void allocate(); 364 365 /** Do the packet modify the same addresses. */ 366 bool intersect(Packet *p); 367}; 368 369bool fixPacket(Packet *func, Packet *timing); 370#endif //__MEM_PACKET_HH
| 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 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); } 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 } 270 271 /** Alternate constructor if you are trying to create a packet with 272 * a request that is for a whole block, not the address from the req. 273 * this allows for overriding the size/addr of the req.*/ 274 Packet(Request *_req, Command _cmd, short _dest, int _blkSize) 275 : data(NULL), staticData(false), dynamicData(false), arrayData(false), 276 addr(_req->paddr & ~(_blkSize - 1)), size(_blkSize), 277 dest(_dest), 278 addrSizeValid(_req->validPaddr), srcValid(false), 279 req(_req), coherence(NULL), senderState(NULL), cmd(_cmd), 280 result(Unknown) 281 { 282 flags = 0; 283 } 284 285 /** Destructor. */ 286 ~Packet() 287 { deleteData(); } 288 289 /** Reinitialize packet address and size from the associated 290 * Request object, and reset other fields that may have been 291 * modified by a previous transaction. Typically called when a 292 * statically allocated Request/Packet pair is reused for 293 * multiple transactions. */ 294 void reinitFromRequest() { 295 assert(req->validPaddr); 296 addr = req->paddr; 297 size = req->size; 298 addrSizeValid = true; 299 result = Unknown; 300 if (dynamicData) { 301 deleteData(); 302 dynamicData = false; 303 arrayData = false; 304 } 305 } 306 307 /** Take a request packet and modify it in place to be suitable 308 * for returning as a response to that request. Used for timing 309 * accesses only. For atomic and functional accesses, the 310 * request packet is always implicitly passed back *without* 311 * modifying the command or destination fields, so this function 312 * should not be called. */ 313 void makeTimingResponse() { 314 assert(needsResponse()); 315 assert(isRequest()); 316 int icmd = (int)cmd; 317 icmd &= ~(IsRequest); 318 icmd |= IsResponse; 319 cmd = (Command)icmd; 320 dest = src; 321 srcValid = false; 322 } 323 324 /** Take a request packet that has been returned as NACKED and modify it so 325 * that it can be sent out again. Only packets that need a response can be 326 * NACKED, so verify that that is true. */ 327 void reinitNacked() { 328 assert(needsResponse() && result == Nacked); 329 dest = Broadcast; 330 result = Unknown; 331 } 332 333 334 /** Set the data pointer to the following value that should not be freed. */ 335 template <typename T> 336 void dataStatic(T *p); 337 338 /** Set the data pointer to a value that should have delete [] called on it. 339 */ 340 template <typename T> 341 void dataDynamicArray(T *p); 342 343 /** set the data pointer to a value that should have delete called on it. */ 344 template <typename T> 345 void dataDynamic(T *p); 346 347 /** return the value of what is pointed to in the packet. */ 348 template <typename T> 349 T get(); 350 351 /** get a pointer to the data ptr. */ 352 template <typename T> 353 T* getPtr(); 354 355 /** set the value in the data pointer to v. */ 356 template <typename T> 357 void set(T v); 358 359 /** delete the data pointed to in the data pointer. Ok to call to matter how 360 * data was allocted. */ 361 void deleteData(); 362 363 /** If there isn't data in the packet, allocate some. */ 364 void allocate(); 365 366 /** Do the packet modify the same addresses. */ 367 bool intersect(Packet *p); 368}; 369 370bool fixPacket(Packet *func, Packet *timing); 371#endif //__MEM_PACKET_HH
|