gem5  v22.1.0.0
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 
51 namespace gem5
52 {
53 
54 namespace
55 {
56 
57 class 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", nullptr) {}
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 
82 class 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", nullptr) {}
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 
106  // General.
107  AddrRangeList getAddrRanges() const override { return AddrRangeList(); }
108 };
109 
110 DefaultRequestPort defaultRequestPort;
111 DefaultResponsePort defaultResponsePort;
112 
113 } // anonymous namespace
114 
118 RequestPort::RequestPort(const std::string& name, SimObject* _owner,
119  PortID _id) : Port(name, _id), _responsePort(&defaultResponsePort),
120  owner(*_owner)
121 {
122 }
123 
125 {
126 }
127 
128 void
130 {
131  auto *response_port = dynamic_cast<ResponsePort *>(&peer);
132  fatal_if(!response_port, "Can't bind port %s to non-response port %s.",
133  name(), peer.name());
134  // request port keeps track of the response port
135  _responsePort = response_port;
136  Port::bind(peer);
137  // response port also keeps track of request port
139 }
140 
141 void
143 {
144  panic_if(!isConnected(), "Can't unbind request port %s which is "
145  "not bound.", name());
147  _responsePort = &defaultResponsePort;
148  Port::unbind();
149 }
150 
153 {
154  return _responsePort->getAddrRanges();
155 }
156 
157 void
159 {
160  auto req = std::make_shared<Request>(
161  a, 1, 0, Request::funcRequestorId);
162 
163  Packet pkt(req, MemCmd::PrintReq);
164  Packet::PrintReqState prs(std::cerr);
165  pkt.senderState = &prs;
166 
167  sendFunctional(&pkt);
168 }
169 
173 ResponsePort::ResponsePort(const std::string& name, SimObject* _owner,
174  PortID id) : Port(name, id), _requestPort(&defaultRequestPort),
175  defaultBackdoorWarned(false), owner(*_owner)
176 {
177 }
178 
180 {
181 }
182 
183 void
185 {
186  _requestPort = &defaultRequestPort;
187  Port::unbind();
188 }
189 
190 void
192 {
193  _requestPort = &request_port;
194  Port::bind(request_port);
195 }
196 
197 Tick
199 {
200  if (!defaultBackdoorWarned) {
202  "Port %s doesn't support requesting a back door.", name());
203  defaultBackdoorWarned = true;
204  }
205  return recvAtomic(pkt);
206 }
207 
208 } // namespace gem5
#define DPRINTF(x,...)
Definition: trace.hh:186
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:479
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
SenderState * senderState
This packet's sender state.
Definition: packet.hh:544
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:124
void unbind() override
Unbind this request port and the associated response port.
Definition: port.cc:142
ResponsePort * _responsePort
Definition: port.hh:83
AddrRangeList getAddrRanges() const
Get the address ranges of the connected responder port.
Definition: port.cc:152
void bind(Port &peer) override
Bind this request port to a response port.
Definition: port.cc:129
RequestPort(const std::string &name, SimObject *_owner, PortID id=InvalidPortID)
Request port.
Definition: port.cc:118
void sendFunctional(PacketPtr pkt) const
Send a functional request packet, where the data is instantly updated everywhere in the memory system...
Definition: port.hh:485
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:158
@ 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:270
Tick recvAtomicBackdoor(PacketPtr pkt, MemBackdoorPtr &backdoor) override
Default implementations.
Definition: port.cc:198
ResponsePort(const std::string &name, SimObject *_owner, PortID id=InvalidPortID)
Response port.
Definition: port.cc:173
void responderUnbind()
Called by the request port to unbind.
Definition: port.cc:184
bool defaultBackdoorWarned
Definition: port.hh:276
void responderBind(RequestPort &request_port)
Called by the request port to bind.
Definition: port.cc:191
virtual AddrRangeList getAddrRanges() const =0
Get a list of the non-overlapping address ranges the owner is responsible for.
virtual ~ResponsePort()
Definition: port.cc:179
RequestPort * _requestPort
Definition: port.hh:274
Abstract superclass for simulation objects.
Definition: sim_object.hh:148
std::list< AddrRange > AddrRangeList
Convenience typedef for a collection of address ranges.
Definition: addr_range.hh:57
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition: logging.hh:226
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:204
Port Object Declaration.
Bitfield< 33 > id
Definition: misc_types.hh:257
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
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:49

Generated on Wed Dec 21 2022 10:22:37 for gem5 by doxygen 1.9.1