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