Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | // ========== Copyright Header Begin ========================================== |
2 | // | |
3 | // OpenSPARC T2 Processor File: peu_csr.cpp | |
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 | #include "peu_csr.hpp" | |
36 | #include "pcie_common/logger.hpp" | |
37 | ||
38 | namespace pcie { | |
39 | ||
40 | /// Init start the CSR Ring intf | |
41 | void peu_csr::init(void) { | |
42 | ring_data_out.write(0x00); | |
43 | csr_port.create_csr_db(); | |
44 | for ( ; ; ) { | |
45 | ring_data_out.write(0x00); | |
46 | LOG_DEBUG << "PEU_CSR::CREATE CSR()\n"; | |
47 | csr_port.reset_csr_db(); | |
48 | LOG_DEBUG << "PEU_CSR::CREATE CSR() DONE\n"; | |
49 | ||
50 | wait (rst_l.posedge_event()); | |
51 | } | |
52 | } | |
53 | ||
54 | /// Read the incoming CSR ring request packet | |
55 | void peu_csr::read_csr_ring(void) { | |
56 | ||
57 | csr_pkt *nxt_rng_req; | |
58 | sc_uint<CSR_RING_WDTH> data_in; | |
59 | ||
60 | for ( ; ; ) { | |
61 | ||
62 | wait (csr_if_clk.negedge_event()); | |
63 | data_in = ring_data_in.read().to_uint(); | |
64 | if (data_in(CSR_RING_CMND_BITS) != 0) { | |
65 | ||
66 | /// Read CSR Ring cycle 1 | |
67 | nxt_rng_req = new csr_pkt; | |
68 | nxt_rng_req->cmd = data_in(CSR_RING_CMND_BITS); | |
69 | nxt_rng_req->srcb = data_in(CSR_RING_SRCB_BITS); | |
70 | nxt_rng_req->addr = data_in(CSR_RING_ADDR_BITS); | |
71 | ||
72 | /// Read CSR Ring cycle 2 | |
73 | wait (csr_if_clk.negedge_event()); | |
74 | data_in = ring_data_in.read(); | |
75 | nxt_rng_req->data(CSR_RDMS_BITS) = data_in; | |
76 | ||
77 | /// Read CSR Ring cycle 3 | |
78 | wait (csr_if_clk.negedge_event()); | |
79 | data_in = ring_data_in.read(); | |
80 | nxt_rng_req->data(CSR_RDLS_BITS) = data_in; | |
81 | ||
82 | LOG_DEBUG << "CSR Ring In: " | |
83 | << ((nxt_rng_req->cmd == CSR_CMND_WREQ) ? "WRITE: " : | |
84 | (nxt_rng_req->cmd == CSR_CMND_RREQ) ? "READ: " : "UnKnown Cmd:" ) | |
85 | << ", Addr: " << nxt_rng_req->addr | |
86 | << ", SrcBus: " << nxt_rng_req->srcb << ", Data: " << nxt_rng_req->data; | |
87 | ring_in_q.push(nxt_rng_req); | |
88 | } | |
89 | } // for ever | |
90 | } // peu_csr::read_csr_ring | |
91 | ||
92 | ||
93 | /// Write the CSR Ring packet on the out bus | |
94 | void peu_csr::write_csr_ring(void) { | |
95 | ||
96 | csr_pkt* rng_rsp; | |
97 | sc_uint<CSR_RING_WDTH> data_out; | |
98 | ||
99 | for ( ; ; ) { | |
100 | wait (csr_if_clk.posedge_event()); | |
101 | ||
102 | if (!(ring_out_q.empty())) { | |
103 | rng_rsp = ring_out_q.front(); | |
104 | ring_out_q.pop(); | |
105 | LOG_DEBUG << "CSR Ring Out: " | |
106 | << ((rng_rsp->cmd == CSR_CMND_WREQ) ? "WRITE: " : | |
107 | (rng_rsp->cmd == CSR_CMND_RREQ) ? "READ: " : | |
108 | (rng_rsp->cmd == CSR_CMND_RRSP) ? "READ RSP: " : | |
109 | (rng_rsp->cmd == CSR_CMND_WRSP) ? "WRITE RSP: " : "UnKnown CMD") | |
110 | << ", Addr: " << rng_rsp->addr | |
111 | << ", SrcBus: " << rng_rsp->srcb << ", Data: " << rng_rsp->data; | |
112 | ||
113 | data_out(CSR_RING_CMND_BITS) = rng_rsp->cmd; | |
114 | data_out(CSR_RING_SRCB_BITS) = rng_rsp->srcb; | |
115 | data_out(CSR_RING_ADDR_BITS) = rng_rsp->addr; | |
116 | ring_data_out.write(data_out); | |
117 | ||
118 | wait (csr_if_clk.posedge_event()); | |
119 | data_out = rng_rsp->data(CSR_RDMS_BITS); | |
120 | ring_data_out.write(data_out); | |
121 | ||
122 | wait (csr_if_clk.posedge_event()); | |
123 | data_out = rng_rsp->data(CSR_RDLS_BITS); | |
124 | ring_data_out.write(data_out); | |
125 | ||
126 | data_out = 0x0; | |
127 | wait (csr_if_clk.posedge_event()); | |
128 | ring_data_out.write(data_out); | |
129 | delete rng_rsp; | |
130 | ||
131 | } | |
132 | } | |
133 | } // write_csr_ring() | |
134 | ||
135 | ||
136 | void peu_csr::process_ring_req() { | |
137 | ||
138 | csr_pkt *nxt_req; | |
139 | csr_pkt *nxt_rsp; | |
140 | ||
141 | LOG_DEBUG << "> PEU_CSR:: process_ring_req()"; | |
142 | ||
143 | for ( ; ; ) { | |
144 | wait (csr_if_clk.negedge_event()); | |
145 | if (!(ring_in_q.empty())) { | |
146 | nxt_req = ring_in_q.front(); | |
147 | ring_in_q.pop(); | |
148 | nxt_rsp = new csr_pkt; | |
149 | nxt_rsp->is_rsp = true; | |
150 | nxt_rsp->cmd = nxt_req->cmd; | |
151 | nxt_rsp->srcb = nxt_req->srcb; | |
152 | nxt_rsp->addr = nxt_req->addr; | |
153 | nxt_rsp->data = nxt_req->data; | |
154 | ring_out_q.push(nxt_req); | |
155 | ||
156 | switch (nxt_rsp->cmd) { | |
157 | case CSR_CMND_WREQ: | |
158 | if (csr_port.is_mapped(nxt_rsp->addr)) { | |
159 | nxt_rsp->data = csr_port.write_csr(nxt_rsp->addr, nxt_rsp->data); | |
160 | nxt_rsp->cmd = CSR_CMND_WRSP; | |
161 | ring_out_q.push(nxt_rsp); | |
162 | } | |
163 | break; | |
164 | ||
165 | case CSR_CMND_RREQ: | |
166 | if (csr_port.is_mapped(nxt_rsp->addr)) { | |
167 | nxt_rsp->data = csr_port.read_csr(nxt_rsp->addr); | |
168 | nxt_rsp->cmd = CSR_CMND_RRSP; | |
169 | ring_out_q.push(nxt_rsp); | |
170 | } | |
171 | break; | |
172 | default: | |
173 | LOG_WARNING << "CSR Packet with Unsupported CMD: " << nxt_rsp->cmd; | |
174 | } | |
175 | } | |
176 | } | |
177 | } // process_ring_req() | |
178 | ||
179 | } // namespace pcie |