ArmPkg: Add initial OpteeLib implementation
[mirror_edk2.git] / ArmPkg / Library / OpteeLib / Optee.c
1 /** @file
2 Api's to communicate with OP-TEE OS (Trusted OS based on ARM TrustZone) via
3 secure monitor calls.
4
5 Copyright (c) 2018, Linaro Ltd. All rights reserved.<BR>
6
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15 **/
16
17 #include <Library/ArmSmcLib.h>
18 #include <Library/BaseLib.h>
19 #include <Library/OpteeLib.h>
20
21 #include <IndustryStandard/ArmStdSmc.h>
22
23 /**
24 Check for OP-TEE presence.
25 **/
26 BOOLEAN
27 EFIAPI
28 IsOpteePresent (
29 VOID
30 )
31 {
32 ARM_SMC_ARGS ArmSmcArgs;
33
34 // Send a Trusted OS Calls UID command
35 ArmSmcArgs.Arg0 = ARM_SMC_ID_TOS_UID;
36 ArmCallSmc (&ArmSmcArgs);
37
38 if ((ArmSmcArgs.Arg0 == OPTEE_OS_UID0) &&
39 (ArmSmcArgs.Arg1 == OPTEE_OS_UID1) &&
40 (ArmSmcArgs.Arg2 == OPTEE_OS_UID2) &&
41 (ArmSmcArgs.Arg3 == OPTEE_OS_UID3)) {
42 return TRUE;
43 } else {
44 return FALSE;
45 }
46 }