]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/Library/PlatformIntelBdsLib/IntelBdsPlatform.c
ArmPlatformPkg/PlatformIntelBdsLib: remove ARM BDS dependency
[mirror_edk2.git] / ArmPlatformPkg / Library / PlatformIntelBdsLib / IntelBdsPlatform.c
1 /** @file
2
3 Copyright (c) 2004 - 2008, Intel Corporation. All rights reserved.<BR>
4 Copyright (c) 2014, ARM Ltd. All rights reserved.<BR>
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 #include "IntelBdsPlatform.h"
17
18 ///
19 /// Predefined platform default time out value
20 ///
21 UINT16 gPlatformBootTimeOutDefault;
22
23 EFI_STATUS
24 EFIAPI
25 PlatformIntelBdsConstructor (
26 IN EFI_HANDLE ImageHandle,
27 IN EFI_SYSTEM_TABLE *SystemTable
28 )
29 {
30 gPlatformBootTimeOutDefault = (UINT16)PcdGet16 (PcdPlatformBootTimeOut);
31 return EFI_SUCCESS;
32 }
33
34 //
35 // BDS Platform Functions
36 //
37 /**
38 Platform Bds init. Include the platform firmware vendor, revision
39 and so crc check.
40
41 **/
42 VOID
43 EFIAPI
44 PlatformBdsInit (
45 VOID
46 )
47 {
48 }
49
50 STATIC
51 EFI_STATUS
52 GetConsoleDevicePathFromVariable (
53 IN CHAR16* ConsoleVarName,
54 IN CHAR16* DefaultConsolePaths,
55 OUT EFI_DEVICE_PATH** DevicePaths
56 )
57 {
58 EFI_STATUS Status;
59 UINTN Size;
60 EFI_DEVICE_PATH_PROTOCOL* DevicePathInstances;
61 EFI_DEVICE_PATH_PROTOCOL* DevicePathInstance;
62 CHAR16* DevicePathStr;
63 CHAR16* NextDevicePathStr;
64 EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL *EfiDevicePathFromTextProtocol;
65
66 Status = EFI_SUCCESS;
67 Size = 0;
68
69 DevicePathInstances = BdsLibGetVariableAndSize (ConsoleVarName, &gEfiGlobalVariableGuid, &Size);
70 if (DevicePathInstances == NULL) {
71 // In case no default console device path has been defined we assume a driver handles the console (eg: SimpleTextInOutSerial)
72 if ((DefaultConsolePaths == NULL) || (DefaultConsolePaths[0] == L'\0')) {
73 *DevicePaths = NULL;
74 return EFI_SUCCESS;
75 }
76
77 Status = gBS->LocateProtocol (&gEfiDevicePathFromTextProtocolGuid, NULL, (VOID **)&EfiDevicePathFromTextProtocol);
78 ASSERT_EFI_ERROR(Status);
79
80 // Extract the Device Path instances from the multi-device path string
81 while ((DefaultConsolePaths != NULL) && (DefaultConsolePaths[0] != L'\0')) {
82 NextDevicePathStr = StrStr (DefaultConsolePaths, L";");
83 if (NextDevicePathStr == NULL) {
84 DevicePathStr = DefaultConsolePaths;
85 DefaultConsolePaths = NULL;
86 } else {
87 DevicePathStr = (CHAR16*)AllocateCopyPool ((NextDevicePathStr - DefaultConsolePaths + 1) * sizeof(CHAR16), DefaultConsolePaths);
88 *(DevicePathStr + (NextDevicePathStr - DefaultConsolePaths)) = L'\0';
89 DefaultConsolePaths = NextDevicePathStr;
90 if (DefaultConsolePaths[0] == L';') {
91 DefaultConsolePaths++;
92 }
93 }
94
95 DevicePathInstance = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath (DevicePathStr);
96 ASSERT(DevicePathInstance != NULL);
97 DevicePathInstances = AppendDevicePathInstance (DevicePathInstances, DevicePathInstance);
98
99 if (NextDevicePathStr != NULL) {
100 FreePool (DevicePathStr);
101 }
102 FreePool (DevicePathInstance);
103 }
104
105 // Set the environment variable with this device path multi-instances
106 Size = GetDevicePathSize (DevicePathInstances);
107 if (Size > 0) {
108 gRT->SetVariable (
109 ConsoleVarName,
110 &gEfiGlobalVariableGuid,
111 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
112 Size,
113 DevicePathInstances
114 );
115 } else {
116 Status = EFI_INVALID_PARAMETER;
117 }
118 }
119
120 if (!EFI_ERROR(Status)) {
121 *DevicePaths = DevicePathInstances;
122 }
123 return Status;
124 }
125
126 STATIC
127 EFI_STATUS
128 InitializeConsolePipe (
129 IN EFI_DEVICE_PATH *ConsoleDevicePaths,
130 IN EFI_GUID *Protocol,
131 OUT EFI_HANDLE *Handle,
132 OUT VOID* *Interface
133 )
134 {
135 EFI_STATUS Status;
136 UINTN Size;
137 UINTN NoHandles;
138 EFI_HANDLE *Buffer;
139 EFI_DEVICE_PATH_PROTOCOL* DevicePath;
140
141 // Connect all the Device Path Consoles
142 while (ConsoleDevicePaths != NULL) {
143 DevicePath = GetNextDevicePathInstance (&ConsoleDevicePaths, &Size);
144
145 Status = BdsLibConnectDevicePath (DevicePath);
146 if (!EFI_ERROR (Status)) {
147 //
148 // If BdsLibConnectDevicePath () succeeded, *Handle must have a non-NULL
149 // value. So ASSERT that this is the case.
150 //
151 gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &DevicePath, Handle);
152 ASSERT (*Handle != NULL);
153 }
154 DEBUG_CODE_BEGIN();
155 if (EFI_ERROR(Status)) {
156 // We convert back to the text representation of the device Path
157 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;
158 CHAR16* DevicePathTxt;
159 EFI_STATUS Status;
160
161 Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);
162 if (!EFI_ERROR(Status)) {
163 DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (DevicePath, TRUE, TRUE);
164
165 DEBUG((EFI_D_ERROR,"Fail to start the console with the Device Path '%s'. (Error '%r')\n", DevicePathTxt, Status));
166
167 FreePool (DevicePathTxt);
168 }
169 }
170 DEBUG_CODE_END();
171
172 // If the console splitter driver is not supported by the platform then use the first Device Path
173 // instance for the console interface.
174 if (!EFI_ERROR(Status) && (*Interface == NULL)) {
175 Status = gBS->HandleProtocol (*Handle, Protocol, Interface);
176 }
177 }
178
179 // No Device Path has been defined for this console interface. We take the first protocol implementation
180 if (*Interface == NULL) {
181 Status = gBS->LocateHandleBuffer (ByProtocol, Protocol, NULL, &NoHandles, &Buffer);
182 if (EFI_ERROR (Status)) {
183 BdsLibConnectAll ();
184 Status = gBS->LocateHandleBuffer (ByProtocol, Protocol, NULL, &NoHandles, &Buffer);
185 }
186
187 if (!EFI_ERROR(Status)) {
188 *Handle = Buffer[0];
189 Status = gBS->HandleProtocol (*Handle, Protocol, Interface);
190 ASSERT_EFI_ERROR (Status);
191 FreePool (Buffer);
192 }
193 } else {
194 Status = EFI_SUCCESS;
195 }
196
197 return Status;
198 }
199
200 /**
201 Connect the predefined platform default console device. Always try to find
202 and enable the vga device if have.
203
204 @param PlatformConsole Predefined platform default console device array.
205
206 @retval EFI_SUCCESS Success connect at least one ConIn and ConOut
207 device, there must have one ConOut device is
208 active vga device.
209 @return Return the status of BdsLibConnectAllDefaultConsoles ()
210
211 **/
212 EFI_STATUS
213 PlatformBdsConnectConsole (
214 VOID
215 )
216 {
217 EFI_STATUS Status;
218 EFI_DEVICE_PATH* ConOutDevicePaths;
219 EFI_DEVICE_PATH* ConInDevicePaths;
220 EFI_DEVICE_PATH* ConErrDevicePaths;
221
222 // By getting the Console Device Paths from the environment variables before initializing the console pipe, we
223 // create the 3 environment variables (ConIn, ConOut, ConErr) that allows to initialize all the console interface
224 // of newly installed console drivers
225 Status = GetConsoleDevicePathFromVariable (L"ConOut", (CHAR16*)PcdGetPtr(PcdDefaultConOutPaths), &ConOutDevicePaths);
226 ASSERT_EFI_ERROR (Status);
227 Status = GetConsoleDevicePathFromVariable (L"ConIn", (CHAR16*)PcdGetPtr(PcdDefaultConInPaths), &ConInDevicePaths);
228 ASSERT_EFI_ERROR (Status);
229 Status = GetConsoleDevicePathFromVariable (L"ErrOut", (CHAR16*)PcdGetPtr(PcdDefaultConOutPaths), &ConErrDevicePaths);
230 ASSERT_EFI_ERROR (Status);
231
232 // Initialize the Consoles
233 Status = InitializeConsolePipe (ConOutDevicePaths, &gEfiSimpleTextOutProtocolGuid, &gST->ConsoleOutHandle, (VOID **)&gST->ConOut);
234 ASSERT_EFI_ERROR (Status);
235 Status = InitializeConsolePipe (ConInDevicePaths, &gEfiSimpleTextInProtocolGuid, &gST->ConsoleInHandle, (VOID **)&gST->ConIn);
236 ASSERT_EFI_ERROR (Status);
237 Status = InitializeConsolePipe (ConErrDevicePaths, &gEfiSimpleTextOutProtocolGuid, &gST->StandardErrorHandle, (VOID **)&gST->StdErr);
238 if (EFI_ERROR(Status)) {
239 // In case of error, we reuse the console output for the error output
240 gST->StandardErrorHandle = gST->ConsoleOutHandle;
241 gST->StdErr = gST->ConOut;
242 }
243
244 return Status;
245 }
246
247 /**
248 Connect with predefined platform connect sequence,
249 the OEM/IBV can customize with their own connect sequence.
250 **/
251 VOID
252 PlatformBdsConnectSequence (
253 VOID
254 )
255 {
256 }
257
258 /**
259 Load the predefined driver option, OEM/IBV can customize this
260 to load their own drivers
261
262 @param BdsDriverLists - The header of the driver option link list.
263
264 **/
265 VOID
266 PlatformBdsGetDriverOption (
267 IN OUT LIST_ENTRY *BdsDriverLists
268 )
269 {
270 }
271
272 /**
273 Perform the platform diagnostic, such like test memory. OEM/IBV also
274 can customize this function to support specific platform diagnostic.
275
276 @param MemoryTestLevel The memory test intensive level
277 @param QuietBoot Indicate if need to enable the quiet boot
278 @param BaseMemoryTest A pointer to BdsMemoryTest()
279
280 **/
281 VOID
282 PlatformBdsDiagnostics (
283 IN EXTENDMEM_COVERAGE_LEVEL MemoryTestLevel,
284 IN BOOLEAN QuietBoot,
285 IN BASEM_MEMORY_TEST BaseMemoryTest
286 )
287 {
288 }
289
290 /**
291 The function will execute with as the platform policy, current policy
292 is driven by boot mode. IBV/OEM can customize this code for their specific
293 policy action.
294
295 @param DriverOptionList The header of the driver option link list
296 @param BootOptionList The header of the boot option link list
297 @param ProcessCapsules A pointer to ProcessCapsules()
298 @param BaseMemoryTest A pointer to BaseMemoryTest()
299
300 **/
301 VOID
302 EFIAPI
303 PlatformBdsPolicyBehavior (
304 IN LIST_ENTRY *DriverOptionList,
305 IN LIST_ENTRY *BootOptionList,
306 IN PROCESS_CAPSULES ProcessCapsules,
307 IN BASEM_MEMORY_TEST BaseMemoryTest
308 )
309 {
310 EFI_STATUS Status;
311
312 Status = PlatformBdsConnectConsole ();
313 ASSERT_EFI_ERROR (Status);
314 }
315
316 /**
317 Hook point after a boot attempt succeeds. We don't expect a boot option to
318 return, so the UEFI 2.0 specification defines that you will default to an
319 interactive mode and stop processing the BootOrder list in this case. This
320 is also a platform implementation and can be customized by IBV/OEM.
321
322 @param Option Pointer to Boot Option that succeeded to boot.
323
324 **/
325 VOID
326 EFIAPI
327 PlatformBdsBootSuccess (
328 IN BDS_COMMON_OPTION *Option
329 )
330 {
331 }
332
333 /**
334 Hook point after a boot attempt fails.
335
336 @param Option Pointer to Boot Option that failed to boot.
337 @param Status Status returned from failed boot.
338 @param ExitData Exit data returned from failed boot.
339 @param ExitDataSize Exit data size returned from failed boot.
340
341 **/
342 VOID
343 EFIAPI
344 PlatformBdsBootFail (
345 IN BDS_COMMON_OPTION *Option,
346 IN EFI_STATUS Status,
347 IN CHAR16 *ExitData,
348 IN UINTN ExitDataSize
349 )
350 {
351 }
352
353 /**
354 This function locks platform flash that is not allowed to be updated during normal boot path.
355 The flash layout is platform specific.
356 **/
357 VOID
358 EFIAPI
359 PlatformBdsLockNonUpdatableFlash (
360 VOID
361 )
362 {
363 return;
364 }
365
366
367 /**
368 Lock the ConsoleIn device in system table. All key
369 presses will be ignored until the Password is typed in. The only way to
370 disable the password is to type it in to a ConIn device.
371
372 @param Password Password used to lock ConIn device.
373
374 @retval EFI_SUCCESS lock the Console In Spliter virtual handle successfully.
375 @retval EFI_UNSUPPORTED Password not found
376
377 **/
378 EFI_STATUS
379 EFIAPI
380 LockKeyboards (
381 IN CHAR16 *Password
382 )
383 {
384 return EFI_UNSUPPORTED;
385 }