2 This file defines the SPI NOR Flash Protocol.
4 Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
7 @par Revision Reference:
8 This Protocol was introduced in UEFI PI Specification 1.6.
12 #ifndef __SPI_NOR_FLASH_PROTOCOL_H__
13 #define __SPI_NOR_FLASH_PROTOCOL_H__
15 #include <Protocol/SpiConfiguration.h>
18 /// Global ID for the SPI NOR Flash Protocol
20 #define EFI_SPI_NOR_FLASH_PROTOCOL_GUID \
21 { 0xb57ec3fe, 0xf833, 0x4ba6, \
22 { 0x85, 0x78, 0x2a, 0x7d, 0x6a, 0x87, 0x44, 0x4b }}
24 typedef struct _EFI_SPI_NOR_FLASH_PROTOCOL EFI_SPI_NOR_FLASH_PROTOCOL
;
27 Read the 3 byte manufacture and device ID from the SPI flash.
29 This routine must be called at or below TPL_NOTIFY.
30 This routine reads the 3 byte manufacture and device ID from the flash part
31 filling the buffer provided.
33 @param[in] This Pointer to an EFI_SPI_NOR_FLASH_PROTOCOL data structure.
34 @param[out] Buffer Pointer to a 3 byte buffer to receive the manufacture and
39 @retval EFI_SUCCESS The manufacture and device ID was read
41 @retval EFI_INVALID_PARAMETER Buffer is NULL
42 @retval EFI_DEVICE_ERROR Invalid data received from SPI flash part.
47 (EFIAPI
*EFI_SPI_NOR_FLASH_PROTOCOL_GET_FLASH_ID
) (
48 IN CONST EFI_SPI_NOR_FLASH_PROTOCOL
*This
,
53 Read data from the SPI flash.
55 This routine must be called at or below TPL_NOTIFY.
56 This routine reads data from the SPI part in the buffer provided.
58 @param[in] This Pointer to an EFI_SPI_NOR_FLASH_PROTOCOL data
60 @param[in] FlashAddress Address in the flash to start reading
61 @param[in] LengthInBytes Read length in bytes
62 @param[out] Buffer Address of a buffer to receive the data
64 @retval EFI_SUCCESS The data was read successfully.
65 @retval EFI_INVALID_PARAMETER Buffer is NULL, or
66 FlashAddress >= This->FlashSize, or
67 LengthInBytes > This->FlashSize - FlashAddress
72 (EFIAPI
*EFI_SPI_NOR_FLASH_PROTOCOL_READ_DATA
) (
73 IN CONST EFI_SPI_NOR_FLASH_PROTOCOL
*This
,
74 IN UINT32 FlashAddress
,
75 IN UINT32 LengthInBytes
,
80 Read the flash status register.
82 This routine must be called at or below TPL_NOTIFY.
83 This routine reads the flash part status register.
85 @param[in] This Pointer to an EFI_SPI_NOR_FLASH_PROTOCOL data
87 @param[in] LengthInBytes Number of status bytes to read.
88 @param[out] FlashStatus Pointer to a buffer to receive the flash status.
90 @retval EFI_SUCCESS The status register was read successfully.
95 (EFIAPI
*EFI_SPI_NOR_FLASH_PROTOCOL_READ_STATUS
) (
96 IN CONST EFI_SPI_NOR_FLASH_PROTOCOL
*This
,
97 IN UINT32 LengthInBytes
,
98 OUT UINT8
*FlashStatus
102 Write the flash status register.
104 This routine must be called at or below TPL_N OTIFY.
105 This routine writes the flash part status register.
107 @param[in] This Pointer to an EFI_SPI_NOR_FLASH_PROTOCOL data
109 @param[in] LengthInBytes Number of status bytes to write.
110 @param[in] FlashStatus Pointer to a buffer containing the new status.
112 @retval EFI_SUCCESS The status write was successful.
113 @retval EFI_OUT_OF_RESOURCES Failed to allocate the write buffer.
118 (EFIAPI
*EFI_SPI_NOR_FLASH_PROTOCOL_WRITE_STATUS
) (
119 IN CONST EFI_SPI_NOR_FLASH_PROTOCOL
*This
,
120 IN UINT32 LengthInBytes
,
121 IN UINT8
*FlashStatus
125 Write data to the SPI flash.
127 This routine must be called at or below TPL_NOTIFY.
128 This routine breaks up the write operation as necessary to write the data to
131 @param[in] This Pointer to an EFI_SPI_NOR_FLASH_PROTOCOL data
133 @param[in] FlashAddress Address in the flash to start writing
134 @param[in] LengthInBytes Write length in bytes
135 @param[in] Buffer Address of a buffer containing the data
137 @retval EFI_SUCCESS The data was written successfully.
138 @retval EFI_INVALID_PARAMETER Buffer is NULL, or
139 FlashAddress >= This->FlashSize, or
140 LengthInBytes > This->FlashSize - FlashAddress
141 @retval EFI_OUT_OF_RESOURCES Insufficient memory to copy buffer.
146 (EFIAPI
*EFI_SPI_NOR_FLASH_PROTOCOL_WRITE_DATA
) (
147 IN CONST EFI_SPI_NOR_FLASH_PROTOCOL
*This
,
148 IN UINT32 FlashAddress
,
149 IN UINT32 LengthInBytes
,
154 Efficiently erases one or more 4KiB regions in the SPI flash.
156 This routine must be called at or below TPL_NOTIFY.
157 This routine uses a combination of 4 KiB and larger blocks to erase the
160 @param[in] This Pointer to an EFI_SPI_NOR_FLASH_PROTOCOL data
162 @param[in] FlashAddress Address within a 4 KiB block to start erasing
163 @param[in] BlockCount Number of 4 KiB blocks to erase
165 @retval EFI_SUCCESS The erase was completed successfully.
166 @retval EFI_INVALID_PARAMETER FlashAddress >= This->FlashSize, or
168 > This->FlashSize - FlashAddress
173 (EFIAPI
*EFI_SPI_NOR_FLASH_PROTOCOL_ERASE
) (
174 IN CONST EFI_SPI_NOR_FLASH_PROTOCOL
*This
,
175 IN UINT32 FlashAddress
,
180 /// The EFI_SPI_NOR_FLASH_PROTOCOL exists in the SPI peripheral layer.
181 /// This protocol manipulates the SPI NOR flash parts using a common set of
182 /// commands. The board layer provides the interconnection and configuration
183 /// details for the SPI NOR flash part. The SPI NOR flash driver uses this
184 /// configuration data to expose a generic interface which provides the
186 /// * Read manufacture and device ID
188 /// * Read data using low frequency
191 /// * Erase 4 KiB blocks
192 /// * Erase 32 or 64 KiB blocks
194 /// The EFI_SPI_NOR_FLASH_PROTOCOL also exposes some APls to set the security
195 /// features on the legacy SPI flash controller.
197 struct _EFI_SPI_NOR_FLASH_PROTOCOL
{
199 /// Pointer to an EFI_SPI_PERIPHERAL data structure
201 CONST EFI_SPI_PERIPHERAL
*SpiPeripheral
;
204 /// Flash size in bytes
209 /// Manufacture and Device ID
214 /// Erase block size in bytes
216 UINT32 EraseBlockBytes
;
219 /// Read the 3 byte manufacture and device ID from the SPI flash.
221 EFI_SPI_NOR_FLASH_PROTOCOL_GET_FLASH_ID GetFlashid
;
224 /// Read data from the SPI flash.
226 EFI_SPI_NOR_FLASH_PROTOCOL_READ_DATA ReadData
;
229 /// Low frequency read data from the SPI flash.
231 EFI_SPI_NOR_FLASH_PROTOCOL_READ_DATA LfReadData
;
234 /// Read the flash status register.
236 EFI_SPI_NOR_FLASH_PROTOCOL_READ_STATUS ReadStatus
;
239 /// Write the flash status register.
241 EFI_SPI_NOR_FLASH_PROTOCOL_WRITE_STATUS WriteStatus
;
244 /// Write data to the SPI flash.
246 EFI_SPI_NOR_FLASH_PROTOCOL_WRITE_DATA WriteData
;
249 /// Efficiently erases one or more 4KiB regions in the SPI flash.
251 EFI_SPI_NOR_FLASH_PROTOCOL_ERASE Erase
;
254 extern EFI_GUID gEfiSpiNorFlashProtocolGuid
;
256 #endif // __SPI_NOR_FLASH_PROTOCOL_H__