]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h
MdeModulePkg: Deprecate EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
[mirror_edk2.git] / MdeModulePkg / Library / UefiBootManagerLib / InternalBm.h
index 8e8534dd4d472f075b441c687822f72e9a46b772..0224bd34a9ed92fbfc7e4bcdfe29bae91916d1f0 100644 (file)
@@ -1,7 +1,8 @@
 /** @file\r
   BDS library definition, include the file and data structure\r
 \r
-Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>\r
+(C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>\r
 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 +22,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <IndustryStandard/PeImage.h>\r
 #include <IndustryStandard/Atapi.h>\r
 #include <IndustryStandard/Scsi.h>\r
+#include <IndustryStandard/Nvme.h>\r
 \r
 #include <Protocol/PciRootBridgeIo.h>\r
 #include <Protocol/BlockIo.h>\r
@@ -37,12 +39,15 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Protocol/GraphicsOutput.h>\r
 #include <Protocol/UsbIo.h>\r
 #include <Protocol/DiskInfo.h>\r
+#include <Protocol/NvmExpressPassthru.h>\r
 #include <Protocol/IdeControllerInit.h>\r
 #include <Protocol/BootLogo.h>\r
 #include <Protocol/DriverHealth.h>\r
 #include <Protocol/FormBrowser2.h>\r
+#include <Protocol/VariableLock.h>\r
+#include <Protocol/RamDisk.h>\r
+#include <Protocol/DeferredImageLoad.h>\r
 \r
-#include <Guid/ZeroGuid.h>\r
 #include <Guid/MemoryTypeInformation.h>\r
 #include <Guid/FileInfo.h>\r
 #include <Guid/GlobalVariable.h>\r
@@ -90,7 +95,6 @@ typedef enum {
   BmMessageSataBoot,\r
   BmMessageUsbBoot,\r
   BmMessageScsiBoot,\r
-  BmMessageNetworkBoot,\r
   BmMiscBoot\r
 } BM_BOOT_TYPE;\r
 \r
@@ -100,12 +104,23 @@ CHAR16 *
   IN EFI_HANDLE          Handle\r
   );\r
 \r
-#define BM_OPTION_NAME_LEN                          sizeof ("SysPrep####")\r
+//\r
+// PlatformRecovery#### is the load option with the longest name\r
+//\r
+#define BM_OPTION_NAME_LEN                          sizeof ("PlatformRecovery####")\r
 extern CHAR16  *mBmLoadOptionName[];\r
 \r
+/**\r
+  Visitor function to be called by BmForEachVariable for each variable\r
+  in variable storage.\r
+\r
+  @param Name    Variable name.\r
+  @param Guid    Variable GUID.\r
+  @param Context The same context passed to BmForEachVariable.\r
+**/\r
 typedef\r
 VOID\r
-(*VARIABLE_VISITOR) (\r
+(*BM_VARIABLE_VISITOR) (\r
   CHAR16                *Name,\r
   EFI_GUID              *Guid,\r
   VOID                  *Context\r
@@ -118,11 +133,18 @@ VOID
   @param Context   The context passed to Visitor function.\r
 **/\r
 VOID\r
-ForEachVariable (\r
-  VARIABLE_VISITOR            Visitor,\r
+BmForEachVariable (\r
+  BM_VARIABLE_VISITOR         Visitor,\r
   VOID                        *Context\r
   );\r
 \r
+#define BM_BOOT_DESCRIPTION_ENTRY_SIGNATURE SIGNATURE_32 ('b', 'm', 'd', 'h')\r
+typedef struct {\r
+  UINT32                                    Signature;\r
+  LIST_ENTRY                                Link;\r
+  EFI_BOOT_MANAGER_BOOT_DESCRIPTION_HANDLER Handler;\r
+} BM_BOOT_DESCRIPTION_ENTRY;\r
+\r
 /**\r
   Repair all the controllers according to the Driver Health status queried.\r
 **/\r
@@ -145,28 +167,6 @@ typedef struct {
 \r
 #define BM_HOTKEY_FROM_LINK(a) CR (a, BM_HOTKEY, Link, BM_HOTKEY_SIGNATURE)\r
 \r
-/**\r
-  Get the image file buffer data and buffer size by its device path. \r
-\r
-  @param FilePath  On input, a pointer to an allocated buffer containing the device\r
-                   path of the file.\r
-                   On output the pointer could be NULL when the function fails to\r
-                   load the boot option, or could point to an allocated buffer containing\r
-                   the device path of the file.\r
-                   It could be updated by either short-form device path expanding,\r
-                   or default boot file path appending.\r
-                   Caller is responsible to free it when it's non-NULL.\r
-  @param FileSize  A pointer to the size of the file buffer.\r
-\r
-  @retval NULL   File is NULL, or FileSize is NULL. Or, the file can't be found.\r
-  @retval other  The file buffer. The caller is responsible to free the memory.\r
-**/\r
-VOID *\r
-BmLoadEfiBootOption (\r
-  IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath,\r
-  OUT    UINTN                    *FileSize\r
-  );\r
-\r
 /**\r
   Get the Option Number that wasn't used.\r
 \r
@@ -200,35 +200,19 @@ BmWriteBootToOsPerformanceData (
   IN VOID       *Context\r
   );\r
 \r
-\r
-/**\r
-  Get the headers (dos, image, optional header) from an image\r
-\r
-  @param  Device                SimpleFileSystem device handle\r
-  @param  FileName              File name for the image\r
-  @param  DosHeader             Pointer to dos header\r
-  @param  Hdr                   The buffer in which to return the PE32, PE32+, or TE header.\r
-\r
-  @retval EFI_SUCCESS           Successfully get the machine type.\r
-  @retval EFI_NOT_FOUND         The file is not found.\r
-  @retval EFI_LOAD_ERROR        File is not a valid image file.\r
-\r
-**/\r
-EFI_STATUS\r
-BmGetImageHeader (\r
-  IN  EFI_HANDLE                  Device,\r
-  IN  CHAR16                      *FileName,\r
-  OUT EFI_IMAGE_DOS_HEADER        *DosHeader,\r
-  OUT EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION   Hdr\r
-  );\r
-\r
 /**\r
   This routine adjust the memory information for different memory type and \r
-  save them into the variables for next boot.\r
+  save them into the variables for next boot. It resets the system when\r
+  memory information is updated and the current boot option belongs to\r
+  boot category instead of application category. It doesn't count the\r
+  reserved memory occupied by RAM Disk.\r
+\r
+  @param Boot               TRUE if current boot option belongs to boot\r
+                            category instead of application category.\r
 **/\r
 VOID\r
 BmSetMemoryTypeInformationVariable (\r
-  VOID\r
+  IN BOOLEAN                    Boot\r
   );\r
 \r
 /**\r
@@ -291,8 +275,7 @@ BmStopHotkeyService (
   @param  VendorGuid             A unique identifier for the vendor.\r
   @param  Attributes             Attributes bitmask to set for the variable.\r
   @param  DataSize               The size in bytes of the Data buffer. Unless the EFI_VARIABLE_APPEND_WRITE, \r
-                                 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, or \r
-                                 EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero \r
+                                 or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero\r
                                  causes the variable to be deleted. When the EFI_VARIABLE_APPEND_WRITE attribute is \r
                                  set, then a SetVariable() call with a DataSize of zero will not cause any change to \r
                                  the variable value (the timestamp associated with the variable may be updated however \r
@@ -310,9 +293,8 @@ BmStopHotkeyService (
   @retval EFI_DEVICE_ERROR       The variable could not be retrieved due to a hardware error.\r
   @retval EFI_WRITE_PROTECTED    The variable in question is read-only.\r
   @retval EFI_WRITE_PROTECTED    The variable in question cannot be deleted.\r
-  @retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS \r
-                                 or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS being set, but the AuthInfo \r
-                                 does NOT pass the validation check carried out by the firmware.\r
+  @retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS\r
+                                 being set, but the AuthInfo does NOT pass the validation check carried out by the firmware.\r
 \r
   @retval EFI_NOT_FOUND          The variable trying to be updated or deleted was not found.\r
 **/\r
@@ -325,42 +307,6 @@ BmSetVariableAndReportStatusCodeOnError (
   IN VOID       *Data\r
   );\r
 \r
-/**\r
-  Get the load option by its device path.\r
-\r
-  @param FilePath  The device path pointing to a load option.\r
-                   It could be a short-form device path.\r
-  @param FullPath  Return the full device path of the load option after\r
-                   short-form device path expanding.\r
-                   Caller is responsible to free it.\r
-  @param FileSize  Return the load option size.\r
-\r
-  @return The load option buffer. Caller is responsible to free the memory.\r
-**/\r
-VOID *\r
-BmGetLoadOptionBuffer (\r
-  IN  EFI_DEVICE_PATH_PROTOCOL          *FilePath,\r
-  OUT EFI_DEVICE_PATH_PROTOCOL          **FullPath,\r
-  OUT UINTN                             *FileSize\r
-  );\r
-\r
-/**\r
-  Return whether the PE header of the load option is valid or not.\r
-\r
-  @param[in] Type       The load option type.\r
-  @param[in] FileBuffer The PE file buffer of the load option.\r
-  @param[in] FileSize   The size of the load option file.\r
-\r
-  @retval TRUE  The PE header of the load option is valid.\r
-  @retval FALSE The PE header of the load option is not valid.\r
-**/\r
-BOOLEAN\r
-BmIsLoadOptionPeHeaderValid (\r
-  IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE Type,\r
-  IN VOID                              *FileBuffer,\r
-  IN UINTN                             FileSize\r
-  );\r
-\r
 /**\r
   Function compares a device path data structure to that of all the nodes of a\r
   second device path instance.\r
@@ -399,43 +345,144 @@ BmDelPartMatchInstance (
   IN     EFI_DEVICE_PATH_PROTOCOL  *Single\r
   );\r
 \r
+/**\r
+  Repair all the controllers according to the Driver Health status queried.\r
+**/\r
+VOID\r
+BmRepairAllControllers (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Print the device path info.\r
+\r
+  @param DevicePath           The device path need to print.\r
+**/\r
+VOID\r
+BmPrintDp (\r
+  EFI_DEVICE_PATH_PROTOCOL            *DevicePath\r
+  );\r
 \r
 /**\r
-  Return the index of the load option in the load option array.\r
+  Convert a single character to number.\r
+  It assumes the input Char is in the scope of L'0' ~ L'9' and L'A' ~ L'F'\r
 \r
-  The function consider two load options are equal when the \r
-  OptionType, Attributes, Description, FilePath and OptionalData are equal.\r
+  @param    Char   The input char which need to convert to int.\r
 \r
-  @param Key    Pointer to the load option to be found.\r
-  @param Array  Pointer to the array of load options to be found.\r
-  @param Count  Number of entries in the Array.\r
+  @return  The converted 8-bit number or (UINTN) -1 if conversion failed.\r
+**/\r
+UINTN\r
+BmCharToUint (\r
+  IN CHAR16                           Char\r
+  );\r
+\r
+/**\r
+  Return the boot description for the controller.\r
 \r
-  @retval -1          Key wasn't found in the Array.\r
-  @retval 0 ~ Count-1 The index of the Key in the Array.\r
+  @param Handle                Controller handle.\r
+\r
+  @return  The description string.\r
 **/\r
-INTN\r
-BmFindLoadOption (\r
-  IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *Key,\r
-  IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *Array,\r
-  IN UINTN                              Count\r
+CHAR16 *\r
+BmGetBootDescription (\r
+  IN EFI_HANDLE                  Handle\r
   );\r
 \r
 /**\r
-  Repair all the controllers according to the Driver Health status queried.\r
+  Enumerate all boot option descriptions and append " 2"/" 3"/... to make\r
+  unique description.\r
+\r
+  @param BootOptions            Array of boot options.\r
+  @param BootOptionCount        Count of boot options.\r
 **/\r
 VOID\r
-BmRepairAllControllers (\r
-  VOID\r
+BmMakeBootOptionDescriptionUnique (\r
+  EFI_BOOT_MANAGER_LOAD_OPTION         *BootOptions,\r
+  UINTN                                BootOptionCount\r
   );\r
 \r
 /**\r
-  Print the device path info.\r
+  Get the file buffer from the specified Load File instance.\r
 \r
-  @param DevicePath           The device path need to print.\r
+  @param LoadFileHandle The specified Load File instance.\r
+  @param FilePath       The file path which will pass to LoadFile().\r
+\r
+  @return  The full device path pointing to the load option buffer.\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+BmExpandLoadFile (\r
+  IN  EFI_HANDLE                      LoadFileHandle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL        *FilePath\r
+  );\r
+\r
+/**\r
+  Return the RAM Disk device path created by LoadFile.\r
+\r
+  @param FilePath  The source file path.\r
+\r
+  @return Callee-to-free RAM Disk device path\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+BmGetRamDiskDevicePath (\r
+  IN EFI_DEVICE_PATH_PROTOCOL *FilePath\r
+  );\r
+\r
+/**\r
+  Destroy the RAM Disk.\r
+\r
+  The destroy operation includes to call RamDisk.Unregister to\r
+  unregister the RAM DISK from RAM DISK driver, free the memory\r
+  allocated for the RAM Disk.\r
+\r
+  @param RamDiskDevicePath    RAM Disk device path.\r
 **/\r
 VOID\r
-BmPrintDp (\r
-  EFI_DEVICE_PATH_PROTOCOL            *DevicePath\r
+BmDestroyRamDisk (\r
+  IN EFI_DEVICE_PATH_PROTOCOL *RamDiskDevicePath\r
+  );\r
+\r
+/**\r
+  Get the next possible full path pointing to the load option.\r
+\r
+  @param FilePath  The device path pointing to a load option.\r
+                   It could be a short-form device path.\r
+  @param FullPath  The full path returned by the routine in last call.\r
+                   Set to NULL in first call.\r
+\r
+  @return The next possible full path pointing to the load option.\r
+          Caller is responsible to free the memory.\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+BmGetNextLoadOptionDevicePath (\r
+  IN  EFI_DEVICE_PATH_PROTOCOL          *FilePath,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL          *FullPath\r
   );\r
 \r
+/**\r
+  Return the next matched load option buffer.\r
+  The routine keeps calling BmGetNextLoadOptionDevicePath() until a valid\r
+  load option is read.\r
+\r
+  @param Type      The load option type.\r
+                   It's used to check whether the load option is valid.\r
+                   When it's LoadOptionTypeMax, the routine only guarantees\r
+                   the load option is a valid PE image but doesn't guarantee\r
+                   the PE's subsystem type is valid.\r
+  @param FilePath  The device path pointing to a load option.\r
+                   It could be a short-form device path.\r
+  @param FullPath  Return the next full device path of the load option after\r
+                   short-form device path expanding.\r
+                   Caller is responsible to free it.\r
+                   NULL to return the first matched full device path.\r
+  @param FileSize  Return the load option size.\r
+\r
+  @return The load option buffer. Caller is responsible to free the memory.\r
+**/\r
+VOID *\r
+BmGetNextLoadOptionBuffer (\r
+  IN  EFI_BOOT_MANAGER_LOAD_OPTION_TYPE Type,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL          *FilePath,\r
+  OUT EFI_DEVICE_PATH_PROTOCOL          **FullPath,\r
+  OUT UINTN                             *FileSize\r
+  );\r
 #endif // _INTERNAL_BM_H_\r