]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/SmmServicesTableLib/SmmServicesTableLib.c
PI 1.1 SMM Feature Check-in
[mirror_edk2.git] / MdePkg / Library / SmmServicesTableLib / SmmServicesTableLib.c
1 /** @file
2 SMM Services Table Library.
3
4 Copyright (c) 2009, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include <PiDxe.h>
16 #include <PiSmm.h>
17 #include <Protocol/SmmBase2.h>
18 #include <Library/UefiBootServicesTableLib.h>
19 #include <Library/SmmServicesTableLib.h>
20 #include <Library/DebugLib.h>
21
22 EFI_SMM_SYSTEM_TABLE2 *gSmst = NULL;
23 EFI_SMM_BASE2_PROTOCOL *mInternalSmmBase2 = NULL;
24
25
26 /**
27 The constructor function caches the pointer of Smm Services Table.
28
29 @param ImageHandle The firmware allocated handle for the EFI image.
30 @param SystemTable A pointer to the EFI System Table.
31
32 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
33
34 **/
35 EFI_STATUS
36 EFIAPI
37 SmmServicesTableLibConstructor (
38 IN EFI_HANDLE ImageHandle,
39 IN EFI_SYSTEM_TABLE *SystemTable
40 )
41 {
42 EFI_STATUS Status;
43 BOOLEAN InSmm;
44
45 //
46 // Retrieve SMM Base2 Protocol
47 //
48 Status = gBS->LocateProtocol (
49 &gEfiSmmBase2ProtocolGuid,
50 NULL,
51 (VOID **) &mInternalSmmBase2
52 );
53 ASSERT_EFI_ERROR (Status);
54 ASSERT (mInternalSmmBase2 != NULL);
55
56 //
57 // Check to see if we are already in SMM
58 //
59 mInternalSmmBase2->InSmm (mInternalSmmBase2, &InSmm);
60
61 if (!InSmm) {
62 //
63 // We are not in SMM, so SMST is not needed
64 //
65 return EFI_SUCCESS;
66 }
67
68 //
69 // We are in SMM, retrieve the pointer to SMM System Table
70 //
71 mInternalSmmBase2->GetSmstLocation (mInternalSmmBase2, &gSmst);
72
73 ASSERT (gSmst != NULL);
74
75 return EFI_SUCCESS;
76 }
77
78
79 /**
80 This function allows the caller to determine if the driver is executing in
81 System Management Mode(SMM).
82
83 This function returns TRUE if the driver is executing in SMM and FALSE if the
84 driver is not executing in SMM.
85
86 @retval TRUE The driver is executing in System Management Mode (SMM).
87 @retval FALSE The driver is not executing in System Management Mode (SMM).
88
89 **/
90 BOOLEAN
91 EFIAPI
92 InSmm (
93 VOID
94 )
95 {
96 BOOLEAN InSmm;
97
98 //
99 // Check to see if we are already in SMM
100 //
101 mInternalSmmBase2->InSmm (mInternalSmmBase2, &InSmm);
102
103 return InSmm;
104 }