port.hh revision 13207
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#ifndef __SYSTEMC_CORE_PORT_HH__
3113207Sgabeblack@google.com#define __SYSTEMC_CORE_PORT_HH__
3213207Sgabeblack@google.com
3313207Sgabeblack@google.com#include <list>
3413207Sgabeblack@google.com#include <vector>
3513207Sgabeblack@google.com
3613207Sgabeblack@google.com#include "systemc/ext/core/sc_interface.hh"
3713207Sgabeblack@google.com#include "systemc/ext/core/sc_port.hh"
3813207Sgabeblack@google.com
3913207Sgabeblack@google.comnamespace sc_gem5
4013207Sgabeblack@google.com{
4113207Sgabeblack@google.com
4213207Sgabeblack@google.comclass StaticSensitivityPort;
4313207Sgabeblack@google.comclass StaticSensitivityFinder;
4413207Sgabeblack@google.com
4513207Sgabeblack@google.comclass Port;
4613207Sgabeblack@google.com
4713207Sgabeblack@google.comextern std::list<Port *> allPorts;
4813207Sgabeblack@google.com
4913207Sgabeblack@google.comclass Port
5013207Sgabeblack@google.com{
5113207Sgabeblack@google.com  private:
5213207Sgabeblack@google.com    ::sc_core::sc_port_base *portBase;
5313207Sgabeblack@google.com
5413207Sgabeblack@google.com    bool finalized;
5513207Sgabeblack@google.com    int _maxSize;
5613207Sgabeblack@google.com    int _size;
5713207Sgabeblack@google.com
5813207Sgabeblack@google.com    void finalizePort(StaticSensitivityPort *port);
5913207Sgabeblack@google.com    void finalizeFinder(StaticSensitivityFinder *finder);
6013207Sgabeblack@google.com
6113207Sgabeblack@google.com    void
6213207Sgabeblack@google.com    addInterface(::sc_core::sc_interface *i)
6313207Sgabeblack@google.com    {
6413207Sgabeblack@google.com        _size++;
6513207Sgabeblack@google.com        portBase->_gem5AddInterface(i);
6613207Sgabeblack@google.com    }
6713207Sgabeblack@google.com
6813207Sgabeblack@google.com    void
6913207Sgabeblack@google.com    addInterfaces(::sc_core::sc_port_base *pb)
7013207Sgabeblack@google.com    {
7113207Sgabeblack@google.com        for (int i = 0; i < pb->size(); i++)
7213207Sgabeblack@google.com            addInterface(pb->_gem5Interface(i));
7313207Sgabeblack@google.com    }
7413207Sgabeblack@google.com
7513207Sgabeblack@google.com    ::sc_core::sc_interface *
7613207Sgabeblack@google.com    getInterface(int i)
7713207Sgabeblack@google.com    {
7813207Sgabeblack@google.com        return portBase->_gem5Interface(i);
7913207Sgabeblack@google.com    }
8013207Sgabeblack@google.com
8113207Sgabeblack@google.com    struct Binding
8213207Sgabeblack@google.com    {
8313207Sgabeblack@google.com        explicit Binding(::sc_core::sc_interface *interface) :
8413207Sgabeblack@google.com            interface(interface), port(nullptr)
8513207Sgabeblack@google.com        {}
8613207Sgabeblack@google.com
8713207Sgabeblack@google.com        explicit Binding(::sc_core::sc_port_base *port) :
8813207Sgabeblack@google.com            interface(nullptr), port(port)
8913207Sgabeblack@google.com        {}
9013207Sgabeblack@google.com
9113207Sgabeblack@google.com        ::sc_core::sc_interface *interface;
9213207Sgabeblack@google.com        ::sc_core::sc_port_base *port;
9313207Sgabeblack@google.com    };
9413207Sgabeblack@google.com
9513207Sgabeblack@google.com    struct Sensitivity
9613207Sgabeblack@google.com    {
9713207Sgabeblack@google.com        Sensitivity(StaticSensitivityPort *port) :
9813207Sgabeblack@google.com            port(port), finder(nullptr)
9913207Sgabeblack@google.com        {}
10013207Sgabeblack@google.com
10113207Sgabeblack@google.com        Sensitivity(StaticSensitivityFinder *finder) :
10213207Sgabeblack@google.com            port(nullptr), finder(finder)
10313207Sgabeblack@google.com        {}
10413207Sgabeblack@google.com
10513207Sgabeblack@google.com        StaticSensitivityPort *port;
10613207Sgabeblack@google.com        StaticSensitivityFinder *finder;
10713207Sgabeblack@google.com    };
10813207Sgabeblack@google.com
10913207Sgabeblack@google.com    std::vector<Binding *> bindings;
11013207Sgabeblack@google.com    std::vector<Sensitivity *> sensitivities;
11113207Sgabeblack@google.com
11213207Sgabeblack@google.com  public:
11313207Sgabeblack@google.com    static Port *
11413207Sgabeblack@google.com    fromPort(const ::sc_core::sc_port_base *pb)
11513207Sgabeblack@google.com    {
11613207Sgabeblack@google.com        return pb->_gem5Port;
11713207Sgabeblack@google.com    }
11813207Sgabeblack@google.com
11913207Sgabeblack@google.com    ::sc_core::sc_port_base *sc_port_base() { return portBase; }
12013207Sgabeblack@google.com
12113207Sgabeblack@google.com    Port(::sc_core::sc_port_base *port_base, int max) :
12213207Sgabeblack@google.com        portBase(port_base), finalized(false), _maxSize(max), _size(0)
12313207Sgabeblack@google.com    {
12413207Sgabeblack@google.com        allPorts.push_front(this);
12513207Sgabeblack@google.com    }
12613207Sgabeblack@google.com
12713207Sgabeblack@google.com    void
12813207Sgabeblack@google.com    bind(::sc_core::sc_interface *interface)
12913207Sgabeblack@google.com    {
13013207Sgabeblack@google.com        bindings.push_back(new Binding(interface));
13113207Sgabeblack@google.com    }
13213207Sgabeblack@google.com
13313207Sgabeblack@google.com    void
13413207Sgabeblack@google.com    bind(::sc_core::sc_port_base *port)
13513207Sgabeblack@google.com    {
13613207Sgabeblack@google.com        bindings.push_back(new Binding(port));
13713207Sgabeblack@google.com    }
13813207Sgabeblack@google.com
13913207Sgabeblack@google.com    void sensitive(StaticSensitivityPort *port);
14013207Sgabeblack@google.com    void sensitive(StaticSensitivityFinder *finder);
14113207Sgabeblack@google.com
14213207Sgabeblack@google.com    void finalize();
14313207Sgabeblack@google.com
14413207Sgabeblack@google.com    int size() { return _size; }
14513207Sgabeblack@google.com    int maxSize() { return _maxSize; }
14613207Sgabeblack@google.com};
14713207Sgabeblack@google.com
14813207Sgabeblack@google.com} // namespace sc_gem5
14913207Sgabeblack@google.com
15013207Sgabeblack@google.com#endif // __SYSTEMC_CORE_PORT_HH__
151