blob: 25b2421f50ce30e0c41fdc94acaadb015e87eb11 [file] [log] [blame]
Manish Pandey0145ec32024-08-12 17:59:54 +01001/*
2 * Copyright (c) 2024, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
Manish Pandey0145ec32024-08-12 17:59:54 +01006#include <arch.h>
7#include <arch_helpers.h>
8#include <arm_arch_svc.h>
Arvind Ram Prakash81916212024-08-15 15:08:23 -05009#include <events.h>
10#include <plat_topology.h>
11#include <platform.h>
12#include <platform_def.h>
13#include <power_management.h>
14#include <psci.h>
Manish Pandey0145ec32024-08-12 17:59:54 +010015#include <smccc.h>
16#include <sync.h>
Arvind Ram Prakash81916212024-08-15 15:08:23 -050017#include <test_helpers.h>
Manish Pandey0145ec32024-08-12 17:59:54 +010018#include <tftf_lib.h>
Manish Pandey0145ec32024-08-12 17:59:54 +010019
Arvind Ram Prakash81916212024-08-15 15:08:23 -050020static event_t cpu_has_entered_test[PLATFORM_CORE_COUNT];
21
22static volatile bool undef_injection_triggered;
23
24static unsigned int test_result;
25
Charlie Barehame4f2eaa2024-08-12 17:59:54 +010026static bool undef_injection_handler(void)
Arvind Ram Prakash81916212024-08-15 15:08:23 -050027{
28 uint64_t esr_el2 = read_esr_el2();
29 if (EC_BITS(esr_el2) == EC_UNKNOWN) {
30 undef_injection_triggered = true;
31 return true;
32 }
33
34 return false;
35}
36
Charlie Barehame4f2eaa2024-08-12 17:59:54 +010037static test_result_t test_trbe(void)
38{
39 unsigned int mpid = read_mpidr_el1() & MPID_MASK;
40 unsigned int core_pos = platform_get_core_pos(mpid);
41 bool check_if_affected = is_trbe_errata_affected_core();
42
43 read_trblimitr_el1();
44
45 if (undef_injection_triggered == true && check_if_affected == true) {
46 test_result = TEST_RESULT_SUCCESS;
47 undef_injection_triggered = false;
48 tftf_testcase_printf("Undef injection triggered for core = %d "
49 "when accessing TRB_LIMTR\n", core_pos);
50 } else if (undef_injection_triggered == false && check_if_affected == false) {
51 test_result = TEST_RESULT_SUCCESS;
52 tftf_testcase_printf("TRB_LIMITR register accessible for core "
53 "= %d\n", core_pos);
54 } else {
55 test_result = TEST_RESULT_FAIL;
56 }
57
58 return test_result;
59}
60
61static test_result_t test_spe(void)
62{
63 unsigned int mpid = read_mpidr_el1() & MPID_MASK;
64 unsigned int core_pos = platform_get_core_pos(mpid);
65
66 read_pmscr_el1();
67
68 if (undef_injection_triggered == true && !is_feat_spe_supported()) {
69 test_result = TEST_RESULT_SUCCESS;
70 undef_injection_triggered = false;
71 tftf_testcase_printf("Undef injection triggered for core = %d "
72 "when accessing PMSCR_EL1\n", core_pos);
73 } else if (undef_injection_triggered == false &&
74 is_feat_spe_supported()) {
75 test_result = TEST_RESULT_SUCCESS;
76 tftf_testcase_printf("PMSCR_EL1 register accessible for core = "
77 "%d\n", core_pos);
78 } else {
79 test_result = TEST_RESULT_FAIL;
80 }
81
82 return test_result;
83}
84
Arvind Ram Prakash81916212024-08-15 15:08:23 -050085/*
86 * Non-lead cpu function that checks if trblimitr_el1 is accessible,
87 * on affected cores this causes a undef injection and passes.In cores that
88 * are not affected test just passes. It fails in other cases.
89 */
90static test_result_t non_lead_cpu_fn(void)
91{
92 unsigned int mpid = read_mpidr_el1() & MPID_MASK;
93 unsigned int core_pos = platform_get_core_pos(mpid);
Charlie Barehame4f2eaa2024-08-12 17:59:54 +010094 test_result_t result;
Arvind Ram Prakash81916212024-08-15 15:08:23 -050095
96 test_result = TEST_RESULT_SUCCESS;
97
98 /* Signal to the lead CPU that the calling CPU has entered the test */
99 tftf_send_event(&cpu_has_entered_test[core_pos]);
100
Charlie Barehame4f2eaa2024-08-12 17:59:54 +0100101 result = test_trbe();
102 if (result != TEST_RESULT_SUCCESS) {
103 tftf_testcase_printf("test_trbe_enabled failed with result "
104 "%d\n", result);
105 test_result = result;
106 }
107
108 result = test_spe();
109 if (result != TEST_RESULT_SUCCESS) {
110 tftf_testcase_printf("test_spe_support failed with result %d\n",
111 result);
112 test_result = result;
113 }
Arvind Ram Prakash81916212024-08-15 15:08:23 -0500114
115 /* Ensure that EL3 still functional */
116 smc_args args;
117 smc_ret_values smc_ret;
118 memset(&args, 0, sizeof(args));
119 args.fid = SMCCC_VERSION;
120 smc_ret = tftf_smc(&args);
121
122 tftf_testcase_printf("SMCCC Version = %d.%d\n",
123 (int)((smc_ret.ret0 >> SMCCC_VERSION_MAJOR_SHIFT) & SMCCC_VERSION_MAJOR_MASK),
124 (int)((smc_ret.ret0 >> SMCCC_VERSION_MINOR_SHIFT) & SMCCC_VERSION_MINOR_MASK));
125
Arvind Ram Prakash81916212024-08-15 15:08:23 -0500126 return test_result;
127}
128
129/* This function kicks off non-lead cpus and the non-lead cpu function
130 * checks if errata is applied or not using the test.
131 */
Manish Pandey0145ec32024-08-12 17:59:54 +0100132test_result_t test_asymmetric_features(void)
133{
Arvind Ram Prakash81916212024-08-15 15:08:23 -0500134 unsigned int lead_mpid;
135 unsigned int cpu_mpid, cpu_node;
136 unsigned int core_pos;
137 int psci_ret;
138
Charlie Barehame4f2eaa2024-08-12 17:59:54 +0100139 test_result_t result;
140
141 test_result = TEST_RESULT_SUCCESS;
142
Arvind Ram Prakash81916212024-08-15 15:08:23 -0500143 undef_injection_triggered = false;
144
Charlie Barehame4f2eaa2024-08-12 17:59:54 +0100145 register_custom_sync_exception_handler(undef_injection_handler);
Arvind Ram Prakash81916212024-08-15 15:08:23 -0500146
147 lead_mpid = read_mpidr_el1() & MPID_MASK;
148
Charlie Barehame4f2eaa2024-08-12 17:59:54 +0100149 /* Testing TRBE and SPE feature in Lead core */
150 result = test_trbe();
151 if (result != TEST_RESULT_SUCCESS) {
152 tftf_testcase_printf("test_trbe_enabled failed with result "
153 "%d\n", result);
154 test_result = result;
155 }
156
157 result = test_spe();
158 if (result != TEST_RESULT_SUCCESS) {
159 tftf_testcase_printf("test_spe_support failed with result %d\n",
160 result);
161 test_result = result;
162 }
163
Arvind Ram Prakash81916212024-08-15 15:08:23 -0500164 SKIP_TEST_IF_LESS_THAN_N_CPUS(2);
165
166 /* Power on all CPUs */
167 for_each_cpu(cpu_node) {
168 cpu_mpid = tftf_get_mpidr_from_node(cpu_node);
169 /* Skip lead CPU as it is already powered on */
170 if (cpu_mpid == lead_mpid)
171 continue;
172
173 psci_ret = tftf_cpu_on(cpu_mpid, (uintptr_t) non_lead_cpu_fn, 0);
174 if (psci_ret != PSCI_E_SUCCESS) {
175 tftf_testcase_printf(
176 "Failed to power on CPU 0x%x (%d)\n",
177 cpu_mpid, psci_ret);
178 return TEST_RESULT_SKIPPED;
179 }
180 }
181
182 /* Wait for non-lead CPUs to enter the test */
183 for_each_cpu(cpu_node) {
184 cpu_mpid = tftf_get_mpidr_from_node(cpu_node);
185 /* Skip lead CPU */
186 if (cpu_mpid == lead_mpid)
187 continue;
188
189 core_pos = platform_get_core_pos(cpu_mpid);
190 tftf_wait_for_event(&cpu_has_entered_test[core_pos]);
191 if (test_result == TEST_RESULT_FAIL)
192 break;
193 }
194
195 unregister_custom_sync_exception_handler();
196
197 return test_result;
Manish Pandey0145ec32024-08-12 17:59:54 +0100198}