SystemC Library API Reference Manual
Reference documentation for the Simics SystemC Library.
 
Loading...
Searching...
No Matches
tlm_bw_transport_if_handler.h
Go to the documentation of this file.
1/*
2 © 2015 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_AWARENESS_TLM_BW_TRANSPORT_IF_HANDLER_H
15#define SIMICS_SYSTEMC_AWARENESS_TLM_BW_TRANSPORT_IF_HANDLER_H
16
17
18
24
25#include <tlm>
26#include <unordered_map>
27
28namespace simics {
29namespace systemc {
30namespace awareness {
31
32template <typename TYPES = tlm::tlm_base_protocol_types>
34 : public TlmBaseHandler,
35 public tlm::tlm_bw_transport_if<TYPES> {
36 public:
37 typedef tlm::tlm_bw_transport_if<TYPES> BW_IF;
39 : is_active_(false) {}
40 void enable() override {
41 if (is_active_)
42 return;
43
44 if (!iface())
45 return;
46
47 is_active_ = true;
48 bw_if()->invalidate_direct_mem_ptr(0,
49 static_cast<sc_dt::uint64>(-1));
50 }
51 void disable() override {
52 is_active_ = false;
53 }
54
55 typedef typename TYPES::tlm_payload_type transaction_type;
56 typedef typename TYPES::tlm_phase_type phase_type;
57 void invalidate_direct_mem_ptr(sc_dt::uint64 start_range,
58 sc_dt::uint64 end_range) override {
61 invalidate_direct_mem_ptr_pre,
62 proxy(), &start_range, &end_range);
63 BW_IF* bw = bw_if();
64 // MPInitiatorSocket does not provide an iface on its export.
65 // When a tool is inserted to the connected target socket,
66 // invalidate_direct_mem_ptr is invoked via the enable method shown
67 // above.
68 if (bw)
69 bw->invalidate_direct_mem_ptr(start_range, end_range);
70
73 invalidate_direct_mem_ptr_post,
74 proxy(), &start_range, &end_range);
75 }
76 tlm::tlm_sync_enum nb_transport_bw(transaction_type &trans, // NOLINT
77 phase_type &phase, // NOLINT
78 sc_core::sc_time &t) override { // NOLINT
79 // suppress DMI hint when there is an instrumentation tool
80 if (controller() && controller()->get_connections_state() !=
82 (&trans)->set_dmi_allowed(false);
83
86 nb_transport_bw_pre,
87 proxy(), &trans, &phase, &t);
88
89 tlm::tlm_sync_enum ret = tlm::TLM_COMPLETED;
90 BW_IF* bw = bw_if();
91 // MPInitiatorSocket does not provide an iface on its export.
92 if (bw)
93 ret = bw->nb_transport_bw(trans, phase, t);
94
97 nb_transport_bw_post,
98 proxy(), &trans, &phase, &t, &ret);
99 return ret;
100 }
101
103 sc_core::sc_interface* sc_iface = iface();
104 if (bw_if_map_.find(sc_iface) == bw_if_map_.end()) {
105 // A micro performance benchmark shows dynamic_cast is a hotspot,
106 // thus the result of it is cached here
107 bw_if_map_.emplace(sc_iface, dynamic_cast<BW_IF*>(sc_iface));
108 }
109 return bw_if_map_[sc_iface];
110 }
111
112 private:
113 bool is_active_;
114 std::unordered_map<sc_core::sc_interface*, BW_IF*> bw_if_map_;
115};
116
117template <typename IF_PROVIDER = sc_core::sc_port_base,
118 typename TYPES = tlm::tlm_base_protocol_types>
119class TlmBwTransportIfHandler : public tlm::tlm_bw_transport_if<TYPES>,
121 public:
122 typedef tlm::tlm_bw_transport_if<TYPES> BW_IF;
123 typedef typename TYPES::tlm_payload_type transaction_type;
124 typedef typename TYPES::tlm_phase_type phase_type;
125
126 explicit TlmBwTransportIfHandler(IF_PROVIDER *bw_if) {
127 first_.set_tlm_iface(new TlmIface(&second_));
128 second_.set_tlm_iface(new TlmIfaceProvider<IF_PROVIDER, TYPES,
129 BW_IF>(bw_if));
130 }
132 first_.set_tlm_iface(new TlmIface(&second_));
133 second_.set_tlm_iface(new TlmIface(bw_if));
134 }
136 tlm_utils::callback_binder_bw<TYPES> *binder_bw)
137 : registry_(binder_bw, this) {
138 first_.set_tlm_iface(new TlmIface(&second_));
139 second_.set_tlm_iface(new TlmIface(binder_bw));
140 }
141
142 void invalidate_direct_mem_ptr(sc_dt::uint64 start_range,
143 sc_dt::uint64 end_range) override {
144 first_.invalidate_direct_mem_ptr(start_range, end_range);
145 }
146 tlm::tlm_sync_enum nb_transport_bw(transaction_type &trans, // NOLINT
147 phase_type &phase, // NOLINT
148 sc_core::sc_time &t) override { // NOLINT
149 return first_.nb_transport_bw(trans, phase, t);
150 }
151
153 return &first_;
154 }
156 return &second_;
157 }
158
159 private:
162 TlmMultiHandlerRegistry registry_;
163};
164
165} // namespace awareness
166} // namespace systemc
167} // namespace simics
168
169#endif
Definition: tlm_base_handler.h:66
virtual instrumentation::ToolController * controller()
Definition: tlm_base_handler.h:83
virtual sc_core::sc_interface * iface()
Definition: tlm_base_handler.h:93
virtual ProxyInterface * proxy()
Definition: tlm_base_handler.h:86
Definition: tlm_bw_transport_if_handler.h:35
void disable() override
Definition: tlm_bw_transport_if_handler.h:51
void enable() override
Definition: tlm_bw_transport_if_handler.h:40
TlmBwTransportIfHandlerBase()
Definition: tlm_bw_transport_if_handler.h:38
tlm::tlm_bw_transport_if< TYPES > BW_IF
Definition: tlm_bw_transport_if_handler.h:37
BW_IF * bw_if()
Definition: tlm_bw_transport_if_handler.h:102
tlm::tlm_sync_enum nb_transport_bw(transaction_type &trans, phase_type &phase, sc_core::sc_time &t) override
Definition: tlm_bw_transport_if_handler.h:76
void invalidate_direct_mem_ptr(sc_dt::uint64 start_range, sc_dt::uint64 end_range) override
Definition: tlm_bw_transport_if_handler.h:57
TYPES::tlm_phase_type phase_type
Definition: tlm_bw_transport_if_handler.h:56
TYPES::tlm_payload_type transaction_type
Definition: tlm_bw_transport_if_handler.h:55
Definition: tlm_bw_transport_if_handler.h:120
TlmBwTransportIfHandler(IF_PROVIDER *bw_if)
Definition: tlm_bw_transport_if_handler.h:126
tlm::tlm_bw_transport_if< TYPES > BW_IF
Definition: tlm_bw_transport_if_handler.h:122
TlmHandlerInterface * firstHandler() override
Definition: tlm_bw_transport_if_handler.h:152
TYPES::tlm_phase_type phase_type
Definition: tlm_bw_transport_if_handler.h:124
TYPES::tlm_payload_type transaction_type
Definition: tlm_bw_transport_if_handler.h:123
TlmHandlerInterface * secondHandler() override
Definition: tlm_bw_transport_if_handler.h:155
TlmBwTransportIfHandler(BW_IF *bw_if)
Definition: tlm_bw_transport_if_handler.h:131
tlm::tlm_sync_enum nb_transport_bw(transaction_type &trans, phase_type &phase, sc_core::sc_time &t) override
Definition: tlm_bw_transport_if_handler.h:146
TlmBwTransportIfHandler(tlm_utils::callback_binder_bw< TYPES > *binder_bw)
Definition: tlm_bw_transport_if_handler.h:135
void invalidate_direct_mem_ptr(sc_dt::uint64 start_range, sc_dt::uint64 end_range) override
Definition: tlm_bw_transport_if_handler.h:142
Definition: tlm_handler_interface.h:24
Definition: tlm_base_handler.h:53
Definition: tlm_base_handler.h:37
Definition: tlm_multi_handler_interface.h:23
Definition: tlm_multi_handler_registry.h:28
@ EMPTY
Definition: tool_controller.h:75
Definition: adapter.h:79
#define DISPATCH_TOOL_CHAIN(controller, iface_type, func,...)
Definition: tool_controller.h:52