]>
Commit | Line | Data |
---|---|---|
23c98c94 | 1 | /** @file\r |
162ed594 | 2 | UEFI handle & protocol handling.\r |
28a00297 | 3 | \r |
23c98c94 | 4 | Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r |
5 | All rights reserved. This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
28a00297 | 12 | \r |
504214c4 | 13 | **/\r |
28a00297 | 14 | \r |
9c4ac31c | 15 | #include "DxeMain.h"\r |
28a00297 | 16 | \r |
17 | \r | |
18 | //\r | |
19 | // mProtocolDatabase - A list of all protocols in the system. (simple list for now)\r | |
20 | // gHandleList - A list of all the handles in the system\r | |
21 | // gProtocolDatabaseLock - Lock to protect the mProtocolDatabase\r | |
22 | // gHandleDatabaseKey - The Key to show that the handle has been created/modified\r | |
23 | //\r | |
e94a9ff7 | 24 | LIST_ENTRY mProtocolDatabase = INITIALIZE_LIST_HEAD_VARIABLE (mProtocolDatabase);\r |
28a00297 | 25 | LIST_ENTRY gHandleList = INITIALIZE_LIST_HEAD_VARIABLE (gHandleList);\r |
26 | EFI_LOCK gProtocolDatabaseLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);\r | |
27 | UINT64 gHandleDatabaseKey = 0;\r | |
28 | \r | |
29 | \r | |
162ed594 | 30 | \r |
31 | /**\r | |
32 | Acquire lock on gProtocolDatabaseLock.\r | |
33 | \r | |
34 | **/\r | |
28a00297 | 35 | VOID\r |
36 | CoreAcquireProtocolLock (\r | |
37 | VOID\r | |
38 | )\r | |
28a00297 | 39 | {\r |
40 | CoreAcquireLock (&gProtocolDatabaseLock);\r | |
41 | }\r | |
42 | \r | |
43 | \r | |
162ed594 | 44 | \r |
45 | /**\r | |
46 | Release lock on gProtocolDatabaseLock.\r | |
47 | \r | |
48 | **/\r | |
28a00297 | 49 | VOID\r |
50 | CoreReleaseProtocolLock (\r | |
51 | VOID\r | |
52 | )\r | |
28a00297 | 53 | {\r |
54 | CoreReleaseLock (&gProtocolDatabaseLock);\r | |
55 | }\r | |
56 | \r | |
57 | \r | |
28a00297 | 58 | \r |
162ed594 | 59 | /**\r |
28a00297 | 60 | Check whether a handle is a valid EFI_HANDLE\r |
28a00297 | 61 | \r |
022c6d45 | 62 | @param UserHandle The handle to check\r |
28a00297 | 63 | \r |
022c6d45 | 64 | @retval EFI_INVALID_PARAMETER The handle is NULL or not a valid EFI_HANDLE.\r |
162ed594 | 65 | @retval EFI_SUCCESS The handle is valid EFI_HANDLE.\r |
28a00297 | 66 | \r |
162ed594 | 67 | **/\r |
68 | EFI_STATUS\r | |
69 | CoreValidateHandle (\r | |
70 | IN EFI_HANDLE UserHandle\r | |
71 | )\r | |
28a00297 | 72 | {\r |
73 | IHANDLE *Handle;\r | |
74 | \r | |
75 | Handle = (IHANDLE *)UserHandle;\r | |
76 | if (Handle == NULL) {\r | |
77 | return EFI_INVALID_PARAMETER;\r | |
78 | }\r | |
79 | if (Handle->Signature != EFI_HANDLE_SIGNATURE) {\r | |
80 | return EFI_INVALID_PARAMETER;\r | |
81 | }\r | |
82 | return EFI_SUCCESS;\r | |
83 | }\r | |
84 | \r | |
85 | \r | |
28a00297 | 86 | \r |
162ed594 | 87 | /**\r |
28a00297 | 88 | Finds the protocol entry for the requested protocol.\r |
28a00297 | 89 | The gProtocolDatabaseLock must be owned\r |
90 | \r | |
022c6d45 | 91 | @param Protocol The ID of the protocol\r |
92 | @param Create Create a new entry if not found\r | |
28a00297 | 93 | \r |
162ed594 | 94 | @return Protocol entry\r |
28a00297 | 95 | \r |
162ed594 | 96 | **/\r |
97 | PROTOCOL_ENTRY *\r | |
98 | CoreFindProtocolEntry (\r | |
99 | IN EFI_GUID *Protocol,\r | |
100 | IN BOOLEAN Create\r | |
101 | )\r | |
28a00297 | 102 | {\r |
103 | LIST_ENTRY *Link;\r | |
104 | PROTOCOL_ENTRY *Item;\r | |
105 | PROTOCOL_ENTRY *ProtEntry;\r | |
106 | \r | |
107 | ASSERT_LOCKED(&gProtocolDatabaseLock);\r | |
108 | \r | |
109 | //\r | |
110 | // Search the database for the matching GUID\r | |
111 | //\r | |
112 | \r | |
113 | ProtEntry = NULL;\r | |
022c6d45 | 114 | for (Link = mProtocolDatabase.ForwardLink;\r |
115 | Link != &mProtocolDatabase;\r | |
28a00297 | 116 | Link = Link->ForwardLink) {\r |
117 | \r | |
118 | Item = CR(Link, PROTOCOL_ENTRY, AllEntries, PROTOCOL_ENTRY_SIGNATURE);\r | |
119 | if (CompareGuid (&Item->ProtocolID, Protocol)) {\r | |
120 | \r | |
121 | //\r | |
122 | // This is the protocol entry\r | |
123 | //\r | |
124 | \r | |
125 | ProtEntry = Item;\r | |
126 | break;\r | |
127 | }\r | |
128 | }\r | |
129 | \r | |
130 | //\r | |
022c6d45 | 131 | // If the protocol entry was not found and Create is TRUE, then\r |
28a00297 | 132 | // allocate a new entry\r |
022c6d45 | 133 | //\r |
28a00297 | 134 | if ((ProtEntry == NULL) && Create) {\r |
9c4ac31c | 135 | ProtEntry = AllocatePool (sizeof(PROTOCOL_ENTRY));\r |
022c6d45 | 136 | \r |
28a00297 | 137 | if (ProtEntry != NULL) {\r |
138 | //\r | |
139 | // Initialize new protocol entry structure\r | |
140 | //\r | |
141 | ProtEntry->Signature = PROTOCOL_ENTRY_SIGNATURE;\r | |
e94a9ff7 | 142 | CopyGuid ((VOID *)&ProtEntry->ProtocolID, Protocol);\r |
28a00297 | 143 | InitializeListHead (&ProtEntry->Protocols);\r |
144 | InitializeListHead (&ProtEntry->Notify);\r | |
145 | \r | |
146 | //\r | |
147 | // Add it to protocol database\r | |
148 | //\r | |
149 | InsertTailList (&mProtocolDatabase, &ProtEntry->AllEntries);\r | |
150 | }\r | |
151 | }\r | |
152 | \r | |
153 | return ProtEntry;\r | |
154 | }\r | |
155 | \r | |
156 | \r | |
162ed594 | 157 | \r |
158 | /**\r | |
159 | Finds the protocol instance for the requested handle and protocol.\r | |
160 | Note: This function doesn't do parameters checking, it's caller's responsibility\r | |
161 | to pass in valid parameters.\r | |
162 | \r | |
022c6d45 | 163 | @param Handle The handle to search the protocol on\r |
164 | @param Protocol GUID of the protocol\r | |
165 | @param Interface The interface for the protocol being searched\r | |
162ed594 | 166 | \r |
167 | @return Protocol instance (NULL: Not found)\r | |
168 | \r | |
169 | **/\r | |
28a00297 | 170 | PROTOCOL_INTERFACE *\r |
171 | CoreFindProtocolInterface (\r | |
172 | IN IHANDLE *Handle,\r | |
173 | IN EFI_GUID *Protocol,\r | |
174 | IN VOID *Interface\r | |
175 | )\r | |
28a00297 | 176 | {\r |
177 | PROTOCOL_INTERFACE *Prot;\r | |
178 | PROTOCOL_ENTRY *ProtEntry;\r | |
179 | LIST_ENTRY *Link;\r | |
180 | \r | |
181 | ASSERT_LOCKED(&gProtocolDatabaseLock);\r | |
182 | Prot = NULL;\r | |
183 | \r | |
184 | //\r | |
185 | // Lookup the protocol entry for this protocol ID\r | |
186 | //\r | |
187 | \r | |
188 | ProtEntry = CoreFindProtocolEntry (Protocol, FALSE);\r | |
189 | if (ProtEntry != NULL) {\r | |
190 | \r | |
191 | //\r | |
192 | // Look at each protocol interface for any matches\r | |
193 | //\r | |
194 | for (Link = Handle->Protocols.ForwardLink; Link != &Handle->Protocols; Link=Link->ForwardLink) {\r | |
195 | \r | |
196 | //\r | |
197 | // If this protocol interface matches, remove it\r | |
198 | //\r | |
199 | Prot = CR(Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);\r | |
200 | if (Prot->Interface == Interface && Prot->Protocol == ProtEntry) {\r | |
201 | break;\r | |
202 | }\r | |
203 | \r | |
204 | Prot = NULL;\r | |
205 | }\r | |
206 | }\r | |
207 | \r | |
208 | return Prot;\r | |
209 | }\r | |
210 | \r | |
28a00297 | 211 | \r |
162ed594 | 212 | /**\r |
28a00297 | 213 | Removes an event from a register protocol notify list on a protocol.\r |
214 | \r | |
022c6d45 | 215 | @param Event The event to search for in the protocol\r |
216 | database.\r | |
28a00297 | 217 | \r |
162ed594 | 218 | @return EFI_SUCCESS if the event was found and removed.\r |
219 | @return EFI_NOT_FOUND if the event was not found in the protocl database.\r | |
28a00297 | 220 | \r |
162ed594 | 221 | **/\r |
162ed594 | 222 | EFI_STATUS\r |
223 | CoreUnregisterProtocolNotifyEvent (\r | |
224 | IN EFI_EVENT Event\r | |
225 | )\r | |
28a00297 | 226 | {\r |
227 | LIST_ENTRY *Link;\r | |
228 | PROTOCOL_ENTRY *ProtEntry;\r | |
229 | LIST_ENTRY *NotifyLink;\r | |
230 | PROTOCOL_NOTIFY *ProtNotify;\r | |
231 | \r | |
232 | CoreAcquireProtocolLock ();\r | |
233 | \r | |
022c6d45 | 234 | for ( Link = mProtocolDatabase.ForwardLink;\r |
235 | Link != &mProtocolDatabase;\r | |
28a00297 | 236 | Link = Link->ForwardLink) {\r |
237 | \r | |
238 | ProtEntry = CR(Link, PROTOCOL_ENTRY, AllEntries, PROTOCOL_ENTRY_SIGNATURE);\r | |
239 | \r | |
022c6d45 | 240 | for ( NotifyLink = ProtEntry->Notify.ForwardLink;\r |
241 | NotifyLink != &ProtEntry->Notify;\r | |
28a00297 | 242 | NotifyLink = NotifyLink->ForwardLink) {\r |
243 | \r | |
244 | ProtNotify = CR(NotifyLink, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE);\r | |
245 | \r | |
246 | if (ProtNotify->Event == Event) {\r | |
247 | RemoveEntryList(&ProtNotify->Link);\r | |
248 | CoreFreePool(ProtNotify);\r | |
249 | CoreReleaseProtocolLock ();\r | |
250 | return EFI_SUCCESS;\r | |
251 | }\r | |
252 | }\r | |
253 | }\r | |
254 | \r | |
255 | CoreReleaseProtocolLock ();\r | |
256 | return EFI_NOT_FOUND;\r | |
257 | }\r | |
258 | \r | |
259 | \r | |
28a00297 | 260 | \r |
162ed594 | 261 | /**\r |
28a00297 | 262 | Removes all the events in the protocol database that match Event.\r |
263 | \r | |
022c6d45 | 264 | @param Event The event to search for in the protocol\r |
265 | database.\r | |
28a00297 | 266 | \r |
162ed594 | 267 | @return EFI_SUCCESS when done searching the entire database.\r |
28a00297 | 268 | \r |
162ed594 | 269 | **/\r |
270 | EFI_STATUS\r | |
271 | CoreUnregisterProtocolNotify (\r | |
272 | IN EFI_EVENT Event\r | |
273 | )\r | |
28a00297 | 274 | {\r |
275 | EFI_STATUS Status;\r | |
276 | \r | |
277 | do {\r | |
278 | Status = CoreUnregisterProtocolNotifyEvent (Event);\r | |
279 | } while (!EFI_ERROR (Status));\r | |
280 | \r | |
281 | return EFI_SUCCESS;\r | |
282 | }\r | |
283 | \r | |
284 | \r | |
285 | \r | |
162ed594 | 286 | \r |
287 | /**\r | |
288 | Wrapper function to CoreInstallProtocolInterfaceNotify. This is the public API which\r | |
289 | Calls the private one which contains a BOOLEAN parameter for notifications\r | |
290 | \r | |
022c6d45 | 291 | @param UserHandle The handle to install the protocol handler on,\r |
292 | or NULL if a new handle is to be allocated\r | |
293 | @param Protocol The protocol to add to the handle\r | |
294 | @param InterfaceType Indicates whether Interface is supplied in\r | |
295 | native form.\r | |
296 | @param Interface The interface for the protocol being added\r | |
162ed594 | 297 | \r |
298 | @return Status code\r | |
299 | \r | |
300 | **/\r | |
28a00297 | 301 | EFI_STATUS\r |
302 | EFIAPI\r | |
303 | CoreInstallProtocolInterface (\r | |
304 | IN OUT EFI_HANDLE *UserHandle,\r | |
305 | IN EFI_GUID *Protocol,\r | |
306 | IN EFI_INTERFACE_TYPE InterfaceType,\r | |
307 | IN VOID *Interface\r | |
308 | )\r | |
28a00297 | 309 | {\r |
310 | return CoreInstallProtocolInterfaceNotify (\r | |
022c6d45 | 311 | UserHandle,\r |
312 | Protocol,\r | |
313 | InterfaceType,\r | |
314 | Interface,\r | |
28a00297 | 315 | TRUE\r |
316 | );\r | |
317 | }\r | |
318 | \r | |
162ed594 | 319 | \r |
320 | /**\r | |
321 | Installs a protocol interface into the boot services environment.\r | |
322 | \r | |
022c6d45 | 323 | @param UserHandle The handle to install the protocol handler on,\r |
324 | or NULL if a new handle is to be allocated\r | |
325 | @param Protocol The protocol to add to the handle\r | |
326 | @param InterfaceType Indicates whether Interface is supplied in\r | |
327 | native form.\r | |
328 | @param Interface The interface for the protocol being added\r | |
329 | @param Notify indicates whether notify the notification list\r | |
330 | for this protocol\r | |
331 | \r | |
332 | @retval EFI_INVALID_PARAMETER Invalid parameter\r | |
333 | @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate\r | |
162ed594 | 334 | @retval EFI_SUCCESS Protocol interface successfully installed\r |
335 | \r | |
336 | **/\r | |
28a00297 | 337 | EFI_STATUS\r |
338 | CoreInstallProtocolInterfaceNotify (\r | |
339 | IN OUT EFI_HANDLE *UserHandle,\r | |
340 | IN EFI_GUID *Protocol,\r | |
341 | IN EFI_INTERFACE_TYPE InterfaceType,\r | |
342 | IN VOID *Interface,\r | |
343 | IN BOOLEAN Notify\r | |
344 | )\r | |
28a00297 | 345 | {\r |
346 | PROTOCOL_INTERFACE *Prot;\r | |
347 | PROTOCOL_ENTRY *ProtEntry;\r | |
348 | IHANDLE *Handle;\r | |
349 | EFI_STATUS Status;\r | |
350 | VOID *ExistingInterface;\r | |
351 | \r | |
352 | //\r | |
353 | // returns EFI_INVALID_PARAMETER if InterfaceType is invalid.\r | |
354 | // Also added check for invalid UserHandle and Protocol pointers.\r | |
355 | //\r | |
356 | if (UserHandle == NULL || Protocol == NULL) {\r | |
357 | return EFI_INVALID_PARAMETER;\r | |
358 | }\r | |
359 | \r | |
360 | if (InterfaceType != EFI_NATIVE_INTERFACE) {\r | |
361 | return EFI_INVALID_PARAMETER;\r | |
362 | }\r | |
363 | \r | |
364 | //\r | |
365 | // Print debug message\r | |
366 | //\r | |
1439777e | 367 | DEBUG((DEBUG_LOAD | DEBUG_INFO, "InstallProtocolInterface: %g %p\n", Protocol, Interface));\r |
28a00297 | 368 | \r |
369 | Status = EFI_OUT_OF_RESOURCES;\r | |
370 | Prot = NULL;\r | |
371 | Handle = NULL;\r | |
372 | \r | |
4008328a | 373 | if (*UserHandle != NULL) {\r |
28a00297 | 374 | Status = CoreHandleProtocol (*UserHandle, Protocol, (VOID **)&ExistingInterface);\r |
375 | if (!EFI_ERROR (Status)) {\r | |
376 | return EFI_INVALID_PARAMETER;\r | |
377 | }\r | |
378 | }\r | |
379 | \r | |
380 | //\r | |
022c6d45 | 381 | // Lock the protocol database\r |
28a00297 | 382 | //\r |
383 | CoreAcquireProtocolLock ();\r | |
384 | \r | |
385 | //\r | |
386 | // Lookup the Protocol Entry for the requested protocol\r | |
387 | //\r | |
388 | ProtEntry = CoreFindProtocolEntry (Protocol, TRUE);\r | |
389 | if (ProtEntry == NULL) {\r | |
390 | goto Done;\r | |
391 | }\r | |
392 | \r | |
393 | //\r | |
394 | // Allocate a new protocol interface structure\r | |
395 | //\r | |
9c4ac31c | 396 | Prot = AllocateZeroPool (sizeof(PROTOCOL_INTERFACE));\r |
28a00297 | 397 | if (Prot == NULL) {\r |
398 | Status = EFI_OUT_OF_RESOURCES;\r | |
399 | goto Done;\r | |
400 | }\r | |
401 | \r | |
402 | //\r | |
403 | // If caller didn't supply a handle, allocate a new one\r | |
404 | //\r | |
405 | Handle = (IHANDLE *)*UserHandle;\r | |
406 | if (Handle == NULL) {\r | |
9c4ac31c | 407 | Handle = AllocateZeroPool (sizeof(IHANDLE));\r |
28a00297 | 408 | if (Handle == NULL) {\r |
409 | Status = EFI_OUT_OF_RESOURCES;\r | |
410 | goto Done;\r | |
411 | }\r | |
412 | \r | |
413 | //\r | |
414 | // Initialize new handler structure\r | |
415 | //\r | |
416 | Handle->Signature = EFI_HANDLE_SIGNATURE;\r | |
417 | InitializeListHead (&Handle->Protocols);\r | |
418 | \r | |
419 | //\r | |
420 | // Initialize the Key to show that the handle has been created/modified\r | |
421 | //\r | |
422 | gHandleDatabaseKey++;\r | |
423 | Handle->Key = gHandleDatabaseKey;\r | |
424 | \r | |
425 | //\r | |
426 | // Add this handle to the list global list of all handles\r | |
427 | // in the system\r | |
428 | //\r | |
429 | InsertTailList (&gHandleList, &Handle->AllHandles);\r | |
022c6d45 | 430 | }\r |
28a00297 | 431 | \r |
432 | Status = CoreValidateHandle (Handle);\r | |
433 | if (EFI_ERROR (Status)) {\r | |
434 | goto Done;\r | |
435 | }\r | |
436 | \r | |
437 | //\r | |
438 | // Each interface that is added must be unique\r | |
439 | //\r | |
440 | ASSERT (CoreFindProtocolInterface (Handle, Protocol, Interface) == NULL);\r | |
441 | \r | |
442 | //\r | |
443 | // Initialize the protocol interface structure\r | |
444 | //\r | |
445 | Prot->Signature = PROTOCOL_INTERFACE_SIGNATURE;\r | |
446 | Prot->Handle = Handle;\r | |
447 | Prot->Protocol = ProtEntry;\r | |
448 | Prot->Interface = Interface;\r | |
449 | \r | |
450 | //\r | |
451 | // Initalize OpenProtocol Data base\r | |
452 | //\r | |
453 | InitializeListHead (&Prot->OpenList);\r | |
454 | Prot->OpenListCount = 0;\r | |
455 | \r | |
456 | //\r | |
022c6d45 | 457 | // Add this protocol interface to the head of the supported\r |
28a00297 | 458 | // protocol list for this handle\r |
459 | //\r | |
460 | InsertHeadList (&Handle->Protocols, &Prot->Link);\r | |
461 | \r | |
462 | //\r | |
022c6d45 | 463 | // Add this protocol interface to the tail of the\r |
28a00297 | 464 | // protocol entry\r |
022c6d45 | 465 | //\r |
28a00297 | 466 | InsertTailList (&ProtEntry->Protocols, &Prot->ByProtocol);\r |
467 | \r | |
468 | //\r | |
022c6d45 | 469 | // Notify the notification list for this protocol\r |
28a00297 | 470 | //\r |
471 | if (Notify) {\r | |
472 | CoreNotifyProtocolEntry (ProtEntry);\r | |
473 | }\r | |
474 | Status = EFI_SUCCESS;\r | |
475 | \r | |
476 | Done:\r | |
477 | //\r | |
478 | // Done, unlock the database and return\r | |
479 | //\r | |
480 | CoreReleaseProtocolLock ();\r | |
481 | if (!EFI_ERROR (Status)) {\r | |
482 | //\r | |
483 | // Return the new handle back to the caller\r | |
484 | //\r | |
485 | *UserHandle = Handle;\r | |
486 | } else {\r | |
487 | //\r | |
488 | // There was an error, clean up\r | |
489 | //\r | |
490 | if (Prot != NULL) {\r | |
491 | CoreFreePool (Prot);\r | |
492 | }\r | |
493 | }\r | |
494 | \r | |
495 | return Status;\r | |
496 | }\r | |
497 | \r | |
498 | \r | |
499 | \r | |
28a00297 | 500 | \r |
162ed594 | 501 | /**\r |
28a00297 | 502 | Installs a list of protocol interface into the boot services environment.\r |
503 | This function calls InstallProtocolInterface() in a loop. If any error\r | |
162ed594 | 504 | occures all the protocols added by this function are removed. This is\r |
28a00297 | 505 | basically a lib function to save space.\r |
506 | \r | |
022c6d45 | 507 | @param Handle The handle to install the protocol handlers on,\r |
508 | or NULL if a new handle is to be allocated\r | |
509 | @param ... EFI_GUID followed by protocol instance. A NULL\r | |
510 | terminates the list. The pairs are the\r | |
511 | arguments to InstallProtocolInterface(). All the\r | |
512 | protocols are added to Handle.\r | |
28a00297 | 513 | \r |
022c6d45 | 514 | @retval EFI_INVALID_PARAMETER Handle is NULL.\r |
162ed594 | 515 | @retval EFI_SUCCESS Protocol interfaces successfully installed.\r |
28a00297 | 516 | \r |
162ed594 | 517 | **/\r |
518 | EFI_STATUS\r | |
519 | EFIAPI\r | |
520 | CoreInstallMultipleProtocolInterfaces (\r | |
521 | IN OUT EFI_HANDLE *Handle,\r | |
522 | ...\r | |
523 | )\r | |
28a00297 | 524 | {\r |
162ed594 | 525 | VA_LIST Args;\r |
28a00297 | 526 | EFI_STATUS Status;\r |
527 | EFI_GUID *Protocol;\r | |
528 | VOID *Interface;\r | |
529 | EFI_TPL OldTpl;\r | |
530 | UINTN Index;\r | |
531 | EFI_HANDLE OldHandle;\r | |
532 | EFI_HANDLE DeviceHandle;\r | |
533 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
022c6d45 | 534 | \r |
28a00297 | 535 | if (Handle == NULL) {\r |
536 | return EFI_INVALID_PARAMETER;\r | |
537 | }\r | |
022c6d45 | 538 | \r |
539 | //\r | |
540 | // Syncronize with notifcations.\r | |
28a00297 | 541 | //\r |
28a00297 | 542 | OldTpl = CoreRaiseTpl (TPL_NOTIFY);\r |
543 | OldHandle = *Handle;\r | |
544 | \r | |
545 | //\r | |
546 | // Check for duplicate device path and install the protocol interfaces\r | |
547 | //\r | |
162ed594 | 548 | VA_START (Args, Handle);\r |
28a00297 | 549 | for (Index = 0, Status = EFI_SUCCESS; !EFI_ERROR (Status); Index++) {\r |
550 | //\r | |
551 | // If protocol is NULL, then it's the end of the list\r | |
552 | //\r | |
162ed594 | 553 | Protocol = VA_ARG (Args, EFI_GUID *);\r |
28a00297 | 554 | if (Protocol == NULL) {\r |
555 | break;\r | |
556 | }\r | |
557 | \r | |
162ed594 | 558 | Interface = VA_ARG (Args, VOID *);\r |
28a00297 | 559 | \r |
560 | //\r | |
561 | // Make sure you are installing on top a device path that has already been added.\r | |
562 | //\r | |
563 | if (CompareGuid (Protocol, &gEfiDevicePathProtocolGuid)) {\r | |
564 | DeviceHandle = NULL;\r | |
565 | DevicePath = Interface;\r | |
566 | Status = CoreLocateDevicePath (&gEfiDevicePathProtocolGuid, &DevicePath, &DeviceHandle);\r | |
4008328a | 567 | if (!EFI_ERROR (Status) && (DeviceHandle != NULL) && IsDevicePathEnd(DevicePath)) {\r |
28a00297 | 568 | Status = EFI_ALREADY_STARTED;\r |
569 | continue;\r | |
570 | }\r | |
571 | }\r | |
022c6d45 | 572 | \r |
28a00297 | 573 | //\r |
574 | // Install it\r | |
575 | //\r | |
576 | Status = CoreInstallProtocolInterface (Handle, Protocol, EFI_NATIVE_INTERFACE, Interface);\r | |
577 | }\r | |
a70c0fd8 | 578 | VA_END (Args);\r |
022c6d45 | 579 | \r |
28a00297 | 580 | //\r |
581 | // If there was an error, remove all the interfaces that were installed without any errors\r | |
582 | //\r | |
583 | if (EFI_ERROR (Status)) {\r | |
584 | //\r | |
585 | // Reset the va_arg back to the first argument.\r | |
586 | //\r | |
162ed594 | 587 | VA_START (Args, Handle);\r |
28a00297 | 588 | for (; Index > 1; Index--) {\r |
162ed594 | 589 | Protocol = VA_ARG (Args, EFI_GUID *);\r |
590 | Interface = VA_ARG (Args, VOID *);\r | |
28a00297 | 591 | CoreUninstallProtocolInterface (*Handle, Protocol, Interface);\r |
022c6d45 | 592 | }\r |
a70c0fd8 | 593 | VA_END (Args);\r |
594 | \r | |
28a00297 | 595 | *Handle = OldHandle;\r |
596 | }\r | |
597 | \r | |
598 | //\r | |
599 | // Done\r | |
600 | //\r | |
601 | CoreRestoreTpl (OldTpl);\r | |
602 | return Status;\r | |
603 | }\r | |
604 | \r | |
28a00297 | 605 | \r |
162ed594 | 606 | /**\r |
28a00297 | 607 | Attempts to disconnect all drivers that are using the protocol interface being queried.\r |
608 | If failed, reconnect all drivers disconnected.\r | |
162ed594 | 609 | Note: This function doesn't do parameters checking, it's caller's responsibility\r |
610 | to pass in valid parameters.\r | |
28a00297 | 611 | \r |
022c6d45 | 612 | @param UserHandle The handle on which the protocol is installed\r |
613 | @param Prot The protocol to disconnect drivers from\r | |
28a00297 | 614 | \r |
022c6d45 | 615 | @retval EFI_SUCCESS Drivers using the protocol interface are all\r |
616 | disconnected\r | |
162ed594 | 617 | @retval EFI_ACCESS_DENIED Failed to disconnect one or all of the drivers\r |
28a00297 | 618 | \r |
162ed594 | 619 | **/\r |
620 | EFI_STATUS\r | |
621 | CoreDisconnectControllersUsingProtocolInterface (\r | |
622 | IN EFI_HANDLE UserHandle,\r | |
623 | IN PROTOCOL_INTERFACE *Prot\r | |
624 | )\r | |
28a00297 | 625 | {\r |
626 | EFI_STATUS Status;\r | |
627 | BOOLEAN ItemFound;\r | |
628 | LIST_ENTRY *Link;\r | |
629 | OPEN_PROTOCOL_DATA *OpenData;\r | |
630 | \r | |
631 | Status = EFI_SUCCESS;\r | |
022c6d45 | 632 | \r |
28a00297 | 633 | //\r |
634 | // Attempt to disconnect all drivers from this protocol interface\r | |
635 | //\r | |
636 | do {\r | |
637 | ItemFound = FALSE;\r | |
638 | for ( Link = Prot->OpenList.ForwardLink;\r | |
639 | (Link != &Prot->OpenList) && !ItemFound;\r | |
640 | Link = Link->ForwardLink ) {\r | |
641 | OpenData = CR (Link, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_SIGNATURE);\r | |
642 | if (OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) {\r | |
643 | ItemFound = TRUE;\r | |
644 | CoreReleaseProtocolLock ();\r | |
645 | Status = CoreDisconnectController (UserHandle, OpenData->AgentHandle, NULL);\r | |
646 | CoreAcquireProtocolLock ();\r | |
647 | if (EFI_ERROR (Status)) {\r | |
648 | ItemFound = FALSE;\r | |
649 | break;\r | |
650 | }\r | |
651 | }\r | |
652 | }\r | |
653 | } while (ItemFound);\r | |
654 | \r | |
655 | if (!EFI_ERROR (Status)) {\r | |
656 | //\r | |
657 | // Attempt to remove BY_HANDLE_PROTOOCL and GET_PROTOCOL and TEST_PROTOCOL Open List items\r | |
658 | //\r | |
659 | do {\r | |
660 | ItemFound = FALSE;\r | |
661 | for ( Link = Prot->OpenList.ForwardLink;\r | |
662 | (Link != &Prot->OpenList) && !ItemFound;\r | |
663 | Link = Link->ForwardLink ) {\r | |
664 | OpenData = CR (Link, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_SIGNATURE);\r | |
022c6d45 | 665 | if (OpenData->Attributes &\r |
28a00297 | 666 | (EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL | EFI_OPEN_PROTOCOL_GET_PROTOCOL | EFI_OPEN_PROTOCOL_TEST_PROTOCOL)) {\r |
667 | ItemFound = TRUE;\r | |
022c6d45 | 668 | RemoveEntryList (&OpenData->Link);\r |
28a00297 | 669 | Prot->OpenListCount--;\r |
670 | CoreFreePool (OpenData);\r | |
671 | }\r | |
672 | }\r | |
673 | } while (ItemFound);\r | |
674 | }\r | |
675 | \r | |
676 | //\r | |
677 | // If there are errors or still has open items in the list, then reconnect all the drivers and return an error\r | |
678 | //\r | |
679 | if (EFI_ERROR (Status) || (Prot->OpenListCount > 0)) {\r | |
680 | CoreReleaseProtocolLock ();\r | |
681 | CoreConnectController (UserHandle, NULL, NULL, TRUE);\r | |
682 | CoreAcquireProtocolLock ();\r | |
683 | Status = EFI_ACCESS_DENIED;\r | |
684 | }\r | |
685 | \r | |
686 | return Status;\r | |
687 | }\r | |
688 | \r | |
689 | \r | |
162ed594 | 690 | \r |
691 | /**\r | |
692 | Uninstalls all instances of a protocol:interfacer from a handle.\r | |
693 | If the last protocol interface is remove from the handle, the\r | |
694 | handle is freed.\r | |
695 | \r | |
022c6d45 | 696 | @param UserHandle The handle to remove the protocol handler from\r |
697 | @param Protocol The protocol, of protocol:interface, to remove\r | |
698 | @param Interface The interface, of protocol:interface, to remove\r | |
162ed594 | 699 | \r |
022c6d45 | 700 | @retval EFI_INVALID_PARAMETER Protocol is NULL.\r |
162ed594 | 701 | @retval EFI_SUCCESS Protocol interface successfully uninstalled.\r |
702 | \r | |
703 | **/\r | |
28a00297 | 704 | EFI_STATUS\r |
705 | EFIAPI\r | |
706 | CoreUninstallProtocolInterface (\r | |
707 | IN EFI_HANDLE UserHandle,\r | |
708 | IN EFI_GUID *Protocol,\r | |
709 | IN VOID *Interface\r | |
710 | )\r | |
28a00297 | 711 | {\r |
712 | EFI_STATUS Status;\r | |
713 | IHANDLE *Handle;\r | |
714 | PROTOCOL_INTERFACE *Prot;\r | |
715 | \r | |
716 | //\r | |
717 | // Check that Protocol is valid\r | |
718 | //\r | |
719 | if (Protocol == NULL) {\r | |
720 | return EFI_INVALID_PARAMETER;\r | |
721 | }\r | |
722 | \r | |
723 | //\r | |
724 | // Check that UserHandle is a valid handle\r | |
725 | //\r | |
726 | Status = CoreValidateHandle (UserHandle);\r | |
727 | if (EFI_ERROR (Status)) {\r | |
728 | return Status;\r | |
729 | }\r | |
730 | \r | |
731 | //\r | |
732 | // Lock the protocol database\r | |
733 | //\r | |
734 | CoreAcquireProtocolLock ();\r | |
735 | \r | |
736 | //\r | |
737 | // Check that Protocol exists on UserHandle, and Interface matches the interface in the database\r | |
738 | //\r | |
739 | Prot = CoreFindProtocolInterface (UserHandle, Protocol, Interface);\r | |
740 | if (Prot == NULL) {\r | |
741 | Status = EFI_NOT_FOUND;\r | |
742 | goto Done;\r | |
743 | }\r | |
744 | \r | |
745 | //\r | |
746 | // Attempt to disconnect all drivers that are using the protocol interface that is about to be removed\r | |
747 | //\r | |
748 | Status = CoreDisconnectControllersUsingProtocolInterface (\r | |
749 | UserHandle,\r | |
750 | Prot\r | |
751 | );\r | |
752 | if (EFI_ERROR (Status)) {\r | |
753 | //\r | |
754 | // One or more drivers refused to release, so return the error\r | |
755 | //\r | |
756 | goto Done;\r | |
757 | }\r | |
758 | \r | |
759 | //\r | |
760 | // Remove the protocol interface from the protocol\r | |
761 | //\r | |
762 | Status = EFI_NOT_FOUND;\r | |
763 | Handle = (IHANDLE *)UserHandle;\r | |
764 | Prot = CoreRemoveInterfaceFromProtocol (Handle, Protocol, Interface);\r | |
765 | \r | |
766 | if (Prot != NULL) {\r | |
767 | //\r | |
768 | // Update the Key to show that the handle has been created/modified\r | |
769 | //\r | |
770 | gHandleDatabaseKey++;\r | |
771 | Handle->Key = gHandleDatabaseKey;\r | |
022c6d45 | 772 | \r |
28a00297 | 773 | //\r |
774 | // Remove the protocol interface from the handle\r | |
775 | //\r | |
776 | RemoveEntryList (&Prot->Link);\r | |
777 | \r | |
778 | //\r | |
779 | // Free the memory\r | |
780 | //\r | |
781 | Prot->Signature = 0;\r | |
782 | CoreFreePool (Prot);\r | |
783 | Status = EFI_SUCCESS;\r | |
784 | }\r | |
785 | \r | |
786 | //\r | |
787 | // If there are no more handlers for the handle, free the handle\r | |
788 | //\r | |
789 | if (IsListEmpty (&Handle->Protocols)) {\r | |
790 | Handle->Signature = 0;\r | |
791 | RemoveEntryList (&Handle->AllHandles);\r | |
792 | CoreFreePool (Handle);\r | |
793 | }\r | |
794 | \r | |
022c6d45 | 795 | Done:\r |
28a00297 | 796 | //\r |
797 | // Done, unlock the database and return\r | |
798 | //\r | |
799 | CoreReleaseProtocolLock ();\r | |
800 | return Status;\r | |
801 | }\r | |
802 | \r | |
803 | \r | |
804 | \r | |
162ed594 | 805 | \r |
806 | /**\r | |
807 | Uninstalls a list of protocol interface in the boot services environment.\r | |
808 | This function calls UnisatllProtocolInterface() in a loop. This is\r | |
809 | basically a lib function to save space.\r | |
810 | \r | |
022c6d45 | 811 | @param Handle The handle to uninstall the protocol\r |
812 | @param ... EFI_GUID followed by protocol instance. A NULL\r | |
813 | terminates the list. The pairs are the\r | |
814 | arguments to UninstallProtocolInterface(). All\r | |
815 | the protocols are added to Handle.\r | |
162ed594 | 816 | \r |
817 | @return Status code\r | |
818 | \r | |
819 | **/\r | |
28a00297 | 820 | EFI_STATUS\r |
821 | EFIAPI\r | |
822 | CoreUninstallMultipleProtocolInterfaces (\r | |
823 | IN EFI_HANDLE Handle,\r | |
824 | ...\r | |
825 | )\r | |
28a00297 | 826 | {\r |
827 | EFI_STATUS Status;\r | |
162ed594 | 828 | VA_LIST Args;\r |
28a00297 | 829 | EFI_GUID *Protocol;\r |
830 | VOID *Interface;\r | |
831 | UINTN Index;\r | |
832 | \r | |
162ed594 | 833 | VA_START (Args, Handle);\r |
28a00297 | 834 | for (Index = 0, Status = EFI_SUCCESS; !EFI_ERROR (Status); Index++) {\r |
835 | //\r | |
836 | // If protocol is NULL, then it's the end of the list\r | |
837 | //\r | |
162ed594 | 838 | Protocol = VA_ARG (Args, EFI_GUID *);\r |
28a00297 | 839 | if (Protocol == NULL) {\r |
840 | break;\r | |
841 | }\r | |
842 | \r | |
162ed594 | 843 | Interface = VA_ARG (Args, VOID *);\r |
28a00297 | 844 | \r |
845 | //\r | |
846 | // Uninstall it\r | |
847 | //\r | |
848 | Status = CoreUninstallProtocolInterface (Handle, Protocol, Interface);\r | |
849 | }\r | |
a70c0fd8 | 850 | VA_END (Args);\r |
28a00297 | 851 | \r |
852 | //\r | |
853 | // If there was an error, add all the interfaces that were\r | |
854 | // uninstalled without any errors\r | |
855 | //\r | |
856 | if (EFI_ERROR (Status)) {\r | |
857 | //\r | |
858 | // Reset the va_arg back to the first argument.\r | |
859 | //\r | |
162ed594 | 860 | VA_START (Args, Handle);\r |
28a00297 | 861 | for (; Index > 1; Index--) {\r |
162ed594 | 862 | Protocol = VA_ARG(Args, EFI_GUID *);\r |
863 | Interface = VA_ARG(Args, VOID *);\r | |
28a00297 | 864 | CoreInstallProtocolInterface (&Handle, Protocol, EFI_NATIVE_INTERFACE, Interface);\r |
022c6d45 | 865 | }\r |
a70c0fd8 | 866 | VA_END (Args);\r |
28a00297 | 867 | }\r |
868 | \r | |
869 | return Status;\r | |
022c6d45 | 870 | }\r |
28a00297 | 871 | \r |
162ed594 | 872 | \r |
873 | /**\r | |
874 | Locate a certain GUID protocol interface in a Handle's protocols.\r | |
875 | \r | |
022c6d45 | 876 | @param UserHandle The handle to obtain the protocol interface on\r |
877 | @param Protocol The GUID of the protocol\r | |
162ed594 | 878 | \r |
879 | @return The requested protocol interface for the handle\r | |
880 | \r | |
881 | **/\r | |
28a00297 | 882 | PROTOCOL_INTERFACE *\r |
883 | CoreGetProtocolInterface (\r | |
884 | IN EFI_HANDLE UserHandle,\r | |
885 | IN EFI_GUID *Protocol\r | |
886 | )\r | |
28a00297 | 887 | {\r |
888 | EFI_STATUS Status;\r | |
889 | PROTOCOL_ENTRY *ProtEntry;\r | |
890 | PROTOCOL_INTERFACE *Prot;\r | |
891 | IHANDLE *Handle;\r | |
892 | LIST_ENTRY *Link;\r | |
893 | \r | |
894 | Status = CoreValidateHandle (UserHandle);\r | |
895 | if (EFI_ERROR (Status)) {\r | |
896 | return NULL;\r | |
897 | }\r | |
022c6d45 | 898 | \r |
28a00297 | 899 | Handle = (IHANDLE *)UserHandle;\r |
900 | \r | |
901 | //\r | |
902 | // Look at each protocol interface for a match\r | |
903 | //\r | |
904 | for (Link = Handle->Protocols.ForwardLink; Link != &Handle->Protocols; Link = Link->ForwardLink) {\r | |
905 | Prot = CR(Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);\r | |
906 | ProtEntry = Prot->Protocol;\r | |
907 | if (CompareGuid (&ProtEntry->ProtocolID, Protocol)) {\r | |
908 | return Prot;\r | |
909 | }\r | |
910 | }\r | |
911 | return NULL;\r | |
912 | }\r | |
913 | \r | |
914 | \r | |
162ed594 | 915 | \r |
916 | /**\r | |
917 | Queries a handle to determine if it supports a specified protocol.\r | |
918 | \r | |
022c6d45 | 919 | @param UserHandle The handle being queried.\r |
920 | @param Protocol The published unique identifier of the protocol.\r | |
921 | @param Interface Supplies the address where a pointer to the\r | |
922 | corresponding Protocol Interface is returned.\r | |
162ed594 | 923 | \r |
11074aab | 924 | @retval EFI_SUCCESS The interface information for the specified protocol was returned.\r |
925 | @retval EFI_UNSUPPORTED The device does not support the specified protocol.\r | |
926 | @retval EFI_INVALID_PARAMETER Handle is not a valid EFI_HANDLE..\r | |
927 | @retval EFI_INVALID_PARAMETER Protocol is NULL.\r | |
928 | @retval EFI_INVALID_PARAMETER Interface is NULL.\r | |
162ed594 | 929 | \r |
930 | **/\r | |
28a00297 | 931 | EFI_STATUS\r |
932 | EFIAPI\r | |
933 | CoreHandleProtocol (\r | |
934 | IN EFI_HANDLE UserHandle,\r | |
935 | IN EFI_GUID *Protocol,\r | |
936 | OUT VOID **Interface\r | |
937 | )\r | |
28a00297 | 938 | {\r |
939 | return CoreOpenProtocol (\r | |
022c6d45 | 940 | UserHandle,\r |
941 | Protocol,\r | |
942 | Interface,\r | |
943 | gDxeCoreImageHandle,\r | |
944 | NULL,\r | |
28a00297 | 945 | EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL\r |
946 | );\r | |
947 | }\r | |
948 | \r | |
949 | \r | |
162ed594 | 950 | \r |
951 | /**\r | |
952 | Locates the installed protocol handler for the handle, and\r | |
953 | invokes it to obtain the protocol interface. Usage information\r | |
954 | is registered in the protocol data base.\r | |
955 | \r | |
022c6d45 | 956 | @param UserHandle The handle to obtain the protocol interface on\r |
957 | @param Protocol The ID of the protocol\r | |
958 | @param Interface The location to return the protocol interface\r | |
959 | @param ImageHandle The handle of the Image that is opening the\r | |
960 | protocol interface specified by Protocol and\r | |
961 | Interface.\r | |
962 | @param ControllerHandle The controller handle that is requiring this\r | |
963 | interface.\r | |
964 | @param Attributes The open mode of the protocol interface\r | |
965 | specified by Handle and Protocol.\r | |
966 | \r | |
967 | @retval EFI_INVALID_PARAMETER Protocol is NULL.\r | |
162ed594 | 968 | @retval EFI_SUCCESS Get the protocol interface.\r |
969 | \r | |
970 | **/\r | |
28a00297 | 971 | EFI_STATUS\r |
972 | EFIAPI\r | |
973 | CoreOpenProtocol (\r | |
974 | IN EFI_HANDLE UserHandle,\r | |
975 | IN EFI_GUID *Protocol,\r | |
976 | OUT VOID **Interface OPTIONAL,\r | |
977 | IN EFI_HANDLE ImageHandle,\r | |
978 | IN EFI_HANDLE ControllerHandle,\r | |
979 | IN UINT32 Attributes\r | |
980 | )\r | |
28a00297 | 981 | {\r |
982 | EFI_STATUS Status;\r | |
983 | PROTOCOL_INTERFACE *Prot;\r | |
984 | LIST_ENTRY *Link;\r | |
985 | OPEN_PROTOCOL_DATA *OpenData;\r | |
986 | BOOLEAN ByDriver;\r | |
987 | BOOLEAN Exclusive;\r | |
988 | BOOLEAN Disconnect;\r | |
989 | BOOLEAN ExactMatch;\r | |
990 | \r | |
991 | //\r | |
992 | // Check for invalid Protocol\r | |
993 | //\r | |
994 | if (Protocol == NULL) {\r | |
995 | return EFI_INVALID_PARAMETER;\r | |
996 | }\r | |
997 | \r | |
998 | //\r | |
999 | // Check for invalid Interface\r | |
1000 | //\r | |
1001 | if (Attributes != EFI_OPEN_PROTOCOL_TEST_PROTOCOL) {\r | |
1002 | if (Interface == NULL) {\r | |
1003 | return EFI_INVALID_PARAMETER;\r | |
1004 | } else {\r | |
1005 | *Interface = NULL;\r | |
1006 | }\r | |
1007 | }\r | |
022c6d45 | 1008 | \r |
28a00297 | 1009 | //\r |
1010 | // Check for invalid UserHandle\r | |
1011 | //\r | |
1012 | Status = CoreValidateHandle (UserHandle);\r | |
1013 | if (EFI_ERROR (Status)) {\r | |
1014 | return Status;\r | |
1015 | }\r | |
1016 | \r | |
1017 | //\r | |
1018 | // Check for invalid Attributes\r | |
1019 | //\r | |
1020 | switch (Attributes) {\r | |
1021 | case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER :\r | |
1022 | Status = CoreValidateHandle (ImageHandle);\r | |
1023 | if (EFI_ERROR (Status)) {\r | |
1024 | return Status;\r | |
1025 | }\r | |
1026 | Status = CoreValidateHandle (ControllerHandle);\r | |
1027 | if (EFI_ERROR (Status)) {\r | |
1028 | return Status;\r | |
1029 | }\r | |
1030 | if (UserHandle == ControllerHandle) {\r | |
1031 | return EFI_INVALID_PARAMETER;\r | |
1032 | }\r | |
1033 | break;\r | |
1034 | case EFI_OPEN_PROTOCOL_BY_DRIVER :\r | |
1035 | case EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE :\r | |
1036 | Status = CoreValidateHandle (ImageHandle);\r | |
1037 | if (EFI_ERROR (Status)) {\r | |
1038 | return Status;\r | |
1039 | }\r | |
1040 | Status = CoreValidateHandle (ControllerHandle);\r | |
1041 | if (EFI_ERROR (Status)) {\r | |
1042 | return Status;\r | |
1043 | }\r | |
1044 | break;\r | |
1045 | case EFI_OPEN_PROTOCOL_EXCLUSIVE :\r | |
1046 | Status = CoreValidateHandle (ImageHandle);\r | |
1047 | if (EFI_ERROR (Status)) {\r | |
1048 | return Status;\r | |
1049 | }\r | |
1050 | break;\r | |
1051 | case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL :\r | |
1052 | case EFI_OPEN_PROTOCOL_GET_PROTOCOL :\r | |
1053 | case EFI_OPEN_PROTOCOL_TEST_PROTOCOL :\r | |
1054 | break;\r | |
1055 | default:\r | |
1056 | return EFI_INVALID_PARAMETER;\r | |
1057 | }\r | |
1058 | \r | |
1059 | //\r | |
1060 | // Lock the protocol database\r | |
1061 | //\r | |
1062 | CoreAcquireProtocolLock ();\r | |
1063 | \r | |
1064 | //\r | |
1065 | // Look at each protocol interface for a match\r | |
1066 | //\r | |
1067 | Prot = CoreGetProtocolInterface (UserHandle, Protocol);\r | |
1068 | if (Prot == NULL) {\r | |
1069 | Status = EFI_UNSUPPORTED;\r | |
1070 | goto Done;\r | |
1071 | }\r | |
1072 | \r | |
1073 | //\r | |
1074 | // This is the protocol interface entry for this protocol\r | |
022c6d45 | 1075 | //\r |
28a00297 | 1076 | if (Attributes != EFI_OPEN_PROTOCOL_TEST_PROTOCOL) {\r |
1077 | *Interface = Prot->Interface;\r | |
1078 | }\r | |
1079 | Status = EFI_SUCCESS;\r | |
1080 | \r | |
1081 | ByDriver = FALSE;\r | |
1082 | Exclusive = FALSE;\r | |
1083 | for ( Link = Prot->OpenList.ForwardLink; Link != &Prot->OpenList; Link = Link->ForwardLink) {\r | |
1084 | OpenData = CR (Link, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_SIGNATURE);\r | |
022c6d45 | 1085 | ExactMatch = (BOOLEAN)((OpenData->AgentHandle == ImageHandle) &&\r |
28a00297 | 1086 | (OpenData->Attributes == Attributes) &&\r |
1087 | (OpenData->ControllerHandle == ControllerHandle));\r | |
1088 | if (OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) {\r | |
1089 | ByDriver = TRUE;\r | |
1090 | if (ExactMatch) {\r | |
1091 | Status = EFI_ALREADY_STARTED;\r | |
1092 | goto Done;\r | |
1093 | }\r | |
1094 | }\r | |
1095 | if (OpenData->Attributes & EFI_OPEN_PROTOCOL_EXCLUSIVE) {\r | |
1096 | Exclusive = TRUE;\r | |
1097 | } else if (ExactMatch) {\r | |
1098 | OpenData->OpenCount++;\r | |
1099 | Status = EFI_SUCCESS;\r | |
1100 | goto Done;\r | |
1101 | }\r | |
1102 | }\r | |
1103 | \r | |
1104 | //\r | |
1105 | // ByDriver TRUE -> A driver is managing (UserHandle, Protocol)\r | |
1106 | // ByDriver FALSE -> There are no drivers managing (UserHandle, Protocol)\r | |
1107 | // Exclusive TRUE -> Something has exclusive access to (UserHandle, Protocol)\r | |
1108 | // Exclusive FALSE -> Nothing has exclusive access to (UserHandle, Protocol)\r | |
1109 | //\r | |
1110 | \r | |
1111 | switch (Attributes) {\r | |
1112 | case EFI_OPEN_PROTOCOL_BY_DRIVER :\r | |
1113 | if (Exclusive || ByDriver) {\r | |
1114 | Status = EFI_ACCESS_DENIED;\r | |
1115 | goto Done;\r | |
1116 | }\r | |
1117 | break;\r | |
1118 | case EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE :\r | |
1119 | case EFI_OPEN_PROTOCOL_EXCLUSIVE :\r | |
1120 | if (Exclusive) {\r | |
1121 | Status = EFI_ACCESS_DENIED;\r | |
1122 | goto Done;\r | |
1123 | }\r | |
1124 | if (ByDriver) {\r | |
1125 | do {\r | |
1126 | Disconnect = FALSE;\r | |
1127 | for ( Link = Prot->OpenList.ForwardLink; (Link != &Prot->OpenList) && (!Disconnect); Link = Link->ForwardLink) {\r | |
1128 | OpenData = CR (Link, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_SIGNATURE);\r | |
1129 | if (OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) {\r | |
1130 | Disconnect = TRUE;\r | |
1131 | CoreReleaseProtocolLock ();\r | |
1132 | Status = CoreDisconnectController (UserHandle, OpenData->AgentHandle, NULL);\r | |
1133 | CoreAcquireProtocolLock ();\r | |
1134 | if (EFI_ERROR (Status)) {\r | |
1135 | Status = EFI_ACCESS_DENIED;\r | |
1136 | goto Done;\r | |
1137 | }\r | |
1138 | }\r | |
1139 | }\r | |
1140 | } while (Disconnect);\r | |
022c6d45 | 1141 | }\r |
28a00297 | 1142 | break;\r |
1143 | case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER :\r | |
1144 | case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL :\r | |
1145 | case EFI_OPEN_PROTOCOL_GET_PROTOCOL :\r | |
1146 | case EFI_OPEN_PROTOCOL_TEST_PROTOCOL :\r | |
1147 | break;\r | |
1148 | }\r | |
1149 | \r | |
1150 | if (ImageHandle == NULL) {\r | |
1151 | Status = EFI_SUCCESS;\r | |
1152 | goto Done;\r | |
1153 | }\r | |
1154 | //\r | |
1155 | // Create new entry\r | |
1156 | //\r | |
9c4ac31c | 1157 | OpenData = AllocatePool (sizeof(OPEN_PROTOCOL_DATA));\r |
28a00297 | 1158 | if (OpenData == NULL) {\r |
1159 | Status = EFI_OUT_OF_RESOURCES;\r | |
1160 | } else {\r | |
1161 | OpenData->Signature = OPEN_PROTOCOL_DATA_SIGNATURE;\r | |
1162 | OpenData->AgentHandle = ImageHandle;\r | |
1163 | OpenData->ControllerHandle = ControllerHandle;\r | |
1164 | OpenData->Attributes = Attributes;\r | |
1165 | OpenData->OpenCount = 1;\r | |
1166 | InsertTailList (&Prot->OpenList, &OpenData->Link);\r | |
1167 | Prot->OpenListCount++;\r | |
1168 | Status = EFI_SUCCESS;\r | |
1169 | }\r | |
1170 | \r | |
1171 | Done:\r | |
1172 | //\r | |
1173 | // Done. Release the database lock are return\r | |
1174 | //\r | |
1175 | CoreReleaseProtocolLock ();\r | |
1176 | return Status;\r | |
1177 | }\r | |
1178 | \r | |
1179 | \r | |
162ed594 | 1180 | \r |
1181 | /**\r | |
1182 | Closes a protocol on a handle that was opened using OpenProtocol().\r | |
1183 | \r | |
022c6d45 | 1184 | @param UserHandle The handle for the protocol interface that was\r |
1185 | previously opened with OpenProtocol(), and is\r | |
1186 | now being closed.\r | |
1187 | @param Protocol The published unique identifier of the protocol.\r | |
1188 | It is the caller's responsibility to pass in a\r | |
1189 | valid GUID.\r | |
1190 | @param AgentHandle The handle of the agent that is closing the\r | |
1191 | protocol interface.\r | |
1192 | @param ControllerHandle If the agent that opened a protocol is a driver\r | |
1193 | that follows the EFI Driver Model, then this\r | |
1194 | parameter is the controller handle that required\r | |
1195 | the protocol interface. If the agent does not\r | |
1196 | follow the EFI Driver Model, then this parameter\r | |
1197 | is optional and may be NULL.\r | |
1198 | \r | |
1199 | @retval EFI_SUCCESS The protocol instance was closed.\r | |
1200 | @retval EFI_INVALID_PARAMETER Handle, AgentHandle or ControllerHandle is not a\r | |
1201 | valid EFI_HANDLE.\r | |
1202 | @retval EFI_NOT_FOUND Can not find the specified protocol or\r | |
162ed594 | 1203 | AgentHandle.\r |
1204 | \r | |
1205 | **/\r | |
28a00297 | 1206 | EFI_STATUS\r |
1207 | EFIAPI\r | |
1208 | CoreCloseProtocol (\r | |
1209 | IN EFI_HANDLE UserHandle,\r | |
1210 | IN EFI_GUID *Protocol,\r | |
1211 | IN EFI_HANDLE AgentHandle,\r | |
022c6d45 | 1212 | IN EFI_HANDLE ControllerHandle\r |
28a00297 | 1213 | )\r |
28a00297 | 1214 | {\r |
1215 | EFI_STATUS Status;\r | |
1216 | PROTOCOL_INTERFACE *ProtocolInterface;\r | |
1217 | LIST_ENTRY *Link;\r | |
1218 | OPEN_PROTOCOL_DATA *OpenData;\r | |
1219 | \r | |
1220 | //\r | |
1221 | // Check for invalid parameters\r | |
1222 | //\r | |
1223 | Status = CoreValidateHandle (UserHandle);\r | |
1224 | if (EFI_ERROR (Status)) {\r | |
1225 | return Status;\r | |
1226 | }\r | |
1227 | Status = CoreValidateHandle (AgentHandle);\r | |
1228 | if (EFI_ERROR (Status)) {\r | |
1229 | return Status;\r | |
1230 | }\r | |
4008328a | 1231 | if (ControllerHandle != NULL) {\r |
28a00297 | 1232 | Status = CoreValidateHandle (ControllerHandle);\r |
1233 | if (EFI_ERROR (Status)) {\r | |
1234 | return Status;\r | |
1235 | }\r | |
1236 | }\r | |
1237 | if (Protocol == NULL) {\r | |
1238 | return EFI_INVALID_PARAMETER;\r | |
1239 | }\r | |
1240 | \r | |
1241 | //\r | |
1242 | // Lock the protocol database\r | |
1243 | //\r | |
1244 | CoreAcquireProtocolLock ();\r | |
1245 | \r | |
1246 | //\r | |
1247 | // Look at each protocol interface for a match\r | |
1248 | //\r | |
1249 | Status = EFI_NOT_FOUND;\r | |
1250 | ProtocolInterface = CoreGetProtocolInterface (UserHandle, Protocol);\r | |
1251 | if (ProtocolInterface == NULL) {\r | |
1252 | goto Done;\r | |
1253 | }\r | |
1254 | \r | |
1255 | //\r | |
1256 | // Walk the Open data base looking for AgentHandle\r | |
1257 | //\r | |
1258 | Link = ProtocolInterface->OpenList.ForwardLink;\r | |
1259 | while (Link != &ProtocolInterface->OpenList) {\r | |
1260 | OpenData = CR (Link, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_SIGNATURE);\r | |
1261 | Link = Link->ForwardLink;\r | |
1262 | if ((OpenData->AgentHandle == AgentHandle) && (OpenData->ControllerHandle == ControllerHandle)) {\r | |
022c6d45 | 1263 | RemoveEntryList (&OpenData->Link);\r |
28a00297 | 1264 | ProtocolInterface->OpenListCount--;\r |
1265 | CoreFreePool (OpenData);\r | |
1266 | Status = EFI_SUCCESS;\r | |
1267 | }\r | |
1268 | }\r | |
1269 | \r | |
1270 | Done:\r | |
1271 | //\r | |
1272 | // Done. Release the database lock and return.\r | |
1273 | //\r | |
1274 | CoreReleaseProtocolLock ();\r | |
1275 | return Status;\r | |
1276 | }\r | |
1277 | \r | |
1278 | \r | |
1279 | \r | |
162ed594 | 1280 | \r |
1281 | /**\r | |
1282 | Return information about Opened protocols in the system\r | |
1283 | \r | |
022c6d45 | 1284 | @param UserHandle The handle to close the protocol interface on\r |
1285 | @param Protocol The ID of the protocol\r | |
11074aab | 1286 | @param EntryBuffer A pointer to a buffer of open protocol information in the\r |
1287 | form of EFI_OPEN_PROTOCOL_INFORMATION_ENTRY structures.\r | |
162ed594 | 1288 | @param EntryCount Number of EntryBuffer entries\r |
1289 | \r | |
11074aab | 1290 | @retval EFI_SUCCESS The open protocol information was returned in EntryBuffer, \r |
1291 | and the number of entries was returned EntryCount.\r | |
1292 | @retval EFI_NOT_FOUND Handle does not support the protocol specified by Protocol.\r | |
1293 | @retval EFI_OUT_OF_RESOURCES There are not enough resources available to allocate EntryBuffer.\r | |
1294 | \r | |
162ed594 | 1295 | **/\r |
28a00297 | 1296 | EFI_STATUS\r |
1297 | EFIAPI\r | |
1298 | CoreOpenProtocolInformation (\r | |
1299 | IN EFI_HANDLE UserHandle,\r | |
1300 | IN EFI_GUID *Protocol,\r | |
1301 | OUT EFI_OPEN_PROTOCOL_INFORMATION_ENTRY **EntryBuffer,\r | |
1302 | OUT UINTN *EntryCount\r | |
1303 | )\r | |
28a00297 | 1304 | {\r |
1305 | EFI_STATUS Status;\r | |
1306 | PROTOCOL_INTERFACE *ProtocolInterface;\r | |
1307 | LIST_ENTRY *Link;\r | |
1308 | OPEN_PROTOCOL_DATA *OpenData;\r | |
1309 | EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *Buffer;\r | |
1310 | UINTN Count;\r | |
1311 | UINTN Size;\r | |
1312 | \r | |
1313 | *EntryBuffer = NULL;\r | |
1314 | *EntryCount = 0;\r | |
1315 | \r | |
1316 | //\r | |
1317 | // Lock the protocol database\r | |
1318 | //\r | |
1319 | CoreAcquireProtocolLock ();\r | |
1320 | \r | |
1321 | //\r | |
1322 | // Look at each protocol interface for a match\r | |
1323 | //\r | |
1324 | Status = EFI_NOT_FOUND;\r | |
1325 | ProtocolInterface = CoreGetProtocolInterface (UserHandle, Protocol);\r | |
1326 | if (ProtocolInterface == NULL) {\r | |
1327 | goto Done;\r | |
1328 | }\r | |
1329 | \r | |
1330 | //\r | |
1331 | // Count the number of Open Entries\r | |
1332 | //\r | |
022c6d45 | 1333 | for ( Link = ProtocolInterface->OpenList.ForwardLink, Count = 0;\r |
28a00297 | 1334 | (Link != &ProtocolInterface->OpenList) ;\r |
1335 | Link = Link->ForwardLink ) {\r | |
1336 | Count++;\r | |
022c6d45 | 1337 | }\r |
28a00297 | 1338 | \r |
1339 | ASSERT (Count == ProtocolInterface->OpenListCount);\r | |
1340 | \r | |
1341 | if (Count == 0) {\r | |
1342 | Size = sizeof(EFI_OPEN_PROTOCOL_INFORMATION_ENTRY);\r | |
1343 | } else {\r | |
1344 | Size = Count * sizeof(EFI_OPEN_PROTOCOL_INFORMATION_ENTRY);\r | |
1345 | }\r | |
1346 | \r | |
9c4ac31c | 1347 | Buffer = AllocatePool (Size);\r |
28a00297 | 1348 | if (Buffer == NULL) {\r |
1349 | Status = EFI_OUT_OF_RESOURCES;\r | |
1350 | goto Done;\r | |
1351 | }\r | |
1352 | \r | |
1353 | Status = EFI_SUCCESS;\r | |
022c6d45 | 1354 | for ( Link = ProtocolInterface->OpenList.ForwardLink, Count = 0;\r |
28a00297 | 1355 | (Link != &ProtocolInterface->OpenList);\r |
1356 | Link = Link->ForwardLink, Count++ ) {\r | |
1357 | OpenData = CR (Link, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_SIGNATURE);\r | |
1358 | \r | |
1359 | Buffer[Count].AgentHandle = OpenData->AgentHandle;\r | |
1360 | Buffer[Count].ControllerHandle = OpenData->ControllerHandle;\r | |
1361 | Buffer[Count].Attributes = OpenData->Attributes;\r | |
1362 | Buffer[Count].OpenCount = OpenData->OpenCount;\r | |
022c6d45 | 1363 | }\r |
28a00297 | 1364 | \r |
1365 | *EntryBuffer = Buffer;\r | |
1366 | *EntryCount = Count;\r | |
022c6d45 | 1367 | \r |
28a00297 | 1368 | Done:\r |
1369 | //\r | |
1439777e | 1370 | // Done. Release the database lock.\r |
28a00297 | 1371 | //\r |
1372 | CoreReleaseProtocolLock ();\r | |
1373 | return Status;\r | |
1374 | }\r | |
1375 | \r | |
1376 | \r | |
1377 | \r | |
162ed594 | 1378 | \r |
1379 | /**\r | |
1380 | Retrieves the list of protocol interface GUIDs that are installed on a handle in a buffer allocated\r | |
1381 | from pool.\r | |
1382 | \r | |
022c6d45 | 1383 | @param UserHandle The handle from which to retrieve the list of\r |
1384 | protocol interface GUIDs.\r | |
1385 | @param ProtocolBuffer A pointer to the list of protocol interface GUID\r | |
1386 | pointers that are installed on Handle.\r | |
1387 | @param ProtocolBufferCount A pointer to the number of GUID pointers present\r | |
1388 | in ProtocolBuffer.\r | |
1389 | \r | |
1390 | @retval EFI_SUCCESS The list of protocol interface GUIDs installed\r | |
1391 | on Handle was returned in ProtocolBuffer. The\r | |
1392 | number of protocol interface GUIDs was returned\r | |
1393 | in ProtocolBufferCount.\r | |
1394 | @retval EFI_INVALID_PARAMETER Handle is NULL.\r | |
1395 | @retval EFI_INVALID_PARAMETER Handle is not a valid EFI_HANDLE.\r | |
1396 | @retval EFI_INVALID_PARAMETER ProtocolBuffer is NULL.\r | |
1397 | @retval EFI_INVALID_PARAMETER ProtocolBufferCount is NULL.\r | |
1398 | @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the\r | |
162ed594 | 1399 | results.\r |
1400 | \r | |
1401 | **/\r | |
28a00297 | 1402 | EFI_STATUS\r |
1403 | EFIAPI\r | |
1404 | CoreProtocolsPerHandle (\r | |
1405 | IN EFI_HANDLE UserHandle,\r | |
1406 | OUT EFI_GUID ***ProtocolBuffer,\r | |
1407 | OUT UINTN *ProtocolBufferCount\r | |
1408 | )\r | |
28a00297 | 1409 | {\r |
1410 | EFI_STATUS Status;\r | |
1411 | IHANDLE *Handle;\r | |
1412 | PROTOCOL_INTERFACE *Prot;\r | |
1413 | LIST_ENTRY *Link;\r | |
1414 | UINTN ProtocolCount;\r | |
1415 | EFI_GUID **Buffer;\r | |
1416 | \r | |
1417 | Status = CoreValidateHandle (UserHandle);\r | |
1418 | if (EFI_ERROR (Status)) {\r | |
1419 | return Status;\r | |
1420 | }\r | |
1421 | \r | |
1422 | Handle = (IHANDLE *)UserHandle;\r | |
1423 | \r | |
1424 | if (ProtocolBuffer == NULL) {\r | |
1425 | return EFI_INVALID_PARAMETER;\r | |
1426 | }\r | |
1427 | \r | |
1428 | if (ProtocolBufferCount == NULL) {\r | |
1429 | return EFI_INVALID_PARAMETER;\r | |
1430 | }\r | |
1431 | \r | |
1432 | *ProtocolBufferCount = 0;\r | |
1433 | \r | |
1434 | ProtocolCount = 0;\r | |
1435 | \r | |
1436 | CoreAcquireProtocolLock ();\r | |
022c6d45 | 1437 | \r |
28a00297 | 1438 | for (Link = Handle->Protocols.ForwardLink; Link != &Handle->Protocols; Link = Link->ForwardLink) {\r |
1439 | ProtocolCount++;\r | |
1440 | }\r | |
1441 | \r | |
1442 | //\r | |
1443 | // If there are no protocol interfaces installed on Handle, then Handle is not a valid EFI_HANDLE\r | |
1444 | //\r | |
1445 | if (ProtocolCount == 0) {\r | |
1446 | Status = EFI_INVALID_PARAMETER;\r | |
1447 | goto Done;\r | |
1448 | }\r | |
1449 | \r | |
9c4ac31c | 1450 | Buffer = AllocatePool (sizeof (EFI_GUID *) * ProtocolCount);\r |
28a00297 | 1451 | if (Buffer == NULL) {\r |
1452 | Status = EFI_OUT_OF_RESOURCES;\r | |
1453 | goto Done;\r | |
1454 | }\r | |
1455 | \r | |
1456 | *ProtocolBuffer = Buffer;\r | |
1457 | *ProtocolBufferCount = ProtocolCount;\r | |
1458 | \r | |
1459 | for ( Link = Handle->Protocols.ForwardLink, ProtocolCount = 0;\r | |
022c6d45 | 1460 | Link != &Handle->Protocols;\r |
28a00297 | 1461 | Link = Link->ForwardLink, ProtocolCount++) {\r |
1462 | Prot = CR(Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);\r | |
1463 | Buffer[ProtocolCount] = &(Prot->Protocol->ProtocolID);\r | |
1464 | }\r | |
1465 | Status = EFI_SUCCESS;\r | |
1466 | \r | |
1467 | Done:\r | |
1468 | CoreReleaseProtocolLock ();\r | |
1469 | return Status;\r | |
1470 | }\r | |
1471 | \r | |
1472 | \r | |
28a00297 | 1473 | \r |
162ed594 | 1474 | /**\r |
28a00297 | 1475 | return handle database key.\r |
1476 | \r | |
28a00297 | 1477 | \r |
162ed594 | 1478 | @return Handle database key.\r |
1479 | \r | |
1480 | **/\r | |
1481 | UINT64\r | |
1482 | CoreGetHandleDatabaseKey (\r | |
1483 | VOID\r | |
1484 | )\r | |
28a00297 | 1485 | {\r |
1486 | return gHandleDatabaseKey;\r | |
1487 | }\r | |
1488 | \r | |
1489 | \r | |
28a00297 | 1490 | \r |
162ed594 | 1491 | /**\r |
28a00297 | 1492 | Go connect any handles that were created or modified while a image executed.\r |
1493 | \r | |
022c6d45 | 1494 | @param Key The Key to show that the handle has been\r |
162ed594 | 1495 | created/modified\r |
28a00297 | 1496 | \r |
162ed594 | 1497 | **/\r |
1498 | VOID\r | |
1499 | CoreConnectHandlesByKey (\r | |
1500 | UINT64 Key\r | |
1501 | )\r | |
28a00297 | 1502 | {\r |
1503 | UINTN Count;\r | |
1504 | LIST_ENTRY *Link;\r | |
1505 | EFI_HANDLE *HandleBuffer;\r | |
1506 | IHANDLE *Handle;\r | |
1507 | UINTN Index;\r | |
1508 | \r | |
1509 | //\r | |
1510 | // Lock the protocol database\r | |
1511 | //\r | |
1512 | CoreAcquireProtocolLock ();\r | |
1513 | \r | |
1514 | for (Link = gHandleList.ForwardLink, Count = 0; Link != &gHandleList; Link = Link->ForwardLink) {\r | |
1515 | Handle = CR (Link, IHANDLE, AllHandles, EFI_HANDLE_SIGNATURE);\r | |
1516 | if (Handle->Key > Key) {\r | |
1517 | Count++;\r | |
1518 | }\r | |
1519 | }\r | |
1520 | \r | |
9c4ac31c | 1521 | HandleBuffer = AllocatePool (Count * sizeof (EFI_HANDLE));\r |
28a00297 | 1522 | if (HandleBuffer == NULL) {\r |
1523 | CoreReleaseProtocolLock ();\r | |
1524 | return;\r | |
1525 | }\r | |
022c6d45 | 1526 | \r |
28a00297 | 1527 | for (Link = gHandleList.ForwardLink, Count = 0; Link != &gHandleList; Link = Link->ForwardLink) {\r |
1528 | Handle = CR (Link, IHANDLE, AllHandles, EFI_HANDLE_SIGNATURE);\r | |
1529 | if (Handle->Key > Key) {\r | |
1530 | HandleBuffer[Count++] = Handle;\r | |
1531 | }\r | |
1532 | }\r | |
1533 | \r | |
1534 | //\r | |
1535 | // Unlock the protocol database\r | |
1536 | //\r | |
1537 | CoreReleaseProtocolLock ();\r | |
1538 | \r | |
1539 | //\r | |
1540 | // Connect all handles whose Key value is greater than Key\r | |
1541 | //\r | |
1542 | for (Index = 0; Index < Count; Index++) {\r | |
1543 | CoreConnectController (HandleBuffer[Index], NULL, NULL, TRUE);\r | |
1544 | }\r | |
022c6d45 | 1545 | \r |
28a00297 | 1546 | CoreFreePool(HandleBuffer);\r |
1547 | }\r |