]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.c
MdeModulePkg/PciBusDxe: reference gFullEnumeration in one file
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / PciBusDxe / PciBus.c
CommitLineData
9060e3ec 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
26329817 11Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
cd5ebaa0 12This program and the accompanying materials\r
9060e3ec 13are licensed and made available under the terms and conditions of the BSD License\r
14which accompanies this distribution. The full text of the license may be found at\r
15http://opensource.org/licenses/bsd-license.php\r
16\r
17THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
18WITHOUT 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
27EFI_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
36EFI_HANDLE gPciHostBrigeHandles[PCI_MAX_HOST_BRIDGE_NUM];\r
ea669c1b 37EFI_INCOMPATIBLE_PCI_DEVICE_SUPPORT_PROTOCOL *gIncompatiblePciDeviceSupport = NULL;\r
9060e3ec 38UINTN gPciHostBridgeNumber = 0;\r
39BOOLEAN gFullEnumeration = TRUE;\r
40UINT64 gAllOne = 0xFFFFFFFFFFFFFFFFULL;\r
41UINT64 gAllZero = 0;\r
42\r
43EFI_PCI_PLATFORM_PROTOCOL *gPciPlatformProtocol;\r
44EFI_PCI_OVERRIDE_PROTOCOL *gPciOverrideProtocol;\r
11a6cc5b 45EDKII_IOMMU_PROTOCOL *mIoMmuProtocol;\r
9060e3ec 46\r
47\r
48GLOBAL_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
67EFI_STATUS\r
68EFIAPI\r
69PciBusEntryPoint (\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
ed356b9e 117 @param RemainingDevicePath Optional parameter use to pick a specific child\r
9060e3ec 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
125EFI_STATUS\r
126EFIAPI\r
127PciBusDriverBindingSupported (\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
ed356b9e 227 @param RemainingDevicePath Optional parameter use to pick a specific child\r
9060e3ec 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
235EFI_STATUS\r
236EFIAPI\r
237PciBusDriverBindingStart (\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
26329817
RN
243 EFI_STATUS Status;\r
244 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r
245 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;\r
9060e3ec 246\r
247 //\r
248 // Check RemainingDevicePath validation\r
249 //\r
250 if (RemainingDevicePath != NULL) {\r
251 //\r
252 // Check if RemainingDevicePath is the End of Device Path Node, \r
253 // if yes, return EFI_SUCCESS\r
254 //\r
255 if (IsDevicePathEnd (RemainingDevicePath)) {\r
256 return EFI_SUCCESS;\r
257 }\r
258 }\r
259\r
500e2ac2
OM
260 gBS->LocateProtocol (\r
261 &gEfiIncompatiblePciDeviceSupportProtocolGuid,\r
262 NULL,\r
ea669c1b 263 (VOID **) &gIncompatiblePciDeviceSupport\r
500e2ac2 264 );\r
9060e3ec 265\r
266 //\r
267 // If PCI Platform protocol is available, get it now.\r
268 // If the platform implements this, it must be installed before BDS phase\r
269 //\r
270 gPciPlatformProtocol = NULL;\r
271 gBS->LocateProtocol (\r
272 &gEfiPciPlatformProtocolGuid,\r
273 NULL,\r
274 (VOID **) &gPciPlatformProtocol\r
275 );\r
276\r
277 //\r
278 // If PCI Platform protocol doesn't exist, try to Pci Override Protocol.\r
279 //\r
280 if (gPciPlatformProtocol == NULL) { \r
281 gPciOverrideProtocol = NULL;\r
282 gBS->LocateProtocol (\r
283 &gEfiPciOverrideProtocolGuid,\r
284 NULL,\r
285 (VOID **) &gPciOverrideProtocol\r
286 );\r
287 } \r
288\r
11a6cc5b
JY
289 if (mIoMmuProtocol == NULL) {\r
290 gBS->LocateProtocol (\r
291 &gEdkiiIoMmuProtocolGuid,\r
292 NULL,\r
293 (VOID **) &mIoMmuProtocol\r
294 );\r
295 }\r
296\r
5624a27d
WL
297 if (PcdGetBool (PcdPciDisableBusEnumeration)) {\r
298 gFullEnumeration = FALSE;\r
299 } else {\r
300 gFullEnumeration = (BOOLEAN) ((SearchHostBridgeHandle (Controller) ? FALSE : TRUE));\r
301 }\r
9060e3ec 302\r
37623a5c 303 //\r
304 // Open Device Path Protocol for PCI root bridge\r
305 //\r
306 Status = gBS->OpenProtocol (\r
307 Controller,\r
308 &gEfiDevicePathProtocolGuid,\r
309 (VOID **) &ParentDevicePath,\r
310 This->DriverBindingHandle,\r
311 Controller,\r
312 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
313 ); \r
314 ASSERT_EFI_ERROR (Status);\r
315\r
316 //\r
317 // Report Status Code to indicate PCI bus starts\r
318 //\r
319 REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
320 EFI_PROGRESS_CODE,\r
321 (EFI_IO_BUS_PCI | EFI_IOB_PC_INIT),\r
322 ParentDevicePath\r
323 );\r
324\r
26329817 325 Status = EFI_SUCCESS;\r
9060e3ec 326 //\r
327 // Enumerate the entire host bridge\r
328 // After enumeration, a database that records all the device information will be created\r
329 //\r
330 //\r
26329817
RN
331 if (gFullEnumeration) {\r
332 //\r
333 // Get the rootbridge Io protocol to find the host bridge handle\r
334 //\r
335 Status = gBS->OpenProtocol (\r
336 Controller,\r
337 &gEfiPciRootBridgeIoProtocolGuid,\r
338 (VOID **) &PciRootBridgeIo,\r
339 gPciBusDriverBinding.DriverBindingHandle,\r
340 Controller,\r
341 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
342 );\r
343\r
344 if (!EFI_ERROR (Status)) {\r
345 Status = PciEnumerator (Controller, PciRootBridgeIo->ParentHandle);\r
346 }\r
347 } else {\r
348 //\r
349 // If PCI bus has already done the full enumeration, never do it again\r
350 //\r
351 Status = PciEnumeratorLight (Controller);\r
352 }\r
9060e3ec 353\r
354 if (EFI_ERROR (Status)) {\r
355 return Status;\r
356 }\r
357\r
358 //\r
359 // Start all the devices under the entire host bridge.\r
360 //\r
361 StartPciDevices (Controller);\r
362\r
26329817 363 gFullEnumeration = FALSE;\r
9060e3ec 364 return EFI_SUCCESS;\r
365}\r
366\r
367/**\r
ed356b9e 368 Stop this driver on ControllerHandle. Support stopping any child handles\r
9060e3ec 369 created by this driver.\r
370\r
371 @param This Protocol instance pointer.\r
372 @param Controller Handle of device to stop driver on.\r
373 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r
374 children is zero stop the entire bus driver.\r
375 @param ChildHandleBuffer List of Child Handles to Stop.\r
376\r
377 @retval EFI_SUCCESS This driver is removed ControllerHandle.\r
378 @retval other This driver was not removed from this device.\r
379\r
380**/\r
381EFI_STATUS\r
382EFIAPI\r
383PciBusDriverBindingStop (\r
384 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
385 IN EFI_HANDLE Controller,\r
386 IN UINTN NumberOfChildren,\r
387 IN EFI_HANDLE *ChildHandleBuffer\r
388 )\r
389{\r
390 EFI_STATUS Status;\r
391 UINTN Index;\r
392 BOOLEAN AllChildrenStopped;\r
393\r
394 if (NumberOfChildren == 0) {\r
395 //\r
396 // Close the bus driver\r
397 //\r
398 gBS->CloseProtocol (\r
399 Controller,\r
400 &gEfiDevicePathProtocolGuid,\r
401 This->DriverBindingHandle,\r
402 Controller\r
403 );\r
404 gBS->CloseProtocol (\r
405 Controller,\r
406 &gEfiPciRootBridgeIoProtocolGuid,\r
407 This->DriverBindingHandle,\r
408 Controller\r
409 );\r
410\r
411 DestroyRootBridgeByHandle (\r
412 Controller\r
413 );\r
414\r
415 return EFI_SUCCESS;\r
416 }\r
417\r
418 //\r
419 // Stop all the children\r
420 //\r
421\r
422 AllChildrenStopped = TRUE;\r
423\r
424 for (Index = 0; Index < NumberOfChildren; Index++) {\r
425\r
426 //\r
427 // De register all the pci device\r
428 //\r
429 Status = DeRegisterPciDevice (Controller, ChildHandleBuffer[Index]);\r
430\r
431 if (EFI_ERROR (Status)) {\r
432 AllChildrenStopped = FALSE;\r
433 }\r
434 }\r
435\r
436 if (!AllChildrenStopped) {\r
437 return EFI_DEVICE_ERROR;\r
438 }\r
439\r
440 return EFI_SUCCESS;\r
441}\r
442\r