SystemC Library API Reference Manual
Reference documentation for the Simics SystemC Library.
 
Loading...
Searching...
No Matches
tlm2_base_protocol_checker.h
Go to the documentation of this file.
1// Filename: tlm2_base_protocol_checker.h
2
3//----------------------------------------------------------------------
4// Copyright (c) 2008-2013 by Doulos Ltd.
5//
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17//----------------------------------------------------------------------
18
19// Author: John Aynsley, Doulos
20
21// Version 1, 11 July 2008
22// Version 2, 16 July 2008 Only generate ref_count > 1 warning from 1st checker of path
23// Version 3, 17 July 2008 Support compilation under SystemC 2.1.v1
24// Version 4, 12 Aug 2008 Add header #include <map>
25// Version 5, 08 Sep 2008 Fix bugs in message text
26// Version 6, 01 Aug 2010 Update messages to refer to OSCI TLM-2.0 LRM of July 2009
27// Version 7, 25 Oct 2011 Minor bug fix for certain compilers: replace u_char with uchar_t
28// Version 8, 02 Nov 2011 Support the endianness conversion functions by excluding the
29// tlm_endian_context extension from the protocol checks
30// Version 9, 17 Aug 2012 Fix LRM reference on line 805 (should be 8.2.11 a) [NOT YET RELEASED]
31// Version 10, 3 Jan 2013 Updated messages to refer to IEEE Std 1666-2011, the combined SystemC + TLM-2.0 LRM
32// Added checks related to the generic payload option attribute
33// Version 11, 14 Mar 2016 Fix minor bug - start_phase should be a copy, not a reference
34
35// TLM-2.0 Base Protocol Compliance Checker
36
37/*
38Instantiate this checker module in-line between initiator and target, initiator and interconnect,
39or interconnect and target by binding the target_socket and initiator_socket
40Binding two checkers either side of an interconnect component, or interleaving a series of
41checkers with interconnect components, will enable some deeper checks as against having just
42a single checker
43
44For example
45
46 Initiator *initiator;
47 Bus *bus;
48 Memory *memory;
49 ...
50 initiator->socket.bind(bus->target_socket);
51 bus->initiator_socket.bind(memory->socket);
52
53might become
54
55 tlm_utils::tlm2_base_protocol_checker<32> *checker1;
56 tlm_utils::tlm2_base_protocol_checker<32> *checker2;
57 ...
58 initiator->socket.bind(checker1->target_socket);
59 checker1->initiator_socket.bind(bus->target_socket);
60 bus->initiator_socket.bind(checker2->target_socket);
61 checker2->initiator_socket.bind(memory->socket);
62
63
64GENERAL FEATURES OF THE BASE PROTOCOL CHECKER
65
66The checks are relatively expensive, hence by default the number of checks is limited.
67A maximum number can be set explicitly by calling set_num_checks(max)
68Checking can be deactivated at any time by calling set_num_checks(0)
69All checkers decrement a single global count, because having some checkers running and
70others not can cause bogus violation reports
71It is not permitted to turn checks on by calling set_num_checks() once checking has been
72deactivated, because this could cause bogus violation reports
73
74The DMI and debug checks are unaffected by the num_checks count (because they are cheap)
75
76The error messages contain User Manual references
77
78The checker is designed to be used with a transaction pool: otherwise it could consume
79a lot of memory. The checker keeps a local copy of each transaction object
80Failures are reported with a severity of SC_ERROR. The actions may be overridden by calling:
81 sc_report_handler::set_actions("tlm2_protocol_checker", ...);
82
83SPECIFIC CHECKS
84
85nb_transport: phase sequence BEGIN_REQ -> END_REQ -> BEGIN_RESP -> END_RESP
86Must not have two outstanding requests or responses (exclusion rules)
87Must not have decreasing timing annotations on calls to or returns from nb_transport_fw/bw
88Phase extensions permitted and ignored
89Must not call b_transport during nb_transport phase sequence and vice-versa
90
91nb_transport: memory manager must be set
92nb_transport: reference count must be non-zero
93First checker in BEGIN_REQ path should see ref_count == 1 (warning only)
94An interconnect component that sets a memory manager should also clear it
95An interconnect component that sets extensions with no memory manager should also clear them
96(Does not bother with these memory manager checks for DMI and debug)
97
98Transaction object must be properly initialized
99Many generic payload attributes must not be modified during the transaction lifetime
100Transaction object must not be re-allocated for a new transaction while still in use
101DMI descriptor must be properly initialized
102Debug transaction must be properly initialized
103Debug byte count must be less than data_length
104
105Checks that require multiple checkers to be instantiated along a transaction path:
106The BEGIN_RESP path must be the reverse of the BEGIN_REQ path
107Transaction object must not be sent with BEGIN_REQ while participating in a previous response
108Interconnect component must not set response status attribute to TLM_OK_RESPONSE
109Interconnect component must not modify data array on the response path
110
111Generic payload option attribute (IEEE Std 1666-2011, SystemC 2.3.x)
112gp_option must be properly initialized and only used for DMI and debug transport
113When gp_option is used, other gp attributes must be initialized and used as per the transport interfaces
114*/
115
116
117// ******************** PREAMBLE ********************
118#ifndef SIMICS_SYSTEMC_AWARENESS_TLM2_BASE_PROTOCOL_CHECKER_H
119#define SIMICS_SYSTEMC_AWARENESS_TLM2_BASE_PROTOCOL_CHECKER_H
120
122
123#include <systemc>
124#include <tlm.h>
125
126#include <deque>
127#include <sstream>
128#include <map>
129
130namespace tlm_utils {
131
132
133// ******************** CLASS DEFINITION ********************
135 public:
136 // Types used when building a trace of the transaction path
137 typedef unsigned char uchar_t;
138 typedef std::deque<sc_core::sc_object*> deque_t;
139
142 : m_request_in_progress(0), m_response_in_progress(0),
143 checker_instance_(proxy) {
144 }
145
147
148 void b_transport_pre_checks( tlm::tlm_generic_payload& trans, sc_core::sc_time& delay);
149
150 void b_transport_post_checks( tlm::tlm_generic_payload& trans, sc_core::sc_time& delay);
151
153 tlm::tlm_generic_payload& trans, tlm::tlm_phase& phase, sc_core::sc_time& delay);
154
156 tlm::tlm_generic_payload& trans, tlm::tlm_phase& start_phase, tlm::tlm_phase& phase,
157 sc_core::sc_time& delay, tlm::tlm_sync_enum status);
158
160 tlm::tlm_generic_payload& trans, tlm::tlm_phase& phase, sc_core::sc_time& delay);
161
163 tlm::tlm_generic_payload& trans, tlm::tlm_phase& phase, sc_core::sc_time& delay,
164 tlm::tlm_sync_enum status);
165
167 tlm::tlm_generic_payload& trans, tlm::tlm_phase& phase, sc_core::sc_time& delay,
168 const char* txt2, const char* txt3, const char* txt4);
169
170 void check_initial_state( tlm::tlm_generic_payload& trans, const char* txt2 );
171 void check_trans_not_modified( tlm::tlm_generic_payload& trans, const char* txt2 );
172 void check_response_path( tlm::tlm_generic_payload& trans, const char* txt2 );
173 void remember_gp_option( tlm::tlm_generic_payload& trans );
174
175 void get_direct_mem_ptr_pre_checks( tlm::tlm_generic_payload& trans, tlm::tlm_dmi& dmi_data );
176
177 void get_direct_mem_ptr_post_checks( tlm::tlm_generic_payload& trans, tlm::tlm_dmi& dmi_data );
178
179 void transport_dbg_pre_checks( tlm::tlm_generic_payload& trans );
180
181 void transport_dbg_post_checks( tlm::tlm_generic_payload& trans, unsigned int count );
182
183 void tlm2error( tlm::tlm_generic_payload& trans, const char* ref, bool warning = false );
184
185 private:
186
187 virtual void reportError(std::ostringstream *stream, bool = false);
188
189 struct state_t {
190 state_t() { has_mm = false; b_call = 0; ph = tlm::UNINITIALIZED_PHASE;
191 gp = 0; data_ptr = 0; byte_enable_ptr = 0; }
192
193 bool has_mm;
194 unsigned int b_call; // Number of b_transport calls in progress
195 tlm::tlm_phase ph;
196 sc_core::sc_time time; // Current time + annotated delay
197 tlm::tlm_generic_payload* gp; // Points to new data and byte enable buffers
198 uchar_t* data_ptr; // Stores original pointers
199 uchar_t* byte_enable_ptr;
200 };
201
202 // Transaction state for the specific hop where this checker is inlined
203 std::map<tlm::tlm_generic_payload*, state_t> m_map;
204
205 // Flags for exclusion rules
206 tlm::tlm_generic_payload* m_request_in_progress;
207 tlm::tlm_generic_payload* m_response_in_progress;
208
209 std::ostringstream txt;
210
211 struct path_t {
212 path_t () { response_in_progress = false; ok_response = false; resp_data_ptr = 0; }
213
214 bool response_in_progress;
215 bool ok_response;
216 deque_t path;
217 uchar_t* resp_data_ptr; // Copy of data on response path
218 };
219
220
221 // Global variable used for checks involving multiple checkers along a transaction path
222 static std::map<tlm::tlm_generic_payload*, path_t> shared_map;
223
225};
226
227} // namespace tlm_utils
228
229#endif
Definition: proxy_interface.h:27
Definition: tlm2_base_protocol_checker.h:134
void transport_dbg_pre_checks(tlm::tlm_generic_payload &trans)
void tlm2error(tlm::tlm_generic_payload &trans, const char *ref, bool warning=false)
std::deque< sc_core::sc_object * > deque_t
Definition: tlm2_base_protocol_checker.h:138
virtual ~tlm2_base_protocol_checker()
Definition: tlm2_base_protocol_checker.h:146
void nb_transport_fw_pre_checks(tlm::tlm_generic_payload &trans, tlm::tlm_phase &phase, sc_core::sc_time &delay)
tlm2_base_protocol_checker(simics::systemc::awareness::ProxyInterface *proxy)
Definition: tlm2_base_protocol_checker.h:140
void b_transport_pre_checks(tlm::tlm_generic_payload &trans, sc_core::sc_time &delay)
void nb_transport_response_checks(tlm::tlm_generic_payload &trans, tlm::tlm_phase &phase, sc_core::sc_time &delay, const char *txt2, const char *txt3, const char *txt4)
void nb_transport_fw_post_checks(tlm::tlm_generic_payload &trans, tlm::tlm_phase &start_phase, tlm::tlm_phase &phase, sc_core::sc_time &delay, tlm::tlm_sync_enum status)
void check_initial_state(tlm::tlm_generic_payload &trans, const char *txt2)
void check_response_path(tlm::tlm_generic_payload &trans, const char *txt2)
void get_direct_mem_ptr_post_checks(tlm::tlm_generic_payload &trans, tlm::tlm_dmi &dmi_data)
void remember_gp_option(tlm::tlm_generic_payload &trans)
void b_transport_post_checks(tlm::tlm_generic_payload &trans, sc_core::sc_time &delay)
void transport_dbg_post_checks(tlm::tlm_generic_payload &trans, unsigned int count)
void nb_transport_bw_post_checks(tlm::tlm_generic_payload &trans, tlm::tlm_phase &phase, sc_core::sc_time &delay, tlm::tlm_sync_enum status)
unsigned char uchar_t
Definition: tlm2_base_protocol_checker.h:137
void get_direct_mem_ptr_pre_checks(tlm::tlm_generic_payload &trans, tlm::tlm_dmi &dmi_data)
void check_trans_not_modified(tlm::tlm_generic_payload &trans, const char *txt2)
void nb_transport_bw_pre_checks(tlm::tlm_generic_payload &trans, tlm::tlm_phase &phase, sc_core::sc_time &delay)
Definition: tlm2_base_protocol_checker.h:130