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

Subversion Repositories pci

[/] [pci/] [tags/] [rel_3/] [rtl/] [verilog/] [pci_decoder.v] - Blame information for rev 6

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

Line No. Rev Author Line
1 2 mihad
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  File name: pci_decoder.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 6 mihad
// Revision 1.1.1.1  2001/10/02 15:33:46  mihad
46
// New project directory structure
47 2 mihad
//
48 6 mihad
//
49 2 mihad
 
50
`include "constants.v"
51 6 mihad
`include "timescale.v"
52 2 mihad
 
53
module PCI_DECODER (hit, addr_out, addr_in, base_addr, mask_addr, tran_addr, at_en, mem_io_space, mem_en, io_en) ;
54
 
55
// Decoding address size parameter - for FPGAs 1MegByte is recommended
56
//   MAXIMUM is 20 (4KBytes), length 12 is 1 MByte !!!
57
parameter               decode_len     = 12 ;
58
 
59
//###########################################################################################################
60
// ALL COMMENTS are written as there were decode_len 20. This number and 12 (32 - 20) are assigning the 
61
// numbers of decoded and compared bits, etc.
62
//###########################################################################################################
63
 
64
/*-----------------------------------------------------------------------------------------------------------
65
DECODER interface decodes input address (ADDR_IN); what means that it validates (HIT), if input address
66
falls within the defined image space boundaries. Image space boundarie is defined with image base address
67
register (BASE_ADDR) and address mask register (MASK_ADDR).
68
Beside that, it also translates (maps) the input address to the output address (ADDR_OUT), regarding the
69
translation address register (TRAN_ADDR) and the address mask register.
70
-----------------------------------------------------------------------------------------------------------*/
71
 
72
// output control  
73
output  hit ;
74
// output address 
75
output  [31:0]   addr_out ;
76
// input address
77
input   [31:0]   addr_in ;
78
 
79
// input registers - 12 LSbits are not valid since the smallest possible size is 4KB !
80
input   [31:(32-decode_len)]    base_addr ;
81
input   [31:(32-decode_len)]    mask_addr ;
82
input   [31:(32-decode_len)]    tran_addr ;
83
 
84
// input bit[2] of the Image Control register used to enable the address translation !
85
input   at_en ;
86
 
87
// memory or io space selection and its enable signals !
88
input   mem_io_space ;
89
input   mem_en ;
90
input   io_en ;
91
 
92
/*-----------------------------------------------------------------------------------------------------------
93
Internal signals !
94
-----------------------------------------------------------------------------------------------------------*/
95
 
96
// bit[31] if address mask register is IMAGE ENABLE bit (img_en)
97
wire    img_en ;
98
 
99
// addr_in_compare are masked input address bits that are compared with masked base_addr
100
wire    [31:(32-decode_len)]    addr_in_compare ;
101
// base_addr_compare are masked base address bits that are compared with masked addr_in
102
wire    [31:(32-decode_len)]    base_addr_compare ;
103
 
104
/*-----------------------------------------------------------------------------------------------------------
105
Decoding the input address!
106
This logic produces the loghest path in this module!
107
 
108
20 MSbits of input addres are as well as base address (20 bits) masked with corrected address mask. Only
109
masked bits of each vector are actually logically compared.
110
Bit[31] of address mask register is used to enable the image space !
111
Because of PCI bus specifications, there is also the comparison of memory/io selection (mem_io_space) and
112
its appropriate enable bit (mem_en / io_en).
113
-----------------------------------------------------------------------------------------------------------*/
114
 
115
assign  addr_in_compare = (addr_in[31:(32-decode_len)] & mask_addr) ;
116
 
117
assign  base_addr_compare = (base_addr & mask_addr) ;
118
 
119
assign  img_en = mask_addr[31] ;
120
 
121
wire    addr_hit = (addr_in_compare == base_addr_compare) ;
122
 
123
wire    space_hit = (~mem_io_space && mem_en && img_en) || (mem_io_space && io_en && img_en) ;
124
 
125
assign  hit = (addr_hit && space_hit) ;
126
 
127
/*-----------------------------------------------------------------------------------------------------------
128
Translating the input address!
129
 
130
Translation of input address is not implemented if ADDR_TRAN_IMPL is not defined
131
 
132
20 MSbits of input address are masked with negated value of the corrected address mask in order to get
133
address bits of the input address which won't be replaced with translation address bits.
134
Translation address bits (20 bits) are masked with corrected address mask. Only masked bits of vector are
135
actually valid, all others are zero.
136
Boath vectors are bit-wise ORed in order to get the valid translation address with an offset of an input
137
address.
138
12 LSbits of an input address are assigned to 12 LSbits of an output addres.
139
-----------------------------------------------------------------------------------------------------------*/
140
 
141
`ifdef ADDR_TRAN_IMPL
142
    // if Address Translation Enable bit is set, then translation address is used othervise input address is used!
143
    // addr_in_combine input address bits are not replaced with translation address!
144
    wire        [31:(32-decode_len)] addr_in_combine ;
145
    // tran_addr_combine are masked and combined with addr_in_combine!
146
    reg         [31:(32-decode_len)] tran_addr_combine ;
147
 
148
    assign addr_in_combine = (addr_in[31:(32-decode_len)] & ~mask_addr) ;
149
    always@(at_en or tran_addr or mask_addr or addr_in)
150
        begin
151
            if (at_en)
152
                        begin
153
                                tran_addr_combine <= (tran_addr & mask_addr) ;
154
                end
155
        else
156
                        begin
157
                                tran_addr_combine <= (addr_in[31:(32-decode_len)] & mask_addr) ;
158
                        end
159
        end
160
 
161
    assign addr_out[31:(32-decode_len)] = (addr_in_combine | tran_addr_combine) ;
162
    assign addr_out[(31-decode_len):0] = addr_in [(31-decode_len):0] ;
163
`else
164
    assign addr_out = addr_in ;
165
`endif
166
 
167
endmodule
168
 

powered by: WebSVN 2.1.0

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