]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/PlatformDriverOverride/PlatformDriOverrideDxe/PlatformDriOverride.c
Code Clean for Driver PlatformDriOverrideDxe and PlatOverMngr application. And Clean...
[mirror_edk2.git] / MdeModulePkg / Universal / PlatformDriverOverride / PlatformDriOverrideDxe / PlatformDriOverride.c
index fd3aee9ad03819fb38c4f62c5b9f152e9dd89d59..aef0f03d72271160c900e61ecf14d8b51315d5a6 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-Copyright (c) 2007, Intel Corporation\r
+Copyright (c) 2007 - 2008, Intel Corporation\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
@@ -9,52 +9,20 @@ http://opensource.org/licenses/bsd-license.php
 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
-Module Name:\r
-\r
-    PlatformDriOverride.c\r
-\r
-Abstract:\r
-\r
-\r
 **/\r
 \r
+#include <Uefi.h>\r
 \r
-#include "PlatformDriOverride.h"\r
-\r
-EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL gPlatformDriverOverride = {\r
-  GetDriver,\r
-  GetDriverPath,\r
-  DriverLoaded\r
-};\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/PlatDriOverLib.h>\r
+#include <Protocol/PlatformDriverOverride.h>\r
 \r
 LIST_ENTRY      mMappingDataBase = INITIALIZE_LIST_HEAD_VARIABLE (mMappingDataBase);\r
 BOOLEAN         mEnvironmentVariableRead = FALSE;\r
-EFI_HANDLE      mCallerImageHandle;\r
-\r
-/**\r
-  Platform Driver Override driver entry point, install the Platform Driver Override Protocol\r
-\r
-  @param  ImageHandle  ImageHandle of the loaded driver.\r
-  @param  SystemTable  Pointer to the EFI System Table.\r
-\r
-  @retval  EFI_SUCCESS               The DXE Driver, DXE Runtime Driver, DXE SMM Driver,\r
-                                     or UEFI Driver exited normally.\r
-  @retval  EFI_INCOMPATIBLE_VERSION  _gUefiDriverRevision is greater than SystemTable->Hdr.Revision.\r
-  @retval  Other                     Return value from ProcessModuleEntryPointList().\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-PlatformDriverOverrideEntry (\r
-  IN EFI_HANDLE        ImageHandle,\r
-  IN EFI_SYSTEM_TABLE  *SystemTable\r
-  )\r
-{\r
-  mEnvironmentVariableRead = FALSE;\r
-  mCallerImageHandle = ImageHandle;\r
-  InitializeListHead (&mMappingDataBase);\r
-  return InstallPlatformDriverOverrideProtocol (&gPlatformDriverOverride);\r
-}\r
-\r
+EFI_HANDLE      mCallerImageHandle = NULL;\r
 \r
 /**\r
   Retrieves the image handle of the platform override driver for a controller in the system.\r
@@ -82,12 +50,13 @@ PlatformDriverOverrideEntry (
 EFI_STATUS\r
 EFIAPI\r
 GetDriver (\r
-  IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL              * This,\r
+  IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL              *This,\r
   IN     EFI_HANDLE                                     ControllerHandle,\r
-  IN OUT EFI_HANDLE                                     * DriverImageHandle\r
+  IN OUT EFI_HANDLE                                     *DriverImageHandle\r
   )\r
 {\r
   EFI_STATUS  Status;\r
+\r
   //\r
   // Check that ControllerHandle is a valid handle\r
   //\r
@@ -105,59 +74,46 @@ GetDriver (
     mEnvironmentVariableRead = TRUE;\r
 \r
     Status = InitOverridesMapping (&mMappingDataBase);\r
-    if (Status == EFI_NOT_FOUND) {\r
-      InitializeListHead (&mMappingDataBase);\r
-      return EFI_NOT_FOUND;\r
-    } else if (Status == EFI_VOLUME_CORRUPTED){\r
-      DEBUG ((DEBUG_ERROR, "Platform Driver Override Variable is corrupt\n"));\r
-      //\r
-      // The environment variable(s) that contain the override mappings from Controller Device Path to\r
-      //  a set of Driver Device Paths is corrupted,  platform code can use LibDeleteOverridesVariables to\r
-      //  delete all orverride variables as a policy. Here can be IBV/OEM customized.\r
-      //\r
-\r
-      //LibDeleteOverridesVariables();\r
-      InitializeListHead (&mMappingDataBase);\r
-      return EFI_NOT_FOUND;\r
-    } else if (EFI_ERROR (Status)){\r
+    if (EFI_ERROR (Status)){\r
+      DEBUG ((DEBUG_ERROR, "The status to Get Platform Driver Override Variable is %r\n", Status));\r
       InitializeListHead (&mMappingDataBase);\r
       return EFI_NOT_FOUND;\r
     }\r
   }\r
+\r
   //\r
-  // if the environment variable does not exist or the variable appears to be corrupt, just return not found\r
+  // if the environment variable does not exist, just return not found\r
   //\r
   if (IsListEmpty (&mMappingDataBase)) {\r
     return EFI_NOT_FOUND;\r
   }\r
 \r
   return GetDriverFromMapping (\r
-            This,\r
             ControllerHandle,\r
             DriverImageHandle,\r
             &mMappingDataBase,\r
             mCallerImageHandle\r
             );\r
-\r
 }\r
 \r
-\r
 /**\r
-  For the use of the ControllerHandle parameter in the GetDriverPath()\r
-  But this API is very difficult to use, so not support.\r
-\r
-  @param  This                   A pointer to the\r
-                                 EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL instance.\r
-  @param  ControllerHandle       The device handle of the controller to check if a\r
-                                 driver override exists.\r
-  @param  DriverImagePath        The device path for this Image.\r
+  Retrieves the device path of the platform override driver for a controller in the system.\r
+  This driver doesn't support this API.\r
+\r
+  @param  This                  A pointer to the EFI_PLATFORM_DRIVER_OVERRIDE_\r
+                                PROTOCOL instance.                            \r
+  @param  ControllerHandle      The device handle of the controller to check if a driver override\r
+                                exists.                                                          \r
+  @param  DriverImageHandle     On input, a pointer to the previous driver image handle returned\r
+                                by GetDriverPath(). On output, a pointer to the next driver         \r
+                                device path.\r
   \r
   @retval EFI_UNSUPPORTED\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 GetDriverPath (\r
-  IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL              * This,\r
+  IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL              *This,\r
   IN     EFI_HANDLE                                     ControllerHandle,\r
   IN OUT EFI_DEVICE_PATH_PROTOCOL                       **DriverImagePath\r
   )\r
@@ -167,30 +123,89 @@ GetDriverPath (
 \r
 \r
 /**\r
-  For the use of the ControllerHandle parameter in the DriverLoaded()\r
-  But this API is very difficult to use, so not support.\r
-\r
-  @param  This                   A pointer to the\r
-                                 EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL instance.\r
-  @param  ControllerHandle       The device handle of the controller to check if a\r
-                                 driver override exists.\r
-  @param  DriverImagePath        The device path for this Image.\r
-  @param  DriverImageHandle      On input, a pointer to the previous driver image\r
-                                 handle returned by GetDriver().  On output, a\r
-                                 pointer to the next driver image handle. Passing\r
-                                 in a NULL,  will return the first driver image\r
-                                 handle for ControllerHandle.\r
+  Used to associate a driver image handle with a device path that was returned on a prior call to the\r
+  GetDriverPath() service. This driver image handle will then be available through the               \r
+  GetDriver() service. This driver doesn't support this API.\r
+\r
+  @param  This                  A pointer to the EFI_PLATFORM_DRIVER_OVERRIDE_\r
+                                PROTOCOL instance.                            \r
+  @param  ControllerHandle      The device handle of the controller.                                                             \r
+  @param  DriverImagePath       A pointer to the driver device path that was returned in a prior\r
+                                call to GetDriverPath().                                                                        \r
+  @param  DriverImageHandle     The driver image handle that was returned by LoadImage()\r
+                                when the driver specified by DriverImagePath was loaded \r
+                                into memory. \r
   \r
   @retval EFI_UNSUPPORTED\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 DriverLoaded (\r
-  IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL          * This,\r
+  IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL          *This,\r
   IN EFI_HANDLE                                     ControllerHandle,\r
-  IN EFI_DEVICE_PATH_PROTOCOL                       * DriverImagePath,\r
+  IN EFI_DEVICE_PATH_PROTOCOL                       *DriverImagePath,\r
   IN EFI_HANDLE                                     DriverImageHandle\r
   )\r
 {\r
   return EFI_UNSUPPORTED;\r
 }\r
+\r
+EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL mPlatformDriverOverride = {\r
+  GetDriver,\r
+  GetDriverPath,\r
+  DriverLoaded\r
+};\r
+\r
+/**\r
+  Platform Driver Override driver entry point, install the Platform Driver Override Protocol\r
+\r
+  @param  ImageHandle  ImageHandle of the loaded driver.\r
+  @param  SystemTable  Pointer to the EFI System Table.\r
+\r
+  @retval  EFI_SUCCESS               The DXE Driver, DXE Runtime Driver, DXE SMM Driver,\r
+                                     or UEFI Driver exited normally.\r
+  @retval  EFI_ALREADY_STARTED       A protocol instance has been installed. Not need install again.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+PlatformDriverOverrideEntry (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  EFI_HANDLE          Handle;\r
+  EFI_STATUS          Status;\r
+  VOID                *Instance;\r
+\r
+  mCallerImageHandle = ImageHandle;\r
+\r
+  //\r
+  // According to UEFI spec, there can be at most a single instance\r
+  // in the system of the EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL.\r
+  // So here we check the existence.\r
+  //\r
+  Status = gBS->LocateProtocol (\r
+                  &gEfiPlatformDriverOverrideProtocolGuid,\r
+                  NULL,\r
+                  &Instance\r
+                  );\r
+  //\r
+  // If there was no error, assume there is an installation and return error\r
+  //\r
+  if (!EFI_ERROR (Status)) {\r
+    return EFI_ALREADY_STARTED;\r
+  }\r
+\r
+  //\r
+  // Install platform driver override protocol\r
+  //\r
+  Handle = NULL;\r
+  Status = gBS->InstallProtocolInterface (\r
+                  &Handle,\r
+                  &gEfiPlatformDriverOverrideProtocolGuid,\r
+                  EFI_NATIVE_INTERFACE,\r
+                  &mPlatformDriverOverride\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+  return EFI_SUCCESS;\r
+}\r