2 Supporting functions implementaion for PCI devices management.
4 Copyright (c) 2006 - 2009, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 // This device structure is serviced as a header.
19 // Its next field points to the first root bridge device node.
21 LIST_ENTRY mPciDevicePool
;
24 Initialize the PCI devices pool.
28 InitializePciDevicePool (
32 InitializeListHead (&mPciDevicePool
);
36 Insert a root bridge into PCI device pool.
38 @param RootBridge A pointer to the PCI_IO_DEVICE.
43 IN PCI_IO_DEVICE
*RootBridge
46 InsertTailList (&mPciDevicePool
, &(RootBridge
->Link
));
50 This function is used to insert a PCI device node under
53 @param Bridge The PCI bridge.
54 @param PciDeviceNode The PCI device needs inserting.
59 IN PCI_IO_DEVICE
*Bridge
,
60 IN PCI_IO_DEVICE
*PciDeviceNode
63 InsertTailList (&Bridge
->ChildList
, &(PciDeviceNode
->Link
));
64 PciDeviceNode
->Parent
= Bridge
;
68 Destroy root bridge and remove it from deivce tree.
70 @param RootBridge The bridge want to be removed.
75 IN PCI_IO_DEVICE
*RootBridge
78 DestroyPciDeviceTree (RootBridge
);
80 FreePciDevice (RootBridge
);
84 Destroy a pci device node.
86 All direct or indirect allocated resource for this node will be freed.
88 @param PciIoDevice A pointer to the PCI_IO_DEVICE to be destoried.
93 IN PCI_IO_DEVICE
*PciIoDevice
96 ASSERT (PciIoDevice
!= NULL
);
98 // Assume all children have been removed underneath this device
100 if (PciIoDevice
->ResourcePaddingDescriptors
!= NULL
) {
101 FreePool (PciIoDevice
->ResourcePaddingDescriptors
);
104 if (PciIoDevice
->DevicePath
!= NULL
) {
105 FreePool (PciIoDevice
->DevicePath
);
108 FreePool (PciIoDevice
);
112 Destroy all the pci device node under the bridge.
113 Bridge itself is not included.
115 @param Bridge A pointer to the PCI_IO_DEVICE.
119 DestroyPciDeviceTree (
120 IN PCI_IO_DEVICE
*Bridge
123 LIST_ENTRY
*CurrentLink
;
126 while (!IsListEmpty (&Bridge
->ChildList
)) {
128 CurrentLink
= Bridge
->ChildList
.ForwardLink
;
131 // Remove this node from the linked list
133 RemoveEntryList (CurrentLink
);
135 Temp
= PCI_IO_DEVICE_FROM_LINK (CurrentLink
);
137 if (!IsListEmpty (&Temp
->ChildList
)) {
138 DestroyPciDeviceTree (Temp
);
141 FreePciDevice (Temp
);
146 Destroy all device nodes under the root bridge
147 specified by Controller.
149 The root bridge itself is also included.
151 @param Controller Root bridge handle.
153 @retval EFI_SUCCESS Destory all devcie nodes successfully.
154 @retval EFI_NOT_FOUND Cannot find any PCI device under specified
159 DestroyRootBridgeByHandle (
160 IN EFI_HANDLE Controller
164 LIST_ENTRY
*CurrentLink
;
167 CurrentLink
= mPciDevicePool
.ForwardLink
;
169 while (CurrentLink
!= NULL
&& CurrentLink
!= &mPciDevicePool
) {
170 Temp
= PCI_IO_DEVICE_FROM_LINK (CurrentLink
);
172 if (Temp
->Handle
== Controller
) {
174 RemoveEntryList (CurrentLink
);
176 DestroyPciDeviceTree (Temp
);
178 FreePciDevice (Temp
);
183 CurrentLink
= CurrentLink
->ForwardLink
;
186 return EFI_NOT_FOUND
;
190 This function registers the PCI IO device.
192 It creates a handle for this PCI IO device (if the handle does not exist), attaches
193 appropriate protocols onto the handle, does necessary initialization, and sets up
194 parent/child relationship with its bus controller.
196 @param Controller An EFI handle for the PCI bus controller.
197 @param PciIoDevice A PCI_IO_DEVICE pointer to the PCI IO device to be registered.
198 @param Handle A pointer to hold the returned EFI handle for the PCI IO device.
200 @retval EFI_SUCCESS The PCI device is successfully registered.
201 @retval other An error occurred when registering the PCI device.
206 IN EFI_HANDLE Controller
,
207 IN PCI_IO_DEVICE
*PciIoDevice
,
208 OUT EFI_HANDLE
*Handle OPTIONAL
212 VOID
*PlatformOpRomBuffer
;
213 UINTN PlatformOpRomSize
;
214 UINT8 PciExpressCapRegOffset
;
215 EFI_PCI_IO_PROTOCOL
*PciIo
;
220 // Install the pciio protocol, device path protocol
222 Status
= gBS
->InstallMultipleProtocolInterfaces (
223 &PciIoDevice
->Handle
,
224 &gEfiDevicePathProtocolGuid
,
225 PciIoDevice
->DevicePath
,
226 &gEfiPciIoProtocolGuid
,
230 if (EFI_ERROR (Status
)) {
235 // Detect if PCI Express Device
237 PciExpressCapRegOffset
= 0;
238 Status
= LocateCapabilityRegBlock (
240 EFI_PCI_CAPABILITY_ID_PCIEXP
,
241 &PciExpressCapRegOffset
,
244 if (!EFI_ERROR (Status
)) {
245 PciIoDevice
->IsPciExp
= TRUE
;
249 // Force Interrupt line to "Unknown" or "No Connection"
251 PciIo
= &(PciIoDevice
->PciIo
);
252 Data8
= PCI_INT_LINE_UNKNOWN
;
253 PciIo
->Pci
.Write (PciIo
, EfiPciIoWidthUint8
, 0x3C, 1, &Data8
);
258 if (!PciIoDevice
->AllOpRomProcessed
) {
261 // Get the OpRom provided by platform
263 if (gPciPlatformProtocol
!= NULL
) {
264 Status
= gPciPlatformProtocol
->GetPciRom (
265 gPciPlatformProtocol
,
267 &PlatformOpRomBuffer
,
270 if (!EFI_ERROR (Status
)) {
271 PciIoDevice
->RomSize
= PlatformOpRomSize
;
272 PciIoDevice
->PciIo
.RomSize
= PlatformOpRomSize
;
273 PciIoDevice
->PciIo
.RomImage
= PlatformOpRomBuffer
;
275 // For OpROM read from gPciPlatformProtocol:
276 // Add the Rom Image to internal database for later PCI light enumeration
278 PciRomAddImageMapping (
280 PciIoDevice
->PciRootBridgeIo
->SegmentNumber
,
281 PciIoDevice
->BusNumber
,
282 PciIoDevice
->DeviceNumber
,
283 PciIoDevice
->FunctionNumber
,
284 (UINT64
) (UINTN
) PciIoDevice
->PciIo
.RomImage
,
285 PciIoDevice
->PciIo
.RomSize
292 // Determine if there are EFI images in the option rom
294 HasEfiImage
= ContainEfiImage (PciIoDevice
->PciIo
.RomImage
, PciIoDevice
->PciIo
.RomSize
);
297 Status
= gBS
->InstallMultipleProtocolInterfaces (
298 &PciIoDevice
->Handle
,
299 &gEfiLoadFile2ProtocolGuid
,
300 &PciIoDevice
->LoadFile2
,
303 if (EFI_ERROR (Status
)) {
304 gBS
->UninstallMultipleProtocolInterfaces (
305 &PciIoDevice
->Handle
,
306 &gEfiDevicePathProtocolGuid
,
307 PciIoDevice
->DevicePath
,
308 &gEfiPciIoProtocolGuid
,
317 if (!PciIoDevice
->AllOpRomProcessed
) {
319 PciIoDevice
->AllOpRomProcessed
= TRUE
;
322 // Dispatch the EFI OpRom for the PCI device.
323 // The OpRom is got from platform in the above code
324 // or loaded from device in the previous round of bus enumeration
327 ProcessOpRomImage (PciIoDevice
);
331 if (PciIoDevice
->BusOverride
) {
333 // Install Bus Specific Driver Override Protocol
335 Status
= gBS
->InstallMultipleProtocolInterfaces (
336 &PciIoDevice
->Handle
,
337 &gEfiBusSpecificDriverOverrideProtocolGuid
,
338 &PciIoDevice
->PciDriverOverride
,
341 if (EFI_ERROR (Status
)) {
342 gBS
->UninstallMultipleProtocolInterfaces (
343 &PciIoDevice
->Handle
,
344 &gEfiDevicePathProtocolGuid
,
345 PciIoDevice
->DevicePath
,
346 &gEfiPciIoProtocolGuid
,
351 gBS
->UninstallMultipleProtocolInterfaces (
352 &PciIoDevice
->Handle
,
353 &gEfiLoadFile2ProtocolGuid
,
354 &PciIoDevice
->LoadFile2
,
363 Status
= gBS
->OpenProtocol (
365 &gEfiPciRootBridgeIoProtocolGuid
,
366 (VOID
**) &(PciIoDevice
->PciRootBridgeIo
),
367 gPciBusDriverBinding
.DriverBindingHandle
,
369 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
371 if (EFI_ERROR (Status
)) {
375 if (Handle
!= NULL
) {
376 *Handle
= PciIoDevice
->Handle
;
380 // Indicate the pci device is registered
382 PciIoDevice
->Registered
= TRUE
;
388 This function is used to remove the whole PCI devices on the specified bridge from
391 @param RootBridgeHandle The root bridge device handle.
392 @param Bridge The bridge device to be removed.
396 RemoveAllPciDeviceOnBridge (
397 EFI_HANDLE RootBridgeHandle
,
398 PCI_IO_DEVICE
*Bridge
401 LIST_ENTRY
*CurrentLink
;
404 while (!IsListEmpty (&Bridge
->ChildList
)) {
406 CurrentLink
= Bridge
->ChildList
.ForwardLink
;
407 Temp
= PCI_IO_DEVICE_FROM_LINK (CurrentLink
);
410 // Check if the current node has been deregistered before
411 // If it is not, then deregister it
413 if (Temp
->Registered
) {
414 DeRegisterPciDevice (RootBridgeHandle
, Temp
->Handle
);
418 // Remove this node from the linked list
420 RemoveEntryList (CurrentLink
);
422 if (!IsListEmpty (&Temp
->ChildList
)) {
423 RemoveAllPciDeviceOnBridge (RootBridgeHandle
, Temp
);
426 FreePciDevice (Temp
);
431 This function is used to de-register the PCI IO device.
433 That includes un-installing PciIo protocol from the specified PCI
436 @param Controller An EFI handle for the PCI bus controller.
437 @param Handle PCI device handle.
439 @retval EFI_SUCCESS The PCI device is successfully de-registered.
440 @retval other An error occurred when de-registering the PCI device.
444 DeRegisterPciDevice (
445 IN EFI_HANDLE Controller
,
450 EFI_PCI_IO_PROTOCOL
*PciIo
;
452 PCI_IO_DEVICE
*PciIoDevice
;
454 LIST_ENTRY
*CurrentLink
;
455 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
457 Status
= gBS
->OpenProtocol (
459 &gEfiPciIoProtocolGuid
,
461 gPciBusDriverBinding
.DriverBindingHandle
,
463 EFI_OPEN_PROTOCOL_GET_PROTOCOL
465 if (!EFI_ERROR (Status
)) {
466 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (PciIo
);
469 // If it is already de-registered
471 if (!PciIoDevice
->Registered
) {
476 // If it is PPB, first de-register its children
479 if (!IsListEmpty (&PciIoDevice
->ChildList
)) {
481 CurrentLink
= PciIoDevice
->ChildList
.ForwardLink
;
483 while (CurrentLink
!= NULL
&& CurrentLink
!= &PciIoDevice
->ChildList
) {
484 Node
= PCI_IO_DEVICE_FROM_LINK (CurrentLink
);
485 Status
= DeRegisterPciDevice (Controller
, Node
->Handle
);
487 if (EFI_ERROR (Status
)) {
491 CurrentLink
= CurrentLink
->ForwardLink
;
496 // Close the child handle
498 Status
= gBS
->CloseProtocol (
500 &gEfiPciRootBridgeIoProtocolGuid
,
501 gPciBusDriverBinding
.DriverBindingHandle
,
506 // Un-install the Device Path protocol and PCI I/O protocol
507 // and Bus Specific Driver Override protocol if needed.
509 if (PciIoDevice
->BusOverride
) {
510 Status
= gBS
->UninstallMultipleProtocolInterfaces (
512 &gEfiDevicePathProtocolGuid
,
513 PciIoDevice
->DevicePath
,
514 &gEfiPciIoProtocolGuid
,
516 &gEfiBusSpecificDriverOverrideProtocolGuid
,
517 &PciIoDevice
->PciDriverOverride
,
521 Status
= gBS
->UninstallMultipleProtocolInterfaces (
523 &gEfiDevicePathProtocolGuid
,
524 PciIoDevice
->DevicePath
,
525 &gEfiPciIoProtocolGuid
,
531 if (!EFI_ERROR (Status
)) {
533 // Try to uninstall LoadFile2 protocol if exists
535 Status
= gBS
->OpenProtocol (
537 &gEfiLoadFile2ProtocolGuid
,
539 gPciBusDriverBinding
.DriverBindingHandle
,
541 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
543 if (!EFI_ERROR (Status
)) {
544 Status
= gBS
->UninstallMultipleProtocolInterfaces (
546 &gEfiLoadFile2ProtocolGuid
,
547 &PciIoDevice
->LoadFile2
,
554 Status
= EFI_SUCCESS
;
558 if (EFI_ERROR (Status
)) {
561 &gEfiPciRootBridgeIoProtocolGuid
,
562 (VOID
**) &PciRootBridgeIo
,
563 gPciBusDriverBinding
.DriverBindingHandle
,
565 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
571 // The Device Driver should disable this device after disconnect
572 // so the Pci Bus driver will not touch this device any more.
573 // Restore the register field to the original value
575 PciIoDevice
->Registered
= FALSE
;
576 PciIoDevice
->Handle
= NULL
;
580 // Handle may be closed before
589 Start to manage the PCI device on the specified root bridge or PCI-PCI Bridge.
591 @param Controller The root bridge handle.
592 @param RootBridge A pointer to the PCI_IO_DEVICE.
593 @param RemainingDevicePath A pointer to the EFI_DEVICE_PATH_PROTOCOL.
594 @param NumberOfChildren Children number.
595 @param ChildHandleBuffer A pointer to the child handle buffer.
597 @retval EFI_NOT_READY Device is not allocated.
598 @retval EFI_UNSUPPORTED Device only support PCI-PCI bridge.
599 @retval EFI_NOT_FOUND Can not find the specific device.
600 @retval EFI_SUCCESS Success to start Pci devices on bridge.
604 StartPciDevicesOnBridge (
605 IN EFI_HANDLE Controller
,
606 IN PCI_IO_DEVICE
*RootBridge
,
607 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
,
608 IN OUT UINT8
*NumberOfChildren
,
609 IN OUT EFI_HANDLE
*ChildHandleBuffer
613 PCI_IO_DEVICE
*PciIoDevice
;
614 EFI_DEV_PATH_PTR Node
;
615 EFI_DEVICE_PATH_PROTOCOL
*CurrentDevicePath
;
617 LIST_ENTRY
*CurrentLink
;
621 CurrentLink
= RootBridge
->ChildList
.ForwardLink
;
623 while (CurrentLink
!= NULL
&& CurrentLink
!= &RootBridge
->ChildList
) {
625 PciIoDevice
= PCI_IO_DEVICE_FROM_LINK (CurrentLink
);
626 if (RemainingDevicePath
!= NULL
) {
628 Node
.DevPath
= RemainingDevicePath
;
630 if (Node
.Pci
->Device
!= PciIoDevice
->DeviceNumber
||
631 Node
.Pci
->Function
!= PciIoDevice
->FunctionNumber
) {
632 CurrentLink
= CurrentLink
->ForwardLink
;
637 // Check if the device has been assigned with required resource
639 if (!PciIoDevice
->Allocated
) {
640 return EFI_NOT_READY
;
644 // Check if the current node has been registered before
645 // If it is not, register it
647 if (!PciIoDevice
->Registered
) {
648 Status
= RegisterPciDevice (
656 if (NumberOfChildren
!= NULL
&& ChildHandleBuffer
!= NULL
&& PciIoDevice
->Registered
) {
657 ChildHandleBuffer
[*NumberOfChildren
] = PciIoDevice
->Handle
;
658 (*NumberOfChildren
)++;
662 // Get the next device path
664 CurrentDevicePath
= NextDevicePathNode (RemainingDevicePath
);
665 if (IsDevicePathEnd (CurrentDevicePath
)) {
672 if (!IsListEmpty (&PciIoDevice
->ChildList
)) {
673 Status
= StartPciDevicesOnBridge (
681 PciIoDevice
->PciIo
.Attributes (
682 &(PciIoDevice
->PciIo
),
683 EfiPciIoAttributeOperationSupported
,
687 Supports
&= EFI_PCI_DEVICE_ENABLE
;
688 PciIoDevice
->PciIo
.Attributes (
689 &(PciIoDevice
->PciIo
),
690 EfiPciIoAttributeOperationEnable
,
699 // Currently, the PCI bus driver only support PCI-PCI bridge
701 return EFI_UNSUPPORTED
;
707 // If remaining device path is NULL,
708 // try to enable all the pci devices under this bridge
710 if (!PciIoDevice
->Registered
&& PciIoDevice
->Allocated
) {
711 Status
= RegisterPciDevice (
719 if (NumberOfChildren
!= NULL
&& ChildHandleBuffer
!= NULL
&& PciIoDevice
->Registered
) {
720 ChildHandleBuffer
[*NumberOfChildren
] = PciIoDevice
->Handle
;
721 (*NumberOfChildren
)++;
724 if (!IsListEmpty (&PciIoDevice
->ChildList
)) {
725 Status
= StartPciDevicesOnBridge (
733 PciIoDevice
->PciIo
.Attributes (
734 &(PciIoDevice
->PciIo
),
735 EfiPciIoAttributeOperationSupported
,
739 Supports
&= EFI_PCI_DEVICE_ENABLE
;
740 PciIoDevice
->PciIo
.Attributes (
741 &(PciIoDevice
->PciIo
),
742 EfiPciIoAttributeOperationEnable
,
749 CurrentLink
= CurrentLink
->ForwardLink
;
753 if (PciIoDevice
== NULL
) {
754 return EFI_NOT_FOUND
;
761 Start to manage all the PCI devices it found previously under
762 the entire host bridge.
764 @param Controller The root bridge handle.
766 @retval EFI_NOT_READY Device is not allocated.
767 @retval EFI_SUCCESS Success to start Pci device on host bridge.
772 IN EFI_HANDLE Controller
775 PCI_IO_DEVICE
*RootBridge
;
776 EFI_HANDLE ThisHostBridge
;
777 LIST_ENTRY
*CurrentLink
;
779 RootBridge
= GetRootBridgeByHandle (Controller
);
780 ASSERT (RootBridge
!= NULL
);
781 ThisHostBridge
= RootBridge
->PciRootBridgeIo
->ParentHandle
;
783 CurrentLink
= mPciDevicePool
.ForwardLink
;
785 while (CurrentLink
!= NULL
&& CurrentLink
!= &mPciDevicePool
) {
787 RootBridge
= PCI_IO_DEVICE_FROM_LINK (CurrentLink
);
789 // Locate the right root bridge to start
791 if (RootBridge
->PciRootBridgeIo
->ParentHandle
== ThisHostBridge
) {
792 StartPciDevicesOnBridge (
801 CurrentLink
= CurrentLink
->ForwardLink
;
808 Create root bridge device.
810 @param RootBridgeHandle Specified root bridge hanle.
812 @return The crated root bridge device instance, NULL means no
813 root bridge device instance created.
818 IN EFI_HANDLE RootBridgeHandle
823 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
824 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
826 Dev
= AllocateZeroPool (sizeof (PCI_IO_DEVICE
));
831 Dev
->Signature
= PCI_IO_DEVICE_SIGNATURE
;
832 Dev
->Handle
= RootBridgeHandle
;
833 InitializeListHead (&Dev
->ChildList
);
835 Status
= gBS
->OpenProtocol (
837 &gEfiDevicePathProtocolGuid
,
838 (VOID
**) &ParentDevicePath
,
839 gPciBusDriverBinding
.DriverBindingHandle
,
841 EFI_OPEN_PROTOCOL_GET_PROTOCOL
844 if (EFI_ERROR (Status
)) {
850 // Record the root bridge parent device path
852 Dev
->DevicePath
= DuplicateDevicePath (ParentDevicePath
);
855 // Get the pci root bridge io protocol
857 Status
= gBS
->OpenProtocol (
859 &gEfiPciRootBridgeIoProtocolGuid
,
860 (VOID
**) &PciRootBridgeIo
,
861 gPciBusDriverBinding
.DriverBindingHandle
,
863 EFI_OPEN_PROTOCOL_GET_PROTOCOL
866 if (EFI_ERROR (Status
)) {
871 Dev
->PciRootBridgeIo
= PciRootBridgeIo
;
874 // Initialize the PCI I/O instance structure
876 InitializePciIoInstance (Dev
);
877 InitializePciDriverOverrideInstance (Dev
);
878 InitializePciLoadFile2 (Dev
);
881 // Initialize reserved resource list and
882 // option rom driver list
884 InitializeListHead (&Dev
->ReservedResourceList
);
885 InitializeListHead (&Dev
->OptionRomDriverList
);
891 Get root bridge device instance by specific root bridge handle.
893 @param RootBridgeHandle Given root bridge handle.
895 @return The root bridge device instance, NULL means no root bridge
896 device instance found.
900 GetRootBridgeByHandle (
901 EFI_HANDLE RootBridgeHandle
904 PCI_IO_DEVICE
*RootBridgeDev
;
905 LIST_ENTRY
*CurrentLink
;
907 CurrentLink
= mPciDevicePool
.ForwardLink
;
909 while (CurrentLink
!= NULL
&& CurrentLink
!= &mPciDevicePool
) {
911 RootBridgeDev
= PCI_IO_DEVICE_FROM_LINK (CurrentLink
);
912 if (RootBridgeDev
->Handle
== RootBridgeHandle
) {
913 return RootBridgeDev
;
916 CurrentLink
= CurrentLink
->ForwardLink
;
923 Judege whether Pci device existed.
925 @param Bridge Parent bridege instance.
926 @param PciIoDevice Device instance.
928 @retval TRUE Pci device existed.
929 @retval FALSE Pci device did not exist.
934 IN PCI_IO_DEVICE
*Bridge
,
935 IN PCI_IO_DEVICE
*PciIoDevice
940 LIST_ENTRY
*CurrentLink
;
942 CurrentLink
= Bridge
->ChildList
.ForwardLink
;
944 while (CurrentLink
!= NULL
&& CurrentLink
!= &Bridge
->ChildList
) {
946 Temp
= PCI_IO_DEVICE_FROM_LINK (CurrentLink
);
948 if (Temp
== PciIoDevice
) {
952 if (!IsListEmpty (&Temp
->ChildList
)) {
953 if (PciDeviceExisted (Temp
, PciIoDevice
)) {
958 CurrentLink
= CurrentLink
->ForwardLink
;
965 Get the active VGA device on the same segment.
967 @param VgaDevice PCI IO instance for the VGA device.
969 @return The active VGA device on the same segment.
973 ActiveVGADeviceOnTheSameSegment (
974 IN PCI_IO_DEVICE
*VgaDevice
977 LIST_ENTRY
*CurrentLink
;
980 CurrentLink
= mPciDevicePool
.ForwardLink
;
982 while (CurrentLink
!= NULL
&& CurrentLink
!= &mPciDevicePool
) {
984 Temp
= PCI_IO_DEVICE_FROM_LINK (CurrentLink
);
986 if (Temp
->PciRootBridgeIo
->SegmentNumber
== VgaDevice
->PciRootBridgeIo
->SegmentNumber
) {
988 Temp
= ActiveVGADeviceOnTheRootBridge (Temp
);
995 CurrentLink
= CurrentLink
->ForwardLink
;
1002 Get the active VGA device on the root bridge.
1004 @param RootBridge PCI IO instance for the root bridge.
1006 @return The active VGA device.
1010 ActiveVGADeviceOnTheRootBridge (
1011 IN PCI_IO_DEVICE
*RootBridge
1014 LIST_ENTRY
*CurrentLink
;
1015 PCI_IO_DEVICE
*Temp
;
1017 CurrentLink
= RootBridge
->ChildList
.ForwardLink
;
1019 while (CurrentLink
!= NULL
&& CurrentLink
!= &RootBridge
->ChildList
) {
1021 Temp
= PCI_IO_DEVICE_FROM_LINK (CurrentLink
);
1023 if (IS_PCI_VGA(&Temp
->Pci
) &&
1025 (EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY
|
1026 EFI_PCI_IO_ATTRIBUTE_VGA_IO
|
1027 EFI_PCI_IO_ATTRIBUTE_VGA_IO_16
)) != 0) {
1031 if (IS_PCI_BRIDGE (&Temp
->Pci
)) {
1033 Temp
= ActiveVGADeviceOnTheRootBridge (Temp
);
1040 CurrentLink
= CurrentLink
->ForwardLink
;
1048 Get HPC PCI address according to its device path.
1050 @param RootBridge Root bridege Io instance.
1051 @param RemainingDevicePath Given searching device path.
1052 @param PciAddress Buffer holding searched result.
1054 @retval EFI_SUCCESS PCI address was stored in PciAddress
1055 @retval EFI_NOT_FOUND Can not find the specific device path.
1059 GetHpcPciAddressFromRootBridge (
1060 IN PCI_IO_DEVICE
*RootBridge
,
1061 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
,
1062 OUT UINT64
*PciAddress
1065 EFI_DEV_PATH_PTR Node
;
1066 PCI_IO_DEVICE
*Temp
;
1067 EFI_DEVICE_PATH_PROTOCOL
*CurrentDevicePath
;
1068 LIST_ENTRY
*CurrentLink
;
1073 CurrentDevicePath
= RemainingDevicePath
;
1074 Node
.DevPath
= CurrentDevicePath
;
1077 while (!IsDevicePathEnd (CurrentDevicePath
)) {
1079 CurrentLink
= RootBridge
->ChildList
.ForwardLink
;
1080 Node
.DevPath
= CurrentDevicePath
;
1082 while (CurrentLink
!= NULL
&& CurrentLink
!= &RootBridge
->ChildList
) {
1083 Temp
= PCI_IO_DEVICE_FROM_LINK (CurrentLink
);
1085 if (Node
.Pci
->Device
== Temp
->DeviceNumber
&&
1086 Node
.Pci
->Function
== Temp
->FunctionNumber
) {
1091 CurrentLink
= CurrentLink
->ForwardLink
;
1095 // Check if we find the bridge
1097 if (CurrentLink
== &RootBridge
->ChildList
) {
1104 CurrentDevicePath
= NextDevicePathNode (CurrentDevicePath
);
1109 CurrentDevicePath
= NextDevicePathNode (CurrentDevicePath
);
1111 if (IsDevicePathEnd (CurrentDevicePath
)) {
1112 *PciAddress
= EFI_PCI_ADDRESS (RootBridge
->BusNumber
, Node
.Pci
->Device
, Node
.Pci
->Function
, 0);
1116 return EFI_NOT_FOUND
;
1120 *PciAddress
= EFI_PCI_ADDRESS (Temp
->BusNumber
, Temp
->DeviceNumber
, Temp
->FunctionNumber
, 0);
1122 return EFI_NOT_FOUND
;