]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiCpuPkg/ExceptionLib: Import PeiCpuExceptionHandlerLib module
authorJeff Fan <jeff.fan@intel.com>
Tue, 24 May 2016 13:39:35 +0000 (21:39 +0800)
committerJeff Fan <jeff.fan@intel.com>
Wed, 1 Jun 2016 07:36:14 +0000 (15:36 +0800)
This module could be linked by CpuMpPei driver to handle reserved vector list
and provide spin lock for BSP/APs to prevent dump message corrupted.

Cc: Michael Kinney <michael.d.kinney@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Feng Tian <feng.tian@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan <jeff.fan@intel.com>
Reviewed-by: Feng Tian <feng.tian@intel.com>
UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h
UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c [new file with mode: 0644]
UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf [new file with mode: 0644]
UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.uni [new file with mode: 0644]
UefiCpuPkg/UefiCpuPkg.dsc

index bbf8004882fd4e3bad2c6b24262ba154884740cf..9c88012e0b51de0c57e39cc711c41a877789e23f 100644 (file)
 \r
 #include "ArchInterruptDefs.h"\r
 \r
+#define CPU_EXCEPTION_HANDLER_LIB_HOB_GUID \\r
+  { \\r
+    0xb21d9148, 0x9211, 0x4d8f, { 0xad, 0xd3, 0x66, 0xb1, 0x89, 0xc9, 0x2c, 0x83 } \\r
+  }\r
+\r
 //\r
 // Record exception handler information\r
 //\r
diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c
new file mode 100644 (file)
index 0000000..c3fd8ae
--- /dev/null
@@ -0,0 +1,184 @@
+/** @file\r
+  CPU exception handler library implementation for PEIM module.\r
+\r
+Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials are licensed and made available under\r
+the terms and conditions of the BSD License that accompanies this distribution.\r
+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 <PiPei.h>\r
+#include "CpuExceptionCommon.h"\r
+#include <Library/DebugLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+\r
+//\r
+// Image Alignment size for PEI phase\r
+//\r
+CONST UINTN    mImageAlignSize   = 4;\r
+CONST UINTN    mDoFarReturnFlag  = 0;\r
+\r
+EFI_GUID mCpuExceptrionHandlerLibHobGuid = CPU_EXCEPTION_HANDLER_LIB_HOB_GUID;\r
+\r
+/**\r
+  Get exception handler data pointer from GUIDed HOb.\r
+\r
+  @return  pointer to exception handler data. \r
+**/\r
+EXCEPTION_HANDLER_DATA *\r
+GetExceptionHandlerData (\r
+  VOID\r
+  )\r
+{\r
+  EFI_HOB_GUID_TYPE       *GuidHob;\r
+  VOID                    *DataInHob;\r
+  EXCEPTION_HANDLER_DATA  *ExceptionHandlerData;\r
+\r
+  ExceptionHandlerData = NULL;\r
+  GuidHob = GetFirstGuidHob (&mCpuExceptrionHandlerLibHobGuid);\r
+  if (GuidHob != NULL) {\r
+    DataInHob = GET_GUID_HOB_DATA (GuidHob);\r
+    ExceptionHandlerData = (EXCEPTION_HANDLER_DATA *)(*(UINTN *)DataInHob);\r
+  }\r
+  ASSERT (ExceptionHandlerData != NULL);\r
+  return ExceptionHandlerData;\r
+}\r
+\r
+/**\r
+  Common exception handler.\r
+\r
+  @param ExceptionType  Exception type.\r
+  @param SystemContext  Pointer to EFI_SYSTEM_CONTEXT.\r
+**/\r
+VOID\r
+EFIAPI\r
+CommonExceptionHandler (\r
+  IN EFI_EXCEPTION_TYPE   ExceptionType, \r
+  IN EFI_SYSTEM_CONTEXT   SystemContext\r
+  )\r
+{\r
+  EXCEPTION_HANDLER_DATA  *ExceptionHandlerData;\r
+\r
+  ExceptionHandlerData = GetExceptionHandlerData ();\r
+  CommonExceptionHandlerWorker (ExceptionType, SystemContext, ExceptionHandlerData);\r
+}\r
+\r
+/**\r
+  Initializes all CPU exceptions entries and provides the default exception handlers.\r
+  \r
+  Caller should try to get an array of interrupt and/or exception vectors that are in use and need to\r
+  persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.\r
+  If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL. \r
+  If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.\r
+  Note: Before invoking this API, caller must allocate memory for IDT table and load \r
+        IDTR by AsmWriteIdtr().\r
+\r
+  @param[in]  VectorInfo    Pointer to reserved vector list.\r
+  \r
+  @retval EFI_SUCCESS           CPU Exception Entries have been successfully initialized \r
+                                with default exception handlers.\r
+  @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.\r
+  @retval EFI_UNSUPPORTED       This function is not supported.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeCpuExceptionHandlers (\r
+  IN EFI_VECTOR_HANDOFF_INFO       *VectorInfo OPTIONAL\r
+  )\r
+{\r
+  EFI_STATUS                       Status;\r
+  EXCEPTION_HANDLER_DATA           *ExceptionHandlerData;\r
+  RESERVED_VECTORS_DATA            *ReservedVectors;\r
+\r
+  ReservedVectors = AllocatePool (sizeof (RESERVED_VECTORS_DATA) * CPU_EXCEPTION_NUM);\r
+  ASSERT (ReservedVectors != NULL);\r
+\r
+  ExceptionHandlerData = AllocatePool (sizeof (EXCEPTION_HANDLER_DATA));\r
+  ASSERT (ExceptionHandlerData != NULL);\r
+  ExceptionHandlerData->ReservedVectors          = ReservedVectors;\r
+  ExceptionHandlerData->ExternalInterruptHandler = NULL;\r
+  InitializeSpinLock (&ExceptionHandlerData->DisplayMessageSpinLock);\r
+\r
+  Status = InitializeCpuExceptionHandlersWorker (VectorInfo, ExceptionHandlerData);\r
+  if (EFI_ERROR (Status)) {\r
+    FreePool (ReservedVectors);\r
+    FreePool (ExceptionHandlerData);\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Build location of CPU MP DATA buffer in HOB\r
+  //\r
+  BuildGuidDataHob (\r
+    &mCpuExceptrionHandlerLibHobGuid,\r
+    (VOID *)&ExceptionHandlerData,\r
+    sizeof(UINT64)\r
+    );\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Initializes all CPU interrupt/exceptions entries and provides the default interrupt/exception handlers.\r
+  \r
+  Caller should try to get an array of interrupt and/or exception vectors that are in use and need to\r
+  persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.\r
+  If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL. \r
+  If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.\r
+\r
+  @param[in]  VectorInfo    Pointer to reserved vector list.\r
+  \r
+  @retval EFI_SUCCESS           All CPU interrupt/exception entries have been successfully initialized \r
+                                with default interrupt/exception handlers.\r
+  @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.\r
+  @retval EFI_UNSUPPORTED       This function is not supported.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeCpuInterruptHandlers (\r
+  IN EFI_VECTOR_HANDOFF_INFO       *VectorInfo OPTIONAL\r
+  )\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+  Registers a function to be called from the processor interrupt handler.\r
+\r
+  This function registers and enables the handler specified by InterruptHandler for a processor \r
+  interrupt or exception type specified by InterruptType. If InterruptHandler is NULL, then the \r
+  handler for the processor interrupt or exception type specified by InterruptType is uninstalled. \r
+  The installed handler is called once for each processor interrupt or exception.\r
+  NOTE: This function should be invoked after InitializeCpuExceptionHandlers() or\r
+  InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED returned.\r
+\r
+  @param[in]  InterruptType     Defines which interrupt or exception to hook.\r
+  @param[in]  InterruptHandler  A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called\r
+                                when a processor interrupt occurs. If this parameter is NULL, then the handler\r
+                                will be uninstalled.\r
+\r
+  @retval EFI_SUCCESS           The handler for the processor interrupt was successfully installed or uninstalled.\r
+  @retval EFI_ALREADY_STARTED   InterruptHandler is not NULL, and a handler for InterruptType was\r
+                                previously installed.\r
+  @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not\r
+                                previously installed.\r
+  @retval EFI_UNSUPPORTED       The interrupt specified by InterruptType is not supported,\r
+                                or this function is not supported.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+RegisterCpuInterruptHandler (\r
+  IN EFI_EXCEPTION_TYPE            InterruptType,\r
+  IN EFI_CPU_INTERRUPT_HANDLER     InterruptHandler\r
+  )\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}
\ No newline at end of file
diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf
new file mode 100644 (file)
index 0000000..d8a2997
--- /dev/null
@@ -0,0 +1,61 @@
+## @file\r
+#  CPU Exception Handler library instance for PEI module.\r
+#\r
+#  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+#  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                      = PeiCpuExceptionHandlerLib\r
+  MODULE_UNI_FILE                = PeiCpuExceptionHandlerLib.uni\r
+  FILE_GUID                      = 980DDA67-44A6-4897-99E6-275290B71F9E\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.1\r
+  LIBRARY_CLASS                  = CpuExceptionHandlerLib|PEI_CORE PEIM\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.Ia32]\r
+  Ia32/ExceptionHandlerAsm.asm\r
+  Ia32/ExceptionHandlerAsm.S   |GCC\r
+  Ia32/ArchExceptionHandler.c\r
+  Ia32/ArchInterruptDefs.h\r
+\r
+[Sources.X64]\r
+  X64/ExceptionHandlerAsm.asm\r
+  X64/ExceptionHandlerAsm.S   |GCC\r
+  X64/ArchExceptionHandler.c\r
+  X64/ArchInterruptDefs.h\r
+\r
+[Sources.common]\r
+  CpuExceptionCommon.h\r
+  CpuExceptionCommon.c\r
+  PeiCpuException.c\r
+  PeiDxeSmmCpuException.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  UefiCpuPkg/UefiCpuPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  SerialPortLib\r
+  PrintLib\r
+  LocalApicLib\r
+  PeCoffGetEntryPointLib\r
+  HobLib\r
+  MemoryAllocationLib\r
+  SynchronizationLib\r
diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.uni b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.uni
new file mode 100644 (file)
index 0000000..8baf045
--- /dev/null
@@ -0,0 +1,22 @@
+// /** @file\r
+// CPU Exception Handler library instance for PEI module.\r
+//\r
+// CPU Exception Handler library instance for PEI module.\r
+//\r
+// Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+//\r
+// 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
+\r
+#string STR_MODULE_ABSTRACT             #language en-US "CPU Exception Handler library instance for PEI module."\r
+\r
+#string STR_MODULE_DESCRIPTION          #language en-US "CPU Exception Handler library instance for PEI module."\r
+\r
index 731915286c3fbf99b22d464baf9e742a02e52388..b35f41b1ed97e474c36f7c61346a7369ebcdadd5 100644 (file)
@@ -73,6 +73,7 @@
 \r
 [LibraryClasses.IA32.PEIM, LibraryClasses.X64.PEIM]\r
   PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLibIdt/PeiServicesTablePointerLibIdt.inf\r
+  CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf\r
 \r
 [LibraryClasses.IPF.PEIM]\r
   PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLibKr7/PeiServicesTablePointerLibKr7.inf\r
   UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf\r
   UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf\r
   UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf\r
+  UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf\r
   UefiCpuPkg/Library/MtrrLib/MtrrLib.inf\r
   UefiCpuPkg/Library/PlatformSecLibNull/PlatformSecLibNull.inf\r
   UefiCpuPkg/Library/SmmCpuPlatformHookLibNull/SmmCpuPlatformHookLibNull.inf\r