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