tport.hh (8711:c7e14f52c682) tport.hh (8856:241ee47b0dc6)
1/*
1/*
2 * Copyright (c) 2012 ARM Limited
3 * All rights reserved.
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
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
14 * Copyright (c) 2006 The Regents of The University of Michigan
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *
40 * Authors: Ali Saidi
41 * Andreas Hansson
29 */
30
31#ifndef __MEM_TPORT_HH__
32#define __MEM_TPORT_HH__
33
34/**
35 * @file
36 *
37 * Declaration of SimpleTimingPort.
38 */
39
40#include <list>
41#include <string>
42
43#include "mem/port.hh"
44#include "sim/eventq.hh"
45
46/**
47 * A simple port for interfacing objects that basically have only
48 * functional memory behavior (e.g. I/O devices) to the memory system.
49 * Both timing and functional accesses are implemented in terms of
50 * atomic accesses. A derived port class thus only needs to provide
51 * recvAtomic() to support all memory access modes.
52 *
53 * The tricky part is handling recvTiming(), where the response must
54 * be scheduled separately via a later call to sendTiming(). This
55 * feature is handled by scheduling an internal event that calls
56 * sendTiming() after a delay, and optionally rescheduling the
57 * response if it is nacked.
58 */
59class SimpleTimingPort : public Port
60{
61 protected:
62 /** A deferred packet, buffered to transmit later. */
63 class DeferredPacket {
64 public:
65 Tick tick; ///< The tick when the packet is ready to transmit
66 PacketPtr pkt; ///< Pointer to the packet to transmit
67 DeferredPacket(Tick t, PacketPtr p)
68 : tick(t), pkt(p)
69 {}
70 };
71
72 typedef std::list<DeferredPacket> DeferredPacketList;
73 typedef std::list<DeferredPacket>::iterator DeferredPacketIterator;
74
75 /** A list of outgoing timing response packets that haven't been
76 * serviced yet. */
77 DeferredPacketList transmitList;
78
42 */
43
44#ifndef __MEM_TPORT_HH__
45#define __MEM_TPORT_HH__
46
47/**
48 * @file
49 *
50 * Declaration of SimpleTimingPort.
51 */
52
53#include <list>
54#include <string>
55
56#include "mem/port.hh"
57#include "sim/eventq.hh"
58
59/**
60 * A simple port for interfacing objects that basically have only
61 * functional memory behavior (e.g. I/O devices) to the memory system.
62 * Both timing and functional accesses are implemented in terms of
63 * atomic accesses. A derived port class thus only needs to provide
64 * recvAtomic() to support all memory access modes.
65 *
66 * The tricky part is handling recvTiming(), where the response must
67 * be scheduled separately via a later call to sendTiming(). This
68 * feature is handled by scheduling an internal event that calls
69 * sendTiming() after a delay, and optionally rescheduling the
70 * response if it is nacked.
71 */
72class SimpleTimingPort : public Port
73{
74 protected:
75 /** A deferred packet, buffered to transmit later. */
76 class DeferredPacket {
77 public:
78 Tick tick; ///< The tick when the packet is ready to transmit
79 PacketPtr pkt; ///< Pointer to the packet to transmit
80 DeferredPacket(Tick t, PacketPtr p)
81 : tick(t), pkt(p)
82 {}
83 };
84
85 typedef std::list<DeferredPacket> DeferredPacketList;
86 typedef std::list<DeferredPacket>::iterator DeferredPacketIterator;
87
88 /** A list of outgoing timing response packets that haven't been
89 * serviced yet. */
90 DeferredPacketList transmitList;
91
92 /** Label to use for print request packets label stack. */
93 const std::string label;
94
79 /** This function attempts to send deferred packets. Scheduled to
80 * be called in the future via SendEvent. */
81 void processSendEvent();
82
83 /**
84 * This class is used to implemented sendTiming() with a delay. When
85 * a delay is requested a the event is scheduled if it isn't already.
86 * When the event time expires it attempts to send the packet.
87 * If it cannot, the packet sent when recvRetry() is called.
88 **/
95 /** This function attempts to send deferred packets. Scheduled to
96 * be called in the future via SendEvent. */
97 void processSendEvent();
98
99 /**
100 * This class is used to implemented sendTiming() with a delay. When
101 * a delay is requested a the event is scheduled if it isn't already.
102 * When the event time expires it attempts to send the packet.
103 * If it cannot, the packet sent when recvRetry() is called.
104 **/
89 Event *sendEvent;
105 EventWrapper<SimpleTimingPort,
106 &SimpleTimingPort::processSendEvent> sendEvent;
90
91 /** If we need to drain, keep the drain event around until we're done
92 * here.*/
93 Event *drainEvent;
94
95 /** Remember whether we're awaiting a retry from the bus. */
96 bool waitingOnRetry;
97
107
108 /** If we need to drain, keep the drain event around until we're done
109 * here.*/
110 Event *drainEvent;
111
112 /** Remember whether we're awaiting a retry from the bus. */
113 bool waitingOnRetry;
114
98 /** Check the list of buffered packets against the supplied
99 * functional request. */
100 bool checkFunctional(PacketPtr funcPkt);
101
102 /** Check whether we have a packet ready to go on the transmit list. */
103 bool deferredPacketReady()
104 { return !transmitList.empty() && transmitList.front().tick <= curTick(); }
105
106 Tick deferredPacketReadyTime()
107 { return transmitList.empty() ? MaxTick : transmitList.front().tick; }
108
109 /**
110 * Schedule a send even if not already waiting for a retry. If the
111 * requested time is before an already scheduled send event it
112 * will be rescheduled.
113 *
114 * @param when
115 */
116 void schedSendEvent(Tick when);
117
118 /** Schedule a sendTiming() event to be called in the future.
119 * @param pkt packet to send
120 * @param absolute time (in ticks) to send packet
121 */
122 void schedSendTiming(PacketPtr pkt, Tick when);
123
124 /** Attempt to send the packet at the head of the deferred packet
125 * list. Caller must guarantee that the deferred packet list is
126 * non-empty and that the head packet is scheduled for curTick() (or
127 * earlier).
128 */
115 /** Check whether we have a packet ready to go on the transmit list. */
116 bool deferredPacketReady()
117 { return !transmitList.empty() && transmitList.front().tick <= curTick(); }
118
119 Tick deferredPacketReadyTime()
120 { return transmitList.empty() ? MaxTick : transmitList.front().tick; }
121
122 /**
123 * Schedule a send even if not already waiting for a retry. If the
124 * requested time is before an already scheduled send event it
125 * will be rescheduled.
126 *
127 * @param when
128 */
129 void schedSendEvent(Tick when);
130
131 /** Schedule a sendTiming() event to be called in the future.
132 * @param pkt packet to send
133 * @param absolute time (in ticks) to send packet
134 */
135 void schedSendTiming(PacketPtr pkt, Tick when);
136
137 /** Attempt to send the packet at the head of the deferred packet
138 * list. Caller must guarantee that the deferred packet list is
139 * non-empty and that the head packet is scheduled for curTick() (or
140 * earlier).
141 */
129 void sendDeferredPacket();
142 virtual void sendDeferredPacket();
130
143
144 /**
145 * Attempt to send the packet at the front of the transmit list,
146 * and set waitingOnRetry accordingly. The packet is temporarily
147 * taken off the list, but put back at the front if not
148 * successfully sent.
149 */
150 void trySendTiming();
151
152 /**
153 * Based on the transmit list, or the provided time, schedule a
154 * send event if there are packets to send. If we are idle and
155 * asked to drain then do so.
156 *
157 * @param time an alternative time for the next send event
158 */
159 void scheduleSend(Tick time = MaxTick);
160
131 /** This function is notification that the device should attempt to send a
132 * packet again. */
133 virtual void recvRetry();
134
135 /** Implemented using recvAtomic(). */
136 void recvFunctional(PacketPtr pkt);
137
138 /** Implemented using recvAtomic(). */
139 bool recvTiming(PacketPtr pkt);
140
141 /**
142 * Simple ports are generally used as slave ports (i.e. the
143 * respond to requests) and thus do not expect to receive any
144 * range changes (as the neighbouring port has a master role and
145 * do not have any address ranges. A subclass can override the
146 * default behaviuor if needed.
147 */
148 virtual void recvRangeChange() { }
149
150
151 public:
161 /** This function is notification that the device should attempt to send a
162 * packet again. */
163 virtual void recvRetry();
164
165 /** Implemented using recvAtomic(). */
166 void recvFunctional(PacketPtr pkt);
167
168 /** Implemented using recvAtomic(). */
169 bool recvTiming(PacketPtr pkt);
170
171 /**
172 * Simple ports are generally used as slave ports (i.e. the
173 * respond to requests) and thus do not expect to receive any
174 * range changes (as the neighbouring port has a master role and
175 * do not have any address ranges. A subclass can override the
176 * default behaviuor if needed.
177 */
178 virtual void recvRangeChange() { }
179
180
181 public:
152 SimpleTimingPort(std::string pname, MemObject *_owner);
182 SimpleTimingPort(const std::string &_name, MemObject *_owner,
183 const std::string _label = "SimpleTimingPort");
153 ~SimpleTimingPort();
154
184 ~SimpleTimingPort();
185
186 /** Check the list of buffered packets against the supplied
187 * functional request. */
188 bool checkFunctional(PacketPtr pkt);
189
155 /** Hook for draining timing accesses from the system. The
156 * associated SimObject's drain() functions should be implemented
157 * something like this when this class is used:
158 \code
159 PioDevice::drain(Event *de)
160 {
161 unsigned int count;
162 count = SimpleTimingPort->drain(de);
163 if (count)
164 changeState(Draining);
165 else
166 changeState(Drained);
167 return count;
168 }
169 \endcode
170 */
171 unsigned int drain(Event *de);
172};
173
174#endif // __MEM_TPORT_HH__
190 /** Hook for draining timing accesses from the system. The
191 * associated SimObject's drain() functions should be implemented
192 * something like this when this class is used:
193 \code
194 PioDevice::drain(Event *de)
195 {
196 unsigned int count;
197 count = SimpleTimingPort->drain(de);
198 if (count)
199 changeState(Draining);
200 else
201 changeState(Drained);
202 return count;
203 }
204 \endcode
205 */
206 unsigned int drain(Event *de);
207};
208
209#endif // __MEM_TPORT_HH__