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; --- 70 unchanged lines hidden (view full) --- 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 |
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 |
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; --- 16 unchanged lines hidden (view full) --- 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); } |
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; --- 27 unchanged lines hidden (view full) --- 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 |
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; --- 23 unchanged lines hidden (view full) --- 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 flags |
256 MemInhibit, 257 Shared, |
258 NUM_PACKET_FLAGS |
259 }; 260 |
261 /** Status flags */ 262 std::bitset<NUM_PACKET_FLAGS> flags; |
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 |
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 |
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 |
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(); } |
306 bool needsExclusive() const { return cmd.needsExclusive(); } |
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(); } |
313 |
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]; } |
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 |
328 bool nic_pkt() { panic("Unimplemented"); M5_DUMMY_RETURN } 329 |
330 /** Accessor function that returns the source index of the packet. */ |
331 short getSrc() const { assert(srcValid); return src; } |
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. */ |
338 short getDest() const { assert(destValid); return dest; } 339 void setDest(short _dest) { dest = _dest; destValid = true; } |
340 341 Addr getAddr() const { assert(addrSizeValid); return addr; } |
342 int getSize() const { assert(addrSizeValid); return size; } |
343 Addr getOffset(int blkSize) const { return addr & (Addr)(blkSize - 1); } 344 |
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) |
350 : cmd(_cmd), req(_req), 351 data(NULL), staticData(false), dynamicData(false), arrayData(false), |
352 addr(_req->paddr), size(_req->size), dest(_dest), |
353 addrSizeValid(_req->validPaddr), srcValid(false), destValid(true), 354 flags(0), time(curTick), senderState(NULL) |
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) |
362 : cmd(_cmd), req(_req), 363 data(NULL), staticData(false), dynamicData(false), arrayData(false), |
364 addr(_req->paddr & ~(_blkSize - 1)), size(_blkSize), dest(_dest), |
365 addrSizeValid(_req->validPaddr), srcValid(false), destValid(true), 366 flags(0), time(curTick), senderState(NULL) |
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) |
377 : cmd(origPkt->cmd), req(origPkt->req), 378 data(NULL), staticData(false), dynamicData(false), arrayData(false), |
379 addr(origPkt->addr), size(origPkt->size), 380 src(origPkt->src), dest(origPkt->dest), |
381 addrSizeValid(origPkt->addrSizeValid), 382 srcValid(origPkt->srcValid), destValid(origPkt->destValid), 383 flags(origPkt->flags), 384 time(curTick), senderState(origPkt->senderState) |
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); |
399 flags = 0; |
400 addr = req->paddr; 401 size = req->size; 402 time = req->time; 403 addrSizeValid = true; |
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 */ |
417 void makeResponse() |
418 { 419 assert(needsResponse()); 420 assert(isRequest()); |
421 cmd = cmd.responseCommand(); |
422 dest = src; 423 destValid = srcValid; 424 srcValid = false; |
425 } 426 |
427 void makeAtomicResponse() |
428 { |
429 makeResponse(); |
430 } 431 |
432 void makeTimingResponse() 433 { |
434 makeResponse(); |
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 { |
445 assert(wasNacked()); 446 cmd = origCmd; 447 assert(needsResponse()); 448 setDest(Broadcast); |
449 } 450 451 452 /** 453 * Set the data pointer to the following value that should not be 454 * freed. 455 */ 456 template <typename T> --- 139 unchanged lines hidden --- |