]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c
MdeModulePkg/SmiHandlerProfile: Add Context support in Unregister
[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 @param Context The context of the SMI handler.
67 If it is NOT NULL, it will be used to check what is registered.
68 @param ContextSize The size of the context in bytes.
69 If Context is NOT NULL, it will be used to check what is registered.
70
71 @retval EFI_SUCCESS The original record is removed.
72 @retval EFI_UNSUPPORTED The feature is unsupported.
73 @retval EFI_NOT_FOUND There is no record for the HandlerGuid and handler.
74 **/
75 EFI_STATUS
76 EFIAPI
77 SmiHandlerProfileUnregisterHandler (
78 IN EFI_GUID *HandlerGuid,
79 IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler,
80 IN VOID *Context, OPTIONAL
81 IN UINTN ContextSize OPTIONAL
82 )
83 {
84 if (mSmiHandlerProfile != NULL) {
85 return mSmiHandlerProfile->UnregisterHandler (mSmiHandlerProfile, HandlerGuid, Handler, Context, ContextSize);
86 }
87 return EFI_UNSUPPORTED;
88 }
89
90 /**
91 The constructor function for SMI handler profile.
92
93 @param ImageHandle The firmware allocated handle for the EFI image.
94 @param SystemTable A pointer to the EFI System Table.
95
96 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
97 **/
98 EFI_STATUS
99 EFIAPI
100 SmmSmiHandlerProfileLibConstructor (
101 IN EFI_HANDLE ImageHandle,
102 IN EFI_SYSTEM_TABLE *SystemTable
103 )
104 {
105 gSmst->SmmLocateProtocol (
106 &gSmiHandlerProfileGuid,
107 NULL,
108 (VOID **) &mSmiHandlerProfile
109 );
110 return EFI_SUCCESS;
111 }
112