1 //////////////////////////////////////////////////////////////////////
3 //// File name "wb_slave.v" ////
5 //// This file is part of the "PCI bridge" project ////
6 //// http://www.opencores.org/cores/pci/ ////
9 //// - Miha Dolenc (mihad@opencores.org) ////
11 //// All additional information is avaliable in the README ////
15 //////////////////////////////////////////////////////////////////////
17 //// Copyright (C) 2001 Miha Dolenc, mihad@opencores.org ////
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. ////
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. ////
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 ////
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 ////
40 //////////////////////////////////////////////////////////////////////
42 // CVS Revision History
44 // $Log: pci_wb_slave.v,v $
45 // Revision 1.1 2007-03-20 17:50:56 sithglan
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.
53 // Revision 1.5 2004/01/24 11:54:18 mihad
54 // Update! SPOCI Implemented!
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.
62 // Revision 1.3 2003/08/14 18:01:53 simons
63 // ifdefs moved to thier own lines, this confuses some of the tools.
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.
69 // Revision 1.1 2003/01/27 16:49:31 mihad
70 // Changed module and file names. Updated scripts accordingly. FIFO synchronizations changed.
72 // Revision 1.4 2002/08/19 16:54:25 mihad
73 // Got rid of undef directives
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
78 // Revision 1.2 2001/10/05 08:14:30 mihad
79 // Updated all files with inclusion of timescale file for simulation purposes.
81 // Revision 1.1.1.1 2001/10/02 15:33:47 mihad
82 // New project directory structure
86 `include "bus_commands.v"
87 `include "pci_constants.v"
89 // synopsys translate_off
90 `include "timescale.v"
91 // synopsys translate_on
105 wb_del_req_pending_in,
106 wb_del_comp_pending_in,
107 pci_drcomp_pending_in,
127 wbw_fifo_wenable_out,
128 wbw_fifo_control_out,
129 wbw_fifo_almost_full_in,
131 wbw_fifo_half_full_in, //Robert, burst issue
132 wbr_fifo_renable_out,
141 cache_line_size_not_zero,
155 /*----------------------------------------------------------------------------------------------------------------------
156 Various parameters needed for state machine and other stuff
157 ----------------------------------------------------------------------------------------------------------------------*/
158 parameter WBR_SEL = 1'b0 ;
159 parameter CONF_SEL = 1'b1 ;
162 parameter S_IDLE = `FSM_BITS'h0 ;
163 parameter S_DEC1 = `FSM_BITS'h1 ;
164 parameter S_DEC2 = `FSM_BITS'h2 ;
165 parameter S_START = `FSM_BITS'h3 ;
166 parameter S_W_ADDR_DATA = `FSM_BITS'h4 ;
167 parameter S_READ = `FSM_BITS'h5 ;
168 parameter S_CONF_WRITE = `FSM_BITS'h6 ;
169 parameter S_CONF_READ = `FSM_BITS'h7 ;
171 /*----------------------------------------------------------------------------------------------------------------------
172 System signals inputs
173 wb_clock_in - WISHBONE bus clock input
174 reset_in - system reset input controlled by bridge's reset logic
175 ----------------------------------------------------------------------------------------------------------------------*/
176 input wb_clock_in, reset_in ;
178 /*----------------------------------------------------------------------------------------------------------------------
179 Inputs from address decoding logic
180 wb_hit_in - Decoder logic indicates if address is in a range of one of images
181 wb_conf_hit_in - Decoder logic indicates that address is in configuration space range
182 wb_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
184 wb_pref_en_in - Prefetch enable signal from currently selected image - used for PCI bus command usage
185 wb_addr_in - Address already transalted from WB bus to PCI bus input
186 wb_mrl_en_in - Memory read line enable input for each image
187 ----------------------------------------------------------------------------------------------------------------------*/
188 input [4:0] wb_hit_in ; // hit indicators
189 input wb_conf_hit_in ; // configuration hit indicator
190 input [4:0] wb_pref_en_in ; // prefetch enable from all images
191 input [4:0] wb_mrl_en_in ; // Memory Read line command enable from images
192 input [4:0] wb_map_in ; // address space mapping indicators - 1 memory space mapping, 0-IO space mapping
193 input [31:0] wb_addr_in ; // Translated address input
195 /*----------------------------------------------------------------------------------------------------------------------
196 Delayed transaction control inputs and outputs:
197 Used for locking particular accesses when delayed transactions are in progress:
198 wb_del_addr_in - delayed transaction address input - when completion is ready it's used for transaction decoding
199 wb_del_be_in - delayed transaction byte enable input - when completion is ready it's used for transaction decoding
200 ----------------------------------------------------------------------------------------------------------------------*/
201 input [31:0] wb_del_addr_in ;
202 input [3:0] wb_del_be_in ;
204 input [3:0] del_bc_in ; // delayed request bus command used
205 input wb_del_req_pending_in ; // delayed request pending indicator
206 input wb_del_comp_pending_in ; // delayed completion pending indicator
207 input pci_drcomp_pending_in ; // PCI initiated delayed read completion pending
209 output [3:0] del_bc_out ; // delayed transaction bus command output
211 output del_req_out ; // output for issuing delayed transaction requests
213 output del_done_out ; // output indicating current delayed completion finished on WISHBONE bus
215 output del_burst_out ; // delayed burst transaction indicator
217 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
219 output del_write_out ; // write enable for delayed transaction - used for indicating that transaction is a write
221 input del_write_in ; // indicates that current delayed completion is from a write request
222 input del_error_in ; // indicate that delayed request terminated with an error - used for write requests
224 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
226 /*----------------------------------------------------------------------------------------------------------------------
227 Configuration space access control and data signals
228 wb_conf_offset_out - lower 12 bits of address input provided for register offset
229 wb_conf_renable - read enable signal for configuration space accesses
230 wb_conf_wenable - write enable signal for configuration space accesses
231 wb_conf_be_out - byte enable signals for configuration space accesses
232 wb_conf_data_in - data from configuration space
233 wb_conf_data_in - data provided for configuration space
234 ----------------------------------------------------------------------------------------------------------------------*/
235 output [11:0] wb_conf_offset_out ; // register offset output
236 output wb_conf_renable_out, // configuration read and write enable outputs
237 wb_conf_wenable_out ;
238 output [3:0] wb_conf_be_out ; // byte enable outputs for configuration space
239 input [31:0] wb_conf_data_in ; // configuration data input from configuration space
240 output [31:0] wb_conf_data_out ; // configuration data output for configuration space
242 /*----------------------------------------------------------------------------------------------------------------------
243 Data from WISHBONE bus output to interiror of the core:
244 Data output is used for normal and configuration accesses.
245 ---------------------------------------------------------------------------------------------------------------------*/
246 output [31:0] wb_data_out ;
248 /*----------------------------------------------------------------------------------------------------------------------
249 Bus command - byte enable output - during address phase of image access this bus holds information about PCI
250 bus command that should be used, during dataphases ( configuration or image access ) this bus contains inverted
252 ---------------------------------------------------------------------------------------------------------------------*/
253 output [3:0] wb_cbe_out ;
255 /*----------------------------------------------------------------------------------------------------------------------
256 WBW_FIFO control signals used for sinking data into WBW_FIFO and status monitoring
257 ---------------------------------------------------------------------------------------------------------------------*/
258 output wbw_fifo_wenable_out ; // write enable for WBW_FIFO output
259 output [3:0] wbw_fifo_control_out ; // control bus output for WBW_FIFO
260 input wbw_fifo_almost_full_in ; // almost full status indicator from WBW_FIFO
261 input wbw_fifo_full_in ; // full status indicator from WBW_FIFO
262 input wbw_fifo_half_full_in; //Robert, burst issue
264 /*----------------------------------------------------------------------------------------------------------------------
265 WBR_FIFO control signals used for fetching data from WBR_FIFO and status monitoring
266 ---------------------------------------------------------------------------------------------------------------------*/
267 output wbr_fifo_renable_out ; // WBR_FIFO read enable output
268 input [3:0] wbr_fifo_be_in ; // byte enable input from WBR_FIFO
269 input [31:0] wbr_fifo_data_in ; // data input from WBR_FIFO
270 input [3:0] wbr_fifo_control_in ; // control bus input from WBR_FIFO
271 output wbr_fifo_flush_out ; // flush signal for WBR_FIFO
272 input wbr_fifo_empty_in ; // empty status indicator from WBR_FIFO
274 // used for transaction ordering requirements - WISHBONE read cannot complete until writes from PCI are completed
275 input pciw_fifo_empty_in ; // empty status indicator from PCIW_FIFO
277 /*----------------------------------------------------------------------------------------------------------------------
278 wbs_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 )
280 init_complete_in: while initialization sequence is in progress, the state machine
281 remains in the idle state - it does not respond to accesses.
282 ---------------------------------------------------------------------------------------------------------------------*/
284 input init_complete_in ;
286 // cache line size register must hold appropriate value to enable read bursts and special commands on PCI bus!
287 input cache_line_size_not_zero ;
289 // state machine signals to wb_addr_mux when to sample wb address input
290 output sample_address_out ;
291 reg sample_address_out ;
293 /*----------------------------------------------------------------------------------------------------------------------
294 WISHBONE bus interface signals - can be connected directly to WISHBONE bus
295 ---------------------------------------------------------------------------------------------------------------------*/
296 input CYC_I ; // cycle indicator
297 input STB_I ; // strobe input - input data is valid when strobe and cycle indicator are high
298 input WE_I ; // write enable input - 1 - write operation, 0 - read operation
299 input [3:0] SEL_I ; // Byte select inputs
300 input [31:0] SDATA_I ; // WISHBONE slave interface input data bus
301 output [31:0] SDATA_O ; // WISHBONE slave interface output data bus
302 output ACK_O ; // Acknowledge output - qualifies valid data on data output bus or received data on data input bus
303 output RTY_O ; // retry output - signals to WISHBONE master that cycle should be terminated and retried later
304 output ERR_O ; // Signals to WISHBONE master that access resulted in an error
305 input CAB_I ; // consecutive address burst input - indicates that master will do a serial address transfer in current cycle
307 `ifdef REGISTER_WBS_OUTPUTS
313 reg [3:0] del_bc_out ; // delayed transaction bus command output
314 reg del_req_out ; // output for issuing delayed transaction requests
315 reg del_done_out ; // output indicating current delayed completion finished on WISHBONE bus
316 reg del_burst_out ; // delayed burst transaction indicator
317 reg del_in_progress_out ; // delayed in progress indicator - since delayed transaction can be a burst transaction, progress indicator must be used for proper operation
318 reg del_write_out ; // write enable for delayed transaction - used for indicating that transaction is a write
321 reg wb_conf_wenable_out ;
322 reg [31:0] wb_conf_data_out ; // configuration data output for configuration space
325 reg [3:0] wb_conf_be_out ; // byte enable outputs for configuration space
326 reg [31:0] wb_data_out ;
328 reg [3:0] wb_cbe_out ;
330 reg wbw_fifo_wenable_out ; // write enable for WBW_FIFO output
331 reg [3:0] wbw_fifo_control_out ; // control bus output for WBW_FIFO
333 reg wbr_fifo_renable_out ; // WBR_FIFO read enable output
336 reg [(`FSM_BITS - 1):0] c_state ; //current state register
338 reg [(`FSM_BITS - 1):0] n_state ; //next state input to current state register
340 // state machine register control
341 always@(posedge wb_clock_in or posedge reset_in)
344 c_state <= #`FF_DELAY S_IDLE ;
346 c_state <= #`FF_DELAY n_state ;
350 // variable for bus command multiplexer logic output for delayed requests
353 //register for intermediate data and select storage
354 reg [35:0] d_incoming ;
356 // enable for incoming data register
359 // incoming data register control logic
360 always@(posedge wb_clock_in or posedge 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} ;
368 /*===================================================================================================================================================================================
369 Write 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
377 wire wimg_wallow = ~|{ wbw_fifo_half_full_in, wb_del_req_pending_in, pci_drcomp_pending_in, wbs_lock_in } ;
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 } ;
383 /*===================================================================================================================================================================================
384 WISHBONE 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 ===================================================================================================================================================================================*/
389 wire wdo_del_request = ~|{ wb_del_req_pending_in, wb_del_comp_pending_in, wbs_lock_in } ;
391 /*===================================================================================================================================================================================
392 WISHBONE 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 ===================================================================================================================================================================================*/
398 wire wdel_addr_hit = ( wb_del_addr_in == wb_addr_in ) && ( SEL_I == wb_del_be_in ) ;
400 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)) ;
401 reg del_completion_allow ;
403 /*----------------------------------------------------------------------------------------------------------------------
404 img_hit - state of wb_hit_in bus when when state machine signals decode is over
405 ---------------------------------------------------------------------------------------------------------------------*/
407 wire wb_hit = |( img_hit ) ;
409 /*----------------------------------------------------------------------------------------------------------------------
410 Control logic for image control signals
411 pref_en - prefetch enable of currently selected image
412 mrl_en - Memory read line enable of currently selected image
413 map - Address space mapping for currently selected image
414 ---------------------------------------------------------------------------------------------------------------------*/
415 reg pref_en, mrl_en, map ;
416 wire wpref_en = |(wb_pref_en_in & wb_hit_in) ;
417 wire wmrl_en = |(wb_mrl_en_in & wb_hit_in) ;
418 wire wmap = |(wb_map_in & wb_hit_in) ;
420 // state machine controls when results from decoders, comparison etc. are sampled into registers to decode an access
424 always@(posedge reset_in or posedge wb_clock_in)
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 ;
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 ;
453 wire 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
456 wire do_dread_completion = del_completion_allow && del_addr_hit ;
460 // wires indicating allowance for configuration cycle generation requests
461 wire do_ccyc_req = 1'b0 ;
462 wire do_ccyc_comp = 1'b0 ;
464 // wires indicating allowance for interrupt acknowledge cycle generation requests
465 wire do_iack_req = 1'b0 ;
466 wire do_iack_comp = 1'b0 ;
468 // variables for configuration access control signals
470 assign wb_conf_wenable_out = 1'b0 ;
472 // configuration cycle data register hit
473 wire ccyc_hit = 1'b0 ;
474 wire iack_hit = 1'b0 ;
476 wire wccyc_hit = 1'b0 ;
477 wire wiack_hit = 1'b0 ;
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 ;
486 wire wccyc_hit = (wb_addr_in[8:2] == {1'b1, `CNF_DATA_ADDR}) ;
488 wire wiack_hit = (wb_addr_in[8:2] == {1'b1, `INT_ACK_ADDR}) ;
492 always@(posedge reset_in or posedge wb_clock_in)
496 ccyc_hit <= #`FF_DELAY 1'b0 ;
497 iack_hit <= #`FF_DELAY 1'b0 ;
502 ccyc_hit <= #`FF_DELAY wccyc_hit ;
503 iack_hit <= #`FF_DELAY wiack_hit ;
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
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
515 // variables for configuration access control signals
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)
523 current_delayed_is_ccyc <= #`FF_DELAY 1'b0 ;
524 current_delayed_is_iack <= #`FF_DELAY 1'b0 ;
529 current_delayed_is_ccyc <= #`FF_DELAY 1'b0 ;
530 current_delayed_is_iack <= #`FF_DELAY 1'b0 ;
533 if ( del_req_out && wb_conf_hit )
535 current_delayed_is_ccyc <= #`FF_DELAY do_ccyc_req ;
536 current_delayed_is_iack <= #`FF_DELAY do_iack_req ;
543 // configuration read enable - supplied for host and guest bridges
545 assign wb_conf_renable_out = conf_renable ;
547 // burst access indicator
548 wire burst_transfer = CYC_I && CAB_I ;
550 // WBW_FIFO control output
551 reg [3:0] wbw_fifo_control ;
553 // WBW_FIFO wenable output assignment
554 reg wbw_fifo_wenable ;
556 // WBR_FIFO control outputs
557 reg wbr_fifo_flush, wbr_fifo_renable ; // flush and read enable outputs
559 // flush signal for WBR_FIFO must be registered, since it asinchronously resets some status registers
560 wire wbr_fifo_flush_reg ;
561 pci_async_reset_flop async_reset_as_wbr_flush
563 .data_in (wbr_fifo_flush),
564 .clk_in (wb_clock_in),
565 .async_reset_data_out (wbr_fifo_flush_reg),
568 assign wbr_fifo_flush_out = wbr_fifo_flush_reg ;
570 // delayed transaction request control signals
571 reg del_req, del_done ;
573 // WISHBONE handshaking control outputs
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
579 wire wattempt = ( CYC_I && STB_I && WE_I ) && (!ACK_O && !ERR_O && !RTY_O) ;
580 wire rattempt = ( CYC_I && STB_I && ~WE_I ) && (!ACK_O && !ERR_O && !RTY_O) ;
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
585 wire wattempt = ( CYC_I && STB_I && WE_I ) ; // write is qualified when cycle, strobe and write enable inputs are all high
586 wire rattempt = ( CYC_I && STB_I && ~WE_I ) ; // read is qualified when cycle and strobe are high and write enable is low
589 /*----------------------------------------------------------------------------------------------------------------------
590 Delayed transaction bus command generation
591 Bus command for delayed reads depends on image's address space mapping and control bits and
592 whether or not these are interrupt acknowledge requests or configuration cycle requests
593 ---------------------------------------------------------------------------------------------------------------------*/
595 always@(map or mrl_en or ccyc_hit or WE_I or wb_conf_hit or CAB_I or pref_en)
598 // only host implementation supports configuration and interrupt acknowledge commands
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 ;
613 del_bc = `BC_IO_READ ;
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
627 reg del_in_progress ; // state machine indicates whether current read completion is in progress on WISHBONE bus
629 wire image_access_error = (map && burst_transfer) ; // IO write is a burst
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 ;
638 reg wbw_data_out_sel ;
639 parameter SEL_ADDR_IN = 1'b1 ;
640 parameter SEL_DATA_IN = 1'b0 ;
644 `ifdef WB_DECODE_FAST
645 `ifdef REGISTER_WBS_OUTPUTS
646 `define PCI_WB_SLAVE_S_DEC1
650 `ifdef WB_DECODE_MEDIUM
651 `define PCI_WB_SLAVE_S_DEC1
654 `ifdef WB_DECODE_SLOW
655 `define PCI_WB_SLAVE_S_DEC1
656 `define PCI_WB_SLAVE_S_DEC2
658 // state machine logic
667 do_dread_completion or
668 wbr_fifo_control_in or
677 image_access_error or
678 wbw_fifo_almost_full_in or
685 // default signal values
686 // response signals inactive
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 ;
697 wbw_fifo_wenable = 1'b0 ;
698 d_incoming_ena = 1'b0 ;
700 // read signals inactive
701 wbr_fifo_flush = 1'b0 ;
702 wbr_fifo_renable = 1'b0 ;
706 // configuration space control signals inactive
707 conf_wenable = 1'b0 ;
708 conf_renable = 1'b0 ;
710 // read is not in progress
711 del_in_progress = 1'b0 ;
715 wbw_data_out_sel = SEL_ADDR_IN ;
717 sample_address_out = 1'b0 ;
721 if ( (wattempt || rattempt) & init_complete_in )
724 `ifdef PCI_WB_SLAVE_S_DEC1
731 sample_address_out = 1'b1 ;
736 `ifdef PCI_WB_SLAVE_S_DEC1
738 if ( wattempt || rattempt )
741 `ifdef PCI_WB_SLAVE_S_DEC2
753 `ifdef PCI_WB_SLAVE_S_DEC2
756 if ( wattempt || rattempt )
766 if (wb_conf_hit) // configuration space hit
769 wbw_data_out_sel = SEL_CCYC_ADDR ;
773 n_state = S_CONF_WRITE ; // go to conf. write state
777 n_state = S_CONF_READ ; // go to conf. read state
780 n_state = S_IDLE ; // master terminated - go back to idle state
784 if( wb_hit && (wattempt || rattempt) )
786 wbw_data_out_sel = SEL_DATA_IN ;
788 // check error conditions for image writes or reads
789 if ( image_access_error )
791 n_state = S_IDLE ; // go back to idle state because of an error condition
793 end // error conditions
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
800 n_state = S_IDLE ; // go back to IDLE
804 del_req = do_del_request && rattempt ;
807 else // everything OK - proceed
810 n_state = S_W_ADDR_DATA ; // goto write transfer state
812 // respond with acknowledge
815 wbw_fifo_wenable = 1'b1 ;
817 // data is latched to data incoming intermidiate stage - it will be put in FIFO later
818 d_incoming_ena = 1'b1 ;
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 ;
827 if ( wbr_fifo_control_in[`DATA_ERROR_CTRL_BIT] || wbr_fifo_control_in[`LAST_CTRL_BIT] )
830 n_state = S_IDLE ; // go back to idle state
831 // respond that read is finished
836 n_state = S_READ ; // go to read state
845 wbw_data_out_sel = SEL_DATA_IN ;
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 ) )
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 ;
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 ;
863 wbw_fifo_wenable = wattempt ;
864 d_incoming_ena = wattempt ;
869 // this state is for reads only - in this state read is in progress all the time
870 del_in_progress = 1'b1 ;
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 ;
875 // if acknowledge is beeing signalled then enable read from wbr fifo
876 wbr_fifo_renable = burst_transfer && rattempt && ~wbr_fifo_empty_in ;
878 if ( ~burst_transfer || rattempt && (wbr_fifo_empty_in || wbr_fifo_control_in[`DATA_ERROR_CTRL_BIT] || wbr_fifo_control_in[`LAST_CTRL_BIT]) )
882 wbr_fifo_flush = ~wbr_fifo_empty_in ;
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 ;
898 n_state = S_IDLE ; // next state after configuration access is always idle
900 if ( burst_transfer )
907 if ( do_ccyc_req || (ccyc_hit && ~do_ccyc_comp))
915 ack = ~del_error_in ;
920 conf_wenable = ~ccyc_hit ;
924 conf_wenable = 1'b1 ;
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 ) ;
938 n_state = S_IDLE ; // next state after configuration access is always idle
940 if ( burst_transfer )
947 if ( do_ccyc_req || ( ccyc_hit && ~do_ccyc_comp ))
952 if ( do_iack_req || ( iack_hit && ~do_iack_comp ))
957 if ( do_iack_comp || do_ccyc_comp )
960 ack = ~del_error_in ;
964 ack = ~( ccyc_hit || iack_hit ) ;
965 conf_renable = ~( ccyc_hit || iack_hit ) ;
969 conf_renable = 1'b1 ;
974 n_state = S_IDLE ; // return to idle state
979 // configuration space offset output assignment
980 assign wb_conf_offset_out = {wb_addr_in[11:2], 2'b00} ; // upper 10 bits of address input and two zeros
982 // data output assignment - for image writes, first data is address, subsequent data comes from intermediate register
985 reg [1:0] wbw_data_out_sel_reg ;
986 always@(posedge wb_clock_in or posedge reset_in)
989 wbw_data_out_sel_reg <= #`FF_DELAY SEL_ADDR_IN ;
991 wbw_data_out_sel_reg <= #`FF_DELAY wbw_data_out_sel ;
994 always@(wbw_data_out_sel_reg or wb_addr_in or ccyc_addr_in or d_incoming)
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 ;
1004 reg wbw_data_out_sel_reg ;
1005 always@(posedge wb_clock_in or posedge reset_in)
1008 wbw_data_out_sel_reg <= #`FF_DELAY SEL_ADDR_IN ;
1010 wbw_data_out_sel_reg <= #`FF_DELAY wbw_data_out_sel ;
1013 always@(wbw_data_out_sel_reg or wb_addr_in or d_incoming)
1015 if ( wbw_data_out_sel_reg )
1016 wb_data = wb_addr_in ;
1018 wb_data = d_incoming ;
1023 // command / byte enable assignment - with address, bus command is provided, with data - byte enables are provided
1026 always@(wbw_data_out_sel_reg or d_incoming or map)
1028 if (wbw_data_out_sel_reg && map)
1029 wb_cbe = `BC_IO_WRITE ;
1031 if (wbw_data_out_sel_reg)
1032 wb_cbe = `BC_MEM_WRITE ;
1034 wb_cbe = ~(d_incoming[35:32]) ;
1037 // for configuration writes, data output is always data from WISHBONE - in guest implementation data is all 0.
1039 assign wb_conf_data_out = 32'h00000000 ;
1045 `define PCI_WB_SLAVE_DO_OUT_MUX
1049 `define PCI_WB_SLAVE_DO_OUT_MUX ;
1053 `ifdef PCI_WB_SLAVE_DO_OUT_MUX
1054 reg [31:0] sdata_source ;
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 ;
1060 always@(posedge wb_clock_in or posedge reset_in)
1063 sdata_o_sel <= #`FF_DELAY WBR_SEL ;
1066 sdata_o_sel <= #`FF_DELAY sdata_o_sel_new ;
1069 always@(sdata_o_sel or wbr_fifo_data_in or wb_conf_data_in)
1072 WBR_SEL :sdata_source = wbr_fifo_data_in ;
1073 CONF_SEL:sdata_source = wb_conf_data_in ;
1077 wire [31:0] sdata_source = wbr_fifo_data_in ;
1080 `ifdef REGISTER_WBS_OUTPUTS
1082 always@(posedge wb_clock_in or posedge reset_in)
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 ;
1093 wb_conf_wenable_out <= #`FF_DELAY 1'b0 ;
1094 wb_conf_data_out <= #`FF_DELAY 0 ;
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 ;
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 ;
1118 wb_conf_wenable_out <= #`FF_DELAY conf_wenable ;
1119 wb_conf_data_out <= #`FF_DELAY SDATA_I ;
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 ;
1138 assign SDATA_O = sdata_source ;
1140 assign ACK_O = ack ;
1141 assign RTY_O = rty ;
1142 assign ERR_O = err ;
1144 // write operation indicator for delayed transaction requests
1145 assign del_write_out = WE_I ;
1146 assign del_bc_out = del_bc ;
1147 assign del_req_out = del_req ; // read request
1148 assign del_done_out = del_done ; // read done
1149 assign del_burst_out = del_burst ;
1150 assign del_in_progress_out = del_in_progress ;
1152 assign wb_conf_data_out = SDATA_I ;
1153 assign wb_conf_wenable_out = conf_wenable ;
1155 // Configuration space byte enables output
1156 assign wb_conf_be_out = SEL_I ; // just route select lines from WISHBONE to conf space
1157 assign wb_data_out = wb_data ;
1158 assign wb_cbe_out = wb_cbe ;
1159 assign wbw_fifo_wenable_out = wbw_fifo_wenable ; //write enable for WBW_FIFO
1160 assign wbw_fifo_control_out = wbw_fifo_control ; //control bus output for WBW_FIFO
1161 assign wbr_fifo_renable_out = wbr_fifo_renable ; //read enable for wbr_fifo
1164 endmodule //WB_SLAVE