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 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
63 // PCI Bus Driver Global Variables
66 EFI_DRIVER_BINDING_PROTOCOL gPciBusDriverBinding
= {
67 PciBusDriverBindingSupported
,
68 PciBusDriverBindingStart
,
69 PciBusDriverBindingStop
,
75 EFI_INCOMPATIBLE_PCI_DEVICE_SUPPORT_PROTOCOL
*gEfiIncompatiblePciDeviceSupport
= NULL
;
76 EFI_HANDLE gPciHostBrigeHandles
[PCI_MAX_HOST_BRIDGE_NUM
];
77 UINTN gPciHostBridgeNumber
;
78 BOOLEAN gFullEnumeration
;
79 UINT64 gAllOne
= 0xFFFFFFFFFFFFFFFFULL
;
82 EFI_PCI_PLATFORM_PROTOCOL
*gPciPlatformProtocol
;
85 // PCI Bus Driver Support Functions
90 IN EFI_HANDLE ImageHandle
,
91 IN EFI_SYSTEM_TABLE
*SystemTable
97 Initialize the global variables
98 publish the driver binding protocol
102 IN EFI_HANDLE ImageHandle,
103 IN EFI_SYSTEM_TABLE *SystemTable
111 // TODO: ImageHandle - add argument and description to function comment
112 // TODO: SystemTable - add argument and description to function comment
116 InitializePciDevicePool ();
118 gFullEnumeration
= TRUE
;
120 gPciHostBridgeNumber
= 0;
122 InstallHotPlugRequestProtocol (&Status
);
128 PciBusDriverBindingSupported (
129 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
130 IN EFI_HANDLE Controller
,
131 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
137 Check to see if pci bus driver supports the given controller
141 IN EFI_DRIVER_BINDING_PROTOCOL *This,
142 IN EFI_HANDLE Controller,
143 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
150 // TODO: This - add argument and description to function comment
151 // TODO: Controller - add argument and description to function comment
152 // TODO: RemainingDevicePath - add argument and description to function comment
153 // TODO: EFI_UNSUPPORTED - add return value to function comment
156 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
157 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
158 EFI_DEV_PATH_PTR Node
;
160 if (RemainingDevicePath
!= NULL
) {
161 Node
.DevPath
= RemainingDevicePath
;
162 if (Node
.DevPath
->Type
!= HARDWARE_DEVICE_PATH
||
163 Node
.DevPath
->SubType
!= HW_PCI_DP
||
164 DevicePathNodeLength(Node
.DevPath
) != sizeof(PCI_DEVICE_PATH
)) {
165 return EFI_UNSUPPORTED
;
169 // Open the IO Abstraction(s) needed to perform the supported test
171 Status
= gBS
->OpenProtocol (
173 &gEfiDevicePathProtocolGuid
,
174 (VOID
**) &ParentDevicePath
,
175 This
->DriverBindingHandle
,
177 EFI_OPEN_PROTOCOL_BY_DRIVER
179 if (Status
== EFI_ALREADY_STARTED
) {
183 if (EFI_ERROR (Status
)) {
189 &gEfiDevicePathProtocolGuid
,
190 This
->DriverBindingHandle
,
194 Status
= gBS
->OpenProtocol (
196 &gEfiPciRootBridgeIoProtocolGuid
,
197 (VOID
**) &PciRootBridgeIo
,
198 This
->DriverBindingHandle
,
200 EFI_OPEN_PROTOCOL_BY_DRIVER
202 if (Status
== EFI_ALREADY_STARTED
) {
206 if (EFI_ERROR (Status
)) {
212 &gEfiPciRootBridgeIoProtocolGuid
,
213 This
->DriverBindingHandle
,
222 PciBusDriverBindingStart (
223 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
224 IN EFI_HANDLE Controller
,
225 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
231 Start to management the controller passed in
235 IN EFI_DRIVER_BINDING_PROTOCOL *This,
236 IN EFI_HANDLE Controller,
237 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
243 // TODO: This - add argument and description to function comment
244 // TODO: Controller - add argument and description to function comment
245 // TODO: RemainingDevicePath - add argument and description to function comment
246 // TODO: EFI_SUCCESS - add return value to function comment
250 Status
= gBS
->LocateProtocol (
251 &gEfiIncompatiblePciDeviceSupportProtocolGuid
,
253 (VOID
**) &gEfiIncompatiblePciDeviceSupport
257 // If PCI Platform protocol is available, get it now.
258 // If the platform implements this, it must be installed before BDS phase
260 gPciPlatformProtocol
= NULL
;
261 gBS
->LocateProtocol (
262 &gEfiPciPlatformProtocolGuid
,
264 (VOID
**) &gPciPlatformProtocol
267 gFullEnumeration
= (BOOLEAN
) ((SearchHostBridgeHandle (Controller
) ? FALSE
: TRUE
));
270 // Enumerate the entire host bridge
271 // After enumeration, a database that records all the device information will be created
274 Status
= PciEnumerator (Controller
);
276 if (EFI_ERROR (Status
)) {
281 // Enable PCI device specified by remaining device path. BDS or other driver can call the
282 // start more than once.
285 StartPciDevices (Controller
, RemainingDevicePath
);
292 PciBusDriverBindingStop (
293 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
294 IN EFI_HANDLE Controller
,
295 IN UINTN NumberOfChildren
,
296 IN EFI_HANDLE
*ChildHandleBuffer
302 Stop one or more children created at start of pci bus driver
303 if all the the children get closed, close the protocol
307 IN EFI_DRIVER_BINDING_PROTOCOL *This,
308 IN EFI_HANDLE Controller,
309 IN UINTN NumberOfChildren,
310 IN EFI_HANDLE *ChildHandleBuffer
316 // TODO: This - add argument and description to function comment
317 // TODO: Controller - add argument and description to function comment
318 // TODO: NumberOfChildren - add argument and description to function comment
319 // TODO: ChildHandleBuffer - add argument and description to function comment
320 // TODO: EFI_SUCCESS - add return value to function comment
321 // TODO: EFI_DEVICE_ERROR - add return value to function comment
322 // TODO: EFI_SUCCESS - add return value to function comment
326 BOOLEAN AllChildrenStopped
;
328 if (NumberOfChildren
== 0) {
330 // Close the bus driver
334 &gEfiDevicePathProtocolGuid
,
335 This
->DriverBindingHandle
,
340 &gEfiPciRootBridgeIoProtocolGuid
,
341 This
->DriverBindingHandle
,
345 DestroyRootBridgeByHandle (
353 // Stop all the children
356 AllChildrenStopped
= TRUE
;
358 for (Index
= 0; Index
< NumberOfChildren
; Index
++) {
361 // De register all the pci device
363 Status
= DeRegisterPciDevice (Controller
, ChildHandleBuffer
[Index
]);
365 if (EFI_ERROR (Status
)) {
366 AllChildrenStopped
= FALSE
;
370 if (!AllChildrenStopped
) {
371 return EFI_DEVICE_ERROR
;