port.cc revision 13288
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
3213288Sgabeblack@google.com#include "systemc/core/process.hh"
3313207Sgabeblack@google.com#include "systemc/core/sensitivity.hh"
3413260Sgabeblack@google.com#include "systemc/ext/channel/sc_signal_in_if.hh"
3513207Sgabeblack@google.com
3613207Sgabeblack@google.comnamespace sc_gem5
3713207Sgabeblack@google.com{
3813207Sgabeblack@google.com
3913207Sgabeblack@google.comvoid
4013207Sgabeblack@google.comPort::finalizePort(StaticSensitivityPort *port)
4113207Sgabeblack@google.com{
4213207Sgabeblack@google.com    for (int i = 0; i < size(); i++)
4313207Sgabeblack@google.com        port->addEvent(&getInterface(i)->default_event());
4413207Sgabeblack@google.com}
4513207Sgabeblack@google.com
4613207Sgabeblack@google.comvoid
4713207Sgabeblack@google.comPort::finalizeFinder(StaticSensitivityFinder *finder)
4813207Sgabeblack@google.com{
4913207Sgabeblack@google.com    for (int i = 0; i < size(); i++)
5013207Sgabeblack@google.com        finder->addEvent(&finder->find(getInterface(i)));
5113207Sgabeblack@google.com}
5213207Sgabeblack@google.com
5313207Sgabeblack@google.comvoid
5413288Sgabeblack@google.comPort::finalizeReset(Reset *reset)
5513260Sgabeblack@google.com{
5613260Sgabeblack@google.com    assert(size() <= 1);
5713260Sgabeblack@google.com    if (size()) {
5813260Sgabeblack@google.com        auto iface =
5913260Sgabeblack@google.com            dynamic_cast<sc_core::sc_signal_in_if<bool> *>(getInterface(0));
6013260Sgabeblack@google.com        assert(iface);
6113288Sgabeblack@google.com        if (!reset->install(iface))
6213288Sgabeblack@google.com            delete reset;
6313260Sgabeblack@google.com    }
6413260Sgabeblack@google.com}
6513260Sgabeblack@google.com
6613260Sgabeblack@google.comvoid
6713207Sgabeblack@google.comPort::sensitive(StaticSensitivityPort *port)
6813207Sgabeblack@google.com{
6913207Sgabeblack@google.com    if (finalized)
7013207Sgabeblack@google.com        finalizePort(port);
7113207Sgabeblack@google.com    else
7213207Sgabeblack@google.com        sensitivities.push_back(new Sensitivity(port));
7313207Sgabeblack@google.com}
7413207Sgabeblack@google.com
7513207Sgabeblack@google.comvoid
7613207Sgabeblack@google.comPort::sensitive(StaticSensitivityFinder *finder)
7713207Sgabeblack@google.com{
7813207Sgabeblack@google.com    if (finalized)
7913207Sgabeblack@google.com        finalizeFinder(finder);
8013207Sgabeblack@google.com    else
8113207Sgabeblack@google.com        sensitivities.push_back(new Sensitivity(finder));
8213207Sgabeblack@google.com}
8313207Sgabeblack@google.com
8413207Sgabeblack@google.comvoid
8513288Sgabeblack@google.comPort::addReset(Reset *reset)
8613260Sgabeblack@google.com{
8713260Sgabeblack@google.com    if (finalized)
8813260Sgabeblack@google.com        finalizeReset(reset);
8913260Sgabeblack@google.com    else
9013288Sgabeblack@google.com        resets.push_back(reset);
9113260Sgabeblack@google.com}
9213260Sgabeblack@google.com
9313260Sgabeblack@google.comvoid
9413207Sgabeblack@google.comPort::finalize()
9513207Sgabeblack@google.com{
9613207Sgabeblack@google.com    if (finalized)
9713207Sgabeblack@google.com        return;
9813207Sgabeblack@google.com    finalized = true;
9913207Sgabeblack@google.com
10013207Sgabeblack@google.com    for (auto &b: bindings) {
10113207Sgabeblack@google.com        if (b->interface) {
10213207Sgabeblack@google.com            addInterface(b->interface);
10313207Sgabeblack@google.com        } else {
10413207Sgabeblack@google.com            b->port->_gem5Port->finalize();
10513207Sgabeblack@google.com            addInterfaces(b->port);
10613207Sgabeblack@google.com        }
10713207Sgabeblack@google.com        delete b;
10813207Sgabeblack@google.com    }
10913207Sgabeblack@google.com
11013207Sgabeblack@google.com    bindings.clear();
11113207Sgabeblack@google.com
11213207Sgabeblack@google.com    for (auto &s: sensitivities) {
11313207Sgabeblack@google.com        if (s->port)
11413207Sgabeblack@google.com            finalizePort(s->port);
11513288Sgabeblack@google.com        else
11613260Sgabeblack@google.com            finalizeFinder(s->finder);
11713207Sgabeblack@google.com        delete s;
11813207Sgabeblack@google.com    }
11913207Sgabeblack@google.com
12013207Sgabeblack@google.com    sensitivities.clear();
12113288Sgabeblack@google.com
12213288Sgabeblack@google.com    for (auto &r: resets)
12313288Sgabeblack@google.com        finalizeReset(r);
12413288Sgabeblack@google.com
12513288Sgabeblack@google.com    resets.clear();
12613207Sgabeblack@google.com}
12713207Sgabeblack@google.com
12813273Sgabeblack@google.comvoid
12913273Sgabeblack@google.comPort::regPort()
13013273Sgabeblack@google.com{
13113273Sgabeblack@google.com    if (!regPortNeeded)
13213273Sgabeblack@google.com        return;
13313273Sgabeblack@google.com
13413273Sgabeblack@google.com    for (int i = 0; i < size(); i++)
13513273Sgabeblack@google.com        getInterface(i)->register_port(*portBase, portBase->_ifTypeName());
13613273Sgabeblack@google.com}
13713273Sgabeblack@google.com
13813207Sgabeblack@google.comstd::list<Port *> allPorts;
13913207Sgabeblack@google.com
14013207Sgabeblack@google.com} // namespace sc_gem5
141