]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Code scrub EdkFvbServiceLib.
authorqhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 6 Nov 2008 08:29:42 +0000 (08:29 +0000)
committerqhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 6 Nov 2008 08:29:42 +0000 (08:29 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@6412 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Library/EdkFvbServiceLib/EdkFvbServiceLib.inf
MdeModulePkg/Library/EdkFvbServiceLib/Fvb.c
MdeModulePkg/Library/EdkFvbServiceLib/Fvb.h

index 886f2f49bdc8c57df224d8d8e448bf4f6e70ae58..9101fc38e23de468b18e03de51db698cdae9545b 100644 (file)
@@ -20,7 +20,7 @@
   FILE_GUID                      = bd4d540e-04b0-4b10-8fd5-4a7bb533cf67\r
   MODULE_TYPE                    = DXE_RUNTIME_DRIVER\r
   VERSION_STRING                 = 1.0\r
-  LIBRARY_CLASS                  = FvbServiceLib|DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION\r
+  LIBRARY_CLASS                  = FvbServiceLib|DXE_RUNTIME_DRIVER DXE_SMM_DRIVER\r
   EDK_RELEASE_VERSION            = 0x00020000\r
   EFI_SPECIFICATION_VERSION      = 0x00020000\r
 \r
   DebugLib\r
   BaseLib\r
   UefiLib\r
+  MemoryAllocationLib\r
 \r
 [Protocols]\r
   gEfiFirmwareVolumeBlockProtocolGuid           # PROTOCOL_NOTIFY SOMETIMES_CONSUMED\r
   gEfiFvbExtensionProtocolGuid                  # PROTOCOL ALWAYS_CONSUMED\r
-  gEfiFirmwareVolumeBlockProtocolGuid           # PROTOCOL ALWAYS_CONSUMED\r
+\r
 \r
index 65a2ac8c6fc085a00e0d77021bb8e8d5c9a686f6..6080b1c0c61bb419f52eeecfa7489d38d1b8be1e 100644 (file)
@@ -8,7 +8,6 @@
   were described in the HOB. We have to remember the handle so we can tell if\r
   the protocol has been reinstalled and it needs updateing.\r
 \r
-  If you are using any of these lib functions.you must first call FvbInitialize ().\r
 \r
 Copyright (c) 2006 - 2008, Intel Corporation\r
 All rights reserved. This program and the accompanying materials\r
@@ -24,6 +23,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include "Fvb.h"\r
 \r
+\r
 //\r
 // Event for Set Virtual Map Changed Event\r
 //\r
@@ -32,9 +32,9 @@ EFI_EVENT mSetVirtualMapChangedEvent = NULL;
 //\r
 // Lib will ASSERT if more FVB devices than this are added to the system.\r
 //\r
-FVB_ENTRY          *mFvbEntry;\r
-EFI_EVENT          mFvbRegistration;\r
-UINTN              mFvbCount;\r
+FVB_ENTRY          *mFvbEntry       = NULL;\r
+EFI_EVENT          mFvbRegistration = NULL;\r
+UINTN              mFvbCount        = 0;\r
 \r
 /**\r
   Check whether an address is runtime memory or not.\r
@@ -78,12 +78,8 @@ IsRuntimeMemory (
   // Enlarge space here, because we will allocate pool now.\r
   //\r
   MemoryMapSize += EFI_PAGE_SIZE;\r
-  Status = gBS->AllocatePool (\r
-                  EfiBootServicesData,\r
-                  MemoryMapSize,\r
-                  (VOID**)&MemoryMap\r
-                  );\r
-  ASSERT_EFI_ERROR (Status);\r
+  MemoryMap = AllocatePool (MemoryMapSize);\r
+  ASSERT (MemoryMap != NULL);\r
 \r
   //\r
   // Get System MemoryMap\r
@@ -108,7 +104,7 @@ IsRuntimeMemory (
       //\r
       // Found it\r
       //\r
-      if (MemoryMap->Attribute & EFI_MEMORY_RUNTIME) {\r
+      if ((MemoryMap->Attribute & EFI_MEMORY_RUNTIME) != 0) {\r
         IsRuntime = TRUE;\r
       }\r
       break;\r
@@ -116,17 +112,18 @@ IsRuntimeMemory (
     //\r
     // Get next item\r
     //\r
-    MemoryMap = (EFI_MEMORY_DESCRIPTOR *)((UINTN)MemoryMap + DescriptorSize);\r
+    MemoryMap = (EFI_MEMORY_DESCRIPTOR *)((UINTN) MemoryMap + DescriptorSize);\r
   }\r
 \r
   //\r
   // Done\r
   //\r
-  gBS->FreePool (MemoryMapPtr);\r
+  FreePool (MemoryMapPtr);\r
 \r
   return IsRuntime;\r
 }\r
 \r
+\r
 /**\r
   Update mFvbEntry. Add new entry, or update existing entry if Fvb protocol is\r
   reinstalled.\r
@@ -211,14 +208,11 @@ FvbNotificationEvent (
     }\r
 \r
     //\r
-    // Check the FVB can be accessed in RUNTIME, The FVBs in FVB handle list comes\r
-    // from two way:\r
-    // 1) Dxe Core. (FVB information is transferred from FV HOB).\r
-    // 2) FVB driver.\r
-    // The FVB produced Dxe core is used for discoverying DXE driver and dispatch. These\r
-    // FVBs can only be accessed in boot time.\r
-    // FVB driver will discovery all FV in FLASH and these FVBs can be accessed in runtime.\r
-    // The FVB itself produced by FVB driver is allocated in runtime memory. So we can\r
+    // Check the FVB can be accessed in RUNTIME, The FVBs in FVB handle list come from two ways:\r
+    // 1) Dxe Core. (FVB information is transferred from FV HOB). 2) FVB driver. The FVB produced\r
+    // Dxe core is used to discovery DXE driver and dispatch. These FVBs can only be accessed in\r
+    // boot time. FVB driver will discovery all FV in FLASH and these FVBs can be accessed in\r
+    // runtime. The FVB itself produced by FVB driver is allocated in runtime memory. So we can\r
     // determine the what FVB can be accessed in RUNTIME by judging whether FVB itself is allocated\r
     // in RUNTIME memory.\r
     //\r
@@ -241,13 +235,14 @@ FvbVirtualAddressChangeNotifyEvent (
   )\r
 {\r
   UINTN Index;\r
+\r
   if (mFvbEntry != NULL) {\r
     for (Index = 0; Index < MAX_FVB_COUNT; Index++) {\r
       if (!mFvbEntry[Index].IsRuntimeAccess) {\r
         continue;\r
       }\r
 \r
-      if (NULL != mFvbEntry[Index].Fvb) {\r
+      if (mFvbEntry[Index].Fvb != NULL) {\r
         EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->GetBlockSize);\r
         EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->GetPhysicalAddress);\r
         EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->GetAttributes);\r
@@ -258,7 +253,7 @@ FvbVirtualAddressChangeNotifyEvent (
         EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb);\r
       }\r
 \r
-      if (NULL != mFvbEntry[Index].FvbExtension) {\r
+      if (mFvbEntry[Index].FvbExtension != NULL) {\r
         EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].FvbExtension->EraseFvbCustomBlock);\r
         EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].FvbExtension);\r
       }\r
@@ -268,6 +263,7 @@ FvbVirtualAddressChangeNotifyEvent (
   }\r
 }\r
 \r
+\r
 /**\r
   Library constructor function entry.\r
 \r
@@ -284,21 +280,14 @@ FvbLibInitialize (
   IN EFI_SYSTEM_TABLE   *SystemTable\r
   )\r
 {\r
-  UINTN Status;\r
-  mFvbCount = 0;\r
-\r
-  Status = gBS->AllocatePool (\r
-                  EfiRuntimeServicesData,\r
-                  (UINTN) sizeof (FVB_ENTRY) * MAX_FVB_COUNT,\r
-                  (VOID *) &mFvbEntry\r
-                  );\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  ZeroMem (mFvbEntry, sizeof (FVB_ENTRY) * MAX_FVB_COUNT);\r
+  EFI_STATUS Status;\r
\r
+  mFvbEntry = AllocateRuntimeZeroPool (sizeof (FVB_ENTRY) * MAX_FVB_COUNT);\r
+  ASSERT (mFvbEntry != NULL);\r
 \r
+  //\r
+  // Register FvbNotificationEvent () notify function.\r
+  // \r
   EfiCreateProtocolNotifyEvent (\r
     &gEfiFirmwareVolumeBlockProtocolGuid,\r
     TPL_CALLBACK,\r
@@ -319,7 +308,7 @@ FvbLibInitialize (
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-  return EFI_SUCCESS;\r
+  return Status;\r
 }\r
 \r
 //\r
@@ -328,10 +317,6 @@ FvbLibInitialize (
 // The Instance translates into Fvb instance. The Fvb order defined by HOBs and\r
 // thus the sequence of FVB protocol addition define Instance.\r
 //\r
-// EfiFvbInitialize () must be called before any of the following functions\r
-// must be called.\r
-// =============================================================================\r
-//\r
 \r
 /**\r
   Reads specified number of bytes into a buffer from the specified block.\r
@@ -362,14 +347,18 @@ FvbLibInitialize (
   @param[out]     Buffer           Pointer to a caller allocated buffer that will be\r
                                    used to hold the data read.\r
 \r
-  @retval   EFI_SUCCESS                   The firmware volume was read successfully and contents are in Buffer.\r
-  @retval   EFI_BAD_BUFFER_SIZE    Read attempted across an LBA boundary.  On output, NumBytes contains the total number of bytes returned in Buffer.\r
+  @retval   EFI_SUCCESS            The firmware volume was read successfully and contents are in Buffer.\r
+  @retval   EFI_BAD_BUFFER_SIZE    Read attempted across an LBA boundary.  On output, NumBytes contains\r
+                                   the total number of bytes returned in Buffer.\r
   @retval   EFI_ACCESS_DENIED      The firmware volume is in the ReadDisabled state.\r
   @retval   EFI_DEVICE_ERROR       The block device is not functioning correctly and could not be read.\r
-  @retval   EFI_INVALID_PARAMETER  Invalid parameter, Instance is larger than the max FVB number. Lba index is larger than the last block of the firmware volume. Offset is larger than the block size.\r
+  @retval   EFI_INVALID_PARAMETER  Invalid parameter, Instance is larger than the max FVB number. Lba index\r
+                                   is larger than the last block of the firmware volume. Offset is larger\r
+                                   than the block size.\r
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 EfiFvbReadBlock (\r
   IN UINTN                                        Instance,\r
   IN EFI_LBA                                      Lba,\r
@@ -436,13 +425,14 @@ EfiFvbReadBlock (
   @retval EFI_SUCCESS           The firmware volume was written successfully.\r
   @retval EFI_BAD_BUFFER_SIZE   The write was attempted across an LBA boundary. \r
                                 On output, NumBytes contains the total number of bytes actually written.\r
-  @retval EFI_ACCESS_DENIED        The firmware volume is in the WriteDisabled state.\r
+  @retval EFI_ACCESS_DENIED     The firmware volume is in the WriteDisabled state.\r
   @retval EFI_DEVICE_ERROR      The block device is malfunctioning and could not be written.\r
   @retval EFI_INVALID_PARAMETER Invalid parameter, Instance is larger than the max FVB number. \r
                                 Lba index is larger than the last block of the firmware volume.\r
                                 Offset is larger than the block size.\r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 EfiFvbWriteBlock (\r
   IN UINTN                                        Instance,\r
   IN EFI_LBA                                      Lba,\r
@@ -464,6 +454,7 @@ EfiFvbWriteBlock (
   return mFvbEntry[Instance].Fvb->Write (mFvbEntry[Instance].Fvb, Lba, Offset, NumBytes, Buffer);\r
 }\r
 \r
+\r
 /**\r
   Erases and initializes a firmware volume block.\r
 \r
@@ -493,6 +484,7 @@ EfiFvbWriteBlock (
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 EfiFvbEraseBlock (\r
   IN UINTN                                Instance,\r
   IN EFI_LBA                              Lba\r
@@ -509,6 +501,7 @@ EfiFvbEraseBlock (
   return mFvbEntry[Instance].Fvb->EraseBlocks (mFvbEntry[Instance].Fvb, Lba, 1, EFI_LBA_LIST_TERMINATOR);\r
 }\r
 \r
+\r
 /**\r
   Retrieves the attributes and current settings of the specified block, \r
   returns resulting attributes in output parameter.\r
@@ -527,6 +520,7 @@ EfiFvbEraseBlock (
   @retval   EFI_INVALID_PARAMETER  Invalid parameter. Instance is larger than the max FVB number. \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 EfiFvbGetVolumeAttributes (\r
   IN UINTN                                Instance,\r
   OUT EFI_FVB_ATTRIBUTES_2                *Attributes\r
@@ -545,6 +539,7 @@ EfiFvbGetVolumeAttributes (
   return mFvbEntry[Instance].Fvb->GetAttributes (mFvbEntry[Instance].Fvb, Attributes);\r
 }\r
 \r
+\r
 /**\r
   Modify the attributes and current settings of the specified block\r
   according to the input parameter.\r
@@ -566,6 +561,7 @@ EfiFvbGetVolumeAttributes (
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 EfiFvbSetVolumeAttributes (\r
   IN     UINTN                                Instance,\r
   IN OUT EFI_FVB_ATTRIBUTES_2                 *Attributes\r
@@ -584,6 +580,7 @@ EfiFvbSetVolumeAttributes (
   return mFvbEntry[Instance].Fvb->SetAttributes (mFvbEntry[Instance].Fvb, Attributes);\r
 }\r
 \r
+\r
 /**\r
   Retrieves the physical address of the specified memory mapped FV.\r
 \r
@@ -603,6 +600,7 @@ EfiFvbSetVolumeAttributes (
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 EfiFvbGetPhysicalAddress (\r
   IN UINTN                                Instance,\r
   OUT EFI_PHYSICAL_ADDRESS                *BaseAddress\r
@@ -621,6 +619,7 @@ EfiFvbGetPhysicalAddress (
   return mFvbEntry[Instance].Fvb->GetPhysicalAddress (mFvbEntry[Instance].Fvb, BaseAddress);\r
 }\r
 \r
+\r
 /**\r
   Retrieve the block size of the specified fv.\r
   \r
@@ -630,7 +629,7 @@ EfiFvbGetPhysicalAddress (
   the last block of the firmware volume, this function return the status code\r
   EFI_INVALID_PARAMETER.\r
 \r
-  If BlockSize is NULL, then ASSERT().\r
+  If BlockSize  is NULL, then ASSERT().\r
   \r
   If NumOfBlocks  is NULL, then ASSERT().\r
 \r
@@ -648,6 +647,7 @@ EfiFvbGetPhysicalAddress (
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 EfiFvbGetBlockSize (\r
   IN UINTN                                        Instance,\r
   IN EFI_LBA                                      Lba,\r
@@ -669,6 +669,7 @@ EfiFvbGetBlockSize (
   return mFvbEntry[Instance].Fvb->GetBlockSize (mFvbEntry[Instance].Fvb, Lba, BlockSize, NumOfBlocks);\r
 }\r
 \r
+\r
 /**\r
   Erases and initializes a specified range of a firmware volume.\r
 \r
@@ -691,6 +692,7 @@ EfiFvbGetBlockSize (
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 EfiFvbEraseCustomBlockRange (\r
   IN UINTN                                Instance,\r
   IN EFI_LBA                              StartLba,\r
index 5d54fd18c92c84af8faf81d26d3f10fa065a121e..7d0a09c7e1f0cda46425a2c820e34d5010dfcf76 100644 (file)
@@ -31,6 +31,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/UefiRuntimeLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
 \r
 #define MAX_FVB_COUNT 16\r
 \r