port.cc revision 13293
1/* 2 * Copyright 2018 Google, Inc. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer; 8 * redistributions in binary form must reproduce the above copyright 9 * notice, this list of conditions and the following disclaimer in the 10 * documentation and/or other materials provided with the distribution; 11 * neither the name of the copyright holders nor the names of its 12 * contributors may be used to endorse or promote products derived from 13 * this software without specific prior written permission. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * 27 * Authors: Gabe Black 28 */ 29 30#include "systemc/core/port.hh" 31 32#include "base/logging.hh" 33#include "systemc/core/process.hh" 34#include "systemc/core/sensitivity.hh" 35#include "systemc/ext/channel/sc_signal_in_if.hh" 36 37namespace sc_gem5 38{ 39 40void 41Port::finalizePort(StaticSensitivityPort *port) 42{ 43 for (int i = 0; i < size(); i++) 44 port->addEvent(&getInterface(i)->default_event()); 45} 46 47void 48Port::finalizeFinder(StaticSensitivityFinder *finder) 49{ 50 for (int i = 0; i < size(); i++) 51 finder->addEvent(&finder->find(getInterface(i))); 52} 53 54void 55Port::finalizeReset(Reset *reset) 56{ 57 assert(size() <= 1); 58 if (size()) { 59 auto iface = 60 dynamic_cast<sc_core::sc_signal_in_if<bool> *>(getInterface(0)); 61 assert(iface); 62 if (!reset->install(iface)) 63 delete reset; 64 } 65} 66 67void 68Port::sensitive(StaticSensitivityPort *port) 69{ 70 if (finalized) 71 finalizePort(port); 72 else 73 sensitivities.push_back(new Sensitivity(port)); 74} 75 76void 77Port::sensitive(StaticSensitivityFinder *finder) 78{ 79 if (finalized) 80 finalizeFinder(finder); 81 else 82 sensitivities.push_back(new Sensitivity(finder)); 83} 84 85void 86Port::addReset(Reset *reset) 87{ 88 if (finalized) 89 finalizeReset(reset); 90 else 91 resets.push_back(reset); 92} 93 94void 95Port::finalize() 96{ 97 if (finalized) 98 return; 99 finalized = true; 100 101 for (auto &b: bindings) { 102 if (b->interface) { 103 addInterface(b->interface); 104 } else { 105 b->port->_gem5Port->finalize(); 106 addInterfaces(b->port); 107 } 108 delete b; 109 } 110 111 bindings.clear(); 112 113 for (auto &s: sensitivities) { 114 if (s->port) 115 finalizePort(s->port); 116 else 117 finalizeFinder(s->finder); 118 delete s; 119 } 120 121 sensitivities.clear(); 122 123 for (auto &r: resets) 124 finalizeReset(r); 125 126 resets.clear(); 127 128 switch (portBase->_portPolicy()) { 129 case sc_core::SC_ONE_OR_MORE_BOUND: 130 if (size() == 0) 131 portBase->report_error( 132 "(E109) complete binding failed", "port not bound"); 133 break; 134 case sc_core::SC_ALL_BOUND: 135 if (size() < maxSize() || size() < 1) { 136 std::stringstream ss; 137 ss << size() << " actual binds is less than required " << 138 maxSize(); 139 portBase->report_error( 140 "(E109) complete binding failed", ss.str().c_str()); 141 } 142 break; 143 case sc_core::SC_ZERO_OR_MORE_BOUND: 144 break; 145 default: 146 panic("Unrecognized port policy %d.", portBase->_portPolicy()); 147 } 148} 149 150void 151Port::regPort() 152{ 153 if (!regPortNeeded) 154 return; 155 156 for (int i = 0; i < size(); i++) 157 getInterface(i)->register_port(*portBase, portBase->_ifTypeName()); 158} 159 160std::list<Port *> allPorts; 161 162} // namespace sc_gem5 163