]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | Driver Binding functions for PCI Bus module.\r | |
3 | \r | |
4 | Single PCI bus driver instance will manager all PCI Root Bridges in one EFI based firmware,\r | |
5 | since all PCI Root Bridges' resources need to be managed together.\r | |
6 | Supported() function will try to get PCI Root Bridge IO Protocol.\r | |
7 | Start() function will get PCI Host Bridge Resource Allocation Protocol to manage all\r | |
8 | PCI Root Bridges. So it means platform needs install PCI Root Bridge IO protocol for each\r | |
9 | PCI Root Bus and install PCI Host Bridge Resource Allocation Protocol.\r | |
10 | \r | |
11 | Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r | |
12 | This program and the accompanying materials\r | |
13 | are licensed and made available under the terms and conditions of the BSD License\r | |
14 | which accompanies this distribution. The full text of the license may be found at\r | |
15 | http://opensource.org/licenses/bsd-license.php\r | |
16 | \r | |
17 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
18 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
19 | \r | |
20 | **/\r | |
21 | \r | |
22 | #include "PciBus.h"\r | |
23 | \r | |
24 | //\r | |
25 | // PCI Bus Driver Global Variables\r | |
26 | //\r | |
27 | EFI_DRIVER_BINDING_PROTOCOL gPciBusDriverBinding = {\r | |
28 | PciBusDriverBindingSupported,\r | |
29 | PciBusDriverBindingStart,\r | |
30 | PciBusDriverBindingStop,\r | |
31 | 0xa,\r | |
32 | NULL,\r | |
33 | NULL\r | |
34 | };\r | |
35 | \r | |
36 | EFI_HANDLE gPciHostBrigeHandles[PCI_MAX_HOST_BRIDGE_NUM];\r | |
37 | EFI_INCOMPATIBLE_PCI_DEVICE_SUPPORT_PROTOCOL *gIncompatiblePciDeviceSupport = NULL;\r | |
38 | UINTN gPciHostBridgeNumber = 0;\r | |
39 | BOOLEAN gFullEnumeration = TRUE;\r | |
40 | UINT64 gAllOne = 0xFFFFFFFFFFFFFFFFULL;\r | |
41 | UINT64 gAllZero = 0;\r | |
42 | \r | |
43 | EFI_PCI_PLATFORM_PROTOCOL *gPciPlatformProtocol;\r | |
44 | EFI_PCI_OVERRIDE_PROTOCOL *gPciOverrideProtocol;\r | |
45 | EDKII_IOMMU_PROTOCOL *mIoMmuProtocol;\r | |
46 | \r | |
47 | \r | |
48 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_PCI_HOTPLUG_REQUEST_PROTOCOL mPciHotPlugRequest = {\r | |
49 | PciHotPlugRequestNotify\r | |
50 | };\r | |
51 | \r | |
52 | /**\r | |
53 | The Entry Point for PCI Bus module. The user code starts with this function.\r | |
54 | \r | |
55 | Installs driver module protocols and. Creates virtual device handles for ConIn,\r | |
56 | ConOut, and StdErr. Installs Simple Text In protocol, Simple Text In Ex protocol,\r | |
57 | Simple Pointer protocol, Absolute Pointer protocol on those virtual handlers.\r | |
58 | Installs Graphics Output protocol and/or UGA Draw protocol if needed.\r | |
59 | \r | |
60 | @param[in] ImageHandle The firmware allocated handle for the EFI image.\r | |
61 | @param[in] SystemTable A pointer to the EFI System Table.\r | |
62 | \r | |
63 | @retval EFI_SUCCESS The entry point is executed successfully.\r | |
64 | @retval other Some error occurred when executing this entry point.\r | |
65 | \r | |
66 | **/\r | |
67 | EFI_STATUS\r | |
68 | EFIAPI\r | |
69 | PciBusEntryPoint (\r | |
70 | IN EFI_HANDLE ImageHandle,\r | |
71 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
72 | )\r | |
73 | {\r | |
74 | EFI_STATUS Status;\r | |
75 | EFI_HANDLE Handle;\r | |
76 | \r | |
77 | //\r | |
78 | // Initializes PCI devices pool\r | |
79 | //\r | |
80 | InitializePciDevicePool ();\r | |
81 | \r | |
82 | //\r | |
83 | // Install driver model protocol(s).\r | |
84 | //\r | |
85 | Status = EfiLibInstallDriverBindingComponentName2 (\r | |
86 | ImageHandle,\r | |
87 | SystemTable,\r | |
88 | &gPciBusDriverBinding,\r | |
89 | ImageHandle,\r | |
90 | &gPciBusComponentName,\r | |
91 | &gPciBusComponentName2\r | |
92 | );\r | |
93 | ASSERT_EFI_ERROR (Status);\r | |
94 | \r | |
95 | if (FeaturePcdGet (PcdPciBusHotplugDeviceSupport)) {\r | |
96 | //\r | |
97 | // If Hot Plug is supported, install EFI PCI Hot Plug Request protocol.\r | |
98 | //\r | |
99 | Handle = NULL;\r | |
100 | Status = gBS->InstallProtocolInterface (\r | |
101 | &Handle,\r | |
102 | &gEfiPciHotPlugRequestProtocolGuid,\r | |
103 | EFI_NATIVE_INTERFACE,\r | |
104 | &mPciHotPlugRequest\r | |
105 | );\r | |
106 | }\r | |
107 | \r | |
108 | return Status;\r | |
109 | }\r | |
110 | \r | |
111 | /**\r | |
112 | Test to see if this driver supports ControllerHandle. Any ControllerHandle\r | |
113 | than contains a gEfiPciRootBridgeIoProtocolGuid protocol can be supported.\r | |
114 | \r | |
115 | @param This Protocol instance pointer.\r | |
116 | @param Controller Handle of device to test.\r | |
117 | @param RemainingDevicePath Optional parameter use to pick a specific child\r | |
118 | device to start.\r | |
119 | \r | |
120 | @retval EFI_SUCCESS This driver supports this device.\r | |
121 | @retval EFI_ALREADY_STARTED This driver is already running on this device.\r | |
122 | @retval other This driver does not support this device.\r | |
123 | \r | |
124 | **/\r | |
125 | EFI_STATUS\r | |
126 | EFIAPI\r | |
127 | PciBusDriverBindingSupported (\r | |
128 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
129 | IN EFI_HANDLE Controller,\r | |
130 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
131 | )\r | |
132 | {\r | |
133 | EFI_STATUS Status;\r | |
134 | EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r | |
135 | EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;\r | |
136 | EFI_DEV_PATH_PTR Node;\r | |
137 | \r | |
138 | //\r | |
139 | // Check RemainingDevicePath validation\r | |
140 | //\r | |
141 | if (RemainingDevicePath != NULL) {\r | |
142 | //\r | |
143 | // Check if RemainingDevicePath is the End of Device Path Node, \r | |
144 | // if yes, go on checking other conditions\r | |
145 | //\r | |
146 | if (!IsDevicePathEnd (RemainingDevicePath)) {\r | |
147 | //\r | |
148 | // If RemainingDevicePath isn't the End of Device Path Node,\r | |
149 | // check its validation\r | |
150 | //\r | |
151 | Node.DevPath = RemainingDevicePath;\r | |
152 | if (Node.DevPath->Type != HARDWARE_DEVICE_PATH ||\r | |
153 | Node.DevPath->SubType != HW_PCI_DP ||\r | |
154 | DevicePathNodeLength(Node.DevPath) != sizeof(PCI_DEVICE_PATH)) {\r | |
155 | return EFI_UNSUPPORTED;\r | |
156 | }\r | |
157 | }\r | |
158 | }\r | |
159 | \r | |
160 | //\r | |
161 | // Check if Pci Root Bridge IO protocol is installed by platform\r | |
162 | //\r | |
163 | Status = gBS->OpenProtocol (\r | |
164 | Controller,\r | |
165 | &gEfiPciRootBridgeIoProtocolGuid,\r | |
166 | (VOID **) &PciRootBridgeIo,\r | |
167 | This->DriverBindingHandle,\r | |
168 | Controller,\r | |
169 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
170 | );\r | |
171 | if (Status == EFI_ALREADY_STARTED) {\r | |
172 | return EFI_SUCCESS;\r | |
173 | }\r | |
174 | \r | |
175 | if (EFI_ERROR (Status)) {\r | |
176 | return Status;\r | |
177 | }\r | |
178 | \r | |
179 | //\r | |
180 | // Close the I/O Abstraction(s) used to perform the supported test\r | |
181 | //\r | |
182 | gBS->CloseProtocol (\r | |
183 | Controller,\r | |
184 | &gEfiPciRootBridgeIoProtocolGuid,\r | |
185 | This->DriverBindingHandle,\r | |
186 | Controller\r | |
187 | );\r | |
188 | \r | |
189 | //\r | |
190 | // Open the EFI Device Path protocol needed to perform the supported test\r | |
191 | //\r | |
192 | Status = gBS->OpenProtocol (\r | |
193 | Controller,\r | |
194 | &gEfiDevicePathProtocolGuid,\r | |
195 | (VOID **) &ParentDevicePath,\r | |
196 | This->DriverBindingHandle,\r | |
197 | Controller,\r | |
198 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
199 | );\r | |
200 | if (Status == EFI_ALREADY_STARTED) {\r | |
201 | return EFI_SUCCESS;\r | |
202 | }\r | |
203 | \r | |
204 | if (EFI_ERROR (Status)) {\r | |
205 | return Status;\r | |
206 | }\r | |
207 | \r | |
208 | //\r | |
209 | // Close protocol, don't use device path protocol in the Support() function\r | |
210 | //\r | |
211 | gBS->CloseProtocol (\r | |
212 | Controller,\r | |
213 | &gEfiDevicePathProtocolGuid,\r | |
214 | This->DriverBindingHandle,\r | |
215 | Controller\r | |
216 | );\r | |
217 | \r | |
218 | return EFI_SUCCESS;\r | |
219 | }\r | |
220 | \r | |
221 | /**\r | |
222 | Start this driver on ControllerHandle and enumerate Pci bus and start\r | |
223 | all device under PCI bus.\r | |
224 | \r | |
225 | @param This Protocol instance pointer.\r | |
226 | @param Controller Handle of device to bind driver to.\r | |
227 | @param RemainingDevicePath Optional parameter use to pick a specific child\r | |
228 | device to start.\r | |
229 | \r | |
230 | @retval EFI_SUCCESS This driver is added to ControllerHandle.\r | |
231 | @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle.\r | |
232 | @retval other This driver does not support this device.\r | |
233 | \r | |
234 | **/\r | |
235 | EFI_STATUS\r | |
236 | EFIAPI\r | |
237 | PciBusDriverBindingStart (\r | |
238 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
239 | IN EFI_HANDLE Controller,\r | |
240 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
241 | )\r | |
242 | {\r | |
243 | EFI_STATUS Status;\r | |
244 | EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r | |
245 | \r | |
246 | //\r | |
247 | // Check RemainingDevicePath validation\r | |
248 | //\r | |
249 | if (RemainingDevicePath != NULL) {\r | |
250 | //\r | |
251 | // Check if RemainingDevicePath is the End of Device Path Node, \r | |
252 | // if yes, return EFI_SUCCESS\r | |
253 | //\r | |
254 | if (IsDevicePathEnd (RemainingDevicePath)) {\r | |
255 | return EFI_SUCCESS;\r | |
256 | }\r | |
257 | }\r | |
258 | \r | |
259 | gBS->LocateProtocol (\r | |
260 | &gEfiIncompatiblePciDeviceSupportProtocolGuid,\r | |
261 | NULL,\r | |
262 | (VOID **) &gIncompatiblePciDeviceSupport\r | |
263 | );\r | |
264 | \r | |
265 | //\r | |
266 | // If PCI Platform protocol is available, get it now.\r | |
267 | // If the platform implements this, it must be installed before BDS phase\r | |
268 | //\r | |
269 | gPciPlatformProtocol = NULL;\r | |
270 | gBS->LocateProtocol (\r | |
271 | &gEfiPciPlatformProtocolGuid,\r | |
272 | NULL,\r | |
273 | (VOID **) &gPciPlatformProtocol\r | |
274 | );\r | |
275 | \r | |
276 | //\r | |
277 | // If PCI Platform protocol doesn't exist, try to Pci Override Protocol.\r | |
278 | //\r | |
279 | if (gPciPlatformProtocol == NULL) { \r | |
280 | gPciOverrideProtocol = NULL;\r | |
281 | gBS->LocateProtocol (\r | |
282 | &gEfiPciOverrideProtocolGuid,\r | |
283 | NULL,\r | |
284 | (VOID **) &gPciOverrideProtocol\r | |
285 | );\r | |
286 | } \r | |
287 | \r | |
288 | if (mIoMmuProtocol == NULL) {\r | |
289 | gBS->LocateProtocol (\r | |
290 | &gEdkiiIoMmuProtocolGuid,\r | |
291 | NULL,\r | |
292 | (VOID **) &mIoMmuProtocol\r | |
293 | );\r | |
294 | }\r | |
295 | \r | |
296 | if (PcdGetBool (PcdPciDisableBusEnumeration)) {\r | |
297 | gFullEnumeration = FALSE;\r | |
298 | } else {\r | |
299 | gFullEnumeration = (BOOLEAN) ((SearchHostBridgeHandle (Controller) ? FALSE : TRUE));\r | |
300 | }\r | |
301 | \r | |
302 | //\r | |
303 | // Open Device Path Protocol for PCI root bridge\r | |
304 | //\r | |
305 | Status = gBS->OpenProtocol (\r | |
306 | Controller,\r | |
307 | &gEfiDevicePathProtocolGuid,\r | |
308 | (VOID **) &ParentDevicePath,\r | |
309 | This->DriverBindingHandle,\r | |
310 | Controller,\r | |
311 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
312 | ); \r | |
313 | ASSERT_EFI_ERROR (Status);\r | |
314 | \r | |
315 | //\r | |
316 | // Report Status Code to indicate PCI bus starts\r | |
317 | //\r | |
318 | REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r | |
319 | EFI_PROGRESS_CODE,\r | |
320 | (EFI_IO_BUS_PCI | EFI_IOB_PC_INIT),\r | |
321 | ParentDevicePath\r | |
322 | );\r | |
323 | \r | |
324 | //\r | |
325 | // Enumerate the entire host bridge\r | |
326 | // After enumeration, a database that records all the device information will be created\r | |
327 | //\r | |
328 | //\r | |
329 | Status = PciEnumerator (Controller);\r | |
330 | \r | |
331 | if (EFI_ERROR (Status)) {\r | |
332 | return Status;\r | |
333 | }\r | |
334 | \r | |
335 | //\r | |
336 | // Start all the devices under the entire host bridge.\r | |
337 | //\r | |
338 | StartPciDevices (Controller);\r | |
339 | \r | |
340 | return EFI_SUCCESS;\r | |
341 | }\r | |
342 | \r | |
343 | /**\r | |
344 | Stop this driver on ControllerHandle. Support stopping any child handles\r | |
345 | created by this driver.\r | |
346 | \r | |
347 | @param This Protocol instance pointer.\r | |
348 | @param Controller Handle of device to stop driver on.\r | |
349 | @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r | |
350 | children is zero stop the entire bus driver.\r | |
351 | @param ChildHandleBuffer List of Child Handles to Stop.\r | |
352 | \r | |
353 | @retval EFI_SUCCESS This driver is removed ControllerHandle.\r | |
354 | @retval other This driver was not removed from this device.\r | |
355 | \r | |
356 | **/\r | |
357 | EFI_STATUS\r | |
358 | EFIAPI\r | |
359 | PciBusDriverBindingStop (\r | |
360 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
361 | IN EFI_HANDLE Controller,\r | |
362 | IN UINTN NumberOfChildren,\r | |
363 | IN EFI_HANDLE *ChildHandleBuffer\r | |
364 | )\r | |
365 | {\r | |
366 | EFI_STATUS Status;\r | |
367 | UINTN Index;\r | |
368 | BOOLEAN AllChildrenStopped;\r | |
369 | \r | |
370 | if (NumberOfChildren == 0) {\r | |
371 | //\r | |
372 | // Close the bus driver\r | |
373 | //\r | |
374 | gBS->CloseProtocol (\r | |
375 | Controller,\r | |
376 | &gEfiDevicePathProtocolGuid,\r | |
377 | This->DriverBindingHandle,\r | |
378 | Controller\r | |
379 | );\r | |
380 | gBS->CloseProtocol (\r | |
381 | Controller,\r | |
382 | &gEfiPciRootBridgeIoProtocolGuid,\r | |
383 | This->DriverBindingHandle,\r | |
384 | Controller\r | |
385 | );\r | |
386 | \r | |
387 | DestroyRootBridgeByHandle (\r | |
388 | Controller\r | |
389 | );\r | |
390 | \r | |
391 | return EFI_SUCCESS;\r | |
392 | }\r | |
393 | \r | |
394 | //\r | |
395 | // Stop all the children\r | |
396 | //\r | |
397 | \r | |
398 | AllChildrenStopped = TRUE;\r | |
399 | \r | |
400 | for (Index = 0; Index < NumberOfChildren; Index++) {\r | |
401 | \r | |
402 | //\r | |
403 | // De register all the pci device\r | |
404 | //\r | |
405 | Status = DeRegisterPciDevice (Controller, ChildHandleBuffer[Index]);\r | |
406 | \r | |
407 | if (EFI_ERROR (Status)) {\r | |
408 | AllChildrenStopped = FALSE;\r | |
409 | }\r | |
410 | }\r | |
411 | \r | |
412 | if (!AllChildrenStopped) {\r | |
413 | return EFI_DEVICE_ERROR;\r | |
414 | }\r | |
415 | \r | |
416 | return EFI_SUCCESS;\r | |
417 | }\r | |
418 | \r |