coherent_xbar.cc revision 10883
12497SN/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 *
142497SN/A * Copyright (c) 2006 The Regents of The University of Michigan
152497SN/A * All rights reserved.
162497SN/A *
172497SN/A * Redistribution and use in source and binary forms, with or without
182497SN/A * modification, are permitted provided that the following conditions are
192497SN/A * met: redistributions of source code must retain the above copyright
202497SN/A * notice, this list of conditions and the following disclaimer;
212497SN/A * redistributions in binary form must reproduce the above copyright
222497SN/A * notice, this list of conditions and the following disclaimer in the
232497SN/A * documentation and/or other materials provided with the distribution;
242497SN/A * neither the name of the copyright holders nor the names of its
252497SN/A * contributors may be used to endorse or promote products derived from
262497SN/A * this software without specific prior written permission.
272497SN/A *
282497SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
292497SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
302497SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
312497SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
322497SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
332497SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
342497SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
352497SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
362497SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
372497SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
382497SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
392665SN/A *
402665SN/A * Authors: Ali Saidi
418715SN/A *          Andreas Hansson
428922SN/A *          William Wang
432497SN/A */
442497SN/A
452497SN/A/**
462982SN/A * @file
4710405Sandreas.hansson@arm.com * Definition of a crossbar object.
482497SN/A */
492497SN/A
502846SN/A#include "base/misc.hh"
512548SN/A#include "base/trace.hh"
5210405Sandreas.hansson@arm.com#include "debug/AddrRanges.hh"
5310405Sandreas.hansson@arm.com#include "debug/CoherentXBar.hh"
5410405Sandreas.hansson@arm.com#include "mem/coherent_xbar.hh"
559524SN/A#include "sim/system.hh"
562497SN/A
5710405Sandreas.hansson@arm.comCoherentXBar::CoherentXBar(const CoherentXBarParams *p)
5810719SMarco.Balboni@ARM.com    : BaseXBar(p), system(p->system), snoopFilter(p->snoop_filter),
5910719SMarco.Balboni@ARM.com      snoopResponseLatency(p->snoop_response_latency)
607523SN/A{
618851SN/A    // create the ports based on the size of the master and slave
628948SN/A    // vector ports, and the presence of the default port, the ports
638948SN/A    // are enumerated starting from zero
648851SN/A    for (int i = 0; i < p->port_master_connection_count; ++i) {
659095SN/A        std::string portName = csprintf("%s.master[%d]", name(), i);
6610405Sandreas.hansson@arm.com        MasterPort* bp = new CoherentXBarMasterPort(portName, *this, i);
678922SN/A        masterPorts.push_back(bp);
689715SN/A        reqLayers.push_back(new ReqLayer(*bp, *this,
699715SN/A                                         csprintf(".reqLayer%d", i)));
7010713Sandreas.hansson@arm.com        snoopLayers.push_back(new SnoopRespLayer(*bp, *this,
7110713Sandreas.hansson@arm.com                                                 csprintf(".snoopLayer%d", i)));
728851SN/A    }
738851SN/A
748948SN/A    // see if we have a default slave device connected and if so add
758948SN/A    // our corresponding master port
768915SN/A    if (p->port_default_connection_count) {
779031SN/A        defaultPortID = masterPorts.size();
789095SN/A        std::string portName = name() + ".default";
7910405Sandreas.hansson@arm.com        MasterPort* bp = new CoherentXBarMasterPort(portName, *this,
809036SN/A                                                   defaultPortID);
818922SN/A        masterPorts.push_back(bp);
829715SN/A        reqLayers.push_back(new ReqLayer(*bp, *this, csprintf(".reqLayer%d",
839715SN/A                                             defaultPortID)));
8410713Sandreas.hansson@arm.com        snoopLayers.push_back(new SnoopRespLayer(*bp, *this,
8510713Sandreas.hansson@arm.com                                                 csprintf(".snoopLayer%d",
8610713Sandreas.hansson@arm.com                                                          defaultPortID)));
878915SN/A    }
888915SN/A
898948SN/A    // create the slave ports, once again starting at zero
908851SN/A    for (int i = 0; i < p->port_slave_connection_count; ++i) {
919095SN/A        std::string portName = csprintf("%s.slave[%d]", name(), i);
9210405Sandreas.hansson@arm.com        SlavePort* bp = new CoherentXBarSlavePort(portName, *this, i);
938922SN/A        slavePorts.push_back(bp);
949715SN/A        respLayers.push_back(new RespLayer(*bp, *this,
959715SN/A                                           csprintf(".respLayer%d", i)));
969716SN/A        snoopRespPorts.push_back(new SnoopRespPort(*bp, *this));
978851SN/A    }
988851SN/A
9910402SN/A    if (snoopFilter)
10010402SN/A        snoopFilter->setSlavePorts(slavePorts);
10110402SN/A
1027523SN/A    clearPortCache();
1037523SN/A}
1047523SN/A
10510405Sandreas.hansson@arm.comCoherentXBar::~CoherentXBar()
1069715SN/A{
10710405Sandreas.hansson@arm.com    for (auto l: reqLayers)
10810405Sandreas.hansson@arm.com        delete l;
10910405Sandreas.hansson@arm.com    for (auto l: respLayers)
11010405Sandreas.hansson@arm.com        delete l;
11110405Sandreas.hansson@arm.com    for (auto l: snoopLayers)
11210405Sandreas.hansson@arm.com        delete l;
11310405Sandreas.hansson@arm.com    for (auto p: snoopRespPorts)
11410405Sandreas.hansson@arm.com        delete p;
1159715SN/A}
1169715SN/A
1172568SN/Avoid
11810405Sandreas.hansson@arm.comCoherentXBar::init()
1192568SN/A{
1209278SN/A    // the base class is responsible for determining the block size
12110405Sandreas.hansson@arm.com    BaseXBar::init();
1229278SN/A
1238948SN/A    // iterate over our slave ports and determine which of our
1248948SN/A    // neighbouring master ports are snooping and add them as snoopers
12510405Sandreas.hansson@arm.com    for (const auto& p: slavePorts) {
1269088SN/A        // check if the connected master port is snooping
12710405Sandreas.hansson@arm.com        if (p->isSnooping()) {
12810405Sandreas.hansson@arm.com            DPRINTF(AddrRanges, "Adding snooping master %s\n",
12910405Sandreas.hansson@arm.com                    p->getMasterPort().name());
13010405Sandreas.hansson@arm.com            snoopPorts.push_back(p);
1318711SN/A        }
1328711SN/A    }
1332568SN/A
1349036SN/A    if (snoopPorts.empty())
13510405Sandreas.hansson@arm.com        warn("CoherentXBar %s has no snooping ports attached!\n", name());
1363244SN/A}
1373244SN/A
1388948SN/Abool
13910405Sandreas.hansson@arm.comCoherentXBar::recvTimingReq(PacketPtr pkt, PortID slave_port_id)
1403244SN/A{
14110883Sali.jafri@arm.com    // @todo temporary hack to deal with memory corruption issue until
14210883Sali.jafri@arm.com    // 4-phase transactions are complete
14310883Sali.jafri@arm.com    for (int x = 0; x < pendingDelete.size(); x++)
14410883Sali.jafri@arm.com        delete pendingDelete[x];
14510883Sali.jafri@arm.com    pendingDelete.clear();
14610883Sali.jafri@arm.com
1478975SN/A    // determine the source port based on the id
1489032SN/A    SlavePort *src_port = slavePorts[slave_port_id];
1493244SN/A
1509091SN/A    // remember if the packet is an express snoop
1519091SN/A    bool is_express_snoop = pkt->isExpressSnoop();
15210656Sandreas.hansson@arm.com    bool is_inhibited = pkt->memInhibitAsserted();
15310656Sandreas.hansson@arm.com    // for normal requests, going downstream, the express snoop flag
15410656Sandreas.hansson@arm.com    // and the inhibited flag should always be the same
15510656Sandreas.hansson@arm.com    assert(is_express_snoop == is_inhibited);
1569091SN/A
1579612SN/A    // determine the destination based on the address
1589712SN/A    PortID master_port_id = findPort(pkt->getAddr());
1599612SN/A
16010405Sandreas.hansson@arm.com    // test if the crossbar should be considered occupied for the current
1619033SN/A    // port, and exclude express snoops from the check
1629715SN/A    if (!is_express_snoop && !reqLayers[master_port_id]->tryTiming(src_port)) {
16310405Sandreas.hansson@arm.com        DPRINTF(CoherentXBar, "recvTimingReq: src %s %s 0x%x BUSY\n",
1648949SN/A                src_port->name(), pkt->cmdString(), pkt->getAddr());
1653244SN/A        return false;
1663244SN/A    }
1673244SN/A
16810405Sandreas.hansson@arm.com    DPRINTF(CoherentXBar, "recvTimingReq: src %s %s expr %d 0x%x\n",
1699091SN/A            src_port->name(), pkt->cmdString(), is_express_snoop,
1709091SN/A            pkt->getAddr());
1715197SN/A
1729712SN/A    // store size and command as they might be modified when
1739712SN/A    // forwarding the packet
1749712SN/A    unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0;
1759712SN/A    unsigned int pkt_cmd = pkt->cmdToIndex();
1769712SN/A
17710719SMarco.Balboni@ARM.com    // store the old header delay so we can restore it if needed
17810719SMarco.Balboni@ARM.com    Tick old_header_delay = pkt->headerDelay;
17910719SMarco.Balboni@ARM.com
18010719SMarco.Balboni@ARM.com    // a request sees the frontend and forward latency
18110719SMarco.Balboni@ARM.com    Tick xbar_delay = (frontendLatency + forwardLatency) * clockPeriod();
18210719SMarco.Balboni@ARM.com
18310719SMarco.Balboni@ARM.com    // set the packet header and payload delay
18410719SMarco.Balboni@ARM.com    calcPacketTiming(pkt, xbar_delay);
18510719SMarco.Balboni@ARM.com
18610719SMarco.Balboni@ARM.com    // determine how long to be crossbar layer is busy
18710719SMarco.Balboni@ARM.com    Tick packetFinishTime = clockEdge(Cycles(1)) + pkt->payloadDelay;
1884912SN/A
18910821Sandreas.hansson@arm.com    if (!system->bypassCaches()) {
1908979SN/A        // the packet is a memory-mapped request and should be
1918979SN/A        // broadcasted to our snoopers but the source
19210402SN/A        if (snoopFilter) {
19310402SN/A            // check with the snoop filter where to forward this packet
19410402SN/A            auto sf_res = snoopFilter->lookupRequest(pkt, *src_port);
19510719SMarco.Balboni@ARM.com            // If SnoopFilter is enabled, the total time required by a packet
19610719SMarco.Balboni@ARM.com            // to be delivered through the xbar has to be charged also with
19710719SMarco.Balboni@ARM.com            // to lookup latency of the snoop filter (sf_res.second).
19810719SMarco.Balboni@ARM.com            pkt->headerDelay += sf_res.second * clockPeriod();
19910402SN/A            packetFinishTime += sf_res.second * clockPeriod();
20010405Sandreas.hansson@arm.com            DPRINTF(CoherentXBar, "recvTimingReq: src %s %s 0x%x"\
20110402SN/A                    " SF size: %i lat: %i\n", src_port->name(),
20210402SN/A                    pkt->cmdString(), pkt->getAddr(), sf_res.first.size(),
20310402SN/A                    sf_res.second);
20410402SN/A            forwardTiming(pkt, slave_port_id, sf_res.first);
20510402SN/A        } else {
20610402SN/A            forwardTiming(pkt, slave_port_id);
20710402SN/A        }
2088979SN/A    }
2098948SN/A
21010883Sali.jafri@arm.com    // forwardTiming snooped into peer caches of the sender, and if
21110883Sali.jafri@arm.com    // this is a clean evict, but the packet is found in a cache, do
21210883Sali.jafri@arm.com    // not forward it
21310883Sali.jafri@arm.com    if (pkt->cmd == MemCmd::CleanEvict && pkt->isBlockCached()) {
21410883Sali.jafri@arm.com        DPRINTF(CoherentXBar, "recvTimingReq: Clean evict 0x%x still cached, "
21510883Sali.jafri@arm.com                "not forwarding\n", pkt->getAddr());
21610883Sali.jafri@arm.com
21710883Sali.jafri@arm.com        // update the layer state and schedule an idle event
21810883Sali.jafri@arm.com        reqLayers[master_port_id]->succeededTiming(packetFinishTime);
21910883Sali.jafri@arm.com        pendingDelete.push_back(pkt);
22010883Sali.jafri@arm.com        return true;
22110883Sali.jafri@arm.com    }
22210883Sali.jafri@arm.com
22310656Sandreas.hansson@arm.com    // remember if the packet will generate a snoop response
22410656Sandreas.hansson@arm.com    const bool expect_snoop_resp = !is_inhibited && pkt->memInhibitAsserted();
22510656Sandreas.hansson@arm.com    const bool expect_response = pkt->needsResponse() &&
22610656Sandreas.hansson@arm.com        !pkt->memInhibitAsserted();
2278915SN/A
22810402SN/A    // Note: Cannot create a copy of the full packet, here.
22910402SN/A    MemCmd orig_cmd(pkt->cmd);
23010402SN/A
2319612SN/A    // since it is a normal request, attempt to send the packet
2329712SN/A    bool success = masterPorts[master_port_id]->sendTimingReq(pkt);
2338948SN/A
23410821Sandreas.hansson@arm.com    if (snoopFilter && !system->bypassCaches()) {
23510402SN/A        // The packet may already be overwritten by the sendTimingReq function.
23610402SN/A        // The snoop filter needs to see the original request *and* the return
23710402SN/A        // status of the send operation, so we need to recreate the original
23810402SN/A        // request.  Atomic mode does not have the issue, as there the send
23910402SN/A        // operation and the response happen instantaneously and don't need two
24010402SN/A        // phase tracking.
24110402SN/A        MemCmd tmp_cmd(pkt->cmd);
24210402SN/A        pkt->cmd = orig_cmd;
24310402SN/A        // Let the snoop filter know about the success of the send operation
24410402SN/A        snoopFilter->updateRequest(pkt, *src_port, !success);
24510402SN/A        pkt->cmd = tmp_cmd;
24610402SN/A    }
24710402SN/A
24810656Sandreas.hansson@arm.com    // check if we were successful in sending the packet onwards
24910656Sandreas.hansson@arm.com    if (!success)  {
25010656Sandreas.hansson@arm.com        // express snoops and inhibited packets should never be forced
25110656Sandreas.hansson@arm.com        // to retry
25210656Sandreas.hansson@arm.com        assert(!is_express_snoop);
25310656Sandreas.hansson@arm.com        assert(!pkt->memInhibitAsserted());
25410656Sandreas.hansson@arm.com
25510719SMarco.Balboni@ARM.com        // restore the header delay
25610719SMarco.Balboni@ARM.com        pkt->headerDelay = old_header_delay;
25710656Sandreas.hansson@arm.com
25810656Sandreas.hansson@arm.com        DPRINTF(CoherentXBar, "recvTimingReq: src %s %s 0x%x RETRY\n",
25910656Sandreas.hansson@arm.com                src_port->name(), pkt->cmdString(), pkt->getAddr());
26010656Sandreas.hansson@arm.com
26110656Sandreas.hansson@arm.com        // update the layer state and schedule an idle event
26210656Sandreas.hansson@arm.com        reqLayers[master_port_id]->failedTiming(src_port,
26310719SMarco.Balboni@ARM.com                                                clockEdge(Cycles(1)));
2649091SN/A    } else {
26510656Sandreas.hansson@arm.com        // express snoops currently bypass the crossbar state entirely
26610656Sandreas.hansson@arm.com        if (!is_express_snoop) {
26710656Sandreas.hansson@arm.com            // if this particular request will generate a snoop
26810656Sandreas.hansson@arm.com            // response
26910656Sandreas.hansson@arm.com            if (expect_snoop_resp) {
27010656Sandreas.hansson@arm.com                // we should never have an exsiting request outstanding
27110656Sandreas.hansson@arm.com                assert(outstandingSnoop.find(pkt->req) ==
27210656Sandreas.hansson@arm.com                       outstandingSnoop.end());
27310656Sandreas.hansson@arm.com                outstandingSnoop.insert(pkt->req);
2748948SN/A
27510656Sandreas.hansson@arm.com                // basic sanity check on the outstanding snoops
27610656Sandreas.hansson@arm.com                panic_if(outstandingSnoop.size() > 512,
27710656Sandreas.hansson@arm.com                         "Outstanding snoop requests exceeded 512\n");
27810656Sandreas.hansson@arm.com            }
2798948SN/A
28010656Sandreas.hansson@arm.com            // remember where to route the normal response to
28110656Sandreas.hansson@arm.com            if (expect_response || expect_snoop_resp) {
28210656Sandreas.hansson@arm.com                assert(routeTo.find(pkt->req) == routeTo.end());
28310656Sandreas.hansson@arm.com                routeTo[pkt->req] = slave_port_id;
2849549SN/A
28510656Sandreas.hansson@arm.com                panic_if(routeTo.size() > 512,
28610656Sandreas.hansson@arm.com                         "Routing table exceeds 512 packets\n");
28710656Sandreas.hansson@arm.com            }
2888948SN/A
28910405Sandreas.hansson@arm.com            // update the layer state and schedule an idle event
2909715SN/A            reqLayers[master_port_id]->succeededTiming(packetFinishTime);
2919091SN/A        }
2928975SN/A
29310656Sandreas.hansson@arm.com        // stats updates only consider packets that were successfully sent
2949712SN/A        pktCount[slave_port_id][master_port_id]++;
29510405Sandreas.hansson@arm.com        pktSize[slave_port_id][master_port_id] += pkt_size;
2969712SN/A        transDist[pkt_cmd]++;
29710656Sandreas.hansson@arm.com
29810656Sandreas.hansson@arm.com        if (is_express_snoop)
29910656Sandreas.hansson@arm.com            snoops++;
3009712SN/A    }
3019712SN/A
3029091SN/A    return success;
3038975SN/A}
3048975SN/A
3058975SN/Abool
30610405Sandreas.hansson@arm.comCoherentXBar::recvTimingResp(PacketPtr pkt, PortID master_port_id)
3078975SN/A{
3088975SN/A    // determine the source port based on the id
3099032SN/A    MasterPort *src_port = masterPorts[master_port_id];
3108975SN/A
31110656Sandreas.hansson@arm.com    // determine the destination
31210656Sandreas.hansson@arm.com    const auto route_lookup = routeTo.find(pkt->req);
31310656Sandreas.hansson@arm.com    assert(route_lookup != routeTo.end());
31410656Sandreas.hansson@arm.com    const PortID slave_port_id = route_lookup->second;
31510572Sandreas.hansson@arm.com    assert(slave_port_id != InvalidPortID);
31610572Sandreas.hansson@arm.com    assert(slave_port_id < respLayers.size());
3179713SN/A
31810405Sandreas.hansson@arm.com    // test if the crossbar should be considered occupied for the
31910405Sandreas.hansson@arm.com    // current port
3209715SN/A    if (!respLayers[slave_port_id]->tryTiming(src_port)) {
32110405Sandreas.hansson@arm.com        DPRINTF(CoherentXBar, "recvTimingResp: src %s %s 0x%x BUSY\n",
3228975SN/A                src_port->name(), pkt->cmdString(), pkt->getAddr());
3238975SN/A        return false;
3248975SN/A    }
3258975SN/A
32610405Sandreas.hansson@arm.com    DPRINTF(CoherentXBar, "recvTimingResp: src %s %s 0x%x\n",
3278975SN/A            src_port->name(), pkt->cmdString(), pkt->getAddr());
3288975SN/A
3299712SN/A    // store size and command as they might be modified when
3309712SN/A    // forwarding the packet
3319712SN/A    unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0;
3329712SN/A    unsigned int pkt_cmd = pkt->cmdToIndex();
3339712SN/A
33410719SMarco.Balboni@ARM.com    // a response sees the response latency
33510719SMarco.Balboni@ARM.com    Tick xbar_delay = responseLatency * clockPeriod();
33610719SMarco.Balboni@ARM.com
33710719SMarco.Balboni@ARM.com    // set the packet header and payload delay
33810719SMarco.Balboni@ARM.com    calcPacketTiming(pkt, xbar_delay);
33910719SMarco.Balboni@ARM.com
34010719SMarco.Balboni@ARM.com    // determine how long to be crossbar layer is busy
34110719SMarco.Balboni@ARM.com    Tick packetFinishTime = clockEdge(Cycles(1)) + pkt->payloadDelay;
3428975SN/A
34310821Sandreas.hansson@arm.com    if (snoopFilter && !system->bypassCaches()) {
34410402SN/A        // let the snoop filter inspect the response and update its state
34510402SN/A        snoopFilter->updateResponse(pkt, *slavePorts[slave_port_id]);
34610402SN/A    }
34710402SN/A
3489712SN/A    // send the packet through the destination slave port
3499712SN/A    bool success M5_VAR_USED = slavePorts[slave_port_id]->sendTimingResp(pkt);
3508975SN/A
3518975SN/A    // currently it is illegal to block responses... can lead to
3528975SN/A    // deadlock
3538975SN/A    assert(success);
3548975SN/A
35510656Sandreas.hansson@arm.com    // remove the request from the routing table
35610656Sandreas.hansson@arm.com    routeTo.erase(route_lookup);
35710656Sandreas.hansson@arm.com
3589715SN/A    respLayers[slave_port_id]->succeededTiming(packetFinishTime);
3598975SN/A
3609712SN/A    // stats updates
3619712SN/A    pktCount[slave_port_id][master_port_id]++;
36210405Sandreas.hansson@arm.com    pktSize[slave_port_id][master_port_id] += pkt_size;
3639712SN/A    transDist[pkt_cmd]++;
3649712SN/A
3658975SN/A    return true;
3668975SN/A}
3678975SN/A
3688975SN/Avoid
36910405Sandreas.hansson@arm.comCoherentXBar::recvTimingSnoopReq(PacketPtr pkt, PortID master_port_id)
3708975SN/A{
37110405Sandreas.hansson@arm.com    DPRINTF(CoherentXBar, "recvTimingSnoopReq: src %s %s 0x%x\n",
3729032SN/A            masterPorts[master_port_id]->name(), pkt->cmdString(),
3738975SN/A            pkt->getAddr());
3748975SN/A
3759712SN/A    // update stats here as we know the forwarding will succeed
3769712SN/A    transDist[pkt->cmdToIndex()]++;
37710405Sandreas.hansson@arm.com    snoops++;
3789712SN/A
3798975SN/A    // we should only see express snoops from caches
3808975SN/A    assert(pkt->isExpressSnoop());
3818975SN/A
38210656Sandreas.hansson@arm.com    // remeber if the packet is inhibited so we can see if it changes
38310656Sandreas.hansson@arm.com    const bool is_inhibited = pkt->memInhibitAsserted();
3849032SN/A
38510402SN/A    if (snoopFilter) {
38610402SN/A        // let the Snoop Filter work its magic and guide probing
38710402SN/A        auto sf_res = snoopFilter->lookupSnoop(pkt);
38810402SN/A        // No timing here: packetFinishTime += sf_res.second * clockPeriod();
38910405Sandreas.hansson@arm.com        DPRINTF(CoherentXBar, "recvTimingSnoopReq: src %s %s 0x%x"\
39010402SN/A                " SF size: %i lat: %i\n", masterPorts[master_port_id]->name(),
39110402SN/A                pkt->cmdString(), pkt->getAddr(), sf_res.first.size(),
39210402SN/A                sf_res.second);
39310402SN/A
39410402SN/A        // forward to all snoopers
39510402SN/A        forwardTiming(pkt, InvalidPortID, sf_res.first);
39610402SN/A    } else {
39710402SN/A        forwardTiming(pkt, InvalidPortID);
39810402SN/A    }
3998975SN/A
40010656Sandreas.hansson@arm.com    // if we can expect a response, remember how to route it
40110656Sandreas.hansson@arm.com    if (!is_inhibited && pkt->memInhibitAsserted()) {
40210656Sandreas.hansson@arm.com        assert(routeTo.find(pkt->req) == routeTo.end());
40310656Sandreas.hansson@arm.com        routeTo[pkt->req] = master_port_id;
40410656Sandreas.hansson@arm.com    }
40510656Sandreas.hansson@arm.com
4068975SN/A    // a snoop request came from a connected slave device (one of
4078975SN/A    // our master ports), and if it is not coming from the slave
4088975SN/A    // device responsible for the address range something is
4098975SN/A    // wrong, hence there is nothing further to do as the packet
4108975SN/A    // would be going back to where it came from
4119032SN/A    assert(master_port_id == findPort(pkt->getAddr()));
4128975SN/A}
4138975SN/A
4148975SN/Abool
41510405Sandreas.hansson@arm.comCoherentXBar::recvTimingSnoopResp(PacketPtr pkt, PortID slave_port_id)
4168975SN/A{
4178975SN/A    // determine the source port based on the id
4189032SN/A    SlavePort* src_port = slavePorts[slave_port_id];
4198975SN/A
42010656Sandreas.hansson@arm.com    // get the destination
42110656Sandreas.hansson@arm.com    const auto route_lookup = routeTo.find(pkt->req);
42210656Sandreas.hansson@arm.com    assert(route_lookup != routeTo.end());
42310656Sandreas.hansson@arm.com    const PortID dest_port_id = route_lookup->second;
42410572Sandreas.hansson@arm.com    assert(dest_port_id != InvalidPortID);
4259714SN/A
4269714SN/A    // determine if the response is from a snoop request we
4279714SN/A    // created as the result of a normal request (in which case it
42810656Sandreas.hansson@arm.com    // should be in the outstandingSnoop), or if we merely forwarded
4299714SN/A    // someone else's snoop request
43010656Sandreas.hansson@arm.com    const bool forwardAsSnoop = outstandingSnoop.find(pkt->req) ==
43110656Sandreas.hansson@arm.com        outstandingSnoop.end();
4329714SN/A
43310405Sandreas.hansson@arm.com    // test if the crossbar should be considered occupied for the
43410405Sandreas.hansson@arm.com    // current port, note that the check is bypassed if the response
43510405Sandreas.hansson@arm.com    // is being passed on as a normal response since this is occupying
43610405Sandreas.hansson@arm.com    // the response layer rather than the snoop response layer
4379715SN/A    if (forwardAsSnoop) {
43810572Sandreas.hansson@arm.com        assert(dest_port_id < snoopLayers.size());
4399715SN/A        if (!snoopLayers[dest_port_id]->tryTiming(src_port)) {
44010405Sandreas.hansson@arm.com            DPRINTF(CoherentXBar, "recvTimingSnoopResp: src %s %s 0x%x BUSY\n",
4419715SN/A                    src_port->name(), pkt->cmdString(), pkt->getAddr());
4429715SN/A            return false;
4439715SN/A        }
4449716SN/A    } else {
4459716SN/A        // get the master port that mirrors this slave port internally
4469716SN/A        MasterPort* snoop_port = snoopRespPorts[slave_port_id];
44710572Sandreas.hansson@arm.com        assert(dest_port_id < respLayers.size());
4489716SN/A        if (!respLayers[dest_port_id]->tryTiming(snoop_port)) {
44910405Sandreas.hansson@arm.com            DPRINTF(CoherentXBar, "recvTimingSnoopResp: src %s %s 0x%x BUSY\n",
4509716SN/A                    snoop_port->name(), pkt->cmdString(), pkt->getAddr());
4519716SN/A            return false;
4529716SN/A        }
4538975SN/A    }
4548975SN/A
45510405Sandreas.hansson@arm.com    DPRINTF(CoherentXBar, "recvTimingSnoopResp: src %s %s 0x%x\n",
4568975SN/A            src_port->name(), pkt->cmdString(), pkt->getAddr());
4578975SN/A
4589712SN/A    // store size and command as they might be modified when
4599712SN/A    // forwarding the packet
4609712SN/A    unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0;
4619712SN/A    unsigned int pkt_cmd = pkt->cmdToIndex();
4629712SN/A
4638975SN/A    // responses are never express snoops
4648975SN/A    assert(!pkt->isExpressSnoop());
4658975SN/A
46610719SMarco.Balboni@ARM.com    // a snoop response sees the snoop response latency, and if it is
46710719SMarco.Balboni@ARM.com    // forwarded as a normal response, the response latency
46810719SMarco.Balboni@ARM.com    Tick xbar_delay =
46910719SMarco.Balboni@ARM.com        (forwardAsSnoop ? snoopResponseLatency : responseLatency) *
47010719SMarco.Balboni@ARM.com        clockPeriod();
47110719SMarco.Balboni@ARM.com
47210719SMarco.Balboni@ARM.com    // set the packet header and payload delay
47310719SMarco.Balboni@ARM.com    calcPacketTiming(pkt, xbar_delay);
47410719SMarco.Balboni@ARM.com
47510719SMarco.Balboni@ARM.com    // determine how long to be crossbar layer is busy
47610719SMarco.Balboni@ARM.com    Tick packetFinishTime = clockEdge(Cycles(1)) + pkt->payloadDelay;
4778975SN/A
4789714SN/A    // forward it either as a snoop response or a normal response
4799714SN/A    if (forwardAsSnoop) {
4809714SN/A        // this is a snoop response to a snoop request we forwarded,
4819714SN/A        // e.g. coming from the L1 and going to the L2, and it should
4829714SN/A        // be forwarded as a snoop response
48310402SN/A
48410402SN/A        if (snoopFilter) {
48510402SN/A            // update the probe filter so that it can properly track the line
48610402SN/A            snoopFilter->updateSnoopForward(pkt, *slavePorts[slave_port_id],
48710402SN/A                                            *masterPorts[dest_port_id]);
48810402SN/A        }
48910402SN/A
4909712SN/A        bool success M5_VAR_USED =
4919712SN/A            masterPorts[dest_port_id]->sendTimingSnoopResp(pkt);
4929712SN/A        pktCount[slave_port_id][dest_port_id]++;
49310405Sandreas.hansson@arm.com        pktSize[slave_port_id][dest_port_id] += pkt_size;
4948975SN/A        assert(success);
4959714SN/A
4969715SN/A        snoopLayers[dest_port_id]->succeededTiming(packetFinishTime);
4973244SN/A    } else {
4988975SN/A        // we got a snoop response on one of our slave ports,
49910405Sandreas.hansson@arm.com        // i.e. from a coherent master connected to the crossbar, and
50010405Sandreas.hansson@arm.com        // since we created the snoop request as part of recvTiming,
50110405Sandreas.hansson@arm.com        // this should now be a normal response again
50210656Sandreas.hansson@arm.com        outstandingSnoop.erase(pkt->req);
5038948SN/A
50410656Sandreas.hansson@arm.com        // this is a snoop response from a coherent master, hence it
50510656Sandreas.hansson@arm.com        // should never go back to where the snoop response came from,
50610656Sandreas.hansson@arm.com        // but instead to where the original request came from
5079712SN/A        assert(slave_port_id != dest_port_id);
5088948SN/A
50910402SN/A        if (snoopFilter) {
51010402SN/A            // update the probe filter so that it can properly track the line
51110402SN/A            snoopFilter->updateSnoopResponse(pkt, *slavePorts[slave_port_id],
51210402SN/A                                    *slavePorts[dest_port_id]);
51310402SN/A        }
51410402SN/A
51510405Sandreas.hansson@arm.com        DPRINTF(CoherentXBar, "recvTimingSnoopResp: src %s %s 0x%x"\
51610402SN/A                " FWD RESP\n", src_port->name(), pkt->cmdString(),
51710402SN/A                pkt->getAddr());
51810402SN/A
5199714SN/A        // as a normal response, it should go back to a master through
5209714SN/A        // one of our slave ports, at this point we are ignoring the
5219714SN/A        // fact that the response layer could be busy and do not touch
5229714SN/A        // its state
5239712SN/A        bool success M5_VAR_USED =
5249712SN/A            slavePorts[dest_port_id]->sendTimingResp(pkt);
5258975SN/A
5269714SN/A        // @todo Put the response in an internal FIFO and pass it on
5279714SN/A        // to the response layer from there
5289714SN/A
5298975SN/A        // currently it is illegal to block responses... can lead
5308975SN/A        // to deadlock
5318948SN/A        assert(success);
5329716SN/A
5339716SN/A        respLayers[dest_port_id]->succeededTiming(packetFinishTime);
5343244SN/A    }
5353244SN/A
53610656Sandreas.hansson@arm.com    // remove the request from the routing table
53710656Sandreas.hansson@arm.com    routeTo.erase(route_lookup);
53810656Sandreas.hansson@arm.com
5399712SN/A    // stats updates
5409712SN/A    transDist[pkt_cmd]++;
54110405Sandreas.hansson@arm.com    snoops++;
5429712SN/A
5438948SN/A    return true;
5448948SN/A}
5458948SN/A
5463210SN/A
5478948SN/Avoid
54810405Sandreas.hansson@arm.comCoherentXBar::forwardTiming(PacketPtr pkt, PortID exclude_slave_port_id,
54910402SN/A                           const std::vector<SlavePort*>& dests)
5508948SN/A{
55110405Sandreas.hansson@arm.com    DPRINTF(CoherentXBar, "%s for %s address %x size %d\n", __func__,
5529663SN/A            pkt->cmdString(), pkt->getAddr(), pkt->getSize());
5539663SN/A
5549524SN/A    // snoops should only happen if the system isn't bypassing caches
5559524SN/A    assert(!system->bypassCaches());
5569524SN/A
55710401SN/A    unsigned fanout = 0;
55810401SN/A
55910405Sandreas.hansson@arm.com    for (const auto& p: dests) {
5608948SN/A        // we could have gotten this request from a snooping master
5618948SN/A        // (corresponding to our own slave port that is also in
5628948SN/A        // snoopPorts) and should not send it back to where it came
5638948SN/A        // from
5649031SN/A        if (exclude_slave_port_id == InvalidPortID ||
5658948SN/A            p->getId() != exclude_slave_port_id) {
5668948SN/A            // cache is not allowed to refuse snoop
5678975SN/A            p->sendTimingSnoopReq(pkt);
56810401SN/A            fanout++;
5698948SN/A        }
5708948SN/A    }
57110401SN/A
57210401SN/A    // Stats for fanout of this forward operation
57310401SN/A    snoopFanout.sample(fanout);
5742497SN/A}
5752497SN/A
5769092SN/Avoid
57710713Sandreas.hansson@arm.comCoherentXBar::recvReqRetry(PortID master_port_id)
5789092SN/A{
5799093SN/A    // responses and snoop responses never block on forwarding them,
5809093SN/A    // so the retry will always be coming from a port to which we
5819093SN/A    // tried to forward a request
5829715SN/A    reqLayers[master_port_id]->recvRetry();
5839092SN/A}
5849092SN/A
5859036SN/ATick
58610405Sandreas.hansson@arm.comCoherentXBar::recvAtomic(PacketPtr pkt, PortID slave_port_id)
5872657SN/A{
58810405Sandreas.hansson@arm.com    DPRINTF(CoherentXBar, "recvAtomic: packet src %s addr 0x%x cmd %s\n",
5899032SN/A            slavePorts[slave_port_id]->name(), pkt->getAddr(),
5908949SN/A            pkt->cmdString());
5918915SN/A
59210405Sandreas.hansson@arm.com    unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0;
59310405Sandreas.hansson@arm.com    unsigned int pkt_cmd = pkt->cmdToIndex();
5949712SN/A
5958979SN/A    MemCmd snoop_response_cmd = MemCmd::InvalidCmd;
5968979SN/A    Tick snoop_response_latency = 0;
5978979SN/A
59810821Sandreas.hansson@arm.com    if (!system->bypassCaches()) {
5998979SN/A        // forward to all snoopers but the source
60010402SN/A        std::pair<MemCmd, Tick> snoop_result;
60110402SN/A        if (snoopFilter) {
60210402SN/A            // check with the snoop filter where to forward this packet
60310402SN/A            auto sf_res =
60410402SN/A                snoopFilter->lookupRequest(pkt, *slavePorts[slave_port_id]);
60510402SN/A            snoop_response_latency += sf_res.second * clockPeriod();
60610405Sandreas.hansson@arm.com            DPRINTF(CoherentXBar, "%s: src %s %s 0x%x"\
60710402SN/A                    " SF size: %i lat: %i\n", __func__,
60810402SN/A                    slavePorts[slave_port_id]->name(), pkt->cmdString(),
60910402SN/A                    pkt->getAddr(), sf_res.first.size(), sf_res.second);
61010402SN/A            snoop_result = forwardAtomic(pkt, slave_port_id, InvalidPortID,
61110402SN/A                                         sf_res.first);
61210402SN/A        } else {
61310402SN/A            snoop_result = forwardAtomic(pkt, slave_port_id);
61410402SN/A        }
6158979SN/A        snoop_response_cmd = snoop_result.first;
61610402SN/A        snoop_response_latency += snoop_result.second;
6178979SN/A    }
6188915SN/A
6198948SN/A    // even if we had a snoop response, we must continue and also
6208948SN/A    // perform the actual request at the destination
62110405Sandreas.hansson@arm.com    PortID master_port_id = findPort(pkt->getAddr());
62210405Sandreas.hansson@arm.com
62310405Sandreas.hansson@arm.com    // stats updates for the request
62410405Sandreas.hansson@arm.com    pktCount[slave_port_id][master_port_id]++;
62510405Sandreas.hansson@arm.com    pktSize[slave_port_id][master_port_id] += pkt_size;
62610405Sandreas.hansson@arm.com    transDist[pkt_cmd]++;
6278948SN/A
6288948SN/A    // forward the request to the appropriate destination
62910405Sandreas.hansson@arm.com    Tick response_latency = masterPorts[master_port_id]->sendAtomic(pkt);
6308948SN/A
63110402SN/A    // Lower levels have replied, tell the snoop filter
63210821Sandreas.hansson@arm.com    if (snoopFilter && !system->bypassCaches() && pkt->isResponse()) {
63310402SN/A        snoopFilter->updateResponse(pkt, *slavePorts[slave_port_id]);
63410402SN/A    }
63510402SN/A
6368948SN/A    // if we got a response from a snooper, restore it here
6378948SN/A    if (snoop_response_cmd != MemCmd::InvalidCmd) {
6388948SN/A        // no one else should have responded
6398948SN/A        assert(!pkt->isResponse());
6408948SN/A        pkt->cmd = snoop_response_cmd;
6418948SN/A        response_latency = snoop_response_latency;
6428948SN/A    }
6438948SN/A
6449712SN/A    // add the response data
64510405Sandreas.hansson@arm.com    if (pkt->isResponse()) {
64610405Sandreas.hansson@arm.com        pkt_size = pkt->hasData() ? pkt->getSize() : 0;
64710405Sandreas.hansson@arm.com        pkt_cmd = pkt->cmdToIndex();
64810405Sandreas.hansson@arm.com
64910405Sandreas.hansson@arm.com        // stats updates
65010405Sandreas.hansson@arm.com        pktCount[slave_port_id][master_port_id]++;
65110405Sandreas.hansson@arm.com        pktSize[slave_port_id][master_port_id] += pkt_size;
65210405Sandreas.hansson@arm.com        transDist[pkt_cmd]++;
65310405Sandreas.hansson@arm.com    }
6549712SN/A
65510694SMarco.Balboni@ARM.com    // @todo: Not setting header time
65610694SMarco.Balboni@ARM.com    pkt->payloadDelay = response_latency;
6578948SN/A    return response_latency;
6588948SN/A}
6598948SN/A
6608948SN/ATick
66110405Sandreas.hansson@arm.comCoherentXBar::recvAtomicSnoop(PacketPtr pkt, PortID master_port_id)
6628948SN/A{
66310405Sandreas.hansson@arm.com    DPRINTF(CoherentXBar, "recvAtomicSnoop: packet src %s addr 0x%x cmd %s\n",
6649032SN/A            masterPorts[master_port_id]->name(), pkt->getAddr(),
6658949SN/A            pkt->cmdString());
6668948SN/A
6679712SN/A    // add the request snoop data
66810405Sandreas.hansson@arm.com    snoops++;
6699712SN/A
6708948SN/A    // forward to all snoopers
67110402SN/A    std::pair<MemCmd, Tick> snoop_result;
67210402SN/A    Tick snoop_response_latency = 0;
67310402SN/A    if (snoopFilter) {
67410402SN/A        auto sf_res = snoopFilter->lookupSnoop(pkt);
67510402SN/A        snoop_response_latency += sf_res.second * clockPeriod();
67610405Sandreas.hansson@arm.com        DPRINTF(CoherentXBar, "%s: src %s %s 0x%x SF size: %i lat: %i\n",
67710402SN/A                __func__, masterPorts[master_port_id]->name(), pkt->cmdString(),
67810402SN/A                pkt->getAddr(), sf_res.first.size(), sf_res.second);
67910402SN/A        snoop_result = forwardAtomic(pkt, InvalidPortID, master_port_id,
68010402SN/A                                     sf_res.first);
68110402SN/A    } else {
68210402SN/A        snoop_result = forwardAtomic(pkt, InvalidPortID);
68310402SN/A    }
6848948SN/A    MemCmd snoop_response_cmd = snoop_result.first;
68510402SN/A    snoop_response_latency += snoop_result.second;
6868948SN/A
6878948SN/A    if (snoop_response_cmd != MemCmd::InvalidCmd)
6888948SN/A        pkt->cmd = snoop_response_cmd;
6898948SN/A
6909712SN/A    // add the response snoop data
69110401SN/A    if (pkt->isResponse()) {
69210405Sandreas.hansson@arm.com        snoops++;
69310401SN/A    }
6949712SN/A
69510694SMarco.Balboni@ARM.com    // @todo: Not setting header time
69610694SMarco.Balboni@ARM.com    pkt->payloadDelay = snoop_response_latency;
6978948SN/A    return snoop_response_latency;
6988948SN/A}
6998948SN/A
7008948SN/Astd::pair<MemCmd, Tick>
70110405Sandreas.hansson@arm.comCoherentXBar::forwardAtomic(PacketPtr pkt, PortID exclude_slave_port_id,
70210402SN/A                           PortID source_master_port_id,
70310402SN/A                           const std::vector<SlavePort*>& dests)
7048948SN/A{
7059032SN/A    // the packet may be changed on snoops, record the original
7069032SN/A    // command to enable us to restore it between snoops so that
7078948SN/A    // additional snoops can take place properly
7084626SN/A    MemCmd orig_cmd = pkt->cmd;
7094879SN/A    MemCmd snoop_response_cmd = MemCmd::InvalidCmd;
7104879SN/A    Tick snoop_response_latency = 0;
7113662SN/A
7129524SN/A    // snoops should only happen if the system isn't bypassing caches
7139524SN/A    assert(!system->bypassCaches());
7149524SN/A
71510401SN/A    unsigned fanout = 0;
71610401SN/A
71710405Sandreas.hansson@arm.com    for (const auto& p: dests) {
7188915SN/A        // we could have gotten this request from a snooping master
7198915SN/A        // (corresponding to our own slave port that is also in
7208915SN/A        // snoopPorts) and should not send it back to where it came
7218915SN/A        // from
72210402SN/A        if (exclude_slave_port_id != InvalidPortID &&
72310402SN/A            p->getId() == exclude_slave_port_id)
72410402SN/A            continue;
72510401SN/A
72610402SN/A        Tick latency = p->sendAtomicSnoop(pkt);
72710402SN/A        fanout++;
72810402SN/A
72910402SN/A        // in contrast to a functional access, we have to keep on
73010402SN/A        // going as all snoopers must be updated even if we get a
73110402SN/A        // response
73210402SN/A        if (!pkt->isResponse())
73310402SN/A            continue;
73410402SN/A
73510402SN/A        // response from snoop agent
73610402SN/A        assert(pkt->cmd != orig_cmd);
73710402SN/A        assert(pkt->memInhibitAsserted());
73810402SN/A        // should only happen once
73910402SN/A        assert(snoop_response_cmd == MemCmd::InvalidCmd);
74010402SN/A        // save response state
74110402SN/A        snoop_response_cmd = pkt->cmd;
74210402SN/A        snoop_response_latency = latency;
74310402SN/A
74410402SN/A        if (snoopFilter) {
74510402SN/A            // Handle responses by the snoopers and differentiate between
74610402SN/A            // responses to requests from above and snoops from below
74710402SN/A            if (source_master_port_id != InvalidPortID) {
74810402SN/A                // Getting a response for a snoop from below
74910402SN/A                assert(exclude_slave_port_id == InvalidPortID);
75010402SN/A                snoopFilter->updateSnoopForward(pkt, *p,
75110402SN/A                             *masterPorts[source_master_port_id]);
75210402SN/A            } else {
75310402SN/A                // Getting a response for a request from above
75410402SN/A                assert(source_master_port_id == InvalidPortID);
75510402SN/A                snoopFilter->updateSnoopResponse(pkt, *p,
75610402SN/A                             *slavePorts[exclude_slave_port_id]);
7574626SN/A            }
7584626SN/A        }
75910402SN/A        // restore original packet state for remaining snoopers
76010402SN/A        pkt->cmd = orig_cmd;
7614626SN/A    }
7624626SN/A
76310401SN/A    // Stats for fanout
76410401SN/A    snoopFanout.sample(fanout);
76510401SN/A
7668948SN/A    // the packet is restored as part of the loop and any potential
7678948SN/A    // snoop response is part of the returned pair
7688948SN/A    return std::make_pair(snoop_response_cmd, snoop_response_latency);
7692497SN/A}
7702497SN/A
7712497SN/Avoid
77210405Sandreas.hansson@arm.comCoherentXBar::recvFunctional(PacketPtr pkt, PortID slave_port_id)
7732497SN/A{
7748663SN/A    if (!pkt->isPrint()) {
7758663SN/A        // don't do DPRINTFs on PrintReq as it clutters up the output
77610405Sandreas.hansson@arm.com        DPRINTF(CoherentXBar,
7778949SN/A                "recvFunctional: packet src %s addr 0x%x cmd %s\n",
7789032SN/A                slavePorts[slave_port_id]->name(), pkt->getAddr(),
7798663SN/A                pkt->cmdString());
7808663SN/A    }
7818663SN/A
78210821Sandreas.hansson@arm.com    if (!system->bypassCaches()) {
7838979SN/A        // forward to all snoopers but the source
7849032SN/A        forwardFunctional(pkt, slave_port_id);
7858979SN/A    }
7864912SN/A
7878948SN/A    // there is no need to continue if the snooping has found what we
7888948SN/A    // were looking for and the packet is already a response
7898948SN/A    if (!pkt->isResponse()) {
7909031SN/A        PortID dest_id = findPort(pkt->getAddr());
7918948SN/A
7928948SN/A        masterPorts[dest_id]->sendFunctional(pkt);
7938948SN/A    }
7948948SN/A}
7958948SN/A
7968948SN/Avoid
79710405Sandreas.hansson@arm.comCoherentXBar::recvFunctionalSnoop(PacketPtr pkt, PortID master_port_id)
7988948SN/A{
7998948SN/A    if (!pkt->isPrint()) {
8008948SN/A        // don't do DPRINTFs on PrintReq as it clutters up the output
80110405Sandreas.hansson@arm.com        DPRINTF(CoherentXBar,
8028949SN/A                "recvFunctionalSnoop: packet src %s addr 0x%x cmd %s\n",
8039032SN/A                masterPorts[master_port_id]->name(), pkt->getAddr(),
8048948SN/A                pkt->cmdString());
8058948SN/A    }
8068948SN/A
8078948SN/A    // forward to all snoopers
8089031SN/A    forwardFunctional(pkt, InvalidPortID);
8098948SN/A}
8108948SN/A
8118948SN/Avoid
81210405Sandreas.hansson@arm.comCoherentXBar::forwardFunctional(PacketPtr pkt, PortID exclude_slave_port_id)
8138948SN/A{
8149524SN/A    // snoops should only happen if the system isn't bypassing caches
8159524SN/A    assert(!system->bypassCaches());
8169524SN/A
81710405Sandreas.hansson@arm.com    for (const auto& p: snoopPorts) {
8188915SN/A        // we could have gotten this request from a snooping master
8198915SN/A        // (corresponding to our own slave port that is also in
8208915SN/A        // snoopPorts) and should not send it back to where it came
8218915SN/A        // from
8229031SN/A        if (exclude_slave_port_id == InvalidPortID ||
8238948SN/A            p->getId() != exclude_slave_port_id)
8248948SN/A            p->sendFunctionalSnoop(pkt);
8258915SN/A
8268948SN/A        // if we get a response we are done
8278948SN/A        if (pkt->isResponse()) {
8288948SN/A            break;
8298915SN/A        }
8303650SN/A    }
8312497SN/A}
8322497SN/A
8339092SN/Aunsigned int
83410405Sandreas.hansson@arm.comCoherentXBar::drain(DrainManager *dm)
8359092SN/A{
8369093SN/A    // sum up the individual layers
8379715SN/A    unsigned int total = 0;
83810405Sandreas.hansson@arm.com    for (auto l: reqLayers)
83910405Sandreas.hansson@arm.com        total += l->drain(dm);
84010405Sandreas.hansson@arm.com    for (auto l: respLayers)
84110405Sandreas.hansson@arm.com        total += l->drain(dm);
84210405Sandreas.hansson@arm.com    for (auto l: snoopLayers)
84310405Sandreas.hansson@arm.com        total += l->drain(dm);
8449715SN/A    return total;
8459092SN/A}
8469092SN/A
8479712SN/Avoid
84810405Sandreas.hansson@arm.comCoherentXBar::regStats()
8499712SN/A{
85010405Sandreas.hansson@arm.com    // register the stats of the base class and our layers
85110405Sandreas.hansson@arm.com    BaseXBar::regStats();
85210405Sandreas.hansson@arm.com    for (auto l: reqLayers)
85310405Sandreas.hansson@arm.com        l->regStats();
85410405Sandreas.hansson@arm.com    for (auto l: respLayers)
85510405Sandreas.hansson@arm.com        l->regStats();
85610405Sandreas.hansson@arm.com    for (auto l: snoopLayers)
85710405Sandreas.hansson@arm.com        l->regStats();
8589712SN/A
85910405Sandreas.hansson@arm.com    snoops
86010405Sandreas.hansson@arm.com        .name(name() + ".snoops")
86110401SN/A        .desc("Total snoops (count)")
86210401SN/A    ;
86310401SN/A
86410401SN/A    snoopFanout
86510401SN/A        .init(0, snoopPorts.size(), 1)
86610401SN/A        .name(name() + ".snoop_fanout")
86710401SN/A        .desc("Request fanout histogram")
86810401SN/A    ;
8699712SN/A}
8709712SN/A
87110405Sandreas.hansson@arm.comCoherentXBar *
87210405Sandreas.hansson@arm.comCoherentXBarParams::create()
8732497SN/A{
87410405Sandreas.hansson@arm.com    return new CoherentXBar(this);
8752497SN/A}
876