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 2

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

powered by: WebSVN 2.1.0

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