]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.c
MdeModulePkg: introduce PcdPciDisableBusEnumeration
[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
37623a5c 11Copyright (c) 2006 - 2012, 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
37EFI_INCOMPATIBLE_PCI_DEVICE_SUPPORT_PROTOCOL *gEfiIncompatiblePciDeviceSupport = NULL;\r
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
45\r
46\r
47GLOBAL_REMOVE_IF_UNREFERENCED EFI_PCI_HOTPLUG_REQUEST_PROTOCOL mPciHotPlugRequest = {\r
48 PciHotPlugRequestNotify\r
49};\r
50\r
51/**\r
52 The Entry Point for PCI Bus module. The user code starts with this function.\r
53\r
54 Installs driver module protocols and. Creates virtual device handles for ConIn,\r
55 ConOut, and StdErr. Installs Simple Text In protocol, Simple Text In Ex protocol,\r
56 Simple Pointer protocol, Absolute Pointer protocol on those virtual handlers.\r
57 Installs Graphics Output protocol and/or UGA Draw protocol if needed.\r
58\r
59 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
60 @param[in] SystemTable A pointer to the EFI System Table.\r
61\r
62 @retval EFI_SUCCESS The entry point is executed successfully.\r
63 @retval other Some error occurred when executing this entry point.\r
64\r
65**/\r
66EFI_STATUS\r
67EFIAPI\r
68PciBusEntryPoint (\r
69 IN EFI_HANDLE ImageHandle,\r
70 IN EFI_SYSTEM_TABLE *SystemTable\r
71 )\r
72{\r
73 EFI_STATUS Status;\r
74 EFI_HANDLE Handle;\r
75\r
76 //\r
77 // Initializes PCI devices pool\r
78 //\r
79 InitializePciDevicePool ();\r
80\r
81 //\r
82 // Install driver model protocol(s).\r
83 //\r
84 Status = EfiLibInstallDriverBindingComponentName2 (\r
85 ImageHandle,\r
86 SystemTable,\r
87 &gPciBusDriverBinding,\r
88 ImageHandle,\r
89 &gPciBusComponentName,\r
90 &gPciBusComponentName2\r
91 );\r
92 ASSERT_EFI_ERROR (Status);\r
93\r
94 if (FeaturePcdGet (PcdPciBusHotplugDeviceSupport)) {\r
95 //\r
96 // If Hot Plug is supported, install EFI PCI Hot Plug Request protocol.\r
97 //\r
98 Handle = NULL;\r
99 Status = gBS->InstallProtocolInterface (\r
100 &Handle,\r
101 &gEfiPciHotPlugRequestProtocolGuid,\r
102 EFI_NATIVE_INTERFACE,\r
103 &mPciHotPlugRequest\r
104 );\r
105 }\r
106\r
107 return Status;\r
108}\r
109\r
110/**\r
111 Test to see if this driver supports ControllerHandle. Any ControllerHandle\r
112 than contains a gEfiPciRootBridgeIoProtocolGuid protocol can be supported.\r
113\r
114 @param This Protocol instance pointer.\r
115 @param Controller Handle of device to test.\r
116 @param RemainingDevicePath Optional parameter use to pick a specific child.\r
117 device to start.\r
118\r
119 @retval EFI_SUCCESS This driver supports this device.\r
120 @retval EFI_ALREADY_STARTED This driver is already running on this device.\r
121 @retval other This driver does not support this device.\r
122\r
123**/\r
124EFI_STATUS\r
125EFIAPI\r
126PciBusDriverBindingSupported (\r
127 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
128 IN EFI_HANDLE Controller,\r
129 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
130 )\r
131{\r
132 EFI_STATUS Status;\r
133 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r
134 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;\r
135 EFI_DEV_PATH_PTR Node;\r
136\r
137 //\r
138 // Check RemainingDevicePath validation\r
139 //\r
140 if (RemainingDevicePath != NULL) {\r
141 //\r
142 // Check if RemainingDevicePath is the End of Device Path Node, \r
143 // if yes, go on checking other conditions\r
144 //\r
145 if (!IsDevicePathEnd (RemainingDevicePath)) {\r
146 //\r
147 // If RemainingDevicePath isn't the End of Device Path Node,\r
148 // check its validation\r
149 //\r
150 Node.DevPath = RemainingDevicePath;\r
151 if (Node.DevPath->Type != HARDWARE_DEVICE_PATH ||\r
152 Node.DevPath->SubType != HW_PCI_DP ||\r
153 DevicePathNodeLength(Node.DevPath) != sizeof(PCI_DEVICE_PATH)) {\r
154 return EFI_UNSUPPORTED;\r
155 }\r
156 }\r
157 }\r
158\r
159 //\r
160 // Check if Pci Root Bridge IO protocol is installed by platform\r
161 //\r
162 Status = gBS->OpenProtocol (\r
163 Controller,\r
164 &gEfiPciRootBridgeIoProtocolGuid,\r
165 (VOID **) &PciRootBridgeIo,\r
166 This->DriverBindingHandle,\r
167 Controller,\r
168 EFI_OPEN_PROTOCOL_BY_DRIVER\r
169 );\r
170 if (Status == EFI_ALREADY_STARTED) {\r
171 return EFI_SUCCESS;\r
172 }\r
173\r
174 if (EFI_ERROR (Status)) {\r
175 return Status;\r
176 }\r
177\r
178 //\r
179 // Close the I/O Abstraction(s) used to perform the supported test\r
180 //\r
181 gBS->CloseProtocol (\r
182 Controller,\r
183 &gEfiPciRootBridgeIoProtocolGuid,\r
184 This->DriverBindingHandle,\r
185 Controller\r
186 );\r
187\r
188 //\r
189 // Open the EFI Device Path protocol needed to perform the supported test\r
190 //\r
191 Status = gBS->OpenProtocol (\r
192 Controller,\r
193 &gEfiDevicePathProtocolGuid,\r
194 (VOID **) &ParentDevicePath,\r
195 This->DriverBindingHandle,\r
196 Controller,\r
197 EFI_OPEN_PROTOCOL_BY_DRIVER\r
198 );\r
199 if (Status == EFI_ALREADY_STARTED) {\r
200 return EFI_SUCCESS;\r
201 }\r
202\r
203 if (EFI_ERROR (Status)) {\r
204 return Status;\r
205 }\r
206\r
207 //\r
208 // Close protocol, don't use device path protocol in the Support() function\r
209 //\r
210 gBS->CloseProtocol (\r
211 Controller,\r
212 &gEfiDevicePathProtocolGuid,\r
213 This->DriverBindingHandle,\r
214 Controller\r
215 );\r
216\r
217 return EFI_SUCCESS;\r
218}\r
219\r
220/**\r
221 Start this driver on ControllerHandle and enumerate Pci bus and start\r
222 all device under PCI bus.\r
223\r
224 @param This Protocol instance pointer.\r
225 @param Controller Handle of device to bind driver to.\r
226 @param RemainingDevicePath Optional parameter use to pick a specific child.\r
227 device to start.\r
228\r
229 @retval EFI_SUCCESS This driver is added to ControllerHandle.\r
230 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle.\r
231 @retval other This driver does not support this device.\r
232\r
233**/\r
234EFI_STATUS\r
235EFIAPI\r
236PciBusDriverBindingStart (\r
237 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
238 IN EFI_HANDLE Controller,\r
239 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
240 )\r
241{\r
37623a5c 242 EFI_STATUS Status;\r
243 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r
9060e3ec 244\r
245 //\r
246 // Check RemainingDevicePath validation\r
247 //\r
248 if (RemainingDevicePath != NULL) {\r
249 //\r
250 // Check if RemainingDevicePath is the End of Device Path Node, \r
251 // if yes, return EFI_SUCCESS\r
252 //\r
253 if (IsDevicePathEnd (RemainingDevicePath)) {\r
254 return EFI_SUCCESS;\r
255 }\r
256 }\r
257\r
258 Status = gBS->LocateProtocol (\r
259 &gEfiIncompatiblePciDeviceSupportProtocolGuid,\r
260 NULL,\r
261 (VOID **) &gEfiIncompatiblePciDeviceSupport\r
262 );\r
263\r
264 //\r
265 // If PCI Platform protocol is available, get it now.\r
266 // If the platform implements this, it must be installed before BDS phase\r
267 //\r
268 gPciPlatformProtocol = NULL;\r
269 gBS->LocateProtocol (\r
270 &gEfiPciPlatformProtocolGuid,\r
271 NULL,\r
272 (VOID **) &gPciPlatformProtocol\r
273 );\r
274\r
275 //\r
276 // If PCI Platform protocol doesn't exist, try to Pci Override Protocol.\r
277 //\r
278 if (gPciPlatformProtocol == NULL) { \r
279 gPciOverrideProtocol = NULL;\r
280 gBS->LocateProtocol (\r
281 &gEfiPciOverrideProtocolGuid,\r
282 NULL,\r
283 (VOID **) &gPciOverrideProtocol\r
284 );\r
285 } \r
286\r
5624a27d
WL
287 if (PcdGetBool (PcdPciDisableBusEnumeration)) {\r
288 gFullEnumeration = FALSE;\r
289 } else {\r
290 gFullEnumeration = (BOOLEAN) ((SearchHostBridgeHandle (Controller) ? FALSE : TRUE));\r
291 }\r
9060e3ec 292\r
37623a5c 293 //\r
294 // Open Device Path Protocol for PCI root bridge\r
295 //\r
296 Status = gBS->OpenProtocol (\r
297 Controller,\r
298 &gEfiDevicePathProtocolGuid,\r
299 (VOID **) &ParentDevicePath,\r
300 This->DriverBindingHandle,\r
301 Controller,\r
302 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
303 ); \r
304 ASSERT_EFI_ERROR (Status);\r
305\r
306 //\r
307 // Report Status Code to indicate PCI bus starts\r
308 //\r
309 REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
310 EFI_PROGRESS_CODE,\r
311 (EFI_IO_BUS_PCI | EFI_IOB_PC_INIT),\r
312 ParentDevicePath\r
313 );\r
314\r
9060e3ec 315 //\r
316 // Enumerate the entire host bridge\r
317 // After enumeration, a database that records all the device information will be created\r
318 //\r
319 //\r
320 Status = PciEnumerator (Controller);\r
321\r
322 if (EFI_ERROR (Status)) {\r
323 return Status;\r
324 }\r
325\r
326 //\r
327 // Start all the devices under the entire host bridge.\r
328 //\r
329 StartPciDevices (Controller);\r
330\r
331 return EFI_SUCCESS;\r
332}\r
333\r
334/**\r
335 Stop this driver on ControllerHandle. Support stoping any child handles\r
336 created by this driver.\r
337\r
338 @param This Protocol instance pointer.\r
339 @param Controller Handle of device to stop driver on.\r
340 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r
341 children is zero stop the entire bus driver.\r
342 @param ChildHandleBuffer List of Child Handles to Stop.\r
343\r
344 @retval EFI_SUCCESS This driver is removed ControllerHandle.\r
345 @retval other This driver was not removed from this device.\r
346\r
347**/\r
348EFI_STATUS\r
349EFIAPI\r
350PciBusDriverBindingStop (\r
351 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
352 IN EFI_HANDLE Controller,\r
353 IN UINTN NumberOfChildren,\r
354 IN EFI_HANDLE *ChildHandleBuffer\r
355 )\r
356{\r
357 EFI_STATUS Status;\r
358 UINTN Index;\r
359 BOOLEAN AllChildrenStopped;\r
360\r
361 if (NumberOfChildren == 0) {\r
362 //\r
363 // Close the bus driver\r
364 //\r
365 gBS->CloseProtocol (\r
366 Controller,\r
367 &gEfiDevicePathProtocolGuid,\r
368 This->DriverBindingHandle,\r
369 Controller\r
370 );\r
371 gBS->CloseProtocol (\r
372 Controller,\r
373 &gEfiPciRootBridgeIoProtocolGuid,\r
374 This->DriverBindingHandle,\r
375 Controller\r
376 );\r
377\r
378 DestroyRootBridgeByHandle (\r
379 Controller\r
380 );\r
381\r
382 return EFI_SUCCESS;\r
383 }\r
384\r
385 //\r
386 // Stop all the children\r
387 //\r
388\r
389 AllChildrenStopped = TRUE;\r
390\r
391 for (Index = 0; Index < NumberOfChildren; Index++) {\r
392\r
393 //\r
394 // De register all the pci device\r
395 //\r
396 Status = DeRegisterPciDevice (Controller, ChildHandleBuffer[Index]);\r
397\r
398 if (EFI_ERROR (Status)) {\r
399 AllChildrenStopped = FALSE;\r
400 }\r
401 }\r
402\r
403 if (!AllChildrenStopped) {\r
404 return EFI_DEVICE_ERROR;\r
405 }\r
406\r
407 return EFI_SUCCESS;\r
408}\r
409\r