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