Message.hh revision 10893:f567e80c0714
111590SCurtis.Dunham@arm.com/* 211590SCurtis.Dunham@arm.com * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 311590SCurtis.Dunham@arm.com * All rights reserved. 411590SCurtis.Dunham@arm.com * 511590SCurtis.Dunham@arm.com * Redistribution and use in source and binary forms, with or without 611590SCurtis.Dunham@arm.com * modification, are permitted provided that the following conditions are 711590SCurtis.Dunham@arm.com * met: redistributions of source code must retain the above copyright 811590SCurtis.Dunham@arm.com * notice, this list of conditions and the following disclaimer; 911590SCurtis.Dunham@arm.com * redistributions in binary form must reproduce the above copyright 1011590SCurtis.Dunham@arm.com * notice, this list of conditions and the following disclaimer in the 1111590SCurtis.Dunham@arm.com * documentation and/or other materials provided with the distribution; 1211590SCurtis.Dunham@arm.com * neither the name of the copyright holders nor the names of its 1311590SCurtis.Dunham@arm.com * contributors may be used to endorse or promote products derived from 1411590SCurtis.Dunham@arm.com * this software without specific prior written permission. 1511590SCurtis.Dunham@arm.com * 1611590SCurtis.Dunham@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1711590SCurtis.Dunham@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1811590SCurtis.Dunham@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1911590SCurtis.Dunham@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2011590SCurtis.Dunham@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2111590SCurtis.Dunham@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2211590SCurtis.Dunham@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2311590SCurtis.Dunham@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2411590SCurtis.Dunham@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2511590SCurtis.Dunham@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2611590SCurtis.Dunham@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2711590SCurtis.Dunham@arm.com */ 2811590SCurtis.Dunham@arm.com 2911590SCurtis.Dunham@arm.com#ifndef __MEM_RUBY_SLICC_INTERFACE_MESSAGE_HH__ 3011590SCurtis.Dunham@arm.com#define __MEM_RUBY_SLICC_INTERFACE_MESSAGE_HH__ 3111590SCurtis.Dunham@arm.com 3211590SCurtis.Dunham@arm.com#include <iostream> 3311590SCurtis.Dunham@arm.com#include <memory> 3411590SCurtis.Dunham@arm.com#include <stack> 3511590SCurtis.Dunham@arm.com 3611590SCurtis.Dunham@arm.com#include "mem/packet.hh" 3711590SCurtis.Dunham@arm.com 3811590SCurtis.Dunham@arm.comclass Message; 3911590SCurtis.Dunham@arm.comtypedef std::shared_ptr<Message> MsgPtr; 4011590SCurtis.Dunham@arm.com 4111590SCurtis.Dunham@arm.comclass Message 4211590SCurtis.Dunham@arm.com{ 4311590SCurtis.Dunham@arm.com public: 4411590SCurtis.Dunham@arm.com Message(Tick curTime) 4511590SCurtis.Dunham@arm.com : m_time(curTime), 4611590SCurtis.Dunham@arm.com m_LastEnqueueTime(curTime), 4711590SCurtis.Dunham@arm.com m_DelayedTicks(0), m_msg_counter(0) 4811590SCurtis.Dunham@arm.com { } 4911590SCurtis.Dunham@arm.com 5011590SCurtis.Dunham@arm.com Message(const Message &other) 5111590SCurtis.Dunham@arm.com : m_time(other.m_time), 5211590SCurtis.Dunham@arm.com m_LastEnqueueTime(other.m_LastEnqueueTime), 5311590SCurtis.Dunham@arm.com m_DelayedTicks(other.m_DelayedTicks), 5411590SCurtis.Dunham@arm.com m_msg_counter(other.m_msg_counter) 5511590SCurtis.Dunham@arm.com { } 5611590SCurtis.Dunham@arm.com 5711590SCurtis.Dunham@arm.com virtual ~Message() { } 5811590SCurtis.Dunham@arm.com 5911590SCurtis.Dunham@arm.com virtual MsgPtr clone() const = 0; 6011590SCurtis.Dunham@arm.com virtual void print(std::ostream& out) const = 0; 6111590SCurtis.Dunham@arm.com virtual void setIncomingLink(int) {} 6211590SCurtis.Dunham@arm.com virtual void setVnet(int) {} 6311590SCurtis.Dunham@arm.com 6411590SCurtis.Dunham@arm.com /** 6511590SCurtis.Dunham@arm.com * The two functions below are used for reading / writing the message 6611590SCurtis.Dunham@arm.com * functionally. The methods return true if the address in the packet 6711590SCurtis.Dunham@arm.com * matches the address / address range in the message. Each message 6811590SCurtis.Dunham@arm.com * class that can be potentially searched for the address needs to 6911590SCurtis.Dunham@arm.com * implement these methods. 7011590SCurtis.Dunham@arm.com */ 7111590SCurtis.Dunham@arm.com virtual bool functionalRead(Packet *pkt) = 0; 7211590SCurtis.Dunham@arm.com virtual bool functionalWrite(Packet *pkt) = 0; 7311590SCurtis.Dunham@arm.com 7411590SCurtis.Dunham@arm.com //! Update the delay this message has experienced so far. 7511590SCurtis.Dunham@arm.com void updateDelayedTicks(Tick curTime) 7611590SCurtis.Dunham@arm.com { 7711590SCurtis.Dunham@arm.com assert(m_LastEnqueueTime <= curTime); 7811590SCurtis.Dunham@arm.com Tick delta = curTime - m_LastEnqueueTime; 7911590SCurtis.Dunham@arm.com m_DelayedTicks += delta; 80 } 81 const Tick getDelayedTicks() const {return m_DelayedTicks;} 82 83 void setLastEnqueueTime(const Tick& time) { m_LastEnqueueTime = time; } 84 const Tick getLastEnqueueTime() const {return m_LastEnqueueTime;} 85 86 const Tick& getTime() const { return m_time; } 87 void setMsgCounter(uint64_t c) { m_msg_counter = c; } 88 uint64_t getMsgCounter() const { return m_msg_counter; } 89 90 private: 91 const Tick m_time; 92 Tick m_LastEnqueueTime; // my last enqueue time 93 Tick m_DelayedTicks; // my delayed cycles 94 uint64_t m_msg_counter; // FIXME, should this be a 64-bit value? 95}; 96 97inline bool 98operator>(const MsgPtr &lhs, const MsgPtr &rhs) 99{ 100 const Message *l = lhs.get(); 101 const Message *r = rhs.get(); 102 103 if (l->getLastEnqueueTime() == r->getLastEnqueueTime()) { 104 assert(l->getMsgCounter() != r->getMsgCounter()); 105 return l->getMsgCounter() > r->getMsgCounter(); 106 } 107 return l->getLastEnqueueTime() > r->getLastEnqueueTime(); 108} 109 110inline std::ostream& 111operator<<(std::ostream& out, const Message& obj) 112{ 113 obj.print(out); 114 out << std::flush; 115 return out; 116} 117 118#endif // __MEM_RUBY_SLICC_INTERFACE_MESSAGE_HH__ 119