38 ArmSmcArgs.Arg0 = ARM_SMC_ID_TOS_UID;
41 if ((ArmSmcArgs.Arg0 == OPTEE_OS_UID0) &&
42 (ArmSmcArgs.Arg1 == OPTEE_OS_UID1) &&
43 (ArmSmcArgs.Arg2 == OPTEE_OS_UID2) &&
44 (ArmSmcArgs.Arg3 == OPTEE_OS_UID3))
54OpteeSharedMemoryRemap (
66 ArmSmcArgs.Arg0 = OPTEE_SMC_GET_SHARED_MEMORY_CONFIG;
69 if (ArmSmcArgs.Arg0 != OPTEE_SMC_RETURN_OK) {
70 DEBUG ((DEBUG_WARN,
"OP-TEE shared memory not supported\n"));
71 return EFI_UNSUPPORTED;
74 if (ArmSmcArgs.Arg3 != OPTEE_SMC_SHARED_MEMORY_CACHED) {
75 DEBUG ((DEBUG_WARN,
"OP-TEE: Only normal cached shared memory supported\n"));
76 return EFI_UNSUPPORTED;
79 Start = (ArmSmcArgs.Arg1 + SIZE_4KB - 1) & ~(SIZE_4KB - 1);
80 End = (ArmSmcArgs.Arg1 + ArmSmcArgs.Arg2) & ~(SIZE_4KB - 1);
81 PhysicalAddress = Start;
84 if (Size < SIZE_4KB) {
85 DEBUG ((DEBUG_WARN,
"OP-TEE shared memory too small\n"));
86 return EFI_BUFFER_TOO_SMALL;
92 EFI_MEMORY_WB | EFI_MEMORY_XP,
95 if (EFI_ERROR (Status)) {
99 OpteeSharedMemoryInformation.Base = (
UINTN)PhysicalAddress;
100 OpteeSharedMemoryInformation.Size = Size;
114 DEBUG ((DEBUG_WARN,
"OP-TEE not present\n"));
115 return EFI_UNSUPPORTED;
118 Status = OpteeSharedMemoryRemap ();
119 if (EFI_ERROR (Status)) {
120 DEBUG ((DEBUG_WARN,
"OP-TEE shared memory remap failed\n"));
133 return (Return != OPTEE_SMC_RETURN_UNKNOWN_FUNCTION) &&
134 ((Return & OPTEE_SMC_RETURN_RPC_PREFIX_MASK) ==
135 OPTEE_SMC_RETURN_RPC_PREFIX);
149 IN UINT64 PhysicalArg
155 ArmSmcArgs.Arg0 = OPTEE_SMC_CALL_WITH_ARG;
156 ArmSmcArgs.Arg1 = (UINT32)(PhysicalArg >> 32);
157 ArmSmcArgs.Arg2 = (UINT32)PhysicalArg;
162 if (IsOpteeSmcReturnRpc (ArmSmcArgs.Arg0)) {
163 switch (ArmSmcArgs.Arg0) {
164 case OPTEE_SMC_RETURN_RPC_FOREIGN_INTERRUPT:
178 ArmSmcArgs.Arg0 = OPTEE_SMC_RETURN_FROM_RPC;
184 return ArmSmcArgs.Arg0;
189EfiGuidToRfc4122Uuid (
197 CopyMem (Rfc4122Uuid->Data4, Guid->Data4, sizeof (Rfc4122Uuid->Data4));
210 if (OpteeSharedMemoryInformation.Base == 0) {
211 DEBUG ((DEBUG_WARN,
"OP-TEE not initialized\n"));
212 return EFI_NOT_STARTED;
218 MessageArg->Command = OPTEE_MESSAGE_COMMAND_OPEN_SESSION;
224 MessageArg->Params[0].Attribute = OPTEE_MESSAGE_ATTRIBUTE_TYPE_VALUE_INPUT |
225 OPTEE_MESSAGE_ATTRIBUTE_META;
226 MessageArg->Params[1].Attribute = OPTEE_MESSAGE_ATTRIBUTE_TYPE_VALUE_INPUT |
227 OPTEE_MESSAGE_ATTRIBUTE_META;
228 EfiGuidToRfc4122Uuid (
230 &OpenSessionArg->Uuid
233 MessageArg->Params[1].Union.Value.C = OPTEE_LOGIN_PUBLIC;
235 MessageArg->NumParams = 2;
238 MessageArg->Return = OPTEE_ERROR_COMMUNICATION;
239 MessageArg->ReturnOrigin = OPTEE_ORIGIN_COMMUNICATION;
242 OpenSessionArg->Session = MessageArg->Session;
243 OpenSessionArg->Return = MessageArg->Return;
244 OpenSessionArg->ReturnOrigin = MessageArg->ReturnOrigin;
259 if (OpteeSharedMemoryInformation.Base == 0) {
260 DEBUG ((DEBUG_WARN,
"OP-TEE not initialized\n"));
261 return EFI_NOT_STARTED;
267 MessageArg->Command = OPTEE_MESSAGE_COMMAND_CLOSE_SESSION;
268 MessageArg->Session = Session;
284 UINTN ParamSharedMemoryAddress;
285 UINTN SharedMemorySize;
289 ~(
sizeof (UINT64) - 1);
290 ParamSharedMemoryAddress = OpteeSharedMemoryInformation.Base + Size;
291 SharedMemorySize = OpteeSharedMemoryInformation.Size - Size;
293 for (Idx = 0; Idx < NumParams; Idx++) {
298 InParam = InParams + Idx;
299 MessageParam = MessageParams + Idx;
300 Attribute = InParam->Attribute & OPTEE_MESSAGE_ATTRIBUTE_TYPE_MASK;
303 case OPTEE_MESSAGE_ATTRIBUTE_TYPE_NONE:
304 MessageParam->Attribute = OPTEE_MESSAGE_ATTRIBUTE_TYPE_NONE;
305 ZeroMem (&MessageParam->Union, sizeof (MessageParam->Union));
308 case OPTEE_MESSAGE_ATTRIBUTE_TYPE_VALUE_INPUT:
309 case OPTEE_MESSAGE_ATTRIBUTE_TYPE_VALUE_OUTPUT:
310 case OPTEE_MESSAGE_ATTRIBUTE_TYPE_VALUE_INOUT:
311 MessageParam->Attribute = Attribute;
312 MessageParam->Union.Value.A = InParam->Union.Value.A;
313 MessageParam->Union.Value.B = InParam->Union.Value.B;
314 MessageParam->Union.Value.C = InParam->Union.Value.C;
317 case OPTEE_MESSAGE_ATTRIBUTE_TYPE_MEMORY_INPUT:
318 case OPTEE_MESSAGE_ATTRIBUTE_TYPE_MEMORY_OUTPUT:
319 case OPTEE_MESSAGE_ATTRIBUTE_TYPE_MEMORY_INOUT:
320 MessageParam->Attribute = Attribute;
322 if (InParam->Union.Memory.Size > SharedMemorySize) {
323 return EFI_OUT_OF_RESOURCES;
327 (VOID *)ParamSharedMemoryAddress,
328 (VOID *)(
UINTN)InParam->Union.Memory.BufferAddress,
329 InParam->Union.Memory.Size
331 MessageParam->Union.Memory.BufferAddress = (UINT64)ParamSharedMemoryAddress;
332 MessageParam->Union.Memory.Size = InParam->Union.Memory.Size;
334 Size = (InParam->Union.Memory.Size +
sizeof (UINT64) - 1) &
335 ~(
sizeof (UINT64) - 1);
336 ParamSharedMemoryAddress += Size;
337 SharedMemorySize -= Size;
341 return EFI_INVALID_PARAMETER;
350OpteeFromMessageParam (
358 for (Idx = 0; Idx < NumParams; Idx++) {
363 OutParam = OutParams + Idx;
364 MessageParam = MessageParams + Idx;
365 Attribute = MessageParam->Attribute & OPTEE_MESSAGE_ATTRIBUTE_TYPE_MASK;
368 case OPTEE_MESSAGE_ATTRIBUTE_TYPE_NONE:
369 OutParam->Attribute = OPTEE_MESSAGE_ATTRIBUTE_TYPE_NONE;
370 ZeroMem (&OutParam->Union, sizeof (OutParam->Union));
373 case OPTEE_MESSAGE_ATTRIBUTE_TYPE_VALUE_INPUT:
374 case OPTEE_MESSAGE_ATTRIBUTE_TYPE_VALUE_OUTPUT:
375 case OPTEE_MESSAGE_ATTRIBUTE_TYPE_VALUE_INOUT:
376 OutParam->Attribute = Attribute;
377 OutParam->Union.Value.A = MessageParam->Union.Value.A;
378 OutParam->Union.Value.B = MessageParam->Union.Value.B;
379 OutParam->Union.Value.C = MessageParam->Union.Value.C;
382 case OPTEE_MESSAGE_ATTRIBUTE_TYPE_MEMORY_INPUT:
383 case OPTEE_MESSAGE_ATTRIBUTE_TYPE_MEMORY_OUTPUT:
384 case OPTEE_MESSAGE_ATTRIBUTE_TYPE_MEMORY_INOUT:
385 OutParam->Attribute = Attribute;
387 if (MessageParam->Union.Memory.Size > OutParam->Union.Memory.Size) {
388 return EFI_BAD_BUFFER_SIZE;
392 (VOID *)(
UINTN)OutParam->Union.Memory.BufferAddress,
393 (VOID *)(
UINTN)MessageParam->Union.Memory.BufferAddress,
394 MessageParam->Union.Memory.Size
396 OutParam->Union.Memory.Size = MessageParam->Union.Memory.Size;
400 return EFI_INVALID_PARAMETER;
418 if (OpteeSharedMemoryInformation.Base == 0) {
419 DEBUG ((DEBUG_WARN,
"OP-TEE not initialized\n"));
420 return EFI_NOT_STARTED;
426 MessageArg->Command = OPTEE_MESSAGE_COMMAND_INVOKE_FUNCTION;
427 MessageArg->Function = InvokeFunctionArg->Function;
428 MessageArg->Session = InvokeFunctionArg->Session;
430 Status = OpteeToMessageParam (
432 OPTEE_MAX_CALL_PARAMS,
433 InvokeFunctionArg->Params
439 MessageArg->NumParams = OPTEE_MAX_CALL_PARAMS;
442 MessageArg->Return = OPTEE_ERROR_COMMUNICATION;
443 MessageArg->ReturnOrigin = OPTEE_ORIGIN_COMMUNICATION;
446 if (OpteeFromMessageParam (
447 InvokeFunctionArg->Params,
448 OPTEE_MAX_CALL_PARAMS,
452 MessageArg->Return = OPTEE_ERROR_COMMUNICATION;
453 MessageArg->ReturnOrigin = OPTEE_ORIGIN_COMMUNICATION;
456 InvokeFunctionArg->Return = MessageArg->Return;
457 InvokeFunctionArg->ReturnOrigin = MessageArg->ReturnOrigin;
EFI_STATUS ArmSetMemoryAttributes(IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Attributes, IN UINT64 AttributeMask)
VOID ArmCallSmc(IN OUT ARM_SMC_ARGS *Args)
UINT16 EFIAPI SwapBytes16(IN UINT16 Value)
UINT32 EFIAPI SwapBytes32(IN UINT32 Value)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
#define DEBUG(Expression)
BOOLEAN EFIAPI IsOpteePresent(VOID)
STATIC UINT32 OpteeCallWithArg(IN UINT64 PhysicalArg)
UINT64 EFI_PHYSICAL_ADDRESS