summaryrefslogtreecommitdiffstats
path: root/ArmPkg
diff options
context:
space:
mode:
authorRebecca Cran <rebecca@nuviainc.com>2021-12-13 11:30:55 -0700
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2021-12-14 11:30:26 +0000
commit4d303524451d87d411c972736015138a8a4f03f6 (patch)
treea266cd1f4a9ba9361734d9c7be3a604464e0896c /ArmPkg
parent7a6e6ae9332614d386446d2a73e34b74fe66446f (diff)
downloadedk2-4d303524451d87d411c972736015138a8a4f03f6.tar.gz
edk2-4d303524451d87d411c972736015138a8a4f03f6.tar.bz2
edk2-4d303524451d87d411c972736015138a8a4f03f6.zip
ArmPkg: Add SMC helper functions
Add functions ArmCallSmc0/1/2/3 to do SMC calls with 0, 1, 2 or 3 arguments. The functions return up to 3 values. Signed-off-by: Rebecca Cran <rebecca@nuviainc.com> Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
Diffstat (limited to 'ArmPkg')
-rw-r--r--ArmPkg/Include/Library/ArmSmcLib.h73
-rw-r--r--ArmPkg/Library/ArmSmcLib/ArmSmc.c129
-rw-r--r--ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf3
-rw-r--r--ArmPkg/Library/ArmSmcLibNull/ArmSmcLibNull.c85
4 files changed, 290 insertions, 0 deletions
diff --git a/ArmPkg/Include/Library/ArmSmcLib.h b/ArmPkg/Include/Library/ArmSmcLib.h
index f5b45f0a8c..beef0175c3 100644
--- a/ArmPkg/Include/Library/ArmSmcLib.h
+++ b/ArmPkg/Include/Library/ArmSmcLib.h
@@ -1,5 +1,6 @@
/** @file
*
+* Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR>
* Copyright (c) 2012-2014, ARM Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -37,4 +38,76 @@ ArmCallSmc (
IN OUT ARM_SMC_ARGS *Args
);
+/** Trigger an SMC call with 3 arguments.
+
+ @param Function The SMC function.
+ @param Arg1 Argument/result.
+ @param Arg2 Argument/result.
+ @param Arg3 Argument/result.
+
+ @return The SMC error code.
+
+**/
+UINTN
+ArmCallSmc3 (
+ IN UINTN Function,
+ IN OUT UINTN *Arg1 OPTIONAL,
+ IN OUT UINTN *Arg2 OPTIONAL,
+ IN OUT UINTN *Arg3 OPTIONAL
+ );
+
+/** Trigger an SMC call with 2 arguments.
+
+ @param Function The SMC function.
+ @param Arg1 Argument/result.
+ @param Arg2 Argument/result.
+ @param Arg3 Result.
+
+ @return The SMC error code.
+
+**/
+UINTN
+ArmCallSmc2 (
+ IN UINTN Function,
+ IN OUT UINTN *Arg1 OPTIONAL,
+ IN OUT UINTN *Arg2 OPTIONAL,
+ OUT UINTN *Arg3 OPTIONAL
+ );
+
+/** Trigger an SMC call with 1 argument.
+
+ @param Function The SMC function.
+ @param Arg1 Argument/result.
+ @param Arg2 Result.
+ @param Arg3 Result.
+
+ @return The SMC error code.
+
+**/
+UINTN
+ArmCallSmc1 (
+ IN UINTN Function,
+ IN OUT UINTN *Arg1 OPTIONAL,
+ OUT UINTN *Arg2 OPTIONAL,
+ OUT UINTN *Arg3 OPTIONAL
+ );
+
+/** Trigger an SMC call with 0 arguments.
+
+ @param Function The SMC function.
+ @param Arg1 Result.
+ @param Arg2 Result.
+ @param Arg3 Result.
+
+ @return The SMC error code.
+
+**/
+UINTN
+ArmCallSmc0 (
+ IN UINTN Function,
+ OUT UINTN *Arg1 OPTIONAL,
+ OUT UINTN *Arg2 OPTIONAL,
+ OUT UINTN *Arg3 OPTIONAL
+ );
+
#endif // ARM_SMC_LIB_H_
diff --git a/ArmPkg/Library/ArmSmcLib/ArmSmc.c b/ArmPkg/Library/ArmSmcLib/ArmSmc.c
new file mode 100644
index 0000000000..254507e219
--- /dev/null
+++ b/ArmPkg/Library/ArmSmcLib/ArmSmc.c
@@ -0,0 +1,129 @@
+/** @file
+ SMC helper functions.
+
+ Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Library/ArmSmcLib.h>
+#include <Library/BaseMemoryLib.h>
+
+/** Triggers an SMC call with 3 arguments.
+
+ @param Function The SMC function.
+ @param Arg1 Argument/result.
+ @param Arg2 Argument/result.
+ @param Arg3 Argument/result.
+
+ @return The SMC error code.
+**/
+UINTN
+ArmCallSmc3 (
+ IN UINTN Function,
+ IN OUT UINTN *Arg1 OPTIONAL,
+ IN OUT UINTN *Arg2 OPTIONAL,
+ IN OUT UINTN *Arg3 OPTIONAL
+ )
+{
+ ARM_SMC_ARGS Args;
+ UINTN ErrorCode;
+
+ ZeroMem (&Args, sizeof (ARM_SMC_ARGS));
+
+ Args.Arg0 = Function;
+
+ if (Arg1 != NULL) {
+ Args.Arg1 = *Arg1;
+ }
+
+ if (Arg2 != NULL) {
+ Args.Arg2 = *Arg2;
+ }
+
+ if (Arg3 != NULL) {
+ Args.Arg3 = *Arg3;
+ }
+
+ ArmCallSmc (&Args);
+
+ ErrorCode = Args.Arg0;
+
+ if (Arg1 != NULL) {
+ *Arg1 = Args.Arg1;
+ }
+
+ if (Arg2 != NULL) {
+ *Arg2 = Args.Arg2;
+ }
+
+ if (Arg3 != NULL) {
+ *Arg3 = Args.Arg3;
+ }
+
+ return ErrorCode;
+}
+
+/** Trigger an SMC call with 2 arguments.
+
+ @param Function The SMC function.
+ @param Arg1 Argument/result.
+ @param Arg2 Argument/result.
+ @param Arg3 Result.
+
+ @return The SMC error code.
+
+**/
+UINTN
+ArmCallSmc2 (
+ IN UINTN Function,
+ IN OUT UINTN *Arg1 OPTIONAL,
+ IN OUT UINTN *Arg2 OPTIONAL,
+ OUT UINTN *Arg3 OPTIONAL
+ )
+{
+ return ArmCallSmc3 (Function, Arg1, Arg2, Arg3);
+}
+
+/** Trigger an SMC call with 1 argument.
+
+ @param Function The SMC function.
+ @param Arg1 Argument/result.
+ @param Arg2 Result.
+ @param Arg3 Result.
+
+ @return The SMC error code.
+
+**/
+UINTN
+ArmCallSmc1 (
+ IN UINTN Function,
+ IN OUT UINTN *Arg1 OPTIONAL,
+ OUT UINTN *Arg2 OPTIONAL,
+ OUT UINTN *Arg3 OPTIONAL
+ )
+{
+ return ArmCallSmc3 (Function, Arg1, Arg2, Arg3);
+}
+
+/** Trigger an SMC call with 0 arguments.
+
+ @param Function The SMC function.
+ @param Arg1 Result.
+ @param Arg2 Result.
+ @param Arg3 Result.
+
+ @return The SMC error code.
+
+**/
+UINTN
+ArmCallSmc0 (
+ IN UINTN Function,
+ OUT UINTN *Arg1 OPTIONAL,
+ OUT UINTN *Arg2 OPTIONAL,
+ OUT UINTN *Arg3 OPTIONAL
+ )
+{
+ return ArmCallSmc3 (Function, Arg1, Arg2, Arg3);
+}
diff --git a/ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf b/ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf
index 4f4b09f452..a89f9203fb 100644
--- a/ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf
+++ b/ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf
@@ -20,6 +20,9 @@
[Sources.AARCH64]
AArch64/ArmSmc.S
+[Sources]
+ ArmSmc.c
+
[Packages]
MdePkg/MdePkg.dec
ArmPkg/ArmPkg.dec
diff --git a/ArmPkg/Library/ArmSmcLibNull/ArmSmcLibNull.c b/ArmPkg/Library/ArmSmcLibNull/ArmSmcLibNull.c
index 3c1adef8eb..28514e43c2 100644
--- a/ArmPkg/Library/ArmSmcLibNull/ArmSmcLibNull.c
+++ b/ArmPkg/Library/ArmSmcLibNull/ArmSmcLibNull.c
@@ -1,4 +1,5 @@
//
+// Copyright (c) 2021, NUVIA Inc. All rights reserved.
// Copyright (c) 2016, Linaro Limited. All rights reserved.
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -7,6 +8,7 @@
#include <Base.h>
#include <Library/ArmSmcLib.h>
+#include <IndustryStandard/ArmStdSmc.h>
VOID
ArmCallSmc (
@@ -14,3 +16,86 @@ ArmCallSmc (
)
{
}
+
+/** Triggers an SMC call with 3 arguments.
+
+ @param Function The SMC function.
+ @param Arg1 Argument/result.
+ @param Arg2 Argument/result.
+ @param Arg3 Argument/result.
+
+ @return The SMC error code.
+**/
+UINTN
+ArmCallSmc3 (
+ IN UINTN Function,
+ IN OUT UINTN *Arg1 OPTIONAL,
+ IN OUT UINTN *Arg2 OPTIONAL,
+ IN OUT UINTN *Arg3 OPTIONAL
+ )
+{
+ return SMC_ARCH_CALL_NOT_SUPPORTED;
+}
+
+/** Trigger an SMC call with 2 arguments.
+
+ @param Function The SMC function.
+ @param Arg1 Argument/result.
+ @param Arg2 Argument/result.
+ @param Arg3 Result.
+
+ @return The SMC error code.
+
+**/
+UINTN
+ArmCallSmc2 (
+ IN UINTN Function,
+ IN OUT UINTN *Arg1 OPTIONAL,
+ IN OUT UINTN *Arg2 OPTIONAL,
+ OUT UINTN *Arg3 OPTIONAL
+ )
+{
+ return SMC_ARCH_CALL_NOT_SUPPORTED;
+}
+
+/** Trigger an SMC call with 1 argument.
+
+ @param Function The SMC function.
+ @param Arg1 Argument/result.
+ @param Arg2 Result.
+ @param Arg3 Result.
+
+ @return The SMC error code.
+
+**/
+UINTN
+ArmCallSmc1 (
+ IN UINTN Function,
+ IN OUT UINTN *Arg1 OPTIONAL,
+ OUT UINTN *Arg2 OPTIONAL,
+ OUT UINTN *Arg3 OPTIONAL
+ )
+{
+ return SMC_ARCH_CALL_NOT_SUPPORTED;
+}
+
+/** Trigger an SMC call with 0 arguments.
+
+ @param Function The SMC function.
+ @param Arg1 Result.
+ @param Arg2 Result.
+ @param Arg3 Result.
+
+ @return The SMC error code.
+
+**/
+UINTN
+ArmCallSmc0 (
+ IN UINTN Function,
+ OUT UINTN *Arg1 OPTIONAL,
+ OUT UINTN *Arg2 OPTIONAL,
+ OUT UINTN *Arg3 OPTIONAL
+ )
+{
+ return SMC_ARCH_CALL_NOT_SUPPORTED;
+}