port.cc revision 9178
12405SN/A/* 22405SN/A * Copyright (c) 2012 ARM Limited 32405SN/A * All rights reserved 42405SN/A * 52405SN/A * The license below extends only to copyright in the software and shall 62405SN/A * not be construed as granting a license to any other intellectual 72405SN/A * property including but not limited to intellectual property relating 82405SN/A * to a hardware implementation of the functionality of the software 92405SN/A * licensed hereunder. You may use the software subject to the license 102405SN/A * terms below provided that you ensure that this notice is replicated 112405SN/A * unmodified and in its entirety in all distributions of the software, 122405SN/A * modified or unmodified, in source code or in binary form. 132405SN/A * 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. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * 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 322982Sstever@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 332982Sstever@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 342405SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 353918Ssaidi@eecs.umich.edu * 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 382642Sstever@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 394190Ssaidi@eecs.umich.edu * 402405SN/A * Authors: Steve Reinhardt 412405SN/A * Andreas Hansson 425283Sgblack@eecs.umich.edu * William Wang 435283Sgblack@eecs.umich.edu */ 445283Sgblack@eecs.umich.edu 455283Sgblack@eecs.umich.edu/** 465283Sgblack@eecs.umich.edu * @file 475283Sgblack@eecs.umich.edu * Port object definitions. 485283Sgblack@eecs.umich.edu */ 495283Sgblack@eecs.umich.edu#include "base/trace.hh" 505283Sgblack@eecs.umich.edu#include "mem/mem_object.hh" 515283Sgblack@eecs.umich.edu#include "mem/port.hh" 525283Sgblack@eecs.umich.edu 535283Sgblack@eecs.umich.eduPort::Port(const std::string &_name, MemObject& _owner, PortID _id) 545283Sgblack@eecs.umich.edu : portName(_name), id(_id), owner(_owner) 555283Sgblack@eecs.umich.edu{ 565283Sgblack@eecs.umich.edu} 575283Sgblack@eecs.umich.edu 585283Sgblack@eecs.umich.eduPort::~Port() 595283Sgblack@eecs.umich.edu{ 605283Sgblack@eecs.umich.edu} 615283Sgblack@eecs.umich.edu 625283Sgblack@eecs.umich.edu/** 635283Sgblack@eecs.umich.edu * Master port 645283Sgblack@eecs.umich.edu */ 655283Sgblack@eecs.umich.eduMasterPort::MasterPort(const std::string& name, MemObject* owner, PortID _id) 665283Sgblack@eecs.umich.edu : Port(name, *owner, _id), _slavePort(NULL) 675283Sgblack@eecs.umich.edu{ 685283Sgblack@eecs.umich.edu} 695283Sgblack@eecs.umich.edu 705283Sgblack@eecs.umich.eduMasterPort::~MasterPort() 715283Sgblack@eecs.umich.edu{ 725283Sgblack@eecs.umich.edu} 735283Sgblack@eecs.umich.edu 745283Sgblack@eecs.umich.eduSlavePort& 755283Sgblack@eecs.umich.eduMasterPort::getSlavePort() const 765283Sgblack@eecs.umich.edu{ 775283Sgblack@eecs.umich.edu if(_slavePort == NULL) 785283Sgblack@eecs.umich.edu panic("Cannot getSlavePort on master port %s that is not connected\n", 795283Sgblack@eecs.umich.edu name()); 805283Sgblack@eecs.umich.edu 815283Sgblack@eecs.umich.edu return *_slavePort; 825283Sgblack@eecs.umich.edu} 835283Sgblack@eecs.umich.edu 845283Sgblack@eecs.umich.eduvoid 855283Sgblack@eecs.umich.eduMasterPort::unbind() 865283Sgblack@eecs.umich.edu{ 875283Sgblack@eecs.umich.edu if (_slavePort == NULL) 885283Sgblack@eecs.umich.edu panic("Attempting to unbind master port %s that is not connected\n", 895283Sgblack@eecs.umich.edu name()); 905283Sgblack@eecs.umich.edu _slavePort->unbind(); 915283Sgblack@eecs.umich.edu _slavePort = NULL; 925283Sgblack@eecs.umich.edu} 935283Sgblack@eecs.umich.edu 945283Sgblack@eecs.umich.eduvoid 955283Sgblack@eecs.umich.eduMasterPort::bind(SlavePort& slave_port) 965283Sgblack@eecs.umich.edu{ 975283Sgblack@eecs.umich.edu if (_slavePort != NULL) 985283Sgblack@eecs.umich.edu panic("Attempting to bind master port %s that is already connected\n", 995283Sgblack@eecs.umich.edu name()); 1002405SN/A 1012642Sstever@eecs.umich.edu // master port keeps track of the slave port 1022642Sstever@eecs.umich.edu _slavePort = &slave_port; 1032642Sstever@eecs.umich.edu 1042642Sstever@eecs.umich.edu // slave port also keeps track of master port 1052642Sstever@eecs.umich.edu _slavePort->bind(*this); 1062642Sstever@eecs.umich.edu} 1072642Sstever@eecs.umich.edu 1084190Ssaidi@eecs.umich.edubool 1094190Ssaidi@eecs.umich.eduMasterPort::isConnected() const 1104190Ssaidi@eecs.umich.edu{ 1114190Ssaidi@eecs.umich.edu return _slavePort != NULL; 1124190Ssaidi@eecs.umich.edu} 1134190Ssaidi@eecs.umich.edu 1144190Ssaidi@eecs.umich.eduunsigned 1154190Ssaidi@eecs.umich.eduMasterPort::peerBlockSize() const 1164022Sstever@eecs.umich.edu{ 1172405SN/A return _slavePort->deviceBlockSize(); 1182663Sstever@eecs.umich.edu} 1192405SN/A 1202406SN/AAddrRangeList 1212406SN/AMasterPort::getAddrRanges() const 1222663Sstever@eecs.umich.edu{ 1234870Sstever@eecs.umich.edu return _slavePort->getAddrRanges(); 1242566SN/A} 1252630SN/A 1262405SN/ATick 1272405SN/AMasterPort::sendAtomic(PacketPtr pkt) 1282405SN/A{ 1292405SN/A assert(pkt->isRequest()); 1302405SN/A return _slavePort->recvAtomic(pkt); 1312461SN/A} 1322405SN/A 1334022Sstever@eecs.umich.eduvoid 1342405SN/AMasterPort::sendFunctional(PacketPtr pkt) 1352405SN/A{ 1362405SN/A assert(pkt->isRequest()); 1372461SN/A return _slavePort->recvFunctional(pkt); 1382405SN/A} 1394022Sstever@eecs.umich.edu 1402405SN/Abool 1412405SN/AMasterPort::sendTimingReq(PacketPtr pkt) 1422420SN/A{ 1432461SN/A assert(pkt->isRequest()); 1442420SN/A return _slavePort->recvTimingReq(pkt); 1452420SN/A} 1462420SN/A 1472420SN/Abool 1483918Ssaidi@eecs.umich.eduMasterPort::sendTimingSnoopResp(PacketPtr pkt) 1494022Sstever@eecs.umich.edu{ 1502421SN/A assert(pkt->isResponse()); 1512548SN/A return _slavePort->recvTimingSnoopResp(pkt); 1522420SN/A} 1535314Sstever@gmail.com 1545314Sstever@gmail.comvoid 1555314Sstever@gmail.comMasterPort::sendRetry() 1565314Sstever@gmail.com{ 1575314Sstever@gmail.com _slavePort->recvRetry(); 1585314Sstever@gmail.com} 1595314Sstever@gmail.com 1605314Sstever@gmail.comvoid 1615314Sstever@gmail.comMasterPort::printAddr(Addr a) 1625314Sstever@gmail.com{ 1635314Sstever@gmail.com Request req(a, 1, 0, Request::funcMasterId); 1645314Sstever@gmail.com Packet pkt(&req, MemCmd::PrintReq); 165 Packet::PrintReqState prs(std::cerr); 166 pkt.senderState = &prs; 167 168 sendFunctional(&pkt); 169} 170 171/** 172 * Slave port 173 */ 174SlavePort::SlavePort(const std::string& name, MemObject* owner, PortID id) 175 : Port(name, *owner, id), _masterPort(NULL) 176{ 177} 178 179SlavePort::~SlavePort() 180{ 181} 182 183void 184SlavePort::unbind() 185{ 186 _masterPort = NULL; 187} 188 189void 190SlavePort::bind(MasterPort& master_port) 191{ 192 _masterPort = &master_port; 193} 194 195MasterPort& 196SlavePort::getMasterPort() const 197{ 198 if (_masterPort == NULL) 199 panic("Cannot getMasterPort on slave port %s that is not connected\n", 200 name()); 201 202 return *_masterPort; 203} 204 205unsigned 206SlavePort::peerBlockSize() const 207{ 208 return _masterPort->deviceBlockSize(); 209} 210 211bool 212SlavePort::isConnected() const 213{ 214 return _masterPort != NULL; 215} 216 217Tick 218SlavePort::sendAtomicSnoop(PacketPtr pkt) 219{ 220 assert(pkt->isRequest()); 221 return _masterPort->recvAtomicSnoop(pkt); 222} 223 224void 225SlavePort::sendFunctionalSnoop(PacketPtr pkt) 226{ 227 assert(pkt->isRequest()); 228 return _masterPort->recvFunctionalSnoop(pkt); 229} 230 231bool 232SlavePort::sendTimingResp(PacketPtr pkt) 233{ 234 assert(pkt->isResponse()); 235 return _masterPort->recvTimingResp(pkt); 236} 237 238void 239SlavePort::sendTimingSnoopReq(PacketPtr pkt) 240{ 241 assert(pkt->isRequest()); 242 _masterPort->recvTimingSnoopReq(pkt); 243} 244 245void 246SlavePort::sendRetry() 247{ 248 _masterPort->recvRetry(); 249} 250