blob: bc357bc881035b6ea932d4b8d230ead63b8b0fd8 [file] [log] [blame]
Shruti Gupta24597d12023-10-02 10:40:19 +01001/*
2 * Copyright (c) 2023, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#include <stdio.h>
9
10#include <arch_features.h>
11#include <arch_helpers.h>
12#include <debug.h>
13#include <fpu.h>
14#include <host_realm_helper.h>
15#include <host_shared_data.h>
16#include <psci.h>
17#include "realm_def.h"
18#include <realm_rsi.h>
19#include <realm_tests.h>
20#include <realm_psci.h>
21#include <tftf_lib.h>
22
23#define CXT_ID_MAGIC 0x100
24static uint64_t is_secondary_cpu_booted;
25
26static void rec1_handler(u_register_t cxt_id)
27{
28 realm_printf("Realm: running on CPU = 0x%lx cxt_id= 0x%lx\n",
29 read_mpidr_el1() & MPID_MASK, cxt_id);
30 if (cxt_id < CXT_ID_MAGIC || cxt_id > CXT_ID_MAGIC + MAX_REC_COUNT) {
31 realm_printf("Realm: Wrong cxt_id\n");
32 rsi_exit_to_host(HOST_CALL_EXIT_FAILED_CMD);
33 }
34 is_secondary_cpu_booted++;
35 realm_cpu_off();
36}
37
38static void rec2_handler(u_register_t cxt_id)
39{
40 rsi_exit_to_host(HOST_CALL_EXIT_FAILED_CMD);
41}
42
43bool test_realm_multiple_rec_psci_denied_cmd(void)
44{
45 u_register_t ret;
46
47 is_secondary_cpu_booted = 0U;
48 ret = realm_cpu_on(1U, (uintptr_t)rec1_handler, 0x100);
49 if (ret != PSCI_E_DENIED) {
50 return false;
51 }
52
53 if (is_secondary_cpu_booted != 0U) {
54 rsi_exit_to_host(HOST_CALL_EXIT_FAILED_CMD);
55 }
56
57 ret = realm_psci_affinity_info(1U, MPIDR_AFFLVL0);
58 if (ret != PSCI_STATE_OFF) {
59 realm_printf("CPU 1 should have been off\n");
60 return false;
61 }
62
63 ret = realm_cpu_on(2U, (uintptr_t)rec2_handler, 0x102);
64 if (ret != PSCI_E_ALREADY_ON) {
65 realm_printf("CPU 2 should have been already on\n");
66 return false;
67 }
68 return true;
69}