Commit | Line | Data |
---|---|---|
49ba9447 | 1 | /** @file\r |
2 | Platform BDS customizations.\r | |
3 | \r | |
ea5396f3 | 4 | Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r |
56d7640a | 5 | This program and the accompanying materials\r |
49ba9447 | 6 | are licensed and made available under the terms and conditions of the BSD License\r |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include "BdsPlatform.h"\r | |
2cd086a6 | 16 | #include "QemuBootOrder.h"\r |
49ba9447 | 17 | \r |
18 | \r | |
40f2c454 | 19 | //\r |
20 | // Global data\r | |
21 | //\r | |
22 | \r | |
23 | VOID *mEfiDevPathNotifyReg;\r | |
24 | EFI_EVENT mEfiDevPathEvent;\r | |
9607962d | 25 | VOID *mEmuVariableEventReg;\r |
26 | EFI_EVENT mEmuVariableEvent;\r | |
e955462b | 27 | BOOLEAN mDetectVgaOnly;\r |
28 | \r | |
29 | \r | |
30 | //\r | |
31 | // Type definitions\r | |
32 | //\r | |
33 | \r | |
34 | typedef\r | |
35 | EFI_STATUS\r | |
36 | (EFIAPI *PROTOCOL_INSTANCE_CALLBACK)(\r | |
37 | IN EFI_HANDLE Handle,\r | |
38 | IN VOID *Instance,\r | |
39 | IN VOID *Context\r | |
40 | );\r | |
41 | \r | |
42 | /**\r | |
43 | @param[in] Handle - Handle of PCI device instance\r | |
44 | @param[in] PciIo - PCI IO protocol instance\r | |
45 | @param[in] Pci - PCI Header register block\r | |
46 | **/\r | |
47 | typedef\r | |
48 | EFI_STATUS\r | |
49 | (EFIAPI *VISIT_PCI_INSTANCE_CALLBACK)(\r | |
50 | IN EFI_HANDLE Handle,\r | |
51 | IN EFI_PCI_IO_PROTOCOL *PciIo,\r | |
52 | IN PCI_TYPE00 *Pci\r | |
53 | );\r | |
40f2c454 | 54 | \r |
55 | \r | |
56 | //\r | |
57 | // Function prototypes\r | |
58 | //\r | |
59 | \r | |
e955462b | 60 | EFI_STATUS\r |
61 | VisitAllInstancesOfProtocol (\r | |
62 | IN EFI_GUID *Id,\r | |
63 | IN PROTOCOL_INSTANCE_CALLBACK CallBackFunction,\r | |
64 | IN VOID *Context\r | |
65 | );\r | |
66 | \r | |
67 | EFI_STATUS\r | |
68 | VisitAllPciInstancesOfProtocol (\r | |
69 | IN VISIT_PCI_INSTANCE_CALLBACK CallBackFunction\r | |
70 | );\r | |
71 | \r | |
40f2c454 | 72 | VOID\r |
73 | InstallDevicePathCallback (\r | |
74 | VOID\r | |
75 | );\r | |
76 | \r | |
49ba9447 | 77 | //\r |
78 | // BDS Platform Functions\r | |
79 | //\r | |
80 | VOID\r | |
81 | EFIAPI\r | |
82 | PlatformBdsInit (\r | |
370ec7f1 | 83 | VOID\r |
49ba9447 | 84 | )\r |
85 | /*++\r | |
86 | \r | |
87 | Routine Description:\r | |
88 | \r | |
89 | Platform Bds init. Incude the platform firmware vendor, revision\r | |
90 | and so crc check.\r | |
91 | \r | |
92 | Arguments:\r | |
93 | \r | |
49ba9447 | 94 | Returns:\r |
95 | \r | |
96 | None.\r | |
97 | \r | |
98 | --*/\r | |
99 | {\r | |
100 | DEBUG ((EFI_D_INFO, "PlatformBdsInit\n"));\r | |
40f2c454 | 101 | InstallDevicePathCallback ();\r |
49ba9447 | 102 | }\r |
103 | \r | |
104 | \r | |
105 | EFI_STATUS\r | |
106 | ConnectRootBridge (\r | |
107 | VOID\r | |
108 | )\r | |
109 | /*++\r | |
110 | \r | |
111 | Routine Description:\r | |
112 | \r | |
113 | Connect RootBridge\r | |
114 | \r | |
115 | Arguments:\r | |
116 | \r | |
117 | None.\r | |
118 | \r | |
119 | Returns:\r | |
120 | \r | |
121 | EFI_SUCCESS - Connect RootBridge successfully.\r | |
122 | EFI_STATUS - Connect RootBridge fail.\r | |
123 | \r | |
124 | --*/\r | |
125 | {\r | |
126 | EFI_STATUS Status;\r | |
127 | EFI_HANDLE RootHandle;\r | |
128 | \r | |
129 | //\r | |
130 | // Make all the PCI_IO protocols on PCI Seg 0 show up\r | |
131 | //\r | |
132 | BdsLibConnectDevicePath (gPlatformRootBridges[0]);\r | |
133 | \r | |
134 | Status = gBS->LocateDevicePath (\r | |
135 | &gEfiDevicePathProtocolGuid,\r | |
136 | &gPlatformRootBridges[0],\r | |
137 | &RootHandle\r | |
138 | );\r | |
139 | if (EFI_ERROR (Status)) {\r | |
140 | return Status;\r | |
141 | }\r | |
142 | \r | |
143 | Status = gBS->ConnectController (RootHandle, NULL, NULL, FALSE);\r | |
144 | if (EFI_ERROR (Status)) {\r | |
145 | return Status;\r | |
146 | }\r | |
147 | \r | |
148 | return EFI_SUCCESS;\r | |
149 | }\r | |
150 | \r | |
151 | \r | |
152 | EFI_STATUS\r | |
153 | PrepareLpcBridgeDevicePath (\r | |
154 | IN EFI_HANDLE DeviceHandle\r | |
155 | )\r | |
156 | /*++\r | |
157 | \r | |
158 | Routine Description:\r | |
159 | \r | |
160 | Add IsaKeyboard to ConIn,\r | |
161 | add IsaSerial to ConOut, ConIn, ErrOut.\r | |
162 | LPC Bridge: 06 01 00\r | |
163 | \r | |
164 | Arguments:\r | |
165 | \r | |
166 | DeviceHandle - Handle of PCIIO protocol.\r | |
167 | \r | |
168 | Returns:\r | |
169 | \r | |
170 | EFI_SUCCESS - LPC bridge is added to ConOut, ConIn, and ErrOut.\r | |
171 | EFI_STATUS - No LPC bridge is added.\r | |
172 | \r | |
173 | --*/\r | |
174 | {\r | |
175 | EFI_STATUS Status;\r | |
176 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
177 | EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;\r | |
178 | CHAR16 *DevPathStr;\r | |
179 | \r | |
180 | DevicePath = NULL;\r | |
181 | Status = gBS->HandleProtocol (\r | |
182 | DeviceHandle,\r | |
183 | &gEfiDevicePathProtocolGuid,\r | |
184 | (VOID*)&DevicePath\r | |
185 | );\r | |
186 | if (EFI_ERROR (Status)) {\r | |
187 | return Status;\r | |
188 | }\r | |
189 | TempDevicePath = DevicePath;\r | |
190 | \r | |
191 | //\r | |
192 | // Register Keyboard\r | |
193 | //\r | |
194 | DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gPnpPs2KeyboardDeviceNode);\r | |
195 | \r | |
196 | BdsLibUpdateConsoleVariable (VarConsoleInp, DevicePath, NULL);\r | |
197 | \r | |
198 | //\r | |
199 | // Register COM1\r | |
200 | //\r | |
201 | DevicePath = TempDevicePath;\r | |
202 | gPnp16550ComPortDeviceNode.UID = 0;\r | |
203 | \r | |
204 | DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gPnp16550ComPortDeviceNode);\r | |
205 | DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gUartDeviceNode);\r | |
206 | DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gTerminalTypeDeviceNode);\r | |
207 | \r | |
208 | //\r | |
209 | // Print Device Path\r | |
210 | //\r | |
211 | DevPathStr = DevicePathToStr(DevicePath);\r | |
863986b3 RN |
212 | if (DevPathStr != NULL) {\r |
213 | DEBUG((\r | |
214 | EFI_D_INFO,\r | |
215 | "BdsPlatform.c+%d: COM%d DevPath: %s\n",\r | |
216 | __LINE__,\r | |
217 | gPnp16550ComPortDeviceNode.UID + 1,\r | |
218 | DevPathStr\r | |
219 | ));\r | |
220 | FreePool(DevPathStr);\r | |
221 | }\r | |
49ba9447 | 222 | \r |
223 | BdsLibUpdateConsoleVariable (VarConsoleOut, DevicePath, NULL);\r | |
224 | BdsLibUpdateConsoleVariable (VarConsoleInp, DevicePath, NULL);\r | |
225 | BdsLibUpdateConsoleVariable (VarErrorOut, DevicePath, NULL);\r | |
226 | \r | |
227 | //\r | |
228 | // Register COM2\r | |
229 | //\r | |
230 | DevicePath = TempDevicePath;\r | |
231 | gPnp16550ComPortDeviceNode.UID = 1;\r | |
232 | \r | |
233 | DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gPnp16550ComPortDeviceNode);\r | |
234 | DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gUartDeviceNode);\r | |
235 | DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gTerminalTypeDeviceNode);\r | |
236 | \r | |
237 | //\r | |
238 | // Print Device Path\r | |
239 | //\r | |
240 | DevPathStr = DevicePathToStr(DevicePath);\r | |
863986b3 RN |
241 | if (DevPathStr != NULL) {\r |
242 | DEBUG((\r | |
243 | EFI_D_INFO,\r | |
244 | "BdsPlatform.c+%d: COM%d DevPath: %s\n",\r | |
245 | __LINE__,\r | |
246 | gPnp16550ComPortDeviceNode.UID + 1,\r | |
247 | DevPathStr\r | |
248 | ));\r | |
249 | FreePool(DevPathStr);\r | |
250 | }\r | |
49ba9447 | 251 | \r |
252 | BdsLibUpdateConsoleVariable (VarConsoleOut, DevicePath, NULL);\r | |
253 | BdsLibUpdateConsoleVariable (VarConsoleInp, DevicePath, NULL);\r | |
254 | BdsLibUpdateConsoleVariable (VarErrorOut, DevicePath, NULL);\r | |
255 | \r | |
256 | return EFI_SUCCESS;\r | |
257 | }\r | |
258 | \r | |
259 | EFI_STATUS\r | |
260 | GetGopDevicePath (\r | |
261 | IN EFI_DEVICE_PATH_PROTOCOL *PciDevicePath,\r | |
262 | OUT EFI_DEVICE_PATH_PROTOCOL **GopDevicePath\r | |
263 | )\r | |
264 | {\r | |
265 | UINTN Index;\r | |
266 | EFI_STATUS Status;\r | |
267 | EFI_HANDLE PciDeviceHandle;\r | |
268 | EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;\r | |
269 | EFI_DEVICE_PATH_PROTOCOL *TempPciDevicePath;\r | |
270 | UINTN GopHandleCount;\r | |
271 | EFI_HANDLE *GopHandleBuffer;\r | |
272 | \r | |
273 | if (PciDevicePath == NULL || GopDevicePath == NULL) {\r | |
274 | return EFI_INVALID_PARAMETER;\r | |
275 | }\r | |
276 | \r | |
277 | //\r | |
278 | // Initialize the GopDevicePath to be PciDevicePath\r | |
279 | //\r | |
280 | *GopDevicePath = PciDevicePath;\r | |
281 | TempPciDevicePath = PciDevicePath;\r | |
282 | \r | |
283 | Status = gBS->LocateDevicePath (\r | |
284 | &gEfiDevicePathProtocolGuid,\r | |
285 | &TempPciDevicePath,\r | |
286 | &PciDeviceHandle\r | |
287 | );\r | |
288 | if (EFI_ERROR (Status)) {\r | |
289 | return Status;\r | |
290 | }\r | |
291 | \r | |
292 | //\r | |
293 | // Try to connect this handle, so that GOP dirver could start on this\r | |
294 | // device and create child handles with GraphicsOutput Protocol installed\r | |
295 | // on them, then we get device paths of these child handles and select\r | |
296 | // them as possible console device.\r | |
297 | //\r | |
298 | gBS->ConnectController (PciDeviceHandle, NULL, NULL, FALSE);\r | |
299 | \r | |
300 | Status = gBS->LocateHandleBuffer (\r | |
301 | ByProtocol,\r | |
302 | &gEfiGraphicsOutputProtocolGuid,\r | |
303 | NULL,\r | |
304 | &GopHandleCount,\r | |
305 | &GopHandleBuffer\r | |
306 | );\r | |
307 | if (!EFI_ERROR (Status)) {\r | |
308 | //\r | |
309 | // Add all the child handles as possible Console Device\r | |
310 | //\r | |
311 | for (Index = 0; Index < GopHandleCount; Index++) {\r | |
312 | Status = gBS->HandleProtocol (GopHandleBuffer[Index], &gEfiDevicePathProtocolGuid, (VOID*)&TempDevicePath);\r | |
313 | if (EFI_ERROR (Status)) {\r | |
314 | continue;\r | |
315 | }\r | |
316 | if (CompareMem (\r | |
317 | PciDevicePath,\r | |
318 | TempDevicePath,\r | |
319 | GetDevicePathSize (PciDevicePath) - END_DEVICE_PATH_LENGTH\r | |
320 | ) == 0) {\r | |
321 | //\r | |
322 | // In current implementation, we only enable one of the child handles\r | |
323 | // as console device, i.e. sotre one of the child handle's device\r | |
324 | // path to variable "ConOut"\r | |
325 | // In futhure, we could select all child handles to be console device\r | |
326 | //\r | |
327 | \r | |
328 | *GopDevicePath = TempDevicePath;\r | |
329 | \r | |
330 | //\r | |
331 | // Delete the PCI device's path that added by GetPlugInPciVgaDevicePath()\r | |
332 | // Add the integrity GOP device path.\r | |
333 | //\r | |
334 | BdsLibUpdateConsoleVariable (VarConsoleOutDev, NULL, PciDevicePath);\r | |
335 | BdsLibUpdateConsoleVariable (VarConsoleOutDev, TempDevicePath, NULL);\r | |
336 | }\r | |
337 | }\r | |
338 | gBS->FreePool (GopHandleBuffer);\r | |
339 | }\r | |
340 | \r | |
341 | return EFI_SUCCESS;\r | |
342 | }\r | |
343 | \r | |
344 | EFI_STATUS\r | |
345 | PreparePciVgaDevicePath (\r | |
346 | IN EFI_HANDLE DeviceHandle\r | |
347 | )\r | |
348 | /*++\r | |
349 | \r | |
350 | Routine Description:\r | |
351 | \r | |
352 | Add PCI VGA to ConOut.\r | |
353 | PCI VGA: 03 00 00\r | |
354 | \r | |
355 | Arguments:\r | |
356 | \r | |
357 | DeviceHandle - Handle of PCIIO protocol.\r | |
358 | \r | |
359 | Returns:\r | |
360 | \r | |
361 | EFI_SUCCESS - PCI VGA is added to ConOut.\r | |
362 | EFI_STATUS - No PCI VGA device is added.\r | |
363 | \r | |
364 | --*/\r | |
365 | {\r | |
366 | EFI_STATUS Status;\r | |
367 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
368 | EFI_DEVICE_PATH_PROTOCOL *GopDevicePath;\r | |
369 | \r | |
ea5396f3 RN |
370 | DevicePath = NULL;\r |
371 | GopDevicePath = NULL;\r | |
49ba9447 | 372 | Status = gBS->HandleProtocol (\r |
373 | DeviceHandle,\r | |
374 | &gEfiDevicePathProtocolGuid,\r | |
375 | (VOID*)&DevicePath\r | |
376 | );\r | |
377 | if (EFI_ERROR (Status)) {\r | |
378 | return Status;\r | |
379 | }\r | |
380 | \r | |
381 | GetGopDevicePath (DevicePath, &GopDevicePath);\r | |
382 | DevicePath = GopDevicePath;\r | |
383 | \r | |
384 | BdsLibUpdateConsoleVariable (VarConsoleOut, DevicePath, NULL);\r | |
385 | \r | |
386 | return EFI_SUCCESS;\r | |
387 | }\r | |
388 | \r | |
389 | EFI_STATUS\r | |
390 | PreparePciSerialDevicePath (\r | |
391 | IN EFI_HANDLE DeviceHandle\r | |
392 | )\r | |
393 | /*++\r | |
394 | \r | |
395 | Routine Description:\r | |
396 | \r | |
397 | Add PCI Serial to ConOut, ConIn, ErrOut.\r | |
398 | PCI Serial: 07 00 02\r | |
399 | \r | |
400 | Arguments:\r | |
401 | \r | |
402 | DeviceHandle - Handle of PCIIO protocol.\r | |
403 | \r | |
404 | Returns:\r | |
405 | \r | |
406 | EFI_SUCCESS - PCI Serial is added to ConOut, ConIn, and ErrOut.\r | |
407 | EFI_STATUS - No PCI Serial device is added.\r | |
408 | \r | |
409 | --*/\r | |
410 | {\r | |
411 | EFI_STATUS Status;\r | |
412 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
413 | \r | |
414 | DevicePath = NULL;\r | |
415 | Status = gBS->HandleProtocol (\r | |
416 | DeviceHandle,\r | |
417 | &gEfiDevicePathProtocolGuid,\r | |
418 | (VOID*)&DevicePath\r | |
419 | );\r | |
420 | if (EFI_ERROR (Status)) {\r | |
421 | return Status;\r | |
422 | }\r | |
423 | \r | |
424 | DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gUartDeviceNode);\r | |
425 | DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gTerminalTypeDeviceNode);\r | |
426 | \r | |
427 | BdsLibUpdateConsoleVariable (VarConsoleOut, DevicePath, NULL);\r | |
428 | BdsLibUpdateConsoleVariable (VarConsoleInp, DevicePath, NULL);\r | |
429 | BdsLibUpdateConsoleVariable (VarErrorOut, DevicePath, NULL);\r | |
430 | \r | |
431 | return EFI_SUCCESS;\r | |
432 | }\r | |
433 | \r | |
434 | EFI_STATUS\r | |
e955462b | 435 | VisitAllInstancesOfProtocol (\r |
436 | IN EFI_GUID *Id,\r | |
437 | IN PROTOCOL_INSTANCE_CALLBACK CallBackFunction,\r | |
438 | IN VOID *Context\r | |
49ba9447 | 439 | )\r |
49ba9447 | 440 | {\r |
441 | EFI_STATUS Status;\r | |
442 | UINTN HandleCount;\r | |
443 | EFI_HANDLE *HandleBuffer;\r | |
444 | UINTN Index;\r | |
e955462b | 445 | VOID *Instance;\r |
49ba9447 | 446 | \r |
447 | //\r | |
448 | // Start to check all the PciIo to find all possible device\r | |
449 | //\r | |
450 | HandleCount = 0;\r | |
451 | HandleBuffer = NULL;\r | |
452 | Status = gBS->LocateHandleBuffer (\r | |
453 | ByProtocol,\r | |
e955462b | 454 | Id,\r |
49ba9447 | 455 | NULL,\r |
456 | &HandleCount,\r | |
457 | &HandleBuffer\r | |
458 | );\r | |
459 | if (EFI_ERROR (Status)) {\r | |
460 | return Status;\r | |
461 | }\r | |
462 | \r | |
463 | for (Index = 0; Index < HandleCount; Index++) {\r | |
e955462b | 464 | Status = gBS->HandleProtocol (HandleBuffer[Index], Id, &Instance);\r |
49ba9447 | 465 | if (EFI_ERROR (Status)) {\r |
466 | continue;\r | |
467 | }\r | |
468 | \r | |
e955462b | 469 | Status = (*CallBackFunction) (\r |
470 | HandleBuffer[Index],\r | |
471 | Instance,\r | |
472 | Context\r | |
473 | );\r | |
474 | }\r | |
49ba9447 | 475 | \r |
e955462b | 476 | gBS->FreePool (HandleBuffer);\r |
607ca510 | 477 | \r |
e955462b | 478 | return EFI_SUCCESS;\r |
479 | }\r | |
480 | \r | |
481 | \r | |
482 | EFI_STATUS\r | |
483 | EFIAPI\r | |
484 | VisitingAPciInstance (\r | |
485 | IN EFI_HANDLE Handle,\r | |
486 | IN VOID *Instance,\r | |
487 | IN VOID *Context\r | |
488 | )\r | |
489 | {\r | |
490 | EFI_STATUS Status;\r | |
491 | EFI_PCI_IO_PROTOCOL *PciIo;\r | |
492 | PCI_TYPE00 Pci;\r | |
493 | \r | |
494 | PciIo = (EFI_PCI_IO_PROTOCOL*) Instance;\r | |
495 | \r | |
496 | //\r | |
497 | // Check for all PCI device\r | |
498 | //\r | |
499 | Status = PciIo->Pci.Read (\r | |
500 | PciIo,\r | |
501 | EfiPciIoWidthUint32,\r | |
502 | 0,\r | |
503 | sizeof (Pci) / sizeof (UINT32),\r | |
504 | &Pci\r | |
505 | );\r | |
506 | if (EFI_ERROR (Status)) {\r | |
507 | return Status;\r | |
508 | }\r | |
509 | \r | |
7d9cf3f2 | 510 | return (*(VISIT_PCI_INSTANCE_CALLBACK)(UINTN) Context) (\r |
e955462b | 511 | Handle,\r |
512 | PciIo,\r | |
513 | &Pci\r | |
514 | );\r | |
515 | \r | |
516 | }\r | |
517 | \r | |
518 | \r | |
519 | \r | |
520 | EFI_STATUS\r | |
521 | VisitAllPciInstances (\r | |
522 | IN VISIT_PCI_INSTANCE_CALLBACK CallBackFunction\r | |
523 | )\r | |
524 | {\r | |
525 | return VisitAllInstancesOfProtocol (\r | |
526 | &gEfiPciIoProtocolGuid,\r | |
527 | VisitingAPciInstance,\r | |
7d9cf3f2 | 528 | (VOID*)(UINTN) CallBackFunction\r |
e955462b | 529 | );\r |
530 | }\r | |
531 | \r | |
532 | \r | |
533 | /**\r | |
534 | Do platform specific PCI Device check and add them to\r | |
535 | ConOut, ConIn, ErrOut.\r | |
536 | \r | |
537 | @param[in] Handle - Handle of PCI device instance\r | |
538 | @param[in] PciIo - PCI IO protocol instance\r | |
539 | @param[in] Pci - PCI Header register block\r | |
540 | \r | |
541 | @retval EFI_SUCCESS - PCI Device check and Console variable update successfully.\r | |
542 | @retval EFI_STATUS - PCI Device check or Console variable update fail.\r | |
543 | \r | |
544 | **/\r | |
545 | EFI_STATUS\r | |
8861fc79 | 546 | EFIAPI\r |
e955462b | 547 | DetectAndPreparePlatformPciDevicePath (\r |
548 | IN EFI_HANDLE Handle,\r | |
549 | IN EFI_PCI_IO_PROTOCOL *PciIo,\r | |
550 | IN PCI_TYPE00 *Pci\r | |
551 | )\r | |
552 | {\r | |
553 | EFI_STATUS Status;\r | |
554 | \r | |
555 | Status = PciIo->Attributes (\r | |
556 | PciIo,\r | |
557 | EfiPciIoAttributeOperationEnable,\r | |
558 | EFI_PCI_DEVICE_ENABLE,\r | |
559 | NULL\r | |
560 | );\r | |
561 | ASSERT_EFI_ERROR (Status);\r | |
562 | \r | |
563 | if (!mDetectVgaOnly) {\r | |
564 | //\r | |
565 | // Here we decide whether it is LPC Bridge\r | |
566 | //\r | |
567 | if ((IS_PCI_LPC (Pci)) ||\r | |
568 | ((IS_PCI_ISA_PDECODE (Pci)) &&\r | |
569 | (Pci->Hdr.VendorId == 0x8086) &&\r | |
570 | (Pci->Hdr.DeviceId == 0x7000)\r | |
571 | )\r | |
572 | ) {\r | |
49ba9447 | 573 | //\r |
e955462b | 574 | // Add IsaKeyboard to ConIn,\r |
575 | // add IsaSerial to ConOut, ConIn, ErrOut\r | |
49ba9447 | 576 | //\r |
e955462b | 577 | DEBUG ((EFI_D_INFO, "Found LPC Bridge device\n"));\r |
578 | PrepareLpcBridgeDevicePath (Handle);\r | |
579 | return EFI_SUCCESS;\r | |
49ba9447 | 580 | }\r |
49ba9447 | 581 | //\r |
e955462b | 582 | // Here we decide which Serial device to enable in PCI bus\r |
49ba9447 | 583 | //\r |
e955462b | 584 | if (IS_PCI_16550SERIAL (Pci)) {\r |
49ba9447 | 585 | //\r |
e955462b | 586 | // Add them to ConOut, ConIn, ErrOut.\r |
49ba9447 | 587 | //\r |
e955462b | 588 | DEBUG ((EFI_D_INFO, "Found PCI 16550 SERIAL device\n"));\r |
589 | PreparePciSerialDevicePath (Handle);\r | |
590 | return EFI_SUCCESS;\r | |
49ba9447 | 591 | }\r |
592 | }\r | |
593 | \r | |
e955462b | 594 | //\r |
595 | // Here we decide which VGA device to enable in PCI bus\r | |
596 | //\r | |
597 | if (IS_PCI_VGA (Pci)) {\r | |
598 | //\r | |
599 | // Add them to ConOut.\r | |
600 | //\r | |
601 | DEBUG ((EFI_D_INFO, "Found PCI VGA device\n"));\r | |
602 | PreparePciVgaDevicePath (Handle);\r | |
603 | return EFI_SUCCESS;\r | |
604 | }\r | |
49ba9447 | 605 | \r |
e955462b | 606 | return Status;\r |
607 | }\r | |
608 | \r | |
609 | \r | |
610 | /**\r | |
611 | Do platform specific PCI Device check and add them to ConOut, ConIn, ErrOut\r | |
612 | \r | |
613 | @param[in] DetectVgaOnly - Only detect VGA device if it's TRUE.\r | |
614 | \r | |
615 | @retval EFI_SUCCESS - PCI Device check and Console variable update successfully.\r | |
616 | @retval EFI_STATUS - PCI Device check or Console variable update fail.\r | |
617 | \r | |
618 | **/\r | |
619 | EFI_STATUS\r | |
620 | DetectAndPreparePlatformPciDevicePaths (\r | |
621 | BOOLEAN DetectVgaOnly\r | |
622 | )\r | |
623 | {\r | |
624 | mDetectVgaOnly = DetectVgaOnly;\r | |
625 | return VisitAllPciInstances (DetectAndPreparePlatformPciDevicePath);\r | |
49ba9447 | 626 | }\r |
627 | \r | |
628 | \r | |
629 | EFI_STATUS\r | |
630 | PlatformBdsConnectConsole (\r | |
631 | IN BDS_CONSOLE_CONNECT_ENTRY *PlatformConsole\r | |
632 | )\r | |
633 | /*++\r | |
634 | \r | |
635 | Routine Description:\r | |
636 | \r | |
637 | Connect the predefined platform default console device. Always try to find\r | |
638 | and enable the vga device if have.\r | |
639 | \r | |
640 | Arguments:\r | |
641 | \r | |
642 | PlatformConsole - Predfined platform default console device array.\r | |
643 | \r | |
644 | Returns:\r | |
645 | \r | |
646 | EFI_SUCCESS - Success connect at least one ConIn and ConOut\r | |
647 | device, there must have one ConOut device is\r | |
648 | active vga device.\r | |
649 | \r | |
650 | EFI_STATUS - Return the status of\r | |
651 | BdsLibConnectAllDefaultConsoles ()\r | |
652 | \r | |
653 | --*/\r | |
654 | {\r | |
655 | EFI_STATUS Status;\r | |
656 | UINTN Index;\r | |
657 | EFI_DEVICE_PATH_PROTOCOL *VarConout;\r | |
658 | EFI_DEVICE_PATH_PROTOCOL *VarConin;\r | |
659 | UINTN DevicePathSize;\r | |
660 | \r | |
661 | //\r | |
662 | // Connect RootBridge\r | |
663 | //\r | |
49ba9447 | 664 | VarConout = BdsLibGetVariableAndSize (\r |
665 | VarConsoleOut,\r | |
666 | &gEfiGlobalVariableGuid,\r | |
667 | &DevicePathSize\r | |
668 | );\r | |
669 | VarConin = BdsLibGetVariableAndSize (\r | |
670 | VarConsoleInp,\r | |
671 | &gEfiGlobalVariableGuid,\r | |
672 | &DevicePathSize\r | |
673 | );\r | |
674 | \r | |
675 | if (VarConout == NULL || VarConin == NULL) {\r | |
676 | //\r | |
677 | // Do platform specific PCI Device check and add them to ConOut, ConIn, ErrOut\r | |
678 | //\r | |
e955462b | 679 | DetectAndPreparePlatformPciDevicePaths (FALSE);\r |
49ba9447 | 680 | \r |
681 | //\r | |
682 | // Have chance to connect the platform default console,\r | |
683 | // the platform default console is the minimue device group\r | |
684 | // the platform should support\r | |
685 | //\r | |
686 | for (Index = 0; PlatformConsole[Index].DevicePath != NULL; ++Index) {\r | |
687 | //\r | |
688 | // Update the console variable with the connect type\r | |
689 | //\r | |
690 | if ((PlatformConsole[Index].ConnectType & CONSOLE_IN) == CONSOLE_IN) {\r | |
691 | BdsLibUpdateConsoleVariable (VarConsoleInp, PlatformConsole[Index].DevicePath, NULL);\r | |
692 | }\r | |
693 | if ((PlatformConsole[Index].ConnectType & CONSOLE_OUT) == CONSOLE_OUT) {\r | |
694 | BdsLibUpdateConsoleVariable (VarConsoleOut, PlatformConsole[Index].DevicePath, NULL);\r | |
695 | }\r | |
696 | if ((PlatformConsole[Index].ConnectType & STD_ERROR) == STD_ERROR) {\r | |
697 | BdsLibUpdateConsoleVariable (VarErrorOut, PlatformConsole[Index].DevicePath, NULL);\r | |
698 | }\r | |
699 | }\r | |
700 | } else {\r | |
701 | //\r | |
702 | // Only detect VGA device and add them to ConOut\r | |
703 | //\r | |
e955462b | 704 | DetectAndPreparePlatformPciDevicePaths (TRUE);\r |
49ba9447 | 705 | }\r |
706 | \r | |
707 | //\r | |
708 | // Connect the all the default console with current cosole variable\r | |
709 | //\r | |
710 | Status = BdsLibConnectAllDefaultConsoles ();\r | |
711 | if (EFI_ERROR (Status)) {\r | |
712 | return Status;\r | |
713 | }\r | |
714 | \r | |
715 | return EFI_SUCCESS;\r | |
716 | }\r | |
717 | \r | |
718 | \r | |
719 | VOID\r | |
720 | PciInitialization (\r | |
721 | )\r | |
722 | {\r | |
723 | //\r | |
40f2c454 | 724 | // Bus 0, Device 0, Function 0 - Host to PCI Bridge\r |
725 | //\r | |
726 | PciWrite8 (PCI_LIB_ADDRESS (0, 0, 0, 0x3c), 0x00);\r | |
727 | \r | |
728 | //\r | |
729 | // Bus 0, Device 1, Function 0 - PCI to ISA Bridge\r | |
49ba9447 | 730 | //\r |
40f2c454 | 731 | PciWrite8 (PCI_LIB_ADDRESS (0, 1, 0, 0x3c), 0x00);\r |
05c89c7f | 732 | PciWrite8 (PCI_LIB_ADDRESS (0, 1, 0, 0x60), 0x0b); // LNKA routing target\r |
733 | PciWrite8 (PCI_LIB_ADDRESS (0, 1, 0, 0x61), 0x0b); // LNKB routing target\r | |
734 | PciWrite8 (PCI_LIB_ADDRESS (0, 1, 0, 0x62), 0x0a); // LNKC routing target\r | |
735 | PciWrite8 (PCI_LIB_ADDRESS (0, 1, 0, 0x63), 0x0a); // LNKD routing target\r | |
49ba9447 | 736 | \r |
737 | //\r | |
40f2c454 | 738 | // Bus 0, Device 1, Function 1 - IDE Controller\r |
49ba9447 | 739 | //\r |
40f2c454 | 740 | PciWrite8 (PCI_LIB_ADDRESS (0, 1, 1, 0x3c), 0x00);\r |
741 | PciWrite8 (PCI_LIB_ADDRESS (0, 1, 1, 0x0d), 0x40);\r | |
49ba9447 | 742 | \r |
743 | //\r | |
40f2c454 | 744 | // Bus 0, Device 1, Function 3 - Power Managment Controller\r |
49ba9447 | 745 | //\r |
05c89c7f | 746 | PciWrite8 (PCI_LIB_ADDRESS (0, 1, 3, 0x3c), 0x09);\r |
747 | PciWrite8 (PCI_LIB_ADDRESS (0, 1, 3, 0x3d), 0x01); // INTA\r | |
49ba9447 | 748 | \r |
749 | //\r | |
40f2c454 | 750 | // Bus 0, Device 2, Function 0 - Video Controller\r |
49ba9447 | 751 | //\r |
40f2c454 | 752 | PciWrite8 (PCI_LIB_ADDRESS (0, 2, 0, 0x3c), 0x00);\r |
49ba9447 | 753 | \r |
754 | //\r | |
40f2c454 | 755 | // Bus 0, Device 3, Function 0 - Network Controller\r |
49ba9447 | 756 | //\r |
05c89c7f | 757 | PciWrite8 (PCI_LIB_ADDRESS (0, 3, 0, 0x3c), 0x0a);\r |
758 | PciWrite8 (PCI_LIB_ADDRESS (0, 3, 0, 0x3d), 0x01); // INTA (-> LNKC)\r | |
49ba9447 | 759 | \r |
760 | //\r | |
a5595b1e | 761 | // Bus 0, Device 5, Function 0 - RAM Memory\r |
49ba9447 | 762 | //\r |
05c89c7f | 763 | PciWrite8 (PCI_LIB_ADDRESS (0, 5, 0, 0x3c), 0x0b);\r |
764 | PciWrite8 (PCI_LIB_ADDRESS (0, 5, 0, 0x3d), 0x01); // INTA (-> LNKA)\r | |
49ba9447 | 765 | }\r |
766 | \r | |
767 | \r | |
9b167857 | 768 | VOID\r |
769 | AcpiInitialization (\r | |
770 | VOID\r | |
771 | )\r | |
772 | {\r | |
773 | //\r | |
774 | // Set ACPI SCI_EN bit in PMCNTRL\r | |
775 | //\r | |
776 | IoOr16 ((PciRead32 (PCI_LIB_ADDRESS (0, 1, 3, 0x40)) & ~BIT0) + 4, BIT0);\r | |
777 | }\r | |
778 | \r | |
779 | \r | |
14b21de9 | 780 | EFI_STATUS\r |
781 | EFIAPI\r | |
782 | ConnectRecursivelyIfPciMassStorage (\r | |
783 | IN EFI_HANDLE Handle,\r | |
784 | IN EFI_PCI_IO_PROTOCOL *Instance,\r | |
785 | IN PCI_TYPE00 *PciHeader\r | |
786 | )\r | |
787 | {\r | |
788 | EFI_STATUS Status;\r | |
789 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
790 | CHAR16 *DevPathStr;\r | |
791 | \r | |
792 | if (IS_CLASS1 (PciHeader, PCI_CLASS_MASS_STORAGE)) {\r | |
793 | DevicePath = NULL;\r | |
794 | Status = gBS->HandleProtocol (\r | |
795 | Handle,\r | |
796 | &gEfiDevicePathProtocolGuid,\r | |
797 | (VOID*)&DevicePath\r | |
798 | );\r | |
799 | if (EFI_ERROR (Status)) {\r | |
800 | return Status;\r | |
801 | }\r | |
802 | \r | |
803 | //\r | |
804 | // Print Device Path\r | |
805 | //\r | |
806 | DevPathStr = DevicePathToStr (DevicePath);\r | |
863986b3 RN |
807 | if (DevPathStr != NULL) {\r |
808 | DEBUG((\r | |
809 | EFI_D_INFO,\r | |
810 | "Found Mass Storage device: %s\n",\r | |
811 | DevPathStr\r | |
812 | ));\r | |
813 | FreePool(DevPathStr);\r | |
814 | }\r | |
14b21de9 | 815 | \r |
816 | Status = gBS->ConnectController (Handle, NULL, NULL, TRUE);\r | |
817 | if (EFI_ERROR (Status)) {\r | |
818 | return Status;\r | |
819 | }\r | |
820 | \r | |
821 | }\r | |
822 | \r | |
823 | return EFI_SUCCESS;\r | |
824 | }\r | |
825 | \r | |
826 | \r | |
9607962d | 827 | /**\r |
828 | This notification function is invoked when the\r | |
829 | EMU Variable FVB has been changed.\r | |
830 | \r | |
831 | @param Event The event that occured\r | |
832 | @param Context For EFI compatiblity. Not used.\r | |
833 | \r | |
834 | **/\r | |
835 | VOID\r | |
836 | EFIAPI\r | |
837 | EmuVariablesUpdatedCallback (\r | |
838 | IN EFI_EVENT Event,\r | |
839 | IN VOID *Context\r | |
840 | )\r | |
841 | {\r | |
842 | DEBUG ((EFI_D_INFO, "EmuVariablesUpdatedCallback\n"));\r | |
843 | UpdateNvVarsOnFileSystem ();\r | |
844 | }\r | |
845 | \r | |
846 | \r | |
14b21de9 | 847 | EFI_STATUS\r |
848 | EFIAPI\r | |
849 | VisitingFileSystemInstance (\r | |
850 | IN EFI_HANDLE Handle,\r | |
851 | IN VOID *Instance,\r | |
852 | IN VOID *Context\r | |
853 | )\r | |
854 | {\r | |
855 | EFI_STATUS Status;\r | |
856 | STATIC BOOLEAN ConnectedToFileSystem = FALSE;\r | |
857 | \r | |
858 | if (ConnectedToFileSystem) {\r | |
859 | return EFI_ALREADY_STARTED;\r | |
860 | }\r | |
861 | \r | |
862 | Status = ConnectNvVarsToFileSystem (Handle);\r | |
863 | if (EFI_ERROR (Status)) {\r | |
864 | return Status;\r | |
865 | }\r | |
866 | \r | |
867 | ConnectedToFileSystem = TRUE;\r | |
9607962d | 868 | mEmuVariableEvent =\r |
869 | EfiCreateProtocolNotifyEvent (\r | |
870 | &gEfiDevicePathProtocolGuid,\r | |
871 | TPL_CALLBACK,\r | |
872 | EmuVariablesUpdatedCallback,\r | |
873 | NULL,\r | |
874 | &mEmuVariableEventReg\r | |
875 | );\r | |
876 | PcdSet64 (PcdEmuVariableEvent, (UINT64)(UINTN) mEmuVariableEvent);\r | |
877 | \r | |
14b21de9 | 878 | return EFI_SUCCESS;\r |
879 | }\r | |
880 | \r | |
881 | \r | |
882 | VOID\r | |
883 | PlatformBdsRestoreNvVarsFromHardDisk (\r | |
884 | )\r | |
885 | {\r | |
886 | VisitAllPciInstances (ConnectRecursivelyIfPciMassStorage);\r | |
887 | VisitAllInstancesOfProtocol (\r | |
888 | &gEfiSimpleFileSystemProtocolGuid,\r | |
889 | VisitingFileSystemInstance,\r | |
890 | NULL\r | |
891 | );\r | |
3d131d1a | 892 | \r |
14b21de9 | 893 | }\r |
894 | \r | |
895 | \r | |
49ba9447 | 896 | VOID\r |
897 | PlatformBdsConnectSequence (\r | |
898 | VOID\r | |
899 | )\r | |
900 | /*++\r | |
901 | \r | |
902 | Routine Description:\r | |
903 | \r | |
904 | Connect with predeined platform connect sequence,\r | |
905 | the OEM/IBV can customize with their own connect sequence.\r | |
906 | \r | |
907 | Arguments:\r | |
908 | \r | |
909 | None.\r | |
910 | \r | |
911 | Returns:\r | |
912 | \r | |
913 | None.\r | |
914 | \r | |
915 | --*/\r | |
916 | {\r | |
917 | UINTN Index;\r | |
918 | \r | |
919 | DEBUG ((EFI_D_INFO, "PlatformBdsConnectSequence\n"));\r | |
920 | \r | |
921 | Index = 0;\r | |
922 | \r | |
923 | //\r | |
924 | // Here we can get the customized platform connect sequence\r | |
925 | // Notes: we can connect with new variable which record the\r | |
926 | // last time boots connect device path sequence\r | |
927 | //\r | |
928 | while (gPlatformConnectSequence[Index] != NULL) {\r | |
929 | //\r | |
930 | // Build the platform boot option\r | |
931 | //\r | |
932 | BdsLibConnectDevicePath (gPlatformConnectSequence[Index]);\r | |
933 | Index++;\r | |
934 | }\r | |
935 | \r | |
936 | //\r | |
937 | // Just use the simple policy to connect all devices\r | |
938 | //\r | |
939 | BdsLibConnectAll ();\r | |
940 | \r | |
941 | PciInitialization ();\r | |
9b167857 | 942 | AcpiInitialization ();\r |
40f2c454 | 943 | \r |
944 | //\r | |
945 | // Clear the logo after all devices are connected.\r | |
946 | //\r | |
947 | gST->ConOut->ClearScreen (gST->ConOut);\r | |
49ba9447 | 948 | }\r |
949 | \r | |
950 | VOID\r | |
951 | PlatformBdsGetDriverOption (\r | |
952 | IN OUT LIST_ENTRY *BdsDriverLists\r | |
953 | )\r | |
954 | /*++\r | |
955 | \r | |
956 | Routine Description:\r | |
957 | \r | |
958 | Load the predefined driver option, OEM/IBV can customize this\r | |
959 | to load their own drivers\r | |
960 | \r | |
961 | Arguments:\r | |
962 | \r | |
963 | BdsDriverLists - The header of the driver option link list.\r | |
964 | \r | |
965 | Returns:\r | |
966 | \r | |
967 | None.\r | |
968 | \r | |
969 | --*/\r | |
970 | {\r | |
971 | DEBUG ((EFI_D_INFO, "PlatformBdsGetDriverOption\n"));\r | |
972 | return;\r | |
973 | }\r | |
974 | \r | |
975 | VOID\r | |
976 | PlatformBdsDiagnostics (\r | |
977 | IN EXTENDMEM_COVERAGE_LEVEL MemoryTestLevel,\r | |
d18476d0 | 978 | IN BOOLEAN QuietBoot,\r |
979 | IN BASEM_MEMORY_TEST BaseMemoryTest\r | |
49ba9447 | 980 | )\r |
981 | /*++\r | |
982 | \r | |
983 | Routine Description:\r | |
984 | \r | |
985 | Perform the platform diagnostic, such like test memory. OEM/IBV also\r | |
986 | can customize this fuction to support specific platform diagnostic.\r | |
987 | \r | |
988 | Arguments:\r | |
989 | \r | |
990 | MemoryTestLevel - The memory test intensive level\r | |
991 | \r | |
992 | QuietBoot - Indicate if need to enable the quiet boot\r | |
993 | \r | |
d18476d0 | 994 | BaseMemoryTest - A pointer to BaseMemoryTest()\r |
995 | \r | |
49ba9447 | 996 | Returns:\r |
997 | \r | |
998 | None.\r | |
999 | \r | |
1000 | --*/\r | |
1001 | {\r | |
1002 | EFI_STATUS Status;\r | |
1003 | \r | |
1004 | DEBUG ((EFI_D_INFO, "PlatformBdsDiagnostics\n"));\r | |
1005 | \r | |
1006 | //\r | |
1007 | // Here we can decide if we need to show\r | |
1008 | // the diagnostics screen\r | |
1009 | // Notes: this quiet boot code should be remove\r | |
1010 | // from the graphic lib\r | |
1011 | //\r | |
1012 | if (QuietBoot) {\r | |
d46f3632 | 1013 | EnableQuietBoot (PcdGetPtr(PcdLogoFile));\r |
49ba9447 | 1014 | //\r |
1015 | // Perform system diagnostic\r | |
1016 | //\r | |
d18476d0 | 1017 | Status = BaseMemoryTest (MemoryTestLevel);\r |
49ba9447 | 1018 | if (EFI_ERROR (Status)) {\r |
1019 | DisableQuietBoot ();\r | |
1020 | }\r | |
1021 | \r | |
1022 | return ;\r | |
1023 | }\r | |
1024 | //\r | |
1025 | // Perform system diagnostic\r | |
1026 | //\r | |
d18476d0 | 1027 | Status = BaseMemoryTest (MemoryTestLevel);\r |
49ba9447 | 1028 | }\r |
1029 | \r | |
1030 | \r | |
1031 | VOID\r | |
1032 | EFIAPI\r | |
1033 | PlatformBdsPolicyBehavior (\r | |
49ba9447 | 1034 | IN OUT LIST_ENTRY *DriverOptionList,\r |
d18476d0 | 1035 | IN OUT LIST_ENTRY *BootOptionList,\r |
1036 | IN PROCESS_CAPSULES ProcessCapsules,\r | |
1037 | IN BASEM_MEMORY_TEST BaseMemoryTest\r | |
49ba9447 | 1038 | )\r |
1039 | /*++\r | |
1040 | \r | |
1041 | Routine Description:\r | |
1042 | \r | |
1043 | The function will excute with as the platform policy, current policy\r | |
1044 | is driven by boot mode. IBV/OEM can customize this code for their specific\r | |
1045 | policy action.\r | |
1046 | \r | |
1047 | Arguments:\r | |
1048 | \r | |
49ba9447 | 1049 | DriverOptionList - The header of the driver option link list\r |
1050 | \r | |
1051 | BootOptionList - The header of the boot option link list\r | |
1052 | \r | |
d18476d0 | 1053 | ProcessCapsules - A pointer to ProcessCapsules()\r |
1054 | \r | |
1055 | BaseMemoryTest - A pointer to BaseMemoryTest()\r | |
1056 | \r | |
49ba9447 | 1057 | Returns:\r |
1058 | \r | |
1059 | None.\r | |
1060 | \r | |
1061 | --*/\r | |
1062 | {\r | |
1063 | EFI_STATUS Status;\r | |
1064 | UINT16 Timeout;\r | |
1065 | EFI_EVENT UserInputDurationTime;\r | |
1066 | LIST_ENTRY *Link;\r | |
1067 | BDS_COMMON_OPTION *BootOption;\r | |
1068 | UINTN Index;\r | |
1069 | EFI_INPUT_KEY Key;\r | |
1070 | EFI_TPL OldTpl;\r | |
370ec7f1 | 1071 | EFI_BOOT_MODE BootMode;\r |
49ba9447 | 1072 | \r |
1073 | DEBUG ((EFI_D_INFO, "PlatformBdsPolicyBehavior\n"));\r | |
1074 | \r | |
14b21de9 | 1075 | ConnectRootBridge ();\r |
1076 | \r | |
2590861a LE |
1077 | if (PcdGetBool (PcdOvmfFlashVariablesEnable)) {\r |
1078 | DEBUG ((EFI_D_INFO, "PlatformBdsPolicyBehavior: not restoring NvVars "\r | |
1079 | "from disk since flash variables appear to be supported.\n"));\r | |
1080 | } else {\r | |
1081 | //\r | |
1082 | // Try to restore variables from the hard disk early so\r | |
1083 | // they can be used for the other BDS connect operations.\r | |
1084 | //\r | |
1085 | PlatformBdsRestoreNvVarsFromHardDisk ();\r | |
1086 | }\r | |
14b21de9 | 1087 | \r |
49ba9447 | 1088 | //\r |
1089 | // Init the time out value\r | |
1090 | //\r | |
1091 | Timeout = PcdGet16 (PcdPlatformBootTimeOut);\r | |
1092 | \r | |
1093 | //\r | |
1094 | // Load the driver option as the driver option list\r | |
1095 | //\r | |
1096 | PlatformBdsGetDriverOption (DriverOptionList);\r | |
1097 | \r | |
1098 | //\r | |
1099 | // Get current Boot Mode\r | |
1100 | //\r | |
370ec7f1 | 1101 | Status = BdsLibGetBootMode (&BootMode);\r |
1102 | DEBUG ((EFI_D_ERROR, "Boot Mode:%x\n", BootMode));\r | |
49ba9447 | 1103 | \r |
1104 | //\r | |
1105 | // Go the different platform policy with different boot mode\r | |
1106 | // Notes: this part code can be change with the table policy\r | |
1107 | //\r | |
370ec7f1 | 1108 | ASSERT (BootMode == BOOT_WITH_FULL_CONFIGURATION);\r |
49ba9447 | 1109 | //\r |
1110 | // Connect platform console\r | |
1111 | //\r | |
1112 | Status = PlatformBdsConnectConsole (gPlatformConsole);\r | |
1113 | if (EFI_ERROR (Status)) {\r | |
1114 | //\r | |
1115 | // Here OEM/IBV can customize with defined action\r | |
1116 | //\r | |
1117 | PlatformBdsNoConsoleAction ();\r | |
1118 | }\r | |
1119 | //\r | |
1120 | // Create a 300ms duration event to ensure user has enough input time to enter Setup\r | |
1121 | //\r | |
1122 | Status = gBS->CreateEvent (\r | |
1123 | EVT_TIMER,\r | |
1124 | 0,\r | |
1125 | NULL,\r | |
1126 | NULL,\r | |
1127 | &UserInputDurationTime\r | |
1128 | );\r | |
1129 | ASSERT (Status == EFI_SUCCESS);\r | |
1130 | Status = gBS->SetTimer (UserInputDurationTime, TimerRelative, 3000000);\r | |
1131 | ASSERT (Status == EFI_SUCCESS);\r | |
1132 | //\r | |
1133 | // Memory test and Logo show\r | |
1134 | //\r | |
d18476d0 | 1135 | PlatformBdsDiagnostics (IGNORE, TRUE, BaseMemoryTest);\r |
49ba9447 | 1136 | \r |
1137 | //\r | |
1138 | // Perform some platform specific connect sequence\r | |
1139 | //\r | |
1140 | PlatformBdsConnectSequence ();\r | |
1141 | \r | |
52fba289 | 1142 | //\r |
1143 | // Process QEMU's -kernel command line option\r | |
1144 | //\r | |
1145 | TryRunningQemuKernel ();\r | |
1146 | \r | |
49ba9447 | 1147 | DEBUG ((EFI_D_INFO, "BdsLibConnectAll\n"));\r |
1148 | BdsLibConnectAll ();\r | |
1149 | BdsLibEnumerateAllBootOption (BootOptionList);\r | |
1150 | \r | |
2cd086a6 | 1151 | SetBootOrderFromQemu (BootOptionList);\r |
49ba9447 | 1152 | //\r |
de5ae37b LE |
1153 | // The BootOrder variable may have changed, reload the in-memory list with\r |
1154 | // it.\r | |
49ba9447 | 1155 | //\r |
de5ae37b | 1156 | BdsLibBuildOptionFromVar (BootOptionList, L"BootOrder");\r |
49ba9447 | 1157 | \r |
1158 | //\r | |
1159 | // To give the User a chance to enter Setup here, if user set TimeOut is 0.\r | |
1160 | // BDS should still give user a chance to enter Setup\r | |
1161 | //\r | |
1162 | // Connect first boot option, and then check user input before exit\r | |
1163 | //\r | |
1164 | for (Link = BootOptionList->ForwardLink; Link != BootOptionList;Link = Link->ForwardLink) {\r | |
1165 | BootOption = CR (Link, BDS_COMMON_OPTION, Link, BDS_LOAD_OPTION_SIGNATURE);\r | |
1166 | if (!IS_LOAD_OPTION_TYPE (BootOption->Attribute, LOAD_OPTION_ACTIVE)) {\r | |
1167 | //\r | |
1168 | // skip the header of the link list, becuase it has no boot option\r | |
1169 | //\r | |
1170 | continue;\r | |
1171 | } else {\r | |
1172 | //\r | |
1173 | // Make sure the boot option device path connected, but ignore the BBS device path\r | |
1174 | //\r | |
1175 | if (DevicePathType (BootOption->DevicePath) != BBS_DEVICE_PATH) {\r | |
1176 | BdsLibConnectDevicePath (BootOption->DevicePath);\r | |
1177 | }\r | |
1178 | break;\r | |
1179 | }\r | |
1180 | }\r | |
1181 | \r | |
1182 | //\r | |
1183 | // Check whether the user input after the duration time has expired\r | |
1184 | //\r | |
1185 | OldTpl = EfiGetCurrentTpl();\r | |
1186 | gBS->RestoreTPL (TPL_APPLICATION);\r | |
1187 | gBS->WaitForEvent (1, &UserInputDurationTime, &Index);\r | |
1188 | gBS->CloseEvent (UserInputDurationTime);\r | |
1189 | Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r | |
1190 | gBS->RaiseTPL (OldTpl);\r | |
1191 | \r | |
1192 | if (!EFI_ERROR (Status)) {\r | |
1193 | //\r | |
1194 | // Enter Setup if user input\r | |
1195 | //\r | |
1196 | Timeout = 0xffff;\r | |
1197 | PlatformBdsEnterFrontPage (Timeout, FALSE);\r | |
1198 | }\r | |
49ba9447 | 1199 | }\r |
1200 | \r | |
1201 | VOID\r | |
1202 | EFIAPI\r | |
1203 | PlatformBdsBootSuccess (\r | |
1204 | IN BDS_COMMON_OPTION *Option\r | |
1205 | )\r | |
1206 | /*++\r | |
1207 | \r | |
1208 | Routine Description:\r | |
1209 | \r | |
1210 | Hook point after a boot attempt succeeds. We don't expect a boot option to\r | |
1211 | return, so the EFI 1.0 specification defines that you will default to an\r | |
1212 | interactive mode and stop processing the BootOrder list in this case. This\r | |
1213 | is alos a platform implementation and can be customized by IBV/OEM.\r | |
1214 | \r | |
1215 | Arguments:\r | |
1216 | \r | |
1217 | Option - Pointer to Boot Option that succeeded to boot.\r | |
1218 | \r | |
1219 | Returns:\r | |
1220 | \r | |
1221 | None.\r | |
1222 | \r | |
1223 | --*/\r | |
1224 | {\r | |
1225 | CHAR16 *TmpStr;\r | |
1226 | \r | |
1227 | DEBUG ((EFI_D_INFO, "PlatformBdsBootSuccess\n"));\r | |
1228 | //\r | |
1229 | // If Boot returned with EFI_SUCCESS and there is not in the boot device\r | |
1230 | // select loop then we need to pop up a UI and wait for user input.\r | |
1231 | //\r | |
1232 | TmpStr = Option->StatusString;\r | |
1233 | if (TmpStr != NULL) {\r | |
1234 | BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL);\r | |
1235 | FreePool (TmpStr);\r | |
1236 | }\r | |
1237 | }\r | |
1238 | \r | |
1239 | VOID\r | |
1240 | EFIAPI\r | |
1241 | PlatformBdsBootFail (\r | |
1242 | IN BDS_COMMON_OPTION *Option,\r | |
1243 | IN EFI_STATUS Status,\r | |
1244 | IN CHAR16 *ExitData,\r | |
1245 | IN UINTN ExitDataSize\r | |
1246 | )\r | |
1247 | /*++\r | |
1248 | \r | |
1249 | Routine Description:\r | |
1250 | \r | |
1251 | Hook point after a boot attempt fails.\r | |
1252 | \r | |
1253 | Arguments:\r | |
1254 | \r | |
1255 | Option - Pointer to Boot Option that failed to boot.\r | |
1256 | \r | |
1257 | Status - Status returned from failed boot.\r | |
1258 | \r | |
1259 | ExitData - Exit data returned from failed boot.\r | |
1260 | \r | |
1261 | ExitDataSize - Exit data size returned from failed boot.\r | |
1262 | \r | |
1263 | Returns:\r | |
1264 | \r | |
1265 | None.\r | |
1266 | \r | |
1267 | --*/\r | |
1268 | {\r | |
1269 | CHAR16 *TmpStr;\r | |
1270 | \r | |
1271 | DEBUG ((EFI_D_INFO, "PlatformBdsBootFail\n"));\r | |
1272 | \r | |
1273 | //\r | |
1274 | // If Boot returned with failed status then we need to pop up a UI and wait\r | |
1275 | // for user input.\r | |
1276 | //\r | |
1277 | TmpStr = Option->StatusString;\r | |
1278 | if (TmpStr != NULL) {\r | |
1279 | BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL);\r | |
1280 | FreePool (TmpStr);\r | |
1281 | }\r | |
1282 | }\r | |
1283 | \r | |
1284 | EFI_STATUS\r | |
1285 | PlatformBdsNoConsoleAction (\r | |
1286 | VOID\r | |
1287 | )\r | |
1288 | /*++\r | |
1289 | \r | |
1290 | Routine Description:\r | |
1291 | \r | |
1292 | This function is remained for IBV/OEM to do some platform action,\r | |
1293 | if there no console device can be connected.\r | |
1294 | \r | |
1295 | Arguments:\r | |
1296 | \r | |
1297 | None.\r | |
1298 | \r | |
1299 | Returns:\r | |
1300 | \r | |
1301 | EFI_SUCCESS - Direct return success now.\r | |
1302 | \r | |
1303 | --*/\r | |
1304 | {\r | |
1305 | DEBUG ((EFI_D_INFO, "PlatformBdsNoConsoleAction\n"));\r | |
1306 | return EFI_SUCCESS;\r | |
1307 | }\r | |
1308 | \r | |
24cdd14e | 1309 | VOID\r |
49ba9447 | 1310 | EFIAPI\r |
1311 | PlatformBdsLockNonUpdatableFlash (\r | |
1312 | VOID\r | |
1313 | )\r | |
1314 | {\r | |
1315 | DEBUG ((EFI_D_INFO, "PlatformBdsLockNonUpdatableFlash\n"));\r | |
24cdd14e | 1316 | return;\r |
49ba9447 | 1317 | }\r |
40f2c454 | 1318 | \r |
1319 | \r | |
1320 | /**\r | |
1321 | This notification function is invoked when an instance of the\r | |
1322 | EFI_DEVICE_PATH_PROTOCOL is produced.\r | |
1323 | \r | |
1324 | @param Event The event that occured\r | |
1325 | @param Context For EFI compatiblity. Not used.\r | |
1326 | \r | |
1327 | **/\r | |
1328 | VOID\r | |
1329 | EFIAPI\r | |
1330 | NotifyDevPath (\r | |
1331 | IN EFI_EVENT Event,\r | |
1332 | IN VOID *Context\r | |
1333 | )\r | |
1334 | {\r | |
1335 | EFI_HANDLE Handle;\r | |
1336 | EFI_STATUS Status;\r | |
1337 | UINTN BufferSize;\r | |
1338 | EFI_DEVICE_PATH_PROTOCOL *DevPathNode;\r | |
1339 | ATAPI_DEVICE_PATH *Atapi;\r | |
1340 | \r | |
1341 | //\r | |
1342 | // Examine all new handles\r | |
1343 | //\r | |
1344 | for (;;) {\r | |
1345 | //\r | |
1346 | // Get the next handle\r | |
1347 | //\r | |
1348 | BufferSize = sizeof (Handle);\r | |
1349 | Status = gBS->LocateHandle (\r | |
1350 | ByRegisterNotify,\r | |
1351 | NULL,\r | |
1352 | mEfiDevPathNotifyReg,\r | |
1353 | &BufferSize,\r | |
1354 | &Handle\r | |
1355 | );\r | |
1356 | \r | |
1357 | //\r | |
1358 | // If not found, we're done\r | |
1359 | //\r | |
1360 | if (EFI_NOT_FOUND == Status) {\r | |
1361 | break;\r | |
1362 | }\r | |
1363 | \r | |
1364 | if (EFI_ERROR (Status)) {\r | |
1365 | continue;\r | |
1366 | }\r | |
1367 | \r | |
1368 | //\r | |
1369 | // Get the DevicePath protocol on that handle\r | |
1370 | //\r | |
1371 | Status = gBS->HandleProtocol (Handle, &gEfiDevicePathProtocolGuid, (VOID **)&DevPathNode);\r | |
1372 | ASSERT_EFI_ERROR (Status);\r | |
1373 | \r | |
1374 | while (!IsDevicePathEnd (DevPathNode)) {\r | |
1375 | //\r | |
1376 | // Find the handler to dump this device path node\r | |
1377 | //\r | |
1378 | if (\r | |
1379 | (DevicePathType(DevPathNode) == MESSAGING_DEVICE_PATH) &&\r | |
1380 | (DevicePathSubType(DevPathNode) == MSG_ATAPI_DP)\r | |
1381 | ) {\r | |
1382 | Atapi = (ATAPI_DEVICE_PATH*) DevPathNode;\r | |
1383 | PciOr16 (\r | |
1384 | PCI_LIB_ADDRESS (\r | |
1385 | 0,\r | |
1386 | 1,\r | |
1387 | 1,\r | |
1388 | (Atapi->PrimarySecondary == 1) ? 0x42: 0x40\r | |
1389 | ),\r | |
1390 | BIT15\r | |
1391 | );\r | |
1392 | }\r | |
1393 | \r | |
1394 | //\r | |
1395 | // Next device path node\r | |
1396 | //\r | |
1397 | DevPathNode = NextDevicePathNode (DevPathNode);\r | |
1398 | }\r | |
1399 | }\r | |
1400 | \r | |
1401 | return;\r | |
1402 | }\r | |
1403 | \r | |
1404 | \r | |
1405 | VOID\r | |
1406 | InstallDevicePathCallback (\r | |
1407 | VOID\r | |
1408 | )\r | |
1409 | {\r | |
1410 | DEBUG ((EFI_D_INFO, "Registered NotifyDevPath Event\n"));\r | |
1411 | mEfiDevPathEvent = EfiCreateProtocolNotifyEvent (\r | |
1412 | &gEfiDevicePathProtocolGuid,\r | |
1413 | TPL_CALLBACK,\r | |
1414 | NotifyDevPath,\r | |
1415 | NULL,\r | |
1416 | &mEfiDevPathNotifyReg\r | |
1417 | );\r | |
1418 | }\r | |
1419 | \r | |
24cdd14e LG |
1420 | /**\r |
1421 | Lock the ConsoleIn device in system table. All key\r | |
1422 | presses will be ignored until the Password is typed in. The only way to\r | |
1423 | disable the password is to type it in to a ConIn device.\r | |
1424 | \r | |
1425 | @param Password Password used to lock ConIn device.\r | |
1426 | \r | |
1427 | @retval EFI_SUCCESS lock the Console In Spliter virtual handle successfully.\r | |
1428 | @retval EFI_UNSUPPORTED Password not found\r | |
1429 | \r | |
1430 | **/\r | |
1431 | EFI_STATUS\r | |
1432 | EFIAPI\r | |
1433 | LockKeyboards (\r | |
1434 | IN CHAR16 *Password\r | |
1435 | )\r | |
1436 | {\r | |
1437 | return EFI_UNSUPPORTED;\r | |
1438 | }\r | |
5106d422 | 1439 | \r |