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

Subversion Repositories theia_gpu

[/] [theia_gpu/] [branches/] [icarus_version/] [rtl/] [Theia.v] - Blame information for rev 200

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

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

powered by: WebSVN 2.1.0

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