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

Subversion Repositories sparc64soc

[/] [sparc64soc/] [trunk/] [T1-common/] [srams/] [bw_r_tlb_fpga.v] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 dmitryr
// ========== Copyright Header Begin ==========================================
2
// 
3
// OpenSPARC T1 Processor File: bw_r_tlb.v
4
// Copyright (c) 2006 Sun Microsystems, Inc.  All Rights Reserved.
5
// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
6
// 
7
// The above named program is free software; you can redistribute it and/or
8
// modify it under the terms of the GNU General Public
9
// License version 2 as published by the Free Software Foundation.
10
// 
11
// The above named program is distributed in the hope that it will be 
12
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
// General Public License for more details.
15
// 
16
// You should have received a copy of the GNU General Public
17
// License along with this work; if not, write to the Free Software
18
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19
// 
20
// ========== Copyright Header End ============================================
21
///////////////////////////////////////////////////////////////////////
22
/*
23
//      Description:    Common TLB for Instruction Fetch and Load/Stores
24
*/
25
////////////////////////////////////////////////////////////////////////
26
// Global header file includes
27
////////////////////////////////////////////////////////////////////////
28
`include        "sys.h" // system level definition file which contains the 
29
                                        // time scale definition
30
 
31
////////////////////////////////////////////////////////////////////////
32
// Local header file includes / local defines
33
////////////////////////////////////////////////////////////////////////
34
`include        "lsu.h"
35
 
36
//FPGA_SYN enables all FPGA related modifications
37
`ifdef FPGA_SYN
38
`define FPGA_SYN_TLB
39
`endif
40
 
41
 
42
`ifdef FPGA_SYN_TLB
43
`ifdef FPGA_SYN_8TLB
44
  `define TLB_ENTRIES 8
45
  `define TLB_INDEX_WIDTH 3
46
`else
47
`ifdef FPGA_SYN_16TLB
48
  `define TLB_ENTRIES 16
49
  `define TLB_INDEX_WIDTH 4
50
`else
51
`ifdef FPGA_SYN_32TLB
52
  `define TLB_ENTRIES 32
53
  `define TLB_INDEX_WIDTH 5
54
`else
55
  `define TLB_ENTRIES 64
56
  `define TLB_INDEX_WIDTH 6
57
`endif
58
`endif
59
`endif
60
 
61
module bw_r_tlb_fpga ( /*AUTOARG*/
62
   // Outputs
63
   tlb_rd_tte_tag, tlb_rd_tte_data, tlb_pgnum, tlb_pgnum_crit,
64
   tlb_cam_hit, cache_way_hit, cache_hit, so,
65
   // Inputs
66
   tlb_cam_vld, tlb_cam_key, tlb_cam_pid,
67
   tlb_demap_key, tlb_addr_mask_l, tlb_ctxt,
68
   tlb_wr_vld, tlb_wr_tte_tag, tlb_wr_tte_data, tlb_rd_tag_vld,
69
   tlb_rd_data_vld, tlb_rw_index, tlb_rw_index_vld, tlb_demap,
70
   tlb_demap_auto, tlb_demap_all, cache_ptag_w0, cache_ptag_w1,
71
   cache_ptag_w2, cache_ptag_w3, cache_set_vld, tlb_bypass_va,
72
   tlb_bypass, se, si, hold, adj, arst_l, rst_soft_l, rclk,
73
   rst_tri_en
74
   ) ;
75
 
76
 
77
input                   tlb_cam_vld ;           // ld/st requires xlation. 
78
input   [40:0]           tlb_cam_key ;           // cam data for loads/stores;includes vld 
79
                                                // CHANGE : add real bit for cam.
80
input   [2:0]            tlb_cam_pid ;           // NEW: pid for cam. 
81
input   [40:0]           tlb_demap_key ;         // cam data for demap; includes vlds. 
82
                                                // CHANGE : add real bit for demap
83
input                   tlb_addr_mask_l ;       // address masking occurs
84
input   [12:0]           tlb_ctxt ;              // context for cam xslate/demap. 
85
input                   tlb_wr_vld;             // write to tlb. 
86
input   [58:0]           tlb_wr_tte_tag;         // CHANGE:tte tag to be written (55+4-1)
87
                                                // R(+1b),PID(+3b),G(-1b). 
88
input   [42:0]           tlb_wr_tte_data;        // tte data to be written.
89
                                                // No change(!!!) - G bit becomes spare
90
input                   tlb_rd_tag_vld ;        // read tag
91
input                   tlb_rd_data_vld ;       // read data
92
input   [5:0]            tlb_rw_index ;          // index to read/write tlb.
93
input                   tlb_rw_index_vld ;      // indexed write else use algorithm.
94
input                   tlb_demap ;             // demap : page/ctxt/all/auto.  
95
input                   tlb_demap_auto ;        // demap is of type auto 
96
input                   tlb_demap_all;          // demap-all operation : encoded separately.
97
input   [29:0]           cache_ptag_w0;          // way1 30b(D)/29b(I) tag.
98
input   [29:0]           cache_ptag_w1;          // way2 30b(D)/29b(I) tag.
99
input   [29:0]           cache_ptag_w2;          // way0 30b(D)/29b(I) tag.
100
input   [29:0]           cache_ptag_w3;          // way3 30b(D)/29b(I) tag.
101
input   [3:0]            cache_set_vld;          // set vld-4 ways
102
input   [12:10]         tlb_bypass_va;          // bypass va.other va bits from cam-data
103
input                   tlb_bypass;             // bypass tlb xslation
104
 
105
input                   se ;                    // scan-enable ; unused
106
input                   si ;                    // scan data in ; unused
107
input                   hold ;                  // scan hold signal
108
input   [7:0]            adj ;                   // self-time adjustment ; unused
109
input                   arst_l ;                // synchronous for tlb ; unused 
110
input                   rst_soft_l ;            // software reset - asi
111
input                   rclk;
112
input                   rst_tri_en ;
113
 
114
output  [58:0]           tlb_rd_tte_tag;         // CHANGE: tte tag read from tlb.
115
output  [42:0]           tlb_rd_tte_data;        // tte data read from tlb.
116
// Need two ports for tlb_pgnum - critical and non-critical.
117
output  [39:10]         tlb_pgnum ;             // bypass or xslated pgnum
118
output  [39:10]         tlb_pgnum_crit ;        // bypass or xslated pgnum - critical
119
output                  tlb_cam_hit ;           // xlation hits in tlb.
120
output  [3:0]            cache_way_hit;          // tag comparison results.
121
output                  cache_hit;              // tag comparison result - 'or' of above.
122
 
123
//output                        tlb_writeable ;         // tlb can be written in current cycle.
124
 
125
output                  so ;            // scan data out ; unused
126
 
127
wire    [53:0]           tlb_cam_data ;
128
wire    [58:0]           wr_tte_tag ;    // CHANGE
129
wire    [42:0]           wr_tte_data ;
130
wire    [29:3]          phy_pgnum_m;
131
wire    [29:0]           pgnum_m;
132
wire    [`TLB_ENTRIES-1:0] used ;
133
wire                    tlb_not_writeable ;
134
wire    [40:25]         tlb_cam_key_masked ;
135
wire    [26:0]           tlb_cam_comp_key ;
136
wire                    cam_vld ;
137
wire                    demap_other ;
138
wire    [3:0]    cache_way_hit ;
139
wire    [`TLB_ENTRIES-1:0]               mismatch;
140
 
141
reg                     tlb_not_writeable_d1 ;
142
reg                     tlb_writeable ;
143
wire    [`TLB_ENTRIES-1:0]               tlb_entry_locked ;
144
wire    [`TLB_ENTRIES-1:0]               cam_hit ;
145
wire    [`TLB_ENTRIES-1:0]               demap_hit ;
146
reg     [`TLB_ENTRIES-1:0]               ademap_hit ;
147
wire    [58:0]           rd_tte_tag ;    // CHANGE
148
wire    [42:0]           rd_tte_data ;
149
wire    [42:0]           tlb_rd_tte_data ;
150
reg                     cam_vld_tmp ;
151
reg     [2:0]            cam_pid ;
152
reg     [53:0]           cam_data ;
153
reg                     demap_auto, demap_other_tmp, demap_all ;
154
reg     [`TLB_ENTRIES-1:0]               tlb_entry_vld ;
155
wire    [`TLB_ENTRIES-1:0]               tlb_entry_used ;
156
reg     [`TLB_ENTRIES-1:0]               tlb_entry_replace ;
157
reg     [`TLB_ENTRIES-1:0]               tlb_entry_replace_d2 ;
158
wire    [29:0]           pgnum_g ;
159
reg     [3:0]            cache_set_vld_g;
160
reg     [29:0]           cache_ptag_w0_g,cache_ptag_w1_g;
161
reg     [29:0]           cache_ptag_w2_g,cache_ptag_w3_g;
162
reg     [`TLB_ENTRIES-1:0]               rw_wdline ;
163
 
164
reg                     rd_tag;
165
reg                     rd_data;
166
reg                     wr_vld_tmp;
167
reg     [`TLB_INDEX_WIDTH-1:0]           rw_index;
168
reg                     rw_index_vld;
169
reg     [29:0]           vrtl_pgnum_m;
170
wire                    bypass ;
171
reg         bypass_d;
172
wire                    wr_vld ;
173
 
174
integer i,j,k,l,m,n,p,r,s,t,u,w;
175
 
176
`define CAM_CTXT_12_0_HI        12      // 13b ctxt
177
`define CAM_CTXT_12_0_LO        0
178
 
179
 
180
//=========================================================================================
181
//      What's Left :
182
//=========================================================================================
183
 
184
// Scan Insertion - scan to be ignored in formal verification for now.
185
 
186
//=========================================================================================
187
//      Design Notes.
188
//=========================================================================================
189
 
190
// - Supported Demap Operations - By Page, By Context, All But
191
// Locked, Autodemap, Invalidate-All i.e., reset. Demap Partition is
192
// not supported - it is mapped to demap-all by logic. 
193
// - Interpretation of demap inputs
194
//      - tlb_demap - this is used to signal demap by page, by ctxt
195
//      ,all, and autodemap. 
196
//      - tlb_demap_ctxt - If a demap_by_ctxt operation is occuring then
197
//      this signal and tlb_demap must be active.
198
//      - tlb_demap_all - demap all operation. If a demap_all operation is
199
//      occuring, then tlb_demap_all must be asserted with tlb_demap. 
200
// - Reset is similar to demap-all except that *all* entries
201
// are invalidated. The action is initiated by software. The reset occurs
202
// on the negedge and is synchronous with the clk.
203
// - TTE Tag and Data
204
//      - The TTE tag and data can be read together. Each will have its 
205
//      own bus and the muxing will occur externally. The tag needs to
206
//      be read on a data request to supply the valid bit.
207
//      - The TTE tag and data can be written together.
208
// - The cam hit is a separate output signal based on the 
209
// the match signals.
210
// - Read/Write may occur based on supplied index. If not valid
211
// then use replacement way determined by algorithm to write.
212
// - Only write can use replacement way determined by algorithm.
213
// - Data is formatted appr. on read or write in the MMU. 
214
// - The TLB will generate a signal which reports whether the 
215
// tlb can be filled in the current cycle or not.
216
// **Physical Tag Comparison**
217
// For I-SIDE, comparison is of 28b, whereas for D-side, comparison is of 29b. The actual
218
// comparison, due to legacy, is for 30b.
219
// For the I-TLB, va[11:10] must be hardwired to the same value as the lsb of the 4 tags
220
// at the port level. Since the itag it only 28b, add two least significant bits to extend it to 30b.
221
// Similarly, for the dside, va[10] needs to be made same.      
222
// **Differentiating among Various TLB Operations**
223
// Valid bits are now associated with the key to allow selective incorporation of
224
// match results. The 5 valid bits are : v4(b47-28),v3(b27-22),v2(21-16),v1(b15-13)
225
// and Gk(G bit for auto-demap). The rules of use are :
226
//      - cam: v4-v1 are set high. G=~cam_real=0/1.
227
//      - demap_by_page : v4-v1 are set high. G=1. cam_real=0.
228
//      - demap_by_ctxt : v4-v1 are low. G=1. cam_real=0
229
//      - demap_all : v4-v1 are don't-care. G=x. cam_real=x
230
//      - autodemap : v4-v1 are based on page size of incoming tte. G=~cam_real=0/1.
231
// Note : Gk is now used only to void a context match on a Real Translation.
232
// In general, if a valid bit is low then the corresponding va field will not take
233
// part in the match. Similarly, for the ctxt, if Gk=1, the ctxt will participate
234
// in the match.
235
//
236
// Demap Table (For Satya) :
237
// Note : To include a context match, Gk must be set to 1.
238
//--------------------------------------------------------------------------------------------------------
239
//tlb_demap tlb_demap_all  tlb_ctxt Gk  Vk4 Vk3 Vk2 Vk1 Real    Operation
240
//--------------------------------------------------------------------------------------------------------
241
//0             x               x   x   x   x   x   x   0       No demap operation
242
//1             0                0   1   1   1   1   1   0        Demap by page
243
//1             0                0   1   1   0   0   0   0/1     256M demap(auto demap)
244
//1             0                0   0   1   0   0   0   0        256M demap(auto demap) (*Illgl*)
245
//1             0                0   1   1   1   0   0   0/1     4M demap(auto demap)
246
//1             0                0   0   1   1   0   0   0        4M demap(auto demap) (*Illgl*)
247
//1             0                0   1   1   1   1   0   0/1     64k demap(auto demap)
248
//1             0                0   0   1   1   1   0   0        64k demap(auto demap) (*Illgl*)
249
//1             0                0   1   1   1   1   1   0/1     8k demap(auto demap)
250
//1             0                0   0   1   1   1   1   0        8k demap(auto demap) (*Illgl*)
251
//1             0                1   1   0   0   0   0   0        demap by ctxt
252
//1             1               x   x   x   x   x   x   0        demap_all
253
//------------------------------------------------------------------------------------------
254
//-----
255
//All other are illegal combinations
256
//
257
//=========================================================================================
258
//      Changes related to Hypervisor/Legacy Compatibility
259
//=========================================================================================
260
//
261
// - Add PID. PID does not effect demap-all. Otherwise it is included in cam, other demap
262
// operations and auto-demap.
263
// - Add R. Real translation ignores context. This is controlled externally by Gk.
264
// - Remove G bit for tte. Input remains in demap-key/cam-key to allow for disabling
265
//   of context match Real Translation  
266
// - Final Page Size support - 8KB,64KB,4M,256M
267
// - SPARC_HPV_EN has been defined to enable new tlb design support. 
268
// Issues : 
269
// -Max ptag size is now 28b. Satya, will this help the speed at all. I doubt it !
270
 
271
//=========================================================================================
272
//      Miscellaneous
273
//=========================================================================================
274
   wire clk;
275
   assign clk = rclk;
276
 
277
wire async_reset, sync_reset ;
278
assign  async_reset = ~arst_l ;                         // hardware
279
assign  sync_reset = (~rst_soft_l & ~rst_tri_en) ;      // software
280
 
281
wire rw_disable ;
282
// INNO - wr/rd gated off. Note required as rst_tri_en is
283
// asserted, but implemented in addition in schematic.
284
assign  rw_disable = ~arst_l | rst_tri_en ;
285
 
286
 
287
reg     [`TLB_INDEX_WIDTH-1:0]   cam_hit_encoded;
288
integer ii;
289
 
290
reg cam_hit_any;
291
 
292
always @(cam_hit) begin
293
  cam_hit_any = 1'b0;
294
  cam_hit_encoded = {`TLB_INDEX_WIDTH{1'b0}};
295
  for(ii=0;ii<`TLB_ENTRIES;ii=ii+1) begin
296
    if(cam_hit[ii]) begin
297
      cam_hit_encoded = ii;
298
      cam_hit_any = 1'b1;
299
    end
300
  end
301
end
302
 
303
reg cam_hit_any_or_bypass;
304
 
305
always @(posedge clk)
306
  cam_hit_any_or_bypass <= cam_hit_any | bypass;
307
 
308
 
309
 
310
//=========================================================================================
311
//      Stage Data
312
//=========================================================================================
313
// Apply address masking
314
assign  tlb_cam_key_masked[40:25]
315
        = {16{tlb_addr_mask_l}} &
316
                tlb_cam_key[`CAM_VA_47_28_HI:`CAM_VA_47_28_LO+4] ;
317
 
318
// Reconstitute cam data CHANGE : add additional bit for real mapping
319
assign  tlb_cam_data[53:13] = tlb_demap ?
320
        tlb_demap_key[40:0] :
321
        {tlb_cam_key_masked[40:25],tlb_cam_key[`CAM_VA_47_28_LO+3:0]} ;
322
 
323
assign tlb_cam_comp_key[26:0] =
324
                tlb_demap ?
325
                        {tlb_demap_key[32:21], tlb_demap_key[19:14],tlb_demap_key[12:7],
326
                        tlb_demap_key[5:3]} :
327
                        {tlb_cam_key_masked[32:25],tlb_cam_key[24:21],
328
                        tlb_cam_key[19:14],tlb_cam_key[12:7],tlb_cam_key[5:3]} ;
329
 
330
assign  tlb_cam_data[12:0] = tlb_ctxt[12:0] ;
331
 
332
// These signals are flow-thru.
333
assign  wr_tte_tag[58:0]         = tlb_wr_tte_tag[58:0] ; // CHANGE
334
assign  wr_tte_data[42:0]        = tlb_wr_tte_data[42:0] ;
335
 
336
// CHANGE(SATYA) - Currently the rw_index/rw_index_vld are shared by both reads
337
// and writes. However, writes are done in the cycle of broadcast, whereas
338
// the reads are done a cycle later, as given in the model(incorrect) 
339
// They have to be treated uniformly. To make the model work, I've assumed the read/write 
340
// are done in the cycle the valids are broadcast. 
341
always @ (posedge clk)
342
        begin
343
        if (hold)
344
                begin
345
                cam_pid[2:0]             <= cam_pid[2:0] ;
346
                cam_vld_tmp             <= cam_vld_tmp ;
347
                cam_data[53:0]           <= cam_data[53:0] ;
348
                demap_other_tmp         <= demap_other_tmp ;
349
                demap_auto              <= demap_auto ;
350
                demap_all               <= demap_all ;
351
                wr_vld_tmp              <= wr_vld_tmp ;
352
                rd_tag                  <= rd_tag ;
353
                rd_data                 <= rd_data ;
354
                rw_index_vld            <= rw_index_vld ;
355
                rw_index[`TLB_INDEX_WIDTH-1:0]           <= rw_index[`TLB_INDEX_WIDTH-1:0] ;
356
                end
357
        else
358
                begin
359
                cam_pid[2:0]             <= tlb_cam_pid[2:0] ;
360
                cam_vld_tmp             <= tlb_cam_vld ;
361
                cam_data[53:0]           <= tlb_cam_data[53:0] ;
362
                demap_other_tmp         <= tlb_demap ;
363
                demap_auto              <= tlb_demap_auto ;
364
                demap_all               <= tlb_demap_all ;
365
                wr_vld_tmp              <= tlb_wr_vld ;
366
                rd_tag                  <= tlb_rd_tag_vld ;
367
                rd_data                 <= tlb_rd_data_vld ;
368
                rw_index_vld            <= tlb_rw_index_vld ;
369
                rw_index[`TLB_INDEX_WIDTH-1:0]           <= tlb_rw_index[`TLB_INDEX_WIDTH-1:0] ;
370
                end
371
 
372
        end
373
 
374
// INNO - gate cam,demap,wr with rst_tri_en.
375
reg rst_tri_en_lat;
376
 
377
 always        @ (clk)
378
 rst_tri_en_lat = rst_tri_en;
379
 
380
assign  cam_vld = cam_vld_tmp & ~rst_tri_en_lat ;
381
assign  demap_other = demap_other_tmp & ~rst_tri_en ;
382
assign  wr_vld = wr_vld_tmp & ~rst_tri_en ;
383
 
384
//=========================================================================================
385
//      Generate Write Wordlines
386
//=========================================================================================
387
 
388
 
389
assign tlb_rd_tte_tag[58:0] = rd_tte_tag[58:0] ;  // CHANGE
390
 
391
assign tlb_rd_tte_data[42:0]     = rd_tte_data[42:0] ;
392
 
393
//=========================================================================================
394
//      CAM/DEMAP STLB for xlation
395
//=========================================================================================
396
 
397
 
398
// Demap and CAM operation are mutually exclusive.
399
 
400
always  @ ( negedge clk )
401
        begin
402
 
403
                for (n=0;n<`TLB_ENTRIES;n=n+1)
404
                        begin
405
                                if (demap_auto & demap_other)
406
                                        ademap_hit[n] = (~mismatch[n] & demap_other & tlb_entry_vld[n]) ;
407
                        end
408
 
409
        end  // always
410
 
411
 
412
assign  tlb_cam_hit = |cam_hit[`TLB_ENTRIES-1:0] ;
413
 
414
// Change tlb_entry_vld handling for multi-threaded tlb writes.
415
// A write is always preceeded by an autodemap. The intent is to make the result of autodemap
416
// (clearing of vld bit if hit) invisible until write occurs. In the same cycle that the write
417
// occurs, the vld bit for an entry will be cleared if there is an autodemap hit. The write
418
// and admp action may even be to same entry. The write must dominate. There is no need to
419
// clear the dmp latches after the write/clear has occurred as the subsequent admp will set
420
// up new state in the latches.
421
 
422
// Define valid bit based on write/demap/reset. 
423
 
424
always  @ (/*AUTOSENSE*/rd_data or rd_tag or rw_index or rw_index_vld
425
           or wr_vld_tmp)
426
        begin
427
                for (i=0;i<`TLB_ENTRIES;i=i+1)
428
                        if ((rw_index[`TLB_INDEX_WIDTH-1:0] == i) & ((wr_vld_tmp & rw_index_vld) | rd_tag | rd_data))
429
                                rw_wdline[i] = 1'b1 ;
430
                        else    rw_wdline[i] = 1'b0 ;
431
 
432
        end
433
 
434
 
435
always @ (negedge clk)
436
        begin
437
        for (r=0;r<`TLB_ENTRIES;r=r+1)
438
        begin // for
439
        if (((rw_index_vld & rw_wdline[r]) | (~rw_index_vld & tlb_entry_replace_d2[r])) &
440
                wr_vld & ~rw_disable)
441
                        tlb_entry_vld[r] <= wr_tte_tag[`STLB_TAG_V] ;   // write
442
        else    begin
443
                if (ademap_hit[r] & wr_vld)                     // autodemap specifically
444
                        tlb_entry_vld[r] <= 1'b0 ;
445
                end
446
          if ((demap_hit[r] & ~demap_auto) | sync_reset)        // non-auto-demap, reset
447
                        tlb_entry_vld[r] <= 1'b0 ;
448
          if(async_reset) tlb_entry_vld[r] <= 1'b0 ;
449
 
450
        end // for
451
        end
452
 
453
 
454
//=========================================================================================
455
//      TAG COMPARISON
456
//=========================================================================================
457
 
458
reg [30:0] va_tag_plus ;
459
 
460
// Stage to m
461
always @(posedge clk)
462
                begin
463
                // INNO - add hold to this input
464
                if (hold)
465
                        va_tag_plus[30:0] <= va_tag_plus[30:0] ;
466
                else
467
                        va_tag_plus[30:0]
468
                        <= {tlb_cam_comp_key[26:0],tlb_bypass_va[12:10],tlb_bypass};
469
                end
470
 
471
always @(posedge clk)
472
   begin
473
      vrtl_pgnum_m[29:0] <= va_tag_plus[30:1] ;
474
      bypass_d<=va_tag_plus[0];
475
   end
476
assign bypass = va_tag_plus[0] ;
477
 
478
// Mux to bypass va or form pa tag based on tte-data.
479
 
480
assign  phy_pgnum_m[29:3] =
481
        {rd_tte_data[`STLB_DATA_PA_39_28_HI:`STLB_DATA_PA_39_28_LO],
482
                rd_tte_data[`STLB_DATA_PA_27_22_HI:`STLB_DATA_PA_27_22_LO],
483
                        rd_tte_data[`STLB_DATA_PA_21_16_HI:`STLB_DATA_PA_21_16_LO],
484
                                rd_tte_data[`STLB_DATA_PA_15_13_HI:`STLB_DATA_PA_15_13_LO]};
485
 
486
// Derive the tlb-based physical address.
487
assign pgnum_m[2:0] = vrtl_pgnum_m[2:0];
488
assign pgnum_m[5:3] = (~rd_tte_data[`STLB_DATA_15_13_SEL] & ~bypass_d)
489
                                ? phy_pgnum_m[5:3] : vrtl_pgnum_m[5:3] ;
490
assign pgnum_m[11:6] = (~rd_tte_data[`STLB_DATA_21_16_SEL] & ~bypass_d)
491
                                ? phy_pgnum_m[11:6] : vrtl_pgnum_m[11:6] ;
492
assign pgnum_m[17:12] = (~rd_tte_data[`STLB_DATA_27_22_SEL] & ~bypass_d)
493
                                ? phy_pgnum_m[17:12] : vrtl_pgnum_m[17:12] ;
494
assign pgnum_m[29:18] = ~bypass_d ? phy_pgnum_m[29:18] : vrtl_pgnum_m[29:18];
495
 
496
// Stage to g
497
// Flop tags in tlb itself and do comparison immediately after rising edge.
498
// Similarly stage va/pa tag to g
499
 
500
assign pgnum_g[29:0] = pgnum_m[29:0];
501
 
502
always @(posedge clk)
503
                begin
504
 
505
                        // rm hold on these inputs.
506
                        cache_set_vld_g[3:0]     <= cache_set_vld[3:0] ;
507
                        cache_ptag_w0_g[29:0]    <= cache_ptag_w0[29:0] ;
508
                        cache_ptag_w1_g[29:0]    <= cache_ptag_w1[29:0] ;
509
                        cache_ptag_w2_g[29:0]    <= cache_ptag_w2[29:0] ;
510
                        cache_ptag_w3_g[29:0]    <= cache_ptag_w3[29:0] ;
511
                end
512
 
513
 
514
// Need to stage by a cycle where used.
515
assign  tlb_pgnum[39:10] = pgnum_g[29:0] ;
516
// Same cycle as cam - meant for one load on critical path
517
assign  tlb_pgnum_crit[39:10] = pgnum_m[29:0] ;
518
 
519
 
520
assign  cache_way_hit[0] =
521
        (cache_ptag_w0_g[29:0] == pgnum_g[29:0]) & cache_set_vld_g[0] & cam_hit_any_or_bypass;
522
assign  cache_way_hit[1] =
523
        (cache_ptag_w1_g[29:0] == pgnum_g[29:0]) & cache_set_vld_g[1] & cam_hit_any_or_bypass;
524
assign  cache_way_hit[2] =
525
        (cache_ptag_w2_g[29:0] == pgnum_g[29:0]) & cache_set_vld_g[2] & cam_hit_any_or_bypass;
526
assign  cache_way_hit[3] =
527
        (cache_ptag_w3_g[29:0] == pgnum_g[29:0]) & cache_set_vld_g[3] & cam_hit_any_or_bypass;
528
 
529
assign  cache_hit = |cache_way_hit[3:0];
530
 
531
 
532
//=========================================================================================
533
//      TLB ENTRY REPLACEMENT
534
//=========================================================================================
535
 
536
// A single Used bit is used to track the replacement state of each entry.
537
// Only an unused entry can be replaced.
538
// An Unused entry is :
539
//                      - an invalid entry
540
//                      - a valid entry which has had its Used bit cleared.
541
//                              - on write of a valid entry, the Used bit is set.
542
//                              - The Used bit of a valid entry is cleared if all
543
//                              entries have their Used bits set and the entry itself is not Locked.
544
// A locked entry should always appear to be Used.
545
// A single priority-encoder is required to evaluate the used status. Priority is static
546
// and used entry0 is of the highest priority if unused.
547
 
548
// Timing :
549
// Used bit gets updated by cam-hit or hit on negedge.
550
// After Used bit gets updated off negedge, the replacement entry can be generated in
551
// Phase2. In parallel, it is determined whether all Used bits are set or not. If
552
// so, then they are cleared on the next negedge with the replacement entry generated
553
// in the related Phase1 
554
 
555
// Choosing replacement entry
556
// Replacement entry is integer k
557
 
558
assign  tlb_not_writeable = &used[`TLB_ENTRIES-1:0] ;
559
/*
560
// Used bit can be set because of write or because of cam-hit.
561
always @(negedge clk)
562
        begin
563
                for (s=0;s<`TLB_ENTRIES;s=s+1)
564
                        begin
565
                                if (cam_hit[s])
566
                                        tlb_entry_used[s] <= 1'b1;
567
                        end
568
 
569
// Clear on following edge if necessary.
570
// CHANGE(SATYA) : tlb_entry_used qualified with valid needs to be used to determine
571
// whether the Used bits are to be cleared. This allows invalid entries created
572
// by a demap to be used for replacement. Else we will ignore these entries
573
// for replacement
574
 
575
                if (tlb_not_writeable)
576
                        begin
577
                                for (t=0;t<`TLB_ENTRIES;t=t+1)
578
                                        begin
579
                                                if (~tlb_entry_locked[t])
580
                                                        tlb_entry_used[t] <= 1'b0;
581
                                        end
582
                        end
583
        end
584
*/
585
 
586
// Determine whether entry should be squashed.
587
 
588
assign  used[`TLB_ENTRIES-1:0] = tlb_entry_used[`TLB_ENTRIES-1:0] & tlb_entry_vld[`TLB_ENTRIES-1:0] ;
589
 
590
 
591
// Based on updated Used state, generate replacement entry.
592
// So, replacement entries can be generated on a cycle-by-cycle basis. 
593
//always @(/*AUTOSENSE*/squash or used)
594
 
595
        reg     [`TLB_ENTRIES-1:0]       tlb_entry_replace_d1;
596
        reg             tlb_replace_flag;
597
        always @(/*AUTOSENSE*/used)
598
        begin
599
          tlb_replace_flag=1'b0;
600
          tlb_entry_replace_d1 = {`TLB_ENTRIES-1{1'b0}};
601
          // Priority is given to entry0
602
          for (u=0;u<`TLB_ENTRIES;u=u+1)
603
          begin
604
            if(~tlb_replace_flag & ~used[u])
605
            begin
606
              tlb_entry_replace_d1[u] = ~used[u] ;
607
              tlb_replace_flag=1'b1;
608
            end
609
          end
610
          if(~tlb_replace_flag) begin
611
             tlb_entry_replace_d1[`TLB_ENTRIES-1] = 1'b1;
612
          end
613
        end
614
        always @(posedge clk)
615
        begin
616
          // named in this manner to keep arch model happy.
617
          tlb_entry_replace <= tlb_entry_replace_d1 ;
618
        end
619
        // INNO - 2 stage delay before update is visible
620
        always @(posedge clk)
621
        begin
622
          tlb_entry_replace_d2 <= tlb_entry_replace ;
623
        end
624
 
625
reg [`TLB_INDEX_WIDTH-1:0]  tlb_index_a1;
626
reg [`TLB_INDEX_WIDTH-1:0]  tlb_index;
627
wire tlb_index_vld_a1 = |tlb_entry_replace;
628
reg  tlb_index_vld;
629
integer jj;
630
always @(tlb_entry_replace) begin
631
  tlb_index_a1 = {`TLB_INDEX_WIDTH{1'b0}};
632
  for(jj=0;jj<`TLB_ENTRIES;jj=jj+1)
633
    if(tlb_entry_replace[jj]) tlb_index_a1 = jj;
634
end
635
always @(posedge clk) begin
636
  tlb_index <= tlb_index_a1;  //use instead of tlb_entry_replace_d2;
637
  tlb_index_vld <= tlb_index_vld_a1;
638
end
639
 
640
 
641
 
642
 
643
//=========================================================================================
644
//      TLB WRITEABLE DETECTION
645
//=========================================================================================
646
 
647
// 2-cycles later, tlb become writeable
648
always @(posedge clk)
649
        begin
650
                tlb_not_writeable_d1 <= tlb_not_writeable ;
651
        end
652
 
653
always @(posedge clk)
654
        begin
655
                tlb_writeable <= ~tlb_not_writeable_d1 ;
656
        end
657
 
658
bw_r_tlb_tag_ram_fpga bw_r_tlb_tag_ram_fpga (
659
        .rd_tag(rd_tag),
660
        .rw_index_vld(rw_index_vld),
661
        .wr_vld_tmp(wr_vld_tmp),
662
        .clk(clk),
663
        .rw_index(rw_index),
664
        .tlb_index(tlb_index),
665
        .tlb_index_vld(tlb_index_vld),
666
        .rw_disable(rw_disable),
667
        .rst_tri_en(rst_tri_en),
668
        .wr_tte_tag(wr_tte_tag),
669
        .tlb_entry_vld(tlb_entry_vld),
670
        .tlb_entry_used(tlb_entry_used),
671
        .tlb_entry_locked(tlb_entry_locked),
672
        .rd_tte_tag(rd_tte_tag),
673
        .mismatch(mismatch),
674
        .tlb_writeable(tlb_writeable),
675
        .cam_vld(cam_vld),
676
        .wr_vld(wr_vld),
677
        .cam_data(cam_data),
678
        .cam_hit(cam_hit),
679
        .cam_pid(cam_pid),
680
        .demap_all(demap_all),
681
        .demap_hit(demap_hit),
682
        .demap_other(demap_other)
683
);
684
 
685
bw_r_tlb_data_ram_fpga bw_r_tlb_data_ram_fpga (
686
        .rd_data(rd_data),
687
        .rw_index_vld(rw_index_vld),
688
        .wr_vld_tmp(wr_vld_tmp),
689
        .clk(clk),
690
        .cam_vld(cam_vld),
691
        .cam_index(cam_hit_encoded),
692
        .cam_hit_any(cam_hit_any),
693
        .rw_index(rw_index),
694
        .tlb_index(tlb_index),
695
        .tlb_index_vld(tlb_index_vld),
696
        .rw_disable(rw_disable),
697
        .rst_tri_en(rst_tri_en),
698
        .wr_tte_data(wr_tte_data),
699
        .rd_tte_data(rd_tte_data),
700
        .wr_vld(wr_vld)
701
);
702
 
703
 
704
endmodule
705
 
706
module bw_r_tlb_tag_ram_fpga(
707
        rd_tag,
708
        rw_index_vld,
709
        wr_vld_tmp,
710
        clk,
711
        rw_index,
712
        tlb_index,
713
        tlb_index_vld,
714
        rw_disable,
715
        rst_tri_en,
716
        wr_tte_tag,
717
        tlb_entry_vld,
718
        tlb_entry_used,
719
        tlb_entry_locked,
720
        rd_tte_tag,
721
        mismatch,
722
        tlb_writeable,
723
        wr_vld,
724
        cam_vld,
725
        cam_data,
726
        cam_hit,
727
        cam_pid,
728
        demap_all,
729
        demap_other,
730
        demap_hit);
731
 
732
input           rd_tag;
733
input           rw_index_vld;
734
input           wr_vld_tmp;
735
input           clk;
736
input   [`TLB_INDEX_WIDTH-1:0]   rw_index;
737
input   [`TLB_INDEX_WIDTH-1:0]   tlb_index;
738
input           tlb_index_vld;
739
input           rw_disable;
740
input           rst_tri_en;
741
input   [58:0]   wr_tte_tag;
742
input   [`TLB_ENTRIES-1:0]       tlb_entry_vld;
743
input           tlb_writeable;
744
input           wr_vld;
745
input   [2:0]    cam_pid;
746
input           demap_all;
747
input           demap_other;
748
input   [53:0]   cam_data;
749
input           cam_vld ;
750
 
751
output  [`TLB_ENTRIES-1:0]       cam_hit ;
752
output  [`TLB_ENTRIES-1:0]       demap_hit ;
753
output  [`TLB_ENTRIES-1:0]       tlb_entry_used;
754
output  [`TLB_ENTRIES-1:0]       tlb_entry_locked;
755
reg     [`TLB_ENTRIES-1:0]       tlb_entry_locked ;
756
 
757
output  [58:0]   rd_tte_tag;
758
reg     [58:0]   rd_tte_tag;
759
output  [`TLB_ENTRIES-1:0]       mismatch;
760
 
761
reg     [`TLB_ENTRIES-1:0]       sat;
762
 
763
reg     [`TLB_ENTRIES-1:0]       mismatch;
764
reg     [`TLB_ENTRIES-1:0]       cam_hit ;
765
reg     [`TLB_ENTRIES-1:0]       demap_all_but_locked_hit ;
766
reg     [58:0]   tag ;   // CHANGE
767
 
768
 
769
reg     [`TLB_ENTRIES-1:0]       mismatch_va_b47_28;
770
reg     [`TLB_ENTRIES-1:0]       mismatch_va_b27_22;
771
reg     [`TLB_ENTRIES-1:0]       mismatch_va_b21_16;
772
reg     [`TLB_ENTRIES-1:0]       mismatch_va_b15_13;
773
reg     [`TLB_ENTRIES-1:0]       mismatch_ctxt;
774
reg     [`TLB_ENTRIES-1:0]       mismatch_pid;
775
reg     [`TLB_ENTRIES-1:0]       mismatch_type;
776
reg     [`TLB_ENTRIES-1:0]       tlb_entry_used ;
777
 
778
integer i,j,n,m, w, p, k, s, t;
779
 
780
 
781
reg     [58:0]           tte_tag_ram  [`TLB_ENTRIES-1:0] /* synthesis syn_ramstyle = block_ram  syn_ramstyle = no_rw_check */ ;
782
 
783
reg     [58:0]   tmp_tag ;
784
 
785
wire wren = rw_index_vld & wr_vld_tmp & ~rw_disable;
786
wire tlben = tlb_index_vld & ~rw_index_vld & wr_vld_tmp & ~rw_disable;
787
wire  [`TLB_INDEX_WIDTH-1:0] wr_addr = wren ? rw_index : tlb_index;
788
 
789
 
790
always  @ (negedge clk) begin
791
//=========================================================================================
792
//      Write TLB
793
//=========================================================================================
794
 
795
        if(wren | tlben) begin
796
                tte_tag_ram[wr_addr] <= wr_tte_tag[58:0];
797
                tlb_entry_used[wr_addr] <= wr_tte_tag[`STLB_TAG_U];
798
                tlb_entry_locked[wr_addr] = wr_tte_tag[`STLB_TAG_L];
799
        end else begin
800
          tlb_entry_used <= (tlb_entry_used | cam_hit) & (tlb_entry_locked | ~{`TLB_ENTRIES{~tlb_writeable & ~cam_vld & ~wr_vld & ~rd_tag & ~rst_tri_en}}) ;
801
        end
802
 
803
//=========================================================================================
804
//      Read STLB
805
//=========================================================================================
806
 
807
        if(rd_tag & ~rw_disable) begin
808
                tmp_tag  <= tte_tag_ram[rw_index];
809
        end
810
 
811
 
812
end // always
813
 
814
always @(posedge clk) begin
815
  if(rd_tag & ~rw_disable)
816
    rd_tte_tag[58:0] = {tmp_tag[58:27], tlb_entry_vld[rw_index], tlb_entry_locked[rw_index], tlb_entry_used[rw_index], tmp_tag[23:0]};
817
  else if(wren | tlben)
818
    rd_tte_tag[58:0] = wr_tte_tag[58:0];
819
end
820
 
821
reg     [58:0]           tte_tag_ram2  [`TLB_ENTRIES-1:0];
822
 
823
always  @ (negedge clk) begin
824
  if(wren | tlben)
825
    tte_tag_ram2[wr_addr] <= wr_tte_tag[58:0];
826
end
827
 
828
 
829
always  @ (cam_data or cam_pid or cam_vld or demap_all
830
           or demap_other or tlb_entry_vld)
831
        begin
832
 
833
                for (n=0;n<`TLB_ENTRIES;n=n+1)
834
                        begin
835
                        tag[58:0] = tte_tag_ram2[n] ;    // CHANGE
836
 
837
                        mismatch_va_b47_28[n] =
838
                        (tag[`STLB_TAG_VA_47_28_HI:`STLB_TAG_VA_47_28_LO]
839
                        != cam_data[`CAM_VA_47_28_HI+13:`CAM_VA_47_28_LO+13]);
840
 
841
                        mismatch_va_b27_22[n] =
842
                        (tag[`STLB_TAG_VA_27_22_HI:`STLB_TAG_VA_27_22_LO]
843
                        != cam_data[`CAM_VA_27_22_HI+13:`CAM_VA_27_22_LO+13]);
844
 
845
                        mismatch_va_b21_16[n] =
846
                        (tag[`STLB_TAG_VA_21_16_HI:`STLB_TAG_VA_21_16_LO]
847
                        != cam_data[`CAM_VA_21_16_HI+13:`CAM_VA_21_16_LO+13]) ;
848
 
849
                        mismatch_va_b15_13[n] =
850
                        (tag[`STLB_TAG_VA_15_13_HI:`STLB_TAG_VA_15_13_LO]
851
                        != cam_data[`CAM_VA_15_13_HI+13:`CAM_VA_15_13_LO+13]) ;
852
 
853
                        mismatch_ctxt[n] =
854
                        (tag[`STLB_TAG_CTXT_12_0_HI:`STLB_TAG_CTXT_12_0_LO]
855
                        != cam_data[`CAM_CTXT_12_0_HI:`CAM_CTXT_12_0_LO]) ;
856
 
857
                        mismatch_pid[n] = (tag[`STLB_TAG_PID_HI:`STLB_TAG_PID_LO] != cam_pid[2:0]) ;
858
                        mismatch_type[n] = (tag[`STLB_TAG_R] ^ cam_data[`CAM_REAL_V+13]);
859
 
860
                        mismatch[n] =
861
                        (mismatch_va_b47_28[n] & cam_data[`CAM_VA_47_28_V+13])                          |
862
                        (mismatch_va_b27_22[n] & tag[`STLB_TAG_VA_27_22_V] & cam_data[`CAM_VA_27_22_V+13])      |
863
                        (mismatch_va_b21_16[n] & tag[`STLB_TAG_VA_21_16_V] & cam_data[`CAM_VA_21_16_V+13])      |
864
                        (mismatch_va_b15_13[n] & tag[`STLB_TAG_VA_15_13_V] & cam_data[`CAM_VA_15_13_V+13])      |
865
                        (mismatch_ctxt[n] & ~cam_data[`CAM_CTXT_GK+13]) |
866
                        (mismatch_type[n] & ~demap_all)         |
867
                        mismatch_pid[n] ;       // pid always included in mismatch calculations
868
 
869
                        demap_all_but_locked_hit[n] = ~tag[`STLB_TAG_L] & demap_all ;
870
 
871
                        cam_hit[n]      = ~mismatch[n] & cam_vld   & tlb_entry_vld[n] ;
872
                end
873
 
874
        end  // always
875
 
876
        assign demap_hit = demap_all ? ~mismatch & demap_all_but_locked_hit & tlb_entry_vld & {`TLB_ENTRIES{demap_other}}
877
                                     : ~mismatch & tlb_entry_vld & {`TLB_ENTRIES{demap_other}};
878
 
879
endmodule
880
 
881
 
882
 
883
module bw_r_tlb_data_ram_fpga(rd_data, rw_index_vld, wr_vld_tmp, clk, cam_vld,
884
        rw_index, tlb_index, tlb_index_vld, rw_disable, rst_tri_en, wr_tte_data,
885
        rd_tte_data, cam_index, cam_hit_any, wr_vld);
886
 
887
        input                   rd_data;
888
        input                   rw_index_vld;
889
        input                   wr_vld_tmp;
890
        input                   clk;
891
        input   [(6 - 1):0]     rw_index;
892
        input   [(6 - 1):0]     tlb_index;
893
        input                   tlb_index_vld;
894
        input   [(6 - 1):0]     cam_index;
895
        input                   cam_hit_any;
896
        input                   rw_disable;
897
        input                   rst_tri_en;
898
        input                   cam_vld;
899
        input   [42:0]          wr_tte_data;
900
        input                   wr_vld;
901
        output  [42:0]          rd_tte_data;
902
 
903
        wire    [42:0]          rd_tte_data;
904
 
905
        reg     [42:0]          tte_data_ram[(64 - 1):0];
906
 
907
        wire [5:0] wr_addr = (rw_index_vld & wr_vld_tmp) ? rw_index :tlb_index;
908
        wire wr_en = ((rw_index_vld & wr_vld_tmp) & (~rw_disable)) |
909
                     (((tlb_index_vld & (~rw_index_vld)) & wr_vld_tmp) & (~rw_disable));
910
 
911
        always @(posedge clk) begin
912
          if (wr_en)
913
            tte_data_ram[wr_addr] <= wr_tte_data[42:0];
914
          end
915
 
916
        wire [5:0] rd_addr = rd_data ? rw_index : cam_index;
917
        wire rd_en = (rd_data & (~rw_disable)) | ((cam_vld & (~rw_disable)));
918
 
919
        reg [42:0] rd_tte_data_temp;
920
 
921
        always @(posedge clk) begin
922
          //required for simulation; otherwise regression fails...
923
          if((cam_vld & (~rw_disable)) & (!cam_hit_any)) begin
924
            rd_tte_data_temp <= 43'bx;
925
          end else
926
          if (rd_en) begin
927
            rd_tte_data_temp[42:0] <= tte_data_ram[rd_addr];
928
          end
929
        end
930
 
931
reg rdwe;
932
reg [42:0] wr_tte_data_d;
933
 
934
 
935
       always @(posedge clk) begin
936
         wr_tte_data_d <= wr_tte_data;
937
       end
938
       always @(posedge clk) begin
939
         if(wr_en) rdwe <= 1'b1;
940
         else if(rd_en) rdwe <= 1'b0;
941
       end
942
 
943
       assign rd_tte_data = rdwe ? wr_tte_data_d : rd_tte_data_temp;
944
 
945
endmodule
946
 
947
`else
948
 
949
module bw_r_tlb ( /*AUTOARG*/
950
   // Outputs
951
   tlb_rd_tte_tag, tlb_rd_tte_data, tlb_pgnum, tlb_pgnum_crit,
952
   tlb_cam_hit, cache_way_hit, cache_hit, so,
953
   // Inputs
954
   tlb_cam_vld, tlb_cam_key, tlb_cam_pid,
955
   tlb_demap_key, tlb_addr_mask_l, tlb_ctxt,
956
   tlb_wr_vld, tlb_wr_tte_tag, tlb_wr_tte_data, tlb_rd_tag_vld,
957
   tlb_rd_data_vld, tlb_rw_index, tlb_rw_index_vld, tlb_demap,
958
   tlb_demap_auto, tlb_demap_all, cache_ptag_w0, cache_ptag_w1,
959
   cache_ptag_w2, cache_ptag_w3, cache_set_vld, tlb_bypass_va,
960
   tlb_bypass, se, si, hold, adj, arst_l, rst_soft_l, rclk,
961
   rst_tri_en
962
   ) ;
963
 
964
 
965
input                   tlb_cam_vld ;           // ld/st requires xlation. 
966
input   [40:0]           tlb_cam_key ;           // cam data for loads/stores;includes vld 
967
                                                // CHANGE : add real bit for cam.
968
input   [2:0]            tlb_cam_pid ;           // NEW: pid for cam. 
969
input   [40:0]           tlb_demap_key ;         // cam data for demap; includes vlds. 
970
                                                // CHANGE : add real bit for demap
971
input                   tlb_addr_mask_l ;       // address masking occurs
972
input   [12:0]           tlb_ctxt ;              // context for cam xslate/demap. 
973
input                   tlb_wr_vld;             // write to tlb. 
974
input   [58:0]           tlb_wr_tte_tag;         // CHANGE:tte tag to be written (55+4-1)
975
                                                // R(+1b),PID(+3b),G(-1b). 
976
input   [42:0]           tlb_wr_tte_data;        // tte data to be written.
977
                                                // No change(!!!) - G bit becomes spare
978
input                   tlb_rd_tag_vld ;        // read tag
979
input                   tlb_rd_data_vld ;       // read data
980
input   [5:0]            tlb_rw_index ;          // index to read/write tlb.
981
input                   tlb_rw_index_vld ;      // indexed write else use algorithm.
982
input                   tlb_demap ;             // demap : page/ctxt/all/auto.  
983
input                   tlb_demap_auto ;        // demap is of type auto 
984
input                   tlb_demap_all;          // demap-all operation : encoded separately.
985
input   [29:0]           cache_ptag_w0;          // way1 30b(D)/29b(I) tag.
986
input   [29:0]           cache_ptag_w1;          // way2 30b(D)/29b(I) tag.
987
input   [29:0]           cache_ptag_w2;          // way0 30b(D)/29b(I) tag.
988
input   [29:0]           cache_ptag_w3;          // way3 30b(D)/29b(I) tag.
989
input   [3:0]            cache_set_vld;          // set vld-4 ways
990
input   [12:10]         tlb_bypass_va;          // bypass va.other va bits from cam-data
991
input                   tlb_bypass;             // bypass tlb xslation
992
 
993
input                   se ;                    // scan-enable ; unused
994
input                   si ;                    // scan data in ; unused
995
input                   hold ;                  // scan hold signal
996
input   [7:0]            adj ;                   // self-time adjustment ; unused
997
input                   arst_l ;                // synchronous for tlb ; unused 
998
input                   rst_soft_l ;            // software reset - asi
999
input                   rclk;
1000
input                   rst_tri_en ;
1001
 
1002
output  [58:0]           tlb_rd_tte_tag;         // CHANGE: tte tag read from tlb.
1003
output  [42:0]           tlb_rd_tte_data;        // tte data read from tlb.
1004
// Need two ports for tlb_pgnum - critical and non-critical.
1005
output  [39:10]         tlb_pgnum ;             // bypass or xslated pgnum
1006
output  [39:10]         tlb_pgnum_crit ;        // bypass or xslated pgnum - critical
1007
output                  tlb_cam_hit ;           // xlation hits in tlb.
1008
output  [3:0]            cache_way_hit;          // tag comparison results.
1009
output                  cache_hit;              // tag comparison result - 'or' of above.
1010
 
1011
//output                        tlb_writeable ;         // tlb can be written in current cycle.
1012
 
1013
output                  so ;            // scan data out ; unused
1014
 
1015
wire    [53:0]           tlb_cam_data ;
1016
wire    [58:0]           wr_tte_tag ;    // CHANGE
1017
wire    [42:0]           wr_tte_data ;
1018
wire    [29:3]          phy_pgnum_m;
1019
wire    [29:0]           pgnum_m;
1020
wire    [63:0]           used ;
1021
wire                    tlb_not_writeable ;
1022
wire    [40:25]         tlb_cam_key_masked ;
1023
wire    [26:0]           tlb_cam_comp_key ;
1024
wire                    cam_vld ;
1025
wire                    demap_other ;
1026
wire    [3:0]    cache_way_hit ;
1027
 
1028
reg                     tlb_not_writeable_d1 ;
1029
reg                     tlb_writeable ;
1030
reg     [58:0]           tte_tag_ram  [63:0] ;    // CHANGE
1031
reg     [42:0]           tte_data_ram [63:0] ;
1032
reg     [63:0]           tlb_entry_vld ;
1033
reg     [63:0]           tlb_entry_locked ;
1034
reg     [63:0]           ademap_hit ;
1035
reg     [58:0]           rd_tte_tag ;    // CHANGE
1036
reg     [42:0]           rd_tte_data ;
1037
reg     [58:0]           tlb_rd_tte_tag ; // CHANGE      
1038
reg     [42:0]           tlb_rd_tte_data ;
1039
reg                     cam_vld_tmp ;
1040
reg     [2:0]            cam_pid ;
1041
reg     [53:0]           cam_data ;
1042
reg                     demap_auto, demap_other_tmp, demap_all ;
1043
reg     [63:0]           mismatch ;
1044
reg     [63:0]           cam_hit ;
1045
reg     [63:0]           demap_hit ;
1046
reg     [63:0]           demap_all_but_locked_hit ;
1047
reg     [63:0]           mismatch_va_b47_28 ;
1048
reg     [63:0]           mismatch_va_b27_22 ;
1049
reg     [63:0]           mismatch_va_b21_16 ;
1050
reg     [63:0]           mismatch_va_b15_13 ;
1051
reg     [63:0]           mismatch_ctxt ;
1052
reg     [63:0]           mismatch_pid ;
1053
reg     [58:0]           tag ;   // CHANGE
1054
reg     [63:0]           rw_wdline ;
1055
reg     [63:0]           tlb_entry_used ;
1056
reg     [63:0]           tlb_entry_replace ;
1057
reg     [63:0]           tlb_entry_replace_d2 ;
1058
reg     [29:0]           pgnum_g ;
1059
reg     [3:0]            cache_set_vld_g;
1060
reg     [29:0]           cache_ptag_w0_g,cache_ptag_w1_g;
1061
reg     [29:0]           cache_ptag_w2_g,cache_ptag_w3_g;
1062
reg                     wr_vld_tmp;
1063
reg                     rd_tag;
1064
reg                     rd_data;
1065
reg                     rw_index_vld;
1066
reg     [5:0]            rw_index;
1067
reg     [63:0]           sat ;
1068
 
1069
wire    [29:0]           vrtl_pgnum_m;
1070
wire                    bypass ;
1071
 
1072
wire                    wr_vld ;
1073
 
1074
integer i,j,k,l,m,n,p,r,s,t,u,w;
1075
 
1076
/*AUTOWIRE*/
1077
// Beginning of automatic wires (for undeclared instantiated-module outputs)
1078
// End of automatics
1079
 
1080
// Some bits are removed from the tag and data. 
1081
// 'U' must be defined as a '1' on a write.
1082
// 'L' required for demap all function.
1083
// Do not need an internal valid bit for va range 47:22.
1084
// These bits are always valid for a page. 
1085
// 
1086
// TTE STLB_TAG
1087
//
1088
//`define       STLB_TAG_PID_HI         58      : NEW PID - bit2
1089
//`define       STLB_TAG_PID_LO         56      : NEW PID - bit0
1090
//`define       STLB_TAG_R              55      : NEW Real bit
1091
//`define       STLB_TAG_PARITY         54      // Parity kept in same posn to avoid having
1092
//`define       STLB_TAG_VA_47_28_HI    53      // to redo interface
1093
//`define       STLB_TAG_VA_47_28_LO    34
1094
//`define       STLB_TAG_VA_27_22_HI    33      
1095
//`define       STLB_TAG_VA_27_22_LO    28
1096
//`define       STLB_TAG_27_22_V        27      
1097
//`define       STLB_TAG_V              26      : valid for entry. Write of 0 resets it.
1098
//`define       STLB_TAG_L              25
1099
//`define       STLB_TAG_U              24      
1100
//`define       STLB_TAG_VA_21_16_HI    23
1101
//`define       STLB_TAG_VA_21_16_LO    18
1102
//`define       STLB_TAG_VA_21_16_V     17              
1103
//`define       STLB_TAG_VA_15_13_HI    16
1104
//`define       STLB_TAG_VA_15_13_LO    14
1105
//`define       STLB_TAG_VA_15_13_V     13
1106
//`define       STLB_TAG_CTXT_12_0_HI   12      // removed Global bit
1107
//`define       STLB_TAG_CTXT_12_0_LO   0
1108
////                            Total - 59b
1109
////
1110
//// TTE STLB_DATA
1111
////
1112
//// Soft[12:7] & Soft2[58:50] are removed.
1113
//// Diag[49:41] are removed. Used bit used for Diag[0] on read.
1114
//// CV is included for software correctness.
1115
//// PA<40> is removed as it is not used.
1116
//// G/L present in data even though present in tag : can't read out simultaneously.
1117
//   (Unfortunately this is no longer correct. For data read, tag is also read
1118
//   simultaneously to get valid bit, used bits).
1119
//`define       STLB_DATA_PARITY        42 
1120
//`define       STLB_DATA_PA_39_28_HI   41      // CHANGE
1121
//`define       STLB_DATA_PA_39_28_LO   30
1122
//`define       STLB_DATA_PA_27_22_HI   29      // CHANGE
1123
//`define       STLB_DATA_PA_27_22_LO   24
1124
//`define       STLB_DATA_27_22_SEL     23
1125
//`define       STLB_DATA_PA_21_16_HI   22      // CHANGE
1126
//`define       STLB_DATA_PA_21_16_LO   17
1127
//`define       STLB_DATA_21_16_SEL     16
1128
//`define       STLB_DATA_PA_15_13_HI   15      
1129
//`define       STLB_DATA_PA_15_13_LO   13
1130
//`define       STLB_DATA_15_13_SEL     12
1131
//`define       STLB_DATA_V             11      : static, does not get modified.
1132
//`define       STLB_DATA_NFO           10
1133
//`define       STLB_DATA_IE            9
1134
//`define       STLB_DATA_L             8       : added for read.
1135
//`define       STLB_DATA_CP            7 
1136
//`define       STLB_DATA_CV            6 
1137
//`define       STLB_DATA_E             5 
1138
//`define       STLB_DATA_P             4 
1139
//`define       STLB_DATA_W             3 
1140
//`define       STLB_DATA_SPARE_HI      2       : Global bit has been removed
1141
//`define       STLB_DATA_SPARE_LO      0        
1142
//                              Total - 43b
1143
 
1144
// Valid bits for key(tlb_cam_key/tlb_demap_key).
1145
// Total - 41b
1146
//`define       CAM_VA_47_28_HI         40
1147
//`define       CAM_VA_47_28_LO         21
1148
//`define       CAM_VA_47_28_V          20      // b47-28 participate in match
1149
//`define       CAM_VA_27_22_HI         19
1150
//`define       CAM_VA_27_22_LO         14
1151
//`define       CAM_VA_27_22_V          13      // b27-22 participate in match
1152
//`define       CAM_VA_21_16_HI         12
1153
//`define       CAM_VA_21_16_LO         7
1154
//`define       CAM_VA_21_16_V          6       // b21-16 participate in match
1155
//`define       CAM_VA_15_13_HI         5       
1156
//`define       CAM_VA_15_13_LO         3       
1157
//`define       CAM_VA_15_13_V          2       // b15-13 participate in match
1158
//`define       CAM_CTXT_GK             1       // Context participates in match
1159
//`define       CAM_REAL_V              0        // cam/demap applies to real mapping
1160
 
1161
 
1162
// ctxt port is different from cam key port even though both are
1163
// required for cam. (tlb_ctxt)
1164
// If Gk is set then ctxt will not participate in match.
1165
// Total - 14b
1166
`define CAM_CTXT_12_0_HI        12      // 13b ctxt
1167
`define CAM_CTXT_12_0_LO        0
1168
 
1169
 
1170
//=========================================================================================
1171
//      What's Left :
1172
//=========================================================================================
1173
 
1174
// Scan Insertion - scan to be ignored in formal verification for now.
1175
 
1176
//=========================================================================================
1177
//      Design Notes.
1178
//=========================================================================================
1179
 
1180
// - Supported Demap Operations - By Page, By Context, All But
1181
// Locked, Autodemap, Invalidate-All i.e., reset. Demap Partition is
1182
// not supported - it is mapped to demap-all by logic. 
1183
// - Interpretation of demap inputs
1184
//      - tlb_demap - this is used to signal demap by page, by ctxt
1185
//      ,all, and autodemap. 
1186
//      - tlb_demap_ctxt - If a demap_by_ctxt operation is occuring then
1187
//      this signal and tlb_demap must be active.
1188
//      - tlb_demap_all - demap all operation. If a demap_all operation is
1189
//      occuring, then tlb_demap_all must be asserted with tlb_demap. 
1190
// - Reset is similar to demap-all except that *all* entries
1191
// are invalidated. The action is initiated by software. The reset occurs
1192
// on the negedge and is synchronous with the clk.
1193
// - TTE Tag and Data
1194
//      - The TTE tag and data can be read together. Each will have its 
1195
//      own bus and the muxing will occur externally. The tag needs to
1196
//      be read on a data request to supply the valid bit.
1197
//      - The TTE tag and data can be written together.
1198
// - The cam hit is a separate output signal based on the 
1199
// the match signals.
1200
// - Read/Write may occur based on supplied index. If not valid
1201
// then use replacement way determined by algorithm to write.
1202
// - Only write can use replacement way determined by algorithm.
1203
// - Data is formatted appr. on read or write in the MMU. 
1204
// - The TLB will generate a signal which reports whether the 
1205
// tlb can be filled in the current cycle or not.
1206
// **Physical Tag Comparison**
1207
// For I-SIDE, comparison is of 28b, whereas for D-side, comparison is of 29b. The actual
1208
// comparison, due to legacy, is for 30b.
1209
// For the I-TLB, va[11:10] must be hardwired to the same value as the lsb of the 4 tags
1210
// at the port level. Since the itag it only 28b, add two least significant bits to extend it to 30b.
1211
// Similarly, for the dside, va[10] needs to be made same.      
1212
// **Differentiating among Various TLB Operations**
1213
// Valid bits are now associated with the key to allow selective incorporation of
1214
// match results. The 5 valid bits are : v4(b47-28),v3(b27-22),v2(21-16),v1(b15-13)
1215
// and Gk(G bit for auto-demap). The rules of use are :
1216
//      - cam: v4-v1 are set high. G=~cam_real=0/1.
1217
//      - demap_by_page : v4-v1 are set high. G=1. cam_real=0.
1218
//      - demap_by_ctxt : v4-v1 are low. G=1. cam_real=0
1219
//      - demap_all : v4-v1 are don't-care. G=x. cam_real=x
1220
//      - autodemap : v4-v1 are based on page size of incoming tte. G=~cam_real=0/1.
1221
// Note : Gk is now used only to void a context match on a Real Translation.
1222
// In general, if a valid bit is low then the corresponding va field will not take
1223
// part in the match. Similarly, for the ctxt, if Gk=1, the ctxt will participate
1224
// in the match.
1225
//
1226
// Demap Table (For Satya) :
1227
// Note : To include a context match, Gk must be set to 1.
1228
//--------------------------------------------------------------------------------------------------------
1229
//tlb_demap tlb_demap_all  tlb_ctxt Gk  Vk4 Vk3 Vk2 Vk1 Real    Operation
1230
//--------------------------------------------------------------------------------------------------------
1231
//0             x               x   x   x   x   x   x   0       No demap operation
1232
//1             0                0   1   1   1   1   1   0        Demap by page
1233
//1             0                0   1   1   0   0   0   0/1     256M demap(auto demap)
1234
//1             0                0   0   1   0   0   0   0        256M demap(auto demap) (*Illgl*)
1235
//1             0                0   1   1   1   0   0   0/1     4M demap(auto demap)
1236
//1             0                0   0   1   1   0   0   0        4M demap(auto demap) (*Illgl*)
1237
//1             0                0   1   1   1   1   0   0/1     64k demap(auto demap)
1238
//1             0                0   0   1   1   1   0   0        64k demap(auto demap) (*Illgl*)
1239
//1             0                0   1   1   1   1   1   0/1     8k demap(auto demap)
1240
//1             0                0   0   1   1   1   1   0        8k demap(auto demap) (*Illgl*)
1241
//1             0                1   1   0   0   0   0   0        demap by ctxt
1242
//1             1               x   x   x   x   x   x   0        demap_all
1243
//------------------------------------------------------------------------------------------
1244
//-----
1245
//All other are illegal combinations
1246
//
1247
//=========================================================================================
1248
//      Changes related to Hypervisor/Legacy Compatibility
1249
//=========================================================================================
1250
//
1251
// - Add PID. PID does not effect demap-all. Otherwise it is included in cam, other demap
1252
// operations and auto-demap.
1253
// - Add R. Real translation ignores context. This is controlled externally by Gk.
1254
// - Remove G bit for tte. Input remains in demap-key/cam-key to allow for disabling
1255
//   of context match Real Translation  
1256
// - Final Page Size support - 8KB,64KB,4M,256M
1257
// - SPARC_HPV_EN has been defined to enable new tlb design support. 
1258
// Issues : 
1259
// -Max ptag size is now 28b. Satya, will this help the speed at all. I doubt it !
1260
 
1261
//=========================================================================================
1262
//      Miscellaneous
1263
//=========================================================================================
1264
   wire clk;
1265
   assign clk = rclk;
1266
 
1267
wire async_reset, sync_reset ;
1268
assign  async_reset = ~arst_l ;                         // hardware
1269
assign  sync_reset = (~rst_soft_l & ~rst_tri_en) ;      // software
1270
 
1271
wire rw_disable ;
1272
// INNO - wr/rd gated off. Note required as rst_tri_en is
1273
// asserted, but implemented in addition in schematic.
1274
assign  rw_disable = ~arst_l | rst_tri_en ;
1275
 
1276
//=========================================================================================
1277
//      Stage Data
1278
//=========================================================================================
1279
// Apply address masking
1280
assign  tlb_cam_key_masked[40:25]
1281
        = {16{tlb_addr_mask_l}} &
1282
                tlb_cam_key[`CAM_VA_47_28_HI:`CAM_VA_47_28_LO+4] ;
1283
 
1284
// Reconstitute cam data CHANGE : add additional bit for real mapping
1285
assign  tlb_cam_data[53:13] = tlb_demap ?
1286
        tlb_demap_key[40:0] :
1287
        {tlb_cam_key_masked[40:25],tlb_cam_key[`CAM_VA_47_28_LO+3:0]} ;
1288
 
1289
assign tlb_cam_comp_key[26:0] =
1290
                tlb_demap ?
1291
                        {tlb_demap_key[32:21], tlb_demap_key[19:14],tlb_demap_key[12:7],
1292
                        tlb_demap_key[5:3]} :
1293
                        {tlb_cam_key_masked[32:25],tlb_cam_key[24:21],
1294
                        tlb_cam_key[19:14],tlb_cam_key[12:7],tlb_cam_key[5:3]} ;
1295
 
1296
assign  tlb_cam_data[12:0] = tlb_ctxt[12:0] ;
1297
 
1298
// These signals are flow-thru.
1299
assign  wr_tte_tag[58:0]         = tlb_wr_tte_tag[58:0] ; // CHANGE
1300
assign  wr_tte_data[42:0]        = tlb_wr_tte_data[42:0] ;
1301
 
1302
// CHANGE(SATYA) - Currently the rw_index/rw_index_vld are shared by both reads
1303
// and writes. However, writes are done in the cycle of broadcast, whereas
1304
// the reads are done a cycle later, as given in the model(incorrect) 
1305
// They have to be treated uniformly. To make the model work, I've assumed the read/write 
1306
// are done in the cycle the valids are broadcast. 
1307
always @ (posedge clk)
1308
        begin
1309
        if (hold)
1310
                begin
1311
                cam_pid[2:0]             <= cam_pid[2:0] ;
1312
                cam_vld_tmp             <= cam_vld_tmp ;
1313
                cam_data[53:0]           <= cam_data[53:0] ;
1314
                demap_other_tmp         <= demap_other_tmp ;
1315
                demap_auto              <= demap_auto ;
1316
                demap_all               <= demap_all ;
1317
                wr_vld_tmp              <= wr_vld_tmp ;
1318
                rd_tag                  <= rd_tag ;
1319
                rd_data                 <= rd_data ;
1320
                rw_index_vld            <= rw_index_vld ;
1321
                rw_index[5:0]            <= rw_index[5:0] ;
1322
                end
1323
        else
1324
                begin
1325
                cam_pid[2:0]             <= tlb_cam_pid[2:0] ;
1326
                cam_vld_tmp             <= tlb_cam_vld ;
1327
                cam_data[53:0]           <= tlb_cam_data[53:0] ;
1328
                demap_other_tmp         <= tlb_demap ;
1329
                demap_auto              <= tlb_demap_auto ;
1330
                demap_all               <= tlb_demap_all ;
1331
                wr_vld_tmp              <= tlb_wr_vld ;
1332
                rd_tag                  <= tlb_rd_tag_vld ;
1333
                rd_data                 <= tlb_rd_data_vld ;
1334
                rw_index_vld            <= tlb_rw_index_vld ;
1335
                rw_index[5:0]            <= tlb_rw_index[5:0] ;
1336
                end
1337
 
1338
        end
1339
 
1340
// INNO - gate cam,demap,wr with rst_tri_en.
1341
reg rst_tri_en_lat;
1342
 
1343
 always        @ (clk)
1344
 rst_tri_en_lat = rst_tri_en;
1345
 
1346
assign  cam_vld = cam_vld_tmp & ~rst_tri_en_lat ;
1347
assign  demap_other = demap_other_tmp & ~rst_tri_en ;
1348
assign  wr_vld = wr_vld_tmp & ~rst_tri_en ;
1349
 
1350
//=========================================================================================
1351
//      Generate Write Wordlines
1352
//=========================================================================================
1353
 
1354
// Based on static rw index     
1355
// This generates the wordlines for a read/write to the tlb based on index. Wordlines for
1356
// the write based on replacement alg. are muxed in later.
1357
always  @ (/*AUTOSENSE*/rd_data or rd_tag or rw_index or rw_index_vld
1358
           or wr_vld_tmp)
1359
        begin
1360
                for (i=0;i<64;i=i+1)
1361
                        if ((rw_index[5:0] == i) & ((wr_vld_tmp & rw_index_vld) | rd_tag | rd_data))
1362
                                rw_wdline[i] = 1'b1 ;
1363
                        else    rw_wdline[i] = 1'b0 ;
1364
 
1365
        end
1366
 
1367
//=========================================================================================
1368
//      Write TLB
1369
//=========================================================================================
1370
 
1371
reg     [58:0]   tmp_tag ;
1372
reg     [42:0]   tmp_data ;
1373
 
1374
// Currently TLB_TAG and TLB_DATA RAMs are written in the B phase. 
1375
// Used bit is set on write in later code as it is also effected by read of tlb.
1376
always  @ (negedge clk)
1377
        begin
1378
                for (j=0;j<64;j=j+1)
1379
                        if (((rw_index_vld & rw_wdline[j]) | (~rw_index_vld & tlb_entry_replace_d2[j])) & wr_vld_tmp & ~rw_disable)
1380
                                begin
1381
                                if (~rst_tri_en)
1382
                                        begin
1383
                                        tte_tag_ram[j] <= wr_tte_tag[58:0];      // CHANGE
1384
                                        tte_data_ram[j] <= wr_tte_data[42:0];
1385
                                        //tlb_entry_vld[j] <= wr_tte_tag[`STLB_TAG_V] ;
1386
                                        tlb_entry_used[j] <= wr_tte_tag[`STLB_TAG_U] ;
1387
                                        tlb_entry_locked[j] = wr_tte_tag[`STLB_TAG_L] ;
1388
                                        // write-thru 
1389
                                        rd_tte_tag[58:0]  <= wr_tte_tag[58:0] ;   // CHANGE 
1390
                                        rd_tte_data[42:0] <=  wr_tte_data[42:0];
1391
 
1392
                                        end
1393
                                else
1394
                                        begin
1395
                                        tmp_tag[58:0]=tte_tag_ram[j]; // use non-blocking
1396
                                        tmp_data[42:0]=tte_data_ram[j];
1397
                                        // INNO - read wins.
1398
                                        rd_tte_tag[58:0] <=
1399
                                        {tmp_tag[58:27], tlb_entry_vld[j],tlb_entry_locked[j],
1400
                                        tlb_entry_used[j], tmp_tag[23:0]}  ;
1401
                                        rd_tte_data[42:0] <= {tmp_data[42:12],tmp_data[11:0]} ;
1402
                                        end
1403
 
1404
                        end
1405
 
1406
//=========================================================================================
1407
//      Read STLB
1408
//=========================================================================================
1409
 
1410
                for (m=0;m<64;m=m+1)
1411
                        if (rw_wdline[m] & (rd_tag | rd_data) & ~rw_disable)
1412
                                begin
1413
                                        tmp_tag  = tte_tag_ram[m] ;
1414
                                        tmp_data = tte_data_ram[m] ;
1415
                                        if (rd_tag)
1416
                                                rd_tte_tag[58:0] <=      // CHANGE - Bug 2185
1417
                                                {tmp_tag[58:27], tlb_entry_vld[m],tlb_entry_locked[m],
1418
                                                tlb_entry_used[m], tmp_tag[23:0]}  ;
1419
                                                //{tmp_tag[58:29], tlb_entry_vld[m],tlb_entry_locked[m], 
1420
                                                //tlb_entry_used[m], tmp_tag[25:0]}  ;
1421
                                        if (rd_data) begin
1422
                                                rd_tte_data[42:0] <= {tmp_data[42:12],tmp_data[11:0]} ;
1423
                                        end
1424
 
1425
                                end
1426
 
1427
                if (cam_vld & ~rw_disable)
1428
                begin
1429
                        //Checking for no hit and multiple hits
1430
                        sat = 64'd0;
1431
                        for (w=0;w<64;w=w+1)
1432
                        begin
1433
                                if(cam_hit[w])
1434
                                begin
1435
                                        sat = sat + 64'd1 ;
1436
                                end
1437
                        end
1438
                        // Only one hit occur read the data
1439
                        if(sat == 64'd1)
1440
                        begin
1441
                                for (p=0;p<64;p=p+1)
1442
                                begin
1443
                                        if (cam_hit[p])
1444
                                        begin
1445
                                                rd_tte_data[42:0] <= tte_data_ram[p] ;
1446
                                        end
1447
                                end
1448
                        end
1449
                        else
1450
                        begin
1451
                                // INNO - just to keep the tool happy.
1452
                                // ram cell will not be corrupted.
1453
                                for (k=0;k<64;k=k+1)
1454
                                begin
1455
                                        if (cam_hit[k])
1456
                                        tte_data_ram[k] <= 43'bx ;
1457
                                end
1458
                                rd_tte_data[42:0] <= 43'bx ;
1459
                        end
1460
                end
1461
 
1462
                for (s=0;s<64;s=s+1)
1463
                        begin
1464
                                if (cam_hit[s])
1465
                                        tlb_entry_used[s] <= 1'b1;
1466
                        end
1467
 
1468
// Clear on following edge if necessary.
1469
// CHANGE(SATYA) : tlb_entry_used qualified with valid needs to be used to determine
1470
// whether the Used bits are to be cleared. This allows invalid entries created
1471
// by a demap to be used for replacement. Else we will ignore these entries
1472
// for replacement
1473
 
1474
                //if (tlb_not_writeable)
1475
                if (~tlb_writeable & ~cam_vld & ~wr_vld & ~rd_tag & ~rst_tri_en)
1476
                        begin
1477
                                for (t=0;t<64;t=t+1)
1478
                                        begin
1479
                                                //if (~tlb_entry_locked[t])
1480
                                                if (~tlb_entry_locked[t] & ~cam_vld & ~wr_vld)
1481
                                                        tlb_entry_used[t] <= 1'b0;
1482
                                        end
1483
                        end
1484
        end
1485
 
1486
// Stage to next cycle.
1487
always  @ (posedge clk)
1488
        begin
1489
                tlb_rd_tte_tag[58:0]     <= rd_tte_tag[58:0] ;    // CHANGE
1490
                tlb_rd_tte_data[42:0]    <= rd_tte_data[42:0] ;
1491
        end
1492
 
1493
//=========================================================================================
1494
//      CAM/DEMAP STLB for xlation
1495
//=========================================================================================
1496
 
1497
//  no_hit logic does not work because it is set in multiple clock
1498
//  domains and is reset before ever having a chance to be effective
1499
//reg   no_hit ;
1500
 
1501
 
1502
// Demap and CAM operation are mutually exclusive.
1503
 
1504
always  @ ( negedge clk )
1505
        begin
1506
 
1507
                for (n=0;n<64;n=n+1)
1508
                        begin
1509
                        /*if (demap_all)  begin
1510
                                if (demap_auto & demap_other) ademap_hit[n]   =
1511
                                        (~mismatch[n] & demap_all_but_locked_hit[n] & demap_other
1512
                                                & tlb_entry_vld[n]) ;
1513
                                end
1514
                        else    begin */
1515
                                if (demap_auto & demap_other) ademap_hit[n]    =
1516
                                        (~mismatch[n] & demap_other & tlb_entry_vld[n]) ;
1517
                                //end
1518
                        end
1519
 
1520
        end  // always
1521
 
1522
always  @ (/*AUTOSENSE*/ /*memory or*/
1523
           cam_data or cam_pid or cam_vld or demap_all
1524
           or demap_other or tlb_entry_vld)
1525
        begin
1526
 
1527
                for (n=0;n<64;n=n+1)
1528
                        begin
1529
                        tag[58:0] = tte_tag_ram[n] ;     // CHANGE
1530
 
1531
                        mismatch_va_b47_28[n] =
1532
                        (tag[`STLB_TAG_VA_47_28_HI:`STLB_TAG_VA_47_28_LO]
1533
                        != cam_data[`CAM_VA_47_28_HI+13:`CAM_VA_47_28_LO+13]);
1534
 
1535
                        mismatch_va_b27_22[n] =
1536
                        (tag[`STLB_TAG_VA_27_22_HI:`STLB_TAG_VA_27_22_LO]
1537
                        != cam_data[`CAM_VA_27_22_HI+13:`CAM_VA_27_22_LO+13]);
1538
 
1539
                        mismatch_va_b21_16[n] =
1540
                        (tag[`STLB_TAG_VA_21_16_HI:`STLB_TAG_VA_21_16_LO]
1541
                        != cam_data[`CAM_VA_21_16_HI+13:`CAM_VA_21_16_LO+13]) ;
1542
 
1543
                        mismatch_va_b15_13[n] =
1544
                        (tag[`STLB_TAG_VA_15_13_HI:`STLB_TAG_VA_15_13_LO]
1545
                        != cam_data[`CAM_VA_15_13_HI+13:`CAM_VA_15_13_LO+13]) ;
1546
 
1547
                        mismatch_ctxt[n] =
1548
                        (tag[`STLB_TAG_CTXT_12_0_HI:`STLB_TAG_CTXT_12_0_LO]
1549
                        != cam_data[`CAM_CTXT_12_0_HI:`CAM_CTXT_12_0_LO]) ;
1550
 
1551
                        mismatch_pid[n] = (tag[`STLB_TAG_PID_HI:`STLB_TAG_PID_LO] != cam_pid[2:0]) ;
1552
 
1553
                        mismatch[n] =
1554
                        (mismatch_va_b47_28[n] & cam_data[`CAM_VA_47_28_V+13])                          |
1555
                        (mismatch_va_b27_22[n] & tag[`STLB_TAG_VA_27_22_V] & cam_data[`CAM_VA_27_22_V+13])      |
1556
                        (mismatch_va_b21_16[n] & tag[`STLB_TAG_VA_21_16_V] & cam_data[`CAM_VA_21_16_V+13])      |
1557
                        (mismatch_va_b15_13[n] & tag[`STLB_TAG_VA_15_13_V] & cam_data[`CAM_VA_15_13_V+13])      |
1558
                        (mismatch_ctxt[n] & ~cam_data[`CAM_CTXT_GK+13]) |
1559
                        // mismatch is request type not equal to entry type. types are real/virtual.
1560
                        ((tag[`STLB_TAG_R] ^ cam_data[`CAM_REAL_V+13]) & ~demap_all)    |
1561
                        //(mismatch_real[n] & cam_data[`CAM_REAL_V+13])         |
1562
                        mismatch_pid[n] ;       // pid always included in mismatch calculations
1563
 
1564
                        demap_all_but_locked_hit[n] =
1565
                        ~tag[`STLB_TAG_L] & demap_all ;
1566
 
1567
                        cam_hit[n]      =
1568
                                ~mismatch[n] & cam_vld   & tlb_entry_vld[n] ;
1569
 
1570
                        if (demap_all)  begin
1571
                                // Satya(10/3) - I've simplified the demap-all equation
1572
                                // Pls confirm that this is okay. Otherwise we will nee
1573
                                // qualifying bits for the pid and r fields.
1574
                                /*demap_hit[n]  =
1575
                                        (demap_all_but_locked_hit[n] & demap_other) ;*/
1576
                                demap_hit[n]    =
1577
                                        (~mismatch[n] & demap_all_but_locked_hit[n] & demap_other
1578
                                                & tlb_entry_vld[n]) ;
1579
                                // qualification with demap_auto to prevent ademap_hit from
1580
                                // being cleared. Satya-we could get rid of this.
1581
                                // ademap_hit[n] is a phase A device and needs to be in a clocked always block
1582
                                //if (demap_auto & demap_other & clk) ademap_hit[n]   =
1583
                                //        (~mismatch[n] & demap_all_but_locked_hit[n] & demap_other
1584
                                //                & tlb_entry_vld[n]) ;
1585
                                end
1586
                        else    begin
1587
                                demap_hit[n]    =
1588
                                        (~mismatch[n] & demap_other & tlb_entry_vld[n]) ;
1589
                                // qualification with demap_auto to prevent ademap_hit from
1590
                                // being cleared. Satya-this is the only one we need.
1591
                                //if (demap_auto & demap_other & clk) ademap_hit[n]    =
1592
                                //        (~mismatch[n] & demap_other & tlb_entry_vld[n]) ;
1593
                                end
1594
//                      no_hit = cam_vld ;
1595
                        end
1596
 
1597
        end  // always
1598
 
1599
assign  tlb_cam_hit = |cam_hit[63:0] ;
1600
 
1601
// Read on CAM hit occurs on negedge.
1602
/* MOVED TO COMMON ALWAYS BLOCK
1603
always @ (negedge clk)
1604
        begin
1605
                if (|cam_hit[63:0])
1606
                        begin
1607
                        for (p=0;p<64;p=p+1)
1608
                                if (cam_hit[p])
1609
                                begin
1610
                                        rd_tte_data[42:0] <= tte_data_ram[p] ;
1611
                                end
1612
//                              no_hit = 1'b0 ;
1613
                        end
1614
//              else    if (no_hit) begin
1615
//                      rd_tte_data[42:0] <= {43{1'bx}};
1616
//                      no_hit = 1'b0 ;
1617
//                      end
1618
        end
1619
*/
1620
// Change tlb_entry_vld handling for multi-threaded tlb writes.
1621
// A write is always preceeded by an autodemap. The intent is to make the result of autodemap
1622
// (clearing of vld bit if hit) invisible until write occurs. In the same cycle that the write
1623
// occurs, the vld bit for an entry will be cleared if there is an autodemap hit. The write
1624
// and admp action may even be to same entry. The write must dominate. There is no need to
1625
// clear the dmp latches after the write/clear has occurred as the subsequent admp will set
1626
// up new state in the latches.
1627
 
1628
// Define valid bit based on write/demap/reset. 
1629
always @ (negedge clk)
1630
        begin
1631
        for (r=0;r<64;r=r+1)
1632
        begin // for
1633
        if (((rw_index_vld & rw_wdline[r]) | (~rw_index_vld & tlb_entry_replace_d2[r])) &
1634
                wr_vld & ~rw_disable)
1635
                        tlb_entry_vld[r] <= wr_tte_tag[`STLB_TAG_V] ;   // write
1636
        else    begin
1637
                if (ademap_hit[r] & wr_vld)                     // autodemap specifically
1638
                        tlb_entry_vld[r] <= 1'b0 ;
1639
                end
1640
          if ((demap_hit[r] & ~demap_auto) | sync_reset)        // non-auto-demap, reset
1641
                        tlb_entry_vld[r] <= 1'b0 ;
1642
        end // for
1643
        end
1644
 
1645
 
1646
// async reset.
1647
always  @ (async_reset)
1648
        begin
1649
        for (l=0;l<64;l=l+1)
1650
                begin
1651
                tlb_entry_vld[l] <= 1'b0 ;
1652
                end
1653
        end
1654
 
1655
//=========================================================================================
1656
//      TAG COMPARISON
1657
//=========================================================================================
1658
 
1659
reg [30:0] va_tag_plus ;
1660
 
1661
// Stage to m
1662
always @(posedge clk)
1663
                begin
1664
                // INNO - add hold to this input
1665
                if (hold)
1666
                        va_tag_plus[30:0] <= va_tag_plus[30:0] ;
1667
                else
1668
                        va_tag_plus[30:0]
1669
                        <= {tlb_cam_comp_key[26:0],tlb_bypass_va[12:10],tlb_bypass};
1670
                end
1671
 
1672
assign vrtl_pgnum_m[29:0] = va_tag_plus[30:1] ;
1673
assign bypass = va_tag_plus[0] ;
1674
 
1675
// Mux to bypass va or form pa tag based on tte-data.
1676
 
1677
assign  phy_pgnum_m[29:3] =
1678
        {rd_tte_data[`STLB_DATA_PA_39_28_HI:`STLB_DATA_PA_39_28_LO],
1679
                rd_tte_data[`STLB_DATA_PA_27_22_HI:`STLB_DATA_PA_27_22_LO],
1680
                        rd_tte_data[`STLB_DATA_PA_21_16_HI:`STLB_DATA_PA_21_16_LO],
1681
                                rd_tte_data[`STLB_DATA_PA_15_13_HI:`STLB_DATA_PA_15_13_LO]};
1682
 
1683
// Derive the tlb-based physical address.
1684
assign pgnum_m[2:0] = vrtl_pgnum_m[2:0];
1685
assign pgnum_m[5:3] = (~rd_tte_data[`STLB_DATA_15_13_SEL] & ~bypass)
1686
                                ? phy_pgnum_m[5:3] : vrtl_pgnum_m[5:3] ;
1687
assign pgnum_m[11:6] = (~rd_tte_data[`STLB_DATA_21_16_SEL] & ~bypass)
1688
                                ? phy_pgnum_m[11:6] : vrtl_pgnum_m[11:6] ;
1689
assign pgnum_m[17:12] = (~rd_tte_data[`STLB_DATA_27_22_SEL] & ~bypass)
1690
                                ? phy_pgnum_m[17:12] : vrtl_pgnum_m[17:12] ;
1691
assign pgnum_m[29:18] = ~bypass ? phy_pgnum_m[29:18] : vrtl_pgnum_m[29:18];
1692
 
1693
// Stage to g
1694
// Flop tags in tlb itself and do comparison immediately after rising edge.
1695
// Similarly stage va/pa tag to g
1696
always @(posedge clk)
1697
                begin
1698
                        pgnum_g[29:0] <= pgnum_m[29:0];
1699
                        // rm hold on these inputs.
1700
                        cache_set_vld_g[3:0]     <= cache_set_vld[3:0] ;
1701
                        cache_ptag_w0_g[29:0]    <= cache_ptag_w0[29:0] ;
1702
                        cache_ptag_w1_g[29:0]    <= cache_ptag_w1[29:0] ;
1703
                        cache_ptag_w2_g[29:0]    <= cache_ptag_w2[29:0] ;
1704
                        cache_ptag_w3_g[29:0]    <= cache_ptag_w3[29:0] ;
1705
                end
1706
 
1707
 
1708
// Need to stage by a cycle where used.
1709
assign  tlb_pgnum[39:10] = pgnum_g[29:0] ;
1710
// Same cycle as cam - meant for one load on critical path
1711
assign  tlb_pgnum_crit[39:10] = pgnum_m[29:0] ;
1712
 
1713
 
1714
assign  cache_way_hit[0] =
1715
        (cache_ptag_w0_g[29:0] == pgnum_g[29:0]) & cache_set_vld_g[0];
1716
assign  cache_way_hit[1] =
1717
        (cache_ptag_w1_g[29:0] == pgnum_g[29:0]) & cache_set_vld_g[1];
1718
assign  cache_way_hit[2] =
1719
        (cache_ptag_w2_g[29:0] == pgnum_g[29:0]) & cache_set_vld_g[2];
1720
assign  cache_way_hit[3] =
1721
        (cache_ptag_w3_g[29:0] == pgnum_g[29:0]) & cache_set_vld_g[3];
1722
 
1723
assign  cache_hit = |cache_way_hit[3:0];
1724
 
1725
 
1726
//=========================================================================================
1727
//      TLB ENTRY REPLACEMENT
1728
//=========================================================================================
1729
 
1730
// A single Used bit is used to track the replacement state of each entry.
1731
// Only an unused entry can be replaced.
1732
// An Unused entry is :
1733
//                      - an invalid entry
1734
//                      - a valid entry which has had its Used bit cleared.
1735
//                              - on write of a valid entry, the Used bit is set.
1736
//                              - The Used bit of a valid entry is cleared if all
1737
//                              entries have their Used bits set and the entry itself is not Locked.
1738
// A locked entry should always appear to be Used.
1739
// A single priority-encoder is required to evaluate the used status. Priority is static
1740
// and used entry0 is of the highest priority if unused.
1741
 
1742
// Timing :
1743
// Used bit gets updated by cam-hit or hit on negedge.
1744
// After Used bit gets updated off negedge, the replacement entry can be generated in
1745
// Phase2. In parallel, it is determined whether all Used bits are set or not. If
1746
// so, then they are cleared on the next negedge with the replacement entry generated
1747
// in the related Phase1 
1748
 
1749
// Choosing replacement entry
1750
// Replacement entry is integer k
1751
 
1752
assign  tlb_not_writeable = &used[63:0] ;
1753
/*
1754
// Used bit can be set because of write or because of cam-hit.
1755
always @(negedge clk)
1756
        begin
1757
                for (s=0;s<64;s=s+1)
1758
                        begin
1759
                                if (cam_hit[s])
1760
                                        tlb_entry_used[s] <= 1'b1;
1761
                        end
1762
 
1763
// Clear on following edge if necessary.
1764
// CHANGE(SATYA) : tlb_entry_used qualified with valid needs to be used to determine
1765
// whether the Used bits are to be cleared. This allows invalid entries created
1766
// by a demap to be used for replacement. Else we will ignore these entries
1767
// for replacement
1768
 
1769
                if (tlb_not_writeable)
1770
                        begin
1771
                                for (t=0;t<64;t=t+1)
1772
                                        begin
1773
                                                if (~tlb_entry_locked[t])
1774
                                                        tlb_entry_used[t] <= 1'b0;
1775
                                        end
1776
                        end
1777
        end
1778
*/
1779
 
1780
// Determine whether entry should be squashed.
1781
 
1782
assign  used[63:0] = tlb_entry_used[63:0] & tlb_entry_vld[63:0] ;
1783
 
1784
/*assign squash[0] = 1'b0 ;
1785
assign squash[1] = ~used[0] ;
1786
assign squash[2] = |(~used[1:0]) ;
1787
assign squash[3] = |(~used[2:0]) ;
1788
assign squash[4] = |(~used[3:0]) ;
1789
assign squash[5] = |(~used[4:0]) ;
1790
assign squash[6] = |(~used[5:0]) ;
1791
assign squash[7] = |(~used[6:0]) ;
1792
assign squash[8] = |(~used[7:0]) ;
1793
assign squash[9] = |(~used[8:0]) ;
1794
assign squash[10] = |(~used[9:0]) ;
1795
assign squash[11] = |(~used[10:0]) ;
1796
assign squash[12] = |(~used[11:0]) ;
1797
assign squash[13] = |(~used[12:0]) ;
1798
assign squash[14] = |(~used[13:0]) ;
1799
assign squash[15] = |(~used[14:0]) ;
1800
assign squash[16] = |(~used[15:0]) ;
1801
assign squash[17] = |(~used[16:0]) ;
1802
assign squash[18] = |(~used[17:0]) ;
1803
assign squash[19] = |(~used[18:0]) ;
1804
assign squash[20] = |(~used[19:0]) ;
1805
assign squash[21] = |(~used[20:0]) ;
1806
assign squash[22] = |(~used[21:0]) ;
1807
assign squash[23] = |(~used[22:0]) ;
1808
assign squash[24] = |(~used[23:0]) ;
1809
assign squash[25] = |(~used[24:0]) ;
1810
assign squash[26] = |(~used[25:0]) ;
1811
assign squash[27] = |(~used[26:0]) ;
1812
assign squash[28] = |(~used[27:0]) ;
1813
assign squash[29] = |(~used[28:0]) ;
1814
assign squash[30] = |(~used[29:0]) ;
1815
assign squash[31] = |(~used[30:0]) ;
1816
assign squash[32] = |(~used[31:0]) ;
1817
assign squash[33] = |(~used[32:0]) ;
1818
assign squash[34] = |(~used[33:0]) ;
1819
assign squash[35] = |(~used[34:0]) ;
1820
assign squash[36] = |(~used[35:0]) ;
1821
assign squash[37] = |(~used[36:0]) ;
1822
assign squash[38] = |(~used[37:0]) ;
1823
assign squash[39] = |(~used[38:0]) ;
1824
assign squash[40] = |(~used[39:0]) ;
1825
assign squash[41] = |(~used[40:0]) ;
1826
assign squash[42] = |(~used[41:0]) ;
1827
assign squash[43] = |(~used[42:0]) ;
1828
assign squash[44] = |(~used[43:0]) ;
1829
assign squash[45] = |(~used[44:0]) ;
1830
assign squash[46] = |(~used[45:0]) ;
1831
assign squash[47] = |(~used[46:0]) ;
1832
assign squash[48] = |(~used[47:0]) ;
1833
assign squash[49] = |(~used[48:0]) ;
1834
assign squash[50] = |(~used[49:0]) ;
1835
assign squash[51] = |(~used[50:0]) ;
1836
assign squash[52] = |(~used[51:0]) ;
1837
assign squash[53] = |(~used[52:0]) ;
1838
assign squash[54] = |(~used[53:0]) ;
1839
assign squash[55] = |(~used[54:0]) ;
1840
assign squash[56] = |(~used[55:0]) ;
1841
assign squash[57] = |(~used[56:0]) ;
1842
assign squash[58] = |(~used[57:0]) ;
1843
assign squash[59] = |(~used[58:0]) ;
1844
assign squash[60] = |(~used[59:0]) ;
1845
assign squash[61] = |(~used[60:0]) ;
1846
assign squash[62] = |(~used[61:0]) ;
1847
assign squash[63] = |(~used[62:0]) ; */
1848
 
1849
// Based on updated Used state, generate replacement entry.
1850
// So, replacement entries can be generated on a cycle-by-cycle basis. 
1851
//always @(/*AUTOSENSE*/squash or used)
1852
 
1853
        reg     [63:0]   tlb_entry_replace_d1;
1854
        reg             tlb_replace_flag;
1855
        always @(/*AUTOSENSE*/used)
1856
        begin
1857
          tlb_replace_flag=1'b0;
1858
          tlb_entry_replace_d1 = 64'b0;
1859
          // Priority is given to entry0
1860
          for (u=0;u<64;u=u+1)
1861
          begin
1862
            if(~tlb_replace_flag & ~used[u])
1863
            begin
1864
              tlb_entry_replace_d1[u] = ~used[u] ;
1865
              tlb_replace_flag=1'b1;
1866
            end
1867
          end
1868
          if(~tlb_replace_flag) begin
1869
             tlb_entry_replace_d1[63] = 1'b1;
1870
          end
1871
        end
1872
        always @(posedge clk)
1873
        begin
1874
          // named in this manner to keep arch model happy.
1875
          tlb_entry_replace <= tlb_entry_replace_d1 ;
1876
        end
1877
        // INNO - 2 stage delay before update is visible
1878
        always @(posedge clk)
1879
        begin
1880
          tlb_entry_replace_d2 <= tlb_entry_replace ;
1881
        end
1882
 
1883
//=========================================================================================
1884
//      TLB WRITEABLE DETECTION
1885
//=========================================================================================
1886
 
1887
// 2-cycles later, tlb become writeable
1888
always @(posedge clk)
1889
        begin
1890
                tlb_not_writeable_d1 <= tlb_not_writeable ;
1891
        end
1892
 
1893
always @(posedge clk)
1894
        begin
1895
                tlb_writeable <= ~tlb_not_writeable_d1 ;
1896
        end
1897
 
1898
endmodule
1899
 
1900
`endif
1901
 

powered by: WebSVN 2.1.0

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