Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RACL] Implement config parsing, racl_ctrl, and reggen checks #25664

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Razer6
Copy link
Member

@Razer6 Razer6 commented Dec 16, 2024

This is the initial PR implementing RACL and consists of three commits:

  1. Parse the RACL configuration file that is passed int the top-level HJSON file and render the top_racl_pkg.sv from it. If no RACL is used in the top, i.e., there is no RACL config passed, a default top_racl_pkg.sv is rendered to provide the minimal type information for all RACL usages in IPs. This package is a virtual core, and different Tops can generate their own version.

  2. Implement the ipgen'ed racl_ctrl policy distributing IP. This IP renders all policies of a given policy group that is defined in the racl.hjson file. Currently, topgen only supports rendering the first RACL group's racl_ctrl IP due to some tooling limitations. Note, racl_ctrl's registers themselves are not yet protected with RACL.

  3. Implement reggen support for RACL checks. On IP.hjson level, you can enable RACL on a per-bus granularity.

@Razer6 Razer6 requested a review from msfschaffner as a code owner December 16, 2024 14:02
@Razer6 Razer6 requested review from andreaskurth, rswarbrick and matutem and removed request for msfschaffner December 16, 2024 14:02
@Razer6 Razer6 force-pushed the racl-package branch 7 times, most recently from d3da1a9 to fecd82b Compare December 16, 2024 16:22
hw/ip/dma/lint/dma.waiver Outdated Show resolved Hide resolved
hw/ip_templates/racl_ctrl/data/racl_ctrl.hjson.tpl Outdated Show resolved Hide resolved
hw/ip_templates/racl_ctrl/data/racl_ctrl.hjson.tpl Outdated Show resolved Hide resolved
hw/ip_templates/racl_ctrl/data/racl_ctrl.hjson.tpl Outdated Show resolved Hide resolved
hw/ip_templates/racl_ctrl/racl_ctrl.core.tpl Outdated Show resolved Hide resolved
hw/ip_templates/racl_ctrl/rtl/racl_ctrl.sv.tpl Outdated Show resolved Hide resolved
util/topgen.py Outdated Show resolved Hide resolved
@Razer6 Razer6 force-pushed the racl-package branch 2 times, most recently from 7d1df47 to dfcda08 Compare December 17, 2024 08:23
@Razer6 Razer6 requested a review from andreaskurth December 17, 2024 08:44
@Razer6
Copy link
Member Author

Razer6 commented Dec 17, 2024

@andreaskurth Thanks for the initial feedback. I changed the docs or created issues for it. Can you take another look?

@Razer6 Razer6 changed the title [RACL] Implement config parsing and racl_ctrl [RACL] Implement config parsing, racl_ctrl, and reggen checks Dec 17, 2024
@Razer6 Razer6 force-pushed the racl-package branch 4 times, most recently from ade3d52 to 465f2af Compare December 17, 2024 15:24
# TODO further error handling
error = check_keys(racl_config, racl_required, [], [], 'RACL Config')
if error:
raise SystemExit(f"Error occured while validating {config_file}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd strongly suggest putting a tiny bit more type checking in here. Something like extracting roles and policies as a list / dictionary, respectively (doing a basic type check) and maybe checking the item and key/value types for them respectively.

Extracting that properly will get rid of the dictionary lookups lower down in the function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hehe, I put a todo above exactly for that ;-)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created #25690 to track this.

util/raclgen/lib.py Outdated Show resolved Hide resolved
def generate_racl(topcfg: Dict[str, object], out_path: Path) -> None:
# Not all tops use RACL
if 'racl_config' not in topcfg:
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it make sense to set topcfg['racl'] to None in this situation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason this was not added is to make it easier to detect if no RACL is used, i.e., down below: completecfg.get('racl', DEFAULT_RACL_CONFIG)

util/topgen.py Outdated Show resolved Hide resolved
util/topgen/templates/toplevel_racl_pkg.sv.tpl Outdated Show resolved Hide resolved
util/topgen/templates/toplevel_racl_pkg.sv.tpl Outdated Show resolved Hide resolved
util/topgen/templates/toplevel_racl_pkg.sv.tpl Outdated Show resolved Hide resolved
hw/ip_templates/racl_ctrl/lint/racl_ctrl.vlt.tpl Outdated Show resolved Hide resolved
hw/ip_templates/racl_ctrl/lint/racl_ctrl.waiver.tpl Outdated Show resolved Hide resolved
util/topgen.py Outdated Show resolved Hide resolved
util/reggen/bus_interfaces.py Show resolved Hide resolved
@@ -115,7 +117,13 @@
%>
`include "prim_assert.sv"

module ${mod_name} (
module ${mod_name}${' (' if not racl_support else ''}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid the isolated # stuff, maybe it makes sense to use something like ${' # (' if racl_support else ' ('} ?

Copy link
Member Author

@Razer6 Razer6 Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only reason for that was to keep the diff 0 when not enabling RACL on one IP. Otherwise we would generate a small whitespace diff for all regtops.

util/reggen/reg_top.sv.tpl Show resolved Hide resolved
util/reggen/reg_top.sv.tpl Outdated Show resolved Hide resolved
}


def parse_racl_config(config_path: str):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coud you add a return type, probably ...str) -> Dict[str, object]: or some more specific type for the value in the Dict?

except OSError:
raise SystemExit(sys.exc_info()[1])

# TODO further error handling
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some hint about the missing checks?


for racl_group, policies in racl_config['policies'].items():
for policy in policies:
def compute_policy_value(permission: str):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the return value type delaration could be ... str) -> int:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants