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 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution.  The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10 
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 
14 **/
15 
16 #include "PiSmmCpuDxeSmm.h"
17 
18 UINTN             mSmmRelocationOriginalAddress;
19 volatile BOOLEAN  *mRebasedFlag;
20 
21 /**
22   Hook return address of SMM Save State so that semaphore code
23   can be executed immediately after AP exits SMM to indicate to
24   the BSP that an AP has exited SMM after SMBASE relocation.
25 
26   @param[in] CpuIndex     The processor index.
27   @param[in] RebasedFlag  A pointer to a flag that is set to TRUE
28                           immediately after AP exits SMM.
29 
30 **/
31 VOID
SemaphoreHook(IN UINTN CpuIndex,IN volatile BOOLEAN * RebasedFlag)32 SemaphoreHook (
33   IN UINTN             CpuIndex,
34   IN volatile BOOLEAN  *RebasedFlag
35   )
36 {
37   SMRAM_SAVE_STATE_MAP  *CpuState;
38 
39   mRebasedFlag = RebasedFlag;
40 
41   CpuState = (SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET);
42   mSmmRelocationOriginalAddress = (UINTN)HookReturnFromSmm (
43                                            CpuIndex,
44                                            CpuState,
45                                            (UINT64)(UINTN)&SmmRelocationSemaphoreComplete,
46                                            (UINT64)(UINTN)&SmmRelocationSemaphoreComplete
47                                            );
48 }
49