port.cc revision 13293
113207Sgabeblack@google.com/* 213207Sgabeblack@google.com * Copyright 2018 Google, Inc. 313207Sgabeblack@google.com * 413207Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 513207Sgabeblack@google.com * modification, are permitted provided that the following conditions are 613207Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 713207Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 813207Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 913207Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1013207Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1113207Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1213207Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1313207Sgabeblack@google.com * this software without specific prior written permission. 1413207Sgabeblack@google.com * 1513207Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1613207Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1713207Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1813207Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1913207Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2013207Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2113207Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2213207Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2313207Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2413207Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2513207Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2613207Sgabeblack@google.com * 2713207Sgabeblack@google.com * Authors: Gabe Black 2813207Sgabeblack@google.com */ 2913207Sgabeblack@google.com 3013207Sgabeblack@google.com#include "systemc/core/port.hh" 3113207Sgabeblack@google.com 3213293Sgabeblack@google.com#include "base/logging.hh" 3313288Sgabeblack@google.com#include "systemc/core/process.hh" 3413207Sgabeblack@google.com#include "systemc/core/sensitivity.hh" 3513260Sgabeblack@google.com#include "systemc/ext/channel/sc_signal_in_if.hh" 3613207Sgabeblack@google.com 3713207Sgabeblack@google.comnamespace sc_gem5 3813207Sgabeblack@google.com{ 3913207Sgabeblack@google.com 4013207Sgabeblack@google.comvoid 4113207Sgabeblack@google.comPort::finalizePort(StaticSensitivityPort *port) 4213207Sgabeblack@google.com{ 4313207Sgabeblack@google.com for (int i = 0; i < size(); i++) 4413207Sgabeblack@google.com port->addEvent(&getInterface(i)->default_event()); 4513207Sgabeblack@google.com} 4613207Sgabeblack@google.com 4713207Sgabeblack@google.comvoid 4813207Sgabeblack@google.comPort::finalizeFinder(StaticSensitivityFinder *finder) 4913207Sgabeblack@google.com{ 5013207Sgabeblack@google.com for (int i = 0; i < size(); i++) 5113207Sgabeblack@google.com finder->addEvent(&finder->find(getInterface(i))); 5213207Sgabeblack@google.com} 5313207Sgabeblack@google.com 5413207Sgabeblack@google.comvoid 5513288Sgabeblack@google.comPort::finalizeReset(Reset *reset) 5613260Sgabeblack@google.com{ 5713260Sgabeblack@google.com assert(size() <= 1); 5813260Sgabeblack@google.com if (size()) { 5913260Sgabeblack@google.com auto iface = 6013260Sgabeblack@google.com dynamic_cast<sc_core::sc_signal_in_if<bool> *>(getInterface(0)); 6113260Sgabeblack@google.com assert(iface); 6213288Sgabeblack@google.com if (!reset->install(iface)) 6313288Sgabeblack@google.com delete reset; 6413260Sgabeblack@google.com } 6513260Sgabeblack@google.com} 6613260Sgabeblack@google.com 6713260Sgabeblack@google.comvoid 6813207Sgabeblack@google.comPort::sensitive(StaticSensitivityPort *port) 6913207Sgabeblack@google.com{ 7013207Sgabeblack@google.com if (finalized) 7113207Sgabeblack@google.com finalizePort(port); 7213207Sgabeblack@google.com else 7313207Sgabeblack@google.com sensitivities.push_back(new Sensitivity(port)); 7413207Sgabeblack@google.com} 7513207Sgabeblack@google.com 7613207Sgabeblack@google.comvoid 7713207Sgabeblack@google.comPort::sensitive(StaticSensitivityFinder *finder) 7813207Sgabeblack@google.com{ 7913207Sgabeblack@google.com if (finalized) 8013207Sgabeblack@google.com finalizeFinder(finder); 8113207Sgabeblack@google.com else 8213207Sgabeblack@google.com sensitivities.push_back(new Sensitivity(finder)); 8313207Sgabeblack@google.com} 8413207Sgabeblack@google.com 8513207Sgabeblack@google.comvoid 8613288Sgabeblack@google.comPort::addReset(Reset *reset) 8713260Sgabeblack@google.com{ 8813260Sgabeblack@google.com if (finalized) 8913260Sgabeblack@google.com finalizeReset(reset); 9013260Sgabeblack@google.com else 9113288Sgabeblack@google.com resets.push_back(reset); 9213260Sgabeblack@google.com} 9313260Sgabeblack@google.com 9413260Sgabeblack@google.comvoid 9513207Sgabeblack@google.comPort::finalize() 9613207Sgabeblack@google.com{ 9713207Sgabeblack@google.com if (finalized) 9813207Sgabeblack@google.com return; 9913207Sgabeblack@google.com finalized = true; 10013207Sgabeblack@google.com 10113207Sgabeblack@google.com for (auto &b: bindings) { 10213207Sgabeblack@google.com if (b->interface) { 10313207Sgabeblack@google.com addInterface(b->interface); 10413207Sgabeblack@google.com } else { 10513207Sgabeblack@google.com b->port->_gem5Port->finalize(); 10613207Sgabeblack@google.com addInterfaces(b->port); 10713207Sgabeblack@google.com } 10813207Sgabeblack@google.com delete b; 10913207Sgabeblack@google.com } 11013207Sgabeblack@google.com 11113207Sgabeblack@google.com bindings.clear(); 11213207Sgabeblack@google.com 11313207Sgabeblack@google.com for (auto &s: sensitivities) { 11413207Sgabeblack@google.com if (s->port) 11513207Sgabeblack@google.com finalizePort(s->port); 11613288Sgabeblack@google.com else 11713260Sgabeblack@google.com finalizeFinder(s->finder); 11813207Sgabeblack@google.com delete s; 11913207Sgabeblack@google.com } 12013207Sgabeblack@google.com 12113207Sgabeblack@google.com sensitivities.clear(); 12213288Sgabeblack@google.com 12313288Sgabeblack@google.com for (auto &r: resets) 12413288Sgabeblack@google.com finalizeReset(r); 12513288Sgabeblack@google.com 12613288Sgabeblack@google.com resets.clear(); 12713293Sgabeblack@google.com 12813293Sgabeblack@google.com switch (portBase->_portPolicy()) { 12913293Sgabeblack@google.com case sc_core::SC_ONE_OR_MORE_BOUND: 13013293Sgabeblack@google.com if (size() == 0) 13113293Sgabeblack@google.com portBase->report_error( 13213293Sgabeblack@google.com "(E109) complete binding failed", "port not bound"); 13313293Sgabeblack@google.com break; 13413293Sgabeblack@google.com case sc_core::SC_ALL_BOUND: 13513293Sgabeblack@google.com if (size() < maxSize() || size() < 1) { 13613293Sgabeblack@google.com std::stringstream ss; 13713293Sgabeblack@google.com ss << size() << " actual binds is less than required " << 13813293Sgabeblack@google.com maxSize(); 13913293Sgabeblack@google.com portBase->report_error( 14013293Sgabeblack@google.com "(E109) complete binding failed", ss.str().c_str()); 14113293Sgabeblack@google.com } 14213293Sgabeblack@google.com break; 14313293Sgabeblack@google.com case sc_core::SC_ZERO_OR_MORE_BOUND: 14413293Sgabeblack@google.com break; 14513293Sgabeblack@google.com default: 14613293Sgabeblack@google.com panic("Unrecognized port policy %d.", portBase->_portPolicy()); 14713293Sgabeblack@google.com } 14813207Sgabeblack@google.com} 14913207Sgabeblack@google.com 15013273Sgabeblack@google.comvoid 15113273Sgabeblack@google.comPort::regPort() 15213273Sgabeblack@google.com{ 15313273Sgabeblack@google.com if (!regPortNeeded) 15413273Sgabeblack@google.com return; 15513273Sgabeblack@google.com 15613273Sgabeblack@google.com for (int i = 0; i < size(); i++) 15713273Sgabeblack@google.com getInterface(i)->register_port(*portBase, portBase->_ifTypeName()); 15813273Sgabeblack@google.com} 15913273Sgabeblack@google.com 16013207Sgabeblack@google.comstd::list<Port *> allPorts; 16113207Sgabeblack@google.com 16213207Sgabeblack@google.com} // namespace sc_gem5 163