Gareth Stockwell | a0a8ec6 | 2023-01-06 16:20:49 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2023, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <power_management.h> |
| 8 | #include <test_helpers.h> |
| 9 | |
| 10 | __attribute__((noinline)) |
| 11 | static void debug_hook_func(void) |
| 12 | { |
| 13 | __asm__ volatile( |
| 14 | "nop\n" |
| 15 | "nop\n" |
| 16 | "nop\n" |
| 17 | "nop\n" |
| 18 | "debug_hook:\n" |
| 19 | ".global debug_hook\n" |
| 20 | "nop\n" |
| 21 | "nop\n" |
| 22 | "nop\n" |
| 23 | "nop\n" |
| 24 | ); |
| 25 | |
| 26 | return; |
| 27 | } |
| 28 | |
| 29 | static test_result_t secondary_cpu(void) |
| 30 | { |
| 31 | debug_hook_func(); |
| 32 | return TEST_RESULT_SUCCESS; |
| 33 | } |
| 34 | |
| 35 | /* |
| 36 | * This is intended for use in conjunction with Trusted Firmware eXplorer |
| 37 | * (TFX). |
| 38 | * |
| 39 | * 1. Power up all secondary CPUs and execute test_nop. |
| 40 | * 2. TFX is expected to set a breakpoint on debug_hook. When this is hit, |
| 41 | * TFX takes over control and starts injecting test code. |
| 42 | * 3. Once the test is complete, TFX powers down all CPUs. |
| 43 | */ |
| 44 | test_result_t test_nop(void) |
| 45 | { |
| 46 | u_register_t lead_mpid, target_mpid; |
| 47 | int cpu_node; |
| 48 | long long ret; |
| 49 | |
| 50 | lead_mpid = read_mpidr_el1() & MPID_MASK; |
| 51 | |
| 52 | /* Start all other CPUs */ |
| 53 | for_each_cpu(cpu_node) { |
| 54 | target_mpid = tftf_get_mpidr_from_node(cpu_node) & MPID_MASK; |
| 55 | |
| 56 | if (lead_mpid == target_mpid) { |
| 57 | continue; |
| 58 | } |
| 59 | |
| 60 | ret = tftf_cpu_on(target_mpid, (uintptr_t)secondary_cpu, 0); |
| 61 | if (ret != PSCI_E_SUCCESS) { |
| 62 | ERROR("CPU ON failed for 0x0x%llx\n", (unsigned long long)target_mpid); |
| 63 | return TEST_RESULT_FAIL; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | /* Do the actual work */ |
| 68 | debug_hook_func(); |
| 69 | |
| 70 | /* Wait for other CPUs to complete */ |
| 71 | for_each_cpu(cpu_node) { |
| 72 | target_mpid = tftf_get_mpidr_from_node(cpu_node) & MPID_MASK; |
| 73 | |
| 74 | if (lead_mpid == target_mpid) { |
| 75 | continue; |
| 76 | } |
| 77 | |
| 78 | while (tftf_psci_affinity_info(target_mpid, MPIDR_AFFLVL0) != PSCI_STATE_OFF) { |
| 79 | continue; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | return TEST_RESULT_SUCCESS; |
| 84 | } |