SimpleLTTarget1.h revision 12922
112922Sgabeblack@google.com/***************************************************************************** 212922Sgabeblack@google.com 312922Sgabeblack@google.com Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 412922Sgabeblack@google.com more contributor license agreements. See the NOTICE file distributed 512922Sgabeblack@google.com with this work for additional information regarding copyright ownership. 612922Sgabeblack@google.com Accellera licenses this file to you under the Apache License, Version 2.0 712922Sgabeblack@google.com (the "License"); you may not use this file except in compliance with the 812922Sgabeblack@google.com License. You may obtain a copy of the License at 912922Sgabeblack@google.com 1012922Sgabeblack@google.com http://www.apache.org/licenses/LICENSE-2.0 1112922Sgabeblack@google.com 1212922Sgabeblack@google.com Unless required by applicable law or agreed to in writing, software 1312922Sgabeblack@google.com distributed under the License is distributed on an "AS IS" BASIS, 1412922Sgabeblack@google.com WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 1512922Sgabeblack@google.com implied. See the License for the specific language governing 1612922Sgabeblack@google.com permissions and limitations under the License. 1712922Sgabeblack@google.com 1812922Sgabeblack@google.com *****************************************************************************/ 1912922Sgabeblack@google.com 2012922Sgabeblack@google.com#ifndef __SIMPLE_LT_TARGET1_H__ 2112922Sgabeblack@google.com#define __SIMPLE_LT_TARGET1_H__ 2212922Sgabeblack@google.com 2312922Sgabeblack@google.com#include "tlm.h" 2412922Sgabeblack@google.com#include <cassert> 2512922Sgabeblack@google.com#include <vector> 2612922Sgabeblack@google.com 2712922Sgabeblack@google.comclass SimpleLTTarget1 : 2812922Sgabeblack@google.com public sc_core::sc_module, 2912922Sgabeblack@google.com public virtual tlm::tlm_fw_transport_if<> 3012922Sgabeblack@google.com{ 3112922Sgabeblack@google.compublic: 3212922Sgabeblack@google.com typedef tlm::tlm_generic_payload transaction_type; 3312922Sgabeblack@google.com typedef tlm::tlm_phase phase_type; 3412922Sgabeblack@google.com typedef tlm::tlm_sync_enum sync_enum_type; 3512922Sgabeblack@google.com typedef tlm::tlm_fw_transport_if<> fw_interface_type; 3612922Sgabeblack@google.com typedef tlm::tlm_bw_transport_if<> bw_interface_type; 3712922Sgabeblack@google.com typedef tlm::tlm_target_socket<32> target_socket_type; 3812922Sgabeblack@google.com 3912922Sgabeblack@google.compublic: 4012922Sgabeblack@google.com target_socket_type socket; 4112922Sgabeblack@google.com 4212922Sgabeblack@google.compublic: 4312922Sgabeblack@google.com SC_HAS_PROCESS(SimpleLTTarget1); 4412922Sgabeblack@google.com SimpleLTTarget1(sc_core::sc_module_name name, bool invalidate = false) : 4512922Sgabeblack@google.com sc_core::sc_module(name), 4612922Sgabeblack@google.com socket("socket"), 4712922Sgabeblack@google.com m_invalidate(invalidate) 4812922Sgabeblack@google.com { 4912922Sgabeblack@google.com // Bind this target's interface to the target socket 5012922Sgabeblack@google.com socket(*this); 5112922Sgabeblack@google.com if (invalidate) 5212922Sgabeblack@google.com { 5312922Sgabeblack@google.com SC_METHOD(invalidate_dmi_method); 5412922Sgabeblack@google.com sensitive << m_invalidate_dmi_event; 5512922Sgabeblack@google.com dont_initialize(); 5612922Sgabeblack@google.com m_invalidate_dmi_time = sc_core::sc_time(25, sc_core::SC_NS); 5712922Sgabeblack@google.com } 5812922Sgabeblack@google.com } 5912922Sgabeblack@google.com 6012922Sgabeblack@google.com sync_enum_type nb_transport_fw(transaction_type& trans, phase_type& phase, sc_core::sc_time& t) 6112922Sgabeblack@google.com { 6212922Sgabeblack@google.com //Target never calls wait, so we can do this 6312922Sgabeblack@google.com b_transport(trans, t); 6412922Sgabeblack@google.com 6512922Sgabeblack@google.com return tlm::TLM_COMPLETED; 6612922Sgabeblack@google.com } 6712922Sgabeblack@google.com 6812922Sgabeblack@google.com void b_transport(transaction_type& trans, sc_core::sc_time &t) 6912922Sgabeblack@google.com { 7012922Sgabeblack@google.com sc_dt::uint64 address = trans.get_address(); 7112922Sgabeblack@google.com assert(address < 400); 7212922Sgabeblack@google.com 7312922Sgabeblack@google.com unsigned int& data = *reinterpret_cast<unsigned int*>(trans.get_data_ptr()); 7412922Sgabeblack@google.com if (trans.get_command() == tlm::TLM_WRITE_COMMAND) { 7512922Sgabeblack@google.com std::cout << name() << ": Received write request: A = 0x" 7612922Sgabeblack@google.com << std::hex << (unsigned int)address 7712922Sgabeblack@google.com << ", D = 0x" << data << std::dec 7812922Sgabeblack@google.com << " @ " << sc_core::sc_time_stamp() << std::endl; 7912922Sgabeblack@google.com 8012922Sgabeblack@google.com *reinterpret_cast<unsigned int*>(&mMem[address]) = data; 8112922Sgabeblack@google.com t+= sc_core::sc_time(10, sc_core::SC_NS); 8212922Sgabeblack@google.com 8312922Sgabeblack@google.com } else { 8412922Sgabeblack@google.com std::cout << name() << ": Received read request: A = 0x" 8512922Sgabeblack@google.com << std::hex << (unsigned int)address << std::dec 8612922Sgabeblack@google.com << " @ " << sc_core::sc_time_stamp() << std::endl; 8712922Sgabeblack@google.com 8812922Sgabeblack@google.com data = *reinterpret_cast<unsigned int*>(&mMem[address]); 8912922Sgabeblack@google.com t += sc_core::sc_time(100, sc_core::SC_NS); 9012922Sgabeblack@google.com } 9112922Sgabeblack@google.com 9212922Sgabeblack@google.com trans.set_response_status(tlm::TLM_OK_RESPONSE); 9312922Sgabeblack@google.com 9412922Sgabeblack@google.com trans.set_dmi_allowed(true); 9512922Sgabeblack@google.com } 9612922Sgabeblack@google.com 9712922Sgabeblack@google.com unsigned int transport_dbg(transaction_type& r) 9812922Sgabeblack@google.com { 9912922Sgabeblack@google.com if (r.get_address() >= 400) return 0; 10012922Sgabeblack@google.com 10112922Sgabeblack@google.com unsigned int tmp = (int)r.get_address(); 10212922Sgabeblack@google.com unsigned int num_bytes; 10312922Sgabeblack@google.com if (tmp + r.get_data_length() >= 400) { 10412922Sgabeblack@google.com num_bytes = 400 - tmp; 10512922Sgabeblack@google.com 10612922Sgabeblack@google.com } else { 10712922Sgabeblack@google.com num_bytes = r.get_data_length(); 10812922Sgabeblack@google.com } 10912922Sgabeblack@google.com if (r.is_read()) { 11012922Sgabeblack@google.com for (unsigned int i = 0; i < num_bytes; ++i) { 11112922Sgabeblack@google.com r.get_data_ptr()[i] = mMem[i + tmp]; 11212922Sgabeblack@google.com } 11312922Sgabeblack@google.com 11412922Sgabeblack@google.com } else { 11512922Sgabeblack@google.com for (unsigned int i = 0; i < num_bytes; ++i) { 11612922Sgabeblack@google.com mMem[i + tmp] = r.get_data_ptr()[i]; 11712922Sgabeblack@google.com } 11812922Sgabeblack@google.com } 11912922Sgabeblack@google.com return num_bytes; 12012922Sgabeblack@google.com } 12112922Sgabeblack@google.com 12212922Sgabeblack@google.com bool get_direct_mem_ptr(transaction_type& trans, 12312922Sgabeblack@google.com tlm::tlm_dmi& dmi_data) 12412922Sgabeblack@google.com { 12512922Sgabeblack@google.com sc_dt::uint64 address = trans.get_address(); 12612922Sgabeblack@google.com if (m_invalidate) m_invalidate_dmi_event.notify(m_invalidate_dmi_time); 12712922Sgabeblack@google.com if (address < 400) { 12812922Sgabeblack@google.com dmi_data.allow_read_write(); 12912922Sgabeblack@google.com dmi_data.set_start_address(0x0); 13012922Sgabeblack@google.com dmi_data.set_end_address(399); 13112922Sgabeblack@google.com dmi_data.set_dmi_ptr(mMem); 13212922Sgabeblack@google.com dmi_data.set_read_latency(sc_core::sc_time(100, sc_core::SC_NS)); 13312922Sgabeblack@google.com dmi_data.set_write_latency(sc_core::sc_time(10, sc_core::SC_NS)); 13412922Sgabeblack@google.com return true; 13512922Sgabeblack@google.com 13612922Sgabeblack@google.com } else { 13712922Sgabeblack@google.com // should not happen 13812922Sgabeblack@google.com dmi_data.set_start_address(trans.get_address()); 13912922Sgabeblack@google.com dmi_data.set_end_address(trans.get_address()); 14012922Sgabeblack@google.com return false; 14112922Sgabeblack@google.com 14212922Sgabeblack@google.com } 14312922Sgabeblack@google.com } 14412922Sgabeblack@google.com 14512922Sgabeblack@google.com void invalidate_dmi_method() 14612922Sgabeblack@google.com { 14712922Sgabeblack@google.com sc_dt::uint64 start_address = 0x0; 14812922Sgabeblack@google.com sc_dt::uint64 end_address = 399; 14912922Sgabeblack@google.com socket->invalidate_direct_mem_ptr(start_address, end_address); 15012922Sgabeblack@google.com } 15112922Sgabeblack@google.comprivate: 15212922Sgabeblack@google.com unsigned char mMem[400]; 15312922Sgabeblack@google.com bool m_invalidate; 15412922Sgabeblack@google.com sc_core::sc_event m_invalidate_dmi_event; 15512922Sgabeblack@google.com sc_core::sc_time m_invalidate_dmi_time; 15612922Sgabeblack@google.com}; 15712922Sgabeblack@google.com 15812922Sgabeblack@google.com#endif 159