]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Include/Protocol/SpiIo.h
MdePkg FirmwareManagement.h: Fix typo EFI_SECURITY_VIOLATIO
[mirror_edk2.git] / MdePkg / Include / Protocol / SpiIo.h
CommitLineData
db04b706
MH
1/** @file\r
2 This file defines the SPI I/O 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_IO_PROTOCOL_H__\r
19#define __SPI_IO_PROTOCOL_H__\r
20\r
21#include <Protocol/LegacySpiController.h>\r
22#include <Protocol/SpiConfiguration.h>\r
23\r
24typedef struct _EFI_SPI_IO_PROTOCOL EFI_SPI_IO_PROTOCOL;\r
25\r
26///\r
27/// Note: The UEFI PI 1.6 specification does not specify values for the\r
28/// members below. The order matches the specification.\r
29///\r
30typedef enum {\r
31 ///\r
32 /// Data flowing in both direction between the host and\r
33 /// SPI peripheral.ReadBytes must equal WriteBytes and both ReadBuffer and\r
34 /// WriteBuffer must be provided.\r
35 ///\r
36 SPI_TRANSACTION_FULL_DUPLEX,\r
37\r
38 ///\r
39 /// Data flowing from the host to the SPI peripheral.ReadBytes must be\r
40 /// zero.WriteBytes must be non - zero and WriteBuffer must be provided.\r
41 ///\r
42 SPI_TRANSACTION_WRITE_ONLY,\r
43\r
44 ///\r
45 /// Data flowing from the SPI peripheral to the host.WriteBytes must be\r
46 /// zero.ReadBytes must be non - zero and ReadBuffer must be provided.\r
47 ///\r
48 SPI_TRANSACTION_READ_ONLY,\r
49\r
50 ///\r
51 /// Data first flowing from the host to the SPI peripheral and then data\r
52 /// flows from the SPI peripheral to the host.These types of operations get\r
53 /// used for SPI flash devices when control data (opcode, address) must be\r
54 /// passed to the SPI peripheral to specify the data to be read.\r
55 ///\r
56 SPI_TRANSACTION_WRITE_THEN_READ\r
57} EFI_SPI_TRANSACTION_TYPE;\r
58\r
59/**\r
60 Initiate a SPI transaction between the host and a SPI peripheral.\r
61\r
62 This routine must be called at or below TPL_NOTIFY.\r
63 This routine works with the SPI bus layer to pass the SPI transaction to the\r
64 SPI controller for execution on the SPI bus. There are four types of\r
65 supported transactions supported by this routine:\r
66 * Full Duplex: WriteBuffer and ReadBuffer are the same size.\r
67 * Write Only: WriteBuffer contains data for SPI peripheral, ReadBytes = 0\r
68 * Read Only: ReadBuffer to receive data from SPI peripheral, WriteBytes = 0\r
69 * Write Then Read: WriteBuffer contains control data to write to SPI\r
70 peripheral before data is placed into the ReadBuffer.\r
71 Both WriteBytes and ReadBytes must be non-zero.\r
72\r
73 @param[in] This Pointer to an EFI_SPI_IO_PROTOCOL structure.\r
74 @param[in] TransactionType Type of SPI transaction.\r
75 @param[in] DebugTransaction Set TRUE only when debugging is desired.\r
76 Debugging may be turned on for a single SPI\r
77 transaction. Only this transaction will display\r
78 debugging messages. All other transactions with\r
79 this value set to FALSE will not display any\r
80 debugging messages.\r
81 @param[in] ClockHz Specify the ClockHz value as zero (0) to use\r
82 the maximum clock frequency supported by the\r
83 SPI controller and part. Specify a non-zero\r
84 value only when a specific SPI transaction\r
85 requires a reduced clock rate.\r
86 @param[in] BusWidth Width of the SPI bus in bits: 1, 2, 4\r
87 @param[in] FrameSize Frame size in bits, range: 1 - 32\r
88 @param[in] WriteBytes The length of the WriteBuffer in bytes.\r
89 Specify zero for read-only operations.\r
90 @param[in] WriteBuffer The buffer containing data to be sent from the\r
91 host to the SPI chip. Specify NULL for read\r
92 only operations.\r
93 * Frame sizes 1-8 bits: UINT8 (one byte) per\r
94 frame\r
95 * Frame sizes 7-16 bits: UINT16 (two bytes) per\r
96 frame\r
97 * Frame sizes 17-32 bits: UINT32 (four bytes)\r
98 per frame The transmit frame is in the least\r
99 significant N bits.\r
100 @param[in] ReadBytes The length of the ReadBuffer in bytes.\r
101 Specify zero for write-only operations.\r
102 @param[out] ReadBuffer The buffer to receeive data from the SPI chip\r
103 during the transaction. Specify NULL for write\r
104 only operations.\r
105 * Frame sizes 1-8 bits: UINT8 (one byte) per\r
106 frame\r
107 * Frame sizes 7-16 bits: UINT16 (two bytes) per\r
108 frame\r
109 * Frame sizes 17-32 bits: UINT32 (four bytes)\r
110 per frame The received frame is in the least\r
111 significant N bits.\r
112\r
113 @retval EFI_SUCCESS The SPI transaction completed successfully\r
114 @retval EFI_BAD_BUFFER_SIZE The writeBytes value was invalid\r
115 @retval EFI_BAD_BUFFER_SIZE The ReadBytes value was invalid\r
116 @retval EFI_INVALID_PARAMETER TransactionType is not valid,\r
117 or BusWidth not supported by SPI peripheral or\r
118 SPI host controller,\r
119 or WriteBytes non-zero and WriteBuffer is\r
120 NULL,\r
121 or ReadBytes non-zero and ReadBuffer is NULL,\r
122 or ReadBuffer != WriteBuffer for full-duplex\r
123 type,\r
124 or WriteBuffer was NULL,\r
125 or TPL is too high\r
126 @retval EFI_OUT_OF_RESOURCES Insufficient memory for SPI transaction\r
127 @retval EFI_UNSUPPORTED The FrameSize is not supported by the SPI bus\r
128 layer or the SPI host controller\r
129 @retval EFI_UNSUPPORTED The SPI controller was not able to support\r
130\r
131**/\r
132typedef\r
133EFI_STATUS\r
134(EFIAPI *EFI_SPI_IO_PROTOCOL_TRANSACTION) (\r
135 IN CONST EFI_SPI_IO_PROTOCOL *This,\r
136 IN EFI_SPI_TRANSACTION_TYPE TransactionType,\r
137 IN BOOLEAN DebugTransaction,\r
138 IN UINT32 ClockHz OPTIONAL,\r
139 IN UINT32 BusWidth,\r
140 IN UINT32 FrameSize,\r
141 IN UINT32 WriteBytes,\r
142 IN UINT8 *WriteBuffer,\r
143 IN UINT32 ReadBytes,\r
144 OUT UINT8 *ReadBuffer\r
145 );\r
146\r
147/**\r
148 Update the SPI peripheral associated with this SPI 10 instance.\r
149\r
150 Support socketed SPI parts by allowing the SPI peripheral driver to replace\r
151 the SPI peripheral after the connection is made. An example use is socketed\r
152 SPI NOR flash parts, where the size and parameters change depending upon\r
153 device is in the socket.\r
154\r
155 @param[in] This Pointer to an EFI_SPI_IO_PROTOCOL structure.\r
156 @param[in] SpiPeripheral Pointer to an EFI_SPI_PERIPHERAL structure.\r
157\r
158 @retval EFI_SUCCESS The SPI peripheral was updated successfully\r
159 @retval EFI_INVALID_PARAMETER The SpiPeripheral value is NULL,\r
160 or the SpiPeripheral->SpiBus is NULL,\r
161 or the SpiP eripheral - >SpiBus pointing at\r
162 wrong bus,\r
163 or the SpiP eripheral - >SpiPart is NULL\r
164\r
165**/\r
166typedef EFI_STATUS\r
167(EFIAPI *EFI_SPI_IO_PROTOCOL_UPDATE_SPI_PERIPHERAL) (\r
168 IN CONST EFI_SPI_IO_PROTOCOL *This,\r
169 IN CONST EFI_SPI_PERIPHERAL *SpiPeripheral\r
170 );\r
171\r
172///\r
173/// The EFI_SPI_BUS_ TRANSACTION data structure contains the description of the\r
174/// SPI transaction to perform on the host controller.\r
175///\r
176typedef struct _EFI_SPI_BUS_TRANSACTION {\r
177 ///\r
178 /// Pointer to the SPI peripheral being manipulated.\r
179 ///\r
180 CONST EFI_SPI_PERIPHERAL *SpiPeripheral;\r
181\r
182 ///\r
183 /// Type of transaction specified by one of the EFI_SPI_TRANSACTION_TYPE\r
184 /// values.\r
185 ///\r
186 EFI_SPI_TRANSACTION_TYPE TransactionType;\r
187\r
188 ///\r
189 /// TRUE if the transaction is being debugged. Debugging may be turned on for\r
190 /// a single SPI transaction. Only this transaction will display debugging\r
191 /// messages. All other transactions with this value set to FALSE will not\r
192 /// display any debugging messages.\r
193 ///\r
194 BOOLEAN DebugTransaction;\r
195\r
196 ///\r
197 /// SPI bus width in bits: 1, 2, 4\r
198 ///\r
199 UINT32 BusWidth;\r
200\r
201 ///\r
202 /// Frame size in bits, range: 1 - 32\r
203 ///\r
204 UINT32 FrameSize;\r
205\r
206 ///\r
207 /// Length of the write buffer in bytes\r
208 ///\r
209 UINT32 WriteBytes;\r
210\r
211 ///\r
212 /// Buffer containing data to send to the SPI peripheral\r
213 /// Frame sizes 1 - 8 bits: UINT8 (one byte) per frame\r
214 /// Frame sizes 7 - 16 bits : UINT16 (two bytes) per frame\r
215 ///\r
216 UINT8 *WriteBuffer;\r
217\r
218 ///\r
219 /// Length of the read buffer in bytes\r
220 ///\r
221 UINT32 ReadBytes;\r
222\r
223 ///\r
224 /// Buffer to receive the data from the SPI peripheral\r
225 /// * Frame sizes 1 - 8 bits: UINT8 (one byte) per frame\r
226 /// * Frame sizes 7 - 16 bits : UINT16 (two bytes) per frame\r
227 /// * Frame sizes 17 - 32 bits : UINT32 (four bytes) per frame\r
228 ///\r
229 UINT8 *ReadBuffer;\r
230} EFI_SPI_BUS_TRANSACTION;\r
231\r
232///\r
233/// Support managed SPI data transactions between the SPI controller and a SPI\r
234/// chip.\r
235///\r
236struct _EFI_SPI_IO_PROTOCOL {\r
237 ///\r
238 /// Address of an EFI_SPI_PERIPHERAL data structure associated with this\r
239 /// protocol instance.\r
240 ///\r
241 CONST EFI_SPI_PERIPHERAL *SpiPeripheral;\r
242\r
243 ///\r
244 /// Address of the original EFI_SPI_PERIPHERAL data structure associated with\r
245 /// this protocol instance.\r
246 ///\r
247 CONST EFI_SPI_PERIPHERAL *OriginalSpiPeripheral;\r
248\r
249 ///\r
250 /// Mask of frame sizes which the SPI 10 layer supports. Frame size of N-bits\r
251 /// is supported when bit N-1 is set. The host controller must support a\r
252 /// frame size of 8-bits. Frame sizes of 16, 24 and 32-bits are converted to\r
253 /// 8-bit frame sizes by the SPI bus layer if the frame size is not supported\r
254 /// by the SPI host controller.\r
255 ///\r
256 UINT32 FrameSizeSupportMask;\r
257\r
258 ///\r
259 /// Maximum transfer size in bytes: 1 - Oxffffffff\r
260 ///\r
261 UINT32 MaximumTransferBytes;\r
262\r
263 ///\r
264 /// Transaction attributes: One or more from:\r
265 /// * SPI_10_SUPPORTS_2_B1T_DATA_BUS_W1DTH\r
266 /// - The SPI host and peripheral supports a 2-bit data bus\r
267 /// * SPI_IO_SUPPORTS_4_BIT_DATA_BUS_W1DTH\r
268 /// - The SPI host and peripheral supports a 4-bit data bus\r
269 /// * SPI_IO_TRANSFER_SIZE_INCLUDES_OPCODE\r
270 /// - Transfer size includes the opcode byte\r
271 /// * SPI_IO_TRANSFER_SIZE_INCLUDES_ADDRESS\r
272 /// - Transfer size includes the 3 address bytes\r
273 ///\r
274 UINT32 Attributes;\r
275\r
276 ///\r
277 /// Pointer to legacy SPI controller protocol\r
278 ///\r
279 CONST EFI_LEGACY_SPI_CONTROLLER_PROTOCOL *LegacySpiProtocol;\r
280\r
281 ///\r
282 /// Initiate a SPI transaction between the host and a SPI peripheral.\r
283 ///\r
284 EFI_SPI_IO_PROTOCOL_TRANSACTION Transaction;\r
285\r
286 ///\r
287 /// Update the SPI peripheral associated with this SPI 10 instance.\r
288 ///\r
289 EFI_SPI_IO_PROTOCOL_UPDATE_SPI_PERIPHERAL UpdateSpiPeripheral;\r
290};\r
291\r
292#endif // __SPI_IO_PROTOCOL_H__\r