Zelalem Aweke | 50a3056 | 2021-07-09 15:32:21 -0500 | [diff] [blame] | 1 | /* |
Soby Mathew | 319fb08 | 2022-03-22 13:58:52 +0000 | [diff] [blame] | 2 | * Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved. |
Zelalem Aweke | 50a3056 | 2021-07-09 15:32:21 -0500 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Zelalem Aweke | 50a3056 | 2021-07-09 15:32:21 -0500 | [diff] [blame] | 7 | #include <common/debug.h> |
| 8 | #include <plat/common/platform.h> |
Javier Almansa Sobrino | 1d0ca40 | 2022-04-25 17:18:15 +0100 | [diff] [blame] | 9 | #include <services/rmm_core_manifest.h> |
Soby Mathew | 319fb08 | 2022-03-22 13:58:52 +0000 | [diff] [blame] | 10 | #include <services/rmmd_svc.h> |
Zelalem Aweke | 50a3056 | 2021-07-09 15:32:21 -0500 | [diff] [blame] | 11 | #include <services/trp/platform_trp.h> |
Javier Almansa Sobrino | 1d0ca40 | 2022-04-25 17:18:15 +0100 | [diff] [blame] | 12 | #include <trp_helpers.h> |
| 13 | #include "trp_private.h" |
Zelalem Aweke | 50a3056 | 2021-07-09 15:32:21 -0500 | [diff] [blame] | 14 | |
| 15 | #include <platform_def.h> |
Zelalem Aweke | 50a3056 | 2021-07-09 15:32:21 -0500 | [diff] [blame] | 16 | |
Javier Almansa Sobrino | 8c980a4 | 2021-11-24 18:37:37 +0000 | [diff] [blame] | 17 | /* Parameters received from the previous image */ |
| 18 | static unsigned int trp_boot_abi_version; |
| 19 | static uintptr_t trp_shared_region_start; |
| 20 | |
Javier Almansa Sobrino | 1d0ca40 | 2022-04-25 17:18:15 +0100 | [diff] [blame] | 21 | /* Parameters received from boot manifest */ |
| 22 | uint32_t trp_boot_manifest_version; |
Javier Almansa Sobrino | 8c980a4 | 2021-11-24 18:37:37 +0000 | [diff] [blame] | 23 | |
Zelalem Aweke | 50a3056 | 2021-07-09 15:32:21 -0500 | [diff] [blame] | 24 | /******************************************************************************* |
| 25 | * Setup function for TRP. |
| 26 | ******************************************************************************/ |
Javier Almansa Sobrino | 8c980a4 | 2021-11-24 18:37:37 +0000 | [diff] [blame] | 27 | void trp_setup(uint64_t x0, |
| 28 | uint64_t x1, |
| 29 | uint64_t x2, |
| 30 | uint64_t x3) |
Zelalem Aweke | 50a3056 | 2021-07-09 15:32:21 -0500 | [diff] [blame] | 31 | { |
Javier Almansa Sobrino | 8c980a4 | 2021-11-24 18:37:37 +0000 | [diff] [blame] | 32 | /* |
AlexeiFedorov | b96253d | 2022-11-24 13:42:44 +0000 | [diff] [blame^] | 33 | * Validate boot parameters |
Javier Almansa Sobrino | 8c980a4 | 2021-11-24 18:37:37 +0000 | [diff] [blame] | 34 | * |
AlexeiFedorov | b96253d | 2022-11-24 13:42:44 +0000 | [diff] [blame^] | 35 | * According to the Boot Interface ABI v.0.1, |
| 36 | * the parameters received from EL3 are: |
| 37 | * x0: CPUID (verified earlier, so not used) |
Javier Almansa Sobrino | 8c980a4 | 2021-11-24 18:37:37 +0000 | [diff] [blame] | 38 | * x1: Boot Interface version |
| 39 | * x2: PLATFORM_CORE_COUNT |
| 40 | * x3: Pointer to the shared memory area. |
| 41 | */ |
| 42 | |
| 43 | (void)x0; |
| 44 | |
| 45 | if (TRP_RMM_EL3_VERSION_GET_MAJOR(x1) != TRP_RMM_EL3_ABI_VERS_MAJOR) { |
| 46 | trp_boot_abort(E_RMM_BOOT_VERSION_MISMATCH); |
| 47 | } |
| 48 | |
| 49 | if ((void *)x3 == NULL) { |
| 50 | trp_boot_abort(E_RMM_BOOT_INVALID_SHARED_BUFFER); |
| 51 | } |
| 52 | |
| 53 | if (x2 > TRP_PLATFORM_CORE_COUNT) { |
| 54 | trp_boot_abort(E_RMM_BOOT_CPUS_OUT_OF_RANGE); |
| 55 | } |
| 56 | |
| 57 | trp_boot_abi_version = x1; |
| 58 | trp_shared_region_start = x3; |
| 59 | flush_dcache_range((uintptr_t)&trp_boot_abi_version, |
| 60 | sizeof(trp_boot_abi_version)); |
| 61 | flush_dcache_range((uintptr_t)&trp_shared_region_start, |
| 62 | sizeof(trp_shared_region_start)); |
| 63 | |
Zelalem Aweke | 50a3056 | 2021-07-09 15:32:21 -0500 | [diff] [blame] | 64 | /* Perform early platform-specific setup */ |
Javier Almansa Sobrino | 1d0ca40 | 2022-04-25 17:18:15 +0100 | [diff] [blame] | 65 | trp_early_platform_setup((rmm_manifest_t *)trp_shared_region_start); |
Zelalem Aweke | 50a3056 | 2021-07-09 15:32:21 -0500 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | /* Main function for TRP */ |
| 69 | void trp_main(void) |
| 70 | { |
| 71 | NOTICE("TRP: %s\n", version_string); |
| 72 | NOTICE("TRP: %s\n", build_message); |
Javier Almansa Sobrino | 8c980a4 | 2021-11-24 18:37:37 +0000 | [diff] [blame] | 73 | NOTICE("TRP: Supported RMM-EL3 Interface ABI: v.%u.%u\n", |
| 74 | TRP_RMM_EL3_ABI_VERS_MAJOR, TRP_RMM_EL3_ABI_VERS_MINOR); |
AlexeiFedorov | b96253d | 2022-11-24 13:42:44 +0000 | [diff] [blame^] | 75 | NOTICE("TRP: Boot Manifest Version: v.%u.%u\n", |
Javier Almansa Sobrino | 1d0ca40 | 2022-04-25 17:18:15 +0100 | [diff] [blame] | 76 | RMMD_GET_MANIFEST_VERSION_MAJOR(trp_boot_manifest_version), |
| 77 | RMMD_GET_MANIFEST_VERSION_MINOR(trp_boot_manifest_version)); |
AlexeiFedorov | b96253d | 2022-11-24 13:42:44 +0000 | [diff] [blame^] | 78 | INFO("TRP: Memory base: 0x%lx\n", (unsigned long)RMM_BASE); |
| 79 | INFO("TRP: Shared region base address: 0x%lx\n", |
Javier Almansa Sobrino | 8c980a4 | 2021-11-24 18:37:37 +0000 | [diff] [blame] | 80 | (unsigned long)trp_shared_region_start); |
AlexeiFedorov | b96253d | 2022-11-24 13:42:44 +0000 | [diff] [blame^] | 81 | INFO("TRP: Total size: 0x%lx bytes\n", |
| 82 | (unsigned long)(RMM_END - RMM_BASE)); |
Javier Almansa Sobrino | 8c980a4 | 2021-11-24 18:37:37 +0000 | [diff] [blame] | 83 | INFO("TRP: RMM-EL3 Interface ABI reported by EL3: v.%u.%u\n", |
| 84 | TRP_RMM_EL3_VERSION_GET_MAJOR(trp_boot_abi_version), |
| 85 | TRP_RMM_EL3_VERSION_GET_MINOR(trp_boot_abi_version)); |
Zelalem Aweke | 50a3056 | 2021-07-09 15:32:21 -0500 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | /******************************************************************************* |
| 89 | * Returning RMI version back to Normal World |
| 90 | ******************************************************************************/ |
AlexeiFedorov | b96253d | 2022-11-24 13:42:44 +0000 | [diff] [blame^] | 91 | static void trp_ret_rmi_version(struct trp_smc_result *smc_ret) |
Zelalem Aweke | 50a3056 | 2021-07-09 15:32:21 -0500 | [diff] [blame] | 92 | { |
| 93 | VERBOSE("RMM version is %u.%u\n", RMI_ABI_VERSION_MAJOR, |
| 94 | RMI_ABI_VERSION_MINOR); |
AlexeiFedorov | b96253d | 2022-11-24 13:42:44 +0000 | [diff] [blame^] | 95 | smc_ret->x[0] = RMI_ABI_VERSION; |
Zelalem Aweke | 50a3056 | 2021-07-09 15:32:21 -0500 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | /******************************************************************************* |
| 99 | * Transitioning granule of NON-SECURE type to REALM type |
| 100 | ******************************************************************************/ |
AlexeiFedorov | b96253d | 2022-11-24 13:42:44 +0000 | [diff] [blame^] | 101 | static void trp_asc_mark_realm(unsigned long long x1, |
| 102 | struct trp_smc_result *smc_ret) |
Zelalem Aweke | 50a3056 | 2021-07-09 15:32:21 -0500 | [diff] [blame] | 103 | { |
Zelalem Aweke | 50a3056 | 2021-07-09 15:32:21 -0500 | [diff] [blame] | 104 | VERBOSE("Delegating granule 0x%llx\n", x1); |
AlexeiFedorov | b96253d | 2022-11-24 13:42:44 +0000 | [diff] [blame^] | 105 | smc_ret->x[0] = trp_smc(set_smc_args(RMM_GTSI_DELEGATE, x1, |
| 106 | 0UL, 0UL, 0UL, 0UL, 0UL, 0UL)); |
Zelalem Aweke | 50a3056 | 2021-07-09 15:32:21 -0500 | [diff] [blame] | 107 | |
AlexeiFedorov | b96253d | 2022-11-24 13:42:44 +0000 | [diff] [blame^] | 108 | if (smc_ret->x[0] != 0ULL) { |
Zelalem Aweke | 50a3056 | 2021-07-09 15:32:21 -0500 | [diff] [blame] | 109 | ERROR("Granule transition from NON-SECURE type to REALM type " |
AlexeiFedorov | b96253d | 2022-11-24 13:42:44 +0000 | [diff] [blame^] | 110 | "failed 0x%llx\n", smc_ret->x[0]); |
Zelalem Aweke | 50a3056 | 2021-07-09 15:32:21 -0500 | [diff] [blame] | 111 | } |
Zelalem Aweke | 50a3056 | 2021-07-09 15:32:21 -0500 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | /******************************************************************************* |
| 115 | * Transitioning granule of REALM type to NON-SECURE type |
| 116 | ******************************************************************************/ |
AlexeiFedorov | b96253d | 2022-11-24 13:42:44 +0000 | [diff] [blame^] | 117 | static void trp_asc_mark_nonsecure(unsigned long long x1, |
| 118 | struct trp_smc_result *smc_ret) |
Zelalem Aweke | 50a3056 | 2021-07-09 15:32:21 -0500 | [diff] [blame] | 119 | { |
Zelalem Aweke | 50a3056 | 2021-07-09 15:32:21 -0500 | [diff] [blame] | 120 | VERBOSE("Undelegating granule 0x%llx\n", x1); |
AlexeiFedorov | b96253d | 2022-11-24 13:42:44 +0000 | [diff] [blame^] | 121 | smc_ret->x[0] = trp_smc(set_smc_args(RMM_GTSI_UNDELEGATE, x1, |
| 122 | 0UL, 0UL, 0UL, 0UL, 0UL, 0UL)); |
Zelalem Aweke | 50a3056 | 2021-07-09 15:32:21 -0500 | [diff] [blame] | 123 | |
AlexeiFedorov | b96253d | 2022-11-24 13:42:44 +0000 | [diff] [blame^] | 124 | if (smc_ret->x[0] != 0ULL) { |
Zelalem Aweke | 50a3056 | 2021-07-09 15:32:21 -0500 | [diff] [blame] | 125 | ERROR("Granule transition from REALM type to NON-SECURE type " |
AlexeiFedorov | b96253d | 2022-11-24 13:42:44 +0000 | [diff] [blame^] | 126 | "failed 0x%llx\n", smc_ret->x[0]); |
Zelalem Aweke | 50a3056 | 2021-07-09 15:32:21 -0500 | [diff] [blame] | 127 | } |
Zelalem Aweke | 50a3056 | 2021-07-09 15:32:21 -0500 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | /******************************************************************************* |
| 131 | * Main RMI SMC handler function |
| 132 | ******************************************************************************/ |
AlexeiFedorov | b96253d | 2022-11-24 13:42:44 +0000 | [diff] [blame^] | 133 | void trp_rmi_handler(unsigned long fid, |
| 134 | unsigned long long x1, unsigned long long x2, |
| 135 | unsigned long long x3, unsigned long long x4, |
| 136 | unsigned long long x5, unsigned long long x6, |
| 137 | struct trp_smc_result *smc_ret) |
Zelalem Aweke | 50a3056 | 2021-07-09 15:32:21 -0500 | [diff] [blame] | 138 | { |
AlexeiFedorov | b96253d | 2022-11-24 13:42:44 +0000 | [diff] [blame^] | 139 | /* Not used in the current implementation */ |
| 140 | (void)x2; |
| 141 | (void)x3; |
| 142 | (void)x4; |
| 143 | (void)x5; |
| 144 | (void)x6; |
| 145 | |
Zelalem Aweke | 50a3056 | 2021-07-09 15:32:21 -0500 | [diff] [blame] | 146 | switch (fid) { |
| 147 | case RMI_RMM_REQ_VERSION: |
AlexeiFedorov | b96253d | 2022-11-24 13:42:44 +0000 | [diff] [blame^] | 148 | trp_ret_rmi_version(smc_ret); |
| 149 | break; |
Zelalem Aweke | 50a3056 | 2021-07-09 15:32:21 -0500 | [diff] [blame] | 150 | case RMI_RMM_GRANULE_DELEGATE: |
AlexeiFedorov | b96253d | 2022-11-24 13:42:44 +0000 | [diff] [blame^] | 151 | trp_asc_mark_realm(x1, smc_ret); |
| 152 | break; |
Zelalem Aweke | 50a3056 | 2021-07-09 15:32:21 -0500 | [diff] [blame] | 153 | case RMI_RMM_GRANULE_UNDELEGATE: |
AlexeiFedorov | b96253d | 2022-11-24 13:42:44 +0000 | [diff] [blame^] | 154 | trp_asc_mark_nonsecure(x1, smc_ret); |
| 155 | break; |
Zelalem Aweke | 50a3056 | 2021-07-09 15:32:21 -0500 | [diff] [blame] | 156 | default: |
AlexeiFedorov | b96253d | 2022-11-24 13:42:44 +0000 | [diff] [blame^] | 157 | ERROR("Invalid SMC code to %s, FID %lx\n", __func__, fid); |
| 158 | smc_ret->x[0] = SMC_UNK; |
Zelalem Aweke | 50a3056 | 2021-07-09 15:32:21 -0500 | [diff] [blame] | 159 | } |
Zelalem Aweke | 50a3056 | 2021-07-09 15:32:21 -0500 | [diff] [blame] | 160 | } |