TianoCore EDK2 master
Loading...
Searching...
No Matches
SpiCommon.h File Reference

Go to the source code of this file.

Data Structures

struct  SPI_INSTANCE
 

Macros

#define WAIT_TIME   6000000
 Wait Time = 6 seconds = 6000000 microseconds.
 
#define WAIT_PERIOD   10
 Wait Period = 10 microseconds.
 
#define SC_SPI_PRIVATE_DATA_SIGNATURE   SIGNATURE_32 ('P', 'S', 'P', 'I')
 

Enumerations

enum  FLASH_CYCLE_TYPE {
  FlashCycleRead , FlashCycleWrite , FlashCycleErase , FlashCycleReadSfdp ,
  FlashCycleReadJedecId , FlashCycleWriteStatus , FlashCycleReadStatus , FlashCycleMax
}
 
enum  FLASH_COMPONENT_NUM { FlashComponent0 , FlashComponent1 , FlashComponentMax }
 

Functions

UINT32 AcquireSpiBar0 (IN UINTN PchSpiBase)
 
VOID ReleaseSpiBar0 (IN UINTN PchSpiBase)
 
EFI_STATUS EFIAPI DisableBiosWriteProtect (IN UINTN PchSpiBase, IN UINT8 CpuSmmBwp)
 
VOID EFIAPI EnableBiosWriteProtect (IN UINTN PchSpiBase, IN UINT8 CpuSmmBwp)
 
UINT8 SaveAndDisableSpiPrefetchCache (IN UINTN PchSpiBase)
 
VOID SetSpiBiosControlRegister (IN UINTN PchSpiBase, IN UINT8 BiosCtlValue)
 
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 PchSpiBar0, IN BOOLEAN ErrorCheck)
 

Detailed Description

Header file for the SPI flash module.

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

Definition in file SpiCommon.h.

Macro Definition Documentation

◆ SC_SPI_PRIVATE_DATA_SIGNATURE

#define SC_SPI_PRIVATE_DATA_SIGNATURE   SIGNATURE_32 ('P', 'S', 'P', 'I')

Private data structure definitions for the driver

Definition at line 60 of file SpiCommon.h.

◆ WAIT_PERIOD

#define WAIT_PERIOD   10

Wait Period = 10 microseconds.

Definition at line 32 of file SpiCommon.h.

◆ WAIT_TIME

#define WAIT_TIME   6000000

Wait Time = 6 seconds = 6000000 microseconds.

Maximum time allowed while waiting the SPI cycle to complete Wait Time = 6 seconds = 6000000 microseconds Wait Period = 10 microseconds

Definition at line 31 of file SpiCommon.h.

Enumeration Type Documentation

◆ FLASH_COMPONENT_NUM

Flash Component Number

Definition at line 51 of file SpiCommon.h.

◆ FLASH_CYCLE_TYPE

Flash cycle Type

Definition at line 37 of file SpiCommon.h.

Function Documentation

◆ AcquireSpiBar0()

UINT32 AcquireSpiBar0 ( IN UINTN  PchSpiBase)

Acquire SPI MMIO BAR

Parameters
[in]PchSpiBasePCH SPI PCI Base Address
Return values
ReturnSPI BAR Address

Acquire SPI MMIO BAR.

Parameters
[in]PchSpiBasePCH SPI PCI Base Address
Return values
ReturnSPI BAR Address

Definition at line 18 of file PchSpi.c.

◆ DisableBiosWriteProtect()

EFI_STATUS EFIAPI DisableBiosWriteProtect ( IN UINTN  PchSpiBase,
IN UINT8  CpuSmmBwp 
)

This function is a hook for Spi to disable BIOS Write Protect

Parameters
[in]PchSpiBasePCH SPI PCI Base Address
[in]CpuSmmBwpNeed to disable CPU SMM Bios write protection or not
Return values
EFI_SUCCESSThe protocol instance was properly initialized
EFI_ACCESS_DENIEDThe BIOS Region can only be updated in SMM phase

This function is a hook for Spi to disable BIOS Write Protect.

Parameters
[in]PchSpiBasePCH SPI PCI Base Address
[in]CpuSmmBwpNeed to disable CPU SMM Bios write protection or not
Return values
EFI_SUCCESSThe protocol instance was properly initialized
EFI_ACCESS_DENIEDThe BIOS Region can only be updated in SMM phase

Definition at line 83 of file PchSpi.c.

◆ EnableBiosWriteProtect()

VOID EFIAPI EnableBiosWriteProtect ( IN UINTN  PchSpiBase,
IN UINT8  CpuSmmBwp 
)

This function is a hook for Spi to enable BIOS Write Protect

Parameters
[in]PchSpiBasePCH SPI PCI Base Address
[in]CpuSmmBwpNeed to disable CPU SMM Bios write protection or not
Return values
None

This function is a hook for Spi to enable BIOS Write Protect.

Parameters
[in]PchSpiBasePCH SPI PCI Base Address
[in]CpuSmmBwpNeed to disable CPU SMM Bios write protection or not

Definition at line 114 of file PchSpi.c.

◆ ReleaseSpiBar0()

VOID ReleaseSpiBar0 ( IN UINTN  PchSpiBase)

Release SPI MMIO BAR. Do nothing.

Parameters
[in]PchSpiBasePCH SPI PCI Base Address
Return values
None

Release SPI MMIO BAR. Do nothing.

Parameters
[in]PchSpiBasePCH SPI PCI Base Address

Definition at line 32 of file PchSpi.c.

◆ SaveAndDisableSpiPrefetchCache()

UINT8 SaveAndDisableSpiPrefetchCache ( IN UINTN  PchSpiBase)

This function disables SPI Prefetching and caching, and returns previous BIOS Control Register value before disabling.

Parameters
[in]PchSpiBasePCH SPI PCI Base Address
Return values
PreviousBIOS Control Register value

Definition at line 139 of file PchSpi.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]SpiRegionTypeThe 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.

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.

◆ SetSpiBiosControlRegister()

VOID SetSpiBiosControlRegister ( IN UINTN  PchSpiBase,
IN UINT8  BiosCtlValue 
)

This function updates BIOS Control Register with the given value.

Parameters
[in]PchSpiBasePCH SPI PCI Base Address
[in]BiosCtlValueBIOS Control Register Value to be updated
Return values
None

This function updates BIOS Control Register with the given value.

Parameters
[in]PchSpiBasePCH SPI PCI Base Address
[in]BiosCtlValueBIOS Control Register Value to be updated

Definition at line 164 of file PchSpi.c.

◆ WaitForSpiCycleComplete()

BOOLEAN WaitForSpiCycleComplete ( IN UINT32  ScSpiBar0,
IN BOOLEAN  ErrorCheck 
)

Wait execution cycle to complete on the SPI interface.

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

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.