port.hh (13270:99e1cfb8c6e8) port.hh (13273:af60ddcf2a32)
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 * Authors: Gabe Black
28 */
29
30#ifndef __SYSTEMC_CORE_PORT_HH__
31#define __SYSTEMC_CORE_PORT_HH__
32
33#include <list>
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 * Authors: Gabe Black
28 */
29
30#ifndef __SYSTEMC_CORE_PORT_HH__
31#define __SYSTEMC_CORE_PORT_HH__
32
33#include <list>
34#include <typeinfo>
34#include <vector>
35
36#include "base/cprintf.hh"
37#include "systemc/ext/core/sc_interface.hh"
38#include "systemc/ext/core/sc_port.hh"
39
40namespace sc_gem5
41{
42
43class StaticSensitivityPort;
44class StaticSensitivityFinder;
45class ResetSensitivityPort;
46
47class Port;
48
49extern std::list<Port *> allPorts;
50
51class Port
52{
53 private:
54 ::sc_core::sc_port_base *portBase;
55
56 bool finalized;
57 int _maxSize;
58 int _size;
59
35#include <vector>
36
37#include "base/cprintf.hh"
38#include "systemc/ext/core/sc_interface.hh"
39#include "systemc/ext/core/sc_port.hh"
40
41namespace sc_gem5
42{
43
44class StaticSensitivityPort;
45class StaticSensitivityFinder;
46class ResetSensitivityPort;
47
48class Port;
49
50extern std::list<Port *> allPorts;
51
52class Port
53{
54 private:
55 ::sc_core::sc_port_base *portBase;
56
57 bool finalized;
58 int _maxSize;
59 int _size;
60
61 bool regPortNeeded;
62
60 void finalizePort(StaticSensitivityPort *port);
61 void finalizeFinder(StaticSensitivityFinder *finder);
62 void finalizeReset(ResetSensitivityPort *reset);
63
64 void
65 addInterface(::sc_core::sc_interface *iface)
66 {
67 for (int i = 0; i < _size; i++) {
68 if (getInterface(i) == iface) {
69 std::string msg =
70 csprintf("interface already bound to port: port '%s' (%s)",
71 portBase->name(), portBase->kind());
72 SC_REPORT_ERROR("(E107) bind interface to port failed",
73 msg.c_str());
74 }
75 }
76 _size++;
77 portBase->_gem5AddInterface(iface);
78 }
79
80 void
81 addInterfaces(::sc_core::sc_port_base *pb)
82 {
63 void finalizePort(StaticSensitivityPort *port);
64 void finalizeFinder(StaticSensitivityFinder *finder);
65 void finalizeReset(ResetSensitivityPort *reset);
66
67 void
68 addInterface(::sc_core::sc_interface *iface)
69 {
70 for (int i = 0; i < _size; i++) {
71 if (getInterface(i) == iface) {
72 std::string msg =
73 csprintf("interface already bound to port: port '%s' (%s)",
74 portBase->name(), portBase->kind());
75 SC_REPORT_ERROR("(E107) bind interface to port failed",
76 msg.c_str());
77 }
78 }
79 _size++;
80 portBase->_gem5AddInterface(iface);
81 }
82
83 void
84 addInterfaces(::sc_core::sc_port_base *pb)
85 {
86 // Only the ports farthest from the interfaces call register_port.
87 pb->_gem5Port->regPortNeeded = false;
83 for (int i = 0; i < pb->size(); i++)
84 addInterface(pb->_gem5Interface(i));
85 }
86
87 ::sc_core::sc_interface *
88 getInterface(int i)
89 {
90 return portBase->_gem5Interface(i);
91 }
92
93 struct Binding
94 {
95 explicit Binding(::sc_core::sc_interface *interface) :
96 interface(interface), port(nullptr)
97 {}
98
99 explicit Binding(::sc_core::sc_port_base *port) :
100 interface(nullptr), port(port)
101 {}
102
103 ::sc_core::sc_interface *interface;
104 ::sc_core::sc_port_base *port;
105 };
106
107 struct Sensitivity
108 {
109 Sensitivity(StaticSensitivityPort *port) :
110 port(port), finder(nullptr), reset(nullptr)
111 {}
112
113 Sensitivity(StaticSensitivityFinder *finder) :
114 port(nullptr), finder(finder), reset(nullptr)
115 {}
116
117 Sensitivity(ResetSensitivityPort *reset) :
118 port(nullptr), finder(nullptr), reset(reset)
119 {}
120
121 StaticSensitivityPort *port;
122 StaticSensitivityFinder *finder;
123 ResetSensitivityPort *reset;
124 };
125
126 std::vector<Binding *> bindings;
127 std::vector<Sensitivity *> sensitivities;
128
129 public:
130 static Port *
131 fromPort(const ::sc_core::sc_port_base *pb)
132 {
133 return pb->_gem5Port;
134 }
135
136 ::sc_core::sc_port_base *sc_port_base() { return portBase; }
137
138 Port(::sc_core::sc_port_base *port_base, int max) :
88 for (int i = 0; i < pb->size(); i++)
89 addInterface(pb->_gem5Interface(i));
90 }
91
92 ::sc_core::sc_interface *
93 getInterface(int i)
94 {
95 return portBase->_gem5Interface(i);
96 }
97
98 struct Binding
99 {
100 explicit Binding(::sc_core::sc_interface *interface) :
101 interface(interface), port(nullptr)
102 {}
103
104 explicit Binding(::sc_core::sc_port_base *port) :
105 interface(nullptr), port(port)
106 {}
107
108 ::sc_core::sc_interface *interface;
109 ::sc_core::sc_port_base *port;
110 };
111
112 struct Sensitivity
113 {
114 Sensitivity(StaticSensitivityPort *port) :
115 port(port), finder(nullptr), reset(nullptr)
116 {}
117
118 Sensitivity(StaticSensitivityFinder *finder) :
119 port(nullptr), finder(finder), reset(nullptr)
120 {}
121
122 Sensitivity(ResetSensitivityPort *reset) :
123 port(nullptr), finder(nullptr), reset(reset)
124 {}
125
126 StaticSensitivityPort *port;
127 StaticSensitivityFinder *finder;
128 ResetSensitivityPort *reset;
129 };
130
131 std::vector<Binding *> bindings;
132 std::vector<Sensitivity *> sensitivities;
133
134 public:
135 static Port *
136 fromPort(const ::sc_core::sc_port_base *pb)
137 {
138 return pb->_gem5Port;
139 }
140
141 ::sc_core::sc_port_base *sc_port_base() { return portBase; }
142
143 Port(::sc_core::sc_port_base *port_base, int max) :
139 portBase(port_base), finalized(false), _maxSize(max), _size(0)
144 portBase(port_base), finalized(false), _maxSize(max), _size(0),
145 regPortNeeded(true)
140 {
141 allPorts.push_front(this);
142 }
143
144 void
145 bind(::sc_core::sc_interface *interface)
146 {
147 if (bindings.empty())
148 addInterface(interface);
149 else
150 bindings.push_back(new Binding(interface));
151 }
152
153 void
154 bind(::sc_core::sc_port_base *port)
155 {
156 bindings.push_back(new Binding(port));
157 }
158
159 void sensitive(StaticSensitivityPort *port);
160 void sensitive(StaticSensitivityFinder *finder);
161 void sensitive(ResetSensitivityPort *reset);
162
163 void finalize();
146 {
147 allPorts.push_front(this);
148 }
149
150 void
151 bind(::sc_core::sc_interface *interface)
152 {
153 if (bindings.empty())
154 addInterface(interface);
155 else
156 bindings.push_back(new Binding(interface));
157 }
158
159 void
160 bind(::sc_core::sc_port_base *port)
161 {
162 bindings.push_back(new Binding(port));
163 }
164
165 void sensitive(StaticSensitivityPort *port);
166 void sensitive(StaticSensitivityFinder *finder);
167 void sensitive(ResetSensitivityPort *reset);
168
169 void finalize();
170 void regPort();
164
165 int size() { return _size; }
166 int maxSize() { return _maxSize; }
167};
168
169} // namespace sc_gem5
170
171#endif // __SYSTEMC_CORE_PORT_HH__
171
172 int size() { return _size; }
173 int maxSize() { return _maxSize; }
174};
175
176} // namespace sc_gem5
177
178#endif // __SYSTEMC_CORE_PORT_HH__