123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396 |
- /** @file
- Header file for the PCH SPI Common Driver.
- Copyright (c) 2019 Intel Corporation. All rights reserved. <BR>
- SPDX-License-Identifier: BSD-2-Clause-Patent
- **/
- #ifndef _PCH_SPI_COMMON_LIB_H_
- #define _PCH_SPI_COMMON_LIB_H_
- //
- // Maximum time allowed while waiting the SPI cycle to complete
- // Wait Time = 6 seconds = 6000000 microseconds
- // Wait Period = 10 microseconds
- //
- #define SPI_WAIT_TIME 6000000 ///< Wait Time = 6 seconds = 6000000 microseconds
- #define SPI_WAIT_PERIOD 10 ///< Wait Period = 10 microseconds
- ///
- /// Flash cycle Type
- ///
- typedef enum {
- FlashCycleRead,
- FlashCycleWrite,
- FlashCycleErase,
- FlashCycleReadSfdp,
- FlashCycleReadJedecId,
- FlashCycleWriteStatus,
- FlashCycleReadStatus,
- FlashCycleMax
- } FLASH_CYCLE_TYPE;
- ///
- /// Flash Component Number
- ///
- typedef enum {
- FlashComponent0,
- FlashComponent1,
- FlashComponentMax
- } FLASH_COMPONENT_NUM;
- ///
- /// Private data structure definitions for the driver
- ///
- #define PCH_SPI_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('P', 'S', 'P', 'I')
- typedef struct {
- UINT32 Signature;
- EFI_HANDLE Handle;
- EFI_SPI_PROTOCOL SpiProtocol;
- UINT16 PchAcpiBase;
- UINTN PchSpiBase;
- UINT16 ReadPermission;
- UINT16 WritePermission;
- UINT32 SfdpVscc0Value;
- UINT32 SfdpVscc1Value;
- UINT16 PchStrapBaseAddr;
- UINT16 PchStrapSize;
- UINT16 CpuStrapBaseAddr;
- UINT16 CpuStrapSize;
- UINT8 NumberOfComponents;
- UINT32 Component1StartAddr;
- UINT32 TotalFlashSize;
- } SPI_INSTANCE;
- #define SPI_INSTANCE_FROM_SPIPROTOCOL(a) CR (a, SPI_INSTANCE, SpiProtocol, PCH_SPI_PRIVATE_DATA_SIGNATURE)
- //
- // Function prototypes used by the SPI protocol.
- //
- /**
- Initialize an SPI protocol instance.
- @param[in] SpiInstance Pointer to SpiInstance to initialize
- @retval EFI_SUCCESS The protocol instance was properly initialized
- @exception EFI_UNSUPPORTED The PCH is not supported by this module
- **/
- EFI_STATUS
- SpiProtocolConstructor (
- IN SPI_INSTANCE *SpiInstance
- );
- /**
- This function is a hook for Spi to disable BIOS Write Protect
- @retval EFI_SUCCESS The protocol instance was properly initialized
- @retval EFI_ACCESS_DENIED The BIOS Region can only be updated in SMM phase
- **/
- EFI_STATUS
- EFIAPI
- DisableBiosWriteProtect (
- VOID
- );
- /**
- This function is a hook for Spi to enable BIOS Write Protect
- **/
- VOID
- EFIAPI
- EnableBiosWriteProtect (
- VOID
- );
- /**
- Acquire pch spi mmio address.
- @param[in] SpiInstance Pointer to SpiInstance to initialize
- @retval PchSpiBar0 return SPI MMIO address
- **/
- UINTN
- AcquireSpiBar0 (
- IN SPI_INSTANCE *SpiInstance
- );
- /**
- Release pch spi mmio address.
- @param[in] SpiInstance Pointer to SpiInstance to initialize
- @retval None
- **/
- VOID
- ReleaseSpiBar0 (
- IN SPI_INSTANCE *SpiInstance
- );
- /**
- Read data from the flash part.
- @param[in] This Pointer to the PCH_SPI_PROTOCOL instance.
- @param[in] FlashRegionType The Flash Region type for flash cycle which is listed in the Descriptor.
- @param[in] Address The Flash Linear Address must fall within a region for which BIOS has access permissions.
- @param[in] ByteCount Number of bytes in the data portion of the SPI cycle.
- @param[out] Buffer The Pointer to caller-allocated buffer containing the dada received.
- It is the caller's responsibility to make sure Buffer is large enough for the total number of bytes read.
- @retval EFI_SUCCESS Command succeed.
- @retval EFI_INVALID_PARAMETER The parameters specified are not valid.
- @retval EFI_DEVICE_ERROR Device error, command aborts abnormally.
- **/
- EFI_STATUS
- EFIAPI
- SpiProtocolFlashRead (
- IN EFI_SPI_PROTOCOL *This,
- IN FLASH_REGION_TYPE FlashRegionType,
- IN UINT32 Address,
- IN UINT32 ByteCount,
- OUT UINT8 *Buffer
- );
- /**
- Write data to the flash part.
- @param[in] This Pointer to the PCH_SPI_PROTOCOL instance.
- @param[in] FlashRegionType The Flash Region type for flash cycle which is listed in the Descriptor.
- @param[in] Address The Flash Linear Address must fall within a region for which BIOS has access permissions.
- @param[in] ByteCount Number of bytes in the data portion of the SPI cycle.
- @param[in] Buffer Pointer to caller-allocated buffer containing the data sent during the SPI cycle.
- @retval EFI_SUCCESS Command succeed.
- @retval EFI_INVALID_PARAMETER The parameters specified are not valid.
- @retval EFI_DEVICE_ERROR Device error, command aborts abnormally.
- **/
- EFI_STATUS
- EFIAPI
- SpiProtocolFlashWrite (
- IN EFI_SPI_PROTOCOL *This,
- IN FLASH_REGION_TYPE FlashRegionType,
- IN UINT32 Address,
- IN UINT32 ByteCount,
- IN UINT8 *Buffer
- );
- /**
- Erase some area on the flash part.
- @param[in] This Pointer to the PCH_SPI_PROTOCOL instance.
- @param[in] FlashRegionType The Flash Region type for flash cycle which is listed in the Descriptor.
- @param[in] Address The Flash Linear Address must fall within a region for which BIOS has access permissions.
- @param[in] ByteCount Number of bytes in the data portion of the SPI cycle.
- @retval EFI_SUCCESS Command succeed.
- @retval EFI_INVALID_PARAMETER The parameters specified are not valid.
- @retval EFI_DEVICE_ERROR Device error, command aborts abnormally.
- **/
- EFI_STATUS
- EFIAPI
- SpiProtocolFlashErase (
- IN EFI_SPI_PROTOCOL *This,
- IN FLASH_REGION_TYPE FlashRegionType,
- IN UINT32 Address,
- IN UINT32 ByteCount
- );
- /**
- Read SFDP data from the flash part.
- @param[in] This Pointer to the PCH_SPI_PROTOCOL instance.
- @param[in] ComponentNumber The Componen Number for chip select
- @param[in] Address The starting byte address for SFDP data read.
- @param[in] ByteCount Number of bytes in SFDP data portion of the SPI cycle
- @param[out] SfdpData The 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
- @retval EFI_SUCCESS Command succeed.
- @retval EFI_INVALID_PARAMETER The parameters specified are not valid.
- @retval EFI_DEVICE_ERROR Device error, command aborts abnormally.
- **/
- EFI_STATUS
- EFIAPI
- SpiProtocolFlashReadSfdp (
- IN EFI_SPI_PROTOCOL *This,
- IN UINT8 ComponentNumber,
- IN UINT32 Address,
- IN UINT32 ByteCount,
- OUT UINT8 *SfdpData
- );
- /**
- Read Jedec Id from the flash part.
- @param[in] This Pointer to the PCH_SPI_PROTOCOL instance.
- @param[in] ComponentNumber The Componen Number for chip select
- @param[in] ByteCount Number of bytes in JedecId data portion of the SPI cycle, the data size is 3 typically
- @param[out] JedecId The 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.
- @retval EFI_SUCCESS Command succeed.
- @retval EFI_INVALID_PARAMETER The parameters specified are not valid.
- @retval EFI_DEVICE_ERROR Device error, command aborts abnormally.
- **/
- EFI_STATUS
- EFIAPI
- SpiProtocolFlashReadJedecId (
- IN EFI_SPI_PROTOCOL *This,
- IN UINT8 ComponentNumber,
- IN UINT32 ByteCount,
- OUT UINT8 *JedecId
- );
- /**
- Write the status register in the flash part.
- @param[in] This Pointer to the PCH_SPI_PROTOCOL instance.
- @param[in] ByteCount Number of bytes in Status data portion of the SPI cycle, the data size is 1 typically
- @param[in] StatusValue The Pointer to caller-allocated buffer containing the value of Status register writing
- @retval EFI_SUCCESS Command succeed.
- @retval EFI_INVALID_PARAMETER The parameters specified are not valid.
- @retval EFI_DEVICE_ERROR Device error, command aborts abnormally.
- **/
- EFI_STATUS
- EFIAPI
- SpiProtocolFlashWriteStatus (
- IN EFI_SPI_PROTOCOL *This,
- IN UINT32 ByteCount,
- IN UINT8 *StatusValue
- );
- /**
- Read status register in the flash part.
- @param[in] This Pointer to the PCH_SPI_PROTOCOL instance.
- @param[in] ByteCount Number of bytes in Status data portion of the SPI cycle, the data size is 1 typically
- @param[out] StatusValue The Pointer to caller-allocated buffer containing the value of Status register received.
- @retval EFI_SUCCESS Command succeed.
- @retval EFI_INVALID_PARAMETER The parameters specified are not valid.
- @retval EFI_DEVICE_ERROR Device error, command aborts abnormally.
- **/
- EFI_STATUS
- EFIAPI
- SpiProtocolFlashReadStatus (
- IN EFI_SPI_PROTOCOL *This,
- IN UINT32 ByteCount,
- OUT UINT8 *StatusValue
- );
- /**
- Get the SPI region base and size, based on the enum type
- @param[in] This Pointer to the PCH_SPI_PROTOCOL instance.
- @param[in] FlashRegionType The Flash Region type for for the base address which is listed in the Descriptor.
- @param[out] BaseAddress The Flash Linear Address for the Region 'n' Base
- @param[out] RegionSize The size for the Region 'n'
- @retval EFI_SUCCESS Read success
- @retval EFI_INVALID_PARAMETER Invalid region type given
- @retval EFI_DEVICE_ERROR The region is not used
- **/
- EFI_STATUS
- EFIAPI
- SpiProtocolGetRegionAddress (
- IN EFI_SPI_PROTOCOL *This,
- IN FLASH_REGION_TYPE FlashRegionType,
- OUT UINT32 *BaseAddress,
- OUT UINT32 *RegionSize
- );
- /**
- Read PCH Soft Strap Values
- @param[in] This Pointer to the PCH_SPI_PROTOCOL instance.
- @param[in] SoftStrapAddr PCH Soft Strap address offset from FPSBA.
- @param[in] ByteCount Number of bytes in SoftStrap data portion of the SPI cycle
- @param[out] SoftStrapValue The Pointer to caller-allocated buffer containing PCH Soft Strap Value.
- If the value of ByteCount is 0, the data type of SoftStrapValue should be UINT16 and SoftStrapValue will be PCH Soft Strap Length
- It is the caller's responsibility to make sure Buffer is large enough for the total number of bytes read.
- @retval EFI_SUCCESS Command succeed.
- @retval EFI_INVALID_PARAMETER The parameters specified are not valid.
- @retval EFI_DEVICE_ERROR Device error, command aborts abnormally.
- **/
- EFI_STATUS
- EFIAPI
- SpiProtocolReadPchSoftStrap (
- IN EFI_SPI_PROTOCOL *This,
- IN UINT32 SoftStrapAddr,
- IN UINT32 ByteCount,
- OUT VOID *SoftStrapValue
- );
- /**
- Read CPU Soft Strap Values
- @param[in] This Pointer to the PCH_SPI_PROTOCOL instance.
- @param[in] SoftStrapAddr CPU Soft Strap address offset from FCPUSBA.
- @param[in] ByteCount Number of bytes in SoftStrap data portion of the SPI cycle.
- @param[out] SoftStrapValue The Pointer to caller-allocated buffer containing CPU Soft Strap Value.
- If the value of ByteCount is 0, the data type of SoftStrapValue should be UINT16 and SoftStrapValue will be PCH Soft Strap Length
- It is the caller's responsibility to make sure Buffer is large enough for the total number of bytes read.
- @retval EFI_SUCCESS Command succeed.
- @retval EFI_INVALID_PARAMETER The parameters specified are not valid.
- @retval EFI_DEVICE_ERROR Device error, command aborts abnormally.
- **/
- EFI_STATUS
- EFIAPI
- SpiProtocolReadCpuSoftStrap (
- IN EFI_SPI_PROTOCOL *This,
- IN UINT32 SoftStrapAddr,
- IN UINT32 ByteCount,
- OUT VOID *SoftStrapValue
- );
- /**
- This function sends the programmed SPI command to the slave device.
- @param[in] This Pointer to the PCH_SPI_PROTOCOL instance.
- @param[in] SpiRegionType The SPI Region type for flash cycle which is listed in the Descriptor
- @param[in] FlashCycleType The Flash SPI cycle type list in HSFC (Hardware Sequencing Flash Control Register) register
- @param[in] Address The Flash Linear Address must fall within a region for which BIOS has access permissions.
- @param[in] ByteCount Number of bytes in the data portion of the SPI cycle.
- @param[in,out] Buffer Pointer to caller-allocated buffer containing the dada received or sent during the SPI cycle.
- @retval EFI_SUCCESS SPI command completes successfully.
- @retval EFI_DEVICE_ERROR Device error, the command aborts abnormally.
- @retval EFI_ACCESS_DENIED Some unrecognized command encountered in hardware sequencing mode
- @retval EFI_INVALID_PARAMETER The parameters specified are not valid.
- **/
- EFI_STATUS
- SendSpiCmd (
- IN EFI_SPI_PROTOCOL *This,
- IN FLASH_REGION_TYPE FlashRegionType,
- IN FLASH_CYCLE_TYPE FlashCycleType,
- IN UINT32 Address,
- IN UINT32 ByteCount,
- IN OUT UINT8 *Buffer
- );
- /**
- Wait execution cycle to complete on the SPI interface.
- @param[in] This The SPI protocol instance
- @param[in] PchSpiBar0 Spi MMIO base address
- @param[in] ErrorCheck TRUE if the SpiCycle needs to do the error check
- @retval TRUE SPI cycle completed on the interface.
- @retval FALSE Time out while waiting the SPI cycle to complete.
- It's not safe to program the next command on the SPI interface.
- **/
- BOOLEAN
- WaitForSpiCycleComplete (
- IN EFI_SPI_PROTOCOL *This,
- IN UINTN PchSpiBar0,
- IN BOOLEAN ErrorCheck
- );
- #endif
|