gem5  v21.1.0.2
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 "sim/sim_object.hh"
49 
50 namespace gem5
51 {
52 
53 namespace
54 {
55 
56 class DefaultRequestPort : public RequestPort
57 {
58  protected:
59  [[noreturn]] void
60  blowUp() const
61  {
62  throw UnboundPortException();
63  }
64 
65  public:
66  DefaultRequestPort() : RequestPort("default_request_port", nullptr) {}
67 
68  // Atomic protocol.
69  Tick recvAtomicSnoop(PacketPtr) override { blowUp(); }
70 
71  // Timing protocol.
72  bool recvTimingResp(PacketPtr) override { blowUp(); }
73  void recvTimingSnoopReq(PacketPtr) override { blowUp(); }
74  void recvReqRetry() override { blowUp(); }
75  void recvRetrySnoopResp() override { blowUp(); }
76 
77  // Functional protocol.
78  void recvFunctionalSnoop(PacketPtr) override { blowUp(); }
79 };
80 
81 class DefaultResponsePort : public ResponsePort
82 {
83  protected:
84  [[noreturn]] void
85  blowUp() const
86  {
87  throw UnboundPortException();
88  }
89 
90  public:
91  DefaultResponsePort() : ResponsePort("default_response_port", nullptr) {}
92 
93  // Atomic protocol.
94  Tick recvAtomic(PacketPtr) override { blowUp(); }
95 
96  // Timing protocol.
97  bool recvTimingReq(PacketPtr) override { blowUp(); }
98  bool tryTiming(PacketPtr) override { blowUp(); }
99  bool recvTimingSnoopResp(PacketPtr) override { blowUp(); }
100  void recvRespRetry() override { blowUp(); }
101 
102  // Functional protocol.
103  void recvFunctional(PacketPtr) override { blowUp(); }
104 
105  // General.
106  AddrRangeList getAddrRanges() const override { return AddrRangeList(); }
107 };
108 
109 DefaultRequestPort defaultRequestPort;
110 DefaultResponsePort defaultResponsePort;
111 
112 } // anonymous namespace
113 
117 RequestPort::RequestPort(const std::string& name, SimObject* _owner,
118  PortID _id) : Port(name, _id), _responsePort(&defaultResponsePort),
119  owner(*_owner)
120 {
121 }
122 
124 {
125 }
126 
127 void
129 {
130  auto *response_port = dynamic_cast<ResponsePort *>(&peer);
131  fatal_if(!response_port, "Can't bind port %s to non-response port %s.",
132  name(), peer.name());
133  // request port keeps track of the response port
134  _responsePort = response_port;
135  Port::bind(peer);
136  // response port also keeps track of request port
138 }
139 
140 void
142 {
143  panic_if(!isConnected(), "Can't unbind request port %s which is "
144  "not bound.", name());
146  _responsePort = &defaultResponsePort;
147  Port::unbind();
148 }
149 
152 {
153  return _responsePort->getAddrRanges();
154 }
155 
156 void
158 {
159  auto req = std::make_shared<Request>(
160  a, 1, 0, Request::funcRequestorId);
161 
162  Packet pkt(req, MemCmd::PrintReq);
163  Packet::PrintReqState prs(std::cerr);
164  pkt.senderState = &prs;
165 
166  sendFunctional(&pkt);
167 }
168 
172 ResponsePort::ResponsePort(const std::string& name, SimObject* _owner,
173  PortID id) : Port(name, id), _requestPort(&defaultRequestPort),
174  defaultBackdoorWarned(false), owner(*_owner)
175 {
176 }
177 
179 {
180 }
181 
182 void
184 {
185  _requestPort = &defaultRequestPort;
186  Port::unbind();
187 }
188 
189 void
191 {
192  _requestPort = &request_port;
193  Port::bind(request_port);
194 }
195 
196 Tick
198 {
199  if (!defaultBackdoorWarned) {
200  warn("Port %s doesn't support requesting a back door.", name());
201  defaultBackdoorWarned = true;
202  }
203  return recvAtomic(pkt);
204 }
205 
206 } // namespace gem5
gem5::PortID
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:252
warn
#define warn(...)
Definition: logging.hh:245
gem5::RequestPort::unbind
void unbind() override
Unbind this request port and the associated response port.
Definition: port.cc:141
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:128
gem5::ResponsePort::_requestPort
RequestPort * _requestPort
Definition: port.hh:274
gem5::AddrRangeList
std::list< AddrRange > AddrRangeList
Convenience typedef for a collection of address ranges.
Definition: addr_range.hh:641
gem5::RequestPort::RequestPort
RequestPort(const std::string &name, SimObject *_owner, PortID id=InvalidPortID)
Request port.
Definition: port.cc:117
gem5::ArmISA::a
Bitfield< 8 > a
Definition: misc_types.hh:65
gem5::ResponsePort::responderUnbind
void responderUnbind()
Called by the request port to unbind.
Definition: port.cc:183
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:77
gem5::PacketPtr
Packet * PacketPtr
Definition: thread_context.hh:75
gem5::RequestPort::~RequestPort
virtual ~RequestPort()
Definition: port.cc:123
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:485
gem5::ResponsePort::responderBind
void responderBind(RequestPort &request_port)
Called by the request port to bind.
Definition: port.cc:190
sim_object.hh
gem5::ResponsePort::~ResponsePort
virtual ~ResponsePort()
Definition: port.cc:178
gem5::Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:283
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:151
gem5::SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:146
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::Packet::senderState
SenderState * senderState
This packet's sender state.
Definition: packet.hh:534
name
const std::string & name()
Definition: trace.cc:49
gem5::MemBackdoor
Definition: backdoor.hh:41
gem5::ResponsePort::ResponsePort
ResponsePort(const std::string &name, SimObject *_owner, PortID id=InvalidPortID)
Response port.
Definition: port.cc:172
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:268
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:203
gem5::Request::funcRequestorId
@ funcRequestorId
This requestor id is used for functional requests that don't come from a particular device.
Definition: request.hh:260
gem5::Port
Ports are used to interface objects to each other.
Definition: port.hh:61
gem5::RequestPort::_responsePort
ResponsePort * _responsePort
Definition: port.hh:83
gem5::ResponsePort::defaultBackdoorWarned
bool defaultBackdoorWarned
Definition: port.hh:276
gem5::ArmISA::id
Bitfield< 33 > id
Definition: misc_types.hh:250
trace.hh
gem5::MemCmd::PrintReq
@ PrintReq
Definition: packet.hh:135
std::list< AddrRange >
gem5::ResponsePort::recvAtomicBackdoor
Tick recvAtomicBackdoor(PacketPtr pkt, MemBackdoorPtr &backdoor) override
Default implementations.
Definition: port.cc:197
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:225
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
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:157
gem5::Packet::PrintReqState
Object used to maintain state of a PrintReq.
Definition: packet.hh:468

Generated on Tue Sep 21 2021 12:25:34 for gem5 by doxygen 1.8.17