]>
Commit | Line | Data |
---|---|---|
51dd408a ED |
1 | /** @file\r |
2 | SMM MP protocol implementation\r | |
3 | \r | |
4 | Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r | |
5 | \r | |
6 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
7 | \r | |
8 | **/\r | |
9 | \r | |
10 | #include "PiSmmCpuDxeSmm.h"\r | |
11 | #include "SmmMp.h"\r | |
12 | \r | |
13 | ///\r | |
14 | /// SMM MP Protocol instance\r | |
15 | ///\r | |
16 | EFI_MM_MP_PROTOCOL mSmmMp = {\r | |
17 | EFI_MM_MP_PROTOCOL_REVISION,\r | |
18 | 0,\r | |
19 | SmmMpGetNumberOfProcessors,\r | |
20 | SmmMpDispatchProcedure,\r | |
21 | SmmMpBroadcastProcedure,\r | |
22 | SmmMpSetStartupProcedure,\r | |
23 | SmmMpCheckForProcedure,\r | |
24 | SmmMpWaitForProcedure\r | |
25 | };\r | |
26 | \r | |
27 | /**\r | |
28 | Service to retrieves the number of logical processor in the platform.\r | |
29 | \r | |
30 | @param[in] This The EFI_MM_MP_PROTOCOL instance.\r | |
31 | @param[out] NumberOfProcessors Pointer to the total number of logical processors in the system,\r | |
32 | including the BSP and all APs.\r | |
33 | \r | |
34 | @retval EFI_SUCCESS The number of processors was retrieved successfully\r | |
35 | @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL\r | |
36 | **/\r | |
37 | EFI_STATUS\r | |
38 | EFIAPI\r | |
39 | SmmMpGetNumberOfProcessors (\r | |
40 | IN CONST EFI_MM_MP_PROTOCOL *This,\r | |
41 | OUT UINTN *NumberOfProcessors\r | |
42 | )\r | |
43 | {\r | |
44 | if (NumberOfProcessors == NULL) {\r | |
45 | return EFI_INVALID_PARAMETER;\r | |
46 | }\r | |
47 | \r | |
48 | *NumberOfProcessors = gSmmCpuPrivate->SmmCoreEntryContext.NumberOfCpus;\r | |
49 | \r | |
50 | return EFI_SUCCESS;\r | |
51 | }\r | |
52 | \r | |
53 | /**\r | |
54 | This service allows the caller to invoke a procedure one of the application processors (AP). This\r | |
55 | function uses an optional token parameter to support blocking and non-blocking modes. If the token\r | |
56 | is passed into the call, the function will operate in a non-blocking fashion and the caller can\r | |
57 | check for completion with CheckOnProcedure or WaitForProcedure.\r | |
58 | \r | |
59 | @param[in] This The EFI_MM_MP_PROTOCOL instance.\r | |
60 | @param[in] Procedure A pointer to the procedure to be run on the designated target\r | |
61 | AP of the system. Type EFI_AP_PROCEDURE2 is defined below in\r | |
62 | related definitions.\r | |
63 | @param[in] CpuNumber The zero-based index of the processor number of the target\r | |
64 | AP, on which the code stream is supposed to run. If the number\r | |
65 | points to the calling processor then it will not run the\r | |
66 | supplied code.\r | |
67 | @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for this AP to\r | |
68 | finish execution of Procedure, either for blocking or\r | |
69 | non-blocking mode. Zero means infinity. If the timeout\r | |
70 | expires before this AP returns from Procedure, then Procedure\r | |
71 | on the AP is terminated. If the timeout expires in blocking\r | |
72 | mode, the call returns EFI_TIMEOUT. If the timeout expires\r | |
73 | in non-blocking mode, the timeout determined can be through\r | |
74 | CheckOnProcedure or WaitForProcedure.\r | |
75 | Note that timeout support is optional. Whether an\r | |
76 | implementation supports this feature, can be determined via\r | |
77 | the Attributes data member.\r | |
78 | @param[in,out] ProcedureArguments Allows the caller to pass a list of parameters to the code\r | |
79 | that is run by the AP. It is an optional common mailbox\r | |
80 | between APs and the caller to share information.\r | |
81 | @param[in,out] Token This is parameter is broken into two components:\r | |
82 | 1.Token->Completion is an optional parameter that allows the\r | |
83 | caller to execute the procedure in a blocking or non-blocking\r | |
84 | fashion. If it is NULL the call is blocking, and the call will\r | |
85 | not return until the AP has completed the procedure. If the\r | |
86 | token is not NULL, the call will return immediately. The caller\r | |
87 | can check whether the procedure has completed with\r | |
88 | CheckOnProcedure or WaitForProcedure.\r | |
89 | 2.Token->Status The implementation updates the address pointed\r | |
90 | at by this variable with the status code returned by Procedure\r | |
91 | when it completes execution on the target AP, or with EFI_TIMEOUT\r | |
92 | if the Procedure fails to complete within the optional timeout.\r | |
93 | The implementation will update this variable with EFI_NOT_READY\r | |
94 | prior to starting Procedure on the target AP\r | |
95 | @param[in,out] CPUStatus This optional pointer may be used to get the status code returned\r | |
96 | by Procedure when it completes execution on the target AP, or with\r | |
97 | EFI_TIMEOUT if the Procedure fails to complete within the optional\r | |
98 | timeout. The implementation will update this variable with\r | |
99 | EFI_NOT_READY prior to starting Procedure on the target AP.\r | |
100 | \r | |
101 | @retval EFI_SUCCESS In the blocking case, this indicates that Procedure has completed\r | |
102 | execution on the target AP.\r | |
103 | In the non-blocking case this indicates that the procedure has\r | |
104 | been successfully scheduled for execution on the target AP.\r | |
105 | @retval EFI_INVALID_PARAMETER The input arguments are out of range. Either the target AP is the\r | |
106 | caller of the function, or the Procedure or Token is NULL\r | |
107 | @retval EFI_NOT_READY If the target AP is busy executing another procedure\r | |
108 | @retval EFI_ALREADY_STARTED Token is already in use for another procedure\r | |
109 | @retval EFI_TIMEOUT In blocking mode, the timeout expired before the specified AP\r | |
110 | has finished\r | |
111 | @retval EFI_OUT_OF_RESOURCES Could not allocate a required resource.\r | |
112 | \r | |
113 | **/\r | |
114 | EFI_STATUS\r | |
115 | EFIAPI\r | |
116 | SmmMpDispatchProcedure (\r | |
117 | IN CONST EFI_MM_MP_PROTOCOL *This,\r | |
118 | IN EFI_AP_PROCEDURE2 Procedure,\r | |
119 | IN UINTN CpuNumber,\r | |
120 | IN UINTN TimeoutInMicroseconds,\r | |
121 | IN OUT VOID *ProcedureArguments OPTIONAL,\r | |
122 | IN OUT MM_COMPLETION *Token,\r | |
123 | IN OUT EFI_STATUS *CPUStatus\r | |
124 | )\r | |
125 | {\r | |
126 | return InternalSmmStartupThisAp (\r | |
127 | Procedure,\r | |
128 | CpuNumber,\r | |
129 | ProcedureArguments,\r | |
130 | Token,\r | |
131 | TimeoutInMicroseconds,\r | |
132 | CPUStatus\r | |
133 | );\r | |
134 | }\r | |
135 | \r | |
136 | /**\r | |
137 | This service allows the caller to invoke a procedure on all running application processors (AP)\r | |
138 | except the caller. This function uses an optional token parameter to support blocking and\r | |
139 | nonblocking modes. If the token is passed into the call, the function will operate in a non-blocking\r | |
140 | fashion and the caller can check for completion with CheckOnProcedure or WaitForProcedure.\r | |
141 | \r | |
142 | It is not necessary for the implementation to run the procedure on every processor on the platform.\r | |
143 | Processors that are powered down in such a way that they cannot respond to interrupts, may be\r | |
144 | excluded from the broadcast.\r | |
145 | \r | |
146 | \r | |
147 | @param[in] This The EFI_MM_MP_PROTOCOL instance.\r | |
148 | @param[in] Procedure A pointer to the code stream to be run on the APs that have\r | |
149 | entered MM. Type EFI_AP_PROCEDURE is defined below in related\r | |
150 | definitions.\r | |
151 | @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for the APs to finish\r | |
152 | execution of Procedure, either for blocking or non-blocking mode.\r | |
153 | Zero means infinity. If the timeout expires before all APs return\r | |
154 | from Procedure, then Procedure on the failed APs is terminated. If\r | |
155 | the timeout expires in blocking mode, the call returns EFI_TIMEOUT.\r | |
156 | If the timeout expires in non-blocking mode, the timeout determined\r | |
157 | can be through CheckOnProcedure or WaitForProcedure.\r | |
158 | Note that timeout support is optional. Whether an implementation\r | |
159 | supports this feature can be determined via the Attributes data\r | |
160 | member.\r | |
161 | @param[in,out] ProcedureArguments Allows the caller to pass a list of parameters to the code\r | |
162 | that is run by the AP. It is an optional common mailbox\r | |
163 | between APs and the caller to share information.\r | |
164 | @param[in,out] Token This is parameter is broken into two components:\r | |
165 | 1.Token->Completion is an optional parameter that allows the\r | |
166 | caller to execute the procedure in a blocking or non-blocking\r | |
167 | fashion. If it is NULL the call is blocking, and the call will\r | |
168 | not return until the AP has completed the procedure. If the\r | |
169 | token is not NULL, the call will return immediately. The caller\r | |
170 | can check whether the procedure has completed with\r | |
171 | CheckOnProcedure or WaitForProcedure.\r | |
172 | 2.Token->Status The implementation updates the address pointed\r | |
173 | at by this variable with the status code returned by Procedure\r | |
174 | when it completes execution on the target AP, or with EFI_TIMEOUT\r | |
175 | if the Procedure fails to complete within the optional timeout.\r | |
176 | The implementation will update this variable with EFI_NOT_READY\r | |
177 | prior to starting Procedure on the target AP\r | |
178 | @param[in,out] CPUStatus This optional pointer may be used to get the individual status\r | |
179 | returned by every AP that participated in the broadcast. This\r | |
180 | parameter if used provides the base address of an array to hold\r | |
181 | the EFI_STATUS value of each AP in the system. The size of the\r | |
182 | array can be ascertained by the GetNumberOfProcessors function.\r | |
183 | As mentioned above, the broadcast may not include every processor\r | |
184 | in the system. Some implementations may exclude processors that\r | |
185 | have been powered down in such a way that they are not responsive\r | |
186 | to interrupts. Additionally the broadcast excludes the processor\r | |
187 | which is making the BroadcastProcedure call. For every excluded\r | |
188 | processor, the array entry must contain a value of EFI_NOT_STARTED\r | |
189 | \r | |
190 | @retval EFI_SUCCESS In the blocking case, this indicates that Procedure has completed\r | |
191 | execution on the APs.\r | |
192 | In the non-blocking case this indicates that the procedure has\r | |
193 | been successfully scheduled for execution on the APs.\r | |
194 | @retval EFI_INVALID_PARAMETER The Procedure or Token is NULL\r | |
195 | @retval EFI_NOT_READY If the target AP is busy executing another procedure\r | |
196 | @retval EFI_ALREADY_STARTED Token is already in use for another procedure\r | |
197 | @retval EFI_TIMEOUT In blocking mode, the timeout expired before the specified AP\r | |
198 | has finished.\r | |
199 | @retval EFI_OUT_OF_RESOURCES Could not allocate a required resource.\r | |
200 | \r | |
201 | **/\r | |
202 | EFI_STATUS\r | |
203 | EFIAPI\r | |
204 | SmmMpBroadcastProcedure (\r | |
205 | IN CONST EFI_MM_MP_PROTOCOL *This,\r | |
206 | IN EFI_AP_PROCEDURE2 Procedure,\r | |
207 | IN UINTN TimeoutInMicroseconds,\r | |
208 | IN OUT VOID *ProcedureArguments OPTIONAL,\r | |
209 | IN OUT MM_COMPLETION *Token,\r | |
210 | IN OUT EFI_STATUS *CPUStatus\r | |
211 | )\r | |
212 | {\r | |
213 | return InternalSmmStartupAllAPs(\r | |
214 | Procedure,\r | |
215 | TimeoutInMicroseconds,\r | |
216 | ProcedureArguments,\r | |
217 | Token,\r | |
218 | CPUStatus\r | |
219 | );\r | |
220 | }\r | |
221 | \r | |
222 | /**\r | |
223 | This service allows the caller to set a startup procedure that will be executed when an AP powers\r | |
224 | up from a state where core configuration and context is lost. The procedure is execution has the\r | |
225 | following properties:\r | |
226 | 1. The procedure executes before the processor is handed over to the operating system.\r | |
227 | 2. All processors execute the same startup procedure.\r | |
228 | 3. The procedure may run in parallel with other procedures invoked through the functions in this\r | |
229 | protocol, or with processors that are executing an MM handler or running in the operating system.\r | |
230 | \r | |
231 | \r | |
232 | @param[in] This The EFI_MM_MP_PROTOCOL instance.\r | |
233 | @param[in] Procedure A pointer to the code stream to be run on the designated target AP\r | |
234 | of the system. Type EFI_AP_PROCEDURE is defined below in Volume 2\r | |
235 | with the related definitions of\r | |
236 | EFI_MP_SERVICES_PROTOCOL.StartupAllAPs.\r | |
237 | If caller may pass a value of NULL to deregister any existing\r | |
238 | startup procedure.\r | |
239 | @param[in,out] ProcedureArguments Allows the caller to pass a list of parameters to the code that is\r | |
240 | run by the AP. It is an optional common mailbox between APs and\r | |
241 | the caller to share information\r | |
242 | \r | |
243 | @retval EFI_SUCCESS The Procedure has been set successfully.\r | |
244 | @retval EFI_INVALID_PARAMETER The Procedure is NULL but ProcedureArguments not NULL.\r | |
245 | \r | |
246 | **/\r | |
247 | EFI_STATUS\r | |
248 | EFIAPI\r | |
249 | SmmMpSetStartupProcedure (\r | |
250 | IN CONST EFI_MM_MP_PROTOCOL *This,\r | |
251 | IN EFI_AP_PROCEDURE Procedure,\r | |
252 | IN OUT VOID *ProcedureArguments OPTIONAL\r | |
253 | )\r | |
254 | {\r | |
255 | return RegisterStartupProcedure (Procedure, ProcedureArguments);\r | |
256 | }\r | |
257 | \r | |
258 | /**\r | |
259 | When non-blocking execution of a procedure on an AP is invoked with DispatchProcedure,\r | |
260 | via the use of a token, this function can be used to check for completion of the procedure on the AP.\r | |
261 | The function takes the token that was passed into the DispatchProcedure call. If the procedure\r | |
262 | is complete, and therefore it is now possible to run another procedure on the same AP, this function\r | |
263 | returns EFI_SUCESS. In this case the status returned by the procedure that executed on the AP is\r | |
264 | returned in the token's Status field. If the procedure has not yet completed, then this function\r | |
265 | returns EFI_NOT_READY.\r | |
266 | \r | |
267 | When a non-blocking execution of a procedure is invoked with BroadcastProcedure, via the\r | |
268 | use of a token, this function can be used to check for completion of the procedure on all the\r | |
269 | broadcast APs. The function takes the token that was passed into the BroadcastProcedure\r | |
270 | call. If the procedure is complete on all broadcast APs this function returns EFI_SUCESS. In this\r | |
271 | case the Status field in the token passed into the function reflects the overall result of the\r | |
272 | invocation, which may be EFI_SUCCESS, if all executions succeeded, or the first observed failure.\r | |
273 | If the procedure has not yet completed on the broadcast APs, the function returns\r | |
274 | EFI_NOT_READY.\r | |
275 | \r | |
276 | @param[in] This The EFI_MM_MP_PROTOCOL instance.\r | |
277 | @param[in] Token This parameter describes the token that was passed into\r | |
278 | DispatchProcedure or BroadcastProcedure.\r | |
279 | \r | |
280 | @retval EFI_SUCCESS Procedure has completed.\r | |
281 | @retval EFI_NOT_READY The Procedure has not completed.\r | |
282 | @retval EFI_INVALID_PARAMETER Token or Token->Completion is NULL\r | |
283 | @retval EFI_NOT_FOUND Token is not currently in use for a non-blocking call\r | |
284 | \r | |
285 | **/\r | |
286 | EFI_STATUS\r | |
287 | EFIAPI\r | |
288 | SmmMpCheckForProcedure (\r | |
289 | IN CONST EFI_MM_MP_PROTOCOL *This,\r | |
290 | IN MM_COMPLETION Token\r | |
291 | )\r | |
292 | {\r | |
293 | if (Token == NULL) {\r | |
294 | return EFI_INVALID_PARAMETER;\r | |
295 | }\r | |
296 | \r | |
297 | if (!IsTokenInUse ((SPIN_LOCK *)Token)) {\r | |
298 | return EFI_NOT_FOUND;\r | |
299 | }\r | |
300 | \r | |
301 | return IsApReady ((SPIN_LOCK *)Token);\r | |
302 | }\r | |
303 | \r | |
304 | /**\r | |
305 | When a non-blocking execution of a procedure on an AP is invoked via DispatchProcedure,\r | |
306 | this function will block the caller until the remote procedure has completed on the designated AP.\r | |
307 | The non-blocking procedure invocation is identified by the Token parameter, which must match the\r | |
308 | token that used when DispatchProcedure was called. Upon completion the status returned by\r | |
309 | the procedure that executed on the AP is used to update the token's Status field.\r | |
310 | \r | |
311 | When a non-blocking execution of a procedure on an AP is invoked via BroadcastProcedure\r | |
312 | this function will block the caller until the remote procedure has completed on all of the APs that\r | |
313 | entered MM. The non-blocking procedure invocation is identified by the Token parameter, which\r | |
314 | must match the token that used when BroadcastProcedure was called. Upon completion the\r | |
315 | overall status returned by the procedures that executed on the broadcast AP is used to update the\r | |
316 | token's Status field. The overall status may be EFI_SUCCESS, if all executions succeeded, or the\r | |
317 | first observed failure.\r | |
318 | \r | |
319 | \r | |
320 | @param[in] This The EFI_MM_MP_PROTOCOL instance.\r | |
321 | @param[in] Token This parameter describes the token that was passed into\r | |
322 | DispatchProcedure or BroadcastProcedure.\r | |
323 | \r | |
324 | @retval EFI_SUCCESS Procedure has completed.\r | |
325 | @retval EFI_INVALID_PARAMETER Token or Token->Completion is NULL\r | |
326 | @retval EFI_NOT_FOUND Token is not currently in use for a non-blocking call\r | |
327 | \r | |
328 | **/\r | |
329 | EFI_STATUS\r | |
330 | EFIAPI\r | |
331 | SmmMpWaitForProcedure (\r | |
332 | IN CONST EFI_MM_MP_PROTOCOL *This,\r | |
333 | IN MM_COMPLETION Token\r | |
334 | )\r | |
335 | {\r | |
336 | EFI_STATUS Status;\r | |
337 | \r | |
338 | do {\r | |
339 | Status = SmmMpCheckForProcedure (This, Token);\r | |
340 | } while (Status == EFI_NOT_READY);\r | |
341 | \r | |
342 | return Status;\r | |
343 | }\r | |
344 | \r |