gem5  v22.1.0.0
port.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2018 Google, Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met: redistributions of source code must retain the above copyright
7  * notice, this list of conditions and the following disclaimer;
8  * redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution;
11  * neither the name of the copyright holders nor the names of its
12  * contributors may be used to endorse or promote products derived from
13  * this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef __SYSTEMC_CORE_PORT_HH__
29 #define __SYSTEMC_CORE_PORT_HH__
30 
31 #include <list>
32 #include <typeinfo>
33 #include <vector>
34 
35 #include "base/cprintf.hh"
38 
39 namespace sc_gem5
40 {
41 
42 class StaticSensitivityPort;
43 class StaticSensitivityFinder;
44 class Reset;
45 
46 class Port;
47 
49 
50 class Port
51 {
52  private:
54 
55  bool finalized;
56  int _maxSize;
57  int _size;
58 
60 
63  void finalizeReset(Reset *reset);
64 
65  void
67  {
69  _size++;
70  }
71 
72  void
74  {
75  // Only the ports farthest from the interfaces call register_port.
76  pb->_gem5Port->regPortNeeded = false;
77  for (int i = 0; i < pb->size(); i++)
79  }
80 
83  {
84  return portBase->_gem5Interface(i);
85  }
86 
87  struct Binding
88  {
90  interface(interface), port(nullptr)
91  {}
92 
94  interface(nullptr), port(port)
95  {}
96 
99  };
100 
101  struct Sensitivity
102  {
104  port(port), finder(nullptr)
105  {}
106 
108  port(nullptr), finder(finder)
109  {}
110 
113  };
114 
118 
119  public:
120  static Port *
121  fromPort(const ::sc_core::sc_port_base *pb)
122  {
123  return pb->_gem5Port;
124  }
125 
127 
128  Port(::sc_core::sc_port_base *port_base, int max) :
129  portBase(port_base), finalized(false), _maxSize(max), _size(0),
130  regPortNeeded(true)
131  {
132  allPorts.push_front(this);
133  }
134 
135  ~Port() { allPorts.remove(this); }
136 
137  void
139  {
140  if (bindings.empty())
141  addInterface(interface);
142  else
143  bindings.push_back(new Binding(interface));
144  }
145 
146  void
148  {
149  bindings.push_back(new Binding(port));
150  }
151 
152  void sensitive(StaticSensitivityPort *port);
153  void sensitive(StaticSensitivityFinder *finder);
154  void addReset(Reset *reset);
155 
156  void finalize();
157  void regPort();
158 
159  int size() { return _size; }
160  int maxSize() { return _maxSize ? _maxSize : _size; }
161 };
162 
163 } // namespace sc_gem5
164 
165 #endif // __SYSTEMC_CORE_PORT_HH__
virtual void _gem5AddInterface(sc_interface *i)=0
::sc_gem5::Port * _gem5Port
Definition: sc_port.hh:112
virtual sc_interface * _gem5Interface(int n) const =0
int size() const
Definition: sc_port.cc:107
void addInterface(::sc_core::sc_interface *iface)
Definition: port.hh:66
void finalize()
Definition: port.cc:94
void bind(::sc_core::sc_interface *interface)
Definition: port.hh:138
::sc_core::sc_port_base * portBase
Definition: port.hh:53
void bind(::sc_core::sc_port_base *port)
Definition: port.hh:147
std::vector< Reset * > resets
Definition: port.hh:117
void finalizePort(StaticSensitivityPort *port)
Definition: port.cc:40
int _maxSize
Definition: port.hh:56
int maxSize()
Definition: port.hh:160
void finalizeFinder(StaticSensitivityFinder *finder)
Definition: port.cc:47
::sc_core::sc_port_base * sc_port_base()
Definition: port.hh:126
Port(::sc_core::sc_port_base *port_base, int max)
Definition: port.hh:128
void addReset(Reset *reset)
Definition: port.cc:85
::sc_core::sc_interface * getInterface(int i)
Definition: port.hh:82
int _size
Definition: port.hh:57
std::vector< Binding * > bindings
Definition: port.hh:115
void addInterfaces(::sc_core::sc_port_base *pb)
Definition: port.hh:73
std::vector< Sensitivity * > sensitivities
Definition: port.hh:116
bool finalized
Definition: port.hh:55
void sensitive(StaticSensitivityPort *port)
Definition: port.cc:67
void finalizeReset(Reset *reset)
Definition: port.cc:54
int size()
Definition: port.hh:159
static Port * fromPort(const ::sc_core::sc_port_base *pb)
Definition: port.hh:121
bool regPortNeeded
Definition: port.hh:59
void regPort()
Definition: port.cc:158
STL list class.
Definition: stl.hh:51
STL vector class.
Definition: stl.hh:37
Bitfield< 7 > i
Definition: misc_types.hh:67
@ Reset
Definition: types.hh:70
std::list< Port * > allPorts
Definition: port.cc:167
Binding(::sc_core::sc_interface *interface)
Definition: port.hh:89
::sc_core::sc_interface * interface
Definition: port.hh:97
Binding(::sc_core::sc_port_base *port)
Definition: port.hh:93
::sc_core::sc_port_base * port
Definition: port.hh:98
Sensitivity(StaticSensitivityPort *port)
Definition: port.hh:103
StaticSensitivityPort * port
Definition: port.hh:111
StaticSensitivityFinder * finder
Definition: port.hh:112
Sensitivity(StaticSensitivityFinder *finder)
Definition: port.hh:107

Generated on Wed Dec 21 2022 10:22:37 for gem5 by doxygen 1.9.1