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