packet_queue.hh revision 8711
12SN/A/*
21762SN/A * Copyright (c) 2006 The Regents of The University of Michigan
32SN/A * All rights reserved.
42SN/A *
52SN/A * Redistribution and use in source and binary forms, with or without
62SN/A * modification, are permitted provided that the following conditions are
72SN/A * met: redistributions of source code must retain the above copyright
82SN/A * notice, this list of conditions and the following disclaimer;
92SN/A * redistributions in binary form must reproduce the above copyright
102SN/A * notice, this list of conditions and the following disclaimer in the
112SN/A * documentation and/or other materials provided with the distribution;
122SN/A * neither the name of the copyright holders nor the names of its
132SN/A * contributors may be used to endorse or promote products derived from
142SN/A * this software without specific prior written permission.
152SN/A *
162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu *
282665Ssaidi@eecs.umich.edu * Authors: Ali Saidi
292665Ssaidi@eecs.umich.edu */
302SN/A
312SN/A#ifndef __MEM_TPORT_HH__
321717SN/A#define __MEM_TPORT_HH__
331717SN/A
342SN/A/**
352SN/A * @file
362SN/A *
37707SN/A * Declaration of SimpleTimingPort.
381858SN/A */
3956SN/A
402856Srdreslin@umich.edu#include <list>
412109SN/A#include <string>
422SN/A
432190SN/A#include "mem/port.hh"
442315SN/A#include "sim/eventq.hh"
452680Sktlim@umich.edu
462SN/A/**
472856Srdreslin@umich.edu * A simple port for interfacing objects that basically have only
482SN/A * functional memory behavior (e.g. I/O devices) to the memory system.
492356SN/A * Both timing and functional accesses are implemented in terms of
502356SN/A * atomic accesses.  A derived port class thus only needs to provide
512356SN/A * recvAtomic() to support all memory access modes.
522356SN/A *
532356SN/A * The tricky part is handling recvTiming(), where the response must
542356SN/A * be scheduled separately via a later call to sendTiming().  This
552356SN/A * feature is handled by scheduling an internal event that calls
562356SN/A * sendTiming() after a delay, and optionally rescheduling the
573126Sktlim@umich.edu * response if it is nacked.
582356SN/A */
592356SN/Aclass SimpleTimingPort : public Port
602356SN/A{
612356SN/A  protected:
622356SN/A    /** A deferred packet, buffered to transmit later. */
632356SN/A    class DeferredPacket {
642856Srdreslin@umich.edu      public:
652SN/A        Tick tick;      ///< The tick when the packet is ready to transmit
661634SN/A        PacketPtr pkt;  ///< Pointer to the packet to transmit
671634SN/A        DeferredPacket(Tick t, PacketPtr p)
681695SN/A            : tick(t), pkt(p)
691634SN/A        {}
701634SN/A    };
712359SN/A
721695SN/A    typedef std::list<DeferredPacket> DeferredPacketList;
731695SN/A    typedef std::list<DeferredPacket>::iterator DeferredPacketIterator;
741695SN/A
751634SN/A    /** A list of outgoing timing response packets that haven't been
761858SN/A     * serviced yet. */
772SN/A    DeferredPacketList transmitList;
782107SN/A
792SN/A    /** This function attempts to send deferred packets.  Scheduled to
802SN/A     * be called in the future via SendEvent. */
812SN/A    void processSendEvent();
822SN/A
832SN/A    /**
842SN/A     * This class is used to implemented sendTiming() with a delay. When
851133SN/A     * a delay is requested a the event is scheduled if it isn't already.
862SN/A     * When the event time expires it attempts to send the packet.
872SN/A     * If it cannot, the packet sent when recvRetry() is called.
882107SN/A     **/
892SN/A    Event *sendEvent;
902SN/A
912SN/A    /** If we need to drain, keep the drain event around until we're done
922SN/A     * here.*/
932SN/A    Event *drainEvent;
942SN/A
952SN/A    /** Remember whether we're awaiting a retry from the bus. */
961917SN/A    bool waitingOnRetry;
971917SN/A
981917SN/A    /** Check the list of buffered packets against the supplied
991917SN/A     * functional request. */
1001917SN/A    bool checkFunctional(PacketPtr funcPkt);
1011917SN/A
1021917SN/A    /** Check whether we have a packet ready to go on the transmit list. */
1031917SN/A    bool deferredPacketReady()
1041917SN/A    { return !transmitList.empty() && transmitList.front().tick <= curTick(); }
1051917SN/A
1061917SN/A    Tick deferredPacketReadyTime()
1071917SN/A    { return transmitList.empty() ? MaxTick : transmitList.front().tick; }
1082SN/A
1092SN/A    /**
1102SN/A     * Schedule a send even if not already waiting for a retry. If the
1112680Sktlim@umich.edu     * requested time is before an already scheduled send event it
1122SN/A     * will be rescheduled.
1132SN/A     *
114393SN/A     * @param when
115393SN/A     */
116393SN/A    void schedSendEvent(Tick when);
117393SN/A
118393SN/A    /** Schedule a sendTiming() event to be called in the future.
119393SN/A     * @param pkt packet to send
120393SN/A     * @param absolute time (in ticks) to send packet
121393SN/A     */
122393SN/A    void schedSendTiming(PacketPtr pkt, Tick when);
123393SN/A
124393SN/A    /** Attempt to send the packet at the head of the deferred packet
125393SN/A     * list.  Caller must guarantee that the deferred packet list is
126393SN/A     * non-empty and that the head packet is scheduled for curTick() (or
127393SN/A     * earlier).
1282SN/A     */
1292SN/A    void sendDeferredPacket();
1301400SN/A
1311400SN/A    /** This function is notification that the device should attempt to send a
1321400SN/A     * packet again. */
1331400SN/A    virtual void recvRetry();
1341400SN/A
1351400SN/A    /** Implemented using recvAtomic(). */
1361400SN/A    void recvFunctional(PacketPtr pkt);
1371400SN/A
1381400SN/A    /** Implemented using recvAtomic(). */
1391695SN/A    bool recvTiming(PacketPtr pkt);
1401400SN/A
1411400SN/A    /**
1422378SN/A     * Simple ports are generally used as slave ports (i.e. the
1433170Sstever@eecs.umich.edu     * respond to requests) and thus do not expect to receive any
1441858SN/A     * range changes (as the neighbouring port has a master role and
1451917SN/A     * do not have any address ranges. A subclass can override the
1461400SN/A     * default behaviuor if needed.
1472356SN/A     */
1482315SN/A    virtual void recvRangeChange() { }
1491917SN/A
1501917SN/A
1511400SN/A  public:
1522SN/A    SimpleTimingPort(std::string pname, MemObject *_owner);
1531400SN/A    ~SimpleTimingPort();
1542SN/A
1551400SN/A    /** Hook for draining timing accesses from the system.  The
1561191SN/A     * associated SimObject's drain() functions should be implemented
1572SN/A     * something like this when this class is used:
1581129SN/A     \code
1591917SN/A          PioDevice::drain(Event *de)
1602SN/A          {
1612SN/A              unsigned int count;
1622103SN/A              count = SimpleTimingPort->drain(de);
1632103SN/A              if (count)
1642680Sktlim@umich.edu                  changeState(Draining);
165180SN/A              else
1661492SN/A                  changeState(Drained);
1671492SN/A              return count;
1682798Sktlim@umich.edu          }
169180SN/A     \endcode
170180SN/A    */
171180SN/A    unsigned int drain(Event *de);
172180SN/A};
173180SN/A
174124SN/A#endif // __MEM_TPORT_HH__
175124SN/A