]>
Commit | Line | Data |
---|---|---|
db04b706 MH |
1 | /** @file\r |
2 | This file defines the SPI NOR Flash Protocol.\r | |
3 | \r | |
4 | Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>\r | |
9344f092 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
db04b706 MH |
6 | \r |
7 | @par Revision Reference:\r | |
8 | This Protocol was introduced in UEFI PI Specification 1.6.\r | |
9 | \r | |
10 | **/\r | |
11 | \r | |
12 | #ifndef __SPI_NOR_FLASH_PROTOCOL_H__\r | |
13 | #define __SPI_NOR_FLASH_PROTOCOL_H__\r | |
14 | \r | |
15 | #include <Protocol/SpiConfiguration.h>\r | |
16 | \r | |
17 | ///\r | |
18 | /// Global ID for the SPI NOR Flash Protocol\r | |
19 | ///\r | |
20 | #define EFI_SPI_NOR_FLASH_PROTOCOL_GUID \\r | |
21 | { 0xb57ec3fe, 0xf833, 0x4ba6, \\r | |
22 | { 0x85, 0x78, 0x2a, 0x7d, 0x6a, 0x87, 0x44, 0x4b }}\r | |
23 | \r | |
24 | typedef struct _EFI_SPI_NOR_FLASH_PROTOCOL EFI_SPI_NOR_FLASH_PROTOCOL;\r | |
25 | \r | |
26 | /**\r | |
27 | Read the 3 byte manufacture and device ID from the SPI flash.\r | |
28 | \r | |
29 | This routine must be called at or below TPL_NOTIFY.\r | |
30 | This routine reads the 3 byte manufacture and device ID from the flash part\r | |
31 | filling the buffer provided.\r | |
32 | \r | |
33 | @param[in] This Pointer to an EFI_SPI_NOR_FLASH_PROTOCOL data structure.\r | |
34 | @param[out] Buffer Pointer to a 3 byte buffer to receive the manufacture and\r | |
35 | device ID.\r | |
36 | \r | |
37 | \r | |
38 | \r | |
39 | @retval EFI_SUCCESS The manufacture and device ID was read\r | |
40 | successfully.\r | |
41 | @retval EFI_INVALID_PARAMETER Buffer is NULL\r | |
42 | @retval EFI_DEVICE_ERROR Invalid data received from SPI flash part.\r | |
43 | \r | |
44 | **/\r | |
45 | typedef\r | |
46 | EFI_STATUS\r | |
47 | (EFIAPI *EFI_SPI_NOR_FLASH_PROTOCOL_GET_FLASH_ID) (\r | |
48 | IN CONST EFI_SPI_NOR_FLASH_PROTOCOL *This,\r | |
49 | OUT UINT8 *Buffer\r | |
50 | );\r | |
51 | \r | |
52 | /**\r | |
53 | Read data from the SPI flash.\r | |
54 | \r | |
55 | This routine must be called at or below TPL_NOTIFY.\r | |
56 | This routine reads data from the SPI part in the buffer provided.\r | |
57 | \r | |
58 | @param[in] This Pointer to an EFI_SPI_NOR_FLASH_PROTOCOL data\r | |
59 | structure.\r | |
60 | @param[in] FlashAddress Address in the flash to start reading\r | |
61 | @param[in] LengthInBytes Read length in bytes\r | |
62 | @param[out] Buffer Address of a buffer to receive the data\r | |
63 | \r | |
64 | @retval EFI_SUCCESS The data was read successfully.\r | |
65 | @retval EFI_INVALID_PARAMETER Buffer is NULL, or\r | |
66 | FlashAddress >= This->FlashSize, or\r | |
67 | LengthInBytes > This->FlashSize - FlashAddress\r | |
68 | \r | |
69 | **/\r | |
70 | typedef\r | |
71 | EFI_STATUS\r | |
72 | (EFIAPI *EFI_SPI_NOR_FLASH_PROTOCOL_READ_DATA) (\r | |
73 | IN CONST EFI_SPI_NOR_FLASH_PROTOCOL *This,\r | |
74 | IN UINT32 FlashAddress,\r | |
75 | IN UINT32 LengthInBytes,\r | |
76 | OUT UINT8 *Buffer\r | |
77 | );\r | |
78 | \r | |
79 | /**\r | |
80 | Read the flash status register.\r | |
81 | \r | |
82 | This routine must be called at or below TPL_NOTIFY.\r | |
83 | This routine reads the flash part status register.\r | |
84 | \r | |
85 | @param[in] This Pointer to an EFI_SPI_NOR_FLASH_PROTOCOL data\r | |
86 | structure.\r | |
87 | @param[in] LengthInBytes Number of status bytes to read.\r | |
88 | @param[out] FlashStatus Pointer to a buffer to receive the flash status.\r | |
89 | \r | |
90 | @retval EFI_SUCCESS The status register was read successfully.\r | |
91 | \r | |
92 | **/\r | |
93 | typedef\r | |
94 | EFI_STATUS\r | |
95 | (EFIAPI *EFI_SPI_NOR_FLASH_PROTOCOL_READ_STATUS) (\r | |
96 | IN CONST EFI_SPI_NOR_FLASH_PROTOCOL *This,\r | |
97 | IN UINT32 LengthInBytes,\r | |
98 | OUT UINT8 *FlashStatus\r | |
99 | );\r | |
100 | \r | |
101 | /**\r | |
102 | Write the flash status register.\r | |
103 | \r | |
104 | This routine must be called at or below TPL_N OTIFY.\r | |
105 | This routine writes the flash part status register.\r | |
106 | \r | |
107 | @param[in] This Pointer to an EFI_SPI_NOR_FLASH_PROTOCOL data\r | |
108 | structure.\r | |
109 | @param[in] LengthInBytes Number of status bytes to write.\r | |
110 | @param[in] FlashStatus Pointer to a buffer containing the new status.\r | |
111 | \r | |
112 | @retval EFI_SUCCESS The status write was successful.\r | |
113 | @retval EFI_OUT_OF_RESOURCES Failed to allocate the write buffer.\r | |
114 | \r | |
115 | **/\r | |
116 | typedef\r | |
117 | EFI_STATUS\r | |
118 | (EFIAPI *EFI_SPI_NOR_FLASH_PROTOCOL_WRITE_STATUS) (\r | |
119 | IN CONST EFI_SPI_NOR_FLASH_PROTOCOL *This,\r | |
120 | IN UINT32 LengthInBytes,\r | |
121 | IN UINT8 *FlashStatus\r | |
122 | );\r | |
123 | \r | |
124 | /**\r | |
125 | Write data to the SPI flash.\r | |
126 | \r | |
127 | This routine must be called at or below TPL_NOTIFY.\r | |
128 | This routine breaks up the write operation as necessary to write the data to\r | |
129 | the SPI part.\r | |
130 | \r | |
131 | @param[in] This Pointer to an EFI_SPI_NOR_FLASH_PROTOCOL data\r | |
132 | structure.\r | |
133 | @param[in] FlashAddress Address in the flash to start writing\r | |
134 | @param[in] LengthInBytes Write length in bytes\r | |
135 | @param[in] Buffer Address of a buffer containing the data\r | |
136 | \r | |
137 | @retval EFI_SUCCESS The data was written successfully.\r | |
138 | @retval EFI_INVALID_PARAMETER Buffer is NULL, or\r | |
139 | FlashAddress >= This->FlashSize, or\r | |
140 | LengthInBytes > This->FlashSize - FlashAddress\r | |
141 | @retval EFI_OUT_OF_RESOURCES Insufficient memory to copy buffer.\r | |
142 | \r | |
143 | **/\r | |
144 | typedef\r | |
145 | EFI_STATUS\r | |
146 | (EFIAPI *EFI_SPI_NOR_FLASH_PROTOCOL_WRITE_DATA) (\r | |
147 | IN CONST EFI_SPI_NOR_FLASH_PROTOCOL *This,\r | |
148 | IN UINT32 FlashAddress,\r | |
149 | IN UINT32 LengthInBytes,\r | |
150 | IN UINT8 *Buffer\r | |
151 | );\r | |
152 | \r | |
153 | /**\r | |
154 | Efficiently erases one or more 4KiB regions in the SPI flash.\r | |
155 | \r | |
156 | This routine must be called at or below TPL_NOTIFY.\r | |
157 | This routine uses a combination of 4 KiB and larger blocks to erase the\r | |
158 | specified area.\r | |
159 | \r | |
160 | @param[in] This Pointer to an EFI_SPI_NOR_FLASH_PROTOCOL data\r | |
161 | structure.\r | |
162 | @param[in] FlashAddress Address within a 4 KiB block to start erasing\r | |
163 | @param[in] BlockCount Number of 4 KiB blocks to erase\r | |
164 | \r | |
165 | @retval EFI_SUCCESS The erase was completed successfully.\r | |
166 | @retval EFI_INVALID_PARAMETER FlashAddress >= This->FlashSize, or\r | |
167 | BlockCount * 4 KiB\r | |
168 | > This->FlashSize - FlashAddress\r | |
169 | \r | |
170 | **/\r | |
171 | typedef\r | |
172 | EFI_STATUS\r | |
173 | (EFIAPI *EFI_SPI_NOR_FLASH_PROTOCOL_ERASE) (\r | |
174 | IN CONST EFI_SPI_NOR_FLASH_PROTOCOL *This,\r | |
175 | IN UINT32 FlashAddress,\r | |
176 | IN UINT32 BlockCount\r | |
177 | );\r | |
178 | \r | |
179 | ///\r | |
180 | /// The EFI_SPI_NOR_FLASH_PROTOCOL exists in the SPI peripheral layer.\r | |
181 | /// This protocol manipulates the SPI NOR flash parts using a common set of\r | |
182 | /// commands. The board layer provides the interconnection and configuration\r | |
183 | /// details for the SPI NOR flash part. The SPI NOR flash driver uses this\r | |
184 | /// configuration data to expose a generic interface which provides the\r | |
185 | /// following APls:\r | |
186 | /// * Read manufacture and device ID\r | |
187 | /// * Read data\r | |
188 | /// * Read data using low frequency\r | |
189 | /// * Read status\r | |
190 | /// * Write data\r | |
191 | /// * Erase 4 KiB blocks\r | |
192 | /// * Erase 32 or 64 KiB blocks\r | |
193 | /// * Write status\r | |
194 | /// The EFI_SPI_NOR_FLASH_PROTOCOL also exposes some APls to set the security\r | |
195 | /// features on the legacy SPI flash controller.\r | |
196 | ///\r | |
197 | struct _EFI_SPI_NOR_FLASH_PROTOCOL {\r | |
198 | ///\r | |
199 | /// Pointer to an EFI_SPI_PERIPHERAL data structure\r | |
200 | ///\r | |
201 | CONST EFI_SPI_PERIPHERAL *SpiPeripheral;\r | |
202 | \r | |
203 | ///\r | |
204 | /// Flash size in bytes\r | |
205 | ///\r | |
206 | UINT32 FlashSize;\r | |
207 | \r | |
208 | ///\r | |
209 | /// Manufacture and Device ID\r | |
210 | ///\r | |
211 | UINT8 Deviceid[3];\r | |
212 | \r | |
213 | ///\r | |
214 | /// Erase block size in bytes\r | |
215 | ///\r | |
216 | UINT32 EraseBlockBytes;\r | |
217 | \r | |
218 | ///\r | |
219 | /// Read the 3 byte manufacture and device ID from the SPI flash.\r | |
220 | ///\r | |
221 | EFI_SPI_NOR_FLASH_PROTOCOL_GET_FLASH_ID GetFlashid;\r | |
222 | \r | |
223 | ///\r | |
224 | /// Read data from the SPI flash.\r | |
225 | ///\r | |
226 | EFI_SPI_NOR_FLASH_PROTOCOL_READ_DATA ReadData;\r | |
227 | \r | |
228 | ///\r | |
229 | /// Low frequency read data from the SPI flash.\r | |
230 | ///\r | |
231 | EFI_SPI_NOR_FLASH_PROTOCOL_READ_DATA LfReadData;\r | |
232 | \r | |
233 | ///\r | |
234 | /// Read the flash status register.\r | |
235 | ///\r | |
236 | EFI_SPI_NOR_FLASH_PROTOCOL_READ_STATUS ReadStatus;\r | |
237 | \r | |
238 | ///\r | |
239 | /// Write the flash status register.\r | |
240 | ///\r | |
241 | EFI_SPI_NOR_FLASH_PROTOCOL_WRITE_STATUS WriteStatus;\r | |
242 | \r | |
243 | ///\r | |
244 | /// Write data to the SPI flash.\r | |
245 | ///\r | |
246 | EFI_SPI_NOR_FLASH_PROTOCOL_WRITE_DATA WriteData;\r | |
247 | \r | |
248 | ///\r | |
249 | /// Efficiently erases one or more 4KiB regions in the SPI flash.\r | |
250 | ///\r | |
251 | EFI_SPI_NOR_FLASH_PROTOCOL_ERASE Erase;\r | |
252 | };\r | |
253 | \r | |
254 | extern EFI_GUID gEfiSpiNorFlashProtocolGuid;\r | |
255 | \r | |
256 | #endif // __SPI_NOR_FLASH_PROTOCOL_H__\r |