From a0c0a6fd05046d6e930b38a340ce701ba04de695 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Wed, 30 Oct 2019 16:31:27 +0100 Subject: [PATCH] integration/SoCMemRegion: use type instead of io_region/linker_region and export type to csv/json Supported types: "cached", "io", "cached+linker", "io+linker", default="cached" --- litex/soc/integration/common.py | 10 +++++----- litex/soc/integration/export.py | 9 ++++++--- litex/soc/integration/soc_core.py | 12 +++++++----- litex/tools/remote/csr_builder.py | 8 ++++---- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/litex/soc/integration/common.py b/litex/soc/integration/common.py index 46ab2083..3a56ffa7 100644 --- a/litex/soc/integration/common.py +++ b/litex/soc/integration/common.py @@ -77,11 +77,11 @@ def SoCConstant(value): return value class SoCMemRegion: - def __init__(self, origin, length, io_region=False, linker_region=False): - self.origin = origin - self.length = length - self.io_region = io_region - self.linker_region = linker_region + def __init__(self, origin, length, type): + assert type in ["cached", "io", "cached+linker", "io+linker"] + self.origin = origin + self.length = length + self.type = type class SoCCSRRegion: def __init__(self, origin, busword, obj): diff --git a/litex/soc/integration/export.py b/litex/soc/integration/export.py index b369458e..4fa5fb1c 100644 --- a/litex/soc/integration/export.py +++ b/litex/soc/integration/export.py @@ -243,7 +243,8 @@ def get_csr_json(csr_regions={}, constants={}, mem_regions={}): for name, region in mem_regions.items(): d["memories"][name.lower()] = { "base": region.origin, - "size": region.length + "size": region.length, + "type": region.type, } return json.dumps(d, indent=4) @@ -264,7 +265,9 @@ def get_csr_csv(csr_regions={}, constants={}, mem_regions={}): for name, value in d["constants"].items(): r += "constant,{},{},,\n".format(name, value) for name in d["memories"].keys(): - r += "memory_region,{},0x{:08x},{:d},\n".format(name, + r += "memory_region,{},0x{:08x},{:d},{:s}\n".format(name, d["memories"][name]["base"], - d["memories"][name]["size"]) + d["memories"][name]["size"], + d["memories"][name]["type"], + ) return r diff --git a/litex/soc/integration/soc_core.py b/litex/soc/integration/soc_core.py index 4def3497..b9e7b7bc 100644 --- a/litex/soc/integration/soc_core.py +++ b/litex/soc/integration/soc_core.py @@ -379,7 +379,7 @@ class SoCCore(Module): r0 = regions[n0] for n1 in list(regions.keys())[i+1:]: r1 = regions[n1] - if r0.linker_region or r1.linker_region: + if ("linker" in r0.type) or ("linker" in r1.type): continue if r0.origin >= (r1.origin + r1.length): continue @@ -389,14 +389,16 @@ class SoCCore(Module): i += 1 return None - def add_memory_region(self, name, origin, length, io_region=False, linker_region=False): + def add_memory_region(self, name, origin, length, type="cached", io_region=False): + if io_region: # 2019-10-30: io_region retro-compatibility + deprecated_warning(": io_region replaced by type=\"io\".") + type = "io" length = 2**log2_int(length, False) - if io_region: + if "io" in type: self.check_io_region(name, origin, length) if name in self.mem_regions.keys(): raise ValueError("Memory region conflict, {} name already used".format(name)) - self.mem_regions[name] = SoCMemRegion(origin, length, - io_region=io_region, linker_region=linker_region) + self.mem_regions[name] = SoCMemRegion(origin, length, type) overlap = self.check_regions_overlap(self.mem_regions) if overlap is not None: raise ValueError("Memory region conflict between {} and {}".format(overlap[0], overlap[1])) diff --git a/litex/tools/remote/csr_builder.py b/litex/tools/remote/csr_builder.py index a06cbe87..c798052d 100644 --- a/litex/tools/remote/csr_builder.py +++ b/litex/tools/remote/csr_builder.py @@ -54,10 +54,10 @@ class CSRRegister: class CSRMemoryRegion: - def __init__(self, base, size): + def __init__(self, base, size, type): self.base = base self.size = size - + self.type = type class CSRBuilder: def __init__(self, comm, csr_csv, csr_data_width=None): @@ -115,7 +115,7 @@ class CSRBuilder: def build_memories(self): d = {} for item in self.items: - group, name, base, size, dummy1 = item + group, name, base, size, type = item if group == "memory_region": - d[name] = CSRMemoryRegion(int(base, 16), int(size)) + d[name] = CSRMemoryRegion(int(base, 16), int(size), type) return CSRElements(d) -- 2.30.2