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>
This commit removes an wrong goto statement which may cause DXE_ASSERT!
`ConfigRequest` example: `&NameValueVar0&NameValueVar1&NameValueVar2`.
When `*Progress` is `&NameValueVar2`, code will run to `goto Done;`,
then return NULL.
Signed-off-by: Yang Gang <yanggang@byosoft.com.cn>
When using MM communicate v3 to fetch variable, the header calculation
was incorrect, causing the variable driver on the secure environment to
have random behavior.
This change refactored the original routine by following the current
DXE instance (mostly).
Signed-off-by: Kun Qin <kun.qin@microsoft.com>
`if (CurrentForm != NULL)` and
`if (InScopeDisable && (CurrentForm == NULL))`conflict.
`if (CurrentForm != NULL)` should be `if (CurrentExpression != NULL)`.
Signed-off-by: Yang Gang <yanggang@byosoft.com.cn>
This PR introduces a new feature to enable infinite boot retries based on a newly created PCD.
When true, the system will continuously loop over all boot options.
PCD default is FALSE to match existing functionality.
This change is tested on QEMU based virtual platforms and physical
platforms.
This change is useful for certain server cases. Infinite retries allows
a server to continuously attempt boot in case of network failure and
recovery, and for such attempts to be accurately recorded in the TCG
logs.
Co-authored-by: Kun Qin <kun.qin@microsoft.com>
Co-authored-by: Aaron Pop <aaron.pop@microsoft.com>
Co-authored-by: Michael Kubacki <michael.kubacki@microsoft.com>
Signed-off-by: Sherry Fan <sherryfan@microsoft.com>
MdeModulePkg/Universal/CapsuleOnDiskLoadPei/CapsuleOnDiskLoadPei.c:176:11: error: variable ‘Index’ set but not used [-Werror=unused-but-set-variable=]
176 | UINTN Index;
| ^~~~~
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiGenFromFv.c: In function ‘ParseFv’:
MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiGenFromFv.c:263:34: error: variable ‘FfsIndex’ set but not used [-Werror=unused-but-set-variable=]
263 | UINTN FfsIndex;
| ^~~~~~~~
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
MdeModulePkg/Universal/DisplayEngineDxe/ProcessOptions.c: In function ‘CreateSharedPopUp’:
MdeModulePkg/Universal/DisplayEngineDxe/ProcessOptions.c:590:11: error: variable ‘Count’ set but not used [-Werror=unused-but-set-variable=]
590 | UINTN Count;
| ^~~~~
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
MdeModulePkg/Universal/SmbiosMeasurementDxe/SmbiosMeasurementDxe.c: In function ‘GetSmbiosStringById’:
MdeModulePkg/Universal/SmbiosMeasurementDxe/SmbiosMeasurementDxe.c:221:10: error: variable ‘Size’ set but not used [-Werror=unused-but-set-variable=]
221 | UINTN Size;
| ^~~~
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.c: In function ‘CreateDialog’:
MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.c:435:18: error: variable ‘Count’ set but not used [-Werror=unused-but-set-variable=]
435 | UINTN Count;
| ^~~~~
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Add a retry mechanism to UsbMassReadBlocks() to improve robustness
when reading from USB mass storage devices. Some USB devices may
experience transient failures during read operations that can be
recovered by resetting the device and retrying.
The implementation:
- Saves original buffer parameters (Buffer, Lba, BufferSize)
- Attempts the read operation up to 4 times (initial + 3 retries)
- Resets the device via UsbMassReset() before each retry
- Restores buffer parameters before each retry attempt
This change is compliant with USB Mass Storage Class Bulk-Only
Transport Spec Rev 1.0:
- Section 5.3.4: Defines Reset Recovery procedure
- Section 3.1: States device is ready for next CBW after reset
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Jacek Kolakowski <jacek.kolakowski@intel.com>
Signed-off-by: Paul Grimes <Paul.Grimes@amd.com>
P2P bridge Memory Base/Limit registers (0x20-0x22) only support 32-bit
addresses. Previously, MEM64 resources behind such bridges were always
degraded to MEM32, forcing allocation below 4GB. This can lead to
resource constraints when using massive storage (such as MPF drives)
as MEM32 space is limited on most platforms.
Based on PCIe Base Specification 6.3+, assigning 64-bit resources
irrespective of the prefetchable/non-prefetchable BAR bit is allowed.
In DegradeResource(), if an upstream bridge supports PMEM64, MEM64
resources are now degraded to PMEM64 first. This enables 64-bit BAR
allocation for devices like NVMe controllers that declare non-
prefetchable 64-bit BARs.
We still fall back to MEM32 degradation if the bridge lacks PMEM64
support as well.
Ref: PCI-SIG ECN "Removing Prefetchable Terminology" (2024-04-05)
Ref: PCIe Base Specification 6.3+
Signed-off-by: Kun Qin <kuqin12@gmail.com>
The documentation of InstallPpi() and NotifyPpi() in both the spec and
function comment indicate to return EFI_OUT_OF_RESOURCES if memory
allocation fails.
However, the implementation of those two services assert if memory
allocation fails. This is a mismatch between what the function expected to
return and what actually returns.
Fix this by returning EFI_OUT_OF_RESOURCES if memory allocation fails,
so the code matches the documentation and comply with the spec. It is
expected service consumers(callers of these functions) to handle
failures appriciately.
Signed-off-by: Khalid Ali <khaliidcaliy@gmail.com>
Fix alignment issues in memory map entries returned by
GetMemoryMap() when RUNTIME_PAGE_ALLOCATION_GRANULARITY is
larger than DEFAULT_PAGE_ALLOCATION_GRANULARITY.
There are no issues in the Page/Pool Allocation/Free services.
Logic issues issues are addressed in the memory map returned
by GetMemoryMap() due to missing cases for memory map entries
of type EfiConventionalMemory that overlap special memory bins.
Add logic to handle all possible memory map splits required to
convert internal memory map entries into an EFI Memory Map with
EFI Memory Map entries the follow alignment requirements when
the EFI Memory Map entries cover memory bins.
The four cases that must be handled are:
* Memory map entry contained within a bin. [Already covered]
Convert memory map entry type
* Memory map entry overlaps beginning of bin. [Added]
Split memory map entry at beginning of bin.
* Memory map entry overlaps end of bin. [Added]
Split memory map entry at end of bin.
* Memory map entry overlaps entire bin. [Added]
Split memory map entry at both ends of bin.
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
Fix alignment issues in memory map entries returned by
GetMemoryMap() when RUNTIME_PAGE_ALLOCATION_GRANULARITY is
larger than DEFAULT_PAGE_ALLOCATION_GRANULARITY.
Alignment issues are addressed in the initial memory map
layout when Memory Type Information is provided with memory
bins that use RUNTIME_PAGE_ALLOCATION_GRANULARITY.
There are no issues in the Page/Pool Allocation/Free services.
* CoreSetMemoryTypeInformationRange() make sure there is room
for all bins when accounting for alignment requirements.
Allocate space for bins with base and length following
alignment requirements.
* CoreSetMemoryTypeInformationRange() round up NumberOfPages in
Memory Type Information based on alignment requirements.
This is required so GetMemoryMap() will generate memory
map entries that always follow alignment requirements.
* CoreAddMemoryDescriptor() round up NumberOfPages in
Memory Type Information based on alignment requirements.
This is required so GetMemoryMap() will generate memory
map entries that always follow alignment requirements.
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
The comment for the Buffer parameter incorrectly said
"then no the size" instead of "then the size".
This patch fixes the typo only; no functional changes.
Reported-by: Yao Zi <ziyao@disroot.org>
Signed-off-by: Dongyan Qian <qiandongyan@loongson.cn>
The comment for the Buffer parameter incorrectly said
"then no the size" instead of "then the size".
This patch fixes the typo only; no functional changes.
Signed-off-by: Dongyan Qian <qiandongyan@loongson.cn>
The RSDP table come from ACPI HOB which may no store in the
EfiACPIReclaimMemory-type memory. Therefore need to reserve an
EfiACPIReclaimMemory-type memory for it.
Signed-off-by: George Liao <george.liao@intel.com>
In StandaloneMM mode, IsStatusCodeUsingSerialPort is expecting to
find gMmStatusCodeUseSerialHobGuid, and will assert if it is not found.
Change the logic so that if the Guided Hob is not found, to let
the function return FALSE and progress to proceed.
Signed-off-by: Aaron Pop <aaronpop@microsoft.com>
When StartBusNumber is 0xFF NextNumber would overflow and wrap back to 0.
This will be bypass check NextNumber > MaxNumberInRange as a result
PCI enumeration will continue instead of breaking due to lack of resources.
Signed-off-by: Arkadiusz Filipowski <arkadiusz.filipowski@intel.com>
This commit adds a host based unit test for DxeReportStatusCodeLib
that ensures that the platform cannot invert the TPL on an initial
call to ReportStatusCode functionality.
Signed-off-by: Joey Vagedes <joey.vagedes@gmail.com>
This commit stops the library from querying the protocol database for
the status code protocol at the time of library function use. This logic
can result in a TPL inversion if the protocol has not yet been cached
and the caller is calling the library function when the TPL is higher
then TPL_NOTIFY.
Instead, the protocol is now located during the constructor of the
library. If the protocol is not found, then an on-protocol install event
is registered which will cache the protocol. A destructor is also added
to close the event in the scenario that the driver is unloaded before
the protocol is installed.
Signed-off-by: Joey Vagedes <joey.vagedes@gmail.com>
This commit stops the library from querying the protocol database for
the status code protocol at the time of library function use. This logic
can result in a TPL inversion if the protocol has not yet been cached
and the caller is calling the library function when the TPL is higher
then TPL_NOTIFY.
Instead, the protocol is now located during the constructor of the
library. If the protocol is not found, then an on-protocol install event
is registered which will cache the protocol. A destructor is also added
to close the event in the scenario that the driver is unloaded before
the protocol is installed.
Signed-off-by: Joey Vagedes <joey.vagedes@gmail.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>
In the current code, the HiiPackageList will be created and destroyed
each time the form is closed, which is unneccessary. This patch makes a
function that produces the origin HiiPackageList. The function will only
be called when the driver is initialized and the HiiPackageList will be
directly updated in DriverHealthManagerCleanDynamicString function. This
approach can avoid the unneccessary creation and destruction of the
HiiPackageList.
Signed-off-by: Qihang Gao <gaoqihang@loongson.cn>
The DriverHealthManagerStrings.uni file defines both English and French
languages, resulting in the generation of two Unicode string packages: the
first for English and the second for French. When cleaning the dynamic
strings from the HII package list, the pointer which should point to
dynamic string package incorrectly points to the static French package,
causing it to be unexpectedly cleaned.
This patch fixes the pointer of EFI_HII_PACKAGE_END type PackageHeader.
This way, there is no need for concern regarding the number of language
packages available.
Signed-off-by: Qihang Gao <gaoqihang@loongson.cn>
Commit 2d69507a4d added an attribute check to
prevent freeing memory that is read-only, read-protected, or for which
attribute retrieval fails. In such cases the code returned EFI_SUCCESS and
leaked the memory.
This introduced a regression in the System Architecture Compliance Suite
(ACS) BS.FreePages – Not Existent Memory test.
Link: https://github.com/tianocore/edk2-test/blob/edk2-test-stable202509/uefi-sct/Doc/TestCaseSpec/03_Services_Boot_Services.md#freepages
Test number: 5.1.2.2.1
GetMemoryAttributes() returns EFI_UNSUPPORTED for memory regions outside
system memory. The previous change treated all errors as a reason to leak
memory, while only the EFI_NO_MAPPING error code should trigger that
behavior. As a result, freeing non-existent memory incorrectly returned
EFI_SUCCESS instead of EFI_NOT_FOUND.
To fix this, memory is now leaked only when:
- GetMemoryAttributes() returns EFI_NO_MAPPING (inconsistent attributes),
or
- GetMemoryAttributes() succeeds and the pages are marked RO or RP.
All other errors fall through to CoreInternalFreePages(), restoring the
previous and correct behavior.
Signed-off-by: Piotr Wejman <piotr.wejman@arm.com>
After Execute UFS SCSI Commands, the Trd->PRDTL is dirty. It will cause issue
when next UFS DM Command is executed.
According to UFSHCI Spec, for UFS DeviceManagement function Trd->PRDTL
must be set to Zero.
Signed-off-by: Black.Li <black.li@cixtech.com>
Update GCC Family to undefined _MSC_VER to match settings used
by other compilers. This addresses clang compatibility issues
for host-based unit test builds.
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
Correct a typographical error in the DebugServicePei module by renaming
the function and entry point from DebugSerivceInitialize to
DebugServiceInitialize in both the C source file and the INF
configuration file.
Signed-off-by: Jeremy Compostella <jeremy.compostella@intel.com>
11687 introduced a null check and break on the orderedlist
carriage return input handler. The carriage return is a special
case that should result in exiting the menu, but the null check
that prevented null pointer access changed the logic to continue
in the input wait loop.
Removed the break while still preventing null variable access
and allow function to exit.
11689 introduced checks on the call to EfiBootManagerGetLoadOptions,
but this encounterd a problem with the way that a default
platform recovery option was created.
The default platform recovery option was attempting to go through
existing recovery options to get the next available recovery option
number. The introduced null check short circuited these additional
calls and resulted in the platform recovery option not being created.
Modified the logic to no longer attempt to access recovery options
when non exist, and still create the default platform recovery option.
Signed-off-by: Aaron Pop <aaronpop@microsoft.com>
The changes introduced by ff3c1ad which made two calls to
ProcessOpRomImage() resulted a platform where single OpRom present, the
same image to be loaded and started.
Prevent loading and starting same image twice.
Signed-off-by: Khalid Ali <khaliidcaliy@gmail.com>
Suggested-by: Ard Biesheuvel <ardb@kernel.org>
Issue:https://github.com/tianocore/edk2/issues/11800
If there are multiple Option ROM images existed, current code will load
the first image that the emulator supports. Usually, x86 ROM image is
the first one and non-x86 ROM image is behind x86 ROM image. When the
emulator is introduced, x86 ROM image instead of native image is loaded
on non-x86 platforms.
This patch introduces a mechanism to prioritize the loading of native
images. Firstly, search the native image. If the native one is found,
just finish the process since the goal is reached. Otherwise, search
the foriegn images that the platform may support.
Signed-off-by: Qihang Gao <gaoqihang@loongson.cn>
Signed-off-by: Chao Li <lichao@loongson.cn>
Suggested-by: Ard Biesheuvel <ardb@kernel.org>
Tested-by: Chen Zhang <zhangchen@loongson.cn>
Cc: Dongyan Qian <qiandongyan@loongson.cn>
11686, 11687, 11688, 11689 included some inverted conditionals
during the refactor. While the system booted, some behavior
was incorrect based on the inverted conditionals.
Signed-off-by: Aaron Pop <aaronpop@microsoft.com>
Replace UINTN casts with EFI_PHYSICAL_ADDRESS in places where the result
is negated, as otherwise, the top bits may remain 0 unexpectedly.
VS2022 started warning about this, and thus breaking the IA32 CI build.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Address the build regressions, introduced in #11724, #11688, #11686#11685.
These build regressions are for uninitialized variables before use.
Signed-off-by: Aaron Pop <aaronpop@microsoft.com>
The function headers for FillWriteBuffer have become out of
date with the implementation. Update the function headers
to more clearly define the interface for recent changes.
Signed-off-by: Aaron Pop <aaronpop@microsoft.com>
Since VariableLock compromises security in the SMM environment,
it is deprecated. Used VariablePolicy instead for stronger and
more flexible UEFI variable protection.
Ref: [acd66e4]
Cc: Sachin Ganesh <sachinganesh@ami.com>
Signed-off-by: Sathya Ravichandran <sathyar@ami.com>