integration/SoCMemRegion: use type instead of io_region/linker_region and export...
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Wed, 30 Oct 2019 15:31:27 +0000 (16:31 +0100)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Wed, 30 Oct 2019 15:42:26 +0000 (16:42 +0100)
Supported types: "cached", "io", "cached+linker", "io+linker", default="cached"

litex/soc/integration/common.py
litex/soc/integration/export.py
litex/soc/integration/soc_core.py
litex/tools/remote/csr_builder.py

index 46ab20830689d7fd6d88f42d433a65ab12b44e56..3a56ffa7ef827bd23aebe534e52d0ab6964a03df 100644 (file)
@@ -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):
index b369458e296eb8cdcdbd71db827b6e9654ed7cc8..4fa5fb1c6fae3c8b0d5ad3ecda1c2503dffb66ad 100644 (file)
@@ -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
index 4def34976e65f8b4a6a42de1018f21d169db48f6..b9e7b7bc87a2c671a78c373d834479335f9aac43 100644 (file)
@@ -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]))
index a06cbe87da5a61b7ac5871e21b29f87e5294899c..c798052d3d296afe760fb2c561b81910a6b1e9e5 100644 (file)
@@ -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)