xbar.cc revision 10713
12497SN/A/*
210713Sandreas.hansson@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"
539152SN/A#include "debug/Drain.hh"
5410405Sandreas.hansson@arm.com#include "debug/XBar.hh"
5510405Sandreas.hansson@arm.com#include "mem/xbar.hh"
562497SN/A
5710405Sandreas.hansson@arm.comBaseXBar::BaseXBar(const BaseXBarParams *p)
589157SN/A    : MemObject(p),
599091SN/A      headerCycles(p->header_cycles), width(p->width),
609279SN/A      gotAddrRanges(p->port_default_connection_count +
619279SN/A                          p->port_master_connection_count, false),
629279SN/A      gotAllAddrRanges(false), defaultPortID(InvalidPortID),
639814SN/A      useDefaultRange(p->use_default_range)
649240SN/A{}
658851SN/A
6610405Sandreas.hansson@arm.comBaseXBar::~BaseXBar()
679036SN/A{
6810405Sandreas.hansson@arm.com    for (auto m: masterPorts)
6910405Sandreas.hansson@arm.com        delete m;
708851SN/A
7110405Sandreas.hansson@arm.com    for (auto s: slavePorts)
7210405Sandreas.hansson@arm.com        delete s;
737523SN/A}
747523SN/A
759278SN/Avoid
7610405Sandreas.hansson@arm.comBaseXBar::init()
779278SN/A{
789278SN/A}
799278SN/A
809294SN/ABaseMasterPort &
8110405Sandreas.hansson@arm.comBaseXBar::getMasterPort(const std::string &if_name, PortID idx)
822640SN/A{
838948SN/A    if (if_name == "master" && idx < masterPorts.size()) {
848948SN/A        // the master port index translates directly to the vector position
858922SN/A        return *masterPorts[idx];
868851SN/A    } else  if (if_name == "default") {
879031SN/A        return *masterPorts[defaultPortID];
888715SN/A    } else {
898922SN/A        return MemObject::getMasterPort(if_name, idx);
908922SN/A    }
918922SN/A}
928922SN/A
939294SN/ABaseSlavePort &
9410405Sandreas.hansson@arm.comBaseXBar::getSlavePort(const std::string &if_name, PortID idx)
958922SN/A{
968948SN/A    if (if_name == "slave" && idx < slavePorts.size()) {
978948SN/A        // the slave port index translates directly to the vector position
988948SN/A        return *slavePorts[idx];
998922SN/A    } else {
1008922SN/A        return MemObject::getSlavePort(if_name, idx);
1013489SN/A    }
1022640SN/A}
1032640SN/A
1049547SN/Avoid
10510405Sandreas.hansson@arm.comBaseXBar::calcPacketTiming(PacketPtr pkt)
1062497SN/A{
10710405Sandreas.hansson@arm.com    // the crossbar will be called at a time that is not necessarily
1089547SN/A    // coinciding with its own clock, so start by determining how long
1099547SN/A    // until the next clock edge (could be zero)
1109648SN/A    Tick offset = clockEdge() - curTick();
1115354SN/A
11210694SMarco.Balboni@ARM.com    // Determine how many cycles are needed to send the data
11310694SMarco.Balboni@ARM.com    // If the packet has no data we take into account just the cycle to send
11410694SMarco.Balboni@ARM.com    // the header.
1159547SN/A    unsigned dataCycles = pkt->hasData() ? divCeil(pkt->getSize(), width) : 0;
1163210SN/A
1179549SN/A    // before setting the bus delay fields of the packet, ensure that
11810405Sandreas.hansson@arm.com    // the delay from any previous crossbar has been accounted for
11910694SMarco.Balboni@ARM.com    if (pkt->headerDelay != 0 || pkt->payloadDelay != 0)
12010405Sandreas.hansson@arm.com        panic("Packet %s already has delay (%d, %d) that should be "
12110694SMarco.Balboni@ARM.com              "accounted for.\n", pkt->cmdString(), pkt->headerDelay,
12210694SMarco.Balboni@ARM.com              pkt->payloadDelay);
1239549SN/A
12410694SMarco.Balboni@ARM.com    // The headerDelay takes into account the relative time to deliver the
12510694SMarco.Balboni@ARM.com    // header of the packet. It will be charged of the additional delay of
12610694SMarco.Balboni@ARM.com    // the xbar if the packet goes through it.
12710694SMarco.Balboni@ARM.com    pkt->headerDelay = (headerCycles + 1) * clockPeriod() + offset;
1283218SN/A
12910694SMarco.Balboni@ARM.com    // The payloadDelay takes into account the relative time to deliver the
13010694SMarco.Balboni@ARM.com    // payload of the packet. If the packet has no data its value is just one
13110694SMarco.Balboni@ARM.com    // tick (due to header) plus the offset value.
13210694SMarco.Balboni@ARM.com    pkt->payloadDelay = (headerCycles + dataCycles) * clockPeriod() + offset;
1335354SN/A}
1345354SN/A
1359715SN/Atemplate <typename SrcType, typename DstType>
13610405Sandreas.hansson@arm.comBaseXBar::Layer<SrcType,DstType>::Layer(DstType& _port, BaseXBar& _xbar,
1379715SN/A                                       const std::string& _name) :
13810405Sandreas.hansson@arm.com    port(_port), xbar(_xbar), _name(_name), state(IDLE), drainManager(NULL),
13910347SN/A    waitingForPeer(NULL), releaseEvent(this)
1409092SN/A{
1419092SN/A}
1429092SN/A
1439715SN/Atemplate <typename SrcType, typename DstType>
14410405Sandreas.hansson@arm.comvoid BaseXBar::Layer<SrcType,DstType>::occupyLayer(Tick until)
1455354SN/A{
14610405Sandreas.hansson@arm.com    // ensure the state is busy at this point, as the layer should
1479612SN/A    // transition from idle as soon as it has decided to forward the
1489612SN/A    // packet to prevent any follow-on calls to sendTiming seeing an
14910405Sandreas.hansson@arm.com    // unoccupied layer
1509612SN/A    assert(state == BUSY);
1515354SN/A
15210405Sandreas.hansson@arm.com    // until should never be 0 as express snoops never occupy the layer
1539091SN/A    assert(until != 0);
15410405Sandreas.hansson@arm.com    xbar.schedule(releaseEvent, until);
1559091SN/A
1569712SN/A    // account for the occupied ticks
1579712SN/A    occupancy += until - curTick();
1589712SN/A
15910405Sandreas.hansson@arm.com    DPRINTF(BaseXBar, "The crossbar layer is now busy from tick %d to %d\n",
1609091SN/A            curTick(), until);
1613244SN/A}
1623244SN/A
1639715SN/Atemplate <typename SrcType, typename DstType>
1648948SN/Abool
16510405Sandreas.hansson@arm.comBaseXBar::Layer<SrcType,DstType>::tryTiming(SrcType* src_port)
1668948SN/A{
1679716SN/A    // if we are in the retry state, we will not see anything but the
1689716SN/A    // retrying port (or in the case of the snoop ports the snoop
1699716SN/A    // response port that mirrors the actual slave port) as we leave
1709716SN/A    // this state again in zero time if the peer does not immediately
17110405Sandreas.hansson@arm.com    // call the layer when receiving the retry
1729716SN/A
1739716SN/A    // first we see if the layer is busy, next we check if the
1749716SN/A    // destination port is already engaged in a transaction waiting
1759716SN/A    // for a retry from the peer
1769716SN/A    if (state == BUSY || waitingForPeer != NULL) {
1779716SN/A        // the port should not be waiting already
1789716SN/A        assert(std::find(waitingForLayer.begin(), waitingForLayer.end(),
1799716SN/A                         src_port) == waitingForLayer.end());
1809716SN/A
1819612SN/A        // put the port at the end of the retry list waiting for the
1829612SN/A        // layer to be freed up (and in the case of a busy peer, for
18310405Sandreas.hansson@arm.com        // that transaction to go through, and then the layer to free
1849612SN/A        // up)
1859715SN/A        waitingForLayer.push_back(src_port);
1869091SN/A        return false;
1878948SN/A    }
1889091SN/A
1899612SN/A    state = BUSY;
1909611SN/A
1919091SN/A    return true;
1928948SN/A}
1938948SN/A
1949715SN/Atemplate <typename SrcType, typename DstType>
1958975SN/Avoid
19610405Sandreas.hansson@arm.comBaseXBar::Layer<SrcType,DstType>::succeededTiming(Tick busy_time)
1978948SN/A{
1989612SN/A    // we should have gone from idle or retry to busy in the tryTiming
1999612SN/A    // test
2009091SN/A    assert(state == BUSY);
2019091SN/A
20210405Sandreas.hansson@arm.com    // occupy the layer accordingly
2039092SN/A    occupyLayer(busy_time);
2049091SN/A}
2059091SN/A
2069715SN/Atemplate <typename SrcType, typename DstType>
2079091SN/Avoid
20810405Sandreas.hansson@arm.comBaseXBar::Layer<SrcType,DstType>::failedTiming(SrcType* src_port,
2099715SN/A                                              Tick busy_time)
2109091SN/A{
2119612SN/A    // ensure no one got in between and tried to send something to
2129612SN/A    // this port
2139715SN/A    assert(waitingForPeer == NULL);
2149091SN/A
2159612SN/A    // if the source port is the current retrying one or not, we have
2169612SN/A    // failed in forwarding and should track that we are now waiting
2179612SN/A    // for the peer to send a retry
2189715SN/A    waitingForPeer = src_port;
2199612SN/A
2209612SN/A    // we should have gone from idle or retry to busy in the tryTiming
2219612SN/A    // test
2229612SN/A    assert(state == BUSY);
2239091SN/A
2249091SN/A    // occupy the bus accordingly
2259092SN/A    occupyLayer(busy_time);
2268948SN/A}
2278948SN/A
2289715SN/Atemplate <typename SrcType, typename DstType>
2298948SN/Avoid
23010405Sandreas.hansson@arm.comBaseXBar::Layer<SrcType,DstType>::releaseLayer()
2312657SN/A{
2328915SN/A    // releasing the bus means we should now be idle
2339091SN/A    assert(state == BUSY);
2349092SN/A    assert(!releaseEvent.scheduled());
2359091SN/A
2369091SN/A    // update the state
2379091SN/A    state = IDLE;
2383252SN/A
2399612SN/A    // bus layer is now idle, so if someone is waiting we can retry
2409612SN/A    if (!waitingForLayer.empty()) {
24110347SN/A        // there is no point in sending a retry if someone is still
24210347SN/A        // waiting for the peer
24310347SN/A        if (waitingForPeer == NULL)
24410347SN/A            retryWaiting();
2459710SN/A    } else if (waitingForPeer == NULL && drainManager) {
24610405Sandreas.hansson@arm.com        DPRINTF(Drain, "Crossbar done draining, signaling drain manager\n");
2479091SN/A        //If we weren't able to drain before, do it now.
2489342SN/A        drainManager->signalDrainDone();
2493512SN/A        // Clear the drain event once we're done with it.
2509342SN/A        drainManager = NULL;
2513512SN/A    }
2522657SN/A}
2532657SN/A
2549715SN/Atemplate <typename SrcType, typename DstType>
2558915SN/Avoid
25610405Sandreas.hansson@arm.comBaseXBar::Layer<SrcType,DstType>::retryWaiting()
2578915SN/A{
2589612SN/A    // this should never be called with no one waiting
2599612SN/A    assert(!waitingForLayer.empty());
2608915SN/A
2619091SN/A    // we always go to retrying from idle
2629091SN/A    assert(state == IDLE);
2639091SN/A
2649611SN/A    // update the state
2659091SN/A    state = RETRY;
2668915SN/A
2679611SN/A    // set the retrying port to the front of the retry list and pop it
2689611SN/A    // off the list
26910347SN/A    SrcType* retryingPort = waitingForLayer.front();
2709612SN/A    waitingForLayer.pop_front();
2719611SN/A
2729612SN/A    // tell the port to retry, which in some cases ends up calling the
27310405Sandreas.hansson@arm.com    // layer again
27410713Sandreas.hansson@arm.com    sendRetry(retryingPort);
2758915SN/A
27610405Sandreas.hansson@arm.com    // If the layer is still in the retry state, sendTiming wasn't
2779612SN/A    // called in zero time (e.g. the cache does this), burn a cycle
2789091SN/A    if (state == RETRY) {
2799612SN/A        // update the state to busy and reset the retrying port, we
2809612SN/A        // have done our bit and sent the retry
2819091SN/A        state = BUSY;
2829091SN/A
28310405Sandreas.hansson@arm.com        // occupy the crossbar layer until the next cycle ends
28410405Sandreas.hansson@arm.com        occupyLayer(xbar.clockEdge(Cycles(1)));
2858915SN/A    }
2868915SN/A}
2878915SN/A
2889715SN/Atemplate <typename SrcType, typename DstType>
2898915SN/Avoid
29010405Sandreas.hansson@arm.comBaseXBar::Layer<SrcType,DstType>::recvRetry()
2918915SN/A{
2929612SN/A    // we should never get a retry without having failed to forward
2939612SN/A    // something to this port
2949715SN/A    assert(waitingForPeer != NULL);
2958915SN/A
2969715SN/A    // add the port where the failed packet originated to the front of
2979715SN/A    // the waiting ports for the layer, this allows us to call retry
29810405Sandreas.hansson@arm.com    // on the port immediately if the crossbar layer is idle
2999715SN/A    waitingForLayer.push_front(waitingForPeer);
3009612SN/A
3019715SN/A    // we are no longer waiting for the peer
3029715SN/A    waitingForPeer = NULL;
3039612SN/A
30410405Sandreas.hansson@arm.com    // if the layer is idle, retry this port straight away, if we
3059612SN/A    // are busy, then simply let the port wait for its turn
3069091SN/A    if (state == IDLE) {
3078915SN/A        retryWaiting();
3089612SN/A    } else {
3099612SN/A        assert(state == BUSY);
3108915SN/A    }
3118915SN/A}
3128915SN/A
3139031SN/APortID
31410405Sandreas.hansson@arm.comBaseXBar::findPort(Addr addr)
3152497SN/A{
3169279SN/A    // we should never see any address lookups before we've got the
3179279SN/A    // ranges of all connected slave modules
3189279SN/A    assert(gotAllAddrRanges);
3199279SN/A
3209279SN/A    // Check the cache
3219031SN/A    PortID dest_id = checkPortCache(addr);
3229031SN/A    if (dest_id != InvalidPortID)
3237523SN/A        return dest_id;
3247523SN/A
3259279SN/A    // Check the address map interval tree
32610405Sandreas.hansson@arm.com    auto i = portMap.find(addr);
3277523SN/A    if (i != portMap.end()) {
3287523SN/A        dest_id = i->second;
3299279SN/A        updatePortCache(dest_id, i->first);
3307523SN/A        return dest_id;
3314958SN/A    }
3322846SN/A
3332846SN/A    // Check if this matches the default range
3347523SN/A    if (useDefaultRange) {
3359405SN/A        if (defaultRange.contains(addr)) {
33610405Sandreas.hansson@arm.com            DPRINTF(AddrRanges, "  found addr %#llx on default\n",
3379279SN/A                    addr);
3389279SN/A            return defaultPortID;
3392846SN/A        }
3409031SN/A    } else if (defaultPortID != InvalidPortID) {
34110405Sandreas.hansson@arm.com        DPRINTF(AddrRanges, "Unable to find destination for addr %#llx, "
3428849SN/A                "will use default port\n", addr);
3439031SN/A        return defaultPortID;
3442846SN/A    }
3452846SN/A
3468849SN/A    // we should use the range for the default port and it did not
3478849SN/A    // match, or the default port is not set
34810405Sandreas.hansson@arm.com    fatal("Unable to find destination for addr %#llx on %s\n", addr,
3498849SN/A          name());
3503074SN/A}
3513074SN/A
35210405Sandreas.hansson@arm.com/** Function called by the port when the crossbar is receiving a range change.*/
3532497SN/Avoid
35410405Sandreas.hansson@arm.comBaseXBar::recvRangeChange(PortID master_port_id)
3552497SN/A{
35610405Sandreas.hansson@arm.com    DPRINTF(AddrRanges, "Received range change from slave port %s\n",
3579407SN/A            masterPorts[master_port_id]->getSlavePort().name());
3589407SN/A
3599279SN/A    // remember that we got a range from this master port and thus the
3609279SN/A    // connected slave module
3619279SN/A    gotAddrRanges[master_port_id] = true;
3622846SN/A
3639279SN/A    // update the global flag
3649279SN/A    if (!gotAllAddrRanges) {
3659279SN/A        // take a logical AND of all the ports and see if we got
3669279SN/A        // ranges from everyone
3679279SN/A        gotAllAddrRanges = true;
3689279SN/A        std::vector<bool>::const_iterator r = gotAddrRanges.begin();
3699279SN/A        while (gotAllAddrRanges &&  r != gotAddrRanges.end()) {
3709279SN/A            gotAllAddrRanges &= *r++;
3719279SN/A        }
3729407SN/A        if (gotAllAddrRanges)
37310405Sandreas.hansson@arm.com            DPRINTF(AddrRanges, "Got address ranges from all slaves\n");
3749279SN/A    }
3752534SN/A
3769279SN/A    // note that we could get the range from the default port at any
3779279SN/A    // point in time, and we cannot assume that the default range is
3789279SN/A    // set before the other ones are, so we do additional checks once
3799279SN/A    // all ranges are provided
3809032SN/A    if (master_port_id == defaultPortID) {
3819279SN/A        // only update if we are indeed checking ranges for the
3829279SN/A        // default port since the port might not have a valid range
3839279SN/A        // otherwise
3847523SN/A        if (useDefaultRange) {
3859279SN/A            AddrRangeList ranges = masterPorts[master_port_id]->getAddrRanges();
3869279SN/A
3879279SN/A            if (ranges.size() != 1)
38810405Sandreas.hansson@arm.com                fatal("Crossbar %s may only have a single default range",
3899279SN/A                      name());
3909279SN/A
3919279SN/A            defaultRange = ranges.front();
3929279SN/A        }
3939279SN/A    } else {
3949279SN/A        // the ports are allowed to update their address ranges
3959279SN/A        // dynamically, so remove any existing entries
3969279SN/A        if (gotAddrRanges[master_port_id]) {
39710405Sandreas.hansson@arm.com            for (auto p = portMap.begin(); p != portMap.end(); ) {
3989279SN/A                if (p->second == master_port_id)
3999279SN/A                    // erasing invalidates the iterator, so advance it
4009279SN/A                    // before the deletion takes place
4019279SN/A                    portMap.erase(p++);
4029279SN/A                else
4039279SN/A                    p++;
4043489SN/A            }
4052846SN/A        }
4062565SN/A
4079279SN/A        AddrRangeList ranges = masterPorts[master_port_id]->getAddrRanges();
4082497SN/A
40910405Sandreas.hansson@arm.com        for (const auto& r: ranges) {
41010405Sandreas.hansson@arm.com            DPRINTF(AddrRanges, "Adding range %s for id %d\n",
41110405Sandreas.hansson@arm.com                    r.to_string(), master_port_id);
41210405Sandreas.hansson@arm.com            if (portMap.insert(r, master_port_id) == portMap.end()) {
41310405Sandreas.hansson@arm.com                PortID conflict_id = portMap.find(r)->second;
41410414SCurtis.Dunham@arm.com                fatal("%s has two ports responding within range %s:\n\t%s\n\t%s\n",
4159032SN/A                      name(),
41610414SCurtis.Dunham@arm.com                      r.to_string(),
4179032SN/A                      masterPorts[master_port_id]->getSlavePort().name(),
4188922SN/A                      masterPorts[conflict_id]->getSlavePort().name());
4195490SN/A            }
4202846SN/A        }
4212565SN/A    }
4222568SN/A
4239279SN/A    // if we have received ranges from all our neighbouring slave
4249279SN/A    // modules, go ahead and tell our connected master modules in
4259279SN/A    // turn, this effectively assumes a tree structure of the system
4269279SN/A    if (gotAllAddrRanges) {
42710405Sandreas.hansson@arm.com        DPRINTF(AddrRanges, "Aggregating address ranges\n");
42810405Sandreas.hansson@arm.com        xbarRanges.clear();
4299564SN/A
4309564SN/A        // start out with the default range
4319564SN/A        if (useDefaultRange) {
4329564SN/A            if (!gotAddrRanges[defaultPortID])
43310405Sandreas.hansson@arm.com                fatal("Crossbar %s uses default range, but none provided",
4349564SN/A                      name());
4359564SN/A
43610405Sandreas.hansson@arm.com            xbarRanges.push_back(defaultRange);
43710405Sandreas.hansson@arm.com            DPRINTF(AddrRanges, "-- Adding default %s\n",
4389564SN/A                    defaultRange.to_string());
4399564SN/A        }
4409564SN/A
4419564SN/A        // merge all interleaved ranges and add any range that is not
4429564SN/A        // a subset of the default range
4439564SN/A        std::vector<AddrRange> intlv_ranges;
44410405Sandreas.hansson@arm.com        for (const auto& r: portMap) {
4459564SN/A            // if the range is interleaved then save it for now
44610405Sandreas.hansson@arm.com            if (r.first.interleaved()) {
4479564SN/A                // if we already got interleaved ranges that are not
4489564SN/A                // part of the same range, then first do a merge
4499564SN/A                // before we add the new one
4509564SN/A                if (!intlv_ranges.empty() &&
45110405Sandreas.hansson@arm.com                    !intlv_ranges.back().mergesWith(r.first)) {
45210405Sandreas.hansson@arm.com                    DPRINTF(AddrRanges, "-- Merging range from %d ranges\n",
4539564SN/A                            intlv_ranges.size());
4549564SN/A                    AddrRange merged_range(intlv_ranges);
4559564SN/A                    // next decide if we keep the merged range or not
4569564SN/A                    if (!(useDefaultRange &&
4579564SN/A                          merged_range.isSubset(defaultRange))) {
45810405Sandreas.hansson@arm.com                        xbarRanges.push_back(merged_range);
45910405Sandreas.hansson@arm.com                        DPRINTF(AddrRanges, "-- Adding merged range %s\n",
4609564SN/A                                merged_range.to_string());
4619564SN/A                    }
4629564SN/A                    intlv_ranges.clear();
4639564SN/A                }
46410405Sandreas.hansson@arm.com                intlv_ranges.push_back(r.first);
4659564SN/A            } else {
4669564SN/A                // keep the current range if not a subset of the default
4679564SN/A                if (!(useDefaultRange &&
46810405Sandreas.hansson@arm.com                      r.first.isSubset(defaultRange))) {
46910405Sandreas.hansson@arm.com                    xbarRanges.push_back(r.first);
47010405Sandreas.hansson@arm.com                    DPRINTF(AddrRanges, "-- Adding range %s\n",
47110405Sandreas.hansson@arm.com                            r.first.to_string());
4729564SN/A                }
4739564SN/A            }
4749564SN/A        }
4759564SN/A
4769564SN/A        // if there is still interleaved ranges waiting to be merged,
4779564SN/A        // go ahead and do it
4789564SN/A        if (!intlv_ranges.empty()) {
47910405Sandreas.hansson@arm.com            DPRINTF(AddrRanges, "-- Merging range from %d ranges\n",
4809564SN/A                    intlv_ranges.size());
4819564SN/A            AddrRange merged_range(intlv_ranges);
4829564SN/A            if (!(useDefaultRange && merged_range.isSubset(defaultRange))) {
48310405Sandreas.hansson@arm.com                xbarRanges.push_back(merged_range);
48410405Sandreas.hansson@arm.com                DPRINTF(AddrRanges, "-- Adding merged range %s\n",
4859564SN/A                        merged_range.to_string());
4869564SN/A            }
4879564SN/A        }
4889564SN/A
4899279SN/A        // also check that no range partially overlaps with the
4909279SN/A        // default range, this has to be done after all ranges are set
4919279SN/A        // as there are no guarantees for when the default range is
4929279SN/A        // update with respect to the other ones
4939279SN/A        if (useDefaultRange) {
49410405Sandreas.hansson@arm.com            for (const auto& r: xbarRanges) {
4959564SN/A                // see if the new range is partially
4969564SN/A                // overlapping the default range
49710405Sandreas.hansson@arm.com                if (r.intersects(defaultRange) &&
49810405Sandreas.hansson@arm.com                    !r.isSubset(defaultRange))
4999564SN/A                    fatal("Range %s intersects the "                    \
5009564SN/A                          "default range of %s but is not a "           \
50110405Sandreas.hansson@arm.com                          "subset\n", r.to_string(), name());
5029279SN/A            }
5039279SN/A        }
5049279SN/A
5059279SN/A        // tell all our neighbouring master ports that our address
5069279SN/A        // ranges have changed
50710405Sandreas.hansson@arm.com        for (const auto& s: slavePorts)
50810405Sandreas.hansson@arm.com            s->sendRangeChange();
5099279SN/A    }
5109279SN/A
5119279SN/A    clearPortCache();
5122497SN/A}
5132497SN/A
5148711SN/AAddrRangeList
51510405Sandreas.hansson@arm.comBaseXBar::getAddrRanges() const
5162497SN/A{
5179279SN/A    // we should never be asked without first having sent a range
5189279SN/A    // change, and the latter is only done once we have all the ranges
5199279SN/A    // of the connected devices
5209279SN/A    assert(gotAllAddrRanges);
5212568SN/A
5229407SN/A    // at the moment, this never happens, as there are no cycles in
52310405Sandreas.hansson@arm.com    // the range queries and no devices on the master side of a crossbar
5249407SN/A    // (CPU, cache, bridge etc) actually care about the ranges of the
5259407SN/A    // ports they are connected to
5269407SN/A
52710405Sandreas.hansson@arm.com    DPRINTF(AddrRanges, "Received address range request\n");
5282846SN/A
52910405Sandreas.hansson@arm.com    return xbarRanges;
5308711SN/A}
5318711SN/A
5329712SN/Avoid
53310405Sandreas.hansson@arm.comBaseXBar::regStats()
5349712SN/A{
5359712SN/A    using namespace Stats;
5369712SN/A
5379712SN/A    transDist
5389712SN/A        .init(MemCmd::NUM_MEM_CMDS)
5399712SN/A        .name(name() + ".trans_dist")
5409712SN/A        .desc("Transaction distribution")
5419712SN/A        .flags(nozero);
5429712SN/A
5439712SN/A    // get the string representation of the commands
5449712SN/A    for (int i = 0; i < MemCmd::NUM_MEM_CMDS; i++) {
5459712SN/A        MemCmd cmd(i);
5469712SN/A        const std::string &cstr = cmd.toString();
5479712SN/A        transDist.subname(i, cstr);
5489712SN/A    }
5499712SN/A
5509712SN/A    pktCount
5519712SN/A        .init(slavePorts.size(), masterPorts.size())
5529712SN/A        .name(name() + ".pkt_count")
5539712SN/A        .desc("Packet count per connected master and slave (bytes)")
5549712SN/A        .flags(total | nozero | nonan);
5559712SN/A
55610405Sandreas.hansson@arm.com    pktSize
5579712SN/A        .init(slavePorts.size(), masterPorts.size())
55810405Sandreas.hansson@arm.com        .name(name() + ".pkt_size")
5599712SN/A        .desc("Cumulative packet size per connected master and slave (bytes)")
5609712SN/A        .flags(total | nozero | nonan);
5619712SN/A
5629712SN/A    // both the packet count and total size are two-dimensional
5639712SN/A    // vectors, indexed by slave port id and master port id, thus the
5649712SN/A    // neighbouring master and slave, they do not differentiate what
5659712SN/A    // came from the master and was forwarded to the slave (requests
5669712SN/A    // and snoop responses) and what came from the slave and was
5679712SN/A    // forwarded to the master (responses and snoop requests)
5689712SN/A    for (int i = 0; i < slavePorts.size(); i++) {
5699712SN/A        pktCount.subname(i, slavePorts[i]->getMasterPort().name());
57010405Sandreas.hansson@arm.com        pktSize.subname(i, slavePorts[i]->getMasterPort().name());
5719712SN/A        for (int j = 0; j < masterPorts.size(); j++) {
5729712SN/A            pktCount.ysubname(j, masterPorts[j]->getSlavePort().name());
57310405Sandreas.hansson@arm.com            pktSize.ysubname(j, masterPorts[j]->getSlavePort().name());
5749712SN/A        }
5759712SN/A    }
5769712SN/A}
5779712SN/A
5789715SN/Atemplate <typename SrcType, typename DstType>
5793470SN/Aunsigned int
58010405Sandreas.hansson@arm.comBaseXBar::Layer<SrcType,DstType>::drain(DrainManager *dm)
5813470SN/A{
5823470SN/A    //We should check that we're not "doing" anything, and that noone is
5833470SN/A    //waiting. We might be idle but have someone waiting if the device we
5843470SN/A    //contacted for a retry didn't actually retry.
5859612SN/A    if (state != IDLE) {
58610405Sandreas.hansson@arm.com        DPRINTF(Drain, "Crossbar not drained\n");
5879342SN/A        drainManager = dm;
5883470SN/A        return 1;
5893470SN/A    }
5905057SN/A    return 0;
5913470SN/A}
5929093SN/A
5939715SN/Atemplate <typename SrcType, typename DstType>
5949712SN/Avoid
59510405Sandreas.hansson@arm.comBaseXBar::Layer<SrcType,DstType>::regStats()
5969712SN/A{
5979712SN/A    using namespace Stats;
5989712SN/A
5999712SN/A    occupancy
6009712SN/A        .name(name() + ".occupancy")
6019712SN/A        .desc("Layer occupancy (ticks)")
6029712SN/A        .flags(nozero);
6039712SN/A
6049712SN/A    utilization
6059712SN/A        .name(name() + ".utilization")
6069712SN/A        .desc("Layer utilization (%)")
6079712SN/A        .precision(1)
6089712SN/A        .flags(nozero);
6099712SN/A
6109712SN/A    utilization = 100 * occupancy / simTicks;
6119712SN/A}
6129712SN/A
6139093SN/A/**
61410405Sandreas.hansson@arm.com * Crossbar layer template instantiations. Could be removed with _impl.hh
6159093SN/A * file, but since there are only two given options (MasterPort and
6169093SN/A * SlavePort) it seems a bit excessive at this point.
6179093SN/A */
61810405Sandreas.hansson@arm.comtemplate class BaseXBar::Layer<SlavePort,MasterPort>;
61910405Sandreas.hansson@arm.comtemplate class BaseXBar::Layer<MasterPort,SlavePort>;
620