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.
27 // PCI Bus Driver Global Variables
30 EFI_DRIVER_BINDING_PROTOCOL gPciBusDriverBinding
= {
31 PciBusDriverBindingSupported
,
32 PciBusDriverBindingStart
,
33 PciBusDriverBindingStop
,
39 EFI_INCOMPATIBLE_PCI_DEVICE_SUPPORT_PROTOCOL
*gEfiIncompatiblePciDeviceSupport
= NULL
;
40 EFI_HANDLE gPciHostBrigeHandles
[PCI_MAX_HOST_BRIDGE_NUM
];
41 UINTN gPciHostBridgeNumber
;
42 BOOLEAN gFullEnumeration
;
43 UINT64 gAllOne
= 0xFFFFFFFFFFFFFFFFULL
;
46 EFI_PCI_PLATFORM_PROTOCOL
*gPciPlatformProtocol
;
49 // PCI Bus Driver Support Functions
54 IN EFI_HANDLE ImageHandle
,
55 IN EFI_SYSTEM_TABLE
*SystemTable
61 Initialize the global variables
62 publish the driver binding protocol
66 IN EFI_HANDLE ImageHandle,
67 IN EFI_SYSTEM_TABLE *SystemTable
75 // TODO: ImageHandle - add argument and description to function comment
76 // TODO: SystemTable - add argument and description to function comment
80 InitializePciDevicePool ();
82 gFullEnumeration
= TRUE
;
84 gPciHostBridgeNumber
= 0;
86 InstallHotPlugRequestProtocol (&Status
);
92 PciBusDriverBindingSupported (
93 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
94 IN EFI_HANDLE Controller
,
95 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
101 Check to see if pci bus driver supports the given controller
105 IN EFI_DRIVER_BINDING_PROTOCOL *This,
106 IN EFI_HANDLE Controller,
107 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
114 // TODO: This - add argument and description to function comment
115 // TODO: Controller - add argument and description to function comment
116 // TODO: RemainingDevicePath - add argument and description to function comment
117 // TODO: EFI_UNSUPPORTED - add return value to function comment
120 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
121 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
122 EFI_DEV_PATH_PTR Node
;
124 if (RemainingDevicePath
!= NULL
) {
125 Node
.DevPath
= RemainingDevicePath
;
126 if (Node
.DevPath
->Type
!= HARDWARE_DEVICE_PATH
||
127 Node
.DevPath
->SubType
!= HW_PCI_DP
||
128 DevicePathNodeLength(Node
.DevPath
) != sizeof(PCI_DEVICE_PATH
)) {
129 return EFI_UNSUPPORTED
;
133 // Open the IO Abstraction(s) needed to perform the supported test
135 Status
= gBS
->OpenProtocol (
137 &gEfiDevicePathProtocolGuid
,
138 (VOID
**) &ParentDevicePath
,
139 This
->DriverBindingHandle
,
141 EFI_OPEN_PROTOCOL_BY_DRIVER
143 if (Status
== EFI_ALREADY_STARTED
) {
147 if (EFI_ERROR (Status
)) {
153 &gEfiDevicePathProtocolGuid
,
154 This
->DriverBindingHandle
,
158 Status
= gBS
->OpenProtocol (
160 &gEfiPciRootBridgeIoProtocolGuid
,
161 (VOID
**) &PciRootBridgeIo
,
162 This
->DriverBindingHandle
,
164 EFI_OPEN_PROTOCOL_BY_DRIVER
166 if (Status
== EFI_ALREADY_STARTED
) {
170 if (EFI_ERROR (Status
)) {
176 &gEfiPciRootBridgeIoProtocolGuid
,
177 This
->DriverBindingHandle
,
186 PciBusDriverBindingStart (
187 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
188 IN EFI_HANDLE Controller
,
189 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
195 Start to management the controller passed in
199 IN EFI_DRIVER_BINDING_PROTOCOL *This,
200 IN EFI_HANDLE Controller,
201 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
207 // TODO: This - add argument and description to function comment
208 // TODO: Controller - add argument and description to function comment
209 // TODO: RemainingDevicePath - add argument and description to function comment
210 // TODO: EFI_SUCCESS - add return value to function comment
214 Status
= gBS
->LocateProtocol (
215 &gEfiIncompatiblePciDeviceSupportProtocolGuid
,
217 (VOID
**) &gEfiIncompatiblePciDeviceSupport
221 // If PCI Platform protocol is available, get it now.
222 // If the platform implements this, it must be installed before BDS phase
224 gPciPlatformProtocol
= NULL
;
225 gBS
->LocateProtocol (
226 &gEfiPciPlatformProtocolGuid
,
228 (VOID
**) &gPciPlatformProtocol
231 gFullEnumeration
= (BOOLEAN
) ((SearchHostBridgeHandle (Controller
) ? FALSE
: TRUE
));
234 // Enumerate the entire host bridge
235 // After enumeration, a database that records all the device information will be created
238 Status
= PciEnumerator (Controller
);
240 if (EFI_ERROR (Status
)) {
245 // Enable PCI device specified by remaining device path. BDS or other driver can call the
246 // start more than once.
249 StartPciDevices (Controller
, RemainingDevicePath
);
256 PciBusDriverBindingStop (
257 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
258 IN EFI_HANDLE Controller
,
259 IN UINTN NumberOfChildren
,
260 IN EFI_HANDLE
*ChildHandleBuffer
266 Stop one or more children created at start of pci bus driver
267 if all the the children get closed, close the protocol
271 IN EFI_DRIVER_BINDING_PROTOCOL *This,
272 IN EFI_HANDLE Controller,
273 IN UINTN NumberOfChildren,
274 IN EFI_HANDLE *ChildHandleBuffer
280 // TODO: This - add argument and description to function comment
281 // TODO: Controller - add argument and description to function comment
282 // TODO: NumberOfChildren - add argument and description to function comment
283 // TODO: ChildHandleBuffer - add argument and description to function comment
284 // TODO: EFI_SUCCESS - add return value to function comment
285 // TODO: EFI_DEVICE_ERROR - add return value to function comment
286 // TODO: EFI_SUCCESS - add return value to function comment
290 BOOLEAN AllChildrenStopped
;
292 if (NumberOfChildren
== 0) {
294 // Close the bus driver
298 &gEfiDevicePathProtocolGuid
,
299 This
->DriverBindingHandle
,
304 &gEfiPciRootBridgeIoProtocolGuid
,
305 This
->DriverBindingHandle
,
309 DestroyRootBridgeByHandle (
317 // Stop all the children
320 AllChildrenStopped
= TRUE
;
322 for (Index
= 0; Index
< NumberOfChildren
; Index
++) {
325 // De register all the pci device
327 Status
= DeRegisterPciDevice (Controller
, ChildHandleBuffer
[Index
]);
329 if (EFI_ERROR (Status
)) {
330 AllChildrenStopped
= FALSE
;
334 if (!AllChildrenStopped
) {
335 return EFI_DEVICE_ERROR
;