]>
Commit | Line | Data |
---|---|---|
a81abf16 JF |
1 | /** @file\r |
2 | CPU exception handler library implementation for PEIM module.\r | |
3 | \r | |
1b2f7b3e | 4 | Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.<BR>\r |
a81abf16 JF |
5 | This program and the accompanying materials are licensed and made available under\r |
6 | the terms and conditions of the BSD License that accompanies this distribution.\r | |
7 | The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php.\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT 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 | |
a81abf16 JF |
21 | CONST UINTN mDoFarReturnFlag = 0;\r |
22 | \r | |
23 | EFI_GUID mCpuExceptrionHandlerLibHobGuid = CPU_EXCEPTION_HANDLER_LIB_HOB_GUID;\r | |
24 | \r | |
25 | /**\r | |
26 | Get exception handler data pointer from GUIDed HOb.\r | |
27 | \r | |
dd563742 | 28 | @return pointer to exception handler data.\r |
a81abf16 JF |
29 | **/\r |
30 | EXCEPTION_HANDLER_DATA *\r | |
31 | GetExceptionHandlerData (\r | |
32 | VOID\r | |
33 | )\r | |
34 | {\r | |
35 | EFI_HOB_GUID_TYPE *GuidHob;\r | |
36 | VOID *DataInHob;\r | |
37 | EXCEPTION_HANDLER_DATA *ExceptionHandlerData;\r | |
38 | \r | |
39 | ExceptionHandlerData = NULL;\r | |
40 | GuidHob = GetFirstGuidHob (&mCpuExceptrionHandlerLibHobGuid);\r | |
41 | if (GuidHob != NULL) {\r | |
42 | DataInHob = GET_GUID_HOB_DATA (GuidHob);\r | |
43 | ExceptionHandlerData = (EXCEPTION_HANDLER_DATA *)(*(UINTN *)DataInHob);\r | |
44 | }\r | |
45 | ASSERT (ExceptionHandlerData != NULL);\r | |
46 | return ExceptionHandlerData;\r | |
47 | }\r | |
48 | \r | |
49 | /**\r | |
50 | Common exception handler.\r | |
51 | \r | |
52 | @param ExceptionType Exception type.\r | |
53 | @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.\r | |
54 | **/\r | |
55 | VOID\r | |
56 | EFIAPI\r | |
57 | CommonExceptionHandler (\r | |
dd563742 | 58 | IN EFI_EXCEPTION_TYPE ExceptionType,\r |
a81abf16 JF |
59 | IN EFI_SYSTEM_CONTEXT SystemContext\r |
60 | )\r | |
61 | {\r | |
62 | EXCEPTION_HANDLER_DATA *ExceptionHandlerData;\r | |
63 | \r | |
64 | ExceptionHandlerData = GetExceptionHandlerData ();\r | |
65 | CommonExceptionHandlerWorker (ExceptionType, SystemContext, ExceptionHandlerData);\r | |
66 | }\r | |
67 | \r | |
68 | /**\r | |
69 | Initializes all CPU exceptions entries and provides the default exception handlers.\r | |
dd563742 | 70 | \r |
a81abf16 JF |
71 | Caller should try to get an array of interrupt and/or exception vectors that are in use and need to\r |
72 | persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.\r | |
dd563742 | 73 | If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL.\r |
a81abf16 | 74 | If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.\r |
dd563742 | 75 | Note: Before invoking this API, caller must allocate memory for IDT table and load\r |
a81abf16 JF |
76 | IDTR by AsmWriteIdtr().\r |
77 | \r | |
78 | @param[in] VectorInfo Pointer to reserved vector list.\r | |
dd563742 JF |
79 | \r |
80 | @retval EFI_SUCCESS CPU Exception Entries have been successfully initialized\r | |
a81abf16 JF |
81 | with default exception handlers.\r |
82 | @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.\r | |
83 | @retval EFI_UNSUPPORTED This function is not supported.\r | |
84 | \r | |
85 | **/\r | |
86 | EFI_STATUS\r | |
87 | EFIAPI\r | |
88 | InitializeCpuExceptionHandlers (\r | |
89 | IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL\r | |
90 | )\r | |
91 | {\r | |
92 | EFI_STATUS Status;\r | |
93 | EXCEPTION_HANDLER_DATA *ExceptionHandlerData;\r | |
94 | RESERVED_VECTORS_DATA *ReservedVectors;\r | |
95 | \r | |
96 | ReservedVectors = AllocatePool (sizeof (RESERVED_VECTORS_DATA) * CPU_EXCEPTION_NUM);\r | |
97 | ASSERT (ReservedVectors != NULL);\r | |
98 | \r | |
99 | ExceptionHandlerData = AllocatePool (sizeof (EXCEPTION_HANDLER_DATA));\r | |
100 | ASSERT (ExceptionHandlerData != NULL);\r | |
101 | ExceptionHandlerData->ReservedVectors = ReservedVectors;\r | |
102 | ExceptionHandlerData->ExternalInterruptHandler = NULL;\r | |
103 | InitializeSpinLock (&ExceptionHandlerData->DisplayMessageSpinLock);\r | |
104 | \r | |
105 | Status = InitializeCpuExceptionHandlersWorker (VectorInfo, ExceptionHandlerData);\r | |
106 | if (EFI_ERROR (Status)) {\r | |
107 | FreePool (ReservedVectors);\r | |
108 | FreePool (ExceptionHandlerData);\r | |
109 | return Status;\r | |
110 | }\r | |
111 | \r | |
112 | //\r | |
113 | // Build location of CPU MP DATA buffer in HOB\r | |
114 | //\r | |
115 | BuildGuidDataHob (\r | |
116 | &mCpuExceptrionHandlerLibHobGuid,\r | |
117 | (VOID *)&ExceptionHandlerData,\r | |
118 | sizeof(UINT64)\r | |
119 | );\r | |
120 | \r | |
121 | return EFI_SUCCESS;\r | |
122 | }\r | |
123 | \r | |
124 | /**\r | |
125 | Initializes all CPU interrupt/exceptions entries and provides the default interrupt/exception handlers.\r | |
dd563742 | 126 | \r |
a81abf16 JF |
127 | Caller should try to get an array of interrupt and/or exception vectors that are in use and need to\r |
128 | persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.\r | |
dd563742 | 129 | If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL.\r |
a81abf16 JF |
130 | If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.\r |
131 | \r | |
132 | @param[in] VectorInfo Pointer to reserved vector list.\r | |
dd563742 JF |
133 | \r |
134 | @retval EFI_SUCCESS All CPU interrupt/exception entries have been successfully initialized\r | |
a81abf16 JF |
135 | with default interrupt/exception handlers.\r |
136 | @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.\r | |
137 | @retval EFI_UNSUPPORTED This function is not supported.\r | |
138 | \r | |
139 | **/\r | |
140 | EFI_STATUS\r | |
141 | EFIAPI\r | |
142 | InitializeCpuInterruptHandlers (\r | |
143 | IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL\r | |
144 | )\r | |
145 | {\r | |
146 | return EFI_UNSUPPORTED;\r | |
147 | }\r | |
148 | \r | |
149 | /**\r | |
150 | Registers a function to be called from the processor interrupt handler.\r | |
151 | \r | |
dd563742 JF |
152 | This function registers and enables the handler specified by InterruptHandler for a processor\r |
153 | interrupt or exception type specified by InterruptType. If InterruptHandler is NULL, then the\r | |
154 | handler for the processor interrupt or exception type specified by InterruptType is uninstalled.\r | |
a81abf16 JF |
155 | The installed handler is called once for each processor interrupt or exception.\r |
156 | NOTE: This function should be invoked after InitializeCpuExceptionHandlers() or\r | |
157 | InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED returned.\r | |
158 | \r | |
159 | @param[in] InterruptType Defines which interrupt or exception to hook.\r | |
160 | @param[in] InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called\r | |
161 | when a processor interrupt occurs. If this parameter is NULL, then the handler\r | |
162 | will be uninstalled.\r | |
163 | \r | |
164 | @retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.\r | |
165 | @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InterruptType was\r | |
166 | previously installed.\r | |
167 | @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not\r | |
168 | previously installed.\r | |
169 | @retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not supported,\r | |
170 | or this function is not supported.\r | |
171 | **/\r | |
172 | EFI_STATUS\r | |
173 | EFIAPI\r | |
174 | RegisterCpuInterruptHandler (\r | |
175 | IN EFI_EXCEPTION_TYPE InterruptType,\r | |
176 | IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler\r | |
177 | )\r | |
178 | {\r | |
179 | return EFI_UNSUPPORTED;\r | |
0ff5aa9c JW |
180 | }\r |
181 | \r | |
182 | /**\r | |
183 | Initializes all CPU exceptions entries with optional extra initializations.\r | |
184 | \r | |
185 | By default, this method should include all functionalities implemented by\r | |
186 | InitializeCpuExceptionHandlers(), plus extra initialization works, if any.\r | |
187 | This could be done by calling InitializeCpuExceptionHandlers() directly\r | |
188 | in this method besides the extra works.\r | |
189 | \r | |
190 | InitData is optional and its use and content are processor arch dependent.\r | |
191 | The typical usage of it is to convey resources which have to be reserved\r | |
192 | elsewhere and are necessary for the extra initializations of exception.\r | |
193 | \r | |
194 | @param[in] VectorInfo Pointer to reserved vector list.\r | |
195 | @param[in] InitData Pointer to data optional for extra initializations\r | |
196 | of exception.\r | |
197 | \r | |
198 | @retval EFI_SUCCESS The exceptions have been successfully\r | |
199 | initialized.\r | |
200 | @retval EFI_INVALID_PARAMETER VectorInfo or InitData contains invalid\r | |
201 | content.\r | |
202 | \r | |
203 | **/\r | |
204 | EFI_STATUS\r | |
205 | EFIAPI\r | |
206 | InitializeCpuExceptionHandlersEx (\r | |
207 | IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,\r | |
208 | IN CPU_EXCEPTION_INIT_DATA *InitData OPTIONAL\r | |
209 | )\r | |
210 | {\r | |
211 | return InitializeCpuExceptionHandlers (VectorInfo);\r | |
212 | }\r |