]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/PiSmmCpuDxeSmm/X64/Semaphore.c
UefiCpuPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / UefiCpuPkg / PiSmmCpuDxeSmm / X64 / Semaphore.c
1 /** @file
2 Semaphore mechanism to indicate to the BSP that an AP has exited SMM
3 after SMBASE relocation.
4
5 Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include "PiSmmCpuDxeSmm.h"
11
12 X86_ASSEMBLY_PATCH_LABEL gPatchSmmRelocationOriginalAddressPtr32;
13 X86_ASSEMBLY_PATCH_LABEL gPatchRebasedFlagAddr32;
14
15 UINTN mSmmRelocationOriginalAddress;
16 volatile BOOLEAN *mRebasedFlag;
17
18 /**
19 AP Semaphore operation in 32-bit mode while BSP runs in 64-bit mode.
20 **/
21 VOID
22 SmmRelocationSemaphoreComplete32 (
23 VOID
24 );
25
26 /**
27 Hook return address of SMM Save State so that semaphore code
28 can be executed immediately after AP exits SMM to indicate to
29 the BSP that an AP has exited SMM after SMBASE relocation.
30
31 @param[in] CpuIndex The processor index.
32 @param[in] RebasedFlag A pointer to a flag that is set to TRUE
33 immediately after AP exits SMM.
34
35 **/
36 VOID
37 SemaphoreHook (
38 IN UINTN CpuIndex,
39 IN volatile BOOLEAN *RebasedFlag
40 )
41 {
42 SMRAM_SAVE_STATE_MAP *CpuState;
43 UINTN TempValue;
44
45 mRebasedFlag = RebasedFlag;
46 PatchInstructionX86 (
47 gPatchRebasedFlagAddr32,
48 (UINT32)(UINTN)mRebasedFlag,
49 4
50 );
51
52 CpuState = (SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET);
53 mSmmRelocationOriginalAddress = HookReturnFromSmm (
54 CpuIndex,
55 CpuState,
56 (UINT64)(UINTN)&SmmRelocationSemaphoreComplete32,
57 (UINT64)(UINTN)&SmmRelocationSemaphoreComplete
58 );
59
60 //
61 // Use temp value to fix ICC complier warning
62 //
63 TempValue = (UINTN)&mSmmRelocationOriginalAddress;
64 PatchInstructionX86 (
65 gPatchSmmRelocationOriginalAddressPtr32,
66 (UINT32)TempValue,
67 4
68 );
69 }