]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/DxePcdLib/DxePcdLib.c
Removed MdePkg usage of ModuleName: in file headers
[mirror_edk2.git] / MdePkg / Library / DxePcdLib / DxePcdLib.c
index fe7ae4247c9045334e3ffc984526fbb4be2170ea..b79400b9072b889adedf13ec3343b12d08b942c6 100644 (file)
@@ -11,10 +11,26 @@ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
 \r
 \r
-Module Name: DxePcdLib.c\r
-\r
 **/\r
 \r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <PiDxe.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+#include <Protocol/Pcd.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/PcdLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+\r
+#include "DxePcdLibInternal.h"\r
+\r
 static PCD_PROTOCOL  *mPcd;\r
 \r
 /**\r
@@ -57,6 +73,8 @@ LibPcdSetSku (
   IN UINTN  SkuId\r
   )\r
 {\r
+  ASSERT (SkuId < 0x100);\r
+\r
   mPcd->SetSku (SkuId);\r
 \r
   return SkuId;\r
@@ -512,20 +530,18 @@ LibPcdSetPtr (
   )\r
 {\r
   EFI_STATUS Status;\r
-  UINTN      Size;\r
-  \r
-  ASSERT ((*SizeOfBuffer > 0) && Buffer == NULL);\r
 \r
-  Size = LibPcdGetSize (TokenNumber);\r
-  \r
-  if (*SizeOfBuffer > Size) {\r
-    *SizeOfBuffer = Size;\r
-    return NULL;\r
+  ASSERT (SizeOfBuffer != NULL);\r
+\r
+  if (*SizeOfBuffer > 0) {\r
+    ASSERT (Buffer != NULL);\r
   }\r
 \r
-  Status = mPcd->SetPtr (TokenNumber, *SizeOfBuffer, Buffer);\r
+  Status = mPcd->SetPtr (TokenNumber, SizeOfBuffer, Buffer);\r
 \r
-  ASSERT_EFI_ERROR (Status);\r
+  if (EFI_ERROR (Status)) {\r
+    return NULL;\r
+  }\r
 \r
   return Buffer;\r
 }\r
@@ -724,20 +740,20 @@ LibPcdSetExPtr (
   )\r
 {\r
   EFI_STATUS  Status;\r
-  UINTN       Size;\r
 \r
   ASSERT (Guid != NULL);\r
-  ASSERT (Buffer != NULL);\r
 \r
-  Size = LibPcdGetExSize (Guid, TokenNumber);\r
-  if (*SizeOfBuffer > Size) {\r
-    *SizeOfBuffer = Size;\r
-    return NULL;\r
+  ASSERT (SizeOfBuffer != NULL);\r
+\r
+  if (*SizeOfBuffer > 0) {\r
+    ASSERT (Buffer != NULL);\r
   }\r
 \r
-  Status = mPcd->SetPtrEx (Guid, TokenNumber, *SizeOfBuffer, Buffer);\r
+  Status = mPcd->SetPtrEx (Guid, TokenNumber, SizeOfBuffer, Buffer);\r
 \r
-  ASSERT_EFI_ERROR (Status);\r
+  if (EFI_ERROR (Status)) {\r
+    return NULL;\r
+  }\r
 \r
   return Buffer;\r
 }\r
@@ -806,7 +822,7 @@ LibPcdCallbackOnSet (
 \r
   ASSERT (NotificationFunction != NULL);\r
 \r
-  Status = mPcd->CallbackOnSet (TokenNumber, Guid, NotificationFunction);\r
+  Status = mPcd->CallbackOnSet (Guid, TokenNumber, NotificationFunction);\r
 \r
   ASSERT_EFI_ERROR (Status);\r
 \r
@@ -838,7 +854,7 @@ LibPcdCancelCallback (
 \r
   ASSERT (NotificationFunction != NULL);\r
     \r
-  Status = mPcd->CancelCallback (TokenNumber, Guid, NotificationFunction);\r
+  Status = mPcd->CancelCallback (Guid, TokenNumber, NotificationFunction);\r
 \r
   ASSERT_EFI_ERROR (Status);\r
 \r
@@ -898,7 +914,7 @@ LibPcdGetNextToken (
   @retval CONST GUID *  The next valid token namespace.\r
 \r
 **/\r
-CONST GUID*           \r
+GUID *           \r
 EFIAPI\r
 LibPcdGetNextTokenSpace (\r
   IN CONST GUID  *Guid\r
@@ -910,6 +926,55 @@ LibPcdGetNextTokenSpace (
 \r
   ASSERT_EFI_ERROR (Status);\r
 \r
-  return Guid;\r
+  return (GUID *) Guid;\r
 }\r
 \r
+\r
+/**\r
+  Sets the PCD entry specified by PatchVariable to the value specified by Buffer \r
+  and SizeOfValue.  Buffer is returned.  If SizeOfValue is greater than \r
+  MaximumDatumSize, then set SizeOfValue to MaximumDatumSize and return \r
+  NULL to indicate that the set operation was not actually performed.  \r
+  If SizeOfValue is set to MAX_ADDRESS, then SizeOfValue must be set to \r
+  MaximumDatumSize and NULL must be returned.\r
+  \r
+  If PatchVariable is NULL, then ASSERT().\r
+  If SizeOfValue is NULL, then ASSERT().\r
+  If SizeOfValue > 0 and Buffer is NULL, then ASSERT().\r
+\r
+  @param[in] PatchVariable      A pointer to the global variable in a module that is \r
+                                the target of the set operation.\r
+  @param[in] MaximumDatumSize   The maximum size allowed for the PCD entry specified by PatchVariable.\r
+  @param[in, out] SizeOfBuffer  A pointer to the size, in bytes, of Buffer.\r
+  @param[in] Buffer             A pointer to the buffer to used to set the target variable.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+LibPatchPcdSetPtr (\r
+  IN        VOID        *PatchVariable,\r
+  IN        UINTN       MaximumDatumSize,\r
+  IN OUT    UINTN       *SizeOfBuffer,\r
+  IN CONST  VOID        *Buffer\r
+  )\r
+{\r
+  ASSERT (PatchVariable != NULL);\r
+  ASSERT (SizeOfBuffer  != NULL);\r
+  \r
+  if (*SizeOfBuffer > 0) {\r
+    ASSERT (Buffer != NULL);\r
+  }\r
+\r
+  if ((*SizeOfBuffer > MaximumDatumSize) ||\r
+      (*SizeOfBuffer == MAX_ADDRESS)) {\r
+    *SizeOfBuffer = MaximumDatumSize;\r
+    return NULL;\r
+  }\r
+    \r
+  CopyMem (PatchVariable, Buffer, *SizeOfBuffer);\r
+  \r
+  return (VOID *) Buffer;\r
+}\r
+\r
+\r
+\r