]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c
9f0af4120a7bf034d7a08fcabcbdd27fc69a6481
[mirror_edk2.git] / UefiCpuPkg / Library / CpuExceptionHandlerLib / SmmException.c
1 /** @file
2 CPU exception handler library implementation for SMM modules.
3
4 Copyright (c) 2013 - 2017, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include <PiSmm.h>
10 #include "CpuExceptionCommon.h"
11
12 CONST UINTN mDoFarReturnFlag = 1;
13
14 RESERVED_VECTORS_DATA mReservedVectorsData[CPU_EXCEPTION_NUM];
15 EFI_CPU_INTERRUPT_HANDLER mExternalInterruptHandlerTable[CPU_EXCEPTION_NUM];
16 EXCEPTION_HANDLER_DATA mExceptionHandlerData = {
17 0, // To be fixed
18 0, // To be fixed
19 mReservedVectorsData,
20 mExternalInterruptHandlerTable
21 };
22
23 /**
24 Common exception handler.
25
26 @param ExceptionType Exception type.
27 @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.
28 **/
29 VOID
30 EFIAPI
31 CommonExceptionHandler (
32 IN EFI_EXCEPTION_TYPE ExceptionType,
33 IN EFI_SYSTEM_CONTEXT SystemContext
34 )
35 {
36 CommonExceptionHandlerWorker (ExceptionType, SystemContext, &mExceptionHandlerData);
37 }
38
39 /**
40 Initializes all CPU exceptions entries and provides the default exception handlers.
41
42 Caller should try to get an array of interrupt and/or exception vectors that are in use and need to
43 persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.
44 If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL.
45 If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.
46
47 @param[in] VectorInfo Pointer to reserved vector list.
48
49 @retval EFI_SUCCESS CPU Exception Entries have been successfully initialized
50 with default exception handlers.
51 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.
52 @retval EFI_UNSUPPORTED This function is not supported.
53
54 **/
55 EFI_STATUS
56 EFIAPI
57 InitializeCpuExceptionHandlers (
58 IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
59 )
60 {
61 InitializeSpinLock (&mExceptionHandlerData.DisplayMessageSpinLock);
62 return InitializeCpuExceptionHandlersWorker (VectorInfo, &mExceptionHandlerData);
63 }
64
65 /**
66 Initializes all CPU interrupt/exceptions entries and provides the default interrupt/exception handlers.
67
68 Caller should try to get an array of interrupt and/or exception vectors that are in use and need to
69 persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.
70 If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL.
71 If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.
72
73 @param[in] VectorInfo Pointer to reserved vector list.
74
75 @retval EFI_SUCCESS All CPU interrupt/exception entries have been successfully initialized
76 with default interrupt/exception handlers.
77 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.
78 @retval EFI_UNSUPPORTED This function is not supported.
79
80 **/
81 EFI_STATUS
82 EFIAPI
83 InitializeCpuInterruptHandlers (
84 IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
85 )
86 {
87 return EFI_UNSUPPORTED;
88 }
89
90 /**
91 Registers a function to be called from the processor interrupt handler.
92
93 This function registers and enables the handler specified by InterruptHandler for a processor
94 interrupt or exception type specified by InterruptType. If InterruptHandler is NULL, then the
95 handler for the processor interrupt or exception type specified by InterruptType is uninstalled.
96 The installed handler is called once for each processor interrupt or exception.
97 NOTE: This function should be invoked after InitializeCpuExceptionHandlers() or
98 InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED returned.
99
100 @param[in] InterruptType Defines which interrupt or exception to hook.
101 @param[in] InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called
102 when a processor interrupt occurs. If this parameter is NULL, then the handler
103 will be uninstalled.
104
105 @retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.
106 @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InterruptType was
107 previously installed.
108 @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not
109 previously installed.
110 @retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not supported,
111 or this function is not supported.
112 **/
113 EFI_STATUS
114 EFIAPI
115 RegisterCpuInterruptHandler (
116 IN EFI_EXCEPTION_TYPE InterruptType,
117 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
118 )
119 {
120 return RegisterCpuInterruptHandlerWorker (InterruptType, InterruptHandler, &mExceptionHandlerData);
121 }
122
123 /**
124 Initializes all CPU exceptions entries with optional extra initializations.
125
126 By default, this method should include all functionalities implemented by
127 InitializeCpuExceptionHandlers(), plus extra initialization works, if any.
128 This could be done by calling InitializeCpuExceptionHandlers() directly
129 in this method besides the extra works.
130
131 InitData is optional and its use and content are processor arch dependent.
132 The typical usage of it is to convey resources which have to be reserved
133 elsewhere and are necessary for the extra initializations of exception.
134
135 @param[in] VectorInfo Pointer to reserved vector list.
136 @param[in] InitData Pointer to data optional for extra initializations
137 of exception.
138
139 @retval EFI_SUCCESS The exceptions have been successfully
140 initialized.
141 @retval EFI_INVALID_PARAMETER VectorInfo or InitData contains invalid
142 content.
143
144 **/
145 EFI_STATUS
146 EFIAPI
147 InitializeCpuExceptionHandlersEx (
148 IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,
149 IN CPU_EXCEPTION_INIT_DATA *InitData OPTIONAL
150 )
151 {
152 return InitializeCpuExceptionHandlers (VectorInfo);
153 }