Liming & Bob,

Comments inline.

On 2015/8/18 17:25, Liming Gao wrote:
PcdLib introduces new APIs to get the size of PCD value.
BaseTools generates those macros in AutoGen code.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Bob Feng <bob.c.f...@intel.com>
---
  BaseTools/Source/Python/AutoGen/GenC.py | 70 ++++++++++++++++++++++++++++++---
  1 file changed, 65 insertions(+), 5 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/GenC.py 
b/BaseTools/Source/Python/AutoGen/GenC.py
index 84bd607..d706574 100644
--- a/BaseTools/Source/Python/AutoGen/GenC.py
+++ b/BaseTools/Source/Python/AutoGen/GenC.py
@@ -730,10 +730,25 @@ def DynExPcdTokenNumberMapping(Info, AutoGenH):
                      #  COMPAREGUID() will only be used if the Guid passed in 
is local to the module.
                      AutoGenH.Append('#define _PCD_TOKEN_EX_%s(GuidPtr)   
__PCD_%s_ADDR_CMP(GuidPtr) ? __PCD_%s_ADDR_CMP(GuidPtr) : 
__PCD_%s_VAL_CMP(GuidPtr)  \n'
                                      % (Pcd.TokenCName, Pcd.TokenCName, 
Pcd.TokenCName, Pcd.TokenCName))
                  TokenCNameList.append(TokenCName)

+def GetPcdSize(Pcd):
+    if Pcd.DatumType == 'VOID*':
+        return Pcd.MaxDatumSize

Should it return the current data size, but not max data size?

+    if Pcd.DatumType == 'UINT64':
+        return 8
+    if Pcd.DatumType == 'UINT32':
+        return 4
+    if Pcd.DatumType == 'UINT16':
+        return 2
+    if Pcd.DatumType == 'UINT8':
+        return 1
+    if Pcd.DatumType == 'BOOLEAN':
+        return 1
+
+
  ## Create code for module PCDs
  #
  #   @param      Info        The ModuleAutoGen object
  #   @param      AutoGenC    The TemplateString object for C code
  #   @param      AutoGenH    The TemplateString object for header file
@@ -744,10 +759,14 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
      PcdTokenNumber = Info.PlatformInfo.PcdTokenNumber
      #
      # Write PCDs
      #
      PcdTokenName = '_PCD_TOKEN_' + Pcd.TokenCName
+    PatchPcdSizeTokenName = '_PCD_PATCHABLE_' + Pcd.TokenCName +'_SIZE'
+    PatchPcdSizeVariableName = '_gPcd_BinaryPatch_Size_' + Pcd.TokenCName
+    FixPcdSizeTokenName = '_PCD_SIZE_' + Pcd.TokenCName
+
      if Pcd.Type in gDynamicExPcd:
          TokenNumber = int(Pcd.TokenValue, 0)
          # Add TokenSpaceGuidValue value to PcdTokenName to discriminate the 
DynamicEx PCDs with
          # different Guids but same TokenCName
          PcdExTokenName = '_PCD_TOKEN_' + Pcd.TokenSpaceGuidCName + '_' + 
Pcd.TokenCName
@@ -785,11 +804,12 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
      DatumSize = gDatumSizeStringDatabase[Pcd.DatumType]
      DatumSizeLib = gDatumSizeStringDatabaseLib[Pcd.DatumType]
      GetModeName = '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] 
+ '_' + Pcd.TokenCName
      SetModeName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] 
+ '_' + Pcd.TokenCName
      SetModeStatusName = '_PCD_SET_MODE_' + 
gDatumSizeStringDatabaseH[Pcd.DatumType] + '_S_' + Pcd.TokenCName
-
+    GetModeSizeName = '_PCD_GET_MODE_SIZE' + '_' + Pcd.TokenCName
+
      PcdExCNameList  = []
      if Pcd.Type in gDynamicExPcd:
          if Info.IsLibrary:
              PcdList = Info.LibraryPcdList
          else:
@@ -802,27 +822,30 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
          # If PcdToken and PcdGet/Set used in the Pcds with different Guids 
but same CName, it should failed to build.
          if PcdExCNameList.count(Pcd.TokenCName) > 1:
              AutoGenH.Append('// Disabled the macros, as PcdToken and 
PcdGet/Set are not allowed in the case that more than one DynamicEx Pcds are 
different Guids but same CName.\n')
              AutoGenH.Append('// #define %s  %s\n' % (PcdTokenName, 
PcdExTokenName))
              AutoGenH.Append('// #define %s  LibPcdGetEx%s(&%s, %s)\n' % 
(GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
+            AutoGenH.Append('#define %s LibPcdGetExSize(&%s, %s)\n' % 
(GetModeSizeName,Pcd.TokenSpaceGuidCName, PcdTokenName))
              if Pcd.DatumType == 'VOID*':
                  AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer)  
LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, 
DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
                  AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer)  
LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, 
DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
              else:
                  AutoGenH.Append('// #define %s(Value)  LibPcdSetEx%s(&%s, %s, 
(Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
                  AutoGenH.Append('// #define %s(Value)  LibPcdSetEx%sS(&%s, 
%s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, 
PcdTokenName))
          else:
              AutoGenH.Append('#define %s  %s\n' % (PcdTokenName, 
PcdExTokenName))
              AutoGenH.Append('#define %s  LibPcdGetEx%s(&%s, %s)\n' % 
(GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
+            AutoGenH.Append('#define %s LibPcdGetExSize(&%s, %s)\n' % 
(GetModeSizeName,Pcd.TokenSpaceGuidCName, PcdTokenName))
              if Pcd.DatumType == 'VOID*':
                  AutoGenH.Append('#define %s(SizeOfBuffer, Buffer)  
LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, 
DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
                  AutoGenH.Append('#define %s(SizeOfBuffer, Buffer)  
LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, 
DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
              else:
                  AutoGenH.Append('#define %s(Value)  LibPcdSetEx%s(&%s, %s, 
(Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
                  AutoGenH.Append('#define %s(Value)  LibPcdSetEx%sS(&%s, %s, 
(Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, 
PcdTokenName))
      elif Pcd.Type in gDynamicPcd:
          AutoGenH.Append('#define %s  LibPcdGet%s(%s)\n' % (GetModeName, 
DatumSizeLib, PcdTokenName))
+        AutoGenH.Append('#define %s  LibPcdGetSize(%s)\n' % (GetModeSizeName, 
PcdTokenName))
          if Pcd.DatumType == 'VOID*':
              AutoGenH.Append('#define %s(SizeOfBuffer, Buffer)  
LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName, DatumSizeLib, 
PcdTokenName))
              AutoGenH.Append('#define %s(SizeOfBuffer, Buffer)  
LibPcdSet%sS(%s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, 
DatumSizeLib, PcdTokenName))
          else:
              AutoGenH.Append('#define %s(Value)  LibPcdSet%s(%s, (Value))\n' % 
(SetModeName, DatumSizeLib, PcdTokenName))
@@ -943,27 +966,47 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
          if Pcd.DatumType == 'VOID*':
              #
              # For unicode, UINT16 array will be generated, so the alignment 
of unicode is guaranteed.
              #
              if Unicode:
-                AutoGenH.Append('#define _PCD_PATCHABLE_%s_SIZE %s\n' % 
(Pcd.TokenCName, Pcd.MaxDatumSize))
                  AutoGenH.Append('#define %s  %s%s\n' %(PcdValueName, Type, 
PcdVariableName))
                  AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT16 %s%s 
= %s;\n' % (Const, PcdVariableName, Array, Value))
                  AutoGenH.Append('extern %s UINT16 %s%s;\n' %(Const, 
PcdVariableName, Array))
                  AutoGenH.Append('#define %s  %s%s\n' %(GetModeName, Type, 
PcdVariableName))
              else:
-                AutoGenH.Append('#define _PCD_PATCHABLE_%s_SIZE %s\n' % 
(Pcd.TokenCName, Pcd.MaxDatumSize))
                  AutoGenH.Append('#define %s  %s%s\n' %(PcdValueName, Type, 
PcdVariableName))
                  AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT8 %s%s 
= %s;\n' % (Const, PcdVariableName, Array, Value))
                  AutoGenH.Append('extern %s UINT8 %s%s;\n' %(Const, 
PcdVariableName, Array))
                  AutoGenH.Append('#define %s  %s%s\n' %(GetModeName, Type, 
PcdVariableName))
+
+            if Pcd.Type == TAB_PCDS_FIXED_AT_BUILD:
+                PcdDataSize = GetPcdSize(Pcd)
+                AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, 
PcdDataSize))
+                AutoGenH.Append('#define %s  %s \n' % 
(GetModeSizeName,FixPcdSizeTokenName))
+
+            if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:
+                AutoGenH.Append('#define _PCD_PATCHABLE_%s_SIZE %s\n' % 
(Pcd.TokenCName, Pcd.MaxDatumSize))
+                AutoGenH.Append('#define %s  %s \n' % 
(GetModeSizeName,PatchPcdSizeVariableName))
+                AutoGenH.Append('extern UINTN %s; \n' % 
PatchPcdSizeVariableName)
+                AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s = 
%s;\n' % (PatchPcdSizeVariableName,PatchPcdSizeTokenName))
          elif Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:
              AutoGenH.Append('#define %s  %s\n' %(PcdValueName, Value))
              AutoGenC.Append('volatile %s %s %s = %s;\n' %(Const, 
Pcd.DatumType, PcdVariableName, PcdValueName))
              AutoGenH.Append('extern volatile %s  %s  %s%s;\n' % (Const, 
Pcd.DatumType, PcdVariableName, Array))
              AutoGenH.Append('#define %s  %s%s\n' % (GetModeName, Type, 
PcdVariableName))
+
+            PcdDataSize = GetPcdSize(Pcd)
+            AutoGenH.Append('#define %s %s\n' % (PatchPcdSizeTokenName, 
PcdDataSize))
+
+            AutoGenH.Append('#define %s  %s \n' % 
(GetModeSizeName,PatchPcdSizeVariableName))
+            AutoGenH.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName)
+            AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s = %s;\n' % 
(PatchPcdSizeVariableName,PatchPcdSizeTokenName))
          else:
+            PcdDataSize = GetPcdSize(Pcd)
+            AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, 
PcdDataSize))
+            AutoGenH.Append('#define %s  %s \n' % 
(GetModeSizeName,FixPcdSizeTokenName))
+
              AutoGenH.Append('#define %s  %s\n' %(PcdValueName, Value))
              AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s %s = %s;\n' 
%(Const, Pcd.DatumType, PcdVariableName, PcdValueName))
              AutoGenH.Append('extern %s  %s  %s%s;\n' % (Const, Pcd.DatumType, 
PcdVariableName, Array))
              AutoGenH.Append('#define %s  %s%s\n' % (GetModeName, Type, 
PcdVariableName))

@@ -987,10 +1030,14 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
  def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):
      PcdTokenNumber = Info.PlatformInfo.PcdTokenNumber
      TokenSpaceGuidCName = Pcd.TokenSpaceGuidCName
      TokenCName  = Pcd.TokenCName
      PcdTokenName = '_PCD_TOKEN_' + TokenCName
+    FixPcdSizeTokenName = '_PCD_SIZE_' + Pcd.TokenCName
+    PatchPcdSizeTokenName = '_PCD_PATCHABLE_' + Pcd.TokenCName +'_SIZE'
+    PatchPcdSizeVariableName = '_gPcd_BinaryPatch_Size_' + Pcd.TokenCName
+
      #
      # Write PCDs
      #
      if Pcd.Type in gDynamicExPcd:
          TokenNumber = int(Pcd.TokenValue, 0)
@@ -1026,10 +1073,11 @@ def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):
      DatumSize   = gDatumSizeStringDatabaseH[DatumType]
      DatumSizeLib= gDatumSizeStringDatabaseLib[DatumType]
      GetModeName = '_PCD_GET_MODE_' + DatumSize + '_' + TokenCName
      SetModeName = '_PCD_SET_MODE_' + DatumSize + '_' + TokenCName
      SetModeStatusName = '_PCD_SET_MODE_' + DatumSize + '_S_' + TokenCName
+    GetModeSizeName = '_PCD_GET_MODE_SIZE' + '_' + Pcd.TokenCName

      Type = ''
      Array = ''
      if Pcd.DatumType == 'VOID*':
          Type = '(VOID *)'
@@ -1052,29 +1100,32 @@ def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):
          # If PcdGet/Set used in the Pcds with different Guids but same CName, 
it should failed to build.
          if PcdExCNameList.count(Pcd.TokenCName) > 1:
              AutoGenH.Append('// Disabled the macros, as PcdToken and 
PcdGet/Set are not allowed in the case that more than one DynamicEx Pcds are 
different Guids but same CName.\n')
              AutoGenH.Append('// #define %s  %s\n' % (PcdTokenName, 
PcdExTokenName))
              AutoGenH.Append('// #define %s  LibPcdGetEx%s(&%s, %s)\n' % 
(GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
+            AutoGenH.Append('#define %s LibPcdGetExSize(&%s, %s)\n' % 
(GetModeSizeName,Pcd.TokenSpaceGuidCName, PcdTokenName))
              if Pcd.DatumType == 'VOID*':
                  AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer)  
LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, 
DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
                  AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer)  
LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, 
DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
              else:
                  AutoGenH.Append('// #define %s(Value)  LibPcdSetEx%s(&%s, %s, 
(Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
                  AutoGenH.Append('// #define %s(Value)  LibPcdSetEx%sS(&%s, 
%s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, 
PcdTokenName))
          else:
              AutoGenH.Append('#define %s  %s\n' % (PcdTokenName, 
PcdExTokenName))
              AutoGenH.Append('#define %s  LibPcdGetEx%s(&%s, %s)\n' % 
(GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
+            AutoGenH.Append('#define %s LibPcdGetExSize(&%s, %s)\n' % 
(GetModeSizeName,Pcd.TokenSpaceGuidCName, PcdTokenName))
              if Pcd.DatumType == 'VOID*':
                  AutoGenH.Append('#define %s(SizeOfBuffer, Buffer)  
LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, 
DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
                  AutoGenH.Append('#define %s(SizeOfBuffer, Buffer)  
LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, 
DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
              else:
                  AutoGenH.Append('#define %s(Value)  LibPcdSetEx%s(&%s, %s, 
(Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
                  AutoGenH.Append('#define %s(Value)  LibPcdSetEx%sS(&%s, %s, 
(Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, 
PcdTokenName))
      else:
          AutoGenH.Append('#define _PCD_TOKEN_%s  %dU\n' % (TokenCName, 
TokenNumber))
      if PcdItemType in gDynamicPcd:
          AutoGenH.Append('#define %s  LibPcdGet%s(%s)\n' % (GetModeName, 
DatumSizeLib, PcdTokenName))
+        AutoGenH.Append('#define %s  LibPcdGetSize(%s)\n' % (GetModeSizeName, 
PcdTokenName))
          if DatumType == 'VOID*':
              AutoGenH.Append('#define %s(SizeOfBuffer, Buffer)  
LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName, DatumSizeLib, 
PcdTokenName))
              AutoGenH.Append('#define %s(SizeOfBuffer, Buffer)  
LibPcdSet%sS(%s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, 
DatumSizeLib, PcdTokenName))
          else:
              AutoGenH.Append('#define %s(Value)  LibPcdSet%s(%s, (Value))\n' % 
(SetModeName, DatumSizeLib, PcdTokenName))
@@ -1083,23 +1134,32 @@ def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):
          PcdVariableName = '_gPcd_' + 
gItemTypeStringDatabase[TAB_PCDS_PATCHABLE_IN_MODULE] + '_' + TokenCName
          AutoGenH.Append('extern volatile %s _gPcd_BinaryPatch_%s%s;\n' 
%(DatumType, TokenCName, Array) )
          AutoGenH.Append('#define %s  %s_gPcd_BinaryPatch_%s\n' %(GetModeName, 
Type, TokenCName))
          AutoGenH.Append('#define %s(Value)  (%s = (Value))\n' % (SetModeName, 
PcdVariableName))
          AutoGenH.Append('#define %s(Value)  ((%s = (Value)), 
RETURN_SUCCESS)\n' % (SetModeStatusName, PcdVariableName))
+
+        PcdDataSize = GetPcdSize(Pcd)
+        AutoGenH.Append('#define %s %s\n' % (PatchPcdSizeTokenName, 
PcdDataSize))
+        AutoGenH.Append('#define %s %s\n' % 
(GetModeSizeName,PatchPcdSizeVariableName))
+        AutoGenH.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName)
+
      if PcdItemType == TAB_PCDS_FIXED_AT_BUILD or PcdItemType == 
TAB_PCDS_FEATURE_FLAG:
          key = ".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName))

          if DatumType == 'VOID*' and Array == '[]':
-          DatumType = ['UINT8', 'UINT16'][Pcd.DefaultValue[0] == 'L']
+            DatumType = ['UINT8', 'UINT16'][Pcd.DefaultValue[0] == 'L']
          AutoGenH.Append('extern const %s _gPcd_FixedAtBuild_%s%s;\n' 
%(DatumType, TokenCName, Array))
          AutoGenH.Append('#define %s  %s_gPcd_FixedAtBuild_%s\n' 
%(GetModeName, Type, TokenCName))
          AutoGenH.Append('//#define %s  ASSERT(FALSE)  // It is not allowed to 
set value for a FIXED_AT_BUILD PCD\n' % SetModeName)

          if PcdItemType == TAB_PCDS_FIXED_AT_BUILD and key in Info.ConstPcd:
              AutoGenH.Append('#define _PCD_VALUE_%s %s\n' %(TokenCName, 
Pcd.DefaultValue))

-
+        if PcdItemType == TAB_PCDS_FIXED_AT_BUILD:
+            PcdDataSize = GetPcdSize(Pcd)
+            AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, 
PcdDataSize))
+            AutoGenH.Append('#define %s %s\n' % 
(GetModeSizeName,FixPcdSizeTokenName))

  ## Create code for library constructor
  #
  #   @param      Info        The ModuleAutoGen object
  #   @param      AutoGenC    The TemplateString object for C code


Thanks,
Star

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to