2 Driver Binding functions for PCI Bus module.
4 Single PCI bus driver instance will manager all PCI Root Bridges in one EFI based firmware,
5 since all PCI Root Bridges' resources need to be managed together.
6 Supported() function will try to get PCI Root Bridge IO Protocol.
7 Start() function will get PCI Host Bridge Resource Allocation Protocol to manage all
8 PCI Root Bridges. So it means platform needs install PCI Root Bridge IO protocol for each
9 PCI Root Bus and install PCI Host Bridge Resource Allocation Protocol.
11 Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
12 This program and the accompanying materials
13 are licensed and made available under the terms and conditions of the BSD License
14 which accompanies this distribution. The full text of the license may be found at
15 http://opensource.org/licenses/bsd-license.php
17 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
18 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
25 // PCI Bus Driver Global Variables
27 EFI_DRIVER_BINDING_PROTOCOL gPciBusDriverBinding
= {
28 PciBusDriverBindingSupported
,
29 PciBusDriverBindingStart
,
30 PciBusDriverBindingStop
,
36 EFI_HANDLE gPciHostBrigeHandles
[PCI_MAX_HOST_BRIDGE_NUM
];
37 EFI_INCOMPATIBLE_PCI_DEVICE_SUPPORT_PROTOCOL
*gEfiIncompatiblePciDeviceSupport
= NULL
;
38 UINTN gPciHostBridgeNumber
= 0;
39 BOOLEAN gFullEnumeration
= TRUE
;
40 UINT64 gAllOne
= 0xFFFFFFFFFFFFFFFFULL
;
43 EFI_PCI_PLATFORM_PROTOCOL
*gPciPlatformProtocol
;
44 EFI_PCI_OVERRIDE_PROTOCOL
*gPciOverrideProtocol
;
47 GLOBAL_REMOVE_IF_UNREFERENCED EFI_PCI_HOTPLUG_REQUEST_PROTOCOL mPciHotPlugRequest
= {
48 PciHotPlugRequestNotify
52 The Entry Point for PCI Bus module. The user code starts with this function.
54 Installs driver module protocols and. Creates virtual device handles for ConIn,
55 ConOut, and StdErr. Installs Simple Text In protocol, Simple Text In Ex protocol,
56 Simple Pointer protocol, Absolute Pointer protocol on those virtual handlers.
57 Installs Graphics Output protocol and/or UGA Draw protocol if needed.
59 @param[in] ImageHandle The firmware allocated handle for the EFI image.
60 @param[in] SystemTable A pointer to the EFI System Table.
62 @retval EFI_SUCCESS The entry point is executed successfully.
63 @retval other Some error occurred when executing this entry point.
69 IN EFI_HANDLE ImageHandle
,
70 IN EFI_SYSTEM_TABLE
*SystemTable
77 // Initializes PCI devices pool
79 InitializePciDevicePool ();
82 // Install driver model protocol(s).
84 Status
= EfiLibInstallDriverBindingComponentName2 (
87 &gPciBusDriverBinding
,
89 &gPciBusComponentName
,
90 &gPciBusComponentName2
92 ASSERT_EFI_ERROR (Status
);
94 if (FeaturePcdGet (PcdPciBusHotplugDeviceSupport
)) {
96 // If Hot Plug is supported, install EFI PCI Hot Plug Request protocol.
99 Status
= gBS
->InstallProtocolInterface (
101 &gEfiPciHotPlugRequestProtocolGuid
,
102 EFI_NATIVE_INTERFACE
,
111 Test to see if this driver supports ControllerHandle. Any ControllerHandle
112 than contains a gEfiPciRootBridgeIoProtocolGuid protocol can be supported.
114 @param This Protocol instance pointer.
115 @param Controller Handle of device to test.
116 @param RemainingDevicePath Optional parameter use to pick a specific child.
119 @retval EFI_SUCCESS This driver supports this device.
120 @retval EFI_ALREADY_STARTED This driver is already running on this device.
121 @retval other This driver does not support this device.
126 PciBusDriverBindingSupported (
127 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
128 IN EFI_HANDLE Controller
,
129 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
133 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
134 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
135 EFI_DEV_PATH_PTR Node
;
138 // Check RemainingDevicePath validation
140 if (RemainingDevicePath
!= NULL
) {
142 // Check if RemainingDevicePath is the End of Device Path Node,
143 // if yes, go on checking other conditions
145 if (!IsDevicePathEnd (RemainingDevicePath
)) {
147 // If RemainingDevicePath isn't the End of Device Path Node,
148 // check its validation
150 Node
.DevPath
= RemainingDevicePath
;
151 if (Node
.DevPath
->Type
!= HARDWARE_DEVICE_PATH
||
152 Node
.DevPath
->SubType
!= HW_PCI_DP
||
153 DevicePathNodeLength(Node
.DevPath
) != sizeof(PCI_DEVICE_PATH
)) {
154 return EFI_UNSUPPORTED
;
160 // Check if Pci Root Bridge IO protocol is installed by platform
162 Status
= gBS
->OpenProtocol (
164 &gEfiPciRootBridgeIoProtocolGuid
,
165 (VOID
**) &PciRootBridgeIo
,
166 This
->DriverBindingHandle
,
168 EFI_OPEN_PROTOCOL_BY_DRIVER
170 if (Status
== EFI_ALREADY_STARTED
) {
174 if (EFI_ERROR (Status
)) {
179 // Close the I/O Abstraction(s) used to perform the supported test
183 &gEfiPciRootBridgeIoProtocolGuid
,
184 This
->DriverBindingHandle
,
189 // Open the EFI Device Path protocol needed to perform the supported test
191 Status
= gBS
->OpenProtocol (
193 &gEfiDevicePathProtocolGuid
,
194 (VOID
**) &ParentDevicePath
,
195 This
->DriverBindingHandle
,
197 EFI_OPEN_PROTOCOL_BY_DRIVER
199 if (Status
== EFI_ALREADY_STARTED
) {
203 if (EFI_ERROR (Status
)) {
208 // Close protocol, don't use device path protocol in the Support() function
212 &gEfiDevicePathProtocolGuid
,
213 This
->DriverBindingHandle
,
221 Start this driver on ControllerHandle and enumerate Pci bus and start
222 all device under PCI bus.
224 @param This Protocol instance pointer.
225 @param Controller Handle of device to bind driver to.
226 @param RemainingDevicePath Optional parameter use to pick a specific child.
229 @retval EFI_SUCCESS This driver is added to ControllerHandle.
230 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle.
231 @retval other This driver does not support this device.
236 PciBusDriverBindingStart (
237 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
238 IN EFI_HANDLE Controller
,
239 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
245 // Check RemainingDevicePath validation
247 if (RemainingDevicePath
!= NULL
) {
249 // Check if RemainingDevicePath is the End of Device Path Node,
250 // if yes, return EFI_SUCCESS
252 if (IsDevicePathEnd (RemainingDevicePath
)) {
257 Status
= gBS
->LocateProtocol (
258 &gEfiIncompatiblePciDeviceSupportProtocolGuid
,
260 (VOID
**) &gEfiIncompatiblePciDeviceSupport
264 // If PCI Platform protocol is available, get it now.
265 // If the platform implements this, it must be installed before BDS phase
267 gPciPlatformProtocol
= NULL
;
268 gBS
->LocateProtocol (
269 &gEfiPciPlatformProtocolGuid
,
271 (VOID
**) &gPciPlatformProtocol
275 // If PCI Platform protocol doesn't exist, try to Pci Override Protocol.
277 if (gPciPlatformProtocol
== NULL
) {
278 gPciOverrideProtocol
= NULL
;
279 gBS
->LocateProtocol (
280 &gEfiPciOverrideProtocolGuid
,
282 (VOID
**) &gPciOverrideProtocol
286 gFullEnumeration
= (BOOLEAN
) ((SearchHostBridgeHandle (Controller
) ? FALSE
: TRUE
));
289 // Enumerate the entire host bridge
290 // After enumeration, a database that records all the device information will be created
293 Status
= PciEnumerator (Controller
);
295 if (EFI_ERROR (Status
)) {
300 // Start all the devices under the entire host bridge.
302 StartPciDevices (Controller
);
308 Stop this driver on ControllerHandle. Support stoping any child handles
309 created by this driver.
311 @param This Protocol instance pointer.
312 @param Controller Handle of device to stop driver on.
313 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
314 children is zero stop the entire bus driver.
315 @param ChildHandleBuffer List of Child Handles to Stop.
317 @retval EFI_SUCCESS This driver is removed ControllerHandle.
318 @retval other This driver was not removed from this device.
323 PciBusDriverBindingStop (
324 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
325 IN EFI_HANDLE Controller
,
326 IN UINTN NumberOfChildren
,
327 IN EFI_HANDLE
*ChildHandleBuffer
332 BOOLEAN AllChildrenStopped
;
334 if (NumberOfChildren
== 0) {
336 // Close the bus driver
340 &gEfiDevicePathProtocolGuid
,
341 This
->DriverBindingHandle
,
346 &gEfiPciRootBridgeIoProtocolGuid
,
347 This
->DriverBindingHandle
,
351 DestroyRootBridgeByHandle (
359 // Stop all the children
362 AllChildrenStopped
= TRUE
;
364 for (Index
= 0; Index
< NumberOfChildren
; Index
++) {
367 // De register all the pci device
369 Status
= DeRegisterPciDevice (Controller
, ChildHandleBuffer
[Index
]);
371 if (EFI_ERROR (Status
)) {
372 AllChildrenStopped
= FALSE
;
376 if (!AllChildrenStopped
) {
377 return EFI_DEVICE_ERROR
;