Skip to content

Commit

Permalink
Driver/Optee: apply ffa library
Browse files Browse the repository at this point in the history
Instead of using Svc directly to request storage operation,
use ArmFfaLib.
Also, memory endpoint is no more used. so remove it.

Signed-off-by: Levi Yun <[email protected]>
  • Loading branch information
LeviYeoReum committed Oct 23, 2024
1 parent eb9df20 commit 733eb5a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 40 deletions.
1 change: 1 addition & 0 deletions Drivers/OpTee/OpteeRpmbPkg/OpTeeRpmbFv.inf
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

[LibraryClasses]
ArmSvcLib
ArmFfaLib
BaseLib
BaseMemoryLib
DebugLib
Expand Down
62 changes: 22 additions & 40 deletions Drivers/OpTee/OpteeRpmbPkg/OpTeeRpmbFvb.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <Library/ArmSvcLib.h>
#include <Library/ArmFfaLib.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
Expand All @@ -27,12 +27,11 @@
// Since the FFA autodiscovery mechanism is not yet implemented we are
// hardcoding the ID values for the two operations OP-TEE currently supports
//
// mMemMgrId is used to set the page permissions after relocating the executable
// mStorageId is used to access the RPMB partition via OP-TEE
// In both cases the return value is located in x3. Once the autodiscovery mechanism
// is in place, we'll have to account for an error value in x2 as well, handling
// the autodiscovery failed scenario
STATIC CONST UINT16 mMemMgrId = 3U;
//
STATIC CONST UINT16 mStorageId = 4U;

STATIC MEM_INSTANCE mInstance;
Expand Down Expand Up @@ -63,48 +62,31 @@ ReadWriteRpmb (
IN UINTN Offset
)
{
ARM_SVC_ARGS SvcArgs;
EFI_STATUS Status;

ZeroMem (&SvcArgs, sizeof (SvcArgs));

SvcArgs.Arg0 = ARM_SVC_ID_FFA_MSG_SEND_DIRECT_REQ;
SvcArgs.Arg1 = mStorageId;
SvcArgs.Arg2 = 0;
SvcArgs.Arg3 = SvcAct;
SvcArgs.Arg4 = Addr;
SvcArgs.Arg5 = NumBytes;
SvcArgs.Arg6 = Offset;

ArmCallSvc (&SvcArgs);
if (SvcArgs.Arg3) {
DEBUG ((DEBUG_ERROR, "%a: Svc Call 0x%08x Addr: 0x%08x len: 0x%x Offset: 0x%x failed with 0x%x\n",
__func__, SvcAct, Addr, NumBytes, Offset, SvcArgs.Arg3));
}
EFI_STATUS Status;
DIRECT_MSG_ARGS StorageArgs;

switch (SvcArgs.Arg3) {
case ARM_SVC_SPM_RET_SUCCESS:
Status = EFI_SUCCESS;
break;
ZeroMem (&StorageArgs, sizeof (StorageArgs));

case ARM_SVC_SPM_RET_NOT_SUPPORTED:
Status = EFI_UNSUPPORTED;
break;
StorageArgs.Arg0 = SvcAct;
StorageArgs.Arg1 = Addr;
StorageArgs.Arg2 = NumBytes;
StorageArgs.Arg3 = Offset;

case ARM_SVC_SPM_RET_INVALID_PARAMS:
Status = EFI_INVALID_PARAMETER;
break;

case ARM_SVC_SPM_RET_DENIED:
Status = EFI_ACCESS_DENIED;
break;
Status = ArmFfaLibMsgDirectReq (
mStorageId,
0,
&StorageArgs
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: Failed to call ffa direct message request.\n", __func__));
return Status;
}

case ARM_SVC_SPM_RET_NO_MEMORY:
Status = EFI_OUT_OF_RESOURCES;
break;
Status = FfaStatusToEfiStatus (StorageArgs.Arg0);

default:
Status = EFI_ACCESS_DENIED;
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: SvcAct(0x%08x), Addr(0x%08x), NumBytes(0x%x), Offset(0x%x) failed with 0x%x\n",
__func__, SvcAct, Addr, NumBytes, Offset, StorageArgs.Arg0));
}

return Status;
Expand Down

0 comments on commit 733eb5a

Please sign in to comment.