scc  2022.4.0
SystemC components library
chi_rn_initiator.h
1 /*
2  * Copyright 2021 Arteris IP
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 #pragma once
18 
19 #include <chi/chi_tlm.h>
20 #include <tlm/scc/pe/intor_if.h>
21 #include <scc/ordered_semaphore.h>
22 #include <scc/peq.h>
23 #include <scc/sc_variable.h>
24 #include <systemc>
25 #include <tlm_utils/peq_with_get.h>
26 #include <tuple>
27 #include <unordered_map>
28 
29 namespace chi {
30 namespace pe {
31 
33  public sc_core::sc_module,
34  public chi::chi_bw_transport_if<chi::chi_protocol_types>,
36 {
37 public:
38  using payload_type = chi::chi_protocol_types::tlm_payload_type;
39  using phase_type = chi::chi_protocol_types::tlm_phase_type;
40 
41  sc_core::sc_in<bool> clk_i{"clk_i"};
42 
43  sc_core::sc_export<tlm::scc::pe::intor_fw_b> fw_i{"fw_i"};
44 
45  sc_core::sc_port<tlm::scc::pe::intor_bw_b, 1, sc_core::SC_ZERO_OR_MORE_BOUND> bw_o{"bw_o"};
46 
47  void b_snoop(payload_type& trans, sc_core::sc_time& t) override;
48 
49  tlm::tlm_sync_enum nb_transport_bw(payload_type& trans, phase_type& phase, sc_core::sc_time& t) override;
50 
51  void invalidate_direct_mem_ptr(sc_dt::uint64 start_range, sc_dt::uint64 end_range) override;
52 
53  size_t get_transferwith_in_bytes() const { return transfer_width_in_bytes; }
63  void transport(payload_type& trans, bool blocking) override;
70  void snoop_resp(payload_type& trans, bool sync = false) override;
71 
72  chi_rn_initiator_b(sc_core::sc_module_name nm,
73  sc_core::sc_port_b<chi::chi_fw_transport_if<chi_protocol_types>>& port, size_t transfer_width);
74 
75  virtual ~chi_rn_initiator_b();
76 
77  chi_rn_initiator_b() = delete;
78 
79  chi_rn_initiator_b(chi_rn_initiator_b const&) = delete;
80 
82 
83  chi_rn_initiator_b& operator=(chi_rn_initiator_b const&) = delete;
84 
85  chi_rn_initiator_b& operator=(chi_rn_initiator_b&&) = delete;
86 
87  sc_core::sc_attribute<unsigned> src_id{"src_id", 1};
88 
89  sc_core::sc_attribute<unsigned> tgt_id{"tgt_id", 0}; // home node id will be used as tgt_id in all transaction req
90 
91  sc_core::sc_attribute<bool> data_interleaving{"data_interleaving", true};
92 
93  sc_core::sc_attribute<bool> strict_income_order{"strict_income_order", true};
94 
95  sc_core::sc_attribute<bool> use_legacy_mapping{"use_legacy_mapping", false};
96 
97 protected:
98  void end_of_elaboration() override { clk_if = dynamic_cast<sc_core::sc_clock*>(clk_i.get_interface()); }
99 
100  unsigned calculate_beats(payload_type& p) {
101  // sc_assert(p.get_data_length() > 0);
102  return p.get_data_length() < transfer_width_in_bytes ? 1 : p.get_data_length() / transfer_width_in_bytes;
103  }
104 
105  void snoop_dispatch();
106 
107  void snoop_handler(payload_type* trans);
108 
109  const size_t transfer_width_in_bytes;
110 
111  std::string instance_name;
112 
113  scc::ordered_semaphore req_credits{"req_credits", 0U, true}; // L-credits provided by completer(HN)
114 
115  sc_core::sc_port_b<chi::chi_fw_transport_if<chi_protocol_types>>& socket_fw;
116 
117  struct tx_state {
119  tx_state(std::string const& name)
120  : peq(sc_core::sc_gen_unique_name(name.c_str())) {}
121  };
122  std::unordered_map<uintptr_t, tx_state*> tx_state_by_trans;
123 
124  std::vector<tx_state*> tx_state_pool;
125 
126  std::unordered_map<unsigned, scc::ordered_semaphore> active_tx_by_id;
127 
128  scc::ordered_semaphore strict_order_sem{1};
129 
130  tlm_utils::peq_with_get<payload_type> snp_peq{"snp_peq"}, snp_dispatch_que{"snp_dispatch_que"};
131 
132  unsigned thread_avail{0}, thread_active{0};
133 
134  scc::ordered_semaphore req_order{1};
135 
136  scc::ordered_semaphore req_chnl{1};
137 
138  scc::ordered_semaphore wdat_chnl{1};
139 
140  scc::ordered_semaphore sresp_chnl{1};
141 
142  sc_core::sc_event any_tx_finished;
143 
144  sc_core::sc_time clk_period{10, sc_core::SC_NS};
145 
146 private:
147  void send_wdata(payload_type& trans, chi::pe::chi_rn_initiator_b::tx_state* txs);
148  void handle_snoop_response(payload_type& trans, chi::pe::chi_rn_initiator_b::tx_state* txs);
149  void send_comp_ack(payload_type& trans, tx_state*& txs);
150  void clk_counter() { m_clock_counter++; }
151  unsigned get_clk_cnt() { return m_clock_counter; }
152 
153  void create_data_ext(payload_type& trans);
154  void send_packet(tlm::tlm_phase phase, payload_type& trans, chi::pe::chi_rn_initiator_b::tx_state* txs);
155  void exec_read_write_protocol(const unsigned int txn_id, payload_type& trans,
157  void exec_atomic_protocol(const unsigned int txn_id, payload_type& trans,
159  void send_cresp_response(payload_type& trans);
160  void update_data_extension(chi::chi_data_extension* data_ext, payload_type& trans);
161 
162  unsigned m_clock_counter{0};
163  unsigned m_prev_clk_cnt{0};
164 
165  sc_core::sc_clock* clk_if{nullptr};
166  uint64_t peq_cnt{0};
167 
168  scc::sc_variable<unsigned> tx_waiting{"TxWaiting", 0};
169  scc::sc_variable<unsigned> tx_outstanding{"TxOutstanding", 0};
170 };
171 
175 template <unsigned int BUSWIDTH = 32, typename TYPES = chi::chi_protocol_types, int N = 1,
176  sc_core::sc_port_policy POL = sc_core::SC_ONE_OR_MORE_BOUND>
178 public:
179  using base = chi_rn_initiator_b;
180 
181  using payload_type = base::payload_type;
182  using phase_type = base::phase_type;
187  chi_rn_initiator(const sc_core::sc_module_name& nm, chi::chi_initiator_socket<BUSWIDTH, TYPES, N, POL>& socket_)
188  : chi_rn_initiator_b(nm, socket_.get_base_port(), BUSWIDTH)
189  , socket(socket_) {
190  socket(*this);
191  this->instance_name = socket.name();
192  }
193 
194  chi_rn_initiator() = delete;
195 
196  chi_rn_initiator(chi_rn_initiator const&) = delete;
197 
199 
200  chi_rn_initiator& operator=(chi_rn_initiator const&) = delete;
201 
202  chi_rn_initiator& operator=(chi_rn_initiator&&) = delete;
203 
204 private:
206 };
207 
208 } /* namespace pe */
209 } /* namespace chi */
void transport(payload_type &trans, bool blocking) override
The forward transport function. It behaves blocking and is re-entrant.
void snoop_resp(payload_type &trans, bool sync=false) override
triggers a non-blocking snoop response if the snoop callback does not do so.
chi_rn_initiator(const sc_core::sc_module_name &nm, chi::chi_initiator_socket< BUSWIDTH, TYPES, N, POL > &socket_)
the constructor
The ordered_semaphore primitive channel class.
TLM2.0 components modeling CHI.
Definition: chi_tlm.cpp:21
tlm::tlm_fw_transport_if< TYPES > chi_fw_transport_if
alias declaration for the forward interface
Definition: chi_tlm.h:910
The AXI protocol traits class. Since the protocoll defines additional non-ignorable phases a dedicate...
Definition: chi_tlm.h:895
priority event queue
Definition: peq.h:41