--- /dev/null
+/** @file\r
+\r
+Copyright (c) 2007, 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
+Module Name:\r
+\r
+ PlatformDriOverride.c\r
+\r
+Abstract:\r
+\r
+\r
+**/\r
+\r
+\r
+#include "PlatformDriOverride.h"\r
+\r
+EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL gPlatformDriverOverride = {\r
+ GetDriver,\r
+ GetDriverPath,\r
+ DriverLoaded\r
+};\r
+\r
+STATIC LIST_ENTRY mMappingDataBase = INITIALIZE_LIST_HEAD_VARIABLE (mMappingDataBase);\r
+STATIC BOOLEAN mEnvironmentVariableRead = FALSE;\r
+STATIC EFI_HANDLE mCallerImageHandle;\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+PlatformDriverOverrideEntry (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Platform Driver Override driver entry point, install the Platform Driver Override Protocol\r
+\r
+Arguments:\r
+ (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)\r
+\r
+Returns:\r
+ EFI_STATUS\r
+\r
+--*/\r
+{\r
+ mEnvironmentVariableRead = FALSE;\r
+ mCallerImageHandle = ImageHandle;\r
+ InitializeListHead (&mMappingDataBase);\r
+ return InstallPlatformDriverOverrideProtocol (&gPlatformDriverOverride);\r
+}\r
+\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
+STATIC\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
+ // 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 (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
+ InitializeListHead (&mMappingDataBase);\r
+ return EFI_NOT_FOUND;\r
+ }\r
+ }\r
+ //\r
+ // if the environment variable does not exist or the variable appears to be corrupt, 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() and DriverLoaded() APIs\r
+ makes those APIs very difficult to use, so not support.\r
+\r
+\r
+\r
+**/\r
+STATIC\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
+ For the use of the ControllerHandle parameter in the GetDriverPath() and DriverLoaded() APIs\r
+ makes those APIs very difficult to use, so not support.\r
+\r
+\r
+\r
+**/\r
+STATIC\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