3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 // PCI Bus Driver Global Variables
21 EFI_DRIVER_BINDING_PROTOCOL gPciBusDriverBinding
= {
22 PciBusDriverBindingSupported
,
23 PciBusDriverBindingStart
,
24 PciBusDriverBindingStop
,
30 EFI_INCOMPATIBLE_PCI_DEVICE_SUPPORT_PROTOCOL
*gEfiIncompatiblePciDeviceSupport
= NULL
;
31 EFI_HANDLE gPciHostBrigeHandles
[PCI_MAX_HOST_BRIDGE_NUM
];
32 UINTN gPciHostBridgeNumber
;
33 BOOLEAN gFullEnumeration
;
34 UINT64 gAllOne
= 0xFFFFFFFFFFFFFFFFULL
;
37 EFI_PCI_PLATFORM_PROTOCOL
*gPciPlatformProtocol
;
40 // PCI Bus Driver Support Functions
45 IN EFI_HANDLE ImageHandle
,
46 IN EFI_SYSTEM_TABLE
*SystemTable
52 Initialize the global variables
53 publish the driver binding protocol
57 IN EFI_HANDLE ImageHandle,
58 IN EFI_SYSTEM_TABLE *SystemTable
66 // TODO: ImageHandle - add argument and description to function comment
67 // TODO: SystemTable - add argument and description to function comment
71 InitializePciDevicePool ();
73 gFullEnumeration
= TRUE
;
75 gPciHostBridgeNumber
= 0;
78 // Install driver model protocol(s).
80 Status
= EfiLibInstallDriverBindingComponentName2 (
83 &gPciBusDriverBinding
,
85 &gPciBusComponentName
,
86 &gPciBusComponentName2
88 ASSERT_EFI_ERROR (Status
);
90 InstallHotPlugRequestProtocol (&Status
);
97 PciBusDriverBindingSupported (
98 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
99 IN EFI_HANDLE Controller
,
100 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
106 Check to see if pci bus driver supports the given controller
110 IN EFI_DRIVER_BINDING_PROTOCOL *This,
111 IN EFI_HANDLE Controller,
112 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
119 // TODO: This - add argument and description to function comment
120 // TODO: Controller - add argument and description to function comment
121 // TODO: RemainingDevicePath - add argument and description to function comment
122 // TODO: EFI_UNSUPPORTED - add return value to function comment
125 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
126 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
127 EFI_DEV_PATH_PTR Node
;
129 if (RemainingDevicePath
!= NULL
) {
130 Node
.DevPath
= RemainingDevicePath
;
131 if (Node
.DevPath
->Type
!= HARDWARE_DEVICE_PATH
||
132 Node
.DevPath
->SubType
!= HW_PCI_DP
||
133 DevicePathNodeLength(Node
.DevPath
) != sizeof(PCI_DEVICE_PATH
)) {
134 return EFI_UNSUPPORTED
;
138 // Open the IO Abstraction(s) needed to perform the supported test
140 Status
= gBS
->OpenProtocol (
142 &gEfiDevicePathProtocolGuid
,
143 (VOID
**) &ParentDevicePath
,
144 This
->DriverBindingHandle
,
146 EFI_OPEN_PROTOCOL_BY_DRIVER
148 if (Status
== EFI_ALREADY_STARTED
) {
152 if (EFI_ERROR (Status
)) {
158 &gEfiDevicePathProtocolGuid
,
159 This
->DriverBindingHandle
,
163 Status
= gBS
->OpenProtocol (
165 &gEfiPciRootBridgeIoProtocolGuid
,
166 (VOID
**) &PciRootBridgeIo
,
167 This
->DriverBindingHandle
,
169 EFI_OPEN_PROTOCOL_BY_DRIVER
171 if (Status
== EFI_ALREADY_STARTED
) {
175 if (EFI_ERROR (Status
)) {
181 &gEfiPciRootBridgeIoProtocolGuid
,
182 This
->DriverBindingHandle
,
191 PciBusDriverBindingStart (
192 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
193 IN EFI_HANDLE Controller
,
194 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
200 Start to management the controller passed in
204 IN EFI_DRIVER_BINDING_PROTOCOL *This,
205 IN EFI_HANDLE Controller,
206 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
212 // TODO: This - add argument and description to function comment
213 // TODO: Controller - add argument and description to function comment
214 // TODO: RemainingDevicePath - add argument and description to function comment
215 // TODO: EFI_SUCCESS - add return value to function comment
219 Status
= gBS
->LocateProtocol (
220 &gEfiIncompatiblePciDeviceSupportProtocolGuid
,
222 (VOID
**) &gEfiIncompatiblePciDeviceSupport
226 // If PCI Platform protocol is available, get it now.
227 // If the platform implements this, it must be installed before BDS phase
229 gPciPlatformProtocol
= NULL
;
230 gBS
->LocateProtocol (
231 &gEfiPciPlatformProtocolGuid
,
233 (VOID
**) &gPciPlatformProtocol
236 gFullEnumeration
= (BOOLEAN
) ((SearchHostBridgeHandle (Controller
) ? FALSE
: TRUE
));
239 // Enumerate the entire host bridge
240 // After enumeration, a database that records all the device information will be created
243 Status
= PciEnumerator (Controller
);
245 if (EFI_ERROR (Status
)) {
250 // Enable PCI device specified by remaining device path. BDS or other driver can call the
251 // start more than once.
254 StartPciDevices (Controller
, RemainingDevicePath
);
261 PciBusDriverBindingStop (
262 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
263 IN EFI_HANDLE Controller
,
264 IN UINTN NumberOfChildren
,
265 IN EFI_HANDLE
*ChildHandleBuffer
271 Stop one or more children created at start of pci bus driver
272 if all the the children get closed, close the protocol
276 IN EFI_DRIVER_BINDING_PROTOCOL *This,
277 IN EFI_HANDLE Controller,
278 IN UINTN NumberOfChildren,
279 IN EFI_HANDLE *ChildHandleBuffer
285 // TODO: This - add argument and description to function comment
286 // TODO: Controller - add argument and description to function comment
287 // TODO: NumberOfChildren - add argument and description to function comment
288 // TODO: ChildHandleBuffer - add argument and description to function comment
289 // TODO: EFI_SUCCESS - add return value to function comment
290 // TODO: EFI_DEVICE_ERROR - add return value to function comment
291 // TODO: EFI_SUCCESS - add return value to function comment
295 BOOLEAN AllChildrenStopped
;
297 if (NumberOfChildren
== 0) {
299 // Close the bus driver
303 &gEfiDevicePathProtocolGuid
,
304 This
->DriverBindingHandle
,
309 &gEfiPciRootBridgeIoProtocolGuid
,
310 This
->DriverBindingHandle
,
314 DestroyRootBridgeByHandle (
322 // Stop all the children
325 AllChildrenStopped
= TRUE
;
327 for (Index
= 0; Index
< NumberOfChildren
; Index
++) {
330 // De register all the pci device
332 Status
= DeRegisterPciDevice (Controller
, ChildHandleBuffer
[Index
]);
334 if (EFI_ERROR (Status
)) {
335 AllChildrenStopped
= FALSE
;
339 if (!AllChildrenStopped
) {
340 return EFI_DEVICE_ERROR
;