2 * Copyright (c) 2011-2015 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) 2002-2005 The Regents of The University of Michigan
15 * All rights reserved.
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.
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.
40 * Authors: Ron Dreslinski
48 * Declaration of a coherent crossbar.
51 #ifndef __MEM_COHERENT_XBAR_HH__
52 #define __MEM_COHERENT_XBAR_HH__
54 #include <unordered_set>
56 #include "mem/snoop_filter.hh"
57 #include "mem/xbar.hh"
58 #include "params/CoherentXBar.hh"
61 * A coherent crossbar connects a number of (potentially) snooping
62 * masters and slaves, and routes the request and response packets
63 * based on the address, and also forwards all requests to the
64 * snoopers and deals with the snoop responses.
66 * The coherent crossbar can be used as a template for modelling QPI,
67 * HyperTransport, ACE and coherent OCP buses, and is typically used
68 * for the L1-to-L2 buses and as the main system interconnect. @sa
69 * \ref gem5MemorySystem "gem5 Memory System"
71 class CoherentXBar : public BaseXBar
77 * Declare the layers of this crossbar, one vector for requests,
78 * one for responses, and one for snoop responses
80 std::vector<ReqLayer*> reqLayers;
81 std::vector<RespLayer*> respLayers;
82 std::vector<SnoopRespLayer*> snoopLayers;
85 * Declaration of the coherent crossbar slave port type, one will
86 * be instantiated for each of the master ports connecting to the
89 class CoherentXBarSlavePort : public QueuedSlavePort
94 /** A reference to the crossbar to which this port belongs. */
97 /** A normal packet queue used to store responses. */
98 RespPacketQueue queue;
102 CoherentXBarSlavePort(const std::string &_name,
103 CoherentXBar &_xbar, PortID _id)
104 : QueuedSlavePort(_name, &_xbar, queue, _id), xbar(_xbar),
111 * When receiving a timing request, pass it to the crossbar.
113 virtual bool recvTimingReq(PacketPtr pkt)
114 { return xbar.recvTimingReq(pkt, id); }
117 * When receiving a timing snoop response, pass it to the crossbar.
119 virtual bool recvTimingSnoopResp(PacketPtr pkt)
120 { return xbar.recvTimingSnoopResp(pkt, id); }
123 * When receiving an atomic request, pass it to the crossbar.
125 virtual Tick recvAtomic(PacketPtr pkt)
126 { return xbar.recvAtomic(pkt, id); }
129 * When receiving a functional request, pass it to the crossbar.
131 virtual void recvFunctional(PacketPtr pkt)
132 { xbar.recvFunctional(pkt, id); }
135 * Return the union of all adress ranges seen by this crossbar.
137 virtual AddrRangeList getAddrRanges() const
138 { return xbar.getAddrRanges(); }
143 * Declaration of the coherent crossbar master port type, one will be
144 * instantiated for each of the slave interfaces connecting to the
147 class CoherentXBarMasterPort : public MasterPort
150 /** A reference to the crossbar to which this port belongs. */
155 CoherentXBarMasterPort(const std::string &_name,
156 CoherentXBar &_xbar, PortID _id)
157 : MasterPort(_name, &_xbar, _id), xbar(_xbar)
163 * Determine if this port should be considered a snooper. For
164 * a coherent crossbar master port this is always true.
166 * @return a boolean that is true if this port is snooping
168 virtual bool isSnooping() const
172 * When receiving a timing response, pass it to the crossbar.
174 virtual bool recvTimingResp(PacketPtr pkt)
175 { return xbar.recvTimingResp(pkt, id); }
178 * When receiving a timing snoop request, pass it to the crossbar.
180 virtual void recvTimingSnoopReq(PacketPtr pkt)
181 { return xbar.recvTimingSnoopReq(pkt, id); }
184 * When receiving an atomic snoop request, pass it to the crossbar.
186 virtual Tick recvAtomicSnoop(PacketPtr pkt)
187 { return xbar.recvAtomicSnoop(pkt, id); }
190 * When receiving a functional snoop request, pass it to the crossbar.
192 virtual void recvFunctionalSnoop(PacketPtr pkt)
193 { xbar.recvFunctionalSnoop(pkt, id); }
195 /** When reciving a range change from the peer port (at id),
196 pass it to the crossbar. */
197 virtual void recvRangeChange()
198 { xbar.recvRangeChange(id); }
200 /** When reciving a retry from the peer port (at id),
201 pass it to the crossbar. */
202 virtual void recvReqRetry()
203 { xbar.recvReqRetry(id); }
208 * Internal class to bridge between an incoming snoop response
209 * from a slave port and forwarding it through an outgoing slave
210 * port. It is effectively a dangling master port.
212 class SnoopRespPort : public MasterPort
217 /** The port which we mirror internally. */
218 QueuedSlavePort& slavePort;
223 * Create a snoop response port that mirrors a given slave port.
225 SnoopRespPort(QueuedSlavePort& slave_port, CoherentXBar& _xbar) :
226 MasterPort(slave_port.name() + ".snoopRespPort", &_xbar),
227 slavePort(slave_port) { }
230 * Override the sending of retries and pass them on through
231 * the mirrored slave port.
233 void sendRetryResp() {
234 // forward it as a snoop response retry
235 slavePort.sendRetrySnoopResp();
239 * Provided as necessary.
241 void recvReqRetry() { panic("SnoopRespPort should never see retry\n"); }
244 * Provided as necessary.
246 bool recvTimingResp(PacketPtr pkt)
248 panic("SnoopRespPort should never see timing response\n");
254 std::vector<SnoopRespPort*> snoopRespPorts;
256 std::vector<QueuedSlavePort*> snoopPorts;
259 * Store the outstanding requests that we are expecting snoop
260 * responses from so we can determine which snoop responses we
261 * generated and which ones were merely forwarded.
263 std::unordered_set<RequestPtr> outstandingSnoop;
266 * Keep a pointer to the system to be allow to querying memory system
271 /** A snoop filter that tracks cache line residency and can restrict the
272 * broadcast needed for probes. NULL denotes an absent filter. */
273 SnoopFilter *snoopFilter;
275 /** Cycles of snoop response latency.*/
276 const Cycles snoopResponseLatency;
278 /** Is this crossbar the point of coherency? **/
279 const bool pointOfCoherency;
282 * Upstream caches need this packet until true is returned, so
283 * hold it for deletion until a subsequent call
285 std::unique_ptr<Packet> pendingDelete;
287 /** Function called by the port when the crossbar is recieving a Timing
289 bool recvTimingReq(PacketPtr pkt, PortID slave_port_id);
291 /** Function called by the port when the crossbar is recieving a Timing
293 bool recvTimingResp(PacketPtr pkt, PortID master_port_id);
295 /** Function called by the port when the crossbar is recieving a timing
297 void recvTimingSnoopReq(PacketPtr pkt, PortID master_port_id);
299 /** Function called by the port when the crossbar is recieving a timing
301 bool recvTimingSnoopResp(PacketPtr pkt, PortID slave_port_id);
303 /** Timing function called by port when it is once again able to process
305 void recvReqRetry(PortID master_port_id);
308 * Forward a timing packet to our snoopers, potentially excluding
309 * one of the connected coherent masters to avoid sending a packet
310 * back to where it came from.
312 * @param pkt Packet to forward
313 * @param exclude_slave_port_id Id of slave port to exclude
315 void forwardTiming(PacketPtr pkt, PortID exclude_slave_port_id) {
316 forwardTiming(pkt, exclude_slave_port_id, snoopPorts);
320 * Forward a timing packet to a selected list of snoopers, potentially
321 * excluding one of the connected coherent masters to avoid sending a packet
322 * back to where it came from.
324 * @param pkt Packet to forward
325 * @param exclude_slave_port_id Id of slave port to exclude
326 * @param dests Vector of destination ports for the forwarded pkt
328 void forwardTiming(PacketPtr pkt, PortID exclude_slave_port_id,
329 const std::vector<QueuedSlavePort*>& dests);
331 /** Function called by the port when the crossbar is recieving a Atomic
333 Tick recvAtomic(PacketPtr pkt, PortID slave_port_id);
335 /** Function called by the port when the crossbar is recieving an
336 atomic snoop transaction.*/
337 Tick recvAtomicSnoop(PacketPtr pkt, PortID master_port_id);
340 * Forward an atomic packet to our snoopers, potentially excluding
341 * one of the connected coherent masters to avoid sending a packet
342 * back to where it came from.
344 * @param pkt Packet to forward
345 * @param exclude_slave_port_id Id of slave port to exclude
347 * @return a pair containing the snoop response and snoop latency
349 std::pair<MemCmd, Tick> forwardAtomic(PacketPtr pkt,
350 PortID exclude_slave_port_id)
352 return forwardAtomic(pkt, exclude_slave_port_id, InvalidPortID,
357 * Forward an atomic packet to a selected list of snoopers, potentially
358 * excluding one of the connected coherent masters to avoid sending a packet
359 * back to where it came from.
361 * @param pkt Packet to forward
362 * @param exclude_slave_port_id Id of slave port to exclude
363 * @param source_master_port_id Id of the master port for snoops from below
364 * @param dests Vector of destination ports for the forwarded pkt
366 * @return a pair containing the snoop response and snoop latency
368 std::pair<MemCmd, Tick> forwardAtomic(PacketPtr pkt,
369 PortID exclude_slave_port_id,
370 PortID source_master_port_id,
371 const std::vector<QueuedSlavePort*>&
374 /** Function called by the port when the crossbar is recieving a Functional
376 void recvFunctional(PacketPtr pkt, PortID slave_port_id);
378 /** Function called by the port when the crossbar is recieving a functional
380 void recvFunctionalSnoop(PacketPtr pkt, PortID master_port_id);
383 * Forward a functional packet to our snoopers, potentially
384 * excluding one of the connected coherent masters to avoid
385 * sending a packet back to where it came from.
387 * @param pkt Packet to forward
388 * @param exclude_slave_port_id Id of slave port to exclude
390 void forwardFunctional(PacketPtr pkt, PortID exclude_slave_port_id);
393 * Determine if the crossbar should sink the packet, as opposed to
394 * forwarding it, or responding.
396 bool sinkPacket(const PacketPtr pkt) const;
398 Stats::Scalar snoops;
399 Stats::Scalar snoopTraffic;
400 Stats::Distribution snoopFanout;
406 CoherentXBar(const CoherentXBarParams *p);
408 virtual ~CoherentXBar();
410 virtual void regStats();
413 #endif //__MEM_COHERENT_XBAR_HH__