summaryrefslogtreecommitdiff
path: root/MdeModulePkg/Library/ArmFfaLib
AgeCommit message (Collapse)AuthorFilesLines
2026-07-20MdePkg,MdeModulePkg: ArmFfaLib: Expand to include first 4 registersKun Qin1-3/+9
The direct message arguments stripped off the header, making the underlying FF-A function interface to lose information when it comes to certain return code, i.e. FFA_YIELD and FFA_INTERRUPT. This change adds back the header field for this purpose so that the callers can decide how to act on the corresponding return codes. It then populates the header field for this purpose in FFA direct message functions so that the callers can decide how to act on the corresponding return codes. Continuous-integration-options: PatchCheck.ignore-multi-package Signed-off-by: Kun Qin <kun.qin@microsoft.com>
2026-07-08MdeModulePkg/ArmFfaLib: Use EFI_PAGES_TO_SIZEMingjie Shen3-10/+10
Replace manual page-size multiplication with EFI_PAGES_TO_SIZE in the ArmFfaLib sources. This commit mimics 3457388 and is generated by the following coccinelle scipt: ```smpl @pages_to_size@ expression PAGE_COUNT; @@ - PcdGet64 (PAGE_COUNT) * EFI_PAGE_SIZE + EFI_PAGES_TO_SIZE (PcdGet64 (PAGE_COUNT)) ``` Tested: - stuart_ci_build -c .pytool/CISettings.py -p MdeModulePkg -a AARCH64 -t DEBUG TOOL_CHAIN_TAG=GCC - stuart_ci_build -c .pytool/CISettings.py -p MdeModulePkg -a AARCH64 -t RELEASE,NO-TARGET TOOL_CHAIN_TAG=GCC Signed-off-by: Mingjie Shen <shen497@purdue.edu>
2026-05-29MdeModulePkg/ArmFfaLib: return error when CurrentVersion is NULLYeoreum Yun1-3/+9
Output parameter CurrentVersion of ArmFfaLibGetVersion() is not optional parameter. That means it should return error when CurrentVersion is NULL. Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
2026-05-29MdeModulePkg/ArmFfaLib: Fix VM ID handling for RX release and RXTX unmapShenghu Liu4-12/+43
According to the FFA specification, when FFA_RX_RELEASE or FFA_RXTX_UNMAP is invoked from UEFI as a non-secure virtual instance, the w1 register must be zero (MBZ). Supplying a non-zero value causes the SPMC to return FFA_INVALID_PARAMETER. When these interfaces are invoked from UEFI as a non-secure physical instance, FFA_ID_GET always returns a VM ID of zero. Therefore, providing a non-zero VM ID in this context is unnecessary and may be invalid. Update ArmFfaLib to always set w1 (VM ID / partition ID) to zero when invoking FFA_RX_RELEASE and FFA_RXTX_UNMAP, ensuring compliance with the FFA specification. Signed-off-by: Shenghu Liu <shenghul@qti.qualcomm.com>
2026-04-28ArmPkg,MdePkg,MdeModulePkg: change ArmFfaLibGetVersion() with whole versionYeoreum Yun1-30/+14
Current ArmFfaLibGetVersion()'s arguments receive two arguments -- major version and minor version. However, This gives some impression treating major and minor version of the ABI as two unrelated 16-bit variables as opposed to the upper and lower 16-bits of a 32-bit version variable. Therefore, change the arguments with whole version and let user to get major/minor version via ARM_FFA_MAJOR/MINOR_VERSION_GET macros. Also, add some useful helper to check version compatibility and mimimum require ABI version. Continuous-integration-options: PatchCheck.ignore-multi-package Suggested-by: Leif Lindholm <quic_llindhol@quicinc.com> Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
2026-04-23MdeModulePkg/Library: ArmFfaLib: add mapping ARM_FFA_RET_RETRYYeoreum Yun1-0/+4
There is no mapping ARM_FFA_RET_RETRY with EFI_STATUS but it falls to EFI_UNSUPPORTED. Map ARM_FFA_RET_RETRY with EFI_TIMEOUT so that don't make it fall to EFI_UNSUPPORTED. Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
2026-03-09MdeModulePkg: Add library class SafeIntLib where ArmFfaCommon.c is usedMike Beaton5-0/+5
Required by implementation of ArmFfaLibYield. Fixes: 6479778e6b3890f65580bfbd50426046533b85a8 Signed-off-by: Mike Beaton <mjsbeaton@gmail.com>
2026-03-07MdePkg,MdeModulePkg: Add FFA_YIELD commandRaymond-MS1-0/+41
Add the FF-A YIELD command to the FF-A library. Continuous-integration-options: PatchCheck.ignore-multi-package Signed-off-by: Raymond Diaz <raymonddiaz@microsoft.com>
2026-03-04MdeModulePkg: Add FFA_NS_RES_INFO_GET to ArmFfaCommonrdiaz2-0/+68
Add FFA_NS_RES_INFO_GET implementation to ArmFfaCommon Signed-off-by: Raymond Diaz <raymonddiaz@microsoft.com>
2026-02-24MdeModulePkg: Replace include guards with #pragma onceMichael Kubacki2-8/+2
Replace traditional `#ifndef`/`#define`/`#endif` include guards with `#pragma` once. `#pragma once` is a widely supported preprocessor directive that prevents header files from being included multiple times. It is supported by all toolchains used to build edk2: GCC, Clang/LLVM, and MSVC. Compared to macro-based include guards, `#pragma once`: - Eliminates the risk of macro name collisions or copy/paste errors where two headers inadvertently use the same guard macro. - Eliminate inconsistency in the way include guard macros are named (e.g., some files use `__FILE_H__`, others use `FILE_H_`, etc.). - Reduces boilerplate (three lines replaced by one). - Avoids polluting the macro namespace with guard symbols. - Can improve build times as the preprocessor can skip re-opening the file entirely, rather than re-reading it to find the matching `#endif` ("multiple-include optimization"). - Note that some compilers may already optimize traditional include guards, by recognzining the idiomatic pattern. This change is made acknowledging that overall portability of the code will technically be reduced, as `#pragma once` is not part of the C/C++ standards. However, this is considered acceptable given: 1. edk2 already defines a subset of supported compilers in BaseTools/Conf/tools_def.template, all of which have supported `#pragma once` for over two decades. 2. There have been concerns raised to the project about inconsistent include guard naming and potential macro collisions. Approximate compiler support dates: - MSVC: Supported since Visual C++ 4.2 (1996) - GCC: Supported since 3.4 (2004) (http://gnu.ist.utl.pt/software/gcc/gcc-3.4/changes.html) - Clang (LLVM based): Since initial release in 2007 Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
2026-02-13MdeModulePkg: Add Unmap Callbackedk2-stable202602rdiaz7-0/+103
Add Unmap callback for when PEI and SEC need to invalidate the Rx/Tx buffer HOB on a call to Unmap. Signed-off-by: Raymond Diaz <raymonddiaz@microsoft.com>
2026-02-13MdeModulePkg: Code/Comment cleanuprdiaz6-29/+21
Cleaned various comments and debug messages as well as headers to either fix typos or for readability. Signed-off-by: Raymond Diaz <raymonddiaz@microsoft.com>
2026-02-13MdeModulePkg: Use EFI_PAGES_TO_SIZE macro in ArmFfaSecRxTxMaprdiaz1-9/+9
Replaced all instances of PcdGet64 (PcdFfaTxRxPageCount) * EFI_PAGE_SIZE, with EFI_PAGES_TO_SIZE macro. Signed-off-by: Raymond Diaz <raymonddiaz@microsoft.com>
2026-02-13MdeModulePkg: Remove global usage from ArmFfaSecRxTxMaprdiaz2-80/+125
Removed the global variables in ArmFfaSecRxTxMap. Rx/Tx buffer HOB is now created within the Map function rather than in the constructor of ArmFfaSecLib. This allows for the use of the HOB to find the Rx/Tx buffer information. Signed-off-by: Raymond Diaz <raymonddiaz@microsoft.com>
2026-02-13MdeModulePkg: Remove global usage in ArmFfaCommonrdiaz9-87/+289
Removed global variables in ArmFfaCommon. Moved the globals to locals in each phase's ArmFfaLib implementation. SEC and PEI will query when necessary to avoid setting globals when memory is unavailable. Signed-off-by: Raymond Diaz <raymonddiaz@microsoft.com>
2026-02-13MdeModulePkg: Add helper to check if FF-A is supportedrdiaz2-0/+57
Added ArmFfaLibIsFfaSupported to ArmFfaCommon to allow for queries of FF-A support outside of ArmFfaCommonInit. Signed-off-by: Raymond Diaz <raymonddiaz@microsoft.com>
2026-01-08MdePkg,MdeModulePkg/ArmFfaLib: introduce ArmFfaGetPartitionInfo()Levi Yun1-0/+80
Introduce ArmFfaGetPartitionInfo(), which retrieves the first partition associated with the service GUID. This allows us to remove duplicated code previously used to obtain the partition ID. Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com> Continuous-integration-options: PatchCheck.ignore-multi-package
2026-01-08MdeModulePkg/ArmFfaLib: support ArmFfaLib wihtout Rx/Tx bufferLevi Yun3-0/+63
In the normal world, it is possible to communicate with a secure partition using the ARM_FFA_PARTITION_INFO_GET_REGS ABI, even when the Rx/Tx buffer ABI is not supported. Therefore, treat the EFI_UNSUPPORTED error returned during Rx/Tx buffer mapping as a valid result when the ARM_FFA_PARTITION_INFO_GET_REGS ABI is supported. Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
2026-01-08MdePkg, MdeModulePkg/ArmFfaLib: add funcs to get partition info via regsLevi Yun1-0/+159
Starting from FF-A v1.2 [0], the FFA_PARTITION_INFO_GET_REGS interface was added to retrieve partition information through registers. This ABI is useful in environments where the Rx/Tx buffer does not need to be mapped, or where buffer mapping is not supported for retrieving partition information. To support this, two new APIs are introduced: ArmFfaLibPartitionInfoGetRegs() and ArmFfaLibPartitionCountGetRegs(). Link: https://developer.arm.com/documentation/den0077/latest [0] Continuous-integration-options: PatchCheck.ignore-multi-package Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
2025-10-31MdeModulePkg: ArmFfaLib: Add FFA_YIELD handlingkuqin121-1/+1
If a secure partition on AArch64 platforms would consume extended time to operate with peripherals, it might elect to yield the control back to normal world and expect the normal world to callback after hinted period of time. This change adds the FFA_YIELD handling from ArmFfaLib to support long operations from secure partitions. Timeout arguments are ignored because systems in this context cannot benefit from the timeout period. Treating FFA_YIELD like FFA_INTERRUPT and expecting the caller to invoke FFA_RUN is the least disruptive approach while achieving the intended behavior. This was tested on proprietary hardware platforms and booted to Windows. Signed-off-by: Kun Qin <kun.qin@microsoft.com>
2025-09-12MdeModulePkg/ArmFfaLib: Add MemoryAllocationLibMichael Kubacki5-0/+5
ArmFfaRxTxMap.c is built by both ArmFfaPeiLib and ArmFfaDxeLib. ArmFfaSecRxTxMap.c is built by ArmFfaSecLib. ArmFfaStandaloneMmRxTxMap.c is built by ArmFfaStandaloneMm*Lib. The files depend on `MemoryAllocationLib` APIs such as `AllocateAlignedPages()`. This change adds `MemoryAllocationLib` to those library INF files. Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
2025-09-12MdeModulePkg/ArmFfaLib: Add HobLib to StMm instancesMichael Kubacki2-0/+2
ArmFfaCommon.c is built by both ArmFfaStandaloneMmCoreLib and ArmFfaStandaloneMmLib. It links against HobLiib APIs such as `GetFirstHob()`. Right now, the symbols fail to link: ``` lld-link: error: undefined symbol: GetFirstHob ArmFfaStandaloneMmCoreLib.lib(ArmFfaCommon.obj) ``` Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
2025-09-08MdeModulePkg: consider UNSUPPORTED return as valid in ArmFfaStandaloneMmLibLevi Yun1-0/+13
commit b534cabbdac4 ("ArmFfaLib: Add Rx/Tx support for Stmm secure partition") makes ArmFfaStandlaoneMm(Core)Lib map Rx/Tx buffer in its constructor. This makes a failure of loading StandaloneMm in legacy platform which doesn't implements Rx/Tx buffer related API since it doesn't need to. StandaloneMm could be only service provider not cosumer in some platform where doesn't need to map RxTx buffer. Therefore, Considier EFI_UNSUPPORTED return in ArmFfaStandaloneMmLib's constructor. Fixes: b534cabbdac4 ("ArmFfaLib: Add Rx/Tx support for Stmm secure partition") Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
2025-09-08Global: fix ArmFfaLibRun() caller couldn't get ret-argsLevi Yun1-3/+38
When ArmFfaLibDirectMsgReq(2) is preempted, caller of these functions should resume it works via ArmFfaLibRun() and the secure partition will be return with FFA_DIRECT_MSG_RESP(2) with return arguments. However, since ArmFfaLibRun() gets its return in its stack variable, So caller of ArmFfaLibRun() doesn't get the return arguments from secure partition. To resolve this, add output parameter to ArmFfaLibRun() to receive return arguments. Continuous-integration-options: PatchCheck.ignore-multi-package Fixes: 5d1b38dd07c4 ("ArmPkg: Add ArmFfaLib used in Dxe driver") Reported-by: Mariam Elshakfy <Mariam.Elshakfy@arm.com> Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
2025-07-14MdeModulePkg/Include: change type of buffer address in ArmFfaRxTxBufferInfoLevi Yun5-8/+8
Change type of buffer address type in ArmFfaRxTxBufferInfo so that reduce the type casting. Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
2025-07-14MdeModulePkg/Library: commonize some duplicate code in ArmFfaLibLevi Yun5-225/+194
Some of code for handling Rx/Tx buffer is duplicate. This patch commonize some of duplication routine used in Rx/Tx buffer related functions. Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
2025-07-14MdeModulePkg/Library: add ArmFfaSecLibLevi Yun4-6/+535
To use Arm-FFA intereface in PeilessSec, implments ArmFfaSecLib used by PeilessSec. For example, communicate with TPM service using CRB over ARM-FFA (via Tpm2DeviceLibFfa), PeilessSec need to use Arm-FFA interface. Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
2025-07-14MdeModulePkg/Library: fix memory leak Rx/Tx Buffer in ArmFfaPeiLibLevi Yun6-49/+359
The commit e15fe066036da ("MdeModulePkg/Library: make ArmFfaPeiLib available early PEIM stage") uses ArmFfaPeiLib in the early PEIM stage. However, the Rx/Tx buffer allocated in the early PEIM stage uses temporary memory. This results in a memory leak when the temporary memory's heap is relocated to permanent memory. For example, if the Rx/Tx buffer memory is allocated at 0x20006000 in temporary memory, and if offset between temporary memory and permanent is 0x40000000, then: - Once permanent memory installed the temporary memory at 0x20006000 is migrated to 0x60006000. - However, ArmFfaPeiLib allocates new Rx/Tx buffer without freeing the migrated Rx/Tx buffers, i.e. the buffers at 0x60006000. This results in a memory leak as the migrated Rx/Tx buffer area is lost. To address this memory leak, use the MemoryAllocationHob's name, so that the migrated memory area will be reused as Rx/Tx buffer. This patch also includes rename ArmFfaRxTxStmm.c to ArmFfaStandaloneMmRxTxMap.c to keep the file name convention in ArmFfaLib with ArmFfa{Phase}{...}.c Fixes: e15fe066036da ("MdeModulePkg/Library: ...") Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com> Continuous-integration-options: PatchCheck.ignore-multi-package
2025-06-26MdePkg, MdeModulePkg: ArmFfaLib: Expose FFA_ARGS and ArmCallFfaKun Qin1-35/+1
FFA is a framework that supports various protocols built on top. i.e. memory protocol, which is nothing that can be done through existing interfaces. Instead of requiring protocol authors to check conduit PCD in every implementation, exposing the ArmCallFfa is a unified way to allow other protocols to leverage FFA interfaces. Continuous-integration-options: PatchCheck.ignore-multi-package Signed-off-by: Kun Qin <kun.qin@microsoft.com>
2025-06-26MdeModulePkg: ArmFfaLib: Add Rx/Tx support for Stmm secure partitionKun Qin4-28/+349
This change adds the support for mapping Rx/Tx buffer through the library constructor. The first mapper will produce an MM protocol instance with Rx/Tx information, which allows subsequent consumers to query the information. Signed-off-by: Kun Qin <kun.qin@microsoft.com>
2025-06-05MdeModulePkg: ArmFfaLib: Support UUID-GUID conversion interfacesKun Qin1-45/+2
This change moves the existing ConvertEfiGuidToUuid function to public interface to support newly defined functions prototypes. This change also adds the `ArmConvertUuidToEfiGuid` function implementation, which is an inverse of the original conversion. Signed-off-by: Kun Qin <kun.qin@microsoft.com>
2025-05-28MdeModulePkg/Library: make ArmFfaPeiLib available early PEIM stageLevi Yun2-5/+98
commit 26fb5edff397 ("MdeModulePkg/ArmFfaLib: Add depex on gEfiPeiMemoryDiscoveredPpiGuid") restricts ArmFfaPeiLib usage only after PEI phase can be used permanent memory. However, This would be problem for PEIM which runs before gEfiPeiMemoryDiscoveredPpiGuid Ppi installed. (i.e) Tcg2Pei PEIM. To resolve this, remove dependency on gEfiPeiMemoryDiscoveredPpiGuid and let ArmFfaPeiLib remap the Rx/Tx buffer after gEfiPeiMemoryDiscoveredPpiGuid is installed so that ArmFfaPeiLib can be used with temporary memory. Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com> Fixes: 26fb5edff397 ("MdeModulePkg/ArmFfaLib: ...")
2025-05-01ArmFfaLib: Replace SMCCC_VERSION check with FF-A version checkMohamed Gamal Morsy1-22/+19
Patch 8d03c42d38d1 ("ArmPkg: ArmFfaLib: Update FF-A direct message to support 18 registers") calls SMCCC_VERSION by default during FF-A initialization even if the SMC conduit is not enabled. This leads to sending malformed FF-A versions if the SVC conduit is used instead. This is observed for example when using an SPMC@EL-1 (e.g. rust-spmc) which receives the FF-A message via an SVC call and interprets SMCCC_VERSION as an FF-A Function ID and subsequently fails to handle it. Since 18-register support is only support with FF-A >= 1.2, replace SMCCC_VERSION check with FF-A version check Signed-off-by: Mohamed Gamal Morsy <mohamed.morsy@arm.com>
2025-04-23MdeModulePkg/ArmFfaLib: Add depex on gEfiPeiMemoryDiscoveredPpiGuidAnubhav Raina1-1/+4
If ArmFfaLibRxTxMap is called before permanent memory is installed the memory allocated for the FF-A buffers will be migrated to the permanent memory after it is installed without updating gArmFfaRxTxBufferInfoGuid or unmapping the old buffers and mapping the updated buffers. An ASSERT in MemoryServices at ExitBootServices is triggered when ArmFfaDxeLib tries to call FreeAlignedPages on the original buffer reference. Add depex on gEfiPeiMemoryDiscoveredPpiGuid for ArmFfaPeiLib so any Peims that use FF-A are only dispatched after permanent memory is available. Signed-off-by: Anubhav Raina <anubhav.raina@arm.com>
2025-04-10MdeModulePkg: ArmFfaLib: Move Rx/Tx hob definition to Include/Guid folderKun Qin3-17/+4
Currently, ArmFfaLib uses an internally defined Guided HOB to pass information about the Rx/Tx buffer set up by the first executing agent. However, the GUID definition is solely specified in the DEC file, which is inconsistent with other GUID definitions in MdeModulePkg. This change relocates the GUID definition to the Include/Guid folder to ensure consistency across the package. Signed-off-by: Kun Qin <kun.qin@microsoft.com>
2025-04-10ArmPkg: ArmFfaLib: Move ArmFfaLib implementation to MdeModulePkgKun Qin11-0/+1738
ArmFfaLib is an implementation of an industry specification-defined interface with UEFI specific method of handling Rx/Tx buffer sharing across multiple boot phases, which is more appropriately placed in MdeModulePkg. This update relocates the implementation of ArmFfaLib to MdeModulePkg, thereby supporting the FFA call primitives for all other packages that depend on this interface. Continuous-integration-options: PatchCheck.ignore-multi-package Signed-off-by: Kun Qin <kun.qin@microsoft.com>