port.hh revision 14190
113771Sgabeblack@google.com/* 213771Sgabeblack@google.com * Copyright (c) 2011-2012,2015,2017 ARM Limited 313771Sgabeblack@google.com * All rights reserved 413771Sgabeblack@google.com * 513771Sgabeblack@google.com * The license below extends only to copyright in the software and shall 613771Sgabeblack@google.com * not be construed as granting a license to any other intellectual 713771Sgabeblack@google.com * property including but not limited to intellectual property relating 813771Sgabeblack@google.com * to a hardware implementation of the functionality of the software 913771Sgabeblack@google.com * licensed hereunder. You may use the software subject to the license 1013771Sgabeblack@google.com * terms below provided that you ensure that this notice is replicated 1113771Sgabeblack@google.com * unmodified and in its entirety in all distributions of the software, 1213771Sgabeblack@google.com * modified or unmodified, in source code or in binary form. 1313771Sgabeblack@google.com * 1413771Sgabeblack@google.com * Copyright (c) 2002-2005 The Regents of The University of Michigan 1513771Sgabeblack@google.com * All rights reserved. 1613771Sgabeblack@google.com * 1713771Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 1813771Sgabeblack@google.com * modification, are permitted provided that the following conditions are 1913771Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 2013771Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 2113771Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 2213771Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 2313771Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 2413771Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 2513771Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 2613771Sgabeblack@google.com * this software without specific prior written permission. 2713771Sgabeblack@google.com * 2813771Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2913771Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 3013771Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 3113771Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 3213771Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3313771Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3413771Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3513771Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3613771Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3713771Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3813771Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3913771Sgabeblack@google.com * 4013771Sgabeblack@google.com * Authors: Ron Dreslinski 4113771Sgabeblack@google.com * Andreas Hansson 4213771Sgabeblack@google.com * William Wang 4313771Sgabeblack@google.com */ 4413771Sgabeblack@google.com 4513771Sgabeblack@google.com/** 4613771Sgabeblack@google.com * @file 4713771Sgabeblack@google.com * Port Object Declaration. 4813771Sgabeblack@google.com */ 4913771Sgabeblack@google.com 5013771Sgabeblack@google.com#ifndef __SIM_PORT_HH__ 5113771Sgabeblack@google.com#define __SIM_PORT_HH__ 5213771Sgabeblack@google.com 5313771Sgabeblack@google.com#include <string> 5413771Sgabeblack@google.com 5513771Sgabeblack@google.com#include "base/types.hh" 5613771Sgabeblack@google.com 5713771Sgabeblack@google.com/** 5813771Sgabeblack@google.com * Ports are used to interface objects to each other. 5913771Sgabeblack@google.com */ 6013771Sgabeblack@google.comclass Port 6113771Sgabeblack@google.com{ 6213771Sgabeblack@google.com 6313771Sgabeblack@google.com private: 6413771Sgabeblack@google.com 6513771Sgabeblack@google.com /** Descriptive name (for DPRINTF output) */ 6613782Sgabeblack@google.com const std::string portName; 6713771Sgabeblack@google.com 6813771Sgabeblack@google.com protected: 6913771Sgabeblack@google.com 7013771Sgabeblack@google.com /** 7113771Sgabeblack@google.com * A numeric identifier to distinguish ports in a vector, and set 7213771Sgabeblack@google.com * to InvalidPortID in case this port is not part of a vector. 7313771Sgabeblack@google.com */ 7413771Sgabeblack@google.com const PortID id; 7514189Sgabeblack@google.com 7614189Sgabeblack@google.com /** 7714189Sgabeblack@google.com * A pointer to this port's peer. 7814189Sgabeblack@google.com */ 7914189Sgabeblack@google.com Port *_peer; 8014189Sgabeblack@google.com 8114189Sgabeblack@google.com 8213782Sgabeblack@google.com /** 8313782Sgabeblack@google.com * Whether this port is currently connected to a peer port. 8413782Sgabeblack@google.com */ 8513782Sgabeblack@google.com bool _connected; 8613771Sgabeblack@google.com 8713771Sgabeblack@google.com /** 8813771Sgabeblack@google.com * Abstract base class for ports 8913771Sgabeblack@google.com * 9013771Sgabeblack@google.com * @param _name Port name including the owners name 9113771Sgabeblack@google.com * @param _id A port identifier for vector ports 9213771Sgabeblack@google.com */ 9313771Sgabeblack@google.com Port(const std::string& _name, PortID _id); 9413771Sgabeblack@google.com 9513771Sgabeblack@google.com /** 9613771Sgabeblack@google.com * Virtual destructor due to inheritance. 9713771Sgabeblack@google.com */ 9813771Sgabeblack@google.com virtual ~Port(); 9913771Sgabeblack@google.com 10013771Sgabeblack@google.com public: 10113771Sgabeblack@google.com 10214189Sgabeblack@google.com /** Return a reference to this port's peer. */ 10314189Sgabeblack@google.com Port &getPeer() { return *_peer; } 10414189Sgabeblack@google.com 10513771Sgabeblack@google.com /** Return port name (for DPRINTF). */ 10613771Sgabeblack@google.com const std::string name() const { return portName; } 10713771Sgabeblack@google.com 10813771Sgabeblack@google.com /** Get the port id. */ 10913771Sgabeblack@google.com PortID getId() const { return id; } 11013771Sgabeblack@google.com 11113782Sgabeblack@google.com /** Attach to a peer port. */ 11214189Sgabeblack@google.com virtual void 11314189Sgabeblack@google.com bind(Port &peer) 11414189Sgabeblack@google.com { 11514189Sgabeblack@google.com _peer = &peer; 11614189Sgabeblack@google.com _connected = true; 11714189Sgabeblack@google.com } 11813782Sgabeblack@google.com 11913782Sgabeblack@google.com /** Dettach from a peer port. */ 12014189Sgabeblack@google.com virtual void 12114189Sgabeblack@google.com unbind() 12214189Sgabeblack@google.com { 12314189Sgabeblack@google.com _peer = nullptr; 12414189Sgabeblack@google.com _connected = false; 12514189Sgabeblack@google.com } 12613782Sgabeblack@google.com 12713782Sgabeblack@google.com /** Is this port currently connected to a peer? */ 12813782Sgabeblack@google.com bool isConnected() const { return _connected; } 12914190Sgabeblack@google.com 13014190Sgabeblack@google.com /** A utility function to make it easier to swap out ports. */ 13114190Sgabeblack@google.com void 13214190Sgabeblack@google.com takeOverFrom(Port *old) 13314190Sgabeblack@google.com { 13414190Sgabeblack@google.com assert(old); 13514190Sgabeblack@google.com assert(old->isConnected()); 13614190Sgabeblack@google.com assert(!isConnected()); 13714190Sgabeblack@google.com Port &peer = old->getPeer(); 13814190Sgabeblack@google.com assert(peer.isConnected()); 13914190Sgabeblack@google.com 14014190Sgabeblack@google.com // Disconnect the original binding. 14114190Sgabeblack@google.com old->unbind(); 14214190Sgabeblack@google.com peer.unbind(); 14314190Sgabeblack@google.com 14414190Sgabeblack@google.com // Connect the new binding. 14514190Sgabeblack@google.com peer.bind(*this); 14614190Sgabeblack@google.com bind(peer); 14714190Sgabeblack@google.com } 14813771Sgabeblack@google.com}; 14913771Sgabeblack@google.com 15013771Sgabeblack@google.com#endif //__SIM_PORT_HH__ 151