2017-08-27 05:48:11 +08:00
|
|
|
from collections import OrderedDict
|
|
|
|
from operator import itemgetter
|
|
|
|
import csv
|
|
|
|
|
|
|
|
from misoc.interconnect.csr import CSRStatus, CSRStorage
|
|
|
|
|
|
|
|
|
|
|
|
def _get_csr_data(csv_file):
|
|
|
|
csr_data = OrderedDict()
|
|
|
|
with open(csv_file) as csv_file_f:
|
|
|
|
csv_reader = csv.reader(csv_file_f)
|
|
|
|
for name, address, length, ro in csv_reader:
|
|
|
|
region_name, csr_name = name.split(".")
|
|
|
|
address = int(address, 0)
|
|
|
|
length = int(length, 0)
|
2018-02-13 19:54:51 +08:00
|
|
|
if ro == "ro":
|
|
|
|
ro = True
|
|
|
|
elif ro == "rw":
|
|
|
|
ro = False
|
|
|
|
else:
|
|
|
|
raise ValueError
|
2017-08-27 05:48:11 +08:00
|
|
|
if region_name not in csr_data:
|
|
|
|
csr_data[region_name] = []
|
|
|
|
csr_data[region_name].append((csr_name, address, length, ro))
|
|
|
|
return csr_data
|
|
|
|
|
|
|
|
|
|
|
|
def get_remote_csr_regions(offset, csv_file):
|
2017-08-31 13:34:48 +08:00
|
|
|
busword = 32
|
2017-08-27 05:48:11 +08:00
|
|
|
regions = []
|
|
|
|
for region_name, csrs_info in _get_csr_data(csv_file).items():
|
|
|
|
csrs_info = sorted(csrs_info, key=itemgetter(1))
|
|
|
|
origin = csrs_info[0][1]
|
|
|
|
next_address = origin
|
|
|
|
csrs = []
|
|
|
|
for csr_name, address, length, ro in csrs_info:
|
|
|
|
if address != next_address:
|
|
|
|
raise ValueError("CSRs are not contiguous")
|
2017-08-31 13:34:48 +08:00
|
|
|
nr = (length + busword - 1)//busword
|
|
|
|
next_address += nr*busword//8
|
2017-08-27 05:48:11 +08:00
|
|
|
if ro:
|
2017-08-31 13:34:48 +08:00
|
|
|
csr = CSRStatus(length, name=csr_name)
|
2017-08-27 05:48:11 +08:00
|
|
|
else:
|
2017-08-31 13:34:48 +08:00
|
|
|
csr = CSRStorage(length, name=csr_name)
|
2017-08-27 05:48:11 +08:00
|
|
|
csrs.append(csr)
|
2017-08-31 13:34:48 +08:00
|
|
|
regions.append((region_name, offset + origin, busword, csrs))
|
2017-08-27 05:48:11 +08:00
|
|
|
return regions
|