coherent_xbar.hh revision 11168
12381SN/A/* 210719SMarco.Balboni@ARM.com * Copyright (c) 2011-2015 ARM Limited 38711SN/A * All rights reserved 48711SN/A * 58711SN/A * The license below extends only to copyright in the software and shall 68711SN/A * not be construed as granting a license to any other intellectual 78711SN/A * property including but not limited to intellectual property relating 88711SN/A * to a hardware implementation of the functionality of the software 98711SN/A * licensed hereunder. You may use the software subject to the license 108711SN/A * terms below provided that you ensure that this notice is replicated 118711SN/A * unmodified and in its entirety in all distributions of the software, 128711SN/A * modified or unmodified, in source code or in binary form. 138711SN/A * 142381SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan 152381SN/A * All rights reserved. 162381SN/A * 172381SN/A * Redistribution and use in source and binary forms, with or without 182381SN/A * modification, are permitted provided that the following conditions are 192381SN/A * met: redistributions of source code must retain the above copyright 202381SN/A * notice, this list of conditions and the following disclaimer; 212381SN/A * redistributions in binary form must reproduce the above copyright 222381SN/A * notice, this list of conditions and the following disclaimer in the 232381SN/A * documentation and/or other materials provided with the distribution; 242381SN/A * neither the name of the copyright holders nor the names of its 252381SN/A * contributors may be used to endorse or promote products derived from 262381SN/A * this software without specific prior written permission. 272381SN/A * 282381SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 292381SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 302381SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 312381SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 322381SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 332381SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 342381SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 352381SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 362381SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 372381SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 382381SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 392665SN/A * 402665SN/A * Authors: Ron Dreslinski 412772SN/A * Ali Saidi 428715SN/A * Andreas Hansson 438922SN/A * William Wang 442381SN/A */ 452381SN/A 462381SN/A/** 472982SN/A * @file 4810405Sandreas.hansson@arm.com * Declaration of a coherent crossbar. 492381SN/A */ 502381SN/A 5110405Sandreas.hansson@arm.com#ifndef __MEM_COHERENT_XBAR_HH__ 5210405Sandreas.hansson@arm.com#define __MEM_COHERENT_XBAR_HH__ 532381SN/A 5410402SN/A#include "mem/snoop_filter.hh" 5510405Sandreas.hansson@arm.com#include "mem/xbar.hh" 5610405Sandreas.hansson@arm.com#include "params/CoherentXBar.hh" 572381SN/A 589036SN/A/** 5910405Sandreas.hansson@arm.com * A coherent crossbar connects a number of (potentially) snooping 6010405Sandreas.hansson@arm.com * masters and slaves, and routes the request and response packets 6110405Sandreas.hansson@arm.com * based on the address, and also forwards all requests to the 6210405Sandreas.hansson@arm.com * snoopers and deals with the snoop responses. 639036SN/A * 6410405Sandreas.hansson@arm.com * The coherent crossbar can be used as a template for modelling QPI, 6510405Sandreas.hansson@arm.com * HyperTransport, ACE and coherent OCP buses, and is typically used 6610405Sandreas.hansson@arm.com * for the L1-to-L2 buses and as the main system interconnect. @sa 6710405Sandreas.hansson@arm.com * \ref gem5MemorySystem "gem5 Memory System" 689036SN/A */ 6910405Sandreas.hansson@arm.comclass CoherentXBar : public BaseXBar 702381SN/A{ 719031SN/A 729036SN/A protected: 739036SN/A 748922SN/A /** 7510405Sandreas.hansson@arm.com * Declare the layers of this crossbar, one vector for requests, 7610405Sandreas.hansson@arm.com * one for responses, and one for snoop responses 779092SN/A */ 789715SN/A std::vector<ReqLayer*> reqLayers; 799715SN/A std::vector<RespLayer*> respLayers; 8010713Sandreas.hansson@arm.com std::vector<SnoopRespLayer*> snoopLayers; 819092SN/A 829092SN/A /** 8310405Sandreas.hansson@arm.com * Declaration of the coherent crossbar slave port type, one will 8410405Sandreas.hansson@arm.com * be instantiated for each of the master ports connecting to the 8510405Sandreas.hansson@arm.com * crossbar. 868922SN/A */ 8710888Sandreas.hansson@arm.com class CoherentXBarSlavePort : public QueuedSlavePort 882381SN/A { 899036SN/A 908922SN/A private: 919036SN/A 9210405Sandreas.hansson@arm.com /** A reference to the crossbar to which this port belongs. */ 9310405Sandreas.hansson@arm.com CoherentXBar &xbar; 942381SN/A 9510888Sandreas.hansson@arm.com /** A normal packet queue used to store responses. */ 9610888Sandreas.hansson@arm.com RespPacketQueue queue; 9710888Sandreas.hansson@arm.com 982381SN/A public: 992381SN/A 10010405Sandreas.hansson@arm.com CoherentXBarSlavePort(const std::string &_name, 10110405Sandreas.hansson@arm.com CoherentXBar &_xbar, PortID _id) 10210888Sandreas.hansson@arm.com : QueuedSlavePort(_name, &_xbar, queue, _id), xbar(_xbar), 10310888Sandreas.hansson@arm.com queue(_xbar, *this) 1048922SN/A { } 1058922SN/A 1068922SN/A protected: 1078922SN/A 1088948SN/A /** 10910405Sandreas.hansson@arm.com * When receiving a timing request, pass it to the crossbar. 1108948SN/A */ 1118975SN/A virtual bool recvTimingReq(PacketPtr pkt) 11210405Sandreas.hansson@arm.com { return xbar.recvTimingReq(pkt, id); } 1138922SN/A 1148948SN/A /** 11510405Sandreas.hansson@arm.com * When receiving a timing snoop response, pass it to the crossbar. 1168948SN/A */ 1178975SN/A virtual bool recvTimingSnoopResp(PacketPtr pkt) 11810405Sandreas.hansson@arm.com { return xbar.recvTimingSnoopResp(pkt, id); } 1198948SN/A 1208948SN/A /** 12110405Sandreas.hansson@arm.com * When receiving an atomic request, pass it to the crossbar. 1228948SN/A */ 1238922SN/A virtual Tick recvAtomic(PacketPtr pkt) 12410405Sandreas.hansson@arm.com { return xbar.recvAtomic(pkt, id); } 1258922SN/A 1268948SN/A /** 12710405Sandreas.hansson@arm.com * When receiving a functional request, pass it to the crossbar. 1288948SN/A */ 1298922SN/A virtual void recvFunctional(PacketPtr pkt) 13010405Sandreas.hansson@arm.com { xbar.recvFunctional(pkt, id); } 1318922SN/A 1328948SN/A /** 13310405Sandreas.hansson@arm.com * Return the union of all adress ranges seen by this crossbar. 1349036SN/A */ 1359090SN/A virtual AddrRangeList getAddrRanges() const 13610405Sandreas.hansson@arm.com { return xbar.getAddrRanges(); } 1379036SN/A 1389036SN/A }; 1399036SN/A 1409036SN/A /** 14110405Sandreas.hansson@arm.com * Declaration of the coherent crossbar master port type, one will be 1429036SN/A * instantiated for each of the slave interfaces connecting to the 14310405Sandreas.hansson@arm.com * crossbar. 1449036SN/A */ 14510405Sandreas.hansson@arm.com class CoherentXBarMasterPort : public MasterPort 1469036SN/A { 1479036SN/A private: 14810405Sandreas.hansson@arm.com /** A reference to the crossbar to which this port belongs. */ 14910405Sandreas.hansson@arm.com CoherentXBar &xbar; 1509036SN/A 1519036SN/A public: 1529036SN/A 15310405Sandreas.hansson@arm.com CoherentXBarMasterPort(const std::string &_name, 15410405Sandreas.hansson@arm.com CoherentXBar &_xbar, PortID _id) 15510405Sandreas.hansson@arm.com : MasterPort(_name, &_xbar, _id), xbar(_xbar) 1569036SN/A { } 1579036SN/A 1589036SN/A protected: 1599036SN/A 1609036SN/A /** 1619036SN/A * Determine if this port should be considered a snooper. For 16210405Sandreas.hansson@arm.com * a coherent crossbar master port this is always true. 1639036SN/A * 1649036SN/A * @return a boolean that is true if this port is snooping 1659036SN/A */ 1669036SN/A virtual bool isSnooping() const 1679036SN/A { return true; } 1689036SN/A 1699036SN/A /** 17010405Sandreas.hansson@arm.com * When receiving a timing response, pass it to the crossbar. 1719036SN/A */ 1729036SN/A virtual bool recvTimingResp(PacketPtr pkt) 17310405Sandreas.hansson@arm.com { return xbar.recvTimingResp(pkt, id); } 1749036SN/A 1759036SN/A /** 17610405Sandreas.hansson@arm.com * When receiving a timing snoop request, pass it to the crossbar. 1779036SN/A */ 1789036SN/A virtual void recvTimingSnoopReq(PacketPtr pkt) 17910405Sandreas.hansson@arm.com { return xbar.recvTimingSnoopReq(pkt, id); } 1809036SN/A 1819036SN/A /** 18210405Sandreas.hansson@arm.com * When receiving an atomic snoop request, pass it to the crossbar. 1839036SN/A */ 1849036SN/A virtual Tick recvAtomicSnoop(PacketPtr pkt) 18510405Sandreas.hansson@arm.com { return xbar.recvAtomicSnoop(pkt, id); } 1869036SN/A 1879036SN/A /** 18810405Sandreas.hansson@arm.com * When receiving a functional snoop request, pass it to the crossbar. 1899036SN/A */ 1909036SN/A virtual void recvFunctionalSnoop(PacketPtr pkt) 19110405Sandreas.hansson@arm.com { xbar.recvFunctionalSnoop(pkt, id); } 1929036SN/A 1939036SN/A /** When reciving a range change from the peer port (at id), 19410405Sandreas.hansson@arm.com pass it to the crossbar. */ 1959036SN/A virtual void recvRangeChange() 19610405Sandreas.hansson@arm.com { xbar.recvRangeChange(id); } 1979036SN/A 1989036SN/A /** When reciving a retry from the peer port (at id), 19910405Sandreas.hansson@arm.com pass it to the crossbar. */ 20010713Sandreas.hansson@arm.com virtual void recvReqRetry() 20110713Sandreas.hansson@arm.com { xbar.recvReqRetry(id); } 2028922SN/A 2038922SN/A }; 2048922SN/A 2059716SN/A /** 2069716SN/A * Internal class to bridge between an incoming snoop response 2079716SN/A * from a slave port and forwarding it through an outgoing slave 2089716SN/A * port. It is effectively a dangling master port. 2099716SN/A */ 2109716SN/A class SnoopRespPort : public MasterPort 2119716SN/A { 2129716SN/A 2139716SN/A private: 2149716SN/A 2159716SN/A /** The port which we mirror internally. */ 21610888Sandreas.hansson@arm.com QueuedSlavePort& slavePort; 2179716SN/A 2189716SN/A public: 2199716SN/A 2209716SN/A /** 2219716SN/A * Create a snoop response port that mirrors a given slave port. 2229716SN/A */ 22310888Sandreas.hansson@arm.com SnoopRespPort(QueuedSlavePort& slave_port, CoherentXBar& _xbar) : 22410405Sandreas.hansson@arm.com MasterPort(slave_port.name() + ".snoopRespPort", &_xbar), 2259778SN/A slavePort(slave_port) { } 2269716SN/A 2279716SN/A /** 2289716SN/A * Override the sending of retries and pass them on through 2299716SN/A * the mirrored slave port. 2309716SN/A */ 23110713Sandreas.hansson@arm.com void sendRetryResp() { 23210713Sandreas.hansson@arm.com // forward it as a snoop response retry 23310713Sandreas.hansson@arm.com slavePort.sendRetrySnoopResp(); 2349716SN/A } 2359716SN/A 2369716SN/A /** 2379716SN/A * Provided as necessary. 2389716SN/A */ 23910713Sandreas.hansson@arm.com void recvReqRetry() { panic("SnoopRespPort should never see retry\n"); } 2409716SN/A 2419716SN/A /** 2429716SN/A * Provided as necessary. 2439716SN/A */ 2449716SN/A bool recvTimingResp(PacketPtr pkt) 2459716SN/A { 2469716SN/A panic("SnoopRespPort should never see timing response\n"); 2479716SN/A return false; 2489716SN/A } 2499716SN/A 2509716SN/A }; 2519716SN/A 2529716SN/A std::vector<SnoopRespPort*> snoopRespPorts; 2539716SN/A 25410888Sandreas.hansson@arm.com std::vector<QueuedSlavePort*> snoopPorts; 2554475SN/A 2568948SN/A /** 25710656Sandreas.hansson@arm.com * Store the outstanding requests that we are expecting snoop 25810656Sandreas.hansson@arm.com * responses from so we can determine which snoop responses we 25910656Sandreas.hansson@arm.com * generated and which ones were merely forwarded. 2608948SN/A */ 26111168Sandreas.hansson@arm.com std::unordered_set<RequestPtr> outstandingSnoop; 2628948SN/A 2639524SN/A /** 2649524SN/A * Keep a pointer to the system to be allow to querying memory system 2659524SN/A * properties. 2669524SN/A */ 2679524SN/A System *system; 2689524SN/A 26910402SN/A /** A snoop filter that tracks cache line residency and can restrict the 27010402SN/A * broadcast needed for probes. NULL denotes an absent filter. */ 27110402SN/A SnoopFilter *snoopFilter; 27210402SN/A 27310719SMarco.Balboni@ARM.com /** Cycles of snoop response latency.*/ 27410719SMarco.Balboni@ARM.com const Cycles snoopResponseLatency; 27510719SMarco.Balboni@ARM.com 27610883Sali.jafri@arm.com /** 27710883Sali.jafri@arm.com * @todo this is a temporary workaround until the 4-phase code is committed. 27810883Sali.jafri@arm.com * upstream caches need this packet until true is returned, so hold it for 27910883Sali.jafri@arm.com * deletion until a subsequent call 28010883Sali.jafri@arm.com */ 28110883Sali.jafri@arm.com std::vector<PacketPtr> pendingDelete; 28210883Sali.jafri@arm.com 28310405Sandreas.hansson@arm.com /** Function called by the port when the crossbar is recieving a Timing 2848975SN/A request packet.*/ 2859945SN/A bool recvTimingReq(PacketPtr pkt, PortID slave_port_id); 2868975SN/A 28710405Sandreas.hansson@arm.com /** Function called by the port when the crossbar is recieving a Timing 2888975SN/A response packet.*/ 2899945SN/A bool recvTimingResp(PacketPtr pkt, PortID master_port_id); 2904475SN/A 29110405Sandreas.hansson@arm.com /** Function called by the port when the crossbar is recieving a timing 2928975SN/A snoop request.*/ 2939945SN/A void recvTimingSnoopReq(PacketPtr pkt, PortID master_port_id); 2948975SN/A 29510405Sandreas.hansson@arm.com /** Function called by the port when the crossbar is recieving a timing 2968975SN/A snoop response.*/ 2979945SN/A bool recvTimingSnoopResp(PacketPtr pkt, PortID slave_port_id); 2988948SN/A 2999092SN/A /** Timing function called by port when it is once again able to process 3009092SN/A * requests. */ 30110713Sandreas.hansson@arm.com void recvReqRetry(PortID master_port_id); 3029092SN/A 3038948SN/A /** 3048948SN/A * Forward a timing packet to our snoopers, potentially excluding 3058948SN/A * one of the connected coherent masters to avoid sending a packet 3068948SN/A * back to where it came from. 3078948SN/A * 3088948SN/A * @param pkt Packet to forward 3098948SN/A * @param exclude_slave_port_id Id of slave port to exclude 3108948SN/A */ 31110402SN/A void forwardTiming(PacketPtr pkt, PortID exclude_slave_port_id) { 31210402SN/A forwardTiming(pkt, exclude_slave_port_id, snoopPorts); 31310402SN/A } 31410402SN/A 31510402SN/A /** 31610402SN/A * Forward a timing packet to a selected list of snoopers, potentially 31710402SN/A * excluding one of the connected coherent masters to avoid sending a packet 31810402SN/A * back to where it came from. 31910402SN/A * 32010402SN/A * @param pkt Packet to forward 32110402SN/A * @param exclude_slave_port_id Id of slave port to exclude 32210402SN/A * @param dests Vector of destination ports for the forwarded pkt 32310402SN/A */ 32410402SN/A void forwardTiming(PacketPtr pkt, PortID exclude_slave_port_id, 32510888Sandreas.hansson@arm.com const std::vector<QueuedSlavePort*>& dests); 3268948SN/A 32710405Sandreas.hansson@arm.com /** Function called by the port when the crossbar is recieving a Atomic 3284475SN/A transaction.*/ 3299032SN/A Tick recvAtomic(PacketPtr pkt, PortID slave_port_id); 3304475SN/A 33110405Sandreas.hansson@arm.com /** Function called by the port when the crossbar is recieving an 3328948SN/A atomic snoop transaction.*/ 3339032SN/A Tick recvAtomicSnoop(PacketPtr pkt, PortID master_port_id); 3348948SN/A 3358948SN/A /** 3368948SN/A * Forward an atomic packet to our snoopers, potentially excluding 3378948SN/A * one of the connected coherent masters to avoid sending a packet 3388948SN/A * back to where it came from. 3398948SN/A * 3408948SN/A * @param pkt Packet to forward 3418948SN/A * @param exclude_slave_port_id Id of slave port to exclude 3428948SN/A * 3438948SN/A * @return a pair containing the snoop response and snoop latency 3448948SN/A */ 3458948SN/A std::pair<MemCmd, Tick> forwardAtomic(PacketPtr pkt, 34610402SN/A PortID exclude_slave_port_id) 34710402SN/A { 34810888Sandreas.hansson@arm.com return forwardAtomic(pkt, exclude_slave_port_id, InvalidPortID, 34910888Sandreas.hansson@arm.com snoopPorts); 35010402SN/A } 35110402SN/A 35210402SN/A /** 35310402SN/A * Forward an atomic packet to a selected list of snoopers, potentially 35410402SN/A * excluding one of the connected coherent masters to avoid sending a packet 35510402SN/A * back to where it came from. 35610402SN/A * 35710402SN/A * @param pkt Packet to forward 35810402SN/A * @param exclude_slave_port_id Id of slave port to exclude 35910402SN/A * @param source_master_port_id Id of the master port for snoops from below 36010402SN/A * @param dests Vector of destination ports for the forwarded pkt 36110402SN/A * 36210402SN/A * @return a pair containing the snoop response and snoop latency 36310402SN/A */ 36410402SN/A std::pair<MemCmd, Tick> forwardAtomic(PacketPtr pkt, 36510402SN/A PortID exclude_slave_port_id, 36610402SN/A PortID source_master_port_id, 36710888Sandreas.hansson@arm.com const std::vector<QueuedSlavePort*>& 36810888Sandreas.hansson@arm.com dests); 3698948SN/A 37010405Sandreas.hansson@arm.com /** Function called by the port when the crossbar is recieving a Functional 3714475SN/A transaction.*/ 3729032SN/A void recvFunctional(PacketPtr pkt, PortID slave_port_id); 3734475SN/A 37410405Sandreas.hansson@arm.com /** Function called by the port when the crossbar is recieving a functional 3758948SN/A snoop transaction.*/ 3769032SN/A void recvFunctionalSnoop(PacketPtr pkt, PortID master_port_id); 3778948SN/A 3788948SN/A /** 3798948SN/A * Forward a functional packet to our snoopers, potentially 3808948SN/A * excluding one of the connected coherent masters to avoid 3818948SN/A * sending a packet back to where it came from. 3828948SN/A * 3838948SN/A * @param pkt Packet to forward 3848948SN/A * @param exclude_slave_port_id Id of slave port to exclude 3858948SN/A */ 3869031SN/A void forwardFunctional(PacketPtr pkt, PortID exclude_slave_port_id); 3878948SN/A 38810405Sandreas.hansson@arm.com Stats::Scalar snoops; 38910401SN/A Stats::Distribution snoopFanout; 3909712SN/A 3912381SN/A public: 3922381SN/A 3939036SN/A virtual void init(); 3942568SN/A 39510405Sandreas.hansson@arm.com CoherentXBar(const CoherentXBarParams *p); 3969092SN/A 39710405Sandreas.hansson@arm.com virtual ~CoherentXBar(); 3989715SN/A 3999712SN/A virtual void regStats(); 4002381SN/A}; 4012381SN/A 40210405Sandreas.hansson@arm.com#endif //__MEM_COHERENT_XBAR_HH__ 403