multi_passthrough_initiator_socket.h revision 13511:dc5864c73df3
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 TLM_UTILS_MULTI_PASSTHROUGH_INITIATOR_SOCKET_H_INCLUDED_ 2012027Sjungma@eit.uni-kl.de#define TLM_UTILS_MULTI_PASSTHROUGH_INITIATOR_SOCKET_H_INCLUDED_ 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, sc_core::sc_port_policy POL = sc_core::SC_ONE_OR_MORE_BOUND> 4112027Sjungma@eit.uni-kl.declass multi_passthrough_initiator_socket 4212027Sjungma@eit.uni-kl.de : public multi_init_base< BUSWIDTH, TYPES, N, POL> 4312027Sjungma@eit.uni-kl.de{ 4412027Sjungma@eit.uni-kl.depublic: 4512027Sjungma@eit.uni-kl.de 4612027Sjungma@eit.uni-kl.de //typedefs 4712027Sjungma@eit.uni-kl.de // tlm 2.0 types for nb_transport 4812027Sjungma@eit.uni-kl.de typedef typename TYPES::tlm_payload_type transaction_type; 4912027Sjungma@eit.uni-kl.de typedef typename TYPES::tlm_phase_type phase_type; 5012027Sjungma@eit.uni-kl.de typedef tlm::tlm_sync_enum sync_enum_type; 5112027Sjungma@eit.uni-kl.de 5212027Sjungma@eit.uni-kl.de // typedefs to keep the fn ptr notations short 5312027Sjungma@eit.uni-kl.de typedef sync_enum_type (MODULE::*nb_cb)(int, 5412027Sjungma@eit.uni-kl.de transaction_type&, 5512027Sjungma@eit.uni-kl.de phase_type&, 5612027Sjungma@eit.uni-kl.de sc_core::sc_time&); 5712027Sjungma@eit.uni-kl.de typedef void (MODULE::*dmi_cb)(int, sc_dt::uint64, sc_dt::uint64); 5812027Sjungma@eit.uni-kl.de 5912027Sjungma@eit.uni-kl.de typedef multi_init_base<BUSWIDTH, TYPES, N, POL> base_type; 6012027Sjungma@eit.uni-kl.de 6112027Sjungma@eit.uni-kl.de typedef typename base_type::base_target_socket_type base_target_socket_type; 6212027Sjungma@eit.uni-kl.de 6312027Sjungma@eit.uni-kl.de static const char* default_name() 6412027Sjungma@eit.uni-kl.de { return sc_core::sc_gen_unique_name("multi_passthrough_initiator_socket"); } 6512027Sjungma@eit.uni-kl.de 6612027Sjungma@eit.uni-kl.de //CTOR 6712027Sjungma@eit.uni-kl.de explicit multi_passthrough_initiator_socket(const char* name = default_name()) 6812027Sjungma@eit.uni-kl.de : base_type(name) 6912027Sjungma@eit.uni-kl.de , m_hierarch_bind(0) 7012027Sjungma@eit.uni-kl.de , m_beoe_disabled(false) 7112027Sjungma@eit.uni-kl.de , m_dummy(this,42) 7212027Sjungma@eit.uni-kl.de { 7312027Sjungma@eit.uni-kl.de } 7412027Sjungma@eit.uni-kl.de 7512027Sjungma@eit.uni-kl.de ~multi_passthrough_initiator_socket(){ 7612027Sjungma@eit.uni-kl.de //clean up everything allocated by 'new' 7712027Sjungma@eit.uni-kl.de for (unsigned int i=0; i<m_binders.size(); i++) delete m_binders[i]; 7812027Sjungma@eit.uni-kl.de } 7912027Sjungma@eit.uni-kl.de 8012027Sjungma@eit.uni-kl.de //register callback for nb transport of bw interface 8112027Sjungma@eit.uni-kl.de void register_nb_transport_bw(MODULE* mod, 8212027Sjungma@eit.uni-kl.de sync_enum_type (MODULE::*cb)(int, 8312027Sjungma@eit.uni-kl.de transaction_type&, 8412027Sjungma@eit.uni-kl.de phase_type&, 8512027Sjungma@eit.uni-kl.de sc_core::sc_time&)) 8612027Sjungma@eit.uni-kl.de { 8712027Sjungma@eit.uni-kl.de //warn if there already is a callback 8812027Sjungma@eit.uni-kl.de if (m_nb_f.is_valid()){ 8912027Sjungma@eit.uni-kl.de display_warning("NBTransport_bw callback already registered."); 9012027Sjungma@eit.uni-kl.de return; 9112027Sjungma@eit.uni-kl.de } 9212027Sjungma@eit.uni-kl.de 9312027Sjungma@eit.uni-kl.de //set the functor 9412027Sjungma@eit.uni-kl.de m_nb_f.set_function(mod, cb); 9512027Sjungma@eit.uni-kl.de } 9612027Sjungma@eit.uni-kl.de 9712027Sjungma@eit.uni-kl.de //register callback for dmi function of bw interface 9812027Sjungma@eit.uni-kl.de void register_invalidate_direct_mem_ptr(MODULE* mod, 9912027Sjungma@eit.uni-kl.de void (MODULE::*cb)(int, sc_dt::uint64, sc_dt::uint64)) 10012027Sjungma@eit.uni-kl.de { 10112027Sjungma@eit.uni-kl.de //warn if there already is a callback 10212027Sjungma@eit.uni-kl.de if (m_dmi_f.is_valid()){ 10312027Sjungma@eit.uni-kl.de display_warning("InvalidateDMI callback already registered."); 10412027Sjungma@eit.uni-kl.de return; 10512027Sjungma@eit.uni-kl.de } 10612027Sjungma@eit.uni-kl.de 10712027Sjungma@eit.uni-kl.de //set the functor 10812027Sjungma@eit.uni-kl.de m_dmi_f.set_function(mod, cb); 10912027Sjungma@eit.uni-kl.de } 11012027Sjungma@eit.uni-kl.de 11112027Sjungma@eit.uni-kl.de //Override virtual functions of the tlm_initiator_socket: 11212027Sjungma@eit.uni-kl.de // this function is called whenever an sc_port (as part of a target socket) 11312027Sjungma@eit.uni-kl.de // wants to bind to the export of the underlying tlm_initiator_socket 11412027Sjungma@eit.uni-kl.de //At this time a callback binder is created an returned to the sc_port 11512027Sjungma@eit.uni-kl.de // of the target socket, so that it binds to the callback binder 11612027Sjungma@eit.uni-kl.de virtual tlm::tlm_bw_transport_if<TYPES>& get_base_interface() 11712027Sjungma@eit.uni-kl.de { 11812027Sjungma@eit.uni-kl.de m_binders.push_back(new callback_binder_bw<TYPES>(this, m_binders.size())); 11912027Sjungma@eit.uni-kl.de return *m_binders[m_binders.size()-1]; 12012027Sjungma@eit.uni-kl.de } 12112027Sjungma@eit.uni-kl.de 12212027Sjungma@eit.uni-kl.de // const overload not allowed for multi-sockets 12312027Sjungma@eit.uni-kl.de virtual const tlm::tlm_bw_transport_if<TYPES>& get_base_interface() const 12412027Sjungma@eit.uni-kl.de { 12512027Sjungma@eit.uni-kl.de display_error("'get_base_interface()' const not allowed for multi-sockets."); 12612027Sjungma@eit.uni-kl.de return base_type::get_base_interface(); 12712027Sjungma@eit.uni-kl.de } 12812027Sjungma@eit.uni-kl.de 12912027Sjungma@eit.uni-kl.de //Override virtual functions of the tlm_initiator_socket: 13012027Sjungma@eit.uni-kl.de // this function is called whenever an sc_export (as part of a initiator socket) 13112027Sjungma@eit.uni-kl.de // wants to bind to the export of the underlying tlm_initiator_socket 13212027Sjungma@eit.uni-kl.de // i.e. a hierarchical bind takes place 13312027Sjungma@eit.uni-kl.de virtual sc_core::sc_export<tlm::tlm_bw_transport_if<TYPES> >& get_base_export() 13412027Sjungma@eit.uni-kl.de { 13512027Sjungma@eit.uni-kl.de if (!m_beoe_disabled) //we are not bound hierarchically 13612027Sjungma@eit.uni-kl.de base_type::m_export.bind(m_dummy); //so we bind the dummy to avoid a SystemC error 13712027Sjungma@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 13812027Sjungma@eit.uni-kl.de } 13912027Sjungma@eit.uni-kl.de 14012027Sjungma@eit.uni-kl.de virtual const sc_core::sc_export<tlm::tlm_bw_transport_if<TYPES> >& get_base_export() const 14112027Sjungma@eit.uni-kl.de { 14212027Sjungma@eit.uni-kl.de return base_type::get_base_export(); 14312027Sjungma@eit.uni-kl.de } 14412027Sjungma@eit.uni-kl.de 14512027Sjungma@eit.uni-kl.de //bind against a target socket 14612027Sjungma@eit.uni-kl.de virtual void bind(base_target_socket_type& s) 14712027Sjungma@eit.uni-kl.de { 14812027Sjungma@eit.uni-kl.de //error if this socket is already bound hierarchically 14912027Sjungma@eit.uni-kl.de if (m_hierarch_bind) { 15012027Sjungma@eit.uni-kl.de display_error("Already hierarchically bound."); 15112027Sjungma@eit.uni-kl.de return; 15212027Sjungma@eit.uni-kl.de } 15312027Sjungma@eit.uni-kl.de 15412027Sjungma@eit.uni-kl.de base_type::bind(s); //satisfy systemC, leads to a call to get_base_interface() 15512027Sjungma@eit.uni-kl.de 15612027Sjungma@eit.uni-kl.de //try to cast the target socket into a fw interface 15712027Sjungma@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); 15812027Sjungma@eit.uni-kl.de if (!p_ex_s) { 15912027Sjungma@eit.uni-kl.de display_error("Multi socket not bound to tlm_socket."); 16012027Sjungma@eit.uni-kl.de return; 16112027Sjungma@eit.uni-kl.de } 16212027Sjungma@eit.uni-kl.de 16312027Sjungma@eit.uni-kl.de //try a cast into a multi sockets 16412027Sjungma@eit.uni-kl.de multi_to_multi_bind_base<TYPES>* test=dynamic_cast<multi_to_multi_bind_base<TYPES>*> (p_ex_s); 16512027Sjungma@eit.uni-kl.de if (test) //did we just do a multi-multi bind?? 16612027Sjungma@eit.uni-kl.de //if that is the case the multi target socket must have just created a callback binder 16712027Sjungma@eit.uni-kl.de // which we want to get from it. 16812027Sjungma@eit.uni-kl.de //Moreover, we also just created one, which we will pass to it. 16912027Sjungma@eit.uni-kl.de m_sockets.push_back(test->get_last_binder(m_binders[m_binders.size()-1])); 17012027Sjungma@eit.uni-kl.de else{ // if not just bind normally 17112027Sjungma@eit.uni-kl.de sc_core::sc_export<tlm::tlm_fw_transport_if<TYPES> >& ex_s=*p_ex_s; 17212027Sjungma@eit.uni-kl.de m_sockets.push_back(&((tlm::tlm_fw_transport_if<TYPES>&)ex_s)); //store the interface we are bound against 17312027Sjungma@eit.uni-kl.de } 17412027Sjungma@eit.uni-kl.de } 17512027Sjungma@eit.uni-kl.de 17612027Sjungma@eit.uni-kl.de //operator notation for direct bind 17712027Sjungma@eit.uni-kl.de void operator() (base_target_socket_type& s) 17812027Sjungma@eit.uni-kl.de { 17912027Sjungma@eit.uni-kl.de bind(s); 18012027Sjungma@eit.uni-kl.de } 18112027Sjungma@eit.uni-kl.de 18212027Sjungma@eit.uni-kl.de //SystemC standard callback before end of elaboration 18312027Sjungma@eit.uni-kl.de void before_end_of_elaboration(){ 18412027Sjungma@eit.uni-kl.de //if our export hasn't been bound yet (due to a hierarch binding) 18512027Sjungma@eit.uni-kl.de // we bind it now to avoid a SystemC error. 18612027Sjungma@eit.uni-kl.de //We must do that, because it is legal not to register a callback on this socket 18712027Sjungma@eit.uni-kl.de // as the user might only use b_transport 18812027Sjungma@eit.uni-kl.de if (!base_type::m_export.get_interface()){ 18912027Sjungma@eit.uni-kl.de base_type::m_export.bind(m_dummy); 19012027Sjungma@eit.uni-kl.de } 19112027Sjungma@eit.uni-kl.de 19212027Sjungma@eit.uni-kl.de //'break' here if the socket was told not to do callback binding 19312027Sjungma@eit.uni-kl.de if (m_beoe_disabled) return; 19412027Sjungma@eit.uni-kl.de 19512027Sjungma@eit.uni-kl.de //get the callback binders of the top of the hierachical bind chain 19612027Sjungma@eit.uni-kl.de // NOTE: this could be the same socket if there is no hierachical bind 19712027Sjungma@eit.uni-kl.de std::vector<callback_binder_bw<TYPES>* >& binders=get_hierarch_bind()->get_binders(); 19812027Sjungma@eit.uni-kl.de 19912027Sjungma@eit.uni-kl.de //get the interfaces bound to the top of the hierachical bind chain 20012027Sjungma@eit.uni-kl.de // NOTE: this could be the same socket if there is no hierachical bind 20112027Sjungma@eit.uni-kl.de m_used_sockets=get_hierarch_bind()->get_sockets(); 20212027Sjungma@eit.uni-kl.de 20312027Sjungma@eit.uni-kl.de //register the callbacks of this socket with the callback binders 20412027Sjungma@eit.uni-kl.de // we just got from the top of the hierachical bind chain 20512027Sjungma@eit.uni-kl.de for (unsigned int i=0; i<binders.size(); i++) { 20612027Sjungma@eit.uni-kl.de binders[i]->set_callbacks(m_nb_f, m_dmi_f); 20712027Sjungma@eit.uni-kl.de } 20812027Sjungma@eit.uni-kl.de } 20912027Sjungma@eit.uni-kl.de 21012027Sjungma@eit.uni-kl.de // 21112027Sjungma@eit.uni-kl.de // Bind multi initiator socket to multi initiator socket (hierarchical bind) 21212027Sjungma@eit.uni-kl.de // 21312027Sjungma@eit.uni-kl.de virtual void bind(base_type& s) 21412027Sjungma@eit.uni-kl.de { 21512027Sjungma@eit.uni-kl.de if (m_binders.size()) { 21612027Sjungma@eit.uni-kl.de //a multi socket is either bound hierarchically or directly 21712027Sjungma@eit.uni-kl.de display_error("Socket already directly bound."); 21812027Sjungma@eit.uni-kl.de return; 21912027Sjungma@eit.uni-kl.de } 22012027Sjungma@eit.uni-kl.de if (m_hierarch_bind){ 22112027Sjungma@eit.uni-kl.de display_warning("Socket already bound hierarchically. Bind attempt ignored."); 22212027Sjungma@eit.uni-kl.de return; 22312027Sjungma@eit.uni-kl.de } 22412027Sjungma@eit.uni-kl.de 22512027Sjungma@eit.uni-kl.de //remember to which socket we are hierarchically bound and disable it, 22612027Sjungma@eit.uni-kl.de // so that it won't try to register callbacks itself 22712027Sjungma@eit.uni-kl.de s.disable_cb_bind(); 22812027Sjungma@eit.uni-kl.de m_hierarch_bind=&s; 22912027Sjungma@eit.uni-kl.de base_type::bind(s); //satisfy SystemC 23012027Sjungma@eit.uni-kl.de } 23112027Sjungma@eit.uni-kl.de 23212027Sjungma@eit.uni-kl.de //operator notation for hierarchical bind 23312027Sjungma@eit.uni-kl.de void operator() (base_type& s) 23412027Sjungma@eit.uni-kl.de { 23512027Sjungma@eit.uni-kl.de bind(s); 23612027Sjungma@eit.uni-kl.de } 23712027Sjungma@eit.uni-kl.de 23812027Sjungma@eit.uni-kl.de //get access to sub port 23912027Sjungma@eit.uni-kl.de tlm::tlm_fw_transport_if<TYPES>* operator[](int i){return m_used_sockets[i];} 24012027Sjungma@eit.uni-kl.de 24112027Sjungma@eit.uni-kl.de //get the number of bound targets 24212027Sjungma@eit.uni-kl.de // NOTE: this is only valid at end of elaboration! 24312027Sjungma@eit.uni-kl.de unsigned int size() {return get_hierarch_bind()->get_sockets().size();} 24412027Sjungma@eit.uni-kl.de 24512027Sjungma@eit.uni-kl.deprotected: 24612027Sjungma@eit.uni-kl.de using base_type::display_warning; 24712027Sjungma@eit.uni-kl.de using base_type::display_error; 24812027Sjungma@eit.uni-kl.de 24912027Sjungma@eit.uni-kl.de //implementation of base class interface 25012027Sjungma@eit.uni-kl.de base_type* get_hierarch_bind(){if (m_hierarch_bind) return m_hierarch_bind->get_hierarch_bind(); else return this;} 25112027Sjungma@eit.uni-kl.de void disable_cb_bind(){ m_beoe_disabled=true;} 25212027Sjungma@eit.uni-kl.de std::vector<callback_binder_bw<TYPES>* >& get_binders(){return m_binders;} 25312027Sjungma@eit.uni-kl.de std::vector<tlm::tlm_fw_transport_if<TYPES>*>& get_sockets(){return m_sockets;} 25412027Sjungma@eit.uni-kl.de //vector of connected sockets 25512027Sjungma@eit.uni-kl.de std::vector<tlm::tlm_fw_transport_if<TYPES>*> m_sockets; 25612027Sjungma@eit.uni-kl.de std::vector<tlm::tlm_fw_transport_if<TYPES>*> m_used_sockets; 25712027Sjungma@eit.uni-kl.de //vector of binders that convert untagged interface into tagged interface 25812027Sjungma@eit.uni-kl.de std::vector<callback_binder_bw<TYPES>*> m_binders; 25912027Sjungma@eit.uni-kl.de 26012027Sjungma@eit.uni-kl.de base_type* m_hierarch_bind; //pointer to hierarchical bound multi port 26112027Sjungma@eit.uni-kl.de bool m_beoe_disabled; // bool that remembers whether this socket shall bind callbacks or not 26212027Sjungma@eit.uni-kl.de callback_binder_bw<TYPES> m_dummy; //a callback binder that is bound to the underlying export 26312027Sjungma@eit.uni-kl.de // in case there was no real bind 26412027Sjungma@eit.uni-kl.de 26512027Sjungma@eit.uni-kl.de //callbacks as functors 26612027Sjungma@eit.uni-kl.de // (allows to pass the callback to another socket that does not know the type of the module that owns 26712027Sjungma@eit.uni-kl.de // the callbacks) 26812027Sjungma@eit.uni-kl.de typename callback_binder_bw<TYPES>::nb_func_type m_nb_f; 26912027Sjungma@eit.uni-kl.de typename callback_binder_bw<TYPES>::dmi_func_type m_dmi_f; 27012027Sjungma@eit.uni-kl.de}; 27112027Sjungma@eit.uni-kl.de 27212027Sjungma@eit.uni-kl.detemplate <typename MODULE, 27312027Sjungma@eit.uni-kl.de unsigned int BUSWIDTH = 32, 27412027Sjungma@eit.uni-kl.de typename TYPES = tlm::tlm_base_protocol_types, 27512027Sjungma@eit.uni-kl.de unsigned int N=0> 27612027Sjungma@eit.uni-kl.declass multi_passthrough_initiator_socket_optional 27712027Sjungma@eit.uni-kl.de : public multi_passthrough_initiator_socket<MODULE,BUSWIDTH,TYPES,N,sc_core::SC_ZERO_OR_MORE_BOUND> 27812027Sjungma@eit.uni-kl.de{ 27912027Sjungma@eit.uni-kl.de typedef multi_passthrough_initiator_socket<MODULE,BUSWIDTH,TYPES,N,sc_core::SC_ZERO_OR_MORE_BOUND> socket_b; 28012027Sjungma@eit.uni-kl.depublic: 28112027Sjungma@eit.uni-kl.de multi_passthrough_initiator_socket_optional() : socket_b() {} 28212027Sjungma@eit.uni-kl.de explicit multi_passthrough_initiator_socket_optional(const char* name) : socket_b(name) {} 28312027Sjungma@eit.uni-kl.de}; 28412027Sjungma@eit.uni-kl.de 28512027Sjungma@eit.uni-kl.de} // namespace tlm_utils 28612027Sjungma@eit.uni-kl.de#endif // TLM_UTILS_MULTI_PASSTHROUGH_INITIATOR_SOCKET_H_INCLUDED_ 28712027Sjungma@eit.uni-kl.de