]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/Dxe/Hand/Notify.c
Update to fix minor coding style issues.
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Hand / Notify.c
CommitLineData
23c98c94 1/** @file\r
504214c4 2 UEFI notify infrastructure\r
28a00297 3\r
23c98c94 4Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r
5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
28a00297 12\r
504214c4 13**/\r
28a00297 14\r
15#include <DxeMain.h>\r
16\r
28a00297 17\r
162ed594 18/**\r
28a00297 19 Signal event for every protocol in protocol entry.\r
20\r
162ed594 21 @param ProtEntry Protocol entry\r
28a00297 22\r
162ed594 23**/\r
24VOID\r
25CoreNotifyProtocolEntry (\r
26 IN PROTOCOL_ENTRY *ProtEntry\r
27 )\r
28a00297 28{\r
29 PROTOCOL_NOTIFY *ProtNotify;\r
30 LIST_ENTRY *Link;\r
31\r
32 ASSERT_LOCKED (&gProtocolDatabaseLock);\r
33\r
34 for (Link=ProtEntry->Notify.ForwardLink; Link != &ProtEntry->Notify; Link=Link->ForwardLink) {\r
35 ProtNotify = CR(Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE);\r
36 CoreSignalEvent (ProtNotify->Event);\r
37 }\r
38}\r
39\r
40\r
162ed594 41\r
42/**\r
43 Removes Protocol from the protocol list (but not the handle list).\r
44\r
45 @param Handle The handle to remove protocol on. \r
46 @param Protocol GUID of the protocol to be moved \r
47 @param Interface The interface of the protocol \r
48\r
49 @return Protocol Entry\r
50\r
51**/\r
28a00297 52PROTOCOL_INTERFACE *\r
53CoreRemoveInterfaceFromProtocol (\r
54 IN IHANDLE *Handle,\r
55 IN EFI_GUID *Protocol,\r
56 IN VOID *Interface\r
57 )\r
28a00297 58{\r
59 PROTOCOL_INTERFACE *Prot;\r
60 PROTOCOL_NOTIFY *ProtNotify;\r
61 PROTOCOL_ENTRY *ProtEntry;\r
62 LIST_ENTRY *Link;\r
63\r
64 ASSERT_LOCKED (&gProtocolDatabaseLock);\r
65\r
66 Prot = CoreFindProtocolInterface (Handle, Protocol, Interface);\r
67 if (Prot != NULL) {\r
68\r
69 ProtEntry = Prot->Protocol;\r
70\r
71 //\r
72 // If there's a protocol notify location pointing to this entry, back it up one\r
73 //\r
74\r
75 for(Link = ProtEntry->Notify.ForwardLink; Link != &ProtEntry->Notify; Link=Link->ForwardLink) {\r
76 ProtNotify = CR(Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE);\r
77\r
78 if (ProtNotify->Position == &Prot->ByProtocol) {\r
79 ProtNotify->Position = Prot->ByProtocol.BackLink;\r
80 }\r
81 }\r
82\r
83 //\r
84 // Remove the protocol interface entry\r
85 //\r
86\r
87 RemoveEntryList (&Prot->ByProtocol);\r
88 }\r
89\r
90 return Prot;\r
91}\r
92\r
93\r
94\r
162ed594 95\r
96/**\r
97 Add a new protocol notification record for the request protocol.\r
98\r
99 @param Protocol The requested protocol to add the notify \r
100 registration \r
101 @param Event The event to signal \r
102 @param Registration Returns the registration record \r
103\r
104 @retval EFI_INVALID_PARAMETER Invalid parameter \r
105 @retval EFI_SUCCESS Successfully returned the registration record \r
106 that has been added\r
107\r
108**/\r
28a00297 109EFI_STATUS\r
110EFIAPI\r
111CoreRegisterProtocolNotify (\r
112 IN EFI_GUID *Protocol,\r
113 IN EFI_EVENT Event,\r
114 OUT VOID **Registration\r
115 )\r
28a00297 116{\r
117 PROTOCOL_ENTRY *ProtEntry;\r
118 PROTOCOL_NOTIFY *ProtNotify;\r
119 EFI_STATUS Status;\r
120 \r
121 if ((Protocol == NULL) || (Event == NULL) || (Registration == NULL)) {\r
122 return EFI_INVALID_PARAMETER;\r
123 }\r
124\r
125 CoreAcquireProtocolLock ();\r
126\r
127 ProtNotify = NULL;\r
128 \r
129 //\r
130 // Get the protocol entry to add the notification too\r
131 //\r
132\r
133 ProtEntry = CoreFindProtocolEntry (Protocol, TRUE);\r
134 if (ProtEntry != NULL) {\r
135\r
136 //\r
137 // Allocate a new notification record\r
138 //\r
139\r
140 ProtNotify = CoreAllocateBootServicesPool (sizeof(PROTOCOL_NOTIFY));\r
141\r
142 if (ProtNotify != NULL) {\r
143 \r
144 ProtNotify->Signature = PROTOCOL_NOTIFY_SIGNATURE;\r
145 ProtNotify->Protocol = ProtEntry;\r
146 ProtNotify->Event = Event;\r
147 //\r
148 // start at the begining\r
149 //\r
150 ProtNotify->Position = &ProtEntry->Protocols; \r
151\r
152 InsertTailList (&ProtEntry->Notify, &ProtNotify->Link);\r
153 }\r
154 }\r
155\r
156 CoreReleaseProtocolLock ();\r
157\r
158 //\r
159 // Done. If we have a protocol notify entry, then return it.\r
160 // Otherwise, we must have run out of resources trying to add one\r
161 //\r
162\r
163 Status = EFI_OUT_OF_RESOURCES;\r
164 if (ProtNotify != NULL) {\r
165 *Registration = ProtNotify;\r
166 Status = EFI_SUCCESS;\r
167 }\r
168\r
169 return Status;\r
170}\r
171\r
172\r
173\r
162ed594 174\r
175/**\r
176 Reinstall a protocol interface on a device handle. The OldInterface for Protocol is replaced by the NewInterface.\r
177\r
178 @param UserHandle Handle on which the interface is to be \r
179 reinstalled \r
180 @param Protocol The numeric ID of the interface \r
181 @param OldInterface A pointer to the old interface \r
182 @param NewInterface A pointer to the new interface \r
183\r
184 @retval EFI_SUCCESS The protocol interface was installed\r
185 @retval EFI_NOT_FOUND The OldInterface on the handle was not found\r
186 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value\r
187\r
188**/\r
28a00297 189EFI_STATUS\r
190EFIAPI\r
191CoreReinstallProtocolInterface (\r
192 IN EFI_HANDLE UserHandle,\r
193 IN EFI_GUID *Protocol,\r
194 IN VOID *OldInterface,\r
195 IN VOID *NewInterface\r
196 )\r
28a00297 197{\r
198 EFI_STATUS Status;\r
199 IHANDLE *Handle;\r
200 PROTOCOL_INTERFACE *Prot;\r
201 PROTOCOL_ENTRY *ProtEntry;\r
202\r
203 Status = CoreValidateHandle (UserHandle);\r
204 if (EFI_ERROR (Status)) {\r
205 return Status;\r
206 }\r
207\r
208 if (Protocol == NULL) {\r
209 return EFI_INVALID_PARAMETER;\r
210 }\r
211\r
212 Handle = (IHANDLE *) UserHandle;\r
213\r
214 //\r
215 // Lock the protocol database\r
216 //\r
217 CoreAcquireProtocolLock ();\r
218\r
219 //\r
220 // Check that Protocol exists on UserHandle, and Interface matches the interface in the database\r
221 //\r
222 Prot = CoreFindProtocolInterface (UserHandle, Protocol, OldInterface);\r
223 if (Prot == NULL) {\r
224 CoreReleaseProtocolLock ();\r
225 return EFI_NOT_FOUND;\r
226 }\r
227\r
228 //\r
229 // Attempt to disconnect all drivers that are using the protocol interface that is about to be reinstalled\r
230 //\r
231 Status = CoreDisconnectControllersUsingProtocolInterface (\r
232 UserHandle,\r
233 Prot\r
234 );\r
235 if (EFI_ERROR (Status)) {\r
236 //\r
237 // One or more drivers refused to release, so return the error\r
238 //\r
239 CoreReleaseProtocolLock ();\r
240 return Status;\r
241 }\r
242\r
243 //\r
244 // Remove the protocol interface from the protocol\r
245 //\r
246 Prot = CoreRemoveInterfaceFromProtocol (Handle, Protocol, OldInterface);\r
247\r
248 if (Prot == NULL) {\r
249 CoreReleaseProtocolLock ();\r
250 return EFI_NOT_FOUND;\r
251 }\r
252\r
253 ProtEntry = Prot->Protocol;\r
254\r
255 //\r
256 // Update the interface on the protocol\r
257 //\r
258 Prot->Interface = NewInterface;\r
259\r
260 //\r
261 // Add this protocol interface to the tail of the\r
262 // protocol entry\r
263 //\r
264 InsertTailList (&ProtEntry->Protocols, &Prot->ByProtocol);\r
265\r
266 //\r
267 // Update the Key to show that the handle has been created/modified\r
268 //\r
269 gHandleDatabaseKey++;\r
270 Handle->Key = gHandleDatabaseKey;\r
271\r
272 //\r
273 // Release the lock and connect all drivers to UserHandle\r
274 //\r
275 CoreReleaseProtocolLock ();\r
276 Status = CoreConnectController (\r
277 UserHandle, \r
278 NULL, \r
279 NULL, \r
280 TRUE\r
281 );\r
282 CoreAcquireProtocolLock ();\r
283 \r
284 //\r
285 // Notify the notification list for this protocol\r
286 //\r
287 CoreNotifyProtocolEntry (ProtEntry);\r
288\r
289 CoreReleaseProtocolLock ();\r
290 \r
291 return EFI_SUCCESS;\r
292}\r