-
Notifications
You must be signed in to change notification settings - Fork 792
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[racl] Parse RACL config and generate top_racl_pkg.sv
Signed-off-by: Robert Schilling <[email protected]>
- Loading branch information
Showing
11 changed files
with
296 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright lowRISC contributors (OpenTitan project). | ||
// Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// ------------------- W A R N I N G: A U T O - G E N E R A T E D C O D E !! -------------------// | ||
// PLEASE DO NOT HAND-EDIT THIS FILE. IT HAS BEEN AUTO-GENERATED WITH THE FOLLOWING COMMAND: | ||
// | ||
// util/topgen.py -t hw/top_darjeeling/data/top_darjeeling.hjson \ | ||
// -o hw/top_darjeeling/ \ | ||
// --rnd_cnst_seed \ | ||
// 1017106219537032642877583828875051302543807092889754935647094601236425074047 | ||
|
||
|
||
package top_racl_pkg; | ||
// Number of RACL policies used | ||
parameter int unsigned NrRaclPolicies = 1; | ||
|
||
// RACL role type binary encoded | ||
typedef logic [3:0] racl_role_t; | ||
|
||
// CTN UID assigned the bus originator | ||
typedef logic [7:0] ctn_uid_t; | ||
|
||
// RACL permission and one-hot encoded role vector | ||
typedef logic [2**$bits(racl_role_t)-1:0] racl_role_vec_t; | ||
|
||
// RACL policy vector containing a read and write permission | ||
typedef struct packed { | ||
racl_role_vec_t read_perm; | ||
racl_role_vec_t write_perm; | ||
} racl_policy_t; | ||
|
||
// RACL policy vector for distributing RACL policies from the RACL widget to the subscribing IP | ||
typedef racl_policy_t [NrRaclPolicies-1:0] racl_policy_vec_t; | ||
|
||
// RACL information logged in case of a denial | ||
typedef struct packed { | ||
racl_role_t racl_role; | ||
ctn_uid_t ctn_uid; | ||
// 0: Write access, 1: Read access | ||
logic write_read; | ||
} racl_error_log_t; | ||
|
||
// Extract RACL role bits from the TLUL reserved user bits | ||
function automatic racl_role_t tlul_extract_racl_role_bits(tlul_pkg::tl_a_user_t tl_req_user); | ||
return racl_role_t'(tl_req_user.rsvd[11:8]); | ||
endfunction | ||
|
||
// Extract CTN UID bits from the TLUL reserved user bits | ||
function automatic ctn_uid_t tlul_extract_ctn_uid_bits(tlul_pkg::tl_a_user_t tl_req_user); | ||
return ctn_uid_t'(tl_req_user.rsvd[7:0]); | ||
endfunction | ||
|
||
|
||
endpackage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
CAPI=2: | ||
# Copyright lowRISC contributors (OpenTitan project). | ||
# Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
name: "lowrisc:systems:top_darjeeling_racl_pkg:0.1" | ||
description: "Autogenerated top_darjeeling_racl_pkg used in RTL and DV." | ||
virtual: | ||
- lowrisc:systems:top_racl_pkg | ||
|
||
filesets: | ||
files_rtl: | ||
depend: | ||
- lowrisc:ip:tlul | ||
files: | ||
- rtl/autogen/top_racl_pkg.sv | ||
file_type: systemVerilogSource | ||
|
||
targets: | ||
default: &default_target | ||
filesets: | ||
- files_rtl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright lowRISC contributors (OpenTitan project). | ||
// Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// ------------------- W A R N I N G: A U T O - G E N E R A T E D C O D E !! -------------------// | ||
// PLEASE DO NOT HAND-EDIT THIS FILE. IT HAS BEEN AUTO-GENERATED WITH THE FOLLOWING COMMAND: | ||
// | ||
// util/topgen.py -t hw/top_earlgrey/data/top_earlgrey.hjson \ | ||
// -o hw/top_earlgrey/ \ | ||
// --rnd_cnst_seed \ | ||
// 1017106219537032642877583828875051302543807092889754935647094601236425074047 | ||
|
||
|
||
package top_racl_pkg; | ||
// Number of RACL policies used | ||
parameter int unsigned NrRaclPolicies = 1; | ||
|
||
// RACL role type binary encoded | ||
typedef logic [3:0] racl_role_t; | ||
|
||
// CTN UID assigned the bus originator | ||
typedef logic [7:0] ctn_uid_t; | ||
|
||
// RACL permission and one-hot encoded role vector | ||
typedef logic [2**$bits(racl_role_t)-1:0] racl_role_vec_t; | ||
|
||
// RACL policy vector containing a read and write permission | ||
typedef struct packed { | ||
racl_role_vec_t read_perm; | ||
racl_role_vec_t write_perm; | ||
} racl_policy_t; | ||
|
||
// RACL policy vector for distributing RACL policies from the RACL widget to the subscribing IP | ||
typedef racl_policy_t [NrRaclPolicies-1:0] racl_policy_vec_t; | ||
|
||
// RACL information logged in case of a denial | ||
typedef struct packed { | ||
racl_role_t racl_role; | ||
ctn_uid_t ctn_uid; | ||
// 0: Write access, 1: Read access | ||
logic write_read; | ||
} racl_error_log_t; | ||
|
||
// Extract RACL role bits from the TLUL reserved user bits | ||
function automatic racl_role_t tlul_extract_racl_role_bits(tlul_pkg::tl_a_user_t tl_req_user); | ||
return racl_role_t'(tl_req_user.rsvd[11:8]); | ||
endfunction | ||
|
||
// Extract CTN UID bits from the TLUL reserved user bits | ||
function automatic ctn_uid_t tlul_extract_ctn_uid_bits(tlul_pkg::tl_a_user_t tl_req_user); | ||
return ctn_uid_t'(tl_req_user.rsvd[7:0]); | ||
endfunction | ||
|
||
|
||
endpackage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
CAPI=2: | ||
# Copyright lowRISC contributors (OpenTitan project). | ||
# Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
name: "lowrisc:systems:top_earlgrey_racl_pkg:0.1" | ||
description: "Autogenerated top_earlgrey_racl_pkg used in RTL and DV." | ||
virtual: | ||
- lowrisc:systems:top_racl_pkg | ||
|
||
filesets: | ||
files_rtl: | ||
depend: | ||
- lowrisc:ip:tlul | ||
files: | ||
- rtl/autogen/top_racl_pkg.sv | ||
file_type: systemVerilogSource | ||
|
||
targets: | ||
default: &default_target | ||
filesets: | ||
- files_rtl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Copyright lowRISC contributors (OpenTitan project). | ||
# Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
# SPDX-License-Identifier: Apache-2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Copyright lowRISC contributors (OpenTitan project). | ||
# Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import hjson | ||
import sys | ||
from reggen.validate import check_keys | ||
|
||
# Required fields for the RACL hjson | ||
racl_required = { | ||
'roles': ['l', 'List, specifying all RACL roles'], | ||
'policies': ['g', 'Dict, specifying the policies of all RACL groups'] | ||
} | ||
|
||
|
||
# Default configuration to render the RACL package for systems that don't use RACL but need the | ||
# type definitions | ||
DEFAULT_RACL_CONFIG = { | ||
'nr_policies': 1, | ||
'policies': {}, | ||
} | ||
|
||
|
||
def parse_racl_config(config_file: str): | ||
try: | ||
with open(config_file, 'r') as f_racl_config: | ||
racl_config = hjson.load(f_racl_config) | ||
except OSError: | ||
raise SystemExit(sys.exc_info()[1]) | ||
|
||
# TODO further error handling | ||
error = check_keys(racl_config, racl_required, [], [], 'RACL Config') | ||
if error: | ||
raise SystemExit(f"Error occured while validating {config_file}") | ||
|
||
# Determine the maximum number of policies over all RACL groups for RTL | ||
# RTL needs to create the vectors based on the largest group | ||
racl_config['nr_policies'] = max(len(policies) for policies in racl_config['policies'].values()) | ||
|
||
for racl_group, policies in racl_config['policies'].items(): | ||
for policy in policies: | ||
def compute_policy_value(permission: str): | ||
permission_value = 0 | ||
for role in policy[permission]: | ||
role_id = racl_config['roles'][role]['role_id'] | ||
permission_value += 2**role_id | ||
return permission_value | ||
|
||
policy['rd_default'] = compute_policy_value('allowed_rd') | ||
policy['wr_default'] = compute_policy_value('allowed_wr') | ||
return racl_config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright lowRISC contributors (OpenTitan project). | ||
// Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
${gencmd} | ||
|
||
package top_racl_pkg; | ||
// Number of RACL policies used | ||
parameter int unsigned NrRaclPolicies = ${racl_config['nr_policies']}; | ||
|
||
// RACL role type binary encoded | ||
typedef logic [3:0] racl_role_t; | ||
|
||
// CTN UID assigned the bus originator | ||
typedef logic [7:0] ctn_uid_t; | ||
|
||
// RACL permission and one-hot encoded role vector | ||
typedef logic [2**$bits(racl_role_t)-1:0] racl_role_vec_t; | ||
|
||
// RACL policy vector containing a read and write permission | ||
typedef struct packed { | ||
racl_role_vec_t read_perm; | ||
racl_role_vec_t write_perm; | ||
} racl_policy_t; | ||
|
||
// RACL policy vector for distributing RACL policies from the RACL widget to the subscribing IP | ||
typedef racl_policy_t [NrRaclPolicies-1:0] racl_policy_vec_t; | ||
|
||
// RACL information logged in case of a denial | ||
typedef struct packed { | ||
racl_role_t racl_role; | ||
ctn_uid_t ctn_uid; | ||
// 0: Write access, 1: Read access | ||
logic write_read; | ||
} racl_error_log_t; | ||
|
||
// Extract RACL role bits from the TLUL reserved user bits | ||
function automatic racl_role_t tlul_extract_racl_role_bits(tlul_pkg::tl_a_user_t tl_req_user); | ||
return racl_role_t'(tl_req_user.rsvd[11:8]); | ||
endfunction | ||
|
||
// Extract CTN UID bits from the TLUL reserved user bits | ||
function automatic ctn_uid_t tlul_extract_ctn_uid_bits(tlul_pkg::tl_a_user_t tl_req_user); | ||
return ctn_uid_t'(tl_req_user.rsvd[7:0]); | ||
endfunction | ||
|
||
% for racl_group, policies in racl_config['policies'].items(): | ||
<% prefix = "" if len(racl_config['policies'].keys()) == 1 else f"{racl_group.upper()}_" %>\ | ||
/** | ||
* Policies for group ${racl_group} | ||
*/ | ||
|
||
% for policy in policies: | ||
/* | ||
* Policy ${policy['name']} allowed READ roles: | ||
* ${', '.join(policy['allowed_wr'])} | ||
*/ | ||
parameter racl_policy_t RACL_POLICY_${prefix}${policy['name'].upper()}_RD_DEFAULT = 16'h${f"{policy['rd_default']:x}"}; | ||
|
||
/** | ||
* Policy ${policy['name']} allowed WRITE roles: | ||
* ${', '.join(policy['allowed_wr'])} | ||
*/ | ||
parameter racl_policy_t RACL_POLICY_${prefix}${policy['name'].upper()}_WR_DEFAULT = 16'h${f"{policy['wr_default']:x}"}; | ||
|
||
% endfor | ||
% endfor | ||
|
||
endpackage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters