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 - 2019, Intel Corporation. All rights reserved.<BR>
12 SPDX-License-Identifier: BSD-2-Clause-Patent
19 // PCI Bus Driver Global Variables
21 EFI_DRIVER_BINDING_PROTOCOL gPciBusDriverBinding
= {
22 PciBusDriverBindingSupported
,
23 PciBusDriverBindingStart
,
24 PciBusDriverBindingStop
,
30 EFI_HANDLE gPciHostBrigeHandles
[PCI_MAX_HOST_BRIDGE_NUM
];
31 EFI_INCOMPATIBLE_PCI_DEVICE_SUPPORT_PROTOCOL
*gIncompatiblePciDeviceSupport
= NULL
;
32 UINTN gPciHostBridgeNumber
= 0;
33 BOOLEAN gFullEnumeration
= TRUE
;
34 UINT64 gAllOne
= 0xFFFFFFFFFFFFFFFFULL
;
37 EFI_PCI_PLATFORM_PROTOCOL
*gPciPlatformProtocol
;
38 EFI_PCI_OVERRIDE_PROTOCOL
*gPciOverrideProtocol
;
39 EDKII_IOMMU_PROTOCOL
*mIoMmuProtocol
;
40 EDKII_DEVICE_SECURITY_PROTOCOL
*mDeviceSecurityProtocol
;
42 GLOBAL_REMOVE_IF_UNREFERENCED EFI_PCI_HOTPLUG_REQUEST_PROTOCOL mPciHotPlugRequest
= {
43 PciHotPlugRequestNotify
47 The Entry Point for PCI Bus module. The user code starts with this function.
49 Installs driver module protocols and. Creates virtual device handles for ConIn,
50 ConOut, and StdErr. Installs Simple Text In protocol, Simple Text In Ex protocol,
51 Simple Pointer protocol, Absolute Pointer protocol on those virtual handlers.
52 Installs Graphics Output protocol and/or UGA Draw protocol if needed.
54 @param[in] ImageHandle The firmware allocated handle for the EFI image.
55 @param[in] SystemTable A pointer to the EFI System Table.
57 @retval EFI_SUCCESS The entry point is executed successfully.
58 @retval other Some error occurred when executing this entry point.
64 IN EFI_HANDLE ImageHandle
,
65 IN EFI_SYSTEM_TABLE
*SystemTable
72 // Initializes PCI devices pool
74 InitializePciDevicePool ();
77 // Install driver model protocol(s).
79 Status
= EfiLibInstallDriverBindingComponentName2 (
82 &gPciBusDriverBinding
,
84 &gPciBusComponentName
,
85 &gPciBusComponentName2
87 ASSERT_EFI_ERROR (Status
);
89 if (FeaturePcdGet (PcdPciBusHotplugDeviceSupport
)) {
91 // If Hot Plug is supported, install EFI PCI Hot Plug Request protocol.
94 Status
= gBS
->InstallProtocolInterface (
96 &gEfiPciHotPlugRequestProtocolGuid
,
106 Test to see if this driver supports ControllerHandle. Any ControllerHandle
107 than contains a gEfiPciRootBridgeIoProtocolGuid protocol can be supported.
109 @param This Protocol instance pointer.
110 @param Controller Handle of device to test.
111 @param RemainingDevicePath Optional parameter use to pick a specific child
114 @retval EFI_SUCCESS This driver supports this device.
115 @retval EFI_ALREADY_STARTED This driver is already running on this device.
116 @retval other This driver does not support this device.
121 PciBusDriverBindingSupported (
122 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
123 IN EFI_HANDLE Controller
,
124 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
128 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
129 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
130 EFI_DEV_PATH_PTR Node
;
133 // Check RemainingDevicePath validation
135 if (RemainingDevicePath
!= NULL
) {
137 // Check if RemainingDevicePath is the End of Device Path Node,
138 // if yes, go on checking other conditions
140 if (!IsDevicePathEnd (RemainingDevicePath
)) {
142 // If RemainingDevicePath isn't the End of Device Path Node,
143 // check its validation
145 Node
.DevPath
= RemainingDevicePath
;
146 if ((Node
.DevPath
->Type
!= HARDWARE_DEVICE_PATH
) ||
147 (Node
.DevPath
->SubType
!= HW_PCI_DP
) ||
148 (DevicePathNodeLength (Node
.DevPath
) != sizeof (PCI_DEVICE_PATH
)))
150 return EFI_UNSUPPORTED
;
156 // Check if Pci Root Bridge IO protocol is installed by platform
158 Status
= gBS
->OpenProtocol (
160 &gEfiPciRootBridgeIoProtocolGuid
,
161 (VOID
**)&PciRootBridgeIo
,
162 This
->DriverBindingHandle
,
164 EFI_OPEN_PROTOCOL_BY_DRIVER
166 if (Status
== EFI_ALREADY_STARTED
) {
170 if (EFI_ERROR (Status
)) {
175 // Close the I/O Abstraction(s) used to perform the supported test
179 &gEfiPciRootBridgeIoProtocolGuid
,
180 This
->DriverBindingHandle
,
185 // Open the EFI Device Path protocol needed to perform the supported test
187 Status
= gBS
->OpenProtocol (
189 &gEfiDevicePathProtocolGuid
,
190 (VOID
**)&ParentDevicePath
,
191 This
->DriverBindingHandle
,
193 EFI_OPEN_PROTOCOL_BY_DRIVER
195 if (Status
== EFI_ALREADY_STARTED
) {
199 if (EFI_ERROR (Status
)) {
204 // Close protocol, don't use device path protocol in the Support() function
208 &gEfiDevicePathProtocolGuid
,
209 This
->DriverBindingHandle
,
217 Start this driver on ControllerHandle and enumerate Pci bus and start
218 all device under PCI bus.
220 @param This Protocol instance pointer.
221 @param Controller Handle of device to bind driver to.
222 @param RemainingDevicePath Optional parameter use to pick a specific child
225 @retval EFI_SUCCESS This driver is added to ControllerHandle.
226 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle.
227 @retval other This driver does not support this device.
232 PciBusDriverBindingStart (
233 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
234 IN EFI_HANDLE Controller
,
235 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
239 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
240 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
243 // Initialize PciRootBridgeIo to suppress incorrect compiler warning.
245 PciRootBridgeIo
= NULL
;
248 // Check RemainingDevicePath validation
250 if (RemainingDevicePath
!= NULL
) {
252 // Check if RemainingDevicePath is the End of Device Path Node,
253 // if yes, return EFI_SUCCESS
255 if (IsDevicePathEnd (RemainingDevicePath
)) {
260 gBS
->LocateProtocol (
261 &gEfiIncompatiblePciDeviceSupportProtocolGuid
,
263 (VOID
**)&gIncompatiblePciDeviceSupport
267 // If PCI Platform protocol is available, get it now.
268 // If the platform implements this, it must be installed before BDS phase
270 gPciPlatformProtocol
= NULL
;
271 gBS
->LocateProtocol (
272 &gEfiPciPlatformProtocolGuid
,
274 (VOID
**)&gPciPlatformProtocol
278 // If PCI Platform protocol doesn't exist, try to Pci Override Protocol.
280 if (gPciPlatformProtocol
== NULL
) {
281 gPciOverrideProtocol
= NULL
;
282 gBS
->LocateProtocol (
283 &gEfiPciOverrideProtocolGuid
,
285 (VOID
**)&gPciOverrideProtocol
289 if (mIoMmuProtocol
== NULL
) {
290 gBS
->LocateProtocol (
291 &gEdkiiIoMmuProtocolGuid
,
293 (VOID
**)&mIoMmuProtocol
297 if (mDeviceSecurityProtocol
== NULL
) {
298 gBS
->LocateProtocol (
299 &gEdkiiDeviceSecurityProtocolGuid
,
301 (VOID
**)&mDeviceSecurityProtocol
305 if (PcdGetBool (PcdPciDisableBusEnumeration
)) {
306 gFullEnumeration
= FALSE
;
308 gFullEnumeration
= (BOOLEAN
)((SearchHostBridgeHandle (Controller
) ? FALSE
: TRUE
));
312 // Open Device Path Protocol for PCI root bridge
314 Status
= gBS
->OpenProtocol (
316 &gEfiDevicePathProtocolGuid
,
317 (VOID
**)&ParentDevicePath
,
318 This
->DriverBindingHandle
,
320 EFI_OPEN_PROTOCOL_GET_PROTOCOL
322 ASSERT_EFI_ERROR (Status
);
325 // Report Status Code to indicate PCI bus starts
327 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
329 (EFI_IO_BUS_PCI
| EFI_IOB_PC_INIT
),
333 Status
= EFI_SUCCESS
;
335 // Enumerate the entire host bridge
336 // After enumeration, a database that records all the device information will be created
339 if (gFullEnumeration
) {
341 // Get the rootbridge Io protocol to find the host bridge handle
343 Status
= gBS
->OpenProtocol (
345 &gEfiPciRootBridgeIoProtocolGuid
,
346 (VOID
**)&PciRootBridgeIo
,
347 gPciBusDriverBinding
.DriverBindingHandle
,
349 EFI_OPEN_PROTOCOL_GET_PROTOCOL
352 if (!EFI_ERROR (Status
)) {
353 Status
= PciEnumerator (Controller
, PciRootBridgeIo
->ParentHandle
);
357 // If PCI bus has already done the full enumeration, never do it again
359 Status
= PciEnumeratorLight (Controller
);
362 if (EFI_ERROR (Status
)) {
367 // Start all the devices under the entire host bridge.
369 StartPciDevices (Controller
);
371 if (gFullEnumeration
) {
372 gFullEnumeration
= FALSE
;
374 Status
= gBS
->InstallProtocolInterface (
375 &PciRootBridgeIo
->ParentHandle
,
376 &gEfiPciEnumerationCompleteProtocolGuid
,
377 EFI_NATIVE_INTERFACE
,
380 ASSERT_EFI_ERROR (Status
);
387 Stop this driver on ControllerHandle. Support stopping any child handles
388 created by this driver.
390 @param This Protocol instance pointer.
391 @param Controller Handle of device to stop driver on.
392 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
393 children is zero stop the entire bus driver.
394 @param ChildHandleBuffer List of Child Handles to Stop.
396 @retval EFI_SUCCESS This driver is removed ControllerHandle.
397 @retval other This driver was not removed from this device.
402 PciBusDriverBindingStop (
403 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
404 IN EFI_HANDLE Controller
,
405 IN UINTN NumberOfChildren
,
406 IN EFI_HANDLE
*ChildHandleBuffer
411 BOOLEAN AllChildrenStopped
;
413 if (NumberOfChildren
== 0) {
415 // Close the bus driver
419 &gEfiDevicePathProtocolGuid
,
420 This
->DriverBindingHandle
,
425 &gEfiPciRootBridgeIoProtocolGuid
,
426 This
->DriverBindingHandle
,
430 DestroyRootBridgeByHandle (
438 // Stop all the children
441 AllChildrenStopped
= TRUE
;
443 for (Index
= 0; Index
< NumberOfChildren
; Index
++) {
445 // De register all the pci device
447 Status
= DeRegisterPciDevice (Controller
, ChildHandleBuffer
[Index
]);
449 if (EFI_ERROR (Status
)) {
450 AllChildrenStopped
= FALSE
;
454 if (!AllChildrenStopped
) {
455 return EFI_DEVICE_ERROR
;