gem5  v22.1.0.0
port_proxy.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2013, 2018 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions are
16  * met: redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer;
18  * redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution;
21  * neither the name of the copyright holders nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 
57 #ifndef __MEM_PORT_PROXY_HH__
58 #define __MEM_PORT_PROXY_HH__
59 
60 #include <functional>
61 #include <limits>
62 
64 #include "sim/byteswap.hh"
65 
66 namespace gem5
67 {
68 
69 class RequestPort;
70 class ThreadContext;
71 
87 {
88  public:
89  typedef std::function<void(PacketPtr pkt)> SendFunctionalFunc;
90 
91  private:
93 
95  const unsigned int _cacheLineSize;
96 
97  void
99  {
100  // Since port proxies aren't anyone else's peer, they should never
101  // receive snoops.
102  panic("Port proxies should never receive snoops.");
103  }
104 
105  public:
106  PortProxy(SendFunctionalFunc func, unsigned int cache_line_size) :
107  sendFunctional(func), _cacheLineSize(cache_line_size)
108  {}
109 
110  // Helpers which create typical SendFunctionalFunc-s from other objects.
111  PortProxy(ThreadContext *tc, unsigned int cache_line_size);
112  PortProxy(const RequestPort &port, unsigned int cache_line_size);
113 
114  virtual ~PortProxy() {}
115 
116 
123  void *p, int size) const;
124 
129  const void *p, int size) const;
130 
135  uint8_t v, int size) const;
136 
137 
138 
145  virtual bool
146  tryReadBlob(Addr addr, void *p, int size) const
147  {
148  readBlobPhys(addr, 0, p, size);
149  return true;
150  }
151 
156  virtual bool
157  tryWriteBlob(Addr addr, const void *p, int size) const
158  {
159  writeBlobPhys(addr, 0, p, size);
160  return true;
161  }
162 
167  virtual bool
168  tryMemsetBlob(Addr addr, uint8_t val, int size) const
169  {
170  memsetBlobPhys(addr, 0, val, size);
171  return true;
172  }
173 
174 
175 
181  void
182  readBlob(Addr addr, void *p, int size) const
183  {
184  if (!tryReadBlob(addr, p, size))
185  fatal("readBlob(%#x, ...) failed", addr);
186  }
187 
191  void
192  writeBlob(Addr addr, const void *p, int size) const
193  {
194  if (!tryWriteBlob(addr, p, size))
195  fatal("writeBlob(%#x, ...) failed", addr);
196  }
197 
201  void
202  memsetBlob(Addr addr, uint8_t v, int size) const
203  {
204  if (!tryMemsetBlob(addr, v, size))
205  fatal("memsetBlob(%#x, ...) failed", addr);
206  }
207 
211  template <typename T>
212  T read(Addr address) const;
213 
217  template <typename T>
218  void write(Addr address, const T &data) const;
219 
224  template <typename T>
225  T read(Addr address, ByteOrder guest_byte_order) const;
226 
231  template <typename T>
232  void write(Addr address, T data, ByteOrder guest_byte_order) const;
233 
238  bool tryWriteString(Addr addr, const char *str) const;
239 
243  void
244  writeString(Addr addr, const char *str) const
245  {
246  if (!tryWriteString(addr, str))
247  fatal("writeString(%#x, ...) failed", addr);
248  }
249 
254  bool tryReadString(std::string &str, Addr addr) const;
255 
259  void
260  readString(std::string &str, Addr addr) const
261  {
262  if (!tryReadString(str, addr))
263  fatal("readString(%#x, ...) failed", addr);
264  }
265 
271  bool tryReadString(char *str, Addr addr, size_t maxlen) const;
272 
276  void
277  readString(char *str, Addr addr, size_t maxlen) const
278  {
279  if (!tryReadString(str, addr, maxlen))
280  fatal("readString(%#x, ...) failed", addr);
281  }
282 };
283 
284 
285 template <typename T>
286 T
287 PortProxy::read(Addr address) const
288 {
289  T data;
290  readBlob(address, &data, sizeof(T));
291  return data;
292 }
293 
294 template <typename T>
295 void
296 PortProxy::write(Addr address, const T &data) const
297 {
298  writeBlob(address, &data, sizeof(T));
299 }
300 
301 template <typename T>
302 T
303 PortProxy::read(Addr address, ByteOrder byte_order) const
304 {
305  T data;
306  readBlob(address, &data, sizeof(T));
307  return gtoh(data, byte_order);
308 }
309 
310 template <typename T>
311 void
312 PortProxy::write(Addr address, T data, ByteOrder byte_order) const
313 {
314  data = htog(data, byte_order);
315  writeBlob(address, &data, sizeof(T));
316 }
317 
318 } // namespace gem5
319 
320 #endif // __MEM_PORT_PROXY_HH__
const char data[]
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
This object is a proxy for a port or other object which implements the functional response protocol,...
Definition: port_proxy.hh:87
T read(Addr address) const
Read sizeof(T) bytes from address and return as object T.
Definition: port_proxy.hh:287
const unsigned int _cacheLineSize
Granularity of any transactions issued through this proxy.
Definition: port_proxy.hh:95
void writeBlob(Addr addr, const void *p, int size) const
Same as tryWriteBlob, but insists on success.
Definition: port_proxy.hh:192
virtual bool tryReadBlob(Addr addr, void *p, int size) const
Methods to override in base classes.
Definition: port_proxy.hh:146
std::function< void(PacketPtr pkt)> SendFunctionalFunc
Definition: port_proxy.hh:89
bool tryWriteString(Addr addr, const char *str) const
Write the string str into guest memory at address addr.
Definition: port_proxy.cc:105
virtual ~PortProxy()
Definition: port_proxy.hh:114
void write(Addr address, const T &data) const
Write object T to address.
Definition: port_proxy.hh:296
void memsetBlobPhys(Addr addr, Request::Flags flags, uint8_t v, int size) const
Fill size bytes starting at physical addr with byte value val.
Definition: port_proxy.cc:92
void recvFunctionalSnoop(PacketPtr pkt) override
Receive a functional snoop request packet from the peer.
Definition: port_proxy.hh:98
void readString(std::string &str, Addr addr) const
Same as tryReadString, but insists on success.
Definition: port_proxy.hh:260
virtual bool tryWriteBlob(Addr addr, const void *p, int size) const
Write size bytes from p to address.
Definition: port_proxy.hh:157
void memsetBlob(Addr addr, uint8_t v, int size) const
Same as tryMemsetBlob, but insists on success.
Definition: port_proxy.hh:202
void readString(char *str, Addr addr, size_t maxlen) const
Same as tryReadString, but insists on success.
Definition: port_proxy.hh:277
bool tryReadString(std::string &str, Addr addr) const
Reads the string at guest address addr into the std::string str.
Definition: port_proxy.cc:115
void writeString(Addr addr, const char *str) const
Same as tryWriteString, but insists on success.
Definition: port_proxy.hh:244
void readBlobPhys(Addr addr, Request::Flags flags, void *p, int size) const
Fixed functionality for use in base classes.
Definition: port_proxy.cc:58
PortProxy(SendFunctionalFunc func, unsigned int cache_line_size)
Definition: port_proxy.hh:106
SendFunctionalFunc sendFunctional
Definition: port_proxy.hh:92
void writeBlobPhys(Addr addr, Request::Flags flags, const void *p, int size) const
Write size bytes from p to physical address.
Definition: port_proxy.cc:75
void readBlob(Addr addr, void *p, int size) const
Higher level interfaces based on the above.
Definition: port_proxy.hh:182
virtual bool tryMemsetBlob(Addr addr, uint8_t val, int size) const
Fill size bytes starting at addr with byte value val.
Definition: port_proxy.hh:168
A RequestPort is a specialisation of a Port, which implements the default protocol for the three diff...
Definition: port.hh:79
ThreadContext is the external interface to all thread state for anything outside of the CPU.
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:190
uint8_t flags
Definition: helpers.cc:66
Bitfield< 0 > v
Definition: pagetable.hh:65
Bitfield< 54 > p
Definition: pagetable.hh:70
Bitfield< 63 > val
Definition: misc.hh:776
Bitfield< 3 > addr
Definition: types.hh:84
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
T gtoh(T value, ByteOrder guest_byte_order)
Definition: byteswap.hh:194
T htog(T value, ByteOrder guest_byte_order)
Definition: byteswap.hh:187

Generated on Wed Dec 21 2022 10:22:37 for gem5 by doxygen 1.9.1