1 | /** @file
|
---|
2 | SMM Services Table Library.
|
---|
3 |
|
---|
4 | Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
|
---|
5 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
6 |
|
---|
7 | **/
|
---|
8 |
|
---|
9 | #include <PiSmm.h>
|
---|
10 | #include <Protocol/SmmBase2.h>
|
---|
11 | #include <Library/SmmServicesTableLib.h>
|
---|
12 | #include <Library/DebugLib.h>
|
---|
13 |
|
---|
14 | EFI_SMM_SYSTEM_TABLE2 *gSmst = NULL;
|
---|
15 |
|
---|
16 | /**
|
---|
17 | The constructor function caches the pointer of SMM Services Table.
|
---|
18 |
|
---|
19 | @param ImageHandle The firmware allocated handle for the EFI image.
|
---|
20 | @param SystemTable A pointer to the EFI System Table.
|
---|
21 |
|
---|
22 | @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
|
---|
23 |
|
---|
24 | **/
|
---|
25 | EFI_STATUS
|
---|
26 | EFIAPI
|
---|
27 | SmmServicesTableLibConstructor (
|
---|
28 | IN EFI_HANDLE ImageHandle,
|
---|
29 | IN EFI_SYSTEM_TABLE *SystemTable
|
---|
30 | )
|
---|
31 | {
|
---|
32 | EFI_STATUS Status;
|
---|
33 | EFI_SMM_BASE2_PROTOCOL *InternalSmmBase2;
|
---|
34 |
|
---|
35 | InternalSmmBase2 = NULL;
|
---|
36 | //
|
---|
37 | // Retrieve SMM Base2 Protocol, Do not use gBS from UefiBootServicesTableLib on purpose
|
---|
38 | // to prevent inclusion of gBS, gST, and gImageHandle from SMM Drivers unless the
|
---|
39 | // SMM driver explicitly declares that dependency.
|
---|
40 | //
|
---|
41 | Status = SystemTable->BootServices->LocateProtocol (
|
---|
42 | &gEfiSmmBase2ProtocolGuid,
|
---|
43 | NULL,
|
---|
44 | (VOID **)&InternalSmmBase2
|
---|
45 | );
|
---|
46 | ASSERT_EFI_ERROR (Status);
|
---|
47 | ASSERT (InternalSmmBase2 != NULL);
|
---|
48 |
|
---|
49 | //
|
---|
50 | // We are in SMM, retrieve the pointer to SMM System Table
|
---|
51 | //
|
---|
52 | InternalSmmBase2->GetSmstLocation (InternalSmmBase2, &gSmst);
|
---|
53 | ASSERT (gSmst != NULL);
|
---|
54 |
|
---|
55 | return EFI_SUCCESS;
|
---|
56 | }
|
---|
57 |
|
---|
58 | /**
|
---|
59 | This function allows the caller to determine if the driver is executing in
|
---|
60 | System Management Mode(SMM).
|
---|
61 |
|
---|
62 | This function returns TRUE if the driver is executing in SMM and FALSE if the
|
---|
63 | driver is not executing in SMM.
|
---|
64 |
|
---|
65 | @retval TRUE The driver is executing in System Management Mode (SMM).
|
---|
66 | @retval FALSE The driver is not executing in System Management Mode (SMM).
|
---|
67 |
|
---|
68 | **/
|
---|
69 | BOOLEAN
|
---|
70 | EFIAPI
|
---|
71 | InSmm (
|
---|
72 | VOID
|
---|
73 | )
|
---|
74 | {
|
---|
75 | //
|
---|
76 | // We are already in SMM
|
---|
77 | //
|
---|
78 | return TRUE;
|
---|
79 | }
|
---|