2021-04-08 06:44:59 +00:00
|
|
|
///////////////////////////////////////////
|
2021-07-04 18:59:04 +00:00
|
|
|
// tlbcamline.sv
|
2021-04-08 06:44:59 +00:00
|
|
|
//
|
|
|
|
// Written: tfleming@hmc.edu & jtorrey@hmc.edu 6 April 2021
|
2021-06-01 21:50:37 +00:00
|
|
|
// Modified: kmacsaigoren@hmc.edu 1 June 2021
|
|
|
|
// Implemented SV48 on top of SV39. This included adding SvMode input signal and the wally constants
|
|
|
|
// Mostly this was done to make the PageNumberMixer work.
|
2021-04-08 06:44:59 +00:00
|
|
|
//
|
|
|
|
// Purpose: CAM line for the translation lookaside buffer (TLB)
|
2021-06-07 22:32:34 +00:00
|
|
|
// Determines whether a virtual page number matches the stored key.
|
2021-04-08 06:44:59 +00:00
|
|
|
//
|
|
|
|
// A component of the Wally configurable RISC-V project.
|
|
|
|
//
|
|
|
|
// Copyright (C) 2021 Harvey Mudd College & Oklahoma State University
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
|
|
|
// files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
|
|
|
// modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
|
|
|
|
// is furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
|
|
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
|
|
|
// OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
///////////////////////////////////////////
|
|
|
|
|
2021-06-07 16:37:46 +00:00
|
|
|
`include "wally-config.vh"
|
2021-06-01 21:50:37 +00:00
|
|
|
|
2021-07-04 18:59:04 +00:00
|
|
|
module tlbcamline #(parameter KEY_BITS = 20,
|
2021-07-04 21:52:00 +00:00
|
|
|
parameter SEGMENT_BITS = 10) (
|
|
|
|
input logic clk, reset,
|
|
|
|
input logic [`VPN_BITS-1:0] VirtualPageNumber, // The requested page number to compare against the key
|
|
|
|
input logic [`ASID_BITS-1:0] ASID,
|
|
|
|
input logic WriteEnable, // Write a new entry to this line
|
2021-07-04 22:05:22 +00:00
|
|
|
input logic PTE_G,
|
2021-07-04 21:52:00 +00:00
|
|
|
input logic [1:0] PageTypeWriteVal,
|
|
|
|
input logic TLBFlush, // Flush this line (set valid to 0)
|
|
|
|
output logic [1:0] PageTypeRead, // *** should this be the stored version or the always updated one?
|
|
|
|
output logic Match
|
|
|
|
);
|
2021-04-08 06:44:59 +00:00
|
|
|
|
2021-07-04 21:52:00 +00:00
|
|
|
// PageTypeRead is a key for a tera, giga, mega, or kilopage.
|
2021-04-08 06:44:59 +00:00
|
|
|
// PageType == 2'b00 --> kilopage
|
|
|
|
// PageType == 2'b01 --> megapage
|
2021-06-01 21:50:37 +00:00
|
|
|
// PageType == 2'b10 --> gigapage
|
|
|
|
// PageType == 2'b11 --> terapage
|
2021-04-08 06:44:59 +00:00
|
|
|
|
|
|
|
// This entry has KEY_BITS for the key plus one valid bit.
|
|
|
|
logic Valid;
|
|
|
|
logic [KEY_BITS-1:0] Key;
|
2021-07-04 20:33:13 +00:00
|
|
|
logic [1:0] PageType;
|
2021-06-07 21:03:31 +00:00
|
|
|
|
2021-06-07 22:32:34 +00:00
|
|
|
// Split up key and query into sections for each page table level.
|
2021-07-04 21:52:00 +00:00
|
|
|
logic [`ASID_BITS-1:0] Key_ASID;
|
2021-06-07 22:32:34 +00:00
|
|
|
logic [SEGMENT_BITS-1:0] Key0, Key1, Query0, Query1;
|
2021-07-04 21:52:00 +00:00
|
|
|
logic MatchASID, Match0, Match1;
|
2021-06-07 21:03:31 +00:00
|
|
|
|
2021-07-04 22:05:22 +00:00
|
|
|
assign MatchASID = (ASID == Key_ASID) | PTE_G;
|
2021-07-04 21:01:22 +00:00
|
|
|
|
2021-06-07 21:03:31 +00:00
|
|
|
generate
|
|
|
|
if (`XLEN == 32) begin
|
2021-06-07 22:32:34 +00:00
|
|
|
|
2021-07-04 21:52:00 +00:00
|
|
|
assign {Key_ASID, Key1, Key0} = Key;
|
2021-06-07 22:32:34 +00:00
|
|
|
assign {Query1, Query0} = VirtualPageNumber;
|
2021-06-07 21:03:31 +00:00
|
|
|
|
2021-06-07 22:32:34 +00:00
|
|
|
// Calculate the actual match value based on the input vpn and the page type.
|
|
|
|
// For example, a megapage in SV32 only cares about VPN[1], so VPN[0]
|
|
|
|
// should automatically match.
|
|
|
|
assign Match0 = (Query0 == Key0) || (PageType[0]); // least signifcant section
|
|
|
|
assign Match1 = (Query1 == Key1);
|
2021-06-07 21:03:31 +00:00
|
|
|
|
2021-06-07 22:32:34 +00:00
|
|
|
assign Match = Match0 & Match1 & Valid;
|
2021-06-07 21:03:31 +00:00
|
|
|
end else begin
|
|
|
|
|
2021-06-07 22:32:34 +00:00
|
|
|
logic [SEGMENT_BITS-1:0] Key2, Key3, Query2, Query3;
|
|
|
|
logic Match2, Match3;
|
|
|
|
|
|
|
|
assign {Query3, Query2, Query1, Query0} = VirtualPageNumber;
|
2021-07-04 21:52:00 +00:00
|
|
|
assign {Key_ASID, Key3, Key2, Key1, Key0} = Key;
|
2021-06-07 21:03:31 +00:00
|
|
|
|
2021-06-07 22:32:34 +00:00
|
|
|
// Calculate the actual match value based on the input vpn and the page type.
|
2021-07-04 18:59:04 +00:00
|
|
|
// For example, a gigapage in SV39 only cares about VPN[2], so VPN[0] and VPN[1]
|
2021-06-07 22:32:34 +00:00
|
|
|
// should automatically match.
|
|
|
|
assign Match0 = (Query0 == Key0) || (PageType > 2'd0); // least signifcant section
|
|
|
|
assign Match1 = (Query1 == Key1) || (PageType > 2'd1);
|
|
|
|
assign Match2 = (Query2 == Key2) || (PageType > 2'd2);
|
2021-07-04 18:59:04 +00:00
|
|
|
assign Match3 = (Query3 == Key3); // this should always match in sv39 since both vPN3 and key3 are zeroed by the pagetable walker before getting to the cam
|
2021-06-07 21:03:31 +00:00
|
|
|
|
2021-06-07 22:32:34 +00:00
|
|
|
assign Match = Match0 & Match1 & Match2 & Match3 & Valid;
|
2021-06-07 21:03:31 +00:00
|
|
|
end
|
|
|
|
endgenerate
|
2021-04-08 06:44:59 +00:00
|
|
|
|
|
|
|
// On a write, update the type of the page referred to by this line.
|
2021-07-04 21:01:22 +00:00
|
|
|
flopenr #(2) pagetypeflop(clk, reset, WriteEnable, PageTypeWriteVal, PageType);
|
|
|
|
assign PageTypeRead = PageType & {2{Match}};
|
2021-04-08 06:44:59 +00:00
|
|
|
|
|
|
|
// On a write, set the valid bit high and update the stored key.
|
|
|
|
// On a flush, zero the valid bit and leave the key unchanged.
|
|
|
|
// *** Might we want to update stored key right away to output match on the
|
|
|
|
// write cycle? (using a mux)
|
2021-07-04 21:01:22 +00:00
|
|
|
flopenrc #(1) validbitflop(clk, reset, TLBFlush, WriteEnable, 1'b1, Valid);
|
2021-07-04 21:52:00 +00:00
|
|
|
flopenr #(KEY_BITS) keyflop(clk, reset, WriteEnable, {ASID, VirtualPageNumber}, Key);
|
2021-04-13 16:27:12 +00:00
|
|
|
endmodule
|