From aa9eb1f6a36d2147b7e03d7aaf5b65368d3e47c2 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Thu, 25 Mar 2021 09:49:59 +0100 Subject: [PATCH] integration/soc: Add CSR automatic allocation and enable it by default. Un-allocated CSRs were already automatically detected so when un-allocated we can just simply allocate them automatically instead of raising an error. This also allows simplifying user's code since self.csr.add/self.add_csr will no longer be required. --- litex/soc/integration/soc.py | 41 ++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/litex/soc/integration/soc.py b/litex/soc/integration/soc.py index 845a1e522..a3925d60d 100644 --- a/litex/soc/integration/soc.py +++ b/litex/soc/integration/soc.py @@ -587,15 +587,23 @@ class SoCCSRHandler(SoCLocHandler): self.regions[name] = region # Address map ---------------------------------------------------------------------------------- - def address_map(self, name, memory): + def address_map(self, name, memory, auto_alloc=True): if memory is not None: name = name + "_" + memory.name_override if self.locs.get(name, None) is None: - self.logger.error("CSR {} {}.".format( - colorer(name), - colorer("not found", color="red"))) - self.logger.error(self) - raise + if auto_alloc: + self.add(name, use_loc_if_exists=True) + else: + self.logger.info("{} {} {} at Location {}.".format( + colorer(name, color="underline"), + self.name, + colorer("allocated" if allocated else "added", color="cyan" if allocated else "green"), + colorer(n))) + self.logger.error("CSR {} {}.".format( + colorer(name), + colorer("not found", color="red"))) + self.logger.error(self) + raise return self.locs[name] # Str ------------------------------------------------------------------------------------------ @@ -930,16 +938,6 @@ class SoC(Module): # SoC finalization ----------------------------------------------------------------------------- def do_finalize(self): - self.logger.info(colorer("-"*80, color="bright")) - self.logger.info(colorer("Finalized SoC:")) - self.logger.info(colorer("-"*80, color="bright")) - self.logger.info(self.bus) - if hasattr(self, "dma_bus"): - self.logger.info(self.dma_bus) - self.logger.info(self.csr) - self.logger.info(self.irq) - self.logger.info(colorer("-"*80, color="bright")) - interconnect_p2p_cls = { "wishbone": wishbone.InterconnectPointToPoint, "axi-lite": axi.AXILiteInterconnectPointToPoint, @@ -1082,6 +1080,17 @@ class SoC(Module): self.comb += self.cpu.interrupt[loc].eq(module.ev.irq) self.add_constant(name + "_INTERRUPT", loc) + # SoC Infos -------------------------------------------------------------------------------- + self.logger.info(colorer("-"*80, color="bright")) + self.logger.info(colorer("Finalized SoC:")) + self.logger.info(colorer("-"*80, color="bright")) + self.logger.info(self.bus) + if hasattr(self, "dma_bus"): + self.logger.info(self.dma_bus) + self.logger.info(self.csr) + self.logger.info(self.irq) + self.logger.info(colorer("-"*80, color="bright")) + # SoC build ------------------------------------------------------------------------------------ def build(self, *args, **kwargs): self.build_name = kwargs.pop("build_name", self.platform.name)