2 * Copyright (c) 2011-2013 ARM Limited
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.
14 * Copyright (c) 2006 The Regents of The University of Michigan
15 * Copyright (c) 2015 The University of Bologna
16 * All rights reserved.
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met: redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer;
22 * redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution;
25 * neither the name of the copyright holders nor the names of its
26 * contributors may be used to endorse or promote products derived from
27 * this software without specific prior written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 * Declaration of the SerialLink Class, modeling Hybrid-Memory-Cube's serial
48 #ifndef __MEM_SERIAL_LINK_HH__
49 #define __MEM_SERIAL_LINK_HH__
53 #include "base/types.hh"
54 #include "mem/port.hh"
55 #include "params/SerialLink.hh"
56 #include "sim/clocked_object.hh"
59 * SerialLink is a simple variation of the Bridge class, with the ability to
60 * account for the latency of packet serialization. We assume that the
61 * serializer component at the transmitter side does not need to receive the
62 * whole packet to start the serialization. But the deserializer waits for the
63 * complete packet to check its integrity first.
65 class SerialLink : public ClockedObject
70 * A deferred packet stores a packet along with its scheduled
81 DeferredPacket(PacketPtr _pkt, Tick _tick) : tick(_tick), pkt(_pkt)
85 // Forward declaration to allow the CPU-side port to have a pointer
86 class SerialLinkRequestPort;
89 * The port on the side that receives requests and sends
90 * responses. The CPU-side port has a set of address ranges that it
91 * is responsible for. The CPU-side port also has a buffer for the
92 * responses not yet sent.
94 class SerialLinkResponsePort : public ResponsePort
99 /** The serial_link to which this port belongs. */
100 SerialLink& serial_link;
103 * Request port on the other side of the serial_link.
105 SerialLinkRequestPort& mem_side_port;
107 /** Minimum request delay though this serial_link. */
110 /** Address ranges to pass through the serial_link */
111 const AddrRangeList ranges;
114 * Response packet queue. Response packets are held in this
115 * queue for a specified delay to model the processing delay
116 * of the serial_link. We use a deque as we need to iterate over
117 * the items for functional accesses.
119 std::deque<DeferredPacket> transmitList;
121 /** Counter to track the outstanding responses. */
122 unsigned int outstandingResponses;
124 /** If we should send a retry when space becomes available. */
127 /** Max queue size for reserved responses. */
128 unsigned int respQueueLimit;
131 * Is this side blocked from accepting new response packets.
133 * @return true if the reserved space has reached the set limit
135 bool respQueueFull() const;
138 * Handle send event, scheduled when the packet at the head of
139 * the response queue is ready to transmit (for timing
142 void trySendTiming();
144 /** Send event for the response queue. */
145 EventFunctionWrapper sendEvent;
150 * Constructor for the SerialLinkResponsePort.
152 * @param _name the port name including the owner
153 * @param _serial_link the structural owner
154 * @param _mem_side_port the memory-side port on the other side of the
156 * @param _delay the delay in cycles from receiving to sending
157 * @param _resp_limit the size of the response queue
158 * @param _ranges a number of address ranges to forward
160 SerialLinkResponsePort(const std::string& _name, SerialLink&
161 _serial_link, SerialLinkRequestPort& _mem_side_port,
162 Cycles _delay, int _resp_limit, const
163 std::vector<AddrRange>& _ranges);
166 * Queue a response packet to be sent out later and also schedule
167 * a send if necessary.
169 * @param pkt a response to send out after a delay
170 * @param when tick when response packet should be sent
172 void schedTimingResp(PacketPtr pkt, Tick when);
175 * Retry any stalled request that we have failed to accept at
176 * an earlier point in time. This call will do nothing if no
177 * request is waiting.
179 void retryStalledReq();
183 /** When receiving a timing request from the peer port,
184 pass it to the serial_link. */
185 bool recvTimingReq(PacketPtr pkt);
187 /** When receiving a retry request from the peer port,
188 pass it to the serial_link. */
189 void recvRespRetry();
191 /** When receiving a Atomic requestfrom the peer port,
192 pass it to the serial_link. */
193 Tick recvAtomic(PacketPtr pkt);
195 /** When receiving a Functional request from the peer port,
196 pass it to the serial_link. */
197 void recvFunctional(PacketPtr pkt);
199 /** When receiving a address range request the peer port,
200 pass it to the serial_link. */
201 AddrRangeList getAddrRanges() const;
206 * Port on the side that forwards requests and receives
207 * responses. The memory-side port has a buffer for the requests not
210 class SerialLinkRequestPort : public RequestPort
215 /** The serial_link to which this port belongs. */
216 SerialLink& serial_link;
219 * The response (CPU-side port) port on the other side of
222 SerialLinkResponsePort& cpu_side_port;
224 /** Minimum delay though this serial_link. */
228 * Request packet queue. Request packets are held in this
229 * queue for a specified delay to model the processing delay
230 * of the serial_link. We use a deque as we need to iterate over
231 * the items for functional accesses.
233 std::deque<DeferredPacket> transmitList;
235 /** Max queue size for request packets */
236 const unsigned int reqQueueLimit;
239 * Handle send event, scheduled when the packet at the head of
240 * the outbound queue is ready to transmit (for timing
243 void trySendTiming();
245 /** Send event for the request queue. */
246 EventFunctionWrapper sendEvent;
251 * Constructor for the SerialLinkRequestPort.
253 * @param _name the port name including the owner
254 * @param _serial_link the structural owner
255 * @param _cpu_side_port the CPU-side port on the other
256 * side of the serial_link
257 * @param _delay the delay in cycles from receiving to sending
258 * @param _req_limit the size of the request queue
260 SerialLinkRequestPort(const std::string& _name, SerialLink&
261 _serial_link, SerialLinkResponsePort& _cpu_side_port,
262 Cycles _delay, int _req_limit);
265 * Is this side blocked from accepting new request packets.
267 * @return true if the occupied space has reached the set limit
269 bool reqQueueFull() const;
272 * Queue a request packet to be sent out later and also schedule
273 * a send if necessary.
275 * @param pkt a request to send out after a delay
276 * @param when tick when response packet should be sent
278 void schedTimingReq(PacketPtr pkt, Tick when);
281 * Check a functional request against the packets in our
284 * @param pkt packet to check against
286 * @return true if we find a match
288 bool trySatisfyFunctional(PacketPtr pkt);
292 /** When receiving a timing request from the peer port,
293 pass it to the serial_link. */
294 bool recvTimingResp(PacketPtr pkt);
296 /** When receiving a retry request from the peer port,
297 pass it to the serial_link. */
301 /** Response port of the serial_link. */
302 SerialLinkResponsePort cpu_side_port;
304 /** Request port of the serial_link. */
305 SerialLinkRequestPort mem_side_port;
307 /** Number of parallel lanes in this serial link */
310 /** Speed of each link (Gb/s) in this serial link */
315 Port &getPort(const std::string &if_name,
316 PortID idx=InvalidPortID);
320 typedef SerialLinkParams Params;
322 SerialLink(const SerialLinkParams &p);
325 #endif //__MEM_SERIAL_LINK_HH__