IntelFsp2Pkg: Replace include guards with #pragma once

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>
This commit is contained in:
Michael Kubacki 2026-02-03 13:35:59 -05:00 committed by mergify[bot]
parent 58ace50a43
commit 86047d4742
27 changed files with 27 additions and 107 deletions

View file

@ -5,8 +5,7 @@
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef _FSP_NOTIFY_PHASE_PEIM_H_
#define _FSP_NOTIFY_PHASE_PEIM_H_
#pragma once
#include <Library/PeiServicesLib.h>
#include <Ppi/DxeIpl.h>
@ -14,4 +13,3 @@
#include <Library/FspPlatformLib.h>
#include <Library/FspCommonLib.h>
#include <Library/FspSwitchStackLib.h>
#endif

View file

@ -5,8 +5,7 @@
**/
#ifndef _SEC_FSP_H_
#define _SEC_FSP_H_
#pragma once
#include <PiPei.h>
#include <FspEas.h>
@ -88,5 +87,3 @@ EFIAPI
AsmGetFspInfoHeader (
VOID
);
#endif

View file

@ -5,8 +5,7 @@
**/
#ifndef _SEC_CORE_H_
#define _SEC_CORE_H_
#pragma once
#include <PiPei.h>
#include <Ppi/TemporaryRamSupport.h>
@ -122,5 +121,3 @@ EFIAPI
AsmReadStackPointer (
VOID
);
#endif

View file

@ -7,12 +7,9 @@
**/
#ifndef _FSP_EAS_H_
#define _FSP_EAS_H_
#pragma once
#include <Uefi/UefiBaseType.h>
#include <Guid/GuidHobFspEas.h>
#include <Guid/FspHeaderFile.h>
#include <FspEas/FspApi.h>
#endif

View file

@ -7,8 +7,7 @@
**/
#ifndef _FSP_API_H_
#define _FSP_API_H_
#pragma once
#include <Pi/PiStatusCode.h>
#include <Base.h>
@ -755,5 +754,3 @@ EFI_STATUS
(EFIAPI *FSP_MULTI_PHASE_INIT)(
IN FSP_MULTI_PHASE_PARAMS *MultiPhaseInitParamPtr
);
#endif

View file

@ -5,8 +5,7 @@
**/
#ifndef _FSP_GLOBAL_DATA_H_
#define _FSP_GLOBAL_DATA_H_
#pragma once
#include <FspEas.h>
@ -100,5 +99,3 @@ typedef struct {
} FSP_GLOBAL_DATA;
#pragma pack()
#endif

View file

@ -5,8 +5,7 @@
**/
#ifndef _FSP_MEASURE_POINT_ID_H_
#define _FSP_MEASURE_POINT_ID_H_
#pragma once
//
// 0xD0 - 0xEF are reserved for FSP common measure point
@ -52,5 +51,3 @@
#define FSP_PERF_ID_API_NOTIFY_END_OF_FIRMWARE_ENTRY 0xFC
#define FSP_PERF_ID_API_NOTIFY_END_OF_FIRMWARE_EXIT (FSP_PERF_ID_API_NOTIFY_END_OF_FIRMWARE_ENTRY + 1)
#endif

View file

@ -6,8 +6,7 @@
**/
#ifndef _FSP_STATUS_CODE_H_
#define _FSP_STATUS_CODE_H_
#pragma once
//
// FSP API - 4 BITS
@ -37,5 +36,3 @@
//
#define FSP_STATUS_CODE_API_ENTRY 0x0000
#define FSP_STATUS_CODE_API_EXIT 0x007F
#endif

View file

@ -7,8 +7,7 @@
**/
#ifndef __FSP_NON_VOLATILE_STORAGE_HOB2_H__
#define __FSP_NON_VOLATILE_STORAGE_HOB2_H__
#pragma once
///
/// The Non-Volatile Storage (NVS) HOB version 2 provides > 64KB buffer support.
@ -20,5 +19,3 @@ typedef struct {
} FSP_NON_VOLATILE_STORAGE_HOB2;
extern EFI_GUID gFspNonVolatileStorageHob2Guid;
#endif

View file

@ -7,11 +7,8 @@
**/
#ifndef __GUID_HOB_FSP_EAS_GUID__
#define __GUID_HOB_FSP_EAS_GUID__
#pragma once
extern EFI_GUID gFspBootLoaderTolumHobGuid;
extern EFI_GUID gFspReservedMemoryResourceHobGuid;
extern EFI_GUID gFspNonVolatileStorageHobGuid;
#endif

View file

@ -5,8 +5,7 @@
**/
#ifndef _CACHE_AS_RAM_LIB_H_
#define _CACHE_AS_RAM_LIB_H_
#pragma once
/**
This function disable CAR.
@ -19,5 +18,3 @@ EFIAPI
DisableCacheAsRam (
IN BOOLEAN DisableCar
);
#endif

View file

@ -5,8 +5,7 @@
**/
#ifndef _CACHE_LIB_H_
#define _CACHE_LIB_H_
#pragma once
//
// EFI_MEMORY_CACHE_TYPE
@ -51,5 +50,3 @@ SetCacheAttributes (
IN UINT64 MemoryLength,
IN EFI_MEMORY_CACHE_TYPE MemoryCacheType
);
#endif

View file

@ -5,8 +5,7 @@
**/
#ifndef __DEBUG_DEVICE_LIB_H__
#define __DEBUG_DEVICE_LIB_H__
#pragma once
/**
Returns the debug print device enable state.
@ -19,5 +18,3 @@ EFIAPI
GetDebugPrintDeviceEnable (
VOID
);
#endif

View file

@ -5,8 +5,7 @@
**/
#ifndef _FSP_COMMON_LIB_H_
#define _FSP_COMMON_LIB_H_
#pragma once
#include <FspGlobalData.h>
#include <FspMeasurePointId.h>
@ -314,5 +313,3 @@ EFIAPI
FspApiReturnStatusReset (
IN EFI_STATUS FspResetType
);
#endif

View file

@ -6,8 +6,7 @@
**/
#ifndef _FSP_MULTIPHASE_LIB_H_
#define _FSP_MULTIPHASE_LIB_H_
#pragma once
EFI_STATUS
EFIAPI
@ -51,5 +50,3 @@ FspMultiPhaseSiInitApiHandlerV2 (
IN UINT32 ApiIdx,
IN VOID *ApiParam
);
#endif

View file

@ -5,8 +5,7 @@
**/
#ifndef _FSP_PLATFORM_LIB_H_
#define _FSP_PLATFORM_LIB_H_
#pragma once
/**
Get system memory resource descriptor by owner.
@ -133,5 +132,3 @@ ReadTemporaryRamSize (
IN UINT32 TemporaryRamBase,
OUT UINT32 *TemporaryRamSize
);
#endif

View file

@ -5,8 +5,7 @@
**/
#ifndef _FSP_SEC_PLATFORM_LIB_H_
#define _FSP_SEC_PLATFORM_LIB_H_
#pragma once
/**
This function performs platform level initialization.
@ -115,5 +114,3 @@ FspMultiPhasePlatformGetNumberOfPhases (
IN UINT32 ApiIdx,
IN OUT UINT32 *NumberOfPhasesSupported
);
#endif

View file

@ -5,8 +5,7 @@
**/
#ifndef _FSP_SWITCH_STACK_LIB_H_
#define _FSP_SWITCH_STACK_LIB_H_
#pragma once
/**
@ -51,5 +50,3 @@ EFIAPI
Loader2PeiSwitchStack (
VOID
);
#endif

View file

@ -7,8 +7,7 @@
**/
#ifndef _FSPI_ARCH_CONFIG_PPI_H_
#define _FSPI_ARCH_CONFIG_PPI_H_
#pragma once
#define FSPI_ARCH_CONFIG_PPI_REVISION 0x1
@ -50,5 +49,3 @@ typedef struct {
} FSPI_ARCH_CONFIG_PPI;
extern EFI_GUID gFspiArchConfigPpiGuid;
#endif // _FSPI_ARCH_CONFIG_PPI_H_

View file

@ -7,8 +7,7 @@
**/
#ifndef _FSPM_ARCH_CONFIG_PPI_H_
#define _FSPM_ARCH_CONFIG_PPI_H_
#pragma once
#define FSPM_ARCH_CONFIG_PPI_REVISION 0x1
@ -43,5 +42,3 @@ typedef struct {
} FSPM_ARCH_CONFIG_PPI;
extern EFI_GUID gFspmArchConfigPpiGuid;
#endif // _FSPM_ARCH_CONFIG_PPI_H_

View file

@ -7,8 +7,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef _FSP_TEMP_RAM_EXIT_PPI_H_
#define _FSP_TEMP_RAM_EXIT_PPI_H_
#pragma once
///
/// Global ID for the FSP_TEMP_RAM_EXIT_PPI.
@ -48,5 +47,3 @@ struct _FSP_TEMP_RAM_EXIT_PPI {
};
extern EFI_GUID gFspTempRamExitPpiGuid;
#endif // _FSP_TEMP_RAM_EXIT_PPI_H_

View file

@ -7,8 +7,7 @@
**/
#ifndef EDKII_PEI_VARIABLE_PPI_H_
#define EDKII_PEI_VARIABLE_PPI_H_
#pragma once
#define EDKII_PEI_VARIABLE_PPI_GUID \
{ \
@ -191,5 +190,3 @@ struct _EDKII_PEI_VARIABLE_PPI {
};
extern EFI_GUID gEdkiiPeiVariablePpiGuid;
#endif

View file

@ -5,8 +5,7 @@
**/
#ifndef _CACHE_LIB_INTERNAL_H_
#define _CACHE_LIB_INTERNAL_H_
#pragma once
#define EFI_MSR_CACHE_VARIABLE_MTRR_BASE 0x00000200
#define EFI_MSR_CACHE_VARIABLE_MTRR_END 0x0000020F
@ -48,5 +47,3 @@
#define CPUID_VIR_PHY_ADDRESS_SIZE 0x80000008
#define CPUID_EXTENDED_FUNCTION 0x80000000
#endif

View file

@ -1,5 +1,4 @@
#ifndef __FSPUPD_H__
#define __FSPUPD_H__
#pragma once
#include <FspEas.h>
@ -12,5 +11,3 @@
#define FSPS_UPD_SIGNATURE 0x535F4450554D4551 /* 'QEMUPD_S' */
#pragma pack()
#endif

View file

@ -1,5 +1,4 @@
#ifndef __FSPMUPD_H__
#define __FSPMUPD_H__
#pragma once
#include <FspUpd.h>
@ -68,5 +67,3 @@ typedef struct {
} FSPM_UPD;
#pragma pack()
#endif

View file

@ -1,5 +1,4 @@
#ifndef __FSPSUPD_H__
#define __FSPSUPD_H__
#pragma once
#include <FspUpd.h>
@ -62,5 +61,3 @@ typedef struct {
} FSPS_UPD;
#pragma pack()
#endif

View file

@ -1,5 +1,4 @@
#ifndef __FSPTUPD_H__
#define __FSPTUPD_H__
#pragma once
#include <FspUpd.h>
@ -79,5 +78,3 @@ typedef struct {
} FSPT_UPD;
#pragma pack()
#endif