]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/Library/PlatformBdsLib/BdsPlatform.c
Update the copyright notice format
[mirror_edk2.git] / OvmfPkg / Library / PlatformBdsLib / BdsPlatform.c
index 71be1dbefe3aa09ff4edf8132f37c979da1b8c2f..a2a8f35a7361ee253a73d79b0d76d5e324acc9ef 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Platform BDS customizations.\r
 \r
-  Copyright (c) 2004 - 2008, Intel Corporation. <BR>\r
+  Copyright (c) 2004 - 2009, Intel Corporation. <BR>\r
   All rights reserved. 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
@@ -21,6 +21,8 @@
 \r
 VOID          *mEfiDevPathNotifyReg;\r
 EFI_EVENT     mEfiDevPathEvent;\r
+VOID          *mEmuVariableEventReg;\r
+EFI_EVENT     mEmuVariableEvent;\r
 BOOLEAN       mDetectVgaOnly;\r
 \r
 \r
@@ -513,7 +515,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 +533,7 @@ VisitAllPciInstances (
   return VisitAllInstancesOfProtocol (\r
            &gEfiPciIoProtocolGuid,\r
            VisitingAPciInstance,\r
-           (VOID*) CallBackFunction\r
+           (VOID*)(UINTN) CallBackFunction\r
            );\r
 }\r
 \r
@@ -549,6 +551,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 +669,6 @@ Returns:
   //\r
   // Connect RootBridge\r
   //\r
-  ConnectRootBridge ();\r
-\r
   VarConout = BdsLibGetVariableAndSize (\r
                 VarConsoleOut,\r
                 &gEfiGlobalVariableGuid,\r
@@ -772,6 +773,120 @@ PciInitialization (
 }\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
+    DEBUG((\r
+      EFI_D_INFO,\r
+      "Found Mass Storage device: %s\n",\r
+      DevPathStr\r
+      ));\r
+    FreePool(DevPathStr);\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
 VOID\r
 PlatformBdsConnectSequence (\r
   VOID\r
@@ -950,6 +1065,14 @@ Returns:
 \r
   DEBUG ((EFI_D_INFO, "PlatformBdsPolicyBehavior\n"));\r
 \r
+  ConnectRootBridge ();\r
+\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
   // Init the time out value\r
   //\r