Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | // ========== Copyright Header Begin ========================================== |
2 | // | |
3 | // OpenSPARC T2 Processor File: dmu_imu_gcs_gc_fsm.v | |
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 | module dmu_imu_gcs_gc_fsm ( | |
36 | ||
37 | // Clock and Reset | |
38 | ||
39 | clk, | |
40 | rst_l, | |
41 | ||
42 | // Interface for Arbiter and Incomming Mondo Requests | |
43 | ||
44 | int_req_vec, | |
45 | int_winner_vec, | |
46 | update_winner, | |
47 | ||
48 | // Interface for Group Controller Arbiter | |
49 | ||
50 | gcs_req, | |
51 | gcs_ino, | |
52 | gcs_gnt, | |
53 | ||
54 | // Interface for Mondo Reply Status | |
55 | ||
56 | rss2gcs_rply, | |
57 | rss2gcs_id, | |
58 | rss2gcs_valid, | |
59 | ||
60 | // Interface for Interrupt Retry Timer | |
61 | ||
62 | timer_start, | |
63 | timer_done, | |
64 | ||
65 | // Interface for Static Value for group controller 0-3 | |
66 | ||
67 | static_gc_id, | |
68 | ||
69 | // Debug Interface | |
70 | ||
71 | fsm_dbg | |
72 | ||
73 | ||
74 | ||
75 | ); | |
76 | ||
77 | //############################################################################ | |
78 | // PORT DECLARATIONS | |
79 | //############################################################################ | |
80 | ||
81 | //------------------------------------------------------------------------ | |
82 | // Clock and Reset Signals | |
83 | //------------------------------------------------------------------------ | |
84 | ||
85 | input clk; | |
86 | input rst_l; | |
87 | ||
88 | //----------------------------------------------------- | |
89 | // Interface for Arbiter and Incomming Mondo Requests | |
90 | //----------------------------------------------------- | |
91 | ||
92 | input [63:0] int_req_vec; //Incomming Mondo Requests for 64 to 1 | |
93 | input [63:0] int_winner_vec; //Incomming Mondo winner from local 64 to 1 mondo arbiter | |
94 | output update_winner; //Last mondo winner, serves as input into local mondo arbiter | |
95 | ||
96 | ||
97 | //----------------------------------------------------- | |
98 | // Interface for Group Controller Arbiter | |
99 | //----------------------------------------------------- | |
100 | ||
101 | output gcs_req; // Request to group controller arbiter | |
102 | output [5:0] gcs_ino; // INO for requesting mondo | |
103 | input gcs_gnt; // Acknowldge for Request signal | |
104 | ||
105 | ||
106 | //----------------------------------------------------- | |
107 | // Interface for Mondo Reply Status | |
108 | //----------------------------------------------------- | |
109 | ||
110 | input rss2gcs_rply; // Reply type from RSS ack =1 nack =0 | |
111 | input [1:0] rss2gcs_id; // Group controller ID for response | |
112 | input rss2gcs_valid; // Valid signal to validate respose | |
113 | ||
114 | //----------------------------------------------------- | |
115 | // Interface for Interrupt Retry Timer | |
116 | //----------------------------------------------------- | |
117 | output timer_start; // Signal to start retry timer | |
118 | input timer_done; // SIgnal showing the retry timer is done | |
119 | ||
120 | ||
121 | //----------------------------------------------------- | |
122 | // Interface for Static Value for group controller 0-3 | |
123 | //----------------------------------------------------- | |
124 | input [1:0] static_gc_id; // Id for group controller | |
125 | ||
126 | //----------------------------------------------------- | |
127 | // Debug Interface | |
128 | //----------------------------------------------------- | |
129 | ||
130 | output [`FIRE_DEBUG_WDTH-1:0] fsm_dbg; | |
131 | ||
132 | ||
133 | //############################################################################ | |
134 | // PARAMETERS | |
135 | //############################################################################ | |
136 | parameter IDLE = 2'b00; | |
137 | parameter ARB_REQ = 2'b01; | |
138 | parameter W_4_REPLY = 2'b10; | |
139 | parameter RETRY = 2'b11; | |
140 | ||
141 | ||
142 | //############################################################################ | |
143 | // SIGNAL DECLARATIONS | |
144 | //############################################################################ | |
145 | //------------------------ | |
146 | // Wires | |
147 | //------------------------ | |
148 | ||
149 | wire mondo_ack; | |
150 | wire mondo_nack; | |
151 | wire mondo_needed; | |
152 | ||
153 | //------------------------- | |
154 | // Regs that are NOT flops | |
155 | //------------------------- | |
156 | reg [1:0] n_state; | |
157 | ||
158 | ||
159 | //------------------------ | |
160 | // Regs that are flops | |
161 | //------------------------ | |
162 | ||
163 | reg [1:0] state; | |
164 | ||
165 | //############################################################################ | |
166 | // ZERO IN CHECKERS | |
167 | //############################################################################ | |
168 | ||
169 | ||
170 | //--------------------------------------------------------------------- | |
171 | // REQ / ACK Interface Checkers | |
172 | //--------------------------------------------------------------------- | |
173 | ||
174 | //0in req_ack -req gcs_req -ack gcs_gnt -req_until_ack -new_req_after_ack -max_ack 1 | |
175 | ||
176 | //--------------------------------------------------------------------- | |
177 | // Known and Constant Checkers | |
178 | //--------------------------------------------------------------------- | |
179 | ||
180 | //0in known_driven -var gcs_ino -active gcs_req | |
181 | //0in constant -var gcs_ino -active gcs_req | |
182 | ||
183 | //--------------------------------------------------------------------- | |
184 | // State Machine Checkers | |
185 | //--------------------------------------------------------------------- | |
186 | //0in state_transition -var state -val IDLE -next ARB_REQ | |
187 | //0in state_transition -var state -val ARB_REQ -next W_4_REPLY | |
188 | //0in state_transition -var state -val W_4_REPLY -next ARB_REQ RETRY IDLE | |
189 | //0in state_transition -var state -val RETRY -next ARB_REQ | |
190 | ||
191 | ||
192 | ||
193 | //############################################################################ | |
194 | // FUNCTION DECLARATIONS | |
195 | //############################################################################ | |
196 | ||
197 | //---------------------------------------------------------------------- | |
198 | // This function takes as an input a 64 bit vector with one bit set to | |
199 | // 1 and encodes the bit number into a 6 bit binary number | |
200 | // | |
201 | // For Example on a 8 bit vector | |
202 | // | |
203 | // Last interrupt vector = 00001000 | |
204 | // | |
205 | // Mask Vector = 000100 | |
206 | // | |
207 | //----------------------------------------------------------------------- | |
208 | ||
209 | function [5:0] encode; | |
210 | input [63:0] vec; | |
211 | ||
212 | reg [5:0] enc_vec; | |
213 | reg [6:0] i; | |
214 | ||
215 | begin | |
216 | ||
217 | enc_vec = 6'h3f; | |
218 | ||
219 | for (i=7'd0; i<=7'd63; i=i+7'd1) | |
220 | begin | |
221 | if (vec[i[5:0]]) enc_vec = i[5:0]; | |
222 | end | |
223 | ||
224 | encode = enc_vec; | |
225 | ||
226 | //$display($time,": Ecoded value for vec = %0b is %0b\n",vec, enc_vec); | |
227 | end | |
228 | endfunction | |
229 | ||
230 | ||
231 | //############################################################################ | |
232 | // COMBINATIONAL LOGIC | |
233 | //############################################################################ | |
234 | //------------------------------------------------------------------------- | |
235 | // We have a transaction which needs to be done | |
236 | //------------------------------------------------------------------------- | |
237 | assign mondo_needed = |int_req_vec; | |
238 | ||
239 | //------------------------------------------------------------------------- | |
240 | // Decode reply status bus to detrmin if we have received and ACK or NACK | |
241 | //------------------------------------------------------------------------- | |
242 | ||
243 | assign mondo_ack = rss2gcs_valid & rss2gcs_rply & (static_gc_id == rss2gcs_id); | |
244 | assign mondo_nack = rss2gcs_valid & ~rss2gcs_rply & (static_gc_id == rss2gcs_id); | |
245 | ||
246 | //------------------------------------------------------------------------- | |
247 | // Assign the output values | |
248 | //------------------------------------------------------------------------- | |
249 | ||
250 | assign gcs_req = (state == ARB_REQ); // Only doing a request to gc arbiter in the ARB_REQ state | |
251 | assign gcs_ino = encode(int_winner_vec); // Take last winner and encode to 6 bit value | |
252 | ||
253 | ||
254 | //------------------------------------------------------------------------- | |
255 | // Start the Timer on NACKS | |
256 | //------------------------------------------------------------------------- | |
257 | assign timer_start = (state == W_4_REPLY) & mondo_nack; // Only start counter when get a Nack | |
258 | ||
259 | ||
260 | assign update_winner = ((state == IDLE) & (mondo_needed)) | | |
261 | ((state == W_4_REPLY) & (mondo_needed) & mondo_ack); | |
262 | ||
263 | //------------------------------------------------------------------------- | |
264 | // Debug Ports | |
265 | //------------------------------------------------------------------------- | |
266 | ||
267 | assign fsm_dbg = {state[1:0], mondo_ack, mondo_nack, timer_done, gcs_req, gcs_gnt, mondo_needed}; | |
268 | ||
269 | //########################################################################## | |
270 | // SEQUENTIAL LOGIC | |
271 | //############################################################################ | |
272 | ||
273 | //----------------------------------------------------------------------- | |
274 | // Next State Logic, Assign nest state to current state | |
275 | //----------------------------------------------------------------------- | |
276 | always @(posedge clk) | |
277 | begin | |
278 | if (~rst_l) | |
279 | begin | |
280 | state <= IDLE; | |
281 | end | |
282 | else | |
283 | begin | |
284 | state <= n_state; | |
285 | end | |
286 | end | |
287 | ||
288 | ||
289 | ||
290 | //----------------------------------------------------------------------- | |
291 | // FSM Combination Logic | |
292 | //----------------------------------------------------------------------- | |
293 | ||
294 | always @(state or mondo_needed or gcs_gnt or mondo_ack or mondo_nack or timer_done ) | |
295 | begin | |
296 | ||
297 | case (state) // synopsys parallel_case full_case | |
298 | ||
299 | ||
300 | //******************************************************** | |
301 | // | |
302 | // IDLE STATE | |
303 | // | |
304 | // - Wait here until the arbiter has a mondo which needs | |
305 | // to be sent . | |
306 | // - Do not update the last winner | |
307 | // | |
308 | // -If it has a mondo which needs servicing use the arb | |
309 | // winner as the one to req for | |
310 | // - Update the last winner | |
311 | // | |
312 | // | |
313 | // | |
314 | //******************************************************** | |
315 | ||
316 | IDLE: | |
317 | begin | |
318 | if (mondo_needed) // If there is at least one interrupt thats needs servicing | |
319 | begin | |
320 | n_state = ARB_REQ; | |
321 | end | |
322 | else // If there is no interrupts that needs servicing | |
323 | begin | |
324 | n_state = IDLE; | |
325 | end | |
326 | end | |
327 | ||
328 | //******************************************************** | |
329 | // | |
330 | // ARB_REQ STATE | |
331 | // | |
332 | // - Wait here until the req gets a grant from the gc arb | |
333 | // - Do not update the last winner | |
334 | // | |
335 | //******************************************************** | |
336 | ||
337 | ||
338 | ARB_REQ: | |
339 | begin | |
340 | if (gcs_gnt) // If get granted by main 4 to 1 arbiter go to W_4_REPLY | |
341 | begin | |
342 | n_state = W_4_REPLY; | |
343 | end | |
344 | else | |
345 | begin | |
346 | n_state = ARB_REQ; // If still not granted wait here | |
347 | end | |
348 | end | |
349 | ||
350 | ||
351 | //******************************************************** | |
352 | // | |
353 | // W_4_REPLY STATE | |
354 | // | |
355 | // - Wait here until we get a response from the CPU | |
356 | // | |
357 | // - If we get and ACK | |
358 | // - see if we have any more reqs waiting | |
359 | // - if yes ARB again and update last winner | |
360 | // - if no go to IDLE, no update | |
361 | // | |
362 | // - If we get a nack we need to retry | |
363 | // | |
364 | //******************************************************** | |
365 | ||
366 | ||
367 | W_4_REPLY: | |
368 | begin | |
369 | if (mondo_ack) // if get ACK back from CPU check if more are waiting | |
370 | begin | |
371 | ||
372 | if (mondo_needed) // ACK and more waiting | |
373 | begin | |
374 | n_state = ARB_REQ; | |
375 | end | |
376 | ||
377 | else // ACK and no more waiting | |
378 | begin | |
379 | n_state = IDLE; | |
380 | end | |
381 | end | |
382 | ||
383 | ||
384 | else if (mondo_nack) // if get NACK back from CPU | |
385 | begin | |
386 | n_state = RETRY; | |
387 | end | |
388 | ||
389 | else // NO reply yet | |
390 | begin | |
391 | n_state = W_4_REPLY ; | |
392 | end | |
393 | end | |
394 | ||
395 | //******************************************************** | |
396 | // | |
397 | // RETRY STATE | |
398 | // | |
399 | // - Wait here until the timer expires | |
400 | // - Do not update the last winner | |
401 | // - Need to send this one again | |
402 | // | |
403 | //******************************************************** | |
404 | ||
405 | ||
406 | RETRY: | |
407 | begin | |
408 | if (timer_done) // If get timer done | |
409 | begin | |
410 | n_state = ARB_REQ; | |
411 | end | |
412 | else | |
413 | begin | |
414 | n_state = RETRY; // If still no timer response wait here | |
415 | end | |
416 | end | |
417 | ||
418 | endcase | |
419 | end | |
420 | ||
421 | ||
422 | ||
423 | endmodule | |
424 |