2 Supporting functions implementaion for PCI devices management.
4 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
5 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
288 } else if (gPciOverrideProtocol
!= NULL
) {
289 Status
= gPciOverrideProtocol
->GetPciRom (
290 gPciOverrideProtocol
,
292 &PlatformOpRomBuffer
,
295 if (!EFI_ERROR (Status
)) {
296 PciIoDevice
->RomSize
= PlatformOpRomSize
;
297 PciIoDevice
->PciIo
.RomSize
= PlatformOpRomSize
;
298 PciIoDevice
->PciIo
.RomImage
= PlatformOpRomBuffer
;
300 // For OpROM read from gPciOverrideProtocol:
301 // Add the Rom Image to internal database for later PCI light enumeration
303 PciRomAddImageMapping (
305 PciIoDevice
->PciRootBridgeIo
->SegmentNumber
,
306 PciIoDevice
->BusNumber
,
307 PciIoDevice
->DeviceNumber
,
308 PciIoDevice
->FunctionNumber
,
309 (UINT64
) (UINTN
) PciIoDevice
->PciIo
.RomImage
,
310 PciIoDevice
->PciIo
.RomSize
317 // Determine if there are EFI images in the option rom
319 HasEfiImage
= ContainEfiImage (PciIoDevice
->PciIo
.RomImage
, PciIoDevice
->PciIo
.RomSize
);
322 Status
= gBS
->InstallMultipleProtocolInterfaces (
323 &PciIoDevice
->Handle
,
324 &gEfiLoadFile2ProtocolGuid
,
325 &PciIoDevice
->LoadFile2
,
328 if (EFI_ERROR (Status
)) {
329 gBS
->UninstallMultipleProtocolInterfaces (
330 &PciIoDevice
->Handle
,
331 &gEfiDevicePathProtocolGuid
,
332 PciIoDevice
->DevicePath
,
333 &gEfiPciIoProtocolGuid
,
342 if (!PciIoDevice
->AllOpRomProcessed
) {
344 PciIoDevice
->AllOpRomProcessed
= TRUE
;
347 // Dispatch the EFI OpRom for the PCI device.
348 // The OpRom is got from platform in the above code
349 // or loaded from device in the previous round of bus enumeration
352 ProcessOpRomImage (PciIoDevice
);
356 if (PciIoDevice
->BusOverride
) {
358 // Install Bus Specific Driver Override Protocol
360 Status
= gBS
->InstallMultipleProtocolInterfaces (
361 &PciIoDevice
->Handle
,
362 &gEfiBusSpecificDriverOverrideProtocolGuid
,
363 &PciIoDevice
->PciDriverOverride
,
366 if (EFI_ERROR (Status
)) {
367 gBS
->UninstallMultipleProtocolInterfaces (
368 &PciIoDevice
->Handle
,
369 &gEfiDevicePathProtocolGuid
,
370 PciIoDevice
->DevicePath
,
371 &gEfiPciIoProtocolGuid
,
376 gBS
->UninstallMultipleProtocolInterfaces (
377 &PciIoDevice
->Handle
,
378 &gEfiLoadFile2ProtocolGuid
,
379 &PciIoDevice
->LoadFile2
,
388 Status
= gBS
->OpenProtocol (
390 &gEfiPciRootBridgeIoProtocolGuid
,
391 (VOID
**) &(PciIoDevice
->PciRootBridgeIo
),
392 gPciBusDriverBinding
.DriverBindingHandle
,
394 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
396 if (EFI_ERROR (Status
)) {
400 if (Handle
!= NULL
) {
401 *Handle
= PciIoDevice
->Handle
;
405 // Indicate the pci device is registered
407 PciIoDevice
->Registered
= TRUE
;
413 This function is used to remove the whole PCI devices on the specified bridge from
416 @param RootBridgeHandle The root bridge device handle.
417 @param Bridge The bridge device to be removed.
421 RemoveAllPciDeviceOnBridge (
422 EFI_HANDLE RootBridgeHandle
,
423 PCI_IO_DEVICE
*Bridge
426 LIST_ENTRY
*CurrentLink
;
429 while (!IsListEmpty (&Bridge
->ChildList
)) {
431 CurrentLink
= Bridge
->ChildList
.ForwardLink
;
432 Temp
= PCI_IO_DEVICE_FROM_LINK (CurrentLink
);
435 // Check if the current node has been deregistered before
436 // If it is not, then deregister it
438 if (Temp
->Registered
) {
439 DeRegisterPciDevice (RootBridgeHandle
, Temp
->Handle
);
443 // Remove this node from the linked list
445 RemoveEntryList (CurrentLink
);
447 if (!IsListEmpty (&Temp
->ChildList
)) {
448 RemoveAllPciDeviceOnBridge (RootBridgeHandle
, Temp
);
451 FreePciDevice (Temp
);
456 This function is used to de-register the PCI IO device.
458 That includes un-installing PciIo protocol from the specified PCI
461 @param Controller An EFI handle for the PCI bus controller.
462 @param Handle PCI device handle.
464 @retval EFI_SUCCESS The PCI device is successfully de-registered.
465 @retval other An error occurred when de-registering the PCI device.
469 DeRegisterPciDevice (
470 IN EFI_HANDLE Controller
,
475 EFI_PCI_IO_PROTOCOL
*PciIo
;
477 PCI_IO_DEVICE
*PciIoDevice
;
479 LIST_ENTRY
*CurrentLink
;
480 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
482 Status
= gBS
->OpenProtocol (
484 &gEfiPciIoProtocolGuid
,
486 gPciBusDriverBinding
.DriverBindingHandle
,
488 EFI_OPEN_PROTOCOL_GET_PROTOCOL
490 if (!EFI_ERROR (Status
)) {
491 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (PciIo
);
494 // If it is already de-registered
496 if (!PciIoDevice
->Registered
) {
501 // If it is PPB, first de-register its children
504 if (!IsListEmpty (&PciIoDevice
->ChildList
)) {
506 CurrentLink
= PciIoDevice
->ChildList
.ForwardLink
;
508 while (CurrentLink
!= NULL
&& CurrentLink
!= &PciIoDevice
->ChildList
) {
509 Node
= PCI_IO_DEVICE_FROM_LINK (CurrentLink
);
510 Status
= DeRegisterPciDevice (Controller
, Node
->Handle
);
512 if (EFI_ERROR (Status
)) {
516 CurrentLink
= CurrentLink
->ForwardLink
;
521 // Close the child handle
523 Status
= gBS
->CloseProtocol (
525 &gEfiPciRootBridgeIoProtocolGuid
,
526 gPciBusDriverBinding
.DriverBindingHandle
,
531 // Un-install the Device Path protocol and PCI I/O protocol
532 // and Bus Specific Driver Override protocol if needed.
534 if (PciIoDevice
->BusOverride
) {
535 Status
= gBS
->UninstallMultipleProtocolInterfaces (
537 &gEfiDevicePathProtocolGuid
,
538 PciIoDevice
->DevicePath
,
539 &gEfiPciIoProtocolGuid
,
541 &gEfiBusSpecificDriverOverrideProtocolGuid
,
542 &PciIoDevice
->PciDriverOverride
,
546 Status
= gBS
->UninstallMultipleProtocolInterfaces (
548 &gEfiDevicePathProtocolGuid
,
549 PciIoDevice
->DevicePath
,
550 &gEfiPciIoProtocolGuid
,
556 if (!EFI_ERROR (Status
)) {
558 // Try to uninstall LoadFile2 protocol if exists
560 Status
= gBS
->OpenProtocol (
562 &gEfiLoadFile2ProtocolGuid
,
564 gPciBusDriverBinding
.DriverBindingHandle
,
566 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
568 if (!EFI_ERROR (Status
)) {
569 Status
= gBS
->UninstallMultipleProtocolInterfaces (
571 &gEfiLoadFile2ProtocolGuid
,
572 &PciIoDevice
->LoadFile2
,
579 Status
= EFI_SUCCESS
;
583 if (EFI_ERROR (Status
)) {
586 &gEfiPciRootBridgeIoProtocolGuid
,
587 (VOID
**) &PciRootBridgeIo
,
588 gPciBusDriverBinding
.DriverBindingHandle
,
590 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
596 // The Device Driver should disable this device after disconnect
597 // so the Pci Bus driver will not touch this device any more.
598 // Restore the register field to the original value
600 PciIoDevice
->Registered
= FALSE
;
601 PciIoDevice
->Handle
= NULL
;
605 // Handle may be closed before
614 Start to manage the PCI device on the specified root bridge or PCI-PCI Bridge.
616 @param Controller The root bridge handle.
617 @param RootBridge A pointer to the PCI_IO_DEVICE.
618 @param RemainingDevicePath A pointer to the EFI_DEVICE_PATH_PROTOCOL.
619 @param NumberOfChildren Children number.
620 @param ChildHandleBuffer A pointer to the child handle buffer.
622 @retval EFI_NOT_READY Device is not allocated.
623 @retval EFI_UNSUPPORTED Device only support PCI-PCI bridge.
624 @retval EFI_NOT_FOUND Can not find the specific device.
625 @retval EFI_SUCCESS Success to start Pci devices on bridge.
629 StartPciDevicesOnBridge (
630 IN EFI_HANDLE Controller
,
631 IN PCI_IO_DEVICE
*RootBridge
,
632 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
,
633 IN OUT UINT8
*NumberOfChildren
,
634 IN OUT EFI_HANDLE
*ChildHandleBuffer
638 PCI_IO_DEVICE
*PciIoDevice
;
639 EFI_DEV_PATH_PTR Node
;
640 EFI_DEVICE_PATH_PROTOCOL
*CurrentDevicePath
;
642 LIST_ENTRY
*CurrentLink
;
646 CurrentLink
= RootBridge
->ChildList
.ForwardLink
;
648 while (CurrentLink
!= NULL
&& CurrentLink
!= &RootBridge
->ChildList
) {
650 PciIoDevice
= PCI_IO_DEVICE_FROM_LINK (CurrentLink
);
651 if (RemainingDevicePath
!= NULL
) {
653 Node
.DevPath
= RemainingDevicePath
;
655 if (Node
.Pci
->Device
!= PciIoDevice
->DeviceNumber
||
656 Node
.Pci
->Function
!= PciIoDevice
->FunctionNumber
) {
657 CurrentLink
= CurrentLink
->ForwardLink
;
662 // Check if the device has been assigned with required resource
664 if (!PciIoDevice
->Allocated
) {
665 return EFI_NOT_READY
;
669 // Check if the current node has been registered before
670 // If it is not, register it
672 if (!PciIoDevice
->Registered
) {
673 Status
= RegisterPciDevice (
681 if (NumberOfChildren
!= NULL
&& ChildHandleBuffer
!= NULL
&& PciIoDevice
->Registered
) {
682 ChildHandleBuffer
[*NumberOfChildren
] = PciIoDevice
->Handle
;
683 (*NumberOfChildren
)++;
687 // Get the next device path
689 CurrentDevicePath
= NextDevicePathNode (RemainingDevicePath
);
690 if (IsDevicePathEnd (CurrentDevicePath
)) {
697 if (IS_PCI_BRIDGE (&PciIoDevice
->Pci
)) {
698 Status
= StartPciDevicesOnBridge (
706 PciIoDevice
->PciIo
.Attributes (
707 &(PciIoDevice
->PciIo
),
708 EfiPciIoAttributeOperationSupported
,
712 Supports
&= EFI_PCI_DEVICE_ENABLE
;
713 PciIoDevice
->PciIo
.Attributes (
714 &(PciIoDevice
->PciIo
),
715 EfiPciIoAttributeOperationEnable
,
724 // Currently, the PCI bus driver only support PCI-PCI bridge
726 return EFI_UNSUPPORTED
;
732 // If remaining device path is NULL,
733 // try to enable all the pci devices under this bridge
735 if (!PciIoDevice
->Registered
&& PciIoDevice
->Allocated
) {
736 Status
= RegisterPciDevice (
744 if (NumberOfChildren
!= NULL
&& ChildHandleBuffer
!= NULL
&& PciIoDevice
->Registered
) {
745 ChildHandleBuffer
[*NumberOfChildren
] = PciIoDevice
->Handle
;
746 (*NumberOfChildren
)++;
749 if (IS_PCI_BRIDGE (&PciIoDevice
->Pci
)) {
750 Status
= StartPciDevicesOnBridge (
758 PciIoDevice
->PciIo
.Attributes (
759 &(PciIoDevice
->PciIo
),
760 EfiPciIoAttributeOperationSupported
,
764 Supports
&= EFI_PCI_DEVICE_ENABLE
;
765 PciIoDevice
->PciIo
.Attributes (
766 &(PciIoDevice
->PciIo
),
767 EfiPciIoAttributeOperationEnable
,
774 CurrentLink
= CurrentLink
->ForwardLink
;
778 if (PciIoDevice
== NULL
) {
779 return EFI_NOT_FOUND
;
786 Start to manage all the PCI devices it found previously under
787 the entire host bridge.
789 @param Controller The root bridge handle.
791 @retval EFI_NOT_READY Device is not allocated.
792 @retval EFI_SUCCESS Success to start Pci device on host bridge.
797 IN EFI_HANDLE Controller
800 PCI_IO_DEVICE
*RootBridge
;
801 EFI_HANDLE ThisHostBridge
;
802 LIST_ENTRY
*CurrentLink
;
804 RootBridge
= GetRootBridgeByHandle (Controller
);
805 ASSERT (RootBridge
!= NULL
);
806 ThisHostBridge
= RootBridge
->PciRootBridgeIo
->ParentHandle
;
808 CurrentLink
= mPciDevicePool
.ForwardLink
;
810 while (CurrentLink
!= NULL
&& CurrentLink
!= &mPciDevicePool
) {
812 RootBridge
= PCI_IO_DEVICE_FROM_LINK (CurrentLink
);
814 // Locate the right root bridge to start
816 if (RootBridge
->PciRootBridgeIo
->ParentHandle
== ThisHostBridge
) {
817 StartPciDevicesOnBridge (
826 CurrentLink
= CurrentLink
->ForwardLink
;
833 Create root bridge device.
835 @param RootBridgeHandle Specified root bridge hanle.
837 @return The crated root bridge device instance, NULL means no
838 root bridge device instance created.
843 IN EFI_HANDLE RootBridgeHandle
848 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
849 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
851 Dev
= AllocateZeroPool (sizeof (PCI_IO_DEVICE
));
856 Dev
->Signature
= PCI_IO_DEVICE_SIGNATURE
;
857 Dev
->Handle
= RootBridgeHandle
;
858 InitializeListHead (&Dev
->ChildList
);
860 Status
= gBS
->OpenProtocol (
862 &gEfiDevicePathProtocolGuid
,
863 (VOID
**) &ParentDevicePath
,
864 gPciBusDriverBinding
.DriverBindingHandle
,
866 EFI_OPEN_PROTOCOL_GET_PROTOCOL
869 if (EFI_ERROR (Status
)) {
875 // Record the root bridge parent device path
877 Dev
->DevicePath
= DuplicateDevicePath (ParentDevicePath
);
880 // Get the pci root bridge io protocol
882 Status
= gBS
->OpenProtocol (
884 &gEfiPciRootBridgeIoProtocolGuid
,
885 (VOID
**) &PciRootBridgeIo
,
886 gPciBusDriverBinding
.DriverBindingHandle
,
888 EFI_OPEN_PROTOCOL_GET_PROTOCOL
891 if (EFI_ERROR (Status
)) {
896 Dev
->PciRootBridgeIo
= PciRootBridgeIo
;
899 // Initialize the PCI I/O instance structure
901 InitializePciIoInstance (Dev
);
902 InitializePciDriverOverrideInstance (Dev
);
903 InitializePciLoadFile2 (Dev
);
906 // Initialize reserved resource list and
907 // option rom driver list
909 InitializeListHead (&Dev
->ReservedResourceList
);
910 InitializeListHead (&Dev
->OptionRomDriverList
);
916 Get root bridge device instance by specific root bridge handle.
918 @param RootBridgeHandle Given root bridge handle.
920 @return The root bridge device instance, NULL means no root bridge
921 device instance found.
925 GetRootBridgeByHandle (
926 EFI_HANDLE RootBridgeHandle
929 PCI_IO_DEVICE
*RootBridgeDev
;
930 LIST_ENTRY
*CurrentLink
;
932 CurrentLink
= mPciDevicePool
.ForwardLink
;
934 while (CurrentLink
!= NULL
&& CurrentLink
!= &mPciDevicePool
) {
936 RootBridgeDev
= PCI_IO_DEVICE_FROM_LINK (CurrentLink
);
937 if (RootBridgeDev
->Handle
== RootBridgeHandle
) {
938 return RootBridgeDev
;
941 CurrentLink
= CurrentLink
->ForwardLink
;
948 Judege whether Pci device existed.
950 @param Bridge Parent bridege instance.
951 @param PciIoDevice Device instance.
953 @retval TRUE Pci device existed.
954 @retval FALSE Pci device did not exist.
959 IN PCI_IO_DEVICE
*Bridge
,
960 IN PCI_IO_DEVICE
*PciIoDevice
965 LIST_ENTRY
*CurrentLink
;
967 CurrentLink
= Bridge
->ChildList
.ForwardLink
;
969 while (CurrentLink
!= NULL
&& CurrentLink
!= &Bridge
->ChildList
) {
971 Temp
= PCI_IO_DEVICE_FROM_LINK (CurrentLink
);
973 if (Temp
== PciIoDevice
) {
977 if (!IsListEmpty (&Temp
->ChildList
)) {
978 if (PciDeviceExisted (Temp
, PciIoDevice
)) {
983 CurrentLink
= CurrentLink
->ForwardLink
;
990 Get the active VGA device on the same segment.
992 @param VgaDevice PCI IO instance for the VGA device.
994 @return The active VGA device on the same segment.
998 ActiveVGADeviceOnTheSameSegment (
999 IN PCI_IO_DEVICE
*VgaDevice
1002 LIST_ENTRY
*CurrentLink
;
1003 PCI_IO_DEVICE
*Temp
;
1005 CurrentLink
= mPciDevicePool
.ForwardLink
;
1007 while (CurrentLink
!= NULL
&& CurrentLink
!= &mPciDevicePool
) {
1009 Temp
= PCI_IO_DEVICE_FROM_LINK (CurrentLink
);
1011 if (Temp
->PciRootBridgeIo
->SegmentNumber
== VgaDevice
->PciRootBridgeIo
->SegmentNumber
) {
1013 Temp
= ActiveVGADeviceOnTheRootBridge (Temp
);
1020 CurrentLink
= CurrentLink
->ForwardLink
;
1027 Get the active VGA device on the root bridge.
1029 @param RootBridge PCI IO instance for the root bridge.
1031 @return The active VGA device.
1035 ActiveVGADeviceOnTheRootBridge (
1036 IN PCI_IO_DEVICE
*RootBridge
1039 LIST_ENTRY
*CurrentLink
;
1040 PCI_IO_DEVICE
*Temp
;
1042 CurrentLink
= RootBridge
->ChildList
.ForwardLink
;
1044 while (CurrentLink
!= NULL
&& CurrentLink
!= &RootBridge
->ChildList
) {
1046 Temp
= PCI_IO_DEVICE_FROM_LINK (CurrentLink
);
1048 if (IS_PCI_VGA(&Temp
->Pci
) &&
1050 (EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY
|
1051 EFI_PCI_IO_ATTRIBUTE_VGA_IO
|
1052 EFI_PCI_IO_ATTRIBUTE_VGA_IO_16
)) != 0) {
1056 if (IS_PCI_BRIDGE (&Temp
->Pci
)) {
1058 Temp
= ActiveVGADeviceOnTheRootBridge (Temp
);
1065 CurrentLink
= CurrentLink
->ForwardLink
;
1073 Get HPC PCI address according to its device path.
1075 @param RootBridge Root bridege Io instance.
1076 @param RemainingDevicePath Given searching device path.
1077 @param PciAddress Buffer holding searched result.
1079 @retval EFI_SUCCESS PCI address was stored in PciAddress
1080 @retval EFI_NOT_FOUND Can not find the specific device path.
1084 GetHpcPciAddressFromRootBridge (
1085 IN PCI_IO_DEVICE
*RootBridge
,
1086 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
,
1087 OUT UINT64
*PciAddress
1090 EFI_DEV_PATH_PTR Node
;
1091 PCI_IO_DEVICE
*Temp
;
1092 EFI_DEVICE_PATH_PROTOCOL
*CurrentDevicePath
;
1093 LIST_ENTRY
*CurrentLink
;
1098 CurrentDevicePath
= RemainingDevicePath
;
1099 Node
.DevPath
= CurrentDevicePath
;
1102 while (!IsDevicePathEnd (CurrentDevicePath
)) {
1104 CurrentLink
= RootBridge
->ChildList
.ForwardLink
;
1105 Node
.DevPath
= CurrentDevicePath
;
1107 while (CurrentLink
!= NULL
&& CurrentLink
!= &RootBridge
->ChildList
) {
1108 Temp
= PCI_IO_DEVICE_FROM_LINK (CurrentLink
);
1110 if (Node
.Pci
->Device
== Temp
->DeviceNumber
&&
1111 Node
.Pci
->Function
== Temp
->FunctionNumber
) {
1116 CurrentLink
= CurrentLink
->ForwardLink
;
1120 // Check if we find the bridge
1122 if (CurrentLink
== &RootBridge
->ChildList
) {
1129 CurrentDevicePath
= NextDevicePathNode (CurrentDevicePath
);
1134 CurrentDevicePath
= NextDevicePathNode (CurrentDevicePath
);
1136 if (IsDevicePathEnd (CurrentDevicePath
)) {
1137 *PciAddress
= EFI_PCI_ADDRESS (RootBridge
->BusNumber
, Node
.Pci
->Device
, Node
.Pci
->Function
, 0);
1141 return EFI_NOT_FOUND
;
1145 *PciAddress
= EFI_PCI_ADDRESS (Temp
->BusNumber
, Temp
->DeviceNumber
, Temp
->FunctionNumber
, 0);
1147 return EFI_NOT_FOUND
;