]>
Commit | Line | Data |
---|---|---|
067ed98a RN |
1 | /** @file\r |
2 | Library functions which relate with connecting the device.\r | |
3 | \r | |
4 | Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.<BR>\r | |
5 | 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 | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include "InternalBm.h"\r | |
16 | \r | |
17 | /**\r | |
18 | Connect all the drivers to all the controllers.\r | |
19 | \r | |
20 | This function makes sure all the current system drivers manage the correspoinding\r | |
21 | controllers if have. And at the same time, makes sure all the system controllers\r | |
22 | have driver to manage it if have.\r | |
23 | **/\r | |
24 | VOID\r | |
25 | BmConnectAllDriversToAllControllers (\r | |
26 | VOID\r | |
27 | )\r | |
28 | {\r | |
29 | EFI_STATUS Status;\r | |
30 | UINTN HandleCount;\r | |
31 | EFI_HANDLE *HandleBuffer;\r | |
32 | UINTN Index;\r | |
33 | \r | |
34 | do {\r | |
35 | //\r | |
36 | // Connect All EFI 1.10 drivers following EFI 1.10 algorithm\r | |
37 | //\r | |
38 | gBS->LocateHandleBuffer (\r | |
39 | AllHandles,\r | |
40 | NULL,\r | |
41 | NULL,\r | |
42 | &HandleCount,\r | |
43 | &HandleBuffer\r | |
44 | );\r | |
45 | \r | |
46 | for (Index = 0; Index < HandleCount; Index++) {\r | |
47 | gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE);\r | |
48 | }\r | |
49 | \r | |
50 | if (HandleBuffer != NULL) {\r | |
51 | FreePool (HandleBuffer);\r | |
52 | }\r | |
53 | \r | |
54 | //\r | |
55 | // Check to see if it's possible to dispatch an more DXE drivers.\r | |
56 | // The above code may have made new DXE drivers show up.\r | |
57 | // If any new driver is dispatched (Status == EFI_SUCCESS) and we will try\r | |
58 | // the connect again.\r | |
59 | //\r | |
60 | Status = gDS->Dispatch ();\r | |
61 | \r | |
62 | } while (!EFI_ERROR (Status));\r | |
63 | }\r | |
64 | \r | |
65 | /**\r | |
66 | This function will connect all the system driver to controller\r | |
67 | first, and then special connect the default console, this make\r | |
68 | sure all the system controller available and the platform default\r | |
69 | console connected.\r | |
70 | \r | |
71 | **/\r | |
72 | VOID\r | |
73 | EFIAPI\r | |
74 | EfiBootManagerConnectAll (\r | |
75 | VOID\r | |
76 | )\r | |
77 | {\r | |
78 | //\r | |
79 | // Connect the platform console first\r | |
80 | //\r | |
81 | EfiBootManagerConnectAllDefaultConsoles ();\r | |
82 | \r | |
83 | //\r | |
84 | // Generic way to connect all the drivers\r | |
85 | //\r | |
86 | BmConnectAllDriversToAllControllers ();\r | |
87 | \r | |
88 | //\r | |
89 | // Here we have the assumption that we have already had\r | |
90 | // platform default console\r | |
91 | //\r | |
92 | EfiBootManagerConnectAllDefaultConsoles ();\r | |
93 | }\r | |
94 | \r | |
95 | /**\r | |
96 | This function will create all handles associate with every device\r | |
97 | path node. If the handle associate with one device path node can not\r | |
98 | be created successfully, then still give chance to do the dispatch,\r | |
99 | which load the missing drivers if possible.\r | |
100 | \r | |
101 | @param DevicePathToConnect The device path which will be connected, it can be\r | |
102 | a multi-instance device path\r | |
103 | @param MatchingHandle Return the controller handle closest to the DevicePathToConnect\r | |
104 | \r | |
105 | @retval EFI_SUCCESS All handles associate with every device path node\r | |
106 | have been created.\r | |
107 | @retval EFI_OUT_OF_RESOURCES There is no resource to create new handles.\r | |
108 | @retval EFI_NOT_FOUND Create the handle associate with one device path\r | |
109 | node failed.\r | |
110 | @retval EFI_SECURITY_VIOLATION The user has no permission to start UEFI device \r | |
111 | drivers on the DevicePath.\r | |
112 | **/\r | |
113 | EFI_STATUS\r | |
114 | EFIAPI\r | |
115 | EfiBootManagerConnectDevicePath (\r | |
116 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePathToConnect,\r | |
117 | OUT EFI_HANDLE *MatchingHandle OPTIONAL\r | |
118 | )\r | |
119 | {\r | |
120 | EFI_STATUS Status;\r | |
121 | EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath;\r | |
122 | EFI_HANDLE Handle;\r | |
123 | EFI_HANDLE PreviousHandle;\r | |
124 | EFI_TPL CurrentTpl;\r | |
125 | \r | |
126 | if (DevicePathToConnect == NULL) {\r | |
127 | return EFI_INVALID_PARAMETER;\r | |
128 | }\r | |
129 | \r | |
130 | CurrentTpl = EfiGetCurrentTpl ();\r | |
131 | //\r | |
132 | // Start the real work of connect with RemainingDevicePath\r | |
133 | //\r | |
134 | PreviousHandle = NULL;\r | |
135 | do {\r | |
136 | //\r | |
137 | // Find the handle that best matches the Device Path. If it is only a\r | |
138 | // partial match the remaining part of the device path is returned in\r | |
139 | // RemainingDevicePath.\r | |
140 | //\r | |
141 | RemainingDevicePath = DevicePathToConnect;\r | |
142 | Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &RemainingDevicePath, &Handle);\r | |
143 | if (!EFI_ERROR (Status)) {\r | |
144 | if (Handle == PreviousHandle) {\r | |
145 | //\r | |
146 | // If no forward progress is made try invoking the Dispatcher.\r | |
147 | // A new FV may have been added to the system an new drivers\r | |
148 | // may now be found.\r | |
149 | // Status == EFI_SUCCESS means a driver was dispatched\r | |
150 | // Status == EFI_NOT_FOUND means no new drivers were dispatched\r | |
151 | //\r | |
152 | if (CurrentTpl == TPL_APPLICATION) {\r | |
153 | Status = gDS->Dispatch ();\r | |
154 | } else {\r | |
155 | //\r | |
156 | // Always return EFI_NOT_FOUND here\r | |
157 | // to prevent dead loop when control handle is found but connection failded case\r | |
158 | //\r | |
159 | Status = EFI_NOT_FOUND;\r | |
160 | }\r | |
161 | }\r | |
162 | \r | |
163 | \r | |
164 | if (!EFI_ERROR (Status)) {\r | |
165 | PreviousHandle = Handle;\r | |
166 | //\r | |
167 | // Connect all drivers that apply to Handle and RemainingDevicePath,\r | |
168 | // the Recursive flag is FALSE so only one level will be expanded.\r | |
169 | //\r | |
170 | // If ConnectController fails to find a driver, then still give the chance to \r | |
171 | // do dispatch, because partial RemainingDevicePath may be in the new FV\r | |
172 | //\r | |
173 | // 1. If the connect fail, RemainingDevicepath and handle will not\r | |
174 | // change, so next time will do the dispatch, then dispatch's status\r | |
175 | // will take effect\r | |
176 | // 2. If the connect success, the RemainingDevicepath and handle will\r | |
177 | // change, then avoid the dispatch, we have chance to continue the\r | |
178 | // next connection\r | |
179 | //\r | |
180 | Status = gBS->ConnectController (Handle, NULL, RemainingDevicePath, FALSE);\r | |
181 | if (Status == EFI_NOT_FOUND) {\r | |
182 | Status = EFI_SUCCESS;\r | |
183 | }\r | |
184 | if (MatchingHandle != NULL) {\r | |
185 | *MatchingHandle = Handle;\r | |
186 | }\r | |
187 | }\r | |
188 | }\r | |
189 | //\r | |
190 | // Loop until RemainingDevicePath is an empty device path\r | |
191 | //\r | |
192 | } while (!EFI_ERROR (Status) && !IsDevicePathEnd (RemainingDevicePath));\r | |
193 | \r | |
194 | ASSERT (EFI_ERROR (Status) || IsDevicePathEnd (RemainingDevicePath));\r | |
195 | \r | |
196 | return Status;\r | |
197 | }\r | |
198 | \r | |
199 | /**\r | |
200 | This function will disconnect all current system handles. \r | |
201 | \r | |
202 | gBS->DisconnectController() is invoked for each handle exists in system handle buffer.\r | |
203 | If handle is a bus type handle, all childrens also are disconnected recursively by\r | |
204 | gBS->DisconnectController().\r | |
205 | **/\r | |
206 | VOID\r | |
207 | EFIAPI\r | |
208 | EfiBootManagerDisconnectAll (\r | |
209 | VOID\r | |
210 | )\r | |
211 | {\r | |
212 | UINTN HandleCount;\r | |
213 | EFI_HANDLE *HandleBuffer;\r | |
214 | UINTN Index;\r | |
215 | \r | |
216 | //\r | |
217 | // Disconnect all\r | |
218 | //\r | |
219 | gBS->LocateHandleBuffer (\r | |
220 | AllHandles,\r | |
221 | NULL,\r | |
222 | NULL,\r | |
223 | &HandleCount,\r | |
224 | &HandleBuffer\r | |
225 | );\r | |
226 | for (Index = 0; Index < HandleCount; Index++) {\r | |
227 | gBS->DisconnectController (HandleBuffer[Index], NULL, NULL);\r | |
228 | }\r | |
229 | \r | |
230 | if (HandleBuffer != NULL) {\r | |
231 | FreePool (HandleBuffer);\r | |
232 | }\r | |
233 | }\r | |
234 | \r | |
235 | /**\r | |
236 | Connect the specific Usb device which match the short form device path,\r | |
237 | and whose bus is determined by Host Controller (Uhci or Ehci).\r | |
238 | \r | |
239 | @param DevicePath A short-form device path that starts with the first\r | |
240 | element being a USB WWID or a USB Class device\r | |
241 | path\r | |
242 | \r | |
243 | @return EFI_INVALID_PARAMETER DevicePath is NULL pointer.\r | |
244 | DevicePath is not a USB device path.\r | |
245 | \r | |
246 | @return EFI_SUCCESS Success to connect USB device\r | |
247 | @return EFI_NOT_FOUND Fail to find handle for USB controller to connect.\r | |
248 | \r | |
249 | **/\r | |
250 | EFI_STATUS\r | |
251 | BmConnectUsbShortFormDevicePath (\r | |
252 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
253 | )\r | |
254 | {\r | |
255 | EFI_STATUS Status;\r | |
256 | EFI_HANDLE *Handles;\r | |
257 | UINTN HandleCount;\r | |
258 | UINTN Index;\r | |
259 | EFI_PCI_IO_PROTOCOL *PciIo;\r | |
260 | UINT8 Class[3];\r | |
261 | BOOLEAN AtLeastOneConnected;\r | |
262 | \r | |
263 | //\r | |
264 | // Check the passed in parameters\r | |
265 | //\r | |
266 | if (DevicePath == NULL) {\r | |
267 | return EFI_INVALID_PARAMETER;\r | |
268 | }\r | |
269 | \r | |
270 | if ((DevicePathType (DevicePath) != MESSAGING_DEVICE_PATH) ||\r | |
271 | ((DevicePathSubType (DevicePath) != MSG_USB_CLASS_DP) && (DevicePathSubType (DevicePath) != MSG_USB_WWID_DP))\r | |
272 | ) {\r | |
273 | return EFI_INVALID_PARAMETER;\r | |
274 | }\r | |
275 | \r | |
276 | //\r | |
277 | // Find the usb host controller firstly, then connect with the remaining device path\r | |
278 | //\r | |
279 | AtLeastOneConnected = FALSE;\r | |
280 | Status = gBS->LocateHandleBuffer (\r | |
281 | ByProtocol,\r | |
282 | &gEfiPciIoProtocolGuid,\r | |
283 | NULL,\r | |
284 | &HandleCount,\r | |
285 | &Handles\r | |
286 | );\r | |
287 | if (!EFI_ERROR (Status)) {\r | |
288 | for (Index = 0; Index < HandleCount; Index++) {\r | |
289 | Status = gBS->HandleProtocol (\r | |
290 | Handles[Index],\r | |
291 | &gEfiPciIoProtocolGuid,\r | |
292 | (VOID **) &PciIo\r | |
293 | );\r | |
294 | if (!EFI_ERROR (Status)) {\r | |
295 | //\r | |
296 | // Check whether the Pci device is the wanted usb host controller\r | |
297 | //\r | |
298 | Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint8, 0x09, 3, &Class);\r | |
299 | if (!EFI_ERROR (Status) &&\r | |
300 | ((PCI_CLASS_SERIAL == Class[2]) && (PCI_CLASS_SERIAL_USB == Class[1]))\r | |
301 | ) {\r | |
302 | Status = gBS->ConnectController (\r | |
303 | Handles[Index],\r | |
304 | NULL,\r | |
305 | DevicePath,\r | |
306 | FALSE\r | |
307 | );\r | |
308 | if (!EFI_ERROR(Status)) {\r | |
309 | AtLeastOneConnected = TRUE;\r | |
310 | }\r | |
311 | }\r | |
312 | }\r | |
313 | }\r | |
314 | \r | |
315 | if (Handles != NULL) {\r | |
316 | FreePool (Handles);\r | |
317 | }\r | |
318 | }\r | |
319 | \r | |
320 | return AtLeastOneConnected ? EFI_SUCCESS : EFI_NOT_FOUND;\r | |
321 | }\r |