113521Sgabeblack@google.com/*****************************************************************************
213521Sgabeblack@google.com
313521Sgabeblack@google.com  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
413521Sgabeblack@google.com  more contributor license agreements.  See the NOTICE file distributed
513521Sgabeblack@google.com  with this work for additional information regarding copyright ownership.
613521Sgabeblack@google.com  Accellera licenses this file to you under the Apache License, Version 2.0
713521Sgabeblack@google.com  (the "License"); you may not use this file except in compliance with the
813521Sgabeblack@google.com  License.  You may obtain a copy of the License at
913521Sgabeblack@google.com
1013521Sgabeblack@google.com    http://www.apache.org/licenses/LICENSE-2.0
1113521Sgabeblack@google.com
1213521Sgabeblack@google.com  Unless required by applicable law or agreed to in writing, software
1313521Sgabeblack@google.com  distributed under the License is distributed on an "AS IS" BASIS,
1413521Sgabeblack@google.com  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
1513521Sgabeblack@google.com  implied.  See the License for the specific language governing
1613521Sgabeblack@google.com  permissions and limitations under the License.
1713521Sgabeblack@google.com
1813521Sgabeblack@google.com *****************************************************************************/
1913521Sgabeblack@google.com
2013521Sgabeblack@google.com#ifndef __SYSTEMC_EXT_TLM_CORE_2_SOCKETS_TARGET_SOCKET_HH__
2113521Sgabeblack@google.com#define __SYSTEMC_EXT_TLM_CORE_2_SOCKETS_TARGET_SOCKET_HH__
2213521Sgabeblack@google.com
2313523Sgabeblack@google.com#include <typeindex>
2413523Sgabeblack@google.com
2513586Sgabeblack@google.com#include "../interfaces/fw_bw_ifs.hh"
2613586Sgabeblack@google.com#include "base_socket_if.hh"
2713521Sgabeblack@google.com
2813521Sgabeblack@google.comnamespace tlm
2913521Sgabeblack@google.com{
3013521Sgabeblack@google.com
3113521Sgabeblack@google.comtemplate <unsigned int BUSWIDTH=32, typename FW_IF=tlm_fw_transport_if<>,
3213521Sgabeblack@google.com          typename BW_IF=tlm_bw_transport_if<>>
3313521Sgabeblack@google.comclass tlm_base_target_socket_b
3413521Sgabeblack@google.com{
3513521Sgabeblack@google.com  public:
3613521Sgabeblack@google.com    virtual ~tlm_base_target_socket_b() {}
3713521Sgabeblack@google.com
3813521Sgabeblack@google.com    virtual sc_core::sc_port_b<BW_IF> &get_base_port() = 0;
3913521Sgabeblack@google.com    virtual sc_core::sc_export<FW_IF> &get_base_export() = 0;
4013521Sgabeblack@google.com    virtual FW_IF &get_base_interface() = 0;
4113521Sgabeblack@google.com};
4213521Sgabeblack@google.com
4313521Sgabeblack@google.comtemplate <unsigned int BUSWIDTH, typename FW_IF, typename BW_IF>
4413521Sgabeblack@google.comclass tlm_base_initiator_socket_b;
4513521Sgabeblack@google.com
4613521Sgabeblack@google.comtemplate <unsigned int BUSWIDTH, typename FW_IF, typename BW_IF, int N,
4713521Sgabeblack@google.com          sc_core::sc_port_policy POL>
4813521Sgabeblack@google.comclass tlm_base_initiator_socket;
4913521Sgabeblack@google.com
5013521Sgabeblack@google.comtemplate <unsigned int BUSWIDTH=32, typename FW_IF=tlm_fw_transport_if<>,
5113521Sgabeblack@google.com          typename BW_IF=tlm_bw_transport_if<>, int N=1,
5213521Sgabeblack@google.com          sc_core::sc_port_policy POL=sc_core::SC_ONE_OR_MORE_BOUND>
5313521Sgabeblack@google.comclass tlm_base_target_socket :
5413521Sgabeblack@google.com    public tlm_base_socket_if,
5513521Sgabeblack@google.com    public tlm_base_target_socket_b<BUSWIDTH, FW_IF, BW_IF>,
5613521Sgabeblack@google.com    public sc_core::sc_export<FW_IF>
5713521Sgabeblack@google.com{
5813521Sgabeblack@google.com  public:
5913521Sgabeblack@google.com    typedef FW_IF fw_interface_type;
6013521Sgabeblack@google.com    typedef BW_IF bw_interface_type;
6113521Sgabeblack@google.com    typedef sc_core::sc_port<bw_interface_type, N, POL> port_type;
6213521Sgabeblack@google.com
6313521Sgabeblack@google.com    typedef sc_core::sc_export<fw_interface_type> export_type;
6413521Sgabeblack@google.com    typedef tlm_base_initiator_socket_b<
6513521Sgabeblack@google.com        BUSWIDTH, fw_interface_type, bw_interface_type>
6613521Sgabeblack@google.com        base_initiator_socket_type;
6713521Sgabeblack@google.com
6813521Sgabeblack@google.com    typedef tlm_base_target_socket_b<
6913521Sgabeblack@google.com        BUSWIDTH, fw_interface_type, bw_interface_type> base_type;
7013521Sgabeblack@google.com
7113521Sgabeblack@google.com    template <unsigned int, typename, typename, int, sc_core::sc_port_policy>
7213521Sgabeblack@google.com    friend class tlm_base_initiator_socket;
7313521Sgabeblack@google.com
7413521Sgabeblack@google.com  public:
7513521Sgabeblack@google.com    tlm_base_target_socket() :
7613521Sgabeblack@google.com        export_type(sc_core::sc_gen_unique_name("tlm_base_target_socket")),
7713521Sgabeblack@google.com        m_port(sc_core::sc_gen_unique_name("tlm_base_target_socket_port"))
7813521Sgabeblack@google.com    {}
7913521Sgabeblack@google.com
8013521Sgabeblack@google.com    explicit tlm_base_target_socket(const char *name) :
8113521Sgabeblack@google.com        export_type(name), m_port(sc_core::sc_gen_unique_name(
8213521Sgabeblack@google.com                    (std::string(name) + "_port").c_str()))
8313521Sgabeblack@google.com    {}
8413521Sgabeblack@google.com
8513521Sgabeblack@google.com    virtual const char *kind() const { return "tlm_base_target_socket"; }
8613521Sgabeblack@google.com
8713521Sgabeblack@google.com    //
8813521Sgabeblack@google.com    // Bind target socket to initiator socket
8913521Sgabeblack@google.com    // - Binds the port of the initiator socket to the export of the target
9013521Sgabeblack@google.com    //   socket
9113521Sgabeblack@google.com    // - Binds the port of the target socket to the export of the initiator
9213521Sgabeblack@google.com    //   socket
9313521Sgabeblack@google.com    //
9413521Sgabeblack@google.com    virtual void
9513521Sgabeblack@google.com    bind(base_initiator_socket_type &s)
9613521Sgabeblack@google.com    {
9713521Sgabeblack@google.com        // initiator.port -> target.export
9813521Sgabeblack@google.com        (s.get_base_port())(get_base_interface());
9913521Sgabeblack@google.com        // target.port -> initiator.export
10013521Sgabeblack@google.com        get_base_port()(s.get_base_interface());
10113521Sgabeblack@google.com    }
10213521Sgabeblack@google.com
10313521Sgabeblack@google.com    void operator () (base_initiator_socket_type &s) { bind(s); }
10413521Sgabeblack@google.com
10513521Sgabeblack@google.com    //
10613521Sgabeblack@google.com    // Bind target socket to target socket (hierarchical bind)
10713521Sgabeblack@google.com    // - Binds both the export and the port
10813521Sgabeblack@google.com    //
10913521Sgabeblack@google.com    virtual void
11013521Sgabeblack@google.com    bind(base_type &s)
11113521Sgabeblack@google.com    {
11213521Sgabeblack@google.com        // export
11313521Sgabeblack@google.com        (get_base_export())(s.get_base_export());
11413521Sgabeblack@google.com        // port
11513521Sgabeblack@google.com        (s.get_base_port())(get_base_port());
11613521Sgabeblack@google.com    }
11713521Sgabeblack@google.com
11813521Sgabeblack@google.com    void operator () (base_type &s) { bind(s); }
11913521Sgabeblack@google.com
12013521Sgabeblack@google.com    //
12113521Sgabeblack@google.com    // Bind interface to socket
12213521Sgabeblack@google.com    // - Binds the interface to the export
12313521Sgabeblack@google.com    //
12413521Sgabeblack@google.com    virtual void
12513521Sgabeblack@google.com    bind(fw_interface_type &ifs)
12613521Sgabeblack@google.com    {
12713521Sgabeblack@google.com        export_type *exp = &get_base_export();
12813521Sgabeblack@google.com        if (this == exp) {
12913521Sgabeblack@google.com            export_type::bind(ifs);
13013521Sgabeblack@google.com        } else {
13113521Sgabeblack@google.com            exp->bind( ifs );
13213521Sgabeblack@google.com        }
13313521Sgabeblack@google.com    }
13413521Sgabeblack@google.com
13513521Sgabeblack@google.com    void operator () (fw_interface_type &s) { bind(s); }
13613521Sgabeblack@google.com
13713521Sgabeblack@google.com    //
13813521Sgabeblack@google.com    // Forward to 'size()' of port class.
13913521Sgabeblack@google.com    //
14013521Sgabeblack@google.com    int size() const { return m_port.size(); }
14113521Sgabeblack@google.com
14213521Sgabeblack@google.com    //
14313521Sgabeblack@google.com    // Forward to 'operator->()' of port class.
14413521Sgabeblack@google.com    //
14513521Sgabeblack@google.com    bw_interface_type *operator->() { return m_port.operator->(); }
14613521Sgabeblack@google.com
14713521Sgabeblack@google.com    //
14813521Sgabeblack@google.com    // Forward to 'operator[]()' of port class.
14913521Sgabeblack@google.com    //
15013521Sgabeblack@google.com    bw_interface_type *operator[](int i) { return m_port.operator[](i); }
15113521Sgabeblack@google.com
15213521Sgabeblack@google.com    // Implementation of tlm_base_socket_if functions.
15313521Sgabeblack@google.com    virtual sc_core::sc_port_base &get_port_base() { return m_port; }
15413521Sgabeblack@google.com    virtual sc_core::sc_port_base const &
15513521Sgabeblack@google.com    get_port_base() const
15613521Sgabeblack@google.com    {
15713521Sgabeblack@google.com        return m_port;
15813521Sgabeblack@google.com    }
15913521Sgabeblack@google.com    virtual sc_core::sc_export_base &get_export_base() { return *this; }
16013521Sgabeblack@google.com    virtual sc_core::sc_export_base const &
16113521Sgabeblack@google.com    get_export_base() const
16213521Sgabeblack@google.com    {
16313521Sgabeblack@google.com        return *this;
16413521Sgabeblack@google.com    }
16513521Sgabeblack@google.com    virtual unsigned int get_bus_width() const { return BUSWIDTH; }
16613521Sgabeblack@google.com    virtual tlm_socket_category
16713521Sgabeblack@google.com    get_socket_category() const
16813521Sgabeblack@google.com    {
16913521Sgabeblack@google.com        return TLM_TARGET_SOCKET;
17013521Sgabeblack@google.com    }
17113521Sgabeblack@google.com
17213521Sgabeblack@google.com    // Implementation of tlm_base_target_socket_b functions
17313521Sgabeblack@google.com    virtual sc_core::sc_port_b<BW_IF> &get_base_port() { return m_port; }
17413521Sgabeblack@google.com    virtual sc_core::sc_port_b<BW_IF> const &
17513521Sgabeblack@google.com    get_base_port() const
17613521Sgabeblack@google.com    {
17713521Sgabeblack@google.com        return m_port;
17813521Sgabeblack@google.com    }
17913521Sgabeblack@google.com
18013521Sgabeblack@google.com    virtual FW_IF &get_base_interface() { return *this; }
18113521Sgabeblack@google.com    virtual FW_IF const &get_base_interface() const { return *this; }
18213521Sgabeblack@google.com
18313521Sgabeblack@google.com    virtual sc_core::sc_export<FW_IF> &get_base_export() { return *this; }
18413521Sgabeblack@google.com    virtual sc_core::sc_export<FW_IF> const &
18513521Sgabeblack@google.com    get_base_export() const
18613521Sgabeblack@google.com    {
18713521Sgabeblack@google.com        return *this;
18813521Sgabeblack@google.com    }
18913521Sgabeblack@google.com
19013521Sgabeblack@google.com  protected:
19113521Sgabeblack@google.com    port_type m_port;
19213521Sgabeblack@google.com};
19313521Sgabeblack@google.com
19413521Sgabeblack@google.comtemplate <unsigned int BUSWIDTH=32, typename TYPES=tlm_base_protocol_types,
19513521Sgabeblack@google.com          int N=1, sc_core::sc_port_policy POL=sc_core::SC_ONE_OR_MORE_BOUND>
19613521Sgabeblack@google.comclass tlm_target_socket :
19713521Sgabeblack@google.com    public tlm_base_target_socket<
19813521Sgabeblack@google.com        BUSWIDTH, tlm_fw_transport_if<TYPES>,
19913521Sgabeblack@google.com        tlm_bw_transport_if<TYPES>, N, POL>
20013521Sgabeblack@google.com{
20113521Sgabeblack@google.com  public:
20213521Sgabeblack@google.com    tlm_target_socket() :
20313521Sgabeblack@google.com        tlm_base_target_socket<
20413521Sgabeblack@google.com            BUSWIDTH, tlm_fw_transport_if<TYPES>,
20513521Sgabeblack@google.com            tlm_bw_transport_if<TYPES>, N, POL>()
20613521Sgabeblack@google.com    {}
20713521Sgabeblack@google.com
20813521Sgabeblack@google.com    explicit tlm_target_socket(const char *name) :
20913521Sgabeblack@google.com        tlm_base_target_socket<
21013521Sgabeblack@google.com            BUSWIDTH, tlm_fw_transport_if<TYPES>,
21113521Sgabeblack@google.com            tlm_bw_transport_if<TYPES>, N, POL>(name)
21213521Sgabeblack@google.com    {}
21313521Sgabeblack@google.com
21413521Sgabeblack@google.com    virtual const char* kind() const { return "tlm_target_socket"; }
21513521Sgabeblack@google.com
21613523Sgabeblack@google.com    virtual std::type_index
21713521Sgabeblack@google.com    get_protocol_types() const
21813521Sgabeblack@google.com    {
21913521Sgabeblack@google.com        return typeid(TYPES);
22013521Sgabeblack@google.com    }
22113521Sgabeblack@google.com};
22213521Sgabeblack@google.com
22313521Sgabeblack@google.com} // namespace tlm
22413521Sgabeblack@google.com
22513521Sgabeblack@google.com#endif /* __SYSTEMC_EXT_TLM_CORE_2_SOCKETS_TARGET_SOCKET_HH__ */
226