gem5  v19.0.0.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  * Authors: Andrew Bardsley
38  */
39 
40 #include "mem/external_slave.hh"
41 
42 #include <cctype>
43 #include <iomanip>
44 
45 #include "base/trace.hh"
46 #include "debug/ExternalPort.hh"
47 
53 {
54  public:
55  void processResponseEvent();
56 
58 
62 
65  bool mustRetry;
66 
67  StubSlavePort(const std::string &name_,
68  ExternalSlave &owner_) :
69  ExternalSlave::ExternalPort(name_, owner_),
70  responseEvent([this]{ processResponseEvent(); }, name()),
71  responsePacket(NULL), mustRetry(false)
72  { }
73 
74  Tick recvAtomic(PacketPtr packet);
75  void recvFunctional(PacketPtr packet);
76  bool recvTimingReq(PacketPtr packet);
77  bool recvTimingSnoopResp(PacketPtr packet);
78  void recvRespRetry();
79  void recvFunctionalSnoop(PacketPtr packet);
80 };
81 
82 class StubSlavePortHandler : public
84 {
85  public:
87  const std::string &name_,
89  const std::string &port_data)
90  {
91  StringWrap name(name_);
92 
93  DPRINTF(ExternalPort, "finding stub port '%s'\n", port_data);
94  return new StubSlavePort(name_, owner);
95  }
96 };
97 
98 Tick
100 {
101  if (DTRACE(ExternalPort)) {
102  unsigned int M5_VAR_USED size = packet->getSize();
103 
104  DPRINTF(ExternalPort, "StubSlavePort: recvAtomic a: 0x%x size: %d"
105  " data: ...\n", packet->getAddr(), size);
106  DDUMP(ExternalPort, packet->getConstPtr<uint8_t>(), size);
107  }
108 
109  return 0;
110 }
111 
112 void
114 {
115  recvAtomic(packet);
116 }
117 
118 void
120 {
124 
126  responsePacket = NULL;
127 
128  if (mustRetry)
129  sendRetryReq();
130  mustRetry = false;
131  }
132 }
133 
134 bool
136 {
137  if (responsePacket) {
138  mustRetry = true;
139 
140  return false;
141  } else {
142  recvAtomic(packet);
143 
144  responsePacket = packet;
146 
147  return true;
148  }
149 }
150 
151 bool
153 {
154  fatal("StubSlavePort: function: %s\n", __func__);
155  return false;
156 }
157 
158 void
160 {
161  assert(responsePacket);
162  /* Stub handles only one response at a time so responseEvent should never
163  * be scheduled at this point. Retrys shouldn't need to schedule, we
164  * can safely send the response here */
166 }
167 
168 void
170 {
171  fatal("StubSlavePort: unimplemented function: %s\n", __func__);
172 }
173 
174 std::map<std::string, ExternalSlave::Handler *>
176 
179 {
180  return owner.addrRanges;
181 }
182 
183 ExternalSlave::ExternalSlave(ExternalSlaveParams *params) :
184  SimObject(params),
185  externalPort(NULL),
186  portName(params->name + ".port"),
187  portType(params->port_type),
188  portData(params->port_data),
189  addrRanges(params->addr_ranges.begin(), params->addr_ranges.end())
190 {
191  /* Register the stub handler if it hasn't already been registered */
192  if (portHandlers.find("stub") == portHandlers.end())
194 }
195 
196 Port &
197 ExternalSlave::getPort(const std::string &if_name, PortID idx)
198 {
199  if (if_name == "port") {
200  DPRINTF(ExternalPort, "Trying to bind external port: %s %s\n",
201  portType, portName);
202 
203  if (!externalPort) {
204  auto handlerIter = portHandlers.find(portType);
205 
206  if (handlerIter == portHandlers.end())
207  fatal("Can't find port handler type '%s'\n", portType);
208 
209  externalPort = portHandlers[portType]->getExternalPort(portName,
210  *this, portData);
211 
212  if (!externalPort) {
213  fatal("%s: Can't find external port type: %s"
214  " port_data: '%s'\n", portName, portType, portData);
215  }
216  }
217  return *externalPort;
218  } else {
219  return SimObject::getPort(if_name, idx);
220  }
221 }
222 
223 void
225 {
226  if (!externalPort) {
227  fatal("ExternalSlave %s: externalPort not set!\n", name());
228  } else if (!externalPort->isConnected()) {
229  fatal("ExternalSlave %s is unconnected!\n", name());
230  } else {
232  }
233 }
234 
236 ExternalSlaveParams::create()
237 {
238  return new ExternalSlave(this);
239 }
240 
241 void
242 ExternalSlave::registerHandler(const std::string &handler_name,
243  Handler *handler)
244 {
245  portHandlers[handler_name] = handler;
246 }
#define DPRINTF(x,...)
Definition: trace.hh:229
ExternalPort(const std::string &name_, ExternalSlave &owner_)
Ports are used to interface objects to each other.
Definition: port.hh:60
Derive from this class to create an external port interface.
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
void sendRangeChange() const
Called by the owner to send a range change.
Definition: port.hh:286
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:175
static void registerHandler(const std::string &handler_name, Handler *handler)
Register a handler which can provide ports with port_type == handler_name.
ExternalSlave::ExternalPort * getExternalPort(const std::string &name_, ExternalSlave &owner, const std::string &port_data)
Create or find an external port which can be bound.
AddrRangeList addrRanges
The Range of addresses supported by the devices on the external side of this port.
PacketPtr responsePacket
Stub can handle a single request at a time.
EventFunctionWrapper responseEvent
bool recvTimingReq(PacketPtr packet)
Receive a timing request from the peer.
std::string portData
Handler-specific port configuration.
#define DDUMP(x, data, count)
Definition: trace.hh:228
std::string portName
Name of the bound port.
bool isConnected() const
Is this port currently connected to a peer?
Definition: port.hh:128
Tick recvAtomic(PacketPtr packet)
Receive an atomic request packet from the peer.
void recvFunctional(PacketPtr packet)
Receive a functional request packet from the peer.
StubSlavePort(const std::string &name_, ExternalSlave &owner_)
unsigned getSize() const
Definition: packet.hh:736
bool sendTimingResp(PacketPtr pkt)
Attempt to send a timing response to the master port by calling its corresponding receive function...
Definition: port.hh:357
Tick curTick()
The current simulated tick.
Definition: core.hh:47
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
#define DTRACE(x)
Definition: trace.hh:227
uint32_t headerDelay
The extra delay from seeing the packet until the header is transmitted.
Definition: packet.hh:366
uint64_t Tick
Tick count type.
Definition: types.hh:63
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Port interface.
Addr getAddr() const
Definition: packet.hh:726
bool recvTimingSnoopResp(PacketPtr packet)
Receive a timing snoop response from the peer.
std::string portType
Key to select a port handler.
ExternalSlave is a memory object representing a binding from a gem5 master to a slave port in a syste...
uint32_t payloadDelay
The extra pipelining delay from seeing the packet until the end of payload is transmitted by the comp...
Definition: packet.hh:384
virtual const std::string name() const
Definition: sim_object.hh:120
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:255
static std::map< std::string, Handler * > portHandlers
Registered handlers.
ExternalPort * externalPort
The peer port for the gem5 port "port".
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:937
void sendRetryReq()
Send a retry to the master port that previously attempted a sendTimingReq to this slave port and fail...
Definition: port.hh:380
ExternalSlave(ExternalSlaveParams *params)
const std::string portName
Descriptive name (for DPRINTF output)
Definition: port.hh:66
const std::string name() const
Return port name (for DPRINTF).
Definition: port.hh:106
void processResponseEvent()
void recvFunctionalSnoop(PacketPtr packet)
void schedule(Event &event, Tick when)
Definition: eventq.hh:744
const T * getConstPtr() const
Definition: packet.hh:1099
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:237
static const int NumArgumentRegs M5_VAR_USED
Definition: process.cc:84
bool mustRetry
Received a new request while processing a first.
Abstract superclass for simulation objects.
Definition: sim_object.hh:96
void recvRespRetry()
Called by the peer if sendTimingResp was called on this protocol (causing recvTimingResp to be called...
Implement a `stub&#39; port which just responds to requests by printing a message.
AddrRangeList getAddrRanges() const
Any or all of recv...

Generated on Fri Feb 28 2020 16:27:02 for gem5 by doxygen 1.8.13