blob: 2d925a213a850d1e593b1bb29a446e66e9e3a232 [file] [log] [blame]
Manish Pandeyd72ab092023-12-11 17:43:53 +00001/*
2 * Copyright (c) 2023, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch.h>
8#include <arch_helpers.h>
9#include <arm_arch_svc.h>
10#include <assert.h>
11#include <debug.h>
12#include <smccc.h>
13#include <sync.h>
14#include <tftf_lib.h>
15#include <platform_def.h>
16
17static volatile bool undef_injection_triggered;
18
19static bool undef_injection_handler(void)
20{
21 uint64_t esr_el2 = read_esr_el2();
22 if (EC_BITS(esr_el2) == EC_UNKNOWN) {
23 VERBOSE("UNDEF injection from EL3\n");
24 undef_injection_triggered = true;
25 return true;
26 }
27
28 return false;
29}
30
31/*
32 * Test to verify UNDEF injection support in TF-A
33 *
34 * This test tries to access FGT EL2 registers which traps to EL3 and then
35 * the error is injected back from EL3 to TFTF to ensure that injection
36 * logic in TF-A is working, it also ensures that EL3 is still functional
37 * after UNDEF injection.
38 *
39 * To trap FGT register access to EL3, we run this test on a model with
40 * FEAT_FGT present but the traps from EL3 are not disabled by setting
41 * ENABLE_FEAT_FGT = 0
42 */
43test_result_t test_undef_injection(void)
44{
45 undef_injection_triggered = false;
46
47 register_custom_sync_exception_handler(undef_injection_handler);
48
49 /* Try to access a register which traps to EL3 */
50 read_hfgitr_el2();
51
52 unregister_custom_sync_exception_handler();
53
54 /* Ensure that EL3 still functional */
55 smc_args args;
56 smc_ret_values smc_ret;
57 memset(&args, 0, sizeof(args));
58 args.fid = SMCCC_VERSION;
59 smc_ret = tftf_smc(&args);
60
61 tftf_testcase_printf("SMCCC Version = %d.%d\n",
62 (int)((smc_ret.ret0 >> SMCCC_VERSION_MAJOR_SHIFT) & SMCCC_VERSION_MAJOR_MASK),
63 (int)((smc_ret.ret0 >> SMCCC_VERSION_MINOR_SHIFT) & SMCCC_VERSION_MINOR_MASK));
64
65 if (undef_injection_triggered == false) {
66 return TEST_RESULT_FAIL;
67 }
68
69 return TEST_RESULT_SUCCESS;
70}