]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
Eliminate EFI_IMAGE_MACHINE_TYPE_SUPPORTED.
[mirror_edk2.git] / UefiCpuPkg / PiSmmCpuDxeSmm / MpService.c
CommitLineData
529a5a86
MK
1/** @file\r
2SMM MP service implementation\r
3\r
4Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "PiSmmCpuDxeSmm.h"\r
16\r
17//\r
18// Slots for all MTRR( FIXED MTRR + VARIABLE MTRR + MTRR_LIB_IA32_MTRR_DEF_TYPE)\r
19//\r
20UINT64 gSmiMtrrs[MTRR_NUMBER_OF_FIXED_MTRR + 2 * MTRR_NUMBER_OF_VARIABLE_MTRR + 1];\r
21UINT64 gPhyMask;\r
22SMM_DISPATCHER_MP_SYNC_DATA *mSmmMpSyncData = NULL;\r
23UINTN mSmmMpSyncDataSize;\r
24\r
25/**\r
26 Performs an atomic compare exchange operation to get semaphore.\r
27 The compare exchange operation must be performed using\r
28 MP safe mechanisms.\r
29\r
30 @param Sem IN: 32-bit unsigned integer\r
31 OUT: original integer - 1\r
32 @return Original integer - 1\r
33\r
34**/\r
35UINT32\r
36WaitForSemaphore (\r
37 IN OUT volatile UINT32 *Sem\r
38 )\r
39{\r
40 UINT32 Value;\r
41\r
42 do {\r
43 Value = *Sem;\r
44 } while (Value == 0 ||\r
45 InterlockedCompareExchange32 (\r
46 (UINT32*)Sem,\r
47 Value,\r
48 Value - 1\r
49 ) != Value);\r
50 return Value - 1;\r
51}\r
52\r
53\r
54/**\r
55 Performs an atomic compare exchange operation to release semaphore.\r
56 The compare exchange operation must be performed using\r
57 MP safe mechanisms.\r
58\r
59 @param Sem IN: 32-bit unsigned integer\r
60 OUT: original integer + 1\r
61 @return Original integer + 1\r
62\r
63**/\r
64UINT32\r
65ReleaseSemaphore (\r
66 IN OUT volatile UINT32 *Sem\r
67 )\r
68{\r
69 UINT32 Value;\r
70\r
71 do {\r
72 Value = *Sem;\r
73 } while (Value + 1 != 0 &&\r
74 InterlockedCompareExchange32 (\r
75 (UINT32*)Sem,\r
76 Value,\r
77 Value + 1\r
78 ) != Value);\r
79 return Value + 1;\r
80}\r
81\r
82/**\r
83 Performs an atomic compare exchange operation to lock semaphore.\r
84 The compare exchange operation must be performed using\r
85 MP safe mechanisms.\r
86\r
87 @param Sem IN: 32-bit unsigned integer\r
88 OUT: -1\r
89 @return Original integer\r
90\r
91**/\r
92UINT32\r
93LockdownSemaphore (\r
94 IN OUT volatile UINT32 *Sem\r
95 )\r
96{\r
97 UINT32 Value;\r
98\r
99 do {\r
100 Value = *Sem;\r
101 } while (InterlockedCompareExchange32 (\r
102 (UINT32*)Sem,\r
103 Value, (UINT32)-1\r
104 ) != Value);\r
105 return Value;\r
106}\r
107\r
108/**\r
109 Wait all APs to performs an atomic compare exchange operation to release semaphore.\r
110\r
111 @param NumberOfAPs AP number\r
112\r
113**/\r
114VOID\r
115WaitForAllAPs (\r
116 IN UINTN NumberOfAPs\r
117 )\r
118{\r
119 UINTN BspIndex;\r
120\r
121 BspIndex = mSmmMpSyncData->BspIndex;\r
122 while (NumberOfAPs-- > 0) {\r
123 WaitForSemaphore (&mSmmMpSyncData->CpuData[BspIndex].Run);\r
124 }\r
125}\r
126\r
127/**\r
128 Performs an atomic compare exchange operation to release semaphore\r
129 for each AP.\r
130\r
131**/\r
132VOID\r
133ReleaseAllAPs (\r
134 VOID\r
135 )\r
136{\r
137 UINTN Index;\r
138 UINTN BspIndex;\r
139\r
140 BspIndex = mSmmMpSyncData->BspIndex;\r
141 for (Index = mMaxNumberOfCpus; Index-- > 0;) {\r
142 if (Index != BspIndex && mSmmMpSyncData->CpuData[Index].Present) {\r
143 ReleaseSemaphore (&mSmmMpSyncData->CpuData[Index].Run);\r
144 }\r
145 }\r
146}\r
147\r
148/**\r
149 Checks if all CPUs (with certain exceptions) have checked in for this SMI run\r
150\r
151 @param Exceptions CPU Arrival exception flags.\r
152\r
153 @retval TRUE if all CPUs the have checked in.\r
154 @retval FALSE if at least one Normal AP hasn't checked in.\r
155\r
156**/\r
157BOOLEAN\r
158AllCpusInSmmWithExceptions (\r
159 SMM_CPU_ARRIVAL_EXCEPTIONS Exceptions\r
160 )\r
161{\r
162 UINTN Index;\r
163 SMM_CPU_DATA_BLOCK *CpuData;\r
164 EFI_PROCESSOR_INFORMATION *ProcessorInfo;\r
165\r
166 ASSERT (mSmmMpSyncData->Counter <= mNumberOfCpus);\r
167\r
168 if (mSmmMpSyncData->Counter == mNumberOfCpus) {\r
169 return TRUE;\r
170 }\r
171\r
172 CpuData = mSmmMpSyncData->CpuData;\r
173 ProcessorInfo = gSmmCpuPrivate->ProcessorInfo;\r
174 for (Index = mMaxNumberOfCpus; Index-- > 0;) {\r
175 if (!CpuData[Index].Present && ProcessorInfo[Index].ProcessorId != INVALID_APIC_ID) {\r
176 if (((Exceptions & ARRIVAL_EXCEPTION_DELAYED) != 0) && SmmCpuFeaturesGetSmmRegister (Index, SmmRegSmmDelayed) != 0) {\r
177 continue;\r
178 }\r
179 if (((Exceptions & ARRIVAL_EXCEPTION_BLOCKED) != 0) && SmmCpuFeaturesGetSmmRegister (Index, SmmRegSmmBlocked) != 0) {\r
180 continue;\r
181 }\r
182 if (((Exceptions & ARRIVAL_EXCEPTION_SMI_DISABLED) != 0) && SmmCpuFeaturesGetSmmRegister (Index, SmmRegSmmEnable) != 0) {\r
183 continue;\r
184 }\r
185 return FALSE;\r
186 }\r
187 }\r
188\r
189\r
190 return TRUE;\r
191}\r
192\r
193\r
194/**\r
195 Given timeout constraint, wait for all APs to arrive, and insure when this function returns, no AP will execute normal mode code before\r
196 entering SMM, except SMI disabled APs.\r
197\r
198**/\r
199VOID\r
200SmmWaitForApArrival (\r
201 VOID\r
202 )\r
203{\r
204 UINT64 Timer;\r
205 UINTN Index;\r
206\r
207 ASSERT (mSmmMpSyncData->Counter <= mNumberOfCpus);\r
208\r
209 //\r
210 // Platform implementor should choose a timeout value appropriately:\r
211 // - The timeout value should balance the SMM time constrains and the likelihood that delayed CPUs are excluded in the SMM run. Note\r
212 // the SMI Handlers must ALWAYS take into account the cases that not all APs are available in an SMI run.\r
213 // - The timeout value must, in the case of 2nd timeout, be at least long enough to give time for all APs to receive the SMI IPI\r
214 // and either enter SMM or buffer the SMI, to insure there is no CPU running normal mode code when SMI handling starts. This will\r
215 // be TRUE even if a blocked CPU is brought out of the blocked state by a normal mode CPU (before the normal mode CPU received the\r
216 // SMI IPI), because with a buffered SMI, and CPU will enter SMM immediately after it is brought out of the blocked state.\r
217 // - The timeout value must be longer than longest possible IO operation in the system\r
218 //\r
219\r
220 //\r
221 // Sync with APs 1st timeout\r
222 //\r
223 for (Timer = StartSyncTimer ();\r
224 !IsSyncTimerTimeout (Timer) &&\r
225 !AllCpusInSmmWithExceptions (ARRIVAL_EXCEPTION_BLOCKED | ARRIVAL_EXCEPTION_SMI_DISABLED );\r
226 ) {\r
227 CpuPause ();\r
228 }\r
229\r
230 //\r
231 // Not all APs have arrived, so we need 2nd round of timeout. IPIs should be sent to ALL none present APs,\r
232 // because:\r
233 // a) Delayed AP may have just come out of the delayed state. Blocked AP may have just been brought out of blocked state by some AP running\r
234 // normal mode code. These APs need to be guaranteed to have an SMI pending to insure that once they are out of delayed / blocked state, they\r
235 // enter SMI immediately without executing instructions in normal mode. Note traditional flow requires there are no APs doing normal mode\r
236 // work while SMI handling is on-going.\r
237 // b) As a consequence of SMI IPI sending, (spurious) SMI may occur after this SMM run.\r
238 // c) ** NOTE **: Use SMI disabling feature VERY CAREFULLY (if at all) for traditional flow, because a processor in SMI-disabled state\r
239 // will execute normal mode code, which breaks the traditional SMI handlers' assumption that no APs are doing normal\r
240 // mode work while SMI handling is on-going.\r
241 // d) We don't add code to check SMI disabling status to skip sending IPI to SMI disabled APs, because:\r
242 // - In traditional flow, SMI disabling is discouraged.\r
243 // - In relaxed flow, CheckApArrival() will check SMI disabling status before calling this function.\r
244 // In both cases, adding SMI-disabling checking code increases overhead.\r
245 //\r
246 if (mSmmMpSyncData->Counter < mNumberOfCpus) {\r
247 //\r
248 // Send SMI IPIs to bring outside processors in\r
249 //\r
250 for (Index = mMaxNumberOfCpus; Index-- > 0;) {\r
251 if (!mSmmMpSyncData->CpuData[Index].Present && gSmmCpuPrivate->ProcessorInfo[Index].ProcessorId != INVALID_APIC_ID) {\r
252 SendSmiIpi ((UINT32)gSmmCpuPrivate->ProcessorInfo[Index].ProcessorId);\r
253 }\r
254 }\r
255\r
256 //\r
257 // Sync with APs 2nd timeout.\r
258 //\r
259 for (Timer = StartSyncTimer ();\r
260 !IsSyncTimerTimeout (Timer) &&\r
261 !AllCpusInSmmWithExceptions (ARRIVAL_EXCEPTION_BLOCKED | ARRIVAL_EXCEPTION_SMI_DISABLED );\r
262 ) {\r
263 CpuPause ();\r
264 }\r
265 }\r
266\r
267 return;\r
268}\r
269\r
270\r
271/**\r
272 Replace OS MTRR's with SMI MTRR's.\r
273\r
274 @param CpuIndex Processor Index\r
275\r
276**/\r
277VOID\r
278ReplaceOSMtrrs (\r
279 IN UINTN CpuIndex\r
280 )\r
281{\r
282 PROCESSOR_SMM_DESCRIPTOR *Psd;\r
283 UINT64 *SmiMtrrs;\r
284 MTRR_SETTINGS *BiosMtrr;\r
285\r
286 Psd = (PROCESSOR_SMM_DESCRIPTOR*)(mCpuHotPlugData.SmBase[CpuIndex] + SMM_PSD_OFFSET);\r
287 SmiMtrrs = (UINT64*)(UINTN)Psd->MtrrBaseMaskPtr;\r
288\r
289 SmmCpuFeaturesDisableSmrr ();\r
290\r
291 //\r
292 // Replace all MTRRs registers\r
293 //\r
294 BiosMtrr = (MTRR_SETTINGS*)SmiMtrrs;\r
295 MtrrSetAllMtrrs(BiosMtrr);\r
296}\r
297\r
298/**\r
299 SMI handler for BSP.\r
300\r
301 @param CpuIndex BSP processor Index\r
302 @param SyncMode SMM MP sync mode\r
303\r
304**/\r
305VOID\r
306BSPHandler (\r
307 IN UINTN CpuIndex,\r
308 IN SMM_CPU_SYNC_MODE SyncMode\r
309 )\r
310{\r
311 UINTN Index;\r
312 MTRR_SETTINGS Mtrrs;\r
313 UINTN ApCount;\r
314 BOOLEAN ClearTopLevelSmiResult;\r
315 UINTN PresentCount;\r
316\r
317 ASSERT (CpuIndex == mSmmMpSyncData->BspIndex);\r
318 ApCount = 0;\r
319\r
320 //\r
321 // Flag BSP's presence\r
322 //\r
323 mSmmMpSyncData->InsideSmm = TRUE;\r
324\r
325 //\r
326 // Initialize Debug Agent to start source level debug in BSP handler\r
327 //\r
328 InitializeDebugAgent (DEBUG_AGENT_INIT_ENTER_SMI, NULL, NULL);\r
329\r
330 //\r
331 // Mark this processor's presence\r
332 //\r
333 mSmmMpSyncData->CpuData[CpuIndex].Present = TRUE;\r
334\r
335 //\r
336 // Clear platform top level SMI status bit before calling SMI handlers. If\r
337 // we cleared it after SMI handlers are run, we would miss the SMI that\r
338 // occurs after SMI handlers are done and before SMI status bit is cleared.\r
339 //\r
340 ClearTopLevelSmiResult = ClearTopLevelSmiStatus();\r
341 ASSERT (ClearTopLevelSmiResult == TRUE);\r
342\r
343 //\r
344 // Set running processor index\r
345 //\r
346 gSmmCpuPrivate->SmmCoreEntryContext.CurrentlyExecutingCpu = CpuIndex;\r
347\r
348 //\r
349 // If Traditional Sync Mode or need to configure MTRRs: gather all available APs.\r
350 //\r
351 if (SyncMode == SmmCpuSyncModeTradition || SmmCpuFeaturesNeedConfigureMtrrs()) {\r
352\r
353 //\r
354 // Wait for APs to arrive\r
355 //\r
356 SmmWaitForApArrival();\r
357\r
358 //\r
359 // Lock the counter down and retrieve the number of APs\r
360 //\r
361 mSmmMpSyncData->AllCpusInSync = TRUE;\r
362 ApCount = LockdownSemaphore (&mSmmMpSyncData->Counter) - 1;\r
363\r
364 //\r
365 // Wait for all APs to get ready for programming MTRRs\r
366 //\r
367 WaitForAllAPs (ApCount);\r
368\r
369 if (SmmCpuFeaturesNeedConfigureMtrrs()) {\r
370 //\r
371 // Signal all APs it's time for backup MTRRs\r
372 //\r
373 ReleaseAllAPs ();\r
374\r
375 //\r
376 // WaitForSemaphore() may wait for ever if an AP happens to enter SMM at\r
377 // exactly this point. Please make sure PcdCpuSmmMaxSyncLoops has been set\r
378 // to a large enough value to avoid this situation.\r
379 // Note: For HT capable CPUs, threads within a core share the same set of MTRRs.\r
380 // We do the backup first and then set MTRR to avoid race condition for threads\r
381 // in the same core.\r
382 //\r
383 MtrrGetAllMtrrs(&Mtrrs);\r
384\r
385 //\r
386 // Wait for all APs to complete their MTRR saving\r
387 //\r
388 WaitForAllAPs (ApCount);\r
389\r
390 //\r
391 // Let all processors program SMM MTRRs together\r
392 //\r
393 ReleaseAllAPs ();\r
394\r
395 //\r
396 // WaitForSemaphore() may wait for ever if an AP happens to enter SMM at\r
397 // exactly this point. Please make sure PcdCpuSmmMaxSyncLoops has been set\r
398 // to a large enough value to avoid this situation.\r
399 //\r
400 ReplaceOSMtrrs (CpuIndex);\r
401\r
402 //\r
403 // Wait for all APs to complete their MTRR programming\r
404 //\r
405 WaitForAllAPs (ApCount);\r
406 }\r
407 }\r
408\r
409 //\r
410 // The BUSY lock is initialized to Acquired state\r
411 //\r
412 AcquireSpinLockOrFail (&mSmmMpSyncData->CpuData[CpuIndex].Busy);\r
413\r
414 //\r
415 // Restore SMM Configuration in S3 boot path.\r
416 //\r
417 if (mRestoreSmmConfigurationInS3) {\r
418 //\r
419 // Configure SMM Code Access Check feature if available.\r
420 //\r
421 ConfigSmmCodeAccessCheck ();\r
422 mRestoreSmmConfigurationInS3 = FALSE;\r
423 }\r
424\r
425 //\r
426 // Invoke SMM Foundation EntryPoint with the processor information context.\r
427 //\r
428 gSmmCpuPrivate->SmmCoreEntry (&gSmmCpuPrivate->SmmCoreEntryContext);\r
429\r
430 //\r
431 // Make sure all APs have completed their pending none-block tasks\r
432 //\r
433 for (Index = mMaxNumberOfCpus; Index-- > 0;) {\r
434 if (Index != CpuIndex && mSmmMpSyncData->CpuData[Index].Present) {\r
435 AcquireSpinLock (&mSmmMpSyncData->CpuData[Index].Busy);\r
436 ReleaseSpinLock (&mSmmMpSyncData->CpuData[Index].Busy);;\r
437 }\r
438 }\r
439\r
440 //\r
441 // Perform the remaining tasks\r
442 //\r
443 PerformRemainingTasks ();\r
444\r
445 //\r
446 // If Relaxed-AP Sync Mode: gather all available APs after BSP SMM handlers are done, and\r
447 // make those APs to exit SMI synchronously. APs which arrive later will be excluded and\r
448 // will run through freely.\r
449 //\r
450 if (SyncMode != SmmCpuSyncModeTradition && !SmmCpuFeaturesNeedConfigureMtrrs()) {\r
451\r
452 //\r
453 // Lock the counter down and retrieve the number of APs\r
454 //\r
455 mSmmMpSyncData->AllCpusInSync = TRUE;\r
456 ApCount = LockdownSemaphore (&mSmmMpSyncData->Counter) - 1;\r
457 //\r
458 // Make sure all APs have their Present flag set\r
459 //\r
460 while (TRUE) {\r
461 PresentCount = 0;\r
462 for (Index = mMaxNumberOfCpus; Index-- > 0;) {\r
463 if (mSmmMpSyncData->CpuData[Index].Present) {\r
464 PresentCount ++;\r
465 }\r
466 }\r
467 if (PresentCount > ApCount) {\r
468 break;\r
469 }\r
470 }\r
471 }\r
472\r
473 //\r
474 // Notify all APs to exit\r
475 //\r
476 mSmmMpSyncData->InsideSmm = FALSE;\r
477 ReleaseAllAPs ();\r
478\r
479 //\r
480 // Wait for all APs to complete their pending tasks\r
481 //\r
482 WaitForAllAPs (ApCount);\r
483\r
484 if (SmmCpuFeaturesNeedConfigureMtrrs()) {\r
485 //\r
486 // Signal APs to restore MTRRs\r
487 //\r
488 ReleaseAllAPs ();\r
489\r
490 //\r
491 // Restore OS MTRRs\r
492 //\r
493 SmmCpuFeaturesReenableSmrr ();\r
494 MtrrSetAllMtrrs(&Mtrrs);\r
495\r
496 //\r
497 // Wait for all APs to complete MTRR programming\r
498 //\r
499 WaitForAllAPs (ApCount);\r
500 }\r
501\r
502 //\r
503 // Stop source level debug in BSP handler, the code below will not be\r
504 // debugged.\r
505 //\r
506 InitializeDebugAgent (DEBUG_AGENT_INIT_EXIT_SMI, NULL, NULL);\r
507\r
508 //\r
509 // Signal APs to Reset states/semaphore for this processor\r
510 //\r
511 ReleaseAllAPs ();\r
512\r
513 //\r
514 // Perform pending operations for hot-plug\r
515 //\r
516 SmmCpuUpdate ();\r
517\r
518 //\r
519 // Clear the Present flag of BSP\r
520 //\r
521 mSmmMpSyncData->CpuData[CpuIndex].Present = FALSE;\r
522\r
523 //\r
524 // Gather APs to exit SMM synchronously. Note the Present flag is cleared by now but\r
525 // WaitForAllAps does not depend on the Present flag.\r
526 //\r
527 WaitForAllAPs (ApCount);\r
528\r
529 //\r
530 // Reset BspIndex to -1, meaning BSP has not been elected.\r
531 //\r
532 if (FeaturePcdGet (PcdCpuSmmEnableBspElection)) {\r
533 mSmmMpSyncData->BspIndex = (UINT32)-1;\r
534 }\r
535\r
536 //\r
537 // Allow APs to check in from this point on\r
538 //\r
539 mSmmMpSyncData->Counter = 0;\r
540 mSmmMpSyncData->AllCpusInSync = FALSE;\r
541}\r
542\r
543/**\r
544 SMI handler for AP.\r
545\r
546 @param CpuIndex AP processor Index.\r
547 @param ValidSmi Indicates that current SMI is a valid SMI or not.\r
548 @param SyncMode SMM MP sync mode.\r
549\r
550**/\r
551VOID\r
552APHandler (\r
553 IN UINTN CpuIndex,\r
554 IN BOOLEAN ValidSmi,\r
555 IN SMM_CPU_SYNC_MODE SyncMode\r
556 )\r
557{\r
558 UINT64 Timer;\r
559 UINTN BspIndex;\r
560 MTRR_SETTINGS Mtrrs;\r
561\r
562 //\r
563 // Timeout BSP\r
564 //\r
565 for (Timer = StartSyncTimer ();\r
566 !IsSyncTimerTimeout (Timer) &&\r
567 !mSmmMpSyncData->InsideSmm;\r
568 ) {\r
569 CpuPause ();\r
570 }\r
571\r
572 if (!mSmmMpSyncData->InsideSmm) {\r
573 //\r
574 // BSP timeout in the first round\r
575 //\r
576 if (mSmmMpSyncData->BspIndex != -1) {\r
577 //\r
578 // BSP Index is known\r
579 //\r
580 BspIndex = mSmmMpSyncData->BspIndex;\r
581 ASSERT (CpuIndex != BspIndex);\r
582\r
583 //\r
584 // Send SMI IPI to bring BSP in\r
585 //\r
586 SendSmiIpi ((UINT32)gSmmCpuPrivate->ProcessorInfo[BspIndex].ProcessorId);\r
587\r
588 //\r
589 // Now clock BSP for the 2nd time\r
590 //\r
591 for (Timer = StartSyncTimer ();\r
592 !IsSyncTimerTimeout (Timer) &&\r
593 !mSmmMpSyncData->InsideSmm;\r
594 ) {\r
595 CpuPause ();\r
596 }\r
597\r
598 if (!mSmmMpSyncData->InsideSmm) {\r
599 //\r
600 // Give up since BSP is unable to enter SMM\r
601 // and signal the completion of this AP\r
602 WaitForSemaphore (&mSmmMpSyncData->Counter);\r
603 return;\r
604 }\r
605 } else {\r
606 //\r
607 // Don't know BSP index. Give up without sending IPI to BSP.\r
608 //\r
609 WaitForSemaphore (&mSmmMpSyncData->Counter);\r
610 return;\r
611 }\r
612 }\r
613\r
614 //\r
615 // BSP is available\r
616 //\r
617 BspIndex = mSmmMpSyncData->BspIndex;\r
618 ASSERT (CpuIndex != BspIndex);\r
619\r
620 //\r
621 // Mark this processor's presence\r
622 //\r
623 mSmmMpSyncData->CpuData[CpuIndex].Present = TRUE;\r
624\r
625 if (SyncMode == SmmCpuSyncModeTradition || SmmCpuFeaturesNeedConfigureMtrrs()) {\r
626 //\r
627 // Notify BSP of arrival at this point\r
628 //\r
629 ReleaseSemaphore (&mSmmMpSyncData->CpuData[BspIndex].Run);\r
630 }\r
631\r
632 if (SmmCpuFeaturesNeedConfigureMtrrs()) {\r
633 //\r
634 // Wait for the signal from BSP to backup MTRRs\r
635 //\r
636 WaitForSemaphore (&mSmmMpSyncData->CpuData[CpuIndex].Run);\r
637\r
638 //\r
639 // Backup OS MTRRs\r
640 //\r
641 MtrrGetAllMtrrs(&Mtrrs);\r
642\r
643 //\r
644 // Signal BSP the completion of this AP\r
645 //\r
646 ReleaseSemaphore (&mSmmMpSyncData->CpuData[BspIndex].Run);\r
647\r
648 //\r
649 // Wait for BSP's signal to program MTRRs\r
650 //\r
651 WaitForSemaphore (&mSmmMpSyncData->CpuData[CpuIndex].Run);\r
652\r
653 //\r
654 // Replace OS MTRRs with SMI MTRRs\r
655 //\r
656 ReplaceOSMtrrs (CpuIndex);\r
657\r
658 //\r
659 // Signal BSP the completion of this AP\r
660 //\r
661 ReleaseSemaphore (&mSmmMpSyncData->CpuData[BspIndex].Run);\r
662 }\r
663\r
664 while (TRUE) {\r
665 //\r
666 // Wait for something to happen\r
667 //\r
668 WaitForSemaphore (&mSmmMpSyncData->CpuData[CpuIndex].Run);\r
669\r
670 //\r
671 // Check if BSP wants to exit SMM\r
672 //\r
673 if (!mSmmMpSyncData->InsideSmm) {\r
674 break;\r
675 }\r
676\r
677 //\r
678 // BUSY should be acquired by SmmStartupThisAp()\r
679 //\r
680 ASSERT (\r
681 !AcquireSpinLockOrFail (&mSmmMpSyncData->CpuData[CpuIndex].Busy)\r
682 );\r
683\r
684 //\r
685 // Invoke the scheduled procedure\r
686 //\r
687 (*mSmmMpSyncData->CpuData[CpuIndex].Procedure) (\r
688 (VOID*)mSmmMpSyncData->CpuData[CpuIndex].Parameter\r
689 );\r
690\r
691 //\r
692 // Release BUSY\r
693 //\r
694 ReleaseSpinLock (&mSmmMpSyncData->CpuData[CpuIndex].Busy);\r
695 }\r
696\r
697 if (SmmCpuFeaturesNeedConfigureMtrrs()) {\r
698 //\r
699 // Notify BSP the readiness of this AP to program MTRRs\r
700 //\r
701 ReleaseSemaphore (&mSmmMpSyncData->CpuData[BspIndex].Run);\r
702\r
703 //\r
704 // Wait for the signal from BSP to program MTRRs\r
705 //\r
706 WaitForSemaphore (&mSmmMpSyncData->CpuData[CpuIndex].Run);\r
707\r
708 //\r
709 // Restore OS MTRRs\r
710 //\r
711 SmmCpuFeaturesReenableSmrr ();\r
712 MtrrSetAllMtrrs(&Mtrrs);\r
713 }\r
714\r
715 //\r
716 // Notify BSP the readiness of this AP to Reset states/semaphore for this processor\r
717 //\r
718 ReleaseSemaphore (&mSmmMpSyncData->CpuData[BspIndex].Run);\r
719\r
720 //\r
721 // Wait for the signal from BSP to Reset states/semaphore for this processor\r
722 //\r
723 WaitForSemaphore (&mSmmMpSyncData->CpuData[CpuIndex].Run);\r
724\r
725 //\r
726 // Reset states/semaphore for this processor\r
727 //\r
728 mSmmMpSyncData->CpuData[CpuIndex].Present = FALSE;\r
729\r
730 //\r
731 // Notify BSP the readiness of this AP to exit SMM\r
732 //\r
733 ReleaseSemaphore (&mSmmMpSyncData->CpuData[BspIndex].Run);\r
734\r
735}\r
736\r
737/**\r
738 Create 4G PageTable in SMRAM.\r
739\r
740 @param ExtraPages Additional page numbers besides for 4G memory\r
741 @return PageTable Address\r
742\r
743**/\r
744UINT32\r
745Gen4GPageTable (\r
746 IN UINTN ExtraPages\r
747 )\r
748{\r
749 VOID *PageTable;\r
750 UINTN Index;\r
751 UINT64 *Pte;\r
752 UINTN PagesNeeded;\r
753 UINTN Low2MBoundary;\r
754 UINTN High2MBoundary;\r
755 UINTN Pages;\r
756 UINTN GuardPage;\r
757 UINT64 *Pdpte;\r
758 UINTN PageIndex;\r
759 UINTN PageAddress;\r
760\r
761 Low2MBoundary = 0;\r
762 High2MBoundary = 0;\r
763 PagesNeeded = 0;\r
764 if (FeaturePcdGet (PcdCpuSmmStackGuard)) {\r
765 //\r
766 // Add one more page for known good stack, then find the lower 2MB aligned address.\r
767 //\r
768 Low2MBoundary = (mSmmStackArrayBase + EFI_PAGE_SIZE) & ~(SIZE_2MB-1);\r
769 //\r
770 // Add two more pages for known good stack and stack guard page,\r
771 // then find the lower 2MB aligned address.\r
772 //\r
773 High2MBoundary = (mSmmStackArrayEnd - mSmmStackSize + EFI_PAGE_SIZE * 2) & ~(SIZE_2MB-1);\r
774 PagesNeeded = ((High2MBoundary - Low2MBoundary) / SIZE_2MB) + 1;\r
775 }\r
776 //\r
777 // Allocate the page table\r
778 //\r
779 PageTable = AllocatePages (ExtraPages + 5 + PagesNeeded);\r
780 ASSERT (PageTable != NULL);\r
781\r
782 PageTable = (VOID *)((UINTN)PageTable + EFI_PAGES_TO_SIZE (ExtraPages));\r
783 Pte = (UINT64*)PageTable;\r
784\r
785 //\r
786 // Zero out all page table entries first\r
787 //\r
788 ZeroMem (Pte, EFI_PAGES_TO_SIZE (1));\r
789\r
790 //\r
791 // Set Page Directory Pointers\r
792 //\r
793 for (Index = 0; Index < 4; Index++) {\r
794 Pte[Index] = (UINTN)PageTable + EFI_PAGE_SIZE * (Index + 1) + IA32_PG_P;\r
795 }\r
796 Pte += EFI_PAGE_SIZE / sizeof (*Pte);\r
797\r
798 //\r
799 // Fill in Page Directory Entries\r
800 //\r
801 for (Index = 0; Index < EFI_PAGE_SIZE * 4 / sizeof (*Pte); Index++) {\r
802 Pte[Index] = (Index << 21) + IA32_PG_PS + IA32_PG_RW + IA32_PG_P;\r
803 }\r
804\r
805 if (FeaturePcdGet (PcdCpuSmmStackGuard)) {\r
806 Pages = (UINTN)PageTable + EFI_PAGES_TO_SIZE (5);\r
807 GuardPage = mSmmStackArrayBase + EFI_PAGE_SIZE;\r
808 Pdpte = (UINT64*)PageTable;\r
809 for (PageIndex = Low2MBoundary; PageIndex <= High2MBoundary; PageIndex += SIZE_2MB) {\r
810 Pte = (UINT64*)(UINTN)(Pdpte[BitFieldRead32 ((UINT32)PageIndex, 30, 31)] & ~(EFI_PAGE_SIZE - 1));\r
811 Pte[BitFieldRead32 ((UINT32)PageIndex, 21, 29)] = (UINT64)Pages + IA32_PG_RW + IA32_PG_P;\r
812 //\r
813 // Fill in Page Table Entries\r
814 //\r
815 Pte = (UINT64*)Pages;\r
816 PageAddress = PageIndex;\r
817 for (Index = 0; Index < EFI_PAGE_SIZE / sizeof (*Pte); Index++) {\r
818 if (PageAddress == GuardPage) {\r
819 //\r
820 // Mark the guard page as non-present\r
821 //\r
822 Pte[Index] = PageAddress;\r
823 GuardPage += mSmmStackSize;\r
824 if (GuardPage > mSmmStackArrayEnd) {\r
825 GuardPage = 0;\r
826 }\r
827 } else {\r
828 Pte[Index] = PageAddress + IA32_PG_RW + IA32_PG_P;\r
829 }\r
830 PageAddress+= EFI_PAGE_SIZE;\r
831 }\r
832 Pages += EFI_PAGE_SIZE;\r
833 }\r
834 }\r
835\r
836 return (UINT32)(UINTN)PageTable;\r
837}\r
838\r
839/**\r
840 Set memory cache ability.\r
841\r
842 @param PageTable PageTable Address\r
843 @param Address Memory Address to change cache ability\r
844 @param Cacheability Cache ability to set\r
845\r
846**/\r
847VOID\r
848SetCacheability (\r
849 IN UINT64 *PageTable,\r
850 IN UINTN Address,\r
851 IN UINT8 Cacheability\r
852 )\r
853{\r
854 UINTN PTIndex;\r
855 VOID *NewPageTableAddress;\r
856 UINT64 *NewPageTable;\r
857 UINTN Index;\r
858\r
859 ASSERT ((Address & EFI_PAGE_MASK) == 0);\r
860\r
861 if (sizeof (UINTN) == sizeof (UINT64)) {\r
862 PTIndex = (UINTN)RShiftU64 (Address, 39) & 0x1ff;\r
863 ASSERT (PageTable[PTIndex] & IA32_PG_P);\r
864 PageTable = (UINT64*)(UINTN)(PageTable[PTIndex] & gPhyMask);\r
865 }\r
866\r
867 PTIndex = (UINTN)RShiftU64 (Address, 30) & 0x1ff;\r
868 ASSERT (PageTable[PTIndex] & IA32_PG_P);\r
869 PageTable = (UINT64*)(UINTN)(PageTable[PTIndex] & gPhyMask);\r
870\r
871 //\r
872 // A perfect implementation should check the original cacheability with the\r
873 // one being set, and break a 2M page entry into pieces only when they\r
874 // disagreed.\r
875 //\r
876 PTIndex = (UINTN)RShiftU64 (Address, 21) & 0x1ff;\r
877 if ((PageTable[PTIndex] & IA32_PG_PS) != 0) {\r
878 //\r
879 // Allocate a page from SMRAM\r
880 //\r
881 NewPageTableAddress = AllocatePages (1);\r
882 ASSERT (NewPageTableAddress != NULL);\r
883\r
884 NewPageTable = (UINT64 *)NewPageTableAddress;\r
885\r
886 for (Index = 0; Index < 0x200; Index++) {\r
887 NewPageTable[Index] = PageTable[PTIndex];\r
888 if ((NewPageTable[Index] & IA32_PG_PAT_2M) != 0) {\r
889 NewPageTable[Index] &= ~((UINT64)IA32_PG_PAT_2M);\r
890 NewPageTable[Index] |= (UINT64)IA32_PG_PAT_4K;\r
891 }\r
892 NewPageTable[Index] |= (UINT64)(Index << EFI_PAGE_SHIFT);\r
893 }\r
894\r
895 PageTable[PTIndex] = ((UINTN)NewPageTableAddress & gPhyMask) | IA32_PG_P;\r
896 }\r
897\r
898 ASSERT (PageTable[PTIndex] & IA32_PG_P);\r
899 PageTable = (UINT64*)(UINTN)(PageTable[PTIndex] & gPhyMask);\r
900\r
901 PTIndex = (UINTN)RShiftU64 (Address, 12) & 0x1ff;\r
902 ASSERT (PageTable[PTIndex] & IA32_PG_P);\r
903 PageTable[PTIndex] &= ~((UINT64)((IA32_PG_PAT_4K | IA32_PG_CD | IA32_PG_WT)));\r
904 PageTable[PTIndex] |= (UINT64)Cacheability;\r
905}\r
906\r
907\r
908/**\r
909 Schedule a procedure to run on the specified CPU.\r
910\r
911 @param Procedure The address of the procedure to run\r
912 @param CpuIndex Target CPU Index\r
913 @param ProcArguments The parameter to pass to the procedure\r
914\r
915 @retval EFI_INVALID_PARAMETER CpuNumber not valid\r
916 @retval EFI_INVALID_PARAMETER CpuNumber specifying BSP\r
917 @retval EFI_INVALID_PARAMETER The AP specified by CpuNumber did not enter SMM\r
918 @retval EFI_INVALID_PARAMETER The AP specified by CpuNumber is busy\r
919 @retval EFI_SUCCESS The procedure has been successfully scheduled\r
920\r
921**/\r
922EFI_STATUS\r
923EFIAPI\r
924SmmStartupThisAp (\r
925 IN EFI_AP_PROCEDURE Procedure,\r
926 IN UINTN CpuIndex,\r
927 IN OUT VOID *ProcArguments OPTIONAL\r
928 )\r
929{\r
930 if (CpuIndex >= gSmmCpuPrivate->SmmCoreEntryContext.NumberOfCpus ||\r
931 CpuIndex == gSmmCpuPrivate->SmmCoreEntryContext.CurrentlyExecutingCpu ||\r
932 !mSmmMpSyncData->CpuData[CpuIndex].Present ||\r
933 gSmmCpuPrivate->Operation[CpuIndex] == SmmCpuRemove ||\r
934 !AcquireSpinLockOrFail (&mSmmMpSyncData->CpuData[CpuIndex].Busy)) {\r
935 return EFI_INVALID_PARAMETER;\r
936 }\r
937\r
938 mSmmMpSyncData->CpuData[CpuIndex].Procedure = Procedure;\r
939 mSmmMpSyncData->CpuData[CpuIndex].Parameter = ProcArguments;\r
940 ReleaseSemaphore (&mSmmMpSyncData->CpuData[CpuIndex].Run);\r
941\r
942 if (FeaturePcdGet (PcdCpuSmmBlockStartupThisAp)) {\r
943 AcquireSpinLock (&mSmmMpSyncData->CpuData[CpuIndex].Busy);\r
944 ReleaseSpinLock (&mSmmMpSyncData->CpuData[CpuIndex].Busy);\r
945 }\r
946 return EFI_SUCCESS;\r
947}\r
948\r
949/**\r
950 C function for SMI entry, each processor comes here upon SMI trigger.\r
951\r
952 @param CpuIndex CPU Index\r
953\r
954**/\r
955VOID\r
956EFIAPI\r
957SmiRendezvous (\r
958 IN UINTN CpuIndex\r
959 )\r
960{\r
961 EFI_STATUS Status;\r
962 BOOLEAN ValidSmi;\r
963 BOOLEAN IsBsp;\r
964 BOOLEAN BspInProgress;\r
965 UINTN Index;\r
966 UINTN Cr2;\r
967\r
968 //\r
969 // Save Cr2 because Page Fault exception in SMM may override its value\r
970 //\r
971 Cr2 = AsmReadCr2 ();\r
972\r
973 //\r
974 // Perform CPU specific entry hooks\r
975 //\r
976 SmmCpuFeaturesRendezvousEntry (CpuIndex);\r
977\r
978 //\r
979 // Determine if this is a valid SMI\r
980 //\r
981 ValidSmi = PlatformValidSmi();\r
982\r
983 //\r
984 // Determine if BSP has been already in progress. Note this must be checked after\r
985 // ValidSmi because BSP may clear a valid SMI source after checking in.\r
986 //\r
987 BspInProgress = mSmmMpSyncData->InsideSmm;\r
988\r
989 if (!BspInProgress && !ValidSmi) {\r
990 //\r
991 // If we reach here, it means when we sampled the ValidSmi flag, SMI status had not\r
992 // been cleared by BSP in a new SMI run (so we have a truly invalid SMI), or SMI\r
993 // status had been cleared by BSP and an existing SMI run has almost ended. (Note\r
994 // we sampled ValidSmi flag BEFORE judging BSP-in-progress status.) In both cases, there\r
995 // is nothing we need to do.\r
996 //\r
997 goto Exit;\r
998 } else {\r
999 //\r
1000 // Signal presence of this processor\r
1001 //\r
1002 if (ReleaseSemaphore (&mSmmMpSyncData->Counter) == 0) {\r
1003 //\r
1004 // BSP has already ended the synchronization, so QUIT!!!\r
1005 //\r
1006\r
1007 //\r
1008 // Wait for BSP's signal to finish SMI\r
1009 //\r
1010 while (mSmmMpSyncData->AllCpusInSync) {\r
1011 CpuPause ();\r
1012 }\r
1013 goto Exit;\r
1014 } else {\r
1015\r
1016 //\r
1017 // The BUSY lock is initialized to Released state.\r
1018 // This needs to be done early enough to be ready for BSP's SmmStartupThisAp() call.\r
1019 // E.g., with Relaxed AP flow, SmmStartupThisAp() may be called immediately\r
1020 // after AP's present flag is detected.\r
1021 //\r
1022 InitializeSpinLock (&mSmmMpSyncData->CpuData[CpuIndex].Busy);\r
1023 }\r
1024\r
1025 //\r
1026 // Try to enable NX\r
1027 //\r
1028 if (mXdSupported) {\r
1029 ActivateXd ();\r
1030 }\r
1031\r
1032 if (FeaturePcdGet (PcdCpuSmmProfileEnable)) {\r
1033 ActivateSmmProfile (CpuIndex);\r
1034 }\r
1035\r
1036 if (BspInProgress) {\r
1037 //\r
1038 // BSP has been elected. Follow AP path, regardless of ValidSmi flag\r
1039 // as BSP may have cleared the SMI status\r
1040 //\r
1041 APHandler (CpuIndex, ValidSmi, mSmmMpSyncData->EffectiveSyncMode);\r
1042 } else {\r
1043 //\r
1044 // We have a valid SMI\r
1045 //\r
1046\r
1047 //\r
1048 // Elect BSP\r
1049 //\r
1050 IsBsp = FALSE;\r
1051 if (FeaturePcdGet (PcdCpuSmmEnableBspElection)) {\r
1052 if (!mSmmMpSyncData->SwitchBsp || mSmmMpSyncData->CandidateBsp[CpuIndex]) {\r
1053 //\r
1054 // Call platform hook to do BSP election\r
1055 //\r
1056 Status = PlatformSmmBspElection (&IsBsp);\r
1057 if (EFI_SUCCESS == Status) {\r
1058 //\r
1059 // Platform hook determines successfully\r
1060 //\r
1061 if (IsBsp) {\r
1062 mSmmMpSyncData->BspIndex = (UINT32)CpuIndex;\r
1063 }\r
1064 } else {\r
1065 //\r
1066 // Platform hook fails to determine, use default BSP election method\r
1067 //\r
1068 InterlockedCompareExchange32 (\r
1069 (UINT32*)&mSmmMpSyncData->BspIndex,\r
1070 (UINT32)-1,\r
1071 (UINT32)CpuIndex\r
1072 );\r
1073 }\r
1074 }\r
1075 }\r
1076\r
1077 //\r
1078 // "mSmmMpSyncData->BspIndex == CpuIndex" means this is the BSP\r
1079 //\r
1080 if (mSmmMpSyncData->BspIndex == CpuIndex) {\r
1081\r
1082 //\r
1083 // Clear last request for SwitchBsp.\r
1084 //\r
1085 if (mSmmMpSyncData->SwitchBsp) {\r
1086 mSmmMpSyncData->SwitchBsp = FALSE;\r
1087 for (Index = 0; Index < mMaxNumberOfCpus; Index++) {\r
1088 mSmmMpSyncData->CandidateBsp[Index] = FALSE;\r
1089 }\r
1090 }\r
1091\r
1092 if (FeaturePcdGet (PcdCpuSmmProfileEnable)) {\r
1093 SmmProfileRecordSmiNum ();\r
1094 }\r
1095\r
1096 //\r
1097 // BSP Handler is always called with a ValidSmi == TRUE\r
1098 //\r
1099 BSPHandler (CpuIndex, mSmmMpSyncData->EffectiveSyncMode);\r
1100\r
1101 } else {\r
1102 APHandler (CpuIndex, ValidSmi, mSmmMpSyncData->EffectiveSyncMode);\r
1103 }\r
1104 }\r
1105\r
1106 ASSERT (mSmmMpSyncData->CpuData[CpuIndex].Run == 0);\r
1107\r
1108 //\r
1109 // Wait for BSP's signal to exit SMI\r
1110 //\r
1111 while (mSmmMpSyncData->AllCpusInSync) {\r
1112 CpuPause ();\r
1113 }\r
1114 }\r
1115\r
1116Exit:\r
1117 SmmCpuFeaturesRendezvousExit (CpuIndex);\r
1118 //\r
1119 // Restore Cr2\r
1120 //\r
1121 AsmWriteCr2 (Cr2);\r
1122}\r
1123\r
1124\r
1125/**\r
1126 Initialize un-cacheable data.\r
1127\r
1128**/\r
1129VOID\r
1130EFIAPI\r
1131InitializeMpSyncData (\r
1132 VOID\r
1133 )\r
1134{\r
1135 if (mSmmMpSyncData != NULL) {\r
1136 ZeroMem (mSmmMpSyncData, mSmmMpSyncDataSize);\r
1137 mSmmMpSyncData->CpuData = (SMM_CPU_DATA_BLOCK *)((UINT8 *)mSmmMpSyncData + sizeof (SMM_DISPATCHER_MP_SYNC_DATA));\r
1138 mSmmMpSyncData->CandidateBsp = (BOOLEAN *)(mSmmMpSyncData->CpuData + gSmmCpuPrivate->SmmCoreEntryContext.NumberOfCpus);\r
1139 if (FeaturePcdGet (PcdCpuSmmEnableBspElection)) {\r
1140 //\r
1141 // Enable BSP election by setting BspIndex to -1\r
1142 //\r
1143 mSmmMpSyncData->BspIndex = (UINT32)-1;\r
1144 }\r
1145 mSmmMpSyncData->EffectiveSyncMode = (SMM_CPU_SYNC_MODE) PcdGet8 (PcdCpuSmmSyncMode);\r
1146 }\r
1147}\r
1148\r
1149/**\r
1150 Initialize global data for MP synchronization.\r
1151\r
1152 @param Stacks Base address of SMI stack buffer for all processors.\r
1153 @param StackSize Stack size for each processor in SMM.\r
1154\r
1155**/\r
1156UINT32\r
1157InitializeMpServiceData (\r
1158 IN VOID *Stacks,\r
1159 IN UINTN StackSize\r
1160 )\r
1161{\r
1162 UINT32 Cr3;\r
1163 UINTN Index;\r
1164 MTRR_SETTINGS *Mtrr;\r
1165 PROCESSOR_SMM_DESCRIPTOR *Psd;\r
529a5a86 1166 UINT8 *GdtTssTables;\r
529a5a86
MK
1167 UINTN GdtTableStepSize;\r
1168\r
1169 //\r
1170 // Initialize physical address mask\r
1171 // NOTE: Physical memory above virtual address limit is not supported !!!\r
1172 //\r
1173 AsmCpuid (0x80000008, (UINT32*)&Index, NULL, NULL, NULL);\r
1174 gPhyMask = LShiftU64 (1, (UINT8)Index) - 1;\r
1175 gPhyMask &= (1ull << 48) - EFI_PAGE_SIZE;\r
1176\r
1177 //\r
1178 // Create page tables\r
1179 //\r
1180 Cr3 = SmmInitPageTable ();\r
1181\r
fe5f1949 1182 GdtTssTables = InitGdt (Cr3, &GdtTableStepSize);\r
529a5a86
MK
1183\r
1184 //\r
1185 // Initialize PROCESSOR_SMM_DESCRIPTOR for each CPU\r
1186 //\r
1187 for (Index = 0; Index < mMaxNumberOfCpus; Index++) {\r
1188 Psd = (PROCESSOR_SMM_DESCRIPTOR *)(VOID *)(UINTN)(mCpuHotPlugData.SmBase[Index] + SMM_PSD_OFFSET);\r
1189 CopyMem (Psd, &gcPsd, sizeof (gcPsd));\r
fe5f1949
JY
1190 Psd->SmmGdtPtr = (UINT64)(UINTN)(GdtTssTables + GdtTableStepSize * Index);\r
1191 Psd->SmmGdtSize = gcSmiGdtr.Limit + 1;\r
529a5a86
MK
1192\r
1193 //\r
1194 // Install SMI handler\r
1195 //\r
1196 InstallSmiHandler (\r
1197 Index,\r
1198 (UINT32)mCpuHotPlugData.SmBase[Index],\r
1199 (VOID*)((UINTN)Stacks + (StackSize * Index)),\r
1200 StackSize,\r
1201 (UINTN)Psd->SmmGdtPtr,\r
1202 Psd->SmmGdtSize,\r
1203 gcSmiIdtr.Base,\r
1204 gcSmiIdtr.Limit + 1,\r
1205 Cr3\r
1206 );\r
1207 }\r
1208\r
1209 //\r
1210 // Initialize mSmmMpSyncData\r
1211 //\r
1212 mSmmMpSyncDataSize = sizeof (SMM_DISPATCHER_MP_SYNC_DATA) +\r
1213 (sizeof (SMM_CPU_DATA_BLOCK) + sizeof (BOOLEAN)) * gSmmCpuPrivate->SmmCoreEntryContext.NumberOfCpus;\r
1214 mSmmMpSyncData = (SMM_DISPATCHER_MP_SYNC_DATA*) AllocatePages (EFI_SIZE_TO_PAGES (mSmmMpSyncDataSize));\r
1215 ASSERT (mSmmMpSyncData != NULL);\r
1216 InitializeMpSyncData ();\r
1217\r
1218 //\r
1219 // Record current MTRR settings\r
1220 //\r
1221 ZeroMem(gSmiMtrrs, sizeof (gSmiMtrrs));\r
1222 Mtrr = (MTRR_SETTINGS*)gSmiMtrrs;\r
1223 MtrrGetAllMtrrs (Mtrr);\r
1224\r
1225 return Cr3;\r
1226}\r
1227\r
1228/**\r
1229\r
1230 Register the SMM Foundation entry point.\r
1231\r
1232 @param This Pointer to EFI_SMM_CONFIGURATION_PROTOCOL instance\r
1233 @param SmmEntryPoint SMM Foundation EntryPoint\r
1234\r
1235 @retval EFI_SUCCESS Successfully to register SMM foundation entry point\r
1236\r
1237**/\r
1238EFI_STATUS\r
1239EFIAPI\r
1240RegisterSmmEntry (\r
1241 IN CONST EFI_SMM_CONFIGURATION_PROTOCOL *This,\r
1242 IN EFI_SMM_ENTRY_POINT SmmEntryPoint\r
1243 )\r
1244{\r
1245 //\r
1246 // Record SMM Foundation EntryPoint, later invoke it on SMI entry vector.\r
1247 //\r
1248 gSmmCpuPrivate->SmmCoreEntry = SmmEntryPoint;\r
1249 return EFI_SUCCESS;\r
1250}\r