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
= EfiLibInstallDriverBindingComponentName2 (
82 &gPciBusDriverBinding
,
84 &gPciBusComponentName
,
85 &gPciBusComponentName2
87 ASSERT_EFI_ERROR (Status
);
89 InstallHotPlugRequestProtocol (&Status
);
96 PciBusDriverBindingSupported (
97 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
98 IN EFI_HANDLE Controller
,
99 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
105 Check to see if pci bus driver supports the given controller
109 IN EFI_DRIVER_BINDING_PROTOCOL *This,
110 IN EFI_HANDLE Controller,
111 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
118 // TODO: This - add argument and description to function comment
119 // TODO: Controller - add argument and description to function comment
120 // TODO: RemainingDevicePath - add argument and description to function comment
121 // TODO: EFI_UNSUPPORTED - add return value to function comment
124 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
125 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
126 EFI_DEV_PATH_PTR Node
;
128 if (RemainingDevicePath
!= NULL
) {
129 Node
.DevPath
= RemainingDevicePath
;
130 if (Node
.DevPath
->Type
!= HARDWARE_DEVICE_PATH
||
131 Node
.DevPath
->SubType
!= HW_PCI_DP
||
132 DevicePathNodeLength(Node
.DevPath
) != sizeof(PCI_DEVICE_PATH
)) {
133 return EFI_UNSUPPORTED
;
137 // Open the IO Abstraction(s) needed to perform the supported test
139 Status
= gBS
->OpenProtocol (
141 &gEfiDevicePathProtocolGuid
,
142 (VOID
**) &ParentDevicePath
,
143 This
->DriverBindingHandle
,
145 EFI_OPEN_PROTOCOL_BY_DRIVER
147 if (Status
== EFI_ALREADY_STARTED
) {
151 if (EFI_ERROR (Status
)) {
157 &gEfiDevicePathProtocolGuid
,
158 This
->DriverBindingHandle
,
162 Status
= gBS
->OpenProtocol (
164 &gEfiPciRootBridgeIoProtocolGuid
,
165 (VOID
**) &PciRootBridgeIo
,
166 This
->DriverBindingHandle
,
168 EFI_OPEN_PROTOCOL_BY_DRIVER
170 if (Status
== EFI_ALREADY_STARTED
) {
174 if (EFI_ERROR (Status
)) {
180 &gEfiPciRootBridgeIoProtocolGuid
,
181 This
->DriverBindingHandle
,
190 PciBusDriverBindingStart (
191 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
192 IN EFI_HANDLE Controller
,
193 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
199 Start to management the controller passed in
203 IN EFI_DRIVER_BINDING_PROTOCOL *This,
204 IN EFI_HANDLE Controller,
205 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
211 // TODO: This - add argument and description to function comment
212 // TODO: Controller - add argument and description to function comment
213 // TODO: RemainingDevicePath - add argument and description to function comment
214 // TODO: EFI_SUCCESS - add return value to function comment
219 // If PCI Platform protocol is available, get it now.
220 // If the platform implements this, it must be installed before BDS phase
222 gPciPlatformProtocol
= NULL
;
223 gBS
->LocateProtocol (
224 &gEfiPciPlatformProtocolGuid
,
226 (VOID
**) &gPciPlatformProtocol
229 gFullEnumeration
= (BOOLEAN
) ((SearchHostBridgeHandle (Controller
) ? FALSE
: TRUE
));
232 // Enumerate the entire host bridge
233 // After enumeration, a database that records all the device information will be created
236 Status
= PciEnumerator (Controller
);
238 if (EFI_ERROR (Status
)) {
243 // Enable PCI device specified by remaining device path. BDS or other driver can call the
244 // start more than once.
247 StartPciDevices (Controller
, RemainingDevicePath
);
254 PciBusDriverBindingStop (
255 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
256 IN EFI_HANDLE Controller
,
257 IN UINTN NumberOfChildren
,
258 IN EFI_HANDLE
*ChildHandleBuffer
264 Stop one or more children created at start of pci bus driver
265 if all the the children get closed, close the protocol
269 IN EFI_DRIVER_BINDING_PROTOCOL *This,
270 IN EFI_HANDLE Controller,
271 IN UINTN NumberOfChildren,
272 IN EFI_HANDLE *ChildHandleBuffer
278 // TODO: This - add argument and description to function comment
279 // TODO: Controller - add argument and description to function comment
280 // TODO: NumberOfChildren - add argument and description to function comment
281 // TODO: ChildHandleBuffer - add argument and description to function comment
282 // TODO: EFI_SUCCESS - add return value to function comment
283 // TODO: EFI_DEVICE_ERROR - add return value to function comment
284 // TODO: EFI_SUCCESS - add return value to function comment
288 BOOLEAN AllChildrenStopped
;
290 if (NumberOfChildren
== 0) {
292 // Close the bus driver
296 &gEfiDevicePathProtocolGuid
,
297 This
->DriverBindingHandle
,
302 &gEfiPciRootBridgeIoProtocolGuid
,
303 This
->DriverBindingHandle
,
307 DestroyRootBridgeByHandle (
315 // Stop all the children
318 AllChildrenStopped
= TRUE
;
320 for (Index
= 0; Index
< NumberOfChildren
; Index
++) {
323 // De register all the pci device
325 Status
= DeRegisterPciDevice (Controller
, ChildHandleBuffer
[Index
]);
327 if (EFI_ERROR (Status
)) {
328 AllChildrenStopped
= FALSE
;
332 if (!AllChildrenStopped
) {
333 return EFI_DEVICE_ERROR
;