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