From 9b9e1fa911327bb4e373031e56f45581bcb0f1dd Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Mon, 6 Dec 2021 22:41:58 +0000 Subject: [PATCH] convert DTLBUpdate to use a pair of Memorys one for PTEs and one for TAGs --- src/soc/experiment/dcache.py | 63 ++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 14 deletions(-) diff --git a/src/soc/experiment/dcache.py b/src/soc/experiment/dcache.py index 92a91330..447994f9 100644 --- a/src/soc/experiment/dcache.py +++ b/src/soc/experiment/dcache.py @@ -25,7 +25,7 @@ sys.setrecursionlimit(1000000) from enum import Enum, unique from nmigen import (Module, Signal, Elaboratable, Cat, Repl, Array, Const, - Record) + Record, Memory) from nmutil.util import Display from nmigen.lib.coding import Decoder @@ -155,6 +155,8 @@ print ("tag @: %d-%d width %d" % (SET_SIZE_BITS, REAL_ADDR_BITS, TAG_WIDTH)) TAG_RAM_WIDTH = TAG_WIDTH * NUM_WAYS print ("TAG_RAM_WIDTH", TAG_RAM_WIDTH) +print (" TAG_WIDTH", TAG_WIDTH) +print (" NUM_WAYS", NUM_WAYS) def CacheTagArray(): tag_layout = [('valid', 1), @@ -191,6 +193,7 @@ assert REAL_ADDR_BITS == (TAG_BITS + ROW_BITS + ROW_OFF_BITS), \ assert 64 == WB_DATA_BITS, "Can't yet handle wb width that isn't 64-bits" assert SET_SIZE_BITS <= TLB_LG_PGSZ, "Set indexed by virtual address" + def TLBHit(name): return Record([('valid', 1), ('way', TLB_WAY_BITS)], name=name) @@ -454,6 +457,31 @@ class DTLBUpdate(Elaboratable): comb = m.d.comb sync = m.d.sync + dtlb, tlb_req_index = self.dtlb, self.tlb_req_index + + print ("TLB_TAG_WAY_BITS", TLB_TAG_WAY_BITS) + print (" TLB_EA_TAG_BITS", TLB_EA_TAG_BITS) + print (" TLB_NUM_WAYS", TLB_NUM_WAYS) + print ("TLB_PTE_WAY_BITS", TLB_PTE_WAY_BITS) + print (" TLB_PTE_BITS", TLB_PTE_BITS) + print (" TLB_NUM_WAYS", TLB_NUM_WAYS) + + # TAG and PTE Memory SRAMs. transparent, write-enables are TLB_NUM_WAYS + tagway = Memory(depth=TLB_SET_SIZE, width=TLB_TAG_WAY_BITS) + m.submodules.rd_tagway = rd_tagway = tagway.read_port() + m.submodules.wr_tagway = wr_tagway = tagway.write_port( + granularity=TLB_EA_TAG_BITS) + + pteway = Memory(depth=TLB_SET_SIZE, width=TLB_PTE_WAY_BITS) + m.submodules.rd_pteway = rd_pteway = pteway.read_port() + m.submodules.wr_pteway = wr_pteway = pteway.write_port( + granularity=TLB_PTE_BITS) + + m.d.comb += rd_pteway.addr.eq(self.tlb_read_index) + m.d.comb += rd_tagway.addr.eq(self.tlb_read_index) + m.d.comb += wr_tagway.addr.eq(tlb_req_index) + m.d.comb += wr_pteway.addr.eq(tlb_req_index) + tagset = Signal(TLB_TAG_WAY_BITS) pteset = Signal(TLB_PTE_WAY_BITS) updated = Signal() @@ -463,7 +491,6 @@ class DTLBUpdate(Elaboratable): pb_out = Signal(TLB_PTE_WAY_BITS) # tlb_way_ptes_t dv = Signal(TLB_NUM_WAYS) # tlb_way_valids_t - dtlb, tlb_req_index = self.dtlb, self.tlb_req_index comb += dv.eq(dtlb[tlb_req_index].valid) comb += db_out.eq(dv) @@ -477,29 +504,37 @@ class DTLBUpdate(Elaboratable): comb += db_out.bit_select(self.tlb_hit.way, 1).eq(0) comb += v_updated.eq(1) with m.Elif(self.tlbwe): - # write to tge rrquested tag and PTE - comb += tagset.eq(self.tlb_tag_way) - comb += write_tlb_tag(self.repl_way, tagset, self.eatag) - comb += tb_out.eq(tagset) - - comb += pteset.eq(self.tlb_pte_way) - comb += write_tlb_pte(self.repl_way, pteset, self.pte_data) - comb += pb_out.eq(pteset) - + # write to the requested tag and PTE + comb += write_tlb_tag(self.repl_way, tb_out, self.eatag) + comb += write_tlb_pte(self.repl_way, pb_out, self.pte_data) + # set valid bit comb += db_out.bit_select(self.repl_way, 1).eq(1) comb += updated.eq(1) comb += v_updated.eq(1) with m.If(updated): - sync += dtlb[tlb_req_index].tag.eq(tb_out) - sync += dtlb[tlb_req_index].pte.eq(pb_out) + comb += wr_pteway.data.eq(pb_out) + comb += wr_pteway.en.eq(1<