]> git.zerfleddert.de Git - raggedstone/blame_incremental - ethernet/source/pci/pci_wb_slave.v
make sure to touch the ngc file when synthesis completes, even if unchanged
[raggedstone] / ethernet / source / pci / pci_wb_slave.v
... / ...
CommitLineData
1//////////////////////////////////////////////////////////////////////
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: pci_wb_slave.v,v $
45// Revision 1.1 2007-03-20 17:50:56 sithglan
46// add shit
47//
48// Revision 1.6 2006/07/04 13:16:19 mihad
49// Write burst performance patch applied.
50// Not tested. Everything should be backwards
51// compatible, since functional code is ifdefed.
52//
53// Revision 1.5 2004/01/24 11:54:18 mihad
54// Update! SPOCI Implemented!
55//
56// Revision 1.4 2003/12/19 11:11:30 mihad
57// Compact PCI Hot Swap support added.
58// New testcases added.
59// Specification updated.
60// Test application changed to support WB B3 cycles.
61//
62// Revision 1.3 2003/08/14 18:01:53 simons
63// ifdefs moved to thier own lines, this confuses some of the tools.
64//
65// Revision 1.2 2003/08/03 18:05:06 mihad
66// Added limited WISHBONE B3 support for WISHBONE Slave Unit.
67// Doesn't support full speed bursts yet.
68//
69// Revision 1.1 2003/01/27 16:49:31 mihad
70// Changed module and file names. Updated scripts accordingly. FIFO synchronizations changed.
71//
72// Revision 1.4 2002/08/19 16:54:25 mihad
73// Got rid of undef directives
74//
75// Revision 1.3 2002/02/01 15:25:13 mihad
76// Repaired a few bugs, updated specification, added test bench files and design document
77//
78// Revision 1.2 2001/10/05 08:14:30 mihad
79// Updated all files with inclusion of timescale file for simulation purposes.
80//
81// Revision 1.1.1.1 2001/10/02 15:33:47 mihad
82// New project directory structure
83//
84//
85
86`include "bus_commands.v"
87`include "pci_constants.v"
88
89// synopsys translate_off
90`include "timescale.v"
91// synopsys translate_on
92
93
94
95module pci_wb_slave
96 ( wb_clock_in,
97 reset_in,
98 wb_hit_in,
99 wb_conf_hit_in,
100 wb_map_in,
101 wb_pref_en_in,
102 wb_mrl_en_in,
103 wb_addr_in,
104 del_bc_in,
105 wb_del_req_pending_in,
106 wb_del_comp_pending_in,
107 pci_drcomp_pending_in,
108 del_bc_out,
109 del_req_out,
110 del_done_out,
111 del_burst_out,
112 del_write_out,
113 del_write_in,
114 del_error_in,
115 del_in_progress_out,
116 ccyc_addr_in,
117 wb_del_addr_in,
118 wb_del_be_in,
119 wb_conf_offset_out,
120 wb_conf_renable_out,
121 wb_conf_wenable_out,
122 wb_conf_be_out,
123 wb_conf_data_in,
124 wb_conf_data_out,
125 wb_data_out,
126 wb_cbe_out,
127 wbw_fifo_wenable_out,
128 wbw_fifo_control_out,
129 wbw_fifo_almost_full_in,
130 wbw_fifo_full_in,
131 wbw_fifo_half_full_in, //Robert, burst issue
132 wbr_fifo_renable_out,
133 wbr_fifo_be_in,
134 wbr_fifo_data_in,
135 wbr_fifo_control_in,
136 wbr_fifo_flush_out,
137 wbr_fifo_empty_in,
138 pciw_fifo_empty_in,
139 wbs_lock_in,
140 init_complete_in,
141 cache_line_size_not_zero,
142 sample_address_out,
143 CYC_I,
144 STB_I,
145 WE_I,
146 SEL_I,
147 SDATA_I,
148 SDATA_O,
149 ACK_O,
150 RTY_O,
151 ERR_O,
152 CAB_I
153 );
154
155/*----------------------------------------------------------------------------------------------------------------------
156Various parameters needed for state machine and other stuff
157----------------------------------------------------------------------------------------------------------------------*/
158parameter WBR_SEL = 1'b0 ;
159parameter CONF_SEL = 1'b1 ;
160
161`define FSM_BITS 3
162parameter S_IDLE = `FSM_BITS'h0 ;
163parameter S_DEC1 = `FSM_BITS'h1 ;
164parameter S_DEC2 = `FSM_BITS'h2 ;
165parameter S_START = `FSM_BITS'h3 ;
166parameter S_W_ADDR_DATA = `FSM_BITS'h4 ;
167parameter S_READ = `FSM_BITS'h5 ;
168parameter S_CONF_WRITE = `FSM_BITS'h6 ;
169parameter S_CONF_READ = `FSM_BITS'h7 ;
170
171/*----------------------------------------------------------------------------------------------------------------------
172System signals inputs
173wb_clock_in - WISHBONE bus clock input
174reset_in - system reset input controlled by bridge's reset logic
175----------------------------------------------------------------------------------------------------------------------*/
176input wb_clock_in, reset_in ;
177
178/*----------------------------------------------------------------------------------------------------------------------
179Inputs from address decoding logic
180wb_hit_in - Decoder logic indicates if address is in a range of one of images
181wb_conf_hit_in - Decoder logic indicates that address is in configuration space range
182wb_map_in - Decoder logic provides information about image mapping - memory mapped image - wb_map_in = 0
183 IO space mapped image - wb_map_in = 1
184wb_pref_en_in - Prefetch enable signal from currently selected image - used for PCI bus command usage
185wb_addr_in - Address already transalted from WB bus to PCI bus input
186wb_mrl_en_in - Memory read line enable input for each image
187----------------------------------------------------------------------------------------------------------------------*/
188input [4:0] wb_hit_in ; // hit indicators
189input wb_conf_hit_in ; // configuration hit indicator
190input [4:0] wb_pref_en_in ; // prefetch enable from all images
191input [4:0] wb_mrl_en_in ; // Memory Read line command enable from images
192input [4:0] wb_map_in ; // address space mapping indicators - 1 memory space mapping, 0-IO space mapping
193input [31:0] wb_addr_in ; // Translated address input
194
195/*----------------------------------------------------------------------------------------------------------------------
196Delayed transaction control inputs and outputs:
197Used for locking particular accesses when delayed transactions are in progress:
198wb_del_addr_in - delayed transaction address input - when completion is ready it's used for transaction decoding
199wb_del_be_in - delayed transaction byte enable input - when completion is ready it's used for transaction decoding
200----------------------------------------------------------------------------------------------------------------------*/
201input [31:0] wb_del_addr_in ;
202input [3:0] wb_del_be_in ;
203
204input [3:0] del_bc_in ; // delayed request bus command used
205input wb_del_req_pending_in ; // delayed request pending indicator
206input wb_del_comp_pending_in ; // delayed completion pending indicator
207input pci_drcomp_pending_in ; // PCI initiated delayed read completion pending
208
209output [3:0] del_bc_out ; // delayed transaction bus command output
210
211output del_req_out ; // output for issuing delayed transaction requests
212
213output del_done_out ; // output indicating current delayed completion finished on WISHBONE bus
214
215output del_burst_out ; // delayed burst transaction indicator
216
217output del_in_progress_out ; // delayed in progress indicator - since delayed transaction can be a burst transaction, progress indicator must be used for proper operation
218
219output del_write_out ; // write enable for delayed transaction - used for indicating that transaction is a write
220
221input del_write_in ; // indicates that current delayed completion is from a write request
222input del_error_in ; // indicate that delayed request terminated with an error - used for write requests
223
224input [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
225
226/*----------------------------------------------------------------------------------------------------------------------
227Configuration space access control and data signals
228wb_conf_offset_out - lower 12 bits of address input provided for register offset
229wb_conf_renable - read enable signal for configuration space accesses
230wb_conf_wenable - write enable signal for configuration space accesses
231wb_conf_be_out - byte enable signals for configuration space accesses
232wb_conf_data_in - data from configuration space
233wb_conf_data_in - data provided for configuration space
234----------------------------------------------------------------------------------------------------------------------*/
235output [11:0] wb_conf_offset_out ; // register offset output
236output wb_conf_renable_out, // configuration read and write enable outputs
237 wb_conf_wenable_out ;
238output [3:0] wb_conf_be_out ; // byte enable outputs for configuration space
239input [31:0] wb_conf_data_in ; // configuration data input from configuration space
240output [31:0] wb_conf_data_out ; // configuration data output for configuration space
241
242/*----------------------------------------------------------------------------------------------------------------------
243Data from WISHBONE bus output to interiror of the core:
244Data output is used for normal and configuration accesses.
245---------------------------------------------------------------------------------------------------------------------*/
246output [31:0] wb_data_out ;
247
248/*----------------------------------------------------------------------------------------------------------------------
249Bus command - byte enable output - during address phase of image access this bus holds information about PCI
250bus command that should be used, during dataphases ( configuration or image access ) this bus contains inverted
251SEL_I signals
252---------------------------------------------------------------------------------------------------------------------*/
253output [3:0] wb_cbe_out ;
254
255/*----------------------------------------------------------------------------------------------------------------------
256WBW_FIFO control signals used for sinking data into WBW_FIFO and status monitoring
257---------------------------------------------------------------------------------------------------------------------*/
258output wbw_fifo_wenable_out ; // write enable for WBW_FIFO output
259output [3:0] wbw_fifo_control_out ; // control bus output for WBW_FIFO
260input wbw_fifo_almost_full_in ; // almost full status indicator from WBW_FIFO
261input wbw_fifo_full_in ; // full status indicator from WBW_FIFO
262input wbw_fifo_half_full_in; //Robert, burst issue
263
264/*----------------------------------------------------------------------------------------------------------------------
265WBR_FIFO control signals used for fetching data from WBR_FIFO and status monitoring
266---------------------------------------------------------------------------------------------------------------------*/
267output wbr_fifo_renable_out ; // WBR_FIFO read enable output
268input [3:0] wbr_fifo_be_in ; // byte enable input from WBR_FIFO
269input [31:0] wbr_fifo_data_in ; // data input from WBR_FIFO
270input [3:0] wbr_fifo_control_in ; // control bus input from WBR_FIFO
271output wbr_fifo_flush_out ; // flush signal for WBR_FIFO
272input wbr_fifo_empty_in ; // empty status indicator from WBR_FIFO
273
274// used for transaction ordering requirements - WISHBONE read cannot complete until writes from PCI are completed
275input pciw_fifo_empty_in ; // empty status indicator from PCIW_FIFO
276
277/*----------------------------------------------------------------------------------------------------------------------
278wbs_lock_in: internal signal that locks out all accesses, except delayed completions or configuration accesses.
279( when master operation is disabled via master enable bit in configuration spacei )
280init_complete_in: while initialization sequence is in progress, the state machine
281remains in the idle state - it does not respond to accesses.
282---------------------------------------------------------------------------------------------------------------------*/
283input wbs_lock_in ;
284input init_complete_in ;
285
286// cache line size register must hold appropriate value to enable read bursts and special commands on PCI bus!
287input cache_line_size_not_zero ;
288
289// state machine signals to wb_addr_mux when to sample wb address input
290output sample_address_out ;
291reg sample_address_out ;
292
293/*----------------------------------------------------------------------------------------------------------------------
294WISHBONE bus interface signals - can be connected directly to WISHBONE bus
295---------------------------------------------------------------------------------------------------------------------*/
296input CYC_I ; // cycle indicator
297input STB_I ; // strobe input - input data is valid when strobe and cycle indicator are high
298input WE_I ; // write enable input - 1 - write operation, 0 - read operation
299input [3:0] SEL_I ; // Byte select inputs
300input [31:0] SDATA_I ; // WISHBONE slave interface input data bus
301output [31:0] SDATA_O ; // WISHBONE slave interface output data bus
302output ACK_O ; // Acknowledge output - qualifies valid data on data output bus or received data on data input bus
303output RTY_O ; // retry output - signals to WISHBONE master that cycle should be terminated and retried later
304output ERR_O ; // Signals to WISHBONE master that access resulted in an error
305input CAB_I ; // consecutive address burst input - indicates that master will do a serial address transfer in current cycle
306
307`ifdef REGISTER_WBS_OUTPUTS
308reg [31:0] SDATA_O ;
309reg ACK_O ;
310reg RTY_O ;
311reg ERR_O ;
312
313reg [3:0] del_bc_out ; // delayed transaction bus command output
314reg del_req_out ; // output for issuing delayed transaction requests
315reg del_done_out ; // output indicating current delayed completion finished on WISHBONE bus
316reg del_burst_out ; // delayed burst transaction indicator
317reg del_in_progress_out ; // delayed in progress indicator - since delayed transaction can be a burst transaction, progress indicator must be used for proper operation
318reg del_write_out ; // write enable for delayed transaction - used for indicating that transaction is a write
319
320`ifdef HOST
321reg wb_conf_wenable_out ;
322reg [31:0] wb_conf_data_out ; // configuration data output for configuration space
323`endif
324
325reg [3:0] wb_conf_be_out ; // byte enable outputs for configuration space
326reg [31:0] wb_data_out ;
327
328reg [3:0] wb_cbe_out ;
329
330reg wbw_fifo_wenable_out ; // write enable for WBW_FIFO output
331reg [3:0] wbw_fifo_control_out ; // control bus output for WBW_FIFO
332
333reg wbr_fifo_renable_out ; // WBR_FIFO read enable output
334`endif
335
336reg [(`FSM_BITS - 1):0] c_state ; //current state register
337
338reg [(`FSM_BITS - 1):0] n_state ; //next state input to current state register
339
340// state machine register control
341always@(posedge wb_clock_in or posedge reset_in)
342begin
343 if (reset_in)
344 c_state <= #`FF_DELAY S_IDLE ;
345 else
346 c_state <= #`FF_DELAY n_state ;
347end
348
349
350// variable for bus command multiplexer logic output for delayed requests
351reg [3:0] del_bc ;
352
353//register for intermediate data and select storage
354reg [35:0] d_incoming ;
355
356// enable for incoming data register
357reg d_incoming_ena ;
358
359// incoming data register control logic
360always@(posedge wb_clock_in or posedge reset_in)
361begin
362 if (reset_in)
363 d_incoming <= #`FF_DELAY {35{1'b0}} ;
364 else if (d_incoming_ena)
365 d_incoming <= #`FF_DELAY {SEL_I, SDATA_I} ;
366end
367
368/*===================================================================================================================================================================================
369Write allow for image accesses. Writes through images are allowed when all of following are true:
370- 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
371- delayed read from from WISHBONE to PCI request musn't be present
372- delayed read from PCI to WISHBONE completion musn't be present
373- lock input musn't be set - it can be set because of error reporting or because PCI master state machine is disabled
374===================================================================================================================================================================================*/
375//Robert, burst issue
376//`ifdef BURST_ISSUE
377wire wimg_wallow = ~|{ wbw_fifo_half_full_in, wb_del_req_pending_in, pci_drcomp_pending_in, wbs_lock_in } ;
378//`else
379//wire wimg_wallow = ~|{ wbw_fifo_almost_full_in , wbw_fifo_full_in, wb_del_req_pending_in, pci_drcomp_pending_in, wbs_lock_in } ;
380//`endif
381
382reg img_wallow ;
383/*===================================================================================================================================================================================
384WISHBONE slave can request an image read accesses when all of following are true:
385- delayed completion is not present
386- delayed request is not present
387- operation is not locked because of error reporting mechanism or because PCI master is disabled
388===================================================================================================================================================================================*/
389wire wdo_del_request = ~|{ wb_del_req_pending_in, wb_del_comp_pending_in, wbs_lock_in } ;
390reg do_del_request ;
391/*===================================================================================================================================================================================
392WISHBONE slave can complete an image read accesses when all of following are true:
393- delayed read completion is present
394- delayed read completion is the same as current read access ( dread_completion_hit is 1 )
395- PCI Write FIFO is empty - no posted write is waiting to be finished in PCIW_FIFO
396- WBR_FIFO empty status is not active
397===================================================================================================================================================================================*/
398wire wdel_addr_hit = ( wb_del_addr_in == wb_addr_in ) && ( SEL_I == wb_del_be_in ) ;
399reg del_addr_hit ;
400wire 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)) ;
401reg del_completion_allow ;
402
403/*----------------------------------------------------------------------------------------------------------------------
404img_hit - state of wb_hit_in bus when when state machine signals decode is over
405---------------------------------------------------------------------------------------------------------------------*/
406reg [4:0] img_hit ;
407wire wb_hit = |( img_hit ) ;
408
409/*----------------------------------------------------------------------------------------------------------------------
410Control logic for image control signals
411pref_en - prefetch enable of currently selected image
412mrl_en - Memory read line enable of currently selected image
413map - Address space mapping for currently selected image
414---------------------------------------------------------------------------------------------------------------------*/
415reg pref_en, mrl_en, map ;
416wire wpref_en = |(wb_pref_en_in & wb_hit_in) ;
417wire wmrl_en = |(wb_mrl_en_in & wb_hit_in) ;
418wire wmap = |(wb_map_in & wb_hit_in) ;
419
420// state machine controls when results from decoders, comparison etc. are sampled into registers to decode an access
421reg decode_en ;
422
423reg wb_conf_hit ;
424always@(posedge reset_in or posedge wb_clock_in)
425begin
426 if (reset_in)
427 begin
428 img_wallow <= #`FF_DELAY 1'b0 ;
429 wb_conf_hit <= #`FF_DELAY 1'b0 ;
430 do_del_request <= #`FF_DELAY 1'b0 ;
431 del_addr_hit <= #`FF_DELAY 1'b0 ;
432 del_completion_allow <= #`FF_DELAY 1'b0 ;
433 img_hit <= #`FF_DELAY 5'h00 ;
434 pref_en <= #`FF_DELAY 1'b0 ;
435 mrl_en <= #`FF_DELAY 1'b0 ;
436 map <= #`FF_DELAY 1'b0 ;
437 end
438 else
439 if (decode_en)
440 begin
441 img_wallow <= #`FF_DELAY wimg_wallow ;
442 wb_conf_hit <= #`FF_DELAY wb_conf_hit_in ;
443 do_del_request <= #`FF_DELAY wdo_del_request ;
444 del_addr_hit <= #`FF_DELAY wdel_addr_hit ;
445 del_completion_allow <= #`FF_DELAY wdel_completion_allow ;
446 img_hit <= #`FF_DELAY wb_hit_in ;
447 pref_en <= #`FF_DELAY wpref_en && cache_line_size_not_zero ;
448 mrl_en <= #`FF_DELAY wmrl_en && cache_line_size_not_zero ;
449 map <= #`FF_DELAY wmap ;
450 end
451end
452
453wire del_burst = CAB_I && (pref_en || mrl_en) && ~WE_I && cache_line_size_not_zero ; // delayed burst indicator - only when WB master attempts CAB transfer and cache line size register is set appropriately and
454 // either prefetch enable or memory read line enable of corresponding image are set -
455 // applies for reads only - delayed write cannot be a burst
456wire do_dread_completion = del_completion_allow && del_addr_hit ;
457
458`ifdef GUEST
459
460 // wires indicating allowance for configuration cycle generation requests
461 wire do_ccyc_req = 1'b0 ;
462 wire do_ccyc_comp = 1'b0 ;
463
464 // wires indicating allowance for interrupt acknowledge cycle generation requests
465 wire do_iack_req = 1'b0 ;
466 wire do_iack_comp = 1'b0 ;
467
468 // variables for configuration access control signals
469 reg conf_wenable ;
470 assign wb_conf_wenable_out = 1'b0 ;
471
472 // configuration cycle data register hit
473 wire ccyc_hit = 1'b0 ;
474 wire iack_hit = 1'b0 ;
475
476 wire wccyc_hit = 1'b0 ;
477 wire wiack_hit = 1'b0 ;
478
479`else
480`ifdef HOST
481 // only host implementation has access for generating interrupt acknowledge and configuration cycles
482 // configuration cycle data register hit
483 reg current_delayed_is_ccyc ;
484 reg current_delayed_is_iack ;
485
486 wire wccyc_hit = (wb_addr_in[8:2] == {1'b1, `CNF_DATA_ADDR}) ;
487
488 wire wiack_hit = (wb_addr_in[8:2] == {1'b1, `INT_ACK_ADDR}) ;
489
490 reg iack_hit ;
491 reg ccyc_hit ;
492 always@(posedge reset_in or posedge wb_clock_in)
493 begin
494 if (reset_in)
495 begin
496 ccyc_hit <= #`FF_DELAY 1'b0 ;
497 iack_hit <= #`FF_DELAY 1'b0 ;
498 end
499 else
500 if (decode_en)
501 begin
502 ccyc_hit <= #`FF_DELAY wccyc_hit ;
503 iack_hit <= #`FF_DELAY wiack_hit ;
504 end
505 end
506
507 // wires indicating allowance for configuration cycle generation requests
508 wire do_ccyc_req = do_del_request && ccyc_hit;
509 wire do_ccyc_comp = del_completion_allow && ccyc_hit && current_delayed_is_ccyc ; // && del_bc_hit
510
511 // wires indicating allowance for interrupt acknowledge cycle generation requests
512 wire do_iack_req = do_del_request && iack_hit ;
513 wire do_iack_comp = del_completion_allow && iack_hit && current_delayed_is_iack ; // && del_bc_hit
514
515 // variables for configuration access control signals
516 reg conf_wenable ;
517
518 // following flip-flops remember whether current delayed transaction is interrupt acknowledge or configuration cycle transaction
519 always@(posedge wb_clock_in or posedge reset_in)
520 begin
521 if ( reset_in )
522 begin
523 current_delayed_is_ccyc <= #`FF_DELAY 1'b0 ;
524 current_delayed_is_iack <= #`FF_DELAY 1'b0 ;
525 end
526 else
527 if ( del_done_out )
528 begin
529 current_delayed_is_ccyc <= #`FF_DELAY 1'b0 ;
530 current_delayed_is_iack <= #`FF_DELAY 1'b0 ;
531 end
532 else
533 if ( del_req_out && wb_conf_hit )
534 begin
535 current_delayed_is_ccyc <= #`FF_DELAY do_ccyc_req ;
536 current_delayed_is_iack <= #`FF_DELAY do_iack_req ;
537 end
538 end
539
540`endif
541`endif
542
543// configuration read enable - supplied for host and guest bridges
544reg conf_renable ;
545assign wb_conf_renable_out = conf_renable ;
546
547// burst access indicator
548wire burst_transfer = CYC_I && CAB_I ;
549
550// WBW_FIFO control output
551reg [3:0] wbw_fifo_control ;
552
553// WBW_FIFO wenable output assignment
554reg wbw_fifo_wenable ;
555
556// WBR_FIFO control outputs
557reg wbr_fifo_flush, wbr_fifo_renable ; // flush and read enable outputs
558
559// flush signal for WBR_FIFO must be registered, since it asinchronously resets some status registers
560wire wbr_fifo_flush_reg ;
561pci_async_reset_flop async_reset_as_wbr_flush
562(
563 .data_in (wbr_fifo_flush),
564 .clk_in (wb_clock_in),
565 .async_reset_data_out (wbr_fifo_flush_reg),
566 .reset_in (reset_in)
567) ;
568assign wbr_fifo_flush_out = wbr_fifo_flush_reg ;
569
570// delayed transaction request control signals
571reg del_req, del_done ;
572
573// WISHBONE handshaking control outputs
574reg ack, rty, err ;
575
576`ifdef REGISTER_WBS_OUTPUTS
577// wire for write attempt - 1 when external WB master is attempting a write
578// wire for read attempt - 1 when external master is attempting a read
579wire wattempt = ( CYC_I && STB_I && WE_I ) && (!ACK_O && !ERR_O && !RTY_O) ;
580wire rattempt = ( CYC_I && STB_I && ~WE_I ) && (!ACK_O && !ERR_O && !RTY_O) ;
581
582`else
583// wire for write attempt - 1 when external WB master is attempting a write
584// wire for read attempt - 1 when external master is attempting a read
585wire wattempt = ( CYC_I && STB_I && WE_I ) ; // write is qualified when cycle, strobe and write enable inputs are all high
586wire rattempt = ( CYC_I && STB_I && ~WE_I ) ; // read is qualified when cycle and strobe are high and write enable is low
587
588`endif
589/*----------------------------------------------------------------------------------------------------------------------
590Delayed transaction bus command generation
591Bus command for delayed reads depends on image's address space mapping and control bits and
592whether or not these are interrupt acknowledge requests or configuration cycle requests
593---------------------------------------------------------------------------------------------------------------------*/
594
595always@(map or mrl_en or ccyc_hit or WE_I or wb_conf_hit or CAB_I or pref_en)
596begin
597`ifdef HOST
598// only host implementation supports configuration and interrupt acknowledge commands
599 if (wb_conf_hit)
600 begin
601 case( {ccyc_hit, WE_I} )
602 2'b11: del_bc = `BC_CONF_WRITE ;
603 2'b10: del_bc = `BC_CONF_READ ;
604 2'b01: del_bc = `BC_RESERVED0 ; // invalid combination - interrupt acknowledge cycle must be a read
605 2'b00: del_bc = `BC_IACK ;
606 endcase
607 end
608 else
609`endif
610 begin
611 if ( map )
612 begin
613 del_bc = `BC_IO_READ ;
614 end
615 else
616 begin
617 case ({(CAB_I && mrl_en), pref_en})
618 2'b00: del_bc = `BC_MEM_READ ; // if this is not burst transfer or memory read line command is disabled - use memory read
619 2'b01: del_bc = `BC_MEM_READ ; // same as previous case
620 2'b10: del_bc = `BC_MEM_READ_LN ; // burst transfer, memory read line command enabled, prefetch disabled - use memory read line command
621 2'b11: del_bc = `BC_MEM_READ_MUL ; // same as previous case, except prefetch is enabled - use memory read multiple command
622 endcase
623 end
624 end
625end
626
627reg del_in_progress ; // state machine indicates whether current read completion is in progress on WISHBONE bus
628
629wire image_access_error = (map && burst_transfer) ; // IO write is a burst
630
631`ifdef HOST
632 reg [1:0] wbw_data_out_sel ;
633 parameter SEL_ADDR_IN = 2'b10 ;
634 parameter SEL_CCYC_ADDR = 2'b11 ;
635 parameter SEL_DATA_IN = 2'b00 ;
636`else
637`ifdef GUEST
638 reg wbw_data_out_sel ;
639 parameter SEL_ADDR_IN = 1'b1 ;
640 parameter SEL_DATA_IN = 1'b0 ;
641`endif
642`endif
643
644`ifdef WB_DECODE_FAST
645 `ifdef REGISTER_WBS_OUTPUTS
646 `define PCI_WB_SLAVE_S_DEC1
647 `endif
648`endif
649
650`ifdef WB_DECODE_MEDIUM
651 `define PCI_WB_SLAVE_S_DEC1
652`endif
653
654`ifdef WB_DECODE_SLOW
655 `define PCI_WB_SLAVE_S_DEC1
656 `define PCI_WB_SLAVE_S_DEC2
657`endif
658// state machine logic
659always@(
660 c_state or
661 wattempt or
662 img_wallow or
663 burst_transfer or
664 wb_hit or
665 map or
666 rattempt or
667 do_dread_completion or
668 wbr_fifo_control_in or
669 wb_conf_hit or
670 do_ccyc_req or
671 do_ccyc_comp or
672 ccyc_hit or
673 del_error_in or
674 do_iack_req or
675 do_iack_comp or
676 iack_hit or
677 image_access_error or
678 wbw_fifo_almost_full_in or
679 wbw_fifo_full_in or
680 do_del_request or
681 wbr_fifo_empty_in or
682 init_complete_in
683 )
684begin
685 // default signal values
686 // response signals inactive
687 ack = 1'b0 ;
688 rty = 1'b0 ;
689 err = 1'b0 ;
690
691 //write signals inactive
692 wbw_fifo_control[`ADDR_CTRL_BIT] = 1'b1 ;
693 wbw_fifo_control[`DATA_ERROR_CTRL_BIT] = 1'b0 ;
694 wbw_fifo_control[`LAST_CTRL_BIT] = 1'b0 ;
695 wbw_fifo_control[`UNUSED_CTRL_BIT] = 1'b0 ;
696
697 wbw_fifo_wenable = 1'b0 ;
698 d_incoming_ena = 1'b0 ;
699
700 // read signals inactive
701 wbr_fifo_flush = 1'b0 ;
702 wbr_fifo_renable = 1'b0 ;
703 del_req = 1'b0 ;
704 del_done = 1'b0 ;
705
706 // configuration space control signals inactive
707 conf_wenable = 1'b0 ;
708 conf_renable = 1'b0 ;
709
710 // read is not in progress
711 del_in_progress = 1'b0 ;
712
713 decode_en = 1'b0 ;
714
715 wbw_data_out_sel = SEL_ADDR_IN ;
716
717 sample_address_out = 1'b0 ;
718
719 case (c_state)
720 S_IDLE: begin
721 if ( (wattempt || rattempt) & init_complete_in )
722 begin
723
724 `ifdef PCI_WB_SLAVE_S_DEC1
725 n_state = S_DEC1 ;
726 `else
727 decode_en = 1'b1 ;
728 n_state = S_START ;
729 `endif
730
731 sample_address_out = 1'b1 ;
732 end
733 else
734 n_state = S_IDLE ;
735 end
736`ifdef PCI_WB_SLAVE_S_DEC1
737 S_DEC1: begin
738 if ( wattempt || rattempt )
739 begin
740
741 `ifdef PCI_WB_SLAVE_S_DEC2
742 n_state = S_DEC2 ;
743 `else
744 decode_en = 1'b1 ;
745 n_state = S_START ;
746 `endif
747
748 end
749 else
750 n_state = S_IDLE ;
751 end
752`endif
753`ifdef PCI_WB_SLAVE_S_DEC2
754 S_DEC2: begin
755
756 if ( wattempt || rattempt )
757 begin
758 decode_en = 1'b1 ;
759 n_state = S_START ;
760 end
761 else
762 n_state = S_IDLE ;
763 end
764`endif
765 S_START:begin
766 if (wb_conf_hit) // configuration space hit
767 begin
768 `ifdef HOST
769 wbw_data_out_sel = SEL_CCYC_ADDR ;
770 `endif
771
772 if ( wattempt )
773 n_state = S_CONF_WRITE ; // go to conf. write state
774 else
775 if ( rattempt )
776 begin
777 n_state = S_CONF_READ ; // go to conf. read state
778 end
779 else
780 n_state = S_IDLE ; // master terminated - go back to idle state
781
782 end // wb_conf_hit
783 else
784 if( wb_hit && (wattempt || rattempt) )
785 begin
786 wbw_data_out_sel = SEL_DATA_IN ;
787
788 // check error conditions for image writes or reads
789 if ( image_access_error )
790 begin
791 n_state = S_IDLE ; // go back to idle state because of an error condition
792 err = 1'b1 ;
793 end // error conditions
794 else
795 // check for retry conditions for image writes or reads
796 if ( (wattempt && ~img_wallow) ||
797 (rattempt && ~do_dread_completion) // write to image not allowed, no read ready yet - retry
798 )
799 begin
800 n_state = S_IDLE ; // go back to IDLE
801
802 rty = 1'b1 ;
803
804 del_req = do_del_request && rattempt ;
805
806 end //retry
807 else // everything OK - proceed
808 if ( wattempt )
809 begin
810 n_state = S_W_ADDR_DATA ; // goto write transfer state
811
812 // respond with acknowledge
813 ack = 1'b1 ;
814
815 wbw_fifo_wenable = 1'b1 ;
816
817 // data is latched to data incoming intermidiate stage - it will be put in FIFO later
818 d_incoming_ena = 1'b1 ;
819 end
820 else
821 begin
822 err = wbr_fifo_control_in[`DATA_ERROR_CTRL_BIT] ;
823 ack = ~wbr_fifo_control_in[`DATA_ERROR_CTRL_BIT] ;
824 wbr_fifo_renable = 1'b1 ;
825 del_in_progress = 1'b1 ;
826
827 if ( wbr_fifo_control_in[`DATA_ERROR_CTRL_BIT] || wbr_fifo_control_in[`LAST_CTRL_BIT] )
828 begin
829
830 n_state = S_IDLE ; // go back to idle state
831 // respond that read is finished
832 del_done = 1'b1 ;
833
834 end // end read
835 else
836 n_state = S_READ ; // go to read state
837 end
838 end
839 else
840 n_state = S_IDLE ;
841
842 end
843
844 S_W_ADDR_DATA: begin
845 wbw_data_out_sel = SEL_DATA_IN ;
846 err = 1'b0 ;
847 rty = burst_transfer && wattempt && (wbw_fifo_almost_full_in || wbw_fifo_full_in) ;
848 if ( ~burst_transfer || wattempt && ( wbw_fifo_almost_full_in || wbw_fifo_full_in ) )
849 begin
850 n_state = S_IDLE ;
851
852 // write last data to FIFO and don't latch new data
853 wbw_fifo_control[`ADDR_CTRL_BIT] = 1'b0 ;
854 wbw_fifo_control[`LAST_CTRL_BIT] = 1'b1 ;
855 wbw_fifo_wenable = 1'b1 ;
856 end
857 else
858 begin
859 n_state = S_W_ADDR_DATA ;
860 wbw_fifo_control[`ADDR_CTRL_BIT] = 1'b0 ;
861 wbw_fifo_control[`LAST_CTRL_BIT] = 1'b0 ;
862 ack = wattempt ;
863 wbw_fifo_wenable = wattempt ;
864 d_incoming_ena = wattempt ;
865 end
866 end // S_W_ADDR_DATA
867
868 S_READ:begin
869 // this state is for reads only - in this state read is in progress all the time
870 del_in_progress = 1'b1 ;
871
872 ack = burst_transfer && rattempt && ~wbr_fifo_control_in[`DATA_ERROR_CTRL_BIT] && ~wbr_fifo_empty_in ;
873 err = burst_transfer && rattempt && wbr_fifo_control_in[`DATA_ERROR_CTRL_BIT] && ~wbr_fifo_empty_in ;
874
875 // if acknowledge is beeing signalled then enable read from wbr fifo
876 wbr_fifo_renable = burst_transfer && rattempt && ~wbr_fifo_empty_in ;
877
878 if ( ~burst_transfer || rattempt && (wbr_fifo_empty_in || wbr_fifo_control_in[`DATA_ERROR_CTRL_BIT] || wbr_fifo_control_in[`LAST_CTRL_BIT]) )
879 begin
880 n_state = S_IDLE ;
881 del_done = 1'b1 ;
882 wbr_fifo_flush = ~wbr_fifo_empty_in ;
883 end
884 else
885 begin
886 n_state = S_READ ;
887 end
888 end // S_READ
889
890 S_CONF_WRITE: begin
891 `ifdef HOST
892 wbw_data_out_sel = SEL_CCYC_ADDR ;
893 del_req = do_ccyc_req && ~burst_transfer ;
894 del_done = do_ccyc_comp && ~burst_transfer ;
895 del_in_progress = do_ccyc_comp && ~burst_transfer ;
896 `endif
897
898 n_state = S_IDLE ; // next state after configuration access is always idle
899
900 if ( burst_transfer )
901 begin
902 err = 1'b1 ;
903 end
904 else
905 begin
906 `ifdef HOST
907 if ( do_ccyc_req || (ccyc_hit && ~do_ccyc_comp))
908 begin
909 rty = 1'b1 ;
910 end
911 else
912 if ( do_ccyc_comp )
913 begin
914 err = del_error_in ;
915 ack = ~del_error_in ;
916 end
917 else
918 begin
919 ack = ~ccyc_hit ;
920 conf_wenable = ~ccyc_hit ;
921 end
922 `else
923 ack = 1'b1 ;
924 conf_wenable = 1'b1 ;
925 `endif
926 end
927 end // S_CONF_WRITE
928
929 S_CONF_READ: begin
930 `ifdef HOST
931 wbw_data_out_sel = SEL_CCYC_ADDR ;
932 del_req = ~burst_transfer && ( do_ccyc_req || do_iack_req ) ;
933 del_done = ~burst_transfer && ( do_ccyc_comp || do_iack_comp ) ;
934 del_in_progress = ~burst_transfer && ( do_ccyc_comp || do_iack_comp ) ;
935 wbr_fifo_renable = ~burst_transfer && ( do_ccyc_comp || do_iack_comp ) ;
936 `endif
937
938 n_state = S_IDLE ; // next state after configuration access is always idle
939
940 if ( burst_transfer )
941 begin
942 err = 1'b1 ;
943 end
944 else
945 begin
946 `ifdef HOST
947 if ( do_ccyc_req || ( ccyc_hit && ~do_ccyc_comp ))
948 begin
949 rty = 1'b1 ;
950 end
951 else
952 if ( do_iack_req || ( iack_hit && ~do_iack_comp ))
953 begin
954 rty = 1'b1 ;
955 end
956 else
957 if ( do_iack_comp || do_ccyc_comp )
958 begin
959 err = del_error_in ;
960 ack = ~del_error_in ;
961 end
962 else
963 begin
964 ack = ~( ccyc_hit || iack_hit ) ;
965 conf_renable = ~( ccyc_hit || iack_hit ) ;
966 end
967 `else
968 ack = 1'b1 ;
969 conf_renable = 1'b1 ;
970 `endif
971 end
972 end //S_CONF_READ
973 default:begin
974 n_state = S_IDLE ; // return to idle state
975 end //default
976 endcase
977end
978
979// configuration space offset output assignment
980assign wb_conf_offset_out = {wb_addr_in[11:2], 2'b00} ; // upper 10 bits of address input and two zeros
981
982// data output assignment - for image writes, first data is address, subsequent data comes from intermediate register
983reg [31:0] wb_data ;
984`ifdef HOST
985reg [1:0] wbw_data_out_sel_reg ;
986always@(posedge wb_clock_in or posedge reset_in)
987begin
988 if ( reset_in )
989 wbw_data_out_sel_reg <= #`FF_DELAY SEL_ADDR_IN ;
990 else
991 wbw_data_out_sel_reg <= #`FF_DELAY wbw_data_out_sel ;
992end
993
994always@(wbw_data_out_sel_reg or wb_addr_in or ccyc_addr_in or d_incoming)
995begin
996 case ( wbw_data_out_sel_reg )
997 SEL_CCYC_ADDR: wb_data = ccyc_addr_in ;
998 SEL_DATA_IN: wb_data = d_incoming ;
999 default: wb_data = wb_addr_in ;
1000 endcase
1001end
1002`else
1003`ifdef GUEST
1004reg wbw_data_out_sel_reg ;
1005always@(posedge wb_clock_in or posedge reset_in)
1006begin
1007 if ( reset_in )
1008 wbw_data_out_sel_reg <= #`FF_DELAY SEL_ADDR_IN ;
1009 else
1010 wbw_data_out_sel_reg <= #`FF_DELAY wbw_data_out_sel ;
1011end
1012
1013always@(wbw_data_out_sel_reg or wb_addr_in or d_incoming)
1014begin
1015 if ( wbw_data_out_sel_reg )
1016 wb_data = wb_addr_in ;
1017 else
1018 wb_data = d_incoming ;
1019end
1020`endif
1021`endif
1022
1023// command / byte enable assignment - with address, bus command is provided, with data - byte enables are provided
1024reg [3:0] wb_cbe ;
1025
1026always@(wbw_data_out_sel_reg or d_incoming or map)
1027begin
1028 if (wbw_data_out_sel_reg && map)
1029 wb_cbe = `BC_IO_WRITE ;
1030 else
1031 if (wbw_data_out_sel_reg)
1032 wb_cbe = `BC_MEM_WRITE ;
1033 else
1034 wb_cbe = ~(d_incoming[35:32]) ;
1035end
1036
1037// for configuration writes, data output is always data from WISHBONE - in guest implementation data is all 0.
1038`ifdef GUEST
1039 assign wb_conf_data_out = 32'h00000000 ;
1040`endif
1041
1042`ifdef GUEST
1043 `ifdef NO_CNF_IMAGE
1044 `else
1045 `define PCI_WB_SLAVE_DO_OUT_MUX
1046 `endif
1047`else
1048`ifdef HOST
1049 `define PCI_WB_SLAVE_DO_OUT_MUX ;
1050`endif
1051`endif
1052
1053`ifdef PCI_WB_SLAVE_DO_OUT_MUX
1054 reg [31:0] sdata_source ;
1055
1056 // WISHBONE data output select lines for output multiplexor
1057 wire sdata_o_sel_new = ( wb_conf_hit_in && ~wiack_hit && ~wccyc_hit ) ? CONF_SEL : WBR_SEL ;
1058 reg sdata_o_sel ;
1059
1060 always@(posedge wb_clock_in or posedge reset_in)
1061 begin
1062 if ( reset_in )
1063 sdata_o_sel <= #`FF_DELAY WBR_SEL ;
1064 else
1065 if ( decode_en )
1066 sdata_o_sel <= #`FF_DELAY sdata_o_sel_new ;
1067 end
1068
1069 always@(sdata_o_sel or wbr_fifo_data_in or wb_conf_data_in)
1070 begin
1071 case (sdata_o_sel)
1072 WBR_SEL :sdata_source = wbr_fifo_data_in ;
1073 CONF_SEL:sdata_source = wb_conf_data_in ;
1074 endcase
1075 end
1076`else
1077 wire [31:0] sdata_source = wbr_fifo_data_in ;
1078`endif
1079
1080`ifdef REGISTER_WBS_OUTPUTS
1081
1082always@(posedge wb_clock_in or posedge reset_in)
1083begin
1084 if ( reset_in )
1085 begin
1086 ACK_O <= #`FF_DELAY 1'b0 ;
1087 RTY_O <= #`FF_DELAY 1'b0 ;
1088 ERR_O <= #`FF_DELAY 1'b0 ;
1089 SDATA_O <= #`FF_DELAY 0 ;
1090 del_write_out <= #`FF_DELAY 1'b0 ;
1091
1092 `ifdef HOST
1093 wb_conf_wenable_out <= #`FF_DELAY 1'b0 ;
1094 wb_conf_data_out <= #`FF_DELAY 0 ;
1095 `endif
1096
1097 del_bc_out <= #`FF_DELAY `BC_RESERVED0 ;
1098 del_req_out <= #`FF_DELAY 1'b0 ;
1099 del_done_out <= #`FF_DELAY 1'b0 ;
1100 del_burst_out <= #`FF_DELAY 1'b0 ;
1101 del_in_progress_out <= #`FF_DELAY 1'b0 ;
1102 wb_conf_be_out <= #`FF_DELAY 0 ;
1103 wb_data_out <= #`FF_DELAY 0 ;
1104 wb_cbe_out <= #`FF_DELAY 0 ;
1105 wbw_fifo_wenable_out <= #`FF_DELAY 0 ;
1106 wbw_fifo_control_out <= #`FF_DELAY 0 ;
1107 wbr_fifo_renable_out <= #`FF_DELAY 0 ;
1108 end
1109 else
1110 begin
1111 ACK_O <= #`FF_DELAY ack && !ACK_O ;
1112 RTY_O <= #`FF_DELAY rty && !RTY_O ;
1113 ERR_O <= #`FF_DELAY err && !ERR_O ;
1114 SDATA_O <= #`FF_DELAY sdata_source ;
1115 del_write_out <= #`FF_DELAY WE_I ;
1116
1117 `ifdef HOST
1118 wb_conf_wenable_out <= #`FF_DELAY conf_wenable ;
1119 wb_conf_data_out <= #`FF_DELAY SDATA_I ;
1120 `endif
1121
1122 del_bc_out <= #`FF_DELAY del_bc ;
1123 del_req_out <= #`FF_DELAY del_req ;
1124 del_done_out <= #`FF_DELAY del_done ;
1125 del_burst_out <= #`FF_DELAY del_burst ;
1126 del_in_progress_out <= #`FF_DELAY del_in_progress ;
1127 wb_conf_be_out <= #`FF_DELAY SEL_I ;
1128 wb_data_out <= #`FF_DELAY wb_data ;
1129 wb_cbe_out <= #`FF_DELAY wb_cbe ;
1130 wbw_fifo_wenable_out <= #`FF_DELAY wbw_fifo_wenable ;
1131 wbw_fifo_control_out <= #`FF_DELAY wbw_fifo_control ;
1132 wbr_fifo_renable_out <= #`FF_DELAY wbr_fifo_renable ;
1133 end
1134end
1135
1136`else
1137
1138assign SDATA_O = sdata_source ;
1139
1140assign ACK_O = ack ;
1141assign RTY_O = rty ;
1142assign ERR_O = err ;
1143
1144// write operation indicator for delayed transaction requests
1145assign del_write_out = WE_I ;
1146assign del_bc_out = del_bc ;
1147assign del_req_out = del_req ; // read request
1148assign del_done_out = del_done ; // read done
1149assign del_burst_out = del_burst ;
1150assign del_in_progress_out = del_in_progress ;
1151`ifdef HOST
1152assign wb_conf_data_out = SDATA_I ;
1153assign wb_conf_wenable_out = conf_wenable ;
1154`endif
1155// Configuration space byte enables output
1156assign wb_conf_be_out = SEL_I ; // just route select lines from WISHBONE to conf space
1157assign wb_data_out = wb_data ;
1158assign wb_cbe_out = wb_cbe ;
1159assign wbw_fifo_wenable_out = wbw_fifo_wenable ; //write enable for WBW_FIFO
1160assign wbw_fifo_control_out = wbw_fifo_control ; //control bus output for WBW_FIFO
1161assign wbr_fifo_renable_out = wbr_fifo_renable ; //read enable for wbr_fifo
1162`endif
1163
1164endmodule //WB_SLAVE
Impressum, Datenschutz