QuarkPlatformPkg: Add new package for Galileo boards
[mirror_edk2.git] / QuarkPlatformPkg / Include / Library / PlatformHelperLib.h
1 /** @file
2 PlatformHelperLib function prototype definitions.
3
4 Copyright (c) 2013 Intel Corporation.
5
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #ifndef __PLATFORM_HELPER_LIB_H__
17 #define __PLATFORM_HELPER_LIB_H__
18
19 #include "Platform.h"
20
21 //
22 // Function prototypes for routines exported by this library.
23 //
24
25 /**
26 Find pointer to RAW data in Firmware volume file.
27
28 @param FvNameGuid Firmware volume to search. If == NULL search all.
29 @param FileNameGuid Firmware volume file to search for.
30 @param SectionData Pointer to RAW data section of found file.
31 @param SectionDataSize Pointer to UNITN to get size of RAW data.
32
33 @retval EFI_SUCCESS Raw Data found.
34 @retval EFI_INVALID_PARAMETER FileNameGuid == NULL.
35 @retval EFI_NOT_FOUND Firmware volume file not found.
36 @retval EFI_UNSUPPORTED Unsupported in current enviroment (PEI or DXE).
37
38 **/
39 EFI_STATUS
40 EFIAPI
41 PlatformFindFvFileRawDataSection (
42 IN CONST EFI_GUID *FvNameGuid OPTIONAL,
43 IN CONST EFI_GUID *FileNameGuid,
44 OUT VOID **SectionData,
45 OUT UINTN *SectionDataSize
46 );
47
48 /**
49 Read 8bit character from debug stream.
50
51 Block until character is read.
52
53 @return 8bit character read from debug stream.
54
55 **/
56 CHAR8
57 EFIAPI
58 PlatformDebugPortGetChar8 (
59 VOID
60 );
61
62 /**
63 Find free spi protect register and write to it to protect a flash region.
64
65 @param DirectValue Value to directly write to register.
66 if DirectValue == 0 the use Base & Length below.
67 @param BaseAddress Base address of region in Flash Memory Map.
68 @param Length Length of region to protect.
69
70 @retval EFI_SUCCESS Free spi protect register found & written.
71 @retval EFI_NOT_FOUND Free Spi protect register not found.
72 @retval EFI_DEVICE_ERROR Unable to write to spi protect register.
73
74 **/
75 EFI_STATUS
76 EFIAPI
77 PlatformWriteFirstFreeSpiProtect (
78 IN CONST UINT32 DirectValue,
79 IN CONST UINT32 BaseAddress,
80 IN CONST UINT32 Length
81 );
82
83 /**
84 Lock legacy SPI static configuration information.
85
86 Function will assert if unable to lock config.
87
88 **/
89 VOID
90 EFIAPI
91 PlatformFlashLockConfig (
92 VOID
93 );
94
95 /**
96 Lock regions and config of SPI flash given the policy for this platform.
97
98 Function will assert if unable to lock regions or config.
99
100 @param PreBootPolicy If TRUE do Pre Boot Flash Lock Policy.
101
102 **/
103 VOID
104 EFIAPI
105 PlatformFlashLockPolicy (
106 IN CONST BOOLEAN PreBootPolicy
107 );
108
109 /**
110 Erase and Write to platform flash.
111
112 Routine accesses one flash block at a time, each access consists
113 of an erase followed by a write of FLASH_BLOCK_SIZE. One or both
114 of DoErase & DoWrite params must be TRUE.
115
116 Limitations:-
117 CpuWriteAddress must be aligned to FLASH_BLOCK_SIZE.
118 DataSize must be a multiple of FLASH_BLOCK_SIZE.
119
120 @param Smst If != NULL then InSmm and use to locate
121 SpiProtocol.
122 @param CpuWriteAddress Address in CPU memory map of flash region.
123 @param Data The buffer containing the data to be written.
124 @param DataSize Amount of data to write.
125 @param DoErase Earse each block.
126 @param DoWrite Write to each block.
127
128 @retval EFI_SUCCESS Operation successful.
129 @retval EFI_NOT_READY Required resources not setup.
130 @retval EFI_INVALID_PARAMETER Invalid parameter.
131 @retval Others Unexpected error happened.
132
133 **/
134 EFI_STATUS
135 EFIAPI
136 PlatformFlashEraseWrite (
137 IN VOID *Smst,
138 IN UINTN CpuWriteAddress,
139 IN UINT8 *Data,
140 IN UINTN DataSize,
141 IN BOOLEAN DoErase,
142 IN BOOLEAN DoWrite
143 );
144
145 /** Check if System booted with recovery Boot Stage1 image.
146
147 @retval TRUE If system booted with recovery Boot Stage1 image.
148 @retval FALSE If system booted with normal stage1 image.
149
150 **/
151 BOOLEAN
152 EFIAPI
153 PlatformIsBootWithRecoveryStage1 (
154 VOID
155 );
156
157 /**
158 Clear SPI Protect registers.
159
160 @retval EFI_SUCESS SPI protect registers cleared.
161 @retval EFI_ACCESS_DENIED Unable to clear SPI protect registers.
162 **/
163
164 EFI_STATUS
165 EFIAPI
166 PlatformClearSpiProtect (
167 VOID
168 );
169
170 /**
171 Determine if an SPI address range is protected.
172
173 @param SpiBaseAddress Base of SPI range.
174 @param Length Length of SPI range.
175
176 @retval TRUE Range is protected.
177 @retval FALSE Range is not protected.
178 **/
179 BOOLEAN
180 EFIAPI
181 PlatformIsSpiRangeProtected (
182 IN CONST UINT32 SpiBaseAddress,
183 IN CONST UINT32 Length
184 );
185
186 /**
187 Set Legacy GPIO Level
188
189 @param LevelRegOffset GPIO level register Offset from GPIO Base Address.
190 @param GpioNum GPIO bit to change.
191 @param HighLevel If TRUE set GPIO High else Set GPIO low.
192
193 **/
194 VOID
195 EFIAPI
196 PlatformLegacyGpioSetLevel (
197 IN CONST UINT32 LevelRegOffset,
198 IN CONST UINT32 GpioNum,
199 IN CONST BOOLEAN HighLevel
200 );
201
202 /**
203 Get Legacy GPIO Level
204
205 @param LevelRegOffset GPIO level register Offset from GPIO Base Address.
206 @param GpioNum GPIO bit to check.
207
208 @retval TRUE If bit is SET.
209 @retval FALSE If bit is CLEAR.
210
211 **/
212 BOOLEAN
213 EFIAPI
214 PlatformLegacyGpioGetLevel (
215 IN CONST UINT32 LevelRegOffset,
216 IN CONST UINT32 GpioNum
217 );
218
219 /**
220 Set the direction of Pcal9555 IO Expander GPIO pin.
221
222 @param Pcal9555SlaveAddr I2c Slave address of Pcal9555 Io Expander.
223 @param GpioNum Gpio direction to configure - values 0-7 for Port0
224 and 8-15 for Port1.
225 @param CfgAsInput If TRUE set pin direction as input else set as output.
226
227 **/
228 VOID
229 EFIAPI
230 PlatformPcal9555GpioSetDir (
231 IN CONST UINT32 Pcal9555SlaveAddr,
232 IN CONST UINT32 GpioNum,
233 IN CONST BOOLEAN CfgAsInput
234 );
235
236 /**
237 Set the level of Pcal9555 IO Expander GPIO high or low.
238
239 @param Pcal9555SlaveAddr I2c Slave address of Pcal9555 Io Expander.
240 @param GpioNum Gpio to change values 0-7 for Port0 and 8-15
241 for Port1.
242 @param HighLevel If TRUE set pin high else set pin low.
243
244 **/
245 VOID
246 EFIAPI
247 PlatformPcal9555GpioSetLevel (
248 IN CONST UINT32 Pcal9555SlaveAddr,
249 IN CONST UINT32 GpioNum,
250 IN CONST BOOLEAN HighLevel
251 );
252
253 /**
254
255 Enable pull-up/pull-down resistors of Pcal9555 GPIOs.
256
257 @param Pcal9555SlaveAddr I2c Slave address of Pcal9555 Io Expander.
258 @param GpioNum Gpio to change values 0-7 for Port0 and 8-15
259 for Port1.
260
261 **/
262 VOID
263 EFIAPI
264 PlatformPcal9555GpioEnablePull (
265 IN CONST UINT32 Pcal9555SlaveAddr,
266 IN CONST UINT32 GpioNum
267 );
268
269 /**
270
271 Disable pull-up/pull-down resistors of Pcal9555 GPIOs.
272
273 @param Pcal9555SlaveAddr I2c Slave address of Pcal9555 Io Expander.
274 @param GpioNum Gpio to change values 0-7 for Port0 and 8-15
275 for Port1.
276
277 **/
278 VOID
279 EFIAPI
280 PlatformPcal9555GpioDisablePull (
281 IN CONST UINT32 Pcal9555SlaveAddr,
282 IN CONST UINT32 GpioNum
283 );
284
285 BOOLEAN
286 EFIAPI
287 PlatformPcal9555GpioGetState (
288 IN CONST UINT32 Pcal9555SlaveAddr,
289 IN CONST UINT32 GpioNum
290 );
291
292 /**
293 Init platform LEDs into known state.
294
295 @param PlatformType Executing platform type.
296
297 @retval EFI_SUCCESS Operation success.
298
299 **/
300 EFI_STATUS
301 EFIAPI
302 PlatformLedInit (
303 IN CONST EFI_PLATFORM_TYPE Type
304 );
305
306 /**
307 Turn on or off platform flash update LED.
308
309 @param PlatformType Executing platform type.
310 @param TurnOn If TRUE turn on else turn off.
311
312 @retval EFI_SUCCESS Operation success.
313
314 **/
315 EFI_STATUS
316 EFIAPI
317 PlatformFlashUpdateLed (
318 IN CONST EFI_PLATFORM_TYPE Type,
319 IN CONST BOOLEAN TurnOn
320 );
321
322 #endif // #ifndef __PLATFORM_HELPER_LIB_H__