3 Copyright (c) 2005 - 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.
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
;
79 // PCI Bus Driver Support Functions
84 IN EFI_HANDLE ImageHandle
,
85 IN EFI_SYSTEM_TABLE
*SystemTable
91 Initialize the global variables
92 publish the driver binding protocol
96 IN EFI_HANDLE ImageHandle,
97 IN EFI_SYSTEM_TABLE *SystemTable
109 // Initialize the EFI Driver Library
111 Status
= EfiLibInstallDriverBindingComponentName2 (
114 &gPciBusDriverBinding
,
116 &gPciBusComponentName
,
117 &gPciBusComponentName2
119 ASSERT_EFI_ERROR (Status
);
121 InitializePciDevicePool ();
123 gFullEnumeration
= TRUE
;
130 PciBusDriverBindingSupported (
131 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
132 IN EFI_HANDLE Controller
,
133 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
139 Check to see if pci bus driver supports the given controller
143 IN EFI_DRIVER_BINDING_PROTOCOL *This,
144 IN EFI_HANDLE Controller,
145 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
154 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
155 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
156 EFI_DEV_PATH_PTR Node
;
158 if (RemainingDevicePath
!= NULL
) {
159 Node
.DevPath
= RemainingDevicePath
;
160 if (Node
.DevPath
->Type
!= HARDWARE_DEVICE_PATH
||
161 Node
.DevPath
->SubType
!= HW_PCI_DP
||
162 DevicePathNodeLength(Node
.DevPath
) != sizeof(PCI_DEVICE_PATH
)) {
163 return EFI_UNSUPPORTED
;
167 // Open the IO Abstraction(s) needed to perform the supported test
169 Status
= gBS
->OpenProtocol (
171 &gEfiDevicePathProtocolGuid
,
172 (VOID
**) &ParentDevicePath
,
173 This
->DriverBindingHandle
,
175 EFI_OPEN_PROTOCOL_BY_DRIVER
177 if (Status
== EFI_ALREADY_STARTED
) {
181 if (EFI_ERROR (Status
)) {
187 &gEfiDevicePathProtocolGuid
,
188 This
->DriverBindingHandle
,
192 Status
= gBS
->OpenProtocol (
194 &gEfiPciRootBridgeIoProtocolGuid
,
195 (VOID
**) &PciRootBridgeIo
,
196 This
->DriverBindingHandle
,
198 EFI_OPEN_PROTOCOL_BY_DRIVER
200 if (Status
== EFI_ALREADY_STARTED
) {
204 if (EFI_ERROR (Status
)) {
210 &gEfiPciRootBridgeIoProtocolGuid
,
211 This
->DriverBindingHandle
,
220 PciBusDriverBindingStart (
221 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
222 IN EFI_HANDLE Controller
,
223 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
229 Start to management the controller passed in
233 IN EFI_DRIVER_BINDING_PROTOCOL *This,
234 IN EFI_HANDLE Controller,
235 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
245 // Enumerate the entire host bridge
246 // After enumeration, a database that records all the device information will be created
249 Status
= PciEnumerator (Controller
);
251 if (EFI_ERROR (Status
)) {
256 // Enable PCI device specified by remaining device path. BDS or other driver can call the
257 // start more than once.
260 StartPciDevices (Controller
, RemainingDevicePath
);
267 PciBusDriverBindingStop (
268 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
269 IN EFI_HANDLE Controller
,
270 IN UINTN NumberOfChildren
,
271 IN EFI_HANDLE
*ChildHandleBuffer
277 Stop one or more children created at start of pci bus driver
278 if all the the children get closed, close the protocol
282 IN EFI_DRIVER_BINDING_PROTOCOL *This,
283 IN EFI_HANDLE Controller,
284 IN UINTN NumberOfChildren,
285 IN EFI_HANDLE *ChildHandleBuffer
294 BOOLEAN AllChildrenStopped
;
296 if (NumberOfChildren
== 0) {
298 // Close the bus driver
302 &gEfiDevicePathProtocolGuid
,
303 This
->DriverBindingHandle
,
308 &gEfiPciRootBridgeIoProtocolGuid
,
309 This
->DriverBindingHandle
,
313 DestroyRootBridgeByHandle (
321 // Stop all the children
324 AllChildrenStopped
= TRUE
;
326 for (Index
= 0; Index
< NumberOfChildren
; Index
++) {
329 // De register all the pci device
331 Status
= DeRegisterPciDevice (Controller
, ChildHandleBuffer
[Index
]);
333 if (EFI_ERROR (Status
)) {
334 AllChildrenStopped
= FALSE
;
338 if (!AllChildrenStopped
) {
339 return EFI_DEVICE_ERROR
;