edk2/EmbeddedPkg/Include/Library/NorFlashInfoLib.h
Michael Kubacki de527ff606 EmbeddedPkg: 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>
2026-02-23 21:01:28 +00:00

88 lines
2.5 KiB
C

/** @file
*
* Copyright (c) 2017 Marvell International Ltd.
*
* SPDX-License-Identifier: BSD-2-Clause-Patent
*
**/
#pragma once
#include <Uefi/UefiBaseType.h>
#define NOR_FLASH_MAX_ID_LEN 6
typedef struct {
/* Device name */
UINT16 *Name;
/*
* JEDEC ID
*/
UINT8 Id[NOR_FLASH_MAX_ID_LEN];
UINT8 IdLen;
UINT16 PageSize;
/*
* Below parameters can be referred as BlockSize
* and BlockCount, when treating the NorFlash as
* block device.
*/
UINT32 SectorSize;
UINT32 SectorCount;
UINT16 Flags;
#define NOR_FLASH_ERASE_4K (1 << 0) /* Use 4 KB erase blocks and CMD_ERASE_4K */
#define NOR_FLASH_ERASE_32K (1 << 1) /* Use 32 KB erase blocks and CMD_ERASE_32K */
#define NOR_FLASH_WRITE_FSR (1 << 2) /* Use flag status register for write */
#define NOR_FLASH_4B_ADDR (1 << 3) /* Use 4B addressing */
} NOR_FLASH_INFO;
/* Vendor IDs */
#define NOR_FLASH_ID_ATMEL 0x1f
#define NOR_FLASH_ID_EON 0x1c
#define NOR_FLASH_ID_GIGADEVICE 0xc8
#define NOR_FLASH_ID_ISSI 0x9d
#define NOR_FLASH_ID_MACRONIX 0xc2
#define NOR_FLASH_ID_SPANSION 0x01
#define NOR_FLASH_ID_STMICRO 0x20
#define NOR_FLASH_ID_SST 0xbf
#define NOR_FLASH_ID_WINDBOND 0xef
/**
Return an allocated copy pool of the NOR flash information structure.
@param[in] Id Pointer to an array with JEDEC ID obtained
from the NOR flash with READ_ID command
(0x9f)
@param[in out] FlashInfo Pointer to NOR flash information structure
@param[in] AllocateForRuntime A flag specifying a type of a copy pool
allocation (TRUE for runtime, FALSE for
normal)
@retval EFI_SUCCESS Operation completed successfully
@retval EFI_NOT_FOUND No matching entry in NOR ID table found
@retval EFI_OUT_OF_RESOURCES No pool memory available
**/
EFI_STATUS
EFIAPI
NorFlashGetInfo (
IN UINT8 *Id,
IN OUT NOR_FLASH_INFO **FlashInfo,
IN BOOLEAN AllocateForRuntime
);
/**
Print NOR flash information basing on data stored in
the NOR_FLASH_INFO structure.
@param[in] FlashInfo Pointer to NOR flash information structure
**/
VOID
EFIAPI
NorFlashPrintInfo (
IN NOR_FLASH_INFO *Info
);