gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  * Authors: Andreas Hansson
38  */
39 
59 #ifndef __MEM_PORT_PROXY_HH__
60 #define __MEM_PORT_PROXY_HH__
61 
62 #include <functional>
63 #include <limits>
64 
65 #include "mem/port.hh"
66 #include "sim/byteswap.hh"
67 
83 {
84  public:
85  typedef std::function<void(PacketPtr pkt)> SendFunctionalFunc;
86 
87  private:
88  SendFunctionalFunc sendFunctional;
89 
91  const unsigned int _cacheLineSize;
92 
93  void
95  {
96  // Since port proxies aren't anyone else's peer, they should never
97  // receive snoops.
98  panic("Port proxies should never receive snoops.");
99  }
100 
101  public:
102  PortProxy(SendFunctionalFunc func, unsigned int cacheLineSize) :
103  sendFunctional(func), _cacheLineSize(cacheLineSize)
104  {}
105  PortProxy(const MasterPort &port, unsigned int cacheLineSize) :
106  sendFunctional([&port](PacketPtr pkt)->void {
107  port.sendFunctional(pkt);
108  }), _cacheLineSize(cacheLineSize)
109  {}
110  virtual ~PortProxy() { }
111 
112 
113 
119  void readBlobPhys(Addr addr, Request::Flags flags,
120  void *p, int size) const;
121 
125  void writeBlobPhys(Addr addr, Request::Flags flags,
126  const void *p, int size) const;
127 
131  void memsetBlobPhys(Addr addr, Request::Flags flags,
132  uint8_t v, int size) const;
133 
134 
135 
142  virtual bool
143  tryReadBlob(Addr addr, void *p, int size) const
144  {
145  readBlobPhys(addr, 0, p, size);
146  return true;
147  }
148 
153  virtual bool
154  tryWriteBlob(Addr addr, const void *p, int size) const
155  {
156  writeBlobPhys(addr, 0, p, size);
157  return true;
158  }
159 
164  virtual bool
165  tryMemsetBlob(Addr addr, uint8_t val, int size) const
166  {
167  memsetBlobPhys(addr, 0, val, size);
168  return true;
169  }
170 
171 
172 
178  void
179  readBlob(Addr addr, void *p, int size) const
180  {
181  if (!tryReadBlob(addr, p, size))
182  fatal("readBlob(%#x, ...) failed", addr);
183  }
184 
188  void
189  writeBlob(Addr addr, const void *p, int size) const
190  {
191  if (!tryWriteBlob(addr, p, size))
192  fatal("writeBlob(%#x, ...) failed", addr);
193  }
194 
198  void
199  memsetBlob(Addr addr, uint8_t v, int size) const
200  {
201  if (!tryMemsetBlob(addr, v, size))
202  fatal("memsetBlob(%#x, ...) failed", addr);
203  }
204 
208  template <typename T>
209  T read(Addr address) const;
210 
214  template <typename T>
215  void write(Addr address, const T &data) const;
216 
221  template <typename T>
222  T read(Addr address, ByteOrder guest_byte_order) const;
223 
228  template <typename T>
229  void write(Addr address, T data, ByteOrder guest_byte_order) const;
230 
235  bool tryWriteString(Addr addr, const char *str) const;
236 
240  void
241  writeString(Addr addr, const char *str) const
242  {
243  if (!tryWriteString(addr, str))
244  fatal("writeString(%#x, ...) failed", addr);
245  }
246 
251  bool tryReadString(std::string &str, Addr addr) const;
252 
256  void
257  readString(std::string &str, Addr addr) const
258  {
259  if (!tryReadString(str, addr))
260  fatal("readString(%#x, ...) failed", addr);
261  }
262 
268  bool tryReadString(char *str, Addr addr, size_t maxlen) const;
269 
273  void
274  readString(char *str, Addr addr, size_t maxlen) const
275  {
276  if (!tryReadString(str, addr, maxlen))
277  fatal("readString(%#x, ...) failed", addr);
278  }
279 };
280 
281 
282 template <typename T>
283 T
284 PortProxy::read(Addr address) const
285 {
286  T data;
287  readBlob(address, &data, sizeof(T));
288  return data;
289 }
290 
291 template <typename T>
292 void
293 PortProxy::write(Addr address, const T &data) const
294 {
295  writeBlob(address, &data, sizeof(T));
296 }
297 
298 template <typename T>
299 T
300 PortProxy::read(Addr address, ByteOrder byte_order) const
301 {
302  T data;
303  readBlob(address, &data, sizeof(T));
304  return gtoh(data, byte_order);
305 }
306 
307 template <typename T>
308 void
309 PortProxy::write(Addr address, T data, ByteOrder byte_order) const
310 {
311  data = htog(data, byte_order);
312  writeBlob(address, &data, sizeof(T));
313 }
314 
315 #endif // __MEM_PORT_PROXY_HH__
A MasterPort is a specialisation of a BaseMasterPort, which implements the default protocol for the t...
Definition: port.hh:75
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:167
Bitfield< 28 > v
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:175
T gtoh(T value, ByteOrder guest_byte_order)
Definition: byteswap.hh:166
virtual bool tryWriteBlob(Addr addr, const void *p, int size) const
Write size bytes from p to address.
Definition: port_proxy.hh:154
virtual bool tryReadBlob(Addr addr, void *p, int size) const
Methods to override in base classes.
Definition: port_proxy.hh:143
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:62
const unsigned int _cacheLineSize
Granularity of any transactions issued through this proxy.
Definition: port_proxy.hh:91
void readBlobPhys(Addr addr, Request::Flags flags, void *p, int size) const
Fixed functionality for use in base classes.
Definition: port_proxy.cc:45
void writeString(Addr addr, const char *str) const
Same as tryWriteString, but insists on success.
Definition: port_proxy.hh:241
PortProxy(const MasterPort &port, unsigned int cacheLineSize)
Definition: port_proxy.hh:105
ip6_addr_t addr
Definition: inet.hh:335
T read(Addr address) const
Read sizeof(T) bytes from address and return as object T.
Definition: port_proxy.hh:284
bool tryWriteString(Addr addr, const char *str) const
Write the string str into guest memory at address addr.
Definition: port_proxy.cc:92
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:165
Bitfield< 63 > val
Definition: misc.hh:771
void recvFunctionalSnoop(PacketPtr pkt) override
Receive a functional snoop request packet from the peer.
Definition: port_proxy.hh:94
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:79
T htog(T value, ByteOrder guest_byte_order)
Definition: byteswap.hh:159
void writeBlob(Addr addr, const void *p, int size) const
Same as tryWriteBlob, but insists on success.
Definition: port_proxy.hh:189
void memsetBlob(Addr addr, uint8_t v, int size) const
Same as tryMemsetBlob, but insists on success.
Definition: port_proxy.hh:199
void readString(char *str, Addr addr, size_t maxlen) const
Same as tryReadString, but insists on success.
Definition: port_proxy.hh:274
ByteOrder
Definition: types.hh:247
SendFunctionalFunc sendFunctional
Definition: port_proxy.hh:88
Port Object Declaration.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:255
void readBlob(Addr addr, void *p, int size) const
Higher level interfaces based on the above.
Definition: port_proxy.hh:179
This object is a proxy for a port or other object which implements the functional response protocol...
Definition: port_proxy.hh:82
void readString(std::string &str, Addr addr) const
Same as tryReadString, but insists on success.
Definition: port_proxy.hh:257
std::function< void(PacketPtr pkt)> SendFunctionalFunc
Definition: port_proxy.hh:85
PortProxy(SendFunctionalFunc func, unsigned int cacheLineSize)
Definition: port_proxy.hh:102
virtual ~PortProxy()
Definition: port_proxy.hh:110
void sendFunctional(PacketPtr pkt) const
Send a functional request packet, where the data is instantly updated everywhere in the memory system...
Definition: port.hh:439
void write(Addr address, const T &data) const
Write object T to address.
Definition: port_proxy.hh:293
bool tryReadString(std::string &str, Addr addr) const
Reads the string at guest address addr into the std::string str.
Definition: port_proxy.cc:102
Bitfield< 0 > p
const char data[]

Generated on Fri Feb 28 2020 16:27:02 for gem5 by doxygen 1.8.13