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; --- 31 unchanged lines hidden (view full) --- 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" |
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; --- 30 unchanged lines hidden (view full) --- 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 |
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 --- 4 unchanged lines hidden (view full) --- 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) |
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; --- 23 unchanged lines hidden (view full) --- 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); } |
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; --- 21 unchanged lines hidden (view full) --- 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 */ |
195class Packet : public FastAlloc, public Printable |
196{ 197 public: 198 199 typedef MemCmd::Command Command; 200 201 /** The command field of the packet. */ 202 MemCmd cmd; 203 --- 90 unchanged lines hidden (view full) --- 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 |
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 --- 6 unchanged lines hidden (view full) --- 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(); } |
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 --- 241 unchanged lines hidden (view full) --- 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 */ |
612 bool checkFunctional(Printable *obj, Addr base, int size, uint8_t *data); |
613 614 /** 615 * Check a functional request against a memory value stored in |
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. |
623 */ 624 bool checkFunctional(PacketPtr otherPkt) { |
625 return checkFunctional(otherPkt, 626 otherPkt->getAddr(), otherPkt->getSize(), 627 otherPkt->hasData() ? 628 otherPkt->getPtr<uint8_t>() : NULL); |
629 } |
630 |
631 void pushLabel(const std::string &lbl) { 632 if (isPrint()) { 633 dynamic_cast<PrintReqState*>(senderState)->pushLabel(lbl); 634 } 635 } |
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 |
647#endif //__MEM_PACKET_HH |