TianoCore EDK2 master
Loading...
Searching...
No Matches
SpiNorFlashJedecSfdp.c File Reference

Go to the source code of this file.

Functions

VOID CreateSpiFastReadTableEntry (IN SPI_NOR_FLASH_INSTANCE *Instance, IN UINT32 FastReadInstruction, IN UINT32 FastReadModeClk, IN UINT32 FastReadDummyClk)
 
VOID CalculateEraseTiming (IN UINT32 SfdpEraseTypicalTime, IN UINT32 SfdpEraseTimeMultiplier, OUT UINT32 *EraseTypicalTime, OUT UINT64 *EraseTimeout)
 
VOID DebugPrintEraseType (IN SFDP_SUPPORTED_ERASE_TYPE_RECORD *SupportedEraseType)
 
VOID CreateEraseTypeEntry (IN SPI_NOR_FLASH_INSTANCE *Instance, IN SFDP_SUPPORTED_ERASE_TYPE_RECORD *SupportedEraseType)
 
VOID BuildUpEraseTypeTable (IN SPI_NOR_FLASH_INSTANCE *Instance)
 
BOOLEAN IsTargetEraseType (IN UINT16 EraseType, IN UINT8 TargetTypeNum, IN UINT8 *TargetTypes)
 
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)
 
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)
 
EFI_STATUS GetRegionByFlashAddress (IN SPI_NOR_FLASH_INSTANCE *Instance, IN UINT32 FlashAddress, OUT SFDP_SECTOR_REGION_RECORD **FlashRegion)
 
VOID BuildUpFastReadTable (IN SPI_NOR_FLASH_INSTANCE *Instance)
 
EFI_STATUS SetupRegionEraseInfo (IN SPI_NOR_FLASH_INSTANCE *Instance, IN SFDP_SECTOR_REGION_RECORD *RegionRecord)
 
EFI_STATUS CreateSingleFlashSectorMap (IN SPI_NOR_FLASH_INSTANCE *Instance)
 
EFI_STATUS SetSectorEraseBlockSize (IN SPI_NOR_FLASH_INSTANCE *Instance)
 
EFI_STATUS GetCurrentSectorMapConfiguration (IN SPI_NOR_FLASH_INSTANCE *Instance)
 
EFI_STATUS BuildSectorMapCommandAndMap (IN SPI_NOR_FLASH_INSTANCE *Instance)
 
VOID GetWriteEnableCommand (IN SPI_NOR_FLASH_INSTANCE *Instance)
 
EFI_STATUS GetFastReadParameter (IN SPI_NOR_FLASH_INSTANCE *Instance, IN OUT UINT8 *FastReadInstruction, IN OUT UINT8 *FastReadModeBits, IN OUT UINT8 *FastReadDummyClocks)
 
UINT32 SfdpGetFlashSize (IN SPI_NOR_FLASH_INSTANCE *Instance)
 
EFI_STATUS EFIAPI ReadSfdpHeader (IN SPI_NOR_FLASH_INSTANCE *Instance)
 
EFI_STATUS ReadSfdp (IN SPI_NOR_FLASH_INSTANCE *Instance)
 
EFI_STATUS EFIAPI ReadSfdpParameterHeader (IN SPI_NOR_FLASH_INSTANCE *Instance, IN SFDP_PARAMETER_HEADER *SfdpParameterHeader, IN UINT8 ParameterIdMsb, IN UINT8 ParameterIdLsb)
 
EFI_STATUS EFIAPI SpiReadSfdpPtp (IN SPI_NOR_FLASH_INSTANCE *Instance, IN UINT32 TablePointer, IN VOID *DestBuffer, IN UINT32 LengthInBytes)
 
EFI_STATUS ReadSfdpSectorMapParameterTable (IN SPI_NOR_FLASH_INSTANCE *Instance)
 
EFI_STATUS ReadSfdpBasicParameterTable (IN SPI_NOR_FLASH_INSTANCE *Instance)
 
EFI_STATUS InitialSpiNorFlashSfdpInstance (IN SPI_NOR_FLASH_INSTANCE *Instance)
 

Detailed Description

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

Revision Reference:
Glossary:
  • SFDP - Serial Flash Discoverable Parameters
  • PTP - Parameter Table Pointer

Definition in file SpiNorFlashJedecSfdp.c.

Function Documentation

◆ BuildSectorMapCommandAndMap()

EFI_STATUS BuildSectorMapCommandAndMap ( IN SPI_NOR_FLASH_INSTANCE Instance)

Build sector map configurations.

Parameters
[in]InstanceSPI Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL.
Return values
EFI_SUCCESSRecords 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.

◆ BuildUpEraseTypeTable()

VOID BuildUpEraseTypeTable ( IN SPI_NOR_FLASH_INSTANCE Instance)

Build up the erase type tables.

Parameters
[in]InstanceSPI 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.

◆ BuildUpFastReadTable()

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.

  1. Maximum speed options for certain Fast Read modes are not considered yet. (e.g., 8D-8D-8D or 4S-4D-4D)
Parameters
[in]InstanceSPI 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.

◆ CalculateEraseTiming()

VOID CalculateEraseTiming ( IN UINT32  SfdpEraseTypicalTime,
IN UINT32  SfdpEraseTimeMultiplier,
OUT UINT32 *  EraseTypicalTime,
OUT UINT64 *  EraseTimeout 
)

Calculate erase type typical time.

Parameters
[in]SfdpEraseTypicalTimeErase 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]SfdpEraseTimeMultiplierMultiplier from erase typical time.
[out]EraseTypicalTimePointer to receive Erase typical time in milliseconds.
[out]EraseTimeoutPointer to receive Erase timeout in milliseconds.

Definition at line 88 of file SpiNorFlashJedecSfdp.c.

◆ CreateEraseTypeEntry()

VOID CreateEraseTypeEntry ( IN SPI_NOR_FLASH_INSTANCE Instance,
IN SFDP_SUPPORTED_ERASE_TYPE_RECORD SupportedEraseType 
)

Insert supported erase type entry.

Parameters
[in]InstanceSPI Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL.
[in]SupportedEraseTypePointer to SFDP_SUPPORTED_ERASE_TYPE_RECORD.

Definition at line 150 of file SpiNorFlashJedecSfdp.c.

◆ CreateSingleFlashSectorMap()

EFI_STATUS CreateSingleFlashSectorMap ( IN SPI_NOR_FLASH_INSTANCE Instance)

Create a single flash sector map.

Parameters
[in]InstanceSPI Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL.
Return values
EFI_SUCCESSCurrent sector map configuration is determined. EFI_DEVICE_ERROR Current sector map configuration is not found.

Definition at line 701 of file SpiNorFlashJedecSfdp.c.

◆ CreateSpiFastReadTableEntry()

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.

Parameters
[in]InstanceSPI Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL.
[in]FastReadInstructionThe string of fast read instruction.
[in]FastReadModeClkThe string of fast read mode clock.
[in]FastReadDummyClkThe string of fast read dummy clock.

Definition at line 44 of file SpiNorFlashJedecSfdp.c.

◆ DebugPrintEraseType()

VOID DebugPrintEraseType ( IN SFDP_SUPPORTED_ERASE_TYPE_RECORD SupportedEraseType)

Print out the erase type information.

Parameters
[in]SupportedEraseTypePointer to SFDP_SUPPORTED_ERASE_TYPE_RECORD.

Definition at line 130 of file SpiNorFlashJedecSfdp.c.

◆ GetCurrentSectorMapConfiguration()

EFI_STATUS GetCurrentSectorMapConfiguration ( IN SPI_NOR_FLASH_INSTANCE Instance)

Get the current sector map configuration.

Parameters
[in]InstanceSPI Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL.
Return values
EFI_SUCCESSCurrent sector map configuration is determined. EFI_DEVICE_ERROR Current sector map configuration is not found.

Definition at line 797 of file SpiNorFlashJedecSfdp.c.

◆ GetEraseBlockAttribute()

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.

Parameters
[in]InstanceSpi Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL
[in]FlashRegionThe region the flash address belong.
[in]FlashAddressThe target flash address.
[in]RemainingSizeRemaining size to erase.
[in,out]BlockSizeToEraseInput - The block erase size for this continious blocks. Output - The determined block size for erasing.
[in,out]BlockCountToEraseInput - The expected blocks to erase. Output - The determined number of blocks to erase.
[out]BlockEraseCommandThe erase command used for this continious blocks.
[out]TypicalTimePointer to receive the typical time in millisecond to erase this erase type size.
[out]MaximumTimeoutPointer to receive the maximum timeout in millisecond to erase this erase type size.
Return values
EFI_SUCCESSThe erase block attribute is returned.
EFI_DEVICE_ERRORNo valid SFDP discovered.
EFI_NOT_FOUNDNo valud erase block attribute found.

Definition at line 439 of file SpiNorFlashJedecSfdp.c.

◆ GetEraseTypeRecord()

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.

Parameters
[in]InstanceSPI Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL.
[in]SearchTypeSearch type.
[in]SearchValueThe value of according to search type.
  • For SearchEraseTypeByCommand: SearchValue is the erase instruction.
  • For SearchEraseTypeBySize: SearchValue is the erase block size.
  • For SearchEraseTypeBySmallestSize: SearchValue is not used.
  • For SearchEraseTypeByBiggestSize: SearchValue is not used.
[in]SupportedTypeTargetNumOnly search the specific erase types.
[in]SupportedTypeTargetPointer to SupportedTypeTargetNum of supported erase types.
[out]EraseTypeRecordPointer to receive the erase type record.
Return values
EFI_SUCCESSPointer 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.

◆ GetFastReadParameter()

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.

Parameters
[in]InstanceSpi Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL
[in,out]FastReadInstructionFast Read instruction, the input is the default value.
[in,out]FastReadModeBitsThe operational mode bits.
[in,out]FastReadDummyClocksFast Read wait state (Dummy clocks), the input is the default value.
Return values
EFI_SUCCESSThe parameters are updated.
EFI_NOT_FOUNDNo desired Fas Read mode found.

Definition at line 1150 of file SpiNorFlashJedecSfdp.c.

◆ GetRegionByFlashAddress()

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.

Parameters
[in]InstanceSpi Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL
[in]FlashAddressThe target flash address.
[out]FlashRegionThe target flash address.
Return values
EFI_SUCCESSThe region is returned.
EFI_INVALID_PARAMETERFlashAddress is not belong to any region.
OtherwiseOther errors.

Definition at line 503 of file SpiNorFlashJedecSfdp.c.

◆ GetWriteEnableCommand()

VOID GetWriteEnableCommand ( IN SPI_NOR_FLASH_INSTANCE Instance)

This routine get Write Enable latch command.

Parameters
[in]InstanceSPI 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.

◆ InitialSpiNorFlashSfdpInstance()

EFI_STATUS InitialSpiNorFlashSfdpInstance ( IN SPI_NOR_FLASH_INSTANCE Instance)

Initial SPI_NOR_FLASH_INSTANCE structure.

Parameters
[in]InstancePointer to SPI_NOR_FLASH_INSTANCE. EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL
Return values
EFI_SUCCESSSPI_NOR_FLASH_INSTANCE is initialized according to SPI NOR Flash SFDP specification.
EFI_INVALID_PARAMETERInstance = NULL or Instance->SpiIo == NULL or Instance->SpiIo->SpiPeripheral == NULL or Instance->SpiIo->SpiPeripheral->SpiBus == NULL or Instance->SpiIo->SpiPeripheral->SpiBus->ControllerPath.
OtherwiseFailed to initial SPI_NOR_FLASH_INSTANCE structure.

Definition at line 1710 of file SpiNorFlashJedecSfdp.c.

◆ IsTargetEraseType()

BOOLEAN IsTargetEraseType ( IN UINT16  EraseType,
IN UINT8  TargetTypeNum,
IN UINT8 *  TargetTypes 
)

This function check if the erase type is one of the target erase types.

Parameters
[in]EraseTypeThe erase type.
[in]TargetTypeNumNumber of target search types.
[in]TargetTypesTarget types.
Return values
TRUEYes, this is the target erase type.
FALSENo, this is not the target erase type.

Definition at line 271 of file SpiNorFlashJedecSfdp.c.

◆ ReadSfdp()

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.

Parameters
[in]InstanceSpi Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL
Return values
EFI_SUCCESSHeader is filled in
EFI_DEVICE_ERRORInvalid data received from SPI flash part.

Definition at line 1289 of file SpiNorFlashJedecSfdp.c.

◆ ReadSfdpBasicParameterTable()

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.

Parameters
[in]InstanceSpi Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL
Return values
EFI_SUCCESSThe SPI part size is filled.
EFI_DEVICE_ERRORInvalid data received from SPI flash part.
EFI_NOT_FOUNDParameter header is not found.

Definition at line 1640 of file SpiNorFlashJedecSfdp.c.

◆ ReadSfdpHeader()

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

Parameters
[in]InstanceSpi Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL
Return values
EFI_SUCCESSHeader is filled in
EFI_DEVICE_ERRORInvalid data received from SPI flash part.

Definition at line 1228 of file SpiNorFlashJedecSfdp.c.

◆ ReadSfdpParameterHeader()

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.

Parameters
[in]InstanceSpi Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL
[in]SfdpParameterHeaderSFDP Header Buffer Pointer
[in]ParameterIdMsbMost significant byte of parameter ID.
[in]ParameterIdLsbLowest significant byte of parameter ID.
Return values
EFI_SUCCESSHeader is filled in
EFI_DEVICE_ERRORInvalid data received from SPI flash part.
EFI_NOT_FOUNDUnsupported Parameter Header.

Definition at line 1382 of file SpiNorFlashJedecSfdp.c.

◆ ReadSfdpSectorMapParameterTable()

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.

Parameters
[in]InstanceSpi Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL
Return values
EFI_SUCCESSThe SPI part size is filled.
EFI_DEVICE_ERRORInvalid data received from SPI flash part.

Definition at line 1572 of file SpiNorFlashJedecSfdp.c.

◆ SetSectorEraseBlockSize()

EFI_STATUS SetSectorEraseBlockSize ( IN SPI_NOR_FLASH_INSTANCE Instance)

Set EraseBlockBytes in SPI NOR Flash Protocol.

Parameters
[in]InstanceSpi Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL
Return values
EFI_SUCCESSThe erase block size is returned.
OtherwiseFailed to get erase block size.

Definition at line 768 of file SpiNorFlashJedecSfdp.c.

◆ SetupRegionEraseInfo()

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.

Parameters
[in]InstanceSPI Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL.
[in]RegionRecordPointer to SFDP_SECTOR_REGION_RECORD of this regions.
Return values
EFI_SUCCESSCurrent sector map configuration is determined. EFI_DEVICE_ERROR Current sector map configuration is not found.

Definition at line 653 of file SpiNorFlashJedecSfdp.c.

◆ SfdpGetFlashSize()

UINT32 SfdpGetFlashSize ( IN SPI_NOR_FLASH_INSTANCE Instance)

Return the flash device size from SFDP Basic Flash Parameter Table DWORD 2.

Parameters
[in]InstanceSpi Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL.
Return values
UINT32Flash device size in byte, zero indicates error.

Definition at line 1186 of file SpiNorFlashJedecSfdp.c.

◆ SpiReadSfdpPtp()

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.

Parameters
[in]InstanceSpi Nor Flash Instance data with pointer to EFI_SPI_NOR_FLASH_PROTOCOL and EFI_SPI_IO_PROTOCOL
[in]TablePointerPointer to read data from SFDP.
[in]DestBufferDestination buffer.
[in]LengthInBytesLength to read.
Return values
EFI_SUCCESSThe SPI part size is filled.
EFI_DEVICE_ERRORInvalid data received from SPI flash part.
Othererrors

Definition at line 1490 of file SpiNorFlashJedecSfdp.c.