BaseTools/AutoGen: auto generate MM template APIs and dependencies.
authorSupreeth Venkatesh <supreeth.venkatesh@arm.com>
Mon, 26 Jun 2017 16:47:39 +0000 (00:47 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Fri, 7 Jul 2017 02:49:13 +0000 (10:49 +0800)
This patch adds changes to auto generate MM_CORE_STANDALONE and
MM_STANDALONE Entry Point templates.
Also, it adds changes to help auto generate dependency expressions for
MM_STANDALONE modules.

PI Specification v1.5 specifies Management Mode System Table (MMST)
which is  a collection of common services for managing
MMRAM allocation and providing basic I/O services. MMST is similar to
the UEFI System Table. (Currently, EFI_SMM_SYSTEM_TABLE2 defines
Management Mode System Table)

Some of auto generated MM_CORE_STANDALONE and MM_STANDALONE template
APIs use MMST as parameter.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao <jiewen.yao@intel.com>
Signed-off-by: Supreeth Venkatesh <supreeth.venkatesh@arm.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
BaseTools/Source/Python/AutoGen/GenC.py
BaseTools/Source/Python/AutoGen/GenDepex.py

index 67aaef7..7aa2016 100644 (file)
@@ -237,6 +237,100 @@ ProcessModuleEntryPointList (
 ${END}\r
 """)\r
 \r
+## MM_CORE_STANDALONE Entry Point Templates\r
+gMmCoreStandaloneEntryPointPrototype = TemplateString("""\r
+${BEGIN}\r
+EFI_STATUS\r
+EFIAPI\r
+${Function} (\r
+  IN VOID *HobStart\r
+  );\r
+${END}\r
+""")\r
+\r
+gMmCoreStandaloneEntryPointString = TemplateString("""\r
+${BEGIN}\r
+const UINT32 _gMmRevision = ${PiSpecVersion};\r
+\r
+VOID\r
+EFIAPI\r
+ProcessModuleEntryPointList (\r
+  IN VOID *HobStart\r
+  )\r
+{\r
+  ${Function} (HobStart);\r
+}\r
+${END}\r
+""")\r
+\r
+## MM_STANDALONE Entry Point Templates\r
+gMmStandaloneEntryPointPrototype = TemplateString("""\r
+${BEGIN}\r
+EFI_STATUS\r
+EFIAPI\r
+${Function} (\r
+  IN EFI_HANDLE            ImageHandle,\r
+  IN EFI_SMM_SYSTEM_TABLE2 *MmSystemTable\r
+  );\r
+${END}\r
+""")\r
+\r
+gMmStandaloneEntryPointString = [\r
+TemplateString("""\r
+GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gMmRevision = ${PiSpecVersion};\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ProcessModuleEntryPointList (\r
+  IN EFI_HANDLE            ImageHandle,\r
+  IN EFI_SMM_SYSTEM_TABLE2 *MmSystemTable\r
+  )\r
+\r
+{\r
+  return EFI_SUCCESS;\r
+}\r
+"""),\r
+TemplateString("""\r
+GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gMmRevision = ${PiSpecVersion};\r
+${BEGIN}\r
+EFI_STATUS\r
+EFIAPI\r
+ProcessModuleEntryPointList (\r
+  IN EFI_HANDLE            ImageHandle,\r
+  IN EFI_SMM_SYSTEM_TABLE2 *MmSystemTable\r
+  )\r
+\r
+{\r
+  return ${Function} (ImageHandle, MmSystemTable);\r
+}\r
+${END}\r
+"""),\r
+TemplateString("""\r
+GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gMmRevision = ${PiSpecVersion};\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ProcessModuleEntryPointList (\r
+  IN EFI_HANDLE            ImageHandle,\r
+  IN EFI_SMM_SYSTEM_TABLE2 *MmSystemTable\r
+  )\r
+\r
+{\r
+  EFI_STATUS  Status;\r
+  EFI_STATUS  CombinedStatus;\r
+\r
+  CombinedStatus = EFI_LOAD_ERROR;\r
+${BEGIN}\r
+  Status = ${Function} (ImageHandle, MmSystemTable);\r
+  if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {\r
+    CombinedStatus = Status;\r
+  }\r
+${END}\r
+  return CombinedStatus;\r
+}\r
+""")\r
+]\r
+\r
 ## DXE SMM Entry Point Templates\r
 gDxeSmmEntryPointPrototype = TemplateString("""\r
 ${BEGIN}\r
@@ -580,6 +674,15 @@ ${Function} (
   IN EFI_SYSTEM_TABLE  *SystemTable\r
   );${END}\r
 """),\r
+\r
+'MM'   : TemplateString("""${BEGIN}\r
+EFI_STATUS\r
+EFIAPI\r
+${Function} (\r
+  IN EFI_HANDLE            ImageHandle,\r
+  IN EFI_SMM_SYSTEM_TABLE2  *MmSystemTable\r
+  );${END}\r
+"""),\r
 }\r
 \r
 gLibraryStructorCall = {\r
@@ -597,6 +700,11 @@ gLibraryStructorCall = {
   Status = ${Function} (ImageHandle, SystemTable);\r
   ASSERT_EFI_ERROR (Status);${END}\r
 """),\r
+\r
+'MM'   : TemplateString("""${BEGIN}\r
+  Status = ${Function} (ImageHandle, MmSystemTable);\r
+  ASSERT_EFI_ERROR (Status);${END}\r
+"""),\r
 }\r
 \r
 ## Library Constructor and Destructor Templates\r
@@ -644,6 +752,21 @@ ${BEGIN}  EFI_STATUS  Status;
 ${FunctionCall}${END}\r
 }\r
 """),\r
+\r
+'MM'   :   TemplateString("""\r
+${BEGIN}${FunctionPrototype}${END}\r
+\r
+VOID\r
+EFIAPI\r
+ProcessLibrary${Type}List (\r
+  IN EFI_HANDLE            ImageHandle,\r
+  IN EFI_SMM_SYSTEM_TABLE2  *MmSystemTable\r
+  )\r
+{\r
+${BEGIN}  EFI_STATUS  Status;\r
+${FunctionCall}${END}\r
+}\r
+"""),\r
 }\r
 \r
 gBasicHeaderFile = "Base.h"\r
@@ -661,6 +784,8 @@ gModuleTypeHeaderFile = {
     "UEFI_DRIVER"       :   ["Uefi.h",  "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],\r
     "UEFI_APPLICATION"  :   ["Uefi.h",  "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiApplicationEntryPoint.h"],\r
     "SMM_CORE"          :   ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiDriverEntryPoint.h"],\r
+    "MM_STANDALONE"     :   ["PiSmm.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/SmmDriverStandaloneEntryPoint.h"],\r
+    "MM_CORE_STANDALONE" :  ["PiSmm.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/SmmCoreStandaloneEntryPoint.h"],\r
     "USER_DEFINED"      :   [gBasicHeaderFile]\r
 }\r
 \r
@@ -1266,6 +1391,9 @@ def CreateLibraryConstructorCode(Info, AutoGenC, AutoGenH):
                                 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']:\r
             ConstructorPrototypeString.Append(gLibraryStructorPrototype['DXE'].Replace(Dict))\r
             ConstructorCallingString.Append(gLibraryStructorCall['DXE'].Replace(Dict))\r
+        elif Lib.ModuleType in ['MM_STANDALONE','MM_CORE_STANDALONE']:\r
+            ConstructorPrototypeString.Append(gLibraryStructorPrototype['MM'].Replace(Dict))\r
+            ConstructorCallingString.Append(gLibraryStructorCall['MM'].Replace(Dict))\r
 \r
     if str(ConstructorPrototypeString) == '':\r
         ConstructorPrototypeList = []\r
@@ -1291,6 +1419,8 @@ def CreateLibraryConstructorCode(Info, AutoGenC, AutoGenH):
         elif Info.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',\r
                                  'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']:\r
             AutoGenC.Append(gLibraryString['DXE'].Replace(Dict))\r
+        elif Info.ModuleType in ['MM_STANDALONE','MM_CORE_STANDALONE']:\r
+            AutoGenC.Append(gLibraryString['MM'].Replace(Dict))\r
 \r
 ## Create code for library destructor\r
 #\r
@@ -1323,6 +1453,9 @@ def CreateLibraryDestructorCode(Info, AutoGenC, AutoGenH):
                                 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION', 'SMM_CORE']:\r
             DestructorPrototypeString.Append(gLibraryStructorPrototype['DXE'].Replace(Dict))\r
             DestructorCallingString.Append(gLibraryStructorCall['DXE'].Replace(Dict))\r
+        elif Lib.ModuleType in ['MM_STANDALONE','MM_CORE_STANDALONE']:\r
+            DestructorPrototypeString.Append(gLibraryStructorPrototype['MM'].Replace(Dict))\r
+            DestructorCallingString.Append(gLibraryStructorCall['MM'].Replace(Dict))\r
 \r
     if str(DestructorPrototypeString) == '':\r
         DestructorPrototypeList = []\r
@@ -1348,6 +1481,8 @@ def CreateLibraryDestructorCode(Info, AutoGenC, AutoGenH):
         elif Info.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',\r
                                  'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']:\r
             AutoGenC.Append(gLibraryString['DXE'].Replace(Dict))\r
+        elif Info.ModuleType in ['MM_STANDALONE','MM_CORE_STANDALONE']:\r
+            AutoGenC.Append(gLibraryString['MM'].Replace(Dict))\r
 \r
 \r
 ## Create code for ModuleEntryPoint\r
@@ -1377,7 +1512,7 @@ def CreateModuleEntryPointCode(Info, AutoGenC, AutoGenH):
         'UefiSpecVersion':   UefiSpecVersion + 'U'\r
     }\r
 \r
-    if Info.ModuleType in ['PEI_CORE', 'DXE_CORE', 'SMM_CORE']:\r
+    if Info.ModuleType in ['PEI_CORE', 'DXE_CORE', 'SMM_CORE', 'MM_CORE_STANDALONE']:\r
         if Info.SourceFileList <> None and Info.SourceFileList <> []:\r
           if NumEntryPoints != 1:\r
               EdkLogger.error(\r
@@ -1396,6 +1531,9 @@ def CreateModuleEntryPointCode(Info, AutoGenC, AutoGenH):
     elif Info.ModuleType == 'SMM_CORE':\r
         AutoGenC.Append(gSmmCoreEntryPointString.Replace(Dict))\r
         AutoGenH.Append(gSmmCoreEntryPointPrototype.Replace(Dict))\r
+    elif Info.ModuleType == 'MM_CORE_STANDALONE':\r
+        AutoGenC.Append(gMmCoreStandaloneEntryPointString.Replace(Dict))\r
+        AutoGenH.Append(gMmCoreStandaloneEntryPointPrototype.Replace(Dict))\r
     elif Info.ModuleType == 'PEIM':\r
         if NumEntryPoints < 2:\r
             AutoGenC.Append(gPeimEntryPointString[NumEntryPoints].Replace(Dict))\r
@@ -1413,7 +1551,13 @@ def CreateModuleEntryPointCode(Info, AutoGenC, AutoGenH):
             AutoGenC.Append(gDxeSmmEntryPointString[0].Replace(Dict))\r
         else:\r
             AutoGenC.Append(gDxeSmmEntryPointString[1].Replace(Dict))\r
-        AutoGenH.Append(gDxeSmmEntryPointPrototype.Replace(Dict))    \r
+        AutoGenH.Append(gDxeSmmEntryPointPrototype.Replace(Dict))\r
+    elif Info.ModuleType == 'MM_STANDALONE':\r
+        if NumEntryPoints < 2:\r
+            AutoGenC.Append(gMmStandaloneEntryPointString[NumEntryPoints].Replace(Dict))\r
+        else:\r
+            AutoGenC.Append(gMmStandaloneEntryPointString[2].Replace(Dict))\r
+        AutoGenH.Append(gMmStandaloneEntryPointPrototype.Replace(Dict))\r
     elif Info.ModuleType == 'UEFI_APPLICATION':\r
         if NumEntryPoints < 2:\r
             AutoGenC.Append(gUefiApplicationEntryPointString[NumEntryPoints].Replace(Dict))\r
index 5923a75..7aa22bd 100644 (file)
@@ -42,6 +42,8 @@ gType2Phase = {
     "UEFI_DRIVER"       :   "DXE",\r
     "UEFI_APPLICATION"  :   "DXE",\r
     "SMM_CORE"          :   "DXE",\r
+    "MM_STANDALONE"     :   "MM",\r
+    "MM_CORE_STANDALONE" :  "MM",\r
 }\r
 \r
 ## Convert dependency expression string into EFI internal representation\r
@@ -98,6 +100,19 @@ class DependencyExpression:
             "FALSE" :   0x07,\r
             "END"   :   0x08,\r
             "SOR"   :   0x09\r
+        },\r
+\r
+        "MM"   : {\r
+            "BEFORE":   0x00,\r
+            "AFTER" :   0x01,\r
+            "PUSH"  :   0x02,\r
+            "AND"   :   0x03,\r
+            "OR"    :   0x04,\r
+            "NOT"   :   0x05,\r
+            "TRUE"  :   0x06,\r
+            "FALSE" :   0x07,\r
+            "END"   :   0x08,\r
+            "SOR"   :   0x09\r
         }\r
     }\r
 \r
@@ -289,7 +304,7 @@ class DependencyExpression:
             return\r
 \r
         # don't generate depex if all operands are architecture protocols\r
-        if self.ModuleType in ['UEFI_DRIVER', 'DXE_DRIVER', 'DXE_RUNTIME_DRIVER', 'DXE_SAL_DRIVER', 'DXE_SMM_DRIVER'] and \\r
+        if self.ModuleType in ['UEFI_DRIVER', 'DXE_DRIVER', 'DXE_RUNTIME_DRIVER', 'DXE_SAL_DRIVER', 'DXE_SMM_DRIVER', 'MM_STANDALONE'] and \\r
            Op == 'AND' and \\r
            self.ArchProtocols == set([GuidStructureStringToGuidString(Guid) for Guid in AllOperand]):\r
             self.PostfixNotation = []\r