Skip to content

Commit

Permalink
Merge pull request #21 from JohnSully/outoforder
Browse files Browse the repository at this point in the history
Outoforder
  • Loading branch information
enjoy-digital authored Aug 9, 2018
2 parents 74c3c09 + bfa1d6a commit 26f3f01
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 17 deletions.
15 changes: 8 additions & 7 deletions litedram/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
]


Expand All @@ -72,7 +73,7 @@ def __init__(self, address_align, settings):
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):
Expand All @@ -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
Expand All @@ -103,7 +104,7 @@ def __init__(self, mode, aw, dw, cd="sys", id=0):

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()

Expand Down
28 changes: 22 additions & 6 deletions litedram/core/multiplexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,26 @@ def __init__(self,
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()
Expand Down Expand Up @@ -287,9 +299,13 @@ def steerer_sel(steerer, r_w_n):
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
Expand Down
21 changes: 18 additions & 3 deletions litedram/frontend/crossbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ def get_port(self, mode="both", dw=None, cd="sys", reverse=False):
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

Expand All @@ -48,7 +48,7 @@ def get_port(self, mode="both", dw=None, cd="sys", reverse=False):
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

Expand All @@ -68,6 +68,8 @@ def do_finalize(self):

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))

Expand All @@ -89,6 +91,12 @@ def do_finalize(self):
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]),
Expand Down Expand Up @@ -116,6 +124,12 @@ def do_finalize(self):
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):
Expand All @@ -139,6 +153,7 @@ def do_finalize(self):
# 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
Expand Down
2 changes: 1 addition & 1 deletion litedram/frontend/dma.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def __init__(self, port, fifo_depth=16, fifo_buffered=False):
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)
]
Expand Down

0 comments on commit 26f3f01

Please sign in to comment.