gem5  v20.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 
63 #include "mem/port.hh"
64 #include "sim/byteswap.hh"
65 
81 {
82  public:
83  typedef std::function<void(PacketPtr pkt)> SendFunctionalFunc;
84 
85  private:
87 
89  const unsigned int _cacheLineSize;
90 
91  void
93  {
94  // Since port proxies aren't anyone else's peer, they should never
95  // receive snoops.
96  panic("Port proxies should never receive snoops.");
97  }
98 
99  public:
100  PortProxy(SendFunctionalFunc func, unsigned int cacheLineSize) :
101  sendFunctional(func), _cacheLineSize(cacheLineSize)
102  {}
103  PortProxy(const RequestPort &port, unsigned int cacheLineSize) :
104  sendFunctional([&port](PacketPtr pkt)->void {
105  port.sendFunctional(pkt);
106  }), _cacheLineSize(cacheLineSize)
107  {}
108  virtual ~PortProxy() { }
109 
110 
111 
117  void readBlobPhys(Addr addr, Request::Flags flags,
118  void *p, int size) const;
119 
124  const void *p, int size) const;
125 
130  uint8_t v, int size) const;
131 
132 
133 
140  virtual bool
141  tryReadBlob(Addr addr, void *p, int size) const
142  {
143  readBlobPhys(addr, 0, p, size);
144  return true;
145  }
146 
151  virtual bool
152  tryWriteBlob(Addr addr, const void *p, int size) const
153  {
154  writeBlobPhys(addr, 0, p, size);
155  return true;
156  }
157 
162  virtual bool
163  tryMemsetBlob(Addr addr, uint8_t val, int size) const
164  {
165  memsetBlobPhys(addr, 0, val, size);
166  return true;
167  }
168 
169 
170 
176  void
177  readBlob(Addr addr, void *p, int size) const
178  {
179  if (!tryReadBlob(addr, p, size))
180  fatal("readBlob(%#x, ...) failed", addr);
181  }
182 
186  void
187  writeBlob(Addr addr, const void *p, int size) const
188  {
189  if (!tryWriteBlob(addr, p, size))
190  fatal("writeBlob(%#x, ...) failed", addr);
191  }
192 
196  void
197  memsetBlob(Addr addr, uint8_t v, int size) const
198  {
199  if (!tryMemsetBlob(addr, v, size))
200  fatal("memsetBlob(%#x, ...) failed", addr);
201  }
202 
206  template <typename T>
207  T read(Addr address) const;
208 
212  template <typename T>
213  void write(Addr address, const T &data) const;
214 
219  template <typename T>
220  T read(Addr address, ByteOrder guest_byte_order) const;
221 
226  template <typename T>
227  void write(Addr address, T data, ByteOrder guest_byte_order) const;
228 
233  bool tryWriteString(Addr addr, const char *str) const;
234 
238  void
239  writeString(Addr addr, const char *str) const
240  {
241  if (!tryWriteString(addr, str))
242  fatal("writeString(%#x, ...) failed", addr);
243  }
244 
249  bool tryReadString(std::string &str, Addr addr) const;
250 
254  void
255  readString(std::string &str, Addr addr) const
256  {
257  if (!tryReadString(str, addr))
258  fatal("readString(%#x, ...) failed", addr);
259  }
260 
266  bool tryReadString(char *str, Addr addr, size_t maxlen) const;
267 
271  void
272  readString(char *str, Addr addr, size_t maxlen) const
273  {
274  if (!tryReadString(str, addr, maxlen))
275  fatal("readString(%#x, ...) failed", addr);
276  }
277 };
278 
279 
280 template <typename T>
281 T
282 PortProxy::read(Addr address) const
283 {
284  T data;
285  readBlob(address, &data, sizeof(T));
286  return data;
287 }
288 
289 template <typename T>
290 void
291 PortProxy::write(Addr address, const T &data) const
292 {
293  writeBlob(address, &data, sizeof(T));
294 }
295 
296 template <typename T>
297 T
298 PortProxy::read(Addr address, ByteOrder byte_order) const
299 {
300  T data;
301  readBlob(address, &data, sizeof(T));
302  return gtoh(data, byte_order);
303 }
304 
305 template <typename T>
306 void
307 PortProxy::write(Addr address, T data, ByteOrder byte_order) const
308 {
309  data = htog(data, byte_order);
310  writeBlob(address, &data, sizeof(T));
311 }
312 
313 #endif // __MEM_PORT_PROXY_HH__
PortProxy::tryReadBlob
virtual bool tryReadBlob(Addr addr, void *p, int size) const
Methods to override in base classes.
Definition: port_proxy.hh:141
fatal
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:183
data
const char data[]
Definition: circlebuf.test.cc:42
PortProxy::_cacheLineSize
const unsigned int _cacheLineSize
Granularity of any transactions issued through this proxy.
Definition: port_proxy.hh:89
Flags< FlagsType >
PortProxy::writeBlobPhys
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:60
RequestPort::sendFunctional
void sendFunctional(PacketPtr pkt) const
Send a functional request packet, where the data is instantly updated everywhere in the memory system...
Definition: port.hh:482
PortProxy::tryWriteBlob
virtual bool tryWriteBlob(Addr addr, const void *p, int size) const
Write size bytes from p to address.
Definition: port_proxy.hh:152
PortProxy::writeBlob
void writeBlob(Addr addr, const void *p, int size) const
Same as tryWriteBlob, but insists on success.
Definition: port_proxy.hh:187
PortProxy::readString
void readString(char *str, Addr addr, size_t maxlen) const
Same as tryReadString, but insists on success.
Definition: port_proxy.hh:272
PortProxy::recvFunctionalSnoop
void recvFunctionalSnoop(PacketPtr pkt) override
Receive a functional snoop request packet from the peer.
Definition: port_proxy.hh:92
PortProxy::memsetBlobPhys
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:77
PortProxy::readString
void readString(std::string &str, Addr addr) const
Same as tryReadString, but insists on success.
Definition: port_proxy.hh:255
PortProxy::writeString
void writeString(Addr addr, const char *str) const
Same as tryWriteString, but insists on success.
Definition: port_proxy.hh:239
htog
T htog(T value, ByteOrder guest_byte_order)
Definition: byteswap.hh:155
port.hh
PortProxy::tryWriteString
bool tryWriteString(Addr addr, const char *str) const
Write the string str into guest memory at address addr.
Definition: port_proxy.cc:90
PortProxy::SendFunctionalFunc
std::function< void(PacketPtr pkt)> SendFunctionalFunc
Definition: port_proxy.hh:83
PortProxy::tryMemsetBlob
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:163
RequestPort
A RequestPort is a specialisation of a Port, which implements the default protocol for the three diff...
Definition: port.hh:74
PortProxy::readBlobPhys
void readBlobPhys(Addr addr, Request::Flags flags, void *p, int size) const
Fixed functionality for use in base classes.
Definition: port_proxy.cc:43
X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:769
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
PortProxy
This object is a proxy for a port or other object which implements the functional response protocol,...
Definition: port_proxy.hh:80
PortProxy::read
T read(Addr address) const
Read sizeof(T) bytes from address and return as object T.
Definition: port_proxy.hh:282
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:257
addr
ip6_addr_t addr
Definition: inet.hh:423
PortProxy::sendFunctional
SendFunctionalFunc sendFunctional
Definition: port_proxy.hh:86
gtoh
T gtoh(T value, ByteOrder guest_byte_order)
Definition: byteswap.hh:162
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
PortProxy::PortProxy
PortProxy(SendFunctionalFunc func, unsigned int cacheLineSize)
Definition: port_proxy.hh:100
PortProxy::PortProxy
PortProxy(const RequestPort &port, unsigned int cacheLineSize)
Definition: port_proxy.hh:103
PortProxy::memsetBlob
void memsetBlob(Addr addr, uint8_t v, int size) const
Same as tryMemsetBlob, but insists on success.
Definition: port_proxy.hh:197
PortProxy::readBlob
void readBlob(Addr addr, void *p, int size) const
Higher level interfaces based on the above.
Definition: port_proxy.hh:177
PortProxy::tryReadString
bool tryReadString(std::string &str, Addr addr) const
Reads the string at guest address addr into the std::string str.
Definition: port_proxy.cc:100
ArmISA::v
Bitfield< 28 > v
Definition: miscregs_types.hh:51
PortProxy::write
void write(Addr address, const T &data) const
Write object T to address.
Definition: port_proxy.hh:291
byteswap.hh
FunctionalRequestProtocol
Definition: functional.hh:48
PortProxy::~PortProxy
virtual ~PortProxy()
Definition: port_proxy.hh:108
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171

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