port.cc revision 5283:3ab643fa74be
12100SN/A/* 22083SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan 35268Sksewell@umich.edu * All rights reserved. 45268Sksewell@umich.edu * 55268Sksewell@umich.edu * Redistribution and use in source and binary forms, with or without 65268Sksewell@umich.edu * modification, are permitted provided that the following conditions are 75268Sksewell@umich.edu * met: redistributions of source code must retain the above copyright 85268Sksewell@umich.edu * notice, this list of conditions and the following disclaimer; 95268Sksewell@umich.edu * redistributions in binary form must reproduce the above copyright 105268Sksewell@umich.edu * notice, this list of conditions and the following disclaimer in the 115268Sksewell@umich.edu * documentation and/or other materials provided with the distribution; 125268Sksewell@umich.edu * neither the name of the copyright holders nor the names of its 135268Sksewell@umich.edu * contributors may be used to endorse or promote products derived from 145268Sksewell@umich.edu * this software without specific prior written permission. 155268Sksewell@umich.edu * 165268Sksewell@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 175268Sksewell@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 185268Sksewell@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 195268Sksewell@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 205268Sksewell@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 215268Sksewell@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 225268Sksewell@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 235268Sksewell@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 245268Sksewell@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 255268Sksewell@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 265268Sksewell@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 275268Sksewell@umich.edu * 285268Sksewell@umich.edu * Authors: Steve Reinhardt 295268Sksewell@umich.edu */ 302706Sksewell@umich.edu 312089SN/A/** 322022SN/A * @file 332089SN/A * Port object definitions. 342022SN/A */ 352022SN/A#include <cstring> 362022SN/A 372083SN/A#include "base/chunk_generator.hh" 382239SN/A#include "base/trace.hh" 394661Sksewell@umich.edu#include "mem/mem_object.hh" 402239SN/A#include "mem/port.hh" 412083SN/A 422083SN/Aclass defaultPeerPortClass: public Port 432083SN/A{ 442083SN/A protected: 452083SN/A void blowUp() 462083SN/A { 472083SN/A fatal("Unconnected port!"); 482083SN/A } 492083SN/A 502089SN/A public: 512083SN/A defaultPeerPortClass() : Port("default_port") 522083SN/A {} 532083SN/A 542083SN/A bool recvTiming(PacketPtr) 552089SN/A { 562083SN/A blowUp(); 572083SN/A return false; 582083SN/A } 592083SN/A 602083SN/A Tick recvAtomic(PacketPtr) 612083SN/A { 622089SN/A blowUp(); 632083SN/A return 0; 642022SN/A } 652083SN/A 662022SN/A void recvFunctional(PacketPtr) 672083SN/A { 682083SN/A blowUp(); 692083SN/A } 702022SN/A 712083SN/A void recvStatusChange(Status) 722083SN/A { 732083SN/A blowUp(); 742083SN/A } 752083SN/A 762083SN/A int deviceBlockSize() 772083SN/A { 782089SN/A blowUp(); 792104SN/A return 0; 802083SN/A } 812083SN/A 822083SN/A void getDeviceAddressRanges(AddrRangeList &, bool &) 832083SN/A { 842104SN/A blowUp(); 852089SN/A } 862239SN/A 872239SN/A bool isDefaultPort() { return true; } 882239SN/A 892239SN/A} defaultPeerPort; 902089SN/A 912089SN/APort::Port() : peer(&defaultPeerPort), owner(NULL) 922089SN/A{ 932089SN/A} 942089SN/A 952089SN/APort::Port(const std::string &_name, MemObject *_owner) : 962089SN/A portName(_name), peer(&defaultPeerPort), owner(_owner) 972089SN/A{ 982089SN/A} 992083SN/A 1002089SN/Avoid 1012083SN/APort::setPeer(Port *port) 1022083SN/A{ 1032083SN/A DPRINTF(Config, "setting peer to %s\n", port->name()); 1042083SN/A peer = port; 1052083SN/A} 1062083SN/A 1072083SN/Avoid 1082083SN/APort::removeConn() 1092239SN/A{ 1102239SN/A if (peer->getOwner()) 1112083SN/A peer->getOwner()->deletePortRefs(peer); 1122083SN/A peer = NULL; 1132083SN/A} 1142083SN/A 1152239SN/Avoid 1162083SN/APort::blobHelper(Addr addr, uint8_t *p, int size, MemCmd cmd) 1172083SN/A{ 1182083SN/A Request req; 1192687Sksewell@umich.edu 1202083SN/A for (ChunkGenerator gen(addr, size, peerBlockSize()); 1212083SN/A !gen.done(); gen.next()) { 1222083SN/A req.setPhys(gen.addr(), gen.size(), 0); 1232083SN/A Packet pkt(&req, cmd, Packet::Broadcast); 1242022SN/A pkt.dataStatic(p); 1252022SN/A sendFunctional(&pkt); 1262022SN/A p += gen.size(); 1272083SN/A } 1282083SN/A} 1292083SN/A 1302083SN/Avoid 1312083SN/APort::writeBlob(Addr addr, uint8_t *p, int size) 1322083SN/A{ 1332083SN/A blobHelper(addr, p, size, MemCmd::WriteReq); 1342687Sksewell@umich.edu} 1352083SN/A 1365222Sksewell@umich.eduvoid 1375222Sksewell@umich.eduPort::readBlob(Addr addr, uint8_t *p, int size) 1382083SN/A{ 1392083SN/A blobHelper(addr, p, size, MemCmd::ReadReq); 1402083SN/A} 1412083SN/A 1422083SN/Avoid 1432083SN/APort::memsetBlob(Addr addr, uint8_t val, int size) 1442083SN/A{ 1452083SN/A // quick and dirty... 1462022SN/A uint8_t *buf = new uint8_t[size]; 1472083SN/A 1482083SN/A std::memset(buf, val, size); 1492083SN/A blobHelper(addr, buf, size, MemCmd::WriteReq); 1502083SN/A 1512083SN/A delete [] buf; 1522083SN/A} 1532083SN/A