]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Add 4 Framework/PI SMM thunk drivers. Combined use of these drivers can support usage...
authorrsun3 <rsun3@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 31 Dec 2009 08:42:28 +0000 (08:42 +0000)
committerrsun3 <rsun3@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 31 Dec 2009 08:42:28 +0000 (08:42 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9657 6f19259b-4bc3-4df7-8a09-765794883524

17 files changed:
EdkCompatibilityPkg/Compatibility/Include/Guid/SmmBaseThunkCommunication.h [new file with mode: 0644]
EdkCompatibilityPkg/Compatibility/Include/Protocol/SmmBaseHelperReady.h [new file with mode: 0644]
EdkCompatibilityPkg/Compatibility/SmmAccess2OnSmmAccessThunk/SmmAccess2OnSmmAccessThunk.c [new file with mode: 0644]
EdkCompatibilityPkg/Compatibility/SmmAccess2OnSmmAccessThunk/SmmAccess2OnSmmAccessThunk.h [new file with mode: 0644]
EdkCompatibilityPkg/Compatibility/SmmAccess2OnSmmAccessThunk/SmmAccess2OnSmmAccessThunk.inf [new file with mode: 0644]
EdkCompatibilityPkg/Compatibility/SmmBaseHelper/SmmBaseHelper.c [new file with mode: 0644]
EdkCompatibilityPkg/Compatibility/SmmBaseHelper/SmmBaseHelper.h [new file with mode: 0644]
EdkCompatibilityPkg/Compatibility/SmmBaseHelper/SmmBaseHelper.inf [new file with mode: 0644]
EdkCompatibilityPkg/Compatibility/SmmBaseOnSmmBase2Thunk/SmmBaseOnSmmBase2Thunk.c [new file with mode: 0644]
EdkCompatibilityPkg/Compatibility/SmmBaseOnSmmBase2Thunk/SmmBaseOnSmmBase2Thunk.h [new file with mode: 0644]
EdkCompatibilityPkg/Compatibility/SmmBaseOnSmmBase2Thunk/SmmBaseOnSmmBase2Thunk.inf [new file with mode: 0644]
EdkCompatibilityPkg/Compatibility/SmmControl2OnSmmControlThunk/SmmControl2OnSmmControlThunk.c [new file with mode: 0644]
EdkCompatibilityPkg/Compatibility/SmmControl2OnSmmControlThunk/SmmControl2OnSmmControlThunk.h [new file with mode: 0644]
EdkCompatibilityPkg/Compatibility/SmmControl2OnSmmControlThunk/SmmControl2OnSmmControlThunk.inf [new file with mode: 0644]
EdkCompatibilityPkg/EdkCompatibilityPkg.dec
EdkCompatibilityPkg/EdkCompatibilityPkg.dsc
EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/EntryPoints/EdkIIGlueSmmDriverEntryPoint.c

diff --git a/EdkCompatibilityPkg/Compatibility/Include/Guid/SmmBaseThunkCommunication.h b/EdkCompatibilityPkg/Compatibility/Include/Guid/SmmBaseThunkCommunication.h
new file mode 100644 (file)
index 0000000..f8507e5
--- /dev/null
@@ -0,0 +1,85 @@
+/** @file\r
+  GUID and data structures for communication between SMM Base on SMM Base2 Thunk driver\r
+  and SmmBaseHelper driver.\r
+\r
+  Copyright (c) 2009, Intel Corporation\r
+  All rights reserved. This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#ifndef  _SMM_BASE_THUNK_COMMUNICATION_H_\r
+#define  _SMM_BASE_THUNK_COMMUNICATION_H_\r
+\r
+#include <Protocol/SmmBase.h>\r
+\r
+#define EFI_SMM_BASE_THUNK_COMMUNICATION_GUID \\r
+  { 0x6568a3d6, 0x15f, 0x4b4a, { 0x9c, 0x89, 0x1d, 0x14, 0x63, 0x14, 0x13, 0xa } }\r
+\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL       *FilePath;\r
+  VOID                           *SourceBuffer;\r
+  UINTN                          SourceSize;\r
+  EFI_HANDLE                     *ImageHandle;\r
+  BOOLEAN                        LegacyIA32Binary;\r
+} SMMBASE_REGISTER_ARG;\r
+\r
+typedef struct {\r
+  EFI_HANDLE                     ImageHandle;\r
+} SMMBASE_UNREGISTER_ARG;\r
+\r
+typedef struct {\r
+  EFI_HANDLE                     SmmImageHandle;\r
+  EFI_SMM_CALLBACK_ENTRY_POINT   CallbackAddress;\r
+  BOOLEAN                        MakeLast;\r
+  BOOLEAN                        FloatingPointSave;\r
+} SMMBASE_REGISTER_CALLBACK_ARG;\r
+\r
+typedef struct {\r
+  EFI_MEMORY_TYPE                PoolType;\r
+  UINTN                          Size;\r
+  VOID                           **Buffer;\r
+} SMMBASE_ALLOCATE_POOL_ARG;\r
+\r
+typedef struct {\r
+  VOID                           *Buffer;\r
+} SMMBASE_FREE_POOL_ARG;\r
+\r
+typedef union {\r
+  SMMBASE_REGISTER_ARG           Register;\r
+  SMMBASE_UNREGISTER_ARG         UnRegister;\r
+  SMMBASE_REGISTER_CALLBACK_ARG  RegisterCallback;\r
+  SMMBASE_ALLOCATE_POOL_ARG      AllocatePool;\r
+  SMMBASE_FREE_POOL_ARG          FreePool;\r
+} SMMBASE_FUNCTION_ARGS;\r
+\r
+typedef enum {\r
+  SMMBASE_REGISTER,\r
+  SMMBASE_UNREGISTER,\r
+  SMMBASE_REGISTER_CALLBACK,\r
+  SMMBASE_ALLOCATE_POOL,\r
+  SMMBASE_FREE_POOL,\r
+} SMMBASE_FUNCTION;\r
+\r
+typedef struct {\r
+  SMMBASE_FUNCTION               Function;\r
+  EFI_STATUS                     Status;\r
+  SMMBASE_FUNCTION_ARGS          Args;\r
+} SMMBASE_FUNCTION_DATA;\r
+\r
+#pragma pack(1)\r
+typedef struct {\r
+  EFI_GUID               HeaderGuid;\r
+  UINTN                  MessageLength;\r
+  SMMBASE_FUNCTION_DATA  FunctionData;\r
+} SMMBASETHUNK_COMMUNICATION_DATA;\r
+#pragma pack()\r
+\r
+extern EFI_GUID gEfiSmmBaseThunkCommunicationGuid;\r
+\r
+#endif\r
+\r
diff --git a/EdkCompatibilityPkg/Compatibility/Include/Protocol/SmmBaseHelperReady.h b/EdkCompatibilityPkg/Compatibility/Include/Protocol/SmmBaseHelperReady.h
new file mode 100644 (file)
index 0000000..45d645b
--- /dev/null
@@ -0,0 +1,44 @@
+/** @file\r
+  EFI SMM Base Helper Ready Protocol.\r
+\r
+  This UEFI protocol is produced by the SMM Base Helper SMM driver to provide\r
+  a Framework SMST to the SMM Base Thunk driver. This protocol is also an indicator\r
+  that the SMM Base Helper SMM driver is ready in SMRAM for communication with\r
+  the SMM Base Thunk driver.\r
+\r
+  Copyright (c) 2009, Intel Corporation\r
+  All rights reserved. This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __EFI_SMM_BASE_HELPER_READY_H__\r
+#define __EFI_SMM_BASE_HELPER_READY_H__\r
+\r
+#include <FrameworkSmm.h>\r
+#include <PiSmm.h>\r
+\r
+#define EFI_SMM_BASE_HELPER_READY_PROTOCOL_GUID  \\r
+  { \\r
+    0x910dca07, 0x1f94, 0x4ee7, { 0xaf, 0x2f, 0xff, 0x72, 0xf3, 0x15, 0x43, 0x53 } \\r
+  }\r
+\r
+typedef struct {\r
+  ///\r
+  /// Pointer to the Framework SMST built from PI SMST by SMM Base Helper SMM driver.\r
+  ///\r
+  EFI_SMM_SYSTEM_TABLE          *FrameworkSmst;\r
+  ///\r
+  /// Services function directly called by SMM Base Thunk when in SMM\r
+  ///\r
+  EFI_SMM_HANDLER_ENTRY_POINT2  ServiceEntry;\r
+} EFI_SMM_BASE_HELPER_READY_PROTOCOL;\r
+\r
+extern EFI_GUID gEfiSmmBaseHelperReadyProtocolGuid;\r
+\r
+#endif\r
diff --git a/EdkCompatibilityPkg/Compatibility/SmmAccess2OnSmmAccessThunk/SmmAccess2OnSmmAccessThunk.c b/EdkCompatibilityPkg/Compatibility/SmmAccess2OnSmmAccessThunk/SmmAccess2OnSmmAccessThunk.c
new file mode 100644 (file)
index 0000000..97df22c
--- /dev/null
@@ -0,0 +1,208 @@
+/** @file\r
+  SMM Access2 Protocol on SMM Access Protocol Thunk driver.\r
+\r
+  Copyright (c) 2009 Intel Corporation\r
+  All rights reserved. This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "SmmAccess2OnSmmAccessThunk.h"\r
+\r
+EFI_SMM_ACCESS2_PROTOCOL gSmmAccess2 = {\r
+  SmmAccess2Open,\r
+  SmmAccess2Close,\r
+  SmmAccess2Lock,\r
+  SmmAccess2GetCapabilities,\r
+  FALSE,\r
+  FALSE\r
+};\r
+\r
+EFI_SMM_ACCESS_PROTOCOL  *mSmmAccess;\r
+UINTN                     mSmramRegionNumber;\r
+\r
+/**\r
+  Opens the SMRAM area to be accessible by a boot-service driver.\r
+\r
+  This function "opens" SMRAM so that it is visible while not inside of SMM. The function should \r
+  return EFI_UNSUPPORTED if the hardware does not support hiding of SMRAM. The function \r
+  should return EFI_DEVICE_ERROR if the SMRAM configuration is locked.\r
+\r
+  @param[in] This           The EFI_SMM_ACCESS2_PROTOCOL instance.\r
+\r
+  @retval EFI_SUCCESS       The operation was successful.\r
+  @retval EFI_UNSUPPORTED   The system does not support opening and closing of SMRAM.\r
+  @retval EFI_DEVICE_ERROR  SMRAM cannot be opened, perhaps because it is locked.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmAccess2Open (\r
+  IN EFI_SMM_ACCESS2_PROTOCOL  *This\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  UINTN      DescriptorIndex;\r
+\r
+  ///\r
+  /// Open all SMRAM regions via SMM Access Protocol\r
+  ///\r
+\r
+  Status = EFI_SUCCESS;\r
+  for (DescriptorIndex = 0; DescriptorIndex < mSmramRegionNumber && !EFI_ERROR (Status); DescriptorIndex++) {\r
+    Status = mSmmAccess->Open (mSmmAccess, DescriptorIndex);\r
+  }\r
+  if (!EFI_ERROR (Status)) {\r
+    gSmmAccess2.OpenState = TRUE;\r
+  }\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Inhibits access to the SMRAM.\r
+\r
+  This function "closes" SMRAM so that it is not visible while outside of SMM. The function should \r
+  return EFI_UNSUPPORTED if the hardware does not support hiding of SMRAM.\r
+\r
+  @param[in] This           The EFI_SMM_ACCESS2_PROTOCOL instance.\r
+\r
+  @retval EFI_SUCCESS       The operation was successful.\r
+  @retval EFI_UNSUPPORTED   The system does not support opening and closing of SMRAM.\r
+  @retval EFI_DEVICE_ERROR  SMRAM cannot be closed.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmAccess2Close (\r
+  IN EFI_SMM_ACCESS2_PROTOCOL  *This\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  UINTN      DescriptorIndex;\r
+\r
+  ///\r
+  /// Close all SMRAM regions via SMM Access Protocol\r
+  ///\r
+\r
+  Status = EFI_SUCCESS;\r
+  for (DescriptorIndex = 0; DescriptorIndex < mSmramRegionNumber && !EFI_ERROR (Status); DescriptorIndex++) {\r
+    Status = mSmmAccess->Close (mSmmAccess, DescriptorIndex);\r
+  }\r
+  if (!EFI_ERROR (Status)) {\r
+    gSmmAccess2.OpenState = FALSE;\r
+  }\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Inhibits access to the SMRAM.\r
+\r
+  This function prohibits access to the SMRAM region.  This function is usually implemented such \r
+  that it is a write-once operation. \r
+\r
+  @param[in] This          The EFI_SMM_ACCESS2_PROTOCOL instance.\r
+\r
+  @retval EFI_SUCCESS      The device was successfully locked.\r
+  @retval EFI_UNSUPPORTED  The system does not support locking of SMRAM.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmAccess2Lock (\r
+  IN EFI_SMM_ACCESS2_PROTOCOL  *This\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  UINTN      DescriptorIndex;\r
+\r
+  ///\r
+  /// Lock all SMRAM regions via SMM Access Protocol\r
+  ///\r
+\r
+  Status = EFI_SUCCESS;\r
+  for (DescriptorIndex = 0; DescriptorIndex < mSmramRegionNumber && !EFI_ERROR (Status); DescriptorIndex++) {\r
+    Status = mSmmAccess->Lock (mSmmAccess, DescriptorIndex);\r
+  }\r
+  if (!EFI_ERROR (Status)) {\r
+    gSmmAccess2.LockState = TRUE;\r
+  }\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Queries the memory controller for the possible regions that will support SMRAM.\r
+\r
+  @param[in]     This           The EFI_SMM_ACCESS2_PROTOCOL instance.\r
+  @param[in,out] SmramMapSize   A pointer to the size, in bytes, of the SmramMemoryMap buffer.\r
+  @param[in,out] SmramMap       A pointer to the buffer in which firmware places the current memory map.\r
+\r
+  @retval EFI_SUCCESS           The chipset supported the given resource.\r
+  @retval EFI_BUFFER_TOO_SMALL  The SmramMap parameter was too small.  The current buffer size \r
+                                needed to hold the memory map is returned in SmramMapSize.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmAccess2GetCapabilities (\r
+  IN CONST EFI_SMM_ACCESS2_PROTOCOL  *This,\r
+  IN OUT UINTN                       *SmramMapSize,\r
+  IN OUT EFI_SMRAM_DESCRIPTOR        *SmramMap\r
+  )\r
+{\r
+  return mSmmAccess->GetCapabilities (mSmmAccess, SmramMapSize, SmramMap);\r
+}\r
+\r
+/**\r
+  Entry Point for SMM Access2 On SMM Access Thunk driver.\r
+\r
+  @param[in] ImageHandle  Image handle of this driver.\r
+  @param[in] SystemTable  A Pointer to the EFI System Table.\r
+\r
+  @retval EFI_SUCCESS  The entry point is executed successfully.\r
+  @retval other        Some error occurred when executing this entry point.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmAccess2ThunkMain (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  UINTN                 SmramMapSize;\r
+\r
+  ///\r
+  /// Locate SMM Access Protocol\r
+  ///\r
+  Status = gBS->LocateProtocol (&gEfiSmmAccessProtocolGuid, NULL, (VOID **)&mSmmAccess);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  ///\r
+  /// Calculate number of SMRAM regions\r
+  ///\r
+  SmramMapSize = 0;\r
+  Status = mSmmAccess->GetCapabilities (mSmmAccess, &SmramMapSize, NULL);\r
+  ASSERT (Status == EFI_BUFFER_TOO_SMALL);\r
+\r
+  mSmramRegionNumber =  SmramMapSize/sizeof (EFI_SMRAM_DESCRIPTOR);\r
+  ASSERT (mSmramRegionNumber > 0);\r
+\r
+  ///\r
+  /// Assume all SMRAM regions have consistent OPEN and LOCK states\r
+  ///\r
+  gSmmAccess2.OpenState = mSmmAccess->OpenState;\r
+  gSmmAccess2.LockState = mSmmAccess->LockState;\r
+\r
+  ///\r
+  /// Publish PI SMM Access2 Protocol\r
+  ///\r
+  Status = gBS->InstallProtocolInterface (\r
+                  &ImageHandle,\r
+                  &gEfiSmmAccess2ProtocolGuid,\r
+                  EFI_NATIVE_INTERFACE,\r
+                  &gSmmAccess2\r
+                  );\r
+  return Status;\r
+}\r
+\r
diff --git a/EdkCompatibilityPkg/Compatibility/SmmAccess2OnSmmAccessThunk/SmmAccess2OnSmmAccessThunk.h b/EdkCompatibilityPkg/Compatibility/SmmAccess2OnSmmAccessThunk/SmmAccess2OnSmmAccessThunk.h
new file mode 100644 (file)
index 0000000..bc34159
--- /dev/null
@@ -0,0 +1,99 @@
+/** @file\r
+  Include file for SMM Access2 Protocol on SMM Access Protocol Thunk driver.\r
+  \r
+  Copyright (c) 2009, Intel Corporation\r
+  All rights reserved. This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef  _SMM_ACCESS2_ON_SMM_ACCESS_THUNK_H_\r
+#define  _SMM_ACCESS2_ON_SMM_ACCESS_THUNK_H_\r
+\r
+#include <PiDxe.h>\r
+#include <FrameworkSmm.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Protocol/SmmAccess2.h>\r
+#include <Protocol/SmmAccess.h>\r
+\r
+/**\r
+  Opens the SMRAM area to be accessible by a boot-service driver.\r
+\r
+  This function "opens" SMRAM so that it is visible while not inside of SMM. The function should \r
+  return EFI_UNSUPPORTED if the hardware does not support hiding of SMRAM. The function \r
+  should return EFI_DEVICE_ERROR if the SMRAM configuration is locked.\r
+\r
+  @param[in] This           The EFI_SMM_ACCESS2_PROTOCOL instance.\r
+\r
+  @retval EFI_SUCCESS       The operation was successful.\r
+  @retval EFI_UNSUPPORTED   The system does not support opening and closing of SMRAM.\r
+  @retval EFI_DEVICE_ERROR  SMRAM cannot be opened, perhaps because it is locked.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmAccess2Open (\r
+  IN EFI_SMM_ACCESS2_PROTOCOL  *This\r
+  );\r
+\r
+/**\r
+  Inhibits access to the SMRAM.\r
+\r
+  This function "closes" SMRAM so that it is not visible while outside of SMM. The function should \r
+  return EFI_UNSUPPORTED if the hardware does not support hiding of SMRAM.\r
+\r
+  @param[in] This           The EFI_SMM_ACCESS2_PROTOCOL instance.\r
+\r
+  @retval EFI_SUCCESS       The operation was successful.\r
+  @retval EFI_UNSUPPORTED   The system does not support opening and closing of SMRAM.\r
+  @retval EFI_DEVICE_ERROR  SMRAM cannot be closed.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmAccess2Close (\r
+  IN EFI_SMM_ACCESS2_PROTOCOL  *This\r
+  );\r
+\r
+/**\r
+  Inhibits access to the SMRAM.\r
+\r
+  This function prohibits access to the SMRAM region.  This function is usually implemented such \r
+  that it is a write-once operation. \r
+\r
+  @param[in] This          The EFI_SMM_ACCESS2_PROTOCOL instance.\r
+\r
+  @retval EFI_SUCCESS      The device was successfully locked.\r
+  @retval EFI_UNSUPPORTED  The system does not support locking of SMRAM.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmAccess2Lock (\r
+  IN EFI_SMM_ACCESS2_PROTOCOL  *This\r
+  );\r
+\r
+/**\r
+  Queries the memory controller for the possible regions that will support SMRAM.\r
+\r
+  @param[in]     This           The EFI_SMM_ACCESS2_PROTOCOL instance.\r
+  @param[in,out] SmramMapSize   A pointer to the size, in bytes, of the SmramMemoryMap buffer.\r
+  @param[in,out] SmramMap       A pointer to the buffer in which firmware places the current memory map.\r
+\r
+  @retval EFI_SUCCESS           The chipset supported the given resource.\r
+  @retval EFI_BUFFER_TOO_SMALL  The SmramMap parameter was too small.  The current buffer size \r
+                                needed to hold the memory map is returned in SmramMapSize.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmAccess2GetCapabilities (\r
+  IN CONST EFI_SMM_ACCESS2_PROTOCOL  *This,\r
+  IN OUT UINTN                       *SmramMapSize,\r
+  IN OUT EFI_SMRAM_DESCRIPTOR        *SmramMap\r
+  );\r
+\r
+#endif  \r
diff --git a/EdkCompatibilityPkg/Compatibility/SmmAccess2OnSmmAccessThunk/SmmAccess2OnSmmAccessThunk.inf b/EdkCompatibilityPkg/Compatibility/SmmAccess2OnSmmAccessThunk/SmmAccess2OnSmmAccessThunk.inf
new file mode 100644 (file)
index 0000000..2262f43
--- /dev/null
@@ -0,0 +1,50 @@
+## @file\r
+#  Component description file for SMM Access2 Protocol on SMM Access Protocol Thunk driver.\r
+#\r
+#  Copyright (c) 2009, Intel Corporation\r
+#\r
+#  All rights reserved. This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = SmmAccess2OnSmmAccessThunk\r
+  FILE_GUID                      = 98BBCDA4-18B4-46d3-BD1F-6A3A52D44CF8\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  ENTRY_POINT                    = SmmAccess2ThunkMain\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64\r
+#\r
+\r
+[Sources]\r
+  SmmAccess2OnSmmAccessThunk.c\r
+  SmmAccess2OnSmmAccessThunk.h\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  IntelFrameworkPkg/IntelFrameworkPkg.dec\r
+  EdkCompatibilityPkg/EdkCompatibilityPkg.dec\r
+\r
+[LibraryClasses]\r
+  UefiDriverEntryPoint\r
+  UefiBootServicesTableLib\r
+  DebugLib\r
+\r
+[Protocols]\r
+  gEfiSmmAccessProtocolGuid             # PROTOCOL ALWAYS_CONSUMED\r
+  gEfiSmmAccess2ProtocolGuid            # PROTOCOL ALWAYS_PRODUCED\r
+\r
+[Depex]\r
+  gEfiSmmAccessProtocolGuid\r
+\r
diff --git a/EdkCompatibilityPkg/Compatibility/SmmBaseHelper/SmmBaseHelper.c b/EdkCompatibilityPkg/Compatibility/SmmBaseHelper/SmmBaseHelper.c
new file mode 100644 (file)
index 0000000..381f6ae
--- /dev/null
@@ -0,0 +1,698 @@
+/** @file\r
+  SMM Base Helper SMM driver.\r
+\r
+  This driver is the counterpart of the SMM Base On SMM Base2 Thunk driver. It\r
+  provides helping services in SMM to the SMM Base On SMM Base2 Thunk driver.\r
+\r
+  Copyright (c) 2009, Intel Corporation\r
+  All rights reserved. This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "SmmBaseHelper.h"\r
+\r
+EFI_HANDLE                         mDispatchHandle;\r
+EFI_SMM_CPU_PROTOCOL               *mSmmCpu;\r
+EFI_GUID                           mEfiSmmCpuIoGuid = EFI_SMM_CPU_IO_GUID;\r
+EFI_SMM_BASE_HELPER_READY_PROTOCOL *mSmmBaseHelperReady;\r
+EFI_SMM_SYSTEM_TABLE               *mFrameworkSmst;\r
+\r
+LIST_ENTRY mCallbackInfoListHead = INITIALIZE_LIST_HEAD_VARIABLE (mCallbackInfoListHead);\r
+\r
+CPU_SAVE_STATE_CONVERSION mCpuSaveStateConvTable[] = {\r
+  {EFI_SMM_SAVE_STATE_REGISTER_LDTBASE  , CPU_SAVE_STATE_GET_OFFSET(LDTBase)},\r
+  {EFI_SMM_SAVE_STATE_REGISTER_ES       , CPU_SAVE_STATE_GET_OFFSET(ES)},\r
+  {EFI_SMM_SAVE_STATE_REGISTER_CS       , CPU_SAVE_STATE_GET_OFFSET(CS)},\r
+  {EFI_SMM_SAVE_STATE_REGISTER_SS       , CPU_SAVE_STATE_GET_OFFSET(SS)},\r
+  {EFI_SMM_SAVE_STATE_REGISTER_DS       , CPU_SAVE_STATE_GET_OFFSET(DS)},\r
+  {EFI_SMM_SAVE_STATE_REGISTER_FS       , CPU_SAVE_STATE_GET_OFFSET(FS)},\r
+  {EFI_SMM_SAVE_STATE_REGISTER_GS       , CPU_SAVE_STATE_GET_OFFSET(GS)},\r
+  {EFI_SMM_SAVE_STATE_REGISTER_TR_SEL   , CPU_SAVE_STATE_GET_OFFSET(TR)},\r
+  {EFI_SMM_SAVE_STATE_REGISTER_DR7      , CPU_SAVE_STATE_GET_OFFSET(DR7)},\r
+  {EFI_SMM_SAVE_STATE_REGISTER_DR6      , CPU_SAVE_STATE_GET_OFFSET(DR6)},\r
+  {EFI_SMM_SAVE_STATE_REGISTER_RAX      , CPU_SAVE_STATE_GET_OFFSET(EAX)},\r
+  {EFI_SMM_SAVE_STATE_REGISTER_RBX      , CPU_SAVE_STATE_GET_OFFSET(EBX)},\r
+  {EFI_SMM_SAVE_STATE_REGISTER_RCX      , CPU_SAVE_STATE_GET_OFFSET(ECX)},\r
+  {EFI_SMM_SAVE_STATE_REGISTER_RDX      , CPU_SAVE_STATE_GET_OFFSET(EDX)},\r
+  {EFI_SMM_SAVE_STATE_REGISTER_RSP      , CPU_SAVE_STATE_GET_OFFSET(ESP)},\r
+  {EFI_SMM_SAVE_STATE_REGISTER_RBP      , CPU_SAVE_STATE_GET_OFFSET(EBP)},\r
+  {EFI_SMM_SAVE_STATE_REGISTER_RSI      , CPU_SAVE_STATE_GET_OFFSET(ESI)},\r
+  {EFI_SMM_SAVE_STATE_REGISTER_RDI      , CPU_SAVE_STATE_GET_OFFSET(EDI)},\r
+  {EFI_SMM_SAVE_STATE_REGISTER_RIP      , CPU_SAVE_STATE_GET_OFFSET(EIP)},\r
+  {EFI_SMM_SAVE_STATE_REGISTER_RFLAGS   , CPU_SAVE_STATE_GET_OFFSET(EFLAGS)},\r
+  {EFI_SMM_SAVE_STATE_REGISTER_CR0      , CPU_SAVE_STATE_GET_OFFSET(CR0)},\r
+  {EFI_SMM_SAVE_STATE_REGISTER_CR3      , CPU_SAVE_STATE_GET_OFFSET(CR3)}\r
+};\r
+\r
+/**\r
+  Framework SMST SmmInstallConfigurationTable() Thunk.\r
+\r
+  This thunk calls the PI SMM SmmInstallConfigurationTable() and then update the configuration\r
+  table related fields in the Framework SMST because the PI SMM SmmInstallConfigurationTable()\r
+  function may modify these fields.\r
+\r
+  @param[in] SystemTable         A pointer to the SMM System Table.\r
+  @param[in] Guid                A pointer to the GUID for the entry to add, update, or remove.\r
+  @param[in] Table               A pointer to the buffer of the table to add.\r
+  @param[in] TableSize           The size of the table to install.\r
+\r
+  @retval EFI_SUCCESS            The (Guid, Table) pair was added, updated, or removed.\r
+  @retval EFI_INVALID_PARAMETER  Guid is not valid.\r
+  @retval EFI_NOT_FOUND          An attempt was made to delete a non-existent entry.\r
+  @retval EFI_OUT_OF_RESOURCES   There is not enough memory available to complete the operation.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmInstallConfigurationTable (\r
+  IN EFI_SMM_SYSTEM_TABLE  *SystemTable,\r
+  IN EFI_GUID              *Guid,\r
+  IN VOID                  *Table,\r
+  IN UINTN                 TableSize\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  \r
+  Status = gSmst->SmmInstallConfigurationTable (gSmst, Guid, Table, TableSize);\r
+  if (!EFI_ERROR (Status)) {\r
+    mFrameworkSmst->NumberOfTableEntries = gSmst->NumberOfTableEntries;\r
+    mFrameworkSmst->SmmConfigurationTable = gSmst->SmmConfigurationTable;\r
+  }\r
+  return Status;         \r
+}\r
+\r
+/**\r
+  Construct a Framework SMST based on the PI SMM SMST.\r
+\r
+  @return  Pointer to the constructed Framework SMST.\r
+**/\r
+EFI_SMM_SYSTEM_TABLE *\r
+ConstructFrameworkSmst (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  EFI_SMM_SYSTEM_TABLE  *FrameworkSmst;\r
+\r
+  Status = gSmst->SmmAllocatePool (\r
+                    EfiRuntimeServicesData,\r
+                    sizeof (EFI_SMM_SYSTEM_TABLE),\r
+                    (VOID **)&FrameworkSmst\r
+                    );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  ///\r
+  /// Copy same things from PI SMST to Framework SMST\r
+  ///\r
+  CopyMem (FrameworkSmst, gSmst, (UINTN)(&((EFI_SMM_SYSTEM_TABLE *)0)->SmmIo));\r
+  CopyMem (\r
+    &FrameworkSmst->SmmIo, \r
+    &gSmst->SmmIo,\r
+    sizeof (EFI_SMM_SYSTEM_TABLE) - (UINTN)(&((EFI_SMM_SYSTEM_TABLE *)0)->SmmIo)\r
+    );\r
+\r
+  ///\r
+  /// Update Framework SMST\r
+  ///\r
+  FrameworkSmst->Hdr.Revision = EFI_SMM_SYSTEM_TABLE_REVISION;\r
+  CopyGuid (&FrameworkSmst->EfiSmmCpuIoGuid, &mEfiSmmCpuIoGuid);\r
+\r
+  Status = gSmst->SmmAllocatePool (\r
+                    EfiRuntimeServicesData,\r
+                    gSmst->NumberOfCpus * sizeof (EFI_SMI_CPU_SAVE_STATE),\r
+                    (VOID **)&FrameworkSmst->CpuSaveState\r
+                    );\r
+  ASSERT_EFI_ERROR (Status);\r
+  ZeroMem (FrameworkSmst->CpuSaveState, gSmst->NumberOfCpus * sizeof (EFI_SMI_CPU_SAVE_STATE));\r
+\r
+  ///\r
+  /// Do not support floating point state now\r
+  ///\r
+  FrameworkSmst->CpuOptionalFloatingPointState = NULL;\r
+\r
+  FrameworkSmst->SmmInstallConfigurationTable = SmmInstallConfigurationTable;\r
+\r
+  return FrameworkSmst;\r
+}\r
+\r
+/**\r
+  Load a given Framework SMM driver into SMRAM and invoke its entry point.\r
+\r
+  @param[in]   FilePath              Location of the image to be installed as the handler.\r
+  @param[in]   SourceBuffer          Optional source buffer in case the image file\r
+                                     is in memory.\r
+  @param[in]   SourceSize            Size of the source image file, if in memory.\r
+  @param[out]  ImageHandle           The handle that the base driver uses to decode \r
+                                     the handler. Unique among SMM handlers only, \r
+                                     not unique across DXE/EFI.\r
+\r
+  @retval      EFI_SUCCESS           The operation was successful.\r
+  @retval      EFI_OUT_OF_RESOURCES  There were no additional SMRAM resources to load the handler\r
+  @retval      EFI_UNSUPPORTED       Can not find its copy in normal memory.\r
+  @retval      EFI_INVALID_PARAMETER The handlers was not the correct image type\r
+**/\r
+EFI_STATUS\r
+LoadImage (\r
+  IN      EFI_DEVICE_PATH_PROTOCOL  *FilePath,\r
+  IN      VOID                      *SourceBuffer,\r
+  IN      UINTN                     SourceSize,\r
+  OUT     EFI_HANDLE                *ImageHandle\r
+  )\r
+{\r
+  EFI_STATUS                    Status;\r
+  UINTN                         PageCount;\r
+  EFI_PHYSICAL_ADDRESS          Buffer;\r
+  PE_COFF_LOADER_IMAGE_CONTEXT  ImageContext;\r
+  EFI_HANDLE                    PesudoImageHandle;\r
+  UINTN                         NumHandles;\r
+  UINTN                         Index;\r
+  EFI_HANDLE                    *HandleBuffer;\r
+  EFI_LOADED_IMAGE_PROTOCOL     *LoadedImage;\r
+  EFI_DEVICE_PATH               *LoadedImageDevicePath;\r
+  UINTN                         DevicePathSize;\r
+\r
+  if (FilePath == NULL || ImageHandle == NULL) {    \r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  ///\r
+  /// Assume Framework SMM driver has an image copy in memory before registering itself into SMRAM.\r
+  /// Currently only supports load Framework SMM driver from existing image copy in memory.\r
+  /// Load PE32 Image Protocol can be used to support loading Framework SMM driver directly from FV.\r
+  ///\r
+  if (SourceBuffer == NULL) {\r
+    Status = gBS->LocateHandleBuffer (\r
+                    ByProtocol,\r
+                    &gEfiLoadedImageDevicePathProtocolGuid,\r
+                    NULL,\r
+                    &NumHandles,\r
+                    &HandleBuffer\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      return EFI_UNSUPPORTED;\r
+    }\r
+\r
+    DevicePathSize = GetDevicePathSize (FilePath);\r
+\r
+    for (Index = 0; Index < NumHandles; Index++) {\r
+      Status = gBS->HandleProtocol (\r
+                      HandleBuffer[Index],\r
+                      &gEfiLoadedImageDevicePathProtocolGuid,\r
+                      (VOID **)&LoadedImageDevicePath\r
+                      );\r
+      ASSERT_EFI_ERROR (Status);\r
+\r
+      if (GetDevicePathSize (LoadedImageDevicePath) == DevicePathSize &&\r
+          CompareMem (LoadedImageDevicePath, FilePath, DevicePathSize) == 0) {\r
+          break;\r
+      }     \r
+    }\r
+\r
+    if (Index < NumHandles) {\r
+      Status = gBS->HandleProtocol (\r
+                      HandleBuffer[Index],\r
+                      &gEfiLoadedImageProtocolGuid,\r
+                      (VOID **)&LoadedImage\r
+                      );\r
+      ASSERT_EFI_ERROR (Status);\r
+      \r
+      SourceBuffer = LoadedImage->ImageBase;\r
+      gBS->FreePool (HandleBuffer);\r
+    } else {\r
+      gBS->FreePool (HandleBuffer);\r
+      return EFI_UNSUPPORTED;\r
+    }\r
+  }\r
+\r
+  ImageContext.Handle = SourceBuffer;\r
+  ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;\r
+\r
+  ///\r
+  /// Get information about the image being loaded\r
+  ///\r
+  Status = PeCoffLoaderGetImageInfo (&ImageContext);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  ///\r
+  /// Allocate buffer for loading image into SMRAM\r
+  ///\r
+  PageCount = (UINTN)EFI_SIZE_TO_PAGES (ImageContext.ImageSize + ImageContext.SectionAlignment);\r
+  Status = gSmst->SmmAllocatePages (AllocateAnyPages, EfiRuntimeServicesCode, PageCount, &Buffer);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  ImageContext.ImageAddress = (PHYSICAL_ADDRESS)Buffer;\r
+\r
+  ///\r
+  /// Align buffer on section boundry\r
+  ///\r
+  ImageContext.ImageAddress += ImageContext.SectionAlignment - 1;\r
+  ImageContext.ImageAddress &= ~(ImageContext.SectionAlignment - 1);\r
+\r
+  ///\r
+  /// Load the image into SMRAM\r
+  ///\r
+  Status = PeCoffLoaderLoadImage (&ImageContext);\r
+  if (EFI_ERROR (Status)) {\r
+    goto Error;\r
+  }\r
+\r
+  ///\r
+  /// Relocate the image in our new buffer\r
+  ///\r
+  Status = PeCoffLoaderRelocateImage (&ImageContext);\r
+  if (EFI_ERROR (Status)) {\r
+    goto Error;\r
+  }\r
+\r
+  ///\r
+  /// Flush the instruction cache so the image data are written before we execute it\r
+  ///\r
+  InvalidateInstructionCacheRange ((VOID *)(UINTN) ImageContext.ImageAddress, (UINTN) ImageContext.ImageSize);\r
+\r
+  ///\r
+  /// Update MP state in Framework SMST before transferring control to Framework SMM driver entry point\r
+  /// in case it may invoke AP\r
+  ///\r
+  mFrameworkSmst->CurrentlyExecutingCpu = gSmst->CurrentlyExecutingCpu;\r
+\r
+  ///\r
+  /// For Framework SMM, ImageHandle does not have to be a UEFI image handle.  The only requirement is that the \r
+  /// ImageHandle is a unique value.  Use image base address as the unique value.\r
+  ///\r
+  PesudoImageHandle = (EFI_HANDLE)(UINTN)ImageContext.ImageAddress;\r
+\r
+  Status = ((EFI_IMAGE_ENTRY_POINT)(UINTN)ImageContext.EntryPoint) (PesudoImageHandle, gST);\r
+  if (!EFI_ERROR (Status)) {\r
+    *ImageHandle = PesudoImageHandle;\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+Error:\r
+  gSmst->SmmFreePages (Buffer, PageCount);\r
+  return Status;\r
+}\r
+\r
+/** \r
+  Thunk service of EFI_SMM_BASE_PROTOCOL.Register().\r
+\r
+  @param[in] FunctionData  Pointer to SMMBASE_FUNCTION_DATA.\r
+*/\r
+VOID\r
+Register (\r
+  IN OUT SMMBASE_FUNCTION_DATA *FunctionData\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+\r
+  if (FunctionData->Args.Register.LegacyIA32Binary) {\r
+    Status = EFI_UNSUPPORTED;\r
+  } else {\r
+    Status = LoadImage (\r
+               FunctionData->Args.Register.FilePath,\r
+               FunctionData->Args.Register.SourceBuffer,\r
+               FunctionData->Args.Register.SourceSize,\r
+               FunctionData->Args.Register.ImageHandle\r
+               );\r
+  }\r
+  FunctionData->Status = Status;\r
+}\r
+\r
+/** \r
+  Thunk service of EFI_SMM_BASE_PROTOCOL.UnRegister().\r
+\r
+  @param[in] FunctionData  Pointer to SMMBASE_FUNCTION_DATA.\r
+*/\r
+VOID\r
+UnRegister (\r
+  IN OUT SMMBASE_FUNCTION_DATA *FunctionData\r
+  )\r
+{\r
+  ///\r
+  /// Unregister not supported now\r
+  ///\r
+  FunctionData->Status = EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+  Search for Framework SMI handler information according to specific PI SMM dispatch handle.\r
+\r
+  @param[in] DispatchHandle  The unique handle assigned by SmiHandlerRegister().  \r
+\r
+  @return  Pointer to CALLBACK_INFO.\r
+**/\r
+CALLBACK_INFO *\r
+GetCallbackInfo (\r
+  IN EFI_HANDLE  DispatchHandle\r
+  )\r
+{\r
+  LIST_ENTRY  *Node;\r
+\r
+  Node = GetFirstNode (&mCallbackInfoListHead);\r
+  while (!IsNull (&mCallbackInfoListHead, Node)) {\r
+    if (((CALLBACK_INFO *)Node)->DispatchHandle == DispatchHandle) {\r
+      return (CALLBACK_INFO *)Node;\r
+    }\r
+    Node = GetNextNode (&mCallbackInfoListHead, Node);\r
+  }\r
+  return NULL;\r
+}\r
+\r
+/**\r
+  Callback thunk for Framework SMI handler.\r
+\r
+  This thunk functions calls the Framework SMI handler and converts the return value\r
+  defined from Framework SMI handlers to a correpsonding return value defined by PI SMM.\r
+\r
+  @param[in]     DispatchHandle  The unique handle assigned to this handler by SmiHandlerRegister().\r
+  @param[in]     Context         Points to an optional handler context which was specified when the\r
+                                 handler was registered.\r
+  @param[in,out] CommBuffer      A pointer to a collection of data in memory that will\r
+                                 be conveyed from a non-SMM environment into an SMM environment.\r
+  @param[in,out] CommBufferSize  The size of the CommBuffer.\r
+\r
+  @retval EFI_SUCCESS                         The interrupt was handled and quiesced. No other handlers \r
+                                              should still be called.\r
+  @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED  The interrupt has been quiesced but other handlers should \r
+                                              still be called.\r
+  @retval EFI_WARN_INTERRUPT_SOURCE_PENDING   The interrupt is still pending and other handlers should still \r
+                                              be called.\r
+  @retval EFI_INTERRUPT_PENDING               The interrupt could not be quiesced.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CallbackThunk (\r
+  IN EFI_HANDLE  DispatchHandle,\r
+  IN CONST VOID  *Context         OPTIONAL,\r
+  IN OUT VOID    *CommBuffer      OPTIONAL,\r
+  IN OUT UINTN   *CommBufferSize  OPTIONAL\r
+  )\r
+{\r
+  EFI_STATUS        Status;\r
+  CALLBACK_INFO     *CallbackInfo;\r
+  UINTN             Index;\r
+  UINTN             CpuIndex;\r
+  EFI_SMM_CPU_STATE *State;\r
+  EFI_SMI_CPU_SAVE_STATE *SaveState;\r
+\r
+  ///\r
+  /// Before transferring the control into the Framework SMI handler, update CPU Save States\r
+  /// and MP states in the Framework SMST.\r
+  ///\r
+\r
+  for (CpuIndex = 0; CpuIndex < gSmst->NumberOfCpus; CpuIndex++) {\r
+    State = (EFI_SMM_CPU_STATE *)gSmst->CpuSaveState[CpuIndex];\r
+    SaveState = &mFrameworkSmst->CpuSaveState[CpuIndex].Ia32SaveState;\r
+\r
+    if (State->x86.SMMRevId < EFI_SMM_MIN_REV_ID_x64) {\r
+      SaveState->SMBASE = State->x86.SMBASE;\r
+      SaveState->SMMRevId = State->x86.SMMRevId;\r
+      SaveState->IORestart = State->x86.IORestart;\r
+      SaveState->AutoHALTRestart = State->x86.AutoHALTRestart;\r
+    } else {\r
+      SaveState->SMBASE = State->x64.SMBASE;\r
+      SaveState->SMMRevId = State->x64.SMMRevId;\r
+      SaveState->IORestart = State->x64.IORestart;\r
+      SaveState->AutoHALTRestart = State->x64.AutoHALTRestart;\r
+    }\r
+\r
+    for (Index = 0; Index < sizeof (mCpuSaveStateConvTable) / sizeof (CPU_SAVE_STATE_CONVERSION); Index++) {\r
+      ///\r
+      /// Try to use SMM CPU Protocol to access CPU save states if possible\r
+      ///\r
+      Status = mSmmCpu->ReadSaveState (\r
+                          mSmmCpu,\r
+                          EFI_SMM_SAVE_STATE_IO_WIDTH_UINT32,\r
+                          mCpuSaveStateConvTable[Index].Register,\r
+                          CpuIndex,\r
+                          ((UINT8 *)SaveState) + mCpuSaveStateConvTable[Index].Offset\r
+                          );\r
+      ASSERT_EFI_ERROR (Status);\r
+    }\r
+  }\r
+\r
+  mFrameworkSmst->CurrentlyExecutingCpu = gSmst->CurrentlyExecutingCpu;\r
+\r
+  ///\r
+  /// Search for Framework SMI handler information\r
+  ///\r
+  CallbackInfo = GetCallbackInfo (DispatchHandle);\r
+  ASSERT (CallbackInfo != NULL);\r
+\r
+  ///\r
+  /// Thunk into original Framwork SMI handler\r
+  ///\r
+  Status = (CallbackInfo->CallbackAddress) (\r
+                            CallbackInfo->SmmImageHandle,\r
+                            CommBuffer,\r
+                            CommBufferSize\r
+                            );\r
+  ///\r
+  /// Save CPU Save States in case any of them was modified\r
+  ///\r
+  for (CpuIndex = 0; CpuIndex < gSmst->NumberOfCpus; CpuIndex++) {\r
+    for (Index = 0; Index < sizeof (mCpuSaveStateConvTable) / sizeof (CPU_SAVE_STATE_CONVERSION); Index++) {\r
+      Status = mSmmCpu->WriteSaveState (\r
+                          mSmmCpu,\r
+                          EFI_SMM_SAVE_STATE_IO_WIDTH_UINT32,\r
+                          mCpuSaveStateConvTable[Index].Register,\r
+                          CpuIndex,\r
+                          ((UINT8 *)&mFrameworkSmst->CpuSaveState[CpuIndex].Ia32SaveState) + \r
+                          mCpuSaveStateConvTable[Index].Offset\r
+                          );\r
+    }\r
+  }\r
+\r
+  ///\r
+  /// Conversion of returned status code\r
+  ///\r
+  switch (Status) {\r
+    case EFI_HANDLER_SUCCESS:\r
+      Status = EFI_WARN_INTERRUPT_SOURCE_QUIESCED;\r
+      break;\r
+    case EFI_HANDLER_CRITICAL_EXIT:\r
+    case EFI_HANDLER_SOURCE_QUIESCED:\r
+      Status = EFI_SUCCESS;\r
+      break;\r
+    case EFI_HANDLER_SOURCE_PENDING:\r
+      Status = EFI_WARN_INTERRUPT_SOURCE_PENDING;\r
+      break;\r
+  }\r
+  return Status;\r
+}\r
+\r
+/** \r
+  Thunk service of EFI_SMM_BASE_PROTOCOL.RegisterCallback().\r
+\r
+  @param[in] FunctionData  Pointer to SMMBASE_FUNCTION_DATA.\r
+*/\r
+VOID\r
+RegisterCallback (\r
+  IN OUT SMMBASE_FUNCTION_DATA *FunctionData\r
+  )\r
+{\r
+  EFI_STATUS     Status;\r
+  CALLBACK_INFO  *Buffer;\r
+\r
+  ///\r
+  /// Note that MakeLast and FloatingPointSave options are not supported in PI SMM\r
+  ///\r
+\r
+  ///\r
+  /// Allocate buffer for callback thunk information\r
+  ///\r
+  Status = gSmst->SmmAllocatePool (\r
+                    EfiRuntimeServicesCode,\r
+                    sizeof (CALLBACK_INFO),\r
+                    (VOID **)&Buffer\r
+                    );\r
+  if (!EFI_ERROR (Status)) {\r
+    ///\r
+    /// Fill SmmImageHandle and CallbackAddress into the thunk\r
+    ///\r
+    Buffer->SmmImageHandle = FunctionData->Args.RegisterCallback.SmmImageHandle;\r
+    Buffer->CallbackAddress = FunctionData->Args.RegisterCallback.CallbackAddress;\r
+\r
+    ///\r
+    /// Register the thunk code as a root SMI handler\r
+    ///\r
+    Status = gSmst->SmiHandlerRegister (\r
+                      CallbackThunk,\r
+                      NULL,\r
+                      &Buffer->DispatchHandle\r
+                      );\r
+    if (!EFI_ERROR (Status)) {\r
+      ///\r
+      /// Save this callback info\r
+      ///\r
+      InsertTailList (&mCallbackInfoListHead, &Buffer->Link);\r
+    } else {\r
+      gSmst->SmmFreePool (Buffer);\r
+    }\r
+  }\r
+  FunctionData->Status = Status;\r
+}\r
+\r
+\r
+/** \r
+  Thunk service of EFI_SMM_BASE_PROTOCOL.SmmAllocatePool().\r
+\r
+  @param[in] FunctionData  Pointer to SMMBASE_FUNCTION_DATA.\r
+*/\r
+VOID\r
+HelperAllocatePool (\r
+  IN OUT SMMBASE_FUNCTION_DATA *FunctionData\r
+  )\r
+{\r
+  FunctionData->Status = gSmst->SmmAllocatePool (\r
+                                  FunctionData->Args.AllocatePool.PoolType,\r
+                                  FunctionData->Args.AllocatePool.Size,\r
+                                  FunctionData->Args.AllocatePool.Buffer\r
+                                  );\r
+}\r
+\r
+/** \r
+  Thunk service of EFI_SMM_BASE_PROTOCOL.SmmFreePool().\r
+\r
+  @param[in] FunctionData  Pointer to SMMBASE_FUNCTION_DATA.\r
+*/\r
+VOID\r
+HelperFreePool (\r
+  IN OUT SMMBASE_FUNCTION_DATA *FunctionData\r
+  )\r
+{\r
+  FunctionData->Status = gSmst->SmmFreePool (\r
+                                  FunctionData->Args.FreePool.Buffer\r
+                                  );\r
+}\r
+\r
+/**\r
+  Communication service SMI Handler entry.\r
+\r
+  This SMI handler provides services for the SMM Base Thunk driver.\r
+\r
+  @param[in]     DispatchHandle  The unique handle assigned to this handler by SmiHandlerRegister().\r
+  @param[in]     Context         Points to an optional handler context which was specified when the\r
+                                 handler was registered.\r
+  @param[in,out] CommBuffer      A pointer to a collection of data in memory that will\r
+                                 be conveyed from a non-SMM environment into an SMM environment.\r
+  @param[in,out] CommBufferSize  The size of the CommBuffer.\r
+\r
+  @retval EFI_SUCCESS                         The interrupt was handled and quiesced. No other handlers \r
+                                              should still be called.\r
+  @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED  The interrupt has been quiesced but other handlers should \r
+                                              still be called.\r
+  @retval EFI_WARN_INTERRUPT_SOURCE_PENDING   The interrupt is still pending and other handlers should still \r
+                                              be called.\r
+  @retval EFI_INTERRUPT_PENDING               The interrupt could not be quiesced.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmHandlerEntry (\r
+  IN     EFI_HANDLE               DispatchHandle,\r
+  IN     CONST VOID               *RegisterContext,\r
+  IN OUT VOID                     *CommBuffer,\r
+  IN OUT UINTN                    *CommBufferSize\r
+  )\r
+{\r
+  SMMBASE_FUNCTION_DATA *FunctionData;\r
+\r
+  ASSERT (CommBuffer != NULL);\r
+  ASSERT (*CommBufferSize == sizeof (SMMBASE_FUNCTION_DATA));\r
+\r
+  FunctionData = (SMMBASE_FUNCTION_DATA *)CommBuffer;\r
+\r
+  switch (FunctionData->Function) {\r
+    case SMMBASE_REGISTER:\r
+      Register (FunctionData);\r
+      break;\r
+    case SMMBASE_UNREGISTER:\r
+      UnRegister (FunctionData);\r
+      break;\r
+    case SMMBASE_REGISTER_CALLBACK:\r
+      RegisterCallback (FunctionData);\r
+      break;\r
+    case SMMBASE_ALLOCATE_POOL:\r
+      HelperAllocatePool (FunctionData);\r
+      break;\r
+    case SMMBASE_FREE_POOL:\r
+      HelperFreePool (FunctionData);\r
+      break;\r
+    default:\r
+      ASSERT (FALSE);\r
+      FunctionData->Status = EFI_UNSUPPORTED;\r
+  }\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Entry point function of the SMM Base Helper SMM driver.\r
+\r
+  @param[in] ImageHandle  The firmware allocated handle for the EFI image.  \r
+  @param[in] SystemTable  A pointer to the EFI System Table.\r
+  \r
+  @retval EFI_SUCCESS     The entry point is executed successfully.\r
+  @retval other           Some error occurs when executing this entry point.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmBaseHelperMain (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  EFI_HANDLE  Handle = NULL;\r
+\r
+  ///\r
+  /// Locate SMM CPU Protocol which is used later to update CPU Save States\r
+  ///\r
+  Status = gSmst->SmmLocateProtocol (&gEfiSmmCpuProtocolGuid, NULL, (VOID **) &mSmmCpu);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  ///\r
+  /// Interface structure of SMM BASE Helper Ready Protocol is allocated from UEFI pool\r
+  /// instead of SMM pool so that SMM Base Thunk driver can access it in Non-SMM mode.\r
+  ///\r
+  Status = gBS->AllocatePool (\r
+                  EfiBootServicesData,\r
+                  sizeof (EFI_SMM_BASE_HELPER_READY_PROTOCOL),\r
+                  (VOID **)&mSmmBaseHelperReady\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  ///\r
+  /// Construct Framework SMST from PI SMST\r
+  ///\r
+  mFrameworkSmst = ConstructFrameworkSmst ();\r
+  mSmmBaseHelperReady->FrameworkSmst = mFrameworkSmst;\r
+  mSmmBaseHelperReady->ServiceEntry = SmmHandlerEntry;\r
+\r
+  ///\r
+  /// Register SMM Base Helper services for SMM Base Thunk driver\r
+  ///\r
+  Status = gSmst->SmiHandlerRegister (SmmHandlerEntry, &gEfiSmmBaseThunkCommunicationGuid, &mDispatchHandle);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  ///\r
+  /// Install EFI SMM Base Helper Protocol in the UEFI handle database\r
+  ///\r
+  Status = gBS->InstallProtocolInterface (\r
+                  &Handle,\r
+                  &gEfiSmmBaseHelperReadyProtocolGuid,\r
+                  EFI_NATIVE_INTERFACE,\r
+                  mSmmBaseHelperReady\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Status;\r
+}\r
+\r
diff --git a/EdkCompatibilityPkg/Compatibility/SmmBaseHelper/SmmBaseHelper.h b/EdkCompatibilityPkg/Compatibility/SmmBaseHelper/SmmBaseHelper.h
new file mode 100644 (file)
index 0000000..b372f70
--- /dev/null
@@ -0,0 +1,57 @@
+/** @file\r
+  Include file for SMM Base Helper SMM driver.\r
+  \r
+  Copyright (c) 2009, Intel Corporation\r
+  All rights reserved. This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef  _SMM_BASE_HELPER_H_\r
+#define  _SMM_BASE_HELPER_H_\r
+\r
+#include <PiSmm.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/SmmServicesTableLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/PeCoffLib.h>\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/CacheMaintenanceLib.h>\r
+#include <Guid/SmmBaseThunkCommunication.h>\r
+#include <Protocol/SmmBaseHelperReady.h>\r
+#include <Protocol/SmmCpu.h>\r
+#include <Protocol/LoadedImage.h>\r
+#include <Common/CpuSaveState.h>\r
+\r
+///\r
+/// Structure for tracking paired information of registered Framework SMI handler\r
+/// and correpsonding dispatch handle for SMI handler thunk.\r
+///\r
+typedef struct {\r
+  LIST_ENTRY                    Link;\r
+  EFI_HANDLE                    DispatchHandle;\r
+  EFI_HANDLE                    SmmImageHandle;\r
+  EFI_SMM_CALLBACK_ENTRY_POINT  CallbackAddress;\r
+} CALLBACK_INFO;\r
+\r
+typedef struct {\r
+  ///\r
+  /// PI SMM CPU Save State register index\r
+  ///\r
+  EFI_SMM_SAVE_STATE_REGISTER   Register;\r
+  ///\r
+  /// Offset in Framework SMST\r
+  ///\r
+  UINTN                         Offset;\r
+} CPU_SAVE_STATE_CONVERSION;\r
+\r
+#define CPU_SAVE_STATE_GET_OFFSET(Field)  (UINTN)(&(((EFI_SMM_CPU_SAVE_STATE *) 0)->Ia32SaveState.Field))\r
+\r
+#endif  \r
diff --git a/EdkCompatibilityPkg/Compatibility/SmmBaseHelper/SmmBaseHelper.inf b/EdkCompatibilityPkg/Compatibility/SmmBaseHelper/SmmBaseHelper.inf
new file mode 100644 (file)
index 0000000..6a12600
--- /dev/null
@@ -0,0 +1,62 @@
+## @file\r
+#  Component description file for SMM Base Helper SMM driver.\r
+#\r
+#  Copyright (c) 2009, Intel Corporation.\r
+#\r
+#  All rights reserved. This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = SmmBaseHelper\r
+  FILE_GUID                      = 8C87E0A0-B390-4be3-819C-7C6C83CAE4EB\r
+  MODULE_TYPE                    = DXE_SMM_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  PI_SPECIFICATION_VERSION       = 0x0001000A\r
+\r
+  ENTRY_POINT                    = SmmBaseHelperMain\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 \r
+#\r
+\r
+[Sources]\r
+  SmmBaseHelper.c\r
+  SmmBaseHelper.h\r
\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  IA32FamilyCpuPkg/IA32FamilyCpuPkg.dec\r
+  IntelFrameworkPkg/IntelFrameworkPkg.dec\r
+  EdkCompatibilityPkg/EdkCompatibilityPkg.dec\r
+\r
+[LibraryClasses]\r
+  UefiDriverEntryPoint\r
+  UefiBootServicesTableLib\r
+  SmmServicesTableLib\r
+  BaseMemoryLib\r
+  PeCoffLib\r
+  DevicePathLib\r
+  CacheMaintenanceLib\r
+\r
+[Guids]\r
+  gEfiSmmBaseThunkCommunicationGuid\r
+\r
+[Protocols]\r
+  gEfiSmmBaseHelperReadyProtocolGuid     # PROTOCOL ALWAYS_PRODUCED\r
+  gEfiSmmCpuProtocolGuid                 # PROTOCOL ALWAYS_CONSUMED\r
+  gEfiLoadedImageProtocolGuid            # PROTOCOL ALWAYS_CONSUMED\r
+  gEfiLoadedImageDevicePathProtocolGuid  # PROTOCOL ALWAYS_CONSUMED\r
+\r
+[Depex]\r
+  gEfiSmmCpuProtocolGuid\r
+\r
diff --git a/EdkCompatibilityPkg/Compatibility/SmmBaseOnSmmBase2Thunk/SmmBaseOnSmmBase2Thunk.c b/EdkCompatibilityPkg/Compatibility/SmmBaseOnSmmBase2Thunk/SmmBaseOnSmmBase2Thunk.c
new file mode 100644 (file)
index 0000000..fe6024a
--- /dev/null
@@ -0,0 +1,512 @@
+/** @file\r
+  SMM Base Protocol on SMM Base2 Protocol Thunk driver.\r
+\r
+  This driver co-operates with SMM Base Helper SMM driver to provide SMM Base Protocol\r
+  based on SMM Base2 Protocol.\r
+\r
+  This thunk driver is expected to be loaded before PI SMM IPL driver so that\r
+  SMM BASE Protocol can be published immediately after SMM Base2 Protocol is installed to\r
+  make SMM Base Protocol.InSmm() as early as possible.\r
+\r
+  Copyright (c) 2009 Intel Corporation\r
+  All rights reserved. This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include  "SmmBaseOnSmmBase2Thunk.h"\r
+\r
+EFI_SMM_BASE_PROTOCOL gSmmBase = {\r
+  SmmBaseRegister,\r
+  SmmBaseUnregister,\r
+  SmmBaseCommunicate,\r
+  SmmBaseRegisterCallback,\r
+  SmmBaseInSmm,\r
+  SmmBaseSmmAllocatePool,\r
+  SmmBaseSmmFreePool,\r
+  SmmBaseGetSmstLocation\r
+};\r
+\r
+SMMBASETHUNK_COMMUNICATION_DATA gCommunicationData = {\r
+  EFI_SMM_BASE_THUNK_COMMUNICATION_GUID,\r
+  sizeof (SMMBASE_FUNCTION_DATA)\r
+};\r
+\r
+EFI_HANDLE                         mImageHandle;\r
+EFI_SMM_BASE2_PROTOCOL             *mSmmBase2 = NULL;\r
+EFI_SMM_COMMUNICATION_PROTOCOL     *mSmmCommunication = NULL;\r
+EFI_SMM_BASE_HELPER_READY_PROTOCOL *mSmmBaseHelperReady = NULL;\r
+\r
+BOOLEAN\r
+IsInSmm (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  BOOLEAN    InSmm;\r
+  \r
+  Status = mSmmBase2->InSmm (mSmmBase2, &InSmm);\r
+  ASSERT_EFI_ERROR (Status);\r
+  return InSmm;\r
+}\r
+\r
+/**\r
+  Invoke services provided by SMM Base Helper SMM driver.\r
+**/\r
+VOID\r
+SmmBaseHelperService (\r
+  VOID\r
+  )\r
+{\r
+  UINTN DataSize;\r
+\r
+  gCommunicationData.FunctionData.Status = EFI_UNSUPPORTED;\r
+\r
+  if (IsInSmm()) {\r
+    ///\r
+    /// If in SMM mode, directly call services in SMM Base Helper.\r
+    ///\r
+    if (mSmmBaseHelperReady == NULL) {\r
+      ASSERT (FALSE);\r
+      return;\r
+    }\r
+\r
+    DataSize = (UINTN)(sizeof (SMMBASE_FUNCTION_DATA));\r
+    mSmmBaseHelperReady->ServiceEntry (\r
+                           NULL,\r
+                           NULL,\r
+                           &gCommunicationData.FunctionData,\r
+                           &DataSize\r
+                           );\r
+  } else {\r
+    ///\r
+    /// If in non-SMM mode, call services in SMM Base Helper via SMM Communication Protocol.\r
+    ///\r
+    if (mSmmCommunication == NULL) {\r
+      ASSERT (FALSE);\r
+      return;\r
+    }\r
+\r
+    DataSize = (UINTN)(sizeof (gCommunicationData));\r
+    mSmmCommunication->Communicate (\r
+                         mSmmCommunication,\r
+                         &gCommunicationData,\r
+                         &DataSize\r
+                         );\r
+  }\r
+}\r
+\r
+/**\r
+  Register a given driver into SMRAM. This is the equivalent of performing\r
+  the LoadImage/StartImage into System Management Mode.\r
+\r
+  @param[in]   This                  Protocol instance pointer.\r
+  @param[in]   FilePath              Location of the image to be installed as the handler.\r
+  @param[in]   SourceBuffer          Optional source buffer in case the image file\r
+                                     is in memory.\r
+  @param[in]   SourceSize            Size of the source image file, if in memory.\r
+  @param[out]  ImageHandle           The handle that the base driver uses to decode \r
+                                     the handler. Unique among SMM handlers only, \r
+                                     not unique across DXE/EFI.\r
+  @param[in]   LegacyIA32Binary      An optional parameter specifying that the associated \r
+                                     file is a real-mode IA-32 binary.\r
+\r
+  @retval      EFI_SUCCESS           The operation was successful.\r
+  @retval      EFI_OUT_OF_RESOURCES  There were no additional SMRAM resources to load the handler\r
+  @retval      EFI_UNSUPPORTED       This platform does not support 16-bit handlers.\r
+  @retval      EFI_UNSUPPORTED       Platform is in runtime.\r
+  @retval      EFI_INVALID_PARAMETER The handlers was not the correct image type\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmBaseRegister (\r
+  IN      EFI_SMM_BASE_PROTOCOL     *This,\r
+  IN      EFI_DEVICE_PATH_PROTOCOL  *FilePath,\r
+  IN      VOID                      *SourceBuffer,\r
+  IN      UINTN                     SourceSize,\r
+  OUT     EFI_HANDLE                *ImageHandle,\r
+  IN      BOOLEAN                   LegacyIA32Binary\r
+  )\r
+{\r
+  if (LegacyIA32Binary) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  gCommunicationData.FunctionData.Function = SMMBASE_REGISTER;\r
+  gCommunicationData.FunctionData.Args.Register.FilePath = FilePath;\r
+  gCommunicationData.FunctionData.Args.Register.SourceBuffer = SourceBuffer;\r
+  gCommunicationData.FunctionData.Args.Register.SourceSize = SourceSize;\r
+  gCommunicationData.FunctionData.Args.Register.ImageHandle = ImageHandle;\r
+  gCommunicationData.FunctionData.Args.Register.LegacyIA32Binary = LegacyIA32Binary;\r
+\r
+  SmmBaseHelperService ();\r
+  return gCommunicationData.FunctionData.Status;\r
+}\r
+\r
+/**\r
+  Removes a handler from execution within SMRAM.  This is the equivalent of performing\r
+  the UnloadImage in System Management Mode.\r
+\r
+  @param[in]  This                  Protocol instance pointer.\r
+  @param[in]  ImageHandle           The handler to be removed.\r
+\r
+  @retval     EFI_SUCCESS           The operation was successful\r
+  @retval     EFI_INVALID_PARAMETER The handler did not exist\r
+  @retval     EFI_UNSUPPORTED       Platform is in runtime.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmBaseUnregister (\r
+  IN      EFI_SMM_BASE_PROTOCOL     *This,\r
+  IN      EFI_HANDLE                ImageHandle\r
+  )\r
+{\r
+  gCommunicationData.FunctionData.Function = SMMBASE_UNREGISTER;\r
+  gCommunicationData.FunctionData.Args.UnRegister.ImageHandle = ImageHandle;\r
+\r
+  SmmBaseHelperService ();\r
+  return gCommunicationData.FunctionData.Status;\r
+}\r
+\r
+/**\r
+  The SMM Inter-module Communicate Service Communicate() function\r
+  provides a service to send/receive messages from a registered\r
+  EFI service.  The BASE protocol driver is responsible for doing\r
+  any of the copies such that the data lives in boot-service-accessible RAM.\r
+\r
+  @param[in]      This                  Protocol instance pointer.\r
+  @param[in]      ImageHandle           The handle of the registered driver.\r
+  @param[in,out]  CommunicationBuffer   Pointer to the buffer to convey into SMRAM.\r
+  @param[in,out]  BufferSize            The size of the data buffer being passed in.\r
+                                        On exit, the size of data being returned.\r
+                                        Zero if the handler does not wish to reply with any data.\r
+\r
+  @retval         EFI_SUCCESS           The message was successfully posted\r
+  @retval         EFI_INVALID_PARAMETER The buffer was NULL\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmBaseCommunicate (\r
+  IN      EFI_SMM_BASE_PROTOCOL     *This,\r
+  IN      EFI_HANDLE                ImageHandle,\r
+  IN OUT  VOID                      *CommunicationBuffer,\r
+  IN OUT  UINTN                     *BufferSize\r
+  )\r
+{\r
+  if (mSmmCommunication == NULL) {\r
+    ASSERT (FALSE);\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  return mSmmCommunication->Communicate (\r
+                              mSmmCommunication,\r
+                              CommunicationBuffer,\r
+                              BufferSize\r
+                              );\r
+}\r
+\r
+/**\r
+  Register a callback to execute within SMM.\r
+  This allows receipt of messages created with EFI_SMM_BASE_PROTOCOL.Communicate().\r
+\r
+  @param[in]  This                  Protocol instance pointer.\r
+  @param[in]  SmmImageHandle        Handle of the callback service.\r
+  @param[in]  CallbackAddress       Address of the callback service.\r
+  @param[in]  MakeLast              If present, will stipulate that the handler is posted to \r
+                                    be executed last in the dispatch table.\r
+  @param[in]  FloatingPointSave     An optional parameter that informs the\r
+                                    EFI_SMM_ACCESS_PROTOCOL Driver core if it needs to save\r
+                                    the floating point register state. If any handler\r
+                                    require this, the state will be saved for all handlers.\r
+\r
+  @retval     EFI_SUCCESS           The operation was successful\r
+  @retval     EFI_OUT_OF_RESOURCES  Not enough space in the dispatch queue\r
+  @retval     EFI_UNSUPPORTED       Platform is in runtime.\r
+  @retval     EFI_UNSUPPORTED       The caller is not in SMM.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmBaseRegisterCallback (\r
+  IN      EFI_SMM_BASE_PROTOCOL         *This,\r
+  IN      EFI_HANDLE                    SmmImageHandle,\r
+  IN      EFI_SMM_CALLBACK_ENTRY_POINT  CallbackAddress,\r
+  IN      BOOLEAN                       MakeLast,\r
+  IN      BOOLEAN                       FloatingPointSave\r
+  )\r
+{\r
+  if (!IsInSmm()) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  gCommunicationData.FunctionData.Function = SMMBASE_REGISTER_CALLBACK;\r
+  gCommunicationData.FunctionData.Args.RegisterCallback.SmmImageHandle = SmmImageHandle;\r
+  gCommunicationData.FunctionData.Args.RegisterCallback.CallbackAddress = CallbackAddress;\r
+  gCommunicationData.FunctionData.Args.RegisterCallback.MakeLast = MakeLast;\r
+  gCommunicationData.FunctionData.Args.RegisterCallback.FloatingPointSave = FloatingPointSave;\r
+\r
+  SmmBaseHelperService();\r
+  return gCommunicationData.FunctionData.Status;\r
+}\r
+\r
+/**\r
+  This routine tells caller if execution context is SMM or not.\r
+\r
+  @param[in]   This                   Protocol instance pointer.\r
+  @param[out]  InSmm                  Whether the caller is inside SMM for IA-32\r
+                                      or servicing a PMI for the Itanium processor\r
+                                      family.\r
+\r
+  @retval      EFI_SUCCESS            The operation was successful\r
+  @retval      EFI_INVALID_PARAMETER  InSmm was NULL.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmBaseInSmm (\r
+  IN      EFI_SMM_BASE_PROTOCOL     *This,\r
+  OUT     BOOLEAN                   *InSmm\r
+  )\r
+{\r
+  return mSmmBase2->InSmm (mSmmBase2, InSmm);\r
+}\r
+\r
+/**\r
+  The SmmAllocatePool() function allocates a memory region of Size bytes from memory of\r
+  type PoolType and returns the address of the allocated memory in the location referenced\r
+  by Buffer.  This function allocates pages from EFI SMRAM Memory as needed to grow the\r
+  requested pool type.  All allocations are eight-byte aligned.\r
+\r
+  @param[in]   This                  Protocol instance pointer.\r
+  @param[in]   PoolType              The type of pool to allocate.\r
+                                     The only supported type is EfiRuntimeServicesData;\r
+                                     the interface will internally map this runtime request to \r
+                                     SMRAM for IA-32 and leave as this type for the Itanium \r
+                                     processor family. Other types can be ignored.\r
+  @param[in]   Size                  The number of bytes to allocate from the pool.\r
+  @param[out]  Buffer                A pointer to a pointer to the allocated buffer if the call\r
+                                     succeeds; undefined otherwise.\r
+\r
+  @retval      EFI_SUCCESS           The requested number of bytes was allocated.\r
+  @retval      EFI_OUT_OF_RESOURCES  The pool requested could not be allocated.\r
+  @retval      EFI_UNSUPPORTED       Platform is in runtime.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmBaseSmmAllocatePool (\r
+  IN      EFI_SMM_BASE_PROTOCOL     *This,\r
+  IN      EFI_MEMORY_TYPE           PoolType,\r
+  IN      UINTN                     Size,\r
+  OUT     VOID                      **Buffer\r
+  )\r
+{\r
+  gCommunicationData.FunctionData.Function = SMMBASE_ALLOCATE_POOL;\r
+  gCommunicationData.FunctionData.Args.AllocatePool.PoolType = PoolType;\r
+  gCommunicationData.FunctionData.Args.AllocatePool.Size = Size;\r
+  gCommunicationData.FunctionData.Args.AllocatePool.Buffer = Buffer;\r
+\r
+  SmmBaseHelperService ();\r
+  return gCommunicationData.FunctionData.Status;\r
+}\r
+\r
+/**\r
+  The SmmFreePool() function returns the memory specified by Buffer to the system.\r
+  On return, the memory's type is EFI SMRAM Memory.  The Buffer that is freed must\r
+  have been allocated by SmmAllocatePool().\r
+\r
+  @param[in]  This                  Protocol instance pointer.\r
+  @param[in]  Buffer                Pointer to the buffer allocation.\r
+\r
+  @retval     EFI_SUCCESS           The memory was returned to the system.\r
+  @retval     EFI_INVALID_PARAMETER Buffer was invalid.\r
+  @retval     EFI_UNSUPPORTED       Platform is in runtime.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmBaseSmmFreePool (\r
+  IN      EFI_SMM_BASE_PROTOCOL     *This,\r
+  IN      VOID                      *Buffer\r
+  )\r
+{\r
+  gCommunicationData.FunctionData.Function = SMMBASE_FREE_POOL;\r
+  gCommunicationData.FunctionData.Args.FreePool.Buffer = Buffer;\r
+\r
+  SmmBaseHelperService ();\r
+  return gCommunicationData.FunctionData.Status;\r
+}\r
+\r
+/**\r
+  The GetSmstLocation() function returns the location of the System Management\r
+  Service Table.  The use of the API is such that a driver can discover the\r
+  location of the SMST in its entry point and then cache it in some driver\r
+  global variable so that the SMST can be invoked in subsequent callbacks.\r
+\r
+  @param[in]  This                  Protocol instance pointer.\r
+  @param[in]  Smst                  Pointer to the SMST.\r
+\r
+  @retval     EFI_SUCCESS           The operation was successful\r
+  @retval     EFI_INVALID_PARAMETER Smst was invalid.\r
+  @retval     EFI_UNSUPPORTED       Not in SMM.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmBaseGetSmstLocation (\r
+  IN      EFI_SMM_BASE_PROTOCOL     *This,\r
+  OUT     EFI_SMM_SYSTEM_TABLE      **Smst\r
+  )\r
+{\r
+  if (mSmmBaseHelperReady == NULL) {\r
+    ASSERT (FALSE);\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (!IsInSmm ()) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (Smst == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  *Smst = mSmmBaseHelperReady->FrameworkSmst;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  SMM Base Protocol notification event handler.\r
+\r
+  @param[in] Event    Event whose notification function is being invoked.\r
+  @param[in] Context  Pointer to the notification function's context.\r
+**/\r
+VOID\r
+EFIAPI\r
+SmmBaseProtocolNotification (\r
+  IN EFI_EVENT  Event,\r
+  IN VOID       *Context\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+\r
+  ///\r
+  /// Assume only one instance of SMM Base2 Protocol in the system\r
+  /// Locate SMM Base2 Protocol\r
+  ///\r
+  Status = gBS->LocateProtocol (&gEfiSmmBase2ProtocolGuid, NULL, (VOID **) &mSmmBase2);\r
+  if (!EFI_ERROR (Status)) {\r
+    ///\r
+    /// Publish Framework SMM BASE Protocol immediately after SMM Base2 Protocol is installed to\r
+    /// make SMM Base Protocol.InSmm() available as early as possible.\r
+    ///\r
+    Status = gBS->InstallProtocolInterface (\r
+                    &mImageHandle,\r
+                    &gEfiSmmBaseProtocolGuid,\r
+                    EFI_NATIVE_INTERFACE,\r
+                    &gSmmBase\r
+                    );\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
+}\r
+\r
+/**\r
+  SMM Communication Protocol notification event handler.\r
+\r
+  @param[in] Event    Event whose notification function is being invoked.\r
+  @param[in] Context  Pointer to the notification function's context.\r
+**/\r
+VOID\r
+EFIAPI\r
+SmmCommunicationProtocolNotification (\r
+  IN EFI_EVENT  Event,\r
+  IN VOID       *Context\r
+  )\r
+{\r
+  ///\r
+  /// Assume only one instance of SMM Communication Protocol in the system\r
+  /// Locate SMM Communication Protocol\r
+  ///\r
+  gBS->LocateProtocol (&gEfiSmmCommunicationProtocolGuid, NULL, (VOID **) &mSmmCommunication);\r
+}\r
+\r
+/**\r
+  SMM Base Helper Ready Protocol notification event handler.\r
+\r
+  @param[in] Event    Event whose notification function is being invoked.\r
+  @param[in] Context  Pointer to the notification function's context.\r
+**/\r
+VOID\r
+EFIAPI\r
+SmmBaseHelperReadyProtocolNotification (\r
+  IN EFI_EVENT  Event,\r
+  IN VOID       *Context\r
+  )\r
+{\r
+  ///\r
+  /// Assume only one instance of SMM Base Helper Ready Protocol in the system\r
+  /// Locate SMM Base Helper Ready Protocol\r
+  ///\r
+  gBS->LocateProtocol (&gEfiSmmBaseHelperReadyProtocolGuid, NULL, (VOID **) &mSmmBaseHelperReady);\r
+}\r
+\r
+/**\r
+  Entry Point for SMM Base Protocol on SMM Base2 Protocol Thunk driver.\r
+\r
+  @param[in] ImageHandle  Image handle of this driver.\r
+  @param[in] SystemTable  A Pointer to the EFI System Table.\r
+\r
+  @retval EFI_SUCCESS  The entry point is executed successfully.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmBaseThunkMain (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  VOID *Registration;\r
+\r
+  mImageHandle = ImageHandle;\r
+\r
+  ///\r
+  /// Install notifications for required protocols\r
+  ///\r
+  /// Note we use protocol notifications here so as that this thunk driver can be\r
+  /// loaded before PI SMM IPL driver. Framework SMM BASE Protocol will be published \r
+  /// immediately after SMM Base2 Protocol is installed to make SMM Base Protocol.InSmm()\r
+  /// available as early as possible because some Framework code's behavior depends on\r
+  /// correct detection of SMM mode via SMM Base Protocol.InSmm().\r
+  ///\r
+  /// Also SMM Base Helper driver is expected to be dispatched\r
+  /// in the earliest round of SMM driver dispatch just after SMM IPL driver loads SMM Foundation.\r
+  /// So the full functionality of SMM Base Protocol is ready immediately after SMM IPL driver is\r
+  /// loaded. Since that point Framework SMM driver can be succesufully supported.\r
+  ///\r
+  EfiCreateProtocolNotifyEvent (\r
+    &gEfiSmmBase2ProtocolGuid,\r
+    TPL_CALLBACK,\r
+    SmmBaseProtocolNotification,\r
+    NULL,\r
+    &Registration\r
+    );\r
+\r
+  EfiCreateProtocolNotifyEvent (\r
+    &gEfiSmmCommunicationProtocolGuid,\r
+    TPL_CALLBACK,\r
+    SmmCommunicationProtocolNotification,\r
+    NULL,\r
+    &Registration\r
+    );\r
+\r
+  EfiCreateProtocolNotifyEvent (\r
+    &gEfiSmmBaseHelperReadyProtocolGuid,\r
+    TPL_CALLBACK,\r
+    SmmBaseHelperReadyProtocolNotification,\r
+    NULL,\r
+    &Registration\r
+    );\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
diff --git a/EdkCompatibilityPkg/Compatibility/SmmBaseOnSmmBase2Thunk/SmmBaseOnSmmBase2Thunk.h b/EdkCompatibilityPkg/Compatibility/SmmBaseOnSmmBase2Thunk/SmmBaseOnSmmBase2Thunk.h
new file mode 100644 (file)
index 0000000..6fc3f19
--- /dev/null
@@ -0,0 +1,219 @@
+/** @file\r
+  Include file for SMM Base Protocol on SMM Base2 Protocol Thunk driver.\r
+  \r
+  Copyright (c) 2009, Intel Corporation\r
+  All rights reserved. This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef  _SMM_BASE_ON_SMM_BASE2_THUNK_H_\r
+#define  _SMM_BASE_ON_SMM_BASE2_THUNK_H_\r
+\r
+#include <PiDxe.h>\r
+#include <FrameworkSmm.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UefiLib.h>\r
+#include <Guid/SmmBaseThunkCommunication.h>\r
+#include <Protocol/SmmBase2.h>\r
+#include <Protocol/SmmCommunication.h>\r
+#include <Protocol/SmmBaseHelperReady.h>\r
+\r
+/**\r
+  Register a given driver into SMRAM. This is the equivalent of performing\r
+  the LoadImage/StartImage into System Management Mode.\r
+\r
+  @param[in]   This                  Protocol instance pointer.\r
+  @param[in]   FilePath              Location of the image to be installed as the handler.\r
+  @param[in]   SourceBuffer          Optional source buffer in case the image file\r
+                                     is in memory.\r
+  @param[in]   SourceSize            Size of the source image file, if in memory.\r
+  @param[out]  ImageHandle           The handle that the base driver uses to decode \r
+                                     the handler. Unique among SMM handlers only, \r
+                                     not unique across DXE/EFI.\r
+  @param[in]   LegacyIA32Binary      An optional parameter specifying that the associated \r
+                                     file is a real-mode IA-32 binary.\r
+\r
+  @retval      EFI_SUCCESS           The operation was successful.\r
+  @retval      EFI_OUT_OF_RESOURCES  There were no additional SMRAM resources to load the handler\r
+  @retval      EFI_UNSUPPORTED       This platform does not support 16-bit handlers.\r
+  @retval      EFI_UNSUPPORTED       Platform is in runtime.\r
+  @retval      EFI_INVALID_PARAMETER The handlers was not the correct image type\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmBaseRegister (\r
+  IN      EFI_SMM_BASE_PROTOCOL     *This,\r
+  IN      EFI_DEVICE_PATH_PROTOCOL  *FilePath,\r
+  IN      VOID                      *SourceBuffer,\r
+  IN      UINTN                     SourceSize,\r
+  OUT     EFI_HANDLE                *ImageHandle,\r
+  IN      BOOLEAN                   LegacyIA32Binary\r
+  );\r
+\r
+/**\r
+  Removes a handler from execution within SMRAM.  This is the equivalent of performing\r
+  the UnloadImage in System Management Mode.\r
+\r
+  @param[in]  This                  Protocol instance pointer.\r
+  @param[in]  ImageHandle           The handler to be removed.\r
+\r
+  @retval     EFI_SUCCESS           The operation was successful\r
+  @retval     EFI_INVALID_PARAMETER The handler did not exist\r
+  @retval     EFI_UNSUPPORTED       Platform is in runtime.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmBaseUnregister (\r
+  IN      EFI_SMM_BASE_PROTOCOL     *This,\r
+  IN      EFI_HANDLE                ImageHandle\r
+  );\r
+\r
+/**\r
+  The SMM Inter-module Communicate Service Communicate() function\r
+  provides a service to send/receive messages from a registered\r
+  EFI service.  The BASE protocol driver is responsible for doing\r
+  any of the copies such that the data lives in boot-service-accessible RAM.\r
+\r
+  @param[in]      This                  Protocol instance pointer.\r
+  @param[in]      ImageHandle           The handle of the registered driver.\r
+  @param[in,out]  CommunicationBuffer   Pointer to the buffer to convey into SMRAM.\r
+  @param[in,out]  BufferSize            The size of the data buffer being passed in.\r
+                                        On exit, the size of data being returned.\r
+                                        Zero if the handler does not wish to reply with any data.\r
+\r
+  @retval         EFI_SUCCESS           The message was successfully posted\r
+  @retval         EFI_INVALID_PARAMETER The buffer was NULL\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmBaseCommunicate (\r
+  IN      EFI_SMM_BASE_PROTOCOL     *This,\r
+  IN      EFI_HANDLE                ImageHandle,\r
+  IN OUT  VOID                      *CommunicationBuffer,\r
+  IN OUT  UINTN                     *BufferSize\r
+  );\r
+\r
+/**\r
+  Register a callback to execute within SMM.\r
+  This allows receipt of messages created with EFI_SMM_BASE_PROTOCOL.Communicate().\r
+\r
+  @param[in]  This                  Protocol instance pointer.\r
+  @param[in]  SmmImageHandle        Handle of the callback service.\r
+  @param[in]  CallbackAddress       Address of the callback service.\r
+  @param[in]  MakeLast              If present, will stipulate that the handler is posted to \r
+                                    be executed last in the dispatch table.\r
+  @param[in]  FloatingPointSave     An optional parameter that informs the\r
+                                    EFI_SMM_ACCESS_PROTOCOL Driver core if it needs to save\r
+                                    the floating point register state. If any handler\r
+                                    require this, the state will be saved for all handlers.\r
+\r
+  @retval     EFI_SUCCESS           The operation was successful\r
+  @retval     EFI_OUT_OF_RESOURCES  Not enough space in the dispatch queue\r
+  @retval     EFI_UNSUPPORTED       Platform is in runtime.\r
+  @retval     EFI_UNSUPPORTED       The caller is not in SMM.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmBaseRegisterCallback (\r
+  IN      EFI_SMM_BASE_PROTOCOL         *This,\r
+  IN      EFI_HANDLE                    SmmImageHandle,\r
+  IN      EFI_SMM_CALLBACK_ENTRY_POINT  CallbackAddress,\r
+  IN      BOOLEAN                       MakeLast,\r
+  IN      BOOLEAN                       FloatingPointSave\r
+  );\r
+\r
+/**\r
+  This routine tells caller if execution context is SMM or not.\r
+\r
+  @param[in]   This                   Protocol instance pointer.\r
+  @param[out]  InSmm                  Whether the caller is inside SMM for IA-32\r
+                                      or servicing a PMI for the Itanium processor\r
+                                      family.\r
+\r
+  @retval      EFI_SUCCESS            The operation was successful\r
+  @retval      EFI_INVALID_PARAMETER  InSmm was NULL.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmBaseInSmm (\r
+  IN      EFI_SMM_BASE_PROTOCOL     *This,\r
+  OUT     BOOLEAN                   *InSmm\r
+  );\r
+\r
+/**\r
+  The SmmAllocatePool() function allocates a memory region of Size bytes from memory of\r
+  type PoolType and returns the address of the allocated memory in the location referenced\r
+  by Buffer.  This function allocates pages from EFI SMRAM Memory as needed to grow the\r
+  requested pool type.  All allocations are eight-byte aligned.\r
+\r
+  @param[in]   This                  Protocol instance pointer.\r
+  @param[in]   PoolType              The type of pool to allocate.\r
+                                     The only supported type is EfiRuntimeServicesData;\r
+                                     the interface will internally map this runtime request to \r
+                                     SMRAM for IA-32 and leave as this type for the Itanium \r
+                                     processor family. Other types can be ignored.\r
+  @param[in]   Size                  The number of bytes to allocate from the pool.\r
+  @param[out]  Buffer                A pointer to a pointer to the allocated buffer if the call\r
+                                     succeeds; undefined otherwise.\r
+\r
+  @retval      EFI_SUCCESS           The requested number of bytes was allocated.\r
+  @retval      EFI_OUT_OF_RESOURCES  The pool requested could not be allocated.\r
+  @retval      EFI_UNSUPPORTED       Platform is in runtime.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmBaseSmmAllocatePool (\r
+  IN      EFI_SMM_BASE_PROTOCOL     *This,\r
+  IN      EFI_MEMORY_TYPE           PoolType,\r
+  IN      UINTN                     Size,\r
+  OUT     VOID                      **Buffer\r
+  );\r
+\r
+/**\r
+  The SmmFreePool() function returns the memory specified by Buffer to the system.\r
+  On return, the memory's type is EFI SMRAM Memory.  The Buffer that is freed must\r
+  have been allocated by SmmAllocatePool().\r
+\r
+  @param[in]  This                  Protocol instance pointer.\r
+  @param[in]  Buffer                Pointer to the buffer allocation.\r
+\r
+  @retval     EFI_SUCCESS           The memory was returned to the system.\r
+  @retval     EFI_INVALID_PARAMETER Buffer was invalid.\r
+  @retval     EFI_UNSUPPORTED       Platform is in runtime.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmBaseSmmFreePool (\r
+  IN      EFI_SMM_BASE_PROTOCOL     *This,\r
+  IN      VOID                      *Buffer\r
+  );\r
+\r
+/**\r
+  The GetSmstLocation() function returns the location of the System Management\r
+  Service Table.  The use of the API is such that a driver can discover the\r
+  location of the SMST in its entry point and then cache it in some driver\r
+  global variable so that the SMST can be invoked in subsequent callbacks.\r
+\r
+  @param[in]  This                  Protocol instance pointer.\r
+  @param[in]  Smst                  Pointer to the SMST.\r
+\r
+  @retval     EFI_SUCCESS           The operation was successful\r
+  @retval     EFI_INVALID_PARAMETER Smst was invalid.\r
+  @retval     EFI_UNSUPPORTED       Not in SMM.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmBaseGetSmstLocation (\r
+  IN      EFI_SMM_BASE_PROTOCOL     *This,\r
+  OUT     EFI_SMM_SYSTEM_TABLE      **Smst\r
+  );\r
+\r
+#endif  \r
diff --git a/EdkCompatibilityPkg/Compatibility/SmmBaseOnSmmBase2Thunk/SmmBaseOnSmmBase2Thunk.inf b/EdkCompatibilityPkg/Compatibility/SmmBaseOnSmmBase2Thunk/SmmBaseOnSmmBase2Thunk.inf
new file mode 100644 (file)
index 0000000..cea74e8
--- /dev/null
@@ -0,0 +1,53 @@
+## @file\r
+#  Component description file for SMM Base Protocol on SMM Base2 Protocol Thunk driver.\r
+#\r
+#  Copyright (c) 2009, Intel Corporation\r
+#\r
+#  All rights reserved. This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = SmmBaseOnSmmBase2Thunk\r
+  FILE_GUID                      = 21CCF0B7-246B-412c-A334-0B65A07B28DF\r
+  MODULE_TYPE                    = DXE_RUNTIME_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  ENTRY_POINT                    = SmmBaseThunkMain\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64\r
+#\r
+\r
+[Sources]\r
+  SmmBaseOnSmmBase2Thunk.c\r
+  SmmBaseOnSmmBase2Thunk.h\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  IntelFrameworkPkg/IntelFrameworkPkg.dec\r
+  EdkCompatibilityPkg/EdkCompatibilityPkg.dec\r
+\r
+[LibraryClasses]\r
+  UefiDriverEntryPoint\r
+  UefiBootServicesTableLib\r
+  DebugLib\r
+  UefiLib\r
+\r
+[Protocols]\r
+  gEfiSmmBase2ProtocolGuid            # PROTOCOL SOMETIMES_CONSUMED\r
+  gEfiSmmCommunicationProtocolGuid    # PROTOCOL SOMETIMES_CONSUMED\r
+  gEfiSmmBaseHelperReadyProtocolGuid  # PROTOCOL SOMETIMES_CONSUMED\r
+  gEfiSmmBaseProtocolGuid             # PROTOCOL SOMETIMES_PRODUCED\r
+\r
+[Depex]\r
+  TRUE\r
+\r
diff --git a/EdkCompatibilityPkg/Compatibility/SmmControl2OnSmmControlThunk/SmmControl2OnSmmControlThunk.c b/EdkCompatibilityPkg/Compatibility/SmmControl2OnSmmControlThunk/SmmControl2OnSmmControlThunk.c
new file mode 100644 (file)
index 0000000..1b8a407
--- /dev/null
@@ -0,0 +1,128 @@
+/** @file\r
+  SMM Control2 Protocol on SMM Control Protocol Thunk driver.\r
+\r
+  Copyright (c) 2009 Intel Corporation\r
+  All rights reserved. This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "SmmControl2OnSmmControlThunk.h"\r
+\r
+EFI_SMM_CONTROL2_PROTOCOL gSmmControl2 = {\r
+  SmmControl2Trigger,\r
+  SmmControl2Clear,\r
+  0\r
+};\r
+\r
+EFI_SMM_CONTROL_PROTOCOL  *mSmmControl;\r
+UINT8                      mDataPort;\r
+\r
+/**\r
+  Invokes SMI activation from either the preboot or runtime environment.\r
+\r
+  This function generates an SMI.\r
+\r
+  @param[in]     This                The EFI_SMM_CONTROL2_PROTOCOL instance.\r
+  @param[in,out] CommandPort         The value written to the command port.\r
+  @param[in,out] DataPort            The value written to the data port.\r
+  @param[in]     Periodic            Optional mechanism to engender a periodic stream.\r
+  @param[in]     ActivationInterval  Optional parameter to repeat at this period one\r
+                                     time or, if the Periodic Boolean is set, periodically.\r
+\r
+  @retval EFI_SUCCESS            The SMI/PMI has been engendered.\r
+  @retval EFI_DEVICE_ERROR       The timing is unsupported.\r
+  @retval EFI_INVALID_PARAMETER  The activation period is unsupported.\r
+  @retval EFI_NOT_STARTED        The SMM base service has not been initialized.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmControl2Trigger (\r
+  IN CONST EFI_SMM_CONTROL2_PROTOCOL  *This,\r
+  IN OUT UINT8                        *CommandPort       OPTIONAL,\r
+  IN OUT UINT8                        *DataPort          OPTIONAL,\r
+  IN BOOLEAN                          Periodic           OPTIONAL,\r
+  IN UINTN                            ActivationInterval OPTIONAL\r
+  )\r
+{\r
+  UINTN  ArgumentBufferSize = 0;\r
+\r
+  if (CommandPort != NULL) {\r
+    ArgumentBufferSize = 1;\r
+  }\r
+  if (DataPort != NULL) {\r
+    IoWrite8 (mDataPort, *DataPort);\r
+  }\r
+  return mSmmControl->Trigger (mSmmControl, (INT8 *)CommandPort, &ArgumentBufferSize, Periodic, ActivationInterval);\r
+}\r
+\r
+/**\r
+  Clears any system state that was created in response to the Trigger() call.\r
+\r
+  This function acknowledges and causes the deassertion of the SMI activation source.\r
+\r
+  @param[in] This                The EFI_SMM_CONTROL2_PROTOCOL instance.\r
+  @param[in] Periodic            Optional parameter to repeat at this period one time\r
+\r
+  @retval EFI_SUCCESS            The SMI/PMI has been engendered.\r
+  @retval EFI_DEVICE_ERROR       The source could not be cleared.\r
+  @retval EFI_INVALID_PARAMETER  The service did not support the Periodic input argument.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmControl2Clear (\r
+  IN CONST EFI_SMM_CONTROL2_PROTOCOL  *This,\r
+  IN BOOLEAN                          Periodic OPTIONAL\r
+  )\r
+{\r
+  return mSmmControl->Clear (mSmmControl, Periodic);\r
+}\r
+\r
+/**\r
+  Entry Point for this thunk driver.\r
+\r
+  @param[in] ImageHandle  Image handle of this driver.\r
+  @param[in] SystemTable  A Pointer to the EFI System Table.\r
+\r
+  @retval EFI_SUCCESS  The entry point is executed successfully.\r
+  @retval other        Some error occurred when executing this entry point.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmControl2ThunkMain (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS               Status;\r
+  EFI_SMM_CONTROL_REGISTER RegisterInfo;\r
+\r
+  ///\r
+  /// Locate Framework SMM Control Protocol\r
+  ///\r
+  Status = gBS->LocateProtocol (&gEfiSmmControlProtocolGuid, NULL, (VOID **)&mSmmControl);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  gSmmControl2.MinimumTriggerPeriod = mSmmControl->MinimumTriggerPeriod;\r
+\r
+  Status = mSmmControl->GetRegisterInfo (mSmmControl, &RegisterInfo);\r
+  ASSERT_EFI_ERROR (Status);\r
+  mDataPort = RegisterInfo.SmiDataRegister;\r
+\r
+  ///\r
+  /// Publish framework SMM Control Protocol\r
+  ///\r
+  Status = gBS->InstallProtocolInterface (\r
+                  &ImageHandle,\r
+                  &gEfiSmmControl2ProtocolGuid,\r
+                  EFI_NATIVE_INTERFACE,\r
+                  &gSmmControl2\r
+                  );\r
+  return Status;\r
+}\r
+\r
diff --git a/EdkCompatibilityPkg/Compatibility/SmmControl2OnSmmControlThunk/SmmControl2OnSmmControlThunk.h b/EdkCompatibilityPkg/Compatibility/SmmControl2OnSmmControlThunk/SmmControl2OnSmmControlThunk.h
new file mode 100644 (file)
index 0000000..ebee008
--- /dev/null
@@ -0,0 +1,73 @@
+/** @file\r
+  Include file for SMM Control2 Protocol on SMM Control Protocol Thunk driver.\r
+  \r
+  Copyright (c) 2009, Intel Corporation\r
+  All rights reserved. This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef  _SMM_CONTROL2_ON_SMM_CONTROL_THUNK_H_\r
+#define  _SMM_CONTROL2_ON_SMM_CONTROL_THUNK_H_\r
+\r
+#include <PiDxe.h>\r
+#include <FrameworkSmm.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/IoLib.h>\r
+#include <Protocol/SmmControl2.h>\r
+#include <Protocol/SmmControl.h>\r
+\r
+/**\r
+  Invokes SMI activation from either the preboot or runtime environment.\r
+\r
+  This function generates an SMI.\r
+\r
+  @param[in]     This                The EFI_SMM_CONTROL2_PROTOCOL instance.\r
+  @param[in,out] CommandPort         The value written to the command port.\r
+  @param[in,out] DataPort            The value written to the data port.\r
+  @param[in]     Periodic            Optional mechanism to engender a periodic stream.\r
+  @param[in]     ActivationInterval  Optional parameter to repeat at this period one\r
+                                     time or, if the Periodic Boolean is set, periodically.\r
+\r
+  @retval EFI_SUCCESS            The SMI/PMI has been engendered.\r
+  @retval EFI_DEVICE_ERROR       The timing is unsupported.\r
+  @retval EFI_INVALID_PARAMETER  The activation period is unsupported.\r
+  @retval EFI_NOT_STARTED        The SMM base service has not been initialized.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmControl2Trigger (\r
+  IN CONST EFI_SMM_CONTROL2_PROTOCOL  *This,\r
+  IN OUT UINT8                        *CommandPort       OPTIONAL,\r
+  IN OUT UINT8                        *DataPort          OPTIONAL,\r
+  IN BOOLEAN                          Periodic           OPTIONAL,\r
+  IN UINTN                            ActivationInterval OPTIONAL\r
+  );\r
+\r
+/**\r
+  Clears any system state that was created in response to the Trigger() call.\r
+\r
+  This function acknowledges and causes the deassertion of the SMI activation source.\r
+\r
+  @param[in] This                The EFI_SMM_CONTROL2_PROTOCOL instance.\r
+  @param[in] Periodic            Optional parameter to repeat at this period one time\r
+\r
+  @retval EFI_SUCCESS            The SMI/PMI has been engendered.\r
+  @retval EFI_DEVICE_ERROR       The source could not be cleared.\r
+  @retval EFI_INVALID_PARAMETER  The service did not support the Periodic input argument.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmControl2Clear (\r
+  IN CONST EFI_SMM_CONTROL2_PROTOCOL  *This,\r
+  IN BOOLEAN                          Periodic OPTIONAL\r
+  );\r
+\r
+#endif  \r
diff --git a/EdkCompatibilityPkg/Compatibility/SmmControl2OnSmmControlThunk/SmmControl2OnSmmControlThunk.inf b/EdkCompatibilityPkg/Compatibility/SmmControl2OnSmmControlThunk/SmmControl2OnSmmControlThunk.inf
new file mode 100644 (file)
index 0000000..2c3996b
--- /dev/null
@@ -0,0 +1,51 @@
+## @file\r
+#  Component description file for SMM Control2 Protocol on SMM Control Protocol Thunk driver.\r
+#\r
+#  Copyright (c) 2009, Intel Corporation\r
+#\r
+#  All rights reserved. This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = SmmControl2OnSmmControlThunk\r
+  FILE_GUID                      = B55A4515-5895-4ea8-845B-75B7480F6502\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  ENTRY_POINT                    = SmmControl2ThunkMain\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64\r
+#\r
+\r
+[Sources]\r
+  SmmControl2OnSmmControlThunk.c\r
+  SmmControl2OnSmmControlThunk.h\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  IntelFrameworkPkg/IntelFrameworkPkg.dec\r
+  EdkCompatibilityPkg/EdkCompatibilityPkg.dec\r
+\r
+[LibraryClasses]\r
+  UefiDriverEntryPoint\r
+  UefiBootServicesTableLib\r
+  DebugLib\r
+  IoLib\r
+\r
+[Protocols]\r
+  gEfiSmmControlProtocolGuid            # PROTOCOL ALWAYS_CONSUMED\r
+  gEfiSmmControl2ProtocolGuid           # PROTOCOL ALWAYS_PRODUCED\r
+\r
+[Depex]\r
+  gEfiSmmControlProtocolGuid\r
+\r
index 6472a48357622b51bee929cdf8106e0b6d534b11..0aac9fb14738e82e8ba96b667e1af00068e45c4c 100644 (file)
   ##\r
   LanguageLib|Compatibility/Include/Library/LanguageLib.h\r
 \r
   ##\r
   LanguageLib|Compatibility/Include/Library/LanguageLib.h\r
 \r
+[Guids.common]\r
+  gEfiSmmBaseThunkCommunicationGuid       = { 0x6568a3d6, 0x15f, 0x4b4a, { 0x9c, 0x89, 0x1d, 0x14, 0x63, 0x14, 0x13, 0xa } }\r
+\r
 [Ppis.common]\r
   gEcpPeiPciCfgPpiGuid                    = { 0xb0ee53d4, 0xa049, 0x4a79, { 0xb2, 0xff, 0x19, 0xd9, 0xfa, 0xef, 0xaa, 0x94 }} \r
 \r
 [Protocols.common]\r
   gEfiPrintProtocolGuid                   = { 0xdf2d868e, 0x32fc, 0x4cf0, {0x8e, 0x6b, 0xff, 0xd9, 0x5d, 0x13, 0x43, 0xd0} }\r
 [Ppis.common]\r
   gEcpPeiPciCfgPpiGuid                    = { 0xb0ee53d4, 0xa049, 0x4a79, { 0xb2, 0xff, 0x19, 0xd9, 0xfa, 0xef, 0xaa, 0x94 }} \r
 \r
 [Protocols.common]\r
   gEfiPrintProtocolGuid                   = { 0xdf2d868e, 0x32fc, 0x4cf0, {0x8e, 0x6b, 0xff, 0xd9, 0x5d, 0x13, 0x43, 0xd0} }\r
+  gEfiSmmBaseHelperReadyProtocolGuid      = { 0x910dca07, 0x1f94, 0x4ee7, { 0xaf, 0x2f, 0xff, 0x72, 0xf3, 0x15, 0x43, 0x53 } }\r
 \r
 \r
index 05201e549414eae6887b1cdb3025f9b00fc5aa00..1d88d7106225a4874a7121a43eb462376a60e450 100644 (file)
@@ -63,14 +63,21 @@ define GCC_MACRO                 = -DEFI_SPECIFICATION_VERSION=0x00020000 -DPI_S
   PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf\r
   LanguageLib|EdkCompatibilityPkg/Compatibility/Library/UefiLanguageLib/UefiLanguageLib.inf\r
   DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf\r
   PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf\r
   LanguageLib|EdkCompatibilityPkg/Compatibility/Library/UefiLanguageLib/UefiLanguageLib.inf\r
   DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf\r
+  PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf\r
+  PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BasePeCoffExtraActionLibNull.inf\r
+  CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf\r
 \r
 [LibraryClasses.common.PEIM]\r
   HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf\r
   MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf\r
 \r
 \r
 [LibraryClasses.common.PEIM]\r
   HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf\r
   MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf\r
 \r
-[LibraryClasses.common.DXE_DRIVER]\r
+[LibraryClasses.common.DXE_DRIVER,LibraryClasses.common.DXE_RUNTIME_DRIVER,LibraryClasses.common.DXE_SMM_DRIVER]\r
   MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf\r
 \r
   MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf\r
 \r
+[LibraryClasses.IA32.DXE_SMM_DRIVER,LibraryClasses.X64.DXE_SMM_DRIVER]\r
+  SmmServicesTableLib|MdePkg/Library/SmmServicesTableLib/SmmServicesTableLib.inf\r
+  ReportStatusCodeLib|MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLib.inf\r
+\r
 [BuildOptions]\r
   GCC:*_*_IA32_CC_FLAGS     = -DEFI32 $(GCC_MACRO)\r
   GCC:*_*_IA32_ASM_FLAGS    =\r
 [BuildOptions]\r
   GCC:*_*_IA32_CC_FLAGS     = -DEFI32 $(GCC_MACRO)\r
   GCC:*_*_IA32_ASM_FLAGS    =\r
@@ -267,6 +274,10 @@ define GCC_MACRO                 = -DEFI_SPECIFICATION_VERSION=0x00020000 -DPI_S
   EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/DxePerformanceLib/DxePerformanceLib.inf # Use IA32/X64 specific AsmReadTsc (). \r
   EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/PeiPerformanceLib/PeiPerformanceLib.inf # Use IA32/X64 specific AsmReadTsc ().\r
   EdkCompatibilityPkg/Compatibility/MpServicesOnFrameworkMpServicesThunk/MpServicesOnFrameworkMpServicesThunk.inf\r
   EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/DxePerformanceLib/DxePerformanceLib.inf # Use IA32/X64 specific AsmReadTsc (). \r
   EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/PeiPerformanceLib/PeiPerformanceLib.inf # Use IA32/X64 specific AsmReadTsc ().\r
   EdkCompatibilityPkg/Compatibility/MpServicesOnFrameworkMpServicesThunk/MpServicesOnFrameworkMpServicesThunk.inf\r
+  EdkCompatibilityPkg/Compatibility/SmmBaseOnSmmBase2Thunk/SmmBaseOnSmmBase2Thunk.inf\r
+  EdkCompatibilityPkg/Compatibility/SmmBaseHelper/SmmBaseHelper.inf\r
+  EdkCompatibilityPkg/Compatibility/SmmAccess2OnSmmAccessThunk/SmmAccess2OnSmmAccessThunk.inf\r
+  EdkCompatibilityPkg/Compatibility/SmmControl2OnSmmControlThunk/SmmControl2OnSmmControlThunk.inf\r
 \r
 [Components.IPF]\r
   EdkCompatibilityPkg/Foundation/Cpu/Itanium/CpuIa64Lib/CpuIA64Lib.inf\r
 \r
 [Components.IPF]\r
   EdkCompatibilityPkg/Foundation/Cpu/Itanium/CpuIa64Lib/CpuIA64Lib.inf\r
index 9d5f467cfdfeb15a1fcf53fa8802c3d6be2b2b19..6dd128af8c8f83225934499bac6d9bc0c0ac141d 100644 (file)
@@ -1,6 +1,6 @@
 /*++\r
 \r
 /*++\r
 \r
-Copyright (c) 2004 - 2006, Intel Corporation                                                         \r
+Copyright (c) 2004 - 2009, Intel Corporation                                                         \r
 All rights reserved. This program and the accompanying materials                          \r
 are licensed and made available under the terms and conditions of the BSD License         \r
 which accompanies this distribution.  The full text of the license may be found at        \r
 All rights reserved. This program and the accompanying materials                          \r
 are licensed and made available under the terms and conditions of the BSD License         \r
 which accompanies this distribution.  The full text of the license may be found at        \r
@@ -314,19 +314,14 @@ _ModuleEntryPoint (
   EFI_HANDLE                 Handle;\r
 \r
   //\r
   EFI_HANDLE                 Handle;\r
 \r
   //\r
-  // Cache a pointer to the Boot Services Table \r
+  // Call constructor for all libraries\r
   //\r
   //\r
-  mBS = SystemTable->BootServices;\r
+  ProcessLibraryConstructorList (ImageHandle, SystemTable);\r
 \r
   //\r
 \r
   //\r
-  // Retrieve the Loaded Image Protocol\r
+  // Cache a pointer to the Boot Services Table \r
   //\r
   //\r
-  Status = mBS->HandleProtocol (\r
-                  ImageHandle, \r
-                  &gEfiLoadedImageProtocolGuid,\r
-                  (VOID*)&LoadedImage\r
-                  );\r
-  ASSERT_EFI_ERROR (Status);\r
+  mBS = SystemTable->BootServices;\r
 \r
   //\r
   // Retrieve SMM Base Protocol\r
 \r
   //\r
   // Retrieve SMM Base Protocol\r
@@ -347,6 +342,27 @@ _ModuleEntryPoint (
   //\r
   //\r
   if (!InSmm) {\r
   //\r
   //\r
   if (!InSmm) {\r
+    //\r
+    // Retrieve the Loaded Image Protocol\r
+    //\r
+    Status = mBS->HandleProtocol (\r
+                    ImageHandle, \r
+                    &gEfiLoadedImageProtocolGuid,\r
+                    (VOID*)&LoadedImage\r
+                    );\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+    //\r
+    // Install the unload handler\r
+    //\r
+    Status = mBS->HandleProtocol (\r
+                      ImageHandle,\r
+                      &gEfiLoadedImageProtocolGuid,\r
+                      (VOID **)&LoadedImage\r
+                      );\r
+    ASSERT_EFI_ERROR (Status);\r
+    LoadedImage->Unload = _DriverUnloadHandler;\r
+\r
     //\r
     // Retrieve the Device Path Protocol from the DeviceHandle tha this driver was loaded from\r
     //\r
     //\r
     // Retrieve the Device Path Protocol from the DeviceHandle tha this driver was loaded from\r
     //\r
@@ -368,33 +384,17 @@ _ModuleEntryPoint (
     //\r
     Status = SmmBase->Register (SmmBase, CompleteFilePath, NULL, 0, &Handle, FALSE);\r
     ASSERT_EFI_ERROR (Status);\r
     //\r
     Status = SmmBase->Register (SmmBase, CompleteFilePath, NULL, 0, &Handle, FALSE);\r
     ASSERT_EFI_ERROR (Status);\r
-    return Status;\r
-  }\r
-\r
-  //\r
-  // Call constructor for all libraries\r
-  //\r
-  ProcessLibraryConstructorList (ImageHandle, SystemTable);\r
-\r
-  //\r
-  // Install the unload handler\r
-  //\r
-  Status = mBS->HandleProtocol (\r
-                    ImageHandle,\r
-                    &gEfiLoadedImageProtocolGuid,\r
-                    (VOID **)&LoadedImage\r
-                    );\r
-  ASSERT_EFI_ERROR (Status);\r
-  LoadedImage->Unload = _DriverUnloadHandler;\r
+  } else {\r
 \r
 \r
-  //\r
-  // Call the list of driver entry points\r
-  //\r
-  #ifdef __EDKII_GLUE_MODULE_ENTRY_POINT__\r
-  Status = (__EDKII_GLUE_MODULE_ENTRY_POINT__ (ImageHandle, SystemTable));\r
-  #else\r
-  Status = EFI_SUCCESS;\r
-  #endif\r
+    //\r
+    // Call the list of driver entry points\r
+    //\r
+    #ifdef __EDKII_GLUE_MODULE_ENTRY_POINT__\r
+    Status = (__EDKII_GLUE_MODULE_ENTRY_POINT__ (ImageHandle, SystemTable));\r
+    #else\r
+    Status = EFI_SUCCESS;\r
+    #endif\r
+  }\r
 \r
   if (EFI_ERROR (Status)) {\r
     ProcessLibraryDestructorList (ImageHandle, SystemTable);\r
 \r
   if (EFI_ERROR (Status)) {\r
     ProcessLibraryDestructorList (ImageHandle, SystemTable);\r