MdeModulePkg/SmiHandlerProfile: Add Context support in Unregister
[mirror_edk2.git] / MdeModulePkg / Library / SmmSmiHandlerProfileLib / SmmSmiHandlerProfileLib.c
CommitLineData
e08bfc7d
JY
1/** @file\r
2 SMM driver instance of SmiHandlerProfile Library.\r
3\r
4 Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>\r
5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php.\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include <PiSmm.h>\r
16#include <Library/SmiHandlerProfileLib.h>\r
17#include <Library/SmmServicesTableLib.h>\r
18#include <Guid/SmiHandlerProfile.h>\r
19\r
20SMI_HANDLER_PROFILE_PROTOCOL *mSmiHandlerProfile;\r
21\r
22/**\r
23 This function is called by SmmChildDispatcher module to report\r
24 a new SMI handler is registered, to SmmCore.\r
25\r
26 @param HandlerGuid The GUID to identify the type of the handler.\r
27 For the SmmChildDispatch protocol, the HandlerGuid\r
28 must be the GUID of SmmChildDispatch protocol.\r
29 @param Handler The SMI handler.\r
30 @param CallerAddress The address of the module who registers the SMI handler.\r
31 @param Context The context of the SMI handler.\r
32 For the SmmChildDispatch protocol, the Context\r
33 must match the one defined for SmmChildDispatch protocol.\r
34 @param ContextSize The size of the context in bytes.\r
35 For the SmmChildDispatch protocol, the Context\r
36 must match the one defined for SmmChildDispatch protocol.\r
37\r
38 @retval EFI_SUCCESS The information is recorded.\r
39 @retval EFI_UNSUPPORTED The feature is unsupported.\r
40 @retval EFI_OUT_OF_RESOURCES There is no enough resource to record the information.\r
41**/\r
42EFI_STATUS\r
43EFIAPI\r
44SmiHandlerProfileRegisterHandler (\r
45 IN EFI_GUID *HandlerGuid,\r
46 IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler,\r
47 IN PHYSICAL_ADDRESS CallerAddress,\r
48 IN VOID *Context, OPTIONAL\r
49 IN UINTN ContextSize OPTIONAL\r
50 )\r
51{\r
52 if (mSmiHandlerProfile != NULL) {\r
53 return mSmiHandlerProfile->RegisterHandler (mSmiHandlerProfile, HandlerGuid, Handler, CallerAddress, Context, ContextSize);\r
54 }\r
55 return EFI_UNSUPPORTED;\r
56}\r
57\r
58/**\r
59 This function is called by SmmChildDispatcher module to report\r
60 an existing SMI handler is unregistered, to SmmCore.\r
61\r
62 @param HandlerGuid The GUID to identify the type of the handler.\r
63 For the SmmChildDispatch protocol, the HandlerGuid\r
64 must be the GUID of SmmChildDispatch protocol.\r
65 @param Handler The SMI handler.\r
cb716d29
JY
66 @param Context The context of the SMI handler.\r
67 If it is NOT NULL, it will be used to check what is registered.\r
68 @param ContextSize The size of the context in bytes.\r
69 If Context is NOT NULL, it will be used to check what is registered.\r
e08bfc7d
JY
70\r
71 @retval EFI_SUCCESS The original record is removed.\r
72 @retval EFI_UNSUPPORTED The feature is unsupported.\r
73 @retval EFI_NOT_FOUND There is no record for the HandlerGuid and handler.\r
74**/\r
75EFI_STATUS\r
76EFIAPI\r
77SmiHandlerProfileUnregisterHandler (\r
78 IN EFI_GUID *HandlerGuid,\r
cb716d29
JY
79 IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler,\r
80 IN VOID *Context, OPTIONAL\r
81 IN UINTN ContextSize OPTIONAL\r
e08bfc7d
JY
82 )\r
83{\r
84 if (mSmiHandlerProfile != NULL) {\r
cb716d29 85 return mSmiHandlerProfile->UnregisterHandler (mSmiHandlerProfile, HandlerGuid, Handler, Context, ContextSize);\r
e08bfc7d
JY
86 }\r
87 return EFI_UNSUPPORTED;\r
88}\r
89\r
90/**\r
91 The constructor function for SMI handler profile.\r
92\r
93 @param ImageHandle The firmware allocated handle for the EFI image.\r
94 @param SystemTable A pointer to the EFI System Table.\r
95\r
96 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
97**/\r
98EFI_STATUS\r
99EFIAPI\r
100SmmSmiHandlerProfileLibConstructor (\r
101 IN EFI_HANDLE ImageHandle,\r
102 IN EFI_SYSTEM_TABLE *SystemTable\r
103 )\r
104{\r
105 gSmst->SmmLocateProtocol (\r
106 &gSmiHandlerProfileGuid,\r
107 NULL,\r
8c1183a8 108 (VOID **) &mSmiHandlerProfile\r
e08bfc7d
JY
109 );\r
110 return EFI_SUCCESS;\r
111}\r
112\r