blob: adb929379575ec07ffa7aa54fcdcf87a401925df [file] [log] [blame]
Manish V Badarkhe8a766032022-02-23 11:26:53 +00001/*
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
Manish V Badarkhecc2c7432022-02-24 20:22:39 +000015#include <arch.h>
16#include <arch_helpers.h>
Manish V Badarkhe8a766032022-02-23 11:26:53 +000017#include <common/debug.h>
18#include <common/runtime_svc.h>
Manish V Badarkhecc2c7432022-02-24 20:22:39 +000019#include <drivers/auth/crypto_mod.h>
Manish V Badarkhe8a766032022-02-23 11:26:53 +000020#include "drtm_main.h"
21#include <services/drtm_svc.h>
22
Manish V Badarkhecc2c7432022-02-24 20:22:39 +000023/* This value is used by the SMC to advertise the boot PE */
24static uint64_t boot_pe_aff_value;
25
Manish V Badarkhe8a766032022-02-23 11:26:53 +000026int drtm_setup(void)
27{
Manish V Badarkhecc2c7432022-02-24 20:22:39 +000028 bool rc;
29
Manish V Badarkhe8a766032022-02-23 11:26:53 +000030 INFO("DRTM service setup\n");
31
Manish V Badarkhecc2c7432022-02-24 20:22:39 +000032 boot_pe_aff_value = read_mpidr_el1() & MPIDR_AFFINITY_MASK;
33
34 rc = drtm_dma_prot_init();
35 if (rc) {
36 return INTERNAL_ERROR;
37 }
38
39 /*
40 * initialise the platform supported crypto module that will
41 * be used by the DRTM-service to calculate hash of DRTM-
42 * implementation specific components
43 */
44 crypto_mod_init();
45
Manish V Badarkhe8a766032022-02-23 11:26:53 +000046 return 0;
47}
48
49uint64_t drtm_smc_handler(uint32_t smc_fid,
50 uint64_t x1,
51 uint64_t x2,
52 uint64_t x3,
53 uint64_t x4,
54 void *cookie,
55 void *handle,
56 uint64_t flags)
57{
58 /* Check that the SMC call is from the Normal World. */
59 if (!is_caller_non_secure(flags)) {
60 SMC_RET1(handle, NOT_SUPPORTED);
61 }
62
63 switch (smc_fid) {
64 case ARM_DRTM_SVC_VERSION:
65 INFO("DRTM service handler: version\n");
66 /* Return the version of current implementation */
67 SMC_RET1(handle, ARM_DRTM_VERSION);
68 break; /* not reached */
69
70 case ARM_DRTM_SVC_FEATURES:
71 if (((x1 >> ARM_DRTM_FUNC_SHIFT) & ARM_DRTM_FUNC_MASK) ==
72 ARM_DRTM_FUNC_ID) {
73 /* Dispatch function-based queries. */
74 switch (x1 & FUNCID_MASK) {
75 case ARM_DRTM_SVC_VERSION:
76 SMC_RET1(handle, SUCCESS);
77 break; /* not reached */
78
79 case ARM_DRTM_SVC_FEATURES:
80 SMC_RET1(handle, SUCCESS);
81 break; /* not reached */
82
83 case ARM_DRTM_SVC_UNPROTECT_MEM:
84 SMC_RET1(handle, SUCCESS);
85 break; /* not reached */
86
87 case ARM_DRTM_SVC_DYNAMIC_LAUNCH:
88 SMC_RET1(handle, SUCCESS);
89 break; /* not reached */
90
91 case ARM_DRTM_SVC_CLOSE_LOCALITY:
92 WARN("ARM_DRTM_SVC_CLOSE_LOCALITY feature %s",
93 "is not supported\n");
94 SMC_RET1(handle, NOT_SUPPORTED);
95 break; /* not reached */
96
97 case ARM_DRTM_SVC_GET_ERROR:
98 SMC_RET1(handle, SUCCESS);
99 break; /* not reached */
100
101 case ARM_DRTM_SVC_SET_ERROR:
102 SMC_RET1(handle, SUCCESS);
103 break; /* not reached */
104
105 case ARM_DRTM_SVC_SET_TCB_HASH:
106 WARN("ARM_DRTM_SVC_TCB_HASH feature %s",
107 "is not supported\n");
108 SMC_RET1(handle, NOT_SUPPORTED);
109 break; /* not reached */
110
111 case ARM_DRTM_SVC_LOCK_TCB_HASH:
112 WARN("ARM_DRTM_SVC_LOCK_TCB_HASH feature %s",
113 "is not supported\n");
114 SMC_RET1(handle, NOT_SUPPORTED);
115 break; /* not reached */
116
117 default:
118 ERROR("Unknown DRTM service function\n");
119 SMC_RET1(handle, NOT_SUPPORTED);
120 break; /* not reached */
121 }
122 }
123
124 case ARM_DRTM_SVC_UNPROTECT_MEM:
125 INFO("DRTM service handler: unprotect mem\n");
126 SMC_RET1(handle, SMC_OK);
127 break; /* not reached */
128
129 case ARM_DRTM_SVC_DYNAMIC_LAUNCH:
130 INFO("DRTM service handler: dynamic launch\n");
131 SMC_RET1(handle, SMC_OK);
132 break; /* not reached */
133
134 case ARM_DRTM_SVC_CLOSE_LOCALITY:
135 WARN("DRTM service handler: close locality %s\n",
136 "is not supported");
137 SMC_RET1(handle, NOT_SUPPORTED);
138 break; /* not reached */
139
140 case ARM_DRTM_SVC_GET_ERROR:
141 INFO("DRTM service handler: get error\n");
142 SMC_RET2(handle, SMC_OK, 0);
143 break; /* not reached */
144
145 case ARM_DRTM_SVC_SET_ERROR:
146 INFO("DRTM service handler: set error\n");
147 SMC_RET1(handle, SMC_OK);
148 break; /* not reached */
149
150 case ARM_DRTM_SVC_SET_TCB_HASH:
151 WARN("DRTM service handler: set TCB hash %s\n",
152 "is not supported");
153 SMC_RET1(handle, NOT_SUPPORTED);
154 break; /* not reached */
155
156 case ARM_DRTM_SVC_LOCK_TCB_HASH:
157 WARN("DRTM service handler: lock TCB hash %s\n",
158 "is not supported");
159 SMC_RET1(handle, NOT_SUPPORTED);
160 break; /* not reached */
161
162 default:
163 ERROR("Unknown DRTM service function: 0x%x\n", smc_fid);
164 SMC_RET1(handle, SMC_UNK);
165 break; /* not reached */
166 }
167
168 /* not reached */
169 SMC_RET1(handle, SMC_UNK);
170}