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