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