TianoCore EDK2 master
|
#include <Base.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/DevicePathLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Protocol/SpiConfiguration.h>
#include <Protocol/SpiIo.h>
#include <IndustryStandard/SpiNorFlashJedecSfdp.h>
#include "SpiNorFlash.h"
#include "SpiNorFlashJedecSfdpInternal.h"
Go to the source code of this file.
SPI NOR Flash JEDEC Serial Flash Discoverable Parameters (SFDP) common functions.
Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
Definition in file SpiNorFlashJedecSfdp.c.
EFI_STATUS BuildSectorMapCommandAndMap | ( | IN SPI_NOR_FLASH_INSTANCE * | Instance | ) |
Build sector map configurations.
[in] | Instance | SPI Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL. |
EFI_SUCCESS | Records of sector map configuration command and map descriptor are built up successfully. EFI_OUT_OF_RESOURCES Not enough memory resource. EFI_DEVICE_ERROR SFDP Sector Map Parameter is not constructed correctly. |
Definition at line 927 of file SpiNorFlashJedecSfdp.c.
VOID BuildUpEraseTypeTable | ( | IN SPI_NOR_FLASH_INSTANCE * | Instance | ) |
Build up the erase type tables.
[in] | Instance | SPI Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL. |
Definition at line 171 of file SpiNorFlashJedecSfdp.c.
VOID BuildUpFastReadTable | ( | IN SPI_NOR_FLASH_INSTANCE * | Instance | ) |
Build up the Fast Read capability tables. The earlier linked table in the linked list has the faster transfer. NOTE: 1. The Quad input instructions mentioned in 21th DWOWRD are not considered yet.
[in] | Instance | SPI Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL. |
Definition at line 552 of file SpiNorFlashJedecSfdp.c.
VOID CalculateEraseTiming | ( | IN UINT32 | SfdpEraseTypicalTime, |
IN UINT32 | SfdpEraseTimeMultiplier, | ||
OUT UINT32 * | EraseTypicalTime, | ||
OUT UINT64 * | EraseTimeout | ||
) |
Calculate erase type typical time.
[in] | SfdpEraseTypicalTime | Erase type typical time indicated in Basic Flash Parameter Table. EraseTypicalTime [0:4] - Count EraseTypicalTime [5:6] - Unit 00b: 1ms 01b: 16ms 10b: 128ms 11b: 1s |
[in] | SfdpEraseTimeMultiplier | Multiplier from erase typical time. |
[out] | EraseTypicalTime | Pointer to receive Erase typical time in milliseconds. |
[out] | EraseTimeout | Pointer to receive Erase timeout in milliseconds. |
Definition at line 88 of file SpiNorFlashJedecSfdp.c.
VOID CreateEraseTypeEntry | ( | IN SPI_NOR_FLASH_INSTANCE * | Instance, |
IN SFDP_SUPPORTED_ERASE_TYPE_RECORD * | SupportedEraseType | ||
) |
Insert supported erase type entry.
[in] | Instance | SPI Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL. |
[in] | SupportedEraseType | Pointer to SFDP_SUPPORTED_ERASE_TYPE_RECORD. |
Definition at line 150 of file SpiNorFlashJedecSfdp.c.
EFI_STATUS CreateSingleFlashSectorMap | ( | IN SPI_NOR_FLASH_INSTANCE * | Instance | ) |
Create a single flash sector map.
[in] | Instance | SPI Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL. |
EFI_SUCCESS | Current sector map configuration is determined. EFI_DEVICE_ERROR Current sector map configuration is not found. |
Definition at line 701 of file SpiNorFlashJedecSfdp.c.
VOID CreateSpiFastReadTableEntry | ( | IN SPI_NOR_FLASH_INSTANCE * | Instance, |
IN UINT32 | FastReadInstruction, | ||
IN UINT32 | FastReadModeClk, | ||
IN UINT32 | FastReadDummyClk | ||
) |
Build up the Fast Read capability entry and link it to the linked list.
[in] | Instance | SPI Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL. |
[in] | FastReadInstruction | The string of fast read instruction. |
[in] | FastReadModeClk | The string of fast read mode clock. |
[in] | FastReadDummyClk | The string of fast read dummy clock. |
Definition at line 44 of file SpiNorFlashJedecSfdp.c.
VOID DebugPrintEraseType | ( | IN SFDP_SUPPORTED_ERASE_TYPE_RECORD * | SupportedEraseType | ) |
Print out the erase type information.
[in] | SupportedEraseType | Pointer to SFDP_SUPPORTED_ERASE_TYPE_RECORD. |
Definition at line 130 of file SpiNorFlashJedecSfdp.c.
EFI_STATUS GetCurrentSectorMapConfiguration | ( | IN SPI_NOR_FLASH_INSTANCE * | Instance | ) |
Get the current sector map configuration.
[in] | Instance | SPI Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL. |
EFI_SUCCESS | Current sector map configuration is determined. EFI_DEVICE_ERROR Current sector map configuration is not found. |
Definition at line 797 of file SpiNorFlashJedecSfdp.c.
EFI_STATUS GetEraseBlockAttribute | ( | IN SPI_NOR_FLASH_INSTANCE * | Instance, |
IN SFDP_SECTOR_REGION_RECORD * | FlashRegion, | ||
IN UINT32 | FlashAddress, | ||
IN UINT32 | RemainingSize, | ||
IN OUT UINT32 * | BlockSizeToErase, | ||
IN OUT UINT32 * | BlockCountToErase, | ||
OUT UINT8 * | BlockEraseCommand, | ||
OUT UINT32 * | TypicalTime, | ||
OUT UINT64 * | MaximumTimeout | ||
) |
Get the erase block attribute for the target address.
[in] | Instance | Spi Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL |
[in] | FlashRegion | The region the flash address belong. |
[in] | FlashAddress | The target flash address. |
[in] | RemainingSize | Remaining size to erase. |
[in,out] | BlockSizeToErase | Input - The block erase size for this continious blocks. Output - The determined block size for erasing. |
[in,out] | BlockCountToErase | Input - The expected blocks to erase. Output - The determined number of blocks to erase. |
[out] | BlockEraseCommand | The erase command used for this continious blocks. |
[out] | TypicalTime | Pointer to receive the typical time in millisecond to erase this erase type size. |
[out] | MaximumTimeout | Pointer to receive the maximum timeout in millisecond to erase this erase type size. |
EFI_SUCCESS | The erase block attribute is returned. |
EFI_DEVICE_ERROR | No valid SFDP discovered. |
EFI_NOT_FOUND | No valud erase block attribute found. |
Definition at line 439 of file SpiNorFlashJedecSfdp.c.
EFI_STATUS GetEraseTypeRecord | ( | IN SPI_NOR_FLASH_INSTANCE * | Instance, |
IN SFDP_SEARCH_ERASE_TYPE | SearchType, | ||
IN UINT32 | SearchValue, | ||
IN UINT8 | SupportedTypeTargetNum, | ||
IN UINT8 *SupportedTypeTarget | OPTIONAL, | ||
OUT SFDP_SUPPORTED_ERASE_TYPE_RECORD ** | EraseTypeRecord | ||
) |
Search the erase type record according to the given search type and value.
[in] | Instance | SPI Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL. |
[in] | SearchType | Search type. |
[in] | SearchValue | The value of according to search type.
|
[in] | SupportedTypeTargetNum | Only search the specific erase types. |
[in] | SupportedTypeTarget | Pointer to SupportedTypeTargetNum of supported erase types. |
[out] | EraseTypeRecord | Pointer to receive the erase type record. |
EFI_SUCCESS | Pointer to erase type record is returned. EFI_INVALID_PARAMETER Invalid SearchType. EFI_NOT_FOUND Erase type not found. |
Definition at line 314 of file SpiNorFlashJedecSfdp.c.
EFI_STATUS GetFastReadParameter | ( | IN SPI_NOR_FLASH_INSTANCE * | Instance, |
IN OUT UINT8 * | FastReadInstruction, | ||
IN OUT UINT8 * | FastReadModeBits, | ||
IN OUT UINT8 * | FastReadDummyClocks | ||
) |
This routine returns the desired Fast Read mode.
[in] | Instance | Spi Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL |
[in,out] | FastReadInstruction | Fast Read instruction, the input is the default value. |
[in,out] | FastReadModeBits | The operational mode bits. |
[in,out] | FastReadDummyClocks | Fast Read wait state (Dummy clocks), the input is the default value. |
EFI_SUCCESS | The parameters are updated. |
EFI_NOT_FOUND | No desired Fas Read mode found. |
Definition at line 1150 of file SpiNorFlashJedecSfdp.c.
EFI_STATUS GetRegionByFlashAddress | ( | IN SPI_NOR_FLASH_INSTANCE * | Instance, |
IN UINT32 | FlashAddress, | ||
OUT SFDP_SECTOR_REGION_RECORD ** | FlashRegion | ||
) |
Get the erase block attribute for the target address.
[in] | Instance | Spi Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL |
[in] | FlashAddress | The target flash address. |
[out] | FlashRegion | The target flash address. |
EFI_SUCCESS | The region is returned. |
EFI_INVALID_PARAMETER | FlashAddress is not belong to any region. |
Otherwise | Other errors. |
Definition at line 503 of file SpiNorFlashJedecSfdp.c.
VOID GetWriteEnableCommand | ( | IN SPI_NOR_FLASH_INSTANCE * | Instance | ) |
This routine get Write Enable latch command.
[in] | Instance | SPI Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL. |
Definition at line 1116 of file SpiNorFlashJedecSfdp.c.
EFI_STATUS InitialSpiNorFlashSfdpInstance | ( | IN SPI_NOR_FLASH_INSTANCE * | Instance | ) |
Initial SPI_NOR_FLASH_INSTANCE structure.
[in] | Instance | Pointer to SPI_NOR_FLASH_INSTANCE. EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL |
EFI_SUCCESS | SPI_NOR_FLASH_INSTANCE is initialized according to SPI NOR Flash SFDP specification. |
EFI_INVALID_PARAMETER | Instance = NULL or Instance->SpiIo == NULL or Instance->SpiIo->SpiPeripheral == NULL or Instance->SpiIo->SpiPeripheral->SpiBus == NULL or Instance->SpiIo->SpiPeripheral->SpiBus->ControllerPath. |
Otherwise | Failed to initial SPI_NOR_FLASH_INSTANCE structure. |
Definition at line 1710 of file SpiNorFlashJedecSfdp.c.
This function check if the erase type is one of the target erase types.
[in] | EraseType | The erase type. |
[in] | TargetTypeNum | Number of target search types. |
[in] | TargetTypes | Target types. |
TRUE | Yes, this is the target erase type. |
FALSE | No, this is not the target erase type. |
Definition at line 271 of file SpiNorFlashJedecSfdp.c.
EFI_STATUS ReadSfdp | ( | IN SPI_NOR_FLASH_INSTANCE * | Instance | ) |
Read SFDP This routine reads the JEDEC SPI Flash Discoverable Parameters. We just read the necessary tables in this routine.
[in] | Instance | Spi Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL |
EFI_SUCCESS | Header is filled in |
EFI_DEVICE_ERROR | Invalid data received from SPI flash part. |
Definition at line 1289 of file SpiNorFlashJedecSfdp.c.
EFI_STATUS ReadSfdpBasicParameterTable | ( | IN SPI_NOR_FLASH_INSTANCE * | Instance | ) |
Read SFDP Basic Parameters into buffer.
This routine reads the JEDEC SPI Flash Discoverable Parameters from the SPI chip.
[in] | Instance | Spi Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL |
EFI_SUCCESS | The SPI part size is filled. |
EFI_DEVICE_ERROR | Invalid data received from SPI flash part. |
EFI_NOT_FOUND | Parameter header is not found. |
Definition at line 1640 of file SpiNorFlashJedecSfdp.c.
EFI_STATUS EFIAPI ReadSfdpHeader | ( | IN SPI_NOR_FLASH_INSTANCE * | Instance | ) |
Read SFDP Header
This routine reads the JEDEC SPI Flash Discoverable Parameter header from the SPI chip. Fails if Major Revision is not = 1
[in] | Instance | Spi Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL |
EFI_SUCCESS | Header is filled in |
EFI_DEVICE_ERROR | Invalid data received from SPI flash part. |
Definition at line 1228 of file SpiNorFlashJedecSfdp.c.
EFI_STATUS EFIAPI ReadSfdpParameterHeader | ( | IN SPI_NOR_FLASH_INSTANCE * | Instance, |
IN SFDP_PARAMETER_HEADER * | SfdpParameterHeader, | ||
IN UINT8 | ParameterIdMsb, | ||
IN UINT8 | ParameterIdLsb | ||
) |
Read SFDP Specific Parameter Header.
This routine reads the JEDEC SPI Flash Discoverable Parameter header from the SPI chip. Fails if Major Revision is not = SFDP_SUPPORTED_MAJOR_REVISION.
[in] | Instance | Spi Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL |
[in] | SfdpParameterHeader | SFDP Header Buffer Pointer |
[in] | ParameterIdMsb | Most significant byte of parameter ID. |
[in] | ParameterIdLsb | Lowest significant byte of parameter ID. |
EFI_SUCCESS | Header is filled in |
EFI_DEVICE_ERROR | Invalid data received from SPI flash part. |
EFI_NOT_FOUND | Unsupported Parameter Header. |
Definition at line 1382 of file SpiNorFlashJedecSfdp.c.
EFI_STATUS ReadSfdpSectorMapParameterTable | ( | IN SPI_NOR_FLASH_INSTANCE * | Instance | ) |
Read SFDP Sector Map Parameter into buffer.
This routine reads the JEDEC SPI Flash Discoverable Parameters from the SPI chip.
[in] | Instance | Spi Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL |
EFI_SUCCESS | The SPI part size is filled. |
EFI_DEVICE_ERROR | Invalid data received from SPI flash part. |
Definition at line 1572 of file SpiNorFlashJedecSfdp.c.
EFI_STATUS SetSectorEraseBlockSize | ( | IN SPI_NOR_FLASH_INSTANCE * | Instance | ) |
Set EraseBlockBytes in SPI NOR Flash Protocol.
[in] | Instance | Spi Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL |
EFI_SUCCESS | The erase block size is returned. |
Otherwise | Failed to get erase block size. |
Definition at line 768 of file SpiNorFlashJedecSfdp.c.
EFI_STATUS SetupRegionEraseInfo | ( | IN SPI_NOR_FLASH_INSTANCE * | Instance, |
IN SFDP_SECTOR_REGION_RECORD * | RegionRecord | ||
) |
This function sets up the erase types supported by this region.
[in] | Instance | SPI Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL. |
[in] | RegionRecord | Pointer to SFDP_SECTOR_REGION_RECORD of this regions. |
EFI_SUCCESS | Current sector map configuration is determined. EFI_DEVICE_ERROR Current sector map configuration is not found. |
Definition at line 653 of file SpiNorFlashJedecSfdp.c.
UINT32 SfdpGetFlashSize | ( | IN SPI_NOR_FLASH_INSTANCE * | Instance | ) |
Return the flash device size from SFDP Basic Flash Parameter Table DWORD 2.
[in] | Instance | Spi Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL. |
UINT32 | Flash device size in byte, zero indicates error. |
Definition at line 1186 of file SpiNorFlashJedecSfdp.c.
EFI_STATUS EFIAPI SpiReadSfdpPtp | ( | IN SPI_NOR_FLASH_INSTANCE * | Instance, |
IN UINT32 | TablePointer, | ||
IN VOID * | DestBuffer, | ||
IN UINT32 | LengthInBytes | ||
) |
Read from SFDP table pointer.
This routine sends SPI_FLASH_RDSFDP command and reads parameter from the given TablePointer.
[in] | Instance | Spi Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL |
[in] | TablePointer | Pointer to read data from SFDP. |
[in] | DestBuffer | Destination buffer. |
[in] | LengthInBytes | Length to read. |
EFI_SUCCESS | The SPI part size is filled. |
EFI_DEVICE_ERROR | Invalid data received from SPI flash part. |
Other | errors |
Definition at line 1490 of file SpiNorFlashJedecSfdp.c.