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