port.cc revision 5283:3ab643fa74be
11689SN/A/* 21689SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan 31689SN/A * All rights reserved. 41689SN/A * 51689SN/A * Redistribution and use in source and binary forms, with or without 61689SN/A * modification, are permitted provided that the following conditions are 71689SN/A * met: redistributions of source code must retain the above copyright 81689SN/A * notice, this list of conditions and the following disclaimer; 91689SN/A * redistributions in binary form must reproduce the above copyright 101689SN/A * notice, this list of conditions and the following disclaimer in the 111689SN/A * documentation and/or other materials provided with the distribution; 121689SN/A * neither the name of the copyright holders nor the names of its 131689SN/A * contributors may be used to endorse or promote products derived from 141689SN/A * this software without specific prior written permission. 151689SN/A * 161689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 171689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 181689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 191689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 201689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 211689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 221689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 231689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 241689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 251689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 261689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Steve Reinhardt 291689SN/A */ 301689SN/A 311060SN/A/** 321060SN/A * @file 331060SN/A * Port object definitions. 341060SN/A */ 351689SN/A#include <cstring> 361060SN/A 371060SN/A#include "base/chunk_generator.hh" 381755SN/A#include "base/trace.hh" 391755SN/A#include "mem/mem_object.hh" 401060SN/A#include "mem/port.hh" 411060SN/A 421060SN/Aclass defaultPeerPortClass: public Port 431681SN/A{ 441060SN/A protected: 451060SN/A void blowUp() 461060SN/A { 471858SN/A fatal("Unconnected port!"); 481717SN/A } 492190SN/A 501717SN/A public: 511717SN/A defaultPeerPortClass() : Port("default_port") 521060SN/A {} 531060SN/A 542190SN/A bool recvTiming(PacketPtr) 551060SN/A { 561060SN/A blowUp(); 571060SN/A return false; 581060SN/A } 591060SN/A 601060SN/A Tick recvAtomic(PacketPtr) 611060SN/A { 621464SN/A blowUp(); 631061SN/A return 0; 641858SN/A } 651061SN/A 661061SN/A void recvFunctional(PacketPtr) 671061SN/A { 681060SN/A blowUp(); 691681SN/A } 701685SN/A 711681SN/A void recvStatusChange(Status) 721060SN/A { 731060SN/A blowUp(); 741060SN/A } 751755SN/A 761060SN/A int deviceBlockSize() 771060SN/A { 781060SN/A blowUp(); 791060SN/A return 0; 801060SN/A } 811061SN/A 821060SN/A void getDeviceAddressRanges(AddrRangeList &, bool &) 831060SN/A { 841060SN/A blowUp(); 851060SN/A } 861060SN/A 871060SN/A bool isDefaultPort() { return true; } 881060SN/A 891060SN/A} defaultPeerPort; 901060SN/A 911060SN/APort::Port() : peer(&defaultPeerPort), owner(NULL) 921060SN/A{ 931060SN/A} 941060SN/A 951060SN/APort::Port(const std::string &_name, MemObject *_owner) : 961060SN/A portName(_name), peer(&defaultPeerPort), owner(_owner) 971755SN/A{ 981060SN/A} 991060SN/A 1001755SN/Avoid 1011060SN/APort::setPeer(Port *port) 1021060SN/A{ 1031060SN/A DPRINTF(Config, "setting peer to %s\n", port->name()); 1041060SN/A peer = port; 1051060SN/A} 1061060SN/A 1071060SN/Avoid 1081060SN/APort::removeConn() 1091060SN/A{ 1101060SN/A if (peer->getOwner()) 1111060SN/A peer->getOwner()->deletePortRefs(peer); 1121060SN/A peer = NULL; 1131060SN/A} 1141060SN/A 1151060SN/Avoid 1161060SN/APort::blobHelper(Addr addr, uint8_t *p, int size, MemCmd cmd) 1171060SN/A{ 1181060SN/A Request req; 1191060SN/A 1201060SN/A for (ChunkGenerator gen(addr, size, peerBlockSize()); 1211060SN/A !gen.done(); gen.next()) { 1221060SN/A req.setPhys(gen.addr(), gen.size(), 0); 1231060SN/A Packet pkt(&req, cmd, Packet::Broadcast); 1241755SN/A pkt.dataStatic(p); 1251755SN/A sendFunctional(&pkt); 1261060SN/A p += gen.size(); 1271684SN/A } 1281684SN/A} 1291684SN/A 1301684SN/Avoid 1311060SN/APort::writeBlob(Addr addr, uint8_t *p, int size) 1321060SN/A{ 1331060SN/A blobHelper(addr, p, size, MemCmd::WriteReq); 1341060SN/A} 1351060SN/A 1361060SN/Avoid 1371060SN/APort::readBlob(Addr addr, uint8_t *p, int size) 1381060SN/A{ 1391060SN/A blobHelper(addr, p, size, MemCmd::ReadReq); 1401060SN/A} 1411060SN/A 1421060SN/Avoid 1431060SN/APort::memsetBlob(Addr addr, uint8_t val, int size) 1441858SN/A{ 1451060SN/A // quick and dirty... 1461060SN/A uint8_t *buf = new uint8_t[size]; 1471060SN/A 1481060SN/A std::memset(buf, val, size); 1491060SN/A blobHelper(addr, buf, size, MemCmd::WriteReq); 1501060SN/A 1511060SN/A delete [] buf; 1521681SN/A} 1532245SN/A