gem5 v23.0.0.1
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/ResponsePort.hh"
49#include "sim/sim_object.hh"
50
51namespace gem5
52{
53
54namespace
55{
56
57class DefaultRequestPort : public RequestPort
58{
59 protected:
60 [[noreturn]] void
61 blowUp() const
62 {
63 throw UnboundPortException();
64 }
65
66 public:
67 DefaultRequestPort() : RequestPort("default_request_port") {}
68
69 // Atomic protocol.
70 Tick recvAtomicSnoop(PacketPtr) override { blowUp(); }
71
72 // Timing protocol.
73 bool recvTimingResp(PacketPtr) override { blowUp(); }
74 void recvTimingSnoopReq(PacketPtr) override { blowUp(); }
75 void recvReqRetry() override { blowUp(); }
76 void recvRetrySnoopResp() override { blowUp(); }
77
78 // Functional protocol.
79 void recvFunctionalSnoop(PacketPtr) override { blowUp(); }
80};
81
82class DefaultResponsePort : public ResponsePort
83{
84 protected:
85 [[noreturn]] void
86 blowUp() const
87 {
88 throw UnboundPortException();
89 }
90
91 public:
92 DefaultResponsePort() : ResponsePort("default_response_port") {}
93
94 // Atomic protocol.
95 Tick recvAtomic(PacketPtr) override { blowUp(); }
96
97 // Timing protocol.
98 bool recvTimingReq(PacketPtr) override { blowUp(); }
99 bool tryTiming(PacketPtr) override { blowUp(); }
100 bool recvTimingSnoopResp(PacketPtr) override { blowUp(); }
101 void recvRespRetry() override { blowUp(); }
102
103 // Functional protocol.
104 void recvFunctional(PacketPtr) override { blowUp(); }
105 void
106 recvMemBackdoorReq(const MemBackdoorReq &, MemBackdoorPtr &) override
107 {
108 blowUp();
109 }
110
111 // General.
112 AddrRangeList getAddrRanges() const override { return AddrRangeList(); }
113};
114
115DefaultRequestPort defaultRequestPort;
116DefaultResponsePort defaultResponsePort;
117
118} // anonymous namespace
119
123[[deprecated]]
125 SimObject* _owner,
126 PortID _id):
127 Port(name, _id), _responsePort(&defaultResponsePort), owner{*_owner}
128{
129}
130
131/*** FIXME:
132 * The owner reference member is going through a deprecation path. In the
133 * meantime, it must be initialized but no valid reference is available here.
134 * Using 1 instead of nullptr prevents warning upon dereference. It should be
135 * OK until definitive removal of owner.
136 */
137RequestPort::RequestPort(const std::string& name, PortID _id) :
138 Port(name, _id), _responsePort(&defaultResponsePort),
139 owner{*reinterpret_cast<SimObject*>(1)}
140{
141}
142
144{
145}
146
147void
149{
150 auto *response_port = dynamic_cast<ResponsePort *>(&peer);
151 fatal_if(!response_port, "Can't bind port %s to non-response port %s.",
152 name(), peer.name());
153 // request port keeps track of the response port
154 _responsePort = response_port;
155 Port::bind(peer);
156 // response port also keeps track of request port
158}
159
160void
162{
163 panic_if(!isConnected(), "Can't unbind request port %s which is "
164 "not bound.", name());
166 _responsePort = &defaultResponsePort;
167 Port::unbind();
168}
169
172{
174}
175
176void
178{
179 auto req = std::make_shared<Request>(
181
182 Packet pkt(req, MemCmd::PrintReq);
183 Packet::PrintReqState prs(std::cerr);
184 pkt.senderState = &prs;
185
186 sendFunctional(&pkt);
187}
188
193[[deprecated]]
195 SimObject* _owner,
196 PortID _id):
197 Port(name, _id),
198 _requestPort(&defaultRequestPort),
199 defaultBackdoorWarned(false),
200 owner{*_owner}
201{
202}
203
204
205/*** FIXME:
206 * The owner reference member is going through a deprecation path. In the
207 * meantime, it must be initialized but no valid reference is available here.
208 * Using 1 instead of nullptr prevents warning upon dereference. It should be
209 * OK until definitive removal of owner.
210 */
211ResponsePort::ResponsePort(const std::string& name, PortID id) :
212 Port(name, id),
213 _requestPort(&defaultRequestPort),
214 defaultBackdoorWarned(false),
215 owner{*reinterpret_cast<SimObject*>(1)}
216{
217}
218
220{
221}
222
223void
225{
226 _requestPort = &defaultRequestPort;
227 Port::unbind();
228}
229
230void
232{
233 _requestPort = &request_port;
234 Port::bind(request_port);
235}
236
237Tick
239{
242 "Port %s doesn't support requesting a back door.", name());
244 }
245 return recvAtomic(pkt);
246}
247
248void
250 MemBackdoorPtr &backdoor)
251{
254 "Port %s doesn't support requesting a back door.", name());
256 }
257}
258
259} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:210
virtual Tick recvAtomic(PacketPtr pkt)=0
Receive an atomic request packet from the peer.
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
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:79
virtual ~RequestPort()
Definition port.cc:143
void unbind() override
Unbind this request port and the associated response port.
Definition port.cc:161
ResponsePort * _responsePort
Definition port.hh:83
AddrRangeList getAddrRanges() const
Get the address ranges of the connected responder port.
Definition port.cc:171
void bind(Port &peer) override
Bind this request port to a response port.
Definition port.cc:148
RequestPort(const std::string &name, SimObject *_owner, PortID id=InvalidPortID)
Request port.
Definition port.cc:124
void sendFunctional(PacketPtr pkt) const
Send a functional request packet, where the data is instantly updated everywhere in the memory system...
Definition port.hh:508
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:177
@ 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:288
Tick recvAtomicBackdoor(PacketPtr pkt, MemBackdoorPtr &backdoor) override
Default implementations.
Definition port.cc:238
ResponsePort(const std::string &name, SimObject *_owner, PortID id=InvalidPortID)
Response port.
Definition port.cc:194
void responderUnbind()
Called by the request port to unbind.
Definition port.cc:224
bool defaultBackdoorWarned
Definition port.hh:294
void responderBind(RequestPort &request_port)
Called by the request port to bind.
Definition port.cc:231
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:249
virtual ~ResponsePort()
Definition port.cc:219
RequestPort * _requestPort
Definition port.hh:292
Abstract superclass for simulation objects.
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
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Packet * PacketPtr
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
const std::string & name()
Definition trace.cc:48

Generated on Mon Jul 10 2023 15:32:05 for gem5 by doxygen 1.9.7