litex/misoc/integration/soc_sdram.py

122 lines
5.6 KiB
Python
Raw Normal View History

2015-09-22 12:36:47 -04:00
from migen import *
2015-03-02 05:55:28 -05:00
from migen.genlib.record import *
2015-09-26 09:51:22 -04:00
from misoc.interconnect import wishbone, wishbone2lasmi, lasmi_bus
2015-09-25 06:43:20 -04:00
from misoc.interconnect.csr import AutoCSR
2015-10-01 23:17:47 -04:00
from misoc.cores import dfii, minicon, lasmicon
from misoc.integration.soc_core import *
2015-04-13 10:47:22 -04:00
__all__ = ["SoCSDRAM", "soc_sdram_args", "soc_sdram_argdict"]
2015-10-01 23:17:47 -04:00
class ControllerInjector(Module, AutoCSR):
def __init__(self, phy, controller_type, geom_settings, timing_settings):
self.submodules.dfii = dfii.DFIInjector(geom_settings.addressbits, geom_settings.bankbits,
phy.settings.dfi_databits, phy.settings.nphases)
self.comb += Record.connect(self.dfii.master, phy.dfi)
2015-10-01 23:17:47 -04:00
if controller_type == "lasmicon":
self.submodules.controller = controller = lasmicon.LASMIcon(phy.settings,
geom_settings,
2015-10-01 23:17:47 -04:00
timing_settings)
self.comb += Record.connect(controller.dfi, self.dfii.slave)
2015-09-26 09:51:22 -04:00
self.submodules.crossbar = lasmi_bus.LASMIxbar([controller.lasmic],
controller.nrowbits)
2015-10-01 23:17:47 -04:00
elif controller_type == "minicon":
self.submodules.controller = controller = minicon.Minicon(phy.settings,
geom_settings,
timing_settings)
self.comb += Record.connect(controller.dfi, self.dfii.slave)
else:
raise ValueError("Unsupported SDRAM controller type")
class SoCSDRAM(SoCCore):
csr_map = {
"sdram": 8,
2015-10-01 23:17:47 -04:00
"l2_cache": 9
}
2015-09-25 06:43:20 -04:00
csr_map.update(SoCCore.csr_map)
2015-10-01 23:17:47 -04:00
def __init__(self, platform, clk_freq, l2_size=8192, **kwargs):
2015-09-25 06:43:20 -04:00
SoCCore.__init__(self, platform, clk_freq, **kwargs)
2015-10-01 23:17:47 -04:00
self.l2_size = l2_size
self._sdram_phy = []
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-10-01 23:17:47 -04:00
def register_sdram(self, phy, sdram_controller_type, geom_settings, timing_settings):
assert not self._sdram_phy
self._sdram_phy.append(phy) # encapsulate in list to prevent CSR scanning
2015-10-01 23:17:47 -04:00
self.submodules.sdram = ControllerInjector(
phy, sdram_controller_type, geom_settings, timing_settings)
dfi_databits_divisor = 1 if phy.settings.memtype == "SDR" else 2
sdram_width = phy.settings.dfi_databits//dfi_databits_divisor
2015-10-01 23:17:47 -04:00
main_ram_size = 2**(geom_settings.bankbits +
geom_settings.rowbits +
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-10-01 23:17:47 -04:00
if self.l2_size:
self.add_constant("L2_SIZE", self.l2_size)
2015-06-17 10:32:17 -04:00
# add a Wishbone interface to the DRAM
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-10-01 23:17:47 -04:00
if sdram_controller_type == "lasmicon":
if self.l2_size:
lasmim = self.sdram.crossbar.get_master()
2015-10-01 23:17:47 -04:00
l2_cache = wishbone.Cache(self.l2_size//4, self._wb_sdram, wishbone.Interface(lasmim.dw))
# 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.
2015-09-26 09:51:22 -04:00
from migen.build.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
self.submodules.wishbone2lasmi = wishbone2lasmi.WB2LASMI(self.l2_cache.slave, lasmim)
2015-10-01 23:17:47 -04:00
elif sdram_controller_type == "minicon":
if self.l2_size:
l2_cache = wishbone.Cache(self.l2_size//4, self._wb_sdram, self.sdram.controller.bus)
# 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.
2015-09-26 09:51:22 -04:00
from migen.build.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:
self.submodules.converter = wishbone.Converter(self._wb_sdram, self.sdram.controller.bus)
2015-10-01 23:17:47 -04:00
else:
raise ValueError
def do_finalize(self):
if not self.integrated_main_ram_size:
2015-10-01 23:17:47 -04:00
if not self._sdram_phy:
raise FinalizeError("Need to call SDRAMSoC.register_sdram()")
# arbitrate wishbone interfaces to the DRAM
self.submodules.wb_sdram_con = wishbone.Arbiter(self._wb_sdram_ifs,
self._wb_sdram)
2015-09-25 06:43:20 -04:00
SoCCore.do_finalize(self)
soc_sdram_args = soc_core_args
soc_sdram_argdict = soc_core_argdict