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>
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>
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>
Replaced all instances of PcdGet64 (PcdFfaTxRxPageCount) *
EFI_PAGE_SIZE, with EFI_PAGES_TO_SIZE macro.
Signed-off-by: Raymond Diaz <raymonddiaz@microsoft.com>
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>
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>
Added ArmFfaLibIsFfaSupported to ArmFfaCommon to allow for
queries of FF-A support outside of ArmFfaCommonInit.
Signed-off-by: Raymond Diaz <raymonddiaz@microsoft.com>
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
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>
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>
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>
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>
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>
commit b534cabbda ("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: b534cabbda ("ArmFfaLib: Add Rx/Tx support for Stmm secure partition")
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
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: 5d1b38dd07 ("ArmPkg: Add ArmFfaLib used in Dxe driver")
Reported-by: Mariam Elshakfy <Mariam.Elshakfy@arm.com>
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
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>
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>
The commit e15fe06603
("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: e15fe06603 ("MdeModulePkg/Library: ...")
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
Continuous-integration-options: PatchCheck.ignore-multi-package
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>
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>
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>
commit 26fb5edff3
("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: 26fb5edff3 ("MdeModulePkg/ArmFfaLib: ...")
Patch 8d03c42d38 ("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>