]> git.proxmox.com Git - mirror_edk2.git/blame - QuarkSocPkg/QuarkNorthCluster/Spi/Common/SpiCommon.h
ArmPkg/CompilerIntrinsicsLib: Add uread, uwrite GCC assembly sources
[mirror_edk2.git] / QuarkSocPkg / QuarkNorthCluster / Spi / Common / SpiCommon.h
CommitLineData
9b6bbcdb
MK
1/** @file\r
2Header file for the PCH SPI Common Driver.\r
3\r
4Copyright (c) 2013-2015 Intel Corporation.\r
5\r
c9f231d0 6SPDX-License-Identifier: BSD-2-Clause-Patent\r
9b6bbcdb
MK
7\r
8**/\r
9#ifndef _SPI_COMMON_H_\r
10#define _SPI_COMMON_H_\r
11\r
12#include "Protocol/Spi.h"\r
13#include <Library/PciLib.h>\r
14#include <Library/IoLib.h>\r
15#include <Library/DebugLib.h>\r
16#include <Library/PcdLib.h>\r
17#include <Library/BaseMemoryLib.h>\r
18#include <Library/IntelQNCLib.h>\r
19#include <Library/QNCAccessLib.h>\r
20#include <Uefi/UefiBaseType.h>\r
21\r
22//\r
23// Maximum time allowed while waiting the SPI cycle to complete\r
24// Wait Time = 6 seconds = 6000000 microseconds\r
25// Wait Period = 10 microseconds\r
26//\r
27#define WAIT_TIME 6000000\r
28#define WAIT_PERIOD 10\r
29//\r
30// PCH Required SPI Commands -------- COMMAND SET I ------------\r
31// SPI flash device must support in order to be compatible with PCH\r
32//\r
33#define PCH_SPI_COMMAND_PROGRAM_BYTE 0x02\r
34#define PCH_SPI_COMMAND_READ_DATA 0x03\r
35#define PCH_SPI_COMMAND_WRITE_DISABLE 0x04\r
36#define PCH_SPI_COMMAND_READ_STATUS 0x05\r
37#define PCH_SPI_COMMAND_WRITE_ENABLE 0x06\r
38#define PCH_SPI_COMMAND_FAST_READ 0x0B\r
39#define PCH_SPI_COMMAND_READ_ID 0x9F\r
40#define PCH_SPI_COMMAND_DUAL_FAST_READ 0x3B // Dual Output Fast Read\r
41\r
42//\r
43// Need to support at least one of the following two kinds of size of sector for erasing\r
44//\r
45#define PCH_SPI_COMMAND_4KB_ERASE 0x20\r
46#define PCH_SPI_COMMAND_64KB_ERASE 0xD8\r
47//\r
48// Recommended SPI Commands -------- COMMAND SET II ------------\r
49// SPI flash device best to support\r
50//\r
51#define PCH_SPI_COMMAND_WRITE_STATUS 0x01\r
52#define PCH_SPI_COMMAND_FULL_CHIP_ERASE 0xC7\r
53\r
54//\r
55// Private data structure definitions for the driver\r
56//\r
57#define PCH_SPI_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('P', 'S', 'P', 'I')\r
58\r
59typedef struct {\r
60 UINTN Signature;\r
61 EFI_HANDLE Handle;\r
62 EFI_SPI_PROTOCOL SpiProtocol;\r
63 SPI_INIT_TABLE SpiInitTable;\r
64 UINTN PchRootComplexBar;\r
65 BOOLEAN InitDone; // Set to TRUE on SpiProtocolInit SUCCESS.\r
66 SPI_INIT_INFO InitInfo;\r
67} SPI_INSTANCE;\r
68\r
69#define SPI_INSTANCE_FROM_SPIPROTOCOL(a) CR (a, SPI_INSTANCE, SpiProtocol, PCH_SPI_PRIVATE_DATA_SIGNATURE)\r
70\r
71//\r
72// Function prototypes used by the SPI protocol.\r
73//\r
74EFI_STATUS\r
75SpiProtocolConstructor (\r
76 SPI_INSTANCE *SpiInstance\r
77 )\r
78/*++\r
79\r
80Routine Description:\r
81\r
82 Initialize an SPI protocol instance.\r
83 The function will assert in debug if PCH RCBA has not been initialized\r
84\r
85Arguments:\r
86\r
87 SpiInstance - Pointer to SpiInstance to initialize\r
88\r
89Returns:\r
90\r
91 EFI_SUCCESS The protocol instance was properly initialized\r
92 EFI_UNSUPPORTED The PCH is not supported by this module\r
93\r
94--*/\r
95;\r
96\r
97EFI_STATUS\r
98EFIAPI\r
99SpiProtocolInit (\r
100 IN EFI_SPI_PROTOCOL *This,\r
101 IN SPI_INIT_TABLE *InitTable\r
102 )\r
103/*++\r
104\r
105Routine Description:\r
106\r
107 Initialize the host controller to execute SPI command.\r
108\r
109Arguments:\r
110\r
111 This Pointer to the EFI_SPI_PROTOCOL instance.\r
112 InitTable Initialization data to be programmed into the SPI host controller.\r
113\r
114Returns:\r
115\r
116 EFI_SUCCESS Initialization completed.\r
117 EFI_ACCESS_DENIED The SPI static configuration interface has been locked-down.\r
118 EFI_INVALID_PARAMETER Bad input parameters.\r
119--*/\r
120;\r
121\r
122EFI_STATUS\r
123EFIAPI\r
124SpiProtocolLock (\r
125 IN EFI_SPI_PROTOCOL *This\r
126 )\r
127/*++\r
128\r
129Routine Description:\r
130\r
131 Lock the SPI Static Configuration Interface.\r
132 Once locked, the interface can not be changed and can only be clear by system reset.\r
133\r
134Arguments:\r
135\r
136 This Pointer to the EFI_SPI_PROTOCOL instance.\r
137\r
138Returns:\r
139\r
140 EFI_SUCCESS Lock operation succeed.\r
141 EFI_DEVICE_ERROR Device error, operation failed.\r
142 EFI_ACCESS_DENIED The interface has already been locked.\r
143\r
144--*/\r
145;\r
146\r
147EFI_STATUS\r
148EFIAPI\r
149SpiProtocolExecute (\r
150 IN EFI_SPI_PROTOCOL *This,\r
151 IN UINT8 OpcodeIndex,\r
152 IN UINT8 PrefixOpcodeIndex,\r
153 IN BOOLEAN DataCycle,\r
154 IN BOOLEAN Atomic,\r
155 IN BOOLEAN ShiftOut,\r
156 IN UINTN Address,\r
157 IN UINT32 DataByteCount,\r
158 IN OUT UINT8 *Buffer,\r
159 IN SPI_REGION_TYPE SpiRegionType\r
160 )\r
161/*++\r
162\r
163Routine Description:\r
164\r
165 Execute SPI commands from the host controller.\r
166\r
167Arguments:\r
168\r
169 This Pointer to the EFI_SPI_PROTOCOL instance.\r
170 OpcodeIndex Index of the command in the OpCode Menu.\r
171 PrefixOpcodeIndex Index of the first command to run when in an atomic cycle sequence.\r
172 DataCycle TRUE if the SPI cycle contains data\r
173 Atomic TRUE if the SPI cycle is atomic and interleave cycles are not allowed.\r
174 ShiftOut If DataByteCount is not zero, TRUE to shift data out and FALSE to shift data in.\r
175 Address In Descriptor Mode, for Descriptor Region, GbE Region, ME Region and Platform\r
176 Region, this value specifies the offset from the Region Base; for BIOS Region,\r
177 this value specifies the offset from the start of the BIOS Image. In Non\r
178 Descriptor Mode, this value specifies the offset from the start of the BIOS Image.\r
179 Please note BIOS Image size may be smaller than BIOS Region size (in Descriptor\r
180 Mode) or the flash size (in Non Descriptor Mode), and in this case, BIOS Image is\r
181 supposed to be placed at the top end of the BIOS Region (in Descriptor Mode) or\r
182 the flash (in Non Descriptor Mode)\r
183 DataByteCount Number of bytes in the data portion of the SPI cycle.\r
184 Buffer Pointer to caller-allocated buffer containing the dada received or sent during the SPI cycle.\r
185 SpiRegionType SPI Region type. Values EnumSpiRegionBios, EnumSpiRegionGbE, EnumSpiRegionMe,\r
186 EnumSpiRegionDescriptor, and EnumSpiRegionPlatformData are only applicable in\r
187 Descriptor mode. Value EnumSpiRegionAll is applicable to both Descriptor Mode\r
188 and Non Descriptor Mode, which indicates "SpiRegionOffset" is actually relative\r
189 to base of the 1st flash device (i.e., it is a Flash Linear Address).\r
190\r
191Returns:\r
192\r
193 EFI_SUCCESS Command succeed.\r
194 EFI_INVALID_PARAMETER The parameters specified are not valid.\r
195 EFI_UNSUPPORTED Command not supported.\r
196 EFI_DEVICE_ERROR Device error, command aborts abnormally.\r
197\r
198--*/\r
199;\r
200\r
201EFI_STATUS\r
202SendSpiCmd (\r
203 IN EFI_SPI_PROTOCOL *This,\r
204 IN UINT8 OpcodeIndex,\r
205 IN UINT8 PrefixOpcodeIndex,\r
206 IN BOOLEAN DataCycle,\r
207 IN BOOLEAN Atomic,\r
208 IN BOOLEAN ShiftOut,\r
209 IN UINTN Address,\r
210 IN UINT32 DataByteCount,\r
211 IN OUT UINT8 *Buffer,\r
212 IN SPI_REGION_TYPE SpiRegionType\r
213 )\r
214/*++\r
215\r
216Routine Description:\r
217\r
218 This function sends the programmed SPI command to the slave device.\r
219\r
220Arguments:\r
221\r
222 OpcodeIndex Index of the command in the OpCode Menu.\r
223 PrefixOpcodeIndex Index of the first command to run when in an atomic cycle sequence.\r
224 DataCycle TRUE if the SPI cycle contains data\r
225 Atomic TRUE if the SPI cycle is atomic and interleave cycles are not allowed.\r
226 ShiftOut If DataByteCount is not zero, TRUE to shift data out and FALSE to shift data in.\r
227 Address In Descriptor Mode, for Descriptor Region, GbE Region, ME Region and Platform\r
228 Region, this value specifies the offset from the Region Base; for BIOS Region,\r
229 this value specifies the offset from the start of the BIOS Image. In Non\r
230 Descriptor Mode, this value specifies the offset from the start of the BIOS Image.\r
231 Please note BIOS Image size may be smaller than BIOS Region size (in Descriptor\r
232 Mode) or the flash size (in Non Descriptor Mode), and in this case, BIOS Image is\r
233 supposed to be placed at the top end of the BIOS Region (in Descriptor Mode) or\r
234 the flash (in Non Descriptor Mode)\r
235 DataByteCount Number of bytes in the data portion of the SPI cycle. This function may break the\r
236 data transfer into multiple operations. This function ensures each operation does\r
237 not cross 256 byte flash address boundary.\r
238 *NOTE: if there is some SPI chip that has a stricter address boundary requirement\r
239 (e.g., its write page size is < 256 byte), then the caller cannot rely on this\r
240 function to cut the data transfer at proper address boundaries, and it's the\r
241 caller's reponsibility to pass in a properly cut DataByteCount parameter.\r
242 Buffer Data received or sent during the SPI cycle.\r
243 SpiRegionType SPI Region type. Values EnumSpiRegionBios, EnumSpiRegionGbE, EnumSpiRegionMe,\r
244 EnumSpiRegionDescriptor, and EnumSpiRegionPlatformData are only applicable in\r
245 Descriptor mode. Value EnumSpiRegionAll is applicable to both Descriptor Mode\r
246 and Non Descriptor Mode, which indicates "SpiRegionOffset" is actually relative\r
247 to base of the 1st flash device (i.e., it is a Flash Linear Address).\r
248\r
249Returns:\r
250\r
251 EFI_SUCCESS SPI command completes successfully.\r
252 EFI_DEVICE_ERROR Device error, the command aborts abnormally.\r
253 EFI_ACCESS_DENIED Some unrecognized command encountered in hardware sequencing mode\r
254 EFI_INVALID_PARAMETER The parameters specified are not valid.\r
255\r
256--*/\r
257;\r
258\r
259BOOLEAN\r
260WaitForSpiCycleComplete (\r
261 IN EFI_SPI_PROTOCOL *This,\r
262 IN BOOLEAN ErrorCheck\r
263 )\r
264/*++\r
265\r
266Routine Description:\r
267\r
268 Wait execution cycle to complete on the SPI interface. Check both Hardware\r
269 and Software Sequencing status registers\r
270\r
271Arguments:\r
272\r
273 This - The SPI protocol instance\r
274 UseSoftwareSequence - TRUE if this is a Hardware Sequencing operation\r
275 ErrorCheck - TRUE if the SpiCycle needs to do the error check\r
276\r
277Returns:\r
278\r
279 TRUE SPI cycle completed on the interface.\r
280 FALSE Time out while waiting the SPI cycle to complete.\r
281 It's not safe to program the next command on the SPI interface.\r
282\r
283--*/\r
284;\r
285\r
286EFI_STATUS\r
287EFIAPI\r
288SpiProtocolInfo (\r
289 IN EFI_SPI_PROTOCOL *This,\r
290 OUT SPI_INIT_INFO **InitInfoPtr\r
291 )\r
292/*++\r
293\r
294Routine Description:\r
295\r
296 Return info about SPI host controller, to help callers usage of Execute\r
297 service.\r
298\r
299 If 0xff is returned as an opcode index in init info struct\r
300 then device does not support the operation.\r
301\r
302Arguments:\r
303\r
304 This Pointer to the EFI_SPI_PROTOCOL instance.\r
305 InitInfoPtr Pointer to init info written to this memory location.\r
306\r
307Returns:\r
308\r
309 EFI_SUCCESS Information returned.\r
310 EFI_INVALID_PARAMETER Invalid parameter.\r
311 EFI_NOT_READY Required resources not setup.\r
312 Others Unexpected error happened.\r
313\r
314--*/\r
315;\r
316\r
317#endif\r