port.hh revision 13260:4d18f1d20093
13760SN/A/* 23760SN/A * Copyright 2018 Google, Inc. 33760SN/A * 43760SN/A * Redistribution and use in source and binary forms, with or without 53760SN/A * modification, are permitted provided that the following conditions are 63760SN/A * met: redistributions of source code must retain the above copyright 73760SN/A * notice, this list of conditions and the following disclaimer; 83760SN/A * redistributions in binary form must reproduce the above copyright 93760SN/A * notice, this list of conditions and the following disclaimer in the 103760SN/A * documentation and/or other materials provided with the distribution; 113760SN/A * neither the name of the copyright holders nor the names of its 123760SN/A * contributors may be used to endorse or promote products derived from 133760SN/A * this software without specific prior written permission. 143760SN/A * 153760SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 163760SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 173760SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 183760SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 193760SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 203760SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 213760SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 223760SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 233760SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 243760SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 253760SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 263760SN/A * 273760SN/A * Authors: Gabe Black 285597Sgblack@eecs.umich.edu */ 293760SN/A 303760SN/A#ifndef __SYSTEMC_CORE_PORT_HH__ 315597Sgblack@eecs.umich.edu#define __SYSTEMC_CORE_PORT_HH__ 325597Sgblack@eecs.umich.edu 333760SN/A#include <list> 345597Sgblack@eecs.umich.edu#include <vector> 353760SN/A 363760SN/A#include "base/cprintf.hh" 373760SN/A#include "systemc/ext/core/sc_interface.hh" 383760SN/A#include "systemc/ext/core/sc_port.hh" 393760SN/A 403760SN/Anamespace sc_gem5 415596SN/A{ 423760SN/A 433760SN/Aclass StaticSensitivityPort; 445595SN/Aclass StaticSensitivityFinder; 453760SN/Aclass ResetSensitivityPort; 463760SN/A 473760SN/Aclass Port; 483760SN/A 493760SN/Aextern std::list<Port *> allPorts; 503760SN/A 513760SN/Aclass Port 523760SN/A{ 533760SN/A private: 545597Sgblack@eecs.umich.edu ::sc_core::sc_port_base *portBase; 553760SN/A 563760SN/A bool finalized; 573760SN/A int _maxSize; 583760SN/A int _size; 593760SN/A 605597Sgblack@eecs.umich.edu void finalizePort(StaticSensitivityPort *port); 613760SN/A void finalizeFinder(StaticSensitivityFinder *finder); 623760SN/A void finalizeReset(ResetSensitivityPort *reset); 635597Sgblack@eecs.umich.edu 643760SN/A void 653760SN/A addInterface(::sc_core::sc_interface *iface) 663760SN/A { 673760SN/A for (int i = 0; i < _size; i++) { 683760SN/A if (getInterface(i) == iface) { 693760SN/A std::string msg = 703760SN/A csprintf("interface already bound to port: port '%s' (%s)", 715597Sgblack@eecs.umich.edu portBase->name(), portBase->kind()); 723760SN/A SC_REPORT_ERROR("(E107) bind interface to port failed", 733760SN/A msg.c_str()); 743760SN/A } 753760SN/A } 763760SN/A _size++; 773760SN/A portBase->_gem5AddInterface(iface); 783760SN/A } 793760SN/A 803760SN/A void 813760SN/A addInterfaces(::sc_core::sc_port_base *pb) 823760SN/A { 833760SN/A for (int i = 0; i < pb->size(); i++) 843760SN/A addInterface(pb->_gem5Interface(i)); 853760SN/A } 86 87 ::sc_core::sc_interface * 88 getInterface(int i) 89 { 90 return portBase->_gem5Interface(i); 91 } 92 93 struct Binding 94 { 95 explicit Binding(::sc_core::sc_interface *interface) : 96 interface(interface), port(nullptr) 97 {} 98 99 explicit Binding(::sc_core::sc_port_base *port) : 100 interface(nullptr), port(port) 101 {} 102 103 ::sc_core::sc_interface *interface; 104 ::sc_core::sc_port_base *port; 105 }; 106 107 struct Sensitivity 108 { 109 Sensitivity(StaticSensitivityPort *port) : 110 port(port), finder(nullptr), reset(nullptr) 111 {} 112 113 Sensitivity(StaticSensitivityFinder *finder) : 114 port(nullptr), finder(finder), reset(nullptr) 115 {} 116 117 Sensitivity(ResetSensitivityPort *reset) : 118 port(nullptr), finder(nullptr), reset(reset) 119 {} 120 121 StaticSensitivityPort *port; 122 StaticSensitivityFinder *finder; 123 ResetSensitivityPort *reset; 124 }; 125 126 std::vector<Binding *> bindings; 127 std::vector<Sensitivity *> sensitivities; 128 129 public: 130 static Port * 131 fromPort(const ::sc_core::sc_port_base *pb) 132 { 133 return pb->_gem5Port; 134 } 135 136 ::sc_core::sc_port_base *sc_port_base() { return portBase; } 137 138 Port(::sc_core::sc_port_base *port_base, int max) : 139 portBase(port_base), finalized(false), _maxSize(max), _size(0) 140 { 141 allPorts.push_front(this); 142 } 143 144 void 145 bind(::sc_core::sc_interface *interface) 146 { 147 bindings.push_back(new Binding(interface)); 148 } 149 150 void 151 bind(::sc_core::sc_port_base *port) 152 { 153 bindings.push_back(new Binding(port)); 154 } 155 156 void sensitive(StaticSensitivityPort *port); 157 void sensitive(StaticSensitivityFinder *finder); 158 void sensitive(ResetSensitivityPort *reset); 159 160 void finalize(); 161 162 int size() { return _size; } 163 int maxSize() { return _maxSize; } 164}; 165 166} // namespace sc_gem5 167 168#endif // __SYSTEMC_CORE_PORT_HH__ 169