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