diff mbox series

[edk2,v1,1/1] ArmPkg/OpteeLib: Add dummy RPC handler

Message ID 1544011065-31305-1-git-send-email-sumit.garg@linaro.org
State New
Headers show
Series [edk2,v1,1/1] ArmPkg/OpteeLib: Add dummy RPC handler | expand

Commit Message

Sumit Garg Dec. 5, 2018, 11:57 a.m. UTC
Add dummy RPC handler for RPCs that are not implemented as control
should be returned back to OP-TEE in case any RPC is invoked.

Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Sumit Garg <sumit.garg@linaro.org>

---
 ArmPkg/Library/OpteeLib/OpteeSmc.h |  3 ++
 ArmPkg/Library/OpteeLib/Optee.c    | 34 ++++++++++++++++----
 2 files changed, 30 insertions(+), 7 deletions(-)

-- 
2.7.4

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Comments

Ard Biesheuvel Dec. 6, 2018, 4:58 p.m. UTC | #1
On Wed, 5 Dec 2018 at 12:58, Sumit Garg <sumit.garg@linaro.org> wrote:
>

> Add dummy RPC handler for RPCs that are not implemented as control

> should be returned back to OP-TEE in case any RPC is invoked.

>

> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>

> Cc: Leif Lindholm <leif.lindholm@linaro.org>

> Contributed-under: TianoCore Contribution Agreement 1.1

> Signed-off-by: Sumit Garg <sumit.garg@linaro.org>


Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>


Pushed as bc39c5cbea30..088a5334809d

Thanks

> ---

>  ArmPkg/Library/OpteeLib/OpteeSmc.h |  3 ++

>  ArmPkg/Library/OpteeLib/Optee.c    | 34 ++++++++++++++++----

>  2 files changed, 30 insertions(+), 7 deletions(-)

>

> diff --git a/ArmPkg/Library/OpteeLib/OpteeSmc.h b/ArmPkg/Library/OpteeLib/OpteeSmc.h

> index 9cccd81810c9..6209782aaed7 100644

> --- a/ArmPkg/Library/OpteeLib/OpteeSmc.h

> +++ b/ArmPkg/Library/OpteeLib/OpteeSmc.h

> @@ -25,6 +25,9 @@

>

>  #define OPTEE_SMC_SHARED_MEMORY_CACHED          1

>

> +#define OPTEE_SMC_RETURN_UNKNOWN_FUNCTION       0xffffffff

> +#define OPTEE_SMC_RETURN_RPC_PREFIX_MASK        0xffff0000

> +#define OPTEE_SMC_RETURN_RPC_PREFIX             0xffff0000

>  #define OPTEE_SMC_RETURN_RPC_FOREIGN_INTERRUPT  0xffff0004

>

>  #define OPTEE_MESSAGE_COMMAND_OPEN_SESSION      0

> diff --git a/ArmPkg/Library/OpteeLib/Optee.c b/ArmPkg/Library/OpteeLib/Optee.c

> index 55dcc7853b59..ed2a03c593c2 100644

> --- a/ArmPkg/Library/OpteeLib/Optee.c

> +++ b/ArmPkg/Library/OpteeLib/Optee.c

> @@ -123,6 +123,17 @@ OpteeInit (

>    return EFI_SUCCESS;

>  }

>

> +STATIC

> +BOOLEAN

> +IsOpteeSmcReturnRpc (

> +  UINT32 Return

> +  )

> +{

> +  return (Return != OPTEE_SMC_RETURN_UNKNOWN_FUNCTION) &&

> +         ((Return & OPTEE_SMC_RETURN_RPC_PREFIX_MASK) ==

> +          OPTEE_SMC_RETURN_RPC_PREFIX);

> +}

> +

>  /**

>    Does Standard SMC to OP-TEE in secure world.

>

> @@ -147,13 +158,22 @@ OpteeCallWithArg (

>    while (TRUE) {

>      ArmCallSmc (&ArmSmcArgs);

>

> -    if (ArmSmcArgs.Arg0 == OPTEE_SMC_RETURN_RPC_FOREIGN_INTERRUPT) {

> -      //

> -      // A foreign interrupt was raised while secure world was

> -      // executing, since they are handled in UEFI a dummy RPC is

> -      // performed to let UEFI take the interrupt through the normal

> -      // vector.

> -      //

> +    if (IsOpteeSmcReturnRpc (ArmSmcArgs.Arg0)) {

> +      switch (ArmSmcArgs.Arg0) {

> +      case OPTEE_SMC_RETURN_RPC_FOREIGN_INTERRUPT:

> +        //

> +        // A foreign interrupt was raised while secure world was

> +        // executing, since they are handled in UEFI a dummy RPC is

> +        // performed to let UEFI take the interrupt through the normal

> +        // vector.

> +        //

> +        break;

> +

> +      default:

> +         // Do nothing in case RPC is not implemented.

> +        break;

> +      }

> +

>        ArmSmcArgs.Arg0 = OPTEE_SMC_RETURN_FROM_RPC;

>      } else {

>        break;

> --

> 2.7.4

>

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
diff mbox series

Patch

diff --git a/ArmPkg/Library/OpteeLib/OpteeSmc.h b/ArmPkg/Library/OpteeLib/OpteeSmc.h
index 9cccd81810c9..6209782aaed7 100644
--- a/ArmPkg/Library/OpteeLib/OpteeSmc.h
+++ b/ArmPkg/Library/OpteeLib/OpteeSmc.h
@@ -25,6 +25,9 @@ 
 
 #define OPTEE_SMC_SHARED_MEMORY_CACHED          1
 
+#define OPTEE_SMC_RETURN_UNKNOWN_FUNCTION       0xffffffff
+#define OPTEE_SMC_RETURN_RPC_PREFIX_MASK        0xffff0000
+#define OPTEE_SMC_RETURN_RPC_PREFIX             0xffff0000
 #define OPTEE_SMC_RETURN_RPC_FOREIGN_INTERRUPT  0xffff0004
 
 #define OPTEE_MESSAGE_COMMAND_OPEN_SESSION      0
diff --git a/ArmPkg/Library/OpteeLib/Optee.c b/ArmPkg/Library/OpteeLib/Optee.c
index 55dcc7853b59..ed2a03c593c2 100644
--- a/ArmPkg/Library/OpteeLib/Optee.c
+++ b/ArmPkg/Library/OpteeLib/Optee.c
@@ -123,6 +123,17 @@  OpteeInit (
   return EFI_SUCCESS;
 }
 
+STATIC
+BOOLEAN
+IsOpteeSmcReturnRpc (
+  UINT32 Return
+  )
+{
+  return (Return != OPTEE_SMC_RETURN_UNKNOWN_FUNCTION) &&
+         ((Return & OPTEE_SMC_RETURN_RPC_PREFIX_MASK) ==
+          OPTEE_SMC_RETURN_RPC_PREFIX);
+}
+
 /**
   Does Standard SMC to OP-TEE in secure world.
 
@@ -147,13 +158,22 @@  OpteeCallWithArg (
   while (TRUE) {
     ArmCallSmc (&ArmSmcArgs);
 
-    if (ArmSmcArgs.Arg0 == OPTEE_SMC_RETURN_RPC_FOREIGN_INTERRUPT) {
-      //
-      // A foreign interrupt was raised while secure world was
-      // executing, since they are handled in UEFI a dummy RPC is
-      // performed to let UEFI take the interrupt through the normal
-      // vector.
-      //
+    if (IsOpteeSmcReturnRpc (ArmSmcArgs.Arg0)) {
+      switch (ArmSmcArgs.Arg0) {
+      case OPTEE_SMC_RETURN_RPC_FOREIGN_INTERRUPT:
+        //
+        // A foreign interrupt was raised while secure world was
+        // executing, since they are handled in UEFI a dummy RPC is
+        // performed to let UEFI take the interrupt through the normal
+        // vector.
+        //
+        break;
+
+      default:
+         // Do nothing in case RPC is not implemented.
+        break;
+      }
+
       ArmSmcArgs.Arg0 = OPTEE_SMC_RETURN_FROM_RPC;
     } else {
       break;