port.hh revision 14189
112853Sgabeblack@google.com/* 212853Sgabeblack@google.com * Copyright (c) 2011-2012,2015,2017 ARM Limited 312853Sgabeblack@google.com * All rights reserved 412853Sgabeblack@google.com * 512853Sgabeblack@google.com * The license below extends only to copyright in the software and shall 612853Sgabeblack@google.com * not be construed as granting a license to any other intellectual 712853Sgabeblack@google.com * property including but not limited to intellectual property relating 812853Sgabeblack@google.com * to a hardware implementation of the functionality of the software 912853Sgabeblack@google.com * licensed hereunder. You may use the software subject to the license 1012853Sgabeblack@google.com * terms below provided that you ensure that this notice is replicated 1112853Sgabeblack@google.com * unmodified and in its entirety in all distributions of the software, 1212853Sgabeblack@google.com * modified or unmodified, in source code or in binary form. 1312853Sgabeblack@google.com * 1412853Sgabeblack@google.com * Copyright (c) 2002-2005 The Regents of The University of Michigan 1512853Sgabeblack@google.com * All rights reserved. 1612853Sgabeblack@google.com * 1712853Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 1812853Sgabeblack@google.com * modification, are permitted provided that the following conditions are 1912853Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 2012853Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 2112853Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 2212853Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 2312853Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 2412853Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 2512853Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 2612853Sgabeblack@google.com * this software without specific prior written permission. 2712853Sgabeblack@google.com * 2812853Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2912853Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 3012853Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 3112853Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 3212853Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3312853Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3412853Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3512853Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3612853Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3712853Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3812853Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3912853Sgabeblack@google.com * 4012853Sgabeblack@google.com * Authors: Ron Dreslinski 4112853Sgabeblack@google.com * Andreas Hansson 4212853Sgabeblack@google.com * William Wang 4312853Sgabeblack@google.com */ 4412853Sgabeblack@google.com 4512853Sgabeblack@google.com/** 4612853Sgabeblack@google.com * @file 4712853Sgabeblack@google.com * Port Object Declaration. 4812853Sgabeblack@google.com */ 4912853Sgabeblack@google.com 5012853Sgabeblack@google.com#ifndef __SIM_PORT_HH__ 5112853Sgabeblack@google.com#define __SIM_PORT_HH__ 5212853Sgabeblack@google.com 5312853Sgabeblack@google.com#include <string> 5412853Sgabeblack@google.com 5512853Sgabeblack@google.com#include "base/types.hh" 5612853Sgabeblack@google.com 5712853Sgabeblack@google.com/** 5812853Sgabeblack@google.com * Ports are used to interface objects to each other. 5912853Sgabeblack@google.com */ 6012853Sgabeblack@google.comclass Port 6112853Sgabeblack@google.com{ 6212853Sgabeblack@google.com 6312853Sgabeblack@google.com private: 6412853Sgabeblack@google.com 6512853Sgabeblack@google.com /** Descriptive name (for DPRINTF output) */ 6612853Sgabeblack@google.com const std::string portName; 6712853Sgabeblack@google.com 6812853Sgabeblack@google.com protected: 6912853Sgabeblack@google.com 7012853Sgabeblack@google.com /** 7112853Sgabeblack@google.com * A numeric identifier to distinguish ports in a vector, and set 7212853Sgabeblack@google.com * to InvalidPortID in case this port is not part of a vector. 7312853Sgabeblack@google.com */ 7412853Sgabeblack@google.com const PortID id; 7512853Sgabeblack@google.com 7612853Sgabeblack@google.com /** 7712853Sgabeblack@google.com * A pointer to this port's peer. 7812853Sgabeblack@google.com */ 7912853Sgabeblack@google.com Port *_peer; 8012853Sgabeblack@google.com 8112853Sgabeblack@google.com 8212853Sgabeblack@google.com /** 8312853Sgabeblack@google.com * Whether this port is currently connected to a peer port. 8412853Sgabeblack@google.com */ 8512853Sgabeblack@google.com bool _connected; 8612853Sgabeblack@google.com 8712853Sgabeblack@google.com /** 8812853Sgabeblack@google.com * Abstract base class for ports 8912853Sgabeblack@google.com * 9012853Sgabeblack@google.com * @param _name Port name including the owners name 9112853Sgabeblack@google.com * @param _id A port identifier for vector ports 9212853Sgabeblack@google.com */ 9312853Sgabeblack@google.com Port(const std::string& _name, PortID _id); 9412853Sgabeblack@google.com 9512853Sgabeblack@google.com /** 9612853Sgabeblack@google.com * Virtual destructor due to inheritance. 9712853Sgabeblack@google.com */ 9812853Sgabeblack@google.com virtual ~Port(); 9912853Sgabeblack@google.com 10012853Sgabeblack@google.com public: 10112853Sgabeblack@google.com 10212853Sgabeblack@google.com /** Return a reference to this port's peer. */ 10312853Sgabeblack@google.com Port &getPeer() { return *_peer; } 10412853Sgabeblack@google.com 10512853Sgabeblack@google.com /** Return port name (for DPRINTF). */ 10612853Sgabeblack@google.com const std::string name() const { return portName; } 10712853Sgabeblack@google.com 10812853Sgabeblack@google.com /** Get the port id. */ 10912853Sgabeblack@google.com PortID getId() const { return id; } 11012853Sgabeblack@google.com 11112853Sgabeblack@google.com /** Attach to a peer port. */ 11212853Sgabeblack@google.com virtual void 11312853Sgabeblack@google.com bind(Port &peer) 11412853Sgabeblack@google.com { 11512853Sgabeblack@google.com _peer = &peer; 11612853Sgabeblack@google.com _connected = true; 11712853Sgabeblack@google.com } 11812853Sgabeblack@google.com 11912853Sgabeblack@google.com /** Dettach from a peer port. */ 12012853Sgabeblack@google.com virtual void 12112853Sgabeblack@google.com unbind() 12212853Sgabeblack@google.com { 12312853Sgabeblack@google.com _peer = nullptr; 12412853Sgabeblack@google.com _connected = false; 12512853Sgabeblack@google.com } 12612853Sgabeblack@google.com 12712853Sgabeblack@google.com /** Is this port currently connected to a peer? */ 12812853Sgabeblack@google.com bool isConnected() const { return _connected; } 12912853Sgabeblack@google.com}; 13012853Sgabeblack@google.com 13112853Sgabeblack@google.com#endif //__SIM_PORT_HH__ 13212853Sgabeblack@google.com