gem5 v24.0.0.0
Loading...
Searching...
No Matches
port.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012,2015,2017 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 * Copyright (c) 2002-2005 The Regents of The University of Michigan
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 */
40
45#include "mem/port.hh"
46
47#include "base/trace.hh"
48#include "debug/PortTrace.hh"
49#include "debug/ResponsePort.hh"
50#include "sim/sim_object.hh"
51
52namespace gem5
53{
54
55namespace
56{
57
58class DefaultRequestPort : public RequestPort
59{
60 protected:
61 [[noreturn]] void
62 blowUp() const
63 {
64 throw UnboundPortException();
65 }
66
67 public:
68 DefaultRequestPort() : RequestPort("default_request_port") {}
69
70 // Atomic protocol.
71 Tick recvAtomicSnoop(PacketPtr) override { blowUp(); }
72
73 // Timing protocol.
74 bool recvTimingResp(PacketPtr) override { blowUp(); }
75 void recvTimingSnoopReq(PacketPtr) override { blowUp(); }
76 void recvReqRetry() override { blowUp(); }
77 void recvRetrySnoopResp() override { blowUp(); }
78
79 // Functional protocol.
80 void recvFunctionalSnoop(PacketPtr) override { blowUp(); }
81};
82
83class DefaultResponsePort : public ResponsePort
84{
85 protected:
86 [[noreturn]] void
87 blowUp() const
88 {
89 throw UnboundPortException();
90 }
91
92 public:
93 DefaultResponsePort() : ResponsePort("default_response_port") {}
94
95 // Atomic protocol.
96 Tick recvAtomic(PacketPtr) override { blowUp(); }
97
98 // Timing protocol.
99 bool recvTimingReq(PacketPtr) override { blowUp(); }
100 bool tryTiming(PacketPtr) override { blowUp(); }
101 bool recvTimingSnoopResp(PacketPtr) override { blowUp(); }
102 void recvRespRetry() override { blowUp(); }
103
104 // Functional protocol.
105 void recvFunctional(PacketPtr) override { blowUp(); }
106 void
107 recvMemBackdoorReq(const MemBackdoorReq &, MemBackdoorPtr &) override
108 {
109 blowUp();
110 }
111
112 // General.
113 AddrRangeList getAddrRanges() const override { return AddrRangeList(); }
114};
115
116DefaultRequestPort defaultRequestPort;
117DefaultResponsePort defaultResponsePort;
118
119} // anonymous namespace
120
124[[deprecated]]
126 SimObject* _owner,
127 PortID _id):
128 Port(name, _id), _responsePort(&defaultResponsePort), owner{*_owner}
129{
130}
131
132/*** FIXME:
133 * The owner reference member is going through a deprecation path. In the
134 * meantime, it must be initialized but no valid reference is available here.
135 * Using 1 instead of nullptr prevents warning upon dereference. It should be
136 * OK until definitive removal of owner.
137 */
138RequestPort::RequestPort(const std::string& name, PortID _id) :
139 Port(name, _id), _responsePort(&defaultResponsePort),
140 owner{*reinterpret_cast<SimObject*>(1)}
141{
142}
143
147
148void
150{
151 auto *response_port = dynamic_cast<ResponsePort *>(&peer);
152 fatal_if(!response_port, "Can't bind port %s to non-response port %s.",
153 name(), peer.name());
154 // request port keeps track of the response port
155 _responsePort = response_port;
156 Port::bind(peer);
157 // response port also keeps track of request port
159}
160
161void
163{
164 panic_if(!isConnected(), "Can't unbind request port %s which is "
165 "not bound.", name());
167 _responsePort = &defaultResponsePort;
168 Port::unbind();
169}
170
176
177void
179{
180 auto req = std::make_shared<Request>(
182
183 Packet pkt(req, MemCmd::PrintReq);
184 Packet::PrintReqState prs(std::cerr);
185 pkt.senderState = &prs;
186
187 sendFunctional(&pkt);
188}
189
190void
192{
193 if (!gem5::debug::PortTrace || !pkt)
194 return;
195 auto ext = pkt->getExtension<TracingExtension>();
196 if (!ext) {
197 ext = std::make_shared<TracingExtension>();
198 pkt->setExtension(ext);
199 }
200 ext->add(name(), _responsePort->name(), pkt->getAddr());
201}
202
203void
205{
206 if (!gem5::debug::PortTrace || !pkt)
207 return;
208 auto ext = pkt->getExtension<TracingExtension>();
209 panic_if(!ext, "There is no TracingExtension in the packet.");
210 ext->remove();
211}
212
217[[deprecated]]
219 SimObject* _owner,
220 PortID _id):
221 Port(name, _id),
222 _requestPort(&defaultRequestPort),
223 defaultBackdoorWarned(false),
224 owner{*_owner}
225{
226}
227
228
229/*** FIXME:
230 * The owner reference member is going through a deprecation path. In the
231 * meantime, it must be initialized but no valid reference is available here.
232 * Using 1 instead of nullptr prevents warning upon dereference. It should be
233 * OK until definitive removal of owner.
234 */
235ResponsePort::ResponsePort(const std::string& name, PortID id) :
236 Port(name, id),
237 _requestPort(&defaultRequestPort),
238 defaultBackdoorWarned(false),
239 owner{*reinterpret_cast<SimObject*>(1)}
240{
241}
242
246
247void
249{
250 _requestPort = &defaultRequestPort;
251 Port::unbind();
252}
253
254void
256{
257 _requestPort = &request_port;
258 Port::bind(request_port);
259}
260
261Tick
263{
266 "Port %s doesn't support requesting a back door.", name());
268 }
269 return recvAtomic(pkt);
270}
271
272void
274 MemBackdoorPtr &backdoor)
275{
278 "Port %s doesn't support requesting a back door.", name());
280 }
281}
282
283} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:210
virtual Tick recvAtomic(PacketPtr pkt)=0
Receive an atomic request packet from the peer.
void setExtension(std::shared_ptr< T > ext)
Set a new extension to the packet and replace the old one, if there already exists the same type of e...
std::shared_ptr< T > getExtension()
Get the extension pointer by linear search with the extensionID.
Object used to maintain state of a PrintReq.
Definition packet.hh:480
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
Addr getAddr() const
Definition packet.hh:807
SenderState * senderState
This packet's sender state.
Definition packet.hh:545
Ports are used to interface objects to each other.
Definition port.hh:62
bool isConnected() const
Is this port currently connected to a peer?
Definition port.hh:133
const std::string name() const
Return port name (for DPRINTF).
Definition port.hh:111
virtual void unbind()
Dettach from a peer port.
Definition port.hh:126
virtual void bind(Port &peer)
Attach to a peer port.
Definition port.hh:118
A RequestPort is a specialisation of a Port, which implements the default protocol for the three diff...
Definition port.hh:136
virtual ~RequestPort()
Definition port.cc:144
void unbind() override
Unbind this request port and the associated response port.
Definition port.cc:162
ResponsePort * _responsePort
Definition port.hh:140
AddrRangeList getAddrRanges() const
Get the address ranges of the connected responder port.
Definition port.cc:172
void bind(Port &peer) override
Bind this request port to a response port.
Definition port.cc:149
void addTrace(PacketPtr pkt) const
Definition port.cc:191
void removeTrace(PacketPtr pkt) const
Definition port.cc:204
RequestPort(const std::string &name, SimObject *_owner, PortID id=InvalidPortID)
Request port.
Definition port.cc:125
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
void printAddr(Addr a)
Inject a PrintReq for the given address to print the state of that address throughout the memory syst...
Definition port.cc:178
@ funcRequestorId
This requestor id is used for functional requests that don't come from a particular device.
Definition request.hh:279
A ResponsePort is a specialization of a port.
Definition port.hh:349
Tick recvAtomicBackdoor(PacketPtr pkt, MemBackdoorPtr &backdoor) override
Default implementations.
Definition port.cc:262
ResponsePort(const std::string &name, SimObject *_owner, PortID id=InvalidPortID)
Response port.
Definition port.cc:218
void responderUnbind()
Called by the request port to unbind.
Definition port.cc:248
bool defaultBackdoorWarned
Definition port.hh:355
void responderBind(RequestPort &request_port)
Called by the request port to bind.
Definition port.cc:255
virtual AddrRangeList getAddrRanges() const =0
Get a list of the non-overlapping address ranges the owner is responsible for.
void recvMemBackdoorReq(const MemBackdoorReq &req, MemBackdoorPtr &backdoor) override
Receive a request for a back door to a range of memory.
Definition port.cc:273
virtual ~ResponsePort()
Definition port.cc:243
RequestPort * _requestPort
Definition port.hh:353
Abstract superclass for simulation objects.
TracingExtension is an Extension of the Packet for recording the trace of the Packet.
Definition port.hh:78
std::list< AddrRange > AddrRangeList
Convenience typedef for a collection of address ranges.
Definition addr_range.hh:64
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition logging.hh:236
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition logging.hh:214
Port Object Declaration.
Bitfield< 33 > id
Bitfield< 8 > a
Definition misc_types.hh:66
Bitfield< 12 > ext
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
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
Packet * PacketPtr
const std::string & name()
Definition trace.cc:48

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