port.cc revision 8709
12405SN/A/* 22405SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan 32405SN/A * All rights reserved. 42405SN/A * 52405SN/A * Redistribution and use in source and binary forms, with or without 62405SN/A * modification, are permitted provided that the following conditions are 72405SN/A * met: redistributions of source code must retain the above copyright 82405SN/A * notice, this list of conditions and the following disclaimer; 92405SN/A * redistributions in binary form must reproduce the above copyright 102405SN/A * notice, this list of conditions and the following disclaimer in the 112405SN/A * documentation and/or other materials provided with the distribution; 122405SN/A * neither the name of the copyright holders nor the names of its 132405SN/A * contributors may be used to endorse or promote products derived from 142405SN/A * this software without specific prior written permission. 152405SN/A * 162405SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172405SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182405SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192405SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202405SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212405SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222405SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232405SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242405SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252405SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262405SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Steve Reinhardt 292405SN/A */ 302405SN/A 312405SN/A/** 322982Sstever@eecs.umich.edu * @file 332982Sstever@eecs.umich.edu * Port object definitions. 342405SN/A */ 353918Ssaidi@eecs.umich.edu#include <cstring> 362405SN/A 372405SN/A#include "base/chunk_generator.hh" 382642Sstever@eecs.umich.edu#include "base/trace.hh" 398232Snate@binkert.org#include "debug/Config.hh" 404190Ssaidi@eecs.umich.edu#include "mem/mem_object.hh" 412405SN/A#include "mem/port.hh" 422405SN/A 435494Sstever@gmail.comPort::Port(const std::string &_name, MemObject *_owner) 448709Sandreas.hansson@arm.com : portName(_name), peer(NULL), owner(_owner) 455476Snate@binkert.org{ 465476Snate@binkert.org} 475476Snate@binkert.org 485476Snate@binkert.orgPort::~Port() 495283Sgblack@eecs.umich.edu{ 505283Sgblack@eecs.umich.edu} 515283Sgblack@eecs.umich.edu 522405SN/Avoid 532642Sstever@eecs.umich.eduPort::setPeer(Port *port) 542642Sstever@eecs.umich.edu{ 555494Sstever@gmail.com DPRINTF(Config, "setting peer to %s\n", port->name()); 565476Snate@binkert.org 572642Sstever@eecs.umich.edu peer = port; 582642Sstever@eecs.umich.edu} 592642Sstever@eecs.umich.edu 602642Sstever@eecs.umich.eduvoid 615605Snate@binkert.orgPort::setOwner(MemObject *_owner) 625605Snate@binkert.org{ 635605Snate@binkert.org owner = _owner; 645605Snate@binkert.org} 655605Snate@binkert.org 665605Snate@binkert.orgvoid 675494Sstever@gmail.comPort::removeConn() 685494Sstever@gmail.com{ 698709Sandreas.hansson@arm.com if (peer != NULL) 705494Sstever@gmail.com peer->getOwner()->deletePortRefs(peer); 715494Sstever@gmail.com peer = NULL; 725494Sstever@gmail.com} 735494Sstever@gmail.com 745494Sstever@gmail.comvoid 754022Sstever@eecs.umich.eduPort::blobHelper(Addr addr, uint8_t *p, int size, MemCmd cmd) 762405SN/A{ 772663Sstever@eecs.umich.edu Request req; 782405SN/A 792406SN/A for (ChunkGenerator gen(addr, size, peerBlockSize()); 802406SN/A !gen.done(); gen.next()) { 812663Sstever@eecs.umich.edu req.setPhys(gen.addr(), gen.size(), 0); 824870Sstever@eecs.umich.edu Packet pkt(&req, cmd, Packet::Broadcast); 832566SN/A pkt.dataStatic(p); 842630SN/A sendFunctional(&pkt); 852405SN/A p += gen.size(); 862405SN/A } 872405SN/A} 882405SN/A 892405SN/Avoid 902461SN/APort::writeBlob(Addr addr, uint8_t *p, int size) 912405SN/A{ 924022Sstever@eecs.umich.edu blobHelper(addr, p, size, MemCmd::WriteReq); 932405SN/A} 942405SN/A 952405SN/Avoid 962461SN/APort::readBlob(Addr addr, uint8_t *p, int size) 972405SN/A{ 984022Sstever@eecs.umich.edu blobHelper(addr, p, size, MemCmd::ReadReq); 992405SN/A} 1002405SN/A 1012420SN/Avoid 1022461SN/APort::memsetBlob(Addr addr, uint8_t val, int size) 1032420SN/A{ 1042420SN/A // quick and dirty... 1052420SN/A uint8_t *buf = new uint8_t[size]; 1062420SN/A 1073918Ssaidi@eecs.umich.edu std::memset(buf, val, size); 1084022Sstever@eecs.umich.edu blobHelper(addr, buf, size, MemCmd::WriteReq); 1092421SN/A 1102548SN/A delete [] buf; 1112420SN/A} 1125314Sstever@gmail.com 1135314Sstever@gmail.com 1145314Sstever@gmail.comvoid 1155314Sstever@gmail.comPort::printAddr(Addr a) 1165314Sstever@gmail.com{ 1175314Sstever@gmail.com Request req(a, 1, 0); 1185314Sstever@gmail.com Packet pkt(&req, MemCmd::PrintReq, Packet::Broadcast); 1195314Sstever@gmail.com Packet::PrintReqState prs(std::cerr); 1205314Sstever@gmail.com pkt.senderState = &prs; 1215314Sstever@gmail.com 1225314Sstever@gmail.com sendFunctional(&pkt); 1235314Sstever@gmail.com} 124