]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/SmmSmiHandlerProfileLib/MmSmiHandlerProfileLib.c
MdeModulePkg: Change OPTIONAL keyword usage style
[mirror_edk2.git] / MdeModulePkg / Library / SmmSmiHandlerProfileLib / MmSmiHandlerProfileLib.c
1 /** @file
2 MM driver instance of SmiHandlerProfile Library.
3
4 Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
5 Copyright (c) Microsoft Corporation.
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include <PiMm.h>
11 #include <Library/SmiHandlerProfileLib.h>
12 #include <Library/MmServicesTableLib.h>
13 #include <Guid/SmiHandlerProfile.h>
14
15 SMI_HANDLER_PROFILE_PROTOCOL *mSmiHandlerProfile;
16
17 /**
18 This function is called by SmmChildDispatcher module to report
19 a new SMI handler is registered, to SmmCore.
20
21 @param HandlerGuid The GUID to identify the type of the handler.
22 For the SmmChildDispatch protocol, the HandlerGuid
23 must be the GUID of SmmChildDispatch protocol.
24 @param Handler The SMI handler.
25 @param CallerAddress The address of the module who registers the SMI handler.
26 @param Context The context of the SMI handler.
27 For the SmmChildDispatch protocol, the Context
28 must match the one defined for SmmChildDispatch protocol.
29 @param ContextSize The size of the context in bytes.
30 For the SmmChildDispatch protocol, the Context
31 must match the one defined for SmmChildDispatch protocol.
32
33 @retval EFI_SUCCESS The information is recorded.
34 @retval EFI_UNSUPPORTED The feature is unsupported.
35 @retval EFI_OUT_OF_RESOURCES There is no enough resource to record the information.
36 **/
37 EFI_STATUS
38 EFIAPI
39 SmiHandlerProfileRegisterHandler (
40 IN EFI_GUID *HandlerGuid,
41 IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler,
42 IN PHYSICAL_ADDRESS CallerAddress,
43 IN VOID *Context OPTIONAL,
44 IN UINTN ContextSize OPTIONAL
45 )
46 {
47 if (mSmiHandlerProfile != NULL) {
48 return mSmiHandlerProfile->RegisterHandler (mSmiHandlerProfile, HandlerGuid, Handler, CallerAddress, Context, ContextSize);
49 }
50 return EFI_UNSUPPORTED;
51 }
52
53 /**
54 This function is called by SmmChildDispatcher module to report
55 an existing SMI handler is unregistered, to SmmCore.
56
57 @param HandlerGuid The GUID to identify the type of the handler.
58 For the SmmChildDispatch protocol, the HandlerGuid
59 must be the GUID of SmmChildDispatch protocol.
60 @param Handler The SMI handler.
61 @param Context The context of the SMI handler.
62 If it is NOT NULL, it will be used to check what is registered.
63 @param ContextSize The size of the context in bytes.
64 If Context is NOT NULL, it will be used to check what is registered.
65
66 @retval EFI_SUCCESS The original record is removed.
67 @retval EFI_UNSUPPORTED The feature is unsupported.
68 @retval EFI_NOT_FOUND There is no record for the HandlerGuid and handler.
69 **/
70 EFI_STATUS
71 EFIAPI
72 SmiHandlerProfileUnregisterHandler (
73 IN EFI_GUID *HandlerGuid,
74 IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler,
75 IN VOID *Context OPTIONAL,
76 IN UINTN ContextSize OPTIONAL
77 )
78 {
79 if (mSmiHandlerProfile != NULL) {
80 return mSmiHandlerProfile->UnregisterHandler (mSmiHandlerProfile, HandlerGuid, Handler, Context, ContextSize);
81 }
82 return EFI_UNSUPPORTED;
83 }
84
85 /**
86 The common constructor function for SMI handler profile.
87
88 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
89 **/
90 EFI_STATUS
91 MmSmiHandlerProfileLibInitialization (
92 VOID
93 )
94 {
95 gMmst->MmLocateProtocol (
96 &gSmiHandlerProfileGuid,
97 NULL,
98 (VOID **) &mSmiHandlerProfile
99 );
100 return EFI_SUCCESS;
101 }