tport.hh revision 8711
12914Ssaidi@eecs.umich.edu/* 22914Ssaidi@eecs.umich.edu * Copyright (c) 2006 The Regents of The University of Michigan 32914Ssaidi@eecs.umich.edu * All rights reserved. 42914Ssaidi@eecs.umich.edu * 52914Ssaidi@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 62914Ssaidi@eecs.umich.edu * modification, are permitted provided that the following conditions are 72914Ssaidi@eecs.umich.edu * met: redistributions of source code must retain the above copyright 82914Ssaidi@eecs.umich.edu * notice, this list of conditions and the following disclaimer; 92914Ssaidi@eecs.umich.edu * redistributions in binary form must reproduce the above copyright 102914Ssaidi@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 112914Ssaidi@eecs.umich.edu * documentation and/or other materials provided with the distribution; 122914Ssaidi@eecs.umich.edu * neither the name of the copyright holders nor the names of its 132914Ssaidi@eecs.umich.edu * contributors may be used to endorse or promote products derived from 142914Ssaidi@eecs.umich.edu * this software without specific prior written permission. 152914Ssaidi@eecs.umich.edu * 162914Ssaidi@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172914Ssaidi@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182914Ssaidi@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192914Ssaidi@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202914Ssaidi@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212914Ssaidi@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222914Ssaidi@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232914Ssaidi@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242914Ssaidi@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252914Ssaidi@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262914Ssaidi@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272914Ssaidi@eecs.umich.edu * 282914Ssaidi@eecs.umich.edu * Authors: Ali Saidi 292914Ssaidi@eecs.umich.edu */ 302914Ssaidi@eecs.umich.edu 313091Sstever@eecs.umich.edu#ifndef __MEM_TPORT_HH__ 323091Sstever@eecs.umich.edu#define __MEM_TPORT_HH__ 333091Sstever@eecs.umich.edu 342914Ssaidi@eecs.umich.edu/** 352914Ssaidi@eecs.umich.edu * @file 363091Sstever@eecs.umich.edu * 373091Sstever@eecs.umich.edu * Declaration of SimpleTimingPort. 382914Ssaidi@eecs.umich.edu */ 392914Ssaidi@eecs.umich.edu 408229Snate@binkert.org#include <list> 418229Snate@binkert.org#include <string> 428229Snate@binkert.org 432914Ssaidi@eecs.umich.edu#include "mem/port.hh" 442914Ssaidi@eecs.umich.edu#include "sim/eventq.hh" 452914Ssaidi@eecs.umich.edu 463091Sstever@eecs.umich.edu/** 473091Sstever@eecs.umich.edu * A simple port for interfacing objects that basically have only 483091Sstever@eecs.umich.edu * functional memory behavior (e.g. I/O devices) to the memory system. 493091Sstever@eecs.umich.edu * Both timing and functional accesses are implemented in terms of 503091Sstever@eecs.umich.edu * atomic accesses. A derived port class thus only needs to provide 513091Sstever@eecs.umich.edu * recvAtomic() to support all memory access modes. 523091Sstever@eecs.umich.edu * 533091Sstever@eecs.umich.edu * The tricky part is handling recvTiming(), where the response must 543091Sstever@eecs.umich.edu * be scheduled separately via a later call to sendTiming(). This 553091Sstever@eecs.umich.edu * feature is handled by scheduling an internal event that calls 563091Sstever@eecs.umich.edu * sendTiming() after a delay, and optionally rescheduling the 573091Sstever@eecs.umich.edu * response if it is nacked. 583091Sstever@eecs.umich.edu */ 592914Ssaidi@eecs.umich.educlass SimpleTimingPort : public Port 602914Ssaidi@eecs.umich.edu{ 612914Ssaidi@eecs.umich.edu protected: 624490Sstever@eecs.umich.edu /** A deferred packet, buffered to transmit later. */ 634490Sstever@eecs.umich.edu class DeferredPacket { 644490Sstever@eecs.umich.edu public: 654490Sstever@eecs.umich.edu Tick tick; ///< The tick when the packet is ready to transmit 664490Sstever@eecs.umich.edu PacketPtr pkt; ///< Pointer to the packet to transmit 674490Sstever@eecs.umich.edu DeferredPacket(Tick t, PacketPtr p) 684490Sstever@eecs.umich.edu : tick(t), pkt(p) 694490Sstever@eecs.umich.edu {} 704490Sstever@eecs.umich.edu }; 714490Sstever@eecs.umich.edu 724490Sstever@eecs.umich.edu typedef std::list<DeferredPacket> DeferredPacketList; 734490Sstever@eecs.umich.edu typedef std::list<DeferredPacket>::iterator DeferredPacketIterator; 744490Sstever@eecs.umich.edu 753090Sstever@eecs.umich.edu /** A list of outgoing timing response packets that haven't been 763090Sstever@eecs.umich.edu * serviced yet. */ 774490Sstever@eecs.umich.edu DeferredPacketList transmitList; 784490Sstever@eecs.umich.edu 794490Sstever@eecs.umich.edu /** This function attempts to send deferred packets. Scheduled to 804490Sstever@eecs.umich.edu * be called in the future via SendEvent. */ 814490Sstever@eecs.umich.edu void processSendEvent(); 823091Sstever@eecs.umich.edu 832914Ssaidi@eecs.umich.edu /** 843090Sstever@eecs.umich.edu * This class is used to implemented sendTiming() with a delay. When 853403Ssaidi@eecs.umich.edu * a delay is requested a the event is scheduled if it isn't already. 863403Ssaidi@eecs.umich.edu * When the event time expires it attempts to send the packet. 873403Ssaidi@eecs.umich.edu * If it cannot, the packet sent when recvRetry() is called. 883403Ssaidi@eecs.umich.edu **/ 894490Sstever@eecs.umich.edu Event *sendEvent; 902914Ssaidi@eecs.umich.edu 912914Ssaidi@eecs.umich.edu /** If we need to drain, keep the drain event around until we're done 922914Ssaidi@eecs.umich.edu * here.*/ 932914Ssaidi@eecs.umich.edu Event *drainEvent; 942914Ssaidi@eecs.umich.edu 954492Sstever@eecs.umich.edu /** Remember whether we're awaiting a retry from the bus. */ 964492Sstever@eecs.umich.edu bool waitingOnRetry; 974492Sstever@eecs.umich.edu 984490Sstever@eecs.umich.edu /** Check the list of buffered packets against the supplied 994490Sstever@eecs.umich.edu * functional request. */ 1004929Sstever@gmail.com bool checkFunctional(PacketPtr funcPkt); 1014490Sstever@eecs.umich.edu 1024492Sstever@eecs.umich.edu /** Check whether we have a packet ready to go on the transmit list. */ 1034492Sstever@eecs.umich.edu bool deferredPacketReady() 1047823Ssteve.reinhardt@amd.com { return !transmitList.empty() && transmitList.front().tick <= curTick(); } 1054492Sstever@eecs.umich.edu 1064871Sstever@eecs.umich.edu Tick deferredPacketReadyTime() 1074666Sstever@eecs.umich.edu { return transmitList.empty() ? MaxTick : transmitList.front().tick; } 1084666Sstever@eecs.umich.edu 1098708Sandreas.hansson@arm.com /** 1108708Sandreas.hansson@arm.com * Schedule a send even if not already waiting for a retry. If the 1118708Sandreas.hansson@arm.com * requested time is before an already scheduled send event it 1128708Sandreas.hansson@arm.com * will be rescheduled. 1138708Sandreas.hansson@arm.com * 1148708Sandreas.hansson@arm.com * @param when 1158708Sandreas.hansson@arm.com */ 1168708Sandreas.hansson@arm.com void schedSendEvent(Tick when); 1174666Sstever@eecs.umich.edu 1183403Ssaidi@eecs.umich.edu /** Schedule a sendTiming() event to be called in the future. 1193403Ssaidi@eecs.umich.edu * @param pkt packet to send 1204492Sstever@eecs.umich.edu * @param absolute time (in ticks) to send packet 1213403Ssaidi@eecs.umich.edu */ 1224492Sstever@eecs.umich.edu void schedSendTiming(PacketPtr pkt, Tick when); 1234492Sstever@eecs.umich.edu 1244492Sstever@eecs.umich.edu /** Attempt to send the packet at the head of the deferred packet 1254492Sstever@eecs.umich.edu * list. Caller must guarantee that the deferred packet list is 1267823Ssteve.reinhardt@amd.com * non-empty and that the head packet is scheduled for curTick() (or 1274492Sstever@eecs.umich.edu * earlier). 1284492Sstever@eecs.umich.edu */ 1294492Sstever@eecs.umich.edu void sendDeferredPacket(); 1302914Ssaidi@eecs.umich.edu 1312914Ssaidi@eecs.umich.edu /** This function is notification that the device should attempt to send a 1322914Ssaidi@eecs.umich.edu * packet again. */ 1332914Ssaidi@eecs.umich.edu virtual void recvRetry(); 1342914Ssaidi@eecs.umich.edu 1353091Sstever@eecs.umich.edu /** Implemented using recvAtomic(). */ 1363349Sbinkertn@umich.edu void recvFunctional(PacketPtr pkt); 1373091Sstever@eecs.umich.edu 1383091Sstever@eecs.umich.edu /** Implemented using recvAtomic(). */ 1393349Sbinkertn@umich.edu bool recvTiming(PacketPtr pkt); 1403091Sstever@eecs.umich.edu 1413091Sstever@eecs.umich.edu /** 1428711Sandreas.hansson@arm.com * Simple ports are generally used as slave ports (i.e. the 1438711Sandreas.hansson@arm.com * respond to requests) and thus do not expect to receive any 1448711Sandreas.hansson@arm.com * range changes (as the neighbouring port has a master role and 1458711Sandreas.hansson@arm.com * do not have any address ranges. A subclass can override the 1468711Sandreas.hansson@arm.com * default behaviuor if needed. 1478711Sandreas.hansson@arm.com */ 1488711Sandreas.hansson@arm.com virtual void recvRangeChange() { } 1493091Sstever@eecs.umich.edu 1503091Sstever@eecs.umich.edu 1512914Ssaidi@eecs.umich.edu public: 1525740Snate@binkert.org SimpleTimingPort(std::string pname, MemObject *_owner); 1535740Snate@binkert.org ~SimpleTimingPort(); 1544490Sstever@eecs.umich.edu 1553091Sstever@eecs.umich.edu /** Hook for draining timing accesses from the system. The 1563091Sstever@eecs.umich.edu * associated SimObject's drain() functions should be implemented 1573091Sstever@eecs.umich.edu * something like this when this class is used: 1583091Sstever@eecs.umich.edu \code 1593091Sstever@eecs.umich.edu PioDevice::drain(Event *de) 1603091Sstever@eecs.umich.edu { 1613091Sstever@eecs.umich.edu unsigned int count; 1623091Sstever@eecs.umich.edu count = SimpleTimingPort->drain(de); 1633091Sstever@eecs.umich.edu if (count) 1643091Sstever@eecs.umich.edu changeState(Draining); 1653091Sstever@eecs.umich.edu else 1663091Sstever@eecs.umich.edu changeState(Drained); 1673091Sstever@eecs.umich.edu return count; 1683091Sstever@eecs.umich.edu } 1693091Sstever@eecs.umich.edu \endcode 1703091Sstever@eecs.umich.edu */ 1712914Ssaidi@eecs.umich.edu unsigned int drain(Event *de); 1722914Ssaidi@eecs.umich.edu}; 1732914Ssaidi@eecs.umich.edu 1742914Ssaidi@eecs.umich.edu#endif // __MEM_TPORT_HH__ 175