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