tport.hh revision 3349:fec4a86fa212
14434Ssaidi@eecs.umich.edu/*
24434Ssaidi@eecs.umich.edu * Copyright (c) 2006 The Regents of The University of Michigan
34434Ssaidi@eecs.umich.edu * All rights reserved.
44434Ssaidi@eecs.umich.edu *
54434Ssaidi@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
64434Ssaidi@eecs.umich.edu * modification, are permitted provided that the following conditions are
74434Ssaidi@eecs.umich.edu * met: redistributions of source code must retain the above copyright
84434Ssaidi@eecs.umich.edu * notice, this list of conditions and the following disclaimer;
94434Ssaidi@eecs.umich.edu * redistributions in binary form must reproduce the above copyright
104434Ssaidi@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the
114434Ssaidi@eecs.umich.edu * documentation and/or other materials provided with the distribution;
124434Ssaidi@eecs.umich.edu * neither the name of the copyright holders nor the names of its
134434Ssaidi@eecs.umich.edu * contributors may be used to endorse or promote products derived from
144434Ssaidi@eecs.umich.edu * this software without specific prior written permission.
154434Ssaidi@eecs.umich.edu *
164434Ssaidi@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
174434Ssaidi@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
184434Ssaidi@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
194434Ssaidi@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
204434Ssaidi@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
214434Ssaidi@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
224434Ssaidi@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
234434Ssaidi@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
244434Ssaidi@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
254434Ssaidi@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
264434Ssaidi@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
274434Ssaidi@eecs.umich.edu *
284434Ssaidi@eecs.umich.edu * Authors: Ali Saidi
294434Ssaidi@eecs.umich.edu */
304434Ssaidi@eecs.umich.edu
314434Ssaidi@eecs.umich.edu#ifndef __MEM_TPORT_HH__
324434Ssaidi@eecs.umich.edu#define __MEM_TPORT_HH__
334434Ssaidi@eecs.umich.edu
344434Ssaidi@eecs.umich.edu/**
354434Ssaidi@eecs.umich.edu * @file
364434Ssaidi@eecs.umich.edu *
374434Ssaidi@eecs.umich.edu * Declaration of SimpleTimingPort.
388706Sandreas.hansson@arm.com */
394434Ssaidi@eecs.umich.edu
404434Ssaidi@eecs.umich.edu#include "mem/port.hh"
414434Ssaidi@eecs.umich.edu#include "sim/eventq.hh"
424434Ssaidi@eecs.umich.edu#include <list>
434434Ssaidi@eecs.umich.edu#include <string>
444434Ssaidi@eecs.umich.edu
4514020Sgabeblack@google.com/**
464434Ssaidi@eecs.umich.edu * A simple port for interfacing objects that basically have only
474434Ssaidi@eecs.umich.edu * functional memory behavior (e.g. I/O devices) to the memory system.
486227Snate@binkert.org * Both timing and functional accesses are implemented in terms of
498737Skoansin.tan@gmail.com * atomic accesses.  A derived port class thus only needs to provide
5014010Sgabeblack@google.com * recvAtomic() to support all memory access modes.
518852Sandreas.hansson@arm.com *
524434Ssaidi@eecs.umich.edu * The tricky part is handling recvTiming(), where the response must
534434Ssaidi@eecs.umich.edu * be scheduled separately via a later call to sendTiming().  This
544434Ssaidi@eecs.umich.edu * feature is handled by scheduling an internal event that calls
554434Ssaidi@eecs.umich.edu * sendTiming() after a delay, and optionally rescheduling the
564434Ssaidi@eecs.umich.edu * response if it is nacked.
574434Ssaidi@eecs.umich.edu */
5814010Sgabeblack@google.comclass SimpleTimingPort : public Port
594434Ssaidi@eecs.umich.edu{
604434Ssaidi@eecs.umich.edu  protected:
614434Ssaidi@eecs.umich.edu    /** A list of outgoing timing response packets that haven't been
62     * serviced yet. */
63    std::list<PacketPtr> transmitList;
64
65    /**
66     * This class is used to implemented sendTiming() with a delay. When
67     * a delay is requested a new event is created. When the event time
68     * expires it attempts to send the packet. If it cannot, the packet
69     * is pushed onto the transmit list to be sent when recvRetry() is
70     * called. */
71    class SendEvent : public Event
72    {
73        SimpleTimingPort *port;
74        PacketPtr packet;
75
76      public:
77        SendEvent(SimpleTimingPort *p, PacketPtr pkt, Tick t)
78            : Event(&mainEventQueue), port(p), packet(pkt)
79        { setFlags(AutoDelete); schedule(curTick + t); }
80
81        virtual void process();
82
83        virtual const char *description()
84        { return "Future scheduled sendTiming event"; }
85    };
86
87
88    /** Number of timing requests that are emulating the device timing before
89     * attempting to end up on the bus.
90     */
91    int outTiming;
92
93    /** If we need to drain, keep the drain event around until we're done
94     * here.*/
95    Event *drainEvent;
96
97    /** Schedule a sendTiming() event to be called in the future. */
98    void sendTimingLater(PacketPtr pkt, Tick time)
99    { outTiming++; new SendEvent(this, pkt, time); }
100
101    /** This function is notification that the device should attempt to send a
102     * packet again. */
103    virtual void recvRetry();
104
105    /** Implemented using recvAtomic(). */
106    void recvFunctional(PacketPtr pkt);
107
108    /** Implemented using recvAtomic(). */
109    bool recvTiming(PacketPtr pkt);
110
111    /**
112     * Simple ports generally don't care about any status
113     * changes... can always override this in cases where that's not
114     * true. */
115    virtual void recvStatusChange(Status status) { }
116
117
118  public:
119
120    SimpleTimingPort(std::string pname)
121        : Port(pname), outTiming(0), drainEvent(NULL)
122    {}
123
124    /** Hook for draining timing accesses from the system.  The
125     * associated SimObject's drain() functions should be implemented
126     * something like this when this class is used:
127     \code
128          PioDevice::drain(Event *de)
129          {
130              unsigned int count;
131              count = SimpleTimingPort->drain(de);
132              if (count)
133                  changeState(Draining);
134              else
135                  changeState(Drained);
136              return count;
137          }
138     \endcode
139    */
140    unsigned int drain(Event *de);
141};
142
143#endif // __MEM_TPORT_HH__
144