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" 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 58class MemCmd 59{ 60 public: 61 62 /** List of all commands associated with a packet. */ 63 enum Command 64 { 65 InvalidCmd, 66 ReadReq, 67 ReadResp, 68 WriteReq, 69 WriteResp, 70 Writeback, 71 SoftPFReq, 72 HardPFReq, 73 SoftPFResp, 74 HardPFResp, 75 WriteInvalidateReq, 76 WriteInvalidateResp, 77 UpgradeReq, 78 UpgradeResp, 79 ReadExReq, 80 ReadExResp, 81 LoadLockedReq, 82 LoadLockedResp, 83 StoreCondReq, 84 StoreCondResp, 85 SwapReq, 86 SwapResp,
| 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" 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 58class MemCmd 59{ 60 public: 61 62 /** List of all commands associated with a packet. */ 63 enum Command 64 { 65 InvalidCmd, 66 ReadReq, 67 ReadResp, 68 WriteReq, 69 WriteResp, 70 Writeback, 71 SoftPFReq, 72 HardPFReq, 73 SoftPFResp, 74 HardPFResp, 75 WriteInvalidateReq, 76 WriteInvalidateResp, 77 UpgradeReq, 78 UpgradeResp, 79 ReadExReq, 80 ReadExResp, 81 LoadLockedReq, 82 LoadLockedResp, 83 StoreCondReq, 84 StoreCondResp, 85 SwapReq, 86 SwapResp,
|
| 87 // Error responses 88 // @TODO these should be classified as responses rather than 89 // requests; coding them as requests initially for backwards 90 // compatibility 91 NetworkNackError, // nacked at network layer (not by protocol) 92 InvalidDestError, // packet dest field invalid 93 BadAddressError, // memory address invalid
|
87 NUM_MEM_CMDS 88 }; 89 90 private: 91 /** List of command attributes. */ 92 enum Attribute 93 { 94 IsRead, //!< Data flows from responder to requester 95 IsWrite, //!< Data flows from requester to responder 96 IsPrefetch, //!< Not a demand access 97 IsInvalidate, 98 NeedsExclusive, //!< Requires exclusive copy to complete in-cache 99 IsRequest, //!< Issued by requester 100 IsResponse, //!< Issue by responder 101 NeedsResponse, //!< Requester needs response from target 102 IsSWPrefetch, 103 IsHWPrefetch, 104 IsLocked, //!< Alpha/MIPS LL or SC access 105 HasData, //!< There is an associated payload
| 94 NUM_MEM_CMDS 95 }; 96 97 private: 98 /** List of command attributes. */ 99 enum Attribute 100 { 101 IsRead, //!< Data flows from responder to requester 102 IsWrite, //!< Data flows from requester to responder 103 IsPrefetch, //!< Not a demand access 104 IsInvalidate, 105 NeedsExclusive, //!< Requires exclusive copy to complete in-cache 106 IsRequest, //!< Issued by requester 107 IsResponse, //!< Issue by responder 108 NeedsResponse, //!< Requester needs response from target 109 IsSWPrefetch, 110 IsHWPrefetch, 111 IsLocked, //!< Alpha/MIPS LL or SC access 112 HasData, //!< There is an associated payload
|
| 113 IsError, //!< Error response
|
106 NUM_COMMAND_ATTRIBUTES 107 }; 108 109 /** Structure that defines attributes and other data associated 110 * with a Command. */ 111 struct CommandInfo { 112 /** Set of attribute flags. */ 113 const std::bitset<NUM_COMMAND_ATTRIBUTES> attributes; 114 /** Corresponding response for requests; InvalidCmd if no 115 * response is applicable. */ 116 const Command response; 117 /** String representation (for printing) */ 118 const std::string str; 119 }; 120 121 /** Array to map Command enum to associated info. */ 122 static const CommandInfo commandInfo[]; 123 124 private: 125 126 Command cmd; 127 128 bool testCmdAttrib(MemCmd::Attribute attrib) const { 129 return commandInfo[cmd].attributes[attrib] != 0; 130 } 131 132 public: 133 134 bool isRead() const { return testCmdAttrib(IsRead); } 135 bool isWrite() const { return testCmdAttrib(IsWrite); } 136 bool isRequest() const { return testCmdAttrib(IsRequest); } 137 bool isResponse() const { return testCmdAttrib(IsResponse); }
| 114 NUM_COMMAND_ATTRIBUTES 115 }; 116 117 /** Structure that defines attributes and other data associated 118 * with a Command. */ 119 struct CommandInfo { 120 /** Set of attribute flags. */ 121 const std::bitset<NUM_COMMAND_ATTRIBUTES> attributes; 122 /** Corresponding response for requests; InvalidCmd if no 123 * response is applicable. */ 124 const Command response; 125 /** String representation (for printing) */ 126 const std::string str; 127 }; 128 129 /** Array to map Command enum to associated info. */ 130 static const CommandInfo commandInfo[]; 131 132 private: 133 134 Command cmd; 135 136 bool testCmdAttrib(MemCmd::Attribute attrib) const { 137 return commandInfo[cmd].attributes[attrib] != 0; 138 } 139 140 public: 141 142 bool isRead() const { return testCmdAttrib(IsRead); } 143 bool isWrite() const { return testCmdAttrib(IsWrite); } 144 bool isRequest() const { return testCmdAttrib(IsRequest); } 145 bool isResponse() const { return testCmdAttrib(IsResponse); }
|
138 bool needsExclusive() const { return testCmdAttrib(NeedsExclusive); }
| 146 bool needsExclusive() const { return testCmdAttrib(NeedsExclusive); }
|
139 bool needsResponse() const { return testCmdAttrib(NeedsResponse); } 140 bool isInvalidate() const { return testCmdAttrib(IsInvalidate); } 141 bool hasData() const { return testCmdAttrib(HasData); } 142 bool isReadWrite() const { return isRead() && isWrite(); } 143 bool isLocked() const { return testCmdAttrib(IsLocked); }
| 147 bool needsResponse() const { return testCmdAttrib(NeedsResponse); } 148 bool isInvalidate() const { return testCmdAttrib(IsInvalidate); } 149 bool hasData() const { return testCmdAttrib(HasData); } 150 bool isReadWrite() const { return isRead() && isWrite(); } 151 bool isLocked() const { return testCmdAttrib(IsLocked); }
|
| 152 bool isError() const { return testCmdAttrib(IsError); }
|
144 145 const Command responseCommand() const { 146 return commandInfo[cmd].response; 147 } 148 149 /** Return the string to a cmd given by idx. */ 150 const std::string &toString() const { 151 return commandInfo[cmd].str; 152 } 153 154 int toInt() const { return (int)cmd; } 155 156 MemCmd(Command _cmd) 157 : cmd(_cmd) 158 { } 159 160 MemCmd(int _cmd) 161 : cmd((Command)_cmd) 162 { } 163 164 MemCmd() 165 : cmd(InvalidCmd) 166 { } 167 168 bool operator==(MemCmd c2) { return (cmd == c2.cmd); } 169 bool operator!=(MemCmd c2) { return (cmd != c2.cmd); } 170 171 friend class Packet; 172}; 173 174/** 175 * A Packet is used to encapsulate a transfer between two objects in 176 * the memory system (e.g., the L1 and L2 cache). (In contrast, a 177 * single Request travels all the way from the requester to the 178 * ultimate destination and back, possibly being conveyed by several 179 * different Packets along the way.) 180 */ 181class Packet : public FastAlloc 182{ 183 public: 184 185 typedef MemCmd::Command Command; 186
| 153 154 const Command responseCommand() const { 155 return commandInfo[cmd].response; 156 } 157 158 /** Return the string to a cmd given by idx. */ 159 const std::string &toString() const { 160 return commandInfo[cmd].str; 161 } 162 163 int toInt() const { return (int)cmd; } 164 165 MemCmd(Command _cmd) 166 : cmd(_cmd) 167 { } 168 169 MemCmd(int _cmd) 170 : cmd((Command)_cmd) 171 { } 172 173 MemCmd() 174 : cmd(InvalidCmd) 175 { } 176 177 bool operator==(MemCmd c2) { return (cmd == c2.cmd); } 178 bool operator!=(MemCmd c2) { return (cmd != c2.cmd); } 179 180 friend class Packet; 181}; 182 183/** 184 * A Packet is used to encapsulate a transfer between two objects in 185 * the memory system (e.g., the L1 and L2 cache). (In contrast, a 186 * single Request travels all the way from the requester to the 187 * ultimate destination and back, possibly being conveyed by several 188 * different Packets along the way.) 189 */ 190class Packet : public FastAlloc 191{ 192 public: 193 194 typedef MemCmd::Command Command; 195
|
| 196 /** The command field of the packet. */ 197 MemCmd cmd; 198 199 /** A pointer to the original request. */ 200 RequestPtr req; 201
|
187 private: 188 /** A pointer to the data being transfered. It can be differnt 189 * sizes at each level of the heirarchy so it belongs in the 190 * packet, not request. This may or may not be populated when a 191 * responder recieves the packet. If not populated it memory 192 * should be allocated. 193 */ 194 PacketDataPtr data; 195 196 /** Is the data pointer set to a value that shouldn't be freed 197 * when the packet is destroyed? */ 198 bool staticData; 199 /** The data pointer points to a value that should be freed when 200 * the packet is destroyed. */ 201 bool dynamicData; 202 /** the data pointer points to an array (thus delete [] ) needs to 203 * be called on it rather than simply delete.*/ 204 bool arrayData; 205 206 /** The address of the request. This address could be virtual or 207 * physical, depending on the system configuration. */ 208 Addr addr; 209 210 /** The size of the request or transfer. */ 211 int size; 212 213 /** Device address (e.g., bus ID) of the source of the 214 * transaction. The source is not responsible for setting this 215 * field; it is set implicitly by the interconnect when the 216 * packet is first sent. */ 217 short src; 218 219 /** Device address (e.g., bus ID) of the destination of the 220 * transaction. The special value Broadcast indicates that the 221 * packet should be routed based on its address. This field is 222 * initialized in the constructor and is thus always valid 223 * (unlike * addr, size, and src). */ 224 short dest; 225
| 202 private: 203 /** A pointer to the data being transfered. It can be differnt 204 * sizes at each level of the heirarchy so it belongs in the 205 * packet, not request. This may or may not be populated when a 206 * responder recieves the packet. If not populated it memory 207 * should be allocated. 208 */ 209 PacketDataPtr data; 210 211 /** Is the data pointer set to a value that shouldn't be freed 212 * when the packet is destroyed? */ 213 bool staticData; 214 /** The data pointer points to a value that should be freed when 215 * the packet is destroyed. */ 216 bool dynamicData; 217 /** the data pointer points to an array (thus delete [] ) needs to 218 * be called on it rather than simply delete.*/ 219 bool arrayData; 220 221 /** The address of the request. This address could be virtual or 222 * physical, depending on the system configuration. */ 223 Addr addr; 224 225 /** The size of the request or transfer. */ 226 int size; 227 228 /** Device address (e.g., bus ID) of the source of the 229 * transaction. The source is not responsible for setting this 230 * field; it is set implicitly by the interconnect when the 231 * packet is first sent. */ 232 short src; 233 234 /** Device address (e.g., bus ID) of the destination of the 235 * transaction. The special value Broadcast indicates that the 236 * packet should be routed based on its address. This field is 237 * initialized in the constructor and is thus always valid 238 * (unlike * addr, size, and src). */ 239 short dest; 240
|
| 241 /** The original value of the command field. Only valid when the 242 * current command field is an error condition; in that case, the 243 * previous contents of the command field are copied here. This 244 * field is *not* set on non-error responses. 245 */ 246 MemCmd origCmd; 247
|
226 /** Are the 'addr' and 'size' fields valid? */ 227 bool addrSizeValid; 228 /** Is the 'src' field valid? */ 229 bool srcValid;
| 248 /** Are the 'addr' and 'size' fields valid? */ 249 bool addrSizeValid; 250 /** Is the 'src' field valid? */ 251 bool srcValid;
|
| 252 bool destValid;
|
230
| 253
|
231 enum SnoopFlag {
| 254 enum Flag { 255 // Snoop flags
|
232 MemInhibit, 233 Shared,
| 256 MemInhibit, 257 Shared,
|
234 NUM_SNOOP_FLAGS
| 258 NUM_PACKET_FLAGS
|
235 }; 236
| 259 }; 260
|
237 /** Coherence snoopFlags for snooping */ 238 std::bitset<NUM_SNOOP_FLAGS> snoopFlags;
| 261 /** Status flags */ 262 std::bitset<NUM_PACKET_FLAGS> flags;
|
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
| 263 264 public: 265 266 /** Used to calculate latencies for each packet.*/ 267 Tick time; 268 269 /** The time at which the packet will be fully transmitted */ 270 Tick finishTime; 271 272 /** The time at which the first chunk of the packet will be transmitted */ 273 Tick firstWordTime; 274 275 /** The special destination address indicating that the packet 276 * should be routed based on its address. */ 277 static const short Broadcast = -1; 278
|
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. */ 261 class CoherenceState : public FastAlloc { 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. */ 278 class SenderState : public FastAlloc { 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
| 279 /** A virtual base opaque structure used to hold state associated 280 * with the packet but specific to the sending device (e.g., an 281 * MSHR). A pointer to this state is returned in the packet's 282 * response so that the sender can quickly look up the state 283 * needed to process it. A specific subclass would be derived 284 * from this to carry state specific to a particular sending 285 * device. */ 286 class SenderState : public FastAlloc { 287 public: 288 virtual ~SenderState() {} 289 }; 290 291 /** This packet's sender state. Devices should use dynamic_cast<> 292 * to cast to the state appropriate to the sender. */ 293 SenderState *senderState; 294
|
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
| 295 /** Return the string name of the cmd field (for debugging and 296 * tracing). */ 297 const std::string &cmdString() const { return cmd.toString(); } 298 299 /** Return the index of this command. */ 300 inline int cmdToIndex() const { return cmd.toInt(); } 301
|
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(); }
| 302 bool isRead() const { return cmd.isRead(); } 303 bool isWrite() const { return cmd.isWrite(); } 304 bool isRequest() const { return cmd.isRequest(); } 305 bool isResponse() const { return cmd.isResponse(); }
|
305 bool needsExclusive() const { return cmd.needsExclusive(); }
| 306 bool needsExclusive() const { return cmd.needsExclusive(); }
|
306 bool needsResponse() const { return cmd.needsResponse(); } 307 bool isInvalidate() const { return cmd.isInvalidate(); } 308 bool hasData() const { return cmd.hasData(); } 309 bool isReadWrite() const { return cmd.isReadWrite(); } 310 bool isLocked() const { return cmd.isLocked(); }
| 307 bool needsResponse() const { return cmd.needsResponse(); } 308 bool isInvalidate() const { return cmd.isInvalidate(); } 309 bool hasData() const { return cmd.hasData(); } 310 bool isReadWrite() const { return cmd.isReadWrite(); } 311 bool isLocked() const { return cmd.isLocked(); }
|
| 312 bool isError() const { return cmd.isError(); }
|
311
| 313
|
312 void assertMemInhibit() { snoopFlags[MemInhibit] = true; } 313 void assertShared() { snoopFlags[Shared] = true; } 314 bool memInhibitAsserted() { return snoopFlags[MemInhibit]; } 315 bool sharedAsserted() { return snoopFlags[Shared]; }
| 314 // Snoop flags 315 void assertMemInhibit() { flags[MemInhibit] = true; } 316 void assertShared() { flags[Shared] = true; } 317 bool memInhibitAsserted() { return flags[MemInhibit]; } 318 bool sharedAsserted() { return flags[Shared]; }
|
316
| 319
|
| 320 // Network error conditions... encapsulate them as methods since 321 // their encoding keeps changing (from result field to command 322 // field, etc.) 323 void setNacked() { origCmd = cmd; cmd = MemCmd::NetworkNackError; } 324 void setBadAddress() { origCmd = cmd; cmd = MemCmd::BadAddressError; } 325 bool wasNacked() { return cmd == MemCmd::NetworkNackError; } 326 bool hadBadAddress() { return cmd == MemCmd::BadAddressError; } 327
|
317 bool nic_pkt() { panic("Unimplemented"); M5_DUMMY_RETURN } 318
| 328 bool nic_pkt() { panic("Unimplemented"); M5_DUMMY_RETURN } 329
|
319 /** Possible results of a packet's request. */ 320 enum Result 321 { 322 Success, 323 BadAddress, 324 Nacked, 325 Unknown 326 }; 327 328 /** The result of this packet's request. */ 329 Result result; 330
| |
331 /** Accessor function that returns the source index of the packet. */
| 330 /** Accessor function that returns the source index of the packet. */
|
332 short getSrc() const { assert(srcValid); return src; }
| 331 short getSrc() const { assert(srcValid); return src; }
|
333 void setSrc(short _src) { src = _src; srcValid = true; } 334 /** Reset source field, e.g. to retransmit packet on different bus. */ 335 void clearSrc() { srcValid = false; } 336 337 /** Accessor function that returns the destination index of 338 the packet. */
| 332 void setSrc(short _src) { src = _src; srcValid = true; } 333 /** Reset source field, e.g. to retransmit packet on different bus. */ 334 void clearSrc() { srcValid = false; } 335 336 /** Accessor function that returns the destination index of 337 the packet. */
|
339 short getDest() const { return dest; } 340 void setDest(short _dest) { dest = _dest; }
| 338 short getDest() const { assert(destValid); return dest; } 339 void setDest(short _dest) { dest = _dest; destValid = true; }
|
341 342 Addr getAddr() const { assert(addrSizeValid); return addr; }
| 340 341 Addr getAddr() const { assert(addrSizeValid); return addr; }
|
343 int getSize() const { assert(addrSizeValid); return size; }
| 342 int getSize() const { assert(addrSizeValid); return size; }
|
344 Addr getOffset(int blkSize) const { return addr & (Addr)(blkSize - 1); } 345
| 343 Addr getOffset(int blkSize) const { return addr & (Addr)(blkSize - 1); } 344
|
346 void addrOverride(Addr newAddr) { assert(addrSizeValid); addr = newAddr; } 347 void cmdOverride(MemCmd newCmd) { cmd = newCmd; } 348
| |
349 /** Constructor. Note that a Request object must be constructed 350 * first, but the Requests's physical address and size fields 351 * need not be valid. The command and destination addresses 352 * must be supplied. */ 353 Packet(Request *_req, MemCmd _cmd, short _dest)
| 345 /** Constructor. Note that a Request object must be constructed 346 * first, but the Requests's physical address and size fields 347 * need not be valid. The command and destination addresses 348 * must be supplied. */ 349 Packet(Request *_req, MemCmd _cmd, short _dest)
|
354 : data(NULL), staticData(false), dynamicData(false), arrayData(false),
| 350 : cmd(_cmd), req(_req), 351 data(NULL), staticData(false), dynamicData(false), arrayData(false),
|
355 addr(_req->paddr), size(_req->size), dest(_dest),
| 352 addr(_req->paddr), size(_req->size), dest(_dest),
|
356 addrSizeValid(_req->validPaddr), srcValid(false), 357 snoopFlags(0), 358 time(curTick), 359 req(_req), coherence(NULL), senderState(NULL), cmd(_cmd), 360 result(Unknown)
| 353 addrSizeValid(_req->validPaddr), srcValid(false), destValid(true), 354 flags(0), time(curTick), senderState(NULL)
|
361 { 362 } 363 364 /** Alternate constructor if you are trying to create a packet with 365 * a request that is for a whole block, not the address from the req. 366 * this allows for overriding the size/addr of the req.*/ 367 Packet(Request *_req, MemCmd _cmd, short _dest, int _blkSize)
| 355 { 356 } 357 358 /** Alternate constructor if you are trying to create a packet with 359 * a request that is for a whole block, not the address from the req. 360 * this allows for overriding the size/addr of the req.*/ 361 Packet(Request *_req, MemCmd _cmd, short _dest, int _blkSize)
|
368 : data(NULL), staticData(false), dynamicData(false), arrayData(false),
| 362 : cmd(_cmd), req(_req), 363 data(NULL), staticData(false), dynamicData(false), arrayData(false),
|
369 addr(_req->paddr & ~(_blkSize - 1)), size(_blkSize), dest(_dest),
| 364 addr(_req->paddr & ~(_blkSize - 1)), size(_blkSize), dest(_dest),
|
370 addrSizeValid(_req->validPaddr), srcValid(false), 371 snoopFlags(0), 372 time(curTick), 373 req(_req), coherence(NULL), senderState(NULL), cmd(_cmd), 374 result(Unknown)
| 365 addrSizeValid(_req->validPaddr), srcValid(false), destValid(true), 366 flags(0), time(curTick), senderState(NULL)
|
375 { 376 } 377 378 /** Alternate constructor for copying a packet. Copy all fields 379 * *except* set data allocation as static... even if the original 380 * packet's data was dynamic, we don't want to free it when the 381 * new packet is deallocated. Note that if original packet used 382 * dynamic data, user must guarantee that the new packet's 383 * lifetime is less than that of the original packet. */ 384 Packet(Packet *origPkt)
| 367 { 368 } 369 370 /** Alternate constructor for copying a packet. Copy all fields 371 * *except* set data allocation as static... even if the original 372 * packet's data was dynamic, we don't want to free it when the 373 * new packet is deallocated. Note that if original packet used 374 * dynamic data, user must guarantee that the new packet's 375 * lifetime is less than that of the original packet. */ 376 Packet(Packet *origPkt)
|
385 : data(NULL), staticData(false), dynamicData(false), arrayData(false),
| 377 : cmd(origPkt->cmd), req(origPkt->req), 378 data(NULL), staticData(false), dynamicData(false), arrayData(false),
|
386 addr(origPkt->addr), size(origPkt->size), 387 src(origPkt->src), dest(origPkt->dest),
| 379 addr(origPkt->addr), size(origPkt->size), 380 src(origPkt->src), dest(origPkt->dest),
|
388 addrSizeValid(origPkt->addrSizeValid), srcValid(origPkt->srcValid), 389 snoopFlags(origPkt->snoopFlags), 390 time(curTick), 391 req(origPkt->req), coherence(origPkt->coherence), 392 senderState(origPkt->senderState), cmd(origPkt->cmd), 393 result(origPkt->result)
| 381 addrSizeValid(origPkt->addrSizeValid), 382 srcValid(origPkt->srcValid), destValid(origPkt->destValid), 383 flags(origPkt->flags), 384 time(curTick), senderState(origPkt->senderState)
|
394 { 395 } 396 397 /** Destructor. */ 398 ~Packet() 399 { if (staticData || dynamicData) deleteData(); } 400 401 /** Reinitialize packet address and size from the associated 402 * Request object, and reset other fields that may have been 403 * modified by a previous transaction. Typically called when a 404 * statically allocated Request/Packet pair is reused for 405 * multiple transactions. */ 406 void reinitFromRequest() { 407 assert(req->validPaddr);
| 385 { 386 } 387 388 /** Destructor. */ 389 ~Packet() 390 { if (staticData || dynamicData) deleteData(); } 391 392 /** Reinitialize packet address and size from the associated 393 * Request object, and reset other fields that may have been 394 * modified by a previous transaction. Typically called when a 395 * statically allocated Request/Packet pair is reused for 396 * multiple transactions. */ 397 void reinitFromRequest() { 398 assert(req->validPaddr);
|
408 snoopFlags = 0;
| 399 flags = 0;
|
409 addr = req->paddr; 410 size = req->size; 411 time = req->time; 412 addrSizeValid = true;
| 400 addr = req->paddr; 401 size = req->size; 402 time = req->time; 403 addrSizeValid = true;
|
413 result = Unknown;
| |
414 if (dynamicData) { 415 deleteData(); 416 dynamicData = false; 417 arrayData = false; 418 } 419 } 420 421 /** 422 * Take a request packet and modify it in place to be suitable for 423 * returning as a response to that request. The source and 424 * destination fields are *not* modified, as is appropriate for 425 * atomic accesses. 426 */
| 404 if (dynamicData) { 405 deleteData(); 406 dynamicData = false; 407 arrayData = false; 408 } 409 } 410 411 /** 412 * Take a request packet and modify it in place to be suitable for 413 * returning as a response to that request. The source and 414 * destination fields are *not* modified, as is appropriate for 415 * atomic accesses. 416 */
|
427 void makeAtomicResponse()
| 417 void makeResponse()
|
428 { 429 assert(needsResponse()); 430 assert(isRequest());
| 418 { 419 assert(needsResponse()); 420 assert(isRequest());
|
431 assert(result == Unknown);
| |
432 cmd = cmd.responseCommand();
| 421 cmd = cmd.responseCommand();
|
433 result = Success;
| 422 dest = src; 423 destValid = srcValid; 424 srcValid = false;
|
434 } 435
| 425 } 426
|
436 /** 437 * Perform the additional work required for timing responses above 438 * and beyond atomic responses; i.e., change the destination to 439 * point back to the requester and clear the source field. 440 */ 441 void convertAtomicToTimingResponse()
| 427 void makeAtomicResponse()
|
442 {
| 428 {
|
443 dest = getSrc(); 444 srcValid = false;
| 429 makeResponse();
|
445 } 446
| 430 } 431
|
447 /** 448 * Take a request packet and modify it in place to be suitable for 449 * returning as a response to a timing request. 450 */
| |
451 void makeTimingResponse() 452 {
| 432 void makeTimingResponse() 433 {
|
453 makeAtomicResponse(); 454 convertAtomicToTimingResponse();
| 434 makeResponse();
|
455 } 456 457 /** 458 * Take a request packet that has been returned as NACKED and 459 * modify it so that it can be sent out again. Only packets that 460 * need a response can be NACKED, so verify that that is true. 461 */ 462 void 463 reinitNacked() 464 {
| 435 } 436 437 /** 438 * Take a request packet that has been returned as NACKED and 439 * modify it so that it can be sent out again. Only packets that 440 * need a response can be NACKED, so verify that that is true. 441 */ 442 void 443 reinitNacked() 444 {
|
465 assert(needsResponse() && result == Nacked); 466 dest = Broadcast; 467 result = Unknown;
| 445 assert(wasNacked()); 446 cmd = origCmd; 447 assert(needsResponse()); 448 setDest(Broadcast);
|
468 } 469 470 471 /** 472 * Set the data pointer to the following value that should not be 473 * freed. 474 */ 475 template <typename T> 476 void 477 dataStatic(T *p) 478 { 479 if(dynamicData) 480 dynamicData = false; 481 data = (PacketDataPtr)p; 482 staticData = true; 483 } 484 485 /** 486 * Set the data pointer to a value that should have delete [] 487 * called on it. 488 */ 489 template <typename T> 490 void 491 dataDynamicArray(T *p) 492 { 493 assert(!staticData && !dynamicData); 494 data = (PacketDataPtr)p; 495 dynamicData = true; 496 arrayData = true; 497 } 498 499 /** 500 * set the data pointer to a value that should have delete called 501 * on it. 502 */ 503 template <typename T> 504 void 505 dataDynamic(T *p) 506 { 507 assert(!staticData && !dynamicData); 508 data = (PacketDataPtr)p; 509 dynamicData = true; 510 arrayData = false; 511 } 512 513 /** get a pointer to the data ptr. */ 514 template <typename T> 515 T* 516 getPtr() 517 { 518 assert(staticData || dynamicData); 519 return (T*)data; 520 } 521 522 /** return the value of what is pointed to in the packet. */ 523 template <typename T> 524 T get(); 525 526 /** set the value in the data pointer to v. */ 527 template <typename T> 528 void set(T v); 529 530 /** 531 * Copy data into the packet from the provided pointer. 532 */ 533 void setData(uint8_t *p) 534 { 535 std::memcpy(getPtr<uint8_t>(), p, getSize()); 536 } 537 538 /** 539 * Copy data into the packet from the provided block pointer, 540 * which is aligned to the given block size. 541 */ 542 void setDataFromBlock(uint8_t *blk_data, int blkSize) 543 { 544 setData(blk_data + getOffset(blkSize)); 545 } 546 547 /** 548 * Copy data from the packet to the provided block pointer, which 549 * is aligned to the given block size. 550 */ 551 void writeData(uint8_t *p) 552 { 553 std::memcpy(p, getPtr<uint8_t>(), getSize()); 554 } 555 556 /** 557 * Copy data from the packet to the memory at the provided pointer. 558 */ 559 void writeDataToBlock(uint8_t *blk_data, int blkSize) 560 { 561 writeData(blk_data + getOffset(blkSize)); 562 } 563 564 /** 565 * delete the data pointed to in the data pointer. Ok to call to 566 * matter how data was allocted. 567 */ 568 void deleteData(); 569 570 /** If there isn't data in the packet, allocate some. */ 571 void allocate(); 572 573 /** Do the packet modify the same addresses. */ 574 bool intersect(PacketPtr p); 575 576 /** 577 * Check a functional request against a memory value represented 578 * by a base/size pair and an associated data array. If the 579 * functional request is a read, it may be satisfied by the memory 580 * value. If the functional request is a write, it may update the 581 * memory value. 582 */ 583 bool checkFunctional(Addr base, int size, uint8_t *data); 584 585 /** 586 * Check a functional request against a memory value stored in 587 * another packet (i.e. an in-transit request or response). 588 */ 589 bool checkFunctional(PacketPtr otherPkt) { 590 return (otherPkt->hasData() && 591 checkFunctional(otherPkt->getAddr(), otherPkt->getSize(), 592 otherPkt->getPtr<uint8_t>())); 593 } 594}; 595 596 597 598/** Temporary for backwards compatibility. 599 */ 600inline 601bool fixPacket(PacketPtr func, PacketPtr timing) { 602 return !func->checkFunctional(timing); 603} 604 605/** This function is a wrapper for the fixPacket field that toggles 606 * the hasData bit it is used when a response is waiting in the 607 * caches, but hasn't been marked as a response yet (so the fixPacket 608 * needs to get the correct value for the hasData) 609 */ 610bool fixDelayedResponsePacket(PacketPtr func, PacketPtr timing); 611 612std::ostream & operator<<(std::ostream &o, const Packet &p); 613 614#endif //__MEM_PACKET_HH
| 449 } 450 451 452 /** 453 * Set the data pointer to the following value that should not be 454 * freed. 455 */ 456 template <typename T> 457 void 458 dataStatic(T *p) 459 { 460 if(dynamicData) 461 dynamicData = false; 462 data = (PacketDataPtr)p; 463 staticData = true; 464 } 465 466 /** 467 * Set the data pointer to a value that should have delete [] 468 * called on it. 469 */ 470 template <typename T> 471 void 472 dataDynamicArray(T *p) 473 { 474 assert(!staticData && !dynamicData); 475 data = (PacketDataPtr)p; 476 dynamicData = true; 477 arrayData = true; 478 } 479 480 /** 481 * set the data pointer to a value that should have delete called 482 * on it. 483 */ 484 template <typename T> 485 void 486 dataDynamic(T *p) 487 { 488 assert(!staticData && !dynamicData); 489 data = (PacketDataPtr)p; 490 dynamicData = true; 491 arrayData = false; 492 } 493 494 /** get a pointer to the data ptr. */ 495 template <typename T> 496 T* 497 getPtr() 498 { 499 assert(staticData || dynamicData); 500 return (T*)data; 501 } 502 503 /** return the value of what is pointed to in the packet. */ 504 template <typename T> 505 T get(); 506 507 /** set the value in the data pointer to v. */ 508 template <typename T> 509 void set(T v); 510 511 /** 512 * Copy data into the packet from the provided pointer. 513 */ 514 void setData(uint8_t *p) 515 { 516 std::memcpy(getPtr<uint8_t>(), p, getSize()); 517 } 518 519 /** 520 * Copy data into the packet from the provided block pointer, 521 * which is aligned to the given block size. 522 */ 523 void setDataFromBlock(uint8_t *blk_data, int blkSize) 524 { 525 setData(blk_data + getOffset(blkSize)); 526 } 527 528 /** 529 * Copy data from the packet to the provided block pointer, which 530 * is aligned to the given block size. 531 */ 532 void writeData(uint8_t *p) 533 { 534 std::memcpy(p, getPtr<uint8_t>(), getSize()); 535 } 536 537 /** 538 * Copy data from the packet to the memory at the provided pointer. 539 */ 540 void writeDataToBlock(uint8_t *blk_data, int blkSize) 541 { 542 writeData(blk_data + getOffset(blkSize)); 543 } 544 545 /** 546 * delete the data pointed to in the data pointer. Ok to call to 547 * matter how data was allocted. 548 */ 549 void deleteData(); 550 551 /** If there isn't data in the packet, allocate some. */ 552 void allocate(); 553 554 /** Do the packet modify the same addresses. */ 555 bool intersect(PacketPtr p); 556 557 /** 558 * Check a functional request against a memory value represented 559 * by a base/size pair and an associated data array. If the 560 * functional request is a read, it may be satisfied by the memory 561 * value. If the functional request is a write, it may update the 562 * memory value. 563 */ 564 bool checkFunctional(Addr base, int size, uint8_t *data); 565 566 /** 567 * Check a functional request against a memory value stored in 568 * another packet (i.e. an in-transit request or response). 569 */ 570 bool checkFunctional(PacketPtr otherPkt) { 571 return (otherPkt->hasData() && 572 checkFunctional(otherPkt->getAddr(), otherPkt->getSize(), 573 otherPkt->getPtr<uint8_t>())); 574 } 575}; 576 577 578 579/** Temporary for backwards compatibility. 580 */ 581inline 582bool fixPacket(PacketPtr func, PacketPtr timing) { 583 return !func->checkFunctional(timing); 584} 585 586/** This function is a wrapper for the fixPacket field that toggles 587 * the hasData bit it is used when a response is waiting in the 588 * caches, but hasn't been marked as a response yet (so the fixPacket 589 * needs to get the correct value for the hasData) 590 */ 591bool fixDelayedResponsePacket(PacketPtr func, PacketPtr timing); 592 593std::ostream & operator<<(std::ostream &o, const Packet &p); 594 595#endif //__MEM_PACKET_HH
|