gem5  v22.1.0.0
external_slave.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2014 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  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions are
16  * met: redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer;
18  * redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution;
21  * neither the name of the copyright holders nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #include "mem/external_slave.hh"
39 
40 #include <cctype>
41 #include <iomanip>
42 
43 #include "base/compiler.hh"
44 #include "base/trace.hh"
45 #include "debug/ExternalPort.hh"
46 
47 namespace gem5
48 {
49 
55 {
56  public:
57  void processResponseEvent();
58 
60 
64 
67  bool mustRetry;
68 
69  StubSlavePort(const std::string &name_,
70  ExternalSlave &owner_) :
71  ExternalSlave::ExternalPort(name_, owner_),
72  responseEvent([this]{ processResponseEvent(); }, name()),
73  responsePacket(NULL), mustRetry(false)
74  { }
75 
76  Tick recvAtomic(PacketPtr packet);
77  void recvFunctional(PacketPtr packet);
78  bool recvTimingReq(PacketPtr packet);
79  bool recvTimingSnoopResp(PacketPtr packet);
80  void recvRespRetry();
81  void recvFunctionalSnoop(PacketPtr packet);
82 };
83 
84 class StubSlavePortHandler : public
86 {
87  public:
89  const std::string &name_,
90  ExternalSlave &owner,
91  const std::string &port_data)
92  {
93  StringWrap name(name_);
94 
95  DPRINTF(ExternalPort, "finding stub port '%s'\n", port_data);
96  return new StubSlavePort(name_, owner);
97  }
98 };
99 
100 Tick
102 {
103  if (debug::ExternalPort) {
104  [[maybe_unused]] unsigned int size = packet->getSize();
105 
106  DPRINTF(ExternalPort, "StubSlavePort: recvAtomic a: 0x%x size: %d"
107  " data: ...\n", packet->getAddr(), size);
108  DDUMP(ExternalPort, packet->getConstPtr<uint8_t>(), size);
109  }
110 
111  return 0;
112 }
113 
114 void
116 {
117  recvAtomic(packet);
118 }
119 
120 void
122 {
126 
128  responsePacket = NULL;
129 
130  if (mustRetry)
131  sendRetryReq();
132  mustRetry = false;
133  }
134 }
135 
136 bool
138 {
139  if (responsePacket) {
140  mustRetry = true;
141 
142  return false;
143  } else {
144  recvAtomic(packet);
145 
146  responsePacket = packet;
148 
149  return true;
150  }
151 }
152 
153 bool
155 {
156  fatal("StubSlavePort: function: %s\n", __func__);
157  return false;
158 }
159 
160 void
162 {
163  assert(responsePacket);
164  /* Stub handles only one response at a time so responseEvent should never
165  * be scheduled at this point. Retrys shouldn't need to schedule, we
166  * can safely send the response here */
168 }
169 
170 void
172 {
173  fatal("StubSlavePort: unimplemented function: %s\n", __func__);
174 }
175 
176 std::map<std::string, ExternalSlave::Handler *>
178 
181 {
182  return owner.addrRanges;
183 }
184 
185 ExternalSlave::ExternalSlave(const ExternalSlaveParams &params) :
186  SimObject(params),
187  externalPort(NULL),
188  portName(params.name + ".port"),
189  portType(params.port_type),
190  portData(params.port_data),
191  addrRanges(params.addr_ranges.begin(), params.addr_ranges.end())
192 {
193  /* Register the stub handler if it hasn't already been registered */
194  if (portHandlers.find("stub") == portHandlers.end())
196 }
197 
198 Port &
199 ExternalSlave::getPort(const std::string &if_name, PortID idx)
200 {
201  if (if_name == "port") {
202  DPRINTF(ExternalPort, "Trying to bind external port: %s %s\n",
203  portType, portName);
204 
205  if (!externalPort) {
206  auto handlerIter = portHandlers.find(portType);
207 
208  if (handlerIter == portHandlers.end())
209  fatal("Can't find port handler type '%s'\n", portType);
210 
211  externalPort = portHandlers[portType]->getExternalPort(portName,
212  *this, portData);
213 
214  if (!externalPort) {
215  fatal("%s: Can't find external port type: %s"
216  " port_data: '%s'\n", portName, portType, portData);
217  }
218  }
219  return *externalPort;
220  } else {
221  return SimObject::getPort(if_name, idx);
222  }
223 }
224 
225 void
227 {
228  if (!externalPort) {
229  fatal("ExternalSlave %s: externalPort not set!\n", name());
230  } else if (!externalPort->isConnected()) {
231  fatal("ExternalSlave %s is unconnected!\n", name());
232  } else {
234  }
235 }
236 
237 void
238 ExternalSlave::registerHandler(const std::string &handler_name,
239  Handler *handler)
240 {
241  portHandlers[handler_name] = handler;
242 }
243 
244 } // namespace gem5
#define DDUMP(x, data, count)
DPRINTF is a debugging trace facility that allows one to selectively enable tracing statements.
Definition: trace.hh:180
#define DPRINTF(x,...)
Definition: trace.hh:186
Derive from this class to create an external port interface.
AddrRangeList getAddrRanges() const
Any or all of recv...
ExternalPort(const std::string &name_, ExternalSlave &owner_)
static void registerHandler(const std::string &handler_name, Handler *handler)
Register a handler which can provide ports with port_type == handler_name.
std::string portName
Name of the bound port.
static std::map< std::string, Handler * > portHandlers
Registered handlers.
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
AddrRangeList addrRanges
The Range of addresses supported by the devices on the external side of this port.
std::string portType
Key to select a port handler.
std::string portData
Handler-specific port configuration.
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Port interface.
ExternalSlave(const ExternalSlaveParams &params)
ExternalPort * externalPort
The peer port for the gem5 port "port".
virtual std::string name() const
Definition: named.hh:47
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
Addr getAddr() const
Definition: packet.hh:805
uint32_t payloadDelay
The extra pipelining delay from seeing the packet until the end of payload is transmitted by the comp...
Definition: packet.hh:448
void makeResponse()
Take a request packet and modify it in place to be suitable for returning as a response to that reque...
Definition: packet.hh:1059
uint32_t headerDelay
The extra delay from seeing the packet until the header is transmitted.
Definition: packet.hh:430
unsigned getSize() const
Definition: packet.hh:815
const T * getConstPtr() const
Definition: packet.hh:1221
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
bool sendTimingResp(PacketPtr pkt)
Attempt to send a timing response to the request port by calling its corresponding receive function.
Definition: port.hh:370
void sendRangeChange() const
Called by the owner to send a range change.
Definition: port.hh:296
void sendRetryReq()
Send a retry to the request port that previously attempted a sendTimingReq to this response port and ...
Definition: port.hh:401
Abstract superclass for simulation objects.
Definition: sim_object.hh:148
ExternalSlave::ExternalPort * getExternalPort(const std::string &name_, ExternalSlave &owner, const std::string &port_data)
Create or find an external port which can be bound.
Implement a ‘stub’ port which just responds to requests by printing a message.
Tick recvAtomic(PacketPtr packet)
Receive an atomic request packet from the peer.
StubSlavePort(const std::string &name_, ExternalSlave &owner_)
void recvFunctional(PacketPtr packet)
Receive a functional request packet from the peer.
bool recvTimingSnoopResp(PacketPtr packet)
Receive a timing snoop response from the peer.
void recvFunctionalSnoop(PacketPtr packet)
EventFunctionWrapper responseEvent
bool recvTimingReq(PacketPtr packet)
Receive a timing request from the peer.
bool mustRetry
Received a new request while processing a first.
PacketPtr responsePacket
Stub can handle a single request at a time.
void recvRespRetry()
Called by the peer if sendTimingResp was called on this protocol (causing recvTimingResp to be called...
ExternalSlave is a memory object representing a binding from a gem5 requestor to a response port in a...
void schedule(Event &event, Tick when)
Definition: eventq.hh:1019
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:190
const Params & params() const
Definition: sim_object.hh:176
virtual Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a port with a given name and index.
Definition: sim_object.cc:126
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Packet * PacketPtr
Tick curTick()
The universal simulation clock.
Definition: cur_tick.hh:46
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