gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 <stack>
51 #include <string>
52 
53 #include "base/addr_range.hh"
54 #include "mem/packet.hh"
55 #include "mem/protocol/atomic.hh"
57 #include "mem/protocol/timing.hh"
58 #include "sim/port.hh"
59 
60 namespace gem5
61 {
62 
63 class SimObject;
64 
66 class MasterPort;
67 class SlavePort;
68 
69 class ResponsePort;
70 
76 class TracingExtension : public gem5::Extension<Packet, TracingExtension>
77 {
78  public:
79  TracingExtension() = default;
80  TracingExtension(const std::stack<std::string>& q) { trace_ = q; }
81 
82  std::unique_ptr<ExtensionBase> clone() const override
83  {
84  return std::make_unique<TracingExtension>(trace_);
85  }
86 
87  void
88  add(std::string request_port, std::string response_port)
89  {
90  trace_.push(request_port);
91  trace_.push(response_port);
92  }
93 
94  void
96  {
97  trace_.pop(); // Remove the response port name.
98  trace_.pop(); // Remove the request port name.
99  }
100 
101  bool empty() { return trace_.empty(); }
102  std::stack<std::string>& getTrace() { return trace_; }
103 
104  private:
105  std::stack<std::string> trace_;
106 };
107 
118 class RequestPort: public Port, public AtomicRequestProtocol,
120 {
121  friend class ResponsePort;
122 
123  private:
125 
126  protected:
128 
129  public:
130  [[deprecated("RequestPort ownership is deprecated. "
131  "Owner should now be registered in derived classes.")]]
132  RequestPort(const std::string& name, SimObject* _owner,
133  PortID id=InvalidPortID);
134 
135  RequestPort(const std::string& name, PortID id=InvalidPortID);
136 
137  virtual ~RequestPort();
138 
143  void bind(Port &peer) override;
144 
148  void unbind() override;
149 
159  virtual bool isSnooping() const { return false; }
160 
165 
170  void printAddr(Addr a);
171 
172  public:
173  /* The atomic protocol. */
174 
185 
197 
198  public:
199  /* The functional protocol. */
200 
208  void sendFunctional(PacketPtr pkt) const;
209 
222  void sendMemBackdoorReq(const MemBackdoorReq &req,
223  MemBackdoorPtr &backdoor);
224 
225  public:
226  /* The timing protocol. */
227 
239  bool sendTimingReq(PacketPtr pkt);
240 
252  bool tryTiming(PacketPtr pkt) const;
253 
263  bool sendTimingSnoopResp(PacketPtr pkt);
264 
271  virtual void sendRetryResp();
272 
273  protected:
281  virtual void recvRangeChange() { }
282 
286  Tick
288  {
289  panic("%s was not expecting an atomic snoop request\n", name());
290  return 0;
291  }
292 
293  void
295  {
296  panic("%s was not expecting a functional snoop request\n", name());
297  }
298 
299  void
301  {
302  panic("%s was not expecting a timing snoop request.\n", name());
303  }
304 
305  void
307  {
308  panic("%s was not expecting a snoop retry.\n", name());
309  }
310 
311  private:
312  void addTrace(PacketPtr pkt) const;
313  void removeTrace(PacketPtr pkt) const;
314 };
315 
316 class [[deprecated]] MasterPort : public RequestPort
317 {
318  public:
320 };
321 
331 class ResponsePort : public Port, public AtomicResponseProtocol,
333 {
334  friend class RequestPort;
335 
336  private:
338 
340 
341  protected:
343 
344  public:
345  [[deprecated("ResponsePort ownership is deprecated. "
346  "Owner should now be registered in derived classes.")]]
347  ResponsePort(const std::string& name, SimObject* _owner,
348  PortID id=InvalidPortID);
349 
350  ResponsePort(const std::string& name, PortID id=InvalidPortID);
351 
352  virtual ~ResponsePort();
353 
359  bool isSnooping() const { return _requestPort->isSnooping(); }
360 
365 
373  virtual AddrRangeList getAddrRanges() const = 0;
374 
378  void unbind() override {}
379  void bind(Port &peer) override {}
380 
381  public:
382  /* The atomic protocol. */
383 
393  Tick
395  {
396  try {
398  } catch (UnboundPortException) {
399  reportUnbound();
400  }
401  }
402 
403  public:
404  /* The functional protocol. */
405 
413  void
415  {
416  try {
418  } catch (UnboundPortException) {
419  reportUnbound();
420  }
421  }
422 
423  public:
424  /* The timing protocol. */
425 
437  bool
439  {
440  try {
443  if (!succ)
444  _requestPort->addTrace(pkt);
445  return succ;
446  } catch (UnboundPortException) {
447  reportUnbound();
448  }
449  }
450 
458  void
460  {
461  try {
463  } catch (UnboundPortException) {
464  reportUnbound();
465  }
466  }
467 
472  void
474  {
475  try {
477  } catch (UnboundPortException) {
478  reportUnbound();
479  }
480  }
481 
486  void
488  {
489  try {
491  } catch (UnboundPortException) {
492  reportUnbound();
493  }
494  }
495 
496  protected:
501  void responderUnbind();
502 
507  void responderBind(RequestPort& request_port);
508 
512  Tick recvAtomicBackdoor(PacketPtr pkt, MemBackdoorPtr &backdoor) override;
513  void recvMemBackdoorReq(const MemBackdoorReq &req,
514  MemBackdoorPtr &backdoor) override;
515 
516  bool
517  tryTiming(PacketPtr pkt) override
518  {
519  panic("%s was not expecting a %s\n", name(), __func__);
520  }
521 
522  bool
524  {
525  panic("%s was not expecting a timing snoop response\n", name());
526  }
527 };
528 
529 class [[deprecated]] SlavePort : public ResponsePort
530 {
531  public:
533 };
534 
535 inline Tick
537 {
538  try {
539  addTrace(pkt);
541  removeTrace(pkt);
542  return tick;
543  } catch (UnboundPortException) {
544  reportUnbound();
545  }
546 }
547 
548 inline Tick
550 {
551  try {
552  addTrace(pkt);
554  pkt, backdoor);
555  removeTrace(pkt);
556  return tick;
557  } catch (UnboundPortException) {
558  reportUnbound();
559  }
560 }
561 
562 inline void
564 {
565  try {
566  addTrace(pkt);
568  removeTrace(pkt);
569  } catch (UnboundPortException) {
570  reportUnbound();
571  }
572 }
573 
574 inline void
576  MemBackdoorPtr &backdoor)
577 {
578  try {
580  _responsePort, req, backdoor);
581  } catch (UnboundPortException) {
582  reportUnbound();
583  }
584 }
585 
586 inline bool
588 {
589  try {
590  addTrace(pkt);
592  if (!succ)
593  removeTrace(pkt);
594  return succ;
595  } catch (UnboundPortException) {
596  reportUnbound();
597  }
598 }
599 
600 inline bool
602 {
603  try {
605  } catch (UnboundPortException) {
606  reportUnbound();
607  }
608 }
609 
610 inline bool
612 {
613  try {
615  } catch (UnboundPortException) {
616  reportUnbound();
617  }
618 }
619 
620 inline void
622 {
623  try {
625  } catch (UnboundPortException) {
626  reportUnbound();
627  }
628 }
629 
630 } // namespace gem5
631 
632 #endif //__MEM_PORT_HH__
gem5::PortID
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:245
gem5::RequestPort::tryTiming
bool tryTiming(PacketPtr pkt) const
Check if the responder can handle a timing request.
Definition: port.hh:601
gem5::RequestPort::addTrace
void addTrace(PacketPtr pkt) const
Definition: port.cc:191
gem5::FunctionalRequestProtocol::send
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
gem5::RequestPort::sendTimingReq
bool sendTimingReq(PacketPtr pkt)
Attempt to send a timing request to the responder port by calling its corresponding receive function.
Definition: port.hh:587
gem5::RequestPort::recvFunctionalSnoop
void recvFunctionalSnoop(PacketPtr pkt) override
Receive a functional snoop request packet from the peer.
Definition: port.hh:294
gem5::RequestPort::unbind
void unbind() override
Unbind this request port and the associated response port.
Definition: port.cc:162
gem5::Port::name
const std::string name() const
Return port name (for DPRINTF).
Definition: port.hh:111
gem5::FunctionalRequestProtocol::sendMemBackdoorReq
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
gem5::RequestPort::bind
void bind(Port &peer) override
Bind this request port to a response port.
Definition: port.cc:149
gem5::ResponsePort::sendFunctionalSnoop
void sendFunctionalSnoop(PacketPtr pkt) const
Send a functional snoop request packet, where the data is instantly updated everywhere in the memory ...
Definition: port.hh:414
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::ResponsePort::sendRetrySnoopResp
void sendRetrySnoopResp()
Send a retry to the request port that previously attempted a sendTimingSnoopResp to this response por...
Definition: port.hh:487
gem5::TimingResponseProtocol::sendResp
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
gem5::ResponsePort::_requestPort
RequestPort * _requestPort
Definition: port.hh:337
gem5::TracingExtension::empty
bool empty()
Definition: port.hh:101
gem5::Port::reportUnbound
void reportUnbound() const
Definition: port.cc:60
gem5::AtomicResponseProtocol::sendSnoop
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
gem5::RequestPort::sendAtomic
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:536
gem5::ResponsePort::unbind
void unbind() override
We let the request port do the work, so these don't do anything.
Definition: port.hh:378
gem5::RequestPort::RequestPort
RequestPort(const std::string &name, SimObject *_owner, PortID id=InvalidPortID)
Request port.
Definition: port.cc:125
gem5::TimingResponseProtocol::sendRetryReq
void sendRetryReq(TimingRequestProtocol *peer)
Send a retry to the peer that previously attempted a sendTimingReq to this protocol and failed.
Definition: timing.cc:95
gem5::ArmISA::a
Bitfield< 8 > a
Definition: misc_types.hh:66
gem5::ResponsePort::responderUnbind
void responderUnbind()
Called by the request port to unbind.
Definition: port.cc:248
gem5::TimingRequestProtocol::sendReq
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
gem5::RequestPort::recvRetrySnoopResp
void recvRetrySnoopResp() override
Called by the peer if sendTimingSnoopResp was called on this protocol (causing recvTimingSnoopResp to...
Definition: port.hh:306
gem5::RequestPort::recvRangeChange
virtual void recvRangeChange()
Called to receive an address range change from the peer response port.
Definition: port.hh:281
atomic.hh
gem5::TimingResponseProtocol::sendRetrySnoopResp
void sendRetrySnoopResp(TimingRequestProtocol *peer)
Send a retry to the peer that previously attempted a sendTimingSnoopResp to this peer and failed.
Definition: timing.cc:101
gem5::InvalidPortID
const PortID InvalidPortID
Definition: types.hh:246
gem5::AtomicResponseProtocol
Definition: atomic.hh:89
packet.hh
gem5::RequestPort
A RequestPort is a specialisation of a Port, which implements the default protocol for the three diff...
Definition: port.hh:118
gem5::RequestPort::sendAtomicBackdoor
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:549
gem5::RequestPort::~RequestPort
virtual ~RequestPort()
Definition: port.cc:144
gem5::TracingExtension::getTrace
std::stack< std::string > & getTrace()
Definition: port.hh:102
gem5::FunctionalResponseProtocol
Definition: functional.hh:82
gem5::TracingExtension::clone
std::unique_ptr< ExtensionBase > clone() const override
Definition: port.hh:82
gem5::RequestPort::sendFunctional
void sendFunctional(PacketPtr pkt) const
Send a functional request packet, where the data is instantly updated everywhere in the memory system...
Definition: port.hh:563
gem5::TracingExtension::TracingExtension
TracingExtension(const std::stack< std::string > &q)
Definition: port.hh:80
functional.hh
gem5::ResponsePort::responderBind
void responderBind(RequestPort &request_port)
Called by the request port to bind.
Definition: port.cc:255
gem5::SlavePort
Definition: port.hh:529
gem5::ResponsePort::~ResponsePort
virtual ~ResponsePort()
Definition: port.cc:243
gem5::Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
gem5::TracingExtension::trace_
std::stack< std::string > trace_
Definition: port.hh:105
gem5::Tick
uint64_t Tick
Tick count type.
Definition: types.hh:58
gem5::AtomicRequestProtocol::send
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
gem5::ResponsePort::isSnooping
bool isSnooping() const
Find out if the peer request port is snooping or not.
Definition: port.hh:359
gem5::RequestPort::recvTimingSnoopReq
void recvTimingSnoopReq(PacketPtr pkt) override
Receive a timing snoop request from the peer.
Definition: port.hh:300
gem5::RequestPort::sendRetryResp
virtual void sendRetryResp()
Send a retry to the response port that previously attempted a sendTimingResp to this request port and...
Definition: port.hh:621
gem5::TracingExtension::TracingExtension
TracingExtension()=default
gem5::MasterPort
Definition: port.hh:316
timing.hh
gem5::RequestPort::isSnooping
virtual bool isSnooping() const
Determine if this request port is snooping or not.
Definition: port.hh:159
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::ResponsePort::sendTimingSnoopReq
void sendTimingSnoopReq(PacketPtr pkt)
Attempt to send a timing snoop request packet to the request port by calling its corresponding receiv...
Definition: port.hh:459
gem5::RequestPort::getAddrRanges
AddrRangeList getAddrRanges() const
Get the address ranges of the connected responder port.
Definition: port.cc:172
gem5::SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:146
gem5::TimingResponseProtocol
Definition: timing.hh:125
gem5::TimingRequestProtocol::sendSnoopResp
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
gem5::RequestPort::sendMemBackdoorReq
void sendMemBackdoorReq(const MemBackdoorReq &req, MemBackdoorPtr &backdoor)
Send a request for a back door to a range of memory.
Definition: port.hh:575
gem5::ResponsePort::recvMemBackdoorReq
void recvMemBackdoorReq(const MemBackdoorReq &req, MemBackdoorPtr &backdoor) override
Receive a request for a back door to a range of memory.
Definition: port.cc:273
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::TracingExtension
TracingExtension is an Extension of the Packet for recording the trace of the Packet.
Definition: port.hh:76
gem5::RiscvISA::succ
Bitfield< 23, 20 > succ
Definition: types.hh:90
port.hh
gem5::MemBackdoor
Definition: backdoor.hh:41
gem5::TimingRequestProtocol::trySend
bool trySend(TimingResponseProtocol *peer, PacketPtr pkt) const
Check if the peer can handle a timing request.
Definition: timing.cc:56
gem5::ResponsePort::ResponsePort
ResponsePort(const std::string &name, SimObject *_owner, PortID id=InvalidPortID)
Response port.
Definition: port.cc:218
gem5::ResponsePort::sendRangeChange
void sendRangeChange() const
Called by the owner to send a range change.
Definition: port.hh:364
gem5::AtomicRequestProtocol
Definition: atomic.hh:52
addr_range.hh
gem5::ResponsePort::bind
void bind(Port &peer) override
Attach to a peer port.
Definition: port.hh:379
gem5::ResponsePort::getAddrRanges
virtual AddrRangeList getAddrRanges() const =0
Get a list of the non-overlapping address ranges the owner is responsible for.
gem5::ResponsePort
A ResponsePort is a specialization of a port.
Definition: port.hh:331
gem5::ResponsePort::tryTiming
bool tryTiming(PacketPtr pkt) override
Availability request from the peer.
Definition: port.hh:517
gem5::ResponsePort::owner
SimObject & owner
Definition: port.hh:342
gem5::ArmISA::q
Bitfield< 27 > q
Definition: misc_types.hh:55
gem5::TracingExtension::add
void add(std::string request_port, std::string response_port)
Definition: port.hh:88
gem5::Port
Ports are used to interface objects to each other.
Definition: port.hh:61
gem5::AtomicRequestProtocol::sendBackdoor
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
gem5::FunctionalResponseProtocol::sendSnoop
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
gem5::RequestPort::removeTrace
void removeTrace(PacketPtr pkt) const
Definition: port.cc:204
gem5::RequestPort::_responsePort
ResponsePort * _responsePort
Definition: port.hh:124
gem5::ResponsePort::defaultBackdoorWarned
bool defaultBackdoorWarned
Definition: port.hh:339
gem5::TimingRequestProtocol::sendRetryResp
void sendRetryResp(TimingResponseProtocol *peer)
Send a retry to the peer that previously attempted a sendTimingResp to this protocol and failed.
Definition: timing.cc:72
gem5::Extension
This is the extension for carrying additional information.
Definition: extensible.hh:107
gem5::Port::UnboundPortException
Definition: port.hh:71
gem5::ResponsePort::sendAtomicSnoop
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:394
gem5::TimingRequestProtocol
Definition: timing.hh:51
std::list< AddrRange >
gem5::ResponsePort::recvAtomicBackdoor
Tick recvAtomicBackdoor(PacketPtr pkt, MemBackdoorPtr &backdoor) override
Default implementations.
Definition: port.cc:262
gem5::ResponsePort::recvTimingSnoopResp
bool recvTimingSnoopResp(PacketPtr pkt) override
Receive a timing snoop response from the peer.
Definition: port.hh:523
gem5::FunctionalRequestProtocol
Definition: functional.hh:52
gem5::RequestPort::owner
SimObject & owner
Definition: port.hh:127
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::RequestPort::recvAtomicSnoop
Tick recvAtomicSnoop(PacketPtr pkt) override
Default implementations.
Definition: port.hh:287
gem5::MemBackdoorReq
Definition: backdoor.hh:129
gem5::RequestPort::printAddr
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
gem5::RequestPort::sendTimingSnoopResp
bool sendTimingSnoopResp(PacketPtr pkt)
Attempt to send a timing snoop response packet to the response port by calling its corresponding rece...
Definition: port.hh:611
gem5::TimingResponseProtocol::sendSnoopReq
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
gem5::TracingExtension::remove
void remove()
Definition: port.hh:95
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:188

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