Skip to content

Commit

Permalink
[racl] Define RACL and CTN UID bits from HJSON
Browse files Browse the repository at this point in the history
Signed-off-by: Robert Schilling <[email protected]>
  • Loading branch information
Razer6 committed Jan 23, 2025
1 parent c047598 commit 14ac869
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 31 deletions.
12 changes: 6 additions & 6 deletions hw/top_darjeeling/rtl/autogen/top_racl_pkg.sv
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ package top_racl_pkg;
parameter int unsigned NrRaclPolicies = 1;

// Number of RACL bits transferred
parameter int unsigned NrRaclBits = 4;
parameter int unsigned NrRaclBits = 1;

// Number of CTN UID bits transferred
parameter int unsigned NrCtnUidBits = 8;
parameter int unsigned NrCtnUidBits = 1;

// RACL role type binary encoded
typedef logic [NrRaclBits-1:0] racl_role_t;
Expand All @@ -43,10 +43,10 @@ package top_racl_pkg;
parameter racl_policy_vec_t RACL_POLICY_VEC_DEFAULT = '0;

// Default ROT Private read policy value
parameter racl_role_vec_t RACL_POLICY_ROT_PRIVATE_RD = 16'h0;
parameter racl_role_vec_t RACL_POLICY_ROT_PRIVATE_RD = 2'h0;

// Default ROT Private write policy value
parameter racl_role_vec_t RACL_POLICY_ROT_PRIVATE_WR = 16'h0;
parameter racl_role_vec_t RACL_POLICY_ROT_PRIVATE_WR = 2'h0;

// RACL information logged in case of a denial
typedef struct packed {
Expand All @@ -62,7 +62,7 @@ package top_racl_pkg;
logic unused_rsvd_bits;
unused_rsvd_bits = ^{rsvd};

return racl_role_t'(rsvd[11:8]);
return racl_role_t'(rsvd[0:0]);
endfunction

// Extract CTN UID bits from the TLUL reserved user bits
Expand All @@ -71,7 +71,7 @@ package top_racl_pkg;
logic unused_rsvd_bits;
unused_rsvd_bits = ^{rsvd};

return ctn_uid_t'(rsvd[7:0]);
return ctn_uid_t'(rsvd[0:0]);
endfunction


Expand Down
12 changes: 6 additions & 6 deletions hw/top_earlgrey/rtl/autogen/top_racl_pkg.sv
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ package top_racl_pkg;
parameter int unsigned NrRaclPolicies = 1;

// Number of RACL bits transferred
parameter int unsigned NrRaclBits = 4;
parameter int unsigned NrRaclBits = 1;

// Number of CTN UID bits transferred
parameter int unsigned NrCtnUidBits = 8;
parameter int unsigned NrCtnUidBits = 1;

// RACL role type binary encoded
typedef logic [NrRaclBits-1:0] racl_role_t;
Expand All @@ -43,10 +43,10 @@ package top_racl_pkg;
parameter racl_policy_vec_t RACL_POLICY_VEC_DEFAULT = '0;

// Default ROT Private read policy value
parameter racl_role_vec_t RACL_POLICY_ROT_PRIVATE_RD = 16'h0;
parameter racl_role_vec_t RACL_POLICY_ROT_PRIVATE_RD = 2'h0;

// Default ROT Private write policy value
parameter racl_role_vec_t RACL_POLICY_ROT_PRIVATE_WR = 16'h0;
parameter racl_role_vec_t RACL_POLICY_ROT_PRIVATE_WR = 2'h0;

// RACL information logged in case of a denial
typedef struct packed {
Expand All @@ -62,7 +62,7 @@ package top_racl_pkg;
logic unused_rsvd_bits;
unused_rsvd_bits = ^{rsvd};

return racl_role_t'(rsvd[11:8]);
return racl_role_t'(rsvd[0:0]);
endfunction

// Extract CTN UID bits from the TLUL reserved user bits
Expand All @@ -71,7 +71,7 @@ package top_racl_pkg;
logic unused_rsvd_bits;
unused_rsvd_bits = ^{rsvd};

return ctn_uid_t'(rsvd[7:0]);
return ctn_uid_t'(rsvd[0:0]);
endfunction


Expand Down
12 changes: 6 additions & 6 deletions hw/top_englishbreakfast/rtl/autogen/top_racl_pkg.sv
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ package top_racl_pkg;
parameter int unsigned NrRaclPolicies = 1;

// Number of RACL bits transferred
parameter int unsigned NrRaclBits = 4;
parameter int unsigned NrRaclBits = 1;

// Number of CTN UID bits transferred
parameter int unsigned NrCtnUidBits = 8;
parameter int unsigned NrCtnUidBits = 1;

// RACL role type binary encoded
typedef logic [NrRaclBits-1:0] racl_role_t;
Expand All @@ -43,10 +43,10 @@ package top_racl_pkg;
parameter racl_policy_vec_t RACL_POLICY_VEC_DEFAULT = '0;

// Default ROT Private read policy value
parameter racl_role_vec_t RACL_POLICY_ROT_PRIVATE_RD = 16'h0;
parameter racl_role_vec_t RACL_POLICY_ROT_PRIVATE_RD = 2'h0;

// Default ROT Private write policy value
parameter racl_role_vec_t RACL_POLICY_ROT_PRIVATE_WR = 16'h0;
parameter racl_role_vec_t RACL_POLICY_ROT_PRIVATE_WR = 2'h0;

// RACL information logged in case of a denial
typedef struct packed {
Expand All @@ -62,7 +62,7 @@ package top_racl_pkg;
logic unused_rsvd_bits;
unused_rsvd_bits = ^{rsvd};

return racl_role_t'(rsvd[11:8]);
return racl_role_t'(rsvd[0:0]);
endfunction

// Extract CTN UID bits from the TLUL reserved user bits
Expand All @@ -71,7 +71,7 @@ package top_racl_pkg;
logic unused_rsvd_bits;
unused_rsvd_bits = ^{rsvd};

return ctn_uid_t'(rsvd[7:0]);
return ctn_uid_t'(rsvd[0:0]);
endfunction


Expand Down
19 changes: 19 additions & 0 deletions util/raclgen/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,23 @@
'pb',
'When true, return TLUL error on denied RACL access, otherwise not'
],
'role_bit_lsb': ['d', 'RACL role bit LSB within the TLUL user bit vector'],
'role_bit_msb': ['d', 'RACL role bit MSB within the TLUL user bit vector'],
'ctn_uid_bit_lsb': ['d', 'CTN UID bit LSB within the TLUL user bit vector'],
'ctn_uid_bit_msb': ['d', 'CTN UID bit MSB within the TLUL user bit vector'],
'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 = {
'role_bit_lsb': 0,
'role_bit_msb': 0,
'ctn_uid_bit_lsb': 0,
'ctn_uid_bit_msb': 0,
'nr_role_bits': 1,
'nr_ctn_uid_bits': 1,
'nr_policies': 1,
'policies': {},
'rot_private_policy_rd': 0,
Expand All @@ -49,6 +59,15 @@ def parse_racl_config(config_path: str) -> Dict[str, object]:
if error:
raise SystemExit(f"Error occurred while validating {config_path}")

if racl_config['role_bit_lsb'] > racl_config['role_bit_msb']:
raise ValueError('Invalid RACL role bit configuration LSB > MSB')
if racl_config['ctn_uid_bit_lsb'] > racl_config['ctn_uid_bit_msb']:
raise ValueError('Invalid RACL CTN UID bit configuration LSB > MSB')

racl_config['nr_role_bits'] = racl_config['role_bit_msb'] - racl_config['role_bit_lsb'] + 1
racl_config['nr_ctn_uid_bits'] = racl_config['ctn_uid_bit_msb'] - \
racl_config['ctn_uid_bit_lsb'] + 1

# 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(
Expand Down
10 changes: 5 additions & 5 deletions util/topgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,11 +614,11 @@ def generate_racl(topcfg: Dict[str, object], name_to_block: Dict[str, IpBlock],
policies = topcfg['racl']['policies'][racl_group]

params = {
"module_instance_name": racl_ctrl["type"],
"nr_role_bits": 4,
"nr_ctn_uid_bits": 5,
"nr_policies": len(policies),
"policies": policies
'module_instance_name': racl_ctrl['type'],
'nr_role_bits': topcfg['racl']['nr_role_bits'],
'nr_ctn_uid_bits': topcfg['racl']['nr_ctn_uid_bits'],
'nr_policies': len(policies),
'policies': policies
}

ipgen_render("racl_ctrl", topname, params, out_path)
Expand Down
17 changes: 9 additions & 8 deletions util/topgen/templates/toplevel_racl_pkg.sv.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
${gencmd}
<% racl_role_vec_len = 2 ** racl_config['nr_role_bits'] %>\

package top_racl_pkg;
// Number of RACL policies used
parameter int unsigned NrRaclPolicies = ${racl_config['nr_policies']};

// Number of RACL bits transferred
parameter int unsigned NrRaclBits = 4;
parameter int unsigned NrRaclBits = ${racl_config['nr_role_bits']};

// Number of CTN UID bits transferred
parameter int unsigned NrCtnUidBits = 8;
parameter int unsigned NrCtnUidBits = ${racl_config['nr_ctn_uid_bits']};

// RACL role type binary encoded
typedef logic [NrRaclBits-1:0] racl_role_t;
Expand All @@ -35,10 +36,10 @@ package top_racl_pkg;
parameter racl_policy_vec_t RACL_POLICY_VEC_DEFAULT = '0;

// Default ROT Private read policy value
parameter racl_role_vec_t RACL_POLICY_ROT_PRIVATE_RD = 16'h${f"{racl_config['rot_private_policy_rd']:x}"};
parameter racl_role_vec_t RACL_POLICY_ROT_PRIVATE_RD = ${racl_role_vec_len}'h${f"{racl_config['rot_private_policy_rd']:x}"};

// Default ROT Private write policy value
parameter racl_role_vec_t RACL_POLICY_ROT_PRIVATE_WR = 16'h${f"{racl_config['rot_private_policy_wr']:x}"};
parameter racl_role_vec_t RACL_POLICY_ROT_PRIVATE_WR = ${racl_role_vec_len}'h${f"{racl_config['rot_private_policy_wr']:x}"};

// RACL information logged in case of a denial
typedef struct packed {
Expand All @@ -54,7 +55,7 @@ package top_racl_pkg;
logic unused_rsvd_bits;
unused_rsvd_bits = ^{rsvd};

return racl_role_t'(rsvd[11:8]);
return racl_role_t'(rsvd[${racl_config['role_bit_msb']}:${racl_config['role_bit_lsb']}]);
endfunction

// Extract CTN UID bits from the TLUL reserved user bits
Expand All @@ -63,7 +64,7 @@ package top_racl_pkg;
logic unused_rsvd_bits;
unused_rsvd_bits = ^{rsvd};

return ctn_uid_t'(rsvd[7:0]);
return ctn_uid_t'(rsvd[${racl_config['ctn_uid_bit_msb']}:${racl_config['ctn_uid_bit_lsb']}]);
endfunction

% for racl_group, policies in racl_config['policies'].items():
Expand All @@ -77,13 +78,13 @@ package top_racl_pkg;
* Policy ${policy['name']} allowed READ roles:
* ${', '.join(policy['allowed_wr'])}
*/
parameter racl_role_vec_t RACL_POLICY_${prefix}${policy['name'].upper()}_RD_DEFAULT = 16'h${f"{policy['rd_default']:x}"};
parameter racl_role_vec_t RACL_POLICY_${prefix}${policy['name'].upper()}_RD_DEFAULT = ${racl_role_vec_len}'h${f"{policy['rd_default']:x}"};

/**
* Policy ${policy['name']} allowed WRITE roles:
* ${', '.join(policy['allowed_wr'])}
*/
parameter racl_role_vec_t RACL_POLICY_${prefix}${policy['name'].upper()}_WR_DEFAULT = 16'h${f"{policy['wr_default']:x}"};
parameter racl_role_vec_t RACL_POLICY_${prefix}${policy['name'].upper()}_WR_DEFAULT = ${racl_role_vec_len}'h${f"{policy['wr_default']:x}"};

% endfor
% endfor
Expand Down

0 comments on commit 14ac869

Please sign in to comment.