]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Include/Library/PlatDriOverLib.h
Port PlatformDriOverrideDxe into R9.
[mirror_edk2.git] / MdeModulePkg / Include / Library / PlatDriOverLib.h
diff --git a/MdeModulePkg/Include/Library/PlatDriOverLib.h b/MdeModulePkg/Include/Library/PlatDriOverLib.h
new file mode 100644 (file)
index 0000000..8e6ab17
--- /dev/null
@@ -0,0 +1,255 @@
+/** @file
+
+Copyright (c) 2007, Intel Corporation
+All rights reserved. This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution.  The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+Module Name:
+
+    PlatDriOverLib.h
+
+Abstract:
+
+
+**/
+
+#ifndef _PLAT_DRI_OVER_LIB_H_
+#define _PLAT_DRI_OVER_LIB_H_
+
+#include <PiDxe.h>
+#include <Protocol/PlatformDriverOverride.h>
+#include <Protocol/DevicePath.h>
+#include <Library/BaseLib.h>
+
+#include <VariableFormat.h>
+
+/**\r
+  Install the Platform Driver Override Protocol, and ensure there is only one Platform Driver Override Protocol\r
+  in the system.\r
+\r
+  @param  gPlatformDriverOverride  PlatformDriverOverride protocol interface which\r
+                                   needs to be installed\r
+\r
+  @retval EFI_ALREADY_STARTED      There has been a Platform Driver Override\r
+                                   Protocol in the system, cannot install it again.\r
+  @retval Other                    Returned by InstallProtocolInterface\r
+\r
+**/
+EFI_STATUS
+EFIAPI
+InstallPlatformDriverOverrideProtocol (
+  EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL *gPlatformDriverOverride
+  );
+
+/**\r
+  Free all the mapping database memory resource and initialize the mapping list entry\r
+\r
+  @param  MappingDataBase          Mapping database list entry pointer\r
+\r
+  @retval EFI_INVALID_PARAMETER    mapping database list entry is NULL\r
+  @retval EFI_SUCCESS              Free success\r
+\r
+**/
+EFI_STATUS
+EFIAPI
+FreeMappingDatabase (
+  IN  OUT  LIST_ENTRY            *MappingDataBase
+  );
+
+/**\r
+  Read the environment variable(s) that contain the override mappings from Controller Device Path to\r
+  a set of Driver Device Paths, and create the mapping database in memory with those variable info.\r
+  VariableLayout{\r
+  //\r
+  // NotEnd indicate whether the variable is the last one, and has no subsequent variable need to load.\r
+  // Each variable has MaximumVariableSize limitation, so  we maybe need multi variables to store\r
+  // large mapping infos.\r
+  // The variable(s) name rule is PlatDriOver, PlatDriOver1, PlatDriOver2, ....\r
+  //\r
+  UINT32                         NotEnd;\r
+  //\r
+  // The entry which contains the mapping that Controller Device Path to a set of Driver Device Paths\r
+  // There are often multi mapping entries in a variable.\r
+  //\r
+  UINT32                         SIGNATURE;            //EFI_SIGNATURE_32('p','d','o','i')\r
+  UINT32                         DriverNum;\r
+  EFI_DEVICE_PATH_PROTOCOL       ControllerDevicePath[];\r
+  EFI_DEVICE_PATH_PROTOCOL       DriverDevicePath[];\r
+  EFI_DEVICE_PATH_PROTOCOL       DriverDevicePath[];\r
+  EFI_DEVICE_PATH_PROTOCOL       DriverDevicePath[];\r
+  ......\r
+  UINT32                         SIGNATURE;\r
+  UINT32                         DriverNum;\r
+  EFI_DEVICE_PATH_PROTOCOL       ControllerDevicePath[];\r
+  EFI_DEVICE_PATH_PROTOCOL       DriverDevicePath[];\r
+  EFI_DEVICE_PATH_PROTOCOL       DriverDevicePath[];\r
+  EFI_DEVICE_PATH_PROTOCOL       DriverDevicePath[];\r
+  ......\r
+  }\r
+  typedef struct _PLATFORM_OVERRIDE_ITEM{\r
+  UINTN                          Signature;                  //EFI_SIGNATURE_32('p','d','o','i')\r
+  LIST_ENTRY                     Link;\r
+  UINT32                         DriverInfoNum;\r
+  EFI_DEVICE_PATH_PROTOCOL       *ControllerDevicePath;\r
+  LIST_ENTRY                     DriverInfoList;         //DRIVER_IMAGE_INFO List\r
+  } PLATFORM_OVERRIDE_ITEM;\r
+  typedef struct _DRIVER_IMAGE_INFO{\r
+  UINTN                          Signature;                  //EFI_SIGNATURE_32('p','d','i','i')\r
+  LIST_ENTRY                     Link;\r
+  EFI_HANDLE                     ImageHandle;\r
+  EFI_DEVICE_PATH_PROTOCOL       *DriverImagePath;\r
+  BOOLEAN                        UnLoadable;\r
+  BOOLEAN                        UnStartable;\r
+  } DRIVER_IMAGE_INFO;\r
+\r
+  @param  MappingDataBase          Mapping database list entry pointer\r
+\r
+  @retval EFI_INVALID_PARAMETER    MappingDataBase pointer is null\r
+  @retval EFI_NOT_FOUND            Cannot find the 'PlatDriOver' NV variable\r
+  @retval EFI_VOLUME_CORRUPTED     The found NV variable is corrupted\r
+  @retval EFI_SUCCESS              Create the mapping database in memory\r
+                                   successfully\r
+\r
+**/
+EFI_STATUS
+EFIAPI
+InitOverridesMapping (
+  OUT  LIST_ENTRY            *MappingDataBase
+  );
+
+/**\r
+  Save the memory mapping database into NV environment variable(s)\r
+\r
+  @param  MappingDataBase          Mapping database list entry pointer\r
+\r
+  @retval EFI_INVALID_PARAMETER    MappingDataBase pointer is null\r
+  @retval EFI_SUCCESS              Save memory mapping database successfully\r
+\r
+**/
+EFI_STATUS
+EFIAPI
+SaveOverridesMapping (
+  IN  LIST_ENTRY              *MappingDataBase
+  );
+
+/**\r
+  Retrieves the image handle of the platform override driver for a controller in the system from the memory mapping database.\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\r
+                                   a driver override exists.\r
+  @param  DriverImageHandle        On output, a pointer to the next driver handle.\r
+                                   Passing in a pointer to NULL, will return the\r
+                                   first driver handle for ControllerHandle.\r
+  @param  MappingDataBase          MappingDataBase - Mapping database list entry\r
+                                   pointer\r
+  @param  CallerImageHandle        The caller driver's image handle, for\r
+                                   UpdateFvFileDevicePath use.\r
+\r
+  @retval EFI_INVALID_PARAMETER    The handle specified by ControllerHandle is not\r
+                                   a valid handle.  Or DriverImagePath is not a\r
+                                   device path that was returned on a previous call\r
+                                   to GetDriverPath().\r
+  @retval EFI_NOT_FOUND            A driver override for ControllerHandle was not\r
+                                   found.\r
+  @retval EFI_UNSUPPORTED          The operation is not supported.\r
+  @retval EFI_SUCCESS              The driver override for ControllerHandle was\r
+                                   returned in DriverImagePath.\r
+\r
+**/
+EFI_STATUS
+EFIAPI
+GetDriverFromMapping (
+  IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL              * This,
+  IN     EFI_HANDLE                                     ControllerHandle,
+  IN OUT EFI_HANDLE                                     * DriverImageHandle,
+  IN     LIST_ENTRY                                     * MappingDataBase,
+  IN     EFI_HANDLE                                     CallerImageHandle
+  );
+
+EFI_STATUS
+EFIAPI
+DeleteOverridesVariables (
+  VOID
+  );
+
+/**\r
+  Check mapping database whether already has the  mapping info which\r
+  records the input Controller to input DriverImage.\r
+  If has, the controller's total override driver number and input DriverImage's order number is return.\r
+\r
+  @param  ControllerDevicePath     The controller device path need to add a\r
+                                   override driver image item\r
+  @param  DriverImageDevicePath    The driver image device path need to be insert\r
+  @param  MappingDataBase          Mapping database list entry pointer\r
+  @param  DriverInfoNum            the controller's total override driver number\r
+  @param  DriverImageNO            The inserted order number\r
+\r
+  @return EFI_INVALID_PARAMETER\r
+  @return EFI_NOT_FOUND\r
+  @return EFI_SUCCESS\r
+\r
+**/
+EFI_STATUS
+EFIAPI
+CheckMapping (
+  IN     EFI_DEVICE_PATH_PROTOCOL                       *ControllerDevicePath,
+  IN     EFI_DEVICE_PATH_PROTOCOL                       *DriverImageDevicePath,
+  IN     LIST_ENTRY                                     * MappingDataBase,
+  OUT    UINT32                                         *DriverInfoNum,
+  OUT    UINT32                                         *DriverImageNO
+  );
+
+/**\r
+  Insert a driver image as a controller's override driver into the mapping database.\r
+  The driver image's order number is indicated by DriverImageNO.\r
+\r
+  @param  ControllerDevicePath     The controller device path need to add a\r
+                                   override driver image item\r
+  @param  DriverImageDevicePath    The driver image device path need to be insert\r
+  @param  MappingDataBase          Mapping database list entry pointer\r
+  @param  DriverImageNO            The inserted order number\r
+\r
+  @return EFI_INVALID_PARAMETER\r
+  @return EFI_ALREADY_STARTED\r
+  @return EFI_SUCCESS\r
+\r
+**/
+EFI_STATUS
+EFIAPI
+InsertDriverImage (
+  IN     EFI_DEVICE_PATH_PROTOCOL                       *ControllerDevicePath,
+  IN     EFI_DEVICE_PATH_PROTOCOL                       *DriverImageDevicePath,
+  IN     LIST_ENTRY                                     *MappingDataBase,
+  IN     UINT32                                         DriverImageNO
+  );
+
+/**\r
+  Delete a controller's override driver from the mapping database.\r
+\r
+  @param  ControllerDevicePath     The controller device path need to add a\r
+                                   override driver image item\r
+  @param  DriverImageDevicePath    The driver image device path need to be insert\r
+  @param  MappingDataBase          Mapping database list entry pointer\r
+  @param  DriverImageNO            The inserted order number\r
+\r
+  @return EFI_INVALID_PARAMETER\r
+  @return EFI_NOT_FOUND\r
+  @return EFI_SUCCESS\r
+\r
+**/
+EFI_STATUS
+EFIAPI
+DeleteDriverImage (
+  IN     EFI_DEVICE_PATH_PROTOCOL                       *ControllerDevicePath,
+  IN     EFI_DEVICE_PATH_PROTOCOL                       *DriverImageDevicePath,
+  IN     LIST_ENTRY                                     *MappingDataBase
+  );
+
+#endif