Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / verif / model / vendor / TLM-2006-11-29 / tlm / tlm_ports / tlm_initiator_port_base.h
CommitLineData
86530b38
AT
1/*****************************************************************************
2
3 The following code is derived, directly or indirectly, from the SystemC
4 source code Copyright (c) 1996-2004 by all Contributors.
5 All Rights reserved.
6
7 The contents of this file are subject to the restrictions and limitations
8 set forth in the SystemC Open Source License Version 2.4 (the "License");
9 You may not use this file except in compliance with such restrictions and
10 limitations. You may obtain instructions on how to receive a copy of the
11 License at http://www.systemc.org/. Software distributed by Contributors
12 under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
13 ANY KIND, either express or implied. See the License for the specific
14 language governing rights and limitations under the License.
15
16 *****************************************************************************/
17
18
19#ifndef _TLM_INITIATOR_PORT_BASE_H_
20#define _TLM_INITIATOR_PORT_BASE_H_
21
22
23/*------------------------------------------------------------------------------
24 * Includes
25 *----------------------------------------------------------------------------*/
26#include <vector>
27
28#include "systemc.h"
29
30#include "tlm_ports/tlm_target_port_base.h"
31
32
33 //----------------------------------------------------------------------------
34 /// Class tlm_initiator_port_base: This class is a base class for tlm_initiator port.
35 /**
36 * \n It provides a container to store registered target ports as pointer list (required for target port ID propagation and
37 * transaction recording).
38 * \n It provides also two containers to store registered initiator ports as pointer list:
39 * - The first container registers initiator port from "deeper" initiator port to the the initiator
40 * port directly bound to the interface.
41 * - The second list, named reversed list, allows the port directly bound to the interface to propagate its target
42 * port list to "deeper" initiator ports.
43 *
44 * \n Accessors are provided for all the port lists.
45 **/
46 //----------------------------------------------------------------------------
47 class tlm_initiator_port_base {
48
49 typedef tlm_initiator_port_base this_type;
50 typedef tlm_target_port_base target_port_type;
51
52 public:
53
54 //--------------
55 // Constructor
56 //--------------
57 tlm_initiator_port_base() {
58 // Adds the port itself to the reversed initiator port list
59 m_reversed_initiator_port_list.push_back(this);
60 }
61
62
63 //------------------------------------------
64 /// @name Data members access methods
65 //------------------------------------------
66 /// @{
67
68 /// Register the target port
69 inline void register_target_port(target_port_type * target_port) {
70 m_target_port_list.push_back(target_port);
71 }
72
73 /// Returns the vector of registered target port(s)
74 inline std::vector<target_port_type *>& get_target_port_list() {
75 return(m_target_port_list);
76 }
77
78 /// Sets the vector of registered target port(s) (port propagation)
79 inline void set_target_port_list(std::vector<target_port_type *>& target_port_list) {
80 m_target_port_list = target_port_list;
81 }
82
83 //---------------------------------------------------------------------------
84
85 /// Register the initiator port in the regular list
86 inline void register_initiator_port(this_type * initiator_port) {
87 m_initiator_port_list.push_back(initiator_port);
88 }
89
90 /// Returns the vector of registered initiator port(s)
91 inline std::vector<this_type *>& get_initiator_port_list() {
92 return(m_initiator_port_list);
93 }
94
95 /// Sets the vector of registered initiator port(s) (port propagation)
96 inline void set_initiator_port_list(std::vector<this_type *>& initiator_port_list) {
97 m_initiator_port_list = initiator_port_list;
98 }
99
100 //---------------------------------------------------------------------------
101
102 /// Register the initiator port in the reversed list
103 inline void reversed_register_initiator_port(this_type * initiator_port) {
104 m_reversed_initiator_port_list.push_back(initiator_port);
105 }
106
107 /// Returns the vector of registered initiator port(s), reversed list
108 inline std::vector<this_type *>& get_reversed_initiator_port_list() {
109 return(m_reversed_initiator_port_list);
110 }
111
112 /// Sets the vector of registered initiator port(s) (port propagation) reversed list
113 inline void set_reversed_initiator_port_list(std::vector<this_type *>& initiator_port_list) {
114 m_reversed_initiator_port_list = initiator_port_list;
115 }
116
117 /// @}
118
119
120 protected:
121
122 /// sc_export objects registration
123 /**
124 * Direct registration of the bound target port(s) into current initiator port
125 **/
126 std::vector<target_port_type *> m_target_port_list;
127
128
129 /// sc_port objects registration
130 /**
131 * Direct registration of the bound initiator port into current initiator port
132 **/
133 std::vector<this_type *> m_initiator_port_list;
134
135 /// sc_port objects registration
136 /**
137 * Direct registration of the current initiator port into the bound initiator port for
138 * port propagation: all bound initiator ports get back the same target_port_list
139 **/
140 std::vector<this_type *> m_reversed_initiator_port_list;
141
142 /// Creates the initiator port list from a non NULL initiator_port_type * list
143 /** Reentreant function to create the complete list of bound initiator_port
144 **/
145 void create_port_list(std::vector<this_type *>& port_list) {
146 assert(port_list.size() > 0);
147 this_type& current_port = *port_list[(port_list.size()-1)];
148 // For all the registed initiator port of the port
149 for (int i=0;i<(int)current_port.get_initiator_port_list().size();i++) {
150 // register only other ports (the list contains the port itself)
151 if (static_cast<this_type *>(&current_port) != current_port.get_initiator_port_list()[i]) {
152 port_list.push_back(current_port.get_initiator_port_list()[i]); // register port
153 this->create_port_list(port_list); // find again in the updated port list
154 }
155 }
156 }
157
158
159 };
160
161#endif /* _TLM_INITIATOR_PORT_BASE_H_ */
162
163