OpenCores
URL https://opencores.org/ocsvn/sparc64soc/sparc64soc/trunk

Subversion Repositories sparc64soc

[/] [sparc64soc/] [trunk/] [T1-common/] [common/] [ucb_flow_spi.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dmitryr
// ========== Copyright Header Begin ==========================================
2
// 
3
// OpenSPARC T1 Processor File: ucb_flow_spi.v
4
// Copyright (c) 2006 Sun Microsystems, Inc.  All Rights Reserved.
5
// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
6
// 
7
// The above named program is free software; you can redistribute it and/or
8
// modify it under the terms of the GNU General Public
9
// License version 2 as published by the Free Software Foundation.
10
// 
11
// The above named program is distributed in the hope that it will be 
12
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
// General Public License for more details.
15
// 
16
// You should have received a copy of the GNU General Public
17
// License along with this work; if not, write to the Free Software
18
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19
// 
20
// ========== Copyright Header End ============================================
21
////////////////////////////////////////////////////////////////////////
22
/*
23
//  Module Name:        ucb_flow_spi
24
//      Description:    Unit Control Block
25
//                      - supports 1B/2B/4B/8B read with flow control
26
//                      - supports 1B/2B/4B/8B write with flow control
27
//                      - supports 4B ifill request
28
//                      - supports interrupt return to IO Bridge
29
//                      - provides 1+2 deep buffer for incoming requests
30
//                        from the IO Bridge
31
//                      - provides single buffer for returns going back
32
//                        to the IO Bridge
33
//
34
//                      This module is customized for the SPI.
35
//
36
//                      Data bus width to and from the IO Bridge is
37
//                      configured through parameters UCB_IOB_WIDTH and
38
//                      IOB_UCB_WIDTH.  Supported widths are:
39
//
40
//                      IOB_UCB_WIDTH  UCB_IOB_WIDTH
41
//                      ----------------------------
42
//                      32             8
43
//                      16             8
44
//                       8             8
45
//                       4             4
46
 */
47
////////////////////////////////////////////////////////////////////////
48
// Global header file includes
49
////////////////////////////////////////////////////////////////////////
50
`include        "sys.h" // system level definition file which 
51
                        // contains the time scale definition
52
 
53
`include        "iop.h"
54
 
55
////////////////////////////////////////////////////////////////////////
56
// Local header file includes / local defines
57
////////////////////////////////////////////////////////////////////////
58
`define         UCB_BUF_DEPTH   2
59
`define         UCB_BUF_WIDTH   64+(`UCB_ADDR_HI-`UCB_ADDR_LO+1)+(`UCB_SIZE_HI-`UCB_SIZE_LO+1)+(`UCB_BUF_HI-`UCB_BUF_LO+1)+(`UCB_THR_HI-`UCB_THR_LO+1)+1+1+1
60
 
61
module ucb_flow_spi (/*AUTOARG*/
62
   // Outputs
63
   ucb_iob_stall, rd_req_vld, wr_req_vld, ifill_req_vld, thr_id_in,
64
   buf_id_in, size_in, addr_in, data_in, ack_busy, int_busy,
65
   ucb_iob_vld, ucb_iob_data,
66
   // Inputs
67
   clk, rst_l, iob_ucb_vld, iob_ucb_data, req_acpted, rd_ack_vld,
68
   rd_nack_vld, ifill_ack_vld, ifill_nack_vld, thr_id_out,
69
   buf_id_out, data128, data_out, int_vld, int_typ, int_thr_id,
70
   dev_id, int_stat, int_vec, iob_ucb_stall
71
   );
72
   // synopsys template
73
 
74
   parameter IOB_UCB_WIDTH = 32;  // data bus width from IOB to UCB
75
   parameter UCB_IOB_WIDTH = 8;   // data bus width from UCB to IOB
76
   parameter REG_WIDTH     = 64;  // please do not change this parameter
77
 
78
 
79
   // Globals
80
   input                                clk;
81
   input                                rst_l;
82
 
83
   // Request from IO Bridge
84
   input                                iob_ucb_vld;
85
   input [IOB_UCB_WIDTH-1:0]             iob_ucb_data;
86
   output                               ucb_iob_stall;
87
 
88
   // Request to local unit
89
   output                               rd_req_vld;
90
   output                               wr_req_vld;
91
   output                               ifill_req_vld;
92
   output [`UCB_THR_HI-`UCB_THR_LO:0]   thr_id_in;
93
   output [`UCB_BUF_HI-`UCB_BUF_LO:0]   buf_id_in;
94
   output [`UCB_SIZE_HI-`UCB_SIZE_LO:0] size_in;   // only pertinent to JBI and SPI
95
   output [`UCB_ADDR_HI-`UCB_ADDR_LO:0] addr_in;
96
   output [`UCB_DATA_HI-`UCB_DATA_LO:0] data_in;
97
   input                                req_acpted;
98
 
99
   // Ack/Nack from local unit
100
   input                                rd_ack_vld;
101
   input                                rd_nack_vld;
102
   input                                ifill_ack_vld;
103
   input                                ifill_nack_vld;
104
   input [`UCB_THR_HI-`UCB_THR_LO:0]     thr_id_out;
105
   input [`UCB_BUF_HI-`UCB_BUF_LO:0]     buf_id_out;
106
   input                                data128;   // set to 1 if data returned is 128 bit
107
   input [REG_WIDTH-1:0]                 data_out;
108
   output                               ack_busy;
109
 
110
   // Interrupt from local unit
111
   input                                int_vld;
112
   input [`UCB_PKT_HI-`UCB_PKT_LO:0]     int_typ;          // interrupt type
113
   input [`UCB_THR_HI-`UCB_THR_LO:0]     int_thr_id;       // interrupt thread ID
114
   input [`UCB_INT_DEV_HI-`UCB_INT_DEV_LO:0] dev_id;      // interrupt device ID
115
   input [`UCB_INT_STAT_HI-`UCB_INT_STAT_LO:0] int_stat;  // interrupt status
116
   input [`UCB_INT_VEC_HI-`UCB_INT_VEC_LO:0]   int_vec;   // interrupt vector
117
   output                               int_busy;
118
 
119
   // Output to IO Bridge
120
   output                               ucb_iob_vld;
121
   output [UCB_IOB_WIDTH-1:0]            ucb_iob_data;
122
   input                                iob_ucb_stall;
123
 
124
   // Local signals
125
   wire                                 indata_buf_vld;
126
   wire [127:0]                         indata_buf;
127
   wire                                 ucb_iob_stall_a1;
128
 
129
   wire                                 read_pending;
130
   wire                                 write_pending;
131
   wire                                 ifill_pending;
132
 
133
   wire                                 rd_buf;
134
   wire [`UCB_BUF_DEPTH-1:0]             buf_head_next;
135
   wire [`UCB_BUF_DEPTH-1:0]             buf_head;
136
   wire                                 wr_buf;
137
   wire [`UCB_BUF_DEPTH-1:0]             buf_tail_next;
138
   wire [`UCB_BUF_DEPTH-1:0]             buf_tail;
139
   wire                                 buf_full_next;
140
   wire                                 buf_full;
141
   wire                                 buf_empty_next;
142
   wire                                 buf_empty;
143
   wire [`UCB_BUF_WIDTH-1:0]             req_in;
144
   wire                                 buf0_en;
145
   wire [`UCB_BUF_WIDTH-1:0]             buf0;
146
   wire                                 buf1_en;
147
   wire [`UCB_BUF_WIDTH-1:0]             buf1;
148
   wire [`UCB_BUF_WIDTH-1:0]             req_out;
149
   wire                                 rd_req_vld_nq;
150
   wire                                 wr_req_vld_nq;
151
   wire                                 ifill_req_vld_nq;
152
 
153
   wire                                 ack_buf_rd;
154
   wire                                 ack_buf_wr;
155
   wire                                 ack_buf_vld;
156
   wire                                 ack_buf_vld_next;
157
   wire                                 ack_buf_is_nack;
158
   wire                                 ack_buf_is_data128;
159
   wire [`UCB_PKT_HI-`UCB_PKT_LO:0]     ack_typ_out;
160
   wire [REG_WIDTH+`UCB_BUF_HI-`UCB_PKT_LO:0] ack_buf_in;
161
   wire [REG_WIDTH+`UCB_BUF_HI-`UCB_PKT_LO:0] ack_buf;
162
   wire [(REG_WIDTH+64)/UCB_IOB_WIDTH-1:0] ack_buf_vec;
163
 
164
   wire                                 int_buf_rd;
165
   wire                                 int_buf_wr;
166
   wire                                 int_buf_vld;
167
   wire                                 int_buf_vld_next;
168
   wire [`UCB_INT_VEC_HI-`UCB_PKT_LO:0] int_buf_in;
169
   wire [`UCB_INT_VEC_HI-`UCB_PKT_LO:0] int_buf;
170
   wire [(REG_WIDTH+64)/UCB_IOB_WIDTH-1:0] int_buf_vec;
171
 
172
   wire                                 int_last_rd;
173
   wire                                 outdata_buf_busy;
174
   wire                                 outdata_buf_wr;
175
   wire [REG_WIDTH+63:0]                outdata_buf_in;
176
   wire [(REG_WIDTH+64)/UCB_IOB_WIDTH-1:0] outdata_vec_in;
177
 
178
 
179
////////////////////////////////////////////////////////////////////////
180
// Code starts here
181
////////////////////////////////////////////////////////////////////////
182
   /************************************************************
183
    * Inbound Data
184
    ************************************************************/
185
   // Register size is hardcoded to 64 bits here
186
   ucb_bus_in #(IOB_UCB_WIDTH,64) ucb_bus_in (.rst_l(rst_l),
187
                                              .clk(clk),
188
                                              .vld(iob_ucb_vld),
189
                                              .data(iob_ucb_data),
190
                                              .stall(ucb_iob_stall),
191
                                              .indata_buf_vld(indata_buf_vld),
192
                                              .indata_buf(indata_buf),
193
                                              .stall_a1(ucb_iob_stall_a1));
194
 
195
 
196
   /************************************************************
197
    * Decode inbound packet type
198
    ************************************************************/
199
   assign        read_pending = (indata_buf[`UCB_PKT_HI:`UCB_PKT_LO] ==
200
                                 `UCB_READ_REQ) &
201
                                indata_buf_vld;
202
 
203
   assign        write_pending = (indata_buf[`UCB_PKT_HI:`UCB_PKT_LO] ==
204
                                  `UCB_WRITE_REQ) &
205
                                  indata_buf_vld;
206
 
207
   assign        ifill_pending = (indata_buf[`UCB_PKT_HI:`UCB_PKT_LO] ==
208
                                  `UCB_IFILL_REQ) &
209
                                  indata_buf_vld;
210
 
211
   assign        ucb_iob_stall_a1 = (read_pending | write_pending | ifill_pending) & buf_full;
212
 
213
 
214
   /************************************************************
215
    * Inbound buffer
216
    ************************************************************/
217
   // Head pointer
218
   assign        rd_buf = req_acpted;
219
   assign        buf_head_next = ~rst_l ? `UCB_BUF_DEPTH'b01 :
220
                                 rd_buf ? {buf_head[`UCB_BUF_DEPTH-2:0],
221
                                           buf_head[`UCB_BUF_DEPTH-1]} :
222
                                          buf_head;
223
   dff_ns #(`UCB_BUF_DEPTH) buf_head_ff (.din(buf_head_next),
224
                                         .clk(clk),
225
                                         .q(buf_head));
226
 
227
   // Tail pointer
228
   assign        wr_buf = (read_pending |
229
                           write_pending |
230
                           ifill_pending) &
231
                          ~buf_full;
232
   assign        buf_tail_next = ~rst_l ? `UCB_BUF_DEPTH'b01 :
233
                                 wr_buf ? {buf_tail[`UCB_BUF_DEPTH-2:0],
234
                                           buf_tail[`UCB_BUF_DEPTH-1]} :
235
                                          buf_tail;
236
   dff_ns #(`UCB_BUF_DEPTH) buf_tail_ff (.din(buf_tail_next),
237
                                         .clk(clk),
238
                                         .q(buf_tail));
239
 
240
   // Buffer full
241
   assign        buf_full_next = (buf_head_next == buf_tail_next) &
242
                                 wr_buf;
243
   dffrle_ns #(1) buf_full_ff (.din(buf_full_next),
244
                               .rst_l(rst_l),
245
                               .en(rd_buf|wr_buf),
246
                               .clk(clk),
247
                               .q(buf_full));
248
 
249
   // Buffer empty
250
   assign        buf_empty_next = ((buf_head_next == buf_tail_next) &
251
                                   rd_buf) | ~rst_l;
252
   dffe_ns #(1) buf_empty_ff (.din(buf_empty_next),
253
                              .en(rd_buf|wr_buf|~rst_l),
254
                              .clk(clk),
255
                              .q(buf_empty));
256
 
257
 
258
   assign        req_in = {indata_buf[`UCB_DATA_HI:`UCB_DATA_LO],
259
                           indata_buf[`UCB_ADDR_HI:`UCB_ADDR_LO],
260
                           indata_buf[`UCB_SIZE_HI:`UCB_SIZE_LO],
261
                           indata_buf[`UCB_BUF_HI:`UCB_BUF_LO],
262
                           indata_buf[`UCB_THR_HI:`UCB_THR_LO],
263
                           ifill_pending,
264
                           write_pending,
265
                           read_pending};
266
 
267
   // Buffer 0
268
   assign        buf0_en = buf_tail[0] & wr_buf;
269
   dffe_ns #(`UCB_BUF_WIDTH) buf0_ff (.din(req_in),
270
                                      .en(buf0_en),
271
                                      .clk(clk),
272
                                      .q(buf0));
273
   // Buffer 1
274
   assign        buf1_en = buf_tail[1] & wr_buf;
275
   dffe_ns #(`UCB_BUF_WIDTH) buf1_ff (.din(req_in),
276
                                      .en(buf1_en),
277
                                      .clk(clk),
278
                                      .q(buf1));
279
 
280
   assign        req_out = buf_head[0] ? buf0 :
281
                           buf_head[1] ? buf1 :
282
                                         {`UCB_BUF_WIDTH{1'b0}};
283
 
284
 
285
   /************************************************************
286
    * Inbound interface to local unit
287
    ************************************************************/
288
   assign        {data_in,
289
                  addr_in,
290
                  size_in,
291
                  buf_id_in,
292
                  thr_id_in,
293
                  ifill_req_vld_nq,
294
                  wr_req_vld_nq,
295
                  rd_req_vld_nq} = req_out;
296
 
297
   assign        rd_req_vld = rd_req_vld_nq & ~buf_empty;
298
   assign        wr_req_vld = wr_req_vld_nq & ~buf_empty;
299
   assign        ifill_req_vld = ifill_req_vld_nq & ~buf_empty;
300
 
301
 
302
   /************************************************************
303
    * Outbound Ack/Nack
304
    ************************************************************/
305
   assign        ack_buf_wr = rd_ack_vld | rd_nack_vld | ifill_ack_vld | ifill_nack_vld;
306
 
307
   assign        ack_buf_vld_next = ack_buf_wr ? 1'b1 :
308
                                    ack_buf_rd ? 1'b0 :
309
                                                 ack_buf_vld;
310
 
311
   dffrl_ns #(1) ack_buf_vld_ff (.din(ack_buf_vld_next),
312
                                 .clk(clk),
313
                                 .rst_l(rst_l),
314
                                 .q(ack_buf_vld));
315
 
316
   dffe_ns #(1) ack_buf_is_nack_ff (.din(rd_nack_vld|ifill_nack_vld),
317
                                    .en(ack_buf_wr),
318
                                    .clk(clk),
319
                                    .q(ack_buf_is_nack));
320
 
321
   dffe_ns #(1) ack_buf_is_data128_ff (.din(data128),
322
                                       .en(ack_buf_wr),
323
                                       .clk(clk),
324
                                       .q(ack_buf_is_data128));
325
 
326
   assign        ack_typ_out = rd_ack_vld    ? `UCB_READ_ACK:
327
                               rd_nack_vld   ? `UCB_READ_NACK:
328
                               ifill_ack_vld ? `UCB_IFILL_ACK:
329
                                               `UCB_IFILL_NACK;
330
 
331
   assign        ack_buf_in = {data_out,
332
                               buf_id_out,
333
                               thr_id_out,
334
                               ack_typ_out};
335
 
336
   dffe_ns #(REG_WIDTH+`UCB_BUF_HI-`UCB_PKT_LO+1) ack_buf_ff (.din(ack_buf_in),
337
                                                              .en(ack_buf_wr),
338
                                                              .clk(clk),
339
                                                              .q(ack_buf));
340
 
341
   assign        ack_buf_vec = ack_buf_is_nack    ? {{REG_WIDTH/UCB_IOB_WIDTH{1'b0}},
342
                                                     {64/UCB_IOB_WIDTH{1'b1}}} :
343
                               ack_buf_is_data128 ? {(REG_WIDTH+64)/UCB_IOB_WIDTH{1'b1}} :
344
                                                    {(64+64)/UCB_IOB_WIDTH{1'b1}};
345
 
346
   assign        ack_busy = ack_buf_vld;
347
 
348
 
349
   /************************************************************
350
    * Outbound Interrupt
351
    ************************************************************/
352
   // Assertion: int_buf_wr shoudn't be asserted if int_buf_busy
353
   assign        int_buf_wr = int_vld;
354
 
355
   assign        int_buf_vld_next = int_buf_wr ? 1'b1 :
356
                                    int_buf_rd ? 1'b0 :
357
                                                 int_buf_vld;
358
 
359
   dffrl_ns #(1) int_buf_vld_ff (.din(int_buf_vld_next),
360
                                 .clk(clk),
361
                                 .rst_l(rst_l),
362
                                 .q(int_buf_vld));
363
 
364
   assign        int_buf_in = {int_vec,
365
                               int_stat,
366
                               dev_id,
367
                               int_thr_id,
368
                               int_typ};
369
 
370
   dffe_ns #(`UCB_INT_VEC_HI-`UCB_PKT_LO+1) int_buf_ff (.din(int_buf_in),
371
                                                        .en(int_buf_wr),
372
                                                        .clk(clk),
373
                                                        .q(int_buf));
374
 
375
   assign        int_buf_vec = {{REG_WIDTH/UCB_IOB_WIDTH{1'b0}},
376
                                {64/UCB_IOB_WIDTH{1'b1}}};
377
 
378
   assign        int_busy = int_buf_vld;
379
 
380
 
381
   /************************************************************
382
    * Outbound ack/interrupt Arbitration
383
    ************************************************************/
384
   dffrle_ns #(1) int_last_rd_ff (.din(int_buf_rd),
385
                                  .en(ack_buf_rd|int_buf_rd),
386
                                  .rst_l(rst_l),
387
                                  .clk(clk),
388
                                  .q(int_last_rd));
389
 
390
   assign        ack_buf_rd = ~outdata_buf_busy & ack_buf_vld &
391
                              (~int_buf_vld | int_last_rd);
392
 
393
   assign        int_buf_rd = ~outdata_buf_busy & int_buf_vld &
394
                              (~ack_buf_vld | ~int_last_rd);
395
 
396
   assign        outdata_buf_wr = ack_buf_rd | int_buf_rd;
397
 
398
   assign        outdata_buf_in = ack_buf_rd ? {ack_buf[REG_WIDTH+`UCB_BUF_HI:`UCB_BUF_HI+1],
399
                                                {(`UCB_RSV_HI-`UCB_RSV_LO+1){1'b0}},
400
                                                {(`UCB_ADDR_HI-`UCB_ADDR_LO+1){1'b0}},
401
                                                {(`UCB_SIZE_HI-`UCB_SIZE_LO+1){1'b0}},
402
                                                ack_buf[`UCB_BUF_HI:`UCB_BUF_LO],
403
                                                ack_buf[`UCB_THR_HI:`UCB_THR_LO],
404
                                                ack_buf[`UCB_PKT_HI:`UCB_PKT_LO]}:
405
                                               {{REG_WIDTH{1'b0}},
406
                                                {(`UCB_INT_RSV_HI-`UCB_INT_RSV_LO+1){1'b0}},
407
                                                int_buf[`UCB_INT_VEC_HI:`UCB_INT_VEC_LO],
408
                                                int_buf[`UCB_INT_STAT_HI:`UCB_INT_STAT_LO],
409
                                                int_buf[`UCB_INT_DEV_HI:`UCB_INT_DEV_LO],
410
                                                int_buf[`UCB_THR_HI:`UCB_THR_LO],
411
                                                int_buf[`UCB_PKT_HI:`UCB_PKT_LO]};
412
 
413
   assign        outdata_vec_in = ack_buf_rd ? ack_buf_vec :
414
                                               int_buf_vec;
415
 
416
   ucb_bus_out #(UCB_IOB_WIDTH, REG_WIDTH) ucb_bus_out (.rst_l(rst_l),
417
                                                        .clk(clk),
418
                                                        .outdata_buf_wr(outdata_buf_wr),
419
                                                        .outdata_buf_in(outdata_buf_in),
420
                                                        .outdata_vec_in(outdata_vec_in),
421
                                                        .outdata_buf_busy(outdata_buf_busy),
422
                                                        .vld(ucb_iob_vld),
423
                                                        .data(ucb_iob_data),
424
                                                        .stall(iob_ucb_stall));
425
 
426
 
427
`undef          UCB_BUF_WIDTH
428
 
429
endmodule // ucb_flow_spi
430
 
431
 
432
// Local Variables:
433
// verilog-library-directories:(".")
434
// End:
435
 
436
 
437
 
438
 
439
 
440
 
441
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.