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;
86 // Install driver model protocol(s).
88 Status
= EfiLibInstallAllDriverProtocols (
91 &gPciBusDriverBinding
,
93 &gPciBusComponentName
,
97 ASSERT_EFI_ERROR (Status
);
99 InstallHotPlugRequestProtocol (&Status
);
106 PciBusDriverBindingSupported (
107 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
108 IN EFI_HANDLE Controller
,
109 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
115 Check to see if pci bus driver supports the given controller
119 IN EFI_DRIVER_BINDING_PROTOCOL *This,
120 IN EFI_HANDLE Controller,
121 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
128 // TODO: This - add argument and description to function comment
129 // TODO: Controller - add argument and description to function comment
130 // TODO: RemainingDevicePath - add argument and description to function comment
131 // TODO: EFI_UNSUPPORTED - add return value to function comment
134 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
135 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
136 EFI_DEV_PATH_PTR Node
;
138 if (RemainingDevicePath
!= NULL
) {
139 Node
.DevPath
= RemainingDevicePath
;
140 if (Node
.DevPath
->Type
!= HARDWARE_DEVICE_PATH
||
141 Node
.DevPath
->SubType
!= HW_PCI_DP
||
142 DevicePathNodeLength(Node
.DevPath
) != sizeof(PCI_DEVICE_PATH
)) {
143 return EFI_UNSUPPORTED
;
147 // Open the IO Abstraction(s) needed to perform the supported test
149 Status
= gBS
->OpenProtocol (
151 &gEfiDevicePathProtocolGuid
,
152 (VOID
**) &ParentDevicePath
,
153 This
->DriverBindingHandle
,
155 EFI_OPEN_PROTOCOL_BY_DRIVER
157 if (Status
== EFI_ALREADY_STARTED
) {
161 if (EFI_ERROR (Status
)) {
167 &gEfiDevicePathProtocolGuid
,
168 This
->DriverBindingHandle
,
172 Status
= gBS
->OpenProtocol (
174 &gEfiPciRootBridgeIoProtocolGuid
,
175 (VOID
**) &PciRootBridgeIo
,
176 This
->DriverBindingHandle
,
178 EFI_OPEN_PROTOCOL_BY_DRIVER
180 if (Status
== EFI_ALREADY_STARTED
) {
184 if (EFI_ERROR (Status
)) {
190 &gEfiPciRootBridgeIoProtocolGuid
,
191 This
->DriverBindingHandle
,
200 PciBusDriverBindingStart (
201 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
202 IN EFI_HANDLE Controller
,
203 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
209 Start to management the controller passed in
213 IN EFI_DRIVER_BINDING_PROTOCOL *This,
214 IN EFI_HANDLE Controller,
215 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
221 // TODO: This - add argument and description to function comment
222 // TODO: Controller - add argument and description to function comment
223 // TODO: RemainingDevicePath - add argument and description to function comment
224 // TODO: EFI_SUCCESS - add return value to function comment
229 // If PCI Platform protocol is available, get it now.
230 // If the platform implements this, it must be installed before BDS phase
232 gPciPlatformProtocol
= NULL
;
233 gBS
->LocateProtocol (
234 &gEfiPciPlatformProtocolGuid
,
236 (VOID
**) &gPciPlatformProtocol
239 gFullEnumeration
= (BOOLEAN
) ((SearchHostBridgeHandle (Controller
) ? FALSE
: TRUE
));
242 // Enumerate the entire host bridge
243 // After enumeration, a database that records all the device information will be created
246 Status
= PciEnumerator (Controller
);
248 if (EFI_ERROR (Status
)) {
253 // Enable PCI device specified by remaining device path. BDS or other driver can call the
254 // start more than once.
257 StartPciDevices (Controller
, RemainingDevicePath
);
264 PciBusDriverBindingStop (
265 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
266 IN EFI_HANDLE Controller
,
267 IN UINTN NumberOfChildren
,
268 IN EFI_HANDLE
*ChildHandleBuffer
274 Stop one or more children created at start of pci bus driver
275 if all the the children get closed, close the protocol
279 IN EFI_DRIVER_BINDING_PROTOCOL *This,
280 IN EFI_HANDLE Controller,
281 IN UINTN NumberOfChildren,
282 IN EFI_HANDLE *ChildHandleBuffer
288 // TODO: This - add argument and description to function comment
289 // TODO: Controller - add argument and description to function comment
290 // TODO: NumberOfChildren - add argument and description to function comment
291 // TODO: ChildHandleBuffer - add argument and description to function comment
292 // TODO: EFI_SUCCESS - add return value to function comment
293 // TODO: EFI_DEVICE_ERROR - add return value to function comment
294 // TODO: EFI_SUCCESS - add return value to function comment
298 BOOLEAN AllChildrenStopped
;
300 if (NumberOfChildren
== 0) {
302 // Close the bus driver
306 &gEfiDevicePathProtocolGuid
,
307 This
->DriverBindingHandle
,
312 &gEfiPciRootBridgeIoProtocolGuid
,
313 This
->DriverBindingHandle
,
317 DestroyRootBridgeByHandle (
325 // Stop all the children
328 AllChildrenStopped
= TRUE
;
330 for (Index
= 0; Index
< NumberOfChildren
; Index
++) {
333 // De register all the pci device
335 Status
= DeRegisterPciDevice (Controller
, ChildHandleBuffer
[Index
]);
337 if (EFI_ERROR (Status
)) {
338 AllChildrenStopped
= FALSE
;
342 if (!AllChildrenStopped
) {
343 return EFI_DEVICE_ERROR
;