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

Subversion Repositories pci

[/] [pci/] [tags/] [rel_3/] [rtl/] [verilog/] [pci_target32_interface.v] - Blame information for rev 154

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 mihad
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  File name: pci_target32_interface.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 Markovic, tadej@opencores.org                   ////
10
////                                                              ////
11
////  All additional information is avaliable in the README.txt   ////
12
////  file.                                                       ////
13
////                                                              ////
14
////                                                              ////
15
//////////////////////////////////////////////////////////////////////
16
////                                                              ////
17
//// Copyright (C) 2000 Tadej Markovic, tadej@opencores.org       ////
18
////                                                              ////
19
//// This source file may be used and distributed without         ////
20
//// restriction provided that this copyright statement is not    ////
21
//// removed from the file and that any derivative work contains  ////
22
//// the original copyright notice and the associated disclaimer. ////
23
////                                                              ////
24
//// This source file is free software; you can redistribute it   ////
25
//// and/or modify it under the terms of the GNU Lesser General   ////
26
//// Public License as published by the Free Software Foundation; ////
27
//// either version 2.1 of the License, or (at your option) any   ////
28
//// later version.                                               ////
29
////                                                              ////
30
//// This source is distributed in the hope that it will be       ////
31
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
32
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
33
//// PURPOSE.  See the GNU Lesser General Public License for more ////
34
//// details.                                                     ////
35
////                                                              ////
36
//// You should have received a copy of the GNU Lesser General    ////
37
//// Public License along with this source; if not, download it   ////
38
//// from http://www.opencores.org/lgpl.shtml                     ////
39
////                                                              ////
40
//////////////////////////////////////////////////////////////////////
41
//
42
// CVS Revision History
43
//
44
// $Log: not supported by cvs2svn $
45 73 mihad
// Revision 1.5  2002/08/22 13:28:04  mihad
46
// Updated for synthesis purposes. Gate level simulation was failing in some configurations
47
//
48 53 mihad
// Revision 1.4  2002/02/19 16:32:37  mihad
49
// Modified testbench and fixed some bugs
50
//
51 26 mihad
// Revision 1.3  2002/02/01 15:25:12  mihad
52
// Repaired a few bugs, updated specification, added test bench files and design document
53
//
54 21 mihad
// Revision 1.2  2001/10/05 08:14:30  mihad
55
// Updated all files with inclusion of timescale file for simulation purposes.
56
//
57 6 mihad
// Revision 1.1.1.1  2001/10/02 15:33:47  mihad
58
// New project directory structure
59 2 mihad
//
60 6 mihad
//
61 2 mihad
 
62
`include "bus_commands.v"
63 21 mihad
`include "pci_constants.v"
64
 
65
// synopsys translate_off
66 6 mihad
`include "timescale.v"
67 21 mihad
// synopsys translate_on
68 2 mihad
 
69
module PCI_TARGET32_INTERFACE
70
(
71
    // system inputs
72
    clk_in,
73
    reset_in,
74 21 mihad
 
75 2 mihad
    // PCI Target side of INTERFACE
76
    address_in,
77
    addr_claim_out,
78
    bc_in,
79
    bc0_in,
80
    data_in,
81
    data_out,
82
    be_in,
83
    req_in,
84
    rdy_in,
85
    addr_phase_in,
86 21 mihad
    bckp_devsel_in,
87 2 mihad
    bckp_trdy_in,
88 21 mihad
    bckp_stop_in,
89 2 mihad
    last_reg_in,
90
    frame_reg_in,
91
    fetch_pcir_fifo_in,
92
    load_medium_reg_in,
93
    sel_fifo_mreg_in,
94
    sel_conf_fifo_in,
95
    fetch_conf_in,
96
    load_to_pciw_fifo_in,
97
    load_to_conf_in,
98
    same_read_out,
99
 
100
        norm_access_to_config_out,
101
        read_completed_out,
102
        read_processing_out,
103
        target_abort_out,
104
        disconect_wo_data_out,
105 21 mihad
        disconect_w_data_out,
106 2 mihad
        pciw_fifo_full_out,
107
        pcir_fifo_data_err_out,
108
        wbw_fifo_empty_out,
109 21 mihad
        wbu_del_read_comp_pending_out,
110
 
111 2 mihad
        // Delayed synchronizacion module signals
112 21 mihad
        req_out,
113
    done_out,
114 2 mihad
    in_progress_out,
115 21 mihad
        req_req_pending_in,
116 2 mihad
    req_comp_pending_in,
117 21 mihad
        addr_out,
118
    be_out,
119
    we_out,
120
    bc_out,
121
    burst_ok_out,
122 2 mihad
        strd_addr_in,
123
        strd_bc_in,
124
    status_in,
125
    comp_flush_in,
126
 
127
        // FIFO signals
128 21 mihad
        pcir_fifo_renable_out,
129
        pcir_fifo_data_in,
130
        pcir_fifo_be_in,
131 2 mihad
        pcir_fifo_control_in,
132 21 mihad
        pcir_fifo_flush_out,
133
        pcir_fifo_almost_empty_in,
134 2 mihad
        pcir_fifo_empty_in,
135 21 mihad
        pciw_fifo_wenable_out,
136
        pciw_fifo_addr_data_out,
137
        pciw_fifo_cbe_out,
138
        pciw_fifo_control_out,
139
        pciw_fifo_two_left_in,
140 2 mihad
        pciw_fifo_almost_full_in,
141
        pciw_fifo_full_in,
142
        wbw_fifo_empty_in,
143 21 mihad
        wbu_del_read_comp_pending_in,
144
 
145 2 mihad
        // Configuration space signals
146
        conf_hit_out,
147
        conf_addr_out,
148
        conf_data_out,
149
        conf_data_in,
150
        conf_be_out,
151
        conf_we_out,
152
        conf_re_out,
153
        mem_enable_in,
154
        io_enable_in,
155
        mem_io_addr_space0_in,
156
        mem_io_addr_space1_in,
157
        mem_io_addr_space2_in,
158
        mem_io_addr_space3_in,
159
        mem_io_addr_space4_in,
160
        mem_io_addr_space5_in,
161
        pre_fetch_en0_in,
162
        pre_fetch_en1_in,
163
        pre_fetch_en2_in,
164
        pre_fetch_en3_in,
165
        pre_fetch_en4_in,
166
        pre_fetch_en5_in,
167
        pci_base_addr0_in,
168
        pci_base_addr1_in,
169
        pci_base_addr2_in,
170
        pci_base_addr3_in,
171
        pci_base_addr4_in,
172
        pci_base_addr5_in,
173
        pci_addr_mask0_in,
174
        pci_addr_mask1_in,
175
        pci_addr_mask2_in,
176
        pci_addr_mask3_in,
177
        pci_addr_mask4_in,
178
        pci_addr_mask5_in,
179
        pci_tran_addr0_in,
180
        pci_tran_addr1_in,
181
        pci_tran_addr2_in,
182
        pci_tran_addr3_in,
183
        pci_tran_addr4_in,
184
        pci_tran_addr5_in,
185
        addr_tran_en0_in,
186
        addr_tran_en1_in,
187
        addr_tran_en2_in,
188
        addr_tran_en3_in,
189
        addr_tran_en4_in,
190
        addr_tran_en5_in
191
) ;
192
 
193
/*==================================================================================================================
194
System inputs.
195
==================================================================================================================*/
196
// PCI side clock and reset
197
input   clk_in,
198
        reset_in ;
199
 
200
 
201
/*==================================================================================================================
202 21 mihad
Side of the PCI Target state machine
203 2 mihad
==================================================================================================================*/
204
// Data, byte enables, bus commands and address ports
205
input   [31:0]   address_in ;            // current request address input - registered
206
output          addr_claim_out ;        // current request address claim output
207
input   [3:0]   bc_in ;                          // current request bus command input - registered
208
input                   bc0_in ;                        // current cycle RW signal
209
output  [31:0]  data_out ;                       // for read operations - current dataphase data output
210
input   [31:0]  data_in ;                        // for write operations - current request data input - registered
211
input   [3:0]    be_in ;                         // current dataphase byte enable inputs - registered
212
// Port connection control signals from PCI FSM
213
input           req_in ;                // Read is requested to WB master from PCI side
214
input           rdy_in ;                // DATA / ADDRESS selection from PCI side when read or write - registered
215
input                   addr_phase_in ;         // Indicates address phase and also fast-back-to-back address phase - registered
216 21 mihad
input                   bckp_devsel_in ;        // DEVSEL input (which is registered) equivalent
217
input                   bckp_trdy_in ;          // TRDY input (which is registered) equivalent
218
input                   bckp_stop_in ;          // STOP input (which is registered) equivalent
219 2 mihad
input               last_reg_in ;               // Indicates last data phase - registered
220
input                   frame_reg_in ;          // FRAME input signal - registered
221
input               fetch_pcir_fifo_in ;// Read enable for PCIR_FIFO when when read is finishen on WB side
222
input               load_medium_reg_in ;// Load data from PCIR_FIFO to medium register (first data must be prepared on time)
223
input               sel_fifo_mreg_in ;  // Read data selection between PCIR_FIFO and medium register
224
input               sel_conf_fifo_in ;  // Read data selection between Configuration registers and "FIFO"
225
input               fetch_conf_in ;             // Read enable for configuration space registers
226
input               load_to_pciw_fifo_in ;// Write enable to PCIW_FIFO
227
input               load_to_conf_in ;   // Write enable to Configuration space registers
228
 
229
 
230
/*==================================================================================================================
231
Status outputs to PCI side (FSM)
232
==================================================================================================================*/
233
output                  same_read_out ;                         // Indicates the same read request (important when read is finished on WB side)
234
output                  norm_access_to_config_out ;     // Indicates the access to Configuration space with MEMORY commands
235
output                  read_completed_out ;            // Indicates that read request is completed on WB side
236
output                  read_processing_out ;           // Indicates that read request is processing on WB side
237
output                  target_abort_out ;                      // Indicates target abort termination
238 21 mihad
output                  disconect_wo_data_out ;         // Indicates disconnect without data termination
239
output                  disconect_w_data_out ;          // Indicates disconnect with data termination
240 2 mihad
output                  pciw_fifo_full_out ;            // Indicates that write PCIW_FIFO is full
241
output                  pcir_fifo_data_err_out ;        // Indicates data error on current data read from PCIR_FIFO
242
output                  wbw_fifo_empty_out ;            // Indicates that WB SLAVE has no data to be written to PCI bus
243 21 mihad
output                  wbu_del_read_comp_pending_out ; // Indicates that WB Unit has a delayed read poending!
244 2 mihad
 
245
/*==================================================================================================================
246
Read request interface through Delayed sinchronization module to WB Master
247
==================================================================================================================*/
248
// request, completion, done and progress indicator outputs for delayed_sync module where they are synchronized
249
output                  req_out,                // request qualifier - when 1 it indicates that valid data is provided on outputs
250
                        done_out,               // done output - when 1 indicates that PCI Target has completed a cycle on its bus
251 21 mihad
                        in_progress_out ;       // out progress indicator - indicates that current completion is in progress on
252 2 mihad
                                                                        //   PCI Target side
253
// pending indication inputs - PCI Target side must know about requests and completions
254
input                   req_req_pending_in ;    // request pending input for PCI Target side
255
input                   req_comp_pending_in ;   // completion pending input for PCI Target side - it indicates when completion
256
                                                                                //   is ready for completing on PCI Target bus
257
// various data outputs - PCI Target sets address, bus command, byte enables, write enable and burst
258
output  [31:0]   addr_out ;   // address bus output
259
output  [3:0]    be_out ;     // byte enable output
260
output          we_out ;     // write enable output - read/write request indication 1 = write request / 0 = read request
261
output  [3:0]    bc_out ;     // bus command output
262 21 mihad
output                  burst_ok_out ;  // pre-fetch enable & burst read - qualifies pre-fetch for access to current image space
263 2 mihad
 
264
// completion side signals encoded termination status - 0 = normal completion / 1 = error terminated completion
265
input   [31:0]   strd_addr_in ;  // Stored requested read access address
266
input   [3:0]    strd_bc_in ;    // Stored requested read access bus command
267
input                   status_in ;     // Error status reported - NOT USED because FIFO control bits determin data error status
268
input               comp_flush_in ;     // If completition counter (2^16 clk periods) has expired, PCIR_FIFO must flush data
269
 
270
 
271
/*==================================================================================================================
272
PCIR_PCIW_FIFO signals from pci side
273
==================================================================================================================*/
274 21 mihad
// PCIR_FIFO control signals used for fetching data from PCIR_FIFO
275 2 mihad
output                  pcir_fifo_renable_out ;                 // read enable output to PCIR_FIFO
276
input   [31:0]   pcir_fifo_data_in ;                             // data input from PCIR_FIFO
277
input   [3:0]    pcir_fifo_be_in ;                               // byte enable input from PCIR_FIFO
278
input   [3:0]    pcir_fifo_control_in ;                  // control signals input from PCIR_FIFO
279
output                  pcir_fifo_flush_out ;                   // flush PCIR_FIFO
280
input                   pcir_fifo_almost_empty_in ;             // almost empty indicator from PCIR_FIFO
281
input                   pcir_fifo_empty_in ;                    // empty indicator
282
 
283
// PCIW_FIFO control signals used for sinking data into PCIW_FIFO and status monitoring
284
output                  pciw_fifo_wenable_out ;         // write enable output to PCIW_FIFO
285
output  [31:0]   pciw_fifo_addr_data_out ;       // address / data output signals to PCIW_FIFO
286
output  [3:0]    pciw_fifo_cbe_out ;                     // command / byte enable signals to PCIW_FIFO
287
output  [3:0]    pciw_fifo_control_out ;         // control signals to PCIW_FIFO
288 21 mihad
input                   pciw_fifo_two_left_in ;         // two data spaces left in PCIW_FIFO
289 2 mihad
input                   pciw_fifo_almost_full_in ;      // almost full indicator from PCIW_FIFO
290
input                   pciw_fifo_full_in ;                     // full indicator from PCIW_FIFO
291
 
292
// WBW_FIFO empy control signal used when delayed read is complete in PCIR_FIFO
293
input                   wbw_fifo_empty_in ;                     // empty indicator from WBW_FIFO
294 21 mihad
input                   wbu_del_read_comp_pending_in ; // delayed read pending indicator from WB Unit
295 2 mihad
 
296
 
297
/*==================================================================================================================
298
Configuration space signals - from and to registers
299
==================================================================================================================*/
300
// BUS for reading and writing to configuration space registers
301
output                  conf_hit_out ;  // like "chip select" for configuration space
302
output  [11:0]   conf_addr_out ; // address to configuration space when there is access to it
303
output  [31:0]   conf_data_out ; // data to configuration space - for writing to registers
304
input   [31:0]   conf_data_in ;  // data from configuration space - for reading from registers
305
output  [3:0]    conf_be_out ;   // byte enables used for correct writing to configuration space
306
output                  conf_we_out ;   // write enable control signal - 1 for writing / 0 for nothing
307
output                  conf_re_out ;   // read enable control signal - 1 for reading / 0 for nothing
308
 
309
// Inputs for image control registers
310
input                   mem_enable_in ; // allowed access to memory mapped image
311
input                   io_enable_in ;  // allowed access to io mapped image
312
 
313
// Inputs needed for determining if image is assigned to memory or io space with pre-fetch and address translation
314 21 mihad
input                   mem_io_addr_space0_in ; // bit-0 in pci_base_addr0 register
315
input                   mem_io_addr_space1_in ; // bit-0 in pci_base_addr1 register
316
input                   mem_io_addr_space2_in ; // bit-0 in pci_base_addr2 register
317
input                   mem_io_addr_space3_in ; // bit-0 in pci_base_addr3 register
318
input                   mem_io_addr_space4_in ; // bit-0 in pci_base_addr4 register
319 2 mihad
input                   mem_io_addr_space5_in ; // bit-0 in pci_base_addr5 register
320
input                   pre_fetch_en0_in ;      // bit-1 in pci_image_ctr0 register
321
input                   pre_fetch_en1_in ;      // bit-1 in pci_image_ctr1 register
322
input                   pre_fetch_en2_in ;      // bit-1 in pci_image_ctr2 register
323
input                   pre_fetch_en3_in ;      // bit-1 in pci_image_ctr3 register
324
input                   pre_fetch_en4_in ;      // bit-1 in pci_image_ctr4 register
325
input                   pre_fetch_en5_in ;      // bit-1 in pci_image_ctr5 register
326
 
327
// Input from image registers - register values needed for decoder to work properly
328
input   [31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)]    pci_base_addr0_in ;     // base address from base address register
329
input   [31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)]    pci_base_addr1_in ; // base address from base address register
330
input   [31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)]    pci_base_addr2_in ; // base address from base address register
331
input   [31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)]    pci_base_addr3_in ; // base address from base address register
332
input   [31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)]    pci_base_addr4_in ; // base address from base address register
333
input   [31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)]    pci_base_addr5_in ; // base address from base address register
334
input   [31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)]    pci_addr_mask0_in ; // masking of base address from address mask register
335
input   [31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)]    pci_addr_mask1_in ; // masking of base address from address mask register
336
input   [31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)]    pci_addr_mask2_in ; // masking of base address from address mask register
337
input   [31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)]    pci_addr_mask3_in ; // masking of base address from address mask register
338
input   [31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)]    pci_addr_mask4_in ; // masking of base address from address mask register
339
input   [31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)]    pci_addr_mask5_in ; // masking of base address from address mask register
340
input   [31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)]    pci_tran_addr0_in ; // translation address from address translation register
341
input   [31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)]    pci_tran_addr1_in ; // translation address from address translation register
342
input   [31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)]    pci_tran_addr2_in ; // translation address from address translation register
343
input   [31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)]    pci_tran_addr3_in ; // translation address from address translation register
344
input   [31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)]    pci_tran_addr4_in ; // translation address from address translation register
345
input   [31:(32-`PCI_NUM_OF_DEC_ADDR_LINES)]    pci_tran_addr5_in ; // translation address from address translation register
346
 
347
input                   addr_tran_en0_in ;      // address translation enable bit
348
input                   addr_tran_en1_in ;      // address translation enable bit
349
input                   addr_tran_en2_in ;      // address translation enable bit
350
input                   addr_tran_en3_in ;      // address translation enable bit
351
input                   addr_tran_en4_in ;      // address translation enable bit
352
input                   addr_tran_en5_in ;      // address translation enable bit
353
 
354
/*==================================================================================================================
355
END of input / output PORT DEFINITONS !!!
356
==================================================================================================================*/
357
 
358
// address output from address multiplexer
359
reg             [31:0]   address ;
360
// prefetch enable for access to selected image space
361
reg                             pre_fetch_en ;
362
 
363
// Input addresses and image hits from address decoders - addresses are multiplexed to address
364 21 mihad
`ifdef                  HOST
365
        `ifdef          NO_CNF_IMAGE
366
                `ifdef  PCI_IMAGE0      // if PCI bridge is HOST and IMAGE0 is assigned as general image space
367 2 mihad
wire                    hit0_in ;
368
wire    [31:0]   address0_in ;
369 21 mihad
wire                    pre_fetch_en0 = pre_fetch_en0_in ;
370
                `else
371
wire                    hit0_in         = 1'b0 ;
372
wire    [31:0]   address0_in     = 32'h0 ;
373
wire                    pre_fetch_en0 = 1'b0 ;
374
                `endif
375
        `else
376
wire                    hit0_in ;
377
wire    [31:0]   address0_in ;
378
wire                    pre_fetch_en0 = pre_fetch_en0_in ;
379
        `endif
380
`else // GUEST
381
wire                    hit0_in ;
382
wire    [31:0]   address0_in ;
383
wire                    pre_fetch_en0 = pre_fetch_en0_in ;
384
`endif
385
 
386 2 mihad
wire                    hit1_in ;
387
wire    [31:0]   address1_in ;
388 21 mihad
wire                    pre_fetch_en1 = pre_fetch_en1_in ;
389
 
390
`ifdef          PCI_IMAGE2
391 2 mihad
wire                    hit2_in ;
392
wire    [31:0]   address2_in ;
393 21 mihad
wire                    pre_fetch_en2 = pre_fetch_en2_in ;
394
`else
395
wire                    hit2_in         = 1'b0 ;
396
wire    [31:0]   address2_in     = 32'h0 ;
397
wire                    pre_fetch_en2 = 1'b0 ;
398 2 mihad
`endif
399 21 mihad
 
400 2 mihad
`ifdef          PCI_IMAGE3
401
wire                    hit3_in ;
402
wire    [31:0]   address3_in ;
403 21 mihad
wire                    pre_fetch_en3 = pre_fetch_en3_in ;
404
`else
405
wire                    hit3_in         = 1'b0 ;
406
wire    [31:0]   address3_in     = 32'h0 ;
407
wire                    pre_fetch_en3 = 1'b0 ;
408 2 mihad
`endif
409 21 mihad
 
410 2 mihad
`ifdef          PCI_IMAGE4
411
wire                    hit4_in ;
412
wire    [31:0]   address4_in ;
413 21 mihad
wire                    pre_fetch_en4 = pre_fetch_en4_in ;
414
`else
415
wire                    hit4_in         = 1'b0 ;
416
wire    [31:0]   address4_in     = 32'h0 ;
417
wire                    pre_fetch_en4 = 1'b0 ;
418 2 mihad
`endif
419 21 mihad
 
420 2 mihad
`ifdef          PCI_IMAGE5
421
wire                    hit5_in ;
422
wire    [31:0]   address5_in ;
423 21 mihad
wire                    pre_fetch_en5 = pre_fetch_en5_in ;
424
`else
425
wire                    hit5_in         = 1'b0 ;
426
wire    [31:0]   address5_in     = 32'h0 ;
427
wire                    pre_fetch_en5 = 1'b0 ;
428 2 mihad
`endif
429
 
430
// Include address decoders
431 21 mihad
`ifdef                  HOST
432
        `ifdef          NO_CNF_IMAGE
433
                `ifdef  PCI_IMAGE0      // if PCI bridge is HOST and IMAGE0 is assigned as general image space
434
        PCI_DECODER   #(`PCI_NUM_OF_DEC_ADDR_LINES) decoder0
435
                                   (.hit                        (hit0_in),
436
                                        .addr_out               (address0_in),
437
                                        .addr_in                (address_in),
438
                                        .bc_in                  (bc_in),
439 2 mihad
                                        .base_addr              (pci_base_addr0_in),
440 21 mihad
                                        .mask_addr              (pci_addr_mask0_in),
441
                                        .tran_addr              (pci_tran_addr0_in),
442 2 mihad
                                        .at_en                  (addr_tran_en0_in),
443 21 mihad
                                        .mem_io_space   (mem_io_addr_space0_in),
444
                                        .mem_en                 (mem_enable_in),
445 2 mihad
                                        .io_en                  (io_enable_in)
446
                                        ) ;
447 21 mihad
                `endif
448
        `else
449
        PCI_DECODER   #(`PCI_NUM_OF_DEC_ADDR_LINES) decoder0
450
                                   (.hit                        (hit0_in),
451
                                        .addr_out               (address0_in),
452
                                        .addr_in                (address_in),
453
                                        .bc_in                  (bc_in),
454
                                        .base_addr              (pci_base_addr0_in),
455
                                        .mask_addr              (pci_addr_mask0_in),
456
                                        .tran_addr              (pci_tran_addr0_in),
457
                                        .at_en                  (addr_tran_en0_in),
458
                                        .mem_io_space   (mem_io_addr_space0_in),
459
                                        .mem_en                 (mem_enable_in),
460
                                        .io_en                  (io_enable_in)
461
                                        ) ;
462
        `endif
463
`else // GUEST
464
        PCI_DECODER   #(`PCI_NUM_OF_DEC_ADDR_LINES) decoder0
465
                                   (.hit                        (hit0_in),
466
                                        .addr_out               (address0_in),
467
                                        .addr_in                (address_in),
468
                                        .bc_in                  (bc_in),
469
                                        .base_addr              (pci_base_addr0_in),
470
                                        .mask_addr              (pci_addr_mask0_in),
471
                                        .tran_addr              (pci_tran_addr0_in),
472
                                        .at_en                  (addr_tran_en0_in),
473
                                        .mem_io_space   (mem_io_addr_space0_in),
474
                                        .mem_en                 (mem_enable_in),
475
                                        .io_en                  (io_enable_in)
476
                                        ) ;
477
`endif
478
        PCI_DECODER   #(`PCI_NUM_OF_DEC_ADDR_LINES) decoder1
479
                                   (.hit                        (hit1_in),
480
                                        .addr_out               (address1_in),
481
                                        .addr_in                (address_in),
482
                                        .bc_in                  (bc_in),
483 2 mihad
                                        .base_addr              (pci_base_addr1_in),
484 21 mihad
                                        .mask_addr              (pci_addr_mask1_in),
485
                                        .tran_addr              (pci_tran_addr1_in),
486
                                        .at_en                  (addr_tran_en1_in),
487
                                        .mem_io_space   (mem_io_addr_space1_in),
488
                                        .mem_en                 (mem_enable_in),
489 2 mihad
                                        .io_en                  (io_enable_in)
490
                                        ) ;
491 21 mihad
`ifdef          PCI_IMAGE2
492 2 mihad
        PCI_DECODER   #(`PCI_NUM_OF_DEC_ADDR_LINES) decoder2
493 21 mihad
                                   (.hit                        (hit2_in),
494
                                        .addr_out               (address2_in),
495
                                        .addr_in                (address_in),
496
                                        .bc_in                  (bc_in),
497 2 mihad
                                        .base_addr              (pci_base_addr2_in),
498 21 mihad
                                        .mask_addr              (pci_addr_mask2_in),
499
                                        .tran_addr              (pci_tran_addr2_in),
500
                                        .at_en                  (addr_tran_en2_in),
501
                                        .mem_io_space   (mem_io_addr_space2_in),
502
                                        .mem_en                 (mem_enable_in),
503 2 mihad
                                        .io_en                  (io_enable_in)
504
                                        ) ;
505
`endif
506
`ifdef          PCI_IMAGE3
507 21 mihad
        PCI_DECODER   #(`PCI_NUM_OF_DEC_ADDR_LINES) decoder3
508
                                   (.hit                        (hit3_in),
509
                                        .addr_out               (address3_in),
510
                                        .addr_in                (address_in),
511
                                        .bc_in                  (bc_in),
512 2 mihad
                                        .base_addr              (pci_base_addr3_in),
513 21 mihad
                                        .mask_addr              (pci_addr_mask3_in),
514
                                        .tran_addr              (pci_tran_addr3_in),
515
                                        .at_en                  (addr_tran_en3_in),
516
                                        .mem_io_space   (mem_io_addr_space3_in),
517
                                        .mem_en                 (mem_enable_in),
518 2 mihad
                                        .io_en                  (io_enable_in)
519
                                        ) ;
520
`endif
521
`ifdef          PCI_IMAGE4
522 21 mihad
        PCI_DECODER   #(`PCI_NUM_OF_DEC_ADDR_LINES) decoder4
523
                                   (.hit                        (hit4_in),
524
                                        .addr_out               (address4_in),
525
                                        .addr_in                (address_in),
526
                                        .bc_in                  (bc_in),
527 2 mihad
                                        .base_addr              (pci_base_addr4_in),
528 21 mihad
                                        .mask_addr              (pci_addr_mask4_in),
529
                                        .tran_addr              (pci_tran_addr4_in),
530
                                        .at_en                  (addr_tran_en4_in),
531
                                        .mem_io_space   (mem_io_addr_space4_in),
532
                                        .mem_en                 (mem_enable_in),
533 2 mihad
                                        .io_en                  (io_enable_in)
534
                                        ) ;
535
`endif
536
`ifdef          PCI_IMAGE5
537 21 mihad
        PCI_DECODER   #(`PCI_NUM_OF_DEC_ADDR_LINES) decoder5
538
                                   (.hit                        (hit5_in),
539
                                        .addr_out               (address5_in),
540
                                        .addr_in                (address_in),
541
                                        .bc_in                  (bc_in),
542 2 mihad
                                        .base_addr              (pci_base_addr5_in),
543 21 mihad
                                        .mask_addr              (pci_addr_mask5_in),
544
                                        .tran_addr              (pci_tran_addr5_in),
545
                                        .at_en                  (addr_tran_en5_in),
546
                                        .mem_io_space   (mem_io_addr_space5_in),
547
                                        .mem_en                 (mem_enable_in),
548 2 mihad
                                        .io_en                  (io_enable_in)
549
                                        ) ;
550
`endif
551
 
552
// Internal signals for image hit determination
553
reg                             addr_claim ;// address claim signal is asinchronous set for addr_claim_out signal to PCI Target SM
554
 
555
// Determining if image 0 is assigned to configuration space or as normal pci to wb access!
556
//   if normal access is allowed to configuration space, then hit0 is hit0_conf
557
`ifdef          HOST
558 21 mihad
        `ifdef  NO_CNF_IMAGE
559
                        parameter       hit0_conf = 1'b0 ;
560 2 mihad
        `else
561 21 mihad
                        parameter       hit0_conf = 1'b1 ;      // if normal access is allowed to configuration space, then hit0 is hit0_conf
562 2 mihad
        `endif
563 21 mihad
`else // GUEST
564
                        parameter       hit0_conf = 1'b1 ;      // if normal access is allowed to configuration space, then hit0 is hit0_conf
565 2 mihad
`endif
566
 
567
// Logic with address mux, determining if address is still in the same image space and if it is prefetced or not
568 21 mihad
always@(hit5_in or     hit4_in or     hit3_in or     hit2_in or     hit1_in or     hit0_in or
569
                address5_in or address4_in or address3_in or address2_in or address1_in or address0_in or
570
                pre_fetch_en5 or
571
                pre_fetch_en4 or
572
                pre_fetch_en3 or
573
                pre_fetch_en2 or
574
                pre_fetch_en1 or
575
                pre_fetch_en0
576
                )
577
begin
578
        addr_claim <= (hit5_in || hit4_in) || (hit3_in || hit2_in || hit1_in || hit0_in) ;
579
        case ({hit5_in, hit4_in, hit3_in, hit2_in, hit0_in})
580
        5'b10000 :
581 2 mihad
        begin
582 21 mihad
                address <= address5_in ;
583
                pre_fetch_en <= pre_fetch_en5 ;
584 2 mihad
        end
585 21 mihad
        5'b01000 :
586
        begin
587
                address <= address4_in ;
588
                pre_fetch_en <= pre_fetch_en4 ;
589
        end
590
        5'b00100 :
591
        begin
592
                address <= address3_in ;
593
                pre_fetch_en <= pre_fetch_en3 ;
594
        end
595
        5'b00010 :
596
        begin
597
                address <= address2_in ;
598
                pre_fetch_en <= pre_fetch_en2 ;
599
        end
600
        5'b00001 :
601
        begin
602
                address <= address0_in ;
603
                pre_fetch_en <= pre_fetch_en0 ;
604
        end
605
        default : // IMAGE 1 is always included into PCI bridge
606
        begin
607
                address <= address1_in ;
608
                pre_fetch_en <= pre_fetch_en1 ;
609
        end
610
        endcase
611
end
612 2 mihad
 
613
// Address claim output to PCI Target SM
614
assign  addr_claim_out = addr_claim ;
615
 
616
reg             [31:0]   norm_address ;          // stored normal address (decoded and translated) for access to WB
617
reg                             norm_prf_en ;           // stored pre-fetch enable
618
reg             [3:0]    norm_bc ;                       // stored bus-command
619
reg                             same_read_reg ;         // stored SAME_READ information
620 21 mihad
reg                             target_rd ;             // delayed registered TRDY output equivalent signal
621 2 mihad
 
622
always@(posedge clk_in or posedge reset_in)
623
begin
624 21 mihad
    if (reset_in)
625 2 mihad
        begin
626 21 mihad
                norm_address <= #`FF_DELAY 32'h0000_0000 ;
627
                norm_prf_en <= #`FF_DELAY 1'b0 ;
628
                norm_bc <= #`FF_DELAY 4'h0 ;
629
                same_read_reg <= #`FF_DELAY 1'b0 ;
630 2 mihad
        end
631
        else
632
        begin
633
                if (addr_phase_in)
634
                begin
635 21 mihad
                        norm_address <= #`FF_DELAY address ;
636
                        norm_prf_en <= #`FF_DELAY pre_fetch_en ;
637
                        norm_bc <= #`FF_DELAY bc_in ;
638
                        same_read_reg <= #`FF_DELAY same_read_out ;
639 2 mihad
                end
640
        end
641
end
642 21 mihad
 
643
`ifdef          HOST
644
  `ifdef        NO_CNF_IMAGE
645
                        reg              [1:0]   strd_address ;          // stored INPUT address for accessing Configuration space registers
646
  `else
647
                        reg             [11:0]   strd_address ;          // stored INPUT address for accessing Configuration space registers
648
  `endif
649
`else
650
                        reg             [11:0]   strd_address ;          // stored INPUT address for accessing Configuration space registers
651
`endif
652 2 mihad
always@(posedge clk_in or posedge reset_in)
653
begin
654 21 mihad
    if (reset_in)
655 2 mihad
        begin
656 21 mihad
                strd_address <= #`FF_DELAY 0 ;
657 2 mihad
        end
658
        else
659
        begin
660 21 mihad
                if (addr_phase_in)
661
                begin
662
`ifdef          HOST
663
  `ifdef        NO_CNF_IMAGE
664
                        strd_address <= #`FF_DELAY address_in[1:0] ;
665
  `else
666
                        strd_address <= #`FF_DELAY address_in[11:0] ;
667
  `endif
668
`else
669
                        strd_address <= #`FF_DELAY address_in[11:0] ;
670
`endif
671
                end
672 2 mihad
        end
673
end
674
 
675 21 mihad
always@(posedge clk_in or posedge reset_in)
676
begin
677
    if (reset_in)
678
        begin
679
                target_rd               <= #`FF_DELAY 1'b0 ;
680
        end
681
        else
682
        begin
683
                if (same_read_reg && !bckp_trdy_in)
684
                        target_rd       <= #`FF_DELAY 1'b1 ;// Signal indicates when target ready is deaserted on PCI bus
685
                else if (same_read_reg && bckp_devsel_in && !bckp_stop_in)
686
                        target_rd       <= #`FF_DELAY 1'b1 ;// Signal indicates when target ready is deaserted on PCI bus
687 26 mihad
                else if ((!same_read_reg) || (last_reg_in && target_rd))
688 21 mihad
                        target_rd       <= #`FF_DELAY 1'b0 ;// Signal indicates when target ready is deaserted on PCI bus
689
        end
690
end
691
// '1' indicates asserted TRDY signal when same read operation is performed
692
wire    target_rd_completed     = target_rd ;
693
 
694 2 mihad
reg                             same_read_request ;
695
 
696 21 mihad
// When delayed read is completed on WB, addres and bc must be compered, if there is the same read request
697 2 mihad
always@(address or strd_addr_in or bc_in or strd_bc_in)
698
begin
699
        if ((address == strd_addr_in) & (bc_in == strd_bc_in))
700
                same_read_request <= 1'b1 ;
701
        else
702
                same_read_request <= 1'b0 ;
703
end
704
 
705
assign  same_read_out = (same_read_request) ; // && ~pcir_fifo_empty_in) ;
706
 
707
// Signals for byte enable checking
708
reg                             addr_burst_ok ;
709
reg                             io_be_ok ;
710
 
711
// Byte enable checking for IO, MEMORY and CONFIGURATION spaces - be_in is active low!
712
always@(strd_address or be_in)
713
begin
714
        case (strd_address[1:0])
715
        2'b11 :
716
        begin
717
                addr_burst_ok <= 1'b0 ;
718
                io_be_ok <= (be_in[2] && be_in[1] && be_in[0]) ; // only be3 can be active
719
        end
720
        2'b10 :
721
        begin
722
                addr_burst_ok <= 1'b0 ;
723
                io_be_ok <= (~be_in[2] && be_in[1] && be_in[0]) || (be_in[3] && be_in[2] && be_in[1] && be_in[0]) ;
724
        end
725
        2'b01 :
726
        begin
727
                addr_burst_ok <= 1'b0 ;
728
                io_be_ok <= (~be_in[1] && be_in[0]) || (be_in[3] && be_in[2] && be_in[1] && be_in[0]) ;
729
        end
730
        default :       // 2'b00
731
        begin
732
                addr_burst_ok <= 1'b1 ;
733
                io_be_ok <= (~be_in[0]) || (be_in[3] && be_in[2] && be_in[1] && be_in[0]) ;
734
        end
735
        endcase
736
end
737
 
738 53 mihad
wire calc_target_abort = (norm_bc[3:1] == `BC_IO_RW) ? !io_be_ok : 1'b0 ;
739 2 mihad
 
740 21 mihad
wire [3:0]       pcir_fifo_control_input = pcir_fifo_empty_in ? 4'h0 : pcir_fifo_control_in ;
741
 
742 2 mihad
// Medium registers for data and control busses from PCIR_FIFO
743
reg             [31:0]   pcir_fifo_data_reg ;
744
reg             [3:0]    pcir_fifo_ctrl_reg ;
745
 
746
always@(posedge clk_in or posedge reset_in)
747
begin
748 21 mihad
    if (reset_in)
749 2 mihad
    begin
750 21 mihad
        pcir_fifo_data_reg <= #`FF_DELAY 32'h0000_0000 ;
751
        pcir_fifo_ctrl_reg <=  #`FF_DELAY 4'h0 ;
752 2 mihad
    end
753
    else
754
    begin
755
        if (load_medium_reg_in)
756
        begin
757 21 mihad
                pcir_fifo_data_reg <= #`FF_DELAY pcir_fifo_data_in ;
758
                pcir_fifo_ctrl_reg <= #`FF_DELAY pcir_fifo_control_input ;
759 2 mihad
        end
760
    end
761
end
762
 
763 73 mihad
// when disconnect is signalled, the next data written to fifo will be the last
764
// also when this happens, disconnect must stay asserted until last data is written to the fifo
765
reg next_write_to_pciw_fifo_is_last ;
766
 
767 2 mihad
// selecting "fifo data" from medium registers or from PCIR_FIFO
768 21 mihad
wire [31:0]      pcir_fifo_data = (sel_fifo_mreg_in && !pcir_fifo_empty_in) ? pcir_fifo_data_in : pcir_fifo_data_reg ;
769
wire [3:0]       pcir_fifo_ctrl = (sel_fifo_mreg_in && !pcir_fifo_empty_in) ? pcir_fifo_control_input : pcir_fifo_ctrl_reg ;
770 2 mihad
 
771
// signal assignments to PCI Target FSM
772 21 mihad
assign  read_completed_out = req_comp_pending_in ; // completion pending input for requesting side of the bridge
773 2 mihad
assign  read_processing_out = req_req_pending_in ; // request pending input for requesting side
774 21 mihad
  // when '1', the bus command is IO command - not supported commands are checked in pci_decoder modules
775
  wire  io_memory_bus_command = !norm_bc[3] && !norm_bc[2] ;
776 2 mihad
assign  disconect_wo_data_out = (
777 21 mihad
        ((/*pcir_fifo_ctrl[`LAST_CTRL_BIT] ||*/ pcir_fifo_empty_in || ~burst_ok_out/*addr_burst_ok*/ || io_memory_bus_command) &&
778
                ~bc0_in && ~frame_reg_in) ||
779 73 mihad
        ((pciw_fifo_full_in || pciw_fifo_almost_full_in || next_write_to_pciw_fifo_is_last || (pciw_fifo_two_left_in && pciw_fifo_wenable_out) || ~addr_burst_ok || io_memory_bus_command) &&
780 21 mihad
                bc0_in && ~frame_reg_in)
781 2 mihad
                                                                ) ;
782 21 mihad
assign  disconect_w_data_out =  (
783
        ( burst_ok_out  && !io_memory_bus_command && ~bc0_in ) ||
784
        ( addr_burst_ok && !io_memory_bus_command && bc0_in )
785
                                                                ) ;
786
assign  target_abort_out = ( ~addr_phase_in && calc_target_abort ) ;
787 2 mihad
 
788 21 mihad
`ifdef          HOST
789
        `ifdef  NO_CNF_IMAGE
790
                        // signal assignments to PCI Target FSM
791
                        assign  norm_access_to_config_out = 1'b0 ;
792
                        // control signal assignments to read request sinchronization module
793
                        assign  done_out =  (target_rd_completed && last_reg_in) ;
794
                        assign  in_progress_out = (same_read_reg && ~bckp_trdy_in) ;
795
                        // signal used for PCIR_FIFO flush (with comp_flush_in signal)
796
                        wire    pcir_fifo_flush = (target_rd_completed && last_reg_in && ~pcir_fifo_empty_in) ;
797
        `else
798
                        // signal assignments to PCI Target FSM
799
                        assign  norm_access_to_config_out = (hit0_in && hit0_conf) ;
800
                        // control signal assignments to read request sinchronization module
801
                        assign  done_out =  (~sel_conf_fifo_in && target_rd_completed && last_reg_in) ;
802
                        assign  in_progress_out = (~sel_conf_fifo_in && same_read_reg && ~bckp_trdy_in) ;
803
                        // signal used for PCIR_FIFO flush (with comp_flush_in signal)
804
                        wire    pcir_fifo_flush = (~sel_conf_fifo_in && target_rd_completed && last_reg_in && ~pcir_fifo_empty_in) ;
805
        `endif
806
`else
807
                        // signal assignments to PCI Target FSM
808
                        assign  norm_access_to_config_out = (hit0_in && hit0_conf) ;
809
                        // control signal assignments to read request sinchronization module
810
                        assign  done_out =  (~sel_conf_fifo_in && target_rd_completed && last_reg_in) ;
811
                        assign  in_progress_out = (~sel_conf_fifo_in && same_read_reg && ~bckp_trdy_in) ;
812
                        // signal used for PCIR_FIFO flush (with comp_flush_in signal)
813
                        wire    pcir_fifo_flush = (~sel_conf_fifo_in && target_rd_completed && last_reg_in && ~pcir_fifo_empty_in) ;
814
`endif
815 2 mihad
 
816
// flush signal for PCIR_FIFO must be registered, since it asinchronously resets some status registers
817 21 mihad
wire            pcir_fifo_flush_reg ;
818
async_reset_flop                  async_reset_as_pcir_flush
819
(
820
    .data_in              (comp_flush_in || pcir_fifo_flush),
821
    .clk_in               (clk_in),
822
    .async_reset_data_out (pcir_fifo_flush_reg),
823
    .reset_in                     (reset_in)
824
) ;
825 2 mihad
 
826 73 mihad
always@(posedge clk_in or posedge reset_in)
827
begin
828
    if (reset_in)
829
        next_write_to_pciw_fifo_is_last <= #1 1'b0 ;
830
    else if (next_write_to_pciw_fifo_is_last && pciw_fifo_wenable_out)
831
        next_write_to_pciw_fifo_is_last <= #1 1'b0 ;
832
    else if (pciw_fifo_wenable_out && disconect_wo_data_out)
833
        next_write_to_pciw_fifo_is_last <= #1 1'b1 ;
834
end
835
 
836 2 mihad
// signal assignments from fifo to PCI Target FSM
837
assign  wbw_fifo_empty_out = wbw_fifo_empty_in ;
838 21 mihad
assign  wbu_del_read_comp_pending_out = wbu_del_read_comp_pending_in ;
839 2 mihad
assign  pciw_fifo_full_out = (pciw_fifo_full_in || pciw_fifo_almost_full_in || pciw_fifo_two_left_in) ;
840 21 mihad
assign  pcir_fifo_data_err_out = pcir_fifo_ctrl[`DATA_ERROR_CTRL_BIT] && !sel_conf_fifo_in ;
841 2 mihad
// signal assignments to fifo
842
assign  pcir_fifo_flush_out                                                     = pcir_fifo_flush_reg ;
843 21 mihad
assign  pcir_fifo_renable_out                                           = fetch_pcir_fifo_in && !pcir_fifo_empty_in ;
844 2 mihad
assign  pciw_fifo_wenable_out                                           = load_to_pciw_fifo_in ;
845 21 mihad
assign  pciw_fifo_control_out[`ADDR_CTRL_BIT]           = ~rdy_in ;
846
assign  pciw_fifo_control_out[`BURST_BIT]                       = rdy_in ? ~frame_reg_in : 1'b0 ;
847 2 mihad
assign  pciw_fifo_control_out[`DATA_ERROR_CTRL_BIT]     = 1'b0 ;
848 73 mihad
assign  pciw_fifo_control_out[`LAST_CTRL_BIT]           = rdy_in &&
849
                (next_write_to_pciw_fifo_is_last || last_reg_in || pciw_fifo_almost_full_in || ~addr_burst_ok || io_memory_bus_command);
850 2 mihad
 
851 21 mihad
`ifdef          HOST
852
        `ifdef  NO_CNF_IMAGE
853
                        // data and address outputs assignments to PCI Target FSM
854
                        assign  data_out = pcir_fifo_data ;
855
        `else
856
                        // data and address outputs assignments to PCI Target FSM
857
                        assign  data_out = sel_conf_fifo_in ? conf_data_in : pcir_fifo_data ;
858
        `endif
859
`else
860
                        // data and address outputs assignments to PCI Target FSM
861
                        assign  data_out = sel_conf_fifo_in ? conf_data_in : pcir_fifo_data ;
862
`endif
863
 
864 2 mihad
// data and address outputs assignments to read request sinchronization module
865
assign  req_out = req_in ;
866 21 mihad
        // this address is stored in delayed_sync module and is connected back as strd_addr_in 
867
assign  addr_out = norm_address[31:0] ; // correction of 2 LSBits is done in wb_master module, original address must be saved
868 2 mihad
assign  be_out = be_in ;
869
assign  we_out = 1'b0 ;
870
assign  bc_out = norm_bc ;
871 21 mihad
// burst is OK for reads when there is ((MEM_READ_LN or MEM_READ_MUL) and AD[1:0]==2'b00) OR
872
//   (MEM_READ and Prefetchable_IMAGE and AD[1:0]==2'b00)
873
assign  burst_ok_out = (norm_bc[3] && addr_burst_ok) || (norm_bc[2] && norm_prf_en && addr_burst_ok) ;
874
// data and address outputs assignments to PCIW_FIFO - correction of 2 LSBits 
875
assign  pciw_fifo_addr_data_out = rdy_in ? data_in : {norm_address[31:2], norm_address[1] && io_memory_bus_command,
876
                                                                                                                                                  norm_address[0] && io_memory_bus_command} ;
877 2 mihad
assign  pciw_fifo_cbe_out = rdy_in ? be_in : norm_bc ;
878
// data and address outputs assignments to Configuration space
879 21 mihad
`ifdef          HOST
880
        `ifdef  NO_CNF_IMAGE
881
                        assign  conf_data_out   = 32'h0 ;
882
                        assign  conf_addr_out   = 12'h0 ;
883
                        assign  conf_be_out             = 4'b0 ;
884
                        assign  conf_we_out             = 1'h0 ;
885
        `else
886
                        assign  conf_data_out   = data_in ;
887
                        assign  conf_addr_out   = strd_address[11:0] ;
888
                        assign  conf_be_out             = be_in ;
889
                        assign  conf_we_out             = load_to_conf_in ;
890
        `endif
891
`else
892
                        assign  conf_data_out   = data_in ;
893
                        assign  conf_addr_out   = strd_address[11:0] ;
894
                        assign  conf_be_out             = be_in ;
895
                        assign  conf_we_out             = load_to_conf_in ;
896
`endif
897
// NOT USED NOW, SONCE READ IS ASYNCHRONOUS
898
//assign        conf_re_out = fetch_conf_in ;
899
assign  conf_re_out = 1'b0 ;
900 2 mihad
 
901 21 mihad
endmodule

powered by: WebSVN 2.1.0

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