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