Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | // ========== Copyright Header Begin ========================================== |
2 | // | |
3 | // OpenSPARC T2 Processor File: csr_if_port.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_if_port_hpp__ | |
36 | #define INC_csr_if_port_hpp__ | |
37 | ||
38 | #include <systemc.h> | |
39 | ||
40 | #include "pcie_common/csr_if.hpp" | |
41 | #include "pcie_common/logger.hpp" | |
42 | ||
43 | #include "tlm.h" | |
44 | ||
45 | #define CSR_ADDR_T sc_uint<32> | |
46 | #define CSR_DATA_T sc_uint<64> | |
47 | ||
48 | namespace pcie { | |
49 | USING_NAMESPACE(tlm); | |
50 | USING_NAMESPACE(Logger); | |
51 | ||
52 | /** Port definition for the CSR DB interface */ | |
53 | ||
54 | template < typename ADDR, typename DATA, int N = 1> | |
55 | class csr_if_port : | |
56 | public sc_port< tlm_transport_if < csr_req <ADDR, DATA> , csr_rsp <DATA> > , N > , | |
57 | public virtual csr_if< ADDR, DATA > | |
58 | { | |
59 | public: | |
60 | typedef tlm_transport_if < csr_req <ADDR, DATA>, csr_rsp <DATA> > if_type; | |
61 | ||
62 | csr_if_port( const char* port_name ) : sc_port< if_type, N > (port_name) | |
63 | { | |
64 | } | |
65 | ||
66 | ||
67 | virtual bool is_mapped(const ADDR reg_addr) { | |
68 | csr_req <ADDR, DATA> req; | |
69 | csr_rsp <DATA> rsp; | |
70 | ||
71 | req._cmd = CSR_ISMAPPED; | |
72 | req._addr = reg_addr; | |
73 | rsp = (*this)->transport(req); | |
74 | LOG_DEBUG << "IS_MAPPED (" << name() << ") Addr: " << reg_addr | |
75 | << " Response: " << (rsp._is_mapped ? "true" : "false"); | |
76 | ||
77 | return rsp._is_mapped; | |
78 | } | |
79 | ||
80 | virtual DATA read_csr(const ADDR addr) { | |
81 | ||
82 | csr_req <ADDR, DATA> req; | |
83 | csr_rsp <DATA> rsp; | |
84 | ||
85 | req._cmd = CSR_READ; | |
86 | req._addr = addr; | |
87 | req._read_clear = false; | |
88 | ||
89 | ||
90 | LOG_DEBUG << "READ_CSR ( " << name() << ") Addr : " << addr << "\n"; | |
91 | rsp = (*this)->transport(req); | |
92 | LOG_DEBUG << "READ_CSR ( " << name() << ") Addr : " << addr | |
93 | << " Data returned : " << rsp._data << " \n"; | |
94 | return rsp._data; | |
95 | } | |
96 | ||
97 | ||
98 | virtual DATA write_csr(const ADDR addr, const DATA data) { | |
99 | ||
100 | csr_req <ADDR, DATA> req; | |
101 | csr_rsp <DATA> rsp; | |
102 | ||
103 | req._cmd = CSR_WRITE; | |
104 | req._addr = addr; | |
105 | req._data = data; | |
106 | ||
107 | ||
108 | LOG_DEBUG << "WRITE_CSR ( " << name() << ") Addr : " << addr << "\n"; | |
109 | rsp = (*this)->transport(req); | |
110 | LOG_DEBUG << "WRITE_CSR ( " << name() << ") Addr : " << addr | |
111 | << " Data returned : " << rsp._data << " \n"; | |
112 | return rsp._data; | |
113 | } | |
114 | ||
115 | virtual DATA write_csr_mask(const ADDR addr, const DATA data, const DATA fld_mask) { | |
116 | ||
117 | csr_req <ADDR, DATA> req; | |
118 | csr_rsp <DATA> rsp; | |
119 | ||
120 | req._cmd = CSR_WRITE_MASK; | |
121 | req._addr = addr; | |
122 | req._data = data; | |
123 | req._fld_mask = fld_mask; | |
124 | ||
125 | ||
126 | LOG_DEBUG << "WRITE_CSR ( " << name() << ") Addr : " << addr << "\n"; | |
127 | rsp = (*this)->transport(req); | |
128 | LOG_DEBUG << "WRITE_CSR ( " << name() << ") Addr : " << addr | |
129 | << " Data returned : " << rsp._data << " \n"; | |
130 | return rsp._data; | |
131 | } | |
132 | ||
133 | ||
134 | ||
135 | virtual void set_notify_event(ADDR reg_addr, sc_event* event_handle) { | |
136 | csr_req <ADDR, DATA> req; | |
137 | csr_rsp <DATA> rsp; | |
138 | ||
139 | req._cmd = CSR_SETEVENT; | |
140 | req._addr = reg_addr; | |
141 | req._event = event_handle; | |
142 | rsp = (*this)->transport(req); | |
143 | } | |
144 | ||
145 | virtual void reset_csr_db() { | |
146 | csr_req <ADDR, DATA> req; | |
147 | csr_rsp <DATA> rsp; | |
148 | ||
149 | LOG_DEBUG << "RESET_CSR_DB() "; | |
150 | ||
151 | req._cmd = CSR_RESET; | |
152 | rsp = (*this)->transport(req); | |
153 | LOG_DEBUG << "RESET_CSR_DB() .. returned"; | |
154 | } | |
155 | ||
156 | virtual void create_csr_db() { | |
157 | csr_req <ADDR, DATA> req; | |
158 | csr_rsp <DATA> rsp; | |
159 | ||
160 | LOG_DEBUG << "Create_CSR_DB() "; | |
161 | ||
162 | req._cmd = CSR_CREATE; | |
163 | rsp = (*this)->transport(req); | |
164 | LOG_DEBUG << "Create_CSR_DB() .. returned"; | |
165 | } | |
166 | ||
167 | }; | |
168 | ||
169 | ||
170 | ||
171 | } // namespace pcie | |
172 | ||
173 | ||
174 | #endif // INC_csr_if_port_hpp__ |