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 - 2016, 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
*gIncompatiblePciDeviceSupport
= 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
243 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
246 // Check RemainingDevicePath validation
248 if (RemainingDevicePath
!= NULL
) {
250 // Check if RemainingDevicePath is the End of Device Path Node,
251 // if yes, return EFI_SUCCESS
253 if (IsDevicePathEnd (RemainingDevicePath
)) {
258 gBS
->LocateProtocol (
259 &gEfiIncompatiblePciDeviceSupportProtocolGuid
,
261 (VOID
**) &gIncompatiblePciDeviceSupport
265 // If PCI Platform protocol is available, get it now.
266 // If the platform implements this, it must be installed before BDS phase
268 gPciPlatformProtocol
= NULL
;
269 gBS
->LocateProtocol (
270 &gEfiPciPlatformProtocolGuid
,
272 (VOID
**) &gPciPlatformProtocol
276 // If PCI Platform protocol doesn't exist, try to Pci Override Protocol.
278 if (gPciPlatformProtocol
== NULL
) {
279 gPciOverrideProtocol
= NULL
;
280 gBS
->LocateProtocol (
281 &gEfiPciOverrideProtocolGuid
,
283 (VOID
**) &gPciOverrideProtocol
287 if (PcdGetBool (PcdPciDisableBusEnumeration
)) {
288 gFullEnumeration
= FALSE
;
290 gFullEnumeration
= (BOOLEAN
) ((SearchHostBridgeHandle (Controller
) ? FALSE
: TRUE
));
294 // Open Device Path Protocol for PCI root bridge
296 Status
= gBS
->OpenProtocol (
298 &gEfiDevicePathProtocolGuid
,
299 (VOID
**) &ParentDevicePath
,
300 This
->DriverBindingHandle
,
302 EFI_OPEN_PROTOCOL_GET_PROTOCOL
304 ASSERT_EFI_ERROR (Status
);
307 // Report Status Code to indicate PCI bus starts
309 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
311 (EFI_IO_BUS_PCI
| EFI_IOB_PC_INIT
),
316 // Enumerate the entire host bridge
317 // After enumeration, a database that records all the device information will be created
320 Status
= PciEnumerator (Controller
);
322 if (EFI_ERROR (Status
)) {
327 // Start all the devices under the entire host bridge.
329 StartPciDevices (Controller
);
335 Stop this driver on ControllerHandle. Support stopping any child handles
336 created by this driver.
338 @param This Protocol instance pointer.
339 @param Controller Handle of device to stop driver on.
340 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
341 children is zero stop the entire bus driver.
342 @param ChildHandleBuffer List of Child Handles to Stop.
344 @retval EFI_SUCCESS This driver is removed ControllerHandle.
345 @retval other This driver was not removed from this device.
350 PciBusDriverBindingStop (
351 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
352 IN EFI_HANDLE Controller
,
353 IN UINTN NumberOfChildren
,
354 IN EFI_HANDLE
*ChildHandleBuffer
359 BOOLEAN AllChildrenStopped
;
361 if (NumberOfChildren
== 0) {
363 // Close the bus driver
367 &gEfiDevicePathProtocolGuid
,
368 This
->DriverBindingHandle
,
373 &gEfiPciRootBridgeIoProtocolGuid
,
374 This
->DriverBindingHandle
,
378 DestroyRootBridgeByHandle (
386 // Stop all the children
389 AllChildrenStopped
= TRUE
;
391 for (Index
= 0; Index
< NumberOfChildren
; Index
++) {
394 // De register all the pci device
396 Status
= DeRegisterPciDevice (Controller
, ChildHandleBuffer
[Index
]);
398 if (EFI_ERROR (Status
)) {
399 AllChildrenStopped
= FALSE
;
403 if (!AllChildrenStopped
) {
404 return EFI_DEVICE_ERROR
;