Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | // ========== Copyright Header Begin ========================================== |
2 | // | |
3 | // OpenSPARC T2 Processor File: csr_arb.hpp | |
4 | // Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved | |
5 | // 4150 Network Circle, Santa Clara, California 95054, U.S.A. | |
6 | // | |
7 | // * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
8 | // | |
9 | // This program is free software; you can redistribute it and/or modify | |
10 | // it under the terms of the GNU General Public License as published by | |
11 | // the Free Software Foundation; version 2 of the License. | |
12 | // | |
13 | // This program is distributed in the hope that it will be useful, | |
14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | // GNU General Public License for more details. | |
17 | // | |
18 | // You should have received a copy of the GNU General Public License | |
19 | // along with this program; if not, write to the Free Software | |
20 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 | // | |
22 | // For the avoidance of doubt, and except that if any non-GPL license | |
23 | // choice is available it will apply instead, Sun elects to use only | |
24 | // the General Public License version 2 (GPLv2) at this time for any | |
25 | // software where a choice of GPL license versions is made | |
26 | // available with the language indicating that GPLv2 or any later version | |
27 | // may be used, or where a choice of which version of the GPL is applied is | |
28 | // otherwise unspecified. | |
29 | // | |
30 | // Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
31 | // CA 95054 USA or visit www.sun.com if you need additional information or | |
32 | // have any questions. | |
33 | // | |
34 | // ========== Copyright Header End ============================================ | |
35 | #ifndef INC_csr_arb_hpp__ | |
36 | #define INC_csr_arb_hpp__ | |
37 | ||
38 | #include "pcie_common/config.hpp" | |
39 | #include <queue> | |
40 | ||
41 | USING_NAMESPACE(std); | |
42 | using std::pair; | |
43 | ||
44 | #include "tlm.h" | |
45 | using tlm::tlm_transport_if; | |
46 | using tlm::tlm_slave_if; | |
47 | ||
48 | namespace pcie | |
49 | { | |
50 | template < typename REQ , typename RSP , int N =1> | |
51 | class csr_arb : public sc_module | |
52 | { | |
53 | public: | |
54 | typedef sc_port< tlm_slave_if< REQ , RSP > > port_type; | |
55 | ||
56 | port_type master_port[N]; | |
57 | ||
58 | sc_port< tlm_transport_if< REQ , RSP > , 1 > slave_port; | |
59 | ||
60 | sc_in< bool > csr_clock; | |
61 | ||
62 | SC_HAS_PROCESS( csr_arb ); | |
63 | ||
64 | csr_arb( sc_module_name module_name , | |
65 | const sc_time &t = sc_time( 1 , SC_NS ) ) : | |
66 | sc_module( module_name ) , | |
67 | slave_port("slave_port") , | |
68 | arb_t( t ) | |
69 | { | |
70 | LOG_DEBUG << "csr_arb()"; | |
71 | SC_THREAD( run ); | |
72 | } | |
73 | ||
74 | void add_interface( port_type *port , const int priority ) { | |
75 | if_map.insert( multimap_type::value_type( priority , port ) ); | |
76 | } | |
77 | ||
78 | protected: | |
79 | typedef multimap< int , port_type * > multimap_type; | |
80 | multimap_type if_map; | |
81 | ||
82 | typedef struct { | |
83 | REQ req; | |
84 | port_type *port; | |
85 | } req_port_type; | |
86 | ||
87 | queue < req_port_type* > event_q, read_q, write_q; | |
88 | ||
89 | sc_time arb_t; | |
90 | ||
91 | virtual void run() { | |
92 | req_port_type *next_rp; | |
93 | RSP rsp; | |
94 | LOG_DEBUG << "csr_arb::run()"; | |
95 | for( ;; ) { | |
96 | wait( csr_clock.posedge_event() ); | |
97 | ||
98 | gather_requests (); | |
99 | // Process setup requests | |
100 | while (!event_q.empty()) { | |
101 | next_rp = event_q.front(); | |
102 | event_q.pop(); | |
103 | //LOG_DEBUG << "Calling Event Req : " << next_rp->port->name(); | |
104 | rsp = slave_port->transport((next_rp->req)); | |
105 | //LOG_DEBUG << "Putting Event Req : " << next_rp->port->name(); | |
106 | (*(next_rp->port))->put(rsp); | |
107 | //LOG_DEBUG << "Putting Event Req (done): " << next_rp->port->name(); | |
108 | delete next_rp; | |
109 | //LOG_DEBUG << "Delete ReqPacket"; | |
110 | } | |
111 | while (!write_q.empty()) { | |
112 | next_rp = write_q.front(); | |
113 | write_q.pop(); | |
114 | //LOG_DEBUG << "Calling Write Req"; | |
115 | rsp = slave_port->transport((next_rp->req)); | |
116 | //LOG_DEBUG << "Putting Write Req"; | |
117 | (*(next_rp->port))->put(rsp); | |
118 | delete next_rp; | |
119 | //LOG_DEBUG << "Delete ReqPacket"; | |
120 | ||
121 | } | |
122 | while (!read_q.empty()) { | |
123 | next_rp = read_q.front(); | |
124 | read_q.pop(); | |
125 | //LOG_DEBUG << "Calling Read Req"; | |
126 | rsp = slave_port->transport((next_rp->req)); | |
127 | //LOG_DEBUG << "Putting Read Req"; | |
128 | (*(next_rp->port))->put(rsp); | |
129 | delete next_rp; | |
130 | //LOG_DEBUG << "Delete ReqPacket"; | |
131 | } | |
132 | }//end for(;;) | |
133 | }//end run() | |
134 | ||
135 | virtual void gather_requests () { | |
136 | multimap_type::iterator i; | |
137 | port_type *p; | |
138 | REQ req; | |
139 | req_port_type *rp; | |
140 | ||
141 | for (i = if_map.begin(); i != if_map.end(); ++i) { | |
142 | p = (*i).second; | |
143 | if ( (*p)->nb_get(req) ) { | |
144 | rp = new req_port_type; | |
145 | //LOG_DEBUG << "NEW ReqPacket"; | |
146 | rp->req = req; | |
147 | rp->port = p; | |
148 | ||
149 | switch (rp->req._cmd) { | |
150 | case CSR_RESET: | |
151 | LOG_DEBUG << "CSR_RESET : " << rp->port->name(); | |
152 | event_q.push(rp); | |
153 | break; | |
154 | case CSR_CREATE: | |
155 | LOG_DEBUG << "CSR_CREATE : " << rp->port->name(); | |
156 | event_q.push(rp); | |
157 | break; | |
158 | case CSR_SETEVENT: | |
159 | LOG_DEBUG << "CSR_SETEVENT : " << rp->port->name(); | |
160 | event_q.push(rp); | |
161 | break; | |
162 | case CSR_ISMAPPED: | |
163 | LOG_DEBUG << "CSR_ISMAPPED: " << rp->port->name(); | |
164 | read_q.push(rp); | |
165 | break; | |
166 | case CSR_READ: | |
167 | LOG_DEBUG << "CSR_READ: " << rp->port->name(); | |
168 | read_q.push(rp); | |
169 | break; | |
170 | case CSR_WRITE: | |
171 | LOG_DEBUG << "CSR_WRITE : " << rp->port->name(); | |
172 | write_q.push(rp); | |
173 | break; | |
174 | case CSR_WRITE_MASK: | |
175 | LOG_DEBUG << "CSR_WRITE_FIELD : " << rp->port->name(); | |
176 | write_q.push(rp); | |
177 | break; | |
178 | } | |
179 | } | |
180 | } | |
181 | }//end gather_requests() | |
182 | }; | |
183 | }; | |
184 | #endif //INC_csr_arb_hpp__ |