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_INITIATOR_SOCKET_HH__
2113521Sgabeblack@google.com#define __SYSTEMC_EXT_TLM_CORE_2_SOCKETS_INITIATOR_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,
3213521Sgabeblack@google.com          typename FW_IF=tlm_fw_transport_if<>,
3313521Sgabeblack@google.com          typename BW_IF=tlm_bw_transport_if<>>
3413521Sgabeblack@google.comclass tlm_base_initiator_socket_b
3513521Sgabeblack@google.com{
3613521Sgabeblack@google.com  public:
3713521Sgabeblack@google.com    virtual ~tlm_base_initiator_socket_b() {}
3813521Sgabeblack@google.com
3913521Sgabeblack@google.com    virtual sc_core::sc_port_b<FW_IF> &get_base_port() = 0;
4013521Sgabeblack@google.com    virtual sc_core::sc_port_b<FW_IF> const &get_base_port() const = 0;
4113521Sgabeblack@google.com    virtual BW_IF &get_base_interface() = 0;
4213521Sgabeblack@google.com    virtual BW_IF const &get_base_interface() const = 0;
4313521Sgabeblack@google.com    virtual sc_core::sc_export<BW_IF> &get_base_export() = 0;
4413521Sgabeblack@google.com    virtual sc_core::sc_export<BW_IF> const &get_base_export() const = 0;
4513521Sgabeblack@google.com};
4613521Sgabeblack@google.com
4713521Sgabeblack@google.comtemplate <unsigned int BUSWIDTH, typename FW_IF, typename BW_IF>
4813521Sgabeblack@google.comclass tlm_base_target_socket_b;
4913521Sgabeblack@google.com
5013521Sgabeblack@google.comtemplate <unsigned int BUSWIDTH, typename FW_IF, typename BW_IF, int N,
5113521Sgabeblack@google.com          sc_core::sc_port_policy POL>
5213521Sgabeblack@google.comclass tlm_base_target_socket;
5313521Sgabeblack@google.com
5413521Sgabeblack@google.comtemplate <unsigned int BUSWIDTH=32, typename FW_IF=tlm_fw_transport_if<>,
5513521Sgabeblack@google.com          typename BW_IF=tlm_bw_transport_if<>, int N=1,
5613521Sgabeblack@google.com          sc_core::sc_port_policy POL=sc_core::SC_ONE_OR_MORE_BOUND>
5713521Sgabeblack@google.comclass tlm_base_initiator_socket :
5813521Sgabeblack@google.com    public tlm_base_socket_if,
5913521Sgabeblack@google.com    public tlm_base_initiator_socket_b<BUSWIDTH, FW_IF, BW_IF>,
6013521Sgabeblack@google.com    public sc_core::sc_port<FW_IF, N, POL>
6113521Sgabeblack@google.com{
6213521Sgabeblack@google.com  public:
6313521Sgabeblack@google.com    typedef FW_IF fw_interface_type;
6413521Sgabeblack@google.com    typedef BW_IF bw_interface_type;
6513521Sgabeblack@google.com    typedef sc_core::sc_port<fw_interface_type, N, POL> port_type;
6613521Sgabeblack@google.com
6713521Sgabeblack@google.com    typedef sc_core::sc_export<bw_interface_type> export_type;
6813521Sgabeblack@google.com
6913521Sgabeblack@google.com    typedef tlm_base_target_socket_b<
7013521Sgabeblack@google.com        BUSWIDTH, fw_interface_type, bw_interface_type>
7113521Sgabeblack@google.com        base_target_socket_type;
7213521Sgabeblack@google.com    typedef tlm_base_initiator_socket_b<
7313521Sgabeblack@google.com        BUSWIDTH, fw_interface_type, bw_interface_type> base_type;
7413521Sgabeblack@google.com
7513521Sgabeblack@google.com    template <unsigned int, typename, typename, int, sc_core::sc_port_policy>
7613521Sgabeblack@google.com    friend class tlm_base_target_socket;
7713521Sgabeblack@google.com
7813521Sgabeblack@google.com  public:
7913521Sgabeblack@google.com    tlm_base_initiator_socket() :
8013521Sgabeblack@google.com        port_type(sc_core::sc_gen_unique_name("tlm_base_initiator_socket")),
8113521Sgabeblack@google.com        m_export(sc_core::sc_gen_unique_name(
8213521Sgabeblack@google.com                    "tlm_base_initiator_socket_export"))
8313521Sgabeblack@google.com    {}
8413521Sgabeblack@google.com
8513521Sgabeblack@google.com    explicit tlm_base_initiator_socket(const char *name) : port_type(name),
8613521Sgabeblack@google.com        m_export(sc_core::sc_gen_unique_name(
8713521Sgabeblack@google.com                    (std::string(name) + "_export").c_str()))
8813521Sgabeblack@google.com    {}
8913521Sgabeblack@google.com
9013521Sgabeblack@google.com    virtual const char* kind() const { return "tlm_base_initiator_socket"; }
9113521Sgabeblack@google.com
9213521Sgabeblack@google.com    //
9313521Sgabeblack@google.com    // Bind initiator socket to target socket
9413521Sgabeblack@google.com    // - Binds the port of the initiator socket to the export of the target
9513521Sgabeblack@google.com    //   socket
9613521Sgabeblack@google.com    // - Binds the port of the target socket to the export of the initiator
9713521Sgabeblack@google.com    //   socket
9813521Sgabeblack@google.com    //
9913521Sgabeblack@google.com    virtual void
10013521Sgabeblack@google.com    bind(base_target_socket_type &s)
10113521Sgabeblack@google.com    {
10213521Sgabeblack@google.com        // initiator.port -> target.export
10313521Sgabeblack@google.com        (get_base_port())(s.get_base_interface());
10413521Sgabeblack@google.com        // target.port -> initiator.export
10513521Sgabeblack@google.com        (s.get_base_port())(get_base_interface());
10613521Sgabeblack@google.com    }
10713521Sgabeblack@google.com
10813521Sgabeblack@google.com    void operator () (base_target_socket_type &s) { bind(s); }
10913521Sgabeblack@google.com
11013521Sgabeblack@google.com    //
11113521Sgabeblack@google.com    // Bind initiator socket to initiator socket (hierarchical bind)
11213521Sgabeblack@google.com    // - Binds both the export and the port
11313521Sgabeblack@google.com    //
11413521Sgabeblack@google.com    virtual void
11513521Sgabeblack@google.com    bind(base_type &s)
11613521Sgabeblack@google.com    {
11713521Sgabeblack@google.com        // port
11813521Sgabeblack@google.com        (get_base_port())(s.get_base_port());
11913521Sgabeblack@google.com        // export
12013521Sgabeblack@google.com        (s.get_base_export())(get_base_export());
12113521Sgabeblack@google.com    }
12213521Sgabeblack@google.com
12313521Sgabeblack@google.com    void operator() (base_type &s) { bind(s); }
12413521Sgabeblack@google.com
12513521Sgabeblack@google.com    //
12613521Sgabeblack@google.com    // Bind interface to socket
12713521Sgabeblack@google.com    // - Binds the interface to the export of this socket
12813521Sgabeblack@google.com    //
12913521Sgabeblack@google.com    virtual void bind(bw_interface_type &ifs) { (get_base_export())(ifs); }
13013521Sgabeblack@google.com    void operator() (bw_interface_type &s) { bind(s); }
13113521Sgabeblack@google.com
13213521Sgabeblack@google.com    // Implementation of tlm_base_socket_if functions
13313521Sgabeblack@google.com    virtual sc_core::sc_port_base &get_port_base() { return *this; }
13413521Sgabeblack@google.com    virtual sc_core::sc_port_base const &
13513521Sgabeblack@google.com    get_port_base() const
13613521Sgabeblack@google.com    {
13713521Sgabeblack@google.com        return *this;
13813521Sgabeblack@google.com    }
13913521Sgabeblack@google.com    virtual sc_core::sc_export_base &get_export_base() { return m_export; }
14013521Sgabeblack@google.com    virtual sc_core::sc_export_base const &
14113521Sgabeblack@google.com    get_export_base() const
14213521Sgabeblack@google.com    {
14313521Sgabeblack@google.com        return m_export;
14413521Sgabeblack@google.com    }
14513521Sgabeblack@google.com    virtual unsigned int get_bus_width() const { return BUSWIDTH; }
14613521Sgabeblack@google.com    virtual tlm_socket_category
14713521Sgabeblack@google.com    get_socket_category() const
14813521Sgabeblack@google.com    {
14913521Sgabeblack@google.com        return TLM_INITIATOR_SOCKET;
15013521Sgabeblack@google.com    }
15113521Sgabeblack@google.com
15213521Sgabeblack@google.com    // Implementation of tlm_base_target_socket_b functions
15313521Sgabeblack@google.com    virtual sc_core::sc_port_b<FW_IF> &get_base_port() { return *this; }
15413521Sgabeblack@google.com    virtual sc_core::sc_port_b<FW_IF> const &
15513521Sgabeblack@google.com    get_base_port() const
15613521Sgabeblack@google.com    {
15713521Sgabeblack@google.com        return *this;
15813521Sgabeblack@google.com    }
15913521Sgabeblack@google.com
16013521Sgabeblack@google.com    virtual BW_IF &get_base_interface() { return m_export; }
16113521Sgabeblack@google.com    virtual BW_IF const &get_base_interface() const { return m_export; }
16213521Sgabeblack@google.com
16313521Sgabeblack@google.com    virtual sc_core::sc_export<BW_IF> &get_base_export() { return m_export; }
16413521Sgabeblack@google.com    virtual sc_core::sc_export<BW_IF> const &
16513521Sgabeblack@google.com    get_base_export() const
16613521Sgabeblack@google.com    {
16713521Sgabeblack@google.com        return m_export;
16813521Sgabeblack@google.com    }
16913521Sgabeblack@google.com
17013521Sgabeblack@google.com  protected:
17113521Sgabeblack@google.com    export_type m_export;
17213521Sgabeblack@google.com};
17313521Sgabeblack@google.com
17413521Sgabeblack@google.com//
17513521Sgabeblack@google.com// Convenience socket classes
17613521Sgabeblack@google.com//
17713521Sgabeblack@google.com
17813521Sgabeblack@google.comtemplate <unsigned int BUSWIDTH=32, typename TYPES=tlm_base_protocol_types,
17913521Sgabeblack@google.com          int N=1, sc_core::sc_port_policy POL=sc_core::SC_ONE_OR_MORE_BOUND>
18013521Sgabeblack@google.comclass tlm_initiator_socket : public tlm_base_initiator_socket<
18113521Sgabeblack@google.com                             BUSWIDTH, tlm_fw_transport_if<TYPES>,
18213521Sgabeblack@google.com                             tlm_bw_transport_if<TYPES>, N, POL>
18313521Sgabeblack@google.com{
18413521Sgabeblack@google.com  public:
18513521Sgabeblack@google.com    tlm_initiator_socket() : tlm_base_initiator_socket<
18613521Sgabeblack@google.com                             BUSWIDTH, tlm_fw_transport_if<TYPES>,
18713521Sgabeblack@google.com                             tlm_bw_transport_if<TYPES>, N, POL>()
18813521Sgabeblack@google.com    {}
18913521Sgabeblack@google.com
19013521Sgabeblack@google.com    explicit tlm_initiator_socket(const char *name) :
19113521Sgabeblack@google.com        tlm_base_initiator_socket<BUSWIDTH, tlm_fw_transport_if<TYPES>,
19213521Sgabeblack@google.com                                  tlm_bw_transport_if<TYPES>, N, POL>(name)
19313521Sgabeblack@google.com    {}
19413521Sgabeblack@google.com
19513521Sgabeblack@google.com    virtual const char *kind() const { return "tlm_initiator_socket"; }
19613521Sgabeblack@google.com
19713523Sgabeblack@google.com    virtual std::type_index
19813521Sgabeblack@google.com    get_protocol_types() const
19913521Sgabeblack@google.com    {
20013521Sgabeblack@google.com        return typeid(TYPES);
20113521Sgabeblack@google.com    }
20213521Sgabeblack@google.com};
20313521Sgabeblack@google.com
20413521Sgabeblack@google.com} // namespace tlm
20513521Sgabeblack@google.com
20613521Sgabeblack@google.com#endif /* __SYSTEMC_EXT_TLM_CORE_2_SOCKETS_INITIATOR_SOCKET_HH__ */
207