3 Copyright (c) 2006 - 2007, 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 Driver Global Variables
30 EFI_DRIVER_BINDING_PROTOCOL gPciBusDriverBinding
= {
31 PciBusDriverBindingSupported
,
32 PciBusDriverBindingStart
,
33 PciBusDriverBindingStop
,
39 EFI_HANDLE gPciHostBrigeHandles
[PCI_MAX_HOST_BRIDGE_NUM
];
40 UINTN gPciHostBridgeNumber
;
41 BOOLEAN gFullEnumeration
;
42 UINT64 gAllOne
= 0xFFFFFFFFFFFFFFFFULL
;
45 EFI_PCI_PLATFORM_PROTOCOL
*gPciPlatformProtocol
;
48 // PCI Bus Driver Support Functions
53 IN EFI_HANDLE ImageHandle
,
54 IN EFI_SYSTEM_TABLE
*SystemTable
60 Initialize the global variables
61 publish the driver binding protocol
65 IN EFI_HANDLE ImageHandle,
66 IN EFI_SYSTEM_TABLE *SystemTable
74 // TODO: ImageHandle - add argument and description to function comment
75 // TODO: SystemTable - add argument and description to function comment
79 InitializePciDevicePool ();
81 gFullEnumeration
= TRUE
;
83 gPciHostBridgeNumber
= 0;
85 InstallHotPlugRequestProtocol (&Status
);
91 PciBusDriverBindingSupported (
92 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
93 IN EFI_HANDLE Controller
,
94 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
100 Check to see if pci bus driver supports the given controller
104 IN EFI_DRIVER_BINDING_PROTOCOL *This,
105 IN EFI_HANDLE Controller,
106 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
113 // TODO: This - add argument and description to function comment
114 // TODO: Controller - add argument and description to function comment
115 // TODO: RemainingDevicePath - add argument and description to function comment
116 // TODO: EFI_UNSUPPORTED - add return value to function comment
119 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
120 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
121 EFI_DEV_PATH_PTR Node
;
123 if (RemainingDevicePath
!= NULL
) {
124 Node
.DevPath
= RemainingDevicePath
;
125 if (Node
.DevPath
->Type
!= HARDWARE_DEVICE_PATH
||
126 Node
.DevPath
->SubType
!= HW_PCI_DP
||
127 DevicePathNodeLength(Node
.DevPath
) != sizeof(PCI_DEVICE_PATH
)) {
128 return EFI_UNSUPPORTED
;
132 // Open the IO Abstraction(s) needed to perform the supported test
134 Status
= gBS
->OpenProtocol (
136 &gEfiDevicePathProtocolGuid
,
137 (VOID
**) &ParentDevicePath
,
138 This
->DriverBindingHandle
,
140 EFI_OPEN_PROTOCOL_BY_DRIVER
142 if (Status
== EFI_ALREADY_STARTED
) {
146 if (EFI_ERROR (Status
)) {
152 &gEfiDevicePathProtocolGuid
,
153 This
->DriverBindingHandle
,
157 Status
= gBS
->OpenProtocol (
159 &gEfiPciRootBridgeIoProtocolGuid
,
160 (VOID
**) &PciRootBridgeIo
,
161 This
->DriverBindingHandle
,
163 EFI_OPEN_PROTOCOL_BY_DRIVER
165 if (Status
== EFI_ALREADY_STARTED
) {
169 if (EFI_ERROR (Status
)) {
175 &gEfiPciRootBridgeIoProtocolGuid
,
176 This
->DriverBindingHandle
,
185 PciBusDriverBindingStart (
186 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
187 IN EFI_HANDLE Controller
,
188 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
194 Start to management the controller passed in
198 IN EFI_DRIVER_BINDING_PROTOCOL *This,
199 IN EFI_HANDLE Controller,
200 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
206 // TODO: This - add argument and description to function comment
207 // TODO: Controller - add argument and description to function comment
208 // TODO: RemainingDevicePath - add argument and description to function comment
209 // TODO: EFI_SUCCESS - add return value to function comment
214 // If PCI Platform protocol is available, get it now.
215 // If the platform implements this, it must be installed before BDS phase
217 gPciPlatformProtocol
= NULL
;
218 gBS
->LocateProtocol (
219 &gEfiPciPlatformProtocolGuid
,
221 (VOID
**) &gPciPlatformProtocol
224 gFullEnumeration
= (BOOLEAN
) ((SearchHostBridgeHandle (Controller
) ? FALSE
: TRUE
));
227 // Enumerate the entire host bridge
228 // After enumeration, a database that records all the device information will be created
231 Status
= PciEnumerator (Controller
);
233 if (EFI_ERROR (Status
)) {
238 // Enable PCI device specified by remaining device path. BDS or other driver can call the
239 // start more than once.
242 StartPciDevices (Controller
, RemainingDevicePath
);
249 PciBusDriverBindingStop (
250 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
251 IN EFI_HANDLE Controller
,
252 IN UINTN NumberOfChildren
,
253 IN EFI_HANDLE
*ChildHandleBuffer
259 Stop one or more children created at start of pci bus driver
260 if all the the children get closed, close the protocol
264 IN EFI_DRIVER_BINDING_PROTOCOL *This,
265 IN EFI_HANDLE Controller,
266 IN UINTN NumberOfChildren,
267 IN EFI_HANDLE *ChildHandleBuffer
273 // TODO: This - add argument and description to function comment
274 // TODO: Controller - add argument and description to function comment
275 // TODO: NumberOfChildren - add argument and description to function comment
276 // TODO: ChildHandleBuffer - add argument and description to function comment
277 // TODO: EFI_SUCCESS - add return value to function comment
278 // TODO: EFI_DEVICE_ERROR - add return value to function comment
279 // TODO: EFI_SUCCESS - add return value to function comment
283 BOOLEAN AllChildrenStopped
;
285 if (NumberOfChildren
== 0) {
287 // Close the bus driver
291 &gEfiDevicePathProtocolGuid
,
292 This
->DriverBindingHandle
,
297 &gEfiPciRootBridgeIoProtocolGuid
,
298 This
->DriverBindingHandle
,
302 DestroyRootBridgeByHandle (
310 // Stop all the children
313 AllChildrenStopped
= TRUE
;
315 for (Index
= 0; Index
< NumberOfChildren
; Index
++) {
318 // De register all the pci device
320 Status
= DeRegisterPciDevice (Controller
, ChildHandleBuffer
[Index
]);
322 if (EFI_ERROR (Status
)) {
323 AllChildrenStopped
= FALSE
;
327 if (!AllChildrenStopped
) {
328 return EFI_DEVICE_ERROR
;