112027Sjungma@eit.uni-kl.de/***************************************************************************** 212027Sjungma@eit.uni-kl.de 312027Sjungma@eit.uni-kl.de Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 412027Sjungma@eit.uni-kl.de more contributor license agreements. See the NOTICE file distributed 512027Sjungma@eit.uni-kl.de with this work for additional information regarding copyright ownership. 612027Sjungma@eit.uni-kl.de Accellera licenses this file to you under the Apache License, Version 2.0 712027Sjungma@eit.uni-kl.de (the "License"); you may not use this file except in compliance with the 812027Sjungma@eit.uni-kl.de License. You may obtain a copy of the License at 912027Sjungma@eit.uni-kl.de 1012027Sjungma@eit.uni-kl.de http://www.apache.org/licenses/LICENSE-2.0 1112027Sjungma@eit.uni-kl.de 1212027Sjungma@eit.uni-kl.de Unless required by applicable law or agreed to in writing, software 1312027Sjungma@eit.uni-kl.de distributed under the License is distributed on an "AS IS" BASIS, 1412027Sjungma@eit.uni-kl.de WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 1512027Sjungma@eit.uni-kl.de implied. See the License for the specific language governing 1612027Sjungma@eit.uni-kl.de permissions and limitations under the License. 1712027Sjungma@eit.uni-kl.de 1812027Sjungma@eit.uni-kl.de *****************************************************************************/ 1912027Sjungma@eit.uni-kl.de#ifndef __MULTI_PASSTHROUGH_INITIATOR_SOCKET_H__ 2012027Sjungma@eit.uni-kl.de#define __MULTI_PASSTHROUGH_INITIATOR_SOCKET_H__ 2112027Sjungma@eit.uni-kl.de 2212027Sjungma@eit.uni-kl.de#include "multi_socket_bases.h" 2312027Sjungma@eit.uni-kl.de 2412027Sjungma@eit.uni-kl.denamespace tlm_utils { 2512027Sjungma@eit.uni-kl.de 2612027Sjungma@eit.uni-kl.de/* 2712027Sjungma@eit.uni-kl.deThis class implements a trivial multi initiator socket. 2812027Sjungma@eit.uni-kl.deThe triviality refers to the fact that the socket does not 2912027Sjungma@eit.uni-kl.dedo blocking to non-blocking or non-blocking to blocking conversions. 3012027Sjungma@eit.uni-kl.de 3112027Sjungma@eit.uni-kl.deIt allows to connect multiple targets to this socket. 3212027Sjungma@eit.uni-kl.deThe user has to register callbacks for the bw interface methods 3312027Sjungma@eit.uni-kl.dehe likes to use. The callbacks are basically equal to the bw interface 3412027Sjungma@eit.uni-kl.demethods but carry an additional integer that indicates to which 3512027Sjungma@eit.uni-kl.deindex of this socket the calling target is connected. 3612027Sjungma@eit.uni-kl.de*/ 3712027Sjungma@eit.uni-kl.detemplate <typename MODULE, 3812027Sjungma@eit.uni-kl.de unsigned int BUSWIDTH = 32, 3912027Sjungma@eit.uni-kl.de typename TYPES = tlm::tlm_base_protocol_types, 4012027Sjungma@eit.uni-kl.de unsigned int N=0 4112027Sjungma@eit.uni-kl.de#if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714) 4212027Sjungma@eit.uni-kl.de ,sc_core::sc_port_policy POL = sc_core::SC_ONE_OR_MORE_BOUND 4312027Sjungma@eit.uni-kl.de#endif 4412027Sjungma@eit.uni-kl.de > 4512027Sjungma@eit.uni-kl.declass multi_passthrough_initiator_socket: public multi_init_base< BUSWIDTH, 4612027Sjungma@eit.uni-kl.de TYPES, 4712027Sjungma@eit.uni-kl.de N 4812027Sjungma@eit.uni-kl.de#if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714) 4912027Sjungma@eit.uni-kl.de ,POL 5012027Sjungma@eit.uni-kl.de#endif 5112027Sjungma@eit.uni-kl.de > 5212027Sjungma@eit.uni-kl.de{ 5312027Sjungma@eit.uni-kl.de 5412027Sjungma@eit.uni-kl.depublic: 5512027Sjungma@eit.uni-kl.de 5612027Sjungma@eit.uni-kl.de //typedefs 5712027Sjungma@eit.uni-kl.de // tlm 2.0 types for nb_transport 5812027Sjungma@eit.uni-kl.de typedef typename TYPES::tlm_payload_type transaction_type; 5912027Sjungma@eit.uni-kl.de typedef typename TYPES::tlm_phase_type phase_type; 6012027Sjungma@eit.uni-kl.de typedef tlm::tlm_sync_enum sync_enum_type; 6112027Sjungma@eit.uni-kl.de 6212027Sjungma@eit.uni-kl.de // typedefs to keep the fn ptr notations short 6312027Sjungma@eit.uni-kl.de typedef sync_enum_type (MODULE::*nb_cb)(int, 6412027Sjungma@eit.uni-kl.de transaction_type&, 6512027Sjungma@eit.uni-kl.de phase_type&, 6612027Sjungma@eit.uni-kl.de sc_core::sc_time&); 6712027Sjungma@eit.uni-kl.de typedef void (MODULE::*dmi_cb)(int, sc_dt::uint64, sc_dt::uint64); 6812027Sjungma@eit.uni-kl.de 6912027Sjungma@eit.uni-kl.de typedef multi_init_base<BUSWIDTH, 7012027Sjungma@eit.uni-kl.de TYPES, 7112027Sjungma@eit.uni-kl.de N 7212027Sjungma@eit.uni-kl.de#if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714) 7312027Sjungma@eit.uni-kl.de ,POL 7412027Sjungma@eit.uni-kl.de#endif 7512027Sjungma@eit.uni-kl.de > base_type; 7612027Sjungma@eit.uni-kl.de 7712027Sjungma@eit.uni-kl.de typedef typename base_type::base_target_socket_type base_target_socket_type; 7812027Sjungma@eit.uni-kl.de 7912027Sjungma@eit.uni-kl.de //CTOR 8012027Sjungma@eit.uni-kl.de multi_passthrough_initiator_socket() 8112027Sjungma@eit.uni-kl.de : base_type(sc_core::sc_gen_unique_name("multi_passthrough_initiator_socket")) 8212027Sjungma@eit.uni-kl.de , m_hierarch_bind(0) 8312027Sjungma@eit.uni-kl.de , m_beoe_disabled(false) 8412027Sjungma@eit.uni-kl.de , m_dummy(42) 8512027Sjungma@eit.uni-kl.de { 8612027Sjungma@eit.uni-kl.de } 8712027Sjungma@eit.uni-kl.de 8812027Sjungma@eit.uni-kl.de //CTOR 8912027Sjungma@eit.uni-kl.de multi_passthrough_initiator_socket(const char* name) 9012027Sjungma@eit.uni-kl.de : base_type(name) 9112027Sjungma@eit.uni-kl.de , m_hierarch_bind(0) 9212027Sjungma@eit.uni-kl.de , m_beoe_disabled(false) 9312027Sjungma@eit.uni-kl.de , m_dummy(42) 9412027Sjungma@eit.uni-kl.de { 9512027Sjungma@eit.uni-kl.de } 9612027Sjungma@eit.uni-kl.de 9712027Sjungma@eit.uni-kl.de ~multi_passthrough_initiator_socket(){ 9812027Sjungma@eit.uni-kl.de //clean up everything allocated by 'new' 9912027Sjungma@eit.uni-kl.de for (unsigned int i=0; i<m_binders.size(); i++) delete m_binders[i]; 10012027Sjungma@eit.uni-kl.de } 10112027Sjungma@eit.uni-kl.de 10212027Sjungma@eit.uni-kl.de //simple helpers for warnings an errors to shorten in code notation 10312027Sjungma@eit.uni-kl.de void display_warning(const std::string& text) const { 10412027Sjungma@eit.uni-kl.de std::stringstream s; 10512027Sjungma@eit.uni-kl.de s<<"WARNING in instance "<<base_type::name()<<": "<<text; 10612027Sjungma@eit.uni-kl.de SC_REPORT_WARNING("/OSCI_TLM-2/multi_socket", s.str().c_str()); 10712027Sjungma@eit.uni-kl.de } 10812027Sjungma@eit.uni-kl.de 10912027Sjungma@eit.uni-kl.de void display_error(const std::string& text) const { 11012027Sjungma@eit.uni-kl.de std::stringstream s; 11112027Sjungma@eit.uni-kl.de s<<"ERROR in instance "<<base_type::name()<<": "<<text; 11212027Sjungma@eit.uni-kl.de SC_REPORT_ERROR("/OSCI_TLM-2/multi_socket", s.str().c_str()); 11312027Sjungma@eit.uni-kl.de } 11412027Sjungma@eit.uni-kl.de 11512027Sjungma@eit.uni-kl.de 11612027Sjungma@eit.uni-kl.de //register callback for nb transport of bw interface 11712027Sjungma@eit.uni-kl.de void register_nb_transport_bw(MODULE* mod, 11812027Sjungma@eit.uni-kl.de sync_enum_type (MODULE::*cb)(int, 11912027Sjungma@eit.uni-kl.de transaction_type&, 12012027Sjungma@eit.uni-kl.de phase_type&, 12112027Sjungma@eit.uni-kl.de sc_core::sc_time&)) 12212027Sjungma@eit.uni-kl.de { 12312027Sjungma@eit.uni-kl.de //warn if there already is a callback 12412027Sjungma@eit.uni-kl.de if (!m_nb_f.empty()){ 12512027Sjungma@eit.uni-kl.de display_warning("NBTransport_bw callback already registered."); 12612027Sjungma@eit.uni-kl.de return; 12712027Sjungma@eit.uni-kl.de } 12812027Sjungma@eit.uni-kl.de 12912027Sjungma@eit.uni-kl.de //set the functor 13012027Sjungma@eit.uni-kl.de m_nb_f.set_function(mod, cb); 13112027Sjungma@eit.uni-kl.de } 13212027Sjungma@eit.uni-kl.de 13312027Sjungma@eit.uni-kl.de //register callback for dmi function of bw interface 13412027Sjungma@eit.uni-kl.de void register_invalidate_direct_mem_ptr(MODULE* mod, 13512027Sjungma@eit.uni-kl.de void (MODULE::*cb)(int, sc_dt::uint64, sc_dt::uint64)) 13612027Sjungma@eit.uni-kl.de { 13712027Sjungma@eit.uni-kl.de //warn if there already is a callback 13812027Sjungma@eit.uni-kl.de if (!m_dmi_f.empty()){ 13912027Sjungma@eit.uni-kl.de display_warning("InvalidateDMI callback already registered."); 14012027Sjungma@eit.uni-kl.de return; 14112027Sjungma@eit.uni-kl.de } 14212027Sjungma@eit.uni-kl.de 14312027Sjungma@eit.uni-kl.de //set the functor 14412027Sjungma@eit.uni-kl.de m_dmi_f.set_function(mod, cb); 14512027Sjungma@eit.uni-kl.de } 14612027Sjungma@eit.uni-kl.de 14712027Sjungma@eit.uni-kl.de //Override virtual functions of the tlm_initiator_socket: 14812027Sjungma@eit.uni-kl.de // this function is called whenever an sc_port (as part of a target socket) 14912027Sjungma@eit.uni-kl.de // wants to bind to the export of the underlying tlm_initiator_socket 15012027Sjungma@eit.uni-kl.de //At this time a callback binder is created an returned to the sc_port 15112027Sjungma@eit.uni-kl.de // of the target socket, so that it binds to the callback binder 15212027Sjungma@eit.uni-kl.de virtual tlm::tlm_bw_transport_if<TYPES>& get_base_interface() 15312027Sjungma@eit.uni-kl.de { 15412027Sjungma@eit.uni-kl.de m_binders.push_back(new callback_binder_bw<TYPES>(m_binders.size())); 15512027Sjungma@eit.uni-kl.de return *m_binders[m_binders.size()-1]; 15612027Sjungma@eit.uni-kl.de } 15712027Sjungma@eit.uni-kl.de 15812027Sjungma@eit.uni-kl.de // const overload not allowed for multi-sockets 15912027Sjungma@eit.uni-kl.de virtual const tlm::tlm_bw_transport_if<TYPES>& get_base_interface() const 16012027Sjungma@eit.uni-kl.de { 16112027Sjungma@eit.uni-kl.de display_error("'get_base_interface()' const not allowed for multi-sockets."); 16212027Sjungma@eit.uni-kl.de return base_type::get_base_interface(); 16312027Sjungma@eit.uni-kl.de } 16412027Sjungma@eit.uni-kl.de 16512027Sjungma@eit.uni-kl.de //Override virtual functions of the tlm_initiator_socket: 16612027Sjungma@eit.uni-kl.de // this function is called whenever an sc_export (as part of a initiator socket) 16712027Sjungma@eit.uni-kl.de // wants to bind to the export of the underlying tlm_initiator_socket 16812027Sjungma@eit.uni-kl.de // i.e. a hierarchical bind takes place 16912027Sjungma@eit.uni-kl.de virtual sc_core::sc_export<tlm::tlm_bw_transport_if<TYPES> >& get_base_export() 17012027Sjungma@eit.uni-kl.de { 17112027Sjungma@eit.uni-kl.de if (!m_beoe_disabled) //we are not bound hierarchically 17212027Sjungma@eit.uni-kl.de base_type::m_export.bind(m_dummy); //so we bind the dummy to avoid a SystemC error 17312027Sjungma@eit.uni-kl.de return base_type::get_base_export(); //and then return our own export so that the hierarchical binding is set up properly 17412027Sjungma@eit.uni-kl.de } 17512027Sjungma@eit.uni-kl.de 17612027Sjungma@eit.uni-kl.de virtual const sc_core::sc_export<tlm::tlm_bw_transport_if<TYPES> >& get_base_export() const 17712027Sjungma@eit.uni-kl.de { 17812027Sjungma@eit.uni-kl.de return base_type::get_base_export(); 17912027Sjungma@eit.uni-kl.de } 18012027Sjungma@eit.uni-kl.de 18112027Sjungma@eit.uni-kl.de //bind against a target socket 18212027Sjungma@eit.uni-kl.de virtual void bind(base_target_socket_type& s) 18312027Sjungma@eit.uni-kl.de { 18412027Sjungma@eit.uni-kl.de //error if this socket is already bound hierarchically 18512027Sjungma@eit.uni-kl.de if (m_hierarch_bind) 18612027Sjungma@eit.uni-kl.de display_error("Already hierarchically bound."); 18712027Sjungma@eit.uni-kl.de 18812027Sjungma@eit.uni-kl.de base_type::bind(s); //satisfy systemC, leads to a call to get_base_interface() 18912027Sjungma@eit.uni-kl.de 19012027Sjungma@eit.uni-kl.de //try to cast the target socket into a fw interface 19112027Sjungma@eit.uni-kl.de sc_core::sc_export<tlm::tlm_fw_transport_if<TYPES> >* p_ex_s=dynamic_cast<sc_core::sc_export<tlm::tlm_fw_transport_if<TYPES> >*>(&s); 19212027Sjungma@eit.uni-kl.de if (!p_ex_s) display_error("Multi socket not bound to tlm_socket."); 19312027Sjungma@eit.uni-kl.de 19412027Sjungma@eit.uni-kl.de //try a cast into a multi sockets 19512027Sjungma@eit.uni-kl.de multi_to_multi_bind_base<TYPES>* test=dynamic_cast<multi_to_multi_bind_base<TYPES>*> (p_ex_s); 19612027Sjungma@eit.uni-kl.de if (test) //did we just do a multi-multi bind?? 19712027Sjungma@eit.uni-kl.de //if that is the case the multi target socket must have just created a callback binder 19812027Sjungma@eit.uni-kl.de // which we want to get from it. 19912027Sjungma@eit.uni-kl.de //Moreover, we also just created one, which we will pass to it. 20012027Sjungma@eit.uni-kl.de m_sockets.push_back(test->get_last_binder(m_binders[m_binders.size()-1])); 20112027Sjungma@eit.uni-kl.de else{ // if not just bind normally 20212027Sjungma@eit.uni-kl.de sc_core::sc_export<tlm::tlm_fw_transport_if<TYPES> >& ex_s=*p_ex_s; 20312027Sjungma@eit.uni-kl.de m_sockets.push_back(&((tlm::tlm_fw_transport_if<TYPES>&)ex_s)); //store the interface we are bound against 20412027Sjungma@eit.uni-kl.de } 20512027Sjungma@eit.uni-kl.de } 20612027Sjungma@eit.uni-kl.de 20712027Sjungma@eit.uni-kl.de //operator notation for direct bind 20812027Sjungma@eit.uni-kl.de void operator() (base_target_socket_type& s) 20912027Sjungma@eit.uni-kl.de { 21012027Sjungma@eit.uni-kl.de bind(s); 21112027Sjungma@eit.uni-kl.de } 21212027Sjungma@eit.uni-kl.de 21312027Sjungma@eit.uni-kl.de //SystemC standard callback before end of elaboration 21412027Sjungma@eit.uni-kl.de void before_end_of_elaboration(){ 21512027Sjungma@eit.uni-kl.de //if our export hasn't been bound yet (due to a hierarch binding) 21612027Sjungma@eit.uni-kl.de // we bind it now to avoid a SystemC error. 21712027Sjungma@eit.uni-kl.de //We must do that, because it is legal not to register a callback on this socket 21812027Sjungma@eit.uni-kl.de // as the user might only use b_transport 21912027Sjungma@eit.uni-kl.de if (!base_type::m_export.get_interface()){ 22012027Sjungma@eit.uni-kl.de base_type::m_export.bind(m_dummy); 22112027Sjungma@eit.uni-kl.de } 22212027Sjungma@eit.uni-kl.de 22312027Sjungma@eit.uni-kl.de //'break' here if the socket was told not to do callback binding 22412027Sjungma@eit.uni-kl.de if (m_beoe_disabled) return; 22512027Sjungma@eit.uni-kl.de 22612027Sjungma@eit.uni-kl.de //get the callback binders of the top of the hierachical bind chain 22712027Sjungma@eit.uni-kl.de // NOTE: this could be the same socket if there is no hierachical bind 22812027Sjungma@eit.uni-kl.de std::vector<callback_binder_bw<TYPES>* >& binders=get_hierarch_bind()->get_binders(); 22912027Sjungma@eit.uni-kl.de 23012027Sjungma@eit.uni-kl.de //get the interfaces bound to the top of the hierachical bind chain 23112027Sjungma@eit.uni-kl.de // NOTE: this could be the same socket if there is no hierachical bind 23212027Sjungma@eit.uni-kl.de m_used_sockets=get_hierarch_bind()->get_sockets(); 23312027Sjungma@eit.uni-kl.de 23412027Sjungma@eit.uni-kl.de //register the callbacks of this socket with the callback binders 23512027Sjungma@eit.uni-kl.de // we just got from the top of the hierachical bind chain 23612027Sjungma@eit.uni-kl.de for (unsigned int i=0; i<binders.size(); i++) { 23712027Sjungma@eit.uni-kl.de binders[i]->set_callbacks(m_nb_f, m_dmi_f); 23812027Sjungma@eit.uni-kl.de } 23912027Sjungma@eit.uni-kl.de } 24012027Sjungma@eit.uni-kl.de 24112027Sjungma@eit.uni-kl.de // 24212027Sjungma@eit.uni-kl.de // Bind multi initiator socket to multi initiator socket (hierarchical bind) 24312027Sjungma@eit.uni-kl.de // 24412027Sjungma@eit.uni-kl.de virtual void bind(base_type& s) 24512027Sjungma@eit.uni-kl.de { 24612027Sjungma@eit.uni-kl.de if (m_binders.size()) //a multi socket is either bound hierarchically or directly 24712027Sjungma@eit.uni-kl.de display_error("Socket already directly bound."); 24812027Sjungma@eit.uni-kl.de if (m_hierarch_bind){ 24912027Sjungma@eit.uni-kl.de display_warning("Socket already bound hierarchically. Bind attempt ignored."); 25012027Sjungma@eit.uni-kl.de return; 25112027Sjungma@eit.uni-kl.de } 25212027Sjungma@eit.uni-kl.de 25312027Sjungma@eit.uni-kl.de //remember to which socket we are hierarchically bound and disable it, 25412027Sjungma@eit.uni-kl.de // so that it won't try to register callbacks itself 25512027Sjungma@eit.uni-kl.de s.disable_cb_bind(); 25612027Sjungma@eit.uni-kl.de m_hierarch_bind=&s; 25712027Sjungma@eit.uni-kl.de base_type::bind(s); //satisfy SystemC 25812027Sjungma@eit.uni-kl.de } 25912027Sjungma@eit.uni-kl.de 26012027Sjungma@eit.uni-kl.de //operator notation for hierarchical bind 26112027Sjungma@eit.uni-kl.de void operator() (base_type& s) 26212027Sjungma@eit.uni-kl.de { 26312027Sjungma@eit.uni-kl.de bind(s); 26412027Sjungma@eit.uni-kl.de } 26512027Sjungma@eit.uni-kl.de 26612027Sjungma@eit.uni-kl.de //get access to sub port 26712027Sjungma@eit.uni-kl.de tlm::tlm_fw_transport_if<TYPES>* operator[](int i){return m_used_sockets[i];} 26812027Sjungma@eit.uni-kl.de 26912027Sjungma@eit.uni-kl.de //get the number of bound targets 27012027Sjungma@eit.uni-kl.de // NOTE: this is only valid at end of elaboration! 27112027Sjungma@eit.uni-kl.de unsigned int size() {return get_hierarch_bind()->get_sockets().size();} 27212027Sjungma@eit.uni-kl.de 27312027Sjungma@eit.uni-kl.deprotected: 27412027Sjungma@eit.uni-kl.de //implementation of base class interface 27512027Sjungma@eit.uni-kl.de base_type* get_hierarch_bind(){if (m_hierarch_bind) return m_hierarch_bind->get_hierarch_bind(); else return this;} 27612027Sjungma@eit.uni-kl.de void disable_cb_bind(){ m_beoe_disabled=true;} 27712027Sjungma@eit.uni-kl.de std::vector<callback_binder_bw<TYPES>* >& get_binders(){return m_binders;} 27812027Sjungma@eit.uni-kl.de std::vector<tlm::tlm_fw_transport_if<TYPES>*>& get_sockets(){return m_sockets;} 27912027Sjungma@eit.uni-kl.de //vector of connected sockets 28012027Sjungma@eit.uni-kl.de std::vector<tlm::tlm_fw_transport_if<TYPES>*> m_sockets; 28112027Sjungma@eit.uni-kl.de std::vector<tlm::tlm_fw_transport_if<TYPES>*> m_used_sockets; 28212027Sjungma@eit.uni-kl.de //vector of binders that convert untagged interface into tagged interface 28312027Sjungma@eit.uni-kl.de std::vector<callback_binder_bw<TYPES>*> m_binders; 28412027Sjungma@eit.uni-kl.de 28512027Sjungma@eit.uni-kl.de base_type* m_hierarch_bind; //pointer to hierarchical bound multi port 28612027Sjungma@eit.uni-kl.de bool m_beoe_disabled; // bool that remembers whether this socket shall bind callbacks or not 28712027Sjungma@eit.uni-kl.de callback_binder_bw<TYPES> m_dummy; //a callback binder that is bound to the underlying export 28812027Sjungma@eit.uni-kl.de // in case there was no real bind 28912027Sjungma@eit.uni-kl.de 29012027Sjungma@eit.uni-kl.de //callbacks as functors 29112027Sjungma@eit.uni-kl.de // (allows to pass the callback to another socket that does not know the type of the module that owns 29212027Sjungma@eit.uni-kl.de // the callbacks) 29312027Sjungma@eit.uni-kl.de typename callback_binder_bw<TYPES>::nb_func_type m_nb_f; 29412027Sjungma@eit.uni-kl.de typename callback_binder_bw<TYPES>::dmi_func_type m_dmi_f; 29512027Sjungma@eit.uni-kl.de}; 29612027Sjungma@eit.uni-kl.de 29712027Sjungma@eit.uni-kl.de} 29812027Sjungma@eit.uni-kl.de 29912027Sjungma@eit.uni-kl.de#endif 300