]> git.proxmox.com Git - mirror_edk2.git/commitdiff
IntelFsp2WrapperPkg: BaseFspWrapperApiLib support for X64
authorTed Kuo <ted.kuo@intel.com>
Fri, 15 Apr 2022 08:37:42 +0000 (01:37 -0700)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sat, 16 Apr 2022 00:18:14 +0000 (00:18 +0000)
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3893
Add Execute64BitCode to execute 64bit code from long mode directly
in PEI 64bit.

Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Ashraf Ali S <ashraf.ali.s@intel.com>
Signed-off-by: Ted Kuo <ted.kuo@intel.com>
Reviewed-by: Chasel Chiu <chasel.chiu@intel.com>
Reviewed-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
IntelFsp2WrapperPkg/Library/BaseFspWrapperApiLib/FspWrapperApiLib.c
IntelFsp2WrapperPkg/Library/BaseFspWrapperApiLib/IA32/DispatchExecute.c
IntelFsp2WrapperPkg/Library/BaseFspWrapperApiLib/X64/DispatchExecute.c

index 67faad927ccbed05db773c25dc12499470310426..5b5beb5c6557802fc085196bfa32d25d6fdfb51f 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Provide FSP API related function.\r
 \r
-  Copyright (c) 2014 - 2017, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2014 - 2022, Intel Corporation. All rights reserved.<BR>\r
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
@@ -13,7 +13,7 @@
 #include <Library/BaseMemoryLib.h>\r
 \r
 /**\r
-  Wrapper for a thunk  to transition from long mode to compatibility mode to execute 32-bit code and then transit back to\r
+  Wrapper for a thunk to transition from long mode to compatibility mode to execute 32-bit code and then transit back to\r
   long mode.\r
 \r
   @param[in] Function     The 32bit code entry to be executed.\r
@@ -29,6 +29,22 @@ Execute32BitCode (
   IN UINT64  Param2\r
   );\r
 \r
+/**\r
+  Wrapper to execute 64-bit code directly from long mode.\r
+\r
+  @param[in] Function     The 64bit code entry to be executed.\r
+  @param[in] Param1       The first parameter to pass to 64bit code.\r
+  @param[in] Param2       The second parameter to pass to 64bit code.\r
+\r
+  @return EFI_STATUS.\r
+**/\r
+EFI_STATUS\r
+Execute64BitCode (\r
+  IN UINT64  Function,\r
+  IN UINT64  Param1,\r
+  IN UINT64  Param2\r
+  );\r
+\r
 /**\r
   Find FSP header pointer.\r
 \r
@@ -94,7 +110,11 @@ CallFspNotifyPhase (
 \r
   NotifyPhaseApi = (FSP_NOTIFY_PHASE)((UINTN)FspHeader->ImageBase + FspHeader->NotifyPhaseEntryOffset);\r
   InterruptState = SaveAndDisableInterrupts ();\r
-  Status         = Execute32BitCode ((UINTN)NotifyPhaseApi, (UINTN)NotifyPhaseParams, (UINTN)NULL);\r
+  if ((FspHeader->ImageAttribute & IMAGE_ATTRIBUTE_64BIT_MODE_SUPPORT) == FSP_IA32) {\r
+    Status = Execute32BitCode ((UINTN)NotifyPhaseApi, (UINTN)NotifyPhaseParams, (UINTN)NULL);\r
+  } else {\r
+    Status = Execute64BitCode ((UINTN)NotifyPhaseApi, (UINTN)NotifyPhaseParams, (UINTN)NULL);\r
+  }\r
   SetInterruptState (InterruptState);\r
 \r
   return Status;\r
@@ -127,7 +147,11 @@ CallFspMemoryInit (
 \r
   FspMemoryInitApi = (FSP_MEMORY_INIT)((UINTN)FspHeader->ImageBase + FspHeader->FspMemoryInitEntryOffset);\r
   InterruptState   = SaveAndDisableInterrupts ();\r
-  Status           = Execute32BitCode ((UINTN)FspMemoryInitApi, (UINTN)FspmUpdDataPtr, (UINTN)HobListPtr);\r
+  if ((FspHeader->ImageAttribute & IMAGE_ATTRIBUTE_64BIT_MODE_SUPPORT) == FSP_IA32) {\r
+    Status = Execute32BitCode ((UINTN)FspMemoryInitApi, (UINTN)FspmUpdDataPtr, (UINTN)HobListPtr);\r
+  } else {\r
+    Status = Execute64BitCode ((UINTN)FspMemoryInitApi, (UINTN)FspmUpdDataPtr, (UINTN)HobListPtr);\r
+  }\r
   SetInterruptState (InterruptState);\r
 \r
   return Status;\r
@@ -158,7 +182,11 @@ CallTempRamExit (
 \r
   TempRamExitApi = (FSP_TEMP_RAM_EXIT)((UINTN)FspHeader->ImageBase + FspHeader->TempRamExitEntryOffset);\r
   InterruptState = SaveAndDisableInterrupts ();\r
-  Status         = Execute32BitCode ((UINTN)TempRamExitApi, (UINTN)TempRamExitParam, (UINTN)NULL);\r
+  if ((FspHeader->ImageAttribute & IMAGE_ATTRIBUTE_64BIT_MODE_SUPPORT) == FSP_IA32) {\r
+    Status = Execute32BitCode ((UINTN)TempRamExitApi, (UINTN)TempRamExitParam, (UINTN)NULL);\r
+  } else {\r
+    Status = Execute64BitCode ((UINTN)TempRamExitApi, (UINTN)TempRamExitParam, (UINTN)NULL);\r
+  }\r
   SetInterruptState (InterruptState);\r
 \r
   return Status;\r
@@ -189,7 +217,11 @@ CallFspSiliconInit (
 \r
   FspSiliconInitApi = (FSP_SILICON_INIT)((UINTN)FspHeader->ImageBase + FspHeader->FspSiliconInitEntryOffset);\r
   InterruptState    = SaveAndDisableInterrupts ();\r
-  Status            = Execute32BitCode ((UINTN)FspSiliconInitApi, (UINTN)FspsUpdDataPtr, (UINTN)NULL);\r
+  if ((FspHeader->ImageAttribute & IMAGE_ATTRIBUTE_64BIT_MODE_SUPPORT) == FSP_IA32) {\r
+    Status = Execute32BitCode ((UINTN)FspSiliconInitApi, (UINTN)FspsUpdDataPtr, (UINTN)NULL);\r
+  } else {\r
+    Status = Execute64BitCode ((UINTN)FspSiliconInitApi, (UINTN)FspsUpdDataPtr, (UINTN)NULL);\r
+  }\r
   SetInterruptState (InterruptState);\r
 \r
   return Status;\r
index 4f6a8dd1a73f49439666df3ed978dbb6750d772f..a17ca7dcabe85d737086df0e6cbb94683c3a4049 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Execute 32-bit code in Protected Mode.\r
 \r
-  Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2014 - 2022, Intel Corporation. All rights reserved.<BR>\r
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
@@ -49,3 +49,24 @@ Execute32BitCode (
 \r
   return Status;\r
 }\r
+\r
+/**\r
+  Wrapper for a thunk to transition from compatibility mode to long mode to execute 64-bit code and then transit back to\r
+  compatibility mode.\r
+\r
+  @param[in] Function     The 64bit code entry to be executed.\r
+  @param[in] Param1       The first parameter to pass to 64bit code.\r
+  @param[in] Param2       The second parameter to pass to 64bit code.\r
+\r
+  @return EFI_STATUS.\r
+**/\r
+EFI_STATUS\r
+Execute64BitCode (\r
+  IN UINT64  Function,\r
+  IN UINT64  Param1,\r
+  IN UINT64  Param2\r
+  )\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
index 2ee5bc3dd4424391073ee5cf0eb8b00a96edb14b..591a5c7a5591455862395624f7bada43b7a3fbe0 100644 (file)
@@ -1,9 +1,9 @@
 /** @file\r
-  Execute 32-bit code in Long Mode.\r
+  Execute 64-bit code in Long Mode.\r
   Provide a thunk function to transition from long mode to compatibility mode to execute 32-bit code and then transit\r
   back to long mode.\r
 \r
-  Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2014 - 2022, Intel Corporation. All rights reserved.<BR>\r
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 #include <Library/BaseLib.h>\r
 #include <FspEas.h>\r
 \r
+/**\r
+  FSP API functions.\r
+\r
+  @param[in] Param1       The first parameter to pass to 64bit code.\r
+  @param[in] Param2       The second parameter to pass to 64bit code.\r
+\r
+  @return EFI_STATUS.\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *FSP_FUNCTION)(\r
+  IN VOID *Param1,\r
+  IN VOID *Param2\r
+  );\r
+\r
 #pragma pack(1)\r
 typedef union {\r
   struct {\r
@@ -80,7 +95,7 @@ AsmExecute32BitCode (
   );\r
 \r
 /**\r
-  Wrapper for a thunk  to transition from long mode to compatibility mode to execute 32-bit code and then transit back to\r
+  Wrapper for a thunk to transition from long mode to compatibility mode to execute 32-bit code and then transit back to\r
   long mode.\r
 \r
   @param[in] Function     The 32bit code entry to be executed.\r
@@ -110,3 +125,29 @@ Execute32BitCode (
 \r
   return Status;\r
 }\r
+\r
+/**\r
+  Wrapper to execute 64-bit code directly from long mode.\r
+\r
+  @param[in] Function     The 64bit code entry to be executed.\r
+  @param[in] Param1       The first parameter to pass to 64bit code.\r
+  @param[in] Param2       The second parameter to pass to 64bit code.\r
+\r
+  @return EFI_STATUS.\r
+**/\r
+EFI_STATUS\r
+Execute64BitCode (\r
+  IN UINT64  Function,\r
+  IN UINT64  Param1,\r
+  IN UINT64  Param2\r
+  )\r
+{\r
+  FSP_FUNCTION  EntryFunc;\r
+  EFI_STATUS    Status;\r
+\r
+  EntryFunc = (FSP_FUNCTION)(UINTN)(Function);\r
+  Status    = EntryFunc ((VOID *)(UINTN)Param1, (VOID *)(UINTN)Param2);\r
+\r
+  return Status;\r
+}\r
+\r