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"
This commit is contained in:
Florent Kermarrec 2019-10-30 16:31:27 +01:00
parent 9fcf297387
commit a0c0a6fd05
4 changed files with 22 additions and 17 deletions

View 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):

View 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

View 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]))

View 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)