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