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
|
|
|
|
2015-04-13 10:47:22 -04:00
|
|
|
|
2015-02-28 05:44:14 -05:00
|
|
|
class SDRAMSoC(SoC):
|
2015-04-13 10:19:55 -04:00
|
|
|
csr_map = {
|
2015-04-13 11:56:51 -04:00
|
|
|
"sdram": 8,
|
2015-06-16 13:06:24 -04:00
|
|
|
"l2_cache": 9,
|
2015-04-13 11:56:51 -04:00
|
|
|
"memtest_w": 10,
|
|
|
|
"memtest_r": 11
|
2015-04-13 10:19:55 -04:00
|
|
|
}
|
|
|
|
csr_map.update(SoC.csr_map)
|
2015-02-28 05:44:14 -05:00
|
|
|
|
2015-04-13 10:19:55 -04:00
|
|
|
def __init__(self, platform, clk_freq, sdram_controller_settings,
|
|
|
|
**kwargs):
|
|
|
|
SoC.__init__(self, platform, clk_freq, **kwargs)
|
|
|
|
if isinstance(sdram_controller_settings, str):
|
|
|
|
self.sdram_controller_settings = eval(sdram_controller_settings)
|
|
|
|
else:
|
|
|
|
self.sdram_controller_settings = sdram_controller_settings
|
|
|
|
self._sdram_phy_registered = False
|
2015-06-17 08:52:30 -04:00
|
|
|
self._wb_sdram_ifs = []
|
|
|
|
self._wb_sdram = wishbone.Interface()
|
|
|
|
|
|
|
|
def add_wb_sdram_if(self, interface):
|
|
|
|
if self.finalized:
|
|
|
|
raise FinalizeError
|
|
|
|
self._wb_sdram_ifs.append(interface)
|
2015-02-28 05:44:14 -05:00
|
|
|
|
2015-04-13 10:19:55 -04:00
|
|
|
def register_sdram_phy(self, phy):
|
|
|
|
if self._sdram_phy_registered:
|
|
|
|
raise FinalizeError
|
|
|
|
self._sdram_phy_registered = True
|
2015-02-28 05:44:14 -05:00
|
|
|
|
2015-04-13 10:19:55 -04:00
|
|
|
# Core
|
2015-04-13 11:56:51 -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-04-13 10:19:55 -04:00
|
|
|
dfi_databits_divisor = 1 if phy.settings.memtype == "SDR" else 2
|
|
|
|
sdram_width = phy.settings.dfi_databits//dfi_databits_divisor
|
2015-04-13 11:01:05 -04:00
|
|
|
main_ram_size = 2**(phy.module.geom_settings.bankbits +
|
|
|
|
phy.module.geom_settings.rowbits +
|
2015-04-13 10:19:55 -04:00
|
|
|
phy.module.geom_settings.colbits)*sdram_width//8
|
|
|
|
# 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-06-16 13:06:24 -04:00
|
|
|
l2_size = self.sdram_controller_settings.l2_size
|
2015-06-19 02:39:37 -04:00
|
|
|
if l2_size:
|
|
|
|
self.add_constant("L2_SIZE", l2_size)
|
2015-03-28 18:10:33 -04:00
|
|
|
|
2015-06-17 10:32:17 -04:00
|
|
|
# add a Wishbone interface to the DRAM
|
2015-06-17 08:52:30 -04:00
|
|
|
wb_sdram = wishbone.Interface()
|
|
|
|
self.add_wb_sdram_if(wb_sdram)
|
|
|
|
self.register_mem("main_ram", self.mem_map["main_ram"], wb_sdram, main_ram_size)
|
|
|
|
|
2015-04-13 10:19:55 -04:00
|
|
|
# LASMICON frontend
|
|
|
|
if isinstance(self.sdram_controller_settings, LASMIconSettings):
|
|
|
|
if self.sdram_controller_settings.with_bandwidth:
|
|
|
|
self.sdram.controller.multiplexer.add_bandwidth()
|
2015-03-03 03:02:53 -05:00
|
|
|
|
2015-04-13 10:19:55 -04:00
|
|
|
if self.sdram_controller_settings.with_memtest:
|
|
|
|
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-04-13 10:19:55 -04:00
|
|
|
if l2_size:
|
2015-06-16 13:06:24 -04:00
|
|
|
lasmim = self.sdram.crossbar.get_master()
|
2015-06-17 08:52:30 -04:00
|
|
|
l2_cache = wishbone.Cache(l2_size//4, self._wb_sdram, wishbone.Interface(lasmim.dw))
|
2015-05-04 06:28:49 -04:00
|
|
|
# XXX Vivado ->2015.1 workaround, Vivado is not able to map correctly our L2 cache.
|
|
|
|
# Issue is reported to Xilinx and should be fixed in next releases (2015.2?).
|
2015-04-13 10:19:55 -04:00
|
|
|
# Remove this workaround when fixed by Xilinx.
|
|
|
|
from mibuild.xilinx.vivado import XilinxVivadoToolchain
|
|
|
|
if isinstance(self.platform.toolchain, XilinxVivadoToolchain):
|
|
|
|
from migen.fhdl.simplify import FullMemoryWE
|
2015-06-16 13:06:24 -04:00
|
|
|
self.submodules.l2_cache = FullMemoryWE()(l2_cache)
|
2015-04-13 10:19:55 -04:00
|
|
|
else:
|
2015-06-16 13:06:24 -04:00
|
|
|
self.submodules.l2_cache = l2_cache
|
|
|
|
self.submodules.wishbone2lasmi = wishbone2lasmi.WB2LASMI(self.l2_cache.slave, lasmim)
|
2015-02-28 05:44:14 -05:00
|
|
|
|
2015-04-13 10:19:55 -04:00
|
|
|
# MINICON frontend
|
|
|
|
elif isinstance(self.sdram_controller_settings, MiniconSettings):
|
2015-06-16 13:06:24 -04:00
|
|
|
if l2_size:
|
2015-06-17 08:52:30 -04:00
|
|
|
l2_cache = wishbone.Cache(l2_size//4, self._wb_sdram, self.sdram.controller.bus)
|
2015-06-16 13:06:24 -04:00
|
|
|
# XXX Vivado ->2015.1 workaround, Vivado is not able to map correctly our L2 cache.
|
|
|
|
# Issue is reported to Xilinx and should be fixed in next releases (2015.2?).
|
|
|
|
# Remove this workaround when fixed by Xilinx.
|
|
|
|
from mibuild.xilinx.vivado import XilinxVivadoToolchain
|
|
|
|
if isinstance(self.platform.toolchain, XilinxVivadoToolchain):
|
|
|
|
from migen.fhdl.simplify import FullMemoryWE
|
|
|
|
self.submodules.l2_cache = FullMemoryWE()(l2_cache)
|
|
|
|
else:
|
|
|
|
self.submodules.l2_cache = l2_cache
|
|
|
|
else:
|
2015-06-17 08:52:30 -04:00
|
|
|
self.submodules.converter = wishbone.Converter(self._wb_sdram, self.sdram.controller.bus)
|
2015-02-28 05:44:14 -05:00
|
|
|
|
2015-04-13 10:19:55 -04:00
|
|
|
def do_finalize(self):
|
|
|
|
if not self.integrated_main_ram_size:
|
|
|
|
if not self._sdram_phy_registered:
|
|
|
|
raise FinalizeError("Need to call SDRAMSoC.register_sdram_phy()")
|
2015-06-17 08:52:30 -04:00
|
|
|
|
|
|
|
# arbitrate wishbone interfaces to the DRAM
|
|
|
|
self.submodules.wb_sdram_con = wishbone.Arbiter(self._wb_sdram_ifs,
|
|
|
|
self._wb_sdram)
|
2015-04-13 10:19:55 -04:00
|
|
|
SoC.do_finalize(self)
|