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

Subversion Repositories sparc64soc

[/] [sparc64soc/] [trunk/] [T1-common/] [common/] [ucb_flow_2buf.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_2buf.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_2buf
24
//      Description:    Unit Control Block
25
//                      - supports 64-bit or 128-bit read with flow control
26
//                      - supports 64-bit write with flow control
27
//                      - automactically drops non-64-bit writes
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 intended for units that have
35
//                      64-bit (no 128-bit) registers.
36
//
37
//                      Data bus width to and from the IO Bridge is
38
//                      configured through parameters UCB_IOB_WIDTH and
39
//                      IOB_UCB_WIDTH.  Supported widths are:
40
//
41
//                      IOB_UCB_WIDTH  UCB_IOB_WIDTH
42
//                      ----------------------------
43
//                      32             8
44
//                      16             8
45
//                       8             8
46
//                       4             4
47
 */
48
////////////////////////////////////////////////////////////////////////
49
// Global header file includes
50
////////////////////////////////////////////////////////////////////////
51
`include        "sys.h" // system level definition file which 
52
                        // contains the time scale definition
53
 
54
`include        "iop.h"
55
 
56
////////////////////////////////////////////////////////////////////////
57
// Local header file includes / local defines
58
////////////////////////////////////////////////////////////////////////
59
`define         UCB_BUF_DEPTH   2
60
`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
61
 
62
module ucb_flow_2buf (/*AUTOARG*/
63
   // Outputs
64
   ucb_iob_stall, rd_req_vld, wr_req_vld, thr_id_in, buf_id_in,
65
   size_in, addr_in, data_in, ack_busy, int_busy, ucb_iob_vld,
66
   ucb_iob_data,
67
   // Inputs
68
   clk, rst_l, iob_ucb_vld, iob_ucb_data, req_acpted, rd_ack_vld,
69
   rd_nack_vld, thr_id_out, buf_id_out, data128, data_out, int_vld,
70
   int_typ, int_thr_id, 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 [`UCB_THR_HI-`UCB_THR_LO:0]   thr_id_in;
92
   output [`UCB_BUF_HI-`UCB_BUF_LO:0]   buf_id_in;
93
   output [`UCB_SIZE_HI-`UCB_SIZE_LO:0] size_in;   // only pertinent to PCI
94
   output [`UCB_ADDR_HI-`UCB_ADDR_LO:0] addr_in;
95
   output [`UCB_DATA_HI-`UCB_DATA_LO:0] data_in;
96
   input                                req_acpted;
97
 
98
   // Ack/Nack from local unit
99
   input                                rd_ack_vld;
100
   input                                rd_nack_vld;
101
   input [`UCB_THR_HI-`UCB_THR_LO:0]     thr_id_out;
102
   input [`UCB_BUF_HI-`UCB_BUF_LO:0]     buf_id_out;
103
   input                                data128;   // set to 1 if data returned is 128 bit
104
   input [REG_WIDTH-1:0]                 data_out;
105
   output                               ack_busy;
106
 
107
   // Interrupt from local unit
108
   input                                int_vld;
109
   input [`UCB_PKT_HI-`UCB_PKT_LO:0]     int_typ;          // interrupt type
110
   input [`UCB_THR_HI-`UCB_THR_LO:0]     int_thr_id;       // interrupt thread ID
111
   input [`UCB_INT_DEV_HI-`UCB_INT_DEV_LO:0] dev_id;      // interrupt device ID
112
   input [`UCB_INT_STAT_HI-`UCB_INT_STAT_LO:0] int_stat;  // interrupt status
113
   input [`UCB_INT_VEC_HI-`UCB_INT_VEC_LO:0]   int_vec;   // interrupt vector
114
   output                               int_busy;
115
 
116
   // Output to IO Bridge
117
   output                               ucb_iob_vld;
118
   output [UCB_IOB_WIDTH-1:0]            ucb_iob_data;
119
   input                                iob_ucb_stall;
120
 
121
   // Local signals
122
   wire                                 indata_buf_vld;
123
   wire [127:0]                         indata_buf;
124
   wire                                 ucb_iob_stall_a1;
125
 
126
   wire                                 read_pending;
127
   wire                                 write_pending;
128
   wire                                 illegal_write_size;
129
 
130
   wire                                 rd_buf;
131
   wire [`UCB_BUF_DEPTH-1:0]             buf_head_next;
132
   wire [`UCB_BUF_DEPTH-1:0]             buf_head;
133
   wire                                 wr_buf;
134
   wire [`UCB_BUF_DEPTH-1:0]             buf_tail_next;
135
   wire [`UCB_BUF_DEPTH-1:0]             buf_tail;
136
   wire                                 buf_full_next;
137
   wire                                 buf_full;
138
   wire                                 buf_empty_next;
139
   wire                                 buf_empty;
140
   wire [`UCB_BUF_WIDTH-1:0]             req_in;
141
   wire                                 buf0_en;
142
   wire [`UCB_BUF_WIDTH-1:0]             buf0;
143
   wire                                 buf1_en;
144
   wire [`UCB_BUF_WIDTH-1:0]             buf1;
145
   wire [`UCB_BUF_WIDTH-1:0]             req_out;
146
   wire                                 rd_req_vld_nq;
147
   wire                                 wr_req_vld_nq;
148
 
149
   wire                                 ack_buf_rd;
150
   wire                                 ack_buf_wr;
151
   wire                                 ack_buf_vld;
152
   wire                                 ack_buf_vld_next;
153
   wire                                 ack_buf_is_nack;
154
   wire                                 ack_buf_is_data128;
155
   wire [`UCB_PKT_HI-`UCB_PKT_LO:0]     ack_typ_out;
156
   wire [REG_WIDTH+`UCB_BUF_HI-`UCB_PKT_LO:0] ack_buf_in;
157
   wire [REG_WIDTH+`UCB_BUF_HI-`UCB_PKT_LO:0] ack_buf;
158
   wire [(REG_WIDTH+64)/UCB_IOB_WIDTH-1:0] ack_buf_vec;
159
 
160
   wire                                 int_buf_rd;
161
   wire                                 int_buf_wr;
162
   wire                                 int_buf_vld;
163
   wire                                 int_buf_vld_next;
164
   wire [`UCB_INT_VEC_HI-`UCB_PKT_LO:0] int_buf_in;
165
   wire [`UCB_INT_VEC_HI-`UCB_PKT_LO:0] int_buf;
166
   wire [(REG_WIDTH+64)/UCB_IOB_WIDTH-1:0] int_buf_vec;
167
 
168
   wire                                 int_last_rd;
169
   wire                                 outdata_buf_busy;
170
   wire                                 outdata_buf_wr;
171
   wire [REG_WIDTH+63:0]                outdata_buf_in;
172
   wire [(REG_WIDTH+64)/UCB_IOB_WIDTH-1:0] outdata_vec_in;
173
 
174
 
175
////////////////////////////////////////////////////////////////////////
176
// Code starts here
177
////////////////////////////////////////////////////////////////////////
178
   /************************************************************
179
    * Inbound Data
180
    ************************************************************/
181
   // Register size is hardcoded to 64 bits here because all
182
   // units using the UCB module will only write to 64 bit registers.
183
   ucb_bus_in #(IOB_UCB_WIDTH,64) ucb_bus_in (.rst_l(rst_l),
184
                                              .clk(clk),
185
                                              .vld(iob_ucb_vld),
186
                                              .data(iob_ucb_data),
187
                                              .stall(ucb_iob_stall),
188
                                              .indata_buf_vld(indata_buf_vld),
189
                                              .indata_buf(indata_buf),
190
                                              .stall_a1(ucb_iob_stall_a1));
191
 
192
 
193
   /************************************************************
194
    * Decode inbound packet type
195
    ************************************************************/
196
   assign        read_pending = (indata_buf[`UCB_PKT_HI:`UCB_PKT_LO] ==
197
                                 `UCB_READ_REQ) &
198
                                indata_buf_vld;
199
 
200
   assign        write_pending = (indata_buf[`UCB_PKT_HI:`UCB_PKT_LO] ==
201
                                  `UCB_WRITE_REQ) &
202
                                  indata_buf_vld;
203
 
204
   // 3'b011 is the encoding for double word.  All writes have to be
205
   // 64 bits except writes going to PCI.  PCI will instantiate a
206
   // customized version of UCB.
207
   assign        illegal_write_size = (indata_buf[`UCB_SIZE_HI:`UCB_SIZE_LO] !=
208
                                       3'b011);
209
 
210
   assign        ucb_iob_stall_a1 = (read_pending | write_pending) & buf_full;
211
 
212
 
213
   /************************************************************
214
    * Inbound buffer
215
    ************************************************************/
216
   // Head pointer
217
   assign        rd_buf = req_acpted;
218
   assign        buf_head_next = ~rst_l ? `UCB_BUF_DEPTH'b01 :
219
                                 rd_buf ? {buf_head[`UCB_BUF_DEPTH-2:0],
220
                                           buf_head[`UCB_BUF_DEPTH-1]} :
221
                                          buf_head;
222
   dff_ns #(`UCB_BUF_DEPTH) buf_head_ff (.din(buf_head_next),
223
                                         .clk(clk),
224
                                         .q(buf_head));
225
 
226
   // Tail pointer
227
   assign        wr_buf = (read_pending |
228
                           (write_pending & ~illegal_write_size)) &
229
                          ~buf_full;
230
   assign        buf_tail_next = ~rst_l ? `UCB_BUF_DEPTH'b01 :
231
                                 wr_buf ? {buf_tail[`UCB_BUF_DEPTH-2:0],
232
                                           buf_tail[`UCB_BUF_DEPTH-1]} :
233
                                          buf_tail;
234
   dff_ns #(`UCB_BUF_DEPTH) buf_tail_ff (.din(buf_tail_next),
235
                                         .clk(clk),
236
                                         .q(buf_tail));
237
 
238
   // Buffer full
239
   assign        buf_full_next = (buf_head_next == buf_tail_next) &
240
                                 wr_buf;
241
   dffrle_ns #(1) buf_full_ff (.din(buf_full_next),
242
                               .rst_l(rst_l),
243
                               .en(rd_buf|wr_buf),
244
                               .clk(clk),
245
                               .q(buf_full));
246
 
247
   // Buffer empty
248
   assign        buf_empty_next = ((buf_head_next == buf_tail_next) &
249
                                   rd_buf) | ~rst_l;
250
   dffe_ns #(1) buf_empty_ff (.din(buf_empty_next),
251
                              .en(rd_buf|wr_buf|~rst_l),
252
                              .clk(clk),
253
                              .q(buf_empty));
254
 
255
 
256
   assign        req_in = {indata_buf[`UCB_DATA_HI:`UCB_DATA_LO],
257
                           indata_buf[`UCB_ADDR_HI:`UCB_ADDR_LO],
258
                           indata_buf[`UCB_SIZE_HI:`UCB_SIZE_LO],
259
                           indata_buf[`UCB_BUF_HI:`UCB_BUF_LO],
260
                           indata_buf[`UCB_THR_HI:`UCB_THR_LO],
261
                           write_pending & ~illegal_write_size,
262
                           read_pending};
263
 
264
   // Buffer 0
265
   assign        buf0_en = buf_tail[0] & wr_buf;
266
   dffe_ns #(`UCB_BUF_WIDTH) buf0_ff (.din(req_in),
267
                                      .en(buf0_en),
268
                                      .clk(clk),
269
                                      .q(buf0));
270
   // Buffer 1
271
   assign        buf1_en = buf_tail[1] & wr_buf;
272
   dffe_ns #(`UCB_BUF_WIDTH) buf1_ff (.din(req_in),
273
                                      .en(buf1_en),
274
                                      .clk(clk),
275
                                      .q(buf1));
276
 
277
   assign        req_out = buf_head[0] ? buf0 :
278
                           buf_head[1] ? buf1 :
279
                                         {`UCB_BUF_WIDTH{1'b0}};
280
 
281
 
282
   /************************************************************
283
    * Inbound interface to local unit
284
    ************************************************************/
285
   assign        {data_in,
286
                  addr_in,
287
                  size_in,
288
                  buf_id_in,
289
                  thr_id_in,
290
                  wr_req_vld_nq,
291
                  rd_req_vld_nq} = req_out;
292
 
293
   assign        rd_req_vld = rd_req_vld_nq & ~buf_empty;
294
   assign        wr_req_vld = wr_req_vld_nq & ~buf_empty;
295
 
296
 
297
   /************************************************************
298
    * Outbound Ack/Nack
299
    ************************************************************/
300
   assign        ack_buf_wr = rd_ack_vld | rd_nack_vld;
301
 
302
   assign        ack_buf_vld_next = ack_buf_wr ? 1'b1 :
303
                                    ack_buf_rd ? 1'b0 :
304
                                                 ack_buf_vld;
305
 
306
   dffrl_ns #(1) ack_buf_vld_ff (.din(ack_buf_vld_next),
307
                                 .clk(clk),
308
                                 .rst_l(rst_l),
309
                                 .q(ack_buf_vld));
310
 
311
   dffe_ns #(1) ack_buf_is_nack_ff (.din(rd_nack_vld),
312
                                    .en(ack_buf_wr),
313
                                    .clk(clk),
314
                                    .q(ack_buf_is_nack));
315
 
316
   dffe_ns #(1) ack_buf_is_data128_ff (.din(data128),
317
                                       .en(ack_buf_wr),
318
                                       .clk(clk),
319
                                       .q(ack_buf_is_data128));
320
 
321
   assign        ack_typ_out = rd_ack_vld ? `UCB_READ_ACK:
322
                                            `UCB_READ_NACK;
323
 
324
   assign        ack_buf_in = {data_out,
325
                               buf_id_out,
326
                               thr_id_out,
327
                               ack_typ_out};
328
 
329
   dffe_ns #(REG_WIDTH+`UCB_BUF_HI-`UCB_PKT_LO+1) ack_buf_ff (.din(ack_buf_in),
330
                                                              .en(ack_buf_wr),
331
                                                              .clk(clk),
332
                                                              .q(ack_buf));
333
 
334
   assign        ack_buf_vec = ack_buf_is_nack    ? {{REG_WIDTH/UCB_IOB_WIDTH{1'b0}},
335
                                                     {64/UCB_IOB_WIDTH{1'b1}}} :
336
                               ack_buf_is_data128 ? {(REG_WIDTH+64)/UCB_IOB_WIDTH{1'b1}} :
337
                                                    {(64+64)/UCB_IOB_WIDTH{1'b1}};
338
 
339
   assign        ack_busy = ack_buf_vld;
340
 
341
 
342
   /************************************************************
343
    * Outbound Interrupt
344
    ************************************************************/
345
   // Assertion: int_buf_wr shoudn't be asserted if int_buf_busy
346
   assign        int_buf_wr = int_vld;
347
 
348
   assign        int_buf_vld_next = int_buf_wr ? 1'b1 :
349
                                    int_buf_rd ? 1'b0 :
350
                                                 int_buf_vld;
351
 
352
   dffrl_ns #(1) int_buf_vld_ff (.din(int_buf_vld_next),
353
                                 .clk(clk),
354
                                 .rst_l(rst_l),
355
                                 .q(int_buf_vld));
356
 
357
   assign        int_buf_in = {int_vec,
358
                               int_stat,
359
                               dev_id,
360
                               int_thr_id,
361
                               int_typ};
362
 
363
   dffe_ns #(`UCB_INT_VEC_HI-`UCB_PKT_LO+1) int_buf_ff (.din(int_buf_in),
364
                                                        .en(int_buf_wr),
365
                                                        .clk(clk),
366
                                                        .q(int_buf));
367
 
368
   assign        int_buf_vec = {{REG_WIDTH/UCB_IOB_WIDTH{1'b0}},
369
                                {64/UCB_IOB_WIDTH{1'b1}}};
370
 
371
   assign        int_busy = int_buf_vld;
372
 
373
 
374
   /************************************************************
375
    * Outbound ack/interrupt Arbitration
376
    ************************************************************/
377
   dffrle_ns #(1) int_last_rd_ff (.din(int_buf_rd),
378
                                  .en(ack_buf_rd|int_buf_rd),
379
                                  .rst_l(rst_l),
380
                                  .clk(clk),
381
                                  .q(int_last_rd));
382
 
383
   assign        ack_buf_rd = ~outdata_buf_busy & ack_buf_vld &
384
                              (~int_buf_vld | int_last_rd);
385
 
386
   assign        int_buf_rd = ~outdata_buf_busy & int_buf_vld &
387
                              (~ack_buf_vld | ~int_last_rd);
388
 
389
   assign        outdata_buf_wr = ack_buf_rd | int_buf_rd;
390
 
391
   assign        outdata_buf_in = ack_buf_rd ? {ack_buf[REG_WIDTH+`UCB_BUF_HI:`UCB_BUF_HI+1],
392
                                                {(`UCB_RSV_HI-`UCB_RSV_LO+1){1'b0}},
393
                                                {(`UCB_ADDR_HI-`UCB_ADDR_LO+1){1'b0}},
394
                                                {(`UCB_SIZE_HI-`UCB_SIZE_LO+1){1'b0}},
395
                                                ack_buf[`UCB_BUF_HI:`UCB_BUF_LO],
396
                                                ack_buf[`UCB_THR_HI:`UCB_THR_LO],
397
                                                ack_buf[`UCB_PKT_HI:`UCB_PKT_LO]}:
398
                                               {{REG_WIDTH{1'b0}},
399
                                                {(`UCB_INT_RSV_HI-`UCB_INT_RSV_LO+1){1'b0}},
400
                                                int_buf[`UCB_INT_VEC_HI:`UCB_INT_VEC_LO],
401
                                                int_buf[`UCB_INT_STAT_HI:`UCB_INT_STAT_LO],
402
                                                int_buf[`UCB_INT_DEV_HI:`UCB_INT_DEV_LO],
403
                                                int_buf[`UCB_THR_HI:`UCB_THR_LO],
404
                                                int_buf[`UCB_PKT_HI:`UCB_PKT_LO]};
405
 
406
   assign        outdata_vec_in = ack_buf_rd ? ack_buf_vec :
407
                                               int_buf_vec;
408
 
409
   ucb_bus_out #(UCB_IOB_WIDTH, REG_WIDTH) ucb_bus_out (.rst_l(rst_l),
410
                                                        .clk(clk),
411
                                                        .outdata_buf_wr(outdata_buf_wr),
412
                                                        .outdata_buf_in(outdata_buf_in),
413
                                                        .outdata_vec_in(outdata_vec_in),
414
                                                        .outdata_buf_busy(outdata_buf_busy),
415
                                                        .vld(ucb_iob_vld),
416
                                                        .data(ucb_iob_data),
417
                                                        .stall(iob_ucb_stall));
418
 
419
 
420
`undef          UCB_BUF_WIDTH
421
 
422
endmodule // ucb_flow_2buf
423
 
424
 
425
// Local Variables:
426
// verilog-library-directories:(".")
427
// End:
428
 
429
 
430
 
431
 
432
 
433
 
434
 

powered by: WebSVN 2.1.0

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