gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
gem5::curTick
Tick curTick()
The universal simulation clock.
Definition: cur_tick.hh:46
fatal
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:200
gem5::StubSlavePort::StubSlavePort
StubSlavePort(const std::string &name_, ExternalSlave &owner_)
Definition: external_slave.cc:69
gem5::PortID
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:245
gem5::SimObject::getPort
virtual Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a port with a given name and index.
Definition: sim_object.cc:123
gem5::ExternalSlave
Definition: external_slave.hh:68
gem5::StubSlavePort::mustRetry
bool mustRetry
Received a new request while processing a first.
Definition: external_slave.cc:67
gem5::ExternalSlave::registerHandler
static void registerHandler(const std::string &handler_name, Handler *handler)
Register a handler which can provide ports with port_type == handler_name.
Definition: external_slave.cc:238
gem5::Port::name
const std::string name() const
Return port name (for DPRINTF).
Definition: port.hh:111
gem5::StubSlavePort::recvFunctional
void recvFunctional(PacketPtr packet)
Receive a functional request packet from the peer.
Definition: external_slave.cc:115
gem5::ResponsePort::sendRetryReq
void sendRetryReq()
Send a retry to the request port that previously attempted a sendTimingReq to this response port and ...
Definition: port.hh:473
gem5::StubSlavePort::recvFunctionalSnoop
void recvFunctionalSnoop(PacketPtr packet)
Definition: external_slave.cc:171
gem5::StubSlavePort::processResponseEvent
void processResponseEvent()
Definition: external_slave.cc:121
gem5::ExternalSlave::portName
std::string portName
Name of the bound port.
Definition: external_slave.hh:110
external_slave.hh
gem5::ExternalSlave::portType
std::string portType
Key to select a port handler.
Definition: external_slave.hh:113
gem5::ExternalSlave::portData
std::string portData
Handler-specific port configuration.
Definition: external_slave.hh:116
gem5::ExternalSlave::ExternalPort
Derive from this class to create an external port interface.
Definition: external_slave.hh:72
gem5::StubSlavePort::recvRespRetry
void recvRespRetry()
Called by the peer if sendTimingResp was called on this protocol (causing recvTimingResp to be called...
Definition: external_slave.cc:161
gem5::EventManager::schedule
void schedule(Event &event, Tick when)
Definition: eventq.hh:1012
gem5::StubSlavePort
Implement a ‘stub’ port which just responds to requests by printing a message.
Definition: external_slave.cc:54
gem5::Packet::headerDelay
uint32_t headerDelay
The extra delay from seeing the packet until the header is transmitted.
Definition: packet.hh:431
gem5::ExternalSlave::getPort
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Port interface.
Definition: external_slave.cc:199
gem5::PacketPtr
Packet * PacketPtr
Definition: thread_context.hh:70
gem5::ExternalSlave::ExternalPort::ExternalPort
ExternalPort(const std::string &name_, ExternalSlave &owner_)
Definition: external_slave.hh:78
gem5::Packet::payloadDelay
uint32_t payloadDelay
The extra pipelining delay from seeing the packet until the end of payload is transmitted by the comp...
Definition: packet.hh:449
gem5::ExternalSlave::ExternalPort::owner
ExternalSlave & owner
Definition: external_slave.hh:75
gem5::ExternalSlave::init
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: external_slave.cc:226
gem5::Named::name
virtual std::string name() const
Definition: named.hh:47
gem5::SimObject::params
const Params & params() const
Definition: sim_object.hh:176
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:210
gem5::Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
gem5::ExternalSlave::Handler
Definition: external_slave.hh:95
gem5::StringWrap
Definition: trace.hh:169
gem5::StubSlavePort::recvAtomic
Tick recvAtomic(PacketPtr packet)
Receive an atomic request packet from the peer.
Definition: external_slave.cc:101
gem5::Tick
uint64_t Tick
Tick count type.
Definition: types.hh:58
gem5::ExternalSlave::externalPort
ExternalPort * externalPort
The peer port for the gem5 port "port".
Definition: external_slave.hh:107
gem5::Packet::getConstPtr
const T * getConstPtr() const
Definition: packet.hh:1234
gem5::ResponsePort::sendTimingResp
bool sendTimingResp(PacketPtr pkt)
Attempt to send a timing response to the request port by calling its corresponding receive function.
Definition: port.hh:438
gem5::Port::isConnected
bool isConnected() const
Is this port currently connected to a peer?
Definition: port.hh:133
compiler.hh
gem5::SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:146
gem5::ExternalSlave::portHandlers
static std::map< std::string, Handler * > portHandlers
Registered handlers.
Definition: external_slave.hh:126
gem5::StubSlavePort::responseEvent
EventFunctionWrapper responseEvent
Definition: external_slave.cc:59
gem5::StubSlavePort::responsePacket
PacketPtr responsePacket
Stub can handle a single request at a time.
Definition: external_slave.cc:63
name
const std::string & name()
Definition: trace.cc:48
DDUMP
#define DDUMP(x, data, count)
DPRINTF is a debugging trace facility that allows one to selectively enable tracing statements.
Definition: trace.hh:204
gem5::ResponsePort::sendRangeChange
void sendRangeChange() const
Called by the owner to send a range change.
Definition: port.hh:364
gem5::StubSlavePort::recvTimingSnoopResp
bool recvTimingSnoopResp(PacketPtr packet)
Receive a timing snoop response from the peer.
Definition: external_slave.cc:154
gem5::EventFunctionWrapper::process
void process()
Definition: eventq.hh:1162
gem5::EventFunctionWrapper
Definition: eventq.hh:1136
gem5::StubSlavePortHandler
Definition: external_slave.cc:84
gem5::Port
Ports are used to interface objects to each other.
Definition: port.hh:61
gem5::Packet::makeResponse
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:1062
gem5::ExternalSlave::ExternalSlave
ExternalSlave(const ExternalSlaveParams &params)
Definition: external_slave.cc:185
gem5::ExternalSlave::ExternalPort::getAddrRanges
AddrRangeList getAddrRanges() const
Any or all of recv...
Definition: external_slave.cc:180
trace.hh
std::list< AddrRange >
gem5::Packet::getAddr
Addr getAddr() const
Definition: packet.hh:807
gem5::ExternalSlave::addrRanges
AddrRangeList addrRanges
The Range of addresses supported by the devices on the external side of this port.
Definition: external_slave.hh:120
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::StubSlavePort::recvTimingReq
bool recvTimingReq(PacketPtr packet)
Receive a timing request from the peer.
Definition: external_slave.cc:137
gem5::StubSlavePortHandler::getExternalPort
ExternalSlave::ExternalPort * getExternalPort(const std::string &name_, ExternalSlave &owner, const std::string &port_data)
Create or find an external port which can be bound.
Definition: external_slave.cc:88
gem5::Packet::getSize
unsigned getSize() const
Definition: packet.hh:817

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