port.cc revision 14189
12405SN/A/*
212342Snikos.nikoleris@arm.com * Copyright (c) 2012,2015,2017 ARM Limited
38922Swilliam.wang@arm.com * All rights reserved
48922Swilliam.wang@arm.com *
58922Swilliam.wang@arm.com * The license below extends only to copyright in the software and shall
68922Swilliam.wang@arm.com * not be construed as granting a license to any other intellectual
78922Swilliam.wang@arm.com * property including but not limited to intellectual property relating
88922Swilliam.wang@arm.com * to a hardware implementation of the functionality of the software
98922Swilliam.wang@arm.com * licensed hereunder.  You may use the software subject to the license
108922Swilliam.wang@arm.com * terms below provided that you ensure that this notice is replicated
118922Swilliam.wang@arm.com * unmodified and in its entirety in all distributions of the software,
128922Swilliam.wang@arm.com * modified or unmodified, in source code or in binary form.
138922Swilliam.wang@arm.com *
142405SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan
152405SN/A * All rights reserved.
162405SN/A *
172405SN/A * Redistribution and use in source and binary forms, with or without
182405SN/A * modification, are permitted provided that the following conditions are
192405SN/A * met: redistributions of source code must retain the above copyright
202405SN/A * notice, this list of conditions and the following disclaimer;
212405SN/A * redistributions in binary form must reproduce the above copyright
222405SN/A * notice, this list of conditions and the following disclaimer in the
232405SN/A * documentation and/or other materials provided with the distribution;
242405SN/A * neither the name of the copyright holders nor the names of its
252405SN/A * contributors may be used to endorse or promote products derived from
262405SN/A * this software without specific prior written permission.
272405SN/A *
282405SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
292405SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
302405SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
312405SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
322405SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
332405SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
342405SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
352405SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
362405SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
372405SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
382405SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
392665Ssaidi@eecs.umich.edu *
402665Ssaidi@eecs.umich.edu * Authors: Steve Reinhardt
418922Swilliam.wang@arm.com *          Andreas Hansson
428922Swilliam.wang@arm.com *          William Wang
432405SN/A */
442405SN/A
452405SN/A/**
462982Sstever@eecs.umich.edu * @file
472982Sstever@eecs.umich.edu * Port object definitions.
482405SN/A */
4911793Sbrandon.potter@amd.com#include "mem/port.hh"
5011793Sbrandon.potter@amd.com
512642Sstever@eecs.umich.edu#include "base/trace.hh"
5213892Sgabeblack@google.com#include "sim/sim_object.hh"
532405SN/A
5413769Sgabeblack@google.comBaseMasterPort::BaseMasterPort(const std::string &name, PortID _id)
5513769Sgabeblack@google.com    : Port(name, _id), _baseSlavePort(NULL)
569294Sandreas.hansson@arm.com{
579294Sandreas.hansson@arm.com}
589294Sandreas.hansson@arm.com
599294Sandreas.hansson@arm.comBaseMasterPort::~BaseMasterPort()
609294Sandreas.hansson@arm.com{
619294Sandreas.hansson@arm.com}
629294Sandreas.hansson@arm.com
639294Sandreas.hansson@arm.comBaseSlavePort&
649294Sandreas.hansson@arm.comBaseMasterPort::getSlavePort() const
659294Sandreas.hansson@arm.com{
6611321Ssteve.reinhardt@amd.com    if (_baseSlavePort == NULL)
679294Sandreas.hansson@arm.com        panic("Cannot getSlavePort on master port %s that is not connected\n",
689294Sandreas.hansson@arm.com              name());
699294Sandreas.hansson@arm.com
709294Sandreas.hansson@arm.com    return *_baseSlavePort;
719294Sandreas.hansson@arm.com}
729294Sandreas.hansson@arm.com
7314189Sgabeblack@google.comvoid
7414189Sgabeblack@google.comBaseMasterPort::bind(Port &peer)
7514189Sgabeblack@google.com{
7614189Sgabeblack@google.com    _baseSlavePort = dynamic_cast<BaseSlavePort *>(&peer);
7714189Sgabeblack@google.com    fatal_if(!_baseSlavePort, "Attempt to bind port %s to non-master port %s.",
7814189Sgabeblack@google.com             name(), peer.name());
7914189Sgabeblack@google.com    Port::bind(peer);
8014189Sgabeblack@google.com}
8114189Sgabeblack@google.com
8214189Sgabeblack@google.comvoid
8314189Sgabeblack@google.comBaseMasterPort::unbind()
8414189Sgabeblack@google.com{
8514189Sgabeblack@google.com    _baseSlavePort = nullptr;
8614189Sgabeblack@google.com    Port::unbind();
8714189Sgabeblack@google.com}
8814189Sgabeblack@google.com
8913769Sgabeblack@google.comBaseSlavePort::BaseSlavePort(const std::string &name, PortID _id)
9013769Sgabeblack@google.com    : Port(name, _id), _baseMasterPort(NULL)
919294Sandreas.hansson@arm.com{
929294Sandreas.hansson@arm.com}
939294Sandreas.hansson@arm.com
949294Sandreas.hansson@arm.comBaseSlavePort::~BaseSlavePort()
959294Sandreas.hansson@arm.com{
969294Sandreas.hansson@arm.com}
979294Sandreas.hansson@arm.com
989294Sandreas.hansson@arm.comBaseMasterPort&
999294Sandreas.hansson@arm.comBaseSlavePort::getMasterPort() const
1009294Sandreas.hansson@arm.com{
10111321Ssteve.reinhardt@amd.com    if (_baseMasterPort == NULL)
1029294Sandreas.hansson@arm.com        panic("Cannot getMasterPort on slave port %s that is not connected\n",
1039294Sandreas.hansson@arm.com              name());
1049294Sandreas.hansson@arm.com
1059294Sandreas.hansson@arm.com    return *_baseMasterPort;
1069294Sandreas.hansson@arm.com}
1079294Sandreas.hansson@arm.com
10814189Sgabeblack@google.comvoid
10914189Sgabeblack@google.comBaseSlavePort::bind(Port &peer)
11014189Sgabeblack@google.com{
11114189Sgabeblack@google.com    _baseMasterPort = dynamic_cast<BaseMasterPort *>(&peer);
11214189Sgabeblack@google.com    fatal_if(!_baseMasterPort, "Attempt to bind port %s to non-slave port %s.",
11314189Sgabeblack@google.com             name(), peer.name());
11414189Sgabeblack@google.com    Port::bind(peer);
11514189Sgabeblack@google.com}
11614189Sgabeblack@google.com
11714189Sgabeblack@google.comvoid
11814189Sgabeblack@google.comBaseSlavePort::unbind()
11914189Sgabeblack@google.com{
12014189Sgabeblack@google.com    _baseMasterPort = nullptr;
12114189Sgabeblack@google.com    Port::unbind();
12214189Sgabeblack@google.com}
12314189Sgabeblack@google.com
1248922Swilliam.wang@arm.com/**
1258922Swilliam.wang@arm.com * Master port
1268922Swilliam.wang@arm.com */
12713892Sgabeblack@google.comMasterPort::MasterPort(const std::string& name, SimObject* _owner, PortID _id)
12813769Sgabeblack@google.com    : BaseMasterPort(name, _id), _slavePort(NULL), owner(*_owner)
1292642Sstever@eecs.umich.edu{
1308922Swilliam.wang@arm.com}
1315476Snate@binkert.org
1328922Swilliam.wang@arm.comMasterPort::~MasterPort()
1338922Swilliam.wang@arm.com{
1348922Swilliam.wang@arm.com}
1358922Swilliam.wang@arm.com
1369294Sandreas.hansson@arm.comvoid
13713782Sgabeblack@google.comMasterPort::bind(Port &peer)
1388922Swilliam.wang@arm.com{
13913782Sgabeblack@google.com    auto *slave_port = dynamic_cast<SlavePort *>(&peer);
14013782Sgabeblack@google.com    if (!slave_port) {
14113782Sgabeblack@google.com        fatal("Attempt to bind port %s to non-slave port %s.",
14213782Sgabeblack@google.com                name(), peer.name());
14313782Sgabeblack@google.com    }
14413782Sgabeblack@google.com    // master port keeps track of the slave port
14513782Sgabeblack@google.com    _slavePort = slave_port;
14614189Sgabeblack@google.com    BaseMasterPort::bind(peer);
14713782Sgabeblack@google.com    // slave port also keeps track of master port
14813782Sgabeblack@google.com    _slavePort->slaveBind(*this);
1492642Sstever@eecs.umich.edu}
1502642Sstever@eecs.umich.edu
1512642Sstever@eecs.umich.eduvoid
1529178Sandreas.hansson@arm.comMasterPort::unbind()
1539152Satgutier@umich.edu{
1549178Sandreas.hansson@arm.com    if (_slavePort == NULL)
1559178Sandreas.hansson@arm.com        panic("Attempting to unbind master port %s that is not connected\n",
1569178Sandreas.hansson@arm.com              name());
15713782Sgabeblack@google.com    _slavePort->slaveUnbind();
15814189Sgabeblack@google.com    _slavePort = nullptr;
15914189Sgabeblack@google.com    BaseMasterPort::unbind();
1608922Swilliam.wang@arm.com}
1618922Swilliam.wang@arm.com
1629089Sandreas.hansson@arm.comAddrRangeList
1639089Sandreas.hansson@arm.comMasterPort::getAddrRanges() const
1649089Sandreas.hansson@arm.com{
1659089Sandreas.hansson@arm.com    return _slavePort->getAddrRanges();
1669089Sandreas.hansson@arm.com}
1679089Sandreas.hansson@arm.com
1689087Sandreas.hansson@arm.comvoid
1698922Swilliam.wang@arm.comMasterPort::printAddr(Addr a)
1705314Sstever@gmail.com{
17112749Sgiacomo.travaglini@arm.com    auto req = std::make_shared<Request>(
17212749Sgiacomo.travaglini@arm.com        a, 1, 0, Request::funcMasterId);
17312749Sgiacomo.travaglini@arm.com
17412749Sgiacomo.travaglini@arm.com    Packet pkt(req, MemCmd::PrintReq);
1755314Sstever@gmail.com    Packet::PrintReqState prs(std::cerr);
1765314Sstever@gmail.com    pkt.senderState = &prs;
1775314Sstever@gmail.com
1785314Sstever@gmail.com    sendFunctional(&pkt);
1795314Sstever@gmail.com}
1808922Swilliam.wang@arm.com
1818922Swilliam.wang@arm.com/**
1828922Swilliam.wang@arm.com * Slave port
1838922Swilliam.wang@arm.com */
18413892Sgabeblack@google.comSlavePort::SlavePort(const std::string& name, SimObject* _owner, PortID id)
18513845Sgabeblack@google.com    : BaseSlavePort(name, id), _masterPort(NULL), defaultBackdoorWarned(false),
18613845Sgabeblack@google.com    owner(*_owner)
1878922Swilliam.wang@arm.com{
1888922Swilliam.wang@arm.com}
1898922Swilliam.wang@arm.com
1908922Swilliam.wang@arm.comSlavePort::~SlavePort()
1918922Swilliam.wang@arm.com{
1928922Swilliam.wang@arm.com}
1938922Swilliam.wang@arm.com
1948922Swilliam.wang@arm.comvoid
19513782Sgabeblack@google.comSlavePort::slaveUnbind()
1969152Satgutier@umich.edu{
1979152Satgutier@umich.edu    _masterPort = NULL;
19814189Sgabeblack@google.com    BaseSlavePort::unbind();
1999152Satgutier@umich.edu}
2009152Satgutier@umich.edu
2019152Satgutier@umich.eduvoid
20213782Sgabeblack@google.comSlavePort::slaveBind(MasterPort& master_port)
2038922Swilliam.wang@arm.com{
2048922Swilliam.wang@arm.com    _masterPort = &master_port;
20514189Sgabeblack@google.com    BaseSlavePort::bind(master_port);
2068922Swilliam.wang@arm.com}
2078922Swilliam.wang@arm.com
2088948Sandreas.hansson@arm.comTick
20913845Sgabeblack@google.comSlavePort::recvAtomicBackdoor(PacketPtr pkt, MemBackdoorPtr &backdoor)
21013845Sgabeblack@google.com{
21113845Sgabeblack@google.com    if (!defaultBackdoorWarned) {
21213845Sgabeblack@google.com        warn("Port %s doesn't support requesting a back door.", name());
21313845Sgabeblack@google.com        defaultBackdoorWarned = true;
21413845Sgabeblack@google.com    }
21513845Sgabeblack@google.com    return recvAtomic(pkt);
21613845Sgabeblack@google.com}
217