]> git.proxmox.com Git - mirror_edk2.git/blame - Nt32Pkg/Library/EdkGenericBdsLib/BdsConnect.c
Clean up: update "EFI" to "UEFI" if applicable.
[mirror_edk2.git] / Nt32Pkg / Library / EdkGenericBdsLib / BdsConnect.c
CommitLineData
869f8e34 1/*++\r
2\r
3Copyright (c) 2006 - 2007, Intel Corporation\r
4All rights reserved. This program and the accompanying materials\r
5are licensed and made available under the terms and conditions of the BSD License\r
6which accompanies this distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
8\r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12Module Name:\r
13\r
14 BdsConnect.c\r
15\r
16Abstract:\r
17\r
18 BDS Lib functions which relate with connect the device\r
19\r
20--*/\r
21\r
f2569572 22#include <EdkGenericBdsLibInternal.h>\r
869f8e34 23\r
24VOID\r
25BdsLibConnectAll (\r
26 VOID\r
27 )\r
28/*++\r
29\r
30Routine Description:\r
31\r
32 This function will connect all the system driver to controller\r
33 first, and then special connect the default console, this make\r
34 sure all the system controller avialbe and the platform default\r
35 console connected.\r
36\r
37Arguments:\r
38\r
39 None\r
40\r
41Returns:\r
42\r
43 None\r
44\r
45--*/\r
46{\r
47 //\r
48 // Connect the platform console first\r
49 //\r
50 BdsLibConnectAllDefaultConsoles ();\r
51\r
52 //\r
53 // Generic way to connect all the drivers\r
54 //\r
55 BdsLibConnectAllDriversToAllControllers ();\r
56\r
57 //\r
58 // Here we have the assumption that we have already had\r
59 // platform default console\r
60 //\r
61 BdsLibConnectAllDefaultConsoles ();\r
62}\r
63\r
64VOID\r
65BdsLibGenericConnectAll (\r
66 VOID\r
67 )\r
68/*++\r
69\r
70Routine Description:\r
71\r
72 This function will connect all the system drivers to all controllers\r
73 first, and then connect all the console devices the system current\r
74 have. After this we should get all the device work and console avariable\r
75 if the system have console device.\r
76\r
77Arguments:\r
78\r
79 None\r
80\r
81Returns:\r
82\r
83 None\r
84\r
85--*/\r
86{\r
87 //\r
88 // Most generic way to connect all the drivers\r
89 //\r
90 BdsLibConnectAllDriversToAllControllers ();\r
91 BdsLibConnectAllConsoles ();\r
92}\r
93\r
94EFI_STATUS\r
95BdsLibConnectDevicePath (\r
96 IN EFI_DEVICE_PATH_PROTOCOL *DevicePathToConnect\r
97 )\r
98/*++\r
99\r
100Routine Description:\r
101 This function will create all handles associate with every device\r
102 path node. If the handle associate with one device path node can not\r
103 be created success, then still give one chance to do the dispatch,\r
104 which load the missing drivers if possible.\r
105\r
106Arguments:\r
107\r
108 DevicePathToConnect - The device path which will be connected, it can\r
109 be a multi-instance device path\r
110\r
111Returns:\r
112\r
113 EFI_SUCCESS - All handles associate with every device path\r
114 node have been created\r
115\r
116 EFI_OUT_OF_RESOURCES - There is no resource to create new handles\r
117\r
118 EFI_NOT_FOUND - Create the handle associate with one device\r
119 path node failed\r
120\r
121--*/\r
122{\r
123 EFI_STATUS Status;\r
124 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
125 EFI_DEVICE_PATH_PROTOCOL *CopyOfDevicePath;\r
126 EFI_DEVICE_PATH_PROTOCOL *Instance;\r
127 EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath;\r
128 EFI_DEVICE_PATH_PROTOCOL *Next;\r
129 EFI_HANDLE Handle;\r
130 EFI_HANDLE PreviousHandle;\r
131 UINTN Size;\r
132\r
133 if (DevicePathToConnect == NULL) {\r
134 return EFI_SUCCESS;\r
135 }\r
136\r
137 DevicePath = DuplicateDevicePath (DevicePathToConnect);\r
138 CopyOfDevicePath = DevicePath;\r
139 if (DevicePath == NULL) {\r
140 return EFI_OUT_OF_RESOURCES;\r
141 }\r
142\r
143 do {\r
144 //\r
145 // The outer loop handles multi instance device paths.\r
146 // Only console variables contain multiple instance device paths.\r
147 //\r
148 // After this call DevicePath points to the next Instance\r
149 //\r
150 Instance = GetNextDevicePathInstance (&DevicePath, &Size);\r
151 Next = Instance;\r
152 while (!IsDevicePathEndType (Next)) {\r
153 Next = NextDevicePathNode (Next);\r
154 }\r
155\r
156 SetDevicePathEndNode (Next);\r
157\r
158 //\r
159 // Start the real work of connect with RemainingDevicePath\r
160 //\r
161 PreviousHandle = NULL;\r
162 do {\r
163 //\r
164 // Find the handle that best matches the Device Path. If it is only a\r
165 // partial match the remaining part of the device path is returned in\r
166 // RemainingDevicePath.\r
167 //\r
168 RemainingDevicePath = Instance;\r
169 Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &RemainingDevicePath, &Handle);\r
170\r
171 if (!EFI_ERROR (Status)) {\r
172 if (Handle == PreviousHandle) {\r
173 //\r
174 // If no forward progress is made try invoking the Dispatcher.\r
175 // A new FV may have been added to the system an new drivers\r
176 // may now be found.\r
177 // Status == EFI_SUCCESS means a driver was dispatched\r
178 // Status == EFI_NOT_FOUND means no new drivers were dispatched\r
179 //\r
180 Status = gDS->Dispatch ();\r
181 }\r
182\r
183 if (!EFI_ERROR (Status)) {\r
184 PreviousHandle = Handle;\r
185 //\r
186 // Connect all drivers that apply to Handle and RemainingDevicePath,\r
187 // the Recursive flag is FALSE so only one level will be expanded.\r
188 //\r
189 // Do not check the connect status here, if the connect controller fail,\r
190 // then still give the chance to do dispatch, because partial\r
191 // RemainingDevicepath may be in the new FV\r
192 //\r
193 // 1. If the connect fail, RemainingDevicepath and handle will not\r
194 // change, so next time will do the dispatch, then dispatch's status\r
195 // will take effect\r
196 // 2. If the connect success, the RemainingDevicepath and handle will\r
197 // change, then avoid the dispatch, we have chance to continue the\r
198 // next connection\r
199 //\r
200 gBS->ConnectController (Handle, NULL, RemainingDevicePath, FALSE);\r
201 }\r
202 }\r
203 //\r
204 // Loop until RemainingDevicePath is an empty device path\r
205 //\r
206 } while (!EFI_ERROR (Status) && !IsDevicePathEnd (RemainingDevicePath));\r
207\r
208 } while (DevicePath != NULL);\r
209\r
210 if (CopyOfDevicePath != NULL) {\r
211 FreePool (CopyOfDevicePath);\r
212 }\r
213 //\r
214 // All handle with DevicePath exists in the handle database\r
215 //\r
216 return Status;\r
217}\r
218\r
219EFI_STATUS\r
220BdsLibConnectAllEfi (\r
221 VOID\r
222 )\r
223/*++\r
224\r
225Routine Description:\r
226\r
227 This function will connect all current system handles recursively. The\r
228 connection will finish until every handle's child handle created if it have.\r
229\r
230Arguments:\r
231\r
232 None\r
233\r
234Returns:\r
235\r
236 EFI_SUCCESS - All handles and it's child handle have been connected\r
237\r
238 EFI_STATUS - Return the status of gBS->LocateHandleBuffer().\r
239\r
240--*/\r
241{\r
242 EFI_STATUS Status;\r
243 UINTN HandleCount;\r
244 EFI_HANDLE *HandleBuffer;\r
245 UINTN Index;\r
246\r
247 Status = gBS->LocateHandleBuffer (\r
248 AllHandles,\r
249 NULL,\r
250 NULL,\r
251 &HandleCount,\r
252 &HandleBuffer\r
253 );\r
254 if (EFI_ERROR (Status)) {\r
255 return Status;\r
256 }\r
257\r
258 for (Index = 0; Index < HandleCount; Index++) {\r
259 Status = gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE);\r
260 }\r
261\r
262 FreePool (HandleBuffer);\r
263\r
264 return EFI_SUCCESS;\r
265}\r
266\r
267EFI_STATUS\r
268BdsLibDisconnectAllEfi (\r
269 VOID\r
270 )\r
271/*++\r
272\r
273Routine Description:\r
274\r
275 This function will disconnect all current system handles. The disconnection\r
276 will finish until every handle have been disconnected.\r
277\r
278Arguments:\r
279\r
280 None\r
281\r
282Returns:\r
283\r
284 EFI_SUCCESS - All handles have been disconnected\r
285\r
286 EFI_STATUS - Return the status of gBS->LocateHandleBuffer().\r
287\r
288--*/\r
289{\r
290 EFI_STATUS Status;\r
291 UINTN HandleCount;\r
292 EFI_HANDLE *HandleBuffer;\r
293 UINTN Index;\r
294\r
295 //\r
296 // Disconnect all\r
297 //\r
298 Status = gBS->LocateHandleBuffer (\r
299 AllHandles,\r
300 NULL,\r
301 NULL,\r
302 &HandleCount,\r
303 &HandleBuffer\r
304 );\r
305 if (EFI_ERROR (Status)) {\r
306 return Status;\r
307 }\r
308\r
309 for (Index = 0; Index < HandleCount; Index++) {\r
310 Status = gBS->DisconnectController (HandleBuffer[Index], NULL, NULL);\r
311 }\r
312\r
313 FreePool (HandleBuffer);\r
314\r
315 return EFI_SUCCESS;\r
316}\r
317\r
318VOID\r
319BdsLibConnectAllDriversToAllControllers (\r
320 VOID\r
321 )\r
322/*++\r
323\r
324Routine Description:\r
325\r
326 Connects all drivers to all controllers.\r
327 This function make sure all the current system driver will manage\r
328 the correspoinding controllers if have. And at the same time, make\r
329 sure all the system controllers have driver to manage it if have.\r
330\r
331Arguments:\r
332\r
333 None\r
334\r
335Returns:\r
336\r
337 None\r
338\r
339--*/\r
340{\r
341 EFI_STATUS Status;\r
342\r
343 do {\r
344 //\r
8a7d75b0 345 // Connect All UEFI 2.0 drivers following UEFI 2.0 algorithm\r
869f8e34 346 //\r
347 BdsLibConnectAllEfi ();\r
348\r
349 //\r
350 // Check to see if it's possible to dispatch an more DXE drivers.\r
351 // The BdsLibConnectAllEfi () may have made new DXE drivers show up.\r
352 // If anything is Dispatched Status == EFI_SUCCESS and we will try\r
353 // the connect again.\r
354 //\r
355 Status = gDS->Dispatch ();\r
356\r
357 } while (!EFI_ERROR (Status));\r
358\r
359}\r