gem5 v24.0.0.0
Loading...
Searching...
No Matches
port.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011-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
46#ifndef __MEM_PORT_HH__
47#define __MEM_PORT_HH__
48
49#include <memory>
50#include <sstream>
51#include <stack>
52#include <string>
53
54#include "base/addr_range.hh"
55#include "mem/packet.hh"
59#include "sim/port.hh"
60
61namespace gem5
62{
63
64class SimObject;
65
67class MasterPort;
68class SlavePort;
69
70class ResponsePort;
71
77class TracingExtension : public gem5::Extension<Packet, TracingExtension>
78{
79 public:
80 TracingExtension() = default;
81 TracingExtension(const std::stack<std::string>& q) { trace_ = q; }
82
83 std::unique_ptr<ExtensionBase> clone() const override
84 {
85 return std::make_unique<TracingExtension>(trace_);
86 }
87
88 void
89 add(std::string request_port, std::string response_port, gem5::Addr addr)
90 {
91 trace_.push(request_port + csprintf(" addr=%#llx", addr));
92 trace_.push(response_port);
93 }
94
95 void
97 {
98 trace_.pop(); // Remove the response port name.
99 trace_.pop(); // Remove the request port name.
100 }
101
102 bool empty() { return trace_.empty(); }
103 std::stack<std::string>& getTrace() { return trace_; }
104 std::string getTraceInString()
105 {
106 std::stringstream port_trace;
107 std::stack<std::string> copy_stack = trace_;
108 port_trace << "Port trace of the Packet (" << std::endl
109 << "[Destination] ";
110 while (!copy_stack.empty()) {
111 if (copy_stack.size() == 1)
112 port_trace << "[Source] ";
113 port_trace << copy_stack.top() << std::endl;
114 copy_stack.pop();
115 }
116 port_trace << ")";
117 return port_trace.str();
118 }
119
120 private:
121 std::stack<std::string> trace_;
122};
123
136{
137 friend class ResponsePort;
138
139 private:
141
142 protected:
144
145 public:
146 [[deprecated("RequestPort ownership is deprecated. "
147 "Owner should now be registered in derived classes.")]]
148 RequestPort(const std::string& name, SimObject* _owner,
150
151 RequestPort(const std::string& name, PortID id=InvalidPortID);
152
153 virtual ~RequestPort();
154
159 void bind(Port &peer) override;
160
164 void unbind() override;
165
175 virtual bool isSnooping() const { return false; }
176
181
186 void printAddr(Addr a);
187
188 public:
189 /* The atomic protocol. */
190
201
213
214 public:
215 /* The functional protocol. */
216
224 void sendFunctional(PacketPtr pkt) const;
225
238 void sendMemBackdoorReq(const MemBackdoorReq &req,
239 MemBackdoorPtr &backdoor);
240
241 public:
242 /* The timing protocol. */
243
255 bool sendTimingReq(PacketPtr pkt);
256
268 bool tryTiming(PacketPtr pkt) const;
269
280
287 virtual void sendRetryResp();
288
289 protected:
297 virtual void recvRangeChange() { }
298
302 Tick
304 {
305 panic("%s was not expecting an atomic snoop request\n", name());
306 return 0;
307 }
308
309 void
311 {
312 panic("%s was not expecting a functional snoop request\n", name());
313 }
314
315 void
317 {
318 panic("%s was not expecting a timing snoop request.\n", name());
319 }
320
321 void
323 {
324 panic("%s was not expecting a snoop retry.\n", name());
325 }
326
327 private:
328 void addTrace(PacketPtr pkt) const;
329 void removeTrace(PacketPtr pkt) const;
330};
331
332class [[deprecated]] MasterPort : public RequestPort
333{
334 public:
335 using RequestPort::RequestPort;
336};
337
349{
350 friend class RequestPort;
351
352 private:
354
356
357 protected:
359
360 public:
361 [[deprecated("ResponsePort ownership is deprecated. "
362 "Owner should now be registered in derived classes.")]]
363 ResponsePort(const std::string& name, SimObject* _owner,
365
366 ResponsePort(const std::string& name, PortID id=InvalidPortID);
367
368 virtual ~ResponsePort();
369
375 bool isSnooping() const { return _requestPort->isSnooping(); }
376
381
389 virtual AddrRangeList getAddrRanges() const = 0;
390
394 void unbind() override {}
395 void bind(Port &peer) override {}
396
397 public:
398 /* The atomic protocol. */
399
409 Tick
411 {
412 try {
414 } catch (UnboundPortException) {
416 }
417 }
418
419 public:
420 /* The functional protocol. */
421
429 void
431 {
432 try {
434 } catch (UnboundPortException) {
436 }
437 }
438
439 public:
440 /* The timing protocol. */
441
453 bool
455 {
456 try {
459 if (!succ)
461 return succ;
462 } catch (UnboundPortException) {
464 }
465 }
466
474 void
483
488 void
490 {
491 try {
493 } catch (UnboundPortException) {
495 }
496 }
497
502 void
511
512 protected:
517 void responderUnbind();
518
523 void responderBind(RequestPort& request_port);
524
528 Tick recvAtomicBackdoor(PacketPtr pkt, MemBackdoorPtr &backdoor) override;
529 void recvMemBackdoorReq(const MemBackdoorReq &req,
530 MemBackdoorPtr &backdoor) override;
531
532 bool
533 tryTiming(PacketPtr pkt) override
534 {
535 panic("%s was not expecting a %s\n", name(), __func__);
536 }
537
538 bool
540 {
541 panic("%s was not expecting a timing snoop response\n", name());
542 }
543};
544
545class [[deprecated]] SlavePort : public ResponsePort
546{
547 public:
548 using ResponsePort::ResponsePort;
549};
550
551inline Tick
553{
554 try {
555 addTrace(pkt);
557 removeTrace(pkt);
558 return tick;
559 } catch (UnboundPortException) {
561 }
562}
563
564inline Tick
566{
567 try {
568 addTrace(pkt);
570 pkt, backdoor);
571 removeTrace(pkt);
572 return tick;
573 } catch (UnboundPortException) {
575 }
576}
577
578inline void
580{
581 try {
582 addTrace(pkt);
584 removeTrace(pkt);
585 } catch (UnboundPortException) {
587 }
588}
589
590inline void
592 MemBackdoorPtr &backdoor)
593{
594 try {
596 _responsePort, req, backdoor);
597 } catch (UnboundPortException) {
599 }
600}
601
602inline bool
604{
605 try {
606 addTrace(pkt);
608 if (!succ)
609 removeTrace(pkt);
610 return succ;
611 } catch (UnboundPortException) {
613 }
614}
615
616inline bool
618{
619 try {
621 } catch (UnboundPortException) {
623 }
624}
625
626inline bool
635
636inline void
645
646} // namespace gem5
647
648#endif //__MEM_PORT_HH__
Tick sendBackdoor(AtomicResponseProtocol *peer, PacketPtr pkt, MemBackdoorPtr &backdoor)
Send an atomic request packet like above, but also request a backdoor to the data being accessed.
Definition atomic.cc:58
Tick send(AtomicResponseProtocol *peer, PacketPtr pkt)
Send an atomic request packet, where the data is moved and the state is updated in zero time,...
Definition atomic.cc:51
Tick sendSnoop(AtomicRequestProtocol *peer, PacketPtr pkt)
Send an atomic snoop request packet, where the data is moved and the state is updated in zero time,...
Definition atomic.cc:68
This is the extension for carrying additional information.
void sendMemBackdoorReq(FunctionalResponseProtocol *peer, const MemBackdoorReq &req, MemBackdoorPtr &backdoor)
Send a request for a back door to a range of memory.
Definition functional.cc:57
void send(FunctionalResponseProtocol *peer, PacketPtr pkt) const
Send a functional request packet, where the data is instantly updated everywhere in the memory system...
Definition functional.cc:49
void sendSnoop(FunctionalRequestProtocol *peer, PacketPtr pkt) const
Send a functional snoop request packet, where the data is instantly updated everywhere in the memory ...
Definition functional.cc:67
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
Ports are used to interface objects to each other.
Definition port.hh:62
const std::string name() const
Return port name (for DPRINTF).
Definition port.hh:111
void reportUnbound() const
Definition port.cc:60
A RequestPort is a specialisation of a Port, which implements the default protocol for the three diff...
Definition port.hh:136
void sendMemBackdoorReq(const MemBackdoorReq &req, MemBackdoorPtr &backdoor)
Send a request for a back door to a range of memory.
Definition port.hh:591
virtual void sendRetryResp()
Send a retry to the response port that previously attempted a sendTimingResp to this request port and...
Definition port.hh:637
void recvTimingSnoopReq(PacketPtr pkt) override
Receive a timing snoop request from the peer.
Definition port.hh:316
virtual void recvRangeChange()
Called to receive an address range change from the peer response port.
Definition port.hh:297
SimObject & owner
Definition port.hh:143
virtual ~RequestPort()
Definition port.cc:144
void unbind() override
Unbind this request port and the associated response port.
Definition port.cc:162
virtual bool isSnooping() const
Determine if this request port is snooping or not.
Definition port.hh:175
bool tryTiming(PacketPtr pkt) const
Check if the responder can handle a timing request.
Definition port.hh:617
Tick recvAtomicSnoop(PacketPtr pkt) override
Default implementations.
Definition port.hh:303
ResponsePort * _responsePort
Definition port.hh:140
Tick sendAtomic(PacketPtr pkt)
Send an atomic request packet, where the data is moved and the state is updated in zero time,...
Definition port.hh:552
AddrRangeList getAddrRanges() const
Get the address ranges of the connected responder port.
Definition port.cc:172
void bind(Port &peer) override
Bind this request port to a response port.
Definition port.cc:149
void addTrace(PacketPtr pkt) const
Definition port.cc:191
bool sendTimingReq(PacketPtr pkt)
Attempt to send a timing request to the responder port by calling its corresponding receive function.
Definition port.hh:603
void recvRetrySnoopResp() override
Called by the peer if sendTimingSnoopResp was called on this protocol (causing recvTimingSnoopResp to...
Definition port.hh:322
void removeTrace(PacketPtr pkt) const
Definition port.cc:204
bool sendTimingSnoopResp(PacketPtr pkt)
Attempt to send a timing snoop response packet to the response port by calling its corresponding rece...
Definition port.hh:627
RequestPort(const std::string &name, SimObject *_owner, PortID id=InvalidPortID)
Request port.
Definition port.cc:125
void sendFunctional(PacketPtr pkt) const
Send a functional request packet, where the data is instantly updated everywhere in the memory system...
Definition port.hh:579
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:178
void recvFunctionalSnoop(PacketPtr pkt) override
Receive a functional snoop request packet from the peer.
Definition port.hh:310
Tick sendAtomicBackdoor(PacketPtr pkt, MemBackdoorPtr &backdoor)
Send an atomic request packet like above, but also request a backdoor to the data being accessed.
Definition port.hh:565
A ResponsePort is a specialization of a port.
Definition port.hh:349
SimObject & owner
Definition port.hh:358
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 sendFunctionalSnoop(PacketPtr pkt) const
Send a functional snoop request packet, where the data is instantly updated everywhere in the memory ...
Definition port.hh:430
bool tryTiming(PacketPtr pkt) override
Availability request from the peer.
Definition port.hh:533
void bind(Port &peer) override
Attach to a peer port.
Definition port.hh:395
void sendRetrySnoopResp()
Send a retry to the request port that previously attempted a sendTimingSnoopResp to this response por...
Definition port.hh:503
Tick recvAtomicBackdoor(PacketPtr pkt, MemBackdoorPtr &backdoor) override
Default implementations.
Definition port.cc:262
bool recvTimingSnoopResp(PacketPtr pkt) override
Receive a timing snoop response from the peer.
Definition port.hh:539
Tick sendAtomicSnoop(PacketPtr pkt)
Send an atomic snoop request packet, where the data is moved and the state is updated in zero time,...
Definition port.hh:410
ResponsePort(const std::string &name, SimObject *_owner, PortID id=InvalidPortID)
Response port.
Definition port.cc:218
void sendTimingSnoopReq(PacketPtr pkt)
Attempt to send a timing snoop request packet to the request port by calling its corresponding receiv...
Definition port.hh:475
bool isSnooping() const
Find out if the peer request port is snooping or not.
Definition port.hh:375
void responderUnbind()
Called by the request port to unbind.
Definition port.cc:248
bool defaultBackdoorWarned
Definition port.hh:355
void unbind() override
We let the request port do the work, so these don't do anything.
Definition port.hh:394
void sendRangeChange() const
Called by the owner to send a range change.
Definition port.hh:380
void responderBind(RequestPort &request_port)
Called by the request port to bind.
Definition port.cc:255
virtual AddrRangeList getAddrRanges() const =0
Get a list of the non-overlapping address ranges the owner is responsible for.
void recvMemBackdoorReq(const MemBackdoorReq &req, MemBackdoorPtr &backdoor) override
Receive a request for a back door to a range of memory.
Definition port.cc:273
void sendRetryReq()
Send a retry to the request port that previously attempted a sendTimingReq to this response port and ...
Definition port.hh:489
virtual ~ResponsePort()
Definition port.cc:243
RequestPort * _requestPort
Definition port.hh:353
Abstract superclass for simulation objects.
void sendRetryResp(TimingResponseProtocol *peer)
Send a retry to the peer that previously attempted a sendTimingResp to this protocol and failed.
Definition timing.cc:72
bool trySend(TimingResponseProtocol *peer, PacketPtr pkt) const
Check if the peer can handle a timing request.
Definition timing.cc:56
bool sendReq(TimingResponseProtocol *peer, PacketPtr pkt)
Attempt to send a timing request to the peer by calling its corresponding receive function.
Definition timing.cc:49
bool sendSnoopResp(TimingResponseProtocol *peer, PacketPtr pkt)
Attempt to send a timing snoop response packet to it's peer by calling its corresponding receive func...
Definition timing.cc:64
bool sendResp(TimingRequestProtocol *peer, PacketPtr pkt)
Attempt to send a timing response to the peer by calling its corresponding receive function.
Definition timing.cc:80
void sendSnoopReq(TimingRequestProtocol *peer, PacketPtr pkt)
Attempt to send a timing snoop request packet to the peer by calling its corresponding receive functi...
Definition timing.cc:87
void sendRetrySnoopResp(TimingRequestProtocol *peer)
Send a retry to the peer that previously attempted a sendTimingSnoopResp to this peer and failed.
Definition timing.cc:101
void sendRetryReq(TimingRequestProtocol *peer)
Send a retry to the peer that previously attempted a sendTimingReq to this protocol and failed.
Definition timing.cc:95
TracingExtension is an Extension of the Packet for recording the trace of the Packet.
Definition port.hh:78
std::unique_ptr< ExtensionBase > clone() const override
Definition port.hh:83
std::stack< std::string > trace_
Definition port.hh:121
std::stack< std::string > & getTrace()
Definition port.hh:103
TracingExtension(const std::stack< std::string > &q)
Definition port.hh:81
void add(std::string request_port, std::string response_port, gem5::Addr addr)
Definition port.hh:89
std::string getTraceInString()
Definition port.hh:104
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
Bitfield< 27 > q
Definition misc_types.hh:55
Bitfield< 8 > a
Definition misc_types.hh:66
Bitfield< 23, 20 > succ
Definition types.hh:89
Bitfield< 3 > addr
Definition types.hh:84
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
const PortID InvalidPortID
Definition types.hh:246
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
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
std::string csprintf(const char *format, const Args &...args)
Definition cprintf.hh:161
Declaration of the Packet class.
Port Object Declaration.

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