blob: 33f2fb088bd0097d8c1bda13daffb5cbae5c0f5f [file] [log] [blame]
Zelalem Awekec8bc23e2021-07-09 15:32:21 -05001/*
Soby Mathew68ea9542022-03-22 13:58:52 +00002 * Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
Zelalem Awekec8bc23e2021-07-09 15:32:21 -05003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Zelalem Awekec8bc23e2021-07-09 15:32:21 -05007#include <common/debug.h>
8#include <plat/common/platform.h>
Javier Almansa Sobrino4165e842022-04-25 17:18:15 +01009#include <services/rmm_core_manifest.h>
Soby Mathew68ea9542022-03-22 13:58:52 +000010#include <services/rmmd_svc.h>
Zelalem Awekec8bc23e2021-07-09 15:32:21 -050011#include <services/trp/platform_trp.h>
Javier Almansa Sobrino4165e842022-04-25 17:18:15 +010012#include <trp_helpers.h>
13#include "trp_private.h"
Zelalem Awekec8bc23e2021-07-09 15:32:21 -050014
15#include <platform_def.h>
Zelalem Awekec8bc23e2021-07-09 15:32:21 -050016
Javier Almansa Sobrino7176a772021-11-24 18:37:37 +000017/* Parameters received from the previous image */
18static unsigned int trp_boot_abi_version;
19static uintptr_t trp_shared_region_start;
20
Javier Almansa Sobrino4165e842022-04-25 17:18:15 +010021/* Parameters received from boot manifest */
22uint32_t trp_boot_manifest_version;
Javier Almansa Sobrino7176a772021-11-24 18:37:37 +000023
Zelalem Awekec8bc23e2021-07-09 15:32:21 -050024/*******************************************************************************
25 * Setup function for TRP.
26 ******************************************************************************/
Javier Almansa Sobrino7176a772021-11-24 18:37:37 +000027void trp_setup(uint64_t x0,
28 uint64_t x1,
29 uint64_t x2,
30 uint64_t x3)
Zelalem Awekec8bc23e2021-07-09 15:32:21 -050031{
Javier Almansa Sobrino7176a772021-11-24 18:37:37 +000032 /*
AlexeiFedorovf9044ab2022-11-24 13:42:44 +000033 * Validate boot parameters
Javier Almansa Sobrino7176a772021-11-24 18:37:37 +000034 *
AlexeiFedorovf9044ab2022-11-24 13:42:44 +000035 * 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 Sobrino7176a772021-11-24 18:37:37 +000038 * 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 Awekec8bc23e2021-07-09 15:32:21 -050064 /* Perform early platform-specific setup */
AlexeiFedorov8e754f92022-12-14 17:28:11 +000065 trp_early_platform_setup((struct rmm_manifest *)trp_shared_region_start);
Zelalem Awekec8bc23e2021-07-09 15:32:21 -050066}
67
Javier Almansa Sobrino04a6f2f2022-12-01 17:20:45 +000068int trp_validate_warmboot_args(uint64_t x0, uint64_t x1,
69 uint64_t x2, uint64_t x3)
70{
71 /*
72 * Validate boot parameters for warm boot
73 *
74 * According to the Boot Interface ABI v.0.1, the parameters
75 * received from EL3 during warm boot are:
76 *
77 * x0: CPUID (verified earlier so not used here)
78 * [x1:x3]: RES0
79 */
80
81 (void)x0;
82
83 return ((x1 | x2 | x3) == 0UL) ? 0 : E_RMM_BOOT_UNKNOWN;
84}
85
Zelalem Awekec8bc23e2021-07-09 15:32:21 -050086/* Main function for TRP */
87void trp_main(void)
88{
89 NOTICE("TRP: %s\n", version_string);
90 NOTICE("TRP: %s\n", build_message);
Javier Almansa Sobrino7176a772021-11-24 18:37:37 +000091 NOTICE("TRP: Supported RMM-EL3 Interface ABI: v.%u.%u\n",
92 TRP_RMM_EL3_ABI_VERS_MAJOR, TRP_RMM_EL3_ABI_VERS_MINOR);
AlexeiFedorovf9044ab2022-11-24 13:42:44 +000093 NOTICE("TRP: Boot Manifest Version: v.%u.%u\n",
Javier Almansa Sobrino4165e842022-04-25 17:18:15 +010094 RMMD_GET_MANIFEST_VERSION_MAJOR(trp_boot_manifest_version),
95 RMMD_GET_MANIFEST_VERSION_MINOR(trp_boot_manifest_version));
AlexeiFedorovf9044ab2022-11-24 13:42:44 +000096 INFO("TRP: Memory base: 0x%lx\n", (unsigned long)RMM_BASE);
97 INFO("TRP: Shared region base address: 0x%lx\n",
Javier Almansa Sobrino7176a772021-11-24 18:37:37 +000098 (unsigned long)trp_shared_region_start);
AlexeiFedorovf9044ab2022-11-24 13:42:44 +000099 INFO("TRP: Total size: 0x%lx bytes\n",
100 (unsigned long)(RMM_END - RMM_BASE));
Javier Almansa Sobrino7176a772021-11-24 18:37:37 +0000101 INFO("TRP: RMM-EL3 Interface ABI reported by EL3: v.%u.%u\n",
102 TRP_RMM_EL3_VERSION_GET_MAJOR(trp_boot_abi_version),
103 TRP_RMM_EL3_VERSION_GET_MINOR(trp_boot_abi_version));
Zelalem Awekec8bc23e2021-07-09 15:32:21 -0500104}
105
106/*******************************************************************************
107 * Returning RMI version back to Normal World
108 ******************************************************************************/
Shruti Gupta23c87332023-10-26 12:01:28 +0100109static void trp_ret_rmi_version(unsigned long long rmi_version,
110 struct trp_smc_result *smc_ret)
Zelalem Awekec8bc23e2021-07-09 15:32:21 -0500111{
Shruti Gupta23c87332023-10-26 12:01:28 +0100112 if (rmi_version != RMI_ABI_VERSION) {
113 smc_ret->x[0] = RMI_ERROR_INPUT;
114 } else {
115 smc_ret->x[0] = RMI_SUCCESS;
116 }
Zelalem Awekec8bc23e2021-07-09 15:32:21 -0500117 VERBOSE("RMM version is %u.%u\n", RMI_ABI_VERSION_MAJOR,
118 RMI_ABI_VERSION_MINOR);
Shruti Gupta23c87332023-10-26 12:01:28 +0100119 smc_ret->x[1] = RMI_ABI_VERSION;
120 smc_ret->x[2] = RMI_ABI_VERSION;
Zelalem Awekec8bc23e2021-07-09 15:32:21 -0500121}
122
123/*******************************************************************************
124 * Transitioning granule of NON-SECURE type to REALM type
125 ******************************************************************************/
AlexeiFedorovf9044ab2022-11-24 13:42:44 +0000126static void trp_asc_mark_realm(unsigned long long x1,
127 struct trp_smc_result *smc_ret)
Zelalem Awekec8bc23e2021-07-09 15:32:21 -0500128{
Zelalem Awekec8bc23e2021-07-09 15:32:21 -0500129 VERBOSE("Delegating granule 0x%llx\n", x1);
AlexeiFedorovf9044ab2022-11-24 13:42:44 +0000130 smc_ret->x[0] = trp_smc(set_smc_args(RMM_GTSI_DELEGATE, x1,
131 0UL, 0UL, 0UL, 0UL, 0UL, 0UL));
Zelalem Awekec8bc23e2021-07-09 15:32:21 -0500132
AlexeiFedorovf9044ab2022-11-24 13:42:44 +0000133 if (smc_ret->x[0] != 0ULL) {
Zelalem Awekec8bc23e2021-07-09 15:32:21 -0500134 ERROR("Granule transition from NON-SECURE type to REALM type "
AlexeiFedorovf9044ab2022-11-24 13:42:44 +0000135 "failed 0x%llx\n", smc_ret->x[0]);
Zelalem Awekec8bc23e2021-07-09 15:32:21 -0500136 }
Zelalem Awekec8bc23e2021-07-09 15:32:21 -0500137}
138
139/*******************************************************************************
140 * Transitioning granule of REALM type to NON-SECURE type
141 ******************************************************************************/
AlexeiFedorovf9044ab2022-11-24 13:42:44 +0000142static void trp_asc_mark_nonsecure(unsigned long long x1,
143 struct trp_smc_result *smc_ret)
Zelalem Awekec8bc23e2021-07-09 15:32:21 -0500144{
Zelalem Awekec8bc23e2021-07-09 15:32:21 -0500145 VERBOSE("Undelegating granule 0x%llx\n", x1);
AlexeiFedorovf9044ab2022-11-24 13:42:44 +0000146 smc_ret->x[0] = trp_smc(set_smc_args(RMM_GTSI_UNDELEGATE, x1,
147 0UL, 0UL, 0UL, 0UL, 0UL, 0UL));
Zelalem Awekec8bc23e2021-07-09 15:32:21 -0500148
AlexeiFedorovf9044ab2022-11-24 13:42:44 +0000149 if (smc_ret->x[0] != 0ULL) {
Zelalem Awekec8bc23e2021-07-09 15:32:21 -0500150 ERROR("Granule transition from REALM type to NON-SECURE type "
AlexeiFedorovf9044ab2022-11-24 13:42:44 +0000151 "failed 0x%llx\n", smc_ret->x[0]);
Zelalem Awekec8bc23e2021-07-09 15:32:21 -0500152 }
Zelalem Awekec8bc23e2021-07-09 15:32:21 -0500153}
154
155/*******************************************************************************
156 * Main RMI SMC handler function
157 ******************************************************************************/
AlexeiFedorovf9044ab2022-11-24 13:42:44 +0000158void trp_rmi_handler(unsigned long fid,
159 unsigned long long x1, unsigned long long x2,
160 unsigned long long x3, unsigned long long x4,
161 unsigned long long x5, unsigned long long x6,
162 struct trp_smc_result *smc_ret)
Zelalem Awekec8bc23e2021-07-09 15:32:21 -0500163{
AlexeiFedorovf9044ab2022-11-24 13:42:44 +0000164 /* Not used in the current implementation */
165 (void)x2;
166 (void)x3;
167 (void)x4;
168 (void)x5;
169 (void)x6;
170
Zelalem Awekec8bc23e2021-07-09 15:32:21 -0500171 switch (fid) {
172 case RMI_RMM_REQ_VERSION:
Shruti Gupta23c87332023-10-26 12:01:28 +0100173 trp_ret_rmi_version(x1, smc_ret);
AlexeiFedorovf9044ab2022-11-24 13:42:44 +0000174 break;
Zelalem Awekec8bc23e2021-07-09 15:32:21 -0500175 case RMI_RMM_GRANULE_DELEGATE:
AlexeiFedorovf9044ab2022-11-24 13:42:44 +0000176 trp_asc_mark_realm(x1, smc_ret);
177 break;
Zelalem Awekec8bc23e2021-07-09 15:32:21 -0500178 case RMI_RMM_GRANULE_UNDELEGATE:
AlexeiFedorovf9044ab2022-11-24 13:42:44 +0000179 trp_asc_mark_nonsecure(x1, smc_ret);
180 break;
Zelalem Awekec8bc23e2021-07-09 15:32:21 -0500181 default:
AlexeiFedorovf9044ab2022-11-24 13:42:44 +0000182 ERROR("Invalid SMC code to %s, FID %lx\n", __func__, fid);
183 smc_ret->x[0] = SMC_UNK;
Zelalem Awekec8bc23e2021-07-09 15:32:21 -0500184 }
Zelalem Awekec8bc23e2021-07-09 15:32:21 -0500185}