scc  2022.4.0
SystemC components library
tlm2_pv_av.h
1 /*******************************************************************************
2  * Copyright 2020 MINRES Technologies GmbH
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *******************************************************************************/
16 
17 #ifndef _TLM_TLM2_PV_AV_H_
18 #define _TLM_TLM2_PV_AV_H_
19 
20 #include <memory>
21 #include <tlm>
22 #include <util/ities.h>
23 
25 namespace tlm {
27 namespace scc {
28 
29 template <unsigned int BUSWIDTH = 32, typename TYPES = tlm_base_protocol_types, int N = 1,
30  sc_core::sc_port_policy POL = sc_core::SC_ONE_OR_MORE_BOUND,
31  typename TSOCKET_TYPE = tlm::tlm_target_socket<BUSWIDTH, TYPES, N, POL>,
32  typename ISOCKET_TYPE = tlm::tlm_initiator_socket<BUSWIDTH, TYPES, N, POL>>
33 class tlm2_pv_av_target_adapter : public sc_core::sc_module,
34  public tlm::tlm_fw_transport_if<TYPES>,
35  public tlm::tlm_bw_transport_if<TYPES> {
36 public:
37  using tlm_payload_type = typename TYPES::tlm_payload_type;
38  using tlm_phase_type = typename TYPES::tlm_phase_type;
39  using target_socket_type = TSOCKET_TYPE;
40  using initiator_socket_type = ISOCKET_TYPE;
41 
42  target_socket_type tsck{"tsck"};
43 
45  : tlm2_pv_av_target_adapter(sc_core::sc_gen_unique_name("tlm_pv_av_split")) {}
46 
47  tlm2_pv_av_target_adapter(sc_core::sc_module_name const& nm)
48  : sc_core::sc_module(nm) {
49  tsck.bind(*this);
50  }
51 
52  void bind_pv(target_socket_type& tsck) {
53  pv_isck = util::make_unique<initiator_socket_type>(sc_core::sc_gen_unique_name("pv_isck"));
54  pv_isck->bind(*this);
55  pv_isck->bind(tsck);
56  }
57 
58  void bind_av(TSOCKET_TYPE& tsck) {
59  av_isck = util::make_unique<initiator_socket_type>(sc_core::sc_gen_unique_name("av_isck"));
60  av_isck->bind(*this);
61  av_isck->bind(tsck);
62  }
63 
64  virtual ~tlm2_pv_av_target_adapter() = default;
65 
66 private:
67  tlm::tlm_sync_enum nb_transport_fw(tlm_payload_type& trans, tlm_phase_type& phase, sc_core::sc_time& t) {
68  if(av_isck)
69  return (*av_isck)->nb_transport_fw(trans, phase, t);
70  trans.set_response_status(tlm::TLM_GENERIC_ERROR_RESPONSE);
71  return tlm::TLM_COMPLETED;
72  };
73 
74  void b_transport(tlm_payload_type& trans, sc_core::sc_time& t) {
75  if(pv_isck)
76  (*pv_isck)->b_transport(trans, t);
77  else
78  trans.set_response_status(tlm::TLM_GENERIC_ERROR_RESPONSE);
79  }
80 
81  bool get_direct_mem_ptr(tlm_payload_type& trans, tlm_dmi& dmi_data) {
82  if(pv_isck)
83  return (*pv_isck)->get_direct_mem_ptr(trans, dmi_data);
84  trans.set_response_status(tlm::TLM_GENERIC_ERROR_RESPONSE);
85  trans.set_dmi_allowed(false);
86  return false;
87  }
88 
89  unsigned int transport_dbg(tlm_payload_type& trans) {
90  if(pv_isck)
91  return (*pv_isck)->transport_dbg(trans);
92  trans.set_response_status(tlm::TLM_GENERIC_ERROR_RESPONSE);
93  return 0;
94  }
95 
96  tlm::tlm_sync_enum nb_transport_bw(tlm_payload_type& trans, tlm_phase_type& phase, sc_core::sc_time& t) {
97  return tsck->nb_transport_bw(trans, phase, t);
98  }
99 
100  void invalidate_direct_mem_ptr(sc_dt::uint64 start_range, sc_dt::uint64 end_range) {
101  tsck->invalidate_direct_mem_ptr(start_range, end_range);
102  }
103 
104  std::unique_ptr<initiator_socket_type> pv_isck;
105  std::unique_ptr<initiator_socket_type> av_isck;
106 };
107 
108 template <unsigned int BUSWIDTH = 32, typename TYPES = tlm_base_protocol_types, int N = 1,
109  sc_core::sc_port_policy POL = sc_core::SC_ONE_OR_MORE_BOUND,
110  typename TSOCKET_TYPE = tlm::tlm_target_socket<BUSWIDTH, TYPES, N, POL>,
111  typename ISOCKET_TYPE = tlm::tlm_initiator_socket<BUSWIDTH, TYPES, N, POL>>
112 class tlm2_pv_av_initiator_adapter : public sc_core::sc_module,
113  public tlm::tlm_fw_transport_if<TYPES>,
114  public tlm::tlm_bw_transport_if<TYPES> {
115 public:
116  using tlm_payload_type = typename TYPES::tlm_payload_type;
117  using tlm_phase_type = typename TYPES::tlm_phase_type;
118  using target_socket_type = TSOCKET_TYPE;
119  using initiator_socket_type = ISOCKET_TYPE;
120 
121  initiator_socket_type isck{"isck"};
122 
124  : tlm2_pv_av_initiator_adapter(sc_core::sc_gen_unique_name("tlm_pv_av_split")) {}
125 
126  tlm2_pv_av_initiator_adapter(sc_core::sc_module_name const& nm)
127  : sc_core::sc_module(nm) {
128  isck.bind(*this);
129  }
130 
131  void bind_pv(initiator_socket_type& isck) {
132  pv_tsck = util::make_unique<target_socket_type>(sc_core::sc_gen_unique_name("pv_tsck"));
133  pv_tsck->bind(*this);
134  isck(*pv_tsck);
135  }
136 
137  void bind_av(initiator_socket_type& isck) {
138  av_tsck = util::make_unique<target_socket_type>(sc_core::sc_gen_unique_name("av_tsck"));
139  av_tsck->bind(*this);
140  isck(*av_tsck);
141  }
142 
143  virtual ~tlm2_pv_av_initiator_adapter() = default;
144 
145 private:
146  tlm::tlm_sync_enum nb_transport_fw(tlm_payload_type& trans, tlm_phase_type& phase, sc_core::sc_time& t) {
147  return isck->nb_transport_fw(trans, phase, t);
148  };
149 
150  void b_transport(tlm_payload_type& trans, sc_core::sc_time& t) { isck->b_transport(trans, t); }
151 
152  bool get_direct_mem_ptr(tlm_payload_type& trans, tlm_dmi& dmi_data) { return isck->get_direct_mem_ptr(trans, dmi_data); }
153 
154  unsigned int transport_dbg(tlm_payload_type& trans) { return isck->transport_dbg(trans); }
155 
156  tlm::tlm_sync_enum nb_transport_bw(tlm_payload_type& trans, tlm_phase_type& phase, sc_core::sc_time& t) {
157  if(av_tsck)
158  return (*av_tsck)->nb_transport_bw(trans, phase, t);
159  trans.set_response_status(tlm::TLM_GENERIC_ERROR_RESPONSE);
160  return tlm::TLM_COMPLETED;
161  }
162 
163  void invalidate_direct_mem_ptr(sc_dt::uint64 start_range, sc_dt::uint64 end_range) {
164  if(pv_tsck)
165  (*pv_tsck)->invalidate_direct_mem_ptr(start_range, end_range);
166  }
167 
168  std::unique_ptr<target_socket_type> pv_tsck{};
169  std::unique_ptr<target_socket_type> av_tsck{};
170 };
171 
172 } // namespace scc
173 } /* namespace tlm */
174 
175 #endif /* OSCI_LIB_SCC_INCL_TLM_TLM2_PV_AV_TARGET_ADAPTER_H_ */
SCC SystemC utilities.
SystemC TLM.