This patch adds a generic function for lock tests for all the sbi fwft features. It expects the feature is already locked before being called and tests the locked feature. Signed-off-by: Akshay Behl <akshaybehl231@xxxxxxxxx> --- riscv/sbi-fwft.c | 48 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/riscv/sbi-fwft.c b/riscv/sbi-fwft.c index 581cbf6b..5c0a7f6f 100644 --- a/riscv/sbi-fwft.c +++ b/riscv/sbi-fwft.c @@ -74,6 +74,33 @@ static void fwft_check_reset(uint32_t feature, unsigned long reset) sbiret_report(&ret, SBI_SUCCESS, reset, "resets to %lu", reset); } +/* Must be called after locking the feature using SBI_FWFT_SET_FLAG_LOCK */ +static void fwft_feature_lock_test(int32_t feature, unsigned long locked_value) +{ + struct sbiret ret; + unsigned long alt_value = locked_value ? 0 : 1; + + ret = fwft_set(feature, locked_value, 0); + sbiret_report_error(&ret, SBI_ERR_DENIED_LOCKED, + "Set locked feature to %lu without lock", locked_value); + + ret = fwft_set(feature, locked_value, SBI_FWFT_SET_FLAG_LOCK); + sbiret_report_error(&ret, SBI_ERR_DENIED_LOCKED, + "Set locked feature to %lu with lock", locked_value); + + ret = fwft_set(feature, alt_value, 0); + sbiret_report_error(&ret, SBI_ERR_DENIED_LOCKED, + "Set locked feature to %lu without lock", alt_value); + + ret = fwft_set(feature, alt_value, SBI_FWFT_SET_FLAG_LOCK); + sbiret_report_error(&ret, SBI_ERR_DENIED_LOCKED, + "Set locked feature to %lu with lock", alt_value); + + ret = fwft_get(feature); + sbiret_report(&ret, SBI_SUCCESS, locked_value, + "Get locked feature value %lu", locked_value); +} + static void fwft_check_base(void) { report_prefix_push("base"); @@ -181,11 +208,9 @@ static void fwft_check_misaligned_exc_deleg(void) /* Lock the feature */ ret = fwft_misaligned_exc_set(0, SBI_FWFT_SET_FLAG_LOCK); sbiret_report_error(&ret, SBI_SUCCESS, "Set misaligned deleg feature value 0 and lock"); - ret = fwft_misaligned_exc_set(1, 0); - sbiret_report_error(&ret, SBI_ERR_DENIED_LOCKED, - "Set locked misaligned deleg feature to new value"); - ret = fwft_misaligned_exc_get(); - sbiret_report(&ret, SBI_SUCCESS, 0, "Get misaligned deleg locked value 0"); + + /* Test feature lock */ + fwft_feature_lock_test(SBI_FWFT_MISALIGNED_EXC_DELEG, 0); report_prefix_pop(); } @@ -326,17 +351,8 @@ adue_inval_tests: else enabled = !enabled; - ret = fwft_set(SBI_FWFT_PTE_AD_HW_UPDATING, !enabled, 0); - sbiret_report_error(&ret, SBI_ERR_DENIED_LOCKED, "set locked to %d without lock", !enabled); - - ret = fwft_set(SBI_FWFT_PTE_AD_HW_UPDATING, !enabled, 1); - sbiret_report_error(&ret, SBI_ERR_DENIED_LOCKED, "set locked to %d with lock", !enabled); - - ret = fwft_set(SBI_FWFT_PTE_AD_HW_UPDATING, enabled, 0); - sbiret_report_error(&ret, SBI_ERR_DENIED_LOCKED, "set locked to %d without lock", enabled); - - ret = fwft_set(SBI_FWFT_PTE_AD_HW_UPDATING, enabled, 1); - sbiret_report_error(&ret, SBI_ERR_DENIED_LOCKED, "set locked to %d with lock", enabled); + /* Test the feature lock */ + fwft_feature_lock_test(SBI_FWFT_PTE_AD_HW_UPDATING, enabled); adue_done: install_exception_handler(EXC_LOAD_PAGE_FAULT, NULL); -- 2.34.1