2 * Copyright (c) 2011-2014 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 "base/hashmap.hh"
55 #include "mem/snoop_filter.hh"
56 #include "mem/xbar.hh"
57 #include "params/CoherentXBar.hh"
60 * A coherent crossbar connects a number of (potentially) snooping
61 * masters and slaves, and routes the request and response packets
62 * based on the address, and also forwards all requests to the
63 * snoopers and deals with the snoop responses.
65 * The coherent crossbar can be used as a template for modelling QPI,
66 * HyperTransport, ACE and coherent OCP buses, and is typically used
67 * for the L1-to-L2 buses and as the main system interconnect. @sa
68 * \ref gem5MemorySystem "gem5 Memory System"
70 class CoherentXBar : public BaseXBar
76 * Declare the layers of this crossbar, one vector for requests,
77 * one for responses, and one for snoop responses
79 typedef Layer<SlavePort,MasterPort> ReqLayer;
80 typedef Layer<MasterPort,SlavePort> RespLayer;
81 typedef Layer<SlavePort,MasterPort> SnoopLayer;
82 std::vector<ReqLayer*> reqLayers;
83 std::vector<RespLayer*> respLayers;
84 std::vector<SnoopLayer*> snoopLayers;
87 * Declaration of the coherent crossbar slave port type, one will
88 * be instantiated for each of the master ports connecting to the
91 class CoherentXBarSlavePort : public SlavePort
96 /** A reference to the crossbar to which this port belongs. */
101 CoherentXBarSlavePort(const std::string &_name,
102 CoherentXBar &_xbar, PortID _id)
103 : SlavePort(_name, &_xbar, _id), xbar(_xbar)
109 * When receiving a timing request, pass it to the crossbar.
111 virtual bool recvTimingReq(PacketPtr pkt)
112 { return xbar.recvTimingReq(pkt, id); }
115 * When receiving a timing snoop response, pass it to the crossbar.
117 virtual bool recvTimingSnoopResp(PacketPtr pkt)
118 { return xbar.recvTimingSnoopResp(pkt, id); }
121 * When receiving an atomic request, pass it to the crossbar.
123 virtual Tick recvAtomic(PacketPtr pkt)
124 { return xbar.recvAtomic(pkt, id); }
127 * When receiving a functional request, pass it to the crossbar.
129 virtual void recvFunctional(PacketPtr pkt)
130 { xbar.recvFunctional(pkt, id); }
133 * When receiving a retry, pass it to the crossbar.
135 virtual void recvRetry()
136 { panic("Crossbar slave ports should never retry.\n"); }
139 * Return the union of all adress ranges seen by this crossbar.
141 virtual AddrRangeList getAddrRanges() const
142 { return xbar.getAddrRanges(); }
147 * Declaration of the coherent crossbar master port type, one will be
148 * instantiated for each of the slave interfaces connecting to the
151 class CoherentXBarMasterPort : public MasterPort
154 /** A reference to the crossbar to which this port belongs. */
159 CoherentXBarMasterPort(const std::string &_name,
160 CoherentXBar &_xbar, PortID _id)
161 : MasterPort(_name, &_xbar, _id), xbar(_xbar)
167 * Determine if this port should be considered a snooper. For
168 * a coherent crossbar master port this is always true.
170 * @return a boolean that is true if this port is snooping
172 virtual bool isSnooping() const
176 * When receiving a timing response, pass it to the crossbar.
178 virtual bool recvTimingResp(PacketPtr pkt)
179 { return xbar.recvTimingResp(pkt, id); }
182 * When receiving a timing snoop request, pass it to the crossbar.
184 virtual void recvTimingSnoopReq(PacketPtr pkt)
185 { return xbar.recvTimingSnoopReq(pkt, id); }
188 * When receiving an atomic snoop request, pass it to the crossbar.
190 virtual Tick recvAtomicSnoop(PacketPtr pkt)
191 { return xbar.recvAtomicSnoop(pkt, id); }
194 * When receiving a functional snoop request, pass it to the crossbar.
196 virtual void recvFunctionalSnoop(PacketPtr pkt)
197 { xbar.recvFunctionalSnoop(pkt, id); }
199 /** When reciving a range change from the peer port (at id),
200 pass it to the crossbar. */
201 virtual void recvRangeChange()
202 { xbar.recvRangeChange(id); }
204 /** When reciving a retry from the peer port (at id),
205 pass it to the crossbar. */
206 virtual void recvRetry()
207 { xbar.recvRetry(id); }
212 * Internal class to bridge between an incoming snoop response
213 * from a slave port and forwarding it through an outgoing slave
214 * port. It is effectively a dangling master port.
216 class SnoopRespPort : public MasterPort
221 /** The port which we mirror internally. */
222 SlavePort& slavePort;
227 * Create a snoop response port that mirrors a given slave port.
229 SnoopRespPort(SlavePort& slave_port, CoherentXBar& _xbar) :
230 MasterPort(slave_port.name() + ".snoopRespPort", &_xbar),
231 slavePort(slave_port) { }
234 * Override the sending of retries and pass them on through
235 * the mirrored slave port.
238 slavePort.sendRetry();
242 * Provided as necessary.
244 void recvRetry() { panic("SnoopRespPort should never see retry\n"); }
247 * Provided as necessary.
249 bool recvTimingResp(PacketPtr pkt)
251 panic("SnoopRespPort should never see timing response\n");
257 std::vector<SnoopRespPort*> snoopRespPorts;
259 std::vector<SlavePort*> snoopPorts;
262 * Store the outstanding requests so we can determine which ones
263 * we generated and which ones were merely forwarded. This is used
264 * in the coherent crossbar when coherency responses come back.
266 m5::hash_set<RequestPtr> outstandingReq;
269 * Keep a pointer to the system to be allow to querying memory system
274 /** A snoop filter that tracks cache line residency and can restrict the
275 * broadcast needed for probes. NULL denotes an absent filter. */
276 SnoopFilter *snoopFilter;
278 /** Function called by the port when the crossbar is recieving a Timing
280 bool recvTimingReq(PacketPtr pkt, PortID slave_port_id);
282 /** Function called by the port when the crossbar is recieving a Timing
284 bool recvTimingResp(PacketPtr pkt, PortID master_port_id);
286 /** Function called by the port when the crossbar is recieving a timing
288 void recvTimingSnoopReq(PacketPtr pkt, PortID master_port_id);
290 /** Function called by the port when the crossbar is recieving a timing
292 bool recvTimingSnoopResp(PacketPtr pkt, PortID slave_port_id);
294 /** Timing function called by port when it is once again able to process
296 void recvRetry(PortID master_port_id);
299 * Forward a timing packet to our snoopers, potentially excluding
300 * one of the connected coherent masters to avoid sending a packet
301 * back to where it came from.
303 * @param pkt Packet to forward
304 * @param exclude_slave_port_id Id of slave port to exclude
306 void forwardTiming(PacketPtr pkt, PortID exclude_slave_port_id) {
307 forwardTiming(pkt, exclude_slave_port_id, snoopPorts);
311 * Forward a timing packet to a selected list of snoopers, potentially
312 * excluding one of the connected coherent masters to avoid sending a packet
313 * back to where it came from.
315 * @param pkt Packet to forward
316 * @param exclude_slave_port_id Id of slave port to exclude
317 * @param dests Vector of destination ports for the forwarded pkt
319 void forwardTiming(PacketPtr pkt, PortID exclude_slave_port_id,
320 const std::vector<SlavePort*>& dests);
322 /** Function called by the port when the crossbar is recieving a Atomic
324 Tick recvAtomic(PacketPtr pkt, PortID slave_port_id);
326 /** Function called by the port when the crossbar is recieving an
327 atomic snoop transaction.*/
328 Tick recvAtomicSnoop(PacketPtr pkt, PortID master_port_id);
331 * Forward an atomic packet to our snoopers, potentially excluding
332 * one of the connected coherent masters to avoid sending a packet
333 * back to where it came from.
335 * @param pkt Packet to forward
336 * @param exclude_slave_port_id Id of slave port to exclude
338 * @return a pair containing the snoop response and snoop latency
340 std::pair<MemCmd, Tick> forwardAtomic(PacketPtr pkt,
341 PortID exclude_slave_port_id)
343 return forwardAtomic(pkt, exclude_slave_port_id, InvalidPortID, snoopPorts);
347 * Forward an atomic packet to a selected list of snoopers, potentially
348 * excluding one of the connected coherent masters to avoid sending a packet
349 * back to where it came from.
351 * @param pkt Packet to forward
352 * @param exclude_slave_port_id Id of slave port to exclude
353 * @param source_master_port_id Id of the master port for snoops from below
354 * @param dests Vector of destination ports for the forwarded pkt
356 * @return a pair containing the snoop response and snoop latency
358 std::pair<MemCmd, Tick> forwardAtomic(PacketPtr pkt,
359 PortID exclude_slave_port_id,
360 PortID source_master_port_id,
361 const std::vector<SlavePort*>& dests);
363 /** Function called by the port when the crossbar is recieving a Functional
365 void recvFunctional(PacketPtr pkt, PortID slave_port_id);
367 /** Function called by the port when the crossbar is recieving a functional
369 void recvFunctionalSnoop(PacketPtr pkt, PortID master_port_id);
372 * Forward a functional packet to our snoopers, potentially
373 * excluding one of the connected coherent masters to avoid
374 * sending a packet back to where it came from.
376 * @param pkt Packet to forward
377 * @param exclude_slave_port_id Id of slave port to exclude
379 void forwardFunctional(PacketPtr pkt, PortID exclude_slave_port_id);
381 Stats::Scalar snoops;
382 Stats::Distribution snoopFanout;
388 CoherentXBar(const CoherentXBarParams *p);
390 virtual ~CoherentXBar();
392 unsigned int drain(DrainManager *dm);
394 virtual void regStats();
397 #endif //__MEM_COHERENT_XBAR_HH__