2 This file defines the SPI NOR Flash Protocol.
4 Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD
7 License which accompanies this distribution. The full text of the license may
8 be found at http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 @par Revision Reference:
14 This Protocol was introduced in UEFI PI Specification 1.6.
18 #ifndef __SPI_NOR_FLASH_PROTOCOL_H__
19 #define __SPI_NOR_FLASH_PROTOCOL_H__
21 #include <Protocol/SpiConfiguration.h>
24 /// Global ID for the SPI NOR Flash Protocol
26 #define EFI_SPI_NOR_FLASH_PROTOCOL_GUID \
27 { 0xb57ec3fe, 0xf833, 0x4ba6, \
28 { 0x85, 0x78, 0x2a, 0x7d, 0x6a, 0x87, 0x44, 0x4b }}
30 typedef struct _EFI_SPI_NOR_FLASH_PROTOCOL EFI_SPI_NOR_FLASH_PROTOCOL
;
33 Read the 3 byte manufacture and device ID from the SPI flash.
35 This routine must be called at or below TPL_NOTIFY.
36 This routine reads the 3 byte manufacture and device ID from the flash part
37 filling the buffer provided.
39 @param[in] This Pointer to an EFI_SPI_NOR_FLASH_PROTOCOL data structure.
40 @param[out] Buffer Pointer to a 3 byte buffer to receive the manufacture and
45 @retval EFI_SUCCESS The manufacture and device ID was read
47 @retval EFI_INVALID_PARAMETER Buffer is NULL
48 @retval EFI_DEVICE_ERROR Invalid data received from SPI flash part.
53 (EFIAPI
*EFI_SPI_NOR_FLASH_PROTOCOL_GET_FLASH_ID
) (
54 IN CONST EFI_SPI_NOR_FLASH_PROTOCOL
*This
,
59 Read data from the SPI flash.
61 This routine must be called at or below TPL_NOTIFY.
62 This routine reads data from the SPI part in the buffer provided.
64 @param[in] This Pointer to an EFI_SPI_NOR_FLASH_PROTOCOL data
66 @param[in] FlashAddress Address in the flash to start reading
67 @param[in] LengthInBytes Read length in bytes
68 @param[out] Buffer Address of a buffer to receive the data
70 @retval EFI_SUCCESS The data was read successfully.
71 @retval EFI_INVALID_PARAMETER Buffer is NULL, or
72 FlashAddress >= This->FlashSize, or
73 LengthInBytes > This->FlashSize - FlashAddress
78 (EFIAPI
*EFI_SPI_NOR_FLASH_PROTOCOL_READ_DATA
) (
79 IN CONST EFI_SPI_NOR_FLASH_PROTOCOL
*This
,
80 IN UINT32 FlashAddress
,
81 IN UINT32 LengthInBytes
,
86 Read the flash status register.
88 This routine must be called at or below TPL_NOTIFY.
89 This routine reads the flash part status register.
91 @param[in] This Pointer to an EFI_SPI_NOR_FLASH_PROTOCOL data
93 @param[in] LengthInBytes Number of status bytes to read.
94 @param[out] FlashStatus Pointer to a buffer to receive the flash status.
96 @retval EFI_SUCCESS The status register was read successfully.
101 (EFIAPI
*EFI_SPI_NOR_FLASH_PROTOCOL_READ_STATUS
) (
102 IN CONST EFI_SPI_NOR_FLASH_PROTOCOL
*This
,
103 IN UINT32 LengthInBytes
,
104 OUT UINT8
*FlashStatus
108 Write the flash status register.
110 This routine must be called at or below TPL_N OTIFY.
111 This routine writes the flash part status register.
113 @param[in] This Pointer to an EFI_SPI_NOR_FLASH_PROTOCOL data
115 @param[in] LengthInBytes Number of status bytes to write.
116 @param[in] FlashStatus Pointer to a buffer containing the new status.
118 @retval EFI_SUCCESS The status write was successful.
119 @retval EFI_OUT_OF_RESOURCES Failed to allocate the write buffer.
124 (EFIAPI
*EFI_SPI_NOR_FLASH_PROTOCOL_WRITE_STATUS
) (
125 IN CONST EFI_SPI_NOR_FLASH_PROTOCOL
*This
,
126 IN UINT32 LengthInBytes
,
127 IN UINT8
*FlashStatus
131 Write data to the SPI flash.
133 This routine must be called at or below TPL_NOTIFY.
134 This routine breaks up the write operation as necessary to write the data to
137 @param[in] This Pointer to an EFI_SPI_NOR_FLASH_PROTOCOL data
139 @param[in] FlashAddress Address in the flash to start writing
140 @param[in] LengthInBytes Write length in bytes
141 @param[in] Buffer Address of a buffer containing the data
143 @retval EFI_SUCCESS The data was written successfully.
144 @retval EFI_INVALID_PARAMETER Buffer is NULL, or
145 FlashAddress >= This->FlashSize, or
146 LengthInBytes > This->FlashSize - FlashAddress
147 @retval EFI_OUT_OF_RESOURCES Insufficient memory to copy buffer.
152 (EFIAPI
*EFI_SPI_NOR_FLASH_PROTOCOL_WRITE_DATA
) (
153 IN CONST EFI_SPI_NOR_FLASH_PROTOCOL
*This
,
154 IN UINT32 FlashAddress
,
155 IN UINT32 LengthInBytes
,
160 Efficiently erases one or more 4KiB regions in the SPI flash.
162 This routine must be called at or below TPL_NOTIFY.
163 This routine uses a combination of 4 KiB and larger blocks to erase the
166 @param[in] This Pointer to an EFI_SPI_NOR_FLASH_PROTOCOL data
168 @param[in] FlashAddress Address within a 4 KiB block to start erasing
169 @param[in] BlockCount Number of 4 KiB blocks to erase
171 @retval EFI_SUCCESS The erase was completed successfully.
172 @retval EFI_INVALID_PARAMETER FlashAddress >= This->FlashSize, or
174 > This->FlashSize - FlashAddress
179 (EFIAPI
*EFI_SPI_NOR_FLASH_PROTOCOL_ERASE
) (
180 IN CONST EFI_SPI_NOR_FLASH_PROTOCOL
*This
,
181 IN UINT32 FlashAddress
,
186 /// The EFI_SPI_NOR_FLASH_PROTOCOL exists in the SPI peripheral layer.
187 /// This protocol manipulates the SPI NOR flash parts using a common set of
188 /// commands. The board layer provides the interconnection and configuration
189 /// details for the SPI NOR flash part. The SPI NOR flash driver uses this
190 /// configuration data to expose a generic interface which provides the
192 /// * Read manufacture and device ID
194 /// * Read data using low frequency
197 /// * Erase 4 KiB blocks
198 /// * Erase 32 or 64 KiB blocks
200 /// The EFI_SPI_NOR_FLASH_PROTOCOL also exposes some APls to set the security
201 /// features on the legacy SPI flash controller.
203 struct _EFI_SPI_NOR_FLASH_PROTOCOL
{
205 /// Pointer to an EFI_SPI_PERIPHERAL data structure
207 CONST EFI_SPI_PERIPHERAL
*SpiPeripheral
;
210 /// Flash size in bytes
215 /// Manufacture and Device ID
220 /// Erase block size in bytes
222 UINT32 EraseBlockBytes
;
225 /// Read the 3 byte manufacture and device ID from the SPI flash.
227 EFI_SPI_NOR_FLASH_PROTOCOL_GET_FLASH_ID GetFlashid
;
230 /// Read data from the SPI flash.
232 EFI_SPI_NOR_FLASH_PROTOCOL_READ_DATA ReadData
;
235 /// Low frequency read data from the SPI flash.
237 EFI_SPI_NOR_FLASH_PROTOCOL_READ_DATA LfReadData
;
240 /// Read the flash status register.
242 EFI_SPI_NOR_FLASH_PROTOCOL_READ_STATUS ReadStatus
;
245 /// Write the flash status register.
247 EFI_SPI_NOR_FLASH_PROTOCOL_WRITE_STATUS WriteStatus
;
250 /// Write data to the SPI flash.
252 EFI_SPI_NOR_FLASH_PROTOCOL_WRITE_DATA WriteData
;
255 /// Efficiently erases one or more 4KiB regions in the SPI flash.
257 EFI_SPI_NOR_FLASH_PROTOCOL_ERASE Erase
;
260 extern EFI_GUID gEfiSpiNorFlashProtocolGuid
;
262 #endif // __SPI_NOR_FLASH_PROTOCOL_H__