1 | /** @file
|
---|
2 | Library that provides SMM CPU Sync related operations.
|
---|
3 |
|
---|
4 | The lib provides 3 sets of APIs:
|
---|
5 | 1. ContextInit/ContextDeinit/ContextReset:
|
---|
6 |
|
---|
7 | ContextInit() is called in driver's entrypoint to allocate and initialize the SMM CPU Sync context.
|
---|
8 | ContextDeinit() is called in driver's unload function to deinitialize the SMM CPU Sync context.
|
---|
9 | ContextReset() is called by one of CPUs after all CPUs are ready to exit SMI, which allows CPU to
|
---|
10 | check into the next SMI from this point.
|
---|
11 |
|
---|
12 | 2. GetArrivedCpuCount/CheckInCpu/CheckOutCpu/LockDoor:
|
---|
13 | When SMI happens, all processors including BSP enter to SMM mode by calling CheckInCpu().
|
---|
14 | CheckOutCpu() can be called in error handling flow for the CPU who calls CheckInCpu() earlier.
|
---|
15 | The elected BSP calls LockDoor() so that CheckInCpu() and CheckOutCpu() will return the error code after that.
|
---|
16 | GetArrivedCpuCount() returns the number of checked-in CPUs.
|
---|
17 |
|
---|
18 | 3. WaitForAPs/ReleaseOneAp/WaitForBsp/ReleaseBsp
|
---|
19 | WaitForAPs() & ReleaseOneAp() are called from BSP to wait the number of APs and release one specific AP.
|
---|
20 | WaitForBsp() & ReleaseBsp() are called from APs to wait and release BSP.
|
---|
21 | The 4 APIs are used to synchronize the running flow among BSP and APs.
|
---|
22 | BSP and AP Sync flow can be easy understand as below:
|
---|
23 | BSP: ReleaseOneAp --> AP: WaitForBsp
|
---|
24 | BSP: WaitForAPs <-- AP: ReleaseBsp
|
---|
25 |
|
---|
26 | Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
|
---|
27 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
28 |
|
---|
29 | **/
|
---|
30 |
|
---|
31 | #ifndef SMM_CPU_SYNC_LIB_H_
|
---|
32 | #define SMM_CPU_SYNC_LIB_H_
|
---|
33 |
|
---|
34 | #include <Uefi/UefiBaseType.h>
|
---|
35 |
|
---|
36 | //
|
---|
37 | // Opaque structure for SMM CPU Sync context.
|
---|
38 | //
|
---|
39 | typedef struct SMM_CPU_SYNC_CONTEXT SMM_CPU_SYNC_CONTEXT;
|
---|
40 |
|
---|
41 | /**
|
---|
42 | Create and initialize the SMM CPU Sync context. It is to allocate and initialize the
|
---|
43 | SMM CPU Sync context.
|
---|
44 |
|
---|
45 | If Context is NULL, then ASSERT().
|
---|
46 |
|
---|
47 | @param[in] NumberOfCpus The number of Logical Processors in the system.
|
---|
48 | @param[out] Context Pointer to the new created and initialized SMM CPU Sync context object.
|
---|
49 | NULL will be returned if any error happen during init.
|
---|
50 |
|
---|
51 | @retval RETURN_SUCCESS The SMM CPU Sync context was successful created and initialized.
|
---|
52 | @retval RETURN_OUT_OF_RESOURCES There are not enough resources available to create and initialize SMM CPU Sync context.
|
---|
53 | @retval RETURN_BUFFER_TOO_SMALL Overflow happen
|
---|
54 |
|
---|
55 | **/
|
---|
56 | RETURN_STATUS
|
---|
57 | EFIAPI
|
---|
58 | SmmCpuSyncContextInit (
|
---|
59 | IN UINTN NumberOfCpus,
|
---|
60 | OUT SMM_CPU_SYNC_CONTEXT **Context
|
---|
61 | );
|
---|
62 |
|
---|
63 | /**
|
---|
64 | Deinit an allocated SMM CPU Sync context. The resources allocated in SmmCpuSyncContextInit() will
|
---|
65 | be freed.
|
---|
66 |
|
---|
67 | If Context is NULL, then ASSERT().
|
---|
68 |
|
---|
69 | @param[in,out] Context Pointer to the SMM CPU Sync context object to be deinitialized.
|
---|
70 |
|
---|
71 | **/
|
---|
72 | VOID
|
---|
73 | EFIAPI
|
---|
74 | SmmCpuSyncContextDeinit (
|
---|
75 | IN OUT SMM_CPU_SYNC_CONTEXT *Context
|
---|
76 | );
|
---|
77 |
|
---|
78 | /**
|
---|
79 | Reset SMM CPU Sync context. SMM CPU Sync context will be reset to the initialized state.
|
---|
80 |
|
---|
81 | This function is called by one of CPUs after all CPUs are ready to exit SMI, which allows CPU to
|
---|
82 | check into the next SMI from this point.
|
---|
83 |
|
---|
84 | If Context is NULL, then ASSERT().
|
---|
85 |
|
---|
86 | @param[in,out] Context Pointer to the SMM CPU Sync context object to be reset.
|
---|
87 |
|
---|
88 | **/
|
---|
89 | VOID
|
---|
90 | EFIAPI
|
---|
91 | SmmCpuSyncContextReset (
|
---|
92 | IN OUT SMM_CPU_SYNC_CONTEXT *Context
|
---|
93 | );
|
---|
94 |
|
---|
95 | /**
|
---|
96 | Get current number of arrived CPU in SMI.
|
---|
97 |
|
---|
98 | BSP might need to know the current number of arrived CPU in SMI to make sure all APs
|
---|
99 | in SMI. This API can be for that purpose.
|
---|
100 |
|
---|
101 | If Context is NULL, then ASSERT().
|
---|
102 |
|
---|
103 | @param[in] Context Pointer to the SMM CPU Sync context object.
|
---|
104 |
|
---|
105 | @retval Current number of arrived CPU in SMI.
|
---|
106 |
|
---|
107 | **/
|
---|
108 | UINTN
|
---|
109 | EFIAPI
|
---|
110 | SmmCpuSyncGetArrivedCpuCount (
|
---|
111 | IN SMM_CPU_SYNC_CONTEXT *Context
|
---|
112 | );
|
---|
113 |
|
---|
114 | /**
|
---|
115 | Performs an atomic operation to check in CPU.
|
---|
116 |
|
---|
117 | When SMI happens, all processors including BSP enter to SMM mode by calling SmmCpuSyncCheckInCpu().
|
---|
118 |
|
---|
119 | If Context is NULL, then ASSERT().
|
---|
120 | If CpuIndex exceeds the range of all CPUs in the system, then ASSERT().
|
---|
121 |
|
---|
122 | @param[in,out] Context Pointer to the SMM CPU Sync context object.
|
---|
123 | @param[in] CpuIndex Check in CPU index.
|
---|
124 |
|
---|
125 | @retval RETURN_SUCCESS Check in CPU (CpuIndex) successfully.
|
---|
126 | @retval RETURN_ABORTED Check in CPU failed due to SmmCpuSyncLockDoor() has been called by one elected CPU.
|
---|
127 |
|
---|
128 | **/
|
---|
129 | RETURN_STATUS
|
---|
130 | EFIAPI
|
---|
131 | SmmCpuSyncCheckInCpu (
|
---|
132 | IN OUT SMM_CPU_SYNC_CONTEXT *Context,
|
---|
133 | IN UINTN CpuIndex
|
---|
134 | );
|
---|
135 |
|
---|
136 | /**
|
---|
137 | Performs an atomic operation to check out CPU.
|
---|
138 |
|
---|
139 | This function can be called in error handling flow for the CPU who calls CheckInCpu() earlier.
|
---|
140 | The caller shall make sure the CPU specified by CpuIndex has already checked-in.
|
---|
141 |
|
---|
142 | If Context is NULL, then ASSERT().
|
---|
143 | If CpuIndex exceeds the range of all CPUs in the system, then ASSERT().
|
---|
144 |
|
---|
145 | @param[in,out] Context Pointer to the SMM CPU Sync context object.
|
---|
146 | @param[in] CpuIndex Check out CPU index.
|
---|
147 |
|
---|
148 | @retval RETURN_SUCCESS Check out CPU (CpuIndex) successfully.
|
---|
149 | @retval RETURN_ABORTED Check out CPU failed due to SmmCpuSyncLockDoor() has been called by one elected CPU.
|
---|
150 |
|
---|
151 | **/
|
---|
152 | RETURN_STATUS
|
---|
153 | EFIAPI
|
---|
154 | SmmCpuSyncCheckOutCpu (
|
---|
155 | IN OUT SMM_CPU_SYNC_CONTEXT *Context,
|
---|
156 | IN UINTN CpuIndex
|
---|
157 | );
|
---|
158 |
|
---|
159 | /**
|
---|
160 | Performs an atomic operation lock door for CPU checkin and checkout. After this function:
|
---|
161 | CPU can not check in via SmmCpuSyncCheckInCpu().
|
---|
162 | CPU can not check out via SmmCpuSyncCheckOutCpu().
|
---|
163 |
|
---|
164 | The CPU specified by CpuIndex is elected to lock door. The caller shall make sure the CpuIndex
|
---|
165 | is the actual CPU calling this function to avoid the undefined behavior.
|
---|
166 |
|
---|
167 | If Context is NULL, then ASSERT().
|
---|
168 | If CpuCount is NULL, then ASSERT().
|
---|
169 | If CpuIndex exceeds the range of all CPUs in the system, then ASSERT().
|
---|
170 |
|
---|
171 | @param[in,out] Context Pointer to the SMM CPU Sync context object.
|
---|
172 | @param[in] CpuIndex Indicate which CPU to lock door.
|
---|
173 | @param[out] CpuCount Number of arrived CPU in SMI after look door.
|
---|
174 |
|
---|
175 | **/
|
---|
176 | VOID
|
---|
177 | EFIAPI
|
---|
178 | SmmCpuSyncLockDoor (
|
---|
179 | IN OUT SMM_CPU_SYNC_CONTEXT *Context,
|
---|
180 | IN UINTN CpuIndex,
|
---|
181 | OUT UINTN *CpuCount
|
---|
182 | );
|
---|
183 |
|
---|
184 | /**
|
---|
185 | Used by the BSP to wait for APs.
|
---|
186 |
|
---|
187 | The number of APs need to be waited is specified by NumberOfAPs. The BSP is specified by BspIndex.
|
---|
188 | The caller shall make sure the BspIndex is the actual CPU calling this function to avoid the undefined behavior.
|
---|
189 | The caller shall make sure the NumberOfAPs have already checked-in to avoid the undefined behavior.
|
---|
190 |
|
---|
191 | If Context is NULL, then ASSERT().
|
---|
192 | If NumberOfAPs >= All CPUs in system, then ASSERT().
|
---|
193 | If BspIndex exceeds the range of all CPUs in the system, then ASSERT().
|
---|
194 |
|
---|
195 | Note:
|
---|
196 | This function is blocking mode, and it will return only after the number of APs released by
|
---|
197 | calling SmmCpuSyncReleaseBsp():
|
---|
198 | BSP: WaitForAPs <-- AP: ReleaseBsp
|
---|
199 |
|
---|
200 | @param[in,out] Context Pointer to the SMM CPU Sync context object.
|
---|
201 | @param[in] NumberOfAPs Number of APs need to be waited by BSP.
|
---|
202 | @param[in] BspIndex The BSP Index to wait for APs.
|
---|
203 |
|
---|
204 | **/
|
---|
205 | VOID
|
---|
206 | EFIAPI
|
---|
207 | SmmCpuSyncWaitForAPs (
|
---|
208 | IN OUT SMM_CPU_SYNC_CONTEXT *Context,
|
---|
209 | IN UINTN NumberOfAPs,
|
---|
210 | IN UINTN BspIndex
|
---|
211 | );
|
---|
212 |
|
---|
213 | /**
|
---|
214 | Used by the BSP to release one AP.
|
---|
215 |
|
---|
216 | The AP is specified by CpuIndex. The BSP is specified by BspIndex.
|
---|
217 | The caller shall make sure the BspIndex is the actual CPU calling this function to avoid the undefined behavior.
|
---|
218 | The caller shall make sure the CpuIndex has already checked-in to avoid the undefined behavior.
|
---|
219 |
|
---|
220 | If Context is NULL, then ASSERT().
|
---|
221 | If CpuIndex == BspIndex, then ASSERT().
|
---|
222 | If BspIndex or CpuIndex exceed the range of all CPUs in the system, then ASSERT().
|
---|
223 |
|
---|
224 | @param[in,out] Context Pointer to the SMM CPU Sync context object.
|
---|
225 | @param[in] CpuIndex Indicate which AP need to be released.
|
---|
226 | @param[in] BspIndex The BSP Index to release AP.
|
---|
227 |
|
---|
228 | **/
|
---|
229 | VOID
|
---|
230 | EFIAPI
|
---|
231 | SmmCpuSyncReleaseOneAp (
|
---|
232 | IN OUT SMM_CPU_SYNC_CONTEXT *Context,
|
---|
233 | IN UINTN CpuIndex,
|
---|
234 | IN UINTN BspIndex
|
---|
235 | );
|
---|
236 |
|
---|
237 | /**
|
---|
238 | Used by the AP to wait BSP.
|
---|
239 |
|
---|
240 | The AP is specified by CpuIndex.
|
---|
241 | The caller shall make sure the CpuIndex is the actual CPU calling this function to avoid the undefined behavior.
|
---|
242 | The BSP is specified by BspIndex.
|
---|
243 |
|
---|
244 | If Context is NULL, then ASSERT().
|
---|
245 | If CpuIndex == BspIndex, then ASSERT().
|
---|
246 | If BspIndex or CpuIndex exceed the range of all CPUs in the system, then ASSERT().
|
---|
247 |
|
---|
248 | Note:
|
---|
249 | This function is blocking mode, and it will return only after the AP released by
|
---|
250 | calling SmmCpuSyncReleaseOneAp():
|
---|
251 | BSP: ReleaseOneAp --> AP: WaitForBsp
|
---|
252 |
|
---|
253 | @param[in,out] Context Pointer to the SMM CPU Sync context object.
|
---|
254 | @param[in] CpuIndex Indicate which AP wait BSP.
|
---|
255 | @param[in] BspIndex The BSP Index to be waited.
|
---|
256 |
|
---|
257 | **/
|
---|
258 | VOID
|
---|
259 | EFIAPI
|
---|
260 | SmmCpuSyncWaitForBsp (
|
---|
261 | IN OUT SMM_CPU_SYNC_CONTEXT *Context,
|
---|
262 | IN UINTN CpuIndex,
|
---|
263 | IN UINTN BspIndex
|
---|
264 | );
|
---|
265 |
|
---|
266 | /**
|
---|
267 | Used by the AP to release BSP.
|
---|
268 |
|
---|
269 | The AP is specified by CpuIndex.
|
---|
270 | The caller shall make sure the CpuIndex is the actual CPU calling this function to avoid the undefined behavior.
|
---|
271 | The BSP is specified by BspIndex.
|
---|
272 |
|
---|
273 | If Context is NULL, then ASSERT().
|
---|
274 | If CpuIndex == BspIndex, then ASSERT().
|
---|
275 | If BspIndex or CpuIndex exceed the range of all CPUs in the system, then ASSERT().
|
---|
276 |
|
---|
277 | @param[in,out] Context Pointer to the SMM CPU Sync context object.
|
---|
278 | @param[in] CpuIndex Indicate which AP release BSP.
|
---|
279 | @param[in] BspIndex The BSP Index to be released.
|
---|
280 |
|
---|
281 | **/
|
---|
282 | VOID
|
---|
283 | EFIAPI
|
---|
284 | SmmCpuSyncReleaseBsp (
|
---|
285 | IN OUT SMM_CPU_SYNC_CONTEXT *Context,
|
---|
286 | IN UINTN CpuIndex,
|
---|
287 | IN UINTN BspIndex
|
---|
288 | );
|
---|
289 |
|
---|
290 | #endif
|
---|