gem5 [DEVELOP-FOR-25.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
78
79class SysBridge : public SimObject
80{
81 private:
84
92
94 {
95 protected:
97
98 // Replace the requestor ID in pkt, and return any scratch data we'll
99 // need going back the other way.
102 {
103 RequestorID orig = pkt->requestorId();
104 pkt->req->requestorId(id);
105 return orig;
106 }
107
108 // Restore pkt to use its original requestor ID.
109 static void
111 {
112 pkt->req->requestorId(orig);
113 }
114
116 };
117
119 {
120 private:
122
123 public:
124 SysBridgeTargetPort(const std::string &_name,
125 SysBridgeSourcePort *source_port, RequestorID _id) :
127 sourcePort(source_port)
128 {
129 DPRINTF(SysBridge, "Target side requestor ID = %s.\n", _id);
130 }
131
132 private:
133 void
135 {
136 sourcePort->sendRangeChange();
137 }
138
139 Tick
141 {
142 DPRINTF(SysBridge, "recvAtomicSnoop incoming ID %d.\n",
143 pkt->requestorId());
144 auto data = replaceReqID(pkt);
145 DPRINTF(SysBridge, "recvAtomicSnoop outgoing ID %d.\n",
146 pkt->requestorId());
147 Tick tick = sourcePort->sendAtomicSnoop(pkt);
148 restoreReqID(pkt, data);
149 DPRINTF(SysBridge, "recvAtomicSnoop restored ID %d.\n",
150 pkt->requestorId());
151 return tick;
152 }
153
154 bool
156 {
157 auto *state = dynamic_cast<SysBridgeSenderState *>(
158 pkt->popSenderState());
159 DPRINTF(SysBridge, "recvTimingResp incoming ID %d.\n",
160 pkt->requestorId());
161 restoreReqID(pkt, state->origId);
162 DPRINTF(SysBridge, "recvTimingResp restored ID %d.\n",
163 pkt->requestorId());
164 if (!sourcePort->sendTimingResp(pkt)) {
165 replaceReqID(pkt);
166 DPRINTF(SysBridge, "recvTimingResp un-restored ID %d.\n",
167 pkt->requestorId());
168 pkt->pushSenderState(state);
169 return false;
170 } else {
171 delete state;
172 return true;
173 }
174 }
175
176 void
178 {
179 DPRINTF(SysBridge, "recvTimingSnoopReq incoming ID %d.\n",
180 pkt->requestorId());
181 auto *state = new SysBridgeSenderState(replaceReqID(pkt));
182 pkt->pushSenderState(state);
183 DPRINTF(SysBridge, "recvTimingSnoopReq outgoing ID %d.\n",
184 pkt->requestorId());
185 sourcePort->sendTimingSnoopReq(pkt);
186 }
187
188 void recvReqRetry() override { sourcePort->sendRetryReq(); }
189 void
191 {
192 sourcePort->sendRetrySnoopResp();
193 }
194
195 void
197 {
198 DPRINTF(SysBridge, "recvFunctionalSnoop incoming ID %d.\n",
199 pkt->requestorId());
200 RequestorID orig_id = replaceReqID(pkt);
201 DPRINTF(SysBridge, "recvFunctionalSnoop outgoing ID %d.\n",
202 pkt->requestorId());
203 sourcePort->sendFunctionalSnoop(pkt);
204 restoreReqID(pkt, orig_id);
205 DPRINTF(SysBridge, "recvFunctionalSnoop restored ID %d.\n",
206 pkt->requestorId());
207 }
208 };
209
211 {
212 private:
214
215 public:
216 SysBridgeSourcePort(const std::string &_name,
217 SysBridgeTargetPort *target_port, RequestorID _id) :
219 targetPort(target_port)
220 {
221 DPRINTF(SysBridge, "Source side requestor ID = %s.\n", _id);
222 }
223
224 private:
225 bool
227 {
228 DPRINTF(SysBridge, "recvTimingReq incoming ID %d.\n",
229 pkt->requestorId());
230 auto *state = new SysBridgeSenderState(replaceReqID(pkt));
231 pkt->pushSenderState(state);
232 DPRINTF(SysBridge, "recvTimingReq outgoing ID %d.\n",
233 pkt->requestorId());
234 if (!targetPort->sendTimingReq(pkt)) {
235 restoreReqID(pkt, state->origId);
236 DPRINTF(SysBridge, "recvTimingReq restored ID %d.\n",
237 pkt->requestorId());
238 pkt->popSenderState();
239 delete state;
240 return false;
241 } else {
242 return true;
243 }
244 }
245
246 bool
247 tryTiming(PacketPtr pkt) override
248 {
249 // Since tryTiming shouldn't actually send the packet, we should
250 // be able to clean up inline like we would for atomic methods.
251 // This may not actually be necessary at all, but it's a little
252 // safer.
253 DPRINTF(SysBridge, "tryTiming incoming ID %d.\n",
254 pkt->requestorId());
255 auto data = replaceReqID(pkt);
256 DPRINTF(SysBridge, "tryTiming outgoing ID %d.\n",
257 pkt->requestorId());
258 bool ret = targetPort->tryTiming(pkt);
259 restoreReqID(pkt, data);
260 DPRINTF(SysBridge, "tryTiming restored ID %d.\n",
261 pkt->requestorId());
262 return ret;
263 }
264
265 bool
267 {
268 auto *state = dynamic_cast<SysBridgeSenderState *>(
269 pkt->popSenderState());
270 DPRINTF(SysBridge, "recvTimingSnoopResp incoming ID %d.\n",
271 pkt->requestorId());
272 restoreReqID(pkt, state->origId);
273 DPRINTF(SysBridge, "recvTimingSnoopResp restored ID %d.\n",
274 pkt->requestorId());
275 return targetPort->sendTimingSnoopResp(pkt);
276 }
277
278 void recvRespRetry() override { targetPort->sendRetryResp(); }
279
280 Tick
281 recvAtomic(PacketPtr pkt) override
282 {
283 DPRINTF(SysBridge, "recvAtomic incoming ID %d.\n",
284 pkt->requestorId());
285 auto data = replaceReqID(pkt);
286 DPRINTF(SysBridge, "recvAtomic outgoing ID %d.\n",
287 pkt->requestorId());
288 Tick tick = targetPort->sendAtomic(pkt);
289 restoreReqID(pkt, data);
290 DPRINTF(SysBridge, "recvAtomic restored ID %d.\n",
291 pkt->requestorId());
292 return tick;
293 }
294
295 Tick
297 {
298 DPRINTF(SysBridge, "recvAtomicBackdoor incoming ID %d.\n",
299 pkt->requestorId());
300 auto data = replaceReqID(pkt);
301 DPRINTF(SysBridge, "recvAtomicBackdoor outgoing ID %d.\n",
302 pkt->requestorId());
303 Tick tick = targetPort->sendAtomicBackdoor(pkt, backdoor);
304 restoreReqID(pkt, data);
305 DPRINTF(SysBridge, "recvAtomicBackdoor restored ID %d.\n",
306 pkt->requestorId());
307 return tick;
308 }
309
310 void
312 {
313 DPRINTF(SysBridge, "recvFunctional incoming ID %d.\n",
314 pkt->requestorId());
315 auto data = replaceReqID(pkt);
316 DPRINTF(SysBridge, "recvFunctional outgoing ID %d.\n",
317 pkt->requestorId());
318 targetPort->sendFunctional(pkt);
319 restoreReqID(pkt, data);
320 DPRINTF(SysBridge, "recvFunctional restored ID %d.\n",
321 pkt->requestorId());
322 }
323
324 void
326 MemBackdoorPtr &backdoor) override
327 {
328 targetPort->sendMemBackdoorReq(req, backdoor);
329 }
330
332 getAddrRanges() const override
333 {
334 return targetPort->getAddrRanges();
335 }
336 };
337
340
341 public:
342 Port &getPort(const std::string &if_name,
343 PortID idx=InvalidPortID) override;
344
345 SysBridge(const SysBridgeParams &p);
346};
347
348} // namespace gem5
349
350#endif //__MEM_SYS_BRIDGE_HH__
#define DPRINTF(x,...)
Definition trace.hh:209
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
const char data[]
const std::string _name
Definition named.hh:54
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
Ports are used to interface objects to each other.
Definition port.hh:62
RequestPort(const std::string &name, SimObject *_owner, PortID id=InvalidPortID)
Request port.
Definition port.cc:125
ResponsePort(const std::string &name, SimObject *_owner, PortID id=InvalidPortID)
Response port.
Definition port.cc:218
RequestorID replaceReqID(PacketPtr pkt)
BridgingPort(RequestorID _id)
static void restoreReqID(PacketPtr pkt, RequestorID orig)
SysBridgeSenderState(const RequestorID id)
Definition sys_bridge.hh:88
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.
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
Definition sys_bridge.cc:43
SysBridgeTargetPort targetPort
SysBridge(const SysBridgeParams &p)
Definition sys_bridge.cc:35
SysBridgeSourcePort sourcePort
std::list< AddrRange > AddrRangeList
Convenience typedef for a collection of address ranges.
Definition addr_range.hh:64
SimObject(const Params &p)
Definition sim_object.cc:58
Port Object Declaration.
Bitfield< 33 > id
Bitfield< 0 > p
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
const PortID InvalidPortID
Definition types.hh:246
MemBackdoor * MemBackdoorPtr
Definition backdoor.hh:127
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
Packet * PacketPtr
A virtual base opaque structure used to hold state associated with the packet (e.g....
Definition packet.hh:469

Generated on Mon May 26 2025 09:19:13 for gem5 by doxygen 1.13.2