3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 EFI notify infrastructure
29 CoreNotifyProtocolEntry (
30 IN PROTOCOL_ENTRY
*ProtEntry
36 Signal event for every protocol in protocol entry.
40 ProtEntry - Protocol entry
46 PROTOCOL_NOTIFY
*ProtNotify
;
49 ASSERT_LOCKED (&gProtocolDatabaseLock
);
51 for (Link
=ProtEntry
->Notify
.ForwardLink
; Link
!= &ProtEntry
->Notify
; Link
=Link
->ForwardLink
) {
52 ProtNotify
= CR(Link
, PROTOCOL_NOTIFY
, Link
, PROTOCOL_NOTIFY_SIGNATURE
);
53 CoreSignalEvent (ProtNotify
->Event
);
59 CoreRemoveInterfaceFromProtocol (
61 IN EFI_GUID
*Protocol
,
68 Removes Protocol from the protocol list (but not the handle list).
72 Handle - The handle to remove protocol on.
74 Protocol - GUID of the protocol to be moved
76 Interface - The interface of the protocol
84 PROTOCOL_INTERFACE
*Prot
;
85 PROTOCOL_NOTIFY
*ProtNotify
;
86 PROTOCOL_ENTRY
*ProtEntry
;
89 ASSERT_LOCKED (&gProtocolDatabaseLock
);
91 Prot
= CoreFindProtocolInterface (Handle
, Protocol
, Interface
);
94 ProtEntry
= Prot
->Protocol
;
97 // If there's a protocol notify location pointing to this entry, back it up one
100 for(Link
= ProtEntry
->Notify
.ForwardLink
; Link
!= &ProtEntry
->Notify
; Link
=Link
->ForwardLink
) {
101 ProtNotify
= CR(Link
, PROTOCOL_NOTIFY
, Link
, PROTOCOL_NOTIFY_SIGNATURE
);
103 if (ProtNotify
->Position
== &Prot
->ByProtocol
) {
104 ProtNotify
->Position
= Prot
->ByProtocol
.BackLink
;
109 // Remove the protocol interface entry
112 RemoveEntryList (&Prot
->ByProtocol
);
122 CoreRegisterProtocolNotify (
123 IN EFI_GUID
*Protocol
,
125 OUT VOID
**Registration
131 Add a new protocol notification record for the request protocol.
135 Protocol - The requested protocol to add the notify registration
137 Event - The event to signal
139 Registration - Returns the registration record
144 EFI_INVALID_PARAMETER - Invalid parameter
146 EFI_SUCCESS - Successfully returned the registration record that has been added
150 PROTOCOL_ENTRY
*ProtEntry
;
151 PROTOCOL_NOTIFY
*ProtNotify
;
154 if ((Protocol
== NULL
) || (Event
== NULL
) || (Registration
== NULL
)) {
155 return EFI_INVALID_PARAMETER
;
158 CoreAcquireProtocolLock ();
163 // Get the protocol entry to add the notification too
166 ProtEntry
= CoreFindProtocolEntry (Protocol
, TRUE
);
167 if (ProtEntry
!= NULL
) {
170 // Allocate a new notification record
173 ProtNotify
= CoreAllocateBootServicesPool (sizeof(PROTOCOL_NOTIFY
));
175 if (ProtNotify
!= NULL
) {
177 ProtNotify
->Signature
= PROTOCOL_NOTIFY_SIGNATURE
;
178 ProtNotify
->Protocol
= ProtEntry
;
179 ProtNotify
->Event
= Event
;
181 // start at the begining
183 ProtNotify
->Position
= &ProtEntry
->Protocols
;
185 InsertTailList (&ProtEntry
->Notify
, &ProtNotify
->Link
);
189 CoreReleaseProtocolLock ();
192 // Done. If we have a protocol notify entry, then return it.
193 // Otherwise, we must have run out of resources trying to add one
196 Status
= EFI_OUT_OF_RESOURCES
;
197 if (ProtNotify
!= NULL
) {
198 *Registration
= ProtNotify
;
199 Status
= EFI_SUCCESS
;
209 CoreReinstallProtocolInterface (
210 IN EFI_HANDLE UserHandle
,
211 IN EFI_GUID
*Protocol
,
212 IN VOID
*OldInterface
,
213 IN VOID
*NewInterface
219 Reinstall a protocol interface on a device handle. The OldInterface for Protocol is replaced by the NewInterface.
223 UserHandle - Handle on which the interface is to be reinstalled
224 Protocol - The numeric ID of the interface
225 OldInterface - A pointer to the old interface
226 NewInterface - A pointer to the new interface
233 On EFI_SUCCESS The protocol interface was installed
234 On EFI_NOT_FOUND The OldInterface on the handle was not found
235 On EFI_INVALID_PARAMETER One of the parameters has an invalid value
241 PROTOCOL_INTERFACE
*Prot
;
242 PROTOCOL_ENTRY
*ProtEntry
;
244 Status
= CoreValidateHandle (UserHandle
);
245 if (EFI_ERROR (Status
)) {
249 if (Protocol
== NULL
) {
250 return EFI_INVALID_PARAMETER
;
253 Handle
= (IHANDLE
*) UserHandle
;
256 // Lock the protocol database
258 CoreAcquireProtocolLock ();
261 // Check that Protocol exists on UserHandle, and Interface matches the interface in the database
263 Prot
= CoreFindProtocolInterface (UserHandle
, Protocol
, OldInterface
);
265 CoreReleaseProtocolLock ();
266 return EFI_NOT_FOUND
;
270 // Attempt to disconnect all drivers that are using the protocol interface that is about to be reinstalled
272 Status
= CoreDisconnectControllersUsingProtocolInterface (
276 if (EFI_ERROR (Status
)) {
278 // One or more drivers refused to release, so return the error
280 CoreReleaseProtocolLock ();
285 // Remove the protocol interface from the protocol
287 Prot
= CoreRemoveInterfaceFromProtocol (Handle
, Protocol
, OldInterface
);
290 CoreReleaseProtocolLock ();
291 return EFI_NOT_FOUND
;
294 ProtEntry
= Prot
->Protocol
;
297 // Update the interface on the protocol
299 Prot
->Interface
= NewInterface
;
302 // Add this protocol interface to the tail of the
305 InsertTailList (&ProtEntry
->Protocols
, &Prot
->ByProtocol
);
308 // Update the Key to show that the handle has been created/modified
310 gHandleDatabaseKey
++;
311 Handle
->Key
= gHandleDatabaseKey
;
314 // Release the lock and connect all drivers to UserHandle
316 CoreReleaseProtocolLock ();
317 Status
= CoreConnectController (
323 CoreAcquireProtocolLock ();
326 // Notify the notification list for this protocol
328 CoreNotifyProtocolEntry (ProtEntry
);
330 CoreReleaseProtocolLock ();