Skip to content

Commit 4072557

Browse files
committed
refactor(policy): centralize shared execution policy state
Move shared execution-policy knobs out of scattered globals into a dedicated acs_execution_policy_t with explicit reset and accessor APIs. This keeps execution policy separate from run-request selection state, routes defaults and overrides through one place, and removes direct global and header coupling across VAL, PAL, baremetal, and UEFI paths. - add acs_execution_policy.[ch] as the canonical shared policy object for print, PCIe, timeout, crypto, SLC, and EL1 trap settings - replace direct policy g_* globals across VAL, PAL, test pool, baremetal, and UEFI code with policy fields or acs_policy_get_*() accessors - update baremetal and UEFI entry paths to reset, populate, and consume execution policy explicitly - split generic policy reset defaults from baremetal target overrides, and expose target defaults through acs_get_platform_execution_policy_defaults() - update compile-time and EL3 override helpers to write execution policy separately from run-request filtering state - remove duplicated policy declarations from PAL and UEFI headers and keep the shared policy API in one canonical header - wire acs_execution_policy.c into the relevant VAL build files for baremetal and UEFI flows - keep headers self-contained with shared fixed-width types and drop local scalar typedef wrappers that no longer add value - retain documentation for sys_last_lvl_cache values and el1skiptrap_mask usage in the canonical policy definition Change-Id: I1e320c46aaab9a6479b189d433a0a3d8f7a62258
1 parent d8fcbbb commit 4072557

96 files changed

Lines changed: 833 additions & 552 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apps/baremetal/acs.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,9 @@ extern uint32_t g_num_modules;
9898
extern uint32_t g_skip_modules_arr[];
9999
extern uint32_t g_num_skip_modules;
100100
extern uint32_t g_level_filter_mode;
101-
extern uint32_t g_sys_last_lvl_cache;
102-
extern uint32_t g_timeout_pass;
103-
extern uint32_t g_timeout_fail;
104101

105-
/* Globals from apps/baremetal/acs_globals.c */
106-
extern uint32_t g_pcie_cache_present;
102+
/* Remaining baremetal execution globals from apps/baremetal/acs_globals.c */
107103
extern uint32_t g_el1physkip;
108-
extern uint32_t g_pcie_p2p;
109-
extern uint32_t g_crypto_support;
110-
extern uint32_t g_print_level;
111-
extern uint32_t g_print_mmio;
112104
extern uint32_t g_curr_module;
113105
extern uint32_t g_enable_module;
114106
extern uint32_t g_acs_tests_total;
@@ -117,7 +109,6 @@ extern uint32_t g_acs_tests_fail;
117109
extern uint64_t g_stack_pointer;
118110
extern uint64_t g_exception_ret_addr;
119111
extern uint64_t g_ret_addr;
120-
extern bool g_pcie_skip_dp_nic_ms;
121112
extern uint32_t g_build_sbsa;
122113
extern uint32_t g_build_pcbsa;
123114
extern uint32_t g_its_init;

apps/baremetal/acs_common.c

Lines changed: 73 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "acs.h"
1919
#include <stdint.h>
2020
#include <stdbool.h>
21+
#include "pal/baremetal/base/include/pal_execution_policy.h"
2122
#include "val/include/val_interface.h"
2223
#include "val/include/acs_el3_param.h"
2324
#include "val/include/rule_based_execution_enum.h"
@@ -62,6 +63,57 @@ acs_list_contains(const uint32_t *list, uint32_t count, uint32_t value)
6263
return false;
6364
}
6465

66+
void
67+
acs_load_execution_policy_defaults(acs_execution_policy_t *policy)
68+
{
69+
const acs_execution_policy_t *defaults;
70+
const acs_execution_policy_t *platform_defaults;
71+
72+
if (policy == NULL)
73+
return;
74+
75+
acs_reset_execution_policy();
76+
defaults = acs_get_execution_policy();
77+
/*
78+
* Baremetal entry paths currently pass the shared execution-policy singleton,
79+
* so acs_reset_execution_policy() has already seeded `policy` with the base
80+
* defaults. Keep support for detached policy objects without needlessly
81+
* self-assigning the singleton fields here.
82+
*/
83+
if (policy != defaults) {
84+
policy->pcie_p2p = defaults->pcie_p2p;
85+
policy->pcie_cache_present = defaults->pcie_cache_present;
86+
policy->pcie_skip_dp_nic_ms = defaults->pcie_skip_dp_nic_ms;
87+
policy->print_level = defaults->print_level;
88+
policy->print_mmio = defaults->print_mmio;
89+
policy->timeout_pass = defaults->timeout_pass;
90+
policy->timeout_fail = defaults->timeout_fail;
91+
policy->timer_timeout_us = defaults->timer_timeout_us;
92+
policy->crypto_support = defaults->crypto_support;
93+
policy->sys_last_lvl_cache = defaults->sys_last_lvl_cache;
94+
policy->el1skiptrap_mask = defaults->el1skiptrap_mask;
95+
}
96+
97+
platform_defaults = acs_get_platform_execution_policy_defaults();
98+
if (platform_defaults == NULL)
99+
return;
100+
101+
/* Overlay baremetal platform-specific defaults on top of the generic reset defaults. */
102+
policy->pcie_p2p = platform_defaults->pcie_p2p;
103+
policy->pcie_cache_present = platform_defaults->pcie_cache_present;
104+
policy->pcie_skip_dp_nic_ms = platform_defaults->pcie_skip_dp_nic_ms;
105+
policy->crypto_support = platform_defaults->crypto_support;
106+
policy->sys_last_lvl_cache = platform_defaults->sys_last_lvl_cache;
107+
policy->el1skiptrap_mask = platform_defaults->el1skiptrap_mask;
108+
109+
if (platform_defaults->timeout_pass != 0u)
110+
policy->timeout_pass = platform_defaults->timeout_pass;
111+
if (platform_defaults->timeout_fail != 0u)
112+
policy->timeout_fail = platform_defaults->timeout_fail;
113+
if (platform_defaults->timer_timeout_us != 0u)
114+
policy->timer_timeout_us = platform_defaults->timer_timeout_us;
115+
}
116+
65117
void
66118
acs_load_run_request_defaults(acs_run_request_t *ctx)
67119
{
@@ -104,11 +156,11 @@ acs_load_run_request_defaults(acs_run_request_t *ctx)
104156
}
105157

106158
void
107-
acs_apply_el3_params(acs_run_request_t *ctx)
159+
acs_apply_el3_params(acs_run_request_t *ctx, acs_execution_policy_t *policy)
108160
{
109161
acs_el3_params *params;
110162

111-
if (ctx == NULL)
163+
if (ctx == NULL || policy == NULL)
112164
return;
113165

114166
/* If magic doesn't match, ignore X20 completely */
@@ -168,14 +220,14 @@ acs_apply_el3_params(acs_run_request_t *ctx)
168220
}
169221

170222
/* Override shared runtime knobs and context filter settings from EL3 parameters. */
171-
g_pcie_p2p = params->p2p;
172-
g_pcie_skip_dp_nic_ms = params->skip_dp_nic_ms;
173-
g_print_mmio = params->mmio;
174-
g_crypto_support = params->no_crypto_ext;
175-
g_el1skiptrap_mask = params->el1skiptrap_mask;
223+
policy->pcie_p2p = params->p2p;
224+
policy->pcie_skip_dp_nic_ms = params->skip_dp_nic_ms;
225+
policy->print_mmio = params->mmio;
226+
policy->crypto_support = params->no_crypto_ext ? 0u : 1u;
227+
policy->el1skiptrap_mask = params->el1skiptrap_mask;
176228
ctx->bsa_sw_view_mask = params->software_view_filter;
177-
g_pcie_cache_present = params->cache;
178-
g_sys_last_lvl_cache = params->sys_cache;
229+
policy->pcie_cache_present = params->cache;
230+
policy->sys_last_lvl_cache = params->sys_cache;
179231
ctx->level_value = params->level;
180232

181233
if (params->level_selection >= LVL_FILTER_NONE &&
@@ -186,17 +238,18 @@ acs_apply_el3_params(acs_run_request_t *ctx)
186238
"Override skipped for level filter mode %d\n", params->level_selection);
187239

188240
if (params->verbose >= TRACE && params->verbose <= FATAL)
189-
g_print_level = params->verbose;
241+
policy->print_level = params->verbose;
190242
else
191243
val_print(WARN,
192244
"Override skipped for verbose %d\n", params->verbose);
193245

194246
if (params->timeout >= TIMEOUT_THRESHOLD
195247
&& params->timeout <= TIMEOUT_MAX_THRESHOLD)
196248
{
197-
g_timeout_pass = params->timeout;
198-
g_timer_timeout_us = params->timeout;
199-
g_timeout_fail = g_timeout_pass * WAKEUP_WD_FAILSAFE_TIMEOUT_MULTIPLIER;
249+
policy->timeout_pass = params->timeout;
250+
policy->timer_timeout_us = params->timeout;
251+
policy->timeout_fail =
252+
policy->timeout_pass * WAKEUP_WD_FAILSAFE_TIMEOUT_MULTIPLIER;
200253
}
201254
else
202255
val_print(WARN,
@@ -205,9 +258,9 @@ acs_apply_el3_params(acs_run_request_t *ctx)
205258
}
206259

207260
void
208-
acs_apply_compile_params(acs_run_request_t *ctx)
261+
acs_apply_compile_params(acs_run_request_t *ctx, acs_execution_policy_t *policy)
209262
{
210-
if (ctx == NULL)
263+
if (ctx == NULL || policy == NULL)
211264
return;
212265

213266
#if ACS_HAS_ENABLED_MODULE_LIST
@@ -220,12 +273,12 @@ acs_apply_compile_params(acs_run_request_t *ctx)
220273
/*
221274
* Allow compile-time override of the default print verbosity.
222275
*/
223-
g_print_level = ACS_VERBOSE_LEVEL;
276+
policy->print_level = ACS_VERBOSE_LEVEL;
224277

225-
if (g_print_level < TRACE)
226-
g_print_level = TRACE;
227-
else if (g_print_level > FATAL)
228-
g_print_level = FATAL;
278+
if (policy->print_level < TRACE)
279+
policy->print_level = TRACE;
280+
else if (policy->print_level > FATAL)
281+
policy->print_level = FATAL;
229282
#endif
230283

231284
return;

apps/baremetal/acs_globals.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
#include "acs.h"
2222

2323
/* Global Variables */
24-
bool g_pcie_skip_dp_nic_ms = 0;
25-
uint32_t g_pcie_p2p;
26-
uint32_t g_print_level;
27-
uint32_t g_print_mmio;
2824
uint32_t g_curr_module;
2925
uint32_t g_enable_module;
3026
uint32_t g_acs_tests_total;
@@ -33,7 +29,6 @@ uint32_t g_acs_tests_fail;
3329
uint32_t g_build_sbsa = 0;
3430
uint32_t g_build_pcbsa = 0;
3531
uint32_t g_its_init = 0;
36-
uint32_t g_pcie_cache_present;
3732
uint64_t g_stack_pointer;
3833
uint64_t g_exception_ret_addr;
3934
uint64_t g_ret_addr;

apps/baremetal/bsa_main.c

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,21 @@ freeAcsMeM(void)
6565

6666
/* This routine will furnish global variables with user defined config and set any
6767
default values for the ACS */
68-
uint32_t apply_user_config_and_defaults(acs_run_request_t *ctx)
68+
uint32_t apply_user_config_and_defaults(acs_run_request_t *ctx, acs_execution_policy_t *policy)
6969
{
70-
if (ctx == NULL)
70+
if (ctx == NULL || policy == NULL)
7171
return ACS_STATUS_FAIL;
7272

7373
acs_load_run_request_defaults(ctx);
74+
acs_load_execution_policy_defaults(policy);
7475

7576
/* Set user defined compliance level to be run for
7677
as defined pal/baremetal/target/../include/platform_override_fvp.h */
7778
ctx->level_value = PLATFORM_OVERRIDE_BSA_LEVEL;
78-
g_print_level = PLATFORM_OVERRIDE_PRINT_LEVEL;
79+
policy->print_level = PLATFORM_OVERRIDE_PRINT_LEVEL;
7980

80-
/* Set default values for g_print_mmio */
81-
g_print_mmio = 0;
81+
/* Disable MMIO trace prints by default for standalone baremetal runs. */
82+
policy->print_mmio = 0;
8283
/* If selected rule count is zero, default to BSA */
8384
if (ctx->rule_count == 0) {
8485
/* Standalone BSA Baremetal app, default the run request to BSA */
@@ -87,24 +88,24 @@ uint32_t apply_user_config_and_defaults(acs_run_request_t *ctx)
8788

8889
/* Check sanity of value of level if not valid default to extremes */
8990
if (ctx->level_value < BSA_LEVEL_1) {
90-
val_print(g_print_level, "\nBSA Level %d is not supported.\n", ctx->level_value);
91-
val_print(g_print_level, "\nSetting BSA level to %d\n", BSA_LEVEL_1);
91+
val_print(policy->print_level, "\nBSA Level %d is not supported.\n", ctx->level_value);
92+
val_print(policy->print_level, "\nSetting BSA level to %d\n", BSA_LEVEL_1);
9293
ctx->level_value = BSA_LEVEL_1;
9394
} else if (ctx->level_value >= BSA_LEVEL_SENTINEL) {
94-
val_print(g_print_level, "\nBSA Level %d is not supported.\n", ctx->level_value);
95-
val_print(g_print_level, "\nSetting BSA level FR", BSA_LEVEL_FR);
95+
val_print(policy->print_level, "\nBSA Level %d is not supported.\n", ctx->level_value);
96+
val_print(policy->print_level, "\nSetting BSA level FR", BSA_LEVEL_FR);
9697
ctx->level_value = BSA_LEVEL_FR;
9798
}
9899

99100
/* Check sanity of print level, default accordingly */
100-
if (g_print_level < TRACE) {
101-
val_print(ERROR, "\nPrint Level %d is not supported.\n", g_print_level);
101+
if (policy->print_level < TRACE) {
102+
val_print(ERROR, "\nPrint Level %d is not supported.\n", policy->print_level);
102103
val_print(ERROR, "\nSetting Print level to %d\n", TRACE);
103-
g_print_level = TRACE;
104-
} else if (g_print_level > ERROR) {
105-
val_print(ERROR, "\nPrint Level %d is not supported.\n", g_print_level);
104+
policy->print_level = TRACE;
105+
} else if (policy->print_level > ERROR) {
106+
val_print(ERROR, "\nPrint Level %d is not supported.\n", policy->print_level);
106107
val_print(ERROR, "\nSetting Print level to %d\n", ERROR);
107-
g_print_level = ERROR;
108+
policy->print_level = ERROR;
108109
}
109110

110111
return ACS_STATUS_PASS;
@@ -126,20 +127,22 @@ ShellAppMainbsa()
126127
uint32_t Status;
127128
void *branch_label;
128129
acs_run_request_t *ctx;
130+
acs_execution_policy_t *policy;
129131

130132
acs_reset_run_request();
131133
ctx = acs_get_run_request_mut();
134+
policy = acs_get_execution_policy_mut();
132135

133-
Status = apply_user_config_and_defaults(ctx);
136+
Status = apply_user_config_and_defaults(ctx, policy);
134137
if (Status != ACS_STATUS_PASS) {
135138
val_print(ERROR, "\napply_user_config_and_defaults() failed, Exiting...\n");
136139
goto exit_acs;
137140
}
138141

139142
/* Apply any compile-time rule/module overrides before we consume the run request. */
140-
acs_apply_compile_params(ctx);
143+
acs_apply_compile_params(ctx, policy);
141144
/* Apply any EL3-supplied selection overrides before we consume the run request. */
142-
acs_apply_el3_params(ctx);
145+
acs_apply_el3_params(ctx, policy);
143146

144147
val_print(INFO, "\n\n BSA Architecture Compliance Suite\n");
145148
val_print(INFO, "\n Version %d.", BSA_ACS_MAJOR_VER);
@@ -149,7 +152,7 @@ ShellAppMainbsa()
149152
val_print(INFO, LEVEL_PRINT_FORMAT(ctx->level_value, ctx->level_filter_mode,
150153
BSA_LEVEL_FR), ctx->level_value);
151154

152-
val_print(INFO, "(Print level is %2d)\n\n", g_print_level);
155+
val_print(INFO, "(Print level is %2d)\n\n", policy->print_level);
153156

154157
#if ACS_ENABLE_MMU
155158
val_print(INFO, " Enabling MMU\n");

apps/baremetal/pc_bsa_main.c

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,21 @@ freeAcsMem(void)
7575
/* This routine will furnish global variables with user defined config and set any
7676
default values for the ACS */
7777
static uint32_t
78-
apply_user_config_and_defaults(acs_run_request_t *ctx)
78+
apply_user_config_and_defaults(acs_run_request_t *ctx, acs_execution_policy_t *policy)
7979
{
80-
if (ctx == NULL)
80+
if (ctx == NULL || policy == NULL)
8181
return ACS_STATUS_FAIL;
8282

8383
acs_load_run_request_defaults(ctx);
84+
acs_load_execution_policy_defaults(policy);
8485

8586
/* Set user defined compliance level to be run for
8687
as defined pal/baremetal/target/../include/platform_override_fvp.h */
8788
ctx->level_value = PLATFORM_OVERRIDE_PCBSA_LEVEL;
88-
g_print_level = PLATFORM_OVERRIDE_PRINT_LEVEL;
89+
policy->print_level = PLATFORM_OVERRIDE_PRINT_LEVEL;
8990

90-
/* Set default values for g_print_mmio */
91-
g_print_mmio = 0;
91+
/* Disable MMIO trace prints by default for standalone baremetal runs. */
92+
policy->print_mmio = 0;
9293

9394
/* If selected rule count is zero, default to PCBSA */
9495
if (ctx->rule_count == 0) {
@@ -98,24 +99,24 @@ apply_user_config_and_defaults(acs_run_request_t *ctx)
9899

99100
/* Check sanity of value of level if not valid default to extremes */
100101
if (ctx->level_value < PCBSA_LEVEL_1) {
101-
val_print(g_print_level, "\nPCBSA Level %d is not supported.\n", ctx->level_value);
102-
val_print(g_print_level, "\nSetting PCBSA level to %d\n", PCBSA_LEVEL_1);
102+
val_print(policy->print_level, "\nPCBSA Level %d is not supported.\n", ctx->level_value);
103+
val_print(policy->print_level, "\nSetting PCBSA level to %d\n", PCBSA_LEVEL_1);
103104
ctx->level_value = PCBSA_LEVEL_1;
104105
} else if (ctx->level_value >= PCBSA_LEVEL_SENTINEL) {
105-
val_print(g_print_level, "\nPCBSA Level %d is not supported.\n", ctx->level_value);
106-
val_print(g_print_level, "\nSetting PCBSA level to %d\n", PCBSA_LEVEL_1);
106+
val_print(policy->print_level, "\nPCBSA Level %d is not supported.\n", ctx->level_value);
107+
val_print(policy->print_level, "\nSetting PCBSA level to %d\n", PCBSA_LEVEL_1);
107108
ctx->level_value = PCBSA_LEVEL_1;
108109
}
109110

110111
/* Check sanity of print level, default accordingly */
111-
if (g_print_level < TRACE) {
112-
val_print(ERROR, "\nPrint Level %d is not supported.\n", g_print_level);
112+
if (policy->print_level < TRACE) {
113+
val_print(ERROR, "\nPrint Level %d is not supported.\n", policy->print_level);
113114
val_print(ERROR, "\nSetting Print level to %d\n", TRACE);
114-
g_print_level = TRACE;
115-
} else if (g_print_level > ERROR) {
116-
val_print(ERROR, "\nPrint Level %d is not supported.\n", g_print_level);
115+
policy->print_level = TRACE;
116+
} else if (policy->print_level > ERROR) {
117+
val_print(ERROR, "\nPrint Level %d is not supported.\n", policy->print_level);
117118
val_print(ERROR, "\nSetting Print level to %d\n", ERROR);
118-
g_print_level = ERROR;
119+
policy->print_level = ERROR;
119120
}
120121

121122
return ACS_STATUS_PASS;
@@ -135,20 +136,22 @@ ShellAppMainpcbsa(void)
135136
uint32_t Status;
136137
void *branch_label;
137138
acs_run_request_t *ctx;
139+
acs_execution_policy_t *policy;
138140

139141
acs_reset_run_request();
140142
ctx = acs_get_run_request_mut();
143+
policy = acs_get_execution_policy_mut();
141144

142-
Status = apply_user_config_and_defaults(ctx);
145+
Status = apply_user_config_and_defaults(ctx, policy);
143146
if (Status != ACS_STATUS_PASS) {
144147
val_print(ERROR, "\napply_user_config_and_defaults() failed, Exiting...\n");
145148
goto exit_acs;
146149
}
147150

148151
/* Apply any compile-time test/module overrides before we consume the run request. */
149-
acs_apply_compile_params(ctx);
152+
acs_apply_compile_params(ctx, policy);
150153
/* Apply any EL3-supplied selection overrides before we consume the run request. */
151-
acs_apply_el3_params(ctx);
154+
acs_apply_el3_params(ctx, policy);
152155

153156
#if ACS_ENABLE_MMU
154157
val_print(INFO, " Enabling MMU\n");
@@ -176,7 +179,7 @@ ShellAppMainpcbsa(void)
176179
val_print(INFO, LEVEL_PRINT_FORMAT(ctx->level_value, ctx->level_filter_mode,
177180
PCBSA_LEVEL_FR), ctx->level_value);
178181

179-
val_print(INFO, "(Print level is %2d)\n\n", g_print_level);
182+
val_print(INFO, "(Print level is %2d)\n\n", policy->print_level);
180183

181184
val_print(INFO, " Creating Platform Information Tables\n");
182185

0 commit comments

Comments
 (0)