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

Subversion Repositories pci

[/] [pci/] [tags/] [rel_6/] [rtl/] [verilog/] [pci_conf_space.v] - Blame information for rev 88

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

Line No. Rev Author Line
1 77 mihad
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  File name: conf_space.v                                     ////
4
////                                                              ////
5
////  This file is part of the "PCI bridge" project               ////
6
////  http://www.opencores.org/cores/pci/                         ////
7
////                                                              ////
8
////  Author(s):                                                  ////
9
////      - tadej@opencores.org                                   ////
10
////      - Tadej Markovic                                        ////
11
////                                                              ////
12
////  All additional information is avaliable in the README.txt   ////
13
////  file.                                                       ////
14
////                                                              ////
15
////                                                              ////
16
//////////////////////////////////////////////////////////////////////
17
////                                                              ////
18
//// Copyright (C) 2000 Tadej Markovic, tadej@opencores.org       ////
19
////                                                              ////
20
//// This source file may be used and distributed without         ////
21
//// restriction provided that this copyright statement is not    ////
22
//// removed from the file and that any derivative work contains  ////
23
//// the original copyright notice and the associated disclaimer. ////
24
////                                                              ////
25
//// This source file is free software; you can redistribute it   ////
26
//// and/or modify it under the terms of the GNU Lesser General   ////
27
//// Public License as published by the Free Software Foundation; ////
28
//// either version 2.1 of the License, or (at your option) any   ////
29
//// later version.                                               ////
30
////                                                              ////
31
//// This source is distributed in the hope that it will be       ////
32
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
33
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
34
//// PURPOSE.  See the GNU Lesser General Public License for more ////
35
//// details.                                                     ////
36
////                                                              ////
37
//// You should have received a copy of the GNU Lesser General    ////
38
//// Public License along with this source; if not, download it   ////
39
//// from http://www.opencores.org/lgpl.shtml                     ////
40
////                                                              ////
41
//////////////////////////////////////////////////////////////////////
42
//
43
// CVS Revision History
44
//
45
// $Log: not supported by cvs2svn $
46 88 mihad
// Revision 1.1  2003/01/27 16:49:31  mihad
47
// Changed module and file names. Updated scripts accordingly. FIFO synchronizations changed.
48
//
49 77 mihad
// Revision 1.4  2002/08/13 11:03:53  mihad
50
// Added a few testcases. Repaired wrong reset value for PCI_AM5 register. Repaired Parity Error Detected bit setting. Changed PCI_AM0 to always enabled(regardles of PCI_AM0 define), if image 0 is used as configuration image
51
//
52
// Revision 1.3  2002/02/01 15:25:12  mihad
53
// Repaired a few bugs, updated specification, added test bench files and design document
54
//
55
// Revision 1.2  2001/10/05 08:14:28  mihad
56
// Updated all files with inclusion of timescale file for simulation purposes.
57
//
58
// Revision 1.1.1.1  2001/10/02 15:33:46  mihad
59
// New project directory structure
60
//
61
//
62
 
63
`include "pci_constants.v"
64
 
65
// synopsys translate_off
66
`include "timescale.v"
67
// synopsys translate_on
68
 
69
/*-----------------------------------------------------------------------------------------------------------
70
        w_ prefix is a sign for Write (and read) side of Dual-Port registers
71
        r_ prefix is a sign for Read only side of Dual-Port registers
72
In the first line there are DATA and ADDRESS ports, in the second line there are write enable and read
73
enable signals with chip-select (conf_hit) for config. space.
74
In the third line there are output signlas from Command register of the PCI configuration header !!!
75
In the fourth line there are input signals to Status register of the PCI configuration header !!!
76
In the fifth line there is output from Latency Timer & r_Interrupt pin registers of the PCI conf. header !!!
77
Following are IMAGE specific registers, from which PCI_BASE_ADDR registers are the same as base address
78
registers from the PCI conf. header !!!
79
-----------------------------------------------------------------------------------------------------------*/
80
                                        // normal R/W address, data and control
81
module pci_conf_space
82
                (       w_conf_address_in, w_conf_data_in, w_conf_data_out, r_conf_address_in, r_conf_data_out,
83
                                        w_we, w_re, r_re, w_byte_en, w_clock, reset, pci_clk, wb_clk,
84
                                        // outputs from command register of the PCI header
85
                                        serr_enable, perr_response, pci_master_enable, memory_space_enable, io_space_enable,
86
                                        // inputs to status register of the PCI header
87
                                        perr_in, serr_in, master_abort_recv, target_abort_recv, target_abort_set, master_data_par_err,
88
                                        // output from cache_line_size, latency timer and r_interrupt_pin register of the PCI header
89
                                        cache_line_size_to_pci, cache_line_size_to_wb, cache_lsize_not_zero_to_wb,
90
                                        latency_tim,
91
                                        // output from all pci IMAGE registers
92
                                        pci_base_addr0, pci_base_addr1, pci_base_addr2, pci_base_addr3, pci_base_addr4, pci_base_addr5,
93
                                        pci_memory_io0, pci_memory_io1, pci_memory_io2, pci_memory_io3, pci_memory_io4, pci_memory_io5,
94
                                        pci_addr_mask0, pci_addr_mask1, pci_addr_mask2, pci_addr_mask3, pci_addr_mask4, pci_addr_mask5,
95
                                        pci_tran_addr0, pci_tran_addr1, pci_tran_addr2, pci_tran_addr3, pci_tran_addr4, pci_tran_addr5,
96
                                        pci_img_ctrl0,  pci_img_ctrl1,  pci_img_ctrl2,  pci_img_ctrl3,  pci_img_ctrl4,  pci_img_ctrl5,
97
                                        // input to pci error control and status register, error address and error data registers
98
                                        pci_error_be, pci_error_bc, pci_error_rty_exp, pci_error_es, pci_error_sig, pci_error_addr,
99
                                        pci_error_data,
100
                                        // output from all wishbone IMAGE registers
101
                                        wb_base_addr0, wb_base_addr1, wb_base_addr2, wb_base_addr3, wb_base_addr4, wb_base_addr5,
102
                                        wb_memory_io0, wb_memory_io1, wb_memory_io2, wb_memory_io3, wb_memory_io4, wb_memory_io5,
103
                                        wb_addr_mask0, wb_addr_mask1, wb_addr_mask2, wb_addr_mask3, wb_addr_mask4, wb_addr_mask5,
104
                                        wb_tran_addr0, wb_tran_addr1, wb_tran_addr2, wb_tran_addr3, wb_tran_addr4, wb_tran_addr5,
105
                                        wb_img_ctrl0,  wb_img_ctrl1,  wb_img_ctrl2,  wb_img_ctrl3,  wb_img_ctrl4,  wb_img_ctrl5,
106
                                        // input to wb error control and status register, error address and error data registers
107
                                        wb_error_be, wb_error_bc, wb_error_rty_exp, wb_error_es, wb_error_sig, wb_error_addr, wb_error_data,
108
                                        // output from conf. cycle generation register (sddress), int. control register & interrupt output
109
                                        config_addr, icr_soft_res, int_out,
110
                                        // input to interrupt status register
111
                                        isr_sys_err_int, isr_par_err_int, isr_int_prop ) ;
112
 
113
 
114
/*###########################################################################################################
115
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
116
        Input and output ports
117
        ======================
118
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
119
###########################################################################################################*/
120
 
121
// output data
122
output  [31 : 0]                         w_conf_data_out ;
123
output  [31 : 0]                         r_conf_data_out ;
124
reg             [31 : 0]                         w_conf_data_out ;
125
 
126
`ifdef  NO_CNF_IMAGE
127
`else
128
reg             [31 : 0]                         r_conf_data_out ;
129
`endif
130
 
131
// input data
132
input   [31 : 0]                         w_conf_data_in ;
133
wire    [31 : 0]                         w_conf_pdata_reduced ; // reduced data written into PCI image registers
134
wire    [31 : 0]                         w_conf_wdata_reduced ; // reduced data written into WB  image registers
135
// input address
136
input   [11 : 0]                         w_conf_address_in ;
137
input   [11 : 0]                         r_conf_address_in ;
138
// input control signals
139
input                                                   w_we ;
140
input                                                   w_re ;
141
input                                                   r_re ;
142
input   [3 : 0]                                  w_byte_en ;
143
input                                                   w_clock ;
144
input                                                   reset ;
145
input                                                   pci_clk ;
146
input                                                   wb_clk ;
147
// PCI header outputs from command register
148
output                                                  serr_enable ;
149
output                                                  perr_response ;
150
output                                                  pci_master_enable ;
151
output                                                  memory_space_enable ;
152
output                                                  io_space_enable ;
153
// PCI header inputs to status register
154
input                                                   perr_in ;
155
input                                                   serr_in ;
156
input                                                   master_abort_recv ;
157
input                                                   target_abort_recv ;
158
input                                                   target_abort_set ;
159
input                                                   master_data_par_err ;
160
// PCI header output from cache_line_size, latency timer and interrupt pin
161
output  [7 : 0]                                  cache_line_size_to_pci ; // sinchronized to PCI clock
162
output  [7 : 0]                                  cache_line_size_to_wb ;  // sinchronized to WB clock
163
output                                                  cache_lsize_not_zero_to_wb ; // used in WBU and PCIU
164
output  [7 : 0]                                  latency_tim ;
165
//output        [2 : 0]                                 int_pin ; // only 3 LSbits are important!
166
// PCI output from image registers
167
output  [31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] pci_base_addr0 ;
168
output  [31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] pci_base_addr1 ;
169
output  [31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] pci_base_addr2 ;
170
output  [31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] pci_base_addr3 ;
171
output  [31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] pci_base_addr4 ;
172
output  [31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] pci_base_addr5 ;
173
output                                                  pci_memory_io0 ;
174
output                                                  pci_memory_io1 ;
175
output                                                  pci_memory_io2 ;
176
output                                                  pci_memory_io3 ;
177
output                                                  pci_memory_io4 ;
178
output                                                  pci_memory_io5 ;
179
output  [31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] pci_addr_mask0 ;
180
output  [31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] pci_addr_mask1 ;
181
output  [31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] pci_addr_mask2 ;
182
output  [31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] pci_addr_mask3 ;
183
output  [31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] pci_addr_mask4 ;
184
output  [31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] pci_addr_mask5 ;
185
output  [31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] pci_tran_addr0 ;
186
output  [31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] pci_tran_addr1 ;
187
output  [31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] pci_tran_addr2 ;
188
output  [31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] pci_tran_addr3 ;
189
output  [31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] pci_tran_addr4 ;
190
output  [31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] pci_tran_addr5 ;
191
output  [2 : 1]                 pci_img_ctrl0 ;
192
output  [2 : 1]                 pci_img_ctrl1 ;
193
output  [2 : 1]                 pci_img_ctrl2 ;
194
output  [2 : 1]                 pci_img_ctrl3 ;
195
output  [2 : 1]                 pci_img_ctrl4 ;
196
output  [2 : 1]                 pci_img_ctrl5 ;
197
// PCI input to pci error control and status register, error address and error data registers
198
input   [3 : 0]                                  pci_error_be ;
199
input   [3 : 0]                 pci_error_bc ;
200
input                           pci_error_rty_exp ;
201
input                                                   pci_error_es ;
202
input                           pci_error_sig ;
203
input   [31 : 0]                pci_error_addr ;
204
input   [31 : 0]                pci_error_data ;
205
// WISHBONE output from image registers
206
output  [31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] wb_base_addr0 ;
207
output  [31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] wb_base_addr1 ;
208
output  [31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] wb_base_addr2 ;
209
output  [31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] wb_base_addr3 ;
210
output  [31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] wb_base_addr4 ;
211
output  [31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] wb_base_addr5 ;
212
output                                                  wb_memory_io0 ;
213
output                                                  wb_memory_io1 ;
214
output                                                  wb_memory_io2 ;
215
output                                                  wb_memory_io3 ;
216
output                                                  wb_memory_io4 ;
217
output                                                  wb_memory_io5 ;
218
output  [31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] wb_addr_mask0 ;
219
output  [31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] wb_addr_mask1 ;
220
output  [31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] wb_addr_mask2 ;
221
output  [31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] wb_addr_mask3 ;
222
output  [31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] wb_addr_mask4 ;
223
output  [31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] wb_addr_mask5 ;
224
output  [31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] wb_tran_addr0 ;
225
output  [31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] wb_tran_addr1 ;
226
output  [31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] wb_tran_addr2 ;
227
output  [31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] wb_tran_addr3 ;
228
output  [31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] wb_tran_addr4 ;
229
output  [31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] wb_tran_addr5 ;
230
output  [2 : 0]                 wb_img_ctrl0 ;
231
output  [2 : 0]                 wb_img_ctrl1 ;
232
output  [2 : 0]                 wb_img_ctrl2 ;
233
output  [2 : 0]                 wb_img_ctrl3 ;
234
output  [2 : 0]                 wb_img_ctrl4 ;
235
output  [2 : 0]                 wb_img_ctrl5 ;
236
// WISHBONE input to wb error control and status register, error address and error data registers
237
input   [3 : 0]                          wb_error_be ;
238
input   [3 : 0]                  wb_error_bc ;
239
input                                   wb_error_rty_exp ;
240
input                           wb_error_es ;
241
input                           wb_error_sig ;
242
input   [31 : 0]                wb_error_addr ;
243
input   [31 : 0]                wb_error_data ;
244
// GENERAL output from conf. cycle generation register & int. control register
245
output  [23 : 0]                         config_addr ;
246
output                          icr_soft_res ;
247
output                                                  int_out ;
248
// GENERAL input to interrupt status register
249
input                           isr_sys_err_int ;
250
input                           isr_par_err_int ;
251
input                                                   isr_int_prop ;
252
 
253
 
254
/*###########################################################################################################
255
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
256
        REGISTERS definition
257
        ====================
258
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
259
###########################################################################################################*/
260
 
261
// Decoded Register Select signals for writting (only one address decoder)
262
reg             [55 : 0]                         w_reg_select_dec ;
263
 
264
/*###########################################################################################################
265
-------------------------------------------------------------------------------------------------------------
266
PCI CONFIGURATION SPACE HEADER (type 00h) registers
267
 
268
        BIST and some other registers are not implemented and therefor written in correct
269
        place with comment line. There are also some registers with NOT all bits implemented and therefor uses
270
        _bitX or _bitX2_X1 to sign which bit or range of bits are implemented.
271
        Some special cases and examples are described below!
272
-------------------------------------------------------------------------------------------------------------
273
###########################################################################################################*/
274
 
275
/*-----------------------------------------------------------------------------------------------------------
276
[000h-00Ch] First 4 DWORDs (32-bit) of PCI configuration header - the same regardless of the HEADER type !
277
                        r_ prefix is a sign for read only registers
278
        Vendor_ID is an ID for a specific vendor defined by PCI_SIG - 2321h does not belong to anyone (e.g.
279
        Xilinx's Vendor_ID is 10EEh and Altera's Vendor_ID is 1172h). Device_ID and Revision_ID should be used
280
        together by application. Class_Code has 3 bytes to define BASE class (06h for PCI Bridge), SUB class
281
        (00h for HOST type, 80h for Other Bridge type) and Interface type (00h for normal).
282
-----------------------------------------------------------------------------------------------------------*/
283
                        parameter                       r_vendor_id = `HEADER_VENDOR_ID ;       // 16'h2321 = 16'd8993 !!!
284
                        parameter                       r_device_id = `HEADER_DEVICE_ID ;
285
                        reg                                     command_bit8 ;
286
                        reg                                     command_bit6 ;
287
                        reg             [2 : 0]          command_bit2_0 ;
288
                        reg             [15 : 11]       status_bit15_11 ;
289
                        parameter                       r_status_bit10_9 = 2'b01 ;      // 2'b01 means MEDIUM devsel timing !!!
290
                        reg                                     status_bit8 ;
291
                        parameter                       r_status_bit7 = 1'b1 ; // fast back-to-back capable response !!!
292
                        parameter                       r_status_bit5 = `HEADER_66MHz ;         // 1'b0 indicates 33 MHz capable !!!
293
                        parameter                       r_revision_id = `HEADER_REVISION_ID ;
294
`ifdef          HOST
295
                        parameter                       r_class_code = 24'h06_00_00 ;
296
`else
297
                        parameter                       r_class_code = 24'h06_80_00 ;
298
`endif
299
                        reg             [7 : 0]          cache_line_size_reg     ;
300
                        reg             [7 : 0]          latency_timer ;
301
                        parameter                       r_header_type = 8'h00 ;
302
                        // REG                          bist                                                    NOT implemented !!!
303
 
304
/*-----------------------------------------------------------------------------------------------------------
305
[010h-03Ch] all other DWORDs (32-bit) of PCI configuration header - only for HEADER type 00h !
306
                        r_ prefix is a sign for read only registers
307
        BASE_ADDRESS_REGISTERS are the same as ones in the PCI Target configuration registers section. They
308
        are duplicated and therefor defined just ones and used with the same name as written below. If
309
        IMAGEx is NOT defined there is only parameter image_X assigned to '0' and this parameter is used
310
        elsewhere in the code. This parameter is defined in the INTERNAL SIGNALS part !!!
311
        Interrupt_Pin value 8'h01 is used for INT_A pin used.
312
        MIN_GNT and MAX_LAT are used for device's desired values for Latency Timer value. The value in boath
313
        registers specifies a period of time in units of 1/4 microsecond. ZERO indicates that there are no
314
        major requirements for the settings of Latency Timer.
315
        MIN_GNT specifieshow how long a burst period the device needs at 33MHz. MAX_LAT specifies how often
316
        the device needs to gain access to the PCI bus. Values are choosen assuming that the target does not
317
        insert any wait states. Follow the expamle of settings for simple display card.
318
        If we use 64 (32-bit) FIFO locations for one burst then we need 8 x 1/4 microsecond periods at 33MHz
319
        clock rate => MIN_GNT = 08h ! Resolution is 1024 x 768 (= 786432 pixels for one frame) with 16-bit
320
        color mode. We can transfere 2 16-bit pixels in one FIFO location. From that we calculate, that for
321
        one frame we need 6144 burst transferes in 1/25 second. So we need one burst every 6,51 microsecond
322
        and that is 26 x 1/4 microsecond or 1Ah x 1/4 microsecond => MAX_LAT = 1Ah !
323
-----------------------------------------------------------------------------------------------------------*/
324
                        // REG x 6              base_address_register_X                 IMPLEMENTED as          pci_ba_X !!!
325
                        // REG                  r_cardbus_cis_pointer                   NOT implemented !!!
326
                        // REG                  r_subsystem_vendor_id                   NOT implemented !!!
327
                        // REG                  r_subsystem_id                                  NOT implemented !!!
328
                        // REG                  r_expansion_rom_base_address    NOT implemented !!!
329
                        // REG                  r_cap_list_pointer                              NOT implemented !!!
330
                        reg             [7 : 0]  interrupt_line ;
331
                        parameter               r_interrupt_pin = 8'h01 ;
332
                        parameter               r_min_gnt = 8'h08 ;
333
                        parameter               r_max_lat = 8'h1a ;
334
 
335
 
336
/*###########################################################################################################
337
-------------------------------------------------------------------------------------------------------------
338
PCI Bridge default image SIZE parameters
339
        This parameters are not part of any register group, but are needed for default image size configuration
340
        used in PCI Target and WISHBONE Slave configuration registers!
341
-------------------------------------------------------------------------------------------------------------
342
###########################################################################################################*/
343
 
344
/*-----------------------------------------------------------------------------------------------------------
345
        PCI Target default image size parameters are defined with masked bits for address mask registers of
346
        each image space. By default there are 1MByte of address space defined for def_pci_imageX_addr_map
347
        parameters!
348
-----------------------------------------------------------------------------------------------------------*/
349
                wire    [19:0]   def_pci_image0_addr_map = `PCI_AM0 ;
350
                wire    [19:0]   def_pci_image1_addr_map = `PCI_AM1 ;
351
                wire    [19:0]   def_pci_image2_addr_map = `PCI_AM2 ;
352
                wire    [19:0]   def_pci_image3_addr_map = `PCI_AM3 ;
353
                wire    [19:0]   def_pci_image4_addr_map = `PCI_AM4 ;
354
                wire    [19:0]   def_pci_image5_addr_map = `PCI_AM5 ;
355
 
356
/*-----------------------------------------------------------------------------------------------------------
357
        WISHBONE Slave default image size parameters are defined with masked bits for address mask registers
358
        of each image space. By default there are 1MByte of address space defined for def_wb_imageX_addr_map
359
        parameters except for def_wb_image0_addr_map which is used for configuration space!
360
-----------------------------------------------------------------------------------------------------------*/
361
                        // PARAMETER    def_wb_image0_addr_map  IMPLEMENTED as r_wb_am0 parameter for CONF. space !!!
362
                wire    [19:0]   def_wb_image1_addr_map = 20'h0000_0 ;
363
                wire    [19:0]   def_wb_image2_addr_map = 20'h0000_0 ;
364
                wire    [19:0]   def_wb_image3_addr_map = 20'h0000_0 ;
365
                wire    [19:0]   def_wb_image4_addr_map = 20'h0000_0 ;
366
                wire    [19:0]   def_wb_image5_addr_map = 20'h0000_0 ;
367
 
368
 
369
/*###########################################################################################################
370
-------------------------------------------------------------------------------------------------------------
371
PCI Target configuration registers
372
        There are also some registers with NOT all bits implemented and therefor uses _bitX or _bitX2_X1 to
373
        sign which bit or range of bits are implemented. Some special cases and examples are described below!
374
-------------------------------------------------------------------------------------------------------------
375
###########################################################################################################*/
376
 
377
/*-----------------------------------------------------------------------------------------------------------
378
[100h-168h]
379
        Depending on defines (PCI_IMAGE1 or .. or PCI_IMAGE5 or (PCI_IMAGE0 and HOST)) in constants.v file,
380
        there are registers corresponding to each IMAGE defined to REG and parameter pci_image_X assigned to '1'.
381
        The maximum number of images is "6". By default there are first two images used and the first (PCI_IMAGE0)
382
        is assigned to Configuration space! With a 'define' PCI_IMAGEx you choose the number of used PCI IMAGES
383
        in a bridge without PCI_IMAGE0 (e.g. PCI_IMAGE3 tells, that PCI_IMAGE1, PCI_IMAGE2 and PCI_IMAGE3 are
384
        used for mapping the space from WB to PCI. Offcourse, PCI_IMAGE0 is assigned to Configuration space).
385
        That leave us PCI_IMAGE5 as the maximum number of images.
386
        There is one exeption, when the core is implemented as HOST. If so, then the PCI specification allowes
387
        the Configuration space NOT to be visible on the PCI bus. With `define PCI_IMAGE0 (and `define HOST), we
388
        assign PCI_IMAGE0 to normal WB to PCI image and not to configuration space!
389
 
390
        When error occurs, PCI ERR_ADDR and ERR_DATA registers stores address and data on the bus that
391
        caused error. While ERR_CS register stores Byte Enables and Bus Command in the MSByte. In bits 10
392
        and 8 it reports Retry Counter Expired (for posted writes), Error Source (Master Abort) and Error
393
        Report Signal (signals that error has occured) respectively. With bit 0 we enable Error Reporting
394
        mechanism.
395
-----------------------------------------------------------------------------------------------------------*/
396
`ifdef          HOST
397
        `ifdef  NO_CNF_IMAGE
398
                `ifdef  PCI_IMAGE0      // if PCI bridge is HOST and IMAGE0 is assigned as general image space
399
                        reg             [31 : 12]       pci_ba0_bit31_12 ;
400
                        reg             [2 : 1]         pci_img_ctrl0_bit2_1 ;
401
                        reg                                     pci_ba0_bit0 ;
402
                        reg             [31 : 12]       pci_am0 ;
403
                        reg             [31 : 12]       pci_ta0 ;
404
                `else // if PCI bridge is HOST and IMAGE0 is not used
405
                        wire    [31 : 12]       pci_ba0_bit31_12 = 20'h0000_0 ; // NO base address needed
406
                        wire    [2 : 1]         pci_img_ctrl0_bit2_1 = 2'b00 ; // NO addr.transl. and pre-fetch
407
                        wire                            pci_ba0_bit0 = 0 ; // config. space is MEMORY space
408
                        wire    [31 : 12]       pci_am0 = 20'h0000_0 ; // NO address mask needed
409
                        wire    [31 : 12]       pci_ta0 = 20'h0000_0 ; // NO address translation needed
410
                `endif
411
        `else // if PCI bridge is HOST and IMAGE0 is assigned to PCI configuration space
412
                        reg             [31 : 12]       pci_ba0_bit31_12 ;
413
                        wire    [2 : 1]         pci_img_ctrl0_bit2_1 = 2'b00 ; // NO pre-fetch and read line support
414
                        wire                            pci_ba0_bit0 = 0 ; // config. space is MEMORY space
415
                        wire    [31 : 12]       pci_am0 = 20'hFFFF_F ; // address mask for configuration image always 20'hffff_f
416
                        wire    [31 : 12]       pci_ta0 = 20'h0000_0 ; // NO address translation needed
417
        `endif
418
`else // if PCI bridge is GUEST, then IMAGE0 is assigned to PCI configuration space
419
                        reg             [31 : 12]       pci_ba0_bit31_12 ;
420
                        wire    [2 : 1]         pci_img_ctrl0_bit2_1 = 2'b00 ; // NO addr.transl. and pre-fetch
421
                        wire                            pci_ba0_bit0 = 0 ; // config. space is MEMORY space
422
                        wire    [31 : 12]       pci_am0 = 20'hffff_f ; // address mask for configuration image always 20'hffff_f
423
                        wire    [31 : 12]       pci_ta0 = 20'h0000_0 ; // NO address translation needed
424
`endif
425
// IMAGE1 is included by default, meanwhile other IMAGEs are optional !!!
426
                        reg             [2 : 1]         pci_img_ctrl1_bit2_1 ;
427
                        reg             [31 : 12]       pci_ba1_bit31_12 ;
428
        `ifdef  HOST
429
                        reg                                     pci_ba1_bit0 ;
430
        `else
431
                        wire                            pci_ba1_bit0 = `PCI_BA1_MEM_IO ;
432
        `endif
433
                        reg             [31 : 12]       pci_am1 ;
434
                        reg             [31 : 12]       pci_ta1 ;
435
`ifdef          PCI_IMAGE2
436
                        reg             [2 : 1]         pci_img_ctrl2_bit2_1 ;
437
                        reg             [31 : 12]       pci_ba2_bit31_12 ;
438
        `ifdef  HOST
439
                        reg                                     pci_ba2_bit0 ;
440
        `else
441
                        wire                            pci_ba2_bit0 = `PCI_BA2_MEM_IO ;
442
        `endif
443
                        reg             [31 : 12]       pci_am2 ;
444
                        reg             [31 : 12]       pci_ta2 ;
445
`else
446
            wire        [2 : 1]         pci_img_ctrl2_bit2_1 = 2'b00 ;
447
                        wire    [31 : 12]       pci_ba2_bit31_12 = 20'h0000_0 ;
448
            wire                                pci_ba2_bit0 = 1'b0 ;
449
            wire        [31 : 12]       pci_am2 = 20'h0000_0 ;
450
            wire        [31 : 12]       pci_ta2 = 20'h0000_0 ;
451
`endif
452
`ifdef          PCI_IMAGE3
453
                        reg             [2 : 1]         pci_img_ctrl3_bit2_1 ;
454
                        reg             [31 : 12]       pci_ba3_bit31_12 ;
455
        `ifdef  HOST
456
                        reg                                     pci_ba3_bit0 ;
457
        `else
458
                        wire                            pci_ba3_bit0 = `PCI_BA3_MEM_IO ;
459
        `endif
460
                        reg             [31 : 12]       pci_am3 ;
461
                        reg             [31 : 12]       pci_ta3 ;
462
`else
463
            wire        [2 : 1]         pci_img_ctrl3_bit2_1 = 2'b00 ;
464
                        wire    [31 : 12]       pci_ba3_bit31_12 = 20'h0000_0 ;
465
            wire                                pci_ba3_bit0 = 1'b0 ;
466
            wire        [31 : 12]       pci_am3 = 20'h0000_0 ;
467
            wire        [31 : 12]       pci_ta3 = 20'h0000_0 ;
468
`endif
469
`ifdef          PCI_IMAGE4
470
                        reg             [2 : 1]         pci_img_ctrl4_bit2_1 ;
471
                        reg             [31 : 12]       pci_ba4_bit31_12 ;
472
        `ifdef  HOST
473
                        reg                                     pci_ba4_bit0 ;
474
        `else
475
                        wire                            pci_ba4_bit0 = `PCI_BA4_MEM_IO ;
476
        `endif
477
                        reg             [31 : 12]       pci_am4 ;
478
                        reg             [31 : 12]       pci_ta4 ;
479
`else
480
            wire        [2 : 1]         pci_img_ctrl4_bit2_1 = 2'b00 ;
481
                        wire    [31 : 12]       pci_ba4_bit31_12 = 20'h0000_0 ;
482
            wire                                pci_ba4_bit0 = 1'b0 ;
483
            wire        [31 : 12]       pci_am4 = 20'h0000_0 ;
484
            wire        [31 : 12]       pci_ta4 = 20'h0000_0 ;
485
`endif
486
`ifdef          PCI_IMAGE5
487
                        reg             [2 : 1]         pci_img_ctrl5_bit2_1 ;
488
                        reg             [31 : 12]       pci_ba5_bit31_12 ;
489
        `ifdef  HOST
490
                        reg                                     pci_ba5_bit0 ;
491
        `else
492
                        wire                            pci_ba5_bit0 = `PCI_BA5_MEM_IO ;
493
        `endif
494
                        reg             [31 : 12]       pci_am5 ;
495
                        reg             [31 : 12]       pci_ta5 ;
496
`else
497
            wire        [2 : 1]         pci_img_ctrl5_bit2_1 = 2'b00 ;
498
                        wire    [31 : 12]       pci_ba5_bit31_12 = 20'h0000_0 ;
499
            wire                                pci_ba5_bit0 = 1'b0 ;
500
            wire        [31 : 12]       pci_am5 = 20'h0000_0 ;
501
            wire        [31 : 12]       pci_ta5 = 20'h0000_0 ;
502
`endif
503
                        reg             [31 : 24]       pci_err_cs_bit31_24 ;
504
                        reg                                     pci_err_cs_bit10 ;
505
                        reg                                     pci_err_cs_bit9 ;
506
                        reg                                     pci_err_cs_bit8 ;
507
                        reg                                     pci_err_cs_bit0 ;
508
                        reg             [31 : 0] pci_err_addr ;
509
                        reg             [31 : 0] pci_err_data ;
510
 
511
 
512
/*###########################################################################################################
513
-------------------------------------------------------------------------------------------------------------
514
WISHBONE Slave configuration registers
515
        There are also some registers with NOT all bits implemented and therefor uses _bitX or _bitX2_X1 to
516
        sign which bit or range of bits are implemented. Some special cases and examples are described below!
517
-------------------------------------------------------------------------------------------------------------
518
###########################################################################################################*/
519
 
520
/*-----------------------------------------------------------------------------------------------------------
521
[800h-85Ch]
522
        Depending on defines (WB_IMAGE1 or .. or WB_IMAGE4 or WB_IMAGE5) in constants.v file, there are
523
        registers corresponding to each IMAGE defined to REG and parameter wb_image_X assigned to '1'.
524
        The maximum number of images is "6". By default there are first two images used and the first (WB_IMAGE0)
525
        is assigned to Configuration space! With a 'define' WB_IMAGEx you choose the number of used WB IMAGES in
526
        a bridge without WB_IMAGE0 (e.g. WB_IMAGE3 tells, that WB_IMAGE1, WB_IMAGE2 and WB_IMAGE3 are used for
527
        mapping the space from PCI to WB. Offcourse, WB_IMAGE0 is assigned to Configuration space). That leave
528
        us WB_IMAGE5 as the maximum number of images.
529
 
530
        When error occurs, WISHBONE ERR_ADDR and ERR_DATA registers stores address and data on the bus that
531
        caused error. While ERR_CS register stores Byte Enables and Bus Command in the MSByte. In bits 10, 9
532
        and 8 it reports Retry Counter Expired (for posted writes), Error Source (Master Abort) and Error
533
        Report Signal (signals that error has occured) respectively. With bit 0 we enable Error Reporting
534
        mechanism.
535
-----------------------------------------------------------------------------------------------------------*/
536
// WB_IMAGE0 is always assigned to config. space or is not used
537
                        wire    [2 : 0]          wb_img_ctrl0_bit2_0 = 3'b000 ; // NO addr.transl., pre-fetch and read-line
538
                        wire    [31 : 12]       wb_ba0_bit31_12 = `WB_CONFIGURATION_BASE ;
539
                        wire                            wb_ba0_bit0 = 0 ; // config. space is MEMORY space
540
                        wire    [31 : 12]       wb_am0 = `WB_AM0 ; // 4KBytes of configuration space is minimum
541
                        wire    [31 : 12]       wb_ta0 = 20'h0000_0 ; // NO address translation needed
542
// WB_IMAGE1 is included by default meanwhile others are optional !
543
                        reg             [2 : 0]          wb_img_ctrl1_bit2_0 ;
544
                        reg             [31 : 12]       wb_ba1_bit31_12 ;
545
                        reg                                     wb_ba1_bit0 ;
546
                        reg             [31 : 12]       wb_am1 ;
547
                        reg             [31 : 12]       wb_ta1 ;
548
`ifdef          WB_IMAGE2
549
                        reg             [2 : 0]          wb_img_ctrl2_bit2_0 ;
550
                        reg             [31 : 12]       wb_ba2_bit31_12 ;
551
                        reg                                     wb_ba2_bit0 ;
552
                        reg             [31 : 12]       wb_am2 ;
553
                        reg             [31 : 12]       wb_ta2 ;
554
`else
555
            wire        [2 : 0]          wb_img_ctrl2_bit2_0 = 3'b000 ;
556
                        wire    [31 : 12]       wb_ba2_bit31_12 = 20'h0000_0 ;
557
            wire                                wb_ba2_bit0 = 1'b0 ;
558
            wire        [31 : 12]       wb_am2 = 20'h0000_0 ;
559
            wire        [31 : 12]       wb_ta2 = 20'h0000_0 ;
560
`endif
561
`ifdef          WB_IMAGE3
562
                        reg             [2 : 0]          wb_img_ctrl3_bit2_0 ;
563
                        reg             [31 : 12]       wb_ba3_bit31_12 ;
564
                        reg                                     wb_ba3_bit0 ;
565
                        reg             [31 : 12]       wb_am3 ;
566
                        reg             [31 : 12]       wb_ta3 ;
567
`else
568
            wire        [2 : 0]          wb_img_ctrl3_bit2_0 = 3'b000 ;
569
                        wire    [31 : 12]       wb_ba3_bit31_12 = 20'h0000_0 ;
570
            wire                                wb_ba3_bit0 = 1'b0 ;
571
            wire        [31 : 12]       wb_am3 = 20'h0000_0 ;
572
            wire        [31 : 12]       wb_ta3 = 20'h0000_0 ;
573
`endif
574
`ifdef          WB_IMAGE4
575
                        reg             [2 : 0]          wb_img_ctrl4_bit2_0 ;
576
                        reg             [31 : 12]       wb_ba4_bit31_12 ;
577
                        reg                                     wb_ba4_bit0 ;
578
                        reg             [31 : 12]       wb_am4 ;
579
                        reg             [31 : 12]       wb_ta4 ;
580
`else
581
            wire        [2 : 0]          wb_img_ctrl4_bit2_0 = 3'b000 ;
582
                        wire    [31 : 12]       wb_ba4_bit31_12 = 20'h0000_0 ;
583
            wire                                wb_ba4_bit0 = 1'b0 ;
584
            wire        [31 : 12]       wb_am4 = 20'h0000_0 ;
585
            wire        [31 : 12]       wb_ta4 = 20'h0000_0 ;
586
`endif
587
`ifdef          WB_IMAGE5
588
                        reg             [2 : 0]          wb_img_ctrl5_bit2_0 ;
589
                        reg             [31 : 12]       wb_ba5_bit31_12 ;
590
                        reg                                     wb_ba5_bit0 ;
591
                        reg             [31 : 12]       wb_am5 ;
592
                        reg             [31 : 12]       wb_ta5 ;
593
`else
594
            wire        [2 : 0]          wb_img_ctrl5_bit2_0 = 3'b000 ;
595
                        wire    [31 : 12]       wb_ba5_bit31_12 = 20'h0000_0 ;
596
            wire                                wb_ba5_bit0 = 1'b0 ;
597
            wire        [31 : 12]       wb_am5 = 20'h0000_0 ;
598
            wire        [31 : 12]       wb_ta5 = 20'h0000_0 ;
599
`endif
600
                        reg             [31 : 24]       wb_err_cs_bit31_24 ;
601
/*                      reg                                     wb_err_cs_bit10 ;*/
602
                        reg                                     wb_err_cs_bit9 ;
603
                        reg                                     wb_err_cs_bit8 ;
604
                        reg                                     wb_err_cs_bit0 ;
605
                        reg             [31 : 0] wb_err_addr ;
606
                        reg             [31 : 0] wb_err_data ;
607
 
608
 
609
/*###########################################################################################################
610
-------------------------------------------------------------------------------------------------------------
611
Configuration Cycle address register
612
        There are also some registers with NOT all bits implemented and therefor uses _bitX or _bitX2_X1 to
613
        sign which bit or range of bits are implemented.
614
-------------------------------------------------------------------------------------------------------------
615
###########################################################################################################*/
616
 
617
/*-----------------------------------------------------------------------------------------------------------
618
[860h-868h]
619
        PCI bridge must ignore Type 1 configuration cycles (Master Abort) since they are used for PCI to PCI
620
        bridges. This is single function device, that means responding on configuration cycles to all functions
621
        (or responding only to function 0). Configuration address register for generating configuration cycles
622
        is prepared for all options (it includes Bus Number, Device, Function, Offset and Type).
623
        Interrupt acknowledge register stores interrupt vector data returned during Interrupt Acknowledge cycle.
624
-----------------------------------------------------------------------------------------------------------*/
625
`ifdef          HOST
626
                        reg             [23 : 2]        cnf_addr_bit23_2 ;
627
                        reg                                     cnf_addr_bit0 ;
628
`else // GUEST
629
                        wire    [23 : 2]        cnf_addr_bit23_2        = 22'h0 ;
630
                        wire                            cnf_addr_bit0           = 1'b0 ;
631
`endif
632
                        // reg  [31 : 0]        cnf_data ;              IMPLEMENTED elsewhere !!!!!
633
                        // reg  [31 : 0]        int_ack ;               IMPLEMENTED elsewhere !!!!!
634
 
635
 
636
/*###########################################################################################################
637
-------------------------------------------------------------------------------------------------------------
638
General Interrupt registers
639
        There are also some registers with NOT all bits implemented and therefor uses _bitX or _bitX2_X1 to
640
        sign which bit or range of bits are implemented.
641
-------------------------------------------------------------------------------------------------------------
642
###########################################################################################################*/
643
 
644
/*-----------------------------------------------------------------------------------------------------------
645
[FF8h-FFCh]
646
        Bit 31 in the Interrupt Control register is set by software and used to generate SOFT RESET. Other 4
647
        bits are used to enable interrupt generations.
648
        5 LSbits in the Interrupt Status register are indicating System Error Int, Parity Error Int, PCI & WB
649
        Error Int and Inerrupt respecively. System and Parity errors are implented only in HOST bridge
650
        implementations!
651
-----------------------------------------------------------------------------------------------------------*/
652
                        reg                                     icr_bit31 ;
653
`ifdef          HOST
654
                        reg             [4 : 3]         icr_bit4_3 ;
655
                        reg             [4 : 3]         isr_bit4_3 ;
656
                        reg             [2 : 0]          icr_bit2_0 ;
657
                        reg             [2 : 0]          isr_bit2_0 ;
658
`else // GUEST
659
                        wire    [4 : 3]         icr_bit4_3 = 2'h0 ;
660
                        wire    [4 : 3]         isr_bit4_3 = 2'h0 ;
661
                        reg             [2 : 0]          icr_bit2_0 ;
662
                        reg             [2 : 0]          isr_bit2_0 ;
663
`endif
664
 
665
 
666
/*###########################################################################################################
667
-------------------------------------------------------------------------------------------------------------
668
 
669
 
670
-----------------------------------------------------------------------------------------------------------*/
671
 
672
`ifdef NO_CNF_IMAGE // if IMAGE0 is assigned as general image space
673
 
674
                assign  r_conf_data_out = 32'h0000_0000 ;
675
 
676
`else
677
 
678
    always@(r_conf_address_in or
679
                status_bit15_11 or status_bit8 or command_bit8 or command_bit6 or command_bit2_0 or
680
                latency_timer or cache_line_size_reg or
681
                pci_ba0_bit31_12 or
682
                pci_img_ctrl0_bit2_1 or pci_am0 or pci_ta0 or pci_ba0_bit0 or
683
                pci_img_ctrl1_bit2_1 or pci_am1 or pci_ta1 or pci_ba1_bit31_12 or pci_ba1_bit0 or
684
                pci_img_ctrl2_bit2_1 or pci_am2 or pci_ta2 or pci_ba2_bit31_12 or pci_ba2_bit0 or
685
                pci_img_ctrl3_bit2_1 or pci_am3 or pci_ta3 or pci_ba3_bit31_12 or pci_ba3_bit0 or
686
                pci_img_ctrl4_bit2_1 or pci_am4 or pci_ta4 or pci_ba4_bit31_12 or pci_ba4_bit0 or
687
                pci_img_ctrl5_bit2_1 or pci_am5 or pci_ta5 or pci_ba5_bit31_12 or pci_ba5_bit0 or
688
                interrupt_line or
689
                pci_err_cs_bit31_24 or pci_err_cs_bit10 or pci_err_cs_bit9 or pci_err_cs_bit8 or pci_err_cs_bit0 or
690
                pci_err_addr or pci_err_data or
691
                wb_ba0_bit31_12 or wb_ba0_bit0 or
692
                wb_img_ctrl1_bit2_0 or wb_ba1_bit31_12 or wb_ba1_bit0 or wb_am1 or wb_ta1 or
693
                wb_img_ctrl2_bit2_0 or wb_ba2_bit31_12 or wb_ba2_bit0 or wb_am2 or wb_ta2 or
694
                wb_img_ctrl3_bit2_0 or wb_ba3_bit31_12 or wb_ba3_bit0 or wb_am3 or wb_ta3 or
695
                wb_img_ctrl4_bit2_0 or wb_ba4_bit31_12 or wb_ba4_bit0 or wb_am4 or wb_ta4 or
696
                wb_img_ctrl5_bit2_0 or wb_ba5_bit31_12 or wb_ba5_bit0 or wb_am5 or wb_ta5 or
697
                wb_err_cs_bit31_24 or /*wb_err_cs_bit10 or*/ wb_err_cs_bit9 or wb_err_cs_bit8 or wb_err_cs_bit0 or
698
                wb_err_addr or wb_err_data or
699
                cnf_addr_bit23_2 or cnf_addr_bit0 or icr_bit31 or icr_bit4_3 or icr_bit2_0 or isr_bit4_3 or isr_bit2_0
700
                )
701
    begin
702
        case (r_conf_address_in[8])
703
        1'b0 :
704
        begin
705
          case ({r_conf_address_in[7], r_conf_address_in[6]})
706
          2'b00 :
707
          begin
708
                // PCI header - configuration space
709
                case (r_conf_address_in[5:2])
710
                4'h0: r_conf_data_out = { r_device_id, r_vendor_id } ;
711
                4'h1: r_conf_data_out = { status_bit15_11, r_status_bit10_9, status_bit8, r_status_bit7, 1'h0, r_status_bit5,
712
                                                                         5'h00, 7'h00, command_bit8, 1'h0, command_bit6, 3'h0, command_bit2_0 } ;
713
                4'h2: r_conf_data_out = { r_class_code, r_revision_id } ;
714
                4'h3: r_conf_data_out = { 8'h00, r_header_type, latency_timer, cache_line_size_reg } ;
715
                4'h4:
716
                begin
717
                        r_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_ba0_bit31_12[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] &
718
                                                                                                                                 pci_am0[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
719
                        r_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):1] = 0 ;
720
                        r_conf_data_out[0] = pci_ba0_bit0 & pci_am0[31];
721
                end
722
                4'h5:
723
                begin
724
                        r_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_ba1_bit31_12[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] &
725
                                                                                                                                 pci_am1[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
726
                        r_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):1] = 0 ;
727
                        r_conf_data_out[0] = pci_ba1_bit0 & pci_am1[31];
728
                end
729
                4'h6:
730
                begin
731
                        r_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_ba2_bit31_12[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] &
732
                                                                                                                                 pci_am2[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
733
                        r_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):1] = 0 ;
734
                        r_conf_data_out[0] = pci_ba2_bit0 & pci_am2[31];
735
                end
736
                4'h7:
737
                begin
738
                        r_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_ba3_bit31_12[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] &
739
                                                                                                                                 pci_am3[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
740
                        r_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):1] = 0 ;
741
                        r_conf_data_out[0] = pci_ba3_bit0 & pci_am3[31];
742
                end
743
                4'h8:
744
                begin
745
                        r_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_ba4_bit31_12[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] &
746
                                                                                                                                 pci_am4[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
747
                        r_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):1] = 0 ;
748
                        r_conf_data_out[0] = pci_ba4_bit0 & pci_am4[31];
749
                end
750
                4'h9:
751
                begin
752
                        r_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_ba5_bit31_12[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] &
753
                                                                                                                                 pci_am5[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
754
                        r_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):1] = 0 ;
755
                        r_conf_data_out[0] = pci_ba5_bit0 & pci_am5[31];
756
                end
757
                4'hf: r_conf_data_out = { r_max_lat, r_min_gnt, r_interrupt_pin, interrupt_line } ;
758
                default : r_conf_data_out = 32'h0000_0000 ;
759
                endcase
760
          end
761
          default :
762
            r_conf_data_out = 32'h0000_0000 ;
763
          endcase
764
        end
765
        default :
766
        begin
767
                // PCI target - configuration space
768
                case (r_conf_address_in[7:2])
769
                `P_IMG_CTRL0_ADDR: r_conf_data_out = { 29'h00000000, pci_img_ctrl0_bit2_1, 1'h0 } ;
770
            `P_BA0_ADDR          :
771
                begin
772
                        r_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_ba0_bit31_12[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] &
773
                                                                                                                                 pci_am0[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
774
                        r_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):1] = 0 ;
775
                        r_conf_data_out[0] = pci_ba0_bit0 & pci_am0[31];
776
                end
777
            `P_AM0_ADDR          :
778
                begin
779
                r_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_am0[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
780
                        r_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
781
                end
782
            `P_TA0_ADDR          :
783
                begin
784
                r_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_ta0[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
785
                        r_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
786
                end
787
            `P_IMG_CTRL1_ADDR: r_conf_data_out = { 29'h00000000, pci_img_ctrl1_bit2_1, 1'h0 } ;
788
            `P_BA1_ADDR          :
789
                begin
790
                        r_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_ba1_bit31_12[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] &
791
                                                                                                                                 pci_am1[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
792
                        r_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):1] = 0 ;
793
                        r_conf_data_out[0] = pci_ba1_bit0 & pci_am1[31];
794
                end
795
            `P_AM1_ADDR          :
796
                begin
797
                r_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_am1[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
798
                        r_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
799
                end
800
            `P_TA1_ADDR          :
801
                begin
802
                r_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_ta1[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
803
                        r_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
804
                end
805
            `P_IMG_CTRL2_ADDR: r_conf_data_out = { 29'h00000000, pci_img_ctrl2_bit2_1, 1'h0 } ;
806
            `P_BA2_ADDR          :
807
                begin
808
                        r_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_ba2_bit31_12[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] &
809
                                                                                                                                 pci_am2[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
810
                        r_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):1] = 0 ;
811
                        r_conf_data_out[0] = pci_ba2_bit0 & pci_am2[31];
812
                end
813
            `P_AM2_ADDR          :
814
                begin
815
                r_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_am2[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
816
                        r_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
817
                end
818
            `P_TA2_ADDR          :
819
                begin
820
                r_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_ta2[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
821
                        r_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
822
                end
823
            `P_IMG_CTRL3_ADDR: r_conf_data_out = { 29'h00000000, pci_img_ctrl3_bit2_1, 1'h0 } ;
824
            `P_BA3_ADDR          :
825
                begin
826
                        r_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_ba3_bit31_12[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] &
827
                                                                                                                                 pci_am3[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
828
                        r_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):1] = 0 ;
829
                        r_conf_data_out[0] = pci_ba3_bit0 & pci_am3[31];
830
                end
831
            `P_AM3_ADDR          :
832
                begin
833
                r_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_am3[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
834
                        r_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
835
                end
836
            `P_TA3_ADDR          :
837
                begin
838
                r_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_ta3[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
839
                        r_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
840
                end
841
            `P_IMG_CTRL4_ADDR: r_conf_data_out = { 29'h00000000, pci_img_ctrl4_bit2_1, 1'h0 } ;
842
            `P_BA4_ADDR          :
843
                begin
844
                        r_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_ba4_bit31_12[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] &
845
                                                                                                                                 pci_am4[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
846
                        r_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):1] = 0 ;
847
                        r_conf_data_out[0] = pci_ba4_bit0 & pci_am4[31];
848
                end
849
            `P_AM4_ADDR          :
850
                begin
851
                r_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_am4[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
852
                        r_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
853
                end
854
            `P_TA4_ADDR          :
855
                begin
856
                r_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_ta4[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
857
                        r_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
858
                end
859
            `P_IMG_CTRL5_ADDR: r_conf_data_out = { 29'h00000000, pci_img_ctrl5_bit2_1, 1'h0 } ;
860
            `P_BA5_ADDR          :
861
                begin
862
                        r_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_ba5_bit31_12[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] &
863
                                                                                                                                 pci_am5[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
864
                        r_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):1] = 0 ;
865
                        r_conf_data_out[0] = pci_ba5_bit0 & pci_am5[31];
866
                end
867
            `P_AM5_ADDR          :
868
                begin
869
                r_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_am5[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
870
                        r_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
871
                end
872
            `P_TA5_ADDR          :
873
                begin
874
                r_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_ta5[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
875
                        r_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
876
                end
877
            `P_ERR_CS_ADDR       : r_conf_data_out = { pci_err_cs_bit31_24, 13'h0000, pci_err_cs_bit10, pci_err_cs_bit9,
878
                                                                                   pci_err_cs_bit8, 7'h00, pci_err_cs_bit0 } ;
879
            `P_ERR_ADDR_ADDR : r_conf_data_out = pci_err_addr ;
880
            `P_ERR_DATA_ADDR : r_conf_data_out = pci_err_data ;
881
                // WB slave - configuration space
882
                `WB_CONF_SPC_BAR_ADDR: r_conf_data_out = { wb_ba0_bit31_12, 11'h000, wb_ba0_bit0 } ;
883
                `W_IMG_CTRL1_ADDR: r_conf_data_out = { 29'h00000000, wb_img_ctrl1_bit2_0 } ;
884
                `W_BA1_ADDR              :
885
                begin
886
                        r_conf_data_out[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] = wb_ba1_bit31_12[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] &
887
                                                                                                                                wb_am1[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
888
                        r_conf_data_out[(31-`WB_NUM_OF_DEC_ADDR_LINES):1]  = 0 ;
889
                        r_conf_data_out[0] = wb_ba1_bit0 ;
890
                end
891
                `W_AM1_ADDR              :
892
                begin
893
                        r_conf_data_out[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] = wb_am1[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
894
                        r_conf_data_out[(31-`WB_NUM_OF_DEC_ADDR_LINES):0]  = 0 ;
895
                end
896
                `W_TA1_ADDR              :
897
                begin
898
                        r_conf_data_out[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] = wb_ta1[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
899
                        r_conf_data_out[(31-`WB_NUM_OF_DEC_ADDR_LINES):0]  = 0 ;
900
                end
901
                `W_IMG_CTRL2_ADDR: r_conf_data_out = { 29'h00000000, wb_img_ctrl2_bit2_0 } ;
902
                `W_BA2_ADDR              :
903
                begin
904
                        r_conf_data_out[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] = wb_ba2_bit31_12[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] &
905
                                                                                                                                wb_am2[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
906
                        r_conf_data_out[(31-`WB_NUM_OF_DEC_ADDR_LINES):1]  = 0 ;
907
                        r_conf_data_out[0] = wb_ba2_bit0 ;
908
                end
909
                `W_AM2_ADDR              :
910
                begin
911
                        r_conf_data_out[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] = wb_am2[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
912
                        r_conf_data_out[(31-`WB_NUM_OF_DEC_ADDR_LINES):0]  = 0 ;
913
                end
914
                `W_TA2_ADDR              :
915
                begin
916
                        r_conf_data_out[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] = wb_ta2[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
917
                        r_conf_data_out[(31-`WB_NUM_OF_DEC_ADDR_LINES):0]  = 0 ;
918
                end
919
                `W_IMG_CTRL3_ADDR: r_conf_data_out = { 29'h00000000, wb_img_ctrl3_bit2_0 } ;
920
                `W_BA3_ADDR              :
921
                begin
922
                        r_conf_data_out[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] = wb_ba3_bit31_12[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] &
923
                                                                                                                                wb_am3[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
924
                        r_conf_data_out[(31-`WB_NUM_OF_DEC_ADDR_LINES):1]  = 0 ;
925
                        r_conf_data_out[0] = wb_ba3_bit0 ;
926
                end
927
                `W_AM3_ADDR              :
928
                begin
929
                        r_conf_data_out[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] = wb_am3[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
930
                        r_conf_data_out[(31-`WB_NUM_OF_DEC_ADDR_LINES):0]  = 0 ;
931
                end
932
                `W_TA3_ADDR              :
933
                begin
934
                        r_conf_data_out[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] = wb_ta3[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
935
                        r_conf_data_out[(31-`WB_NUM_OF_DEC_ADDR_LINES):0]  = 0 ;
936
                end
937
                `W_IMG_CTRL4_ADDR: r_conf_data_out = { 29'h00000000, wb_img_ctrl4_bit2_0 } ;
938
                `W_BA4_ADDR              :
939
                begin
940
                        r_conf_data_out[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] = wb_ba4_bit31_12[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] &
941
                                                                                                                                wb_am4[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
942
                        r_conf_data_out[(31-`WB_NUM_OF_DEC_ADDR_LINES):1]  = 0 ;
943
                        r_conf_data_out[0] = wb_ba4_bit0 ;
944
                end
945
                `W_AM4_ADDR              :
946
                begin
947
                        r_conf_data_out[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] = wb_am4[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
948
                        r_conf_data_out[(31-`WB_NUM_OF_DEC_ADDR_LINES):0]  = 0 ;
949
                end
950
                `W_TA4_ADDR              :
951
                begin
952
                        r_conf_data_out[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] = wb_ta4[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
953
                        r_conf_data_out[(31-`WB_NUM_OF_DEC_ADDR_LINES):0]  = 0 ;
954
                end
955
                `W_IMG_CTRL5_ADDR: r_conf_data_out = { 29'h00000000, wb_img_ctrl5_bit2_0 } ;
956
                `W_BA5_ADDR              :
957
                begin
958
                        r_conf_data_out[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] = wb_ba5_bit31_12[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] &
959
                                                                                                                                wb_am5[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
960
                        r_conf_data_out[(31-`WB_NUM_OF_DEC_ADDR_LINES):1]  = 0 ;
961
                        r_conf_data_out[0] = wb_ba5_bit0 ;
962
                end
963
                `W_AM5_ADDR              :
964
                begin
965
                        r_conf_data_out[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] = wb_am5[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
966
                        r_conf_data_out[(31-`WB_NUM_OF_DEC_ADDR_LINES):0]  = 0 ;
967
                end
968
                `W_TA5_ADDR              :
969
                begin
970
                        r_conf_data_out[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] = wb_ta5[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
971
                        r_conf_data_out[(31-`WB_NUM_OF_DEC_ADDR_LINES):0]  = 0 ;
972
                end
973
                `W_ERR_CS_ADDR   : r_conf_data_out = { wb_err_cs_bit31_24, /*13*/14'h0000, /*wb_err_cs_bit10,*/
974
                                                                                   wb_err_cs_bit9, wb_err_cs_bit8, 7'h00, wb_err_cs_bit0 } ;
975
                `W_ERR_ADDR_ADDR : r_conf_data_out = wb_err_addr ;
976
                `W_ERR_DATA_ADDR : r_conf_data_out = wb_err_data ;
977
 
978
                `CNF_ADDR_ADDR   : r_conf_data_out = { 8'h00, cnf_addr_bit23_2, 1'h0, cnf_addr_bit0 } ;
979
                // `CNF_DATA_ADDR: implemented elsewhere !!!
980
                // `INT_ACK_ADDR : implemented elsewhere !!!
981
            `ICR_ADDR            : r_conf_data_out = { icr_bit31, 26'h0000_000, icr_bit4_3, icr_bit2_0 } ;
982
            `ISR_ADDR            : r_conf_data_out = { 27'h0000_000, isr_bit4_3, isr_bit2_0 } ;
983
 
984
                default : r_conf_data_out = 32'h0000_0000 ;
985
                endcase
986
        end
987
        endcase
988
    end
989
 
990
`endif
991
 
992
always@(w_conf_address_in or
993
                status_bit15_11 or status_bit8 or command_bit8 or command_bit6 or command_bit2_0 or
994
                latency_timer or cache_line_size_reg or
995
                pci_ba0_bit31_12 or
996
                pci_img_ctrl0_bit2_1 or pci_am0 or pci_ta0 or pci_ba0_bit0 or
997
                pci_img_ctrl1_bit2_1 or pci_am1 or pci_ta1 or pci_ba1_bit31_12 or pci_ba1_bit0 or
998
                pci_img_ctrl2_bit2_1 or pci_am2 or pci_ta2 or pci_ba2_bit31_12 or pci_ba2_bit0 or
999
                pci_img_ctrl3_bit2_1 or pci_am3 or pci_ta3 or pci_ba3_bit31_12 or pci_ba3_bit0 or
1000
                pci_img_ctrl4_bit2_1 or pci_am4 or pci_ta4 or pci_ba4_bit31_12 or pci_ba4_bit0 or
1001
                pci_img_ctrl5_bit2_1 or pci_am5 or pci_ta5 or pci_ba5_bit31_12 or pci_ba5_bit0 or
1002
                interrupt_line or
1003
                pci_err_cs_bit31_24 or pci_err_cs_bit10 or pci_err_cs_bit9 or pci_err_cs_bit8 or pci_err_cs_bit0 or
1004
                pci_err_addr or pci_err_data or
1005
                wb_ba0_bit31_12 or wb_ba0_bit0 or
1006
                wb_img_ctrl1_bit2_0 or wb_ba1_bit31_12 or wb_ba1_bit0 or wb_am1 or wb_ta1 or
1007
                wb_img_ctrl2_bit2_0 or wb_ba2_bit31_12 or wb_ba2_bit0 or wb_am2 or wb_ta2 or
1008
                wb_img_ctrl3_bit2_0 or wb_ba3_bit31_12 or wb_ba3_bit0 or wb_am3 or wb_ta3 or
1009
                wb_img_ctrl4_bit2_0 or wb_ba4_bit31_12 or wb_ba4_bit0 or wb_am4 or wb_ta4 or
1010
                wb_img_ctrl5_bit2_0 or wb_ba5_bit31_12 or wb_ba5_bit0 or wb_am5 or wb_ta5 or
1011
                wb_err_cs_bit31_24 or /*wb_err_cs_bit10 or*/ wb_err_cs_bit9 or wb_err_cs_bit8 or wb_err_cs_bit0 or
1012
                wb_err_addr or wb_err_data or
1013
                cnf_addr_bit23_2 or cnf_addr_bit0 or icr_bit31 or icr_bit4_3 or icr_bit2_0 or isr_bit4_3 or isr_bit2_0
1014
                )
1015
begin
1016
        case (w_conf_address_in[8])
1017
        1'b0 :
1018
        begin
1019
          case ({w_conf_address_in[7], w_conf_address_in[6]})
1020
          2'b00 :
1021
          begin
1022
                // PCI header - configuration space
1023
                case (w_conf_address_in[5:2])
1024
                4'h0:
1025
                begin
1026
                        w_conf_data_out = { r_device_id, r_vendor_id } ;
1027
                        w_reg_select_dec = 56'h00_0000_0000_0000 ; // Read-Only register
1028
                end
1029
                4'h1: // w_reg_select_dec bit 0
1030
                begin
1031
                        w_conf_data_out = { status_bit15_11, r_status_bit10_9, status_bit8, r_status_bit7, 1'h0, r_status_bit5,
1032
                                                                 5'h00, 7'h00, command_bit8, 1'h0, command_bit6, 3'h0, command_bit2_0 } ;
1033
                        w_reg_select_dec = 56'h00_0000_0000_0001 ;
1034
                end
1035
                4'h2:
1036
                begin
1037
                        w_conf_data_out = { r_class_code, r_revision_id } ;
1038
                        w_reg_select_dec = 56'h00_0000_0000_0000 ; // Read-Only register
1039
                end
1040
                4'h3: // w_reg_select_dec bit 1
1041
                begin
1042
                        w_conf_data_out = { 8'h00, r_header_type, latency_timer, cache_line_size_reg } ;
1043
                        w_reg_select_dec = 56'h00_0000_0000_0002 ;
1044
                end
1045
                4'h4: // w_reg_select_dec bit 4
1046
                begin
1047
                w_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_ba0_bit31_12[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] &
1048
                                                                                                                         pci_am0[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
1049
                w_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):1] = 0 ;
1050
                w_conf_data_out[0] = pci_ba0_bit0 & pci_am0[31];
1051
                        w_reg_select_dec = 56'h00_0000_0000_0010 ; // The same for another address
1052
                end
1053
                4'h5: // w_reg_select_dec bit 8
1054
                begin
1055
                w_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_ba1_bit31_12[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] &
1056
                                                                                                                         pci_am1[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
1057
                w_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):1] = 0 ;
1058
                w_conf_data_out[0] = pci_ba1_bit0 & pci_am1[31];
1059
                        w_reg_select_dec = 56'h00_0000_0000_0100 ; // The same for another address
1060
                end
1061
                4'h6: // w_reg_select_dec bit 12
1062
                begin
1063
                w_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_ba2_bit31_12[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] &
1064
                                                                                                                         pci_am2[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
1065
                w_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):1] = 0 ;
1066
                w_conf_data_out[0] = pci_ba2_bit0 & pci_am2[31];
1067
                        w_reg_select_dec = 56'h00_0000_0000_1000 ; // The same for another address
1068
                end
1069
                4'h7: // w_reg_select_dec bit 16
1070
                begin
1071
                w_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_ba3_bit31_12[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] &
1072
                                                                                                                         pci_am3[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
1073
                w_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):1] = 0 ;
1074
                w_conf_data_out[0] = pci_ba3_bit0 & pci_am3[31];
1075
                        w_reg_select_dec = 56'h00_0000_0001_0000 ; // The same for another address
1076
                end
1077
                4'h8: // w_reg_select_dec bit 20
1078
                begin
1079
                w_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_ba4_bit31_12[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] &
1080
                                                                                                                         pci_am4[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
1081
                w_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):1] = 0 ;
1082
                w_conf_data_out[0] = pci_ba4_bit0 & pci_am4[31];
1083
                        w_reg_select_dec = 56'h00_0000_0010_0000 ; // The same for another address
1084
                end
1085
                4'h9: // w_reg_select_dec bit 24
1086
                begin
1087
                w_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_ba5_bit31_12[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] &
1088
                                                                                                                         pci_am5[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
1089
                w_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):1] = 0 ;
1090
                w_conf_data_out[0] = pci_ba5_bit0 & pci_am5[31];
1091
                        w_reg_select_dec = 56'h00_0000_0100_0000 ; // The same for another address
1092
                end
1093
                4'hf: // w_reg_select_dec bit 2
1094
                begin
1095
                        w_conf_data_out = { r_max_lat, r_min_gnt, r_interrupt_pin, interrupt_line } ;
1096
                        w_reg_select_dec = 56'h00_0000_0000_0004 ;
1097
                end
1098
                default :
1099
                begin
1100
                        w_conf_data_out = 32'h0000_0000 ;
1101
                        w_reg_select_dec = 56'h00_0000_0000_0000 ;
1102
                end
1103
                endcase
1104
          end
1105
          default :
1106
          begin
1107
            w_conf_data_out = 32'h0000_0000 ;
1108
                w_reg_select_dec = 56'h00_0000_0000_0000 ;
1109
          end
1110
          endcase
1111
        end
1112
        default :
1113
        begin
1114
                // PCI target - configuration space
1115
                case (w_conf_address_in[7:2])
1116
                `P_IMG_CTRL0_ADDR:  // w_reg_select_dec bit 3
1117
                begin
1118
                        w_conf_data_out = { 29'h00000000, pci_img_ctrl0_bit2_1, 1'h0 } ;
1119
                        w_reg_select_dec = 56'h00_0000_0000_0008 ;
1120
                end
1121
        `P_BA0_ADDR:   // w_reg_select_dec bit 4
1122
                begin
1123
                w_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_ba0_bit31_12[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] &
1124
                                                                                                                         pci_am0[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
1125
                w_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):1] = 0 ;
1126
                w_conf_data_out[0] = pci_ba0_bit0 & pci_am0[31];
1127
                        w_reg_select_dec = 56'h00_0000_0000_0010 ; // The same for another address
1128
                end
1129
        `P_AM0_ADDR:   // w_reg_select_dec bit 5
1130
                begin
1131
            w_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_am0[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
1132
                w_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
1133
                        w_reg_select_dec = 56'h00_0000_0000_0020 ;
1134
                end
1135
        `P_TA0_ADDR:   // w_reg_select_dec bit 6
1136
                begin
1137
            w_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_ta0[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
1138
                w_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
1139
                        w_reg_select_dec = 56'h00_0000_0000_0040 ;
1140
                end
1141
        `P_IMG_CTRL1_ADDR:   // w_reg_select_dec bit 7
1142
                begin
1143
                        w_conf_data_out = { 29'h00000000, pci_img_ctrl1_bit2_1, 1'h0 } ;
1144
                        w_reg_select_dec = 56'h00_0000_0000_0080 ;
1145
                end
1146
        `P_BA1_ADDR:   // w_reg_select_dec bit 8
1147
                begin
1148
                w_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_ba1_bit31_12[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] &
1149
                                                                                                                         pci_am1[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
1150
                w_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):1] = 0 ;
1151
                w_conf_data_out[0] = pci_ba1_bit0 & pci_am1[31];
1152
                        w_reg_select_dec = 56'h00_0000_0000_0100 ; // The same for another address
1153
                end
1154
        `P_AM1_ADDR:   // w_reg_select_dec bit 9
1155
                begin
1156
            w_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_am1[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
1157
                w_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
1158
                        w_reg_select_dec = 56'h00_0000_0000_0200 ;
1159
                end
1160
        `P_TA1_ADDR:   // w_reg_select_dec bit 10
1161
                begin
1162
            w_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_ta1[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
1163
                w_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
1164
                        w_reg_select_dec = 56'h00_0000_0000_0400 ;
1165
                end
1166
        `P_IMG_CTRL2_ADDR:   // w_reg_select_dec bit 11
1167
                begin
1168
                        w_conf_data_out = { 29'h00000000, pci_img_ctrl2_bit2_1, 1'h0 } ;
1169
                        w_reg_select_dec = 56'h00_0000_0000_0800 ;
1170
                end
1171
        `P_BA2_ADDR:   // w_reg_select_dec bit 12
1172
                begin
1173
                w_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_ba2_bit31_12[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] &
1174
                                                                                                                         pci_am2[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
1175
                w_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):1] = 0 ;
1176
                w_conf_data_out[0] = pci_ba2_bit0 & pci_am2[31];
1177
                        w_reg_select_dec = 56'h00_0000_0000_1000 ; // The same for another address
1178
                end
1179
        `P_AM2_ADDR:   // w_reg_select_dec bit 13
1180
                begin
1181
            w_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_am2[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
1182
                w_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
1183
                        w_reg_select_dec = 56'h00_0000_0000_2000 ;
1184
                end
1185
        `P_TA2_ADDR:   // w_reg_select_dec bit 14
1186
                begin
1187
            w_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_ta2[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
1188
                w_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
1189
                        w_reg_select_dec = 56'h00_0000_0000_4000 ;
1190
                end
1191
        `P_IMG_CTRL3_ADDR:   // w_reg_select_dec bit 15
1192
                begin
1193
                        w_conf_data_out = { 29'h00000000, pci_img_ctrl3_bit2_1, 1'h0 } ;
1194
                        w_reg_select_dec = 56'h00_0000_0000_8000 ;
1195
                end
1196
        `P_BA3_ADDR:   // w_reg_select_dec bit 16
1197
                begin
1198
                w_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_ba3_bit31_12[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] &
1199
                                                                                                                         pci_am3[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
1200
                w_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):1] = 0 ;
1201
                w_conf_data_out[0] = pci_ba3_bit0 & pci_am3[31];
1202
                        w_reg_select_dec = 56'h00_0000_0001_0000 ; // The same for another address
1203
                end
1204
        `P_AM3_ADDR:   // w_reg_select_dec bit 17
1205
                begin
1206
            w_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_am3[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
1207
                w_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
1208
                        w_reg_select_dec = 56'h00_0000_0002_0000 ;
1209
                end
1210
        `P_TA3_ADDR:   // w_reg_select_dec bit 18
1211
                begin
1212
            w_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_ta3[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
1213
                w_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
1214
                        w_reg_select_dec = 56'h00_0000_0004_0000 ;
1215
                end
1216
        `P_IMG_CTRL4_ADDR:   // w_reg_select_dec bit 19
1217
                begin
1218
                        w_conf_data_out = { 29'h00000000, pci_img_ctrl4_bit2_1, 1'h0 } ;
1219
                        w_reg_select_dec = 56'h00_0000_0008_0000 ;
1220
                end
1221
        `P_BA4_ADDR:   // w_reg_select_dec bit 20
1222
                begin
1223
                w_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_ba4_bit31_12[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] &
1224
                                                                                                                         pci_am4[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
1225
                w_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):1] = 0 ;
1226
                w_conf_data_out[0] = pci_ba4_bit0 & pci_am4[31];
1227
                        w_reg_select_dec = 56'h00_0000_0010_0000 ; // The same for another address
1228
                end
1229
        `P_AM4_ADDR:   // w_reg_select_dec bit 21
1230
                begin
1231
            w_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_am4[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
1232
                w_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
1233
                        w_reg_select_dec = 56'h00_0000_0020_0000 ;
1234
                end
1235
        `P_TA4_ADDR:   // w_reg_select_dec bit 22
1236
                begin
1237
            w_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_ta4[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
1238
                w_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
1239
                        w_reg_select_dec = 56'h00_0000_0040_0000 ;
1240
                end
1241
        `P_IMG_CTRL5_ADDR:   // w_reg_select_dec bit 23
1242
                begin
1243
                        w_conf_data_out = { 29'h00000000, pci_img_ctrl5_bit2_1, 1'h0 } ;
1244
                        w_reg_select_dec = 56'h00_0000_0080_0000 ;
1245
                end
1246
        `P_BA5_ADDR:   // w_reg_select_dec bit 24
1247
                begin
1248
                w_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_ba5_bit31_12[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] &
1249
                                                                                                                         pci_am5[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
1250
                w_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):1] = 0 ;
1251
                w_conf_data_out[0] = pci_ba5_bit0 & pci_am5[31];
1252
                        w_reg_select_dec = 56'h00_0000_0100_0000 ; // The same for another address
1253
                end
1254
        `P_AM5_ADDR:   // w_reg_select_dec bit 25
1255
                begin
1256
            w_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_am5[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
1257
                w_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
1258
                        w_reg_select_dec = 56'h00_0000_0200_0000 ;
1259
                end
1260
        `P_TA5_ADDR:   // w_reg_select_dec bit 26
1261
                begin
1262
            w_conf_data_out[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] = pci_ta5[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
1263
                w_conf_data_out[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
1264
                        w_reg_select_dec = 56'h00_0000_0400_0000 ;
1265
                end
1266
        `P_ERR_CS_ADDR:   // w_reg_select_dec bit 27
1267
                begin
1268
                        w_conf_data_out = { pci_err_cs_bit31_24, 13'h0000, pci_err_cs_bit10, pci_err_cs_bit9,
1269
                                                                                   pci_err_cs_bit8, 7'h00, pci_err_cs_bit0 } ;
1270
                        w_reg_select_dec = 56'h00_0000_0800_0000 ;
1271
                end
1272
        `P_ERR_ADDR_ADDR:   // w_reg_select_dec bit 28
1273
                begin
1274
                        w_conf_data_out = pci_err_addr ;
1275
                        w_reg_select_dec = 56'h00_0000_0000_0000 ; // = 56'h00_0000_1000_0000 ;
1276
                end
1277
        `P_ERR_DATA_ADDR:   // w_reg_select_dec bit 29
1278
                begin
1279
                        w_conf_data_out = pci_err_data ;
1280
                        w_reg_select_dec = 56'h00_0000_0000_0000 ; // = 56'h00_0000_2000_0000 ;
1281
                end
1282
                // WB slave - configuration space
1283
                `WB_CONF_SPC_BAR_ADDR:
1284
                begin
1285
                        w_conf_data_out = { wb_ba0_bit31_12, 11'h000, wb_ba0_bit0 } ;
1286
                        w_reg_select_dec = 56'h00_0000_0000_0000 ; // Read-Only register
1287
                end
1288
                `W_IMG_CTRL1_ADDR:   // w_reg_select_dec bit 30
1289
                begin
1290
                        w_conf_data_out = { 29'h00000000, wb_img_ctrl1_bit2_0 } ;
1291
                        w_reg_select_dec = 56'h00_0000_4000_0000 ;
1292
                end
1293
                `W_BA1_ADDR:   // w_reg_select_dec bit 31
1294
                begin
1295
                w_conf_data_out[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] = wb_ba1_bit31_12[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] &
1296
                                                                                                                        wb_am1[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
1297
                w_conf_data_out[(31-`WB_NUM_OF_DEC_ADDR_LINES):1]  = 0 ;
1298
                w_conf_data_out[0] = wb_ba1_bit0 ;
1299
                        w_reg_select_dec = 56'h00_0000_8000_0000 ;
1300
                end
1301
                `W_AM1_ADDR:   // w_reg_select_dec bit 32
1302
                begin
1303
                w_conf_data_out[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] = wb_am1[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
1304
                w_conf_data_out[(31-`WB_NUM_OF_DEC_ADDR_LINES):0]  = 0 ;
1305
                        w_reg_select_dec = 56'h00_0001_0000_0000 ;
1306
                end
1307
                `W_TA1_ADDR:   // w_reg_select_dec bit 33
1308
                begin
1309
                w_conf_data_out[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] = wb_ta1[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
1310
                w_conf_data_out[(31-`WB_NUM_OF_DEC_ADDR_LINES):0]  = 0 ;
1311
                        w_reg_select_dec = 56'h00_0002_0000_0000 ;
1312
                end
1313
                `W_IMG_CTRL2_ADDR:   // w_reg_select_dec bit 34
1314
                begin
1315
                        w_conf_data_out = { 29'h00000000, wb_img_ctrl2_bit2_0 } ;
1316
                        w_reg_select_dec = 56'h00_0004_0000_0000 ;
1317
                end
1318
                `W_BA2_ADDR:   // w_reg_select_dec bit 35
1319
                begin
1320
                w_conf_data_out[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] = wb_ba2_bit31_12[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] &
1321
                                                                                                                        wb_am2[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
1322
                w_conf_data_out[(31-`WB_NUM_OF_DEC_ADDR_LINES):1]  = 0 ;
1323
                w_conf_data_out[0] = wb_ba2_bit0 ;
1324
                        w_reg_select_dec = 56'h00_0008_0000_0000 ;
1325
                end
1326
                `W_AM2_ADDR:   // w_reg_select_dec bit 36
1327
                begin
1328
                w_conf_data_out[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] = wb_am2[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
1329
                w_conf_data_out[(31-`WB_NUM_OF_DEC_ADDR_LINES):0]  = 0 ;
1330
                        w_reg_select_dec = 56'h00_0010_0000_0000 ;
1331
                end
1332
                `W_TA2_ADDR:   // w_reg_select_dec bit 37
1333
                begin
1334
                w_conf_data_out[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] = wb_ta2[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
1335
                w_conf_data_out[(31-`WB_NUM_OF_DEC_ADDR_LINES):0]  = 0 ;
1336
                        w_reg_select_dec = 56'h00_0020_0000_0000 ;
1337
                end
1338
                `W_IMG_CTRL3_ADDR:   // w_reg_select_dec bit 38
1339
                begin
1340
                        w_conf_data_out = { 29'h00000000, wb_img_ctrl3_bit2_0 } ;
1341
                        w_reg_select_dec = 56'h00_0040_0000_0000 ;
1342
                end
1343
                `W_BA3_ADDR:   // w_reg_select_dec bit 39
1344
                begin
1345
                w_conf_data_out[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] = wb_ba3_bit31_12[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] &
1346
                                                                                                                        wb_am3[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
1347
                w_conf_data_out[(31-`WB_NUM_OF_DEC_ADDR_LINES):1]  = 0 ;
1348
                w_conf_data_out[0] = wb_ba3_bit0 ;
1349
                        w_reg_select_dec = 56'h00_0080_0000_0000 ;
1350
                end
1351
                `W_AM3_ADDR:   // w_reg_select_dec bit 40
1352
                begin
1353
                w_conf_data_out[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] = wb_am3[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
1354
                w_conf_data_out[(31-`WB_NUM_OF_DEC_ADDR_LINES):0]  = 0 ;
1355
                        w_reg_select_dec = 56'h00_0100_0000_0000 ;
1356
                end
1357
                `W_TA3_ADDR:   // w_reg_select_dec bit 41
1358
                begin
1359
                w_conf_data_out[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] = wb_ta3[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
1360
                w_conf_data_out[(31-`WB_NUM_OF_DEC_ADDR_LINES):0]  = 0 ;
1361
                        w_reg_select_dec = 56'h00_0200_0000_0000 ;
1362
                end
1363
                `W_IMG_CTRL4_ADDR:   // w_reg_select_dec bit 42
1364
                begin
1365
                        w_conf_data_out = { 29'h00000000, wb_img_ctrl4_bit2_0 } ;
1366
                        w_reg_select_dec = 56'h00_0400_0000_0000 ;
1367
                end
1368
                `W_BA4_ADDR:   // w_reg_select_dec bit 43
1369
                begin
1370
                w_conf_data_out[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] = wb_ba4_bit31_12[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] &
1371
                                                                                                                        wb_am4[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
1372
                w_conf_data_out[(31-`WB_NUM_OF_DEC_ADDR_LINES):1]  = 0 ;
1373
                w_conf_data_out[0] = wb_ba4_bit0 ;
1374
                        w_reg_select_dec = 56'h00_0800_0000_0000 ;
1375
                end
1376
                `W_AM4_ADDR:   // w_reg_select_dec bit 44
1377
                begin
1378
                w_conf_data_out[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] = wb_am4[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
1379
                w_conf_data_out[(31-`WB_NUM_OF_DEC_ADDR_LINES):0]  = 0 ;
1380
                        w_reg_select_dec = 56'h00_1000_0000_0000 ;
1381
                end
1382
                `W_TA4_ADDR:   // w_reg_select_dec bit 45
1383
                begin
1384
                w_conf_data_out[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] = wb_ta4[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
1385
                w_conf_data_out[(31-`WB_NUM_OF_DEC_ADDR_LINES):0]  = 0 ;
1386
                        w_reg_select_dec = 56'h00_2000_0000_0000 ;
1387
                end
1388
                `W_IMG_CTRL5_ADDR:   // w_reg_select_dec bit 46
1389
                begin
1390
                        w_conf_data_out = { 29'h00000000, wb_img_ctrl5_bit2_0 } ;
1391
                        w_reg_select_dec = 56'h00_4000_0000_0000 ;
1392
                end
1393
                `W_BA5_ADDR:   // w_reg_select_dec bit 47
1394
                begin
1395
                w_conf_data_out[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] = wb_ba5_bit31_12[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] &
1396
                                                                                                                        wb_am5[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
1397
                w_conf_data_out[(31-`WB_NUM_OF_DEC_ADDR_LINES):1]  = 0 ;
1398
                w_conf_data_out[0] = wb_ba5_bit0 ;
1399
                        w_reg_select_dec = 56'h00_8000_0000_0000 ;
1400
                end
1401
                `W_AM5_ADDR:   // w_reg_select_dec bit 48
1402
                begin
1403
                w_conf_data_out[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] = wb_am5[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
1404
                w_conf_data_out[(31-`WB_NUM_OF_DEC_ADDR_LINES):0]  = 0 ;
1405
                        w_reg_select_dec = 56'h01_0000_0000_0000 ;
1406
                end
1407
                `W_TA5_ADDR:   // w_reg_select_dec bit 49
1408
                begin
1409
                w_conf_data_out[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] = wb_ta5[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
1410
                w_conf_data_out[(31-`WB_NUM_OF_DEC_ADDR_LINES):0]  = 0 ;
1411
                        w_reg_select_dec = 56'h02_0000_0000_0000 ;
1412
                end
1413
                `W_ERR_CS_ADDR:   // w_reg_select_dec bit 50
1414
                begin
1415
                        w_conf_data_out = { wb_err_cs_bit31_24, /*13*/14'h0000, /*wb_err_cs_bit10,*/
1416
                                                                                   wb_err_cs_bit9, wb_err_cs_bit8, 7'h00, wb_err_cs_bit0 } ;
1417
                        w_reg_select_dec = 56'h04_0000_0000_0000 ;
1418
                end
1419
                `W_ERR_ADDR_ADDR:   // w_reg_select_dec bit 51
1420
                begin
1421
                        w_conf_data_out = wb_err_addr ;
1422
                        w_reg_select_dec = 56'h08_0000_0000_0000 ;
1423
                end
1424
                `W_ERR_DATA_ADDR:   // w_reg_select_dec bit 52
1425
                begin
1426
                        w_conf_data_out = wb_err_data ;
1427
                        w_reg_select_dec = 56'h10_0000_0000_0000 ;
1428
                end
1429
                `CNF_ADDR_ADDR:   // w_reg_select_dec bit 53
1430
                begin
1431
                        w_conf_data_out = { 8'h00, cnf_addr_bit23_2, 1'h0, cnf_addr_bit0 } ;
1432
                        w_reg_select_dec = 56'h20_0000_0000_0000 ;
1433
                end
1434
                // `CNF_DATA_ADDR: implemented elsewhere !!!
1435
                // `INT_ACK_ADDR: implemented elsewhere !!!
1436
        `ICR_ADDR:   // w_reg_select_dec bit 54
1437
                begin
1438
                        w_conf_data_out = { icr_bit31, 26'h0000_000, icr_bit4_3, icr_bit2_0 } ;
1439
                        w_reg_select_dec = 56'h40_0000_0000_0000 ;
1440
                end
1441
        `ISR_ADDR:   // w_reg_select_dec bit 55
1442
                begin
1443
                        w_conf_data_out = { 27'h0000_000, isr_bit4_3, isr_bit2_0 } ;
1444
                        w_reg_select_dec = 56'h80_0000_0000_0000 ;
1445
                end
1446
                default:
1447
                begin
1448
                        w_conf_data_out = 32'h0000_0000 ;
1449
                        w_reg_select_dec = 56'h00_0000_0000_0000 ;
1450
                end
1451
                endcase
1452
        end
1453
        endcase
1454
end
1455
 
1456
// Reduced write data for BASE, MASK and TRANSLATION registers of PCI and WB images
1457
assign  w_conf_pdata_reduced[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)]        = w_conf_data_in[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
1458
assign  w_conf_pdata_reduced[(31-`PCI_NUM_OF_DEC_ADDR_LINES): 0] = 0 ;
1459
assign  w_conf_wdata_reduced[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] = w_conf_data_in[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
1460
assign  w_conf_wdata_reduced[(31-`WB_NUM_OF_DEC_ADDR_LINES): 0]  = 0 ;
1461
 
1462
always@(posedge w_clock or posedge reset)
1463
begin
1464
        // Here are implemented all registers that are reset with RESET signal otherwise they can be normaly written!!!
1465
        // Registers that are commented are implemented after this alwasy statement, because they are e.g. reset with
1466
        //   RESET signal, set with some status signal and they are erased with writting '1' into them !!!
1467
        if (reset)
1468
        begin
1469
                /*status_bit15_11 ; status_bit8 ;*/ command_bit8 <= 1'h0 ; command_bit6 <= 1'h0 ; command_bit2_0 <= 3'h0 ;
1470
                latency_timer <= 8'h00 ; cache_line_size_reg <= 8'h00 ;
1471
                // ALL pci_base address registers are the same as pci_baX registers !
1472
                interrupt_line <= 8'h00 ;
1473
 
1474
                `ifdef          HOST
1475
                  `ifdef        NO_CNF_IMAGE    // if PCI bridge is HOST and IMAGE0 is assigned as general image space
1476
                        `ifdef  PCI_IMAGE0
1477
                                        pci_img_ctrl0_bit2_1 <= 2'h0 ;
1478
                                        pci_ba0_bit31_12 <= 20'h0000_0 ;
1479
                                        pci_ba0_bit0 <= `PCI_BA0_MEM_IO ;
1480
                                        pci_am0 <= `PCI_AM0 ;
1481
                                        pci_ta0 <= 20'h0000_0 ;
1482
                        `endif
1483
                  `else
1484
                                        pci_ba0_bit31_12 <= 20'h0000_0 ;
1485
                  `endif
1486
                `else // GUEST
1487
                                        pci_ba0_bit31_12 <= 20'h0000_0 ;
1488
                `endif
1489
 
1490
                pci_img_ctrl1_bit2_1 <= 2'h0 ;
1491
                pci_ba1_bit31_12 <= 20'h0000_0 ;
1492
        `ifdef  HOST
1493
                pci_ba1_bit0 <= `PCI_BA1_MEM_IO ;
1494
        `endif
1495
                pci_am1 <= `PCI_AM1;
1496
                pci_ta1 <= 20'h0000_0 ;
1497
                `ifdef  PCI_IMAGE2
1498
                                pci_img_ctrl2_bit2_1 <= 2'h0 ;
1499
                                        pci_ba2_bit31_12 <= 20'h0000_0 ;
1500
                        `ifdef  HOST
1501
                                        pci_ba2_bit0 <= `PCI_BA2_MEM_IO ;
1502
                        `endif
1503
                                        pci_am2 <= `PCI_AM2;
1504
                                        pci_ta2 <= 20'h0000_0 ;
1505
                `endif
1506
                `ifdef  PCI_IMAGE3
1507
                                        pci_img_ctrl3_bit2_1 <= 2'h0 ;
1508
                                pci_ba3_bit31_12 <= 20'h0000_0 ;
1509
                `ifdef  HOST
1510
                                pci_ba3_bit0 <= `PCI_BA3_MEM_IO ;
1511
                `endif
1512
                                pci_am3 <= `PCI_AM3;
1513
                                        pci_ta3 <= 20'h0000_0 ;
1514
                `endif
1515
                `ifdef  PCI_IMAGE4
1516
                                        pci_img_ctrl4_bit2_1 <= 2'h0 ;
1517
                                        pci_ba4_bit31_12 <= 20'h0000_0 ;
1518
                        `ifdef  HOST
1519
                                        pci_ba4_bit0 <= `PCI_BA4_MEM_IO ;
1520
                        `endif
1521
                                        pci_am4 <= `PCI_AM4;
1522
                                        pci_ta4 <= 20'h0000_0 ;
1523
                `endif
1524
                `ifdef  PCI_IMAGE5
1525
                                        pci_img_ctrl5_bit2_1 <= 2'h0 ;
1526
                                        pci_ba5_bit31_12 <= 20'h0000_0 ;
1527
                        `ifdef  HOST
1528
                                        pci_ba5_bit0 <= `PCI_BA5_MEM_IO ;
1529
                        `endif
1530
                                        pci_am5 <= `PCI_AM5;
1531
                                        pci_ta5 <= 20'h0000_0 ;
1532
                `endif
1533
                /*pci_err_cs_bit31_24 ; pci_err_cs_bit10; pci_err_cs_bit9 ; pci_err_cs_bit8 ;*/ pci_err_cs_bit0 <= 1'h0 ;
1534
                /*pci_err_addr ;*/
1535
        /*pci_err_data ;*/
1536
                //
1537
                wb_img_ctrl1_bit2_0 <= 3'h0 ;
1538
                wb_ba1_bit31_12 <= 20'h0000_0 ; wb_ba1_bit0 <= 1'h0 ;
1539
                wb_am1 <= 20'h0000_0 ;
1540
                wb_ta1 <= 20'h0000_0 ;
1541
        `ifdef  WB_IMAGE2
1542
                                        wb_img_ctrl2_bit2_0 <= 3'h0 ;
1543
                                        wb_ba2_bit31_12 <= 20'h0000_0 ; wb_ba2_bit0 <= 1'h0 ;
1544
                                        wb_am2 <= 20'h0000_0 ;
1545
                                        wb_ta2 <= 20'h0000_0 ;
1546
                `endif
1547
                `ifdef  WB_IMAGE3
1548
                                        wb_img_ctrl3_bit2_0 <= 3'h0 ;
1549
                                        wb_ba3_bit31_12 <= 20'h0000_0 ; wb_ba3_bit0 <= 1'h0 ;
1550
                                        wb_am3 <= 20'h0000_0 ;
1551
                                        wb_ta3 <= 20'h0000_0 ;
1552
                `endif
1553
                `ifdef  WB_IMAGE4
1554
                                        wb_img_ctrl4_bit2_0 <= 3'h0 ;
1555
                                        wb_ba4_bit31_12 <= 20'h0000_0 ; wb_ba4_bit0 <= 1'h0 ;
1556
                                        wb_am4 <= 20'h0000_0 ;
1557
                                        wb_ta4 <= 20'h0000_0 ;
1558
                `endif
1559
                `ifdef  WB_IMAGE5
1560
                                        wb_img_ctrl5_bit2_0 <= 3'h0 ;
1561
                                wb_ba5_bit31_12 <= 20'h0000_0 ; wb_ba5_bit0 <= 1'h0 ;
1562
                                        wb_am5 <= 20'h0000_0 ;
1563
                                        wb_ta5 <= 20'h0000_0 ;
1564
                `endif
1565
                /*wb_err_cs_bit31_24 ; wb_err_cs_bit10 ; wb_err_cs_bit9 ; wb_err_cs_bit8 ;*/ wb_err_cs_bit0 <= 1'h0 ;
1566
                /*wb_err_addr ;*/
1567
                /*wb_err_data ;*/
1568
 
1569
                `ifdef          HOST
1570
                cnf_addr_bit23_2 <= 22'h0000_00 ; cnf_addr_bit0 <= 1'h0 ;
1571
                `endif
1572
 
1573
                icr_bit31 <= 1'h0 ;
1574
                `ifdef  HOST
1575
                        icr_bit2_0 <= 3'h0 ;
1576
                        icr_bit4_3 <= 2'h0 ;
1577
                `else
1578
                        icr_bit2_0[2:0] <= 3'h0 ;
1579
                `endif
1580
                /*isr_bit4_3 ; isr_bit2_0 ;*/
1581
        end
1582
/* -----------------------------------------------------------------------------------------------------------
1583
Following register bits should have asynchronous RESET & SET! That is why they are IMPLEMENTED separately
1584
after this ALWAYS block!!! (for every register bit, there are two D-FF implemented)
1585
                status_bit15_11[15] <= 1'b1 ;
1586
                status_bit15_11[14] <= 1'b1 ;
1587
                status_bit15_11[13] <= 1'b1 ;
1588
                status_bit15_11[12] <= 1'b1 ;
1589
                status_bit15_11[11] <= 1'b1 ;
1590
                status_bit8 <= 1'b1 ;
1591
                pci_err_cs_bit10 <= 1'b1 ;
1592
                pci_err_cs_bit9 <= 1'b1 ;
1593
                pci_err_cs_bit8 <= 1'b1 ;
1594
                pci_err_cs_bit31_24 <= { pci_error_be, pci_error_bc } ;
1595
                pci_err_addr <= pci_error_addr ;
1596
                pci_err_data <= pci_error_data ;
1597
                wb_err_cs_bit10 <= 1'b1 ;
1598
                wb_err_cs_bit9 <= 1'b1 ;
1599
                wb_err_cs_bit8 <= 1'b1 ;
1600
                wb_err_cs_bit31_24 <= { wb_error_be, wb_error_bc } ;
1601
                wb_err_addr <= wb_error_addr ;
1602
                wb_err_data <= wb_error_data ;
1603
                isr_bit4_0[4] <= 1'b1 & icr_bit4_0[4] ;
1604
                isr_bit4_0[3] <= 1'b1 & icr_bit4_0[3] ;
1605
                isr_bit4_0[2] <= 1'b1 & icr_bit4_0[2] ;
1606
                isr_bit4_0[1] <= 1'b1 & icr_bit4_0[1] ;
1607
                isr_bit4_0[0] <= 1'b1 & icr_bit4_0[0] ;
1608
-----------------------------------------------------------------------------------------------------------*/
1609
        // Here follows normal writting to registers (only to their valid bits) !
1610
        else
1611
        begin
1612
                if (w_we)
1613
                begin
1614
                                // PCI header - configuration space
1615
                                if (w_reg_select_dec[0]) // w_conf_address_in[5:2] = 4'h1:
1616
                                begin
1617
                                        if (~w_byte_en[1])
1618
                                                command_bit8 <= w_conf_data_in[8] ;
1619
                                        if (~w_byte_en[0])
1620
                                        begin
1621
                                                command_bit6 <= w_conf_data_in[6] ;
1622
                                                command_bit2_0 <= w_conf_data_in[2:0] ;
1623
                                        end
1624
                                end
1625
                                if (w_reg_select_dec[1]) // w_conf_address_in[5:2] = 4'h3:
1626
                                begin
1627
                                        if (~w_byte_en[1])
1628
                                                latency_timer <= w_conf_data_in[15:8] ;
1629
                                        if (~w_byte_en[0])
1630
                                                cache_line_size_reg <= w_conf_data_in[7:0] ;
1631
                                end
1632
//                  if (w_reg_select_dec[4]) // w_conf_address_in[5:2] = 4'h4:
1633
//                              Also used with IMAGE0
1634
 
1635
//                  if (w_reg_select_dec[8]) // w_conf_address_in[5:2] = 4'h5:
1636
//                              Also used with IMAGE1
1637
 
1638
//                  if (w_reg_select_dec[12]) // w_conf_address_in[5:2] = 4'h6:
1639
//                              Also used with IMAGE2
1640
 
1641
//                  if (w_reg_select_dec[16]) // w_conf_address_in[5:2] = 4'h7:
1642
//                              Also used with IMAGE3
1643
 
1644
//                  if (w_reg_select_dec[20]) // w_conf_address_in[5:2] = 4'h8:
1645
//                              Also used with IMAGE4
1646
 
1647
//                  if (w_reg_select_dec[24]) // w_conf_address_in[5:2] = 4'h9:
1648
//                              Also used with IMAGE5 and IMAGE6
1649
                                if (w_reg_select_dec[2]) // w_conf_address_in[5:2] = 4'hf:
1650
                                begin
1651
                                        if (~w_byte_en[0])
1652
                                                interrupt_line <= w_conf_data_in[7:0] ;
1653
                                end
1654
                                // PCI target - configuration space
1655
`ifdef          HOST
1656
  `ifdef        NO_CNF_IMAGE
1657
        `ifdef  PCI_IMAGE0      // if PCI bridge is HOST and IMAGE0 is assigned as general image space
1658
                                if (w_reg_select_dec[3]) // case (w_conf_address_in[7:2]) = `P_IMG_CTRL0_ADDR:
1659
                                begin
1660
                                        if (~w_byte_en[0])
1661
                                                pci_img_ctrl0_bit2_1 <= w_conf_data_in[2:1] ;
1662
                                end
1663
                    if (w_reg_select_dec[4]) // case (w_conf_address_in[7:2]) = `P_BA0_ADDR:
1664
                                begin
1665
                                        if (~w_byte_en[3])
1666
                                                pci_ba0_bit31_12[31:24] <= w_conf_pdata_reduced[31:24] ;
1667
                                        if (~w_byte_en[2])
1668
                                                pci_ba0_bit31_12[23:16] <= w_conf_pdata_reduced[23:16] ;
1669
                                        if (~w_byte_en[1])
1670
                                                pci_ba0_bit31_12[15:12] <= w_conf_pdata_reduced[15:12] ;
1671
                                        if (~w_byte_en[0])
1672
                                                pci_ba0_bit0 <= w_conf_data_in[0] ;
1673
                                end
1674
                    if (w_reg_select_dec[5]) // case (w_conf_address_in[7:2]) = `P_AM0_ADDR:
1675
                                begin
1676
                                        if (~w_byte_en[3])
1677
                                                pci_am0[31:24] <= w_conf_pdata_reduced[31:24] ;
1678
                                        if (~w_byte_en[2])
1679
                                                pci_am0[23:16] <= w_conf_pdata_reduced[23:16] ;
1680
                                        if (~w_byte_en[1])
1681
                                                pci_am0[15:12] <= w_conf_pdata_reduced[15:12] ;
1682
                                end
1683
                    if (w_reg_select_dec[6]) // case (w_conf_address_in[7:2]) = `P_TA0_ADDR:
1684
                                begin
1685
                                        if (~w_byte_en[3])
1686
                                                pci_ta0[31:24] <= w_conf_pdata_reduced[31:24] ;
1687
                                        if (~w_byte_en[2])
1688
                                                pci_ta0[23:16] <= w_conf_pdata_reduced[23:16] ;
1689
                                        if (~w_byte_en[1])
1690
                                                pci_ta0[15:12] <= w_conf_pdata_reduced[15:12] ;
1691
                                end
1692
        `endif
1693
  `else
1694
                    if (w_reg_select_dec[4]) // case (w_conf_address_in[7:2]) = `P_BA0_ADDR:
1695
                                begin
1696
                                        if (~w_byte_en[3])
1697
                                                pci_ba0_bit31_12[31:24] <= w_conf_pdata_reduced[31:24] ;
1698
                                        if (~w_byte_en[2])
1699
                                                pci_ba0_bit31_12[23:16] <= w_conf_pdata_reduced[23:16] ;
1700
                                        if (~w_byte_en[1])
1701
                                                pci_ba0_bit31_12[15:12] <= w_conf_pdata_reduced[15:12] ;
1702
                                end
1703
  `endif
1704
`else // GUEST
1705
                    if (w_reg_select_dec[4]) // case (w_conf_address_in[7:2]) = `P_BA0_ADDR:
1706
                                begin
1707
                                        if (~w_byte_en[3])
1708
                                                pci_ba0_bit31_12[31:24] <= w_conf_pdata_reduced[31:24] ;
1709
                                        if (~w_byte_en[2])
1710
                                                pci_ba0_bit31_12[23:16] <= w_conf_pdata_reduced[23:16] ;
1711
                                        if (~w_byte_en[1])
1712
                                                pci_ba0_bit31_12[15:12] <= w_conf_pdata_reduced[15:12] ;
1713
                                end
1714
`endif
1715
                    if (w_reg_select_dec[7]) // case (w_conf_address_in[7:2]) = `P_IMG_CTRL1_ADDR:
1716
                                begin
1717
                                        if (~w_byte_en[0])
1718
                                                pci_img_ctrl1_bit2_1 <= w_conf_data_in[2:1] ;
1719
                                end
1720
                    if (w_reg_select_dec[8]) // case (w_conf_address_in[7:2]) = `P_BA1_ADDR:
1721
                                begin
1722
                                        if (~w_byte_en[3])
1723
                                                pci_ba1_bit31_12[31:24] <= w_conf_pdata_reduced[31:24] ;
1724
                                        if (~w_byte_en[2])
1725
                                                pci_ba1_bit31_12[23:16] <= w_conf_pdata_reduced[23:16] ;
1726
                                        if (~w_byte_en[1])
1727
                                                pci_ba1_bit31_12[15:12] <= w_conf_pdata_reduced[15:12] ;
1728
        `ifdef  HOST
1729
                                        if (~w_byte_en[0])
1730
                                                pci_ba1_bit0 <= w_conf_data_in[0] ;
1731
        `endif
1732
                                end
1733
                    if (w_reg_select_dec[9]) // case (w_conf_address_in[7:2]) = `P_AM1_ADDR:
1734
                                begin
1735
                                        if (~w_byte_en[3])
1736
                                                pci_am1[31:24] <= w_conf_pdata_reduced[31:24] ;
1737
                                        if (~w_byte_en[2])
1738
                                                pci_am1[23:16] <= w_conf_pdata_reduced[23:16] ;
1739
                                        if (~w_byte_en[1])
1740
                                                pci_am1[15:12] <= w_conf_pdata_reduced[15:12] ;
1741
                                end
1742
                    if (w_reg_select_dec[10]) // case (w_conf_address_in[7:2]) = `P_TA1_ADDR:
1743
                                begin
1744
                                        if (~w_byte_en[3])
1745
                                                pci_ta1[31:24] <= w_conf_pdata_reduced[31:24] ;
1746
                                        if (~w_byte_en[2])
1747
                                                pci_ta1[23:16] <= w_conf_pdata_reduced[23:16] ;
1748
                                        if (~w_byte_en[1])
1749
                                                pci_ta1[15:12] <= w_conf_pdata_reduced[15:12] ;
1750
                                end
1751
`ifdef          PCI_IMAGE2
1752
                    if (w_reg_select_dec[11]) // case (w_conf_address_in[7:2]) = `P_IMG_CTRL2_ADDR:
1753
                                begin
1754
                                        if (~w_byte_en[0])
1755
                                                pci_img_ctrl2_bit2_1 <= w_conf_data_in[2:1] ;
1756
                                end
1757
                    if (w_reg_select_dec[12]) // case (w_conf_address_in[7:2]) = `P_BA2_ADDR:
1758
                                begin
1759
                                        if (~w_byte_en[3])
1760
                                                pci_ba2_bit31_12[31:24] <= w_conf_pdata_reduced[31:24] ;
1761
                                        if (~w_byte_en[2])
1762
                                                pci_ba2_bit31_12[23:16] <= w_conf_pdata_reduced[23:16] ;
1763
                                        if (~w_byte_en[1])
1764
                                                pci_ba2_bit31_12[15:12] <= w_conf_pdata_reduced[15:12] ;
1765
        `ifdef  HOST
1766
                                        if (~w_byte_en[0])
1767
                                                pci_ba2_bit0 <= w_conf_data_in[0] ;
1768
        `endif
1769
                                end
1770
                    if (w_reg_select_dec[13]) // case (w_conf_address_in[7:2]) = `P_AM2_ADDR:
1771
                                begin
1772
                                        if (~w_byte_en[3])
1773
                                                pci_am2[31:24] <= w_conf_pdata_reduced[31:24] ;
1774
                                        if (~w_byte_en[2])
1775
                                                pci_am2[23:16] <= w_conf_pdata_reduced[23:16] ;
1776
                                        if (~w_byte_en[1])
1777
                                                pci_am2[15:12] <= w_conf_pdata_reduced[15:12] ;
1778
                                end
1779
                    if (w_reg_select_dec[14]) // case (w_conf_address_in[7:2]) = `P_TA2_ADDR:
1780
                                begin
1781
                                        if (~w_byte_en[3])
1782
                                                pci_ta2[31:24] <= w_conf_pdata_reduced[31:24] ;
1783
                                        if (~w_byte_en[2])
1784
                                                pci_ta2[23:16] <= w_conf_pdata_reduced[23:16] ;
1785
                                        if (~w_byte_en[1])
1786
                                                pci_ta2[15:12] <= w_conf_pdata_reduced[15:12] ;
1787
                                end
1788
`endif
1789
`ifdef          PCI_IMAGE3
1790
                    if (w_reg_select_dec[15]) // case (w_conf_address_in[7:2]) = `P_IMG_CTRL3_ADDR:
1791
                                begin
1792
                                        if (~w_byte_en[0])
1793
                                                pci_img_ctrl3_bit2_1 <= w_conf_data_in[2:1] ;
1794
                                end
1795
                    if (w_reg_select_dec[16]) // case (w_conf_address_in[7:2]) = `P_BA3_ADDR:
1796
                                begin
1797
                                        if (~w_byte_en[3])
1798
                                                pci_ba3_bit31_12[31:24] <= w_conf_pdata_reduced[31:24] ;
1799
                                        if (~w_byte_en[2])
1800
                                                pci_ba3_bit31_12[23:16] <= w_conf_pdata_reduced[23:16] ;
1801
                                        if (~w_byte_en[1])
1802
                                                pci_ba3_bit31_12[15:12] <= w_conf_pdata_reduced[15:12] ;
1803
        `ifdef  HOST
1804
                                        if (~w_byte_en[0])
1805
                                                pci_ba3_bit0 <= w_conf_data_in[0] ;
1806
        `endif
1807
                                end
1808
                    if (w_reg_select_dec[17]) // case (w_conf_address_in[7:2]) = `P_AM3_ADDR:
1809
                                begin
1810
                                        if (~w_byte_en[3])
1811
                                                pci_am3[31:24] <= w_conf_pdata_reduced[31:24] ;
1812
                                        if (~w_byte_en[2])
1813
                                                pci_am3[23:16] <= w_conf_pdata_reduced[23:16] ;
1814
                                        if (~w_byte_en[1])
1815
                                                pci_am3[15:12] <= w_conf_pdata_reduced[15:12] ;
1816
                                end
1817
                    if (w_reg_select_dec[18]) // case (w_conf_address_in[7:2]) = `P_TA3_ADDR:
1818
                                begin
1819
                                        if (~w_byte_en[3])
1820
                                                pci_ta3[31:24] <= w_conf_pdata_reduced[31:24] ;
1821
                                        if (~w_byte_en[2])
1822
                                                pci_ta3[23:16] <= w_conf_pdata_reduced[23:16] ;
1823
                                        if (~w_byte_en[1])
1824
                                                pci_ta3[15:12] <= w_conf_pdata_reduced[15:12] ;
1825
                                end
1826
`endif
1827
`ifdef          PCI_IMAGE4
1828
                    if (w_reg_select_dec[19]) // case (w_conf_address_in[7:2]) = `P_IMG_CTRL4_ADDR:
1829
                                begin
1830
                                        if (~w_byte_en[0])
1831
                                                pci_img_ctrl4_bit2_1 <= w_conf_data_in[2:1] ;
1832
                                end
1833
                    if (w_reg_select_dec[20]) // case (w_conf_address_in[7:2]) = `P_BA4_ADDR:
1834
                                begin
1835
                                        if (~w_byte_en[3])
1836
                                                pci_ba4_bit31_12[31:24] <= w_conf_pdata_reduced[31:24] ;
1837
                                        if (~w_byte_en[2])
1838
                                                pci_ba4_bit31_12[23:16] <= w_conf_pdata_reduced[23:16] ;
1839
                                        if (~w_byte_en[1])
1840
                                                pci_ba4_bit31_12[15:12] <= w_conf_pdata_reduced[15:12] ;
1841
        `ifdef  HOST
1842
                                        if (~w_byte_en[0])
1843
                                                pci_ba4_bit0 <= w_conf_data_in[0] ;
1844
        `endif
1845
                                end
1846
                    if (w_reg_select_dec[21]) // case (w_conf_address_in[7:2]) = `P_AM4_ADDR:
1847
                                begin
1848
                                        if (~w_byte_en[3])
1849
                                                pci_am4[31:24] <= w_conf_pdata_reduced[31:24] ;
1850
                                        if (~w_byte_en[2])
1851
                                                pci_am4[23:16] <= w_conf_pdata_reduced[23:16] ;
1852
                                        if (~w_byte_en[1])
1853
                                                pci_am4[15:12] <= w_conf_pdata_reduced[15:12] ;
1854
                                end
1855
                    if (w_reg_select_dec[22]) // case (w_conf_address_in[7:2]) = `P_TA4_ADDR:
1856
                                begin
1857
                                        if (~w_byte_en[3])
1858
                                                pci_ta4[31:24] <= w_conf_pdata_reduced[31:24] ;
1859
                                        if (~w_byte_en[2])
1860
                                                pci_ta4[23:16] <= w_conf_pdata_reduced[23:16] ;
1861
                                        if (~w_byte_en[1])
1862
                                                pci_ta4[15:12] <= w_conf_pdata_reduced[15:12] ;
1863
                                end
1864
`endif
1865
`ifdef          PCI_IMAGE5
1866
                    if (w_reg_select_dec[23]) // case (w_conf_address_in[7:2]) = `P_IMG_CTRL5_ADDR:
1867
                                begin
1868
                                        if (~w_byte_en[0])
1869
                                                pci_img_ctrl5_bit2_1 <= w_conf_data_in[2:1] ;
1870
                                end
1871
                    if (w_reg_select_dec[24]) // case (w_conf_address_in[7:2]) = `P_BA5_ADDR:
1872
                                begin
1873
                                        if (~w_byte_en[3])
1874
                                                pci_ba5_bit31_12[31:24] <= w_conf_pdata_reduced[31:24] ;
1875
                                        if (~w_byte_en[2])
1876
                                                pci_ba5_bit31_12[23:16] <= w_conf_pdata_reduced[23:16] ;
1877
                                        if (~w_byte_en[1])
1878
                                                pci_ba5_bit31_12[15:12] <= w_conf_pdata_reduced[15:12] ;
1879
        `ifdef  HOST
1880
                                        if (~w_byte_en[0])
1881
                                                pci_ba5_bit0 <= w_conf_data_in[0] ;
1882
        `endif
1883
                                end
1884
                    if (w_reg_select_dec[25]) // case (w_conf_address_in[7:2]) = `P_AM5_ADDR:
1885
                                begin
1886
                                        if (~w_byte_en[3])
1887
                                                pci_am5[31:24] <= w_conf_pdata_reduced[31:24] ;
1888
                                        if (~w_byte_en[2])
1889
                                                pci_am5[23:16] <= w_conf_pdata_reduced[23:16] ;
1890
                                        if (~w_byte_en[1])
1891
                                                pci_am5[15:12] <= w_conf_pdata_reduced[15:12] ;
1892
                                end
1893
                    if (w_reg_select_dec[26]) // case (w_conf_address_in[7:2]) = `P_TA5_ADDR:
1894
                                begin
1895
                                        if (~w_byte_en[3])
1896
                                                pci_ta5[31:24] <= w_conf_pdata_reduced[31:24] ;
1897
                                        if (~w_byte_en[2])
1898
                                                pci_ta5[23:16] <= w_conf_pdata_reduced[23:16] ;
1899
                                        if (~w_byte_en[1])
1900
                                                pci_ta5[15:12] <= w_conf_pdata_reduced[15:12] ;
1901
                                end
1902
`endif
1903
                    if (w_reg_select_dec[27]) // case (w_conf_address_in[7:2]) = `P_ERR_CS_ADDR:
1904
                                begin
1905
                                        if (~w_byte_en[0])
1906
                                                pci_err_cs_bit0 <= w_conf_data_in[0] ;
1907
                                end
1908
                        // WB slave - configuration space
1909
                                if (w_reg_select_dec[30]) // case (w_conf_address_in[7:2]) = `W_IMG_CTRL1_ADDR:
1910
                                begin
1911
                                        if (~w_byte_en[0])
1912
                                                wb_img_ctrl1_bit2_0 <= w_conf_data_in[2:0] ;
1913
                                end
1914
                                if (w_reg_select_dec[31]) // case (w_conf_address_in[7:2]) = `W_BA1_ADDR:
1915
                                begin
1916
                                        if (~w_byte_en[3])
1917
                                                wb_ba1_bit31_12[31:24] <= w_conf_wdata_reduced[31:24] ;
1918
                                        if (~w_byte_en[2])
1919
                                                wb_ba1_bit31_12[23:16] <= w_conf_wdata_reduced[23:16] ;
1920
                                        if (~w_byte_en[1])
1921
                                                wb_ba1_bit31_12[15:12] <= w_conf_wdata_reduced[15:12] ;
1922
                                        if (~w_byte_en[0])
1923
                                                wb_ba1_bit0 <= w_conf_data_in[0] ;
1924
                                end
1925
                                if (w_reg_select_dec[32]) // case (w_conf_address_in[7:2]) = `W_AM1_ADDR:
1926
                                begin
1927
                                        if (~w_byte_en[3])
1928
                                                wb_am1[31:24] <= w_conf_wdata_reduced[31:24] ;
1929
                                        if (~w_byte_en[2])
1930
                                                wb_am1[23:16] <= w_conf_wdata_reduced[23:16] ;
1931
                                        if (~w_byte_en[1])
1932
                                                wb_am1[15:12] <= w_conf_wdata_reduced[15:12] ;
1933
                                end
1934
                                if (w_reg_select_dec[33]) // case (w_conf_address_in[7:2]) = `W_TA1_ADDR:
1935
                                begin
1936
                                        if (~w_byte_en[3])
1937
                                                wb_ta1[31:24] <= w_conf_wdata_reduced[31:24] ;
1938
                                        if (~w_byte_en[2])
1939
                                                wb_ta1[23:16] <= w_conf_wdata_reduced[23:16] ;
1940
                                        if (~w_byte_en[1])
1941
                                                wb_ta1[15:12] <= w_conf_wdata_reduced[15:12] ;
1942
                                end
1943
`ifdef          WB_IMAGE2
1944
                                if (w_reg_select_dec[34]) // case (w_conf_address_in[7:2]) = `W_IMG_CTRL2_ADDR:
1945
                                begin
1946
                                        if (~w_byte_en[0])
1947
                                                wb_img_ctrl2_bit2_0 <= w_conf_data_in[2:0] ;
1948
                                end
1949
                                if (w_reg_select_dec[35]) // case (w_conf_address_in[7:2]) = `W_BA2_ADDR:
1950
                                begin
1951
                                        if (~w_byte_en[3])
1952
                                                wb_ba2_bit31_12[31:24] <= w_conf_wdata_reduced[31:24] ;
1953
                                        if (~w_byte_en[2])
1954
                                                wb_ba2_bit31_12[23:16] <= w_conf_wdata_reduced[23:16] ;
1955
                                        if (~w_byte_en[1])
1956
                                                wb_ba2_bit31_12[15:12] <= w_conf_wdata_reduced[15:12] ;
1957
                                        if (~w_byte_en[0])
1958
                                                wb_ba2_bit0 <= w_conf_data_in[0] ;
1959
                                end
1960
                                if (w_reg_select_dec[36]) // case (w_conf_address_in[7:2]) = `W_AM2_ADDR:
1961
                                begin
1962
                                        if (~w_byte_en[3])
1963
                                                wb_am2[31:24] <= w_conf_wdata_reduced[31:24] ;
1964
                                        if (~w_byte_en[2])
1965
                                                wb_am2[23:16] <= w_conf_wdata_reduced[23:16] ;
1966
                                        if (~w_byte_en[1])
1967
                                                wb_am2[15:12] <= w_conf_wdata_reduced[15:12] ;
1968
                                end
1969
                                if (w_reg_select_dec[37]) // case (w_conf_address_in[7:2]) = `W_TA2_ADDR:
1970
                                begin
1971
                                        if (~w_byte_en[3])
1972
                                                wb_ta2[31:24] <= w_conf_wdata_reduced[31:24] ;
1973
                                        if (~w_byte_en[2])
1974
                                                wb_ta2[23:16] <= w_conf_wdata_reduced[23:16] ;
1975
                                        if (~w_byte_en[1])
1976
                                                wb_ta2[15:12] <= w_conf_wdata_reduced[15:12] ;
1977
                                end
1978
`endif
1979
`ifdef          WB_IMAGE3
1980
                                if (w_reg_select_dec[38]) // case (w_conf_address_in[7:2]) = `W_IMG_CTRL3_ADDR:
1981
                                begin
1982
                                        if (~w_byte_en[0])
1983
                                                wb_img_ctrl3_bit2_0 <= w_conf_data_in[2:0] ;
1984
                                end
1985
                                if (w_reg_select_dec[39]) // case (w_conf_address_in[7:2]) = `W_BA3_ADDR:
1986
                                begin
1987
                                        if (~w_byte_en[3])
1988
                                                wb_ba3_bit31_12[31:24] <= w_conf_wdata_reduced[31:24] ;
1989
                                        if (~w_byte_en[2])
1990
                                                wb_ba3_bit31_12[23:16] <= w_conf_wdata_reduced[23:16] ;
1991
                                        if (~w_byte_en[1])
1992
                                                wb_ba3_bit31_12[15:12] <= w_conf_wdata_reduced[15:12] ;
1993
                                        if (~w_byte_en[0])
1994
                                                wb_ba3_bit0 <= w_conf_data_in[0] ;
1995
                                end
1996
                                if (w_reg_select_dec[40]) // case (w_conf_address_in[7:2]) = `W_AM3_ADDR:
1997
                                begin
1998
                                        if (~w_byte_en[3])
1999
                                                wb_am3[31:24] <= w_conf_wdata_reduced[31:24] ;
2000
                                        if (~w_byte_en[2])
2001
                                                wb_am3[23:16] <= w_conf_wdata_reduced[23:16] ;
2002
                                        if (~w_byte_en[1])
2003
                                                wb_am3[15:12] <= w_conf_wdata_reduced[15:12] ;
2004
                                end
2005
                                if (w_reg_select_dec[41]) // case (w_conf_address_in[7:2]) = `W_TA3_ADDR:
2006
                                begin
2007
                                        if (~w_byte_en[3])
2008
                                                wb_ta3[31:24] <= w_conf_wdata_reduced[31:24] ;
2009
                                        if (~w_byte_en[2])
2010
                                                wb_ta3[23:16] <= w_conf_wdata_reduced[23:16] ;
2011
                                        if (~w_byte_en[1])
2012
                                                wb_ta3[15:12] <= w_conf_wdata_reduced[15:12] ;
2013
                                end
2014
`endif
2015
`ifdef          WB_IMAGE4
2016
                                if (w_reg_select_dec[42]) // case (w_conf_address_in[7:2]) = `W_IMG_CTRL4_ADDR:
2017
                                begin
2018
                                        if (~w_byte_en[0])
2019
                                                wb_img_ctrl4_bit2_0 <= w_conf_data_in[2:0] ;
2020
                                end
2021
                                if (w_reg_select_dec[43]) // case (w_conf_address_in[7:2]) = `W_BA4_ADDR:
2022
                                begin
2023
                                        if (~w_byte_en[3])
2024
                                                wb_ba4_bit31_12[31:24] <= w_conf_wdata_reduced[31:24] ;
2025
                                        if (~w_byte_en[2])
2026
                                                wb_ba4_bit31_12[23:16] <= w_conf_wdata_reduced[23:16] ;
2027
                                        if (~w_byte_en[1])
2028
                                                wb_ba4_bit31_12[15:12] <= w_conf_wdata_reduced[15:12] ;
2029
                                        if (~w_byte_en[0])
2030
                                                wb_ba4_bit0 <= w_conf_data_in[0] ;
2031
                                end
2032
                                if (w_reg_select_dec[44]) // case (w_conf_address_in[7:2]) = `W_AM4_ADDR:
2033
                                begin
2034
                                        if (~w_byte_en[3])
2035
                                                wb_am4[31:24] <= w_conf_wdata_reduced[31:24] ;
2036
                                        if (~w_byte_en[2])
2037
                                                wb_am4[23:16] <= w_conf_wdata_reduced[23:16] ;
2038
                                        if (~w_byte_en[1])
2039
                                                wb_am4[15:12] <= w_conf_wdata_reduced[15:12] ;
2040
                                end
2041
                                if (w_reg_select_dec[45]) // case (w_conf_address_in[7:2]) = `W_TA4_ADDR:
2042
                                begin
2043
                                        if (~w_byte_en[3])
2044
                                                wb_ta4[31:24] <= w_conf_wdata_reduced[31:24] ;
2045
                                        if (~w_byte_en[2])
2046
                                                wb_ta4[23:16] <= w_conf_wdata_reduced[23:16] ;
2047
                                        if (~w_byte_en[1])
2048
                                                wb_ta4[15:12] <= w_conf_wdata_reduced[15:12] ;
2049
                                end
2050
`endif
2051
`ifdef          WB_IMAGE5
2052
                                if (w_reg_select_dec[46]) // case (w_conf_address_in[7:2]) = `W_IMG_CTRL5_ADDR:
2053
                                begin
2054
                                        if (~w_byte_en[0])
2055
                                                wb_img_ctrl5_bit2_0 <= w_conf_data_in[2:0] ;
2056
                                end
2057
                                if (w_reg_select_dec[47]) // case (w_conf_address_in[7:2]) = `W_BA5_ADDR:
2058
                                begin
2059
                                        if (~w_byte_en[3])
2060
                                                wb_ba5_bit31_12[31:24] <= w_conf_wdata_reduced[31:24] ;
2061
                                        if (~w_byte_en[2])
2062
                                                wb_ba5_bit31_12[23:16] <= w_conf_wdata_reduced[23:16] ;
2063
                                        if (~w_byte_en[1])
2064
                                                wb_ba5_bit31_12[15:12] <= w_conf_wdata_reduced[15:12] ;
2065
                                        if (~w_byte_en[0])
2066
                                                wb_ba5_bit0 <= w_conf_data_in[0] ;
2067
                                end
2068
                                if (w_reg_select_dec[48]) // case (w_conf_address_in[7:2]) = `W_AM5_ADDR:
2069
                                begin
2070
                                        if (~w_byte_en[3])
2071
                                                wb_am5[31:24] <= w_conf_wdata_reduced[31:24] ;
2072
                                        if (~w_byte_en[2])
2073
                                                wb_am5[23:16] <= w_conf_wdata_reduced[23:16] ;
2074
                                        if (~w_byte_en[1])
2075
                                                wb_am5[15:12] <= w_conf_wdata_reduced[15:12] ;
2076
                                end
2077
                                if (w_reg_select_dec[49]) // case (w_conf_address_in[7:2]) = `W_TA5_ADDR:
2078
                                begin
2079
                                        if (~w_byte_en[3])
2080
                                                wb_ta5[31:24] <= w_conf_wdata_reduced[31:24] ;
2081
                                        if (~w_byte_en[2])
2082
                                                wb_ta5[23:16] <= w_conf_wdata_reduced[23:16] ;
2083
                                        if (~w_byte_en[1])
2084
                                                wb_ta5[15:12] <= w_conf_wdata_reduced[15:12] ;
2085
                                end
2086
`endif
2087
                                if (w_reg_select_dec[50]) // case (w_conf_address_in[7:2]) = `W_ERR_CS_ADDR:
2088
                                begin
2089
                                        if (~w_byte_en[0])
2090
                                                wb_err_cs_bit0 <= w_conf_data_in[0] ;
2091
                                end
2092
 
2093
`ifdef  HOST
2094
                                if (w_reg_select_dec[53]) // case (w_conf_address_in[7:2]) = `CNF_ADDR_ADDR:
2095
                                begin
2096
                                        if (~w_byte_en[2])
2097
                                                cnf_addr_bit23_2[23:16] <= w_conf_data_in[23:16] ;
2098
                                        if (~w_byte_en[1])
2099
                                                cnf_addr_bit23_2[15:8] <= w_conf_data_in[15:8] ;
2100
                                        if (~w_byte_en[0])
2101
                                        begin
2102
                                                cnf_addr_bit23_2[7:2] <= w_conf_data_in[7:2] ;
2103
                                                cnf_addr_bit0 <= w_conf_data_in[0] ;
2104
                                        end
2105
                                end
2106
`endif
2107
                                // `CNF_DATA_ADDR: implemented elsewhere !!!
2108
                                // `INT_ACK_ADDR : implemented elsewhere !!!
2109
                    if (w_reg_select_dec[54]) // case (w_conf_address_in[7:2]) = `ICR_ADDR:
2110
                                begin
2111
                                        if (~w_byte_en[3])
2112
                                                icr_bit31 <= w_conf_data_in[31] ;
2113
                                        if (~w_byte_en[0])
2114
`ifdef  HOST
2115
                                                icr_bit4_3 <= w_conf_data_in[4:3] ;
2116
                                                icr_bit2_0 <= w_conf_data_in[2:0] ;
2117
`else
2118
                                                icr_bit2_0[2:0] <= w_conf_data_in[2:0] ;
2119
`endif
2120
                                end
2121
                end
2122
        end
2123
end
2124
 
2125
// This signals are synchronous resets for registers, whic occures when asynchronous RESET is '1' or
2126
// data '1' is synchronously written into them!
2127
reg                     delete_status_bit15 ;
2128
reg                     delete_status_bit14 ;
2129
reg                     delete_status_bit13 ;
2130
reg                     delete_status_bit12 ;
2131
reg                     delete_status_bit11 ;
2132
reg                     delete_status_bit8 ;
2133
reg                     delete_pci_err_cs_bit8 ;
2134
reg                     delete_wb_err_cs_bit8 ;
2135
reg                     delete_isr_bit4 ;
2136
reg                     delete_isr_bit3 ;
2137
reg                     delete_isr_bit2 ;
2138
reg                     delete_isr_bit1 ;
2139
 
2140
// This are aditional register bits, which are resets when their value is '1' !!!
2141
always@(w_we or w_reg_select_dec or w_conf_data_in or w_byte_en)
2142
begin
2143
// If '1' is written into, then it also sets signals to '1'
2144
        case ({w_we, w_reg_select_dec[0], w_reg_select_dec[27], w_reg_select_dec[50], w_reg_select_dec[55]})
2145
        {1'b1, 4'b1000} :
2146
        begin
2147
                delete_status_bit15     <= w_conf_data_in[31] & !w_byte_en[3] ;
2148
                delete_status_bit14     <= w_conf_data_in[30] & !w_byte_en[3] ;
2149
                delete_status_bit13     <= w_conf_data_in[29] & !w_byte_en[3] ;
2150
                delete_status_bit12     <= w_conf_data_in[28] & !w_byte_en[3] ;
2151
                delete_status_bit11     <= w_conf_data_in[27] & !w_byte_en[3] ;
2152
                delete_status_bit8      <= w_conf_data_in[24] & !w_byte_en[3] ;
2153
                delete_pci_err_cs_bit8  <= 1'b0 ;
2154
                delete_wb_err_cs_bit8   <= 1'b0 ;
2155
                delete_isr_bit4                 <= 1'b0 ;
2156
                delete_isr_bit3                 <= 1'b0 ;
2157
                delete_isr_bit2                 <= 1'b0 ;
2158
                delete_isr_bit1                 <= 1'b0 ;
2159
        end
2160
        {1'b1, 4'b0100} :
2161
        begin
2162
                delete_status_bit15     <= 1'b0 ;
2163
                delete_status_bit14     <= 1'b0 ;
2164
                delete_status_bit13     <= 1'b0 ;
2165
                delete_status_bit12     <= 1'b0 ;
2166
                delete_status_bit11     <= 1'b0 ;
2167
                delete_status_bit8      <= 1'b0 ;
2168
                delete_pci_err_cs_bit8  <= w_conf_data_in[8]  & !w_byte_en[1] ;
2169
                delete_wb_err_cs_bit8   <= 1'b0 ;
2170
                delete_isr_bit4                 <= 1'b0 ;
2171
                delete_isr_bit3                 <= 1'b0 ;
2172
                delete_isr_bit2                 <= 1'b0 ;
2173
                delete_isr_bit1                 <= 1'b0 ;
2174
        end
2175
        {1'b1, 4'b0010} :
2176
        begin
2177
                delete_status_bit15     <= 1'b0 ;
2178
                delete_status_bit14     <= 1'b0 ;
2179
                delete_status_bit13     <= 1'b0 ;
2180
                delete_status_bit12     <= 1'b0 ;
2181
                delete_status_bit11     <= 1'b0 ;
2182
                delete_status_bit8      <= 1'b0 ;
2183
                delete_pci_err_cs_bit8  <= 1'b0 ;
2184
                delete_wb_err_cs_bit8   <= w_conf_data_in[8]  & !w_byte_en[1] ;
2185
                delete_isr_bit4                 <= 1'b0 ;
2186
                delete_isr_bit3                 <= 1'b0 ;
2187
                delete_isr_bit2                 <= 1'b0 ;
2188
                delete_isr_bit1                 <= 1'b0 ;
2189
        end
2190
        {1'b1, 4'b0001} :
2191
        begin
2192
                delete_status_bit15     <= 1'b0 ;
2193
                delete_status_bit14     <= 1'b0 ;
2194
                delete_status_bit13     <= 1'b0 ;
2195
                delete_status_bit12     <= 1'b0 ;
2196
                delete_status_bit11     <= 1'b0 ;
2197
                delete_status_bit8      <= 1'b0 ;
2198
                delete_pci_err_cs_bit8  <= 1'b0 ;
2199
                delete_wb_err_cs_bit8   <= 1'b0 ;
2200
                delete_isr_bit4                 <= w_conf_data_in[4] & !w_byte_en[0] ;
2201
                delete_isr_bit3                 <= w_conf_data_in[3] & !w_byte_en[0] ;
2202
                delete_isr_bit2                 <= w_conf_data_in[2] & !w_byte_en[0] ;
2203
                delete_isr_bit1                 <= w_conf_data_in[1] & !w_byte_en[0] ;
2204
        end
2205
        default :
2206
        begin
2207
                delete_status_bit15     <= 1'b0 ;
2208
                delete_status_bit14     <= 1'b0 ;
2209
                delete_status_bit13     <= 1'b0 ;
2210
                delete_status_bit12     <= 1'b0 ;
2211
                delete_status_bit11     <= 1'b0 ;
2212
                delete_status_bit8      <= 1'b0 ;
2213
                delete_pci_err_cs_bit8  <= 1'b0 ;
2214
                delete_wb_err_cs_bit8   <= 1'b0 ;
2215
                delete_isr_bit4                 <= 1'b0 ;
2216
                delete_isr_bit3                 <= 1'b0 ;
2217
                delete_isr_bit2                 <= 1'b0 ;
2218
                delete_isr_bit1                 <= 1'b0 ;
2219
        end
2220
        endcase
2221
end
2222
 
2223
// STATUS BITS of PCI Header status register
2224
`ifdef SYNCHRONEOUS_CLOCK_DOMAINS
2225
        // Set and clear FF
2226
        always@(posedge pci_clk or posedge reset)
2227
        begin
2228
                if (reset) // Asynchronous reset
2229
                        status_bit15_11[15] <= 1'b0 ;
2230
                else
2231
                begin
2232
                        if (perr_in) // Synchronous set
2233
                                status_bit15_11[15] <= 1'b1 ;
2234
                        else if (delete_status_bit15) // Synchronous reset
2235
                                status_bit15_11[15] <= 1'b0 ;
2236
                end
2237
        end
2238
        // Set and clear FF
2239
        always@(posedge pci_clk or posedge reset)
2240
        begin
2241
                if (reset) // Asynchronous reset
2242
                        status_bit15_11[14] <= 1'b0 ;
2243
                else
2244
                begin
2245
                        if (serr_in) // Synchronous set
2246
                                status_bit15_11[14] <= 1'b1 ;
2247
                        else if (delete_status_bit14) // Synchronous reset
2248
                                status_bit15_11[14] <= 1'b0 ;
2249
                end
2250
        end
2251
        // Set and clear FF
2252
        always@(posedge pci_clk or posedge reset)
2253
        begin
2254
                if (reset) // Asynchronous reset
2255
                        status_bit15_11[13] <= 1'b0 ;
2256
                else
2257
                begin
2258
                        if (master_abort_recv) // Synchronous set
2259
                                status_bit15_11[13] <= 1'b1 ;
2260
                        else if (delete_status_bit13) // Synchronous reset
2261
                                status_bit15_11[13] <= 1'b0 ;
2262
                end
2263
        end
2264
        // Set and clear FF
2265
        always@(posedge pci_clk or posedge reset)
2266
        begin
2267
                if (reset) // Asynchronous reset
2268
                        status_bit15_11[12] <= 1'b0 ;
2269
                else
2270
                begin
2271
                        if (target_abort_recv) // Synchronous set
2272
                                status_bit15_11[12] <= 1'b1 ;
2273
                        else if (delete_status_bit12) // Synchronous reset
2274
                                status_bit15_11[12] <= 1'b0 ;
2275
                end
2276
        end
2277
        // Set and clear FF
2278
        always@(posedge pci_clk or posedge reset)
2279
        begin
2280
                if (reset) // Asynchronous reset
2281
                        status_bit15_11[11] <= 1'b0 ;
2282
                else
2283
                begin
2284
                        if (target_abort_set) // Synchronous set
2285
                                status_bit15_11[11] <= 1'b1 ;
2286
                        else if (delete_status_bit11) // Synchronous reset
2287
                                status_bit15_11[11] <= 1'b0 ;
2288
                end
2289
        end
2290
        // Set and clear FF
2291
        always@(posedge pci_clk or posedge reset)
2292
        begin
2293
                if (reset) // Asynchronous reset
2294
                        status_bit8 <= 1'b0 ;
2295
                else
2296
                begin
2297
                        if (master_data_par_err) // Synchronous set
2298
                                status_bit8 <= 1'b1 ;
2299
                        else if (delete_status_bit8) // Synchronous reset
2300
                                status_bit8 <= 1'b0 ;
2301
                end
2302
        end
2303
`else // not SYNCHRONEOUS_CLOCK_DOMAINS
2304
  `ifdef HOST
2305
        reg             [15:11] set_status_bit15_11;
2306
        reg             set_status_bit8;
2307
        wire    delete_set_status_bit15;
2308
        wire    delete_set_status_bit14;
2309
        wire    delete_set_status_bit13;
2310
        wire    delete_set_status_bit12;
2311
        wire    delete_set_status_bit11;
2312
        wire    delete_set_status_bit8;
2313
        wire    block_set_status_bit15;
2314
        wire    block_set_status_bit14;
2315
        wire    block_set_status_bit13;
2316
        wire    block_set_status_bit12;
2317
        wire    block_set_status_bit11;
2318
        wire    block_set_status_bit8;
2319
        // Synchronization module for clearing FF between two clock domains
2320
        pci_sync_module                 sync_status_15
2321
        (
2322
                .set_clk_in             (pci_clk),
2323
                .delete_clk_in  (wb_clk),
2324
                .reset_in               (reset),
2325
                .delete_set_out (delete_set_status_bit15),
2326
                .block_set_out  (block_set_status_bit15),
2327
                .delete_in              (delete_status_bit15)
2328
        );
2329
        // Setting FF
2330
        always@(posedge pci_clk or posedge reset)
2331
        begin
2332
                if (reset) // Asynchronous reset
2333
                        set_status_bit15_11[15] <= 1'b0 ;
2334
                else
2335
                begin
2336
                        if (perr_in) // Synchronous set
2337
                                set_status_bit15_11[15] <= 1'b1 ;
2338
                        else if (delete_set_status_bit15) // Synchronous reset
2339
                                set_status_bit15_11[15] <= 1'b0 ;
2340
                end
2341
        end
2342
        // Synchronization module for clearing FF between two clock domains
2343
        pci_sync_module                 sync_status_14
2344
        (
2345
                .set_clk_in             (pci_clk),
2346
                .delete_clk_in  (wb_clk),
2347
                .reset_in               (reset),
2348
                .delete_set_out (delete_set_status_bit14),
2349
                .block_set_out  (block_set_status_bit14),
2350
                .delete_in              (delete_status_bit14)
2351
        );
2352
        // Setting FF
2353
        always@(posedge pci_clk or posedge reset)
2354
        begin
2355
                if (reset) // Asynchronous reset
2356
                        set_status_bit15_11[14] <= 1'b0 ;
2357
                else
2358
                begin
2359
                        if (serr_in) // Synchronous set
2360
                                set_status_bit15_11[14] <= 1'b1 ;
2361
                        else if (delete_set_status_bit14) // Synchronous reset
2362
                                set_status_bit15_11[14] <= 1'b0 ;
2363
                end
2364
        end
2365
        // Synchronization module for clearing FF between two clock domains
2366
        pci_sync_module                 sync_status_13
2367
        (
2368
                .set_clk_in             (pci_clk),
2369
                .delete_clk_in  (wb_clk),
2370
                .reset_in               (reset),
2371
                .delete_set_out (delete_set_status_bit13),
2372
                .block_set_out  (block_set_status_bit13),
2373
                .delete_in              (delete_status_bit13)
2374
        );
2375
        // Setting FF
2376
        always@(posedge pci_clk or posedge reset)
2377
        begin
2378
                if (reset) // Asynchronous reset
2379
                        set_status_bit15_11[13] <= 1'b0 ;
2380
                else
2381
                begin
2382
                        if (master_abort_recv) // Synchronous set
2383
                                set_status_bit15_11[13] <= 1'b1 ;
2384
                        else if (delete_set_status_bit13) // Synchronous reset
2385
                                set_status_bit15_11[13] <= 1'b0 ;
2386
                end
2387
        end
2388
        // Synchronization module for clearing FF between two clock domains
2389
        pci_sync_module                 sync_status_12
2390
        (
2391
                .set_clk_in             (pci_clk),
2392
                .delete_clk_in  (wb_clk),
2393
                .reset_in               (reset),
2394
                .delete_set_out (delete_set_status_bit12),
2395
                .block_set_out  (block_set_status_bit12),
2396
                .delete_in              (delete_status_bit12)
2397
        );
2398
        // Setting FF
2399
        always@(posedge pci_clk or posedge reset)
2400
        begin
2401
                if (reset) // Asynchronous reset
2402
                        set_status_bit15_11[12] <= 1'b0 ;
2403
                else
2404
                begin
2405
                        if (target_abort_recv) // Synchronous set
2406
                                set_status_bit15_11[12] <= 1'b1 ;
2407
                        else if (delete_set_status_bit12) // Synchronous reset
2408
                                set_status_bit15_11[12] <= 1'b0 ;
2409
                end
2410
        end
2411
        // Synchronization module for clearing FF between two clock domains
2412
        pci_sync_module                 sync_status_11
2413
        (
2414
                .set_clk_in             (pci_clk),
2415
                .delete_clk_in  (wb_clk),
2416
                .reset_in               (reset),
2417
                .delete_set_out (delete_set_status_bit11),
2418
                .block_set_out  (block_set_status_bit11),
2419
                .delete_in              (delete_status_bit11)
2420
        );
2421
        // Setting FF
2422
        always@(posedge pci_clk or posedge reset)
2423
        begin
2424
                if (reset) // Asynchronous reset
2425
                        set_status_bit15_11[11] <= 1'b0 ;
2426
                else
2427
                begin
2428
                        if (target_abort_set) // Synchronous set
2429
                                set_status_bit15_11[11] <= 1'b1 ;
2430
                        else if (delete_set_status_bit11) // Synchronous reset
2431
                                set_status_bit15_11[11] <= 1'b0 ;
2432
                end
2433
        end
2434
        // Synchronization module for clearing FF between two clock domains
2435
        pci_sync_module                 sync_status_8
2436
        (
2437
                .set_clk_in             (pci_clk),
2438
                .delete_clk_in  (wb_clk),
2439
                .reset_in               (reset),
2440
                .delete_set_out (delete_set_status_bit8),
2441
                .block_set_out  (block_set_status_bit8),
2442
                .delete_in              (delete_status_bit8)
2443
        );
2444
        // Setting FF
2445
        always@(posedge pci_clk or posedge reset)
2446
        begin
2447
                if (reset) // Asynchronous reset
2448
                        set_status_bit8 <= 1'b0 ;
2449
                else
2450
                begin
2451
                        if (master_data_par_err) // Synchronous set
2452
                                set_status_bit8 <= 1'b1 ;
2453
                        else if (delete_set_status_bit8) // Synchronous reset
2454
                                set_status_bit8 <= 1'b0 ;
2455
                end
2456
        end
2457
        wire [5:0] status_bits   =       {set_status_bit15_11[15] && !block_set_status_bit15,
2458
                                                                 set_status_bit15_11[14] && !block_set_status_bit14,
2459
                                                                 set_status_bit15_11[13] && !block_set_status_bit13,
2460
                                                                 set_status_bit15_11[12] && !block_set_status_bit12,
2461
                                                                 set_status_bit15_11[11] && !block_set_status_bit11,
2462
                                                                 set_status_bit8                 && !block_set_status_bit8      } ;
2463
        wire [5:0] meta_status_bits ;
2464
        // interemediate stage to clk synchronization flip - flops - this ones are prone to metastability
2465 88 mihad
        synchronizer_flop   #(6, 0) status_bits_sync
2466 77 mihad
        (
2467
            .data_in        (status_bits),
2468
            .clk_out        (wb_clk),
2469
            .sync_data_out  (meta_status_bits),
2470
            .async_reset    (reset)
2471
        ) ;
2472
        always@(posedge wb_clk or posedge reset)
2473
        begin
2474
            if (reset)
2475
            begin
2476
                status_bit15_11[15:11]  <= 5'b0 ;
2477
                status_bit8                             <= 1'b0 ;
2478
            end
2479
            else
2480
            begin
2481
                status_bit15_11[15:11]  <= meta_status_bits[5:1] ;
2482
                status_bit8                             <= meta_status_bits[0] ;
2483
            end
2484
        end
2485
  `else // GUEST
2486
        // Set and clear FF
2487
        always@(posedge pci_clk or posedge reset)
2488
        begin
2489
                if (reset) // Asynchronous reset
2490
                        status_bit15_11[15] <= 1'b0 ;
2491
                else
2492
                begin
2493
                        if (perr_in) // Synchronous set
2494
                                status_bit15_11[15] <= 1'b1 ;
2495
                        else if (delete_status_bit15) // Synchronous reset
2496
                                status_bit15_11[15] <= 1'b0 ;
2497
                end
2498
        end
2499
        // Set and clear FF
2500
        always@(posedge pci_clk or posedge reset)
2501
        begin
2502
                if (reset) // Asynchronous reset
2503
                        status_bit15_11[14] <= 1'b0 ;
2504
                else
2505
                begin
2506
                        if (serr_in) // Synchronous set
2507
                                status_bit15_11[14] <= 1'b1 ;
2508
                        else if (delete_status_bit14) // Synchronous reset
2509
                                status_bit15_11[14] <= 1'b0 ;
2510
                end
2511
        end
2512
        // Set and clear FF
2513
        always@(posedge pci_clk or posedge reset)
2514
        begin
2515
                if (reset) // Asynchronous reset
2516
                        status_bit15_11[13] <= 1'b0 ;
2517
                else
2518
                begin
2519
                        if (master_abort_recv) // Synchronous set
2520
                                status_bit15_11[13] <= 1'b1 ;
2521
                        else if (delete_status_bit13) // Synchronous reset
2522
                                status_bit15_11[13] <= 1'b0 ;
2523
                end
2524
        end
2525
        // Set and clear FF
2526
        always@(posedge pci_clk or posedge reset)
2527
        begin
2528
                if (reset) // Asynchronous reset
2529
                        status_bit15_11[12] <= 1'b0 ;
2530
                else
2531
                begin
2532
                        if (target_abort_recv) // Synchronous set
2533
                                status_bit15_11[12] <= 1'b1 ;
2534
                        else if (delete_status_bit12) // Synchronous reset
2535
                                status_bit15_11[12] <= 1'b0 ;
2536
                end
2537
        end
2538
        // Set and clear FF
2539
        always@(posedge pci_clk or posedge reset)
2540
        begin
2541
                if (reset) // Asynchronous reset
2542
                        status_bit15_11[11] <= 1'b0 ;
2543
                else
2544
                begin
2545
                        if (target_abort_set) // Synchronous set
2546
                                status_bit15_11[11] <= 1'b1 ;
2547
                        else if (delete_status_bit11) // Synchronous reset
2548
                                status_bit15_11[11] <= 1'b0 ;
2549
                end
2550
        end
2551
        // Set and clear FF
2552
        always@(posedge pci_clk or posedge reset)
2553
        begin
2554
                if (reset) // Asynchronous reset
2555
                        status_bit8 <= 1'b0 ;
2556
                else
2557
                begin
2558
                        if (master_data_par_err) // Synchronous set
2559
                                status_bit8 <= 1'b1 ;
2560
                        else if (delete_status_bit8) // Synchronous reset
2561
                                status_bit8 <= 1'b0 ;
2562
                end
2563
        end
2564
  `endif
2565
`endif
2566
 
2567
// STATUS BITS of P_ERR_CS - PCI error control and status register
2568
`ifdef SYNCHRONEOUS_CLOCK_DOMAINS
2569
        // Set and clear FF
2570
        always@(posedge pci_clk or posedge reset)
2571
        begin
2572
                if (reset) // Asynchronous reset
2573
                        pci_err_cs_bit8 <= 1'b0 ;
2574
                else
2575
                begin
2576
                        if (pci_error_sig && pci_err_cs_bit0) // Synchronous set
2577
                                pci_err_cs_bit8 <= 1'b1 ;
2578
                        else if (delete_pci_err_cs_bit8) // Synchronous reset
2579
                                pci_err_cs_bit8 <= 1'b0 ;
2580
                end
2581
        end
2582
`else // not SYNCHRONEOUS_CLOCK_DOMAINS
2583
  `ifdef HOST
2584
        // Set and clear FF
2585
        always@(posedge wb_clk or posedge reset)
2586
        begin
2587
                if (reset) // Asynchronous reset
2588
                        pci_err_cs_bit8 <= 1'b0 ;
2589
                else
2590
                begin
2591
                        if (pci_error_sig && pci_err_cs_bit0) // Synchronous set
2592
                                pci_err_cs_bit8 <= 1'b1 ;
2593
                        else if (delete_pci_err_cs_bit8) // Synchronous reset
2594
                                pci_err_cs_bit8 <= 1'b0 ;
2595
                end
2596
        end
2597
  `else // GUEST
2598
        reg             set_pci_err_cs_bit8;
2599
        wire    delete_set_pci_err_cs_bit8;
2600
        wire    block_set_pci_err_cs_bit8;
2601
        // Synchronization module for clearing FF between two clock domains
2602
        pci_sync_module                 sync_pci_err_cs_8
2603
        (
2604
                .set_clk_in             (wb_clk),
2605
                .delete_clk_in  (pci_clk),
2606
                .reset_in               (reset),
2607
                .delete_set_out (delete_set_pci_err_cs_bit8),
2608
                .block_set_out  (block_set_pci_err_cs_bit8),
2609
                .delete_in              (delete_pci_err_cs_bit8)
2610
        );
2611
        // Setting FF
2612
        always@(posedge wb_clk or posedge reset)
2613
        begin
2614
                if (reset) // Asynchronous reset
2615
                        set_pci_err_cs_bit8 <= 1'b0 ;
2616
                else
2617
                begin
2618
                        if (pci_error_sig && pci_err_cs_bit0) // Synchronous set
2619
                                set_pci_err_cs_bit8 <= 1'b1 ;
2620
                        else if (delete_set_pci_err_cs_bit8) // Synchronous reset
2621
                                set_pci_err_cs_bit8 <= 1'b0 ;
2622
                end
2623
        end
2624
        wire    pci_err_cs_bits = set_pci_err_cs_bit8 && !block_set_pci_err_cs_bit8 ;
2625
        wire    meta_pci_err_cs_bits ;
2626
        // interemediate stage to clk synchronization flip - flops - this ones are prone to metastability
2627 88 mihad
        synchronizer_flop #(1,0) pci_err_cs_bits_sync
2628 77 mihad
        (
2629
            .data_in        (pci_err_cs_bits),
2630
            .clk_out        (pci_clk),
2631
            .sync_data_out  (meta_pci_err_cs_bits),
2632
            .async_reset    (reset)
2633
        ) ;
2634
        always@(posedge pci_clk or posedge reset)
2635
        begin
2636
            if (reset)
2637
                pci_err_cs_bit8 <= 1'b0 ;
2638
            else
2639
                pci_err_cs_bit8 <= meta_pci_err_cs_bits ;
2640
        end
2641
  `endif
2642
`endif
2643
        // Set and clear FF
2644
        always@(posedge wb_clk or posedge reset)
2645
        begin
2646
                if (reset) // Asynchronous reset
2647
                        pci_err_cs_bit10 <= 1'b0 ;
2648
                else
2649
                begin
2650
                        if (pci_error_sig) // Synchronous report
2651
                                pci_err_cs_bit10 <= pci_error_rty_exp ;
2652
                end
2653
        end
2654
        // Set and clear FF
2655
        always@(posedge wb_clk or posedge reset)
2656
        begin
2657
                if (reset) // Asynchronous reset
2658
                        pci_err_cs_bit9 <= 1'b0 ;
2659
                else
2660
                begin
2661
                        if (pci_error_sig) // Synchronous report
2662
                                pci_err_cs_bit9 <= pci_error_es ;
2663
                end
2664
        end
2665
        // Set and clear FF
2666
        always@(posedge wb_clk or posedge reset)
2667
        begin
2668
                if (reset) // Asynchronous reset
2669
            begin
2670
                        pci_err_cs_bit31_24 <= 8'h00 ;
2671
                        pci_err_addr <= 32'h0000_0000 ;
2672
                        pci_err_data <= 32'h0000_0000 ;
2673
            end
2674
                else
2675
                        if (pci_error_sig) // Synchronous report
2676
                        begin
2677
                                pci_err_cs_bit31_24 <= { pci_error_be, pci_error_bc } ;
2678
                                pci_err_addr <= pci_error_addr ;
2679
                                pci_err_data <= pci_error_data ;
2680
                        end
2681
        end
2682
 
2683
// STATUS BITS of W_ERR_CS - WB error control and status register
2684
`ifdef SYNCHRONEOUS_CLOCK_DOMAINS
2685
        // Set and clear FF
2686
        always@(posedge pci_clk or posedge reset)
2687
        begin
2688
                if (reset) // Asynchronous reset
2689
                        wb_err_cs_bit8 <= 1'b0 ;
2690
                else
2691
                begin
2692
                        if (wb_error_sig && wb_err_cs_bit0) // Synchronous set
2693
                                wb_err_cs_bit8 <= 1'b1 ;
2694
                        else if (delete_wb_err_cs_bit8) // Synchronous reset
2695
                                wb_err_cs_bit8 <= 1'b0 ;
2696
                end
2697
        end
2698
`else // not SYNCHRONEOUS_CLOCK_DOMAINS
2699
  `ifdef HOST
2700
        reg             set_wb_err_cs_bit8;
2701
        wire    delete_set_wb_err_cs_bit8;
2702
        wire    block_set_wb_err_cs_bit8;
2703
        // Synchronization module for clearing FF between two clock domains
2704
        pci_sync_module                 sync_wb_err_cs_8
2705
        (
2706
                .set_clk_in             (pci_clk),
2707
                .delete_clk_in  (wb_clk),
2708
                .reset_in               (reset),
2709
                .delete_set_out (delete_set_wb_err_cs_bit8),
2710
                .block_set_out  (block_set_wb_err_cs_bit8),
2711
                .delete_in              (delete_wb_err_cs_bit8)
2712
        );
2713
        // Setting FF
2714
        always@(posedge pci_clk or posedge reset)
2715
        begin
2716
                if (reset) // Asynchronous reset
2717
                        set_wb_err_cs_bit8 <= 1'b0 ;
2718
                else
2719
                begin
2720
                        if (wb_error_sig && wb_err_cs_bit0) // Synchronous set
2721
                                set_wb_err_cs_bit8 <= 1'b1 ;
2722
                        else if (delete_set_wb_err_cs_bit8) // Synchronous reset
2723
                                set_wb_err_cs_bit8 <= 1'b0 ;
2724
                end
2725
        end
2726
        wire    wb_err_cs_bits = set_wb_err_cs_bit8 && !block_set_wb_err_cs_bit8 ;
2727
        wire    meta_wb_err_cs_bits ;
2728
        // interemediate stage to clk synchronization flip - flops - this ones are prone to metastability
2729 88 mihad
        synchronizer_flop #(1,0) wb_err_cs_bits_sync
2730 77 mihad
        (
2731
            .data_in        (wb_err_cs_bits),
2732
            .clk_out        (wb_clk),
2733
            .sync_data_out  (meta_wb_err_cs_bits),
2734
            .async_reset    (reset)
2735
        ) ;
2736
        always@(posedge wb_clk or posedge reset)
2737
        begin
2738
            if (reset)
2739
                wb_err_cs_bit8  <= 1'b0 ;
2740
            else
2741
                wb_err_cs_bit8  <= meta_wb_err_cs_bits ;
2742
        end
2743
  `else // GUEST
2744
        // Set and clear FF
2745
        always@(posedge pci_clk or posedge reset)
2746
        begin
2747
                if (reset) // Asynchronous reset
2748
                        wb_err_cs_bit8 <= 1'b0 ;
2749
                else
2750
                begin
2751
                        if (wb_error_sig && wb_err_cs_bit0) // Synchronous set
2752
                                wb_err_cs_bit8 <= 1'b1 ;
2753
                        else if (delete_wb_err_cs_bit8) // Synchronous reset
2754
                                wb_err_cs_bit8 <= 1'b0 ;
2755
                end
2756
        end
2757
  `endif
2758
`endif
2759
/*      // Set and clear FF
2760
        always@(posedge pci_clk or posedge reset)
2761
        begin
2762
                if (reset) // Asynchronous reset
2763
                        wb_err_cs_bit10 <= 1'b0 ;
2764
                else
2765
                begin
2766
                        if (wb_error_sig) // Synchronous report
2767
                                wb_err_cs_bit10 <= wb_error_rty_exp ;
2768
                end
2769
        end */
2770
        // Set and clear FF
2771
        always@(posedge pci_clk or posedge reset)
2772
        begin
2773
                if (reset) // Asynchronous reset
2774
                        wb_err_cs_bit9 <= 1'b0 ;
2775
                else
2776
                begin
2777
                        if (wb_error_sig) // Synchronous report
2778
                                wb_err_cs_bit9 <= wb_error_es ;
2779
                end
2780
        end
2781
        // Set and clear FF
2782
        always@(posedge pci_clk or posedge reset)
2783
        begin
2784
                if (reset) // Asynchronous reset
2785
            begin
2786
                        wb_err_cs_bit31_24 <= 8'h00 ;
2787
                        wb_err_addr <= 32'h0000_0000 ;
2788
                        wb_err_data <= 32'h0000_0000 ;
2789
            end
2790
                else
2791
                        if (wb_error_sig)
2792
                        begin
2793
                                wb_err_cs_bit31_24 <= { wb_error_be, wb_error_bc } ;
2794
                                wb_err_addr <= wb_error_addr ;
2795
                                wb_err_data <= wb_error_data ;
2796
                        end
2797
        end
2798
 
2799
// SERR_INT and PERR_INT STATUS BITS of ISR - interrupt status register
2800
`ifdef SYNCHRONEOUS_CLOCK_DOMAINS
2801
  `ifdef HOST
2802
        // Set and clear FF
2803
        always@(posedge pci_clk or posedge reset)
2804
        begin
2805
                if (reset) // Asynchronous reset
2806
                        isr_bit4_3[4] <= 1'b0 ;
2807
                else
2808
                begin
2809
                        if (isr_sys_err_int && icr_bit4_3[4]) // Synchronous set
2810
                                isr_bit4_3[4] <= 1'b1 ;
2811
                        else if (delete_isr_bit4) // Synchronous reset
2812
                                isr_bit4_3[4] <= 1'b0 ;
2813
                end
2814
        end
2815
        // Set and clear FF
2816
        always@(posedge pci_clk or posedge reset)
2817
        begin
2818
                if (reset) // Asynchronous reset
2819
                        isr_bit4_3[3] <= 1'b0 ;
2820
                else
2821
                begin
2822
                        if (isr_par_err_int && icr_bit4_3[3]) // Synchronous set
2823
                                isr_bit4_3[3] <= 1'b1 ;
2824
                        else if (delete_isr_bit3) // Synchronous reset
2825
                                isr_bit4_3[3] <= 1'b0 ;
2826
                end
2827
        end
2828
  `endif
2829
`else // not SYNCHRONEOUS_CLOCK_DOMAINS
2830
  `ifdef HOST
2831
        reg             [4:3]   set_isr_bit4_3;
2832
        wire    delete_set_isr_bit4;
2833
        wire    delete_set_isr_bit3;
2834
        wire    block_set_isr_bit4;
2835
        wire    block_set_isr_bit3;
2836
        // Synchronization module for clearing FF between two clock domains
2837
        pci_sync_module                 sync_isr_4
2838
        (
2839
                .set_clk_in             (pci_clk),
2840
                .delete_clk_in  (wb_clk),
2841
                .reset_in               (reset),
2842
                .delete_set_out (delete_set_isr_bit4),
2843
                .block_set_out  (block_set_isr_bit4),
2844
                .delete_in              (delete_isr_bit4)
2845
        );
2846
        // Setting FF
2847
        always@(posedge pci_clk or posedge reset)
2848
        begin
2849
                if (reset) // Asynchronous reset
2850
                        set_isr_bit4_3[4] <= 1'b0 ;
2851
                else
2852
                begin
2853
                        if (isr_sys_err_int && icr_bit4_3[4]) // Synchronous set
2854
                                set_isr_bit4_3[4] <= 1'b1 ;
2855
                        else if (delete_set_isr_bit4) // Synchronous reset
2856
                                set_isr_bit4_3[4] <= 1'b0 ;
2857
                end
2858
        end
2859
        // Synchronization module for clearing FF between two clock domains
2860
        pci_sync_module                 sync_isr_3
2861
        (
2862
                .set_clk_in             (pci_clk),
2863
                .delete_clk_in  (wb_clk),
2864
                .reset_in               (reset),
2865
                .delete_set_out (delete_set_isr_bit3),
2866
                .block_set_out  (block_set_isr_bit3),
2867
                .delete_in              (delete_isr_bit3)
2868
        );
2869
        // Setting FF
2870
        always@(posedge pci_clk or posedge reset)
2871
        begin
2872
                if (reset) // Asynchronous reset
2873
                        set_isr_bit4_3[3] <= 1'b0 ;
2874
                else
2875
                begin
2876
                        if (isr_par_err_int && icr_bit4_3[3]) // Synchronous set
2877
                                set_isr_bit4_3[3] <= 1'b1 ;
2878
                        else if (delete_set_isr_bit3) // Synchronous reset
2879
                                set_isr_bit4_3[3] <= 1'b0 ;
2880
                end
2881
        end
2882
        wire [4:3] isr_bits4_3  =       {set_isr_bit4_3[4] && !block_set_isr_bit4,
2883
                                                                 set_isr_bit4_3[3] && !block_set_isr_bit3       } ;
2884
        wire [4:3] meta_isr_bits4_3 ;
2885
        // interemediate stage to clk synchronization flip - flops - this ones are prone to metastability
2886 88 mihad
        synchronizer_flop   #(2, 0) isr_bits_sync
2887 77 mihad
        (
2888
            .data_in        (isr_bits4_3),
2889
            .clk_out        (wb_clk),
2890
            .sync_data_out  (meta_isr_bits4_3),
2891
            .async_reset    (reset)
2892
        ) ;
2893
        always@(posedge wb_clk or posedge reset)
2894
        begin
2895
            if (reset)
2896
                isr_bit4_3[4:3] <= 2'b0 ;
2897
            else
2898
                isr_bit4_3[4:3] <= meta_isr_bits4_3[4:3] ;
2899
        end
2900
  `endif
2901
`endif
2902
 
2903
// PCI_EINT and WB_EINT STATUS BITS of ISR - interrupt status register
2904
`ifdef SYNCHRONEOUS_CLOCK_DOMAINS
2905
  // WB_EINT STATUS BIT
2906
        // Set and clear FF
2907
        always@(posedge pci_clk or posedge reset)
2908
        begin
2909
                if (reset) // Asynchronous reset
2910
                        isr_bit2_0[1] <= 1'b0 ;
2911
                else
2912
                begin
2913
                        if (wb_error_sig && icr_bit2_0[1] && wb_err_cs_bit0) // Synchronous set
2914
                                isr_bit2_0[1] <= 1'b1 ;
2915
                        else if (delete_isr_bit1) // Synchronous reset
2916
                                isr_bit2_0[1] <= 1'b0 ;
2917
                end
2918
        end
2919
  // PCI_EINT STATUS BIT
2920
        // Set and clear FF
2921
        always@(posedge pci_clk or posedge reset)
2922
        begin
2923
                if (reset) // Asynchronous reset
2924
                        isr_bit2_0[2] <= 1'b0 ;
2925
                else
2926
                begin
2927
                        if (pci_error_sig && icr_bit2_0[2] && pci_err_cs_bit0) // Synchronous set
2928
                                isr_bit2_0[2] <= 1'b1 ;
2929
                        else if (delete_isr_bit2) // Synchronous reset
2930
                                isr_bit2_0[2] <= 1'b0 ;
2931
                end
2932
        end
2933
`else // not SYNCHRONEOUS_CLOCK_DOMAINS
2934
  `ifdef HOST
2935
  // WB_EINT STATUS BIT
2936
        reg             set_isr_bit1;
2937
        wire    delete_set_isr_bit1;
2938
        wire    block_set_isr_bit1;
2939
        // Synchronization module for clearing FF between two clock domains
2940
        pci_sync_module                 sync_isr_1
2941
        (
2942
                .set_clk_in             (pci_clk),
2943
                .delete_clk_in  (wb_clk),
2944
                .reset_in               (reset),
2945
                .delete_set_out (delete_set_isr_bit1),
2946
                .block_set_out  (block_set_isr_bit1),
2947
                .delete_in              (delete_isr_bit1)
2948
        );
2949
        // Setting FF
2950
        always@(posedge pci_clk or posedge reset)
2951
        begin
2952
                if (reset) // Asynchronous reset
2953
                        set_isr_bit1 <= 1'b0 ;
2954
                else
2955
                begin
2956
                        if (wb_error_sig && icr_bit2_0[1] && wb_err_cs_bit0) // Synchronous set
2957
                                set_isr_bit1 <= 1'b1 ;
2958
                        else if (delete_set_isr_bit1) // Synchronous reset
2959
                                set_isr_bit1 <= 1'b0 ;
2960
                end
2961
        end
2962
        wire    isr_bit1        = set_isr_bit1 && !block_set_isr_bit1 ;
2963
        wire    meta_isr_bit1 ;
2964
        // interemediate stage to clk synchronization flip - flops - this ones are prone to metastability
2965 88 mihad
        synchronizer_flop   #(1, 0) isr_bit1_sync
2966 77 mihad
        (
2967
            .data_in        (isr_bit1),
2968
            .clk_out        (wb_clk),
2969
            .sync_data_out  (meta_isr_bit1),
2970
            .async_reset    (reset)
2971
        ) ;
2972
        always@(posedge wb_clk or posedge reset)
2973
        begin
2974
            if (reset)
2975
                isr_bit2_0[1]   <= 1'b0 ;
2976
            else
2977
                isr_bit2_0[1]   <= meta_isr_bit1 ;
2978
        end
2979
  // PCI_EINT STATUS BIT
2980
        // Set and clear FF
2981
        always@(posedge wb_clk or posedge reset)
2982
        begin
2983
                if (reset) // Asynchronous reset
2984
                        isr_bit2_0[2] <= 1'b0 ;
2985
                else
2986
                begin
2987
                        if (pci_error_sig && icr_bit2_0[2] && pci_err_cs_bit0) // Synchronous set
2988
                                isr_bit2_0[2] <= 1'b1 ;
2989
                        else if (delete_isr_bit2) // Synchronous reset
2990
                                isr_bit2_0[2] <= 1'b0 ;
2991
                end
2992
        end
2993
  `else // GUEST
2994
  // WB_EINT STATUS BIT
2995
        // Set and clear FF
2996
        always@(posedge pci_clk or posedge reset)
2997
        begin
2998
                if (reset) // Asynchronous reset
2999
                        isr_bit2_0[1] <= 1'b0 ;
3000
                else
3001
                begin
3002
                        if (wb_error_sig && icr_bit2_0[1] && wb_err_cs_bit0) // Synchronous set
3003
                                isr_bit2_0[1] <= 1'b1 ;
3004
                        else if (delete_isr_bit1) // Synchronous reset
3005
                                isr_bit2_0[1] <= 1'b0 ;
3006
                end
3007
        end
3008
  // PCI_EINT STATUS BIT
3009
        reg             set_isr_bit2;
3010
        wire    delete_set_isr_bit2;
3011
        wire    block_set_isr_bit2;
3012
        // Synchronization module for clearing FF between two clock domains
3013
        pci_sync_module                 sync_isr_2
3014
        (
3015
                .set_clk_in             (wb_clk),
3016
                .delete_clk_in  (pci_clk),
3017
                .reset_in               (reset),
3018
                .delete_set_out (delete_set_isr_bit2),
3019
                .block_set_out  (block_set_isr_bit2),
3020
                .delete_in              (delete_isr_bit2)
3021
        );
3022
        // Setting FF
3023
        always@(posedge wb_clk or posedge reset)
3024
        begin
3025
                if (reset) // Asynchronous reset
3026
                        set_isr_bit2 <= 1'b0 ;
3027
                else
3028
                begin
3029
                        if (pci_error_sig && icr_bit2_0[2] && pci_err_cs_bit0) // Synchronous set
3030
                                set_isr_bit2 <= 1'b1 ;
3031
                        else if (delete_set_isr_bit2) // Synchronous reset
3032
                                set_isr_bit2 <= 1'b0 ;
3033
                end
3034
        end
3035
        wire    isr_bit2        = set_isr_bit2 && !block_set_isr_bit2 ;
3036
        wire    meta_isr_bit2 ;
3037
        // interemediate stage to clk synchronization flip - flops - this ones are prone to metastability
3038 88 mihad
        synchronizer_flop   #(1, 0) isr_bit2_sync
3039 77 mihad
        (
3040
            .data_in        (isr_bit2),
3041
            .clk_out        (pci_clk),
3042
            .sync_data_out  (meta_isr_bit2),
3043
            .async_reset    (reset)
3044
        ) ;
3045
        always@(posedge pci_clk or posedge reset)
3046
        begin
3047
            if (reset)
3048
                isr_bit2_0[2]   <= 1'b0 ;
3049
            else
3050
                isr_bit2_0[2]   <= meta_isr_bit2 ;
3051
        end
3052
  `endif
3053
`endif
3054
 
3055
// INT BIT of ISR - interrupt status register
3056
`ifdef HOST
3057
        wire    isr_int_prop_bit = isr_int_prop && icr_bit2_0[0] ;
3058
        wire    meta_isr_int_prop_bit ;
3059
        // interemediate stage to clk synchronization flip - flops - this ones are prone to metastability
3060 88 mihad
        synchronizer_flop   #(1, 0) isr_bit0_sync
3061 77 mihad
        (
3062
            .data_in        (isr_int_prop_bit),
3063
            .clk_out        (wb_clk),
3064
            .sync_data_out  (meta_isr_int_prop_bit),
3065
            .async_reset    (reset)
3066
        ) ;
3067
        always@(posedge wb_clk or posedge reset)
3068
        begin
3069
            if (reset)
3070
                isr_bit2_0[0]    <= 1'b0 ;
3071
            else
3072
                isr_bit2_0[0]    <= meta_isr_int_prop_bit ;
3073
        end
3074
`else // GUEST
3075
  `ifdef SYNCHRONEOUS_CLOCK_DOMAINS
3076
        wire    isr_int_prop_bit = isr_int_prop && icr_bit2_0[0] ;
3077
        always@(posedge pci_clk or posedge reset)
3078
        begin
3079
            if (reset)
3080
                isr_bit2_0[0]    <= 1'b0 ;
3081
            else
3082
                isr_bit2_0[0]    <= isr_int_prop_bit ;
3083
        end
3084
  `else // not SYNCHRONEOUS_CLOCK_DOMAINS
3085
        wire    isr_int_prop_bit = isr_int_prop && icr_bit2_0[0] ;
3086
        wire    meta_isr_int_prop_bit ;
3087
        // interemediate stage to clk synchronization flip - flops - this ones are prone to metastability
3088 88 mihad
        synchronizer_flop   #(1, 0) isr_bit0_sync
3089 77 mihad
        (
3090
            .data_in        (isr_int_prop_bit),
3091
            .clk_out        (pci_clk),
3092
            .sync_data_out  (meta_isr_int_prop_bit),
3093
            .async_reset    (reset)
3094
        ) ;
3095
        always@(posedge pci_clk or posedge reset)
3096
        begin
3097
            if (reset)
3098
                isr_bit2_0[0]    <= 1'b0 ;
3099
            else
3100
                isr_bit2_0[0]    <= meta_isr_int_prop_bit ;
3101
        end
3102
  `endif
3103
`endif
3104
 
3105
// INT PIN
3106
wire    int_in;
3107
wire    int_meta;
3108
reg             interrupt_out;
3109
`ifdef HOST
3110
 `ifdef SYNCHRONEOUS_CLOCK_DOMAINS
3111
        assign  int_in = isr_int_prop_bit || isr_bit2_0[1] || isr_bit2_0[2] || isr_bit4_3[3]  || isr_bit4_3[4];
3112
 `else // not SYNCHRONEOUS_CLOCK_DOMAINS
3113
        assign  int_in = isr_int_prop_bit || isr_bit1      || isr_bit2_0[2] || isr_bits4_3[3] || isr_bits4_3[4];
3114
 `endif
3115
        // interemediate stage to clk synchronization flip - flops - this ones are prone to metastability
3116 88 mihad
        synchronizer_flop   #(1, 0) int_pin_sync
3117 77 mihad
        (
3118
            .data_in        (int_in),
3119
            .clk_out        (wb_clk),
3120
            .sync_data_out  (int_meta),
3121
            .async_reset    (reset)
3122
        ) ;
3123
        always@(posedge wb_clk or posedge reset)
3124
        begin
3125
            if (reset)
3126
                interrupt_out   <= 1'b0 ;
3127
            else
3128
                interrupt_out   <= int_meta ;
3129
        end
3130
`else // GUEST
3131
 `ifdef SYNCHRONEOUS_CLOCK_DOMAINS
3132
        assign  int_in = isr_int_prop_bit || isr_bit2_0[1] || isr_bit2_0[2];
3133
 `else // not SYNCHRONEOUS_CLOCK_DOMAINS
3134
        assign  int_in = isr_int_prop_bit || isr_bit2_0[1] || isr_bit2;
3135
 `endif
3136
        // interemediate stage to clk synchronization flip - flops - this ones are prone to metastability
3137 88 mihad
        synchronizer_flop   #(1, 0) int_pin_sync
3138 77 mihad
        (
3139
            .data_in        (int_in),
3140
            .clk_out        (pci_clk),
3141
            .sync_data_out  (int_meta),
3142
            .async_reset    (reset)
3143
        ) ;
3144
        always@(posedge pci_clk or posedge reset)
3145
        begin
3146
            if (reset)
3147
                interrupt_out   <= 1'b0 ;
3148
            else
3149
                interrupt_out   <= int_meta ;
3150
        end
3151
`endif
3152
 
3153
/*-----------------------------------------------------------------------------------------------------------
3154
        OUTPUTs from registers !!!
3155
-----------------------------------------------------------------------------------------------------------*/
3156
 
3157
// if bridge is HOST then write clock is equal to WB clock, and synchronization of outputs has to be done
3158
`ifdef  HOST
3159
  wire [3:0] command_bits = {command_bit8, command_bit6, command_bit2_0[1:0]} ;
3160
  wire [3:0] meta_command_bits ;
3161
  reg  [3:0] sync_command_bits ;
3162 88 mihad
  synchronizer_flop   #(4, 0)  command_bits_sync
3163 77 mihad
  (
3164
      .data_in        (command_bits),
3165
      .clk_out        (pci_clk),
3166
      .sync_data_out  (meta_command_bits),
3167
      .async_reset    (reset)
3168
  ) ;
3169
  always@(posedge pci_clk or posedge reset)
3170
  begin
3171
      if (reset)
3172
          sync_command_bits <= 4'b0 ;
3173
      else
3174
          sync_command_bits <= meta_command_bits ;
3175
  end
3176
  wire  sync_command_bit8 = sync_command_bits[3] ;
3177
  wire  sync_command_bit6 = sync_command_bits[2] ;
3178
  wire  sync_command_bit1 = sync_command_bits[1] ;
3179
  wire  sync_command_bit0 = sync_command_bits[0] ;
3180
  wire  sync_command_bit2 = command_bit2_0[2] ;
3181
`else   // GUEST
3182
  wire       command_bit = command_bit2_0[2] ;
3183
  wire       meta_command_bit ;
3184
  reg        sync_command_bit ;
3185 88 mihad
  synchronizer_flop   #(1, 0) command_bit_sync
3186 77 mihad
  (
3187
      .data_in        (command_bit),
3188
      .clk_out        (pci_clk),
3189
      .sync_data_out  (meta_command_bit),
3190
      .async_reset    (reset)
3191
  ) ;
3192
  always@(posedge pci_clk or posedge reset)
3193
  begin
3194
      if (reset)
3195
          sync_command_bit <= 1'b0 ;
3196
      else
3197
          sync_command_bit <= meta_command_bit ;
3198
  end
3199
  wire  sync_command_bit8 = command_bit8 ;
3200
  wire  sync_command_bit6 = command_bit6 ;
3201
  wire  sync_command_bit1 = command_bit2_0[1] ;
3202
  wire  sync_command_bit0 = command_bit2_0[0] ;
3203
  wire  sync_command_bit2 = sync_command_bit ;
3204
`endif
3205
// PCI header outputs from command register
3206
assign          serr_enable = sync_command_bit8 ;                                       // to PCI clock
3207
assign          perr_response = sync_command_bit6 ;                     // to PCI clock
3208
assign          pci_master_enable = sync_command_bit2 ;                 // to WB clock
3209
assign          memory_space_enable = sync_command_bit1 ;                       // to PCI clock
3210
assign          io_space_enable = sync_command_bit0 ;                           // to PCI clock
3211
 
3212
// if bridge is HOST then write clock is equal to WB clock, and synchronization of outputs has to be done
3213
        // We don't support cache line sizes smaller that 4 and it must have last two bits zero!!!
3214
wire    cache_lsize_not_zero = ((cache_line_size_reg[7] || cache_line_size_reg[6] || cache_line_size_reg[5] ||
3215
                                                                 cache_line_size_reg[4] || cache_line_size_reg[3] || cache_line_size_reg[2]) &&
3216
                                                                (!cache_line_size_reg[1] && !cache_line_size_reg[0]) );
3217
`ifdef  HOST
3218
  wire [7:2] cache_lsize_to_pci_bits = { cache_line_size_reg[7:2] } ;
3219
  wire [7:2] meta_cache_lsize_to_pci_bits ;
3220
  reg  [7:2] sync_cache_lsize_to_pci_bits ;
3221 88 mihad
  synchronizer_flop   #(6, 0)  cache_lsize_to_pci_bits_sync
3222 77 mihad
  (
3223
      .data_in        (cache_lsize_to_pci_bits),
3224
      .clk_out        (pci_clk),
3225
      .sync_data_out  (meta_cache_lsize_to_pci_bits),
3226
      .async_reset    (reset)
3227
  ) ;
3228
  always@(posedge pci_clk or posedge reset)
3229
  begin
3230
      if (reset)
3231
          sync_cache_lsize_to_pci_bits <= 6'b0 ;
3232
      else
3233
          sync_cache_lsize_to_pci_bits <= meta_cache_lsize_to_pci_bits ;
3234
  end
3235
  wire [7:2] sync_cache_line_size_to_pci_reg    = sync_cache_lsize_to_pci_bits[7:2] ;
3236
  wire [7:2] sync_cache_line_size_to_wb_reg             = cache_line_size_reg[7:2] ;
3237
  wire           sync_cache_lsize_not_zero_to_wb        = cache_lsize_not_zero ;
3238
// Latency timer is sinchronized only to PCI clock when bridge implementation is HOST
3239
  wire [7:0] latency_timer_bits = latency_timer ;
3240
  wire [7:0] meta_latency_timer_bits ;
3241
  reg  [7:0] sync_latency_timer_bits ;
3242 88 mihad
  synchronizer_flop   #(8, 0)  latency_timer_bits_sync
3243 77 mihad
  (
3244
      .data_in        (latency_timer_bits),
3245
      .clk_out        (pci_clk),
3246
      .sync_data_out  (meta_latency_timer_bits),
3247
      .async_reset    (reset)
3248
  ) ;
3249
  always@(posedge pci_clk or posedge reset)
3250
  begin
3251
      if (reset)
3252
          sync_latency_timer_bits <= 8'b0 ;
3253
      else
3254
          sync_latency_timer_bits <= meta_latency_timer_bits ;
3255
  end
3256
  wire [7:0] sync_latency_timer = sync_latency_timer_bits ;
3257
`else   // GUEST
3258
  wire [8:2] cache_lsize_to_wb_bits = { cache_lsize_not_zero, cache_line_size_reg[7:2] } ;
3259
  wire [8:2] meta_cache_lsize_to_wb_bits ;
3260
  reg  [8:2] sync_cache_lsize_to_wb_bits ;
3261 88 mihad
  synchronizer_flop   #(7, 0)  cache_lsize_to_wb_bits_sync
3262 77 mihad
  (
3263
      .data_in        (cache_lsize_to_wb_bits),
3264
      .clk_out        (wb_clk),
3265
      .sync_data_out  (meta_cache_lsize_to_wb_bits),
3266
      .async_reset    (reset)
3267
  ) ;
3268
  always@(posedge wb_clk or posedge reset)
3269
  begin
3270
      if (reset)
3271
          sync_cache_lsize_to_wb_bits <= 7'b0 ;
3272
      else
3273
          sync_cache_lsize_to_wb_bits <= meta_cache_lsize_to_wb_bits ;
3274
  end
3275
  wire [7:2] sync_cache_line_size_to_pci_reg    = cache_line_size_reg[7:2] ;
3276
  wire [7:2] sync_cache_line_size_to_wb_reg             = sync_cache_lsize_to_wb_bits[7:2] ;
3277
  wire           sync_cache_lsize_not_zero_to_wb        = sync_cache_lsize_to_wb_bits[8] ;
3278
// Latency timer
3279
  wire [7:0] sync_latency_timer = latency_timer ;
3280
`endif
3281
// PCI header output from cache_line_size, latency timer and interrupt pin
3282
assign          cache_line_size_to_pci          = {sync_cache_line_size_to_pci_reg, 2'h0} ;  // [7 : 0] to PCI clock
3283
assign          cache_line_size_to_wb           = {sync_cache_line_size_to_wb_reg, 2'h0} ;   // [7 : 0] to WB clock
3284
assign          cache_lsize_not_zero_to_wb      = sync_cache_lsize_not_zero_to_wb ;
3285
 
3286
assign          latency_tim[7 : 0]     = sync_latency_timer ;                    // to PCI clock
3287
//assign                int_pin[2 : 0]         = r_interrupt_pin ;
3288
assign          int_out                            = interrupt_out ;
3289
// PCI output from image registers
3290
//   base address, address mask, translation address and control registers are sinchronized in PCI_DECODER.V module
3291
assign          pci_base_addr0 = pci_ba0_bit31_12[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
3292
assign          pci_base_addr1 = pci_ba1_bit31_12[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
3293
assign          pci_base_addr2 = pci_ba2_bit31_12[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
3294
assign          pci_base_addr3 = pci_ba3_bit31_12[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
3295
assign          pci_base_addr4 = pci_ba4_bit31_12[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
3296
assign          pci_base_addr5 = pci_ba5_bit31_12[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
3297
assign          pci_memory_io0 = pci_ba0_bit0 ;
3298
assign          pci_memory_io1 = pci_ba1_bit0 ;
3299
assign          pci_memory_io2 = pci_ba2_bit0 ;
3300
assign          pci_memory_io3 = pci_ba3_bit0 ;
3301
assign          pci_memory_io4 = pci_ba4_bit0 ;
3302
assign          pci_memory_io5 = pci_ba5_bit0 ;
3303
assign          pci_addr_mask0 = pci_am0[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
3304
assign          pci_addr_mask1 = pci_am1[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
3305
assign          pci_addr_mask2 = pci_am2[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
3306
assign          pci_addr_mask3 = pci_am3[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
3307
assign          pci_addr_mask4 = pci_am4[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
3308
assign          pci_addr_mask5 = pci_am5[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
3309
assign          pci_tran_addr0 = pci_ta0[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
3310
assign          pci_tran_addr1 = pci_ta1[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
3311
assign          pci_tran_addr2 = pci_ta2[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
3312
assign          pci_tran_addr3 = pci_ta3[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
3313
assign          pci_tran_addr4 = pci_ta4[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
3314
assign          pci_tran_addr5 = pci_ta5[31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)] ;
3315
assign          pci_img_ctrl0[2 : 1] = pci_img_ctrl0_bit2_1 ;
3316
assign          pci_img_ctrl1[2 : 1] = pci_img_ctrl1_bit2_1 ;
3317
assign          pci_img_ctrl2[2 : 1] = pci_img_ctrl2_bit2_1 ;
3318
assign          pci_img_ctrl3[2 : 1] = pci_img_ctrl3_bit2_1 ;
3319
assign          pci_img_ctrl4[2 : 1] = pci_img_ctrl4_bit2_1 ;
3320
assign          pci_img_ctrl5[2 : 1] = pci_img_ctrl5_bit2_1 ;
3321
// WISHBONE output from image registers
3322
//   base address, address mask, translation address and control registers are sinchronized in DECODER.V module
3323
assign          wb_base_addr0 = wb_ba0_bit31_12[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
3324
assign          wb_base_addr1 = wb_ba1_bit31_12[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
3325
assign          wb_base_addr2 = wb_ba2_bit31_12[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
3326
assign          wb_base_addr3 = wb_ba3_bit31_12[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
3327
assign          wb_base_addr4 = wb_ba4_bit31_12[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
3328
assign          wb_base_addr5 = wb_ba5_bit31_12[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
3329
assign          wb_memory_io0 = wb_ba0_bit0 ;
3330
assign          wb_memory_io1 = wb_ba1_bit0 ;
3331
assign          wb_memory_io2 = wb_ba2_bit0 ;
3332
assign          wb_memory_io3 = wb_ba3_bit0 ;
3333
assign          wb_memory_io4 = wb_ba4_bit0 ;
3334
assign          wb_memory_io5 = wb_ba5_bit0 ;
3335
assign          wb_addr_mask0 = wb_am0[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
3336
assign          wb_addr_mask1 = wb_am1[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
3337
assign          wb_addr_mask2 = wb_am2[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
3338
assign          wb_addr_mask3 = wb_am3[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
3339
assign          wb_addr_mask4 = wb_am4[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
3340
assign          wb_addr_mask5 = wb_am5[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
3341
assign          wb_tran_addr0 = wb_ta0[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
3342
assign          wb_tran_addr1 = wb_ta1[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
3343
assign          wb_tran_addr2 = wb_ta2[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
3344
assign          wb_tran_addr3 = wb_ta3[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
3345
assign          wb_tran_addr4 = wb_ta4[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
3346
assign          wb_tran_addr5 = wb_ta5[31:(32-`WB_NUM_OF_DEC_ADDR_LINES)] ;
3347
assign          wb_img_ctrl0[2 : 0] = wb_img_ctrl0_bit2_0 ;
3348
assign          wb_img_ctrl1[2 : 0] = wb_img_ctrl1_bit2_0 ;
3349
assign          wb_img_ctrl2[2 : 0] = wb_img_ctrl2_bit2_0 ;
3350
assign          wb_img_ctrl3[2 : 0] = wb_img_ctrl3_bit2_0 ;
3351
assign          wb_img_ctrl4[2 : 0] = wb_img_ctrl4_bit2_0 ;
3352
assign          wb_img_ctrl5[2 : 0] = wb_img_ctrl5_bit2_0 ;
3353
// GENERAL output from conf. cycle generation register & int. control register
3354
assign          config_addr[23 : 0] = { cnf_addr_bit23_2, 1'b0, cnf_addr_bit0 } ;
3355
assign          icr_soft_res = icr_bit31 ;
3356
 
3357
 
3358
endmodule
3359
 

powered by: WebSVN 2.1.0

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