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