gem5 v24.0.0.0
Loading...
Searching...
No Matches
sys_bridge.hh
Go to the documentation of this file.
1/*
2 * Copyright 2021 Google, Inc.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met: redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer;
8 * redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution;
11 * neither the name of the copyright holders nor the names of its
12 * contributors may be used to endorse or promote products derived from
13 * this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#ifndef __MEM_SYS_BRIDGE_HH__
29#define __MEM_SYS_BRIDGE_HH__
30
31#include "base/trace.hh"
32#include "base/types.hh"
33#include "debug/SysBridge.hh"
34#include "mem/port.hh"
35#include "params/SysBridge.hh"
36#include "sim/sim_object.hh"
37
38namespace gem5
39{
40
79class SysBridge : public SimObject
80{
81 private:
84
85 // A structure for whatever we need to keep when bridging a packet.
87 {
89 };
90
92 {
93 private:
95
96 public:
98
99 const PacketData &data() const { return pData; }
100 };
101
103 {
104 protected:
106
107 // Replace the requestor ID in pkt, and return any scratch data we'll
108 // need going back the other way.
110 // Restore pkt to use its original requestor ID.
111 static void
113 {
114 pkt->req = data.req;
115 }
116
117 static void
119 {
120 backup.req = pkt->req;
121 restoreReqID(pkt, data);
122 }
123
125 };
126
128 {
129 private:
131
132 public:
133 SysBridgeTargetPort(const std::string &_name,
134 SysBridgeSourcePort *source_port, RequestorID _id) :
136 sourcePort(source_port)
137 {
138 DPRINTF(SysBridge, "Target side requestor ID = %s.\n", _id);
139 }
140
141 private:
142 void
144 {
146 }
147
148 Tick
150 {
151 DPRINTF(SysBridge, "recvAtomicSnoop incoming ID %d.\n",
152 pkt->requestorId());
153 auto data = replaceReqID(pkt);
154 DPRINTF(SysBridge, "recvAtomicSnoop outgoing ID %d.\n",
155 pkt->requestorId());
156 Tick tick = sourcePort->sendAtomicSnoop(pkt);
157 restoreReqID(pkt, data);
158 DPRINTF(SysBridge, "recvAtomicSnoop restored ID %d.\n",
159 pkt->requestorId());
160 return tick;
161 }
162
163 bool
165 {
166 auto *state = dynamic_cast<SysBridgeSenderState *>(
167 pkt->popSenderState());
168 PacketData backup;
169 DPRINTF(SysBridge, "recvTimingResp incoming ID %d.\n",
170 pkt->requestorId());
171 restoreReqID(pkt, state->data(), backup);
172 DPRINTF(SysBridge, "recvTimingResp restored ID %d.\n",
173 pkt->requestorId());
174 if (!sourcePort->sendTimingResp(pkt)) {
175 restoreReqID(pkt, backup);
176 DPRINTF(SysBridge, "recvTimingResp un-restored ID %d.\n",
177 pkt->requestorId());
179 return false;
180 } else {
181 delete state;
182 return true;
183 }
184 }
185
186 void
188 {
189 DPRINTF(SysBridge, "recvTimingSnoopReq incoming ID %d.\n",
190 pkt->requestorId());
191 auto *state = new SysBridgeSenderState(replaceReqID(pkt));
193 DPRINTF(SysBridge, "recvTimingSnoopReq outgoing ID %d.\n",
194 pkt->requestorId());
196 }
197
198 void recvReqRetry() override { sourcePort->sendRetryReq(); }
199 void
201 {
203 }
204
205 void
207 {
208 DPRINTF(SysBridge, "recvFunctionalSnoop incoming ID %d.\n",
209 pkt->requestorId());
210 auto data = replaceReqID(pkt);
211 DPRINTF(SysBridge, "recvFunctionalSnoop outgoing ID %d.\n",
212 pkt->requestorId());
214 restoreReqID(pkt, data);
215 DPRINTF(SysBridge, "recvFunctionalSnoop restored ID %d.\n",
216 pkt->requestorId());
217 }
218 };
219
221 {
222 private:
224
225 public:
226 SysBridgeSourcePort(const std::string &_name,
227 SysBridgeTargetPort *target_port, RequestorID _id) :
229 targetPort(target_port)
230 {
231 DPRINTF(SysBridge, "Source side requestor ID = %s.\n", _id);
232 }
233
234 private:
235 bool
237 {
238 DPRINTF(SysBridge, "recvTimingReq incoming ID %d.\n",
239 pkt->requestorId());
240 auto *state = new SysBridgeSenderState(replaceReqID(pkt));
242 DPRINTF(SysBridge, "recvTimingReq outgoing ID %d.\n",
243 pkt->requestorId());
244 if (!targetPort->sendTimingReq(pkt)) {
245 restoreReqID(pkt, state->data());
246 DPRINTF(SysBridge, "recvTimingReq restored ID %d.\n",
247 pkt->requestorId());
248 pkt->popSenderState();
249 delete state;
250 return false;
251 } else {
252 return true;
253 }
254 }
255
256 bool
257 tryTiming(PacketPtr pkt) override
258 {
259 // Since tryTiming shouldn't actually send the packet, we should
260 // be able to clean up inline like we would for atomic methods.
261 // This may not actually be necessary at all, but it's a little
262 // safer.
263 DPRINTF(SysBridge, "tryTiming incoming ID %d.\n",
264 pkt->requestorId());
265 auto data = replaceReqID(pkt);
266 DPRINTF(SysBridge, "tryTiming outgoing ID %d.\n",
267 pkt->requestorId());
268 bool ret = targetPort->tryTiming(pkt);
269 restoreReqID(pkt, data);
270 DPRINTF(SysBridge, "tryTiming restored ID %d.\n",
271 pkt->requestorId());
272 return ret;
273 }
274
275 bool
277 {
278 auto *state = dynamic_cast<SysBridgeSenderState *>(
279 pkt->popSenderState());
280 DPRINTF(SysBridge, "recvTimingSnoopResp incoming ID %d.\n",
281 pkt->requestorId());
282 restoreReqID(pkt, state->data());
283 DPRINTF(SysBridge, "recvTimingSnoopResp restored ID %d.\n",
284 pkt->requestorId());
285 return targetPort->sendTimingSnoopResp(pkt);
286 }
287
288 void recvRespRetry() override { targetPort->sendRetryResp(); }
289
290 Tick
291 recvAtomic(PacketPtr pkt) override
292 {
293 DPRINTF(SysBridge, "recvAtomic incoming ID %d.\n",
294 pkt->requestorId());
295 auto data = replaceReqID(pkt);
296 DPRINTF(SysBridge, "recvAtomic outgoing ID %d.\n",
297 pkt->requestorId());
298 Tick tick = targetPort->sendAtomic(pkt);
299 restoreReqID(pkt, data);
300 DPRINTF(SysBridge, "recvAtomic restored ID %d.\n",
301 pkt->requestorId());
302 return tick;
303 }
304
305 Tick
307 {
308 DPRINTF(SysBridge, "recvAtomicBackdoor incoming ID %d.\n",
309 pkt->requestorId());
310 auto data = replaceReqID(pkt);
311 DPRINTF(SysBridge, "recvAtomicBackdoor outgoing ID %d.\n",
312 pkt->requestorId());
313 Tick tick = targetPort->sendAtomicBackdoor(pkt, backdoor);
314 restoreReqID(pkt, data);
315 DPRINTF(SysBridge, "recvAtomicBackdoor restored ID %d.\n",
316 pkt->requestorId());
317 return tick;
318 }
319
320 void
322 {
323 DPRINTF(SysBridge, "recvFunctional incoming ID %d.\n",
324 pkt->requestorId());
325 auto data = replaceReqID(pkt);
326 DPRINTF(SysBridge, "recvFunctional outgoing ID %d.\n",
327 pkt->requestorId());
329 restoreReqID(pkt, data);
330 DPRINTF(SysBridge, "recvFunctional restored ID %d.\n",
331 pkt->requestorId());
332 }
333
334 void
336 MemBackdoorPtr &backdoor) override
337 {
338 targetPort->sendMemBackdoorReq(req, backdoor);
339 }
340
342 getAddrRanges() const override
343 {
344 return targetPort->getAddrRanges();
345 }
346 };
347
350
351 public:
352 Port &getPort(const std::string &if_name,
353 PortID idx=InvalidPortID) override;
354
355 SysBridge(const SysBridgeParams &p);
356};
357
358} // namespace gem5
359
360#endif //__MEM_SYS_BRIDGE_HH__
#define DPRINTF(x,...)
Definition trace.hh:210
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
const char data[]
const std::string _name
Definition named.hh:41
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
RequestorID requestorId() const
Definition packet.hh:780
void pushSenderState(SenderState *sender_state)
Push a new sender state to the packet and make the current sender state the predecessor of the new on...
Definition packet.cc:334
SenderState * popSenderState()
Pop the top of the state stack and return a pointer to it.
Definition packet.cc:342
RequestPtr req
A pointer to the original request.
Definition packet.hh:377
PacketDataPtr data
A pointer to the data being transferred.
Definition packet.hh:387
Ports are used to interface objects to each other.
Definition port.hh:62
A RequestPort is a specialisation of a Port, which implements the default protocol for the three diff...
Definition port.hh:136
void sendMemBackdoorReq(const MemBackdoorReq &req, MemBackdoorPtr &backdoor)
Send a request for a back door to a range of memory.
Definition port.hh:591
virtual void sendRetryResp()
Send a retry to the response port that previously attempted a sendTimingResp to this request port and...
Definition port.hh:637
bool tryTiming(PacketPtr pkt) const
Check if the responder can handle a timing request.
Definition port.hh:617
Tick sendAtomic(PacketPtr pkt)
Send an atomic request packet, where the data is moved and the state is updated in zero time,...
Definition port.hh:552
AddrRangeList getAddrRanges() const
Get the address ranges of the connected responder port.
Definition port.cc:172
bool sendTimingReq(PacketPtr pkt)
Attempt to send a timing request to the responder port by calling its corresponding receive function.
Definition port.hh:603
bool sendTimingSnoopResp(PacketPtr pkt)
Attempt to send a timing snoop response packet to the response port by calling its corresponding rece...
Definition port.hh:627
void sendFunctional(PacketPtr pkt) const
Send a functional request packet, where the data is instantly updated everywhere in the memory system...
Definition port.hh:579
Tick sendAtomicBackdoor(PacketPtr pkt, MemBackdoorPtr &backdoor)
Send an atomic request packet like above, but also request a backdoor to the data being accessed.
Definition port.hh:565
A ResponsePort is a specialization of a port.
Definition port.hh:349
bool sendTimingResp(PacketPtr pkt)
Attempt to send a timing response to the request port by calling its corresponding receive function.
Definition port.hh:454
void sendFunctionalSnoop(PacketPtr pkt) const
Send a functional snoop request packet, where the data is instantly updated everywhere in the memory ...
Definition port.hh:430
void sendRetrySnoopResp()
Send a retry to the request port that previously attempted a sendTimingSnoopResp to this response por...
Definition port.hh:503
Tick sendAtomicSnoop(PacketPtr pkt)
Send an atomic snoop request packet, where the data is moved and the state is updated in zero time,...
Definition port.hh:410
void sendTimingSnoopReq(PacketPtr pkt)
Attempt to send a timing snoop request packet to the request port by calling its corresponding receiv...
Definition port.hh:475
void sendRangeChange() const
Called by the owner to send a range change.
Definition port.hh:380
void sendRetryReq()
Send a retry to the request port that previously attempted a sendTimingReq to this response port and ...
Definition port.hh:489
Abstract superclass for simulation objects.
BridgingPort(RequestorID _id)
PacketData replaceReqID(PacketPtr pkt)
Definition sys_bridge.cc:36
static void restoreReqID(PacketPtr pkt, const PacketData &data)
static void restoreReqID(PacketPtr pkt, const PacketData &data, PacketData &backup)
SysBridgeSenderState(const PacketData &data)
Definition sys_bridge.hh:97
const PacketData & data() const
Definition sys_bridge.hh:99
bool tryTiming(PacketPtr pkt) override
Availability request from the peer.
void recvMemBackdoorReq(const MemBackdoorReq &req, MemBackdoorPtr &backdoor) override
Receive a request for a back door to a range of memory.
void recvRespRetry() override
Called by the peer if sendTimingResp was called on this protocol (causing recvTimingResp to be called...
bool recvTimingReq(PacketPtr pkt) override
Receive a timing request from the peer.
SysBridgeSourcePort(const std::string &_name, SysBridgeTargetPort *target_port, RequestorID _id)
AddrRangeList getAddrRanges() const override
Get a list of the non-overlapping address ranges the owner is responsible for.
Tick recvAtomicBackdoor(PacketPtr pkt, MemBackdoorPtr &backdoor) override
Default implementations.
void recvFunctional(PacketPtr pkt) override
Receive a functional request packet from the peer.
bool recvTimingSnoopResp(PacketPtr pkt) override
Receive a timing snoop response from the peer.
Tick recvAtomic(PacketPtr pkt) override
Receive an atomic request packet from the peer.
Tick recvAtomicSnoop(PacketPtr pkt) override
Default implementations.
void recvReqRetry() override
Called by the peer if sendTimingReq was called on this peer (causing recvTimingReq to be called on th...
void recvRetrySnoopResp() override
Called by the peer if sendTimingSnoopResp was called on this protocol (causing recvTimingSnoopResp to...
void recvTimingSnoopReq(PacketPtr pkt) override
Receive a timing snoop request from the peer.
bool recvTimingResp(PacketPtr pkt) override
Receive a timing response from the peer.
SysBridgeTargetPort(const std::string &_name, SysBridgeSourcePort *source_port, RequestorID _id)
void recvFunctionalSnoop(PacketPtr pkt) override
Receive a functional snoop request packet from the peer.
void recvRangeChange() override
Called to receive an address range change from the peer response port.
Each System object in gem5 is responsible for a set of RequestorIDs which identify different sources ...
Definition sys_bridge.hh:80
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
Definition sys_bridge.cc:53
SysBridgeTargetPort targetPort
SysBridge(const SysBridgeParams &p)
Definition sys_bridge.cc:45
SysBridgeSourcePort sourcePort
atomic_var_t state
Definition helpers.cc:211
Port Object Declaration.
Bitfield< 0 > p
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
std::shared_ptr< Request > RequestPtr
Definition request.hh:94
const PortID InvalidPortID
Definition types.hh:246
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition types.hh:245
uint64_t Tick
Tick count type.
Definition types.hh:58
uint16_t RequestorID
Definition request.hh:95
A virtual base opaque structure used to hold state associated with the packet (e.g....
Definition packet.hh:469

Generated on Tue Jun 18 2024 16:24:05 for gem5 by doxygen 1.11.0