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
548922Swilliam.wang@arm.com/**
558922Swilliam.wang@arm.com * Master port
568922Swilliam.wang@arm.com */
5713892Sgabeblack@google.comMasterPort::MasterPort(const std::string& name, SimObject* _owner, PortID _id)
5814193Sgabeblack@google.com    : Port(name, _id), _slavePort(NULL), owner(*_owner)
592642Sstever@eecs.umich.edu{
608922Swilliam.wang@arm.com}
615476Snate@binkert.org
628922Swilliam.wang@arm.comMasterPort::~MasterPort()
638922Swilliam.wang@arm.com{
648922Swilliam.wang@arm.com}
658922Swilliam.wang@arm.com
669294Sandreas.hansson@arm.comvoid
6713782Sgabeblack@google.comMasterPort::bind(Port &peer)
688922Swilliam.wang@arm.com{
6913782Sgabeblack@google.com    auto *slave_port = dynamic_cast<SlavePort *>(&peer);
7013782Sgabeblack@google.com    if (!slave_port) {
7113782Sgabeblack@google.com        fatal("Attempt to bind port %s to non-slave port %s.",
7213782Sgabeblack@google.com                name(), peer.name());
7313782Sgabeblack@google.com    }
7413782Sgabeblack@google.com    // master port keeps track of the slave port
7513782Sgabeblack@google.com    _slavePort = slave_port;
7614193Sgabeblack@google.com    Port::bind(peer);
7713782Sgabeblack@google.com    // slave port also keeps track of master port
7813782Sgabeblack@google.com    _slavePort->slaveBind(*this);
792642Sstever@eecs.umich.edu}
802642Sstever@eecs.umich.edu
812642Sstever@eecs.umich.eduvoid
829178Sandreas.hansson@arm.comMasterPort::unbind()
839152Satgutier@umich.edu{
849178Sandreas.hansson@arm.com    if (_slavePort == NULL)
859178Sandreas.hansson@arm.com        panic("Attempting to unbind master port %s that is not connected\n",
869178Sandreas.hansson@arm.com              name());
8713782Sgabeblack@google.com    _slavePort->slaveUnbind();
8814189Sgabeblack@google.com    _slavePort = nullptr;
8914193Sgabeblack@google.com    Port::unbind();
908922Swilliam.wang@arm.com}
918922Swilliam.wang@arm.com
929089Sandreas.hansson@arm.comAddrRangeList
939089Sandreas.hansson@arm.comMasterPort::getAddrRanges() const
949089Sandreas.hansson@arm.com{
959089Sandreas.hansson@arm.com    return _slavePort->getAddrRanges();
969089Sandreas.hansson@arm.com}
979089Sandreas.hansson@arm.com
989087Sandreas.hansson@arm.comvoid
998922Swilliam.wang@arm.comMasterPort::printAddr(Addr a)
1005314Sstever@gmail.com{
10112749Sgiacomo.travaglini@arm.com    auto req = std::make_shared<Request>(
10212749Sgiacomo.travaglini@arm.com        a, 1, 0, Request::funcMasterId);
10312749Sgiacomo.travaglini@arm.com
10412749Sgiacomo.travaglini@arm.com    Packet pkt(req, MemCmd::PrintReq);
1055314Sstever@gmail.com    Packet::PrintReqState prs(std::cerr);
1065314Sstever@gmail.com    pkt.senderState = &prs;
1075314Sstever@gmail.com
1085314Sstever@gmail.com    sendFunctional(&pkt);
1095314Sstever@gmail.com}
1108922Swilliam.wang@arm.com
1118922Swilliam.wang@arm.com/**
1128922Swilliam.wang@arm.com * Slave port
1138922Swilliam.wang@arm.com */
11413892Sgabeblack@google.comSlavePort::SlavePort(const std::string& name, SimObject* _owner, PortID id)
11514193Sgabeblack@google.com    : Port(name, id), _masterPort(NULL), defaultBackdoorWarned(false),
11613845Sgabeblack@google.com    owner(*_owner)
1178922Swilliam.wang@arm.com{
1188922Swilliam.wang@arm.com}
1198922Swilliam.wang@arm.com
1208922Swilliam.wang@arm.comSlavePort::~SlavePort()
1218922Swilliam.wang@arm.com{
1228922Swilliam.wang@arm.com}
1238922Swilliam.wang@arm.com
1248922Swilliam.wang@arm.comvoid
12513782Sgabeblack@google.comSlavePort::slaveUnbind()
1269152Satgutier@umich.edu{
1279152Satgutier@umich.edu    _masterPort = NULL;
12814193Sgabeblack@google.com    Port::unbind();
1299152Satgutier@umich.edu}
1309152Satgutier@umich.edu
1319152Satgutier@umich.eduvoid
13213782Sgabeblack@google.comSlavePort::slaveBind(MasterPort& master_port)
1338922Swilliam.wang@arm.com{
1348922Swilliam.wang@arm.com    _masterPort = &master_port;
13514193Sgabeblack@google.com    Port::bind(master_port);
1368922Swilliam.wang@arm.com}
1378922Swilliam.wang@arm.com
1388948Sandreas.hansson@arm.comTick
13913845Sgabeblack@google.comSlavePort::recvAtomicBackdoor(PacketPtr pkt, MemBackdoorPtr &backdoor)
14013845Sgabeblack@google.com{
14113845Sgabeblack@google.com    if (!defaultBackdoorWarned) {
14213845Sgabeblack@google.com        warn("Port %s doesn't support requesting a back door.", name());
14313845Sgabeblack@google.com        defaultBackdoorWarned = true;
14413845Sgabeblack@google.com    }
14513845Sgabeblack@google.com    return recvAtomic(pkt);
14613845Sgabeblack@google.com}
147