SystemC Library API Reference Manual
Reference documentation for the Simics SystemC Library.
 
Loading...
Searching...
No Matches
gasket_factory.h
Go to the documentation of this file.
1/*
2 © 2013 Intel Corporation
3
4 This software and the related documents are Intel copyrighted materials, and
5 your use of them is governed by the express license under which they were
6 provided to you ("License"). Unless the License provides otherwise, you may
7 not use, modify, copy, publish, distribute, disclose or transmit this software
8 or the related documents without Intel's prior written permission.
9
10 This software and the related documents are provided as is, with no express or
11 implied warranties, other than those that are expressly stated in the License.
12*/
13
14#ifndef SIMICS_SYSTEMC_SIMICS2TLM_GASKET_FACTORY_H
15#define SIMICS_SYSTEMC_SIMICS2TLM_GASKET_FACTORY_H
16
17
18#include <tlm_utils/multi_passthrough_target_socket.h>
19
22
23#include <algorithm>
24#include <string>
25
26namespace simics {
27namespace systemc {
28namespace simics2tlm {
29
30namespace internal {
31
32template<unsigned int BUSWIDTH, typename TYPES>
33static Gasket<BUSWIDTH, TYPES> *createGasket(
34 const std::string& socket_name,
35 const simics::ConfObjectRef &simics_obj) {
36 std::string name = "gasket_" + socket_name;
37 std::replace(name.begin(), name.end(), '.', '_');
38
39 const char* char_name = name.c_str();
40 if (sc_core::sc_find_object(char_name))
41 char_name = sc_core::sc_gen_unique_name(char_name);
42
43 // The raw pointer is eventually managed by shared_ptr
44 return new Gasket<BUSWIDTH, TYPES>(char_name, simics_obj);
45}
46} // namespace internal
47
50
52template<unsigned int BUSWIDTH, typename TYPES,
53 int N, sc_core::sc_port_policy POL>
54static GasketInterface::Ptr createGasket(
55 tlm::tlm_initiator_socket<BUSWIDTH, TYPES, N, POL> *initiator_socket,
56 const simics::ConfObjectRef &simics_obj) {
57 FATAL_ERROR_IF(initiator_socket->name() == NULL,
58 "initiator socket not fully initialized, name missing");
59 auto gasket = internal::createGasket<BUSWIDTH, TYPES>(
60 initiator_socket->name(), simics_obj);
61 gasket->bind(*initiator_socket);
62 return GasketInterface::Ptr(gasket);
63}
64
66template<unsigned int BUSWIDTH, typename TYPES,
67 int N, sc_core::sc_port_policy POL>
68static GasketInterface::Ptr createGasket(
69 tlm::tlm_target_socket<BUSWIDTH, TYPES, N, POL> *target_socket,
70 const simics::ConfObjectRef &simics_obj) {
71 FATAL_ERROR_IF(target_socket->name() == NULL,
72 "target socket not fully initialized, name missing");
73 auto gasket = internal::createGasket<BUSWIDTH, TYPES>(
74 target_socket->name(), simics_obj);
75 gasket->bind(*target_socket);
76 return GasketInterface::Ptr(gasket);
77}
78
81template<typename MODULE, unsigned int BUSWIDTH, typename TYPES,
82 unsigned int N, sc_core::sc_port_policy POL>
83static GasketInterface::Ptr createGasket(
84 tlm_utils::multi_passthrough_target_socket<
85 MODULE, BUSWIDTH, TYPES, N, POL> *target_socket,
86 const simics::ConfObjectRef &simics_obj) {
87 FATAL_ERROR_IF(target_socket->name() == NULL,
88 "target socket not fully initialized, name missing");
89 auto gasket = internal::createGasket<BUSWIDTH, TYPES>(
90 target_socket->name(), simics_obj);
91 gasket->bind(*target_socket);
92 return GasketInterface::Ptr(gasket);
93}
94
97 const simics::ConfObjectRef &simics_obj);
98
100 public:
102 virtual GasketInterface::Ptr create(sc_core::sc_object *object,
103 const ConfObjectRef &simics_obj) = 0;
104};
105
106template <unsigned int BUSWIDTH, typename TYPES, int N = 1,
107 sc_core::sc_port_policy POL = sc_core::SC_ONE_OR_MORE_BOUND>
108class GasketFactory : public Registrant<GasketFactoryInterface> {
109 public:
110 typedef tlm::tlm_base_target_socket<BUSWIDTH,
111 tlm::tlm_fw_transport_if<TYPES>,
112 tlm::tlm_bw_transport_if<TYPES>,
113 N, POL> Socket;
114
115 GasketInterface::Ptr create(sc_core::sc_object *object,
116 const ConfObjectRef &simics_obj) override {
117 Socket *socket = dynamic_cast<Socket *>(object);
118 if (!socket)
119 return NULL;
120
121 auto gasket = internal::createGasket<BUSWIDTH, TYPES>(
122 socket->name(), simics_obj);
123 gasket->bind(*socket);
124 return GasketInterface::Ptr(gasket);
125 }
126};
127
129
130} // namespace simics2tlm
131} // namespace systemc
132} // namespace simics
133
134#endif
Definition: registry.h:86
virtual ~GasketFactoryInterface()
Definition: gasket_factory.h:101
virtual GasketInterface::Ptr create(sc_core::sc_object *object, const ConfObjectRef &simics_obj)=0
Definition: gasket_factory.h:108
GasketInterface::Ptr create(sc_core::sc_object *object, const ConfObjectRef &simics_obj) override
Definition: gasket_factory.h:115
tlm::tlm_base_target_socket< BUSWIDTH, tlm::tlm_fw_transport_if< TYPES >, tlm::tlm_bw_transport_if< TYPES >, N, POL > Socket
Definition: gasket_factory.h:113
std::shared_ptr< GasketInterface > Ptr
Definition: gasket_interface.h:35
Core helper for sending a TLM2 transaction over a socket.
Definition: gasket.h:57
GasketInterface::Ptr createGasketByName(std::string socket_name, const simics::ConfObjectRef &simics_obj)
Factory for creating a Gasket and bind it to a target socket.
Definition: adapter.h:79