3 Copyright (c) 2005 - 2006, Intel Corporation. All rights reserved.<BR>
4 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.
27 // PCI Bus Support Function Prototypes
33 IN EFI_HANDLE ImageHandle
,
34 IN EFI_SYSTEM_TABLE
*SystemTable
39 PciBusDriverBindingSupported (
40 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
41 IN EFI_HANDLE Controller
,
42 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
47 PciBusDriverBindingStart (
48 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
49 IN EFI_HANDLE Controller
,
50 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
55 PciBusDriverBindingStop (
56 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
57 IN EFI_HANDLE Controller
,
58 IN UINTN NumberOfChildren
,
59 IN EFI_HANDLE
*ChildHandleBuffer
64 // PCI Bus Driver Global Variables
67 EFI_DRIVER_BINDING_PROTOCOL gPciBusDriverBinding
= {
68 PciBusDriverBindingSupported
,
69 PciBusDriverBindingStart
,
70 PciBusDriverBindingStop
,
76 BOOLEAN gFullEnumeration
;
78 UINT64 gAllOne
= 0xFFFFFFFFFFFFFFFFULL
;
82 // PCI Bus Driver Support Functions
87 IN EFI_HANDLE ImageHandle
,
88 IN EFI_SYSTEM_TABLE
*SystemTable
94 Initialize the global variables
95 publish the driver binding protocol
99 IN EFI_HANDLE ImageHandle,
100 IN EFI_SYSTEM_TABLE *SystemTable
112 // Initialize the EFI Driver Library
114 Status
= EfiLibInstallDriverBindingComponentName2 (
117 &gPciBusDriverBinding
,
119 &gPciBusComponentName
,
120 &gPciBusComponentName2
122 ASSERT_EFI_ERROR (Status
);
124 InitializePciDevicePool ();
126 gFullEnumeration
= TRUE
;
133 PciBusDriverBindingSupported (
134 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
135 IN EFI_HANDLE Controller
,
136 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
142 Check to see if pci bus driver supports the given controller
146 IN EFI_DRIVER_BINDING_PROTOCOL *This,
147 IN EFI_HANDLE Controller,
148 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
157 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
158 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
159 EFI_DEV_PATH_PTR Node
;
161 if (RemainingDevicePath
!= NULL
) {
162 Node
.DevPath
= RemainingDevicePath
;
163 if (Node
.DevPath
->Type
!= HARDWARE_DEVICE_PATH
||
164 Node
.DevPath
->SubType
!= HW_PCI_DP
||
165 DevicePathNodeLength(Node
.DevPath
) != sizeof(PCI_DEVICE_PATH
)) {
166 return EFI_UNSUPPORTED
;
170 // Open the IO Abstraction(s) needed to perform the supported test
172 Status
= gBS
->OpenProtocol (
174 &gEfiDevicePathProtocolGuid
,
175 (VOID
**) &ParentDevicePath
,
176 This
->DriverBindingHandle
,
178 EFI_OPEN_PROTOCOL_BY_DRIVER
180 if (Status
== EFI_ALREADY_STARTED
) {
184 if (EFI_ERROR (Status
)) {
190 &gEfiDevicePathProtocolGuid
,
191 This
->DriverBindingHandle
,
195 Status
= gBS
->OpenProtocol (
197 &gEfiPciRootBridgeIoProtocolGuid
,
198 (VOID
**) &PciRootBridgeIo
,
199 This
->DriverBindingHandle
,
201 EFI_OPEN_PROTOCOL_BY_DRIVER
203 if (Status
== EFI_ALREADY_STARTED
) {
207 if (EFI_ERROR (Status
)) {
213 &gEfiPciRootBridgeIoProtocolGuid
,
214 This
->DriverBindingHandle
,
223 PciBusDriverBindingStart (
224 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
225 IN EFI_HANDLE Controller
,
226 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
232 Start to management the controller passed in
236 IN EFI_DRIVER_BINDING_PROTOCOL *This,
237 IN EFI_HANDLE Controller,
238 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
248 // Enumerate the entire host bridge
249 // After enumeration, a database that records all the device information will be created
252 Status
= PciEnumerator (Controller
);
254 if (EFI_ERROR (Status
)) {
259 // Enable PCI device specified by remaining device path. BDS or other driver can call the
260 // start more than once.
263 StartPciDevices (Controller
, RemainingDevicePath
);
270 PciBusDriverBindingStop (
271 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
272 IN EFI_HANDLE Controller
,
273 IN UINTN NumberOfChildren
,
274 IN EFI_HANDLE
*ChildHandleBuffer
280 Stop one or more children created at start of pci bus driver
281 if all the the children get closed, close the protocol
285 IN EFI_DRIVER_BINDING_PROTOCOL *This,
286 IN EFI_HANDLE Controller,
287 IN UINTN NumberOfChildren,
288 IN EFI_HANDLE *ChildHandleBuffer
297 BOOLEAN AllChildrenStopped
;
299 if (NumberOfChildren
== 0) {
301 // Close the bus driver
305 &gEfiDevicePathProtocolGuid
,
306 This
->DriverBindingHandle
,
311 &gEfiPciRootBridgeIoProtocolGuid
,
312 This
->DriverBindingHandle
,
316 DestroyRootBridgeByHandle (
324 // Stop all the children
327 AllChildrenStopped
= TRUE
;
329 for (Index
= 0; Index
< NumberOfChildren
; Index
++) {
332 // De register all the pci device
334 Status
= DeRegisterPciDevice (Controller
, ChildHandleBuffer
[Index
]);
336 if (EFI_ERROR (Status
)) {
337 AllChildrenStopped
= FALSE
;
341 if (!AllChildrenStopped
) {
342 return EFI_DEVICE_ERROR
;