]> git.proxmox.com Git - mirror_edk2.git/blame - StandaloneMmPkg/Core/Notify.c
StandaloneMmPkg: Apply uncrustify changes
[mirror_edk2.git] / StandaloneMmPkg / Core / Notify.c
CommitLineData
6b46d772
SV
1/** @file\r
2 Support functions for UEFI protocol notification infrastructure.\r
3\r
4 Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\r
5 Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.<BR>\r
86094561 6 SPDX-License-Identifier: BSD-2-Clause-Patent\r
6b46d772
SV
7\r
8**/\r
9\r
10#include "StandaloneMmCore.h"\r
11\r
12/**\r
13 Signal event for every protocol in protocol entry.\r
14\r
15 @param Prot Protocol interface\r
16\r
17**/\r
18VOID\r
19MmNotifyProtocol (\r
20 IN PROTOCOL_INTERFACE *Prot\r
21 )\r
22{\r
23 PROTOCOL_ENTRY *ProtEntry;\r
24 PROTOCOL_NOTIFY *ProtNotify;\r
25 LIST_ENTRY *Link;\r
26\r
27 ProtEntry = Prot->Protocol;\r
91415a36 28 for (Link = ProtEntry->Notify.ForwardLink; Link != &ProtEntry->Notify; Link = Link->ForwardLink) {\r
6b46d772
SV
29 ProtNotify = CR (Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE);\r
30 ProtNotify->Function (&ProtEntry->ProtocolID, Prot->Interface, Prot->Handle);\r
31 }\r
32}\r
33\r
34/**\r
35 Removes Protocol from the protocol list (but not the handle list).\r
36\r
37 @param Handle The handle to remove protocol on.\r
38 @param Protocol GUID of the protocol to be moved\r
39 @param Interface The interface of the protocol\r
40\r
41 @return Protocol Entry\r
42\r
43**/\r
44PROTOCOL_INTERFACE *\r
45MmRemoveInterfaceFromProtocol (\r
46 IN IHANDLE *Handle,\r
47 IN EFI_GUID *Protocol,\r
48 IN VOID *Interface\r
49 )\r
50{\r
51 PROTOCOL_INTERFACE *Prot;\r
52 PROTOCOL_NOTIFY *ProtNotify;\r
53 PROTOCOL_ENTRY *ProtEntry;\r
54 LIST_ENTRY *Link;\r
55\r
56 Prot = MmFindProtocolInterface (Handle, Protocol, Interface);\r
57 if (Prot != NULL) {\r
6b46d772
SV
58 ProtEntry = Prot->Protocol;\r
59\r
60 //\r
61 // If there's a protocol notify location pointing to this entry, back it up one\r
62 //\r
63 for (Link = ProtEntry->Notify.ForwardLink; Link != &ProtEntry->Notify; Link = Link->ForwardLink) {\r
64 ProtNotify = CR (Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE);\r
65\r
66 if (ProtNotify->Position == &Prot->ByProtocol) {\r
67 ProtNotify->Position = Prot->ByProtocol.BackLink;\r
68 }\r
69 }\r
70\r
71 //\r
72 // Remove the protocol interface entry\r
73 //\r
74 RemoveEntryList (&Prot->ByProtocol);\r
75 }\r
76\r
77 return Prot;\r
78}\r
79\r
80/**\r
81 Add a new protocol notification record for the request protocol.\r
82\r
83 @param Protocol The requested protocol to add the notify\r
84 registration\r
85 @param Function Points to the notification function\r
86 @param Registration Returns the registration record\r
87\r
88 @retval EFI_SUCCESS Successfully returned the registration record\r
89 that has been added or unhooked\r
90 @retval EFI_INVALID_PARAMETER Protocol is NULL or Registration is NULL\r
91 @retval EFI_OUT_OF_RESOURCES Not enough memory resource to finish the request\r
92 @retval EFI_NOT_FOUND If the registration is not found when Function == NULL\r
93\r
94**/\r
95EFI_STATUS\r
96EFIAPI\r
97MmRegisterProtocolNotify (\r
91415a36 98 IN CONST EFI_GUID *Protocol,\r
6b46d772 99 IN EFI_MM_NOTIFY_FN Function,\r
91415a36 100 OUT VOID **Registration\r
6b46d772
SV
101 )\r
102{\r
103 PROTOCOL_ENTRY *ProtEntry;\r
104 PROTOCOL_NOTIFY *ProtNotify;\r
105 LIST_ENTRY *Link;\r
106 EFI_STATUS Status;\r
107\r
91415a36 108 if ((Protocol == NULL) || (Registration == NULL)) {\r
6b46d772
SV
109 return EFI_INVALID_PARAMETER;\r
110 }\r
111\r
112 if (Function == NULL) {\r
113 //\r
114 // Get the protocol entry per Protocol\r
115 //\r
91415a36 116 ProtEntry = MmFindProtocolEntry ((EFI_GUID *)Protocol, FALSE);\r
6b46d772 117 if (ProtEntry != NULL) {\r
91415a36 118 ProtNotify = (PROTOCOL_NOTIFY *)*Registration;\r
6b46d772
SV
119 for (Link = ProtEntry->Notify.ForwardLink;\r
120 Link != &ProtEntry->Notify;\r
91415a36
MK
121 Link = Link->ForwardLink)\r
122 {\r
6b46d772
SV
123 //\r
124 // Compare the notification record\r
125 //\r
126 if (ProtNotify == (CR (Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE))) {\r
127 //\r
128 // If Registration is an existing registration, then unhook it\r
129 //\r
130 ProtNotify->Signature = 0;\r
131 RemoveEntryList (&ProtNotify->Link);\r
132 FreePool (ProtNotify);\r
133 return EFI_SUCCESS;\r
134 }\r
135 }\r
136 }\r
91415a36 137\r
6b46d772
SV
138 //\r
139 // If the registration is not found\r
140 //\r
141 return EFI_NOT_FOUND;\r
142 }\r
143\r
144 ProtNotify = NULL;\r
145\r
146 //\r
147 // Get the protocol entry to add the notification too\r
148 //\r
91415a36 149 ProtEntry = MmFindProtocolEntry ((EFI_GUID *)Protocol, TRUE);\r
6b46d772
SV
150 if (ProtEntry != NULL) {\r
151 //\r
152 // Find whether notification already exist\r
153 //\r
154 for (Link = ProtEntry->Notify.ForwardLink;\r
155 Link != &ProtEntry->Notify;\r
91415a36
MK
156 Link = Link->ForwardLink)\r
157 {\r
6b46d772
SV
158 ProtNotify = CR (Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE);\r
159 if (CompareGuid (&ProtNotify->Protocol->ProtocolID, Protocol) &&\r
91415a36
MK
160 (ProtNotify->Function == Function))\r
161 {\r
6b46d772
SV
162 //\r
163 // Notification already exist\r
164 //\r
165 *Registration = ProtNotify;\r
166\r
167 return EFI_SUCCESS;\r
168 }\r
169 }\r
170\r
171 //\r
172 // Allocate a new notification record\r
173 //\r
174 ProtNotify = AllocatePool (sizeof (PROTOCOL_NOTIFY));\r
175 if (ProtNotify != NULL) {\r
176 ProtNotify->Signature = PROTOCOL_NOTIFY_SIGNATURE;\r
91415a36
MK
177 ProtNotify->Protocol = ProtEntry;\r
178 ProtNotify->Function = Function;\r
6b46d772
SV
179 //\r
180 // Start at the ending\r
181 //\r
182 ProtNotify->Position = ProtEntry->Protocols.BackLink;\r
183\r
184 InsertTailList (&ProtEntry->Notify, &ProtNotify->Link);\r
185 }\r
186 }\r
187\r
188 //\r
189 // Done. If we have a protocol notify entry, then return it.\r
190 // Otherwise, we must have run out of resources trying to add one\r
191 //\r
192 Status = EFI_OUT_OF_RESOURCES;\r
193 if (ProtNotify != NULL) {\r
194 *Registration = ProtNotify;\r
91415a36 195 Status = EFI_SUCCESS;\r
6b46d772 196 }\r
91415a36 197\r
6b46d772
SV
198 return Status;\r
199}\r