Refine some internal functions of PCD Driver.
[mirror_edk2.git] / EdkModulePkg / Universal / PCD / Dxe / Service.c
index 53d9621e8cd0809b5641f5d4d6579dd7ed72e19d..e1aded74f99cbed9993d58152675f07fc07f062b 100644 (file)
@@ -27,12 +27,15 @@ PCD_DATABASE * mPcdDatabase;
 LIST_ENTRY mCallbackFnTable[PCD_TOTAL_TOKEN_NUMBER];\r
 \r
 VOID *\r
-GetWorkerByLocalTokenNumber (\r
-  UINT32      LocalTokenNumber,\r
-  BOOLEAN     IsPeiDb,\r
-  UINTN       Size\r
-  ) \r
+GetWorker (\r
+  PCD_TOKEN_NUMBER  TokenNumber,\r
+  UINTN             GetSize\r
+  )\r
 {\r
+  UINT32              *LocalTokenNumberTable;\r
+  UINT16              *SizeTable;\r
+  BOOLEAN             IsPeiDb;\r
+  UINTN               Size;\r
   UINT32              Offset;\r
   EFI_GUID            *GuidTable;\r
   UINT16              *StringTable;\r
@@ -45,7 +48,28 @@ GetWorkerByLocalTokenNumber (
   VPD_HEAD            *VpdHead;\r
   UINT8               *PcdDb;\r
   UINT16              StringTableIdx;      \r
+  UINT32              LocalTokenNumber;\r
+\r
+\r
+  ASSERT (TokenNumber < PCD_TOTAL_TOKEN_NUMBER);\r
+\r
+  Size = DxePcdGetSize (TokenNumber);\r
+  ASSERT (GetSize == Size || GetSize == 0);\r
 \r
+  \r
+  IsPeiDb = (TokenNumber <= PEI_LOCAL_TOKEN_NUMBER) ? TRUE : FALSE;\r
+\r
+  LocalTokenNumberTable  = IsPeiDb ? mPcdDatabase->PeiDb.Init.LocalTokenNumberTable : \r
+                                     mPcdDatabase->DxeDb.Init.LocalTokenNumberTable;\r
+\r
+  SizeTable              = IsPeiDb ? mPcdDatabase->PeiDb.Init.SizeTable: \r
+                                     mPcdDatabase->DxeDb.Init.SizeTable;\r
+\r
+  TokenNumber            = IsPeiDb ? TokenNumber :\r
+                                     TokenNumber - PEI_LOCAL_TOKEN_NUMBER;\r
+\r
+  LocalTokenNumber = LocalTokenNumberTable[TokenNumber];\r
+  \r
   if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == PCD_TYPE_SKU_ENABLED) {\r
     LocalTokenNumber = GetSkuEnabledTokenNumber (LocalTokenNumber & ~PCD_TYPE_SKU_ENABLED, Size, IsPeiDb);\r
   }\r
@@ -93,49 +117,24 @@ GetWorkerByLocalTokenNumber (
   ASSERT (FALSE);\r
       \r
   return NULL;\r
-}\r
   \r
-VOID *\r
-GetWorker (\r
-  UINTN  TokenNumber\r
-  )\r
-{\r
-  UINT32        *LocalTokenNumberTable;\r
-  UINT16        *SizeTable;\r
-  BOOLEAN       IsPeiDb;\r
-\r
-  ASSERT (TokenNumber < PCD_TOTAL_TOKEN_NUMBER);\r
-  \r
-  IsPeiDb = (TokenNumber <= PEI_LOCAL_TOKEN_NUMBER) ? TRUE : FALSE;\r
-\r
-  LocalTokenNumberTable  = IsPeiDb ? mPcdDatabase->PeiDb.Init.LocalTokenNumberTable : \r
-                                     mPcdDatabase->DxeDb.Init.LocalTokenNumberTable;\r
-\r
-  SizeTable              = IsPeiDb ? mPcdDatabase->PeiDb.Init.SizeTable: \r
-                                     mPcdDatabase->DxeDb.Init.SizeTable;\r
-\r
-  TokenNumber            = IsPeiDb ? TokenNumber :\r
-                                     TokenNumber - PEI_LOCAL_TOKEN_NUMBER;\r
-  return GetWorkerByLocalTokenNumber (LocalTokenNumberTable[TokenNumber], IsPeiDb, SizeTable[TokenNumber]);\r
 }\r
 \r
 \r
 \r
 EFI_STATUS\r
 DxeRegisterCallBackWorker (\r
-  IN  UINTN                   TokenNumber,\r
+  IN  PCD_TOKEN_NUMBER        TokenNumber,\r
   IN  CONST GUID              *Guid, OPTIONAL\r
   IN  PCD_PROTOCOL_CALLBACK   CallBackFunction\r
 )\r
 {\r
   CALLBACK_FN_ENTRY       *FnTableEntry;\r
-  EX_PCD_ENTRY_ATTRIBUTE  ExAttr;\r
   LIST_ENTRY              *ListHead;\r
   LIST_ENTRY              *ListNode;\r
 \r
   if (Guid != NULL) {\r
-    GetExPcdTokenAttributes (Guid, TokenNumber, &ExAttr);\r
-    TokenNumber = ExAttr.LocalTokenNumberAlias;\r
+    TokenNumber = GetExPcdTokenNumber (Guid, TokenNumber);\r
   }\r
 \r
   ListHead = &mCallbackFnTable[TokenNumber];\r
@@ -168,19 +167,17 @@ DxeRegisterCallBackWorker (
 \r
 EFI_STATUS\r
 DxeUnRegisterCallBackWorker (\r
-  IN  UINTN                   TokenNumber,\r
+  IN  PCD_TOKEN_NUMBER        TokenNumber,\r
   IN  CONST GUID              *Guid, OPTIONAL\r
   IN  PCD_PROTOCOL_CALLBACK   CallBackFunction\r
 )\r
 {\r
   CALLBACK_FN_ENTRY       *FnTableEntry;\r
-  EX_PCD_ENTRY_ATTRIBUTE  ExAttr;\r
   LIST_ENTRY              *ListHead;\r
   LIST_ENTRY              *ListNode;\r
 \r
   if (Guid != NULL) {\r
-    GetExPcdTokenAttributes (Guid, TokenNumber, &ExAttr);\r
-    TokenNumber = ExAttr.LocalTokenNumberAlias;\r
+    TokenNumber = GetExPcdTokenNumber (Guid, TokenNumber);\r
   }\r
 \r
   ListHead = &mCallbackFnTable[TokenNumber];\r
@@ -452,6 +449,15 @@ SetWorker (
 {\r
   UINT32              *LocalTokenNumberTable;\r
   BOOLEAN             IsPeiDb;\r
+  UINT32              LocalTokenNumber;\r
+  EFI_GUID            *GuidTable;\r
+  UINT16              *StringTable;\r
+  EFI_GUID            *Guid;\r
+  UINT16              *Name;\r
+  VOID                *InternalData;\r
+  VARIABLE_HEAD       *VariableHead;\r
+  UINTN               Offset;\r
+  UINT8               *PcdDb;\r
 \r
 \r
   ASSERT (TokenNumber < PCD_TOTAL_TOKEN_NUMBER);\r
@@ -467,89 +473,16 @@ SetWorker (
   LocalTokenNumberTable  = IsPeiDb ? mPcdDatabase->PeiDb.Init.LocalTokenNumberTable : \r
                                      mPcdDatabase->DxeDb.Init.LocalTokenNumberTable;\r
 \r
-  InvokeCallbackOnSet (0, NULL, TokenNumber, Data, Size);\r
+  if ((TokenNumber < PEI_NEX_TOKEN_NUMBER) ||\r
+      (TokenNumber >= PEI_LOCAL_TOKEN_NUMBER || TokenNumber < (PEI_LOCAL_TOKEN_NUMBER + DXE_NEX_TOKEN_NUMBER))) {\r
+    InvokeCallbackOnSet (0, NULL, TokenNumber, Data, Size);\r
+  }\r
 \r
   TokenNumber = IsPeiDb ? TokenNumber\r
                         : TokenNumber - PEI_LOCAL_TOKEN_NUMBER;\r
-  \r
-  return SetWorkerByLocalTokenNumber (LocalTokenNumberTable[TokenNumber], Data, Size, PtrType, IsPeiDb);\r
-\r
-}\r
-\r
-\r
-\r
-\r
-\r
-VOID *\r
-ExGetWorker (\r
-  IN CONST EFI_GUID         *Guid,\r
-  IN UINTN                  ExTokenNumber,\r
-  IN UINTN                  GetSize\r
-  ) \r
-{\r
-  EX_PCD_ENTRY_ATTRIBUTE Attr;\r
-\r
-  GetExPcdTokenAttributes (Guid, ExTokenNumber, &Attr);\r
-\r
-  ASSERT ((GetSize == Attr.Size) || (GetSize == 0));\r
-\r
-  return GetWorkerByLocalTokenNumber (Attr.LocalTokenNumberAlias,\r
-                                                Attr.IsPeiDb,\r
-                                                Attr.Size\r
-                                                );\r
-}\r
-\r
-\r
-\r
-\r
-\r
-EFI_STATUS\r
-ExSetWorker (\r
-  IN PCD_TOKEN_NUMBER     ExTokenNumber,\r
-  IN CONST EFI_GUID       *Guid,\r
-  VOID                    *Data,\r
-  UINTN                   SetSize,\r
-  BOOLEAN                 PtrType\r
-  )\r
-{\r
-  EX_PCD_ENTRY_ATTRIBUTE Attr;\r
-\r
-  GetExPcdTokenAttributes (Guid, ExTokenNumber, &Attr);\r
-\r
-  ASSERT (!PtrType && (SetSize == Attr.Size));\r
-\r
-  ASSERT (PtrType && (SetSize <= Attr.Size));\r
-\r
-  InvokeCallbackOnSet (ExTokenNumber, Guid, Attr.TokenNumber, Data, Attr.Size);\r
 \r
-  SetWorkerByLocalTokenNumber (Attr.LocalTokenNumberAlias, Data, Attr.Size, PtrType, Attr.IsPeiDb);\r
-\r
-  return EFI_SUCCESS;\r
+  LocalTokenNumber = LocalTokenNumberTable[TokenNumber];\r
   \r
-}\r
-\r
-\r
-\r
-\r
-EFI_STATUS\r
-SetWorkerByLocalTokenNumber (\r
-  UINT32        LocalTokenNumber,\r
-  VOID          *Data,\r
-  UINTN         Size,\r
-  BOOLEAN       PtrType,\r
-  BOOLEAN       IsPeiDb\r
-  )\r
-{\r
-  EFI_GUID            *GuidTable;\r
-  UINT16              *StringTable;\r
-  EFI_GUID            *Guid;\r
-  UINT16              *Name;\r
-  VOID                *InternalData;\r
-  VARIABLE_HEAD       *VariableHead;\r
-  UINTN               Offset;\r
-  UINT8               *PcdDb;\r
-\r
-\r
   if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == PCD_TYPE_SKU_ENABLED) {\r
     LocalTokenNumber = GetSkuEnabledTokenNumber (LocalTokenNumber & ~PCD_TYPE_SKU_ENABLED, Size, IsPeiDb);\r
   }\r
@@ -625,6 +558,46 @@ SetWorkerByLocalTokenNumber (
 \r
 \r
 \r
+\r
+\r
+VOID *\r
+ExGetWorker (\r
+  IN CONST EFI_GUID         *Guid,\r
+  IN UINTN                  ExTokenNumber,\r
+  IN UINTN                  GetSize\r
+  ) \r
+{\r
+  return GetWorker(GetExPcdTokenNumber (Guid, ExTokenNumber), GetSize);\r
+}\r
+\r
+\r
+\r
+\r
+\r
+EFI_STATUS\r
+ExSetWorker (\r
+  IN PCD_TOKEN_NUMBER     ExTokenNumber,\r
+  IN CONST EFI_GUID       *Guid,\r
+  VOID                    *Data,\r
+  UINTN                   SetSize,\r
+  BOOLEAN                 PtrType\r
+  )\r
+{\r
+  PCD_TOKEN_NUMBER        TokenNumber;\r
+  \r
+  TokenNumber = GetExPcdTokenNumber (Guid, ExTokenNumber);\r
+\r
+  InvokeCallbackOnSet (ExTokenNumber, Guid, TokenNumber, Data, SetSize);\r
+\r
+  SetWorker (TokenNumber, Data, SetSize, PtrType);\r
+\r
+  return EFI_SUCCESS;\r
+  \r
+}\r
+\r
+\r
+\r
+\r
 EFI_STATUS\r
 SetHiiVariable (\r
   IN  EFI_GUID     *VariableGuid,\r
@@ -680,56 +653,51 @@ SetHiiVariable (
 \r
 \r
 \r
-VOID\r
-GetExPcdTokenAttributes (\r
+PCD_TOKEN_NUMBER\r
+GetExPcdTokenNumber (\r
   IN CONST EFI_GUID             *Guid,\r
-  IN PCD_TOKEN_NUMBER           ExTokenNumber,\r
-  OUT EX_PCD_ENTRY_ATTRIBUTE    *ExAttr\r
+  IN PCD_TOKEN_NUMBER           ExTokenNumber\r
   )\r
 {\r
   UINT32              i;\r
   DYNAMICEX_MAPPING   *ExMap;\r
   EFI_GUID            *GuidTable;\r
-  UINT16              *SizeTable;\r
+  EFI_GUID            *MatchGuid;\r
+  UINTN               MatchGuidIdx;\r
 \r
   ExMap       = mPcdDatabase->PeiDb.Init.ExMapTable;\r
   GuidTable   = mPcdDatabase->PeiDb.Init.GuidTable;\r
-  SizeTable   = mPcdDatabase->PeiDb.Init.SizeTable;\r
+  \r
+  MatchGuid   = ScanGuid (GuidTable, sizeof(mPcdDatabase->PeiDb.Init.GuidTable), Guid);\r
+  ASSERT (MatchGuid != NULL);\r
+\r
+  MatchGuidIdx = MatchGuid - GuidTable;\r
   \r
   for (i = 0; i < PEI_EXMAPPING_TABLE_SIZE; i++) {\r
     if ((ExTokenNumber == ExMap[i].ExTokenNumber) &&\r
-        CompareGuid (Guid, (CONST EFI_GUID *) &GuidTable[ExMap[i].ExGuidIndex])\r
-      ) {\r
-\r
-        ExAttr->IsPeiDb               = TRUE;\r
-        ExAttr->Size                  = SizeTable[i + PEI_NEX_TOKEN_NUMBER];\r
-        ExAttr->TokenNumber           = i + PEI_NEX_TOKEN_NUMBER;\r
-        ExAttr->LocalTokenNumberAlias = ExMap[i].LocalTokenNumber;\r
-        return;\r
+        (MatchGuidIdx == ExMap[i].ExGuidIndex)) {\r
+        return ExMap[i].LocalTokenNumber;\r
 \r
     }\r
   }\r
   \r
   ExMap       = mPcdDatabase->DxeDb.Init.ExMapTable;\r
   GuidTable   = mPcdDatabase->DxeDb.Init.GuidTable;\r
-  SizeTable   = mPcdDatabase->DxeDb.Init.SizeTable;\r
+\r
+  MatchGuid   = ScanGuid (GuidTable, sizeof(mPcdDatabase->DxeDb.Init.GuidTable), Guid);\r
+  ASSERT (MatchGuid != NULL);\r
+\r
+  MatchGuidIdx = MatchGuid - GuidTable;\r
   \r
   for (i = 0; i < DXE_EXMAPPING_TABLE_SIZE; i++) {\r
     if ((ExTokenNumber == ExMap[i].ExTokenNumber) &&\r
-         CompareGuid (Guid, (CONST EFI_GUID *) &GuidTable[ExMap[i].ExGuidIndex])\r
-      ) {\r
-\r
-        ExAttr->IsPeiDb               = FALSE;\r
-        ExAttr->Size                  = SizeTable[i + DXE_NEX_TOKEN_NUMBER];\r
-        ExAttr->TokenNumber           = i + PEI_LOCAL_TOKEN_NUMBER;\r
-        ExAttr->LocalTokenNumberAlias = ExMap[i].LocalTokenNumber;\r
-        return;\r
-\r
+         (MatchGuidIdx == ExMap[i].ExGuidIndex)) {\r
+        return ExMap[i].LocalTokenNumber + PEI_LOCAL_TOKEN_NUMBER;\r
     }\r
   }\r
 \r
   ASSERT (FALSE);\r
 \r
-  return;\r
+  return 0;\r
 }\r
 \r