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 154

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 21 mihad
// Revision 1.2  2001/10/05 08:14:28  mihad
46
// Updated all files with inclusion of timescale file for simulation purposes.
47
//
48 6 mihad
// Revision 1.1.1.1  2001/10/02 15:33:46  mihad
49
// New project directory structure
50 2 mihad
//
51 6 mihad
//
52 2 mihad
 
53 21 mihad
`include "pci_constants.v"
54
 
55
// synopsys translate_off
56 6 mihad
`include "timescale.v"
57 21 mihad
// synopsys translate_on
58 2 mihad
 
59 21 mihad
module PCI_DECODER (hit, addr_out,
60
                                        addr_in, bc_in,
61
                                        base_addr, mask_addr, tran_addr, at_en,
62
                                        mem_io_space, mem_en, io_en) ;
63 2 mihad
 
64
// Decoding address size parameter - for FPGAs 1MegByte is recommended
65
//   MAXIMUM is 20 (4KBytes), length 12 is 1 MByte !!!
66
parameter               decode_len     = 12 ;
67
 
68
//###########################################################################################################
69 21 mihad
// ALL COMMENTS are written as there were decode_len 20. This number and 12 (32 - 20) are assigning the
70 2 mihad
// numbers of decoded and compared bits, etc.
71
//###########################################################################################################
72
 
73
/*-----------------------------------------------------------------------------------------------------------
74 21 mihad
DECODER interface decodes input address (ADDR_IN); what means that it validates (HIT), if input address
75 2 mihad
falls within the defined image space boundaries. Image space boundarie is defined with image base address
76
register (BASE_ADDR) and address mask register (MASK_ADDR).
77
Beside that, it also translates (maps) the input address to the output address (ADDR_OUT), regarding the
78
translation address register (TRAN_ADDR) and the address mask register.
79
-----------------------------------------------------------------------------------------------------------*/
80
 
81 21 mihad
// output control
82 2 mihad
output  hit ;
83 21 mihad
// output address
84 2 mihad
output  [31:0]   addr_out ;
85 21 mihad
// input address and bus command
86 2 mihad
input   [31:0]   addr_in ;
87 21 mihad
input   [3:0]    bc_in ;
88 2 mihad
 
89
// input registers - 12 LSbits are not valid since the smallest possible size is 4KB !
90
input   [31:(32-decode_len)]    base_addr ;
91
input   [31:(32-decode_len)]    mask_addr ;
92
input   [31:(32-decode_len)]    tran_addr ;
93
 
94
// input bit[2] of the Image Control register used to enable the address translation !
95
input   at_en ;
96
 
97
// memory or io space selection and its enable signals !
98
input   mem_io_space ;
99
input   mem_en ;
100
input   io_en ;
101
 
102
/*-----------------------------------------------------------------------------------------------------------
103
Internal signals !
104
-----------------------------------------------------------------------------------------------------------*/
105
 
106
// bit[31] if address mask register is IMAGE ENABLE bit (img_en)
107
wire    img_en ;
108
 
109
// addr_in_compare are masked input address bits that are compared with masked base_addr
110
wire    [31:(32-decode_len)]    addr_in_compare ;
111
// base_addr_compare are masked base address bits that are compared with masked addr_in
112
wire    [31:(32-decode_len)]    base_addr_compare ;
113
 
114
/*-----------------------------------------------------------------------------------------------------------
115
Decoding the input address!
116
This logic produces the loghest path in this module!
117
 
118
20 MSbits of input addres are as well as base address (20 bits) masked with corrected address mask. Only
119
masked bits of each vector are actually logically compared.
120
Bit[31] of address mask register is used to enable the image space !
121 21 mihad
Because of PCI bus specifications, there is also the comparison of memory/io selection (mem_io_space) and
122 2 mihad
its appropriate enable bit (mem_en / io_en).
123
-----------------------------------------------------------------------------------------------------------*/
124
 
125
assign  addr_in_compare = (addr_in[31:(32-decode_len)] & mask_addr) ;
126
 
127
assign  base_addr_compare = (base_addr & mask_addr) ;
128
 
129
assign  img_en = mask_addr[31] ;
130
 
131
wire    addr_hit = (addr_in_compare == base_addr_compare) ;
132
 
133 21 mihad
wire    space_hit = (!mem_io_space && mem_en && img_en) || (mem_io_space && io_en && img_en) ;
134 2 mihad
 
135 21 mihad
reg             bc_hit ;
136
always@(bc_in or mem_io_space)
137
begin // Allowed bus commands for accesses through IMAGEs to WB bus - BC_CONF_WRITE/READ are not used with address claim!!!
138
        case ( {bc_in[3:1], mem_io_space} )
139
        4'b001_1,       // BC_IO_READ     or BC_IO_WRITE                and IO space
140
        4'b011_0,       // BC_MEM_READ    or BC_MEM_WRITE               and MEM space
141
        4'b110_0,       // BC_MEM_READ_MUL                                              and MEM space - BC_DUAL_ADDR_CYC must NOT be allowed!
142
        4'b111_0:       // BC_MEM_READ_LN or BC_MEM_WRITE_INVAL and MEM space
143
                bc_hit <= 1'b1 ;
144
        default:
145
                bc_hit <= 1'b0 ;
146
        endcase
147
end
148 2 mihad
 
149 21 mihad
wire    bc_forbid = bc_in[3] && bc_in[2] && !bc_in[1] && bc_in[0] ; // BC_DUAL_ADDR_CYC must NOT be allowed!
150
 
151
 
152
assign  hit = (addr_hit && space_hit && bc_hit && !bc_forbid) ;
153
 
154 2 mihad
/*-----------------------------------------------------------------------------------------------------------
155
Translating the input address!
156
 
157
Translation of input address is not implemented if ADDR_TRAN_IMPL is not defined
158
 
159
20 MSbits of input address are masked with negated value of the corrected address mask in order to get
160
address bits of the input address which won't be replaced with translation address bits.
161 21 mihad
Translation address bits (20 bits) are masked with corrected address mask. Only masked bits of vector are
162
actually valid, all others are zero.
163 2 mihad
Boath vectors are bit-wise ORed in order to get the valid translation address with an offset of an input
164
address.
165
12 LSbits of an input address are assigned to 12 LSbits of an output addres.
166
-----------------------------------------------------------------------------------------------------------*/
167
 
168
`ifdef ADDR_TRAN_IMPL
169
    // if Address Translation Enable bit is set, then translation address is used othervise input address is used!
170
    // addr_in_combine input address bits are not replaced with translation address!
171
    wire        [31:(32-decode_len)] addr_in_combine ;
172
    // tran_addr_combine are masked and combined with addr_in_combine!
173
    reg         [31:(32-decode_len)] tran_addr_combine ;
174
 
175
    assign addr_in_combine = (addr_in[31:(32-decode_len)] & ~mask_addr) ;
176
    always@(at_en or tran_addr or mask_addr or addr_in)
177
        begin
178 21 mihad
            if (at_en)
179 2 mihad
                        begin
180
                                tran_addr_combine <= (tran_addr & mask_addr) ;
181
                end
182
        else
183
                        begin
184
                                tran_addr_combine <= (addr_in[31:(32-decode_len)] & mask_addr) ;
185
                        end
186
        end
187
 
188
    assign addr_out[31:(32-decode_len)] = (addr_in_combine | tran_addr_combine) ;
189
    assign addr_out[(31-decode_len):0] = addr_in [(31-decode_len):0] ;
190
`else
191
    assign addr_out = addr_in ;
192
`endif
193
 
194
endmodule
195
 

powered by: WebSVN 2.1.0

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