gem5  v20.1.0.0
SimpleLTTarget1.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4  more contributor license agreements. See the NOTICE file distributed
5  with this work for additional information regarding copyright ownership.
6  Accellera licenses this file to you under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with the
8  License. You may obtain a copy of the License at
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15  implied. See the License for the specific language governing
16  permissions and limitations under the License.
17 
18  *****************************************************************************/
19 
20 #ifndef __SIMPLE_LT_TARGET1_H__
21 #define __SIMPLE_LT_TARGET1_H__
22 
23 #include "tlm.h"
24 #include <cassert>
25 #include <vector>
26 
28  public sc_core::sc_module,
29  public virtual tlm::tlm_fw_transport_if<>
30 {
31 public:
33  typedef tlm::tlm_phase phase_type;
38 
39 public:
41 
42 public:
44  SimpleLTTarget1(sc_core::sc_module_name name, bool invalidate = false) :
46  socket("socket"),
47  m_invalidate(invalidate)
48  {
49  // Bind this target's interface to the target socket
50  socket(*this);
51  if (invalidate)
52  {
57  }
58  }
59 
61  {
62  //Target never calls wait, so we can do this
63  b_transport(trans, t);
64 
65  return tlm::TLM_COMPLETED;
66  }
67 
69  {
70  sc_dt::uint64 address = trans.get_address();
71  assert(address < 400);
72 
73  unsigned int& data = *reinterpret_cast<unsigned int*>(trans.get_data_ptr());
74  if (trans.get_command() == tlm::TLM_WRITE_COMMAND) {
75  std::cout << name() << ": Received write request: A = 0x"
76  << std::hex << (unsigned int)address
77  << ", D = 0x" << data << std::dec
78  << " @ " << sc_core::sc_time_stamp() << std::endl;
79 
80  *reinterpret_cast<unsigned int*>(&mMem[address]) = data;
82 
83  } else {
84  std::cout << name() << ": Received read request: A = 0x"
85  << std::hex << (unsigned int)address << std::dec
86  << " @ " << sc_core::sc_time_stamp() << std::endl;
87 
88  data = *reinterpret_cast<unsigned int*>(&mMem[address]);
90  }
91 
92  trans.set_response_status(tlm::TLM_OK_RESPONSE);
93 
94  trans.set_dmi_allowed(true);
95  }
96 
97  unsigned int transport_dbg(transaction_type& r)
98  {
99  if (r.get_address() >= 400) return 0;
100 
101  unsigned int tmp = (int)r.get_address();
102  unsigned int num_bytes;
103  if (tmp + r.get_data_length() >= 400) {
104  num_bytes = 400 - tmp;
105 
106  } else {
107  num_bytes = r.get_data_length();
108  }
109  if (r.is_read()) {
110  for (unsigned int i = 0; i < num_bytes; ++i) {
111  r.get_data_ptr()[i] = mMem[i + tmp];
112  }
113 
114  } else {
115  for (unsigned int i = 0; i < num_bytes; ++i) {
116  mMem[i + tmp] = r.get_data_ptr()[i];
117  }
118  }
119  return num_bytes;
120  }
121 
123  tlm::tlm_dmi& dmi_data)
124  {
125  sc_dt::uint64 address = trans.get_address();
127  if (address < 400) {
128  dmi_data.allow_read_write();
129  dmi_data.set_start_address(0x0);
130  dmi_data.set_end_address(399);
131  dmi_data.set_dmi_ptr(mMem);
134  return true;
135 
136  } else {
137  // should not happen
138  dmi_data.set_start_address(trans.get_address());
139  dmi_data.set_end_address(trans.get_address());
140  return false;
141 
142  }
143  }
144 
145  void invalidate_dmi_method()
146  {
147  sc_dt::uint64 start_address = 0x0;
148  sc_dt::uint64 end_address = 399;
149  socket->invalidate_direct_mem_ptr(start_address, end_address);
150  }
151 private:
152  unsigned char mMem[400];
153  bool m_invalidate;
156 };
157 
158 #endif
SimpleLTTarget1::socket
target_socket_type socket
Definition: SimpleLTTarget1.h:57
tlm::tlm_bw_transport_if<>
SimpleLTTarget1::SimpleLTTarget1
SimpleLTTarget1(sc_core::sc_module_name name, bool invalidate=false)
Definition: SimpleLTTarget1.h:61
data
const char data[]
Definition: circlebuf.test.cc:42
sc_core::sc_module
Definition: sc_module.hh:97
tlm::tlm_phase
Definition: phase.hh:47
tlm::tlm_dmi::allow_read_write
void allow_read_write()
Definition: dmi.hh:124
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
tlm::tlm_target_socket< 32 >
tlm::TLM_COMPLETED
@ TLM_COMPLETED
Definition: fw_bw_ifs.hh:65
SimpleLTTarget1::nb_transport_fw
sync_enum_type nb_transport_fw(transaction_type &trans, phase_type &phase, sc_core::sc_time &t)
Definition: SimpleLTTarget1.h:77
tlm::tlm_dmi
Definition: dmi.hh:46
tlm::TLM_WRITE_COMMAND
@ TLM_WRITE_COMMAND
Definition: gp.hh:102
tlm::TLM_OK_RESPONSE
@ TLM_OK_RESPONSE
Definition: gp.hh:108
SimpleLTTarget1::SC_HAS_PROCESS
SC_HAS_PROCESS(SimpleLTTarget1)
SimpleLTTarget1::get_direct_mem_ptr
bool get_direct_mem_ptr(transaction_type &trans, tlm::tlm_dmi &dmi_data)
Definition: SimpleLTTarget1.h:139
SimpleLTTarget1::target_socket_type
tlm::tlm_target_socket< 32 > target_socket_type
Definition: SimpleLTTarget1.h:54
tlm::tlm_fw_transport_if
Definition: fw_bw_ifs.hh:221
sc_core::SC_NS
@ SC_NS
Definition: sc_time.hh:43
tlm::tlm_dmi::set_end_address
void set_end_address(sc_dt::uint64 addr)
Definition: dmi.hh:117
sc_dt::uint64
uint64_t uint64
Definition: sc_nbdefs.hh:206
sc_core::sc_module::dont_initialize
void dont_initialize()
Definition: sc_module.cc:336
tlm::tlm_dmi::set_read_latency
void set_read_latency(sc_core::sc_time t)
Definition: dmi.hh:118
SC_METHOD
#define SC_METHOD(name)
Definition: sc_module.hh:299
sc_core::sc_event
Definition: sc_event.hh:169
SimpleLTTarget1::transaction_type
tlm::tlm_generic_payload transaction_type
Definition: SimpleLTTarget1.h:49
MipsISA::r
r
Definition: pra_constants.hh:95
sc_core::sc_time
Definition: sc_time.hh:49
SimpleLTTarget1::mMem
unsigned char mMem[400]
Definition: SimpleLTTarget1.h:169
SimpleLTTarget1::m_invalidate_dmi_event
sc_core::sc_event m_invalidate_dmi_event
Definition: SimpleLTTarget1.h:171
sc_core::sc_module_name
Definition: sc_module_name.hh:41
SimpleLTTarget1::transport_dbg
unsigned int transport_dbg(transaction_type &r)
Definition: SimpleLTTarget1.h:114
SimpleLTTarget1::m_invalidate
bool m_invalidate
Definition: SimpleLTTarget1.h:170
SimpleLTTarget1::sync_enum_type
tlm::tlm_sync_enum sync_enum_type
Definition: SimpleLTTarget1.h:51
SimpleLTTarget1::phase_type
tlm::tlm_phase phase_type
Definition: SimpleLTTarget1.h:50
sc_core::sc_event::notify
void notify()
Definition: sc_event.cc:337
SimpleLTTarget1
Definition: SimpleLTTarget1.h:27
tlm::tlm_dmi::set_write_latency
void set_write_latency(sc_core::sc_time t)
Definition: dmi.hh:119
tlm::tlm_generic_payload
Definition: gp.hh:133
ArmISA::t
Bitfield< 5 > t
Definition: miscregs_types.hh:67
sc_core::sc_object::name
const char * name() const
Definition: sc_object.cc:44
tlm::tlm_sync_enum
tlm_sync_enum
Definition: fw_bw_ifs.hh:48
SimpleLTTarget1::b_transport
void b_transport(transaction_type &trans, sc_core::sc_time &t)
Definition: SimpleLTTarget1.h:85
SimpleLTTarget1::fw_interface_type
tlm::tlm_fw_transport_if fw_interface_type
Definition: SimpleLTTarget1.h:52
tlm::tlm_dmi::set_dmi_ptr
void set_dmi_ptr(unsigned char *p)
Definition: dmi.hh:115
tlm::tlm_dmi::set_start_address
void set_start_address(sc_dt::uint64 addr)
Definition: dmi.hh:116
sc_core::sc_module::sensitive
sc_sensitive sensitive
Definition: sc_module.hh:206
SimpleLTTarget1::invalidate_dmi_method
void invalidate_dmi_method()
Definition: SimpleLTTarget1.h:162
sc_core::sc_time_stamp
const sc_time & sc_time_stamp()
Definition: sc_main.cc:128
SimpleLTTarget1::m_invalidate_dmi_time
sc_core::sc_time m_invalidate_dmi_time
Definition: SimpleLTTarget1.h:172
SimpleLTTarget1::bw_interface_type
tlm::tlm_bw_transport_if bw_interface_type
Definition: SimpleLTTarget1.h:53

Generated on Wed Sep 30 2020 14:02:16 for gem5 by doxygen 1.8.17