port.cc revision 13769:b8f532287e81
12068SN/A/*
22068SN/A * Copyright (c) 2012,2015,2017 ARM Limited
32068SN/A * All rights reserved
42068SN/A *
52068SN/A * The license below extends only to copyright in the software and shall
62068SN/A * not be construed as granting a license to any other intellectual
72068SN/A * property including but not limited to intellectual property relating
82068SN/A * to a hardware implementation of the functionality of the software
92068SN/A * licensed hereunder.  You may use the software subject to the license
102068SN/A * terms below provided that you ensure that this notice is replicated
112068SN/A * unmodified and in its entirety in all distributions of the software,
122068SN/A * modified or unmodified, in source code or in binary form.
132068SN/A *
142068SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan
152068SN/A * All rights reserved.
162068SN/A *
172068SN/A * Redistribution and use in source and binary forms, with or without
182068SN/A * modification, are permitted provided that the following conditions are
192068SN/A * met: redistributions of source code must retain the above copyright
202068SN/A * notice, this list of conditions and the following disclaimer;
212068SN/A * redistributions in binary form must reproduce the above copyright
222068SN/A * notice, this list of conditions and the following disclaimer in the
232068SN/A * documentation and/or other materials provided with the distribution;
242068SN/A * neither the name of the copyright holders nor the names of its
252068SN/A * contributors may be used to endorse or promote products derived from
262068SN/A * this software without specific prior written permission.
272068SN/A *
282665Ssaidi@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
292665Ssaidi@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
302665Ssaidi@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
312068SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
322649Ssaidi@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
332649Ssaidi@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
342649Ssaidi@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
352649Ssaidi@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
362649Ssaidi@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
372068SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
382068SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
392068SN/A *
402068SN/A * Authors: Steve Reinhardt
412068SN/A *          Andreas Hansson
422068SN/A *          William Wang
432068SN/A */
442068SN/A
452068SN/A/**
465736Snate@binkert.org * @file
472068SN/A * Port object definitions.
482068SN/A */
496181Sksewell@umich.edu#include "mem/port.hh"
506181Sksewell@umich.edu
512068SN/A#include "base/trace.hh"
522068SN/A#include "mem/mem_object.hh"
532068SN/A
542068SN/APort::Port(const std::string &_name, PortID _id)
552068SN/A    : portName(_name), id(_id)
562068SN/A{
572068SN/A}
582068SN/A
592068SN/APort::~Port()
602068SN/A{
612068SN/A}
622068SN/A
632068SN/ABaseMasterPort::BaseMasterPort(const std::string &name, PortID _id)
642068SN/A    : Port(name, _id), _baseSlavePort(NULL)
652068SN/A{
662068SN/A}
672068SN/A
682068SN/ABaseMasterPort::~BaseMasterPort()
696181Sksewell@umich.edu{
706181Sksewell@umich.edu}
712068SN/A
722068SN/ABaseSlavePort&
732068SN/ABaseMasterPort::getSlavePort() const
742068SN/A{
752068SN/A    if (_baseSlavePort == NULL)
762068SN/A        panic("Cannot getSlavePort on master port %s that is not connected\n",
772068SN/A              name());
782068SN/A
792068SN/A    return *_baseSlavePort;
802068SN/A}
812068SN/A
822068SN/Abool
832068SN/ABaseMasterPort::isConnected() const
842068SN/A{
852068SN/A    return _baseSlavePort != NULL;
866181Sksewell@umich.edu}
876181Sksewell@umich.edu
882068SN/ABaseSlavePort::BaseSlavePort(const std::string &name, PortID _id)
892068SN/A    : Port(name, _id), _baseMasterPort(NULL)
902068SN/A{
912068SN/A}
922068SN/A
932068SN/ABaseSlavePort::~BaseSlavePort()
942068SN/A{
952068SN/A}
962068SN/A
972068SN/ABaseMasterPort&
982068SN/ABaseSlavePort::getMasterPort() const
992068SN/A{
1002068SN/A    if (_baseMasterPort == NULL)
1012068SN/A        panic("Cannot getMasterPort on slave port %s that is not connected\n",
1022068SN/A              name());
1032068SN/A
1042068SN/A    return *_baseMasterPort;
1052068SN/A}
1062068SN/A
1072068SN/Abool
1082068SN/ABaseSlavePort::isConnected() const
1092068SN/A{
1102068SN/A    return _baseMasterPort != NULL;
1112068SN/A}
1122068SN/A
1133953Sstever@eecs.umich.edu/**
1142068SN/A * Master port
1152068SN/A */
1162068SN/AMasterPort::MasterPort(const std::string& name, MemObject* _owner, PortID _id)
1172068SN/A    : BaseMasterPort(name, _id), _slavePort(NULL), owner(*_owner)
1182068SN/A{
1192068SN/A}
1202068SN/A
1212068SN/AMasterPort::~MasterPort()
1222068SN/A{
1232068SN/A}
1242068SN/A
1252068SN/Avoid
1262068SN/AMasterPort::bind(BaseSlavePort& slave_port)
1272068SN/A{
1282068SN/A    // bind on the level of the base ports
1292068SN/A    _baseSlavePort = &slave_port;
1302227SN/A
1312068SN/A    // also attempt to base the slave to the appropriate type
1322068SN/A    SlavePort* cast_slave_port = dynamic_cast<SlavePort*>(&slave_port);
1332095SN/A
1346181Sksewell@umich.edu    // if this port is compatible, then proceed with the binding
1356181Sksewell@umich.edu    if (cast_slave_port != NULL) {
1362095SN/A        // master port keeps track of the slave port
1372095SN/A        _slavePort = cast_slave_port;
1382095SN/A        // slave port also keeps track of master port
1392068SN/A        _slavePort->bind(*this);
1402068SN/A    } else {
1412068SN/A        fatal("Master port %s cannot bind to %s\n", name(),
1422095SN/A              slave_port.name());
1436181Sksewell@umich.edu    }
1446181Sksewell@umich.edu}
1456181Sksewell@umich.edu
1466181Sksewell@umich.eduvoid
1472095SN/AMasterPort::unbind()
1482132SN/A{
1492095SN/A    if (_slavePort == NULL)
1502095SN/A        panic("Attempting to unbind master port %s that is not connected\n",
1512095SN/A              name());
1522095SN/A    _slavePort->unbind();
1533349Sbinkertn@umich.edu    _slavePort = NULL;
1542623SN/A    _baseSlavePort = NULL;
1552095SN/A}
1562095SN/A
1576181Sksewell@umich.eduAddrRangeList
1586181Sksewell@umich.eduMasterPort::getAddrRanges() const
1596181Sksewell@umich.edu{
1602068SN/A    return _slavePort->getAddrRanges();
1613953Sstever@eecs.umich.edu}
1622068SN/A
1633953Sstever@eecs.umich.eduTick
1642068SN/AMasterPort::sendAtomic(PacketPtr pkt)
1652068SN/A{
1666181Sksewell@umich.edu    assert(pkt->isRequest());
1676181Sksewell@umich.edu    return _slavePort->recvAtomic(pkt);
1682068SN/A}
1692068SN/A
1702132SN/Avoid
1712068SN/AMasterPort::sendFunctional(PacketPtr pkt)
1722068SN/A{
1732068SN/A    assert(pkt->isRequest());
1742068SN/A    return _slavePort->recvFunctional(pkt);
1753953Sstever@eecs.umich.edu}
1762068SN/A
1772090SN/Abool
1782068SN/AMasterPort::sendTimingReq(PacketPtr pkt)
1792068SN/A{
1802068SN/A    assert(pkt->isRequest());
1812068SN/A    return _slavePort->recvTimingReq(pkt);
1822068SN/A}
1832068SN/A
1842068SN/Abool
1852068SN/AMasterPort::tryTiming(PacketPtr pkt) const
1862068SN/A{
1872069SN/A  assert(pkt->isRequest());
1882132SN/A  return _slavePort->tryTiming(pkt);
1892068SN/A}
1902068SN/A
1912068SN/Abool
1922132SN/AMasterPort::sendTimingSnoopResp(PacketPtr pkt)
1932068SN/A{
1942068SN/A    assert(pkt->isResponse());
1952068SN/A    return _slavePort->recvTimingSnoopResp(pkt);
1962069SN/A}
1972068SN/A
1982068SN/Avoid
1992090SN/AMasterPort::sendRetryResp()
2008442Sgblack@eecs.umich.edu{
2012068SN/A    _slavePort->recvRespRetry();
2022068SN/A}
2032068SN/A
2042090SN/Avoid
2052069SN/AMasterPort::printAddr(Addr a)
2062069SN/A{
2072069SN/A    auto req = std::make_shared<Request>(
2082069SN/A        a, 1, 0, Request::funcMasterId);
2092069SN/A
2102069SN/A    Packet pkt(req, MemCmd::PrintReq);
2112069SN/A    Packet::PrintReqState prs(std::cerr);
2122069SN/A    pkt.senderState = &prs;
2132095SN/A
2142132SN/A    sendFunctional(&pkt);
2152095SN/A}
2162095SN/A
2172095SN/A/**
2182132SN/A * Slave port
2192095SN/A */
2202095SN/ASlavePort::SlavePort(const std::string& name, MemObject* _owner, PortID id)
2212095SN/A    : BaseSlavePort(name, id), _masterPort(NULL), owner(*_owner)
2222095SN/A{
2232095SN/A}
2242095SN/A
2252098SN/ASlavePort::~SlavePort()
2268442Sgblack@eecs.umich.edu{
2272095SN/A}
2282095SN/A
2292095SN/Avoid
2302095SN/ASlavePort::unbind()
2312095SN/A{
2322095SN/A    _baseMasterPort = NULL;
2332095SN/A    _masterPort = NULL;
2342095SN/A}
2353349Sbinkertn@umich.edu
2362095SN/Avoid
2372095SN/ASlavePort::bind(MasterPort& master_port)
2382095SN/A{
2392132SN/A    _baseMasterPort = &master_port;
2402095SN/A    _masterPort = &master_port;
2412095SN/A}
2422506SN/A
2432095SN/ATick
2448442Sgblack@eecs.umich.eduSlavePort::sendAtomicSnoop(PacketPtr pkt)
2452095SN/A{
2462098SN/A    assert(pkt->isRequest());
2472095SN/A    return _masterPort->recvAtomicSnoop(pkt);
2482095SN/A}
2492095SN/A
2502098SN/Avoid
2512095SN/ASlavePort::sendFunctionalSnoop(PacketPtr pkt)
2522095SN/A{
2532095SN/A    assert(pkt->isRequest());
2542095SN/A    return _masterPort->recvFunctionalSnoop(pkt);
2552095SN/A}
2562095SN/A
2572095SN/Abool
2582095SN/ASlavePort::sendTimingResp(PacketPtr pkt)
2592069SN/A{
2602132SN/A    assert(pkt->isResponse());
2612069SN/A    return _masterPort->recvTimingResp(pkt);
2622069SN/A}
2632069SN/A
2642132SN/Avoid
2654027Sstever@eecs.umich.eduSlavePort::sendTimingSnoopReq(PacketPtr pkt)
2664027Sstever@eecs.umich.edu{
2674027Sstever@eecs.umich.edu    assert(pkt->isRequest());
2684027Sstever@eecs.umich.edu    _masterPort->recvTimingSnoopReq(pkt);
2694027Sstever@eecs.umich.edu}
2704027Sstever@eecs.umich.edu
2714027Sstever@eecs.umich.eduvoid
2724027Sstever@eecs.umich.eduSlavePort::sendRetryReq()
2734027Sstever@eecs.umich.edu{
2744027Sstever@eecs.umich.edu    _masterPort->recvReqRetry();
2754027Sstever@eecs.umich.edu}
2768442Sgblack@eecs.umich.edu
2778442Sgblack@eecs.umich.eduvoid
2784027Sstever@eecs.umich.eduSlavePort::sendRetrySnoopResp()
2794027Sstever@eecs.umich.edu{
2804027Sstever@eecs.umich.edu    _masterPort->recvRetrySnoopResp();
2814027Sstever@eecs.umich.edu}
2824027Sstever@eecs.umich.edu