-
Notifications
You must be signed in to change notification settings - Fork 3
/
TinyORAMASICWrap.v
362 lines (282 loc) · 12.4 KB
/
TinyORAMASICWrap.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
//==============================================================================
// Section: Includes
//==============================================================================
`include "Const.vh"
//==============================================================================
//==============================================================================
// Module: TinyORAMASICWrap
// Desc: TinyORAMCore augmented with modules to test functionality and
// power for the chip tapeout.
//
// Modes explanation:
// Mode_TrafficGen: Are we using the traffic gen to test ORAM
// *functionality*
// Mode_DummyGen: Are we doing dummy requests forever to test
// *backend power*
//
// Modes encoding:
// Mode_TrafficGen Mode_DummyGen
// 0 0 Takes requests from L2 w/ normal DRAM backend
// 0 1 Self-contained dummy gen test
// 1 0 Traffic gen with normal DRAM backend
// 1 1 Self-contained dummy gen test
//==============================================================================
module TinyORAMASICWrap(
Clock, Reset,
Cmd, PAddr, WMask,
CmdValid, CmdReady,
DataIn,
DataInValid, DataInReady,
DataOut,
DataOutValid, DataOutReady,
DRAMAddress, DRAMCommand, DRAMCommandValid, DRAMCommandReady,
DRAMReadData, DRAMReadDataValid,
DRAMWriteData, DRAMWriteDataValid, DRAMWriteDataReady,
Mode_TrafficGen,
Mode_DummyGen,
ctap_oram_req_val, oram_ctap_res_data
);
//--------------------------------------------------------------------------
// Constants
//--------------------------------------------------------------------------
`ifdef SIMULATION_VIVADO
parameter NetworkWidth = 64; // Princeton's network
parameter JTPWidth = 8;
`else
`include "network_define.v"
`include "jtag.vh"
parameter NetworkWidth = `DATA_WIDTH;
parameter JTPWidth = `JTAG_ORAM_DATA_WIDTH;
`endif
`include "PathORAM.vh"
`include "DMLocal.vh"
`include "DDR3SDRAMLocal.vh"
`include "BucketLocal.vh"
`include "CommandsLocal.vh"
`include "JTAG.vh"
//--------------------------------------------------------------------------
// System I/O
//--------------------------------------------------------------------------
input Clock, Reset;
//--------------------------------------------------------------------------
// User interface
//--------------------------------------------------------------------------
input [BECMDWidth-1:0] Cmd;
input [ORAMU-1:0] PAddr;
input [DMWidth-1:0] WMask;
input CmdValid;
output CmdReady;
input [FEDWidth-1:0] DataIn;
input DataInValid;
output DataInReady;
output [FEDWidth-1:0] DataOut;
output DataOutValid;
input DataOutReady;
//--------------------------------------------------------------------------
// DRAM interface
//--------------------------------------------------------------------------
output [DDRAWidth-1:0] DRAMAddress;
output [DDRCWidth-1:0] DRAMCommand;
output DRAMCommandValid;
input DRAMCommandReady;
input [NetworkWidth-1:0] DRAMReadData;
input DRAMReadDataValid;
output [NetworkWidth-1:0] DRAMWriteData;
output DRAMWriteDataValid;
input DRAMWriteDataReady;
//--------------------------------------------------------------------------
// Mode interface
//--------------------------------------------------------------------------
input Mode_TrafficGen, Mode_DummyGen;
//--------------------------------------------------------------------------
// JTAG interface [to Princeton]
//--------------------------------------------------------------------------
input ctap_oram_req_val;
output [JTPWidth-1:0] oram_ctap_res_data;
//--------------------------------------------------------------------------
// Wires & Regs
//--------------------------------------------------------------------------
wire [BECMDWidth-1:0] Cmd_ORAM;
wire [ORAMU-1:0] PAddr_ORAM;
wire [DMWidth-1:0] WMask_ORAM;
wire CmdValid_ORAM, CmdReady_ORAM;
wire [FEDWidth-1:0] DataIn_ORAM;
wire DataInValid_ORAM, DataInReady_ORAM;
wire [FEDWidth-1:0] DataOut_ORAM;
wire DataOutValid_ORAM, DataOutReady_ORAM;
wire [BECMDWidth-1:0] Cmd_TGen;
wire [ORAMU-1:0] PAddr_TGen;
wire CmdValid_TGen, CmdReady_TGen;
wire [FEDWidth-1:0] DataIn_TGen;
wire DataInValid_TGen, DataInReady_TGen;
wire [FEDWidth-1:0] DataOut_TGen;
wire DataOutValid_TGen, DataOutReady_TGen;
wire [DDRAWidth-1:0] DRAMAddress_ORAM;
wire [DDRCWidth-1:0] DRAMCommand_ORAM;
wire DRAMCommandValid_ORAM, DRAMCommandReady_ORAM;
wire [BEDWidth-1:0] DRAMReadData_ORAM;
wire DRAMReadDataValid_ORAM;
wire [BEDWidth-1:0] DRAMWriteData_ORAM;
wire DRAMWriteDataValid_ORAM, DRAMWriteDataReady_ORAM;
wire [BEDWidth-1:0] DRAMReadData_DGen;
wire DRAMCommandValid_DGen, DRAMCommandReady_DGen, DRAMReadDataValid_DGen;
wire [BEDWidth-1:0] DRAMReadData_BED, DRAMWriteData_BED;
wire DRAMReadDataValid_BED, DRAMWriteDataValid_BED, DRAMWriteDataReady_BED;
// Debugging
wire [JTWidth_Top-1:0] JTAG_Top;
wire [JTWidth_Traffic-1:0] JTAG_Traffic;
wire [JTWidth_UORAM-1:0] JTAG_UORAM;
wire [JTWidth_PMMAC-1:0] JTAG_PMMAC;
wire [JTWidth_Frontend-1:0] JTAG_Frontend;
wire [JTWidth_AES-1:0] JTAG_AES;
wire [JTWidth_StashCore-1:0] JTAG_StashCore;
wire [JTWidth_Stash-1:0] JTAG_Stash;
wire [JTWidth_StashTop-1:0] JTAG_StashTop;
wire [JTWidth_BackendCore-1:0] JTAG_BackendCore;
wire [JTWidth_Backend-1:0] JTAG_Backend;
wire [JTWidth-1:0] JTagData_Wide;
wire JTagInValid, JTagOutValid, JTagOutReady;
//--------------------------------------------------------------------------
// Debugging
//--------------------------------------------------------------------------
assign JTAG_Top = 32'hdeadbeef;
FIFOShiftRound #( .IWidth( JTWidth),
.OWidth( JTPWidth))
jtshift( .Clock( Clock),
.Reset( Reset),
.InData( JTagData_Wide),
.InValid( JTagInValid),
.InAccept( ),
.OutData( oram_ctap_res_data),
.OutValid( JTagOutValid),
.OutReady( JTagOutReady));
assign JTagInValid = ~JTagOutValid && ctap_oram_req_val;
assign JTagOutReady = ctap_oram_req_val;
assign JTagData_Wide = {
JTAG_Top,
JTAG_Traffic,
JTAG_UORAM,
JTAG_PMMAC,
JTAG_Frontend,
JTAG_AES,
JTAG_StashCore,
JTAG_Stash,
JTAG_StashTop,
JTAG_BackendCore,
JTAG_Backend
};
//--------------------------------------------------------------------------
// Core modules
//--------------------------------------------------------------------------
TrafficGenASIC tgen( .Clock( Clock),
.Reset( Reset),
.ORAMCommand( Cmd_TGen),
.ORAMPAddr( PAddr_TGen),
.ORAMCommandValid( CmdValid_TGen),
.ORAMCommandReady( CmdReady_TGen),
.ORAMDataIn( DataIn_TGen),
.ORAMDataInValid( DataInValid_TGen),
.ORAMDataInReady( DataInReady_TGen),
.ORAMDataOut( DataOut_TGen),
.ORAMDataOutValid( DataOutValid_TGen),
.ORAMDataOutReady( DataOutReady_TGen),
.JTAG_Traffic( JTAG_Traffic));
assign Cmd_ORAM = (Mode_TrafficGen) ? Cmd_TGen : Cmd;
assign PAddr_ORAM = (Mode_TrafficGen) ? PAddr_TGen : PAddr;
assign WMask_ORAM = (Mode_TrafficGen) ? {DMWidth{1'b1}} : WMask;
assign CmdValid_ORAM = ( (Mode_TrafficGen) ? CmdValid_TGen : CmdValid ) && ~Mode_DummyGen;
assign CmdReady_TGen = ( (Mode_TrafficGen) ? CmdReady_ORAM : 1'b0 ) && ~Mode_DummyGen;
assign CmdReady = ( (Mode_TrafficGen) ? 1'b0 : CmdReady_ORAM ) && ~Mode_DummyGen;
assign DataIn_ORAM = (Mode_TrafficGen) ? DataIn_TGen : DataIn;
assign DataInValid_ORAM = ( (Mode_TrafficGen) ? DataInValid_TGen : DataInValid ) && ~Mode_DummyGen;
assign DataInReady_TGen = ( (Mode_TrafficGen) ? DataInReady_ORAM : 1'b0 ) && ~Mode_DummyGen;
assign DataInReady = ( (Mode_TrafficGen) ? 1'b0 : DataInReady_ORAM) && ~Mode_DummyGen;
assign DataOut_TGen = DataOut_ORAM;
assign DataOut = DataOut_ORAM;
assign DataOutValid_TGen = ( (Mode_TrafficGen) ? DataOutValid_ORAM : 1'b0 ) && ~Mode_DummyGen;
assign DataOutValid = ( (Mode_TrafficGen) ? 1'b0 : DataOutValid_ORAM) && ~Mode_DummyGen;
assign DataOutReady_ORAM = ( (Mode_TrafficGen) ? DataOutReady_TGen : DataOutReady) && ~Mode_DummyGen;
TinyORAMCore core( .Clock( Clock),
.Reset( Reset),
.Cmd( Cmd_ORAM),
.PAddr( PAddr_ORAM),
.WMask( WMask_ORAM),
.CmdValid( CmdValid_ORAM),
.CmdReady( CmdReady_ORAM),
.DataIn( DataIn_ORAM),
.DataInValid( DataInValid_ORAM),
.DataInReady( DataInReady_ORAM),
.DataOut( DataOut_ORAM),
.DataOutValid( DataOutValid_ORAM),
.DataOutReady( DataOutReady_ORAM),
.DRAMAddress( DRAMAddress_ORAM),
.DRAMCommand( DRAMCommand_ORAM),
.DRAMCommandValid( DRAMCommandValid_ORAM),
.DRAMCommandReady( DRAMCommandReady_ORAM),
.DRAMReadData( DRAMReadData_ORAM),
.DRAMReadDataValid( DRAMReadDataValid_ORAM),
.DRAMWriteData( DRAMWriteData_ORAM),
.DRAMWriteDataValid( DRAMWriteDataValid_ORAM),
.DRAMWriteDataReady( DRAMWriteDataReady_ORAM),
.Mode_DummyGen( Mode_DummyGen),
.JTAG_PMMAC( JTAG_PMMAC),
.JTAG_UORAM( JTAG_UORAM),
.JTAG_Frontend( JTAG_Frontend),
.JTAG_AES( JTAG_AES),
.JTAG_StashCore( JTAG_StashCore),
.JTAG_Stash( JTAG_Stash),
.JTAG_StashTop( JTAG_StashTop),
.JTAG_BackendCore( JTAG_BackendCore),
.JTAG_Backend( JTAG_Backend));
`ifdef SIMULATION
always @(posedge Clock) begin
if (DRAMReadDataValid_ORAM && Mode_DummyGen)
$display("DummyGen giving data %x", DRAMReadData_ORAM);
if (DRAMWriteDataValid_ORAM && Mode_DummyGen)
$display("DummyGen getting data %x", DRAMWriteData_ORAM);
end
`endif
assign DRAMAddress = DRAMAddress_ORAM;
assign DRAMCommand = DRAMCommand_ORAM;
assign DRAMCommandValid = (Mode_DummyGen) ? 1'b0 : DRAMCommandValid_ORAM;
assign DRAMCommandValid_DGen = (Mode_DummyGen) ? DRAMCommandValid_ORAM && DRAMCommand_ORAM == DDR3CMD_Read : 1'b0;
assign DRAMCommandReady_ORAM = (Mode_DummyGen) ? DRAMCommandReady_DGen : DRAMCommandReady;
assign DRAMReadData_ORAM = (Mode_DummyGen) ? DRAMReadData_DGen : DRAMReadData_BED;
assign DRAMReadDataValid_ORAM = (Mode_DummyGen) ? DRAMReadDataValid_DGen : DRAMReadDataValid_BED;
assign DRAMWriteData_BED = DRAMWriteData_ORAM;
assign DRAMWriteDataValid_BED = (Mode_DummyGen) ? 1'b0 : DRAMWriteDataValid_ORAM;
assign DRAMWriteDataReady_ORAM = (Mode_DummyGen) ? 1'b1 : DRAMWriteDataReady_BED;
DummyGenASIC dgen( .Clock( Clock),
.Reset( Reset),
.DRAMCommandValid( DRAMCommandValid_DGen),
.DRAMCommandReady( DRAMCommandReady_DGen),
.DRAMReadData( DRAMReadData_DGen),
.DRAMReadDataValid( DRAMReadDataValid_DGen));
//--------------------------------------------------------------------------
// Funnels to Princeton network width
//--------------------------------------------------------------------------
FIFOShiftRound #( .IWidth( NetworkWidth),
.OWidth( BEDWidth),
.Register( 1))
rd_shft( .Clock( Clock),
.Reset( Reset),
.InData( DRAMReadData),
.InValid( DRAMReadDataValid),
.InAccept( ),
.OutData( DRAMReadData_BED),
.OutValid( DRAMReadDataValid_BED),
.OutReady( 1'b1));
FIFOShiftRound #( .IWidth( BEDWidth),
.OWidth( NetworkWidth),
.Register( 1))
wr_shft( .Clock( Clock),
.Reset( Reset),
.InData( DRAMWriteData_BED),
.InValid( DRAMWriteDataValid_BED),
.InAccept( DRAMWriteDataReady_BED),
.OutData( DRAMWriteData),
.OutValid( DRAMWriteDataValid),
.OutReady( DRAMWriteDataReady));
//--------------------------------------------------------------------------
endmodule
//------------------------------------------------------------------------------