]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/Bds: Allocate reserved memory for RAM Disk boot media
authorNi, Ruiyu <ruiyu.ni@intel.com>
Thu, 31 Mar 2016 02:37:18 +0000 (10:37 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Wed, 6 Apr 2016 05:27:09 +0000 (13:27 +0800)
Use reserved memory to hold the buffer for the RAM disk to
follow the ACPI spec requirement.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Siyuan Fu <siyuan.fu@intel.com>
Reviewed-by: Samer El-Haj-Mahmoud <elhaj@hpe.com>
MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h

index f6c68458abb11f3de8fcd34917167962fdf750d6..a582b905985d5d1b1badad5aaff0d6346a7bd409 100644 (file)
@@ -688,7 +688,6 @@ BmExpandUriDevicePath (
   UINTN                           Index;\r
   UINTN                           HandleCount;\r
   EFI_HANDLE                      *Handles;\r
-  EFI_LOAD_FILE_PROTOCOL          *LoadFile;\r
   VOID                            *FileBuffer;\r
 \r
   EfiBootManagerConnectAll ();\r
@@ -698,37 +697,10 @@ BmExpandUriDevicePath (
     Handles = NULL;\r
   }\r
 \r
-  FileBuffer = NULL;\r
-\r
   for (Index = 0; Index < HandleCount; Index++) {\r
-    Status = gBS->HandleProtocol (Handles[Index], &gEfiLoadFileProtocolGuid, (VOID *) &LoadFile);\r
-    ASSERT_EFI_ERROR (Status);\r
-\r
-    FileBuffer = NULL;\r
-    Status = LoadFile->LoadFile (LoadFile, FilePath, TRUE, FileSize, FileBuffer);\r
-    if (Status == EFI_BUFFER_TOO_SMALL) {\r
-      FileBuffer = AllocatePool (*FileSize);\r
-      if (FileBuffer == NULL) {\r
-        break;\r
-      }\r
-      Status = LoadFile->LoadFile (LoadFile, FilePath, TRUE, FileSize, FileBuffer);\r
-    }\r
-\r
-    if (!EFI_ERROR (Status)) {\r
-      //\r
-      // LoadFile() returns a file buffer mapping to a file system.\r
-      //\r
-      if (Status == EFI_WARN_FILE_SYSTEM) {\r
-        return BmGetFileBufferFromLoadFileFileSystem (Handles[Index], FullPath, FileSize);\r
-      }\r
-\r
-      ASSERT (Status == EFI_SUCCESS);\r
-      *FullPath = DuplicateDevicePath (DevicePathFromHandle (Handles[Index]));\r
-      break;\r
-    }\r
-\r
+    FileBuffer = BmGetFileBufferFromLoadFile (Handles[Index], FilePath, FullPath, FileSize);\r
     if (FileBuffer != NULL) {\r
-      FreePool (FileBuffer);\r
+      break;\r
     }\r
   }\r
 \r
@@ -1127,7 +1099,7 @@ BmMatchHttpBootDevicePath (
   @return  The load option buffer.\r
 **/\r
 VOID *\r
-BmGetFileBufferFromLoadFileFileSystem (\r
+BmGetFileBufferFromLoadFileSystem (\r
   IN  EFI_HANDLE                      LoadFileHandle,\r
   OUT EFI_DEVICE_PATH_PROTOCOL        **FullPath,\r
   OUT UINTN                           *FileSize\r
@@ -1175,8 +1147,78 @@ BmGetFileBufferFromLoadFileFileSystem (
   }\r
 }\r
 \r
+\r
 /**\r
-  Get the file buffer from Load File instance.\r
+  Get the file buffer from the specified Load File instance.\r
+\r
+  @param LoadFileHandle The specified Load File instance.\r
+  @param FilePath       The file path which will pass to LoadFile().\r
+  @param FullPath       Return the full device path pointing to the load option.\r
+  @param FileSize       Return the size of the load option.\r
+\r
+  @return  The load option buffer or NULL if fails.\r
+**/\r
+VOID *\r
+BmGetFileBufferFromLoadFile (\r
+  EFI_HANDLE                          LoadFileHandle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL        *FilePath,\r
+  OUT EFI_DEVICE_PATH_PROTOCOL        **FullPath,\r
+  OUT UINTN                           *FileSize\r
+  )\r
+{\r
+  EFI_STATUS                          Status;\r
+  EFI_LOAD_FILE_PROTOCOL              *LoadFile;\r
+  VOID                                *FileBuffer;\r
+  BOOLEAN                             LoadFileSystem;\r
+  UINTN                               BufferSize;\r
+\r
+  *FileSize = 0;\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  LoadFileHandle,\r
+                  &gEfiLoadFileProtocolGuid,\r
+                  (VOID **) &LoadFile,\r
+                  gImageHandle,\r
+                  NULL,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  FileBuffer = NULL;\r
+  BufferSize = 0;\r
+  Status = LoadFile->LoadFile (LoadFile, FilePath, TRUE, &BufferSize, FileBuffer);\r
+  if ((Status != EFI_WARN_FILE_SYSTEM) && (Status != EFI_BUFFER_TOO_SMALL)) {\r
+    return NULL;\r
+  }\r
+\r
+  LoadFileSystem = (BOOLEAN) (Status == EFI_WARN_FILE_SYSTEM);\r
+  FileBuffer = LoadFileSystem ? AllocateReservedPages (EFI_SIZE_TO_PAGES (BufferSize)) : AllocatePool (BufferSize);\r
+  if (FileBuffer == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  Status = LoadFile->LoadFile (LoadFile, FilePath, TRUE, &BufferSize, FileBuffer);\r
+  if (EFI_ERROR (Status)) {\r
+    if (LoadFileSystem) {\r
+      FreePages (FileBuffer, EFI_SIZE_TO_PAGES (BufferSize));\r
+    } else {\r
+      FreePool (FileBuffer);\r
+    }\r
+    return NULL;\r
+  }\r
+\r
+  if (LoadFileSystem) {\r
+    FileBuffer = BmGetFileBufferFromLoadFileSystem (LoadFileHandle, FullPath, FileSize);\r
+  } else {\r
+    *FileSize = BufferSize;\r
+    *FullPath = DuplicateDevicePath (DevicePathFromHandle (LoadFileHandle));\r
+  }\r
+\r
+  return FileBuffer;\r
+}\r
+\r
+/**\r
+  Get the file buffer from all the Load File instances.\r
 \r
   @param FilePath    The media device path pointing to a LoadFile instance.\r
   @param FullPath    Return the full device path pointing to the load option.\r
@@ -1185,7 +1227,7 @@ BmGetFileBufferFromLoadFileFileSystem (
   @return  The load option buffer.\r
 **/\r
 VOID *\r
-BmGetFileBufferFromLoadFile (\r
+BmGetFileBufferFromLoadFiles (\r
   IN  EFI_DEVICE_PATH_PROTOCOL        *FilePath,\r
   OUT EFI_DEVICE_PATH_PROTOCOL        **FullPath,\r
   OUT UINTN                           *FileSize\r
@@ -1193,13 +1235,10 @@ BmGetFileBufferFromLoadFile (
 {\r
   EFI_STATUS                      Status;\r
   EFI_HANDLE                      Handle;\r
-  VOID                            *FileBuffer;\r
   EFI_HANDLE                      *Handles;\r
   UINTN                           HandleCount;\r
   UINTN                           Index;\r
   EFI_DEVICE_PATH_PROTOCOL        *Node;\r
-  EFI_LOAD_FILE_PROTOCOL          *LoadFile;\r
-  UINTN                           BufferSize;\r
 \r
   //\r
   // Get file buffer from load file instance.\r
@@ -1244,41 +1283,7 @@ BmGetFileBufferFromLoadFile (
     return NULL;\r
   }\r
 \r
-  Status = gBS->HandleProtocol (Handle, &gEfiLoadFileProtocolGuid, (VOID **) &LoadFile);\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
-  BufferSize = 0;\r
-  FileBuffer = NULL;\r
-  Status = LoadFile->LoadFile (LoadFile, FilePath, TRUE, &BufferSize, FileBuffer);\r
-  if (Status == EFI_BUFFER_TOO_SMALL) {\r
-    FileBuffer = AllocatePool (BufferSize);\r
-    if (FileBuffer != NULL) {\r
-      Status = EFI_SUCCESS;\r
-    }\r
-  }\r
-\r
-  if (!EFI_ERROR (Status)) {\r
-    Status = LoadFile->LoadFile (LoadFile, FilePath, TRUE, &BufferSize, FileBuffer);\r
-  }\r
-\r
-  if (!EFI_ERROR (Status)) {\r
-    //\r
-    // LoadFile() returns a file buffer mapping to a file system.\r
-    //\r
-    if (Status == EFI_WARN_FILE_SYSTEM) {\r
-      return BmGetFileBufferFromLoadFileFileSystem (Handle, FullPath, FileSize);\r
-    }\r
-\r
-    ASSERT (Status == EFI_SUCCESS);\r
-    //\r
-    // LoadFile () may cause the device path of the Handle be updated.\r
-    //\r
-    *FullPath = DuplicateDevicePath (DevicePathFromHandle (Handle));\r
-    *FileSize = BufferSize;\r
-    return FileBuffer;\r
-  } else {\r
-    return NULL;\r
-  }\r
+  return BmGetFileBufferFromLoadFile (Handle, FilePath, FullPath, FileSize);\r
 }\r
 \r
 /**\r
@@ -1394,7 +1399,7 @@ BmGetLoadOptionBuffer (
     return FileBuffer;\r
   }\r
 \r
-  return BmGetFileBufferFromLoadFile (FilePath, FullPath, FileSize);\r
+  return BmGetFileBufferFromLoadFiles (FilePath, FullPath, FileSize);\r
 }\r
 \r
 /**\r
index b261d769d24eb9baab5a96135db39c185ca1aaeb..7b6252a4793d56cf7c81189f703412fed740c2b6 100644 (file)
@@ -410,23 +410,6 @@ BmCharToUint (
   IN CHAR16                           Char\r
   );\r
 \r
-\r
-/**\r
-  Get the file buffer from the file system produced by Load File instance.\r
-\r
-  @param LoadFileHandle The handle of LoadFile instance.\r
-  @param FullPath       Return the full device path pointing to the load option.\r
-  @param FileSize       Return the size of the load option.\r
-\r
-  @return  The load option buffer.\r
-**/\r
-VOID *\r
-BmGetFileBufferFromLoadFileFileSystem (\r
-  IN  EFI_HANDLE                      LoadFileHandle,\r
-  OUT EFI_DEVICE_PATH_PROTOCOL        **FullPath,\r
-  OUT UINTN                           *FileSize\r
-  );\r
-\r
 /**\r
   Return the boot description for the controller.\r
 \r
@@ -451,4 +434,22 @@ BmMakeBootOptionDescriptionUnique (
   EFI_BOOT_MANAGER_LOAD_OPTION         *BootOptions,\r
   UINTN                                BootOptionCount\r
   );\r
+\r
+/**\r
+  Get the file buffer from the specified Load File instance.\r
+\r
+  @param LoadFileHandle The specified Load File instance.\r
+  @param FilePath       The file path which will pass to LoadFile().\r
+  @param FullPath       Return the full device path pointing to the load option.\r
+  @param FileSize       Return the size of the load option.\r
+\r
+  @return  The load option buffer or NULL if fails.\r
+**/\r
+VOID *\r
+BmGetFileBufferFromLoadFile (\r
+  EFI_HANDLE                          LoadFileHandle,\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