The MISC_MM_COMMUNICATE_BUFFER stored the FF-A direct message
registers in a DIRECT_MSG_ARGS structure. Populating and reading it
required manually re-indexing every register (EventSvcArgs->Arg4..Arg17
into DirectMsgArgs.Arg0..Arg13). This shifted the register positions and
left the buffer layout inconsistent with the raw FF-A argument register
file, making it error prone to correlate a slot with its architectural
register.
Signed-off-by: Kun Qin <kun.qin@microsoft.com>
Add ArmSmcccSocIdLib to provide a shared interface for checking support
for the SMCCC Architecture SoC ID service and retrieving the JEP106
identification code and SoC revision.
Move the existing SMCCC SoC ID handling out of ProcessorSubClassDxe and
update the driver to use the new library. Continue to use the MIDR value
for the SMBIOS Processor ID when the SMCCC SoC ID service is unavailable.
This allows other SMBIOS implementations to reuse the SMCCC handling
without duplicating it or depending on the legacy ProcessorSubClassDxe
driver.
Signed-off-by: Varshit Pandya <Varshit.Pandya@arm.com>
NanoSecondDelay() currently has a microsecond rounding/precision.
Re-implement the function to have a nanosecond precision.
A MulDivWithRounding() function is added to allow ticks to
nanoseconds or nanoseconds to ticks conversions. This
function is now also used in GetTimeInNanoSecond().
MicroSecondDelay() now relies on NanoSecondDelay() to avoid
having a duplicated implementation.
Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
[Packages] appears twice in ArmStandaloneMmCoreEntryPoint.inf, remove the
redundant one to make the file more concise.
Signed-off-by: Qihang Gao <gaoqihang@loongson.cn>
In GetMemoryPermissions(), PageCount from FFA_MEM_PERM_GET couldn't
be over EFI_SIZE_TO_PAGES(Length) otherwise that's bug of SPMC.
But, current ASSERT() checks PageCount > EFI_SIZE_TO_PAGES(Length)
which is reverse condition for validation.
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
In StandaloneMm, the allowed memory permission combinations are ROX, RO,
and RW.
At the initial stage, all regions are mapped as ROX.
When drivers are loaded for relocation, the image is first mapped as RW.
However, the current mechanism introduces significant overhead
when changing memory permissions. For example, when changing permissions
from ROX to RW, the process is performed in two steps:
1. Clear the execute (X) permission (ROX → RO)
2. Add the write (W) permission (RO → RW)
To execute step (1), the system first retrieves the permissions of
the target region. This may trigger multiple SMC calls,
depending on the permissions of the pages within that region.
This permission retrieval operation is redundant, as there is no need
to maintain an intermediate state. Nevertheless,
it can cause additional SMC calls and coherence operations
from the SPMC (e.g., TLB flushes).
Therefore, this redundant operation should be removed, and in most cases,
the memory permission should be updated with a single
“set memory permission” operation.
Note:
The ArmxxxMemoryRegionxxx() interfaces e.g. ArmSetMemoryRegionNoExec(),
etc. return success when the Length parameter is 0 as
the SectionHeader.Misc.VirtualSize could be 0 Length
like .reloc section:
UpdateMmFoundationPeCoffPermissions: Section 2 of image at 0x7004000
has 0x42000040 permissions
UpdateMmFoundationPeCoffPermissions: Section 2 of image at 0x7004000
has .reloc name
api_ffa_mem_perm_set page_count 0
ERROR: FFA_MEM_PERM_SET: page_count was zero
Continuous-integration-options: PatchCheck.ignore-multi-package
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
Some functions in ArmMmuStandaloneMmLib lack documentation.
Add appropriate documentation for each function.
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
This is preparatory patch to optimize memory permission change
operations for StandaloneMm.
Make Version parameter of IsFfaMemoryAbiSupported() as optional.
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
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>
commit 4ca452c ("ArmPkg/Library: Update StandaloneMmuLib with
FF-A v1.2 with page granularity") introduced page-granular memory
permission updates to fix the StandaloneMm load failure.
However, this approach results in issuing an SMC call
per page when updating permissions over a region.
Since FF-A Memory Management Protocol v1.3 [0],
FFA_MEM_PERM_GET has been updated to return the number of contiguous
pages that share the same memory permission starting from a base address.
With this change, update memory permissions in bulk
(per contiguous page range) to reduce the number of SMC calls,
leveraging FF-A Memory Management Protocol v1.3 [0].
Link: https://developer.arm.com/documentation/den0140/latest [0]
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
Per
https://edk2.groups.io/g/devel/topic/move_armlib_to_baselib/118541649,
this commit moves ArmLib to MdePkg and updates all consumers.
The only change to ArmLib itself is to remove ArmPkg.dec from
the inf.
Continuous-integration-options: PatchCheck.ignore-multi-package
Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
This provides access to the Auxilary ID register, AIDR_EL1.
Continuous-integration-options: PatchCheck.ignore-multi-package
Signed-off-by: Ka-in Ng <kainng@os.amperecomputing.com>
ClangPdb/Msvc do not align the virtual address section lengths.
This needs to be handled by the loader to ensure that lengths are
aligned correctly.
Found while compiling Standalone Mm for a virtual platform using
ClangPdb. This has been masked in GCC/ClangDwarf builds by
GenFw conversion enforcing section alignments during conversion.
Signed-off-by: Aaron Pop <aaronpop@microsoft.com>
The current code uses `0xFUL` for stack alignment. Since this is only specified
to be an unsigned long, it may only be translated to 0xFFFFFFF0 in compilation
using LL64. In this case, if the stack resides above 4GB, the high bits of the
pointer will be truncated. This will cause a data abort immediately when
pushing to the exception stack.
This occurs specifically when using ClangPDB which uses LL64. This is not
observed in GCC because it uses LP64 where unsigned long is 64 bits.
This commit simply changes the mask to `0xFULL` to ensure that the full 64-bit
pointer is correctly masked for alignment in all configurations.
Signed-off-by: Chris Fernald <chfernal@microsoft.com>
ArmLibPrivate.h header file is unused. The header was included in
AArch64Lib.c and ArmLib.c but none of its symbols were actually used.
Remove unused private header file. No functional changes.
Signed-off-by: Vishal Oliyil Kunnil <vishalo@qti.qualcomm.com>
Remove deprecated branch prediction control APIs from ArmLib and their
callers. These interfaces are not required on AArch64 and do not have
any valid in-tree consumers.
Signed-off-by: Vishal Oliyil Kunnil <vishalo@qti.qualcomm.com>
Guid gEfiMmCommunicateHeaderV3Guid is consumed in
ValidateMmCommBufferAddr, but the Guid is not defined
in the INF guids section, resulting in a build error
of unresolved external.
Signed-off-by: Aaron Pop <aaronpop@microsoft.com>
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>
Replacing the non-ASCII characters with ASCII characters fixes build failures onWindows systems using non-English locales. These characters trigger MSVC warningC4819 (“file contains a character that cannot be represented in the current codepage”), which becomes an error when /WX is enabled.
Cc: Sachin Ganesh <sachinganesh@ami.com>
Signed-off-by: dhiineshm <dhiineshm@ami.com>
Pass ARM_MM_HANDLER_CONTEXT to MmHandler
so it can determine:
- whether the request came via FF-A or SPM_MM mode
- the service type
- whether it is a secure request or the source partition ID
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
To verify whether MM communication uses a secure buffer,
introduce the IsSecureMmCommBufferAddr() function.
This is a preparatory patch for MM context generation on Arm.
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
CLANGPDB catches that ArmTransferListLib does not include
all of the libraries it requires. This adds them.
Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
ArmStandaloneMmCoreEntryPoint supports a scenario of building
StandaloneMmCore into OP-TEE and doing self-relocation. This
requires a PIE image, which PE targets do not support. As such,
this scenario is not supported for CLANGPDB.
This commit updates the comment and scopes -fpie to GCC/CLANGDWARF.
Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
Currently, there exists VECTOR_BASE, VECTOR_ENTRY, and VECTOR_END
macros for defining things such as exception vectors. They are
intended to be used as follows:
VECTOR_BASE()
VECTOR_ENTRY()
<some code>
<more VECTOR_ENTRY() code pairings>
VECTOR_END()
This creates a non-enforceable requirement to do this, if
VECTOR_END isn't used, the vector size isn't enforced and
the image section won't be restored to .text. This commit
removes VECTOR_BASE and VECTOR_END and creates a
VECTOR_TABLE macro that encapsulates the behavior of the
two macros, sandwiching the developer provided VECTOR_ENTRY
and code pairings inbetween.
This enforces that VECTOR_BASE and VECTOR_END are used together
and correctly set up/tear down the vector area.
This commit also updates the only users of these macros at the
same time to avoid a build breakage.
Continuous-integration-options: PatchCheck.ignore-multi-package
Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
The ExceptionHandlersEnd symbol is placed in the wrong
section because it comes after the VECTOR_END macro.
However, this symbol is also completely unused, so this
commit removes it.
Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
Ref:[059332b]
Rootcause: The SectionLength was incorrectly computed using
the FFS_FILE_SIZE() macro. This macro operates on the
EFI_FFS_FILE_HEADER structure, which is incompatible with the
SECTION_SIZE header format.
This mismatch introduces a potential defect due to inaccurate
section size calculation.
Solution: To ensure correctness and structural alignment,
SectionLength must be computed using the SECTION_SIZE macro
defined in MdePkg\Include\Pi\PiFirmwareFile.h.
This macro performs size extraction using byte-wise access.
Cc: Sachin Ganesh <sachinganesh@ami.com>
Signed-off-by: Gowtham M <gowthamm@ami.com>
RootCause: SectionSize, SectionLength and FileLength are declared as
UINTN, UINTN and UINT32 but are typecast to UINT32 and masked
with 0x00FFFFFF to store only the lower 24 bits.
Although this approach yields the correct result,
it introduces a potential security vulnerability due to
unsafe typecasting and dereferencing.
Solution: Using the predefined macro FFS_FILE_SIZE()
from MdePkg\Include\Pi\PiFirmwareFile.h,
which safely performs the same operation by reconstruct
the size using individual byte access.
Cc: Sachin Ganesh <sachinganesh@ami.com>
Signed-off-by: Gowtham M <gowthamm@ami.com>
By edk2 convention, a NULL library should be called *LibNull.
ArmMtlNullLib did not follow this convention, so rename it
ArmMtlLibNull.
Signed-off-by: Leif Lindholm <leif.lindholm@oss.qualcomm.com>
edk2 is dropping support for the ARM32 architecture. This
commit removes ARM32 code from the remaining parts of ArmPkg.
Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
edk2 is dropping support for the ARM32 architecture. This
commit removes ARM32 files from ArmLib.
Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
edk2 is dropping support for the ARM32 architecture. This
commit removes ARM32 files from ArmHvcLib.
Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
edk2 is dropping support for the ARM32 architecture. This
commit removes ARM32 files from ArmMonitorLib.
Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
edk2 is dropping support for the ARM32 architecture. This
commit removes ARM32 files from ArmExceptionLib.
Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
edk2 is dropping support for the ARM32 architecture. This
commit removes ARM32 files from ArmStandaloneMmCoreEntryPoint.
Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
edk2 is dropping support for the ARM32 architecture. This
commit removes ARM32 files from DefaultExceptionHandlerLib.
Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
edk2 is dropping support for the ARM32 architecture. This
commit removes ARM32 files from SemiHostLib and SemiHostFs.
Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
edk2 is dropping support for the ARM32 architecture. This
commit removes comments mentioning ARM32 and ARM32 as a
supported arch in ArmPkg.
Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
Added functionality TransferList Library
TransferListVerifyChecksum - Verify TransferList CheckSum
TransferListCheckHeader - Check if TransferList header is valid,
return suitable opcodes validating the header
TransferListFindEntry - Find a specific entry on the TransferList
using the TagId
TransferListDump - Dump the contents of the TransferList header
and the entry headers
Signed-off-by: Prachotan Reddy Bathi <Prachotan.Bathi@arm.com>
The Universal Graphics Adapter (UGA) is a graphic abstraction.
The UGA I/O and Draw protocols are deprecated since UEFI 2.0 was
introduced. Cf. the UEFI spec v2.9:
"Appendix L - EFI 1.10 Protocol Changes and Deprecation List"
section L.2 "Deprecated Protocols"
Remove the UGA support.
Signed-off-by: GuoMinJ <newexplorerj@gmail.com>
Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
Move ArmMmuLib from ArmPkg to UefiCpuPkg for easy maintaining.
Continuous-integration-options: PatchCheck.ignore-multi-package
Signed-off-by: Ajan Zhong <ajan.zhong@newfw.com>