port.cc revision 8922
12405SN/A/*
28922Swilliam.wang@arm.com * Copyright (c) 2012 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 */
492642Sstever@eecs.umich.edu#include "base/trace.hh"
504190Ssaidi@eecs.umich.edu#include "mem/mem_object.hh"
512405SN/A#include "mem/port.hh"
522405SN/A
538922Swilliam.wang@arm.comPort::Port(const std::string &_name, MemObject& _owner)
548709Sandreas.hansson@arm.com    : portName(_name), peer(NULL), owner(_owner)
555476Snate@binkert.org{
565476Snate@binkert.org}
575476Snate@binkert.org
585476Snate@binkert.orgPort::~Port()
595283Sgblack@eecs.umich.edu{
605283Sgblack@eecs.umich.edu}
615283Sgblack@eecs.umich.edu
628922Swilliam.wang@arm.com/**
638922Swilliam.wang@arm.com * Master port
648922Swilliam.wang@arm.com */
658922Swilliam.wang@arm.comMasterPort::MasterPort(const std::string& name, MemObject* owner)
668922Swilliam.wang@arm.com    : Port(name, *owner), _slavePort(NULL)
672642Sstever@eecs.umich.edu{
688922Swilliam.wang@arm.com}
695476Snate@binkert.org
708922Swilliam.wang@arm.comMasterPort::~MasterPort()
718922Swilliam.wang@arm.com{
728922Swilliam.wang@arm.com}
738922Swilliam.wang@arm.com
748922Swilliam.wang@arm.comSlavePort&
758922Swilliam.wang@arm.comMasterPort::getSlavePort() const
768922Swilliam.wang@arm.com{
778922Swilliam.wang@arm.com    if(_slavePort == NULL)
788922Swilliam.wang@arm.com        panic("Cannot getSlavePort on master port %s that is not connected\n",
798922Swilliam.wang@arm.com              name());
808922Swilliam.wang@arm.com
818922Swilliam.wang@arm.com    return *_slavePort;
822642Sstever@eecs.umich.edu}
832642Sstever@eecs.umich.edu
842642Sstever@eecs.umich.eduvoid
858922Swilliam.wang@arm.comMasterPort::bind(SlavePort& slave_port)
865605Snate@binkert.org{
878922Swilliam.wang@arm.com    // master port keeps track of the slave port
888922Swilliam.wang@arm.com    _slavePort = &slave_port;
898922Swilliam.wang@arm.com    peer = &slave_port;
908922Swilliam.wang@arm.com
918922Swilliam.wang@arm.com    // slave port also keeps track of master port
928922Swilliam.wang@arm.com    _slavePort->bind(*this);
935605Snate@binkert.org}
945605Snate@binkert.org
958922Swilliam.wang@arm.combool
968922Swilliam.wang@arm.comMasterPort::isConnected() const
978922Swilliam.wang@arm.com{
988922Swilliam.wang@arm.com    return _slavePort != NULL;
998922Swilliam.wang@arm.com}
1008922Swilliam.wang@arm.com
1018922Swilliam.wang@arm.comunsigned
1028922Swilliam.wang@arm.comMasterPort::peerBlockSize() const
1038922Swilliam.wang@arm.com{
1048922Swilliam.wang@arm.com    return _slavePort->deviceBlockSize();
1058922Swilliam.wang@arm.com}
1068922Swilliam.wang@arm.com
1078922Swilliam.wang@arm.com void
1088922Swilliam.wang@arm.comMasterPort::printAddr(Addr a)
1095314Sstever@gmail.com{
1108832SAli.Saidi@ARM.com    Request req(a, 1, 0, Request::funcMasterId);
1115314Sstever@gmail.com    Packet pkt(&req, MemCmd::PrintReq, Packet::Broadcast);
1125314Sstever@gmail.com    Packet::PrintReqState prs(std::cerr);
1135314Sstever@gmail.com    pkt.senderState = &prs;
1145314Sstever@gmail.com
1155314Sstever@gmail.com    sendFunctional(&pkt);
1165314Sstever@gmail.com}
1178922Swilliam.wang@arm.com
1188922Swilliam.wang@arm.com/**
1198922Swilliam.wang@arm.com * Slave port
1208922Swilliam.wang@arm.com */
1218922Swilliam.wang@arm.comSlavePort::SlavePort(const std::string& name, MemObject* owner)
1228922Swilliam.wang@arm.com    : Port(name, *owner), _masterPort(NULL)
1238922Swilliam.wang@arm.com{
1248922Swilliam.wang@arm.com}
1258922Swilliam.wang@arm.com
1268922Swilliam.wang@arm.comSlavePort::~SlavePort()
1278922Swilliam.wang@arm.com{
1288922Swilliam.wang@arm.com}
1298922Swilliam.wang@arm.com
1308922Swilliam.wang@arm.comvoid
1318922Swilliam.wang@arm.comSlavePort::bind(MasterPort& master_port)
1328922Swilliam.wang@arm.com{
1338922Swilliam.wang@arm.com    _masterPort = &master_port;
1348922Swilliam.wang@arm.com    peer = &master_port;
1358922Swilliam.wang@arm.com}
1368922Swilliam.wang@arm.com
1378922Swilliam.wang@arm.comMasterPort&
1388922Swilliam.wang@arm.comSlavePort::getMasterPort() const
1398922Swilliam.wang@arm.com{
1408922Swilliam.wang@arm.com    if (_masterPort == NULL)
1418922Swilliam.wang@arm.com        panic("Cannot getMasterPort on slave port %s that is not connected\n",
1428922Swilliam.wang@arm.com              name());
1438922Swilliam.wang@arm.com
1448922Swilliam.wang@arm.com    return *_masterPort;
1458922Swilliam.wang@arm.com}
1468922Swilliam.wang@arm.com
1478922Swilliam.wang@arm.comunsigned
1488922Swilliam.wang@arm.comSlavePort::peerBlockSize() const
1498922Swilliam.wang@arm.com{
1508922Swilliam.wang@arm.com    return _masterPort->deviceBlockSize();
1518922Swilliam.wang@arm.com}
1528922Swilliam.wang@arm.com
1538922Swilliam.wang@arm.combool
1548922Swilliam.wang@arm.comSlavePort::isConnected() const
1558922Swilliam.wang@arm.com{
1568922Swilliam.wang@arm.com    return _masterPort != NULL;
1578922Swilliam.wang@arm.com}
158