]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/Library/PlatformBdsLib/BdsPlatform.c
Fix VS2013 build failure.
[mirror_edk2.git] / OvmfPkg / Library / PlatformBdsLib / BdsPlatform.c
index 71be1dbefe3aa09ff4edf8132f37c979da1b8c2f..2a1ca88c2c13ed4be225fd2d16b1b509d9e424e3 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   Platform BDS customizations.\r
 \r
-  Copyright (c) 2004 - 2008, Intel Corporation. <BR>\r
-  All rights reserved. This program and the accompanying materials\r
+  Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
   http://opensource.org/licenses/bsd-license.php\r
@@ -13,6 +13,7 @@
 **/\r
 \r
 #include "BdsPlatform.h"\r
+#include "QemuBootOrder.h"\r
 \r
 \r
 //\r
@@ -21,6 +22,8 @@
 \r
 VOID          *mEfiDevPathNotifyReg;\r
 EFI_EVENT     mEfiDevPathEvent;\r
+VOID          *mEmuVariableEventReg;\r
+EFI_EVENT     mEmuVariableEvent;\r
 BOOLEAN       mDetectVgaOnly;\r
 \r
 \r
@@ -71,19 +74,6 @@ InstallDevicePathCallback (
   VOID\r
   );\r
 \r
-STATIC\r
-VOID\r
-LoadVideoRom (\r
-  VOID\r
-  );\r
-\r
-STATIC\r
-EFI_STATUS\r
-PciRomLoadEfiDriversFromRomImage (\r
-  IN EFI_PHYSICAL_ADDRESS    Rom,\r
-  IN UINTN                   RomSize\r
-  );\r
-\r
 //\r
 // BDS Platform Functions\r
 //\r
@@ -109,7 +99,6 @@ Returns:
 {\r
   DEBUG ((EFI_D_INFO, "PlatformBdsInit\n"));\r
   InstallDevicePathCallback ();\r
-  LoadVideoRom ();\r
 }\r
 \r
 \r
@@ -220,14 +209,16 @@ Returns:
   // Print Device Path\r
   //\r
   DevPathStr = DevicePathToStr(DevicePath);\r
-  DEBUG((\r
-    EFI_D_INFO,\r
-    "BdsPlatform.c+%d: COM%d DevPath: %s\n",\r
-    __LINE__,\r
-    gPnp16550ComPortDeviceNode.UID + 1,\r
-    DevPathStr\r
-    ));\r
-  FreePool(DevPathStr);\r
+  if (DevPathStr != NULL) {\r
+    DEBUG((\r
+      EFI_D_INFO,\r
+      "BdsPlatform.c+%d: COM%d DevPath: %s\n",\r
+      __LINE__,\r
+      gPnp16550ComPortDeviceNode.UID + 1,\r
+      DevPathStr\r
+      ));\r
+    FreePool(DevPathStr);\r
+  }\r
 \r
   BdsLibUpdateConsoleVariable (VarConsoleOut, DevicePath, NULL);\r
   BdsLibUpdateConsoleVariable (VarConsoleInp, DevicePath, NULL);\r
@@ -247,14 +238,16 @@ Returns:
   // Print Device Path\r
   //\r
   DevPathStr = DevicePathToStr(DevicePath);\r
-  DEBUG((\r
-    EFI_D_INFO,\r
-    "BdsPlatform.c+%d: COM%d DevPath: %s\n",\r
-    __LINE__,\r
-    gPnp16550ComPortDeviceNode.UID + 1,\r
-    DevPathStr\r
-    ));\r
-  FreePool(DevPathStr);\r
+  if (DevPathStr != NULL) {\r
+    DEBUG((\r
+      EFI_D_INFO,\r
+      "BdsPlatform.c+%d: COM%d DevPath: %s\n",\r
+      __LINE__,\r
+      gPnp16550ComPortDeviceNode.UID + 1,\r
+      DevPathStr\r
+      ));\r
+    FreePool(DevPathStr);\r
+  }\r
 \r
   BdsLibUpdateConsoleVariable (VarConsoleOut, DevicePath, NULL);\r
   BdsLibUpdateConsoleVariable (VarConsoleInp, DevicePath, NULL);\r
@@ -374,7 +367,8 @@ Returns:
   EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
   EFI_DEVICE_PATH_PROTOCOL  *GopDevicePath;\r
 \r
-  DevicePath = NULL;\r
+  DevicePath    = NULL;\r
+  GopDevicePath = NULL;\r
   Status = gBS->HandleProtocol (\r
                   DeviceHandle,\r
                   &gEfiDevicePathProtocolGuid,\r
@@ -513,7 +507,7 @@ VisitingAPciInstance (
     return Status;\r
   }\r
 \r
-  return (*(VISIT_PCI_INSTANCE_CALLBACK) Context) (\r
+  return (*(VISIT_PCI_INSTANCE_CALLBACK)(UINTN) Context) (\r
            Handle,\r
            PciIo,\r
            &Pci\r
@@ -531,7 +525,7 @@ VisitAllPciInstances (
   return VisitAllInstancesOfProtocol (\r
            &gEfiPciIoProtocolGuid,\r
            VisitingAPciInstance,\r
-           (VOID*) CallBackFunction\r
+           (VOID*)(UINTN) CallBackFunction\r
            );\r
 }\r
 \r
@@ -549,6 +543,7 @@ VisitAllPciInstances (
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 DetectAndPreparePlatformPciDevicePath (\r
   IN EFI_HANDLE           Handle,\r
   IN EFI_PCI_IO_PROTOCOL  *PciIo,\r
@@ -666,8 +661,6 @@ Returns:
   //\r
   // Connect RootBridge\r
   //\r
-  ConnectRootBridge ();\r
-\r
   VarConout = BdsLibGetVariableAndSize (\r
                 VarConsoleOut,\r
                 &gEfiGlobalVariableGuid,\r
@@ -736,10 +729,10 @@ PciInitialization (
   // Bus 0, Device 1, Function 0 - PCI to ISA Bridge\r
   //\r
   PciWrite8 (PCI_LIB_ADDRESS (0, 1, 0, 0x3c), 0x00);\r
-  PciWrite8 (PCI_LIB_ADDRESS (0, 1, 0, 0x60), 0x0b);\r
-  PciWrite8 (PCI_LIB_ADDRESS (0, 1, 0, 0x61), 0x09);\r
-  PciWrite8 (PCI_LIB_ADDRESS (0, 1, 0, 0x62), 0x0b);\r
-  PciWrite8 (PCI_LIB_ADDRESS (0, 1, 0, 0x63), 0x09);\r
+  PciWrite8 (PCI_LIB_ADDRESS (0, 1, 0, 0x60), 0x0b); // LNKA routing target\r
+  PciWrite8 (PCI_LIB_ADDRESS (0, 1, 0, 0x61), 0x0b); // LNKB routing target\r
+  PciWrite8 (PCI_LIB_ADDRESS (0, 1, 0, 0x62), 0x0a); // LNKC routing target\r
+  PciWrite8 (PCI_LIB_ADDRESS (0, 1, 0, 0x63), 0x0a); // LNKD routing target\r
 \r
   //\r
   // Bus 0, Device 1, Function 1 - IDE Controller\r
@@ -750,8 +743,8 @@ PciInitialization (
   //\r
   // Bus 0, Device 1, Function 3 - Power Managment Controller\r
   //\r
-  PciWrite8 (PCI_LIB_ADDRESS (0, 1, 3, 0x3c), 0x0b);\r
-  PciWrite8 (PCI_LIB_ADDRESS (0, 1, 3, 0x3d), 0x01);\r
+  PciWrite8 (PCI_LIB_ADDRESS (0, 1, 3, 0x3c), 0x09);\r
+  PciWrite8 (PCI_LIB_ADDRESS (0, 1, 3, 0x3d), 0x01); // INTA\r
 \r
   //\r
   // Bus 0, Device 2, Function 0 - Video Controller\r
@@ -761,14 +754,142 @@ PciInitialization (
   //\r
   // Bus 0, Device 3, Function 0 - Network Controller\r
   //\r
-  PciWrite8 (PCI_LIB_ADDRESS (0, 3, 0, 0x3c), 0x0b);\r
-  PciWrite8 (PCI_LIB_ADDRESS (0, 3, 0, 0x3d), 0x01);\r
+  PciWrite8 (PCI_LIB_ADDRESS (0, 3, 0, 0x3c), 0x0a);\r
+  PciWrite8 (PCI_LIB_ADDRESS (0, 3, 0, 0x3d), 0x01); // INTA (-> LNKC)\r
 \r
   //\r
-  // Bus 0, Device 4, Function 0 - RAM Memory\r
+  // Bus 0, Device 5, Function 0 - RAM Memory\r
   //\r
-  PciWrite8 (PCI_LIB_ADDRESS (0, 4, 0, 0x3c), 0x09);\r
-  PciWrite8 (PCI_LIB_ADDRESS (0, 4, 0, 0x3d), 0x01);\r
+  PciWrite8 (PCI_LIB_ADDRESS (0, 5, 0, 0x3c), 0x0b);\r
+  PciWrite8 (PCI_LIB_ADDRESS (0, 5, 0, 0x3d), 0x01); // INTA (-> LNKA)\r
+}\r
+\r
+\r
+VOID\r
+AcpiInitialization (\r
+  VOID\r
+  )\r
+{\r
+  //\r
+  // Set ACPI SCI_EN bit in PMCNTRL\r
+  //\r
+  IoOr16 ((PciRead32 (PCI_LIB_ADDRESS (0, 1, 3, 0x40)) & ~BIT0) + 4, BIT0);\r
+}\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ConnectRecursivelyIfPciMassStorage (\r
+  IN EFI_HANDLE           Handle,\r
+  IN EFI_PCI_IO_PROTOCOL  *Instance,\r
+  IN PCI_TYPE00           *PciHeader\r
+  )\r
+{\r
+  EFI_STATUS                Status;\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
+  CHAR16                    *DevPathStr;\r
+\r
+  if (IS_CLASS1 (PciHeader, PCI_CLASS_MASS_STORAGE)) {\r
+    DevicePath = NULL;\r
+    Status = gBS->HandleProtocol (\r
+                    Handle,\r
+                    &gEfiDevicePathProtocolGuid,\r
+                    (VOID*)&DevicePath\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+\r
+    //\r
+    // Print Device Path\r
+    //\r
+    DevPathStr = DevicePathToStr (DevicePath);\r
+    if (DevPathStr != NULL) {\r
+      DEBUG((\r
+        EFI_D_INFO,\r
+        "Found Mass Storage device: %s\n",\r
+        DevPathStr\r
+        ));\r
+      FreePool(DevPathStr);\r
+    }\r
+\r
+    Status = gBS->ConnectController (Handle, NULL, NULL, TRUE);\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  This notification function is invoked when the\r
+  EMU Variable FVB has been changed.\r
+\r
+  @param  Event                 The event that occured\r
+  @param  Context               For EFI compatiblity.  Not used.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+EmuVariablesUpdatedCallback (\r
+  IN  EFI_EVENT Event,\r
+  IN  VOID      *Context\r
+  )\r
+{\r
+  DEBUG ((EFI_D_INFO, "EmuVariablesUpdatedCallback\n"));\r
+  UpdateNvVarsOnFileSystem ();\r
+}\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+VisitingFileSystemInstance (\r
+  IN EFI_HANDLE  Handle,\r
+  IN VOID        *Instance,\r
+  IN VOID        *Context\r
+  )\r
+{\r
+  EFI_STATUS      Status;\r
+  STATIC BOOLEAN  ConnectedToFileSystem = FALSE;\r
+\r
+  if (ConnectedToFileSystem) {\r
+    return EFI_ALREADY_STARTED;\r
+  }\r
+\r
+  Status = ConnectNvVarsToFileSystem (Handle);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  ConnectedToFileSystem = TRUE;\r
+  mEmuVariableEvent =\r
+    EfiCreateProtocolNotifyEvent (\r
+      &gEfiDevicePathProtocolGuid,\r
+      TPL_CALLBACK,\r
+      EmuVariablesUpdatedCallback,\r
+      NULL,\r
+      &mEmuVariableEventReg\r
+      );\r
+  PcdSet64 (PcdEmuVariableEvent, (UINT64)(UINTN) mEmuVariableEvent);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+VOID\r
+PlatformBdsRestoreNvVarsFromHardDisk (\r
+  )\r
+{\r
+  VisitAllPciInstances (ConnectRecursivelyIfPciMassStorage);\r
+  VisitAllInstancesOfProtocol (\r
+    &gEfiSimpleFileSystemProtocolGuid,\r
+    VisitingFileSystemInstance,\r
+    NULL\r
+    );\r
+\r
 }\r
 \r
 \r
@@ -818,6 +939,7 @@ Returns:
   BdsLibConnectAll ();\r
 \r
   PciInitialization ();\r
+  AcpiInitialization ();\r
 \r
   //\r
   // Clear the logo after all devices are connected.\r
@@ -950,6 +1072,19 @@ Returns:
 \r
   DEBUG ((EFI_D_INFO, "PlatformBdsPolicyBehavior\n"));\r
 \r
+  ConnectRootBridge ();\r
+\r
+  if (PcdGetBool (PcdOvmfFlashVariablesEnable)) {\r
+    DEBUG ((EFI_D_INFO, "PlatformBdsPolicyBehavior: not restoring NvVars "\r
+      "from disk since flash variables appear to be supported.\n"));\r
+  } else {\r
+    //\r
+    // Try to restore variables from the hard disk early so\r
+    // they can be used for the other BDS connect operations.\r
+    //\r
+    PlatformBdsRestoreNvVarsFromHardDisk ();\r
+  }\r
+\r
   //\r
   // Init the time out value\r
   //\r
@@ -1004,6 +1139,11 @@ Returns:
   //\r
   PlatformBdsConnectSequence ();\r
 \r
+  //\r
+  // Process QEMU's -kernel command line option\r
+  //\r
+  TryRunningQemuKernel ();\r
+\r
   //\r
   // Give one chance to enter the setup if we\r
   // have the time out\r
@@ -1016,24 +1156,12 @@ Returns:
   BdsLibConnectAll ();\r
   BdsLibEnumerateAllBootOption (BootOptionList);\r
 \r
+  SetBootOrderFromQemu (BootOptionList);\r
   //\r
-  // Please uncomment above ConnectAll and EnumerateAll code and remove following first boot\r
-  // checking code in real production tip.\r
+  // The BootOrder variable may have changed, reload the in-memory list with\r
+  // it.\r
   //\r
-  // In BOOT_WITH_FULL_CONFIGURATION boot mode, should always connect every device\r
-  // and do enumerate all the default boot options. But in development system board, the boot mode\r
-  // cannot be BOOT_ASSUMING_NO_CONFIGURATION_CHANGES because the machine box\r
-  // is always open. So the following code only do the ConnectAll and EnumerateAll at first boot.\r
-  //\r
-  Status = BdsLibBuildOptionFromVar (BootOptionList, L"BootOrder");\r
-  if (EFI_ERROR(Status)) {\r
-    //\r
-    // If cannot find "BootOrder" variable,  it may be first boot.\r
-    // Try to connect all devices and enumerate all boot options here.\r
-    //\r
-    BdsLibConnectAll ();\r
-    BdsLibEnumerateAllBootOption (BootOptionList);\r
-  }\r
+  BdsLibBuildOptionFromVar (BootOptionList, L"BootOrder");\r
 \r
   //\r
   // To give the User a chance to enter Setup here, if user set TimeOut is 0.\r
@@ -1319,175 +1447,3 @@ LockKeyboards (
     return EFI_UNSUPPORTED;\r
 }\r
 \r
-\r
-STATIC\r
-VOID\r
-LoadVideoRom (\r
-  VOID\r
-  )\r
-{\r
-  PCI_DATA_STRUCTURE            *Pcir;\r
-  UINTN                         RomSize;\r
-\r
-  //\r
-  // The virtual machines sometimes load the video rom image\r
-  // directly at the legacy video BIOS location of C000:0000,\r
-  // and do not implement the PCI expansion ROM feature.\r
-  //\r
-  Pcir = (PCI_DATA_STRUCTURE *) (UINTN) 0xc0000;\r
-  RomSize = Pcir->ImageLength * 512;\r
-  PciRomLoadEfiDriversFromRomImage (0xc0000, RomSize);\r
-}\r
-\r
-\r
-STATIC\r
-EFI_STATUS\r
-PciRomLoadEfiDriversFromRomImage (\r
-  IN EFI_PHYSICAL_ADDRESS    Rom,\r
-  IN UINTN                   RomSize\r
-  )\r
-{\r
-  CHAR16                        *FileName;\r
-  EFI_PCI_EXPANSION_ROM_HEADER  *EfiRomHeader;\r
-  PCI_DATA_STRUCTURE            *Pcir;\r
-  UINTN                         ImageIndex;\r
-  UINTN                         RomOffset;\r
-  UINT32                        ImageSize;\r
-  UINT16                        ImageOffset;\r
-  EFI_HANDLE                    ImageHandle;\r
-  EFI_STATUS                    Status;\r
-  EFI_STATUS                    retStatus;\r
-  EFI_DEVICE_PATH_PROTOCOL      *FilePath;\r
-  BOOLEAN                       SkipImage;\r
-  UINT32                        DestinationSize;\r
-  UINT32                        ScratchSize;\r
-  UINT8                         *Scratch;\r
-  VOID                          *ImageBuffer;\r
-  VOID                          *DecompressedImageBuffer;\r
-  UINT32                        ImageLength;\r
-  EFI_DECOMPRESS_PROTOCOL       *Decompress;\r
-\r
-  FileName = L"PciRomInMemory";\r
-\r
-  //FileName = L"PciRom Addr=0000000000000000";\r
-  //HexToString (&FileName[12], Rom, 16);\r
-\r
-  ImageIndex    = 0;\r
-  retStatus     = EFI_NOT_FOUND;\r
-  RomOffset  = (UINTN) Rom;\r
-\r
-  do {\r
-\r
-    EfiRomHeader = (EFI_PCI_EXPANSION_ROM_HEADER *) (UINTN) RomOffset;\r
-\r
-    if (EfiRomHeader->Signature != 0xaa55) {\r
-      return retStatus;\r
-    }\r
-\r
-    Pcir      = (PCI_DATA_STRUCTURE *) (UINTN) (RomOffset + EfiRomHeader->PcirOffset);\r
-    ImageSize = Pcir->ImageLength * 512;\r
-\r
-    if ((Pcir->CodeType == PCI_CODE_TYPE_EFI_IMAGE) &&\r
-        (EfiRomHeader->EfiSignature == EFI_PCI_EXPANSION_ROM_HEADER_EFISIGNATURE) ) {\r
-\r
-      if ((EfiRomHeader->EfiSubsystem == EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER) ||\r
-          (EfiRomHeader->EfiSubsystem == EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER) ) {\r
-\r
-        ImageOffset             = EfiRomHeader->EfiImageHeaderOffset;\r
-        ImageSize               = EfiRomHeader->InitializationSize * 512;\r
-\r
-        ImageBuffer             = (VOID *) (UINTN) (RomOffset + ImageOffset);\r
-        ImageLength             = ImageSize - ImageOffset;\r
-        DecompressedImageBuffer = NULL;\r
-\r
-        //\r
-        // decompress here if needed\r
-        //\r
-        SkipImage = FALSE;\r
-        if (EfiRomHeader->CompressionType > EFI_PCI_EXPANSION_ROM_HEADER_COMPRESSED) {\r
-          SkipImage = TRUE;\r
-        }\r
-\r
-        if (EfiRomHeader->CompressionType == EFI_PCI_EXPANSION_ROM_HEADER_COMPRESSED) {\r
-          Status = gBS->LocateProtocol (&gEfiDecompressProtocolGuid, NULL, (VOID **) &Decompress);\r
-          if (EFI_ERROR (Status)) {\r
-            SkipImage = TRUE;\r
-          } else {\r
-            SkipImage = TRUE;\r
-            Status = Decompress->GetInfo (\r
-                                  Decompress,\r
-                                  ImageBuffer,\r
-                                  ImageLength,\r
-                                  &DestinationSize,\r
-                                  &ScratchSize\r
-                                  );\r
-            if (!EFI_ERROR (Status)) {\r
-              DecompressedImageBuffer = NULL;\r
-              DecompressedImageBuffer = AllocatePool (DestinationSize);\r
-              if (DecompressedImageBuffer != NULL) {\r
-                Scratch = AllocatePool (ScratchSize);\r
-                if (Scratch != NULL) {\r
-                  Status = Decompress->Decompress (\r
-                                        Decompress,\r
-                                        ImageBuffer,\r
-                                        ImageLength,\r
-                                        DecompressedImageBuffer,\r
-                                        DestinationSize,\r
-                                        Scratch,\r
-                                        ScratchSize\r
-                                        );\r
-                  if (!EFI_ERROR (Status)) {\r
-                    ImageBuffer = DecompressedImageBuffer;\r
-                    ImageLength = DestinationSize;\r
-                    SkipImage   = FALSE;\r
-                  }\r
-\r
-                  gBS->FreePool (Scratch);\r
-                }\r
-              }\r
-            }\r
-          }\r
-        }\r
-\r
-        if (!SkipImage) {\r
-\r
-          //\r
-          // load image and start image\r
-          //\r
-\r
-          FilePath = FileDevicePath (NULL, FileName);\r
-\r
-          Status = gBS->LoadImage (\r
-                          FALSE,\r
-                          gImageHandle,\r
-                          FilePath,\r
-                          ImageBuffer,\r
-                          ImageLength,\r
-                          &ImageHandle\r
-                          );\r
-          if (!EFI_ERROR (Status)) {\r
-            Status = gBS->StartImage (ImageHandle, NULL, NULL);\r
-            if (!EFI_ERROR (Status)) {\r
-              retStatus = Status;\r
-            }\r
-          }\r
-          if (FilePath != NULL) {\r
-            gBS->FreePool (FilePath);\r
-          }\r
-        }\r
-\r
-        if (DecompressedImageBuffer != NULL) {\r
-          gBS->FreePool (DecompressedImageBuffer);\r
-        }\r
-\r
-      }\r
-    }\r
-\r
-    RomOffset = RomOffset + ImageSize;\r
-    ImageIndex++;\r
-  } while (((Pcir->Indicator & 0x80) == 0x00) && ((RomOffset - (UINTN) Rom) < RomSize));\r
-\r
-  return retStatus;\r
-}\r
-\r
-\r