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

Subversion Repositories pci

[/] [pci/] [tags/] [rel_3/] [rtl/] [verilog/] [wb_slave.v] - Blame information for rev 6

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 mihad
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  File name "wb_slave.v"                                      ////
4
////                                                              ////
5
////  This file is part of the "PCI bridge" project               ////
6
////  http://www.opencores.org/cores/pci/                         ////
7
////                                                              ////
8
////  Author(s):                                                  ////
9
////      - Miha Dolenc (mihad@opencores.org)                     ////
10
////                                                              ////
11
////  All additional information is avaliable in the README       ////
12
////  file.                                                       ////
13
////                                                              ////
14
////                                                              ////
15
//////////////////////////////////////////////////////////////////////
16
////                                                              ////
17
//// Copyright (C) 2001 Miha Dolenc, mihad@opencores.org          ////
18
////                                                              ////
19
//// This source file may be used and distributed without         ////
20
//// restriction provided that this copyright statement is not    ////
21
//// removed from the file and that any derivative work contains  ////
22
//// the original copyright notice and the associated disclaimer. ////
23
////                                                              ////
24
//// This source file is free software; you can redistribute it   ////
25
//// and/or modify it under the terms of the GNU Lesser General   ////
26
//// Public License as published by the Free Software Foundation; ////
27
//// either version 2.1 of the License, or (at your option) any   ////
28
//// later version.                                               ////
29
////                                                              ////
30
//// This source is distributed in the hope that it will be       ////
31
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
32
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
33
//// PURPOSE.  See the GNU Lesser General Public License for more ////
34
//// details.                                                     ////
35
////                                                              ////
36
//// You should have received a copy of the GNU Lesser General    ////
37
//// Public License along with this source; if not, download it   ////
38
//// from http://www.opencores.org/lgpl.shtml                     ////
39
////                                                              ////
40
//////////////////////////////////////////////////////////////////////
41
//
42
// CVS Revision History
43
//
44
// $Log: not supported by cvs2svn $
45 6 mihad
// Revision 1.1.1.1  2001/10/02 15:33:47  mihad
46
// New project directory structure
47 2 mihad
//
48 6 mihad
//
49 2 mihad
 
50
`include "bus_commands.v"
51
`include "constants.v"
52 6 mihad
`include "timescale.v"
53 2 mihad
 
54
module WB_SLAVE(    wb_clock_in,
55
                    reset_in,
56
                    wb_hit_in,
57
                    wb_conf_hit_in,
58
                    wb_map_in,
59
                    wb_pref_en_in,
60
                    wb_mrl_en_in,
61
                    wb_addr_in,
62
                    del_bc_in,
63
                    wb_del_req_pending_in,
64
                    wb_del_comp_pending_in,
65
                    pci_drcomp_pending_in,
66
                    del_bc_out,
67
                    del_req_out,
68
                    del_done_out,
69
                        del_burst_out,
70
                    del_write_out,
71
                    del_write_in,
72
                    del_error_in,
73
                    del_in_progress_out,
74
                    ccyc_addr_in,
75
                    wb_del_addr_in,
76
                    wb_del_be_in,
77
                    wb_conf_offset_out,
78
                    wb_conf_renable_out,
79
                    wb_conf_wenable_out,
80
                    wb_conf_be_out,
81
                    wb_conf_data_in,
82
                    wb_conf_data_out,
83
                    wb_data_out,
84
                    wb_cbe_out,
85
                    wbw_fifo_wenable_out,
86
                    wbw_fifo_control_out,
87
                    wbw_fifo_almost_full_in,
88
                    wbw_fifo_full_in,
89
                    wbr_fifo_renable_out,
90
                    wbr_fifo_be_in,
91
                    wbr_fifo_data_in,
92
                    wbr_fifo_control_in,
93
                    wbr_fifo_flush_out,
94
                    wbr_fifo_empty_in,
95
                    pciw_fifo_empty_in,
96
                    wbs_lock_in,
97
                    CYC_I,
98
                    STB_I,
99
                    WE_I,
100
                    SEL_I,
101
                    SDATA_I,
102
                    SDATA_O,
103
                    ACK_O,
104
                    RTY_O,
105
                    ERR_O,
106
                    CAB_I
107
                );
108
 
109
/*----------------------------------------------------------------------------------------------------------------------
110
Various parameters needed for state machine and other stuff
111
----------------------------------------------------------------------------------------------------------------------*/
112
parameter WBR_SEL  = 1'b0 ;
113
parameter CONF_SEL = 1'b1 ;
114
 
115
`define FSM_BITS 3
116
parameter S_IDLE         = `FSM_BITS'h0 ;
117
parameter S_DEC1         = `FSM_BITS'h1 ;
118
parameter S_DEC2         = `FSM_BITS'h2 ;
119
parameter S_START        = `FSM_BITS'h3 ;
120
parameter S_W_ADDR_DATA  = `FSM_BITS'h4 ;
121
parameter S_READ         = `FSM_BITS'h5 ;
122
parameter S_CONF_WRITE   = `FSM_BITS'h6 ;
123
parameter S_CONF_READ    = `FSM_BITS'h7 ;
124
 
125
/*----------------------------------------------------------------------------------------------------------------------
126
System signals inputs
127
wb_clock_in - WISHBONE bus clock input
128
reset_in    - system reset input controlled by bridge's reset logic
129
----------------------------------------------------------------------------------------------------------------------*/
130
input wb_clock_in, reset_in ;
131
 
132
/*----------------------------------------------------------------------------------------------------------------------
133
Inputs from address decoding logic
134
wb_hit_in - Decoder logic indicates if address is in a range of one of images
135
wb_conf_hit_in - Decoder logic indicates that address is in configuration space range
136
wb_map_in   - Decoder logic provides information about image mapping - memory mapped image   - wb_map_in = 0
137
                                                                       IO space mapped image - wb_map_in = 1
138
wb_pref_en_in - Prefetch enable signal from currently selected image - used for PCI bus command usage
139
wb_addr_in - Address already transalted from WB bus to PCI bus input
140
wb_mrl_en_in - Memory read line enable input for each image
141
----------------------------------------------------------------------------------------------------------------------*/
142
input [4:0]     wb_hit_in ;         // hit indicators
143
input           wb_conf_hit_in ;    // configuration hit indicator
144
input [4:0]     wb_pref_en_in ;     // prefetch enable from all images
145
input [4:0]     wb_mrl_en_in ;      // Memory Read line command enable from images 
146
input [4:0]     wb_map_in ;         // address space mapping indicators - 1 memory space mapping, 0-IO space mapping
147
input [31:0]    wb_addr_in ;        // Translated address input
148
 
149
/*----------------------------------------------------------------------------------------------------------------------
150
Delayed transaction control inputs and outputs:
151
Used for locking particular accesses when delayed transactions are in progress:
152
wb_del_addr_in - delayed transaction address input - when completion is ready it's used for transaction decoding
153
wb_del_be_in   - delayed transaction byte enable input - when completion is ready it's used for transaction decoding
154
----------------------------------------------------------------------------------------------------------------------*/
155
input  [31:0] wb_del_addr_in ;
156
input  [3:0]  wb_del_be_in ;
157
 
158
input [3:0] del_bc_in ;           // delayed request bus command used
159
input       wb_del_req_pending_in ;   // delayed request pending indicator
160
input       wb_del_comp_pending_in ;  // delayed completion pending indicator
161
input       pci_drcomp_pending_in ; // PCI initiated delayed read completion pending 
162
 
163
output [3:0] del_bc_out ; // delayed transaction bus command output
164
 
165
output del_req_out ; // output for issuing delayed transaction requests
166
 
167
output del_done_out ; // output indicating current delayed completion finished on WISHBONE bus
168
 
169
output del_burst_out ; // delayed burst transaction indicator
170
 
171
output del_in_progress_out ; // delayed in progress indicator - since delayed transaction can be a burst transaction, progress indicator must be used for proper operation
172
 
173
output del_write_out ;   // write enable for delayed transaction - used for indicating that transaction is a write
174
 
175
input  del_write_in ;    // indicates that current delayed completion is from a write request
176
input  del_error_in ;    // indicate that delayed request terminated with an error - used for write requests
177
 
178
input  [31:0] ccyc_addr_in ; // configuration cycle address input - it's separate from other addresses, since it is stored separately and decoded for type 0 configuration access
179
 
180
/*----------------------------------------------------------------------------------------------------------------------
181
Configuration space access control and data signals
182
wb_conf_offset_out  - lower 12 bits of address input provided for register offset
183
wb_conf_renable     - read enable signal for configuration space accesses
184
wb_conf_wenable     - write enable signal for configuration space accesses
185
wb_conf_be_out      - byte enable signals for configuration space accesses
186
wb_conf_data_in     - data from configuration space
187
wb_conf_data_in     - data provided for configuration space
188
----------------------------------------------------------------------------------------------------------------------*/
189
output [11:0]   wb_conf_offset_out ;  // register offset output
190
output          wb_conf_renable_out,  // configuration read and write enable outputs
191
                wb_conf_wenable_out ;
192
output [3:0]    wb_conf_be_out ;      // byte enable outputs for configuration space
193
input  [31:0]   wb_conf_data_in ;     // configuration data input from configuration space
194
output [31:0]   wb_conf_data_out ;    // configuration data output for configuration space
195
 
196
/*----------------------------------------------------------------------------------------------------------------------
197
Data from WISHBONE bus output to interiror of the core:
198
Data output is used for normal and configuration accesses.
199
---------------------------------------------------------------------------------------------------------------------*/
200
output [31:0] wb_data_out ;
201
 
202
/*----------------------------------------------------------------------------------------------------------------------
203
Bus command - byte enable output - during address phase of image access this bus holds information about PCI
204
bus command that should be used, during dataphases ( configuration or image access ) this bus contains inverted
205
SEL_I signals
206
---------------------------------------------------------------------------------------------------------------------*/
207
output [3:0] wb_cbe_out ;
208
 
209
/*----------------------------------------------------------------------------------------------------------------------
210
WBW_FIFO control signals used for sinking data into WBW_FIFO and status monitoring
211
---------------------------------------------------------------------------------------------------------------------*/
212
output       wbw_fifo_wenable_out ;    // write enable for WBW_FIFO output
213
output [3:0] wbw_fifo_control_out ;    // control bus output for WBW_FIFO
214
input        wbw_fifo_almost_full_in ; // almost full status indicator from WBW_FIFO
215
input        wbw_fifo_full_in ;        // full status indicator from WBW_FIFO
216
 
217
/*----------------------------------------------------------------------------------------------------------------------
218
WBR_FIFO control signals used for fetching data from WBR_FIFO and status monitoring
219
---------------------------------------------------------------------------------------------------------------------*/
220
output          wbr_fifo_renable_out ;      // WBR_FIFO read enable output
221
input   [3:0]   wbr_fifo_be_in ;            // byte enable input from WBR_FIFO
222
input   [31:0]  wbr_fifo_data_in ;          // data input from WBR_FIFO
223
input   [3:0]   wbr_fifo_control_in ;       // control bus input from WBR_FIFO
224
output          wbr_fifo_flush_out ;        // flush signal for WBR_FIFO
225
input           wbr_fifo_empty_in ;         // empty status indicator from WBR_FIFO
226
 
227
// used for transaction ordering requirements - WISHBONE read cannot complete until writes from PCI are completed
228
input           pciw_fifo_empty_in ;        // empty status indicator from PCIW_FIFO
229
 
230
/*----------------------------------------------------------------------------------------------------------------------
231
wbs_lock_in - internal signal - when error reporting is enabled and PCI master detects an error while completing
232
posted write on PCI, then WISHBONE slave unit doesn't accept any new requests or posted writes. Delayed completions
233
are allowed to complete on WISHBONE if all other requirements are satisfied also.
234
---------------------------------------------------------------------------------------------------------------------*/
235
input           wbs_lock_in ;
236
 
237
/*----------------------------------------------------------------------------------------------------------------------
238
WISHBONE bus interface signals - can be connected directly to WISHBONE bus
239
---------------------------------------------------------------------------------------------------------------------*/
240
input           CYC_I ;     // cycle indicator
241
input           STB_I ;     // strobe input - input data is valid when strobe and cycle indicator are high
242
input           WE_I  ;     // write enable input - 1 - write operation, 0 - read operation
243
input   [3:0]   SEL_I ;     // Byte select inputs
244
input   [31:0]  SDATA_I ;   // WISHBONE slave interface input data bus
245
output  [31:0]  SDATA_O ;   // WISHBONE slave interface output data bus
246
output          ACK_O ;     // Acknowledge output - qualifies valid data on data output bus or received data on data input bus
247
output          RTY_O ;     // retry output - signals to WISHBONE master that cycle should be terminated and retried later
248
output          ERR_O ;     // Signals to WISHBONE master that access resulted in an error
249
input           CAB_I ;     // consecutive address burst input - indicates that master will do a serial address transfer in current cycle
250
 
251
reg [(`FSM_BITS - 1):0]  c_state ; //current state register
252
// synopsys state_vector c_state
253
 
254
reg [(`FSM_BITS - 1):0]  n_state ; //next state input to current state register
255
 
256
// lock register - lock signal can cross clock domains, so here is register for it
257
reg lock ;
258
always@(posedge reset_in or posedge wb_clock_in)
259
begin
260
    if (reset_in)
261
        lock <= #`FF_DELAY 1'b0 ;
262
    else
263
        lock <= #`FF_DELAY wbs_lock_in ;
264
end
265
 
266
// state machine register control
267
always@(posedge wb_clock_in or posedge reset_in)
268
begin
269
    if (reset_in)
270
        c_state <= #`FF_DELAY S_IDLE ;
271
    else
272
        c_state <= #`FF_DELAY n_state ;
273
end
274
 
275
 
276
// write operation indicator for delayed transaction requests
277
assign del_write_out = WE_I ;
278
 
279
// variable for bus command multiplexer logic output for delayed requests
280
reg [3:0] del_bc ;
281
 
282
//register for intermediate data and select storage
283
reg [35:0] d_incoming ;
284
 
285
// enable for incoming data register
286
reg d_incoming_ena ;
287
 
288
// incoming data register control logic
289
always@(posedge wb_clock_in or posedge reset_in)
290
begin
291
        if (reset_in)
292
                d_incoming <= #`FF_DELAY {35{1'b0}} ;
293
        else if (d_incoming_ena)
294
                d_incoming <= #`FF_DELAY {SEL_I, SDATA_I} ;
295
end
296
 
297
/*===================================================================================================================================================================================
298
Write allow for image accesses. Writes through images are allowed when all of following are true:
299
- WBW_FIFO musn't be almost full nor full for image writes to be allowed - Every transaction takes at least two locations in the FIFO
300
- delayed read from from WISHBONE to PCI request musn't be present
301
- delayed read from PCI to WISHBONE completion musn't be present
302
- lock input musn't be set - it can be set because of error reporting or because PCI master state machine is disabled
303
===================================================================================================================================================================================*/
304
wire wimg_wallow           = ~|{ wbw_fifo_almost_full_in , wbw_fifo_full_in, wb_del_req_pending_in, pci_drcomp_pending_in, lock } ;
305
reg decode_en ;
306
reg img_wallow ;
307
always@(posedge reset_in or posedge wb_clock_in)
308
begin
309
    if (reset_in)
310
        img_wallow <= #`FF_DELAY 1'b0 ;
311
    else
312
    if (decode_en)
313
        img_wallow <= #`FF_DELAY wimg_wallow ;
314
end
315
 
316
 
317
/*===================================================================================================================================================================================
318
WISHBONE slave can request an image read accesses when all of following are true:
319
- delayed completion is not present
320
- delayed request is not present
321
- operation is not locked because of error reporting mechanism or because PCI master is disabled
322
===================================================================================================================================================================================*/
323
wire wdo_del_request     = ~|{ wb_del_req_pending_in, wb_del_comp_pending_in, lock } ;
324
reg do_del_request ;
325
always@(posedge reset_in or posedge wb_clock_in)
326
begin
327
    if (reset_in)
328
        do_del_request <= #`FF_DELAY 1'b0 ;
329
    else
330
    if (decode_en)
331
        do_del_request <= #`FF_DELAY wdo_del_request ;
332
end
333
 
334
/*===================================================================================================================================================================================
335
WISHBONE slave can complete an image read accesses when all of following are true:
336
- delayed read completion is present
337
- delayed read completion is the same as current read access ( dread_completion_hit is 1 )
338
- PCI Write FIFO is empty - no posted write is waiting to be finished in PCIW_FIFO
339
- WBR_FIFO empty status is active
340
===================================================================================================================================================================================*/
341
wire del_bc_hit = ( del_bc == del_bc_in ) ;
342
 
343
wire wdel_addr_hit = ( wb_del_addr_in == wb_addr_in ) && ( SEL_I == wb_del_be_in ) ;
344
reg  del_addr_hit ;
345
always@(posedge reset_in or posedge wb_clock_in)
346
begin
347
    if (reset_in)
348
        del_addr_hit <= #`FF_DELAY 1'b0 ;
349
    else
350
    if ( decode_en )
351
        del_addr_hit <= #`FF_DELAY wdel_addr_hit ;
352
end
353
 
354
wire wdel_completion_allow = wb_del_comp_pending_in && ((~del_write_in && ~WE_I && pciw_fifo_empty_in && ~wbr_fifo_empty_in) || (del_write_in && WE_I)) ;
355
 
356
reg del_completion_allow ;
357
always@(posedge reset_in or posedge wb_clock_in)
358
begin
359
    if (reset_in)
360
        del_completion_allow <= #`FF_DELAY 1'b0 ;
361
    else
362
    if ( decode_en )
363
        del_completion_allow <= #`FF_DELAY wdel_completion_allow ;
364
end
365
 
366
wire do_dread_completion = del_completion_allow && del_bc_hit && del_addr_hit ;
367
 
368
// address allignement indicator
369
wire alligned_address = ~|(wb_addr_in[1:0]) ;
370
 
371
`ifdef GUEST
372
 
373
    // wires indicating allowance for configuration cycle generation requests
374
    wire do_ccyc_req  = 1'b0 ;
375
    wire do_ccyc_comp = 1'b0 ;
376
 
377
    // wires indicating allowance for interrupt acknowledge cycle generation requests
378
    wire do_iack_req  = 1'b0 ;
379
    wire do_iack_comp = 1'b0 ;
380
 
381
    // variables for configuration access control signals
382
    reg conf_wenable ;
383
    assign wb_conf_wenable_out = 1'b0 ;
384
 
385
    // configuration cycle data register hit
386
    wire ccyc_hit = 1'b0 ;
387
    wire iack_hit = 1'b0 ;
388
 
389
`else
390
`ifdef HOST
391
    // only host implementation has access for generating interrupt acknowledge and configuration cycles
392
    // configuration cycle data register hit
393
    wire wccyc_hit = (wb_addr_in[8:2] == {1'b1, `CNF_DATA_ADDR}) && alligned_address ;
394
    reg ccyc_hit ;
395
    always@(posedge reset_in or posedge wb_clock_in)
396
    begin
397
        if (reset_in)
398
            ccyc_hit <= #`FF_DELAY 1'b0 ;
399
        else
400
        if (decode_en)
401
            ccyc_hit <= #`FF_DELAY wccyc_hit ;
402
    end
403
 
404
    wire wiack_hit = (wb_addr_in[8:2] == {1'b1, `INT_ACK_ADDR}) && alligned_address ;
405
    reg iack_hit ;
406
 
407
    always@(posedge reset_in or posedge wb_clock_in)
408
    begin
409
        if (reset_in)
410
            iack_hit <= #`FF_DELAY 1'b0 ;
411
        else
412
        if (decode_en)
413
            iack_hit <= #`FF_DELAY wiack_hit ;
414
    end
415
 
416
    // wires indicating allowance for configuration cycle generation requests
417
    wire do_ccyc_req  = do_del_request && ccyc_hit;
418
    wire do_ccyc_comp = del_completion_allow && del_bc_hit && ccyc_hit;
419
 
420
    // wires indicating allowance for interrupt acknowledge cycle generation requests
421
    wire do_iack_req  = do_del_request && iack_hit ;
422
    wire do_iack_comp = del_completion_allow && del_bc_hit && ccyc_hit;
423
 
424
    // variables for configuration access control signals
425
    reg conf_wenable ;
426
    assign wb_conf_wenable_out = conf_wenable ;
427
 
428
`endif
429
`endif
430
 
431
// configuration read enable - supplied for host and guest bridges
432
reg conf_renable ;
433
assign wb_conf_renable_out = conf_renable ;
434
 
435
// wire for write attempt - 1 when external WB master is attempting a write
436
wire wattempt = ( CYC_I && STB_I && WE_I ) ; // write is qualified when cycle, strobe and write enable inputs are all high
437
 
438
// wire for read attempt - 1 when external WB master is attempting a read
439
wire rattempt = ( CYC_I && STB_I && ~WE_I ) ; // read is qualified when cycle and strobe are high and write enable is low
440
 
441
// burst access indicator
442
wire burst_transfer = CYC_I && CAB_I ;
443
 
444
// SEL_I error indicator for IO and configuration accesses - select lines must be alligned with address
445
reg sel_error ;
446
always@(wb_addr_in or SEL_I)
447
begin
448
    case (wb_addr_in[1:0])
449
        2'b00: sel_error = ~SEL_I[0] ; // select 0 must be 1, all others are don't cares.
450
        2'b01: sel_error = ~SEL_I[1] || SEL_I[0]  ; // byte 0 can't be selected, byte 1 must be selected
451
        2'b10: sel_error = ~SEL_I[2] || SEL_I[1] || SEL_I[0] ; // bytes 0 and 1 can't be selected, byte 2 must be selected
452
        2'b11: sel_error = ~SEL_I[3] || SEL_I[2] || SEL_I[1] || SEL_I[0] ; // bytes 0, 1 and 2 can't be selected, byte 3 must be selected
453
    endcase
454
end
455
 
456
// WBW_FIFO control output
457
reg [3:0] wbw_fifo_control ;
458
assign wbw_fifo_control_out = wbw_fifo_control ; //control bus output for WBW_FIFO
459
 
460
// WBW_FIFO wenable output assignment
461
reg wbw_fifo_wenable ;
462
assign wbw_fifo_wenable_out = wbw_fifo_wenable ; //write enable for WBW_FIFO
463
 
464
// WBR_FIFO control outputs
465
reg wbr_fifo_flush, wbr_fifo_renable ; // flush and read enable outputs
466
assign wbr_fifo_renable_out = wbr_fifo_renable ; //read enable for wbr_fifo
467
 
468
reg wbr_fifo_flush_out ;
469
 
470
always@(posedge reset_in or posedge wb_clock_in)
471
begin
472
    if ( reset_in )
473
        wbr_fifo_flush_out <= #`FF_DELAY 1'b0 ;
474
    else
475
        wbr_fifo_flush_out <= #`FF_DELAY wbr_fifo_flush ;
476
end
477
 
478
// delayed transaction request control signals
479
reg del_req, del_done ;
480
assign del_req_out  = del_req ; // read request
481
assign del_done_out = del_done ; // read done
482
 
483
// WISHBONE handshaking control outputs
484
reg ack, rty, err ;
485
assign ACK_O = ack ;
486
assign RTY_O = rty ;
487
assign ERR_O = err ;
488
 
489
/*----------------------------------------------------------------------------------------------------------------------
490
Control logic for image hits
491
img_hit - state of wb_hit_in bus when first data is acknowledged
492
---------------------------------------------------------------------------------------------------------------------*/
493
reg [4:0] img_hit ;
494
always@(posedge wb_clock_in or posedge reset_in)
495
begin
496
    if (reset_in)
497
        img_hit <= #`FF_DELAY 5'h00 ;
498
    else
499
    if (decode_en)
500
        img_hit <= #`FF_DELAY wb_hit_in ;
501
end
502
 
503
wire wb_hit = |( img_hit ) ;
504
 
505
/*----------------------------------------------------------------------------------------------------------------------
506
Control logic for image control signals
507
pref_en - prefetch enable of currently selected image
508
mrl_en  - Memory read line enable of currently selected image
509
map     - Address space mapping for currently selected image
510
---------------------------------------------------------------------------------------------------------------------*/
511
reg pref_en, mrl_en, map ;
512
 
513
wire wpref_en   = |(wb_pref_en_in & wb_hit_in) ;
514
wire wmrl_en    = |(wb_pref_en_in & wb_hit_in) ;
515
wire wmap       = |(wb_map_in & wb_hit_in) ;
516
 
517
always@(posedge reset_in or posedge wb_clock_in)
518
begin
519
    if (reset_in)
520
    begin
521
        pref_en     <= #`FF_DELAY 1'b0 ;
522
        mrl_en      <= #`FF_DELAY 1'b0 ;
523
        map         <= #`FF_DELAY 1'b0 ;
524
    end
525
    else
526
    if ( decode_en )
527
    begin
528
        pref_en     <= #`FF_DELAY wpref_en ;
529
        mrl_en      <= #`FF_DELAY wmrl_en ;
530
        map         <= #`FF_DELAY wmap ;
531
    end
532
end
533
 
534
assign del_burst_out = CAB_I && pref_en && ~WE_I; // delayed burst indicator - only when WB master attempts CAB transfer and prefetch enable of corresponding image is set - 
535
                                                  // applies for reads only - delayed write cannot be a burst
536
 
537
reg wb_conf_hit ;
538
always@(posedge reset_in or posedge wb_clock_in)
539
begin
540
    if (reset_in)
541
        wb_conf_hit <= #`FF_DELAY 1'b0 ;
542
    else
543
    if (decode_en)
544
        wb_conf_hit <= #`FF_DELAY wb_conf_hit_in ;
545
end
546
 
547
/*----------------------------------------------------------------------------------------------------------------------
548
Delayed transaction bus command generation
549
Bus command for delayed reads depends on image's address space mapping and control bits and
550
whether or not these are interrupt acknowledge requests or configuration cycle requests
551
---------------------------------------------------------------------------------------------------------------------*/
552
assign del_bc_out = del_bc ;
553
 
554
always@(map or mrl_en or ccyc_hit or WE_I or wb_conf_hit or CAB_I or pref_en)
555
begin
556
    if (wb_conf_hit)
557
    begin
558
        case( {ccyc_hit, WE_I} )
559
            2'b11:  del_bc = `BC_CONF_WRITE ;
560
            2'b10:  del_bc = `BC_CONF_READ ;
561
            2'b01:  del_bc = `BC_IACK ;
562
            2'b00:  del_bc = `BC_IACK ;
563
        endcase
564
    end
565
    else
566
    begin
567
        case ( {map, CAB_I && mrl_en && pref_en} )
568
            2'b11:  del_bc = `BC_IO_READ ;
569
            2'b10:  del_bc = `BC_IO_READ ;
570
            2'b01:  del_bc = `BC_MEM_READ_LN ;
571
            2'b00:  del_bc = `BC_MEM_READ ;
572
        endcase
573
    end
574
end
575
 
576
// WISHBONE data output select lines for output multiplexor
577
reg sdata_o_sel ;
578
 
579
reg del_in_progress_out ; // state machine indicates whether current read completion is in progress on WISHBONE bus
580
 
581
wire image_access_error = (map && (burst_transfer || sel_error)) ||   // IO write is a burst or has wrong select lines active= Error
582
                          (~map && ~alligned_address) ;               // Mem write to nonaligned address = error;
583
 
584
`ifdef HOST
585
    reg [1:0]   wbw_data_out_sel ;
586
    parameter SEL_ADDR_IN = 2'b10 ;
587
    parameter SEL_CCYC_ADDR = 2'b11 ;
588
    parameter SEL_DATA_IN   = 2'b00 ;
589
`else
590
`ifdef GUEST
591
    reg wbw_data_out_sel ;
592
    parameter SEL_ADDR_IN = 1'b1 ;
593
    parameter SEL_DATA_IN = 1'b0 ;
594
`endif
595
`endif
596
 
597
// state machine logic
598
always@(
599
        c_state                     or
600
        wattempt                    or
601
        img_wallow                  or
602
        burst_transfer              or
603
        wb_hit                      or
604
        map                         or
605
        alligned_address            or
606
        rattempt                    or
607
        do_dread_completion         or
608
        wbr_fifo_control_in         or
609
        wb_conf_hit                 or
610
        do_ccyc_req                 or
611
        do_ccyc_comp                or
612
        ccyc_hit                    or
613
        del_error_in                or
614
        do_iack_req                 or
615
        do_iack_comp                or
616
        iack_hit                    or
617
        image_access_error          or
618
        wbw_fifo_almost_full_in     or
619
        do_del_request              or
620
        wbr_fifo_empty_in
621
       )
622
begin
623
    // default signal values
624
    // response signals inactive
625
    ack         = 1'b0 ;
626
    rty         = 1'b0 ;
627
    err         = 1'b0 ;
628
 
629
    //write signals inactive
630
    wbw_fifo_control[`ADDR_CTRL_BIT] = 1'b1 ;
631
    wbw_fifo_control[`DATA_ERROR_CTRL_BIT] = 1'b0 ;
632
    wbw_fifo_control[`LAST_CTRL_BIT] = 1'b0 ;
633
    wbw_fifo_control[`UNUSED_CTRL_BIT] = 1'b0 ;
634
 
635
    wbw_fifo_wenable = 1'b0 ;
636
    d_incoming_ena   = 1'b0 ;
637
 
638
    // read signals inactive
639
    wbr_fifo_flush   = 1'b0 ;
640
    wbr_fifo_renable = 1'b0 ;
641
    del_req          = 1'b0 ;
642
    del_done         = 1'b0 ;
643
 
644
    // configuration space control signals inactive
645
    conf_wenable = 1'b0 ;
646
    conf_renable = 1'b0 ;
647
 
648
        // WISHBONE data output selection - drive wbr output
649
    sdata_o_sel = WBR_SEL ;
650
 
651
    // read is not in progress
652
    del_in_progress_out = 1'b0 ;
653
    decode_en = 1'b0 ;
654
    wbw_data_out_sel = SEL_ADDR_IN ;
655
 
656
    case (c_state)
657
    S_IDLE: begin
658
                if ( wattempt || rattempt )
659
                begin
660
                    `ifdef WB_DECODE_FAST
661
                    decode_en = 1'b1 ;
662
                    n_state = S_START ;
663
                    `else
664
                    n_state = S_DEC1 ;
665
                    `endif
666
                end
667
                else
668
                    n_state = S_IDLE ;
669
            end
670
 
671
    S_DEC1: begin
672
                if ( wattempt || rattempt )
673
                begin
674
                    `ifdef WB_DECODE_MEDIUM
675
                    decode_en = 1'b1 ;
676
                    n_state = S_START ;
677
                    `else
678
                    n_state = S_DEC2 ;
679
                    `endif
680
                end
681
                else
682
                    n_state = S_IDLE ;
683
            end
684
 
685
    S_DEC2: begin
686
 
687
                if ( wattempt || rattempt )
688
                begin
689
                    decode_en = 1'b1 ;
690
                    n_state = S_START ;
691
                end
692
                else
693
                    n_state = S_IDLE ;
694
            end
695
 
696
    S_START:begin
697
                if (wb_conf_hit) // configuration space hit
698
                begin
699
                    if ( wattempt )
700
                        n_state = S_CONF_WRITE ; // go to conf. write state
701
                    else
702
                    if ( rattempt )
703
                    begin
704
                        n_state     = S_CONF_READ ; // go to conf. read state
705
                        if(~(ccyc_hit || iack_hit))
706
                            sdata_o_sel = CONF_SEL ;
707
                    end
708
                    else
709
                        n_state = S_IDLE ; // master terminated - go back to idle state
710
 
711
                end // wb_conf_hit*/
712
                else
713
                if(wb_hit && (wattempt || rattempt))
714
                begin
715
 
716
                    // check error conditions for image writes or reads
717
                    if ( image_access_error )
718
                    begin
719
                        n_state = S_IDLE ; // go back to idle state because of an error condition
720
                        err     = 1'b1 ;
721
                    end // error conditions
722
                    else
723
                    // check for retry conditions for image writes or reads
724
                    if ( (wattempt && ~img_wallow) ||
725
                         (rattempt && ~do_dread_completion) // write to image not allowed, no read ready yet - retry
726
                       )
727
                    begin
728
                        n_state = S_IDLE ; // go back to IDLE
729
 
730
                        rty     = 1'b1 ;
731
 
732
                        del_req = do_del_request && rattempt ;
733
 
734
                    end //retry
735
                    else // everything OK - proceed
736
                    if ( wattempt )
737
                    begin
738
                        n_state = S_W_ADDR_DATA ; // goto write transfer state
739
 
740
                        // respond with acknowledge
741
                        ack              = 1'b1 ;
742
 
743
                        wbw_fifo_wenable = 1'b1 ;
744
 
745
                        // data is latched to data incoming intermidiate stage - it will be put in FIFO later
746
                        d_incoming_ena   = 1'b1 ;
747
                    end
748
                    else
749
                    begin
750
                        err = wbr_fifo_control_in[`DATA_ERROR_CTRL_BIT] ;
751
                        ack = ~wbr_fifo_control_in[`DATA_ERROR_CTRL_BIT] ;
752
                        wbr_fifo_renable    = 1'b1 ;
753
                        del_in_progress_out = 1'b1 ;
754
 
755
                        if ( wbr_fifo_control_in[`DATA_ERROR_CTRL_BIT] || wbr_fifo_control_in[`LAST_CTRL_BIT] )
756
                        begin
757
 
758
                            n_state = S_IDLE ; // go back to idle state
759
                            // respond that read is finished
760
                            del_done     = 1'b1 ;
761
 
762
                        end // end read
763
                        else
764
                            n_state = S_READ ; // go to read state
765
                    end
766
                end
767
                else
768
                    n_state = S_IDLE ;
769
            end
770
 
771
    S_W_ADDR_DATA: begin
772
                        wbw_data_out_sel = SEL_DATA_IN ;
773
                        err = burst_transfer && wattempt && ~alligned_address ;
774
                        rty = burst_transfer && wattempt && wbw_fifo_almost_full_in ;
775
 
776
                        if ( ~burst_transfer || wattempt && ( ~alligned_address || wbw_fifo_almost_full_in) )
777
                        begin
778
                            n_state = S_IDLE ;
779
 
780
                            // write last data to FIFO and don't latch new data
781
                            wbw_fifo_control[`ADDR_CTRL_BIT] = 1'b0 ;
782
                            wbw_fifo_control[`LAST_CTRL_BIT] = 1'b1 ;
783
                            wbw_fifo_wenable = 1'b1 ;
784
                        end
785
                        else
786
                        begin
787
                            n_state = S_W_ADDR_DATA ;
788
                            wbw_fifo_control[`ADDR_CTRL_BIT] = 1'b0 ;
789
                            wbw_fifo_control[`LAST_CTRL_BIT] = 1'b0 ;
790
                            ack              = wattempt ;
791
                            wbw_fifo_wenable = wattempt ;
792
                            d_incoming_ena   = wattempt ;
793
                        end
794
                    end // S_W_ADDR_DATA
795
 
796
    S_READ:begin
797
                // this state is for reads only - in this state read is in progress all the time
798
                del_in_progress_out = 1'b1 ;
799
 
800
                ack = burst_transfer && rattempt && ~wbr_fifo_control_in[`DATA_ERROR_CTRL_BIT] && alligned_address    && ~wbr_fifo_empty_in ;
801
                err = burst_transfer && rattempt && ((wbr_fifo_control_in[`DATA_ERROR_CTRL_BIT] || ~alligned_address) && ~wbr_fifo_empty_in) ;
802
                rty = burst_transfer && rattempt && wbr_fifo_empty_in && alligned_address ;
803
 
804
                // if acknowledge is beeing signalled then enable read from wbr fifo
805
                wbr_fifo_renable = burst_transfer && rattempt && alligned_address && ~wbr_fifo_empty_in ;
806
 
807
                if ( ~burst_transfer || rattempt && (~alligned_address || wbr_fifo_empty_in || wbr_fifo_control_in[`DATA_ERROR_CTRL_BIT] || wbr_fifo_control_in[`LAST_CTRL_BIT]) )
808
                begin
809
                    n_state = S_IDLE ;
810
                    del_done = 1'b1 ;
811
                    wbr_fifo_flush = ~wbr_fifo_empty_in && ~(wbr_fifo_control_in[`DATA_ERROR_CTRL_BIT] || wbr_fifo_control_in[`LAST_CTRL_BIT]) ;
812
                end
813
                else
814
                begin
815
                    n_state          = S_READ ;
816
                end
817
            end // S_READ
818
 
819
    S_CONF_WRITE:  begin
820
                        `ifdef HOST
821
                            wbw_data_out_sel    = SEL_CCYC_ADDR ;
822
                        `endif
823
                        n_state             = S_IDLE ; // next state after configuration access is always idle
824
                        del_req             = do_ccyc_req && ~burst_transfer ;
825
                        del_done            = do_ccyc_comp && ~burst_transfer ;
826
                        del_in_progress_out = do_ccyc_comp && ~burst_transfer ;
827
 
828
                        if ( burst_transfer || ~alligned_address )
829
                        begin
830
                            err = 1'b1 ;
831
                        end
832
                        else
833
                        begin
834
                            if ( do_ccyc_req || (ccyc_hit && ~do_ccyc_comp))
835
                            begin
836
                                rty = 1'b1 ;
837
                            end
838
                            else
839
                            if ( do_ccyc_comp )
840
                            begin
841
                                err = del_error_in ;
842
                                ack = ~del_error_in ;
843
                            end
844
                            else
845
                            begin
846
                                ack = ~ccyc_hit ;
847
                                conf_wenable = ~ccyc_hit ;
848
                            end
849
                        end
850
                    end // S_CONF_WRITE
851
 
852
    S_CONF_READ:   begin
853
                        `ifdef HOST
854
                            wbw_data_out_sel = SEL_CCYC_ADDR ;
855
                        `endif
856
                        n_state = S_IDLE ; // next state after configuration access is always idle
857
                        del_req     = ~burst_transfer && ( do_ccyc_req || do_iack_req );
858
                        del_done    = ~burst_transfer && ( do_ccyc_comp || do_iack_comp ) ;
859
                        del_in_progress_out = ~burst_transfer && ( do_ccyc_comp || do_iack_comp ) ;
860
                        wbr_fifo_renable    = ~burst_transfer && ( do_ccyc_comp || do_iack_comp ) ;
861
 
862
                        if ( ~(ccyc_hit || iack_hit) )
863
                            sdata_o_sel = CONF_SEL ;
864
 
865
                        if ( burst_transfer || ~alligned_address )
866
                        begin
867
                            err = 1'b1 ;
868
                        end
869
                        else
870
                        begin
871
 
872
                            if ( do_ccyc_req || ( ccyc_hit && ~do_ccyc_comp ))
873
                            begin
874
                                rty = 1'b1 ;
875
                            end
876
                            else
877
                            if ( do_iack_req || ( iack_hit && ~do_iack_comp ))
878
                            begin
879
                                rty = 1'b1 ;
880
                            end
881
                            else
882
                            if ( do_iack_comp || do_ccyc_comp )
883
                            begin
884
                                err = del_error_in ;
885
                                ack = ~del_error_in ;
886
                            end
887
                            else
888
                            begin
889
                                ack = ~( ccyc_hit || iack_hit ) ;
890
                                conf_renable = ~( ccyc_hit || iack_hit ) ;
891
                            end
892
                        end
893
 
894
                    end //S_CONF_READ
895
    default:begin
896
                n_state = S_IDLE ; // return to idle state
897
            end //default
898
    endcase
899
end
900
 
901
// configuration space offset output assignment
902
assign wb_conf_offset_out = {wb_addr_in[11:2], 2'b00} ; // upper 10 bits of address input and two zeros
903
 
904
// Configuration space byte enables output
905
assign wb_conf_be_out = SEL_I ; // just route select lines from WISHBONE to conf space
906
 
907
// data output assignment - for image writes, first data is address, subsequent data comes from intermediate register
908
reg [31:0] wb_data_out ;
909
`ifdef HOST
910
always@(wbw_data_out_sel or wb_addr_in or ccyc_addr_in or d_incoming)
911
begin
912
    case ( wbw_data_out_sel )
913
        SEL_CCYC_ADDR:  wb_data_out = ccyc_addr_in ;
914
        SEL_DATA_IN:    wb_data_out = d_incoming ;
915
        default: wb_data_out = wb_addr_in ;
916
    endcase
917
end
918
`else
919
`ifdef GUEST
920
always@(wbw_data_out_sel or wb_addr_in or d_incoming)
921
begin
922
    if ( wbw_data_out_sel )
923
        wb_data_out = wb_addr_in ;
924
    else
925
        wb_data_out = d_incoming ;
926
end
927
`endif
928
`endif
929
 
930
// command / byte enable assignment - with address, bus command is provided, with data - byte enables are provided
931
reg [3:0] wb_cbe ;
932
assign wb_cbe_out = wb_cbe ;
933
 
934
always@(wbw_data_out_sel or d_incoming or map)
935
begin
936
    if (wbw_data_out_sel && map)
937
            wb_cbe = `BC_IO_WRITE ;
938
    else
939
    if (wbw_data_out_sel)
940
        wb_cbe = `BC_MEM_WRITE ;
941
        else
942
                wb_cbe = ~(d_incoming[35:32]) ;
943
end
944
 
945
// for configuration writes, data output is always data from WISHBONE - in guest implementation data is all 0.
946
`ifdef GUEST
947
        assign wb_conf_data_out = 32'h00000000 ;
948
`else
949
`ifdef HOST
950
        assign wb_conf_data_out = SDATA_I ;
951
`endif
952
`endif
953
 
954
// WISHBONE data output multiplexor
955
reg [31:0] sdata ;
956
assign SDATA_O = sdata ;
957
 
958
always@(sdata_o_sel or wbr_fifo_data_in or wb_conf_data_in)
959
begin
960
        case (sdata_o_sel)
961
                WBR_SEL :sdata = wbr_fifo_data_in ;
962
                CONF_SEL:sdata = wb_conf_data_in ;
963
        endcase
964
end
965
 
966
endmodule //WB_SLAVE

powered by: WebSVN 2.1.0

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