3 UEFI notify infrastructure
5 Copyright (c) 2006 - 2008, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 CoreNotifyProtocolEntry (
20 IN PROTOCOL_ENTRY
*ProtEntry
26 Signal event for every protocol in protocol entry.
30 ProtEntry - Protocol entry
36 PROTOCOL_NOTIFY
*ProtNotify
;
39 ASSERT_LOCKED (&gProtocolDatabaseLock
);
41 for (Link
=ProtEntry
->Notify
.ForwardLink
; Link
!= &ProtEntry
->Notify
; Link
=Link
->ForwardLink
) {
42 ProtNotify
= CR(Link
, PROTOCOL_NOTIFY
, Link
, PROTOCOL_NOTIFY_SIGNATURE
);
43 CoreSignalEvent (ProtNotify
->Event
);
49 CoreRemoveInterfaceFromProtocol (
51 IN EFI_GUID
*Protocol
,
58 Removes Protocol from the protocol list (but not the handle list).
62 Handle - The handle to remove protocol on.
64 Protocol - GUID of the protocol to be moved
66 Interface - The interface of the protocol
74 PROTOCOL_INTERFACE
*Prot
;
75 PROTOCOL_NOTIFY
*ProtNotify
;
76 PROTOCOL_ENTRY
*ProtEntry
;
79 ASSERT_LOCKED (&gProtocolDatabaseLock
);
81 Prot
= CoreFindProtocolInterface (Handle
, Protocol
, Interface
);
84 ProtEntry
= Prot
->Protocol
;
87 // If there's a protocol notify location pointing to this entry, back it up one
90 for(Link
= ProtEntry
->Notify
.ForwardLink
; Link
!= &ProtEntry
->Notify
; Link
=Link
->ForwardLink
) {
91 ProtNotify
= CR(Link
, PROTOCOL_NOTIFY
, Link
, PROTOCOL_NOTIFY_SIGNATURE
);
93 if (ProtNotify
->Position
== &Prot
->ByProtocol
) {
94 ProtNotify
->Position
= Prot
->ByProtocol
.BackLink
;
99 // Remove the protocol interface entry
102 RemoveEntryList (&Prot
->ByProtocol
);
112 CoreRegisterProtocolNotify (
113 IN EFI_GUID
*Protocol
,
115 OUT VOID
**Registration
121 Add a new protocol notification record for the request protocol.
125 Protocol - The requested protocol to add the notify registration
127 Event - The event to signal
129 Registration - Returns the registration record
134 EFI_INVALID_PARAMETER - Invalid parameter
136 EFI_SUCCESS - Successfully returned the registration record that has been added
140 PROTOCOL_ENTRY
*ProtEntry
;
141 PROTOCOL_NOTIFY
*ProtNotify
;
144 if ((Protocol
== NULL
) || (Event
== NULL
) || (Registration
== NULL
)) {
145 return EFI_INVALID_PARAMETER
;
148 CoreAcquireProtocolLock ();
153 // Get the protocol entry to add the notification too
156 ProtEntry
= CoreFindProtocolEntry (Protocol
, TRUE
);
157 if (ProtEntry
!= NULL
) {
160 // Allocate a new notification record
163 ProtNotify
= CoreAllocateBootServicesPool (sizeof(PROTOCOL_NOTIFY
));
165 if (ProtNotify
!= NULL
) {
167 ProtNotify
->Signature
= PROTOCOL_NOTIFY_SIGNATURE
;
168 ProtNotify
->Protocol
= ProtEntry
;
169 ProtNotify
->Event
= Event
;
171 // start at the begining
173 ProtNotify
->Position
= &ProtEntry
->Protocols
;
175 InsertTailList (&ProtEntry
->Notify
, &ProtNotify
->Link
);
179 CoreReleaseProtocolLock ();
182 // Done. If we have a protocol notify entry, then return it.
183 // Otherwise, we must have run out of resources trying to add one
186 Status
= EFI_OUT_OF_RESOURCES
;
187 if (ProtNotify
!= NULL
) {
188 *Registration
= ProtNotify
;
189 Status
= EFI_SUCCESS
;
199 CoreReinstallProtocolInterface (
200 IN EFI_HANDLE UserHandle
,
201 IN EFI_GUID
*Protocol
,
202 IN VOID
*OldInterface
,
203 IN VOID
*NewInterface
209 Reinstall a protocol interface on a device handle. The OldInterface for Protocol is replaced by the NewInterface.
213 UserHandle - Handle on which the interface is to be reinstalled
214 Protocol - The numeric ID of the interface
215 OldInterface - A pointer to the old interface
216 NewInterface - A pointer to the new interface
223 On EFI_SUCCESS The protocol interface was installed
224 On EFI_NOT_FOUND The OldInterface on the handle was not found
225 On EFI_INVALID_PARAMETER One of the parameters has an invalid value
231 PROTOCOL_INTERFACE
*Prot
;
232 PROTOCOL_ENTRY
*ProtEntry
;
234 Status
= CoreValidateHandle (UserHandle
);
235 if (EFI_ERROR (Status
)) {
239 if (Protocol
== NULL
) {
240 return EFI_INVALID_PARAMETER
;
243 Handle
= (IHANDLE
*) UserHandle
;
246 // Lock the protocol database
248 CoreAcquireProtocolLock ();
251 // Check that Protocol exists on UserHandle, and Interface matches the interface in the database
253 Prot
= CoreFindProtocolInterface (UserHandle
, Protocol
, OldInterface
);
255 CoreReleaseProtocolLock ();
256 return EFI_NOT_FOUND
;
260 // Attempt to disconnect all drivers that are using the protocol interface that is about to be reinstalled
262 Status
= CoreDisconnectControllersUsingProtocolInterface (
266 if (EFI_ERROR (Status
)) {
268 // One or more drivers refused to release, so return the error
270 CoreReleaseProtocolLock ();
275 // Remove the protocol interface from the protocol
277 Prot
= CoreRemoveInterfaceFromProtocol (Handle
, Protocol
, OldInterface
);
280 CoreReleaseProtocolLock ();
281 return EFI_NOT_FOUND
;
284 ProtEntry
= Prot
->Protocol
;
287 // Update the interface on the protocol
289 Prot
->Interface
= NewInterface
;
292 // Add this protocol interface to the tail of the
295 InsertTailList (&ProtEntry
->Protocols
, &Prot
->ByProtocol
);
298 // Update the Key to show that the handle has been created/modified
300 gHandleDatabaseKey
++;
301 Handle
->Key
= gHandleDatabaseKey
;
304 // Release the lock and connect all drivers to UserHandle
306 CoreReleaseProtocolLock ();
307 Status
= CoreConnectController (
313 CoreAcquireProtocolLock ();
316 // Notify the notification list for this protocol
318 CoreNotifyProtocolEntry (ProtEntry
);
320 CoreReleaseProtocolLock ();