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