Skip to content

Commit

Permalink
[reggen] Add unpacked_dimensions field to parameters
Browse files Browse the repository at this point in the history
This allows you to specify unpackage dimensions which are placed after
the name of the parameter, e.g.

parameter type_t param_name [2][3]

[2][3] would be the unpacked dimensions.

This is required to support the new method of specifying PMP reset
values via paramters for Ibex.

This commit just adds the field to the BaseParam class and allows reggen
to read it, it doesn't use the new field for anything.

Signed-off-by: Greg Chadwick <[email protected]>
  • Loading branch information
GregAC committed Oct 29, 2024
1 parent 8f67267 commit 1236c2d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
2 changes: 1 addition & 1 deletion util/ipgen/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self, name: str, desc: Optional[str], param_type: str,
default: str):
assert param_type in self.VALID_PARAM_TYPES

super().__init__(name, desc, param_type)
super().__init__(name, desc, param_type, None)
self.default = default
self.value = None

Expand Down
3 changes: 2 additions & 1 deletion util/reggen/ip_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ def from_raw(param_defaults: List[Tuple[str, str]],
LocalParam(name='NumAlerts',
desc='Number of alerts',
param_type='int',
value=str(len(alerts))))
value=str(len(alerts)),
unpacked_dimensions=None))

scan = check_bool(rd.get('scan', False), 'scan field of ' + what)

Expand Down
36 changes: 29 additions & 7 deletions util/reggen/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,22 @@
's', "number of bits to randomize in the parameter. 0 by default."
],
'randtype': ['s', "type of randomization to perform. none by default"],
'unpacked_dimensions': [
's', "unpacked dimensions of parameter e.g. [16] for a single unpacked "
"dimension of size 16. none by default"],
}


class BaseParam:
def __init__(self, name: str, desc: Optional[str], param_type: str):
def __init__(self,
name: str,
desc: Optional[str],
param_type: str,
unpacked_dimensions: Optional[str]):
self.name = name
self.desc = desc
self.param_type = param_type
self.unpacked_dimensions = unpacked_dimensions

def apply_default(self, value: str) -> None:
if self.param_type[:3] == 'int':
Expand All @@ -45,6 +53,8 @@ def as_dict(self) -> Dict[str, object]:
if self.desc is not None:
rd['desc'] = self.desc
rd['type'] = self.param_type
if self.unpacked_dimensions is not None:
rd['unpacked_dimensions'] = self.unpacked_dimensions
return rd


Expand All @@ -53,8 +63,9 @@ def __init__(self,
name: str,
desc: Optional[str],
param_type: str,
unpacked_dimensions: Optional[str],
value: str):
super().__init__(name, desc, param_type)
super().__init__(name, desc, param_type, unpacked_dimensions)
self.value = value

def expand_value(self, when: str) -> int:
Expand All @@ -77,9 +88,10 @@ def __init__(self,
name: str,
desc: Optional[str],
param_type: str,
unpacked_dimensions: Optional[str],
default: str,
expose: bool):
super().__init__(name, desc, param_type)
super().__init__(name, desc, param_type, unpacked_dimensions)
self.default = default
self.expose = expose

Expand All @@ -99,7 +111,7 @@ def __init__(self,
randtype: str):
assert randcount > 0
assert randtype in ['perm', 'data']
super().__init__(name, desc, param_type)
super().__init__(name, desc, param_type, None)
self.randcount = randcount
self.randtype = randtype

Expand All @@ -120,7 +132,7 @@ def __init__(self,
name: str,
desc: Optional[str],
param_type: str):
super().__init__(name, desc, param_type)
super().__init__(name, desc, param_type, None)


def _parse_parameter(where: str, raw: object) -> BaseParam:
Expand All @@ -137,6 +149,14 @@ def _parse_parameter(where: str, raw: object) -> BaseParam:
else:
desc = check_str(r_desc, 'desc field of ' + where)

r_unpacked_dimensions = rd.get('unpacked_dimensions')
if r_unpacked_dimensions is None:
unpacked_dimensions = None
else:
unpacked_dimensions = \
check_str(r_unpacked_dimensions,
'unpacked_dimensions field of ' + where)

# TODO: We should probably check that any register called RndCnstFoo has
# randtype and randcount.
if name.lower().startswith('rndcnst') and 'randtype' in rd:
Expand Down Expand Up @@ -261,9 +281,11 @@ def _parse_parameter(where: str, raw: object) -> BaseParam:
raise ValueError('At {}, the localparam {} cannot be exposed to '
'the top-level.'
.format(where, name))
return LocalParam(name, desc, param_type, value=default)
return LocalParam(name, desc, param_type, unpacked_dimensions,
value=default)
else:
return Parameter(name, desc, param_type, default, expose)
return Parameter(name, desc, param_type, unpacked_dimensions,
default, expose)


# Note: With a modern enough Python, we'd like this to derive from
Expand Down

0 comments on commit 1236c2d

Please sign in to comment.