MdeModulePkg/SmmSmiHandlerProfileLib: Add SMM instance.
[mirror_edk2.git] / MdeModulePkg / Library / SmmSmiHandlerProfileLib / SmmSmiHandlerProfileLib.c
1 /** @file
2 SMM driver instance of SmiHandlerProfile Library.
3
4 Copyright (c) 2017, 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 <Library/SmiHandlerProfileLib.h>
17 #include <Library/SmmServicesTableLib.h>
18 #include <Guid/SmiHandlerProfile.h>
19
20 SMI_HANDLER_PROFILE_PROTOCOL *mSmiHandlerProfile;
21
22 /**
23 This function is called by SmmChildDispatcher module to report
24 a new SMI handler is registered, to SmmCore.
25
26 @param HandlerGuid The GUID to identify the type of the handler.
27 For the SmmChildDispatch protocol, the HandlerGuid
28 must be the GUID of SmmChildDispatch protocol.
29 @param Handler The SMI handler.
30 @param CallerAddress The address of the module who registers the SMI handler.
31 @param Context The context of the SMI handler.
32 For the SmmChildDispatch protocol, the Context
33 must match the one defined for SmmChildDispatch protocol.
34 @param ContextSize The size of the context in bytes.
35 For the SmmChildDispatch protocol, the Context
36 must match the one defined for SmmChildDispatch protocol.
37
38 @retval EFI_SUCCESS The information is recorded.
39 @retval EFI_UNSUPPORTED The feature is unsupported.
40 @retval EFI_OUT_OF_RESOURCES There is no enough resource to record the information.
41 **/
42 EFI_STATUS
43 EFIAPI
44 SmiHandlerProfileRegisterHandler (
45 IN EFI_GUID *HandlerGuid,
46 IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler,
47 IN PHYSICAL_ADDRESS CallerAddress,
48 IN VOID *Context, OPTIONAL
49 IN UINTN ContextSize OPTIONAL
50 )
51 {
52 if (mSmiHandlerProfile != NULL) {
53 return mSmiHandlerProfile->RegisterHandler (mSmiHandlerProfile, HandlerGuid, Handler, CallerAddress, Context, ContextSize);
54 }
55 return EFI_UNSUPPORTED;
56 }
57
58 /**
59 This function is called by SmmChildDispatcher module to report
60 an existing SMI handler is unregistered, to SmmCore.
61
62 @param HandlerGuid The GUID to identify the type of the handler.
63 For the SmmChildDispatch protocol, the HandlerGuid
64 must be the GUID of SmmChildDispatch protocol.
65 @param Handler The SMI handler.
66
67 @retval EFI_SUCCESS The original record is removed.
68 @retval EFI_UNSUPPORTED The feature is unsupported.
69 @retval EFI_NOT_FOUND There is no record for the HandlerGuid and handler.
70 **/
71 EFI_STATUS
72 EFIAPI
73 SmiHandlerProfileUnregisterHandler (
74 IN EFI_GUID *HandlerGuid,
75 IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler
76 )
77 {
78 if (mSmiHandlerProfile != NULL) {
79 return mSmiHandlerProfile->UnregisterHandler (mSmiHandlerProfile, HandlerGuid, Handler);
80 }
81 return EFI_UNSUPPORTED;
82 }
83
84 /**
85 The constructor function for SMI handler profile.
86
87 @param ImageHandle The firmware allocated handle for the EFI image.
88 @param SystemTable A pointer to the EFI System Table.
89
90 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
91 **/
92 EFI_STATUS
93 EFIAPI
94 SmmSmiHandlerProfileLibConstructor (
95 IN EFI_HANDLE ImageHandle,
96 IN EFI_SYSTEM_TABLE *SystemTable
97 )
98 {
99 gSmst->SmmLocateProtocol (
100 &gSmiHandlerProfileGuid,
101 NULL,
102 &mSmiHandlerProfile
103 );
104 return EFI_SUCCESS;
105 }
106