diff --git a/Drivers/OpTee/OpteeRpmbPkg/OpTeeRpmbFv.inf b/Drivers/OpTee/OpteeRpmbPkg/OpTeeRpmbFv.inf index c3580859ff..4248ace658 100644 --- a/Drivers/OpTee/OpteeRpmbPkg/OpTeeRpmbFv.inf +++ b/Drivers/OpTee/OpteeRpmbPkg/OpTeeRpmbFv.inf @@ -30,6 +30,7 @@ [LibraryClasses] ArmSvcLib + ArmFfaLib BaseLib BaseMemoryLib DebugLib diff --git a/Drivers/OpTee/OpteeRpmbPkg/OpTeeRpmbFvb.c b/Drivers/OpTee/OpteeRpmbPkg/OpTeeRpmbFvb.c index 19252698b2..8b9946a0e1 100644 --- a/Drivers/OpTee/OpteeRpmbPkg/OpTeeRpmbFvb.c +++ b/Drivers/OpTee/OpteeRpmbPkg/OpTeeRpmbFvb.c @@ -7,7 +7,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#include +#include #include #include #include @@ -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; @@ -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;