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

Subversion Repositories theia_gpu

[/] [theia_gpu/] [trunk/] [rtl/] [Theia.v] - Blame information for rev 211

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

Line No. Rev Author Line
1 152 diegovalve
`timescale 1ns / 1ps
2
`include "aDefinitions.v"
3
/**********************************************************************************
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
 
23
//---------------------------------------------------------------------------
24
module THEIA
25
(
26
 
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
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
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
input wire [15:0]                         CREG_I,
54
output wire                   HDL_O,
55
input wire                    STDONE_I,
56
input wire                    HDA_I,
57
input wire                    HDLACK_I,
58
output wire                   RCOMMIT_O,
59
output wire                   DONE_O
60
 
61
);
62
 
63
 
64
 
65
 
66
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
wire [`MAX_CORES-1:0] wDone;
76
wire [`MAX_CORES-1:0] wBusGranted,wBusRequest;
77
//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
 
82
 
83
//wire [`MAX_CORES-1:0] wSTB_O;
84
//wire [`MAX_CORES-1:0] wWE_O;
85
wire [`MAX_CORES-1:0]wACK_O;
86
 
87
 
88
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
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
 
100
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
wire[`WIDTH-1:0]                wCoreBankSelect[`MAX_CORES-1:0];
127
wire [`MAX_CORES-1:0] wHDL_O;
128
 
129
 
130
wire [`MAX_CORES-1:0] wHostDataLatched;
131
wire [`MAX_CORES-1:0] wRCOMMIT_O;
132
wire [`MAX_CORES-1:0] wRCommited;
133
 
134
 
135
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
 
141
//----------------------------------------------------------------      
142
 
143
        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
  wire  wMaskedACK_O;
155
  assign wMaskedACK_O = (SEL_I & wACK_O) ? 1'b1 : 1'b0;
156
  assign ACK_O =  ( MST_I ) ? wMaskedACK_O  : wACK_O[ wBusSelect];
157
 
158
 
159
 wire [`WB_WIDTH-1:0] wDataOut[`MAX_CORES-1:0];
160
 assign OMEM_O = wDataOut[ OMBSEL_I ];
161
 
162
  genvar i;
163
  generate
164
        for (i = 0; i < `MAX_CORES; i = i +1)
165
        begin : CORE
166
                assign wMST_I[i] = (SEL_I[i]) ? MST_I : 0;
167
                assign wSTB_I[i] = (SEL_I[i]) ? STB_I : 0;
168
                assign wCYC_I[i] = (SEL_I[i]) ? CYC_I : 0;
169
                assign wTGA_I[i] = (SEL_I[i]) ? TGA_I : 0;
170
 
171
 
172
                THEIACORE CTHEIA
173
                (
174
                .CLK_I( CLK_I ),
175
                .RST_I( RST_I ),
176
                .RENDREN_I( RENDREN_I[i] ),
177
 
178
                //Slave signals
179
                .ADR_I( ADR_I ),
180
                .WE_I(  WE_I  ),
181
                .STB_I(  wSTB_I[i] ),
182
                .ACK_I( ACK_I ),
183
                .CYC_I( wCYC_I[i] ),
184
                .MST_I( wMST_I[i] ),
185
                .TGA_I( wTGA_I[i] ),
186
                .CREG_I( CREG_I ),
187
 
188
                //Master Signals
189
                .ACK_O(         wACK_O[i] ),
190
                .CYC_O(  wBusRequest[i] ),
191
                .GNT_I(         wBusGranted[i] ),
192
                `ifdef DEBUG
193
                .iDebug_CoreID( i ),
194
                `endif
195
 
196
                .OMEM_WE_O( wOMem_WE[i] ),
197
                .OMEM_ADR_O( wOMEM_Address[i] ),
198
                .OMEM_DAT_O( wOMEM_Dat[i] ),
199
 
200
                .TMEM_DAT_I( wCrossBarDataCollumn[i]    ),
201
                .TMEM_ADR_O( wTMemReadAdr[i]  ),
202
                .TMEM_CYC_O( wCORE_2_TMEM__Req[i]       ),
203
                .TMEM_GNT_I( wTMEM_2_Core__Grant[i]     ),
204
 
205
                .HDA_I(     HDA_I ),                            //Host data available
206
                .HDL_O( wHDL_O[i] ),                            //Host data Latched
207
                .HDLACK_I( ~HDL_O ),                          //Host data Latched ACK
208
                .STDONE_I( STDONE_I ),
209
                .RCOMMIT_O( wRCOMMIT_O[i] ),
210
 
211
 
212
                //Other
213
                .DAT_I( DAT_I ),
214
                .DONE_O( wDone[i] )
215
 
216
        );
217
 
218
        UPCOUNTER_POSEDGE # (1) UP_RCOMMIT
219
        (
220
        .Clock(  CLK_I ),
221
        .Reset( RST_I | HDLACK_I ),
222
        .Initial( 1'b0 ),
223
        .Enable( wRCOMMIT_O[i] ),
224
        .Q(wRCommited[i])
225
        );
226
 
227
        UPCOUNTER_POSEDGE # (1) UP_GREADY
228
        (
229
        .Clock(  CLK_I ),
230
        .Reset( RST_I | HDLACK_I ),
231
        .Initial( 1'b0 ),
232
        .Enable( wHDL_O[i] ),
233
        .Q(wHostDataLatched[i])
234
        );
235
 
236
        RAM_SINGLE_READ_PORT # ( `WB_WIDTH, `WB_WIDTH, 250000 ) OMEM //500000 ) OMEM 
237
(
238
        .Clock(         CLK_I                ),
239
        .iWriteEnable(  wOMem_WE[i]          ),
240
        .iWriteAddress( wOMEM_Address[i]     ),
241
        .iDataIn(       wOMEM_Dat[i]         ),
242
        .iReadAddress0( OMADR_I              ),
243
        .oDataOut0(     wDataOut[i]          )
244
 
245
);
246
 
247
 
248
//If there are "n" banks, memory location "X" would reside in bank number X mod n.
249
//X mod 2^n == X & (2^n - 1)
250
assign wCoreBankSelect[i] = (wTMemReadAdr[i] & (`MAX_TMEM_BANKS-1));
251
 
252
//Each core has 1 bank request slot
253
//Each slot has MAX_TMEM_BANKS bits. Only 1 bit can
254
//be 1 at any given point in time. All bits zero means,
255
//we are not requesting to read from any memory bank.
256
SELECT_1_TO_N # ( `WIDTH, `MAX_CORES ) READDRQ
257
                        (
258
                        .Sel(wCoreBankSelect[ i]),
259
                        .En(wCORE_2_TMEM__Req[i]),
260
                        .O(wBankReadRequest[i])
261
                        );
262
 
263
//The address coming from the core is  virtual adress, meaning it assumes linear
264
//address space, however, since memory is interleaved in a n-way memory we transform
265
//virtual adress into physical adress (relative to the bank) like this
266
//fadr = vadr / n = vadr >> log2(n)
267
 
268
assign wCrossBarAdressCollumn[i] = (wTMemReadAdr[i] >> `MAX_CORE_BITS);
269
 
270
//Connect the granted signal to Arbiter of the Bank we want to read from        
271
assign wTMEM_2_Core__Grant[i] = wBankReadGranted[wCoreBankSelect[i]][i];
272
 
273
//Connect the request signal to Arbiter of the Bank we want to read from        
274
//assign wBankReadRequest[wCoreBankSelect[i]][i] = wCORE_2_TMEM__Req[i];
275
 
276
        end
277
  endgenerate
278
 
279
 
280
////////////// CROSS-BAR INTERCONECTION//////////////////////////
281
 
282
genvar Core,Bank;
283
generate
284
for (Bank = 0; Bank < `MAX_TMEM_BANKS; Bank = Bank + 1)
285
begin : BANK
286
 
287
        //The memory bank itself
288
RAM_SINGLE_READ_PORT     # ( `WB_WIDTH, `WB_WIDTH, 50000 ) TMEM
289
        (
290
        .Clock(         CLK_I                                   ),
291
        .iWriteEnable(  wTMemWriteEnable[Bank]       ),
292
        .iWriteAddress( TMADR_I                      ),
293
        .iDataIn(       TMDAT_I                      ),
294
        .iReadAddress0( wCrossBarAddressRow[Bank]    ), //Connect to the Row of the grid
295
        .oDataOut0(     wCrossBarDataRow[Bank]                  )  //Connect to the Row of the grid
296
 
297
        );
298
 
299
        //Arbiter will Round-Robin Cores attempting to read from the same Bank
300
        //at a given point in time
301
wire [`MAX_CORES-1:0]         wBankReadGrantedDelay[`MAX_TMEM_BANKS-1:0];
302
        Module_BusArbitrer ARB_TMEM
303
        (
304
        .Clock( CLK_I ),
305
        .Reset( RST_I ),
306
        .iRequest( {wBankReadRequest[3][Bank],wBankReadRequest[2][Bank],wBankReadRequest[1][Bank],wBankReadRequest[0][Bank]}),
307
        .oGrant(   wBankReadGrantedDelay[Bank]  ),  //The bit of the core granted to read from this Bank
308
        .oBusSelect( wCurrentCoreSelected[Bank] )                       //The index of the core granted to read from this Bank
309
 
310
        );
311
 
312
        FFD_POSEDGE_SYNCRONOUS_RESET # ( `MAX_CORES ) FFD_GNT
313
(
314
        .Clock(CLK_I),
315
        .Reset(RST_I),
316
        .Enable( 1'b1 ),
317
        .D(wBankReadGrantedDelay[Bank]),
318
        .Q(wBankReadGranted[Bank])
319
);
320
 
321
 
322
        //Create the Cross-Bar interconnection grid now, rows are coonected to the memory banks,
323
        //while collumns are connected to the cores, 2 or more cores can not read from the same
324
        //bank at any given point in time
325
        for (Core = 0; Core < `MAX_CORES; Core = Core + 1)
326
        begin: CORE_CONNECT
327
                //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
328
                assign wCrossBarDataCollumn[ Core ] = ( wCoreBankSelect[ Core ] == Bank ) ? wCrossBarDataRow[ Bank ] : `WB_WIDTH'bz;
329
                //Connect the Address Row of this Bank to the Address Column of the core, only if the Arbiter selected this core for reading
330
                assign wCrossBarAddressRow[ Bank ] = ( wCurrentCoreSelected[ Bank ] == Core ) ? wCrossBarAdressCollumn[Core]: `WB_WIDTH'bz;
331
 
332
        end
333
 
334
end
335
endgenerate
336
 
337
////////////// CROSS-BAR INTERCONECTION//////////////////////////
338
//----------------------------------------------------------------
339
 
340
endmodule
341
//---------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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