gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
52 namespace gem5
53 {
54 
55 namespace
56 {
57 
58 class 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 
83 class 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 
116 DefaultRequestPort defaultRequestPort;
117 DefaultResponsePort defaultResponsePort;
118 
119 } // anonymous namespace
120 
124 [[deprecated]]
125 RequestPort::RequestPort(const std::string& name,
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  */
138 RequestPort::RequestPort(const std::string& name, PortID _id) :
139  Port(name, _id), _responsePort(&defaultResponsePort),
140  owner{*reinterpret_cast<SimObject*>(1)}
141 {
142 }
143 
145 {
146 }
147 
148 void
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 
161 void
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 
173 {
174  return _responsePort->getAddrRanges();
175 }
176 
177 void
179 {
180  auto req = std::make_shared<Request>(
181  a, 1, 0, Request::funcRequestorId);
182 
183  Packet pkt(req, MemCmd::PrintReq);
184  Packet::PrintReqState prs(std::cerr);
185  pkt.senderState = &prs;
186 
187  sendFunctional(&pkt);
188 }
189 
190 void
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());
201 }
202 
203 void
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]]
218 ResponsePort::ResponsePort(const std::string& name,
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  */
235 ResponsePort::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 
244 {
245 }
246 
247 void
249 {
250  _requestPort = &defaultRequestPort;
251  Port::unbind();
252 }
253 
254 void
256 {
257  _requestPort = &request_port;
258  Port::bind(request_port);
259 }
260 
261 Tick
263 {
264  if (!defaultBackdoorWarned) {
266  "Port %s doesn't support requesting a back door.", name());
267  defaultBackdoorWarned = true;
268  }
269  return recvAtomic(pkt);
270 }
271 
272 void
274  MemBackdoorPtr &backdoor)
275 {
276  if (!defaultBackdoorWarned) {
278  "Port %s doesn't support requesting a back door.", name());
279  defaultBackdoorWarned = true;
280  }
281 }
282 
283 } // namespace gem5
gem5::PortID
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:245
gem5::Request::funcRequestorId
@ funcRequestorId
This requestor id is used for functional requests that don't come from a particular device.
Definition: request.hh:279
gem5::RequestPort::addTrace
void addTrace(PacketPtr pkt) const
Definition: port.cc:191
gem5::RequestPort::unbind
void unbind() override
Unbind this request port and the associated response port.
Definition: port.cc:162
gem5::Port::name
const std::string name() const
Return port name (for DPRINTF).
Definition: port.hh:111
gem5::RequestPort::bind
void bind(Port &peer) override
Bind this request port to a response port.
Definition: port.cc:149
gem5::ResponsePort::_requestPort
RequestPort * _requestPort
Definition: port.hh:337
gem5::AddrRangeList
std::list< AddrRange > AddrRangeList
Convenience typedef for a collection of address ranges.
Definition: addr_range.hh:57
gem5::RequestPort::RequestPort
RequestPort(const std::string &name, SimObject *_owner, PortID id=InvalidPortID)
Request port.
Definition: port.cc:125
gem5::MemBackdoorPtr
MemBackdoor * MemBackdoorPtr
Definition: backdoor.hh:127
gem5::ArmISA::a
Bitfield< 8 > a
Definition: misc_types.hh:66
gem5::ResponsePort::responderUnbind
void responderUnbind()
Called by the request port to unbind.
Definition: port.cc:248
gem5::Port::bind
virtual void bind(Port &peer)
Attach to a peer port.
Definition: port.hh:118
gem5::RequestPort
A RequestPort is a specialisation of a Port, which implements the default protocol for the three diff...
Definition: port.hh:118
gem5::PacketPtr
Packet * PacketPtr
Definition: thread_context.hh:70
gem5::Extensible::setExtension
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...
Definition: extensible.hh:142
gem5::RequestPort::~RequestPort
virtual ~RequestPort()
Definition: port.cc:144
gem5::RequestPort::sendFunctional
void sendFunctional(PacketPtr pkt) const
Send a functional request packet, where the data is instantly updated everywhere in the memory system...
Definition: port.hh:563
gem5::ResponsePort::responderBind
void responderBind(RequestPort &request_port)
Called by the request port to bind.
Definition: port.cc:255
sim_object.hh
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:210
gem5::ResponsePort::~ResponsePort
virtual ~ResponsePort()
Definition: port.cc:243
gem5::Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
gem5::Tick
uint64_t Tick
Tick count type.
Definition: types.hh:58
port.hh
gem5::AtomicResponseProtocol::recvAtomic
virtual Tick recvAtomic(PacketPtr pkt)=0
Receive an atomic request packet from the peer.
gem5::Port::isConnected
bool isConnected() const
Is this port currently connected to a peer?
Definition: port.hh:133
gem5::RequestPort::getAddrRanges
AddrRangeList getAddrRanges() const
Get the address ranges of the connected responder port.
Definition: port.cc:172
gem5::SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:146
gem5::ArmISA::ext
Bitfield< 12 > ext
Definition: misc_types.hh:485
gem5::ResponsePort::recvMemBackdoorReq
void recvMemBackdoorReq(const MemBackdoorReq &req, MemBackdoorPtr &backdoor) override
Receive a request for a back door to a range of memory.
Definition: port.cc:273
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::TracingExtension
TracingExtension is an Extension of the Packet for recording the trace of the Packet.
Definition: port.hh:76
gem5::Packet::senderState
SenderState * senderState
This packet's sender state.
Definition: packet.hh:545
name
const std::string & name()
Definition: trace.cc:48
gem5::MemBackdoor
Definition: backdoor.hh:41
gem5::ResponsePort::ResponsePort
ResponsePort(const std::string &name, SimObject *_owner, PortID id=InvalidPortID)
Response port.
Definition: port.cc:218
gem5::Port::unbind
virtual void unbind()
Dettach from a peer port.
Definition: port.hh:126
gem5::ResponsePort::getAddrRanges
virtual AddrRangeList getAddrRanges() const =0
Get a list of the non-overlapping address ranges the owner is responsible for.
gem5::ResponsePort
A ResponsePort is a specialization of a port.
Definition: port.hh:331
panic_if
#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
gem5::Port
Ports are used to interface objects to each other.
Definition: port.hh:61
gem5::Extensible::getExtension
std::shared_ptr< T > getExtension()
Get the extension pointer by linear search with the extensionID.
Definition: extensible.hh:182
gem5::RequestPort::removeTrace
void removeTrace(PacketPtr pkt) const
Definition: port.cc:204
gem5::RequestPort::_responsePort
ResponsePort * _responsePort
Definition: port.hh:124
gem5::ResponsePort::defaultBackdoorWarned
bool defaultBackdoorWarned
Definition: port.hh:339
gem5::ArmISA::id
Bitfield< 33 > id
Definition: misc_types.hh:305
trace.hh
gem5::MemCmd::PrintReq
@ PrintReq
Definition: packet.hh:142
std::list< AddrRange >
gem5::ResponsePort::recvAtomicBackdoor
Tick recvAtomicBackdoor(PacketPtr pkt, MemBackdoorPtr &backdoor) override
Default implementations.
Definition: port.cc:262
fatal_if
#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
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::MemBackdoorReq
Definition: backdoor.hh:129
gem5::RequestPort::printAddr
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
gem5::Packet::PrintReqState
Object used to maintain state of a PrintReq.
Definition: packet.hh:479

Generated on Sun Jul 30 2023 01:56:58 for gem5 by doxygen 1.8.17