gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
66namespace gem5
67{
68
69class RequestPort;
70class ThreadContext;
71
87{
88 public:
89 typedef std::function<void(PacketPtr pkt)> SendFunctionalFunc;
90
91 private:
93
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, Addr 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, Addr cache_line_size);
112 PortProxy(const RequestPort &port, Addr cache_line_size);
113
114 virtual ~PortProxy() {}
115
116
123 void *p, uint64_t size) const;
124
129 const void *p, uint64_t size) const;
130
135 uint8_t v, uint64_t size) const;
136
137
138
145 virtual bool
146 tryReadBlob(Addr addr, void *p, uint64_t size) const
147 {
148 readBlobPhys(addr, 0, p, size);
149 return true;
150 }
151
156 virtual bool
157 tryWriteBlob(Addr addr, const void *p, uint64_t size) const
158 {
159 writeBlobPhys(addr, 0, p, size);
160 return true;
161 }
162
167 virtual bool
168 tryMemsetBlob(Addr addr, uint8_t val, uint64_t size) const
169 {
170 memsetBlobPhys(addr, 0, val, size);
171 return true;
172 }
173
174
175
181 void
182 readBlob(Addr addr, void *p, uint64_t 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, uint64_t 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, uint64_t 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
285template <typename T>
286T
287PortProxy::read(Addr address) const
288{
289 T data;
290 readBlob(address, &data, sizeof(T));
291 return data;
292}
293
294template <typename T>
295void
296PortProxy::write(Addr address, const T &data) const
297{
298 writeBlob(address, &data, sizeof(T));
299}
300
301template <typename T>
302T
303PortProxy::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
310template <typename T>
311void
312PortProxy::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:295
This object is a proxy for a port or other object which implements the functional response protocol,...
Definition port_proxy.hh:87
void memsetBlobPhys(Addr addr, Request::Flags flags, uint8_t v, uint64_t size) const
Fill size bytes starting at physical addr with byte value val.
Definition port_proxy.cc:92
const Addr _cacheLineSize
Granularity of any transactions issued through this proxy.
Definition port_proxy.hh:95
void readBlob(Addr addr, void *p, uint64_t size) const
Higher level interfaces based on the above.
T read(Addr address) const
Read sizeof(T) bytes from address and return as object T.
void readBlobPhys(Addr addr, Request::Flags flags, void *p, uint64_t size) const
Fixed functionality for use in base classes.
Definition port_proxy.cc:58
virtual bool tryMemsetBlob(Addr addr, uint8_t val, uint64_t size) const
Fill size bytes starting at addr with byte value val.
PortProxy(SendFunctionalFunc func, Addr cache_line_size)
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.
void writeBlob(Addr addr, const void *p, uint64_t size) const
Same as tryWriteBlob, but insists on success.
virtual ~PortProxy()
void write(Addr address, const T &data) const
Write object T to address.
virtual bool tryWriteBlob(Addr addr, const void *p, uint64_t size) const
Write size bytes from p to address.
void recvFunctionalSnoop(PacketPtr pkt) override
Receive a functional snoop request packet from the peer.
Definition port_proxy.hh:98
virtual bool tryReadBlob(Addr addr, void *p, uint64_t size) const
Methods to override in base classes.
void readString(std::string &str, Addr addr) const
Same as tryReadString, but insists on success.
void readString(char *str, Addr addr, size_t maxlen) const
Same as tryReadString, but insists on success.
void writeBlobPhys(Addr addr, Request::Flags flags, const void *p, uint64_t size) const
Write size bytes from p to physical address.
Definition port_proxy.cc:75
bool tryReadString(std::string &str, Addr addr) const
Reads the string at guest address addr into the std::string str.
void writeString(Addr addr, const char *str) const
Same as tryWriteString, but insists on success.
void memsetBlob(Addr addr, uint8_t v, uint64_t size) const
Same as tryMemsetBlob, but insists on success.
SendFunctionalFunc sendFunctional
Definition port_proxy.hh:92
A RequestPort is a specialisation of a Port, which implements the default protocol for the three diff...
Definition port.hh:136
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:188
#define fatal(...)
This implements a cprintf based fatal() function.
Definition logging.hh:200
uint8_t flags
Definition helpers.cc:87
Bitfield< 28 > v
Definition misc_types.hh:54
Bitfield< 0 > p
Bitfield< 63 > val
Definition misc.hh:804
Bitfield< 3 > addr
Definition types.hh:84
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
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 Tue Jun 18 2024 16:24:05 for gem5 by doxygen 1.11.0