1e62748e3SManish V Badarkhe /* 2e62748e3SManish V Badarkhe * Copyright (c) 2022 Arm Limited. All rights reserved. 3e62748e3SManish V Badarkhe * 4e62748e3SManish V Badarkhe * SPDX-License-Identifier: BSD-3-Clause 5e62748e3SManish V Badarkhe * 6e62748e3SManish V Badarkhe * DRTM service 7e62748e3SManish V Badarkhe * 8e62748e3SManish V Badarkhe * Authors: 9e62748e3SManish V Badarkhe * Lucian Paul-Trifu <lucian.paultrifu@gmail.com> 10e62748e3SManish V Badarkhe * Brian Nezvadovitz <brinez@microsoft.com> 2021-02-01 11e62748e3SManish V Badarkhe */ 12e62748e3SManish V Badarkhe 13e62748e3SManish V Badarkhe #include <stdint.h> 14e62748e3SManish V Badarkhe 15*d54792bdSManish V Badarkhe #include <arch.h> 16*d54792bdSManish V Badarkhe #include <arch_helpers.h> 17e62748e3SManish V Badarkhe #include <common/debug.h> 18e62748e3SManish V Badarkhe #include <common/runtime_svc.h> 19*d54792bdSManish V Badarkhe #include <drivers/auth/crypto_mod.h> 20e62748e3SManish V Badarkhe #include "drtm_main.h" 21e62748e3SManish V Badarkhe #include <services/drtm_svc.h> 22e62748e3SManish V Badarkhe 23*d54792bdSManish V Badarkhe /* This value is used by the SMC to advertise the boot PE */ 24*d54792bdSManish V Badarkhe static uint64_t boot_pe_aff_value; 25*d54792bdSManish V Badarkhe 26e62748e3SManish V Badarkhe int drtm_setup(void) 27e62748e3SManish V Badarkhe { 28*d54792bdSManish V Badarkhe bool rc; 29*d54792bdSManish V Badarkhe 30e62748e3SManish V Badarkhe INFO("DRTM service setup\n"); 31e62748e3SManish V Badarkhe 32*d54792bdSManish V Badarkhe boot_pe_aff_value = read_mpidr_el1() & MPIDR_AFFINITY_MASK; 33*d54792bdSManish V Badarkhe 34*d54792bdSManish V Badarkhe rc = drtm_dma_prot_init(); 35*d54792bdSManish V Badarkhe if (rc) { 36*d54792bdSManish V Badarkhe return INTERNAL_ERROR; 37*d54792bdSManish V Badarkhe } 38*d54792bdSManish V Badarkhe 39*d54792bdSManish V Badarkhe /* 40*d54792bdSManish V Badarkhe * initialise the platform supported crypto module that will 41*d54792bdSManish V Badarkhe * be used by the DRTM-service to calculate hash of DRTM- 42*d54792bdSManish V Badarkhe * implementation specific components 43*d54792bdSManish V Badarkhe */ 44*d54792bdSManish V Badarkhe crypto_mod_init(); 45*d54792bdSManish V Badarkhe 46e62748e3SManish V Badarkhe return 0; 47e62748e3SManish V Badarkhe } 48e62748e3SManish V Badarkhe 49e62748e3SManish V Badarkhe uint64_t drtm_smc_handler(uint32_t smc_fid, 50e62748e3SManish V Badarkhe uint64_t x1, 51e62748e3SManish V Badarkhe uint64_t x2, 52e62748e3SManish V Badarkhe uint64_t x3, 53e62748e3SManish V Badarkhe uint64_t x4, 54e62748e3SManish V Badarkhe void *cookie, 55e62748e3SManish V Badarkhe void *handle, 56e62748e3SManish V Badarkhe uint64_t flags) 57e62748e3SManish V Badarkhe { 58e62748e3SManish V Badarkhe /* Check that the SMC call is from the Normal World. */ 59e62748e3SManish V Badarkhe if (!is_caller_non_secure(flags)) { 60e62748e3SManish V Badarkhe SMC_RET1(handle, NOT_SUPPORTED); 61e62748e3SManish V Badarkhe } 62e62748e3SManish V Badarkhe 63e62748e3SManish V Badarkhe switch (smc_fid) { 64e62748e3SManish V Badarkhe case ARM_DRTM_SVC_VERSION: 65e62748e3SManish V Badarkhe INFO("DRTM service handler: version\n"); 66e62748e3SManish V Badarkhe /* Return the version of current implementation */ 67e62748e3SManish V Badarkhe SMC_RET1(handle, ARM_DRTM_VERSION); 68e62748e3SManish V Badarkhe break; /* not reached */ 69e62748e3SManish V Badarkhe 70e62748e3SManish V Badarkhe case ARM_DRTM_SVC_FEATURES: 71e62748e3SManish V Badarkhe if (((x1 >> ARM_DRTM_FUNC_SHIFT) & ARM_DRTM_FUNC_MASK) == 72e62748e3SManish V Badarkhe ARM_DRTM_FUNC_ID) { 73e62748e3SManish V Badarkhe /* Dispatch function-based queries. */ 74e62748e3SManish V Badarkhe switch (x1 & FUNCID_MASK) { 75e62748e3SManish V Badarkhe case ARM_DRTM_SVC_VERSION: 76e62748e3SManish V Badarkhe SMC_RET1(handle, SUCCESS); 77e62748e3SManish V Badarkhe break; /* not reached */ 78e62748e3SManish V Badarkhe 79e62748e3SManish V Badarkhe case ARM_DRTM_SVC_FEATURES: 80e62748e3SManish V Badarkhe SMC_RET1(handle, SUCCESS); 81e62748e3SManish V Badarkhe break; /* not reached */ 82e62748e3SManish V Badarkhe 83e62748e3SManish V Badarkhe case ARM_DRTM_SVC_UNPROTECT_MEM: 84e62748e3SManish V Badarkhe SMC_RET1(handle, SUCCESS); 85e62748e3SManish V Badarkhe break; /* not reached */ 86e62748e3SManish V Badarkhe 87e62748e3SManish V Badarkhe case ARM_DRTM_SVC_DYNAMIC_LAUNCH: 88e62748e3SManish V Badarkhe SMC_RET1(handle, SUCCESS); 89e62748e3SManish V Badarkhe break; /* not reached */ 90e62748e3SManish V Badarkhe 91e62748e3SManish V Badarkhe case ARM_DRTM_SVC_CLOSE_LOCALITY: 92e62748e3SManish V Badarkhe WARN("ARM_DRTM_SVC_CLOSE_LOCALITY feature %s", 93e62748e3SManish V Badarkhe "is not supported\n"); 94e62748e3SManish V Badarkhe SMC_RET1(handle, NOT_SUPPORTED); 95e62748e3SManish V Badarkhe break; /* not reached */ 96e62748e3SManish V Badarkhe 97e62748e3SManish V Badarkhe case ARM_DRTM_SVC_GET_ERROR: 98e62748e3SManish V Badarkhe SMC_RET1(handle, SUCCESS); 99e62748e3SManish V Badarkhe break; /* not reached */ 100e62748e3SManish V Badarkhe 101e62748e3SManish V Badarkhe case ARM_DRTM_SVC_SET_ERROR: 102e62748e3SManish V Badarkhe SMC_RET1(handle, SUCCESS); 103e62748e3SManish V Badarkhe break; /* not reached */ 104e62748e3SManish V Badarkhe 105e62748e3SManish V Badarkhe case ARM_DRTM_SVC_SET_TCB_HASH: 106e62748e3SManish V Badarkhe WARN("ARM_DRTM_SVC_TCB_HASH feature %s", 107e62748e3SManish V Badarkhe "is not supported\n"); 108e62748e3SManish V Badarkhe SMC_RET1(handle, NOT_SUPPORTED); 109e62748e3SManish V Badarkhe break; /* not reached */ 110e62748e3SManish V Badarkhe 111e62748e3SManish V Badarkhe case ARM_DRTM_SVC_LOCK_TCB_HASH: 112e62748e3SManish V Badarkhe WARN("ARM_DRTM_SVC_LOCK_TCB_HASH feature %s", 113e62748e3SManish V Badarkhe "is not supported\n"); 114e62748e3SManish V Badarkhe SMC_RET1(handle, NOT_SUPPORTED); 115e62748e3SManish V Badarkhe break; /* not reached */ 116e62748e3SManish V Badarkhe 117e62748e3SManish V Badarkhe default: 118e62748e3SManish V Badarkhe ERROR("Unknown DRTM service function\n"); 119e62748e3SManish V Badarkhe SMC_RET1(handle, NOT_SUPPORTED); 120e62748e3SManish V Badarkhe break; /* not reached */ 121e62748e3SManish V Badarkhe } 122e62748e3SManish V Badarkhe } 123e62748e3SManish V Badarkhe 124e62748e3SManish V Badarkhe case ARM_DRTM_SVC_UNPROTECT_MEM: 125e62748e3SManish V Badarkhe INFO("DRTM service handler: unprotect mem\n"); 126e62748e3SManish V Badarkhe SMC_RET1(handle, SMC_OK); 127e62748e3SManish V Badarkhe break; /* not reached */ 128e62748e3SManish V Badarkhe 129e62748e3SManish V Badarkhe case ARM_DRTM_SVC_DYNAMIC_LAUNCH: 130e62748e3SManish V Badarkhe INFO("DRTM service handler: dynamic launch\n"); 131e62748e3SManish V Badarkhe SMC_RET1(handle, SMC_OK); 132e62748e3SManish V Badarkhe break; /* not reached */ 133e62748e3SManish V Badarkhe 134e62748e3SManish V Badarkhe case ARM_DRTM_SVC_CLOSE_LOCALITY: 135e62748e3SManish V Badarkhe WARN("DRTM service handler: close locality %s\n", 136e62748e3SManish V Badarkhe "is not supported"); 137e62748e3SManish V Badarkhe SMC_RET1(handle, NOT_SUPPORTED); 138e62748e3SManish V Badarkhe break; /* not reached */ 139e62748e3SManish V Badarkhe 140e62748e3SManish V Badarkhe case ARM_DRTM_SVC_GET_ERROR: 141e62748e3SManish V Badarkhe INFO("DRTM service handler: get error\n"); 142e62748e3SManish V Badarkhe SMC_RET2(handle, SMC_OK, 0); 143e62748e3SManish V Badarkhe break; /* not reached */ 144e62748e3SManish V Badarkhe 145e62748e3SManish V Badarkhe case ARM_DRTM_SVC_SET_ERROR: 146e62748e3SManish V Badarkhe INFO("DRTM service handler: set error\n"); 147e62748e3SManish V Badarkhe SMC_RET1(handle, SMC_OK); 148e62748e3SManish V Badarkhe break; /* not reached */ 149e62748e3SManish V Badarkhe 150e62748e3SManish V Badarkhe case ARM_DRTM_SVC_SET_TCB_HASH: 151e62748e3SManish V Badarkhe WARN("DRTM service handler: set TCB hash %s\n", 152e62748e3SManish V Badarkhe "is not supported"); 153e62748e3SManish V Badarkhe SMC_RET1(handle, NOT_SUPPORTED); 154e62748e3SManish V Badarkhe break; /* not reached */ 155e62748e3SManish V Badarkhe 156e62748e3SManish V Badarkhe case ARM_DRTM_SVC_LOCK_TCB_HASH: 157e62748e3SManish V Badarkhe WARN("DRTM service handler: lock TCB hash %s\n", 158e62748e3SManish V Badarkhe "is not supported"); 159e62748e3SManish V Badarkhe SMC_RET1(handle, NOT_SUPPORTED); 160e62748e3SManish V Badarkhe break; /* not reached */ 161e62748e3SManish V Badarkhe 162e62748e3SManish V Badarkhe default: 163e62748e3SManish V Badarkhe ERROR("Unknown DRTM service function: 0x%x\n", smc_fid); 164e62748e3SManish V Badarkhe SMC_RET1(handle, SMC_UNK); 165e62748e3SManish V Badarkhe break; /* not reached */ 166e62748e3SManish V Badarkhe } 167e62748e3SManish V Badarkhe 168e62748e3SManish V Badarkhe /* not reached */ 169e62748e3SManish V Badarkhe SMC_RET1(handle, SMC_UNK); 170e62748e3SManish V Badarkhe } 171