csr: Fix definition(s) of CSR_BASE in generated headers

CSR_BASE is currently defined twice. Once in mem.h as the base
of the CSR region in the SoC address space, and once in csr.h
as the base address for all CSRs.

This fixes two issues with those definitions:

 - The mem.h one is unconditional which prevents an external
redefinition (which is useful under some circumstances such as
when using an address decoder outside of LiteX with a standalone
core).

 - The csr.h one is actually the origin of the first CSR region
rather than the origin of the CSR region in the SoC space. They
are usually the same ... unless you don't have CSR bank 0 in
which case the csr.h one becomes different. This causes conflicts
with the mem.h definition and breaks projects using a standalone
cores.

The first one is fixed by adding the #ifndef/#endif around the
definition of the memory regions, the second one by passing the
csr_base to use to get_csr_header()

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
This commit is contained in:
Benjamin Herrenschmidt 2020-05-22 17:53:20 +10:00 committed by Florent Kermarrec
parent f8bb500a43
commit c78caeb998
2 changed files with 7 additions and 2 deletions

View File

@ -136,8 +136,11 @@ class Builder:
export.get_soc_header(self.soc.constants)) export.get_soc_header(self.soc.constants))
write_to_file( write_to_file(
os.path.join(self.generated_dir, "csr.h"), os.path.join(self.generated_dir, "csr.h"),
export.get_csr_header(self.soc.csr_regions, export.get_csr_header(
self.soc.constants) regions = self.soc.csr_regions,
constants = self.soc.constants,
csr_base = self.soc.mem_regions['csr'].origin
)
) )
write_to_file( write_to_file(
os.path.join(self.generated_dir, "git.h"), os.path.join(self.generated_dir, "git.h"),

View File

@ -118,9 +118,11 @@ def get_mem_header(regions):
r = generated_banner("//") r = generated_banner("//")
r += "#ifndef __GENERATED_MEM_H\n#define __GENERATED_MEM_H\n\n" r += "#ifndef __GENERATED_MEM_H\n#define __GENERATED_MEM_H\n\n"
for name, region in regions.items(): for name, region in regions.items():
r += "#ifndef {name}\n".format(name=name.upper())
r += "#define {name}_BASE 0x{base:08x}L\n#define {name}_SIZE 0x{size:08x}\n\n".format( r += "#define {name}_BASE 0x{base:08x}L\n#define {name}_SIZE 0x{size:08x}\n\n".format(
name=name.upper(), base=region.origin, size=region.length) name=name.upper(), base=region.origin, size=region.length)
r += "#endif\n" r += "#endif\n"
r += "#endif\n"
return r return r
def get_soc_header(constants, with_access_functions=True): def get_soc_header(constants, with_access_functions=True):