]> git.proxmox.com Git - mirror_edk2.git/blame - QuarkSocPkg/QuarkNorthCluster/Include/Protocol/Spi.h
QuarkSocPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / QuarkSocPkg / QuarkNorthCluster / Include / Protocol / Spi.h
CommitLineData
9b6bbcdb
MK
1/** @file\r
2This file defines the EFI SPI Protocol which implements the\r
3Intel(R) ICH SPI Host Controller Compatibility Interface.\r
4\r
5Copyright (c) 2013-2015 Intel Corporation.\r
6\r
c9f231d0 7SPDX-License-Identifier: BSD-2-Clause-Patent\r
9b6bbcdb
MK
8\r
9\r
10**/\r
11#ifndef _SPI_H_\r
12#define _SPI_H_\r
13\r
14//\r
15// Define the SPI protocol GUID\r
16//\r
17// EDK and EDKII have different GUID formats\r
18//\r
19#if !defined(EDK_RELEASE_VERSION) || (EDK_RELEASE_VERSION < 0x00020000)\r
20#define EFI_SPI_PROTOCOL_GUID \\r
21 { \\r
22 0x1156efc6, 0xea32, 0x4396, 0xb5, 0xd5, 0x26, 0x93, 0x2e, 0x83, 0xc3, 0x13 \\r
23 }\r
24#define EFI_SMM_SPI_PROTOCOL_GUID \\r
25 { \\r
26 0xD9072C35, 0xEB8F, 0x43ad, 0xA2, 0x20, 0x34, 0xD4, 0x0E, 0x2A, 0x82, 0x85 \\r
27 }\r
28#else\r
29#define EFI_SPI_PROTOCOL_GUID \\r
30 { \\r
31 0x1156efc6, 0xea32, 0x4396, \\r
32 { \\r
33 0xb5, 0xd5, 0x26, 0x93, 0x2e, 0x83, 0xc3, 0x13 \\r
34 } \\r
35 }\r
36#define EFI_SMM_SPI_PROTOCOL_GUID \\r
37 { \\r
38 0xD9072C35, 0xEB8F, 0x43ad, \\r
39 { \\r
40 0xA2, 0x20, 0x34, 0xD4, 0x0E, 0x2A, 0x82, 0x85 \\r
41 } \\r
42 }\r
43#endif\r
44//\r
45// Extern the GUID for protocol users.\r
46//\r
47extern EFI_GUID gEfiSpiProtocolGuid;\r
48extern EFI_GUID gEfiSmmSpiProtocolGuid;\r
49\r
50//\r
51// Forward reference for ANSI C compatibility\r
52//\r
53typedef struct _EFI_SPI_PROTOCOL EFI_SPI_PROTOCOL;\r
54\r
55//\r
56// SPI protocol data structures and definitions\r
57//\r
58//\r
59// Number of Prefix Opcodes allowed on the SPI interface\r
60//\r
61#define SPI_NUM_PREFIX_OPCODE 2\r
62\r
63//\r
64// Number of Opcodes in the Opcode Menu\r
65//\r
66#define SPI_NUM_OPCODE 8\r
67\r
68#ifdef SERVER_BIOS_FLAG\r
69//\r
70// SPI default opcode slots\r
71//\r
72#define SPI_OPCODE_JEDEC_ID_INDEX 0\r
73#endif // SERVER_BIOS_FLAG\r
74\r
75//\r
76// Opcode Type\r
77// EnumSpiOpcodeCommand: Command without address\r
78// EnumSpiOpcodeRead: Read with address\r
79// EnumSpiOpcodeWrite: Write with address\r
80//\r
81typedef enum {\r
82 EnumSpiOpcodeReadNoAddr,\r
83 EnumSpiOpcodeWriteNoAddr,\r
84 EnumSpiOpcodeRead,\r
85 EnumSpiOpcodeWrite,\r
86 EnumSpiOpcodeMax\r
87} SPI_OPCODE_TYPE;\r
88\r
89typedef enum {\r
90 EnumSpiCycle20MHz,\r
91 EnumSpiCycle33MHz,\r
92 EnumSpiCycle66MHz, // not supported by PCH\r
93 EnumSpiCycle50MHz,\r
94 EnumSpiCycleMax\r
95} SPI_CYCLE_FREQUENCY;\r
96\r
97typedef enum {\r
98 EnumSpiRegionAll,\r
99 EnumSpiRegionBios,\r
100 EnumSpiRegionMe,\r
101 EnumSpiRegionGbE,\r
102 EnumSpiRegionDescriptor,\r
103 EnumSpiRegionPlatformData,\r
104 EnumSpiRegionMax\r
105} SPI_REGION_TYPE;\r
106\r
107//\r
108// Hardware Sequencing required operations (as listed in CougarPoint EDS Table 5-55: "Hardware\r
109// Sequencing Commands and Opcode Requirements"\r
110//\r
111typedef enum {\r
112 EnumSpiOperationWriteStatus,\r
113 EnumSpiOperationProgramData_1_Byte,\r
114 EnumSpiOperationProgramData_64_Byte,\r
115 EnumSpiOperationReadData,\r
116 EnumSpiOperationWriteDisable,\r
117 EnumSpiOperationReadStatus,\r
118 EnumSpiOperationWriteEnable,\r
119 EnumSpiOperationFastRead,\r
120 EnumSpiOperationEnableWriteStatus,\r
121 EnumSpiOperationErase_256_Byte,\r
122 EnumSpiOperationErase_4K_Byte,\r
123 EnumSpiOperationErase_8K_Byte,\r
124 EnumSpiOperationErase_64K_Byte,\r
125 EnumSpiOperationFullChipErase,\r
126 EnumSpiOperationJedecId,\r
127 EnumSpiOperationDualOutputFastRead,\r
128 EnumSpiOperationDiscoveryParameters,\r
129 EnumSpiOperationOther,\r
130 EnumSpiOperationMax\r
131} SPI_OPERATION;\r
132\r
133//\r
134// Opcode menu entries\r
135// Type Operation Type (value to be programmed to the OPTYPE register)\r
136// Code The opcode (value to be programmed to the OPMENU register)\r
137// Frequency The expected frequency to be used (value to be programmed to the SSFC\r
138// Register)\r
139// Operation Which Hardware Sequencing required operation this opcode respoinds to.\r
140// The required operations are listed in EDS Table 5-55: "Hardware\r
141// Sequencing Commands and Opcode Requirements"\r
142// If the opcode does not corresponds to any operation listed, use\r
143// EnumSpiOperationOther\r
144//\r
145typedef struct _SPI_OPCODE_MENU_ENTRY {\r
146 SPI_OPCODE_TYPE Type;\r
147 UINT8 Code;\r
148 SPI_CYCLE_FREQUENCY Frequency;\r
149 SPI_OPERATION Operation;\r
150} SPI_OPCODE_MENU_ENTRY;\r
151\r
152//\r
153// Initialization data table loaded to the SPI host controller\r
154// VendorId Vendor ID of the SPI device\r
155// DeviceId0 Device ID0 of the SPI device\r
156// DeviceId1 Device ID1 of the SPI device\r
157// PrefixOpcode Prefix opcodes which are loaded into the SPI host controller\r
158// OpcodeMenu Opcodes which are loaded into the SPI host controller Opcode Menu\r
159// BiosStartOffset The offset of the start of the BIOS image relative to the flash device.\r
160// Please note this is a Flash Linear Address, NOT a memory space address.\r
161// This value is platform specific and depends on the system flash map.\r
162// This value is only used on non Descriptor mode.\r
163// BiosSize The the BIOS Image size in flash. This value is platform specific\r
164// and depends on the system flash map. Please note BIOS Image size may\r
165// be smaller than BIOS Region size (in Descriptor Mode) or the flash size\r
166// (in Non Descriptor Mode), and in this case, BIOS Image is supposed to be\r
167// placed at the top end of the BIOS Region (in Descriptor Mode) or the flash\r
168// (in Non Descriptor Mode)\r
169//\r
170typedef struct _SPI_INIT_TABLE {\r
171 UINT8 VendorId;\r
172 UINT8 DeviceId0;\r
173 UINT8 DeviceId1;\r
174 UINT8 PrefixOpcode[SPI_NUM_PREFIX_OPCODE];\r
175 SPI_OPCODE_MENU_ENTRY OpcodeMenu[SPI_NUM_OPCODE];\r
176 UINTN BiosStartOffset;\r
177 UINTN BiosSize;\r
178} SPI_INIT_TABLE;\r
179\r
180//\r
181// Public Info struct to show current initialized state of the spi interface.\r
182// OpcodeIndex must be less then SPI_NUM_OPCODE for operation to be supported.\r
183//\r
184typedef struct _SPI_INIT_INFO {\r
185 SPI_INIT_TABLE *InitTable;\r
186 UINT8 JedecIdOpcodeIndex;\r
187 UINT8 OtherOpcodeIndex;\r
188 UINT8 WriteStatusOpcodeIndex;\r
189 UINT8 ProgramOpcodeIndex;\r
190 UINT8 ReadOpcodeIndex;\r
191 UINT8 EraseOpcodeIndex;\r
192 UINT8 ReadStatusOpcodeIndex;\r
193 UINT8 FullChipEraseOpcodeIndex;\r
194} SPI_INIT_INFO;\r
195\r
196//\r
197// Protocol member functions\r
198//\r
199\r
200typedef\r
201EFI_STATUS\r
202(EFIAPI *EFI_SPI_INIT) (\r
203 IN EFI_SPI_PROTOCOL * This,\r
204 IN SPI_INIT_TABLE * InitTable\r
205 );\r
206/*++\r
207\r
208Routine Description:\r
209\r
210 Initializes the host controller to execute SPI commands.\r
211\r
212Arguments:\r
213\r
214 This Pointer to the EFI_SPI_PROTOCOL instance.\r
215 InitTable Pointer to caller-allocated buffer containing the SPI\r
216 interface initialization table.\r
217\r
218Returns:\r
219\r
220 EFI_SUCCESS Opcode initialization on the SPI host controller completed.\r
221 EFI_ACCESS_DENIED The SPI configuration interface is locked.\r
222 EFI_OUT_OF_RESOURCES Not enough resource available to initialize the device.\r
223 EFI_DEVICE_ERROR Device error, operation failed.\r
224\r
225--*/\r
226\r
227typedef\r
228EFI_STATUS\r
229(EFIAPI *EFI_SPI_LOCK) (\r
230 IN EFI_SPI_PROTOCOL * This\r
231 );\r
232/*++\r
233\r
234Routine Description:\r
235\r
236 Lock the SPI Static Configuration Interface.\r
237 Once locked, the interface is no longer open for configuration changes.\r
238 The lock state automatically clears on next system reset.\r
239\r
240Arguments:\r
241\r
242 This Pointer to the EFI_SPI_PROTOCOL instance.\r
243\r
244Returns:\r
245\r
246 EFI_SUCCESS Lock operation succeed.\r
247 EFI_DEVICE_ERROR Device error, operation failed.\r
248 EFI_ACCESS_DENIED The interface has already been locked.\r
249\r
250--*/\r
251\r
252typedef\r
253EFI_STATUS\r
254(EFIAPI *EFI_SPI_EXECUTE) (\r
255 IN EFI_SPI_PROTOCOL * This,\r
256 IN UINT8 OpcodeIndex,\r
257 IN UINT8 PrefixOpcodeIndex,\r
258 IN BOOLEAN DataCycle,\r
259 IN BOOLEAN Atomic,\r
260 IN BOOLEAN ShiftOut,\r
261 IN UINTN Address,\r
262 IN UINT32 DataByteCount,\r
263 IN OUT UINT8 *Buffer,\r
264 IN SPI_REGION_TYPE SpiRegionType\r
265 );\r
266/*++\r
267\r
268Routine Description:\r
269\r
270 Execute SPI commands from the host controller.\r
271\r
272Arguments:\r
273\r
274 This Pointer to the EFI_SPI_PROTOCOL instance.\r
275 OpcodeIndex Index of the command in the OpCode Menu.\r
276 PrefixOpcodeIndex Index of the first command to run when in an atomic cycle sequence.\r
277 DataCycle TRUE if the SPI cycle contains data\r
278 Atomic TRUE if the SPI cycle is atomic and interleave cycles are not allowed.\r
279 ShiftOut If DataByteCount is not zero, TRUE to shift data out and FALSE to shift data in.\r
280 Address In Descriptor Mode, for Descriptor Region, GbE Region, ME Region and Platform\r
281 Region, this value specifies the offset from the Region Base; for BIOS Region,\r
282 this value specifies the offset from the start of the BIOS Image. In Non\r
283 Descriptor Mode, this value specifies the offset from the start of the BIOS Image.\r
284 Please note BIOS Image size may be smaller than BIOS Region size (in Descriptor\r
285 Mode) or the flash size (in Non Descriptor Mode), and in this case, BIOS Image is\r
286 supposed to be placed at the top end of the BIOS Region (in Descriptor Mode) or\r
287 the flash (in Non Descriptor Mode)\r
288 DataByteCount Number of bytes in the data portion of the SPI cycle.\r
289 Buffer Pointer to caller-allocated buffer containing the dada received or sent during the SPI cycle.\r
290 SpiRegionType SPI Region type. Values EnumSpiRegionBios, EnumSpiRegionGbE, EnumSpiRegionMe,\r
291 EnumSpiRegionDescriptor, and EnumSpiRegionPlatformData are only applicable in\r
292 Descriptor mode. Value EnumSpiRegionAll is applicable to both Descriptor Mode\r
293 and Non Descriptor Mode, which indicates "SpiRegionOffset" is actually relative\r
294 to base of the 1st flash device (i.e., it is a Flash Linear Address).\r
295\r
296Returns:\r
297\r
298 EFI_SUCCESS Command succeed.\r
299 EFI_INVALID_PARAMETER The parameters specified are not valid.\r
300 EFI_UNSUPPORTED Command not supported.\r
301 EFI_DEVICE_ERROR Device error, command aborts abnormally.\r
302\r
303--*/\r
304\r
305typedef\r
306EFI_STATUS\r
307(EFIAPI *EFI_SPI_INFO) (\r
308 IN EFI_SPI_PROTOCOL *This,\r
309 OUT SPI_INIT_INFO **InitInfoPtr\r
310 );\r
311/*++\r
312\r
313Routine Description:\r
314\r
315 Return info about SPI host controller, to help callers usage of Execute\r
316 service.\r
317\r
318 If 0xff is returned as an opcode index in init info struct\r
319 then device does not support the operation.\r
320\r
321Arguments:\r
322\r
323 This Pointer to the EFI_SPI_PROTOCOL instance.\r
324 InitInfoPtr Pointer to init info written to this memory location.\r
325\r
326Returns:\r
327\r
328 EFI_SUCCESS Information returned.\r
329 EFI_INVALID_PARAMETER Invalid parameter.\r
330 EFI_NOT_READY Required resources not setup.\r
331 Others Unexpected error happened.\r
332\r
333--*/\r
334\r
335//\r
336// Protocol definition\r
337//\r
338struct _EFI_SPI_PROTOCOL {\r
339 EFI_SPI_INIT Init;\r
340 EFI_SPI_LOCK Lock;\r
341 EFI_SPI_EXECUTE Execute;\r
342 EFI_SPI_INFO Info;\r
343};\r
344\r
345#endif\r