Vishal Bhoj | 82c8071 | 2015-12-15 21:13:33 +0530 | [diff] [blame] | 1 | /** @file
|
| 2 | SMM Services Table Library.
|
| 3 |
|
| 4 | Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
|
| 5 | 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 <PiSmm.h>
|
| 16 | #include <Protocol/SmmBase2.h>
|
| 17 | #include <Library/SmmServicesTableLib.h>
|
| 18 | #include <Library/DebugLib.h>
|
| 19 |
|
| 20 | EFI_SMM_SYSTEM_TABLE2 *gSmst = NULL;
|
| 21 | EFI_SMM_BASE2_PROTOCOL *mInternalSmmBase2 = NULL;
|
| 22 |
|
| 23 | /**
|
| 24 | The constructor function caches the pointer of SMM Services Table.
|
| 25 |
|
| 26 | @param ImageHandle The firmware allocated handle for the EFI image.
|
| 27 | @param SystemTable A pointer to the EFI System Table.
|
| 28 |
|
| 29 | @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
|
| 30 |
|
| 31 | **/
|
| 32 | EFI_STATUS
|
| 33 | EFIAPI
|
| 34 | SmmServicesTableLibConstructor (
|
| 35 | IN EFI_HANDLE ImageHandle,
|
| 36 | IN EFI_SYSTEM_TABLE *SystemTable
|
| 37 | )
|
| 38 | {
|
| 39 | EFI_STATUS Status;
|
| 40 |
|
| 41 | //
|
| 42 | // Retrieve SMM Base2 Protocol, Do not use gBS from UefiBootServicesTableLib on purpose
|
| 43 | // to prevent inclusion of gBS, gST, and gImageHandle from SMM Drivers unless the
|
| 44 | // SMM driver explicity declares that dependency.
|
| 45 | //
|
| 46 | Status = SystemTable->BootServices->LocateProtocol (
|
| 47 | &gEfiSmmBase2ProtocolGuid,
|
| 48 | NULL,
|
| 49 | (VOID **)&mInternalSmmBase2
|
| 50 | );
|
| 51 | ASSERT_EFI_ERROR (Status);
|
| 52 | ASSERT (mInternalSmmBase2 != NULL);
|
| 53 |
|
| 54 | //
|
| 55 | // Check to see if we are already in SMM
|
| 56 | //
|
| 57 | if (!InSmm ()) {
|
| 58 | //
|
| 59 | // We are not in SMM, so SMST is not needed
|
| 60 | //
|
| 61 | return EFI_SUCCESS;
|
| 62 | }
|
| 63 |
|
| 64 | //
|
| 65 | // We are in SMM, retrieve the pointer to SMM System Table
|
| 66 | //
|
| 67 | mInternalSmmBase2->GetSmstLocation (mInternalSmmBase2, &gSmst);
|
| 68 | ASSERT (gSmst != NULL);
|
| 69 |
|
| 70 | return EFI_SUCCESS;
|
| 71 | }
|
| 72 |
|
| 73 | /**
|
| 74 | This function allows the caller to determine if the driver is executing in
|
| 75 | System Management Mode(SMM).
|
| 76 |
|
| 77 | This function returns TRUE if the driver is executing in SMM and FALSE if the
|
| 78 | driver is not executing in SMM.
|
| 79 |
|
| 80 | @retval TRUE The driver is executing in System Management Mode (SMM).
|
| 81 | @retval FALSE The driver is not executing in System Management Mode (SMM).
|
| 82 |
|
| 83 | **/
|
| 84 | BOOLEAN
|
| 85 | EFIAPI
|
| 86 | InSmm (
|
| 87 | VOID
|
| 88 | )
|
| 89 | {
|
| 90 | BOOLEAN InSmm;
|
| 91 |
|
| 92 | //
|
| 93 | // Check to see if we are already in SMM
|
| 94 | //
|
| 95 | mInternalSmmBase2->InSmm (mInternalSmmBase2, &InSmm);
|
| 96 | return InSmm;
|
| 97 | }
|