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
12 All rights reserved. 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
;
45 GLOBAL_REMOVE_IF_UNREFERENCED EFI_PCI_HOTPLUG_REQUEST_PROTOCOL mPciHotPlugRequest
= {
46 PciHotPlugRequestNotify
50 The Entry Point for PCI Bus module. The user code starts with this function.
52 Installs driver module protocols and. Creates virtual device handles for ConIn,
53 ConOut, and StdErr. Installs Simple Text In protocol, Simple Text In Ex protocol,
54 Simple Pointer protocol, Absolute Pointer protocol on those virtual handlers.
55 Installs Graphics Output protocol and/or UGA Draw protocol if needed.
57 @param[in] ImageHandle The firmware allocated handle for the EFI image.
58 @param[in] SystemTable A pointer to the EFI System Table.
60 @retval EFI_SUCCESS The entry point is executed successfully.
61 @retval other Some error occurred when executing this entry point.
67 IN EFI_HANDLE ImageHandle
,
68 IN EFI_SYSTEM_TABLE
*SystemTable
75 // Initializes PCI devices pool
77 InitializePciDevicePool ();
80 // Install driver model protocol(s).
82 Status
= EfiLibInstallDriverBindingComponentName2 (
85 &gPciBusDriverBinding
,
87 &gPciBusComponentName
,
88 &gPciBusComponentName2
90 ASSERT_EFI_ERROR (Status
);
92 if (FeaturePcdGet (PcdPciBusHotplugDeviceSupport
)) {
94 // If Hot Plug is supported, install EFI PCI Hot Plug Request protocol.
97 Status
= gBS
->InstallProtocolInterface (
99 &gEfiPciHotPlugRequestProtocolGuid
,
100 EFI_NATIVE_INTERFACE
,
109 Test to see if this driver supports ControllerHandle. Any ControllerHandle
110 than contains a gEfiPciRootBridgeIoProtocolGuid protocol can be supported.
112 @param This Protocol instance pointer.
113 @param Controller Handle of device to test.
114 @param RemainingDevicePath Optional parameter use to pick a specific child.
117 @retval EFI_SUCCESS This driver supports this device.
118 @retval EFI_ALREADY_STARTED This driver is already running on this device.
119 @retval other This driver does not support this device.
124 PciBusDriverBindingSupported (
125 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
126 IN EFI_HANDLE Controller
,
127 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
131 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
132 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
133 EFI_DEV_PATH_PTR Node
;
136 // Check RemainingDevicePath validation
138 if (RemainingDevicePath
!= NULL
) {
140 // Check if RemainingDevicePath is the End of Device Path Node,
141 // if yes, go on checking other conditions
143 if (!IsDevicePathEnd (RemainingDevicePath
)) {
145 // If RemainingDevicePath isn't the End of Device Path Node,
146 // check its validation
148 Node
.DevPath
= RemainingDevicePath
;
149 if (Node
.DevPath
->Type
!= HARDWARE_DEVICE_PATH
||
150 Node
.DevPath
->SubType
!= HW_PCI_DP
||
151 DevicePathNodeLength(Node
.DevPath
) != sizeof(PCI_DEVICE_PATH
)) {
152 return EFI_UNSUPPORTED
;
158 // Check if Pci Root Bridge IO protocol is installed by platform
160 Status
= gBS
->OpenProtocol (
162 &gEfiPciRootBridgeIoProtocolGuid
,
163 (VOID
**) &PciRootBridgeIo
,
164 This
->DriverBindingHandle
,
166 EFI_OPEN_PROTOCOL_BY_DRIVER
168 if (Status
== EFI_ALREADY_STARTED
) {
172 if (EFI_ERROR (Status
)) {
177 // Close the I/O Abstraction(s) used to perform the supported test
181 &gEfiPciRootBridgeIoProtocolGuid
,
182 This
->DriverBindingHandle
,
187 // Open the EFI Device Path protocol needed to perform the supported test
189 Status
= gBS
->OpenProtocol (
191 &gEfiDevicePathProtocolGuid
,
192 (VOID
**) &ParentDevicePath
,
193 This
->DriverBindingHandle
,
195 EFI_OPEN_PROTOCOL_BY_DRIVER
197 if (Status
== EFI_ALREADY_STARTED
) {
201 if (EFI_ERROR (Status
)) {
206 // Close protocol, don't use device path protocol in the Support() function
210 &gEfiDevicePathProtocolGuid
,
211 This
->DriverBindingHandle
,
219 Start this driver on ControllerHandle and enumerate Pci bus and start
220 all device under PCI bus.
222 @param This Protocol instance pointer.
223 @param Controller Handle of device to bind driver to.
224 @param RemainingDevicePath Optional parameter use to pick a specific child.
227 @retval EFI_SUCCESS This driver is added to ControllerHandle.
228 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle.
229 @retval other This driver does not support this device.
234 PciBusDriverBindingStart (
235 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
236 IN EFI_HANDLE Controller
,
237 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
243 // Check RemainingDevicePath validation
245 if (RemainingDevicePath
!= NULL
) {
247 // Check if RemainingDevicePath is the End of Device Path Node,
248 // if yes, return EFI_SUCCESS
250 if (IsDevicePathEnd (RemainingDevicePath
)) {
255 Status
= gBS
->LocateProtocol (
256 &gEfiIncompatiblePciDeviceSupportProtocolGuid
,
258 (VOID
**) &gEfiIncompatiblePciDeviceSupport
262 // If PCI Platform protocol is available, get it now.
263 // If the platform implements this, it must be installed before BDS phase
265 gPciPlatformProtocol
= NULL
;
266 gBS
->LocateProtocol (
267 &gEfiPciPlatformProtocolGuid
,
269 (VOID
**) &gPciPlatformProtocol
272 gFullEnumeration
= (BOOLEAN
) ((SearchHostBridgeHandle (Controller
) ? FALSE
: TRUE
));
275 // Enumerate the entire host bridge
276 // After enumeration, a database that records all the device information will be created
279 Status
= PciEnumerator (Controller
);
281 if (EFI_ERROR (Status
)) {
286 // Start all the devices under the entire host bridge.
288 StartPciDevices (Controller
);
294 Stop this driver on ControllerHandle. Support stoping any child handles
295 created by this driver.
297 @param This Protocol instance pointer.
298 @param Controller Handle of device to stop driver on.
299 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
300 children is zero stop the entire bus driver.
301 @param ChildHandleBuffer List of Child Handles to Stop.
303 @retval EFI_SUCCESS This driver is removed ControllerHandle.
304 @retval other This driver was not removed from this device.
309 PciBusDriverBindingStop (
310 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
311 IN EFI_HANDLE Controller
,
312 IN UINTN NumberOfChildren
,
313 IN EFI_HANDLE
*ChildHandleBuffer
318 BOOLEAN AllChildrenStopped
;
320 if (NumberOfChildren
== 0) {
322 // Close the bus driver
326 &gEfiDevicePathProtocolGuid
,
327 This
->DriverBindingHandle
,
332 &gEfiPciRootBridgeIoProtocolGuid
,
333 This
->DriverBindingHandle
,
337 DestroyRootBridgeByHandle (
345 // Stop all the children
348 AllChildrenStopped
= TRUE
;
350 for (Index
= 0; Index
< NumberOfChildren
; Index
++) {
353 // De register all the pci device
355 Status
= DeRegisterPciDevice (Controller
, ChildHandleBuffer
[Index
]);
357 if (EFI_ERROR (Status
)) {
358 AllChildrenStopped
= FALSE
;
362 if (!AllChildrenStopped
) {
363 return EFI_DEVICE_ERROR
;