112855Sgabeblack@google.com/***************************************************************************** 212855Sgabeblack@google.com 312855Sgabeblack@google.com Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 412855Sgabeblack@google.com more contributor license agreements. See the NOTICE file distributed 512855Sgabeblack@google.com with this work for additional information regarding copyright ownership. 612855Sgabeblack@google.com Accellera licenses this file to you under the Apache License, Version 2.0 712855Sgabeblack@google.com (the "License"); you may not use this file except in compliance with the 812855Sgabeblack@google.com License. You may obtain a copy of the License at 912855Sgabeblack@google.com 1012855Sgabeblack@google.com http://www.apache.org/licenses/LICENSE-2.0 1112855Sgabeblack@google.com 1212855Sgabeblack@google.com Unless required by applicable law or agreed to in writing, software 1312855Sgabeblack@google.com distributed under the License is distributed on an "AS IS" BASIS, 1412855Sgabeblack@google.com WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 1512855Sgabeblack@google.com implied. See the License for the specific language governing 1612855Sgabeblack@google.com permissions and limitations under the License. 1712855Sgabeblack@google.com 1812855Sgabeblack@google.com *****************************************************************************/ 1912855Sgabeblack@google.com 2012855Sgabeblack@google.com#ifndef __EXTENSIONS_ADAPTORS_H__ 2112855Sgabeblack@google.com#define __EXTENSIONS_ADAPTORS_H__ 2212855Sgabeblack@google.com 2312855Sgabeblack@google.com#include "tlm.h" 2412855Sgabeblack@google.com#include "my_extension.h" 2512855Sgabeblack@google.com 2612855Sgabeblack@google.com#include "tlm_utils/simple_initiator_socket.h" 2712855Sgabeblack@google.com#include "tlm_utils/simple_target_socket.h" 2812855Sgabeblack@google.com 2912855Sgabeblack@google.comtemplate <unsigned int BUSWIDTH = 32> 3012855Sgabeblack@google.comclass adapt_ext2gp : public sc_core::sc_module 3112855Sgabeblack@google.com{ 3212855Sgabeblack@google.com public: 3312855Sgabeblack@google.com typedef tlm::tlm_generic_payload initiator_payload_type; 3412855Sgabeblack@google.com typedef tlm::tlm_generic_payload target_payload_type; 3512855Sgabeblack@google.com typedef tlm_utils::simple_initiator_socket<adapt_ext2gp, BUSWIDTH, 3612855Sgabeblack@google.com tlm::tlm_base_protocol_types> initiator_socket_type; 3712855Sgabeblack@google.com typedef tlm_utils::simple_target_socket<adapt_ext2gp, BUSWIDTH, 3812855Sgabeblack@google.com my_extended_payload_types> target_socket_type; 3912855Sgabeblack@google.com 4012855Sgabeblack@google.com target_socket_type target_socket; 4112855Sgabeblack@google.com initiator_socket_type initiator_socket; 4212855Sgabeblack@google.com 4312855Sgabeblack@google.com SC_HAS_PROCESS(adapt_ext2gp); 4412855Sgabeblack@google.com adapt_ext2gp(sc_core::sc_module_name name_) 4512855Sgabeblack@google.com : sc_core::sc_module(name_) 4612855Sgabeblack@google.com { 4712855Sgabeblack@google.com target_socket.register_nb_transport_fw(this, &adapt_ext2gp::forward_nb_transport); 4812855Sgabeblack@google.com target_socket.register_transport_dbg(this, &adapt_ext2gp::transport_debug); 4912855Sgabeblack@google.com target_socket.register_get_direct_mem_ptr(this, &adapt_ext2gp::get_dmi_pointer); 5012855Sgabeblack@google.com 5112855Sgabeblack@google.com initiator_socket.register_nb_transport_bw(this, &adapt_ext2gp::backward_nb_transport); 5212855Sgabeblack@google.com initiator_socket.register_invalidate_direct_mem_ptr(this, &adapt_ext2gp::invalidate_dmi_pointers); 5312855Sgabeblack@google.com } 5412855Sgabeblack@google.com 5512855Sgabeblack@google.com /////////////// 5612855Sgabeblack@google.com // NB transport 5712855Sgabeblack@google.com /////////////// 5812855Sgabeblack@google.com 5912855Sgabeblack@google.com // Forward direction: The initiator calls this method with an extended 6012855Sgabeblack@google.com // payload. We leave the extension class in the vector, and it will be 6112855Sgabeblack@google.com // ignored by the GP target. 6212855Sgabeblack@google.com tlm::tlm_sync_enum forward_nb_transport(initiator_payload_type& trans, 6312855Sgabeblack@google.com tlm::tlm_phase& phase, 6412855Sgabeblack@google.com sc_core::sc_time& t) 6512855Sgabeblack@google.com { 6612855Sgabeblack@google.com return initiator_socket->nb_transport_fw(trans, phase, t); 6712855Sgabeblack@google.com } 6812855Sgabeblack@google.com // Backward direction: we can assume here that the payload we get 6912855Sgabeblack@google.com // as parameter is the same one that the initiator sent out. Thus, the 7012855Sgabeblack@google.com // extension vector is known to be present. 7112855Sgabeblack@google.com tlm::tlm_sync_enum backward_nb_transport(target_payload_type& trans, 7212855Sgabeblack@google.com tlm::tlm_phase& phase, 7312855Sgabeblack@google.com sc_core::sc_time& t) 7412855Sgabeblack@google.com { 7512855Sgabeblack@google.com return target_socket->nb_transport_bw(trans, phase, t); 7612855Sgabeblack@google.com } 7712855Sgabeblack@google.com 7812855Sgabeblack@google.com bool get_dmi_pointer(target_payload_type& trans, 7912855Sgabeblack@google.com tlm::tlm_dmi& dmi_data) 8012855Sgabeblack@google.com { 8112855Sgabeblack@google.com bool tmp_ret = initiator_socket->get_direct_mem_ptr(trans, 8212855Sgabeblack@google.com dmi_data); 8312855Sgabeblack@google.com return tmp_ret; 8412855Sgabeblack@google.com } 8512855Sgabeblack@google.com 8612855Sgabeblack@google.com ////////////////////////// 8712855Sgabeblack@google.com // simple call forwarders: 8812855Sgabeblack@google.com ////////////////////////// 8912855Sgabeblack@google.com unsigned int transport_debug(target_payload_type& trans) 9012855Sgabeblack@google.com { 9112855Sgabeblack@google.com return initiator_socket->transport_dbg(trans); 9212855Sgabeblack@google.com } 9312855Sgabeblack@google.com void invalidate_dmi_pointers(sc_dt::uint64 start_range, 9412855Sgabeblack@google.com sc_dt::uint64 end_range) 9512855Sgabeblack@google.com { 9612855Sgabeblack@google.com target_socket->invalidate_direct_mem_ptr(start_range, 9712855Sgabeblack@google.com end_range); 9812855Sgabeblack@google.com } 9912855Sgabeblack@google.com}; 10012855Sgabeblack@google.com 10112855Sgabeblack@google.comtemplate <unsigned int BUSWIDTH = 32> 10212855Sgabeblack@google.comclass adapt_gp2ext : public sc_core::sc_module 10312855Sgabeblack@google.com{ 10412855Sgabeblack@google.com public: 10512855Sgabeblack@google.com typedef tlm::tlm_generic_payload initiator_payload_type; 10612855Sgabeblack@google.com typedef tlm::tlm_generic_payload target_payload_type; 10712855Sgabeblack@google.com typedef tlm_utils::simple_initiator_socket<adapt_gp2ext, BUSWIDTH, 10812855Sgabeblack@google.com my_extended_payload_types> initiator_socket_type; 10912855Sgabeblack@google.com typedef tlm_utils::simple_target_socket<adapt_gp2ext, BUSWIDTH, 11012855Sgabeblack@google.com tlm::tlm_base_protocol_types> target_socket_type; 11112855Sgabeblack@google.com 11212855Sgabeblack@google.com target_socket_type target_socket; 11312855Sgabeblack@google.com initiator_socket_type initiator_socket; 11412855Sgabeblack@google.com 11512855Sgabeblack@google.com SC_HAS_PROCESS(adapt_gp2ext); 11612855Sgabeblack@google.com adapt_gp2ext(sc_core::sc_module_name name_) 11712855Sgabeblack@google.com : sc_core::sc_module(name_) 11812855Sgabeblack@google.com { 11912855Sgabeblack@google.com // Optionally, we can initialize our private extension class 12012855Sgabeblack@google.com // here, if required. 12112855Sgabeblack@google.com 12212855Sgabeblack@google.com target_socket.register_nb_transport_fw(this, &adapt_gp2ext::forward_nb_transport); 12312855Sgabeblack@google.com target_socket.register_transport_dbg(this, &adapt_gp2ext::transport_debug); 12412855Sgabeblack@google.com target_socket.register_get_direct_mem_ptr(this, &adapt_gp2ext::get_dmi_pointer); 12512855Sgabeblack@google.com 12612855Sgabeblack@google.com initiator_socket.register_nb_transport_bw(this, &adapt_gp2ext::backward_nb_transport); 12712855Sgabeblack@google.com initiator_socket.register_invalidate_direct_mem_ptr(this, &adapt_gp2ext::invalidate_dmi_pointers); 12812855Sgabeblack@google.com 12912855Sgabeblack@google.com m_ext.m_data = 13; 13012855Sgabeblack@google.com } 13112855Sgabeblack@google.com 13212855Sgabeblack@google.com /////////////// 13312855Sgabeblack@google.com // NB transport 13412855Sgabeblack@google.com /////////////// 13512855Sgabeblack@google.com 13612855Sgabeblack@google.com // Forward direction: We extend the payload on the fly (if needed). 13712855Sgabeblack@google.com tlm::tlm_sync_enum forward_nb_transport(initiator_payload_type& trans, 13812855Sgabeblack@google.com tlm::tlm_phase& phase, 13912855Sgabeblack@google.com sc_core::sc_time& t) 14012855Sgabeblack@google.com { 14112855Sgabeblack@google.com // If the mandatory extension is not there, we need to add it and 14212855Sgabeblack@google.com // store it so that we can re-construc the original state. 14312855Sgabeblack@google.com // Otherwise we don't touch the extension, so that we don't overwrite 14412855Sgabeblack@google.com // it in e.g. a nonGP->GP->nonGP (initiator->interconnect->target) 14512855Sgabeblack@google.com // setup. 14612855Sgabeblack@google.com // Note, however, that there might be situations where we might need to 14712855Sgabeblack@google.com // re-initialize the extension, e.g. for mutable data fields in 14812855Sgabeblack@google.com // different system setups. 14912855Sgabeblack@google.com trans.get_extension(m_initiator_ext); 15012855Sgabeblack@google.com if (!m_initiator_ext) 15112855Sgabeblack@google.com { 15212855Sgabeblack@google.com m_initiator_ext = trans.set_extension(&m_ext); 15312855Sgabeblack@google.com } 15412855Sgabeblack@google.com tlm::tlm_sync_enum tmp = 15512855Sgabeblack@google.com initiator_socket->nb_transport_fw(trans, phase, t); 15612855Sgabeblack@google.com if (tmp == tlm::TLM_COMPLETED) 15712855Sgabeblack@google.com { 15812855Sgabeblack@google.com m_initiator_ext = trans.set_extension(m_initiator_ext); 15912855Sgabeblack@google.com } 16012855Sgabeblack@google.com return tmp; 16112855Sgabeblack@google.com } 16212855Sgabeblack@google.com // Backward direction: only restore of original extension and static_cast. 16312855Sgabeblack@google.com tlm::tlm_sync_enum backward_nb_transport(target_payload_type& trans, 16412855Sgabeblack@google.com tlm::tlm_phase& phase, 16512855Sgabeblack@google.com sc_core::sc_time& t) 16612855Sgabeblack@google.com { 16712855Sgabeblack@google.com m_initiator_ext = trans.set_extension(m_initiator_ext); 16812855Sgabeblack@google.com return target_socket->nb_transport_bw(trans, phase, t); 16912855Sgabeblack@google.com } 17012855Sgabeblack@google.com 17112855Sgabeblack@google.com bool get_dmi_pointer(target_payload_type& trans, 17212855Sgabeblack@google.com tlm::tlm_dmi& dmi_data) 17312855Sgabeblack@google.com { 17412855Sgabeblack@google.com // If the mandatory extension is not there, we need to add it and 17512855Sgabeblack@google.com // store it so that we can re-construc the original state. 17612855Sgabeblack@google.com // Otherwise we don't touch the extension, so that we don't overwrite 17712855Sgabeblack@google.com // it in e.g. a nonGP->GP->nonGP (initiator->interconnect->target) 17812855Sgabeblack@google.com // setup. 17912855Sgabeblack@google.com my_extension* tmp_ext; 18012855Sgabeblack@google.com trans.get_extension(tmp_ext); 18112855Sgabeblack@google.com if (!tmp_ext) 18212855Sgabeblack@google.com { 18312855Sgabeblack@google.com trans.set_extension(&m_ext); 18412855Sgabeblack@google.com } 18512855Sgabeblack@google.com bool tmp_ret = initiator_socket->get_direct_mem_ptr(trans, 18612855Sgabeblack@google.com dmi_data); 18712855Sgabeblack@google.com if(!tmp_ext) 18812855Sgabeblack@google.com { 18912855Sgabeblack@google.com trans.clear_extension(tmp_ext); 19012855Sgabeblack@google.com } 19112855Sgabeblack@google.com return tmp_ret; 19212855Sgabeblack@google.com } 19312855Sgabeblack@google.com ////////////////////////// 19412855Sgabeblack@google.com // simple call forwarders: 19512855Sgabeblack@google.com ////////////////////////// 19612855Sgabeblack@google.com unsigned int transport_debug(target_payload_type& trans) 19712855Sgabeblack@google.com { 19812855Sgabeblack@google.com return initiator_socket->transport_dbg(trans); 19912855Sgabeblack@google.com } 20012855Sgabeblack@google.com void invalidate_dmi_pointers(sc_dt::uint64 start_range, 20112855Sgabeblack@google.com sc_dt::uint64 end_range) 20212855Sgabeblack@google.com { 20312855Sgabeblack@google.com target_socket->invalidate_direct_mem_ptr(start_range, 20412855Sgabeblack@google.com end_range); 20512855Sgabeblack@google.com } 20612855Sgabeblack@google.com 20712855Sgabeblack@google.comprivate: 20812855Sgabeblack@google.com my_extension m_ext; 20912855Sgabeblack@google.com my_extension* m_initiator_ext; 21012855Sgabeblack@google.com}; 21112855Sgabeblack@google.com 21212855Sgabeblack@google.com#endif 213