]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatformDriOverride.c
Change directory name PlatformDriOverride to PlatformDriOverrideDxe.
[mirror_edk2.git] / MdeModulePkg / Universal / PlatformDriOverrideDxe / PlatformDriOverride.c
diff --git a/MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatformDriOverride.c b/MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatformDriOverride.c
new file mode 100644 (file)
index 0000000..64e9a4d
--- /dev/null
@@ -0,0 +1,212 @@
+/** @file\r
+\r
+Copyright (c) 2007 - 2009, 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
+http://opensource.org/licenses/bsd-license.php\r
+\r
+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
+**/\r
+\r
+#include <Uefi.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/PlatformDriverOverrideLib.h>\r
+#include <Protocol/PlatformDriverOverride.h>\r
+\r
+LIST_ENTRY      mMappingDataBase = INITIALIZE_LIST_HEAD_VARIABLE (mMappingDataBase);\r
+BOOLEAN         mEnvironmentVariableRead = FALSE;\r
+EFI_HANDLE      mCallerImageHandle = NULL;\r
+\r
+/**\r
+  Retrieves the image handle of the platform override driver for a controller in the system.\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  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
+\r
+  @retval EFI_SUCCESS            The driver override for ControllerHandle was\r
+                                 returned in DriverImageHandle.\r
+  @retval EFI_NOT_FOUND          A driver override for ControllerHandle was not\r
+                                 found.\r
+  @retval EFI_INVALID_PARAMETER  The handle specified by ControllerHandle is not a\r
+                                 valid handle. DriverImageHandle is not a handle\r
+                                 that was returned on a previous  call to\r
+                                 GetDriver().\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GetDriver (\r
+  IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL              *This,\r
+  IN     EFI_HANDLE                                     ControllerHandle,\r
+  IN OUT EFI_HANDLE                                     *DriverImageHandle\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  //\r
+  // Check that ControllerHandle is a valid handle\r
+  //\r
+  if (ControllerHandle == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Read the environment variable(s) that contain the override mappings from Controller Device Path to\r
+  // a set of Driver Device Paths, and  initialize in memory database of the overrides that map Controller\r
+  // Device Paths to an ordered set of Driver Device Paths and Driver Handles. This action is only performed\r
+  // once and finished in first call.\r
+  //\r
+  if (!mEnvironmentVariableRead) {\r
+    mEnvironmentVariableRead = TRUE;\r
+\r
+    Status = InitOverridesMapping (&mMappingDataBase);\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, just return not found\r
+  //\r
+  if (IsListEmpty (&mMappingDataBase)) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  return GetDriverFromMapping (\r
+            ControllerHandle,\r
+            DriverImageHandle,\r
+            &mMappingDataBase,\r
+            mCallerImageHandle\r
+            );\r
+}\r
+\r
+/**\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  DriverImagePath       On input, a pointer to the previous driver device path returned by\r
+                                GetDriverPath(). On output, a pointer to the next driver\r
+                                device path. Passing in a pointer to NULL, will return the first\r
+                                driver device path for ControllerHandle.\r
+  \r
+  @retval EFI_UNSUPPORTED\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GetDriverPath (\r
+  IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL              *This,\r
+  IN     EFI_HANDLE                                     ControllerHandle,\r
+  IN OUT EFI_DEVICE_PATH_PROTOCOL                       **DriverImagePath\r
+  )\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+\r
+/**\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_HANDLE                                     ControllerHandle,\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