]>
Commit | Line | Data |
---|---|---|
3eb9473e | 1 | /*++\r |
2 | \r | |
4ea9375a HT |
3 | Copyright (c) 2004, Intel Corporation. All rights reserved.<BR>\r |
4 | This program and the accompanying materials \r | |
3eb9473e | 5 | are licensed and made available under the terms and conditions of the BSD License \r |
6 | which accompanies this distribution. The full text of the license may be found at \r | |
7 | http://opensource.org/licenses/bsd-license.php \r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
11 | \r | |
12 | Module Name:\r | |
13 | \r | |
14 | Handle.c\r | |
15 | \r | |
16 | Abstract:\r | |
17 | \r | |
18 | Support for Handle lib fucntions.\r | |
19 | \r | |
20 | --*/\r | |
21 | \r | |
22 | #include "Tiano.h"\r | |
23 | #include "EfiDriverLib.h"\r | |
24 | \r | |
25 | EFI_STATUS\r | |
26 | EfiLibLocateHandleProtocolByProtocols (\r | |
27 | IN OUT EFI_HANDLE * Handle, OPTIONAL\r | |
28 | OUT VOID **Interface, OPTIONAL\r | |
29 | ...\r | |
30 | )\r | |
31 | /*++\r | |
32 | Routine Description:\r | |
33 | \r | |
34 | Function locates Protocol and/or Handle on which all Protocols specified\r | |
35 | as a variable list are installed.\r | |
36 | It supports continued search. The caller must assure that no handles are added\r | |
37 | or removed while performing continued search, by e.g., rising the TPL and not\r | |
38 | calling any handle routines. Otherwise the behavior is undefined.\r | |
39 | \r | |
40 | Arguments:\r | |
41 | \r | |
42 | Handle - The address of handle to receive the handle on which protocols\r | |
43 | indicated by the variable list are installed.\r | |
44 | If points to NULL, all handles are searched. If pointing to a\r | |
45 | handle returned from previous call, searches starting from next handle.\r | |
46 | If NULL, the parameter is ignored.\r | |
47 | \r | |
48 | Interface - The address of a pointer to a protocol interface that will receive\r | |
49 | the interface indicated by first variable argument.\r | |
50 | If NULL, the parameter is ignored.\r | |
51 | \r | |
52 | ... - A variable argument list containing protocol GUIDs. Must end with NULL.\r | |
53 | \r | |
54 | Returns:\r | |
55 | \r | |
56 | EFI_SUCCESS - All the protocols where found on same handle.\r | |
57 | EFI_NOT_FOUND - A Handle with all the protocols installed was not found.\r | |
58 | Other values as may be returned from LocateHandleBuffer() or HandleProtocol().\r | |
59 | \r | |
60 | --*/\r | |
61 | {\r | |
62 | VA_LIST args;\r | |
63 | EFI_STATUS Status;\r | |
64 | EFI_GUID *Protocol;\r | |
65 | EFI_GUID *ProtocolFirst;\r | |
66 | EFI_HANDLE *HandleBuffer;\r | |
67 | UINTN NumberOfHandles;\r | |
68 | UINTN Idx;\r | |
69 | VOID *AnInterface;\r | |
70 | \r | |
71 | AnInterface = NULL;\r | |
72 | VA_START (args, Interface);\r | |
73 | ProtocolFirst = VA_ARG (args, EFI_GUID *);\r | |
74 | \r | |
75 | //\r | |
76 | // Get list of all handles that support the first protocol.\r | |
77 | //\r | |
78 | Status = gBS->LocateHandleBuffer (\r | |
79 | ByProtocol,\r | |
80 | ProtocolFirst,\r | |
81 | NULL,\r | |
82 | &NumberOfHandles,\r | |
83 | &HandleBuffer\r | |
84 | );\r | |
85 | if (EFI_ERROR (Status)) {\r | |
86 | return Status;\r | |
87 | }\r | |
88 | \r | |
89 | //\r | |
90 | // Check if this is a countinuation of handle searching.\r | |
91 | //\r | |
92 | Idx = 0;\r | |
93 | if ((Handle != NULL) && (*Handle != NULL)) {\r | |
94 | //\r | |
95 | // Leave the Idx just beyond the matching handle.\r | |
96 | //\r | |
97 | for (; Idx < NumberOfHandles;) {\r | |
98 | if (*Handle == HandleBuffer[Idx++]) {\r | |
99 | break;\r | |
100 | }\r | |
101 | }\r | |
102 | }\r | |
103 | \r | |
104 | //\r | |
105 | // Iterate handles testing for presence of remaining protocols.\r | |
106 | //\r | |
107 | for (; Idx < NumberOfHandles; Idx++) {\r | |
108 | \r | |
109 | //\r | |
110 | // Start with the second protocol, the first one is sure on this handle.\r | |
111 | //\r | |
112 | VA_START (args, Interface);\r | |
b96b676f | 113 | Protocol = VA_ARG (args, EFI_GUID *);\r |
3eb9473e | 114 | \r |
115 | //\r | |
116 | // Iterate protocols from the variable list.\r | |
117 | //\r | |
118 | while (TRUE) {\r | |
119 | \r | |
120 | Protocol = VA_ARG (args, EFI_GUID *);\r | |
121 | \r | |
122 | if (Protocol == NULL) {\r | |
123 | \r | |
124 | //\r | |
125 | // If here, the list was iterated successfully\r | |
126 | // finding each protocol on a single handle.\r | |
127 | //\r | |
128 | \r | |
129 | Status = EFI_SUCCESS;\r | |
130 | \r | |
131 | //\r | |
132 | // OPTIONAL parameter returning the Handle.\r | |
133 | //\r | |
134 | if (Handle != NULL) {\r | |
135 | *Handle = HandleBuffer[Idx];\r | |
136 | }\r | |
137 | \r | |
138 | //\r | |
139 | // OPTIONAL parameter returning the first rotocol's Interface.\r | |
140 | //\r | |
141 | if (Interface != NULL) {\r | |
142 | Status = gBS->HandleProtocol (\r | |
143 | HandleBuffer[Idx],\r | |
144 | ProtocolFirst,\r | |
145 | Interface\r | |
146 | );\r | |
147 | }\r | |
148 | \r | |
149 | goto lbl_out;\r | |
150 | }\r | |
151 | \r | |
152 | Status = gBS->HandleProtocol (\r | |
153 | HandleBuffer[Idx],\r | |
154 | Protocol,\r | |
155 | &AnInterface\r | |
156 | );\r | |
157 | if (EFI_ERROR (Status)) {\r | |
158 | \r | |
159 | //\r | |
160 | // This handle does not have the iterated protocol.\r | |
161 | //\r | |
162 | break;\r | |
163 | }\r | |
164 | }\r | |
165 | \r | |
166 | }\r | |
167 | \r | |
168 | //\r | |
169 | // If here, no handle that bears all the protocols was found.\r | |
170 | //\r | |
171 | Status = EFI_NOT_FOUND;\r | |
172 | \r | |
173 | lbl_out:\r | |
174 | gBS->FreePool (HandleBuffer);\r | |
175 | return Status;\r | |
176 | }\r |