tport.hh revision 2914:2c524dc023d2
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;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Ali Saidi
29 */
30
31/**
32 * @file
33 * Implement a port which adds simple support of a sendTiming() function that
34 * takes a delay. In this way the * device can immediatly call
35 * sendTiming(pkt, time) after processing a request and the request will be
36 * handled by the port even if the port bus the device connects to is blocked.
37 */
38
39/** recvTiming and drain should be implemented something like this when this
40 * class is used.
41
42bool
43PioPort::recvTiming(Packet *pkt)
44{
45    if (pkt->result == Packet::Nacked) {
46        resendNacked(pkt);
47    } else {
48        Tick latency = device->recvAtomic(pkt);
49        // turn packet around to go back to requester
50        pkt->makeTimingResponse();
51        sendTiming(pkt, latency);
52    }
53    return true;
54}
55
56PioDevice::drain(Event *de)
57{
58    unsigned int count;
59    count = SimpleTimingPort->drain(de);
60    if (count)
61        changeState(Draining);
62    else
63        changeState(Drained);
64    return count;
65}
66*/
67
68#ifndef __MEM_TPORT_HH__
69#define __MEM_TPORT_HH__
70
71#include "mem/port.hh"
72#include "sim/eventq.hh"
73#include <list>
74#include <string>
75
76class SimpleTimingPort : public Port
77{
78  protected:
79    /** A list of outgoing timing response packets that haven't been serviced
80     * yet. */
81    std::list<Packet*> transmitList;
82    /**
83     * This class is used to implemented sendTiming() with a delay. When a delay
84     * is requested a new event is created. When the event time expires it
85     * attempts to send the packet. If it cannot, the packet is pushed onto the
86     * transmit list to be sent when recvRetry() is called. */
87    class SendEvent : public Event
88    {
89        SimpleTimingPort *port;
90        Packet *packet;
91
92        SendEvent(SimpleTimingPort *p, Packet *pkt, Tick t)
93            : Event(&mainEventQueue), port(p), packet(pkt)
94        { setFlags(AutoDelete); schedule(curTick + t); }
95
96        virtual void process();
97
98        virtual const char *description()
99        { return "Future scheduled sendTiming event"; }
100
101        friend class SimpleTimingPort;
102    };
103
104
105    /** Number of timing requests that are emulating the device timing before
106     * attempting to end up on the bus.
107     */
108    int outTiming;
109
110    /** If we need to drain, keep the drain event around until we're done
111     * here.*/
112    Event *drainEvent;
113
114    /** Schedule a sendTiming() event to be called in the future. */
115    void sendTiming(Packet *pkt, Tick time)
116    { outTiming++; new SimpleTimingPort::SendEvent(this, pkt, time); }
117
118    /** This function is notification that the device should attempt to send a
119     * packet again. */
120    virtual void recvRetry();
121
122    void resendNacked(Packet *pkt);
123  public:
124
125    SimpleTimingPort(std::string pname)
126        : Port(pname), outTiming(0), drainEvent(NULL)
127    {}
128
129    unsigned int drain(Event *de);
130
131    friend class SimpleTimingPort::SendEvent;
132};
133
134#endif // __MEM_TPORT_HH__
135