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

Subversion Repositories theia_gpu

[/] [theia_gpu/] [tags/] [latest_stable/] [rtl/] [GPU/] [TOP/] [Theia.v] - Blame information for rev 143

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

Line No. Rev Author Line
1 76 diegovalve
`timescale 1ns / 1ps
2
`include "aDefinitions.v"
3 143 diegovalve
/**********************************************************************************
4
Theia, Ray Cast Programable graphic Processing Unit.
5
Copyright (C) 2010  Diego Valverde (diego.valverde.g@gmail.com)
6
 
7
This program is free software; you can redistribute it and/or
8
modify it under the terms of the GNU General Public License
9
as published by the Free Software Foundation; either version 2
10
of the License, or (at your option) any later version.
11
 
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
GNU General Public License for more details.
16
 
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20
 
21
***********************************************************************************/
22 76 diegovalve
 
23
//---------------------------------------------------------------------------
24
module THEIA
25
(
26 109 diegovalve
 
27
input wire                    CLK_I,    //Input clock
28
input wire                    RST_I,    //Input reset
29
//Theia Interfaces
30
input wire                    MST_I,    //Master signal, THEIA enters configuration mode
31
                                       //when this gets asserted (see documentation)
32
//Wish Bone Interface
33
input wire [`WB_WIDTH-1:0]    DAT_I,     //Input data bus  (Wishbone)
34
input wire                    ACK_I,    //Input ack
35
output wire                   ACK_O,    //Output ack
36
input wire [`WB_WIDTH-1:0]    ADR_I,     //Input address
37
input wire                    WE_I,    //Input write enable
38
input wire                    STB_I,    //Strobe signal, see wishbone documentation
39
input wire                    CYC_I,   //Bus cycle signal, see wishbone documentation
40
input wire [1:0]              TGA_I,   //Input address tag, see THEAI documentation
41 76 diegovalve
input wire [`MAX_CORES-1:0]      SEL_I,  //The WishBone Master uses this signal to configure a specific core (TBD, not sure is needed)
42 109 diegovalve
input wire [`MAX_CORES-1:0]   RENDREN_I,
43
 
44
input wire [`MAX_CORE_BITS-1:0]      OMBSEL_I,  //Output memory bank select
45
input wire [`WB_WIDTH-1:0]           OMADR_I,  //Output adress (relative to current bank)
46
output wire [`WB_WIDTH-1:0]          OMEM_O,      //Output data bus (Wishbone)
47
 
48
input wire [`WB_WIDTH-1:0]           TMDAT_I,
49
input wire [`WB_WIDTH-1:0]           TMADR_I,
50
input wire                           TMWE_I,
51
input wire [`MAX_TMEM_BANKS-1:0]     TMSEL_I,
52
//Control Register
53 76 diegovalve
input wire [15:0]                         CREG_I,
54 143 diegovalve
output wire                   HDL_O,
55 109 diegovalve
input wire                    STDONE_I,
56
input wire                    HDA_I,
57 143 diegovalve
input wire                    HDLACK_I,
58 109 diegovalve
output wire                   RCOMMIT_O,
59
output wire                   DONE_O
60 16 diegovalve
 
61 76 diegovalve
);
62 16 diegovalve
 
63
 
64
 
65 76 diegovalve
 
66 109 diegovalve
wire [`MAX_TMEM_BANKS-1:0] wTMemWriteEnable;
67
SELECT_1_TO_N # ( `MAX_TMEM_BANKS, `MAX_TMEM_BANKS ) TMWE_SEL
68
                        (
69
                        .Sel(TMSEL_I),
70
                        .En(TMWE_I),
71
                        .O(wTMemWriteEnable)
72
                        );
73
 
74
 
75 76 diegovalve
wire [`MAX_CORES-1:0] wDone;
76
wire [`MAX_CORES-1:0] wBusGranted,wBusRequest;
77 109 diegovalve
//wire [`WB_WIDTH-1:0]  wDAT_O[`MAX_CORES-1:0];
78
//wire [`WB_WIDTH-1:0]  wADR_O[`MAX_CORES-1:0];
79
//wire [1:0] wTGA_O[`MAX_CORES-1:0];
80
wire [`MAX_CORE_BITS-1:0] wBusSelect;
81 76 diegovalve
 
82
 
83 109 diegovalve
//wire [`MAX_CORES-1:0] wSTB_O;
84
//wire [`MAX_CORES-1:0] wWE_O;
85
wire [`MAX_CORES-1:0]wACK_O;
86 76 diegovalve
 
87
 
88 109 diegovalve
wire wOMem_WE[`MAX_CORES-1:0];
89
wire [`WB_WIDTH-1:0] wOMEM_Address[`MAX_CORES-1:0];
90
wire [`WB_WIDTH-1:0] wOMEM_Dat[`MAX_CORES-1:0];
91
 
92 76 diegovalve
wire [`MAX_CORES-1:0]   wSTB_I;
93
wire [`MAX_CORES-1:0]   wMST_I;
94
wire [`MAX_CORES-1:0]   wACK_I;
95
wire [`MAX_CORES-1:0]   wCYC_I;
96
wire [1:0]              wTGA_I[`MAX_CORES-1:0];
97
 
98
 
99 143 diegovalve
 
100 109 diegovalve
wire [`WB_WIDTH-1:0]  wTMEM_Data;
101
wire [`WB_WIDTH-1:0]  wTMEM_Address[`MAX_CORES-1:0];
102
wire [`WB_WIDTH-1:0]  wTMEM_ReadAddr;
103
wire [`MAX_CORES-1:0] wTMEM_Resquest;
104
wire [`MAX_CORES-1:0] wTMEM_Granted;
105
 
106
 
107
 
108
//CROSS-BAR cables
109
 
110
 
111
 
112
wire [`WB_WIDTH-1:0]     wCrossBarDataRow[`MAX_TMEM_BANKS-1:0];                   //Horizontal grid Buses comming from each bank 
113
wire [`WB_WIDTH-1:0]     wCrossBarDataCollumn[`MAX_CORES-1:0];          //Vertical grid buses comming from each core.
114
wire [`WB_WIDTH-1:0]     wTMemReadAdr[`MAX_CORES-1:0];                                       //Horizontal grid Buses comming from each core (virtual addr).
115
wire [`WB_WIDTH-1:0]     wCrossBarAdressCollumn[`MAX_CORES-1:0];                  //Vertical grid buses comming from each core. (physical addr).
116
wire [`WB_WIDTH-1:0]     wCrossBarAddressRow[`MAX_TMEM_BANKS-1:0];                //Horizontal grid Buses comming from each bank.
117
 
118
wire                                                wCORE_2_TMEM__Req[`MAX_CORES-1:0];
119
wire [`MAX_TMEM_BANKS -1:0]    wBankReadRequest[`MAX_CORES-1:0];
120
 
121
 
122
wire [`MAX_CORES-1:0]         wBankReadGranted[`MAX_TMEM_BANKS-1:0];
123
wire                           wTMEM_2_Core__Grant[`MAX_CORES-1:0];
124
 
125
wire[`MAX_CORE_BITS-1:0] wCurrentCoreSelected[`MAX_TMEM_BANKS-1:0];
126 143 diegovalve
wire[`WIDTH-1:0]                wCoreBankSelect[`MAX_CORES-1:0];
127
wire [`MAX_CORES-1:0] wHDL_O;
128 109 diegovalve
 
129
 
130 143 diegovalve
wire [`MAX_CORES-1:0] wHostDataLatched;
131 109 diegovalve
wire [`MAX_CORES-1:0] wRCOMMIT_O;
132
wire [`MAX_CORES-1:0] wRCommited;
133
 
134
 
135 143 diegovalve
assign RCOMMIT_O = wRCommited[0] & wRCommited[1] & wRCommited[2] & wRCommited[3];
136
assign HDL_O = wHostDataLatched[0] &  wHostDataLatched[1] &  wHostDataLatched[2] &  wHostDataLatched[3];
137
assign DONE_O = wDone[0] & wDone[1] & wDone[2] & wDone[3];
138
 
139
 
140 109 diegovalve
 
141
//----------------------------------------------------------------      
142
 
143 76 diegovalve
        Module_BusArbitrer ARB1
144
        (
145
        .Clock( CLK_I ),
146
        .Reset( RST_I ),
147
        .iRequest( wBusRequest ),
148
        .oGrant(   wBusGranted ),
149
        .oBusSelect( wBusSelect )
150
 
151
        );
152
//----------------------------------------------------------------
153
 
154 143 diegovalve
 
155 109 diegovalve
  assign ACK_O = wACK_O[ wBusSelect];
156 76 diegovalve
 
157 109 diegovalve
 wire [`WB_WIDTH-1:0] wDataOut[`MAX_CORES-1:0];
158
 assign OMEM_O = wDataOut[ OMBSEL_I ];
159 76 diegovalve
 
160 109 diegovalve
  genvar i;
161
  generate
162
        for (i = 0; i < `MAX_CORES; i = i +1)
163
        begin : CORE
164
                assign wMST_I[i] = (SEL_I[i]) ? MST_I : 0;
165
                assign wSTB_I[i] = (SEL_I[i]) ? STB_I : 0;
166
                assign wCYC_I[i] = (SEL_I[i]) ? CYC_I : 0;
167
                assign wTGA_I[i] = (SEL_I[i]) ? TGA_I : 0;
168 76 diegovalve
 
169 109 diegovalve
 
170
                THEIACORE CTHEIA
171
                (
172
                .CLK_I( CLK_I ),
173 76 diegovalve
                .RST_I( RST_I ),
174 109 diegovalve
                .RENDREN_I( RENDREN_I[i] ),
175 76 diegovalve
 
176
                //Slave signals
177 109 diegovalve
                .ADR_I( ADR_I ),
178 76 diegovalve
                .WE_I(  WE_I  ),
179 109 diegovalve
                .STB_I(  wSTB_I[i] ),
180 82 diegovalve
                .ACK_I( ACK_I ),
181 109 diegovalve
                .CYC_I( wCYC_I[i] ),
182
                .MST_I( wMST_I[i] ),
183
                .TGA_I( wTGA_I[i] ),
184 76 diegovalve
                .CREG_I( CREG_I ),
185
 
186 109 diegovalve
                //Master Signals
187
                .ACK_O(         wACK_O[i] ),
188
                .CYC_O(  wBusRequest[i] ),
189
                .GNT_I(         wBusGranted[i] ),
190 76 diegovalve
                `ifdef DEBUG
191 109 diegovalve
                .iDebug_CoreID( i ),
192 76 diegovalve
                `endif
193
 
194 109 diegovalve
                .OMEM_WE_O( wOMem_WE[i] ),
195
                .OMEM_ADR_O( wOMEM_Address[i] ),
196
                .OMEM_DAT_O( wOMEM_Dat[i] ),
197 76 diegovalve
 
198 109 diegovalve
                .TMEM_DAT_I( wCrossBarDataCollumn[i]    ),
199
                .TMEM_ADR_O( wTMemReadAdr[i]  ),
200
                .TMEM_CYC_O( wCORE_2_TMEM__Req[i]       ),
201
                .TMEM_GNT_I( wTMEM_2_Core__Grant[i]     ),
202 82 diegovalve
 
203 143 diegovalve
                .HDA_I(     HDA_I ),                            //Host data available
204
                .HDL_O( wHDL_O[i] ),                            //Host data Latched
205
                .HDLACK_I( ~HDL_O ),                          //Host data Latched ACK
206 109 diegovalve
                .STDONE_I( STDONE_I ),
207
                .RCOMMIT_O( wRCOMMIT_O[i] ),
208 82 diegovalve
 
209 143 diegovalve
 
210 82 diegovalve
                //Other
211
                .DAT_I( DAT_I ),
212 109 diegovalve
                .DONE_O( wDone[i] )
213
 
214 82 diegovalve
        );
215 109 diegovalve
 
216
        UPCOUNTER_POSEDGE # (1) UP_RCOMMIT
217
        (
218
        .Clock(  CLK_I ),
219 143 diegovalve
        .Reset( RST_I | HDLACK_I ),
220 109 diegovalve
        .Initial( 1'b0 ),
221
        .Enable( wRCOMMIT_O[i] ),
222
        .Q(wRCommited[i])
223
        );
224
 
225
        UPCOUNTER_POSEDGE # (1) UP_GREADY
226
        (
227
        .Clock(  CLK_I ),
228 143 diegovalve
        .Reset( RST_I | HDLACK_I ),
229 109 diegovalve
        .Initial( 1'b0 ),
230 143 diegovalve
        .Enable( wHDL_O[i] ),
231
        .Q(wHostDataLatched[i])
232 109 diegovalve
        );
233
 
234 143 diegovalve
        RAM_SINGLE_READ_PORT # ( `WB_WIDTH, `WB_WIDTH, 250000 ) OMEM //500000 ) OMEM 
235 109 diegovalve
(
236
        .Clock(         CLK_I                ),
237
        .iWriteEnable(  wOMem_WE[i]          ),
238
        .iWriteAddress( wOMEM_Address[i]     ),
239
        .iDataIn(       wOMEM_Dat[i]         ),
240
        .iReadAddress0( OMADR_I              ),
241
        .oDataOut0(     wDataOut[i]          )
242
 
243
);
244
 
245
 
246
//If there are "n" banks, memory location "X" would reside in bank number X mod n.
247
//X mod 2^n == X & (2^n - 1)
248
assign wCoreBankSelect[i] = (wTMemReadAdr[i] & (`MAX_TMEM_BANKS-1));
249
 
250
//Each core has 1 bank request slot
251
//Each slot has MAX_TMEM_BANKS bits. Only 1 bit can
252
//be 1 at any given point in time. All bits zero means,
253
//we are not requesting to read from any memory bank.
254 143 diegovalve
SELECT_1_TO_N # ( `WIDTH, `MAX_CORES ) READDRQ
255 109 diegovalve
                        (
256
                        .Sel(wCoreBankSelect[ i]),
257
                        .En(wCORE_2_TMEM__Req[i]),
258
                        .O(wBankReadRequest[i])
259
                        );
260
 
261
//The address coming from the core is  virtual adress, meaning it assumes linear
262
//address space, however, since memory is interleaved in a n-way memory we transform
263
//virtual adress into physical adress (relative to the bank) like this
264
//fadr = vadr / n = vadr >> log2(n)
265
 
266 143 diegovalve
assign wCrossBarAdressCollumn[i] = (wTMemReadAdr[i] >> `MAX_CORE_BITS);
267 109 diegovalve
 
268
//Connect the granted signal to Arbiter of the Bank we want to read from        
269
assign wTMEM_2_Core__Grant[i] = wBankReadGranted[wCoreBankSelect[i]][i];
270
 
271
//Connect the request signal to Arbiter of the Bank we want to read from        
272
//assign wBankReadRequest[wCoreBankSelect[i]][i] = wCORE_2_TMEM__Req[i];
273
 
274
        end
275
  endgenerate
276
 
277
 
278
////////////// CROSS-BAR INTERCONECTION//////////////////////////
279
 
280
genvar Core,Bank;
281
generate
282
for (Bank = 0; Bank < `MAX_TMEM_BANKS; Bank = Bank + 1)
283
begin : BANK
284
 
285
        //The memory bank itself
286
RAM_SINGLE_READ_PORT     # ( `WB_WIDTH, `WB_WIDTH, 50000 ) TMEM
287
        (
288
        .Clock(         CLK_I                                   ),
289
        .iWriteEnable(  wTMemWriteEnable[Bank]       ),
290
        .iWriteAddress( TMADR_I                      ),
291
        .iDataIn(       TMDAT_I                      ),
292
        .iReadAddress0( wCrossBarAddressRow[Bank]    ), //Connect to the Row of the grid
293
        .oDataOut0(     wCrossBarDataRow[Bank]                  )  //Connect to the Row of the grid
294
 
295
        );
296
 
297
        //Arbiter will Round-Robin Cores attempting to read from the same Bank
298
        //at a given point in time
299
wire [`MAX_CORES-1:0]         wBankReadGrantedDelay[`MAX_TMEM_BANKS-1:0];
300
        Module_BusArbitrer ARB_TMEM
301
        (
302
        .Clock( CLK_I ),
303
        .Reset( RST_I ),
304 143 diegovalve
        .iRequest( {wBankReadRequest[3][Bank],wBankReadRequest[2][Bank],wBankReadRequest[1][Bank],wBankReadRequest[0][Bank]}),
305 109 diegovalve
        .oGrant(   wBankReadGrantedDelay[Bank]  ),  //The bit of the core granted to read from this Bank
306
        .oBusSelect( wCurrentCoreSelected[Bank] )                       //The index of the core granted to read from this Bank
307
 
308
        );
309
 
310
        FFD_POSEDGE_SYNCRONOUS_RESET # ( `MAX_CORES ) FFD_GNT
311
(
312
        .Clock(CLK_I),
313
        .Reset(RST_I),
314
        .Enable( 1'b1 ),
315
        .D(wBankReadGrantedDelay[Bank]),
316
        .Q(wBankReadGranted[Bank])
317
);
318
 
319
 
320
        //Create the Cross-Bar interconnection grid now, rows are coonected to the memory banks,
321
        //while collumns are connected to the cores, 2 or more cores can not read from the same
322
        //bank at any given point in time
323
        for (Core = 0; Core < `MAX_CORES; Core = Core + 1)
324
        begin: CORE_CONNECT
325
                //Connect the Data Collum of this core to the Data Row of current bank, only if the Core is looking for data stored in this bank
326
                assign wCrossBarDataCollumn[ Core ] = ( wCoreBankSelect[ Core ] == Bank ) ? wCrossBarDataRow[ Bank ] : `WB_WIDTH'bz;
327
                //Connect the Address Row of this Bank to the Address Column of the core, only if the Arbiter selected this core for reading
328
                assign wCrossBarAddressRow[ Bank ] = ( wCurrentCoreSelected[ Bank ] == Core ) ? wCrossBarAdressCollumn[Core]: `WB_WIDTH'bz;
329
 
330
        end
331
 
332
end
333
endgenerate
334
 
335
////////////// CROSS-BAR INTERCONECTION//////////////////////////
336 82 diegovalve
//----------------------------------------------------------------
337 109 diegovalve
 
338 76 diegovalve
endmodule
339
//---------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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