diff options
author | Kun Qin <kuqin@microsoft.com> | 2025-03-20 15:59:06 -0700 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2025-06-26 17:38:28 +0000 |
commit | a0d78f6625c3c3f0e4bf6e7ff7002fa595033772 (patch) | |
tree | ec2c92c025de4d224915bd352deff296e177c77e | |
parent | 22142b4f4a7822872aed9281bf3a5994199754b3 (diff) | |
download | edk2-a0d78f6625c3c3f0e4bf6e7ff7002fa595033772.zip edk2-a0d78f6625c3c3f0e4bf6e7ff7002fa595033772.tar.gz edk2-a0d78f6625c3c3f0e4bf6e7ff7002fa595033772.tar.bz2 |
MdePkg: ArmFfaMemMgmtLib: Introduce FF-A memory protocol library
This change introduced a library interface that implements the FF-A
memory protocol v1.3 ALP1:
https://developer.arm.com/documentation/den0140/f
Signed-off-by: Kun Qin <kun.qin@microsoft.com>
-rw-r--r-- | MdePkg/Include/IndustryStandard/ArmFfaMemMgmt.h | 325 | ||||
-rw-r--r-- | MdePkg/Include/Library/ArmFfaMemMgmtLib.h | 289 | ||||
-rw-r--r-- | MdePkg/Library/ArmFfaMemMgmtLib/ArmFfaMemMgmtLib.c | 618 | ||||
-rw-r--r-- | MdePkg/Library/ArmFfaMemMgmtLib/ArmFfaMemMgmtLib.inf | 26 | ||||
-rw-r--r-- | MdePkg/MdePkg.dec | 4 | ||||
-rw-r--r-- | MdePkg/MdePkg.dsc | 1 |
6 files changed, 1263 insertions, 0 deletions
diff --git a/MdePkg/Include/IndustryStandard/ArmFfaMemMgmt.h b/MdePkg/Include/IndustryStandard/ArmFfaMemMgmt.h new file mode 100644 index 0000000..4f9d7c1 --- /dev/null +++ b/MdePkg/Include/IndustryStandard/ArmFfaMemMgmt.h @@ -0,0 +1,325 @@ +/** @file
+ Memory management protocol definitions as specfied in the FF-A Memory Management
+ v1.3 APL1 specification.
+
+ Copyright 2021 The Hafnium Authors.
+ Copyright (c), Microsoft Corporation.
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Glossary:
+ - FF-A - Firmware Framework for Arm A-profile
+
+ @par Reference(s):
+ - FF-A Version 1.3 ALP1 [https://developer.arm.com/documentation/den0077/l]
+ - FF-A Memory Management Protocol 1.3 ALP1 [https://developer.arm.com/documentation/den0140/f]
+
+**/
+
+#ifndef ARM_FFA_MEM_MGMT_H_
+#define ARM_FFA_MEM_MGMT_H_
+
+/**
+ Data access attributes in a memory access permission descriptor. This corresponds
+ to table 1.15 of the FF-A v1.3 APL1, "Memory access permissions descriptor",
+ bits[1:0].
+**/
+#define FFA_DATA_ACCESS_NOT_SPECIFIED 0
+#define FFA_DATA_ACCESS_RO 1
+#define FFA_DATA_ACCESS_RW 2
+#define FFA_DATA_ACCESS_RESERVED 3
+
+/**
+ Intruction access attributes in a memory access permission descriptor.
+
+ This corresponds to table 1.15 of the FF-A Memory Management v1.3 APL1, "Memory
+ access permissions descriptor", bits[3:2].
+**/
+#define FFA_INSTRUCTION_ACCESS_NOT_SPECIFIED 0
+#define FFA_INSTRUCTION_ACCESS_NX 1
+#define FFA_INSTRUCTION_ACCESS_X 2
+#define FFA_INSTRUCTION_ACCESS_RESERVED 3
+
+/**
+ Memory access permission struct definition of memory access permissions descriptor.
+
+ This corresponds to table 1.15 of the FF-A Memory Management v1.3 APL1, "Memory
+ region attributes descriptor".
+**/
+typedef struct {
+ UINT8 DataAccess : 2;
+ UINT8 InstructionAccess : 2;
+ UINT8 Reservd : 4;
+} FFA_MEMORY_ACCESS_PERMISSIONS;
+
+/**
+ Memory shareability attributes in a memory region attributes descriptor.
+
+ This corresponds to table 1.18 of the FF-A Memory Management v1.3 APL1, "Memory
+ region attributes descriptor", bits[1:0].
+**/
+#define FFA_MEMORY_SHARE_NON_SHAREABLE 0
+#define FFA_MEMORY_SHARE_RESERVED 1
+#define FFA_MEMORY_OUTER_SHAREABLE 2
+#define FFA_MEMORY_INNER_SHAREABLE 3
+
+/**
+ Memory cacheability or device memory attributes in a memory region attributes
+ descriptor.
+
+ This corresponds to table 1.18 of the FF-A Memory Management v1.3 APL1, "Memory
+ region attributes descriptor", bits[3:2].
+**/
+#define FFA_MEMORY_CACHE_RESERVED 0x0
+#define FFA_MEMORY_CACHE_NON_CACHEABLE 0x1
+#define FFA_MEMORY_CACHE_RESERVED_1 0x2
+#define FFA_MEMORY_CACHE_WRITE_BACK 0x3
+#define FFA_MEMORY_DEV_NGNRNE 0x0
+#define FFA_MEMORY_DEV_NGNRE 0x1
+#define FFA_MEMORY_DEV_NGRE 0x2
+#define FFA_MEMORY_DEV_GRE 0x3
+
+/**
+ Memory type in a memory region attributes descriptor.
+
+ This corresponds to table 1.18 of the FF-A Memory Management v1.3 APL1, "Memory
+ region attributes descriptor", bits[5:4].
+**/
+#define FFA_MEMORY_NOT_SPECIFIED_MEM 0
+#define FFA_MEMORY_DEVICE_MEM 1
+#define FFA_MEMORY_NORMAL_MEM 2
+
+/**
+ FF-A Memory Management v1.3 APL1 Table 1.18 "Memory region attributes descriptor"
+ bits[6]. Per section 1.10.4.1, NS bit is reserved for FFA_MEM_DONATE/LEND/SHARE
+ and FFA_MEM_RETRIEVE_REQUEST.
+**/
+#define FFA_MEMORY_SECURITY_SECURE 0
+#define FFA_MEMORY_SECURITY_NON_SECURE 1
+
+/**
+ Reserved bits (SBZ) of a memory region attributes descriptor.
+
+ This corresponds to table 1.18 of the FF-A Memory Management v1.3 APL1, "Memory
+ region attributes descriptor", bits[15:7].
+**/
+#define FFA_MEMORY_ATTRIBUTES_MBZ_MASK 0xFF80U
+
+/**
+ Memory region attributes struct definition of memory region attribute descriptor.
+
+ This corresponds to table 1.18 of the FF-A Memory Management v1.3 APL1, "Memory
+ region attributes descriptor".
+**/
+typedef struct {
+ UINT16 Shareability : 2;
+ UINT16 Cacheability : 2;
+ UINT16 Type : 2;
+ UINT16 Security : 1;
+ UINT16 Reserved : 9;
+} FFA_MEMORY_ATTRIBUTES;
+
+/**
+ A set of contiguous pages which is part of a memory region.
+
+ This corresponds to table 1.14 of the the FF-A Memory Management v1.3 APL1, "Constituent
+ memory region descriptor".
+**/
+typedef struct {
+ /**
+ The base IPA of the constituent memory region, aligned to 4 kiB page
+ size granularity.
+ **/
+ UINT64 Address;
+ /** The number of 4 kiB pages in the constituent memory region. **/
+ UINT32 PageCount;
+ /** Reserved field, SBZ. **/
+ UINT32 Reserved;
+} FFA_MEMORY_REGION_CONSTITUENT;
+
+/**
+ A set of pages comprising a memory region.
+
+ This corresponds to table 1.13 of the FF-A Memory Management v1.3 APL1, "Composite
+ memory region descriptor".
+**/
+typedef struct {
+ /**
+ The total number of 4 kiB pages included in this memory region. This
+ must be equal to the sum of page counts specified in each
+ `FFA_MEMORY_REGION_CONSTITUENT`.
+ **/
+ UINT32 TotalPageCount;
+
+ /**
+ The number of constituents (`FFA_MEMORY_REGION_CONSTITUENT`)
+ included in this memory region range.
+ **/
+ UINT32 ConstituentCount;
+ /** Reserved field, SBZ. */
+ UINT64 Reserved;
+ /** An array of `ConstituentCount` memory region constituents. */
+ FFA_MEMORY_REGION_CONSTITUENT Constituents[];
+} FFA_COMPOSITE_MEMORY_REGION;
+
+/**
+ Flags to indicate properties of memory management ABI being invoked.
+
+ This corresponds to table 1.17 of the FF-A Memory Management v1.3 APL1, "Flags
+ Flags usage in FFA_MEM_RETRIEVE_REQ and FFA_MEM_RETRIEVE_RESP ABIs", Bit[0].
+**/
+#define FFA_MEMORY_ACCESS_PERMISSION_FLAG_MASK ((0x1U) << 0)
+#define FFA_MEMORY_ACCESS_PERMISSION_FLAG_UNSPECIFIED ((0x0U) << 0)
+#define FFA_MEMORY_ACCESS_PERMISSION_FLAG_RETRIEVAL ((0x0U) << 0)
+#define FFA_MEMORY_ACCESS_PERMISSION_FLAG_NON_RETRIEVAL ((0x1U) << 0)
+
+/**
+ Memory region attributes descriptor.
+
+ This corresponds to table 1.15 of the FF-A Memory Management v1.3 APL1, "Memory
+ access permissions descriptor".
+**/
+typedef struct {
+ /** The ID of the VM to which the memory is being given or shared. **/
+ UINT16 ReceiverId;
+
+ /**
+ The permissions with which the memory region should be mapped in the
+ receiver's page table.
+ **/
+ FFA_MEMORY_ACCESS_PERMISSIONS Permissions;
+
+ /**
+ Flags used during FFA_MEM_RETRIEVE_REQ and FFA_MEM_RETRIEVE_RESP
+ for memory regions with multiple borrowers.
+ **/
+ UINT8 Flags;
+} FFA_MEMORY_ACCESS_PERMISSIONS_DESCRIPTOR;
+
+/**
+ Endpoint memory access descriptor.
+
+ This corresponds to table 1.16 of the FF-A Memory Management v1.3 APL1, "Endpoint
+ memory access descriptor".
+**/
+typedef struct {
+ FFA_MEMORY_ACCESS_PERMISSIONS_DESCRIPTOR ReceiverPermissions;
+
+ /**
+ Offset in bytes from the start of the outer `FFA_MEMORY_TRANSACTION_DESCRIPTOR` to
+ an `FFA_COMPOSITE_MEMORY_REGION` struct.
+ **/
+ UINT32 CompositeMemoryRegionOffset;
+ UINT8 ImpementationDefined[16];
+ UINT64 Reserved;
+} FFA_ENDPOINT_MEMORY_ACCESS_DESCRIPTOR;
+
+/**
+ Clear memory region contents after unmapping it from the sender and before
+ mapping it for any receiver.
+
+ This corresponds to table 1.22 of the FF-A Memory Management v1.3 APL1, "Flags
+ usage in FFA_MEM_RETRIEVE_REQ ABI", bits[0].
+**/
+#define FFA_MEMORY_REGION_FLAG_CLEAR 0x1
+
+/**
+ Whether the hypervisor may time slice the memory sharing or retrieval
+ operation.
+
+ This corresponds to table 1.22 of the FF-A Memory Management v1.3 APL1, "Flags
+ usage in FFA_MEM_RETRIEVE_REQ ABI", bits[1].
+**/
+#define FFA_MEMORY_REGION_FLAG_TIME_SLICE 0x2
+
+/**
+ Whether the hypervisor should clear the memory region after the receiver
+ relinquishes it or is aborted.
+
+ This corresponds to table 1.22 of the FF-A Memory Management v1.3 APL1, "Flags
+ usage in FFA_MEM_RETRIEVE_REQ ABI", bits[2].
+**/
+#define FFA_MEMORY_REGION_FLAG_CLEAR_RELINQUISH 0x4
+
+/**
+ Transaction type for memory region retrieval.
+
+ This corresponds to table 1.22 of the FF-A Memory Management v1.3 APL1, "Flags
+ usage in FFA_MEM_RETRIEVE_REQ ABI", bits[3].
+**/
+#define FFA_MEMORY_REGION_TRANSACTION_TYPE_MASK ((0x3U) << 3)
+#define FFA_MEMORY_REGION_TRANSACTION_TYPE_UNSPECIFIED ((0x0U) << 3)
+#define FFA_MEMORY_REGION_TRANSACTION_TYPE_SHARE ((0x1U) << 3)
+#define FFA_MEMORY_REGION_TRANSACTION_TYPE_LEND ((0x2U) << 3)
+#define FFA_MEMORY_REGION_TRANSACTION_TYPE_DONATE ((0x3U) << 3)
+
+/**
+ Address range hint for memory region retrieval.
+
+ This corresponds to table 1.22 of the FF-A Memory Management v1.3 APL1, "Flags
+ usage in FFA_MEM_RETRIEVE_REQ ABI", bits[9:5].
+**/
+#define FFA_MEMORY_REGION_ADDRESS_RANGE_HINT_VALID ((0x1U) << 9)
+#define FFA_MEMORY_REGION_ADDRESS_RANGE_HINT_MASK ((0xFU) << 5)
+
+/**
+ On retrieve request, bypass the multi-borrower check.
+
+ This corresponds to table 1.22 of the FF-A Memory Management v1.3 APL1, "Flags
+ usage in FFA_MEM_RETRIEVE_REQ ABI", bits[10].
+**/
+#define FFA_MEMORY_REGION_FLAG_BYPASS_BORROWERS_CHECK (0x1U << 10)
+
+/**
+ Information about a set of pages which are being shared.
+
+ This corresponds to table 1.20 of the FF-A Memory Management v1.3 APL1, "Memory
+ transaction descriptor". Note that it is also used for retrieve requests and responses.
+**/
+typedef struct {
+ /**
+ The ID of the VM which originally sent the memory region, i.e. the
+ owner.
+ **/
+ UINT16 SenderId;
+ FFA_MEMORY_ATTRIBUTES Attributes;
+ /** Flags to control behaviour of the transaction. **/
+ UINT32 Flags;
+ UINT64 Handle;
+
+ /**
+ An implementation defined value associated with the receiver and the
+ memory region.
+ **/
+ UINT64 Tag;
+ /** Size of the memory access descriptor. **/
+ UINT32 MemoryAccessDescSize;
+
+ /**
+ The number of `FFA_ENDPOINT_MEMORY_ACCESS_DESCRIPTOR` entries included in this
+ transaction.
+ **/
+ UINT32 ReceiverCount;
+
+ /**
+ Offset to the 'FFA_ENDPOINT_MEMORY_ACCESS_DESCRIPTOR' field, which relates to
+ the memory access descriptors.
+ **/
+ UINT32 ReceiversOffset;
+ /** Reserved field (12 bytes) SBZ. */
+ UINT8 Reserved[12];
+} FFA_MEMORY_TRANSACTION_DESCRIPTOR;
+
+/**
+ Descriptor used for FFA_MEM_RELINQUISH requests. This corresponds to table
+ 2.25 of the FF-A Memory Management v1.3 APL1, "Descriptor to relinquish a memory
+ region".
+**/
+typedef struct {
+ UINT64 Handle;
+ UINT32 Flags;
+ UINT32 EndpointCount;
+ UINT16 Endpoints[];
+} FFA_MEM_RELINQUISH_DESCRIPTOR;
+
+#endif
diff --git a/MdePkg/Include/Library/ArmFfaMemMgmtLib.h b/MdePkg/Include/Library/ArmFfaMemMgmtLib.h new file mode 100644 index 0000000..c52e15d --- /dev/null +++ b/MdePkg/Include/Library/ArmFfaMemMgmtLib.h @@ -0,0 +1,289 @@ +/** @file
+ Library definition for FF-A memory management protocol.
+
+ Copyright (c) 2020 - 2022, Arm Ltd. All rights reserved.<BR>
+ Copyright (c), Microsoft Corporation.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef ARM_FFA_MEM_MGMT_LIB_H_
+#define ARM_FFA_MEM_MGMT_LIB_H_
+
+#include <Uefi.h>
+
+/**
+ @brief Starts a transaction to transfer of ownership of a memory region
+ from a Sender endpoint to a Receiver endpoint.
+
+ @param[in] TotalLength Total length of the memory transaction descriptor
+ in bytes
+ @param[in] FragmentLength Length in bytes of the memory transaction descriptor
+ passed in this ABI invocation
+ @param[in] BufferAddr Base address of a buffer allocated by the Owner and
+ distinct from the TX buffer
+ @param[in] PageCount Number of 4K pages in the buffer allocated by the
+ Owner and distinct from the TX buffer
+ @param[out] Handle Globally unique Handle to identify the memory region
+ upon successful transmission of the transaction descriptor.
+
+ @retval The translated FF-A error status code
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaMemLibDonate (
+ IN UINT32 TotalLength,
+ IN UINT32 FragmentLength,
+ IN VOID *BufferAddr,
+ IN UINT32 PageCount,
+ OUT UINT64 *Handle
+ );
+
+/**
+ @brief Starts a transaction to transfer of ownership of a memory region
+ from a Sender endpoint to a Receiver endpoint.
+
+ @param[in] TotalLength Total length of the memory transaction descriptor
+ in bytes
+ @param[in] FragmentLength Length in bytes of the memory transaction descriptor
+ passed in this ABI invocation
+ @param[out] Handle Globally unique Handle to identify the memory region
+ upon successful transmission of the transaction descriptor.
+
+ @retval The translated FF-A error status code
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaMemLibDonateRxTx (
+ IN UINT32 TotalLength,
+ IN UINT32 FragmentLength,
+ OUT UINT64 *Handle
+ );
+
+/**
+ @brief Starts a transaction to transfer an Owner’s access to a memory
+ region and grant access to it to one or more Borrowers.
+
+ @param[in] TotalLength Total length of the memory transaction descriptor
+ in bytes
+ @param[in] FragmentLength Length in bytes of the memory transaction
+ descriptor passed in this ABI invocation
+ @param[in] BufferAddr Base address of a buffer allocated by the Owner
+ and distinct from the TX buffer
+ @param[in] PageCount Number of 4K pages in the buffer allocated by
+ the Owner and distinct from the TX buffer
+ @param[out] Handle Globally unique Handle to identify the memory
+ region upon successful transmission of the
+ transaction descriptor.
+
+ @retval The translated FF-A error status code
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaMemLibLend (
+ IN UINT32 TotalLength,
+ IN UINT32 FragmentLength,
+ IN VOID *BufferAddr,
+ IN UINT32 PageCount,
+ OUT UINT64 *Handle
+ );
+
+/**
+ @brief Starts a transaction to transfer an Owner’s access to a memory
+ region and grant access to it to one or more Borrowers through
+ Rx/Tx buffer.
+
+ @param[in] TotalLength Total length of the memory transaction descriptor
+ in bytes
+ @param[in] FragmentLength Length in bytes of the memory transaction descriptor
+ passed in this ABI invocation
+ @param[out] Handle Globally unique Handle to identify the memory region
+ upon successful transmission of the transaction descriptor.
+
+ @retval The translated FF-A error status code
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaMemLibLendRxTx (
+ IN UINT32 TotalLength,
+ IN UINT32 FragmentLength,
+ OUT UINT64 *Handle
+ );
+
+/**
+ @brief Starts a transaction to grant access to a memory region to one or
+ more Borrowers.
+
+ @param[in] TotalLength Total length of the memory transaction descriptor
+ in bytes
+ @param[in] FragmentLength Length in bytes of the memory transaction descriptor
+ passed in this ABI invocation
+ @param[in] BufferAddr Base address of a buffer allocated by the Owner and
+ distinct from the TX buffer
+ @param[in] PageCount Number of 4K pages in the buffer allocated by the
+ Owner and distinct from the TX buffer
+ @param[out] Handle Globally unique Handle to identify the memory region
+ upon successful transmission of the transaction descriptor.
+
+ @retval The translated FF-A error status code
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaMemLibShare (
+ IN UINT32 TotalLength,
+ IN UINT32 FragmentLength,
+ IN VOID *BufferAddr,
+ IN UINT32 PageCount,
+ OUT UINT64 *Handle
+ );
+
+/**
+ @brief Starts a transaction to grant access to a memory region to one or
+ more Borrowers through Rx/Tx buffer.
+
+ @param[in] TotalLength Total length of the memory transaction descriptor
+ in bytes
+ @param[in] FragmentLength Length in bytes of the memory transaction descriptor
+ passed in this ABI invocation
+ @param[out] Handle Globally unique Handle to identify the memory region
+ upon successful transmission of the transaction descriptor.
+
+ @retval The translated FF-A error status code
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaMemLibShareRxTx (
+ IN UINT32 TotalLength,
+ IN UINT32 FragmentLength,
+ OUT UINT64 *Handle
+ );
+
+/**
+ @brief Requests completion of a donate, lend or share memory management
+ transaction.
+
+ @param[in] TotalLength Total length of the memory transaction descriptor
+ in bytes
+ @param[in] FragmentLength Length in bytes of the memory transaction descriptor
+ passed in this ABI invocation
+ @param[in] BufferAddr Base address of a buffer allocated by the Owner
+ and distinct from the TX buffer
+ @param[in] PageCount Number of 4K pages in the buffer allocated by
+ the Owner and distinct from the TX buffer
+ @param[out] RespTotalLength Total length of the response memory transaction
+ descriptor in bytes
+ @param[out] RespFragmentLength Length in bytes of the response memory transaction
+ descriptor passed in this ABI invocation
+
+ @retval The translated FF-A error status code
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaMemLibRetrieveReq (
+ IN UINT32 TotalLength,
+ IN UINT32 FragmentLength,
+ IN VOID *BufferAddr,
+ IN UINT32 PageCount,
+ OUT UINT32 *RespTotalLength,
+ OUT UINT32 *RespFragmentLength
+ );
+
+/**
+ @brief Requests completion of a donate, lend or share memory management
+ transaction through Rx/Tx buffer.
+
+ @param[in] TotalLength Total length of the memory transaction descriptor
+ in bytes
+ @param[in] FragmentLength Length in bytes of the memory transaction descriptor
+ passed in this ABI invocation
+ @param[out] RespTotalLength Total length of the response memory transaction
+ descriptor in bytes
+ @param[out] RespFragmentLength Length in bytes of the response memory transaction
+ descriptor passed in this ABI invocation
+
+ @retval The translated FF-A error status code
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaMemLibRetrieveReqRxTx (
+ IN UINT32 TotalLength,
+ IN UINT32 FragmentLength,
+ OUT UINT32 *RespTotalLength,
+ OUT UINT32 *RespFragmentLength
+ );
+
+/**
+ @brief Starts a transaction to transfer access to a shared or lent
+ memory region from a Borrower back to its Owner.
+
+ @retval The translated FF-A error status code
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaMemLibRelinquish (
+ VOID
+ );
+
+/**
+ @brief Restores exclusive access to a memory region back to its Owner.
+
+ @param[in] Handle Globally unique Handle to identify the memory region
+ @param[in] Flags Flags for modifying the reclaim behavior
+
+ @retval The translated FF-A error status code
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaMemLibReclaim (
+ IN UINT64 Handle,
+ IN UINT32 Flags
+ );
+
+/**
+ @brief Queries the memory attributes of a memory region. This function
+ can only access the regions of the SP's own translation regine.
+ Moreover this interface is only available in the boot phase,
+ i.e. before invoking FFA_MSG_WAIT interface.
+
+ @param[in] BaseAddr Base VA of a translation granule whose
+ permission attributes must be returned.
+ @param[in] PageCount Number of translation granule size pages from the
+ Base address whose permissions must be returned.
+ This is calculated as Input Page count + 1.
+ @param[out] MemoryPerm Permission attributes of the memory region
+
+ @retval The translated FF-A error status code
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaMemLibPermGet (
+ IN CONST VOID *BaseAddr,
+ IN UINT32 PageCount,
+ OUT UINT32 *MemoryPerm
+ );
+
+/**
+ @brief Sets the memory attributes of a memory regions. This function
+ can only access the regions of the SP's own translation regine.
+ Moreover this interface is only available in the boot phase,
+ i.e. before invoking FFA_MSG_WAIT interface.
+
+ @param[in] BaseAddr Base VA of a memory region whose permission
+ attributes must be set.
+ @param[in] PageCount Number of translation granule size pages
+ starting from the Base address whose permissions
+ must be set.
+ @param[in] MemoryPerm Permission attributes to be set for the memory
+ region.
+
+ @retval The translated FF-A error status code
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaMemLibPermSet (
+ IN CONST VOID *BaseAddr,
+ IN UINT32 PageCount,
+ IN UINT32 MemoryPerm
+ );
+
+#endif // ARM_FFA_MEM_MGMT_LIB_H_
diff --git a/MdePkg/Library/ArmFfaMemMgmtLib/ArmFfaMemMgmtLib.c b/MdePkg/Library/ArmFfaMemMgmtLib/ArmFfaMemMgmtLib.c new file mode 100644 index 0000000..91dfd17 --- /dev/null +++ b/MdePkg/Library/ArmFfaMemMgmtLib/ArmFfaMemMgmtLib.c @@ -0,0 +1,618 @@ +// SPDX-License-Identifier: BSD-3-Clause
+
+/** @file
+ This library implements the FF-A memory manage protocol.
+
+ Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.
+ Copyright (c), Microsoft Corporation.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Glossary:
+ - FF-A - Firmware Framework for Arm A-profile
+
+ @par Reference(s):
+ - Arm Firmware Framework for Arm A-Profile v1.3 ALP1: [https://developer.arm.com/documentation/den0077/l]
+ - FF-A Memory Management Protocol [https://developer.arm.com/documentation/den0140/f]
+
+**/
+
+#include <Uefi.h>
+#include <IndustryStandard/ArmFfaMemMgmt.h>
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/ArmFfaLib.h>
+#include <Library/ArmFfaMemMgmtLib.h>
+#include <Library/BaseMemoryLib.h>
+
+/**
+ @brief Starts a transaction to transfer of ownership of a memory region
+ from a Sender endpoint to a Receiver endpoint.
+
+ @param[in] TotalLength Total length of the memory transaction descriptor
+ in bytes
+ @param[in] FragmentLength Length in bytes of the memory transaction descriptor
+ passed in this ABI invocation
+ @param[in] BufferAddr Base address of a buffer allocated by the Owner and
+ distinct from the TX buffer
+ @param[in] PageCount Number of 4K pages in the buffer allocated by the
+ Owner and distinct from the TX buffer
+ @param[out] Handle Globally unique Handle to identify the memory region
+ upon successful transmission of the transaction descriptor.
+
+ @retval The translated FF-A error status code
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaMemLibDonate (
+ IN UINT32 TotalLength,
+ IN UINT32 FragmentLength,
+ IN VOID *BufferAddr,
+ IN UINT32 PageCount,
+ OUT UINT64 *Handle
+ )
+{
+ ARM_FFA_ARGS FfaArgs;
+ EFI_STATUS Status;
+
+ if (Handle == NULL) {
+ DEBUG ((DEBUG_ERROR, "%a: Handle is NULL\n", __func__));
+ return EFI_INVALID_PARAMETER;
+ }
+
+ FfaArgs.Arg0 = ((UINTN)BufferAddr > MAX_UINT32) ? ARM_FID_FFA_MEM_DONATE_AARCH64 : ARM_FID_FFA_MEM_DONATE_AARCH32;
+
+ Status = ArmFfaLibGetFeatures (
+ FfaArgs.Arg0,
+ 0,
+ &FfaArgs.Arg1,
+ &FfaArgs.Arg2
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: Failed to get FFA_MEM_DONATE feature... Status: %r\n", __func__, Status));
+ *Handle = 0U;
+ return Status;
+ }
+
+ FfaArgs.Arg1 = TotalLength;
+ FfaArgs.Arg2 = FragmentLength;
+ FfaArgs.Arg3 = (UINTN)BufferAddr;
+ FfaArgs.Arg4 = PageCount;
+
+ ArmCallFfa (&FfaArgs);
+
+ if (FfaArgs.Arg0 == ARM_FID_FFA_ERROR) {
+ *Handle = 0U;
+ return FfaStatusToEfiStatus (FfaArgs.Arg2);
+ }
+
+ /**
+ There are no 64-bit parameters returned with FFA_SUCCESS, the SPMC
+ will use the default 32-bit version.
+ **/
+ ASSERT (FfaArgs.Arg0 == ARM_FID_FFA_SUCCESS_AARCH32);
+ *Handle = ((UINT64)FfaArgs.Arg3 << 32) | FfaArgs.Arg2;
+ return EFI_SUCCESS;
+}
+
+/**
+ @brief Starts a transaction to transfer of ownership of a memory region
+ from a Sender endpoint to a Receiver endpoint.
+
+ @param[in] TotalLength Total length of the memory transaction descriptor
+ in bytes
+ @param[in] FragmentLength Length in bytes of the memory transaction descriptor
+ passed in this ABI invocation
+ @param[out] Handle Globally unique Handle to identify the memory region
+ upon successful transmission of the transaction descriptor.
+
+ @retval The translated FF-A error status code
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaMemLibDonateRxTx (
+ IN UINT32 TotalLength,
+ IN UINT32 FragmentLength,
+ OUT UINT64 *Handle
+ )
+{
+ return ArmFfaMemLibDonate (TotalLength, FragmentLength, NULL, 0, Handle);
+}
+
+/**
+ @brief Starts a transaction to transfer an Owner’s access to a memory
+ region and grant access to it to one or more Borrowers.
+
+ @param[in] TotalLength Total length of the memory transaction descriptor
+ in bytes
+ @param[in] FragmentLength Length in bytes of the memory transaction
+ descriptor passed in this ABI invocation
+ @param[in] BufferAddr Base address of a buffer allocated by the Owner
+ and distinct from the TX buffer
+ @param[in] PageCount Number of 4K pages in the buffer allocated by
+ the Owner and distinct from the TX buffer
+ @param[out] Handle Globally unique Handle to identify the memory
+ region upon successful transmission of the
+ transaction descriptor.
+
+ @retval The translated FF-A error status code
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaMemLibLend (
+ IN UINT32 TotalLength,
+ IN UINT32 FragmentLength,
+ IN VOID *BufferAddr,
+ IN UINT32 PageCount,
+ OUT UINT64 *Handle
+ )
+{
+ ARM_FFA_ARGS FfaArgs;
+ EFI_STATUS Status;
+
+ if (Handle == NULL) {
+ DEBUG ((DEBUG_ERROR, "%a: Handle is NULL\n", __func__));
+ return EFI_INVALID_PARAMETER;
+ }
+
+ FfaArgs.Arg0 = ((UINTN)BufferAddr > MAX_UINT32) ? ARM_FID_FFA_MEM_LEND_AARCH64 : ARM_FID_FFA_MEM_LEND_AARCH32;
+
+ Status = ArmFfaLibGetFeatures (
+ FfaArgs.Arg0,
+ 0,
+ &FfaArgs.Arg1,
+ &FfaArgs.Arg2
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: Failed to get FFA_MEM_LEND feature... Status: %r\n", __func__, Status));
+ *Handle = 0U;
+ return Status;
+ }
+
+ FfaArgs.Arg1 = TotalLength;
+ FfaArgs.Arg2 = FragmentLength;
+ FfaArgs.Arg3 = (UINTN)BufferAddr;
+ FfaArgs.Arg4 = PageCount;
+
+ ArmCallFfa (&FfaArgs);
+
+ if (FfaArgs.Arg0 == ARM_FID_FFA_ERROR) {
+ *Handle = 0U;
+ return FfaStatusToEfiStatus (FfaArgs.Arg2);
+ }
+
+ /**
+ There are no 64-bit parameters returned with FFA_SUCCESS, the SPMC
+ will use the default 32-bit version.
+ **/
+ ASSERT (FfaArgs.Arg0 == ARM_FID_FFA_SUCCESS_AARCH32);
+ *Handle = ((UINT64)FfaArgs.Arg3 << 32) | FfaArgs.Arg2;
+ return EFI_SUCCESS;
+}
+
+/**
+ @brief Starts a transaction to transfer an Owner’s access to a memory
+ region and grant access to it to one or more Borrowers through
+ Rx/Tx buffer.
+
+ @param[in] TotalLength Total length of the memory transaction descriptor
+ in bytes
+ @param[in] FragmentLength Length in bytes of the memory transaction descriptor
+ passed in this ABI invocation
+ @param[out] Handle Globally unique Handle to identify the memory region
+ upon successful transmission of the transaction descriptor.
+
+ @retval The translated FF-A error status code
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaMemLibLendRxTx (
+ IN UINT32 TotalLength,
+ IN UINT32 FragmentLength,
+ OUT UINT64 *Handle
+ )
+{
+ return ArmFfaMemLibLend (TotalLength, FragmentLength, NULL, 0, Handle);
+}
+
+/**
+ @brief Starts a transaction to grant access to a memory region to one or
+ more Borrowers.
+
+ @param[in] TotalLength Total length of the memory transaction descriptor
+ in bytes
+ @param[in] FragmentLength Length in bytes of the memory transaction descriptor
+ passed in this ABI invocation
+ @param[in] BufferAddr Base address of a buffer allocated by the Owner and
+ distinct from the TX buffer
+ @param[in] PageCount Number of 4K pages in the buffer allocated by the
+ Owner and distinct from the TX buffer
+ @param[out] Handle Globally unique Handle to identify the memory region
+ upon successful transmission of the transaction descriptor.
+
+ @retval The translated FF-A error status code
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaMemLibShare (
+ IN UINT32 TotalLength,
+ IN UINT32 FragmentLength,
+ IN VOID *BufferAddr,
+ IN UINT32 PageCount,
+ OUT UINT64 *Handle
+ )
+{
+ ARM_FFA_ARGS FfaArgs;
+ EFI_STATUS Status;
+
+ if (Handle == NULL) {
+ DEBUG ((DEBUG_ERROR, "%a: Handle is NULL\n", __func__));
+ return EFI_INVALID_PARAMETER;
+ }
+
+ FfaArgs.Arg0 = ((UINTN)BufferAddr > MAX_UINT32) ? ARM_FID_FFA_MEM_SHARE_AARCH64 : ARM_FID_FFA_MEM_SHARE_AARCH32;
+
+ Status = ArmFfaLibGetFeatures (
+ FfaArgs.Arg0,
+ 0,
+ &FfaArgs.Arg1,
+ &FfaArgs.Arg2
+ );
+
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: Failed to get FFA_MEM_SHARE feature... Status: %r\n", __func__, Status));
+ *Handle = 0U;
+ return Status;
+ }
+
+ FfaArgs.Arg1 = TotalLength;
+ FfaArgs.Arg2 = FragmentLength;
+ FfaArgs.Arg3 = (UINTN)BufferAddr;
+ FfaArgs.Arg4 = PageCount;
+
+ ArmCallFfa (&FfaArgs);
+
+ if (FfaArgs.Arg0 == ARM_FID_FFA_ERROR) {
+ *Handle = 0U;
+ return FfaStatusToEfiStatus (FfaArgs.Arg2);
+ }
+
+ /**
+ There are no 64-bit parameters returned with FFA_SUCCESS, the SPMC
+ will use the default 32-bit version.
+ **/
+ ASSERT (FfaArgs.Arg0 == ARM_FID_FFA_SUCCESS_AARCH32);
+ *Handle = ((UINT64)FfaArgs.Arg3 << 32) | FfaArgs.Arg2;
+ return EFI_SUCCESS;
+}
+
+/**
+ @brief Starts a transaction to grant access to a memory region to one or
+ more Borrowers through Rx/Tx buffer.
+
+ @param[in] TotalLength Total length of the memory transaction descriptor
+ in bytes
+ @param[in] FragmentLength Length in bytes of the memory transaction descriptor
+ passed in this ABI invocation
+ @param[out] Handle Globally unique Handle to identify the memory region
+ upon successful transmission of the transaction descriptor.
+
+ @retval The translated FF-A error status code
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaMemLibShareRxTx (
+ IN UINT32 TotalLength,
+ IN UINT32 FragmentLength,
+ OUT UINT64 *Handle
+ )
+{
+ return ArmFfaMemLibShare (TotalLength, FragmentLength, NULL, 0, Handle);
+}
+
+/**
+ @brief Requests completion of a donate, lend or share memory management
+ transaction.
+
+ @param[in] TotalLength Total length of the memory transaction descriptor
+ in bytes
+ @param[in] FragmentLength Length in bytes of the memory transaction descriptor
+ passed in this ABI invocation
+ @param[in] BufferAddr Base address of a buffer allocated by the Owner
+ and distinct from the TX buffer
+ @param[in] PageCount Number of 4K pages in the buffer allocated by
+ the Owner and distinct from the TX buffer
+ @param[out] RespTotalLength Total length of the response memory transaction
+ descriptor in bytes
+ @param[out] RespFragmentLength Length in bytes of the response memory transaction
+ descriptor passed in this ABI invocation
+
+ @retval The translated FF-A error status code
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaMemLibRetrieveReq (
+ IN UINT32 TotalLength,
+ IN UINT32 FragmentLength,
+ IN VOID *BufferAddr,
+ IN UINT32 PageCount,
+ OUT UINT32 *RespTotalLength,
+ OUT UINT32 *RespFragmentLength
+ )
+{
+ ARM_FFA_ARGS FfaArgs;
+ EFI_STATUS Status;
+
+ if ((RespTotalLength == NULL) || (RespFragmentLength == NULL)) {
+ DEBUG ((DEBUG_ERROR, "%a: Handle is NULL\n", __func__));
+ return EFI_INVALID_PARAMETER;
+ }
+
+ FfaArgs.Arg0 = ((UINTN)BufferAddr > MAX_UINT32) ? ARM_FID_FFA_MEM_RETRIEVE_REQ_AARCH64 : ARM_FID_FFA_MEM_RETRIEVE_REQ_AARCH32;
+
+ Status = ArmFfaLibGetFeatures (
+ FfaArgs.Arg0,
+ 0,
+ &FfaArgs.Arg1,
+ &FfaArgs.Arg2
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: Failed to get FFA_MEM_RETRIEVE_REQ feature... Status: %r\n", __func__, Status));
+ *RespTotalLength = 0U;
+ *RespFragmentLength = 0U;
+ return Status;
+ }
+
+ FfaArgs.Arg1 = TotalLength;
+ FfaArgs.Arg2 = FragmentLength;
+ FfaArgs.Arg3 = (UINTN)BufferAddr;
+ FfaArgs.Arg4 = PageCount;
+
+ ArmCallFfa (&FfaArgs);
+
+ if (FfaArgs.Arg0 == ARM_FID_FFA_ERROR) {
+ *RespTotalLength = 0U;
+ *RespFragmentLength = 0U;
+ return FfaStatusToEfiStatus (FfaArgs.Arg2);
+ }
+
+ ASSERT (FfaArgs.Arg0 == ARM_FID_FFA_MEM_RETRIEVE_RESP);
+ *RespTotalLength = FfaArgs.Arg1;
+ *RespFragmentLength = FfaArgs.Arg2;
+ return EFI_SUCCESS;
+}
+
+/**
+ @brief Requests completion of a donate, lend or share memory management
+ transaction through Rx/Tx buffer.
+
+ @param[in] TotalLength Total length of the memory transaction descriptor
+ in bytes
+ @param[in] FragmentLength Length in bytes of the memory transaction descriptor
+ passed in this ABI invocation
+ @param[out] RespTotalLength Total length of the response memory transaction
+ descriptor in bytes
+ @param[out] RespFragmentLength Length in bytes of the response memory transaction
+ descriptor passed in this ABI invocation
+
+ @retval The translated FF-A error status code
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaMemLibRetrieveReqRxTx (
+ IN UINT32 TotalLength,
+ IN UINT32 FragmentLength,
+ OUT UINT32 *RespTotalLength,
+ OUT UINT32 *RespFragmentLength
+ )
+{
+ return ArmFfaMemLibRetrieveReq (
+ TotalLength,
+ FragmentLength,
+ NULL,
+ 0,
+ RespTotalLength,
+ RespFragmentLength
+ );
+}
+
+/**
+ @brief Starts a transaction to transfer access to a shared or lent
+ memory region from a Borrower back to its Owner.
+
+ @retval The translated FF-A error status code
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaMemLibRelinquish (
+ VOID
+ )
+{
+ ARM_FFA_ARGS FfaArgs;
+ EFI_STATUS Status;
+
+ FfaArgs.Arg0 = ARM_FID_FFA_MEM_RETRIEVE_RELINQUISH;
+
+ Status = ArmFfaLibGetFeatures (
+ FfaArgs.Arg0,
+ 0,
+ &FfaArgs.Arg1,
+ &FfaArgs.Arg2
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: Failed to get FFA_MEM_RETRIEVE_RELINQUISH feature... Status: %r\n", __func__, Status));
+ return Status;
+ }
+
+ ArmCallFfa (&FfaArgs);
+
+ if (FfaArgs.Arg0 == ARM_FID_FFA_ERROR) {
+ return FfaStatusToEfiStatus (FfaArgs.Arg2);
+ }
+
+ ASSERT (FfaArgs.Arg0 == ARM_FID_FFA_SUCCESS_AARCH32);
+ return EFI_SUCCESS;
+}
+
+/**
+ @brief Restores exclusive access to a memory region back to its Owner.
+
+ @param[in] Handle Globally unique Handle to identify the memory region
+ @param[in] Flags Flags for modifying the reclaim behavior
+
+ @retval The translated FF-A error status code
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaMemLibReclaim (
+ IN UINT64 Handle,
+ IN UINT32 Flags
+ )
+{
+ ARM_FFA_ARGS FfaArgs;
+ EFI_STATUS Status;
+ UINT32 HandleHi = 0;
+ UINT32 HandleLo = 0;
+
+ FfaArgs.Arg0 = ARM_FID_FFA_MEM_RETRIEVE_RECLAIM;
+
+ Status = ArmFfaLibGetFeatures (
+ FfaArgs.Arg0,
+ 0,
+ &FfaArgs.Arg1,
+ &FfaArgs.Arg2
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: Failed to get FFA_MEM_RETRIEVE_RECLAIM feature... Status: %r\n", __func__, Status));
+ return Status;
+ }
+
+ HandleHi = (Handle >> 32) & MAX_UINT32;
+ HandleLo = Handle & MAX_UINT32;
+
+ FfaArgs.Arg1 = HandleLo;
+ FfaArgs.Arg2 = HandleHi;
+ FfaArgs.Arg3 = Flags;
+
+ ArmCallFfa (&FfaArgs);
+
+ if (FfaArgs.Arg0 == ARM_FID_FFA_ERROR) {
+ return FfaStatusToEfiStatus (FfaArgs.Arg2);
+ }
+
+ ASSERT (FfaArgs.Arg0 == ARM_FID_FFA_SUCCESS_AARCH32);
+ return EFI_SUCCESS;
+}
+
+/**
+ @brief Queries the memory attributes of a memory region. This function
+ can only access the regions of the SP's own translation regine.
+ Moreover this interface is only available in the boot phase,
+ i.e. before invoking FFA_MSG_WAIT interface.
+
+ @param[in] BaseAddr Base VA of a translation granule whose
+ permission attributes must be returned.
+ @param[in] PageCount Number of translation granule size pages from the
+ Base address whose permissions must be returned.
+ This is calculated as Input Page count + 1.
+ @param[out] MemoryPerm Permission attributes of the memory region
+
+ @retval The translated FF-A error status code
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaMemLibPermGet (
+ IN CONST VOID *BaseAddr,
+ IN UINT32 PageCount,
+ OUT UINT32 *MemoryPerm
+ )
+{
+ ARM_FFA_ARGS FfaArgs;
+ EFI_STATUS Status;
+
+ if (MemoryPerm == NULL) {
+ DEBUG ((DEBUG_ERROR, "%a: Handle is NULL\n", __func__));
+ return EFI_INVALID_PARAMETER;
+ }
+
+ FfaArgs.Arg0 = ((UINTN)BaseAddr > MAX_UINT32) ? ARM_FID_FFA_MEM_PERM_GET_AARCH64 : ARM_FID_FFA_MEM_PERM_GET_AARCH32;
+
+ Status = ArmFfaLibGetFeatures (
+ FfaArgs.Arg0,
+ 0,
+ &FfaArgs.Arg1,
+ &FfaArgs.Arg2
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: Failed to get FFA_MEM_PERM_GET feature... Status: %r\n", __func__, Status));
+ return Status;
+ }
+
+ FfaArgs.Arg1 = (UINTN)BaseAddr;
+ FfaArgs.Arg2 = PageCount;
+
+ ArmCallFfa (&FfaArgs);
+
+ if (FfaArgs.Arg0 == ARM_FID_FFA_ERROR) {
+ return FfaStatusToEfiStatus (FfaArgs.Arg2);
+ }
+
+ ASSERT (FfaArgs.Arg0 == ARM_FID_FFA_SUCCESS_AARCH32);
+ *MemoryPerm = FfaArgs.Arg2;
+ return EFI_SUCCESS;
+}
+
+/**
+ @brief Sets the memory attributes of a memory regions. This function
+ can only access the regions of the SP's own translation regine.
+ Moreover this interface is only available in the boot phase,
+ i.e. before invoking FFA_MSG_WAIT interface.
+
+ @param[in] BaseAddr Base VA of a memory region whose permission
+ attributes must be set.
+ @param[in] PageCount Number of translation granule size pages
+ starting from the Base address whose permissions
+ must be set.
+ @param[in] MemoryPerm Permission attributes to be set for the memory
+ region.
+
+ @retval The translated FF-A error status code
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaMemLibPermSet (
+ IN CONST VOID *BaseAddr,
+ IN UINT32 PageCount,
+ IN UINT32 MemoryPerm
+ )
+{
+ ARM_FFA_ARGS FfaArgs;
+ EFI_STATUS Status;
+
+ ASSERT ((MemoryPerm & ARM_FFA_MEM_PERM_RESERVED_MASK) == 0);
+
+ FfaArgs.Arg0 = ((UINTN)BaseAddr > MAX_UINT32) ? ARM_FID_FFA_MEM_PERM_SET_AARCH64 : ARM_FID_FFA_MEM_PERM_SET_AARCH32;
+
+ Status = ArmFfaLibGetFeatures (
+ FfaArgs.Arg0,
+ 0,
+ &FfaArgs.Arg1,
+ &FfaArgs.Arg2
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: Failed to get FFA_MEM_PERM_SET feature... Status: %r\n", __func__, Status));
+ return Status;
+ }
+
+ FfaArgs.Arg1 = (UINTN)BaseAddr;
+ FfaArgs.Arg2 = PageCount;
+ FfaArgs.Arg3 = MemoryPerm;
+
+ ArmCallFfa (&FfaArgs);
+
+ if (FfaArgs.Arg0 == ARM_FID_FFA_ERROR) {
+ return FfaStatusToEfiStatus (FfaArgs.Arg2);
+ }
+
+ ASSERT (FfaArgs.Arg0 == ARM_FID_FFA_SUCCESS_AARCH32);
+ return EFI_SUCCESS;
+}
diff --git a/MdePkg/Library/ArmFfaMemMgmtLib/ArmFfaMemMgmtLib.inf b/MdePkg/Library/ArmFfaMemMgmtLib/ArmFfaMemMgmtLib.inf new file mode 100644 index 0000000..6c3df96 --- /dev/null +++ b/MdePkg/Library/ArmFfaMemMgmtLib/ArmFfaMemMgmtLib.inf @@ -0,0 +1,26 @@ +#/** @file
+#
+# Component description file for ArmFfaMemMgmtLib module
+#
+# Copyright (c), Microsoft Corporation.
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+#**/
+
+[Defines]
+ INF_VERSION = 1.29
+ BASE_NAME = ArmFfaMemMgmtLib
+ FILE_GUID = CC121A12-7C90-46BB-89B8-5F5BAEEFFF12
+ MODULE_TYPE = BASE
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = ArmFfaMemMgmtLib
+
+[Sources.common]
+ ArmFfaMemMgmtLib.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ DebugLib
+ ArmFfaLib
diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index 23d315e..43b0973 100644 --- a/MdePkg/MdePkg.dec +++ b/MdePkg/MdePkg.dec @@ -370,6 +370,10 @@ #
ArmFfaLib|Include/Library/ArmFfaLib.h
+ ## @libraryclass Provides an interface to Arm's Firmware Framework for A-profile (FF-A) memory management functions.
+ #
+ ArmFfaMemMgmtLib|Include/Library/ArmFfaMemMgmtLib.h
+
[Guids]
#
# GUID defined in UEFI2.1/UEFI2.0/EFI1.1
diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index 7525573..2abd7b8 100644 --- a/MdePkg/MdePkg.dsc +++ b/MdePkg/MdePkg.dsc @@ -210,6 +210,7 @@ MdePkg/Library/ArmSmcLib/ArmSmcLib.inf
MdePkg/Library/ArmSmcLibNull/ArmSmcLibNull.inf
MdePkg/Library/ArmSvcLib/ArmSvcLib.inf
+ MdePkg/Library/ArmFfaMemMgmtLib/ArmFfaMemMgmtLib.inf
[Components.RISCV64]
MdePkg/Library/BaseRiscVSbiLib/BaseRiscVSbiLib.inf
|