TianoCore EDK2 master
Loading...
Searching...
No Matches
SpiFlashLib.c File Reference
#include "SpiCommon.h"

Go to the source code of this file.

Functions

SPI_INSTANCEGetSpiInstance (VOID)
 
EFI_STATUS EFIAPI SpiConstructor (VOID)
 
EFI_STATUS EFIAPI SpiFlashRead (IN FLASH_REGION_TYPE FlashRegionType, IN UINT32 Address, IN UINT32 ByteCount, OUT UINT8 *Buffer)
 
EFI_STATUS EFIAPI SpiFlashWrite (IN FLASH_REGION_TYPE FlashRegionType, IN UINT32 Address, IN UINT32 ByteCount, IN UINT8 *Buffer)
 
EFI_STATUS EFIAPI SpiFlashErase (IN FLASH_REGION_TYPE FlashRegionType, IN UINT32 Address, IN UINT32 ByteCount)
 
EFI_STATUS EFIAPI SpiFlashReadSfdp (IN UINT8 ComponentNumber, IN UINT32 ByteCount, OUT UINT8 *SfdpData)
 
EFI_STATUS EFIAPI SpiFlashReadJedecId (IN UINT8 ComponentNumber, IN UINT32 ByteCount, OUT UINT8 *JedecId)
 
EFI_STATUS EFIAPI SpiFlashWriteStatus (IN UINT32 ByteCount, IN UINT8 *StatusValue)
 
EFI_STATUS EFIAPI SpiFlashReadStatus (IN UINT32 ByteCount, OUT UINT8 *StatusValue)
 
EFI_STATUS EFIAPI SpiReadPchSoftStrap (IN UINT32 SoftStrapAddr, IN UINT32 ByteCount, OUT UINT8 *SoftStrapValue)
 
EFI_STATUS SendSpiCmd (IN FLASH_REGION_TYPE FlashRegionType, IN FLASH_CYCLE_TYPE FlashCycleType, IN UINT32 Address, IN UINT32 ByteCount, IN OUT UINT8 *Buffer)
 
BOOLEAN WaitForSpiCycleComplete (IN UINT32 ScSpiBar0, IN BOOLEAN ErrorCheck)
 
EFI_STATUS EFIAPI SpiGetRegionAddress (IN FLASH_REGION_TYPE FlashRegionType, OUT UINT32 *BaseAddress OPTIONAL, OUT UINT32 *RegionSize OPTIONAL)
 

Variables

SPI_INSTANCEmSpiInstance = NULL
 

Detailed Description

Generic driver using Hardware Sequencing registers.

Copyright (c) 2017-2021, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file SpiFlashLib.c.

Function Documentation

◆ GetSpiInstance()

SPI_INSTANCE * GetSpiInstance ( VOID  )

Get SPI Instance from library global data..

Return values
SpiInstanceReturn SPI instance

Definition at line 18 of file SpiFlashLib.c.

◆ SendSpiCmd()

EFI_STATUS SendSpiCmd ( IN FLASH_REGION_TYPE  FlashRegionType,
IN FLASH_CYCLE_TYPE  FlashCycleType,
IN UINT32  Address,
IN UINT32  ByteCount,
IN OUT UINT8 *  Buffer 
)

This function sends the programmed SPI command to the slave device.

Parameters
[in]FlashRegionTypeThe SPI Region type for flash cycle which is listed in the Descriptor
[in]FlashCycleTypeThe Flash SPI cycle type list in HSFC (Hardware Sequencing Flash Control Register) register
[in]AddressThe Flash Linear Address must fall within a region for which BIOS has access permissions.
[in]ByteCountNumber of bytes in the data portion of the SPI cycle.
[in,out]BufferPointer to caller-allocated buffer containing the data received or sent during the SPI cycle.
Return values
EFI_SUCCESSSPI command completes successfully.
EFI_DEVICE_ERRORDevice error, the command aborts abnormally.
EFI_ACCESS_DENIEDSome unrecognized command encountered in hardware sequencing mode
EFI_INVALID_PARAMETERThe parameters specified are not valid.

Restore the settings for SPI Prefetching and Caching and enable BIOS Write Protect

Definition at line 419 of file SpiFlashLib.c.

◆ SpiConstructor()

EFI_STATUS EFIAPI SpiConstructor ( VOID  )

Initialize an SPI library.

Return values
EFI_SUCCESSThe protocol instance was properly initialized
EFI_NOT_FOUNDThe expected SPI info could not be found

Definition at line 42 of file SpiFlashLib.c.

◆ SpiFlashErase()

EFI_STATUS EFIAPI SpiFlashErase ( IN FLASH_REGION_TYPE  FlashRegionType,
IN UINT32  Address,
IN UINT32  ByteCount 
)

Erase some area on the flash part.

Parameters
[in]FlashRegionTypeThe Flash Region type for flash cycle which is listed in the Descriptor.
[in]AddressThe Flash Linear Address must fall within a region for which BIOS has access permissions.
[in]ByteCountNumber of bytes in the data portion of the SPI cycle.
Return values
EFI_SUCCESSCommand succeed.
EFI_INVALID_PARAMETERThe parameters specified are not valid.
EFI_DEVICE_ERRORDevice error, command aborts abnormally.

Definition at line 221 of file SpiFlashLib.c.

◆ SpiFlashRead()

EFI_STATUS EFIAPI SpiFlashRead ( IN FLASH_REGION_TYPE  FlashRegionType,
IN UINT32  Address,
IN UINT32  ByteCount,
OUT UINT8 *  Buffer 
)

Read data from the flash part.

Parameters
[in]FlashRegionTypeThe Flash Region type for flash cycle which is listed in the Descriptor.
[in]AddressThe Flash Linear Address must fall within a region for which BIOS has access permissions.
[in]ByteCountNumber of bytes in the data portion of the SPI cycle.
[out]BufferThe Pointer to caller-allocated buffer containing the data received. It is the caller's responsibility to make sure Buffer is large enough for the total number of bytes read.
Return values
EFI_SUCCESSCommand succeed.
EFI_INVALID_PARAMETERThe parameters specified are not valid.
EFI_DEVICE_ERRORDevice error, command aborts abnormally.

Definition at line 168 of file SpiFlashLib.c.

◆ SpiFlashReadJedecId()

EFI_STATUS EFIAPI SpiFlashReadJedecId ( IN UINT8  ComponentNumber,
IN UINT32  ByteCount,
OUT UINT8 *  JedecId 
)

Read Jedec Id from the flash part.

Parameters
[in]ComponentNumberThe Component Number for chip select
[in]ByteCountNumber of bytes in JedecId data portion of the SPI cycle, the data size is 3 typically
[out]JedecIdThe Pointer to caller-allocated buffer containing JEDEC ID received It is the caller's responsibility to make sure Buffer is large enough for the total number of bytes read.
Return values
EFI_SUCCESSCommand succeed.
EFI_INVALID_PARAMETERThe parameters specified are not valid.
EFI_DEVICE_ERRORDevice error, command aborts abnormally.

Definition at line 290 of file SpiFlashLib.c.

◆ SpiFlashReadSfdp()

EFI_STATUS EFIAPI SpiFlashReadSfdp ( IN UINT8  ComponentNumber,
IN UINT32  ByteCount,
OUT UINT8 *  SfdpData 
)

Read SFDP data from the flash part.

Parameters
[in]ComponentNumberThe Component Number for chip select
[in]ByteCountNumber of bytes in SFDP data portion of the SPI cycle, the max number is 64
[out]SfdpDataThe Pointer to caller-allocated buffer containing the SFDP data received It is the caller's responsibility to make sure Buffer is large enough for the total number of bytes read.
Return values
EFI_SUCCESSCommand succeed.
EFI_INVALID_PARAMETERThe parameters specified are not valid.
EFI_DEVICE_ERRORDevice error, command aborts abnormally.

Definition at line 247 of file SpiFlashLib.c.

◆ SpiFlashReadStatus()

EFI_STATUS EFIAPI SpiFlashReadStatus ( IN UINT32  ByteCount,
OUT UINT8 *  StatusValue 
)

Read status register in the flash part.

Parameters
[in]ByteCountNumber of bytes in Status data portion of the SPI cycle, the data size is 1 typically
[out]StatusValueThe Pointer to caller-allocated buffer containing the value of Status register received.
Return values
EFI_SUCCESSCommand succeed.
EFI_INVALID_PARAMETERThe parameters specified are not valid.
EFI_DEVICE_ERRORDevice error, command aborts abnormally.

Definition at line 354 of file SpiFlashLib.c.

◆ SpiFlashWrite()

EFI_STATUS EFIAPI SpiFlashWrite ( IN FLASH_REGION_TYPE  FlashRegionType,
IN UINT32  Address,
IN UINT32  ByteCount,
IN UINT8 *  Buffer 
)

Write data to the flash part.

Parameters
[in]FlashRegionTypeThe Flash Region type for flash cycle which is listed in the Descriptor.
[in]AddressThe Flash Linear Address must fall within a region for which BIOS has access permissions.
[in]ByteCountNumber of bytes in the data portion of the SPI cycle.
[in]BufferPointer to caller-allocated buffer containing the data sent during the SPI cycle.
Return values
EFI_SUCCESSCommand succeed.
EFI_INVALID_PARAMETERThe parameters specified are not valid.
EFI_DEVICE_ERRORDevice error, command aborts abnormally.

Definition at line 195 of file SpiFlashLib.c.

◆ SpiFlashWriteStatus()

EFI_STATUS EFIAPI SpiFlashWriteStatus ( IN UINT32  ByteCount,
IN UINT8 *  StatusValue 
)

Write the status register in the flash part.

Parameters
[in]ByteCountNumber of bytes in Status data portion of the SPI cycle, the data size is 1 typically
[in]StatusValueThe Pointer to caller-allocated buffer containing the value of Status register writing
Return values
EFI_SUCCESSCommand succeed.
EFI_INVALID_PARAMETERThe parameters specified are not valid.
EFI_DEVICE_ERRORDevice error, command aborts abnormally.

Definition at line 331 of file SpiFlashLib.c.

◆ SpiGetRegionAddress()

EFI_STATUS EFIAPI SpiGetRegionAddress ( IN FLASH_REGION_TYPE  FlashRegionType,
OUT UINT32 *BaseAddress  OPTIONAL,
OUT UINT32 *RegionSize  OPTIONAL 
)

Get the SPI region base and size, based on the enum type

Parameters
[in]FlashRegionTypeThe Flash Region type for for the base address which is listed in the Descriptor.
[out]BaseAddressThe Flash Linear Address for the Region 'n' Base
[out]RegionSizeThe size for the Region 'n'
Return values
EFI_SUCCESSRead success
EFI_INVALID_PARAMETERInvalid region type given
EFI_DEVICE_ERRORThe region is not used

Definition at line 820 of file SpiFlashLib.c.

◆ SpiReadPchSoftStrap()

EFI_STATUS EFIAPI SpiReadPchSoftStrap ( IN UINT32  SoftStrapAddr,
IN UINT32  ByteCount,
OUT UINT8 *  SoftStrapValue 
)

Read SC Soft Strap Values

Parameters
[in]SoftStrapAddrSC Soft Strap address offset from FPSBA.
[in]ByteCountNumber of bytes in SoftStrap data portion of the SPI cycle
[out]SoftStrapValueThe Pointer to caller-allocated buffer containing SC Soft Strap Value. It is the caller's responsibility to make sure Buffer is large enough for the total number of bytes read.
Return values
EFI_SUCCESSCommand succeed.
EFI_INVALID_PARAMETERThe parameters specified are not valid.
EFI_DEVICE_ERRORDevice error, command aborts abnormally.

Definition at line 379 of file SpiFlashLib.c.

◆ WaitForSpiCycleComplete()

BOOLEAN WaitForSpiCycleComplete ( IN UINT32  ScSpiBar0,
IN BOOLEAN  ErrorCheck 
)

Wait execution cycle to complete on the SPI interface.

Parameters
[in]ScSpiBar0Spi MMIO base address
[in]ErrorCheckTRUE if the SpiCycle needs to do the error check
Return values
TRUESPI cycle completed on the interface.
FALSETime out while waiting the SPI cycle to complete. It's not safe to program the next command on the SPI interface.

Definition at line 774 of file SpiFlashLib.c.

Variable Documentation

◆ mSpiInstance

SPI_INSTANCE* mSpiInstance = NULL

Definition at line 10 of file SpiFlashLib.c.