Manish Pandey | 0145ec3 | 2024-08-12 17:59:54 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2024, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
Manish Pandey | 0145ec3 | 2024-08-12 17:59:54 +0100 | [diff] [blame] | 6 | #include <arch.h> |
| 7 | #include <arch_helpers.h> |
| 8 | #include <arm_arch_svc.h> |
Arvind Ram Prakash | 8191621 | 2024-08-15 15:08:23 -0500 | [diff] [blame] | 9 | #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 Pandey | 0145ec3 | 2024-08-12 17:59:54 +0100 | [diff] [blame] | 15 | #include <smccc.h> |
| 16 | #include <sync.h> |
Arvind Ram Prakash | 8191621 | 2024-08-15 15:08:23 -0500 | [diff] [blame] | 17 | #include <test_helpers.h> |
Manish Pandey | 0145ec3 | 2024-08-12 17:59:54 +0100 | [diff] [blame] | 18 | #include <tftf_lib.h> |
Manish Pandey | 0145ec3 | 2024-08-12 17:59:54 +0100 | [diff] [blame] | 19 | |
Arvind Ram Prakash | 8191621 | 2024-08-15 15:08:23 -0500 | [diff] [blame] | 20 | static event_t cpu_has_entered_test[PLATFORM_CORE_COUNT]; |
| 21 | |
| 22 | static volatile bool undef_injection_triggered; |
| 23 | |
| 24 | static unsigned int test_result; |
| 25 | |
Charlie Bareham | e4f2eaa | 2024-08-12 17:59:54 +0100 | [diff] [blame] | 26 | static bool undef_injection_handler(void) |
Arvind Ram Prakash | 8191621 | 2024-08-15 15:08:23 -0500 | [diff] [blame] | 27 | { |
| 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 Bareham | e4f2eaa | 2024-08-12 17:59:54 +0100 | [diff] [blame] | 37 | static 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 | |
| 61 | static 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 Prakash | 8191621 | 2024-08-15 15:08:23 -0500 | [diff] [blame] | 85 | /* |
| 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 | */ |
| 90 | static 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 Bareham | e4f2eaa | 2024-08-12 17:59:54 +0100 | [diff] [blame] | 94 | test_result_t result; |
Arvind Ram Prakash | 8191621 | 2024-08-15 15:08:23 -0500 | [diff] [blame] | 95 | |
| 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 Bareham | e4f2eaa | 2024-08-12 17:59:54 +0100 | [diff] [blame] | 101 | 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 Prakash | 8191621 | 2024-08-15 15:08:23 -0500 | [diff] [blame] | 114 | |
| 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 Prakash | 8191621 | 2024-08-15 15:08:23 -0500 | [diff] [blame] | 126 | 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 Pandey | 0145ec3 | 2024-08-12 17:59:54 +0100 | [diff] [blame] | 132 | test_result_t test_asymmetric_features(void) |
| 133 | { |
Arvind Ram Prakash | 8191621 | 2024-08-15 15:08:23 -0500 | [diff] [blame] | 134 | unsigned int lead_mpid; |
| 135 | unsigned int cpu_mpid, cpu_node; |
| 136 | unsigned int core_pos; |
| 137 | int psci_ret; |
| 138 | |
Charlie Bareham | e4f2eaa | 2024-08-12 17:59:54 +0100 | [diff] [blame] | 139 | test_result_t result; |
| 140 | |
| 141 | test_result = TEST_RESULT_SUCCESS; |
| 142 | |
Arvind Ram Prakash | 8191621 | 2024-08-15 15:08:23 -0500 | [diff] [blame] | 143 | undef_injection_triggered = false; |
| 144 | |
Charlie Bareham | e4f2eaa | 2024-08-12 17:59:54 +0100 | [diff] [blame] | 145 | register_custom_sync_exception_handler(undef_injection_handler); |
Arvind Ram Prakash | 8191621 | 2024-08-15 15:08:23 -0500 | [diff] [blame] | 146 | |
| 147 | lead_mpid = read_mpidr_el1() & MPID_MASK; |
| 148 | |
Charlie Bareham | e4f2eaa | 2024-08-12 17:59:54 +0100 | [diff] [blame] | 149 | /* 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 Prakash | 8191621 | 2024-08-15 15:08:23 -0500 | [diff] [blame] | 164 | 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 Pandey | 0145ec3 | 2024-08-12 17:59:54 +0100 | [diff] [blame] | 198 | } |