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