2015-02-28 05:44:14 -05:00
|
|
|
from migen.fhdl.std import *
|
2015-04-02 02:40:29 -04:00
|
|
|
from migen.bus import wishbone
|
2015-03-02 05:55:28 -05:00
|
|
|
from migen.genlib.record import *
|
2015-02-28 05:44:14 -05:00
|
|
|
|
2015-03-21 17:51:24 -04:00
|
|
|
from misoclib.mem.sdram.core import SDRAMCore
|
|
|
|
from misoclib.mem.sdram.core.lasmicon import LASMIconSettings
|
|
|
|
from misoclib.mem.sdram.core.minicon import MiniconSettings
|
2015-03-02 02:24:51 -05:00
|
|
|
from misoclib.mem.sdram.frontend import memtest, wishbone2lasmi
|
2015-04-02 02:40:29 -04:00
|
|
|
from misoclib.soc import SoC
|
2015-02-28 05:44:14 -05:00
|
|
|
|
|
|
|
class SDRAMSoC(SoC):
|
|
|
|
csr_map = {
|
2015-03-02 06:05:50 -05:00
|
|
|
"sdram": 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)
|
|
|
|
|
2015-03-21 17:51:24 -04:00
|
|
|
def __init__(self, platform, clk_freq, sdram_controller_settings,
|
2015-02-28 05:44:14 -05:00
|
|
|
**kwargs):
|
|
|
|
SoC.__init__(self, platform, clk_freq, **kwargs)
|
2015-03-21 17:51:24 -04:00
|
|
|
if isinstance(sdram_controller_settings, str):
|
|
|
|
self.sdram_controller_settings = eval(sdram_controller_settings)
|
|
|
|
else:
|
|
|
|
self.sdram_controller_settings = sdram_controller_settings
|
2015-02-28 05:44:14 -05:00
|
|
|
self._sdram_phy_registered = False
|
|
|
|
|
2015-03-24 13:26:18 -04:00
|
|
|
def register_sdram_phy(self, phy):
|
2015-02-28 05:44:14 -05:00
|
|
|
if self._sdram_phy_registered:
|
|
|
|
raise FinalizeError
|
|
|
|
self._sdram_phy_registered = True
|
2015-03-21 17:51:24 -04:00
|
|
|
if isinstance(self.sdram_controller_settings, MiniconSettings) and phy.settings.memtype != "SDR":
|
2015-03-19 11:08:03 -04:00
|
|
|
raise NotImplementedError("Minicon only supports SDR memtype for now (" + phy.settings.memtype + ")")
|
2015-02-28 05:44:14 -05:00
|
|
|
|
2015-03-02 06:05:50 -05:00
|
|
|
# Core
|
2015-03-24 13:26:18 -04:00
|
|
|
self.submodules.sdram = SDRAMCore(phy, phy.module.geom_settings, phy.module.timing_settings, self.sdram_controller_settings)
|
2015-02-28 05:44:14 -05:00
|
|
|
|
2015-03-28 18:10:33 -04:00
|
|
|
dfi_databits_divisor = 1 if phy.settings.memtype == "SDR" else 2
|
|
|
|
sdram_width = phy.settings.dfi_databits//dfi_databits_divisor
|
|
|
|
main_ram_size = 2**(phy.module.geom_settings.bankbits+
|
|
|
|
phy.module.geom_settings.rowbits+
|
|
|
|
phy.module.geom_settings.colbits)*sdram_width//8
|
2015-03-28 18:18:08 -04:00
|
|
|
# XXX: Limit main_ram_size to 256MB, we should modify mem_map to allow larger memories.
|
|
|
|
main_ram_size = min(main_ram_size, 256*1024*1024)
|
2015-03-28 18:10:33 -04:00
|
|
|
|
2015-03-02 06:05:50 -05:00
|
|
|
# LASMICON frontend
|
2015-03-21 17:51:24 -04:00
|
|
|
if isinstance(self.sdram_controller_settings, LASMIconSettings):
|
|
|
|
if self.sdram_controller_settings.with_bandwidth:
|
2015-03-03 03:02:53 -05:00
|
|
|
self.sdram.controller.multiplexer.add_bandwidth()
|
|
|
|
|
2015-03-21 17:51:24 -04:00
|
|
|
if self.sdram_controller_settings.with_memtest:
|
2015-03-02 06:05:50 -05:00
|
|
|
self.submodules.memtest_w = memtest.MemtestWriter(self.sdram.crossbar.get_master())
|
|
|
|
self.submodules.memtest_r = memtest.MemtestReader(self.sdram.crossbar.get_master())
|
2015-02-28 05:44:14 -05:00
|
|
|
|
2015-03-29 06:34:40 -04:00
|
|
|
l2_size = self.sdram_controller_settings.l2_size
|
2015-04-02 02:40:29 -04:00
|
|
|
if l2_size:
|
2015-03-12 12:12:35 -04:00
|
|
|
# XXX Vivado 2014.X workaround, Vivado is not able to map correctly our L2 cache.
|
|
|
|
# Issue is reported to Xilinx and should be fixed in next releases (2015.1?).
|
|
|
|
# Remove this workaround when fixed by Xilinx.
|
2015-03-13 18:19:08 -04:00
|
|
|
from mibuild.xilinx.vivado import XilinxVivadoToolchain
|
|
|
|
if isinstance(self.platform.toolchain, XilinxVivadoToolchain):
|
2015-03-12 12:12:35 -04:00
|
|
|
from migen.fhdl.simplify import FullMemoryWE
|
2015-04-06 11:52:34 -04:00
|
|
|
self.submodules.wishbone2lasmi = FullMemoryWE()(wishbone2lasmi.WB2LASMI(l2_size//4, self.sdram.crossbar.get_master()))
|
2015-03-12 12:12:35 -04:00
|
|
|
else:
|
2015-03-21 17:51:24 -04:00
|
|
|
self.submodules.wishbone2lasmi = wishbone2lasmi.WB2LASMI(l2_size//4, self.sdram.crossbar.get_master())
|
2015-03-21 16:00:12 -04:00
|
|
|
self.register_mem("main_ram", self.mem_map["main_ram"], self.wishbone2lasmi.wishbone, main_ram_size)
|
2015-02-28 05:44:14 -05:00
|
|
|
|
2015-03-02 06:05:50 -05:00
|
|
|
# MINICON frontend
|
2015-03-21 17:51:24 -04:00
|
|
|
elif isinstance(self.sdram_controller_settings, MiniconSettings):
|
2015-02-28 05:44:14 -05:00
|
|
|
if sdram_width == 32:
|
2015-03-21 16:00:12 -04:00
|
|
|
self.register_mem("main_ram", self.mem_map["main_ram"], self.sdram.controller.bus, main_ram_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)
|
2015-03-02 06:05:50 -05:00
|
|
|
self.comb += Record.connect(downconverter.wishbone_o, self.sdram.controller.bus)
|
2015-03-21 16:00:12 -04:00
|
|
|
self.register_mem("main_ram", self.mem_map["main_ram"], downconverter.wishbone_i, main_ram_size)
|
2015-02-28 05:44:14 -05:00
|
|
|
else:
|
|
|
|
raise NotImplementedError("Unsupported SDRAM width of {} > 32".format(sdram_width))
|
|
|
|
|
|
|
|
def do_finalize(self):
|
2015-04-01 16:38:04 -04:00
|
|
|
if not self.integrated_main_ram_size:
|
2015-03-06 01:51:44 -05:00
|
|
|
if not self._sdram_phy_registered:
|
|
|
|
raise FinalizeError("Need to call SDRAMSoC.register_sdram_phy()")
|
2015-02-28 05:44:14 -05:00
|
|
|
SoC.do_finalize(self)
|