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

Subversion Repositories pci

[/] [pci/] [tags/] [rel_7/] [rtl/] [verilog/] [pci_target32_interface.v] - Blame information for rev 53

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

powered by: WebSVN 2.1.0

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