Home | History | Annotate | Download | only in SmmServicesTableLib
      1 /** @file
      2   SMM Services Table Library.
      3 
      4   Copyright (c) 2009 - 2015, 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 
     22 /**
     23   The constructor function caches the pointer of SMM Services Table.
     24 
     25   @param  ImageHandle   The firmware allocated handle for the EFI image.
     26   @param  SystemTable   A pointer to the EFI System Table.
     27 
     28   @retval EFI_SUCCESS   The constructor always returns EFI_SUCCESS.
     29 
     30 **/
     31 EFI_STATUS
     32 EFIAPI
     33 SmmServicesTableLibConstructor (
     34   IN EFI_HANDLE        ImageHandle,
     35   IN EFI_SYSTEM_TABLE  *SystemTable
     36   )
     37 {
     38   EFI_STATUS              Status;
     39   EFI_SMM_BASE2_PROTOCOL  *InternalSmmBase2;
     40 
     41   InternalSmmBase2 = NULL;
     42   //
     43   // Retrieve SMM Base2 Protocol,  Do not use gBS from UefiBootServicesTableLib on purpose
     44   // to prevent inclusion of gBS, gST, and gImageHandle from SMM Drivers unless the
     45   // SMM driver explicity declares that dependency.
     46   //
     47   Status = SystemTable->BootServices->LocateProtocol (
     48                                         &gEfiSmmBase2ProtocolGuid,
     49                                         NULL,
     50                                         (VOID **)&InternalSmmBase2
     51                                         );
     52   ASSERT_EFI_ERROR (Status);
     53   ASSERT (InternalSmmBase2 != NULL);
     54 
     55   //
     56   // We are in SMM, retrieve the pointer to SMM System Table
     57   //
     58   InternalSmmBase2->GetSmstLocation (InternalSmmBase2, &gSmst);
     59   ASSERT (gSmst != NULL);
     60 
     61   return EFI_SUCCESS;
     62 }
     63 
     64 /**
     65   This function allows the caller to determine if the driver is executing in
     66   System Management Mode(SMM).
     67 
     68   This function returns TRUE if the driver is executing in SMM and FALSE if the
     69   driver is not executing in SMM.
     70 
     71   @retval  TRUE  The driver is executing in System Management Mode (SMM).
     72   @retval  FALSE The driver is not executing in System Management Mode (SMM).
     73 
     74 **/
     75 BOOLEAN
     76 EFIAPI
     77 InSmm (
     78   VOID
     79   )
     80 {
     81   //
     82   // We are already in SMM
     83   //
     84   return TRUE;
     85 }
     86