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.
18 // PCI Bus Driver Global Variables
21 EFI_DRIVER_BINDING_PROTOCOL gPciBusDriverBinding
= {
22 PciBusDriverBindingSupported
,
23 PciBusDriverBindingStart
,
24 PciBusDriverBindingStop
,
30 EFI_HANDLE gPciHostBrigeHandles
[PCI_MAX_HOST_BRIDGE_NUM
];
31 UINTN gPciHostBridgeNumber
;
32 BOOLEAN gFullEnumeration
;
33 UINT64 gAllOne
= 0xFFFFFFFFFFFFFFFFULL
;
36 EFI_PCI_PLATFORM_PROTOCOL
*gPciPlatformProtocol
;
39 // PCI Bus Driver Support Functions
44 IN EFI_HANDLE ImageHandle
,
45 IN EFI_SYSTEM_TABLE
*SystemTable
51 Initialize the global variables
52 publish the driver binding protocol
56 IN EFI_HANDLE ImageHandle,
57 IN EFI_SYSTEM_TABLE *SystemTable
65 // TODO: ImageHandle - add argument and description to function comment
66 // TODO: SystemTable - add argument and description to function comment
70 InitializePciDevicePool ();
72 gFullEnumeration
= TRUE
;
74 gPciHostBridgeNumber
= 0;
77 // Install driver model protocol(s).
79 Status
= EfiLibInstallAllDriverProtocols (
82 &gPciBusDriverBinding
,
84 &gPciBusComponentName
,
88 ASSERT_EFI_ERROR (Status
);
90 InstallHotPlugRequestProtocol (&Status
);
97 PciBusDriverBindingSupported (
98 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
99 IN EFI_HANDLE Controller
,
100 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
106 Check to see if pci bus driver supports the given controller
110 IN EFI_DRIVER_BINDING_PROTOCOL *This,
111 IN EFI_HANDLE Controller,
112 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
119 // TODO: This - add argument and description to function comment
120 // TODO: Controller - add argument and description to function comment
121 // TODO: RemainingDevicePath - add argument and description to function comment
122 // TODO: EFI_UNSUPPORTED - add return value to function comment
125 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
126 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
127 EFI_DEV_PATH_PTR Node
;
129 if (RemainingDevicePath
!= NULL
) {
130 Node
.DevPath
= RemainingDevicePath
;
131 if (Node
.DevPath
->Type
!= HARDWARE_DEVICE_PATH
||
132 Node
.DevPath
->SubType
!= HW_PCI_DP
||
133 DevicePathNodeLength(Node
.DevPath
) != sizeof(PCI_DEVICE_PATH
)) {
134 return EFI_UNSUPPORTED
;
138 // Open the IO Abstraction(s) needed to perform the supported test
140 Status
= gBS
->OpenProtocol (
142 &gEfiDevicePathProtocolGuid
,
143 (VOID
**) &ParentDevicePath
,
144 This
->DriverBindingHandle
,
146 EFI_OPEN_PROTOCOL_BY_DRIVER
148 if (Status
== EFI_ALREADY_STARTED
) {
152 if (EFI_ERROR (Status
)) {
158 &gEfiDevicePathProtocolGuid
,
159 This
->DriverBindingHandle
,
163 Status
= gBS
->OpenProtocol (
165 &gEfiPciRootBridgeIoProtocolGuid
,
166 (VOID
**) &PciRootBridgeIo
,
167 This
->DriverBindingHandle
,
169 EFI_OPEN_PROTOCOL_BY_DRIVER
171 if (Status
== EFI_ALREADY_STARTED
) {
175 if (EFI_ERROR (Status
)) {
181 &gEfiPciRootBridgeIoProtocolGuid
,
182 This
->DriverBindingHandle
,
191 PciBusDriverBindingStart (
192 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
193 IN EFI_HANDLE Controller
,
194 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
200 Start to management the controller passed in
204 IN EFI_DRIVER_BINDING_PROTOCOL *This,
205 IN EFI_HANDLE Controller,
206 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
212 // TODO: This - add argument and description to function comment
213 // TODO: Controller - add argument and description to function comment
214 // TODO: RemainingDevicePath - add argument and description to function comment
215 // TODO: EFI_SUCCESS - add return value to function comment
220 // If PCI Platform protocol is available, get it now.
221 // If the platform implements this, it must be installed before BDS phase
223 gPciPlatformProtocol
= NULL
;
224 gBS
->LocateProtocol (
225 &gEfiPciPlatformProtocolGuid
,
227 (VOID
**) &gPciPlatformProtocol
230 gFullEnumeration
= (BOOLEAN
) ((SearchHostBridgeHandle (Controller
) ? FALSE
: TRUE
));
233 // Enumerate the entire host bridge
234 // After enumeration, a database that records all the device information will be created
237 Status
= PciEnumerator (Controller
);
239 if (EFI_ERROR (Status
)) {
244 // Enable PCI device specified by remaining device path. BDS or other driver can call the
245 // start more than once.
248 StartPciDevices (Controller
, RemainingDevicePath
);
255 PciBusDriverBindingStop (
256 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
257 IN EFI_HANDLE Controller
,
258 IN UINTN NumberOfChildren
,
259 IN EFI_HANDLE
*ChildHandleBuffer
265 Stop one or more children created at start of pci bus driver
266 if all the the children get closed, close the protocol
270 IN EFI_DRIVER_BINDING_PROTOCOL *This,
271 IN EFI_HANDLE Controller,
272 IN UINTN NumberOfChildren,
273 IN EFI_HANDLE *ChildHandleBuffer
279 // TODO: This - add argument and description to function comment
280 // TODO: Controller - add argument and description to function comment
281 // TODO: NumberOfChildren - add argument and description to function comment
282 // TODO: ChildHandleBuffer - add argument and description to function comment
283 // TODO: EFI_SUCCESS - add return value to function comment
284 // TODO: EFI_DEVICE_ERROR - add return value to function comment
285 // TODO: EFI_SUCCESS - add return value to function comment
289 BOOLEAN AllChildrenStopped
;
291 if (NumberOfChildren
== 0) {
293 // Close the bus driver
297 &gEfiDevicePathProtocolGuid
,
298 This
->DriverBindingHandle
,
303 &gEfiPciRootBridgeIoProtocolGuid
,
304 This
->DriverBindingHandle
,
308 DestroyRootBridgeByHandle (
316 // Stop all the children
319 AllChildrenStopped
= TRUE
;
321 for (Index
= 0; Index
< NumberOfChildren
; Index
++) {
324 // De register all the pci device
326 Status
= DeRegisterPciDevice (Controller
, ChildHandleBuffer
[Index
]);
328 if (EFI_ERROR (Status
)) {
329 AllChildrenStopped
= FALSE
;
333 if (!AllChildrenStopped
) {
334 return EFI_DEVICE_ERROR
;