TianoCore EDK2 master
Loading...
Searching...
No Matches
Notify.c
Go to the documentation of this file.
1
9#include "PiSmmCore.h"
10
17VOID
20 )
21{
22 PROTOCOL_ENTRY *ProtEntry;
23 PROTOCOL_NOTIFY *ProtNotify;
24 LIST_ENTRY *Link;
25
26 ProtEntry = Prot->Protocol;
27 for (Link = ProtEntry->Notify.ForwardLink; Link != &ProtEntry->Notify; Link = Link->ForwardLink) {
28 ProtNotify = CR (Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE);
29 ProtNotify->Function (&ProtEntry->ProtocolID, Prot->Interface, Prot->Handle);
30 }
31}
32
45 IN IHANDLE *Handle,
46 IN EFI_GUID *Protocol,
47 IN VOID *Interface
48 )
49{
51 PROTOCOL_NOTIFY *ProtNotify;
52 PROTOCOL_ENTRY *ProtEntry;
53 LIST_ENTRY *Link;
54
55 Prot = SmmFindProtocolInterface (Handle, Protocol, Interface);
56 if (Prot != NULL) {
57 ProtEntry = Prot->Protocol;
58
59 //
60 // If there's a protocol notify location pointing to this entry, back it up one
61 //
62 for (Link = ProtEntry->Notify.ForwardLink; Link != &ProtEntry->Notify; Link = Link->ForwardLink) {
63 ProtNotify = CR (Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE);
64
65 if (ProtNotify->Position == &Prot->ByProtocol) {
66 ProtNotify->Position = Prot->ByProtocol.BackLink;
67 }
68 }
69
70 //
71 // Remove the protocol interface entry
72 //
74 }
75
76 return Prot;
77}
78
95EFIAPI
97 IN CONST EFI_GUID *Protocol,
98 IN EFI_SMM_NOTIFY_FN Function,
99 OUT VOID **Registration
100 )
101{
102 PROTOCOL_ENTRY *ProtEntry;
103 PROTOCOL_NOTIFY *ProtNotify;
104 LIST_ENTRY *Link;
105 EFI_STATUS Status;
106
107 if ((Protocol == NULL) || (Registration == NULL)) {
108 return EFI_INVALID_PARAMETER;
109 }
110
111 if (Function == NULL) {
112 //
113 // Get the protocol entry per Protocol
114 //
115 ProtEntry = SmmFindProtocolEntry ((EFI_GUID *)Protocol, FALSE);
116 if (ProtEntry != NULL) {
117 ProtNotify = (PROTOCOL_NOTIFY *)*Registration;
118 for (Link = ProtEntry->Notify.ForwardLink;
119 Link != &ProtEntry->Notify;
120 Link = Link->ForwardLink)
121 {
122 //
123 // Compare the notification record
124 //
125 if (ProtNotify == (CR (Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE))) {
126 //
127 // If Registration is an existing registration, then unhook it
128 //
129 ProtNotify->Signature = 0;
130 RemoveEntryList (&ProtNotify->Link);
131 FreePool (ProtNotify);
132 return EFI_SUCCESS;
133 }
134 }
135 }
136
137 //
138 // If the registration is not found
139 //
140 return EFI_NOT_FOUND;
141 }
142
143 ProtNotify = NULL;
144
145 //
146 // Get the protocol entry to add the notification too
147 //
148 ProtEntry = SmmFindProtocolEntry ((EFI_GUID *)Protocol, TRUE);
149 if (ProtEntry != NULL) {
150 //
151 // Find whether notification already exist
152 //
153 for (Link = ProtEntry->Notify.ForwardLink;
154 Link != &ProtEntry->Notify;
155 Link = Link->ForwardLink)
156 {
157 ProtNotify = CR (Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE);
158 if (CompareGuid (&ProtNotify->Protocol->ProtocolID, Protocol) &&
159 (ProtNotify->Function == Function))
160 {
161 //
162 // Notification already exist
163 //
164 *Registration = ProtNotify;
165
166 return EFI_SUCCESS;
167 }
168 }
169
170 //
171 // Allocate a new notification record
172 //
173 ProtNotify = AllocatePool (sizeof (PROTOCOL_NOTIFY));
174 if (ProtNotify != NULL) {
175 ProtNotify->Signature = PROTOCOL_NOTIFY_SIGNATURE;
176 ProtNotify->Protocol = ProtEntry;
177 ProtNotify->Function = Function;
178 //
179 // Start at the ending
180 //
181 ProtNotify->Position = ProtEntry->Protocols.BackLink;
182
183 InsertTailList (&ProtEntry->Notify, &ProtNotify->Link);
184 }
185 }
186
187 //
188 // Done. If we have a protocol notify entry, then return it.
189 // Otherwise, we must have run out of resources trying to add one
190 //
191 Status = EFI_OUT_OF_RESOURCES;
192 if (ProtNotify != NULL) {
193 *Registration = ProtNotify;
194 Status = EFI_SUCCESS;
195 }
196
197 return Status;
198}
LIST_ENTRY *EFIAPI RemoveEntryList(IN CONST LIST_ENTRY *Entry)
Definition: LinkedList.c:590
LIST_ENTRY *EFIAPI InsertTailList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
Definition: LinkedList.c:259
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
Definition: MemLibGuid.c:73
VOID EFIAPI FreePool(IN VOID *Buffer)
PROTOCOL_INTERFACE * SmmFindProtocolInterface(IN IHANDLE *Handle, IN EFI_GUID *Protocol, IN VOID *Interface)
Definition: Handle.c:122
PROTOCOL_ENTRY * SmmFindProtocolEntry(IN EFI_GUID *Protocol, IN BOOLEAN Create)
Definition: Handle.c:56
VOID SmmNotifyProtocol(IN PROTOCOL_INTERFACE *Prot)
Definition: Notify.c:18
PROTOCOL_INTERFACE * SmmRemoveInterfaceFromProtocol(IN IHANDLE *Handle, IN EFI_GUID *Protocol, IN VOID *Interface)
Definition: Notify.c:44
EFI_STATUS EFIAPI SmmRegisterProtocolNotify(IN CONST EFI_GUID *Protocol, IN EFI_SMM_NOTIFY_FN Function, OUT VOID **Registration)
Definition: Notify.c:96
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define VOID
Definition: Base.h:269
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define CR(Record, TYPE, Field, TestSignature)
Definition: DebugLib.h:660
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
Definition: Base.h:213
Definition: Handle.h:17
LIST_ENTRY Notify
Registerd notification handlers.
Definition: Handle.h:46
EFI_GUID ProtocolID
ID of the protocol.
Definition: Handle.h:42
LIST_ENTRY Protocols
All protocol interfaces.
Definition: Handle.h:44
PROTOCOL_ENTRY * Protocol
The protocol ID.
Definition: Handle.h:64
LIST_ENTRY ByProtocol
Link on PROTOCOL_ENTRY.Protocols.
Definition: Handle.h:62
LIST_ENTRY Link
All notifications for this protocol.
Definition: Handle.h:94
EFI_SMM_NOTIFY_FN Function
Notification function.
Definition: PiSmmCore.h:211
LIST_ENTRY * Position
Last position notified.
Definition: Handle.h:98