]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c
UefiCpuPkg: Fix typos in comments
[mirror_edk2.git] / UefiCpuPkg / Library / CpuExceptionHandlerLib / PeiCpuException.c
CommitLineData
a81abf16
JF
1/** @file\r
2 CPU exception handler library implementation for PEIM module.\r
3\r
4Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials are licensed and made available under\r
6the terms and conditions of the BSD License that accompanies this distribution.\r
7The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php.\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include <PiPei.h>\r
16#include "CpuExceptionCommon.h"\r
17#include <Library/DebugLib.h>\r
18#include <Library/HobLib.h>\r
19#include <Library/MemoryAllocationLib.h>\r
20\r
21//\r
22// Image Alignment size for PEI phase\r
23//\r
24CONST UINTN mImageAlignSize = 4;\r
25CONST UINTN mDoFarReturnFlag = 0;\r
26\r
27EFI_GUID mCpuExceptrionHandlerLibHobGuid = CPU_EXCEPTION_HANDLER_LIB_HOB_GUID;\r
28\r
29/**\r
30 Get exception handler data pointer from GUIDed HOb.\r
31\r
32 @return pointer to exception handler data. \r
33**/\r
34EXCEPTION_HANDLER_DATA *\r
35GetExceptionHandlerData (\r
36 VOID\r
37 )\r
38{\r
39 EFI_HOB_GUID_TYPE *GuidHob;\r
40 VOID *DataInHob;\r
41 EXCEPTION_HANDLER_DATA *ExceptionHandlerData;\r
42\r
43 ExceptionHandlerData = NULL;\r
44 GuidHob = GetFirstGuidHob (&mCpuExceptrionHandlerLibHobGuid);\r
45 if (GuidHob != NULL) {\r
46 DataInHob = GET_GUID_HOB_DATA (GuidHob);\r
47 ExceptionHandlerData = (EXCEPTION_HANDLER_DATA *)(*(UINTN *)DataInHob);\r
48 }\r
49 ASSERT (ExceptionHandlerData != NULL);\r
50 return ExceptionHandlerData;\r
51}\r
52\r
53/**\r
54 Common exception handler.\r
55\r
56 @param ExceptionType Exception type.\r
57 @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.\r
58**/\r
59VOID\r
60EFIAPI\r
61CommonExceptionHandler (\r
62 IN EFI_EXCEPTION_TYPE ExceptionType, \r
63 IN EFI_SYSTEM_CONTEXT SystemContext\r
64 )\r
65{\r
66 EXCEPTION_HANDLER_DATA *ExceptionHandlerData;\r
67\r
68 ExceptionHandlerData = GetExceptionHandlerData ();\r
69 CommonExceptionHandlerWorker (ExceptionType, SystemContext, ExceptionHandlerData);\r
70}\r
71\r
72/**\r
73 Initializes all CPU exceptions entries and provides the default exception handlers.\r
74 \r
75 Caller should try to get an array of interrupt and/or exception vectors that are in use and need to\r
76 persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.\r
77 If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL. \r
78 If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.\r
79 Note: Before invoking this API, caller must allocate memory for IDT table and load \r
80 IDTR by AsmWriteIdtr().\r
81\r
82 @param[in] VectorInfo Pointer to reserved vector list.\r
83 \r
84 @retval EFI_SUCCESS CPU Exception Entries have been successfully initialized \r
85 with default exception handlers.\r
86 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.\r
87 @retval EFI_UNSUPPORTED This function is not supported.\r
88\r
89**/\r
90EFI_STATUS\r
91EFIAPI\r
92InitializeCpuExceptionHandlers (\r
93 IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL\r
94 )\r
95{\r
96 EFI_STATUS Status;\r
97 EXCEPTION_HANDLER_DATA *ExceptionHandlerData;\r
98 RESERVED_VECTORS_DATA *ReservedVectors;\r
99\r
100 ReservedVectors = AllocatePool (sizeof (RESERVED_VECTORS_DATA) * CPU_EXCEPTION_NUM);\r
101 ASSERT (ReservedVectors != NULL);\r
102\r
103 ExceptionHandlerData = AllocatePool (sizeof (EXCEPTION_HANDLER_DATA));\r
104 ASSERT (ExceptionHandlerData != NULL);\r
105 ExceptionHandlerData->ReservedVectors = ReservedVectors;\r
106 ExceptionHandlerData->ExternalInterruptHandler = NULL;\r
107 InitializeSpinLock (&ExceptionHandlerData->DisplayMessageSpinLock);\r
108\r
109 Status = InitializeCpuExceptionHandlersWorker (VectorInfo, ExceptionHandlerData);\r
110 if (EFI_ERROR (Status)) {\r
111 FreePool (ReservedVectors);\r
112 FreePool (ExceptionHandlerData);\r
113 return Status;\r
114 }\r
115\r
116 //\r
117 // Build location of CPU MP DATA buffer in HOB\r
118 //\r
119 BuildGuidDataHob (\r
120 &mCpuExceptrionHandlerLibHobGuid,\r
121 (VOID *)&ExceptionHandlerData,\r
122 sizeof(UINT64)\r
123 );\r
124\r
125 return EFI_SUCCESS;\r
126}\r
127\r
128/**\r
129 Initializes all CPU interrupt/exceptions entries and provides the default interrupt/exception handlers.\r
130 \r
131 Caller should try to get an array of interrupt and/or exception vectors that are in use and need to\r
132 persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.\r
133 If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL. \r
134 If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.\r
135\r
136 @param[in] VectorInfo Pointer to reserved vector list.\r
137 \r
138 @retval EFI_SUCCESS All CPU interrupt/exception entries have been successfully initialized \r
139 with default interrupt/exception handlers.\r
140 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.\r
141 @retval EFI_UNSUPPORTED This function is not supported.\r
142\r
143**/\r
144EFI_STATUS\r
145EFIAPI\r
146InitializeCpuInterruptHandlers (\r
147 IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL\r
148 )\r
149{\r
150 return EFI_UNSUPPORTED;\r
151}\r
152\r
153/**\r
154 Registers a function to be called from the processor interrupt handler.\r
155\r
156 This function registers and enables the handler specified by InterruptHandler for a processor \r
157 interrupt or exception type specified by InterruptType. If InterruptHandler is NULL, then the \r
158 handler for the processor interrupt or exception type specified by InterruptType is uninstalled. \r
159 The installed handler is called once for each processor interrupt or exception.\r
160 NOTE: This function should be invoked after InitializeCpuExceptionHandlers() or\r
161 InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED returned.\r
162\r
163 @param[in] InterruptType Defines which interrupt or exception to hook.\r
164 @param[in] InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called\r
165 when a processor interrupt occurs. If this parameter is NULL, then the handler\r
166 will be uninstalled.\r
167\r
168 @retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.\r
169 @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InterruptType was\r
170 previously installed.\r
171 @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not\r
172 previously installed.\r
173 @retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not supported,\r
174 or this function is not supported.\r
175**/\r
176EFI_STATUS\r
177EFIAPI\r
178RegisterCpuInterruptHandler (\r
179 IN EFI_EXCEPTION_TYPE InterruptType,\r
180 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler\r
181 )\r
182{\r
183 return EFI_UNSUPPORTED;\r
184}