1/** @file
2Semaphore mechanism to indicate to the BSP that an AP has exited SMM
3after SMBASE relocation.
4
5Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
6This program and the accompanying materials
7are licensed and made available under the terms and conditions of the BSD License
8which accompanies this distribution.  The full text of the license may be found at
9http://opensource.org/licenses/bsd-license.php
10
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14**/
15
16#include "PiSmmCpuDxeSmm.h"
17
18extern  UINT32    mSmmRelocationOriginalAddressPtr32;
19extern  UINT32    mRebasedFlagAddr32;
20
21UINTN             mSmmRelocationOriginalAddress;
22volatile BOOLEAN  *mRebasedFlag;
23
24/**
25AP Semaphore operation in 32-bit mode while BSP runs in 64-bit mode.
26**/
27VOID
28SmmRelocationSemaphoreComplete32 (
29  VOID
30  );
31
32/**
33  Hook return address of SMM Save State so that semaphore code
34  can be executed immediately after AP exits SMM to indicate to
35  the BSP that an AP has exited SMM after SMBASE relocation.
36
37  @param[in] CpuIndex     The processor index.
38  @param[in] RebasedFlag  A pointer to a flag that is set to TRUE
39                          immediately after AP exits SMM.
40
41**/
42VOID
43SemaphoreHook (
44  IN UINTN             CpuIndex,
45  IN volatile BOOLEAN  *RebasedFlag
46  )
47{
48  SMRAM_SAVE_STATE_MAP  *CpuState;
49  UINTN                 TempValue;
50
51  mRebasedFlag       = RebasedFlag;
52  mRebasedFlagAddr32 = (UINT32)(UINTN)mRebasedFlag;
53
54  CpuState = (SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET);
55  mSmmRelocationOriginalAddress = HookReturnFromSmm (
56                                    CpuIndex,
57                                    CpuState,
58                                    (UINT64)(UINTN)&SmmRelocationSemaphoreComplete32,
59                                    (UINT64)(UINTN)&SmmRelocationSemaphoreComplete
60                                    );
61
62  //
63  // Use temp value to fix ICC complier warning
64  //
65  TempValue = (UINTN)&mSmmRelocationOriginalAddress;
66  mSmmRelocationOriginalAddressPtr32 = (UINT32)TempValue;
67}
68