Merge pull request #21 from JohnSully/outoforder

Outoforder
This commit is contained in:
enjoy-digital 2018-08-09 09:20:55 +02:00 committed by GitHub
commit 26f3f016e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 17 deletions

View file

@ -56,11 +56,12 @@ def cmd_layout(aw):
]
def data_layout(dw):
def data_layout(dw, bankbits):
return [
("wdata", dw, DIR_M_TO_S),
("wdata_we", dw//8, DIR_M_TO_S),
("rdata", dw, DIR_S_TO_M)
("rdata", dw, DIR_S_TO_M),
("rbank", bankbits, DIR_S_TO_M)
]
@ -72,7 +73,7 @@ class LiteDRAMInterface(Record):
self.settings = settings
layout = [("bank"+str(i), cmd_layout(self.aw)) for i in range(self.nbanks)]
layout += data_layout(self.dw)
layout += data_layout(self.dw, settings.geom.bankbits)
Record.__init__(self, layout)
def cmd_description(aw):
@ -87,12 +88,12 @@ def wdata_description(dw):
("we", dw//8)
]
def rdata_description(dw):
return [("data", dw)]
def rdata_description(dw, nbanks):
return [("data", dw), ("bank", nbanks)]
class LiteDRAMPort:
def __init__(self, mode, aw, dw, cd="sys", id=0):
def __init__(self, mode, aw, dw, bankbits, cd="sys", id=0):
self.mode = mode
self.aw = aw
self.dw = dw
@ -103,7 +104,7 @@ class LiteDRAMPort:
self.cmd = stream.Endpoint(cmd_description(aw))
self.wdata = stream.Endpoint(wdata_description(dw))
self.rdata = stream.Endpoint(rdata_description(dw))
self.rdata = stream.Endpoint(rdata_description(dw, bankbits))
self.flush = Signal()

View file

@ -173,14 +173,26 @@ class Multiplexer(Module, AutoCSR):
if tccd is not None:
cas_count = Signal(max=tccd+1)
self.sync += \
If(cas,
cas_count.eq(tccd-1)
).Elif(~cas_allowed,
cas_count.eq(cas_count-1)
)
If(cas,
cas_count.eq(tccd-1)
).Elif(~cas_allowed,
cas_count.eq(cas_count-1)
)
self.comb += cas_allowed.eq(cas_count == 0)
self.comb += [bm.cas_allowed.eq(cas_allowed) for bm in bank_machines]
# tWTR timing
tWTR = settings.timing.tWTR + settings.timing.tCCD # tWTR begins after the transfer is complete, tccd accounts for this
wtr_allowed = Signal(reset=1)
wtr_count = Signal(max=tWTR)
self.sync += [
If(choose_req.cmd.ready & choose_req.cmd.valid & choose_req.cmd.is_write,
wtr_count.eq(tWTR-1)
).Elif(wtr_count != 0,
wtr_count.eq(wtr_count-1)
)
]
# Read/write turnaround
read_available = Signal()
write_available = Signal()
@ -287,9 +299,13 @@ class Multiplexer(Module, AutoCSR):
NextState("READ")
)
)
fsm.act("WTR",
If(wtr_count == 0,
NextState("READ")
)
)
# TODO: reduce this, actual limit is around (cl+1)/nphases
fsm.delayed_enter("RTW", "WRITE", settings.phy.read_latency-1)
fsm.delayed_enter("WTR", "READ", settings.timing.tWTR-1)
if settings.with_bandwidth:
data_width = settings.phy.dfi_databits*settings.phy.nphases

View file

@ -33,12 +33,12 @@ class LiteDRAMCrossbar(Module):
dw = self.dw
# crossbar port
port = LiteDRAMPort(mode, self.rca_bits + self.bank_bits, self.dw, "sys", len(self.masters))
port = LiteDRAMPort(mode, self.rca_bits + self.bank_bits, self.dw, self.bank_bits, "sys", len(self.masters))
self.masters.append(port)
# clock domain crossing
if cd != "sys":
new_port = LiteDRAMPort(mode, port.aw, port.dw, cd, port.id)
new_port = LiteDRAMPort(mode, port.aw, port.dw, self.bank_bits, cd, port.id)
self.submodules += LiteDRAMPortCDC(new_port, port)
port = new_port
@ -48,7 +48,7 @@ class LiteDRAMCrossbar(Module):
adr_shift = -log2_int(dw//self.dw)
else:
adr_shift = log2_int(self.dw//dw)
new_port = LiteDRAMPort(mode, port.aw + adr_shift, dw, cd, port.id)
new_port = LiteDRAMPort(mode, port.aw + adr_shift, dw, self.bank_bits, cd, port.id)
self.submodules += ClockDomainsRenamer(cd)(LiteDRAMPortConverter(new_port, port, reverse))
port = new_port
@ -68,6 +68,8 @@ class LiteDRAMCrossbar(Module):
arbiters = [roundrobin.RoundRobin(nmasters, roundrobin.SP_CE) for n in range(self.nbanks)]
self.submodules += arbiters
rbank = Signal(max=self.nbanks)
for nb, arbiter in enumerate(arbiters):
bank = getattr(controller, "bank"+str(nb))
@ -89,6 +91,12 @@ class LiteDRAMCrossbar(Module):
arbiter.ce.eq(~bank.valid & ~bank.lock)
]
# Get rdata source bank
self.sync += \
If((arbiter.grant == nm) & bank.rdata_valid,
rbank.eq(nb)
)
# route requests
self.comb += [
bank.adr.eq(Array(m_rca)[arbiter.grant]),
@ -116,6 +124,12 @@ class LiteDRAMCrossbar(Module):
master_rdata_valid = new_master_rdata_valid
master_rdata_valids[nm] = master_rdata_valid
# Delay bank output to match rvalid
for i in range(self.read_latency-1):
new_master_rbank = Signal(max=self.nbanks)
self.sync += new_master_rbank.eq(rbank)
rbank = new_master_rbank
for master, master_ready in zip(self.masters, master_readys):
self.comb += master.cmd.ready.eq(master_ready)
for master, master_wdata_ready in zip(self.masters, master_wdata_readys):
@ -139,6 +153,7 @@ class LiteDRAMCrossbar(Module):
# route data reads
for master in self.masters:
self.comb += master.rdata.data.eq(self.controller.rdata)
self.comb += master.rdata.bank.eq(rbank)
def split_master_addresses(self, bank_bits, rca_bits, cba_shift):
m_ba = [] # bank address

View file

@ -69,7 +69,7 @@ class LiteDRAMDMAReader(Module):
self.submodules += fifo
self.comb += [
port.rdata.connect(fifo.sink),
port.rdata.connect(fifo.sink, omit=["bank"]),
fifo.source.connect(source),
data_dequeued.eq(source.valid & source.ready)
]