gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
47namespace gem5
48{
49
55{
56 public:
58
60
64
68
69 StubSlavePort(const std::string &name_,
70 ExternalSlave &owner_) :
71 ExternalSlave::ExternalPort(name_, owner_),
73 responsePacket(NULL), mustRetry(false)
74 { }
75
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
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
100Tick
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
114void
119
120void
135
136bool
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
153bool
155{
156 fatal("StubSlavePort: function: %s\n", __func__);
157 return false;
158}
159
160void
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
170void
172{
173 fatal("StubSlavePort: unimplemented function: %s\n", __func__);
174}
175
176std::map<std::string, ExternalSlave::Handler *>
178
184
185ExternalSlave::ExternalSlave(const ExternalSlaveParams &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
198Port &
199ExternalSlave::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",
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
225void
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
237void
238ExternalSlave::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:204
#define DPRINTF(x,...)
Definition trace.hh:210
Derive from this class to create an external port interface.
AddrRangeList getAddrRanges() const
Any or all of recv... can be overloaded to provide the port's functionality.
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:295
Addr getAddr() const
Definition packet.hh:807
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
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
uint32_t headerDelay
The extra delay from seeing the packet until the header is transmitted.
Definition packet.hh:431
unsigned getSize() const
Definition packet.hh:817
const T * getConstPtr() const
Definition packet.hh:1234
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:454
void sendRangeChange() const
Called by the owner to send a range change.
Definition port.hh:380
void sendRetryReq()
Send a retry to the request port that previously attempted a sendTimingReq to this response port and ...
Definition port.hh:489
Abstract superclass for simulation objects.
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:1012
#define fatal(...)
This implements a cprintf based fatal() function.
Definition logging.hh:200
const Params & params() const
virtual Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a port with a given name and index.
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
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
Packet * PacketPtr
const std::string & name()
Definition trace.cc:48

Generated on Tue Jun 18 2024 16:24:05 for gem5 by doxygen 1.11.0