2015-02-28 05:44:14 -05:00
|
|
|
from migen.fhdl.std import *
|
|
|
|
from migen.bus import wishbone, csr
|
2015-03-02 05:55:28 -05:00
|
|
|
from migen.genlib.record import *
|
2015-02-28 05:44:14 -05:00
|
|
|
|
2015-03-02 02:24:51 -05:00
|
|
|
from misoclib.mem.sdram.bus import dfi, lasmibus
|
2015-03-02 03:08:28 -05:00
|
|
|
from misoclib.mem.sdram.phy import dfii
|
2015-03-02 05:35:53 -05:00
|
|
|
from misoclib.mem.sdram.core import minicon, lasmicon
|
2015-03-02 05:55:28 -05:00
|
|
|
from misoclib.mem.sdram.core.lasmicon.crossbar import Crossbar
|
2015-03-02 02:24:51 -05:00
|
|
|
from misoclib.mem.sdram.frontend import memtest, wishbone2lasmi
|
2015-02-28 06:04:51 -05:00
|
|
|
from misoclib.soc import SoC, mem_decoder
|
2015-02-28 05:44:14 -05:00
|
|
|
|
|
|
|
class SDRAMSoC(SoC):
|
|
|
|
csr_map = {
|
2015-03-01 05:58:46 -05:00
|
|
|
"dfii": 7,
|
2015-03-02 05:55:28 -05:00
|
|
|
"controller": 8,
|
2015-03-01 05:58:46 -05:00
|
|
|
"wishbone2lasmi": 9,
|
|
|
|
"memtest_w": 10,
|
|
|
|
"memtest_r": 11
|
2015-02-28 05:44:14 -05:00
|
|
|
}
|
|
|
|
csr_map.update(SoC.csr_map)
|
|
|
|
|
|
|
|
def __init__(self, platform, clk_freq,
|
|
|
|
ramcon_type="lasmicon",
|
|
|
|
with_l2=True, l2_size=8192,
|
|
|
|
with_memtest=False,
|
|
|
|
**kwargs):
|
|
|
|
SoC.__init__(self, platform, clk_freq, **kwargs)
|
|
|
|
self.ramcon_type = ramcon_type
|
|
|
|
|
|
|
|
self.with_l2 = with_l2
|
|
|
|
self.l2_size = l2_size
|
|
|
|
|
|
|
|
self.with_memtest = with_memtest
|
|
|
|
|
|
|
|
self._sdram_phy_registered = False
|
|
|
|
|
2015-03-02 05:21:13 -05:00
|
|
|
def register_sdram_phy(self, phy, sdram_geom, sdram_timing):
|
2015-02-28 05:44:14 -05:00
|
|
|
if self._sdram_phy_registered:
|
|
|
|
raise FinalizeError
|
|
|
|
self._sdram_phy_registered = True
|
|
|
|
|
|
|
|
# DFI
|
2015-03-02 05:55:28 -05:00
|
|
|
self.submodules.dfii = dfii.DFIInjector(phy, sdram_geom.mux_a, sdram_geom.bank_a)
|
|
|
|
self.comb += Record.connect(self.dfii.master, phy.dfi)
|
2015-02-28 05:44:14 -05:00
|
|
|
|
|
|
|
# LASMICON
|
|
|
|
if self.ramcon_type == "lasmicon":
|
2015-03-02 05:55:28 -05:00
|
|
|
self.submodules.controller = controller = lasmicon.LASMIcon(phy, sdram_geom, sdram_timing)
|
|
|
|
self.comb += Record.connect(controller.dfi, self.dfii.slave)
|
2015-02-28 05:44:14 -05:00
|
|
|
|
2015-03-02 05:55:28 -05:00
|
|
|
self.submodules.crossbar = crossbar = Crossbar([controller.lasmic], controller.nrowbits)
|
2015-02-28 05:44:14 -05:00
|
|
|
|
|
|
|
if self.with_memtest:
|
2015-03-02 05:55:28 -05:00
|
|
|
self.submodules.memtest_w = memtest.MemtestWriter(crossbar.get_master())
|
|
|
|
self.submodules.memtest_r = memtest.MemtestReader(crossbar.get_master())
|
2015-02-28 05:44:14 -05:00
|
|
|
|
|
|
|
if self.with_l2:
|
2015-03-02 05:55:28 -05:00
|
|
|
self.submodules.wishbone2lasmi = wishbone2lasmi.WB2LASMI(self.l2_size//4, crossbar.get_master())
|
|
|
|
lasmic = self.controller.lasmic
|
|
|
|
sdram_size = 2**lasmic.aw*lasmic.dw*lasmic.nbanks//8
|
2015-02-28 05:44:14 -05:00
|
|
|
self.register_mem("sdram", self.mem_map["sdram"], self.wishbone2lasmi.wishbone, sdram_size)
|
|
|
|
|
|
|
|
# MINICON
|
|
|
|
elif self.ramcon_type == "minicon":
|
|
|
|
if self.with_l2:
|
|
|
|
raise ValueError("MINICON does not implement L2 cache (Use LASMICON or disable L2 cache (with_l2=False))")
|
|
|
|
|
2015-03-02 05:55:28 -05:00
|
|
|
self.submodules.controller = controller = minicon.Minicon(phy, sdram_geom, sdram_timing)
|
|
|
|
self.comb += Record.connect(controller.dfi, self.dfii.slave)
|
2015-02-28 05:44:14 -05:00
|
|
|
|
2015-03-02 05:55:28 -05:00
|
|
|
sdram_width = flen(controller.bus.dat_r)
|
2015-02-28 05:44:14 -05:00
|
|
|
sdram_size = 2**(sdram_geom.bank_a+sdram_geom.row_a+sdram_geom.col_a)*sdram_width//8
|
|
|
|
|
|
|
|
if sdram_width == 32:
|
2015-03-02 05:55:28 -05:00
|
|
|
self.register_mem("sdram", self.mem_map["sdram"], controller.bus, sdram_size)
|
2015-02-28 05:44:14 -05:00
|
|
|
elif sdram_width < 32:
|
2015-03-02 05:55:28 -05:00
|
|
|
self.submodules.downconverter = downconverter = wishbone.DownConverter(32, sdram_width)
|
|
|
|
self.comb += Record.connect(downconverter.wishbone_o, controller.bus)
|
|
|
|
self.register_mem("sdram", self.mem_map["sdram"], downconverter.wishbone_i, sdram_size)
|
2015-02-28 05:44:14 -05:00
|
|
|
else:
|
|
|
|
raise NotImplementedError("Unsupported SDRAM width of {} > 32".format(sdram_width))
|
|
|
|
else:
|
|
|
|
raise ValueError("Unsupported SDRAM controller type: {}".format(self.ramcon_type))
|
|
|
|
|
|
|
|
def do_finalize(self):
|
|
|
|
if not self._sdram_phy_registered:
|
|
|
|
raise FinalizeError("Need to call SDRAMSoC.register_sdram_phy()")
|
|
|
|
SoC.do_finalize(self)
|