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.
16 #include "PciEnumeratorSupport.h"
17 #include "PciCommand.h"
21 This routine is used to check whether the pci device is present.
23 @param PciRootBridgeIo Pointer to instance of EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
24 @param Pci Output buffer for PCI device structure
26 @param Device PCI device NO
27 @param Func PCI Func NO
29 @retval EFI_NOT_FOUND device not present
30 @retval EFI_SUCCESS device is found.
34 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
,
45 // Create PCI address map in terms of Bus, Device and Func
47 Address
= EFI_PCI_ADDRESS (Bus
, Device
, Func
, 0);
50 // Read the Vendor Id register
52 Status
= PciRootBridgeIoRead (
61 if (!EFI_ERROR (Status
) && (Pci
->Hdr
).VendorId
!= 0xffff) {
64 // Read the entire config header for the device
67 Status
= PciRootBridgeIoRead (
72 sizeof (PCI_TYPE00
) / sizeof (UINT32
),
83 Collect all the resource information under this root bridge
84 A database that records all the information about pci device subject to this
85 root bridge will then be created.
87 @param Bridge Parent bridge instance
88 @param StartBusNumer Bus number of begining
91 PciPciDeviceInfoCollector (
92 IN PCI_IO_DEVICE
*Bridge
,
101 PCI_IO_DEVICE
*PciIoDevice
;
102 EFI_PCI_IO_PROTOCOL
*PciIo
;
104 Status
= EFI_SUCCESS
;
107 for (Device
= 0; Device
<= PCI_MAX_DEVICE
; Device
++) {
109 for (Func
= 0; Func
<= PCI_MAX_FUNC
; Func
++) {
112 // Check to see whether PCI device is present
115 Status
= PciDevicePresent (
116 Bridge
->PciRootBridgeIo
,
118 (UINT8
) StartBusNumber
,
123 if (!EFI_ERROR (Status
)) {
126 // Call back to host bridge function
128 PreprocessController (Bridge
, (UINT8
) StartBusNumber
, Device
, Func
, EfiPciBeforeResourceCollection
);
131 // Collect all the information about the PCI device discovered
133 Status
= PciSearchDevice (
136 (UINT8
) StartBusNumber
,
143 // Recursively scan PCI busses on the other side of PCI-PCI bridges
147 if (!EFI_ERROR (Status
) && (IS_PCI_BRIDGE (&Pci
) || IS_CARDBUS_BRIDGE (&Pci
))) {
150 // If it is PPB, we need to get the secondary bus to continue the enumeration
152 PciIo
= &(PciIoDevice
->PciIo
);
154 Status
= PciIoRead (PciIo
, EfiPciIoWidthUint8
, 0x19, 1, &SecBus
);
156 if (EFI_ERROR (Status
)) {
161 // Get resource padding for PPB
163 GetResourcePaddingPpb (PciIoDevice
);
166 // Deep enumerate the next level bus
168 Status
= PciPciDeviceInfoCollector (
175 if (Func
== 0 && !IS_PCI_MULTI_FUNC (&Pci
)) {
178 // Skip sub functions, this is not a multi function device
191 Seach required device and get PCI device info block
193 @param Bridge Parent bridge instance
194 @param Pci Output of PCI device info block
195 @param Bus PCI bus NO.
196 @param Device PCI device NO.
197 @param Func PCI func NO.
198 @param PciDevice output of searched PCI device instance
202 IN PCI_IO_DEVICE
*Bridge
,
207 OUT PCI_IO_DEVICE
**PciDevice
210 PCI_IO_DEVICE
*PciIoDevice
;
214 if (!IS_PCI_BRIDGE (Pci
)) {
216 if (IS_CARDBUS_BRIDGE (Pci
)) {
217 PciIoDevice
= GatherP2CInfo (
224 if ((PciIoDevice
!= NULL
) && gFullEnumeration
) {
225 InitializeP2C (PciIoDevice
);
230 // Create private data for Pci Device
232 PciIoDevice
= GatherDeviceInfo (
245 // Create private data for PPB
247 PciIoDevice
= GatherPpbInfo (
256 // Special initialization for PPB including making the PPB quiet
258 if ((PciIoDevice
!= NULL
) && gFullEnumeration
) {
259 InitializePpb (PciIoDevice
);
264 return EFI_OUT_OF_RESOURCES
;
268 // Update the bar information for this PCI device so as to support some specific device
270 UpdatePciInfo (PciIoDevice
);
272 if (PciIoDevice
->DevicePath
== NULL
) {
273 return EFI_OUT_OF_RESOURCES
;
277 // Detect this function has option rom
279 if (gFullEnumeration
) {
281 if (!IS_CARDBUS_BRIDGE (Pci
)) {
283 GetOpRomInfo (PciIoDevice
);
287 ResetPowerManagementFeature (PciIoDevice
);
292 // Insert it into a global tree for future reference
294 InsertPciDevice (Bridge
, PciIoDevice
);
297 // Determine PCI device attributes
300 if (PciDevice
!= NULL
) {
301 *PciDevice
= PciIoDevice
;
308 Create PCI private data for PCI device
310 @param Bridge Parent bridge instance
311 @param Pci PCI bar block
312 @param Bus PCI device Bus NO.
313 @param Device PCI device DeviceNO.
314 @param Func PCI device's func NO.
316 @return new PCI device's private date structure.
320 IN PCI_IO_DEVICE
*Bridge
,
329 PCI_IO_DEVICE
*PciIoDevice
;
330 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
332 PciRootBridgeIo
= Bridge
->PciRootBridgeIo
;
333 PciIoDevice
= CreatePciIoDevice (
346 // Create a device path for this PCI device and store it into its private data
348 CreatePciDevicePath (
354 // If it is a full enumeration, disconnect the device in advance
356 if (gFullEnumeration
) {
358 PciDisableCommandRegister (PciIoDevice
, EFI_PCI_COMMAND_BITS_OWNED
);
363 // Start to parse the bars
365 for (Offset
= 0x10, BarIndex
= 0; Offset
<= 0x24; BarIndex
++) {
366 Offset
= PciParseBar (PciIoDevice
, Offset
, BarIndex
);
373 Create private data for bridge device's PPB.
375 @param Bridge Parent bridge
376 @param Pci Pci device block
377 @param Bus Bridge device's bus NO.
378 @param Device Bridge device's device NO.
379 @param Func Bridge device's func NO.
381 @return bridge device instance
385 IN PCI_IO_DEVICE
*Bridge
,
392 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
393 PCI_IO_DEVICE
*PciIoDevice
;
396 EFI_PCI_IO_PROTOCOL
*PciIo
;
399 PciRootBridgeIo
= Bridge
->PciRootBridgeIo
;
400 PciIoDevice
= CreatePciIoDevice (
413 // Create a device path for this PCI device and store it into its private data
415 CreatePciDevicePath (
420 if (gFullEnumeration
) {
421 PciDisableCommandRegister (PciIoDevice
, EFI_PCI_COMMAND_BITS_OWNED
);
424 // Initalize the bridge control register
426 PciDisableBridgeControlRegister (PciIoDevice
, EFI_PCI_BRIDGE_CONTROL_BITS_OWNED
);
431 // PPB can have two BARs
433 if (PciParseBar (PciIoDevice
, 0x10, PPB_BAR_0
) == 0x14) {
437 PciParseBar (PciIoDevice
, 0x14, PPB_BAR_1
);
440 PciIo
= &PciIoDevice
->PciIo
;
443 // Test whether it support 32 decode or not
445 PciIoRead (PciIo
, EfiPciIoWidthUint8
, 0x1C, 1, &Temp
);
446 PciIoWrite (PciIo
, EfiPciIoWidthUint8
, 0x1C, 1, &gAllOne
);
447 PciIoRead (PciIo
, EfiPciIoWidthUint8
, 0x1C, 1, &Value
);
448 PciIoWrite (PciIo
, EfiPciIoWidthUint8
, 0x1C, 1, &Temp
);
452 PciIoDevice
->Decodes
|= EFI_BRIDGE_IO32_DECODE_SUPPORTED
;
454 PciIoDevice
->Decodes
|= EFI_BRIDGE_IO16_DECODE_SUPPORTED
;
458 Status
= BarExisted (
466 // test if it supports 64 memory or not
468 if (!EFI_ERROR (Status
)) {
470 Status
= BarExisted (
477 if (!EFI_ERROR (Status
)) {
478 PciIoDevice
->Decodes
|= EFI_BRIDGE_PMEM32_DECODE_SUPPORTED
;
479 PciIoDevice
->Decodes
|= EFI_BRIDGE_PMEM64_DECODE_SUPPORTED
;
481 PciIoDevice
->Decodes
|= EFI_BRIDGE_PMEM32_DECODE_SUPPORTED
;
486 // Memory 32 code is required for ppb
488 PciIoDevice
->Decodes
|= EFI_BRIDGE_MEM32_DECODE_SUPPORTED
;
490 GetResourcePaddingPpb (PciIoDevice
);
496 Create private data for hotplug bridge device
498 @param Bridge Parent bridge instance
499 @param Pci PCI bar block
500 @param Bus hotplug bridge device's bus NO.
501 @param Device hotplug bridge device's device NO.
502 @param Func hotplug bridge device's Func NO.
504 @return hotplug bridge device instance
508 IN PCI_IO_DEVICE
*Bridge
,
515 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
516 PCI_IO_DEVICE
*PciIoDevice
;
518 PciRootBridgeIo
= Bridge
->PciRootBridgeIo
;
519 PciIoDevice
= CreatePciIoDevice (
532 // Create a device path for this PCI device and store it into its private data
534 CreatePciDevicePath (
539 if (gFullEnumeration
) {
540 PciDisableCommandRegister (PciIoDevice
, EFI_PCI_COMMAND_BITS_OWNED
);
543 // Initalize the bridge control register
545 PciDisableBridgeControlRegister (PciIoDevice
, EFI_PCCARD_BRIDGE_CONTROL_BITS_OWNED
);
549 // P2C only has one bar that is in 0x10
551 PciParseBar (PciIoDevice
, 0x10, P2C_BAR_0
);
554 // Read PciBar information from the bar register
556 GetBackPcCardBar (PciIoDevice
);
557 PciIoDevice
->Decodes
= EFI_BRIDGE_MEM32_DECODE_SUPPORTED
|
558 EFI_BRIDGE_PMEM32_DECODE_SUPPORTED
|
559 EFI_BRIDGE_IO32_DECODE_SUPPORTED
;
565 Create device path for pci deivce
567 @param ParentDevicePath Parent bridge's path
568 @param PciIoDevice Pci device instance
570 @return device path protocol instance for specific pci device.
572 EFI_DEVICE_PATH_PROTOCOL
*
573 CreatePciDevicePath (
574 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
,
575 IN PCI_IO_DEVICE
*PciIoDevice
579 PCI_DEVICE_PATH PciNode
;
582 // Create PCI device path
584 PciNode
.Header
.Type
= HARDWARE_DEVICE_PATH
;
585 PciNode
.Header
.SubType
= HW_PCI_DP
;
586 SetDevicePathNodeLength (&PciNode
.Header
, sizeof (PciNode
));
588 PciNode
.Device
= PciIoDevice
->DeviceNumber
;
589 PciNode
.Function
= PciIoDevice
->FunctionNumber
;
590 PciIoDevice
->DevicePath
= AppendDevicePathNode (ParentDevicePath
, &PciNode
.Header
);
592 return PciIoDevice
->DevicePath
;
596 Check the bar is existed or not.
598 @param PciIoDevice - A pointer to the PCI_IO_DEVICE.
599 @param Offset - The offset.
600 @param BarLengthValue - The bar length value.
601 @param OriginalBarValue - The original bar value.
603 @retval EFI_NOT_FOUND - The bar don't exist.
604 @retval EFI_SUCCESS - The bar exist.
609 IN PCI_IO_DEVICE
*PciIoDevice
,
611 OUT UINT32
*BarLengthValue
,
612 OUT UINT32
*OriginalBarValue
616 EFI_PCI_IO_PROTOCOL
*PciIo
;
617 UINT32 OriginalValue
;
621 PciIo
= &PciIoDevice
->PciIo
;
624 // Preserve the original value
627 PciIoRead (PciIo
, EfiPciIoWidthUint32
, (UINT8
) Offset
, 1, &OriginalValue
);
630 // Raise TPL to high level to disable timer interrupt while the BAR is probed
632 OldTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
634 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, (UINT8
) Offset
, 1, &gAllOne
);
635 PciIoRead (PciIo
, EfiPciIoWidthUint32
, (UINT8
) Offset
, 1, &Value
);
638 // Write back the original value
640 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, (UINT8
) Offset
, 1, &OriginalValue
);
643 // Restore TPL to its original level
645 gBS
->RestoreTPL (OldTpl
);
647 if (BarLengthValue
!= NULL
) {
648 *BarLengthValue
= Value
;
651 if (OriginalBarValue
!= NULL
) {
652 *OriginalBarValue
= OriginalValue
;
656 return EFI_NOT_FOUND
;
663 Test whether the device can support attributes
665 @param PciIoDevice Pci device instance
666 @param Command Command register value.
667 @param BridgeControl Bridge control value for PPB or P2C.
668 @param OldCommand Old command register offset
669 @param OldBridgeControl Old Bridge control value for PPB or P2C.
674 PciTestSupportedAttribute (
675 IN PCI_IO_DEVICE
*PciIoDevice
,
677 IN UINT16
*BridgeControl
,
678 IN UINT16
*OldCommand
,
679 IN UINT16
*OldBridgeControl
685 // Preserve the original value
687 PciReadCommandRegister (PciIoDevice
, OldCommand
);
690 // Raise TPL to high level to disable timer interrupt while the BAR is probed
692 OldTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
694 PciSetCommandRegister (PciIoDevice
, *Command
);
695 PciReadCommandRegister (PciIoDevice
, Command
);
698 // Write back the original value
700 PciSetCommandRegister (PciIoDevice
, *OldCommand
);
703 // Restore TPL to its original level
705 gBS
->RestoreTPL (OldTpl
);
707 if (IS_PCI_BRIDGE (&PciIoDevice
->Pci
) || IS_CARDBUS_BRIDGE (&PciIoDevice
->Pci
)) {
710 // Preserve the original value
712 PciReadBridgeControlRegister (PciIoDevice
, OldBridgeControl
);
715 // Raise TPL to high level to disable timer interrupt while the BAR is probed
717 OldTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
719 PciSetBridgeControlRegister (PciIoDevice
, *BridgeControl
);
720 PciReadBridgeControlRegister (PciIoDevice
, BridgeControl
);
723 // Write back the original value
725 PciSetBridgeControlRegister (PciIoDevice
, *OldBridgeControl
);
728 // Restore TPL to its original level
730 gBS
->RestoreTPL (OldTpl
);
733 *OldBridgeControl
= 0;
741 Set the supported or current attributes of a PCI device
743 @param PciIoDevice - Structure pointer for PCI device.
744 @param Command - Command register value.
745 @param BridgeControl - Bridge control value for PPB or P2C.
746 @param Option - Make a choice of EFI_SET_SUPPORTS or EFI_SET_ATTRIBUTES.
750 PciSetDeviceAttribute (
751 IN PCI_IO_DEVICE
*PciIoDevice
,
753 IN UINT16 BridgeControl
,
761 if (Command
& EFI_PCI_COMMAND_IO_SPACE
) {
762 Attributes
|= EFI_PCI_IO_ATTRIBUTE_IO
;
765 if (Command
& EFI_PCI_COMMAND_MEMORY_SPACE
) {
766 Attributes
|= EFI_PCI_IO_ATTRIBUTE_MEMORY
;
769 if (Command
& EFI_PCI_COMMAND_BUS_MASTER
) {
770 Attributes
|= EFI_PCI_IO_ATTRIBUTE_BUS_MASTER
;
773 if (Command
& EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
) {
774 Attributes
|= EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO
;
777 if (BridgeControl
& EFI_PCI_BRIDGE_CONTROL_ISA
) {
778 Attributes
|= EFI_PCI_IO_ATTRIBUTE_ISA_IO
;
781 if (BridgeControl
& EFI_PCI_BRIDGE_CONTROL_VGA
) {
782 Attributes
|= EFI_PCI_IO_ATTRIBUTE_VGA_IO
;
783 Attributes
|= EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY
;
784 Attributes
|= EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO
;
787 if (BridgeControl
& EFI_PCI_BRIDGE_CONTROL_VGA_16
) {
788 Attributes
|= EFI_PCI_IO_ATTRIBUTE_VGA_IO_16
;
789 Attributes
|= EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16
;
792 if (Option
== EFI_SET_SUPPORTS
) {
794 Attributes
|= EFI_PCI_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE
|
795 EFI_PCI_IO_ATTRIBUTE_MEMORY_CACHED
|
796 EFI_PCI_IO_ATTRIBUTE_MEMORY_DISABLE
|
797 EFI_PCI_IO_ATTRIBUTE_EMBEDDED_DEVICE
|
798 EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM
|
799 EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE
;
801 if (Attributes
& EFI_PCI_IO_ATTRIBUTE_IO
) {
802 Attributes
|= EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO
;
803 Attributes
|= EFI_PCI_IO_ATTRIBUTE_ISA_IO
;
806 if (IS_PCI_BRIDGE (&PciIoDevice
->Pci
) || IS_CARDBUS_BRIDGE (&PciIoDevice
->Pci
)) {
808 // For bridge, it should support IDE attributes
810 Attributes
|= EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO
;
811 Attributes
|= EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO
;
814 if (IS_PCI_IDE (&PciIoDevice
->Pci
)) {
815 Attributes
|= EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO
;
816 Attributes
|= EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO
;
819 if (IS_PCI_VGA (&PciIoDevice
->Pci
)) {
820 Attributes
|= EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY
;
821 Attributes
|= EFI_PCI_IO_ATTRIBUTE_VGA_IO
;
825 PciIoDevice
->Supports
= Attributes
;
826 PciIoDevice
->Supports
&= ( (PciIoDevice
->Parent
->Supports
) | \
827 EFI_PCI_IO_ATTRIBUTE_IO
| EFI_PCI_IO_ATTRIBUTE_MEMORY
| \
828 EFI_PCI_IO_ATTRIBUTE_BUS_MASTER
);
831 PciIoDevice
->Attributes
= Attributes
;
838 Determine if the device can support Fast Back to Back attribute
840 @param PciIoDevice Pci device instance
841 @param StatusIndex Status register value
844 GetFastBackToBackSupport (
845 IN PCI_IO_DEVICE
*PciIoDevice
,
849 EFI_PCI_IO_PROTOCOL
*PciIo
;
851 UINT32 StatusRegister
;
854 // Read the status register
856 PciIo
= &PciIoDevice
->PciIo
;
857 Status
= PciIoRead (PciIo
, EfiPciIoWidthUint16
, StatusIndex
, 1, &StatusRegister
);
858 if (EFI_ERROR (Status
)) {
859 return EFI_UNSUPPORTED
;
863 // Check the Fast B2B bit
865 if (StatusRegister
& EFI_PCI_FAST_BACK_TO_BACK_CAPABLE
) {
868 return EFI_UNSUPPORTED
;
874 Process the option ROM for all the children of the specified parent PCI device.
875 It can only be used after the first full Option ROM process.
877 @param PciIoDevice Pci device instance
879 @retval EFI_SUCCESS Success Operation.
883 ProcessOptionRomLight (
884 IN PCI_IO_DEVICE
*PciIoDevice
888 LIST_ENTRY
*CurrentLink
;
891 // For RootBridge, PPB , P2C, go recursively to traverse all its children
893 CurrentLink
= PciIoDevice
->ChildList
.ForwardLink
;
894 while (CurrentLink
&& CurrentLink
!= &PciIoDevice
->ChildList
) {
896 Temp
= PCI_IO_DEVICE_FROM_LINK (CurrentLink
);
898 if (!IsListEmpty (&Temp
->ChildList
)) {
899 ProcessOptionRomLight (Temp
);
902 PciRomGetImageMapping (Temp
);
905 // The OpRom has already been processed in the first round
907 Temp
->AllOpRomProcessed
= TRUE
;
909 CurrentLink
= CurrentLink
->ForwardLink
;
916 Determine the related attributes of all devices under a Root Bridge
918 @param PciIoDevice PCI device instance
922 DetermineDeviceAttribute (
923 IN PCI_IO_DEVICE
*PciIoDevice
927 UINT16 BridgeControl
;
929 UINT16 OldBridgeControl
;
930 BOOLEAN FastB2BSupport
;
934 EFI_PCI_IO_PROTOCOL *PciIo;
937 LIST_ENTRY
*CurrentLink
;
941 // For Root Bridge, just copy it by RootBridgeIo proctocol
942 // so as to keep consistent with the actual attribute
944 if (!PciIoDevice
->Parent
) {
945 Status
= PciIoDevice
->PciRootBridgeIo
->GetAttributes (
946 PciIoDevice
->PciRootBridgeIo
,
947 &PciIoDevice
->Supports
,
948 &PciIoDevice
->Attributes
950 if (EFI_ERROR (Status
)) {
956 // Set the attributes to be checked for common PCI devices and PPB or P2C
957 // Since some devices only support part of them, it is better to set the
958 // attribute according to its command or bridge control register
960 Command
= EFI_PCI_COMMAND_IO_SPACE
|
961 EFI_PCI_COMMAND_MEMORY_SPACE
|
962 EFI_PCI_COMMAND_BUS_MASTER
|
963 EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
;
965 BridgeControl
= EFI_PCI_BRIDGE_CONTROL_ISA
| EFI_PCI_BRIDGE_CONTROL_VGA
| EFI_PCI_BRIDGE_CONTROL_VGA_16
;
968 // Test whether the device can support attributes above
970 PciTestSupportedAttribute (PciIoDevice
, &Command
, &BridgeControl
, &OldCommand
, &OldBridgeControl
);
973 // Set the supported attributes for specified PCI device
975 PciSetDeviceAttribute (PciIoDevice
, Command
, BridgeControl
, EFI_SET_SUPPORTS
);
978 // Set the current attributes for specified PCI device
980 PciSetDeviceAttribute (PciIoDevice
, OldCommand
, OldBridgeControl
, EFI_SET_ATTRIBUTES
);
983 // Enable other supported attributes but not defined in PCI_IO_PROTOCOL
985 PciEnableCommandRegister (PciIoDevice
, EFI_PCI_COMMAND_MEMORY_WRITE_AND_INVALIDATE
);
988 // Enable IDE native mode
991 if (IS_PCI_IDE(&PciIoDevice->Pci)) {
993 PciIo = &PciIoDevice->PciIo;
1004 // Set native mode if it can be supported
1006 IdePI |= (((IdePI & 0x0F) >> 1) & 0x05);
1020 FastB2BSupport
= TRUE
;
1023 // P2C can not support FB2B on the secondary side
1025 if (IS_CARDBUS_BRIDGE (&PciIoDevice
->Pci
)) {
1026 FastB2BSupport
= FALSE
;
1030 // For RootBridge, PPB , P2C, go recursively to traverse all its children
1032 CurrentLink
= PciIoDevice
->ChildList
.ForwardLink
;
1033 while (CurrentLink
&& CurrentLink
!= &PciIoDevice
->ChildList
) {
1035 Temp
= PCI_IO_DEVICE_FROM_LINK (CurrentLink
);
1036 Status
= DetermineDeviceAttribute (Temp
);
1037 if (EFI_ERROR (Status
)) {
1041 // Detect Fast Bact to Bact support for the device under the bridge
1043 Status
= GetFastBackToBackSupport (Temp
, PCI_PRIMARY_STATUS_OFFSET
);
1044 if (FastB2BSupport
&& EFI_ERROR (Status
)) {
1045 FastB2BSupport
= FALSE
;
1048 CurrentLink
= CurrentLink
->ForwardLink
;
1051 // Set or clear Fast Back to Back bit for the whole bridge
1053 if (!IsListEmpty (&PciIoDevice
->ChildList
)) {
1055 if (IS_PCI_BRIDGE (&PciIoDevice
->Pci
)) {
1057 Status
= GetFastBackToBackSupport (PciIoDevice
, PCI_BRIDGE_STATUS_REGISTER_OFFSET
);
1059 if (EFI_ERROR (Status
) || (!FastB2BSupport
)) {
1060 FastB2BSupport
= FALSE
;
1061 PciDisableBridgeControlRegister (PciIoDevice
, EFI_PCI_BRIDGE_CONTROL_FAST_BACK_TO_BACK
);
1063 PciEnableBridgeControlRegister (PciIoDevice
, EFI_PCI_BRIDGE_CONTROL_FAST_BACK_TO_BACK
);
1067 CurrentLink
= PciIoDevice
->ChildList
.ForwardLink
;
1068 while (CurrentLink
&& CurrentLink
!= &PciIoDevice
->ChildList
) {
1069 Temp
= PCI_IO_DEVICE_FROM_LINK (CurrentLink
);
1070 if (FastB2BSupport
) {
1071 PciEnableCommandRegister (Temp
, EFI_PCI_COMMAND_FAST_BACK_TO_BACK
);
1073 PciDisableCommandRegister (Temp
, EFI_PCI_COMMAND_FAST_BACK_TO_BACK
);
1076 CurrentLink
= CurrentLink
->ForwardLink
;
1080 // End for IsListEmpty
1086 This routine is used to update the bar information for those incompatible PCI device
1088 @param PciIoDevice Pci device instance
1089 @return EFI_UNSUPPORTED failed to update Pci Info
1093 IN PCI_IO_DEVICE
*PciIoDevice
1100 EFI_PCI_DEVICE_INFO PciDeviceInfo
;
1101 VOID
*Configuration
;
1102 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Ptr
;
1104 Configuration
= NULL
;
1105 Status
= EFI_SUCCESS
;
1107 if (gEfiIncompatiblePciDeviceSupport
== NULL
) {
1109 // It can only be supported after the Incompatible PCI Device
1110 // Support Protocol has been installed
1112 Status
= gBS
->LocateProtocol (
1113 &gEfiIncompatiblePciDeviceSupportProtocolGuid
,
1115 (VOID
**) &gEfiIncompatiblePciDeviceSupport
1118 if (Status
== EFI_SUCCESS
) {
1120 // Check whether the device belongs to incompatible devices from protocol or not
1121 // If it is , then get its special requirement in the ACPI table
1123 Status
= gEfiIncompatiblePciDeviceSupport
->CheckDevice (
1124 gEfiIncompatiblePciDeviceSupport
,
1125 PciIoDevice
->Pci
.Hdr
.VendorId
,
1126 PciIoDevice
->Pci
.Hdr
.DeviceId
,
1127 PciIoDevice
->Pci
.Hdr
.RevisionID
,
1128 PciIoDevice
->Pci
.Device
.SubsystemVendorID
,
1129 PciIoDevice
->Pci
.Device
.SubsystemID
,
1135 if (EFI_ERROR (Status
)) {
1137 // Check whether the device belongs to incompatible devices from library or not
1138 // If it is , then get its special requirement in the ACPI table
1140 if (PcdGet8 (PcdPciIncompatibleDeviceSupportMask
) & PCI_INCOMPATIBLE_ACPI_RESOURCE_SUPPORT
) {
1141 PciDeviceInfo
.VendorID
= PciIoDevice
->Pci
.Hdr
.VendorId
;
1142 PciDeviceInfo
.DeviceID
= PciIoDevice
->Pci
.Hdr
.DeviceId
;
1143 PciDeviceInfo
.RevisionID
= PciIoDevice
->Pci
.Hdr
.RevisionID
;
1144 PciDeviceInfo
.SubsystemVendorID
= PciIoDevice
->Pci
.Device
.SubsystemVendorID
;
1145 PciDeviceInfo
.SubsystemID
= PciIoDevice
->Pci
.Device
.SubsystemID
;
1147 Status
= PciResourceUpdateCheck (&PciDeviceInfo
, &Configuration
);
1151 if (EFI_ERROR (Status
)) {
1152 return EFI_UNSUPPORTED
;
1156 // Update PCI device information from the ACPI table
1158 Ptr
= (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Configuration
;
1160 while (Ptr
->Desc
!= ACPI_END_TAG_DESCRIPTOR
) {
1162 if (Ptr
->Desc
!= ACPI_ADDRESS_SPACE_DESCRIPTOR
) {
1164 // The format is not support
1169 BarIndex
= (UINTN
) Ptr
->AddrTranslationOffset
;
1170 BarEndIndex
= BarIndex
;
1173 // Update all the bars in the device
1175 if (BarIndex
== PCI_BAR_ALL
) {
1177 BarEndIndex
= PCI_MAX_BAR
- 1;
1180 if (BarIndex
>= PCI_MAX_BAR
) {
1185 for (; BarIndex
<= BarEndIndex
; BarIndex
++) {
1187 switch (Ptr
->ResType
) {
1188 case ACPI_ADDRESS_SPACE_TYPE_MEM
:
1191 // Make sure the bar is memory type
1193 if (CheckBarType (PciIoDevice
, (UINT8
) BarIndex
, PciBarTypeMem
)) {
1198 case ACPI_ADDRESS_SPACE_TYPE_IO
:
1201 // Make sure the bar is IO type
1203 if (CheckBarType (PciIoDevice
, (UINT8
) BarIndex
, PciBarTypeIo
)) {
1212 // Update the new alignment for the device
1214 SetNewAlign (&(PciIoDevice
->PciBar
[BarIndex
].Alignment
), Ptr
->AddrRangeMax
);
1217 // Update the new length for the device
1219 if (Ptr
->AddrLen
!= PCI_BAR_NOCHANGE
) {
1220 PciIoDevice
->PciBar
[BarIndex
].Length
= Ptr
->AddrLen
;
1228 gBS
->FreePool (Configuration
);
1234 This routine will update the alignment with the new alignment
1236 @param Alignment old alignment
1237 @param NewAlignment new alignment
1242 IN UINT64
*Alignment
,
1243 IN UINT64 NewAlignment
1246 UINT64 OldAlignment
;
1250 // The new alignment is the same as the original,
1253 if (NewAlignment
== PCI_BAR_OLD_ALIGN
) {
1257 // Check the validity of the parameter
1259 if (NewAlignment
!= PCI_BAR_EVEN_ALIGN
&&
1260 NewAlignment
!= PCI_BAR_SQUAD_ALIGN
&&
1261 NewAlignment
!= PCI_BAR_DQUAD_ALIGN
) {
1262 *Alignment
= NewAlignment
;
1266 OldAlignment
= (*Alignment
) + 1;
1270 // Get the first non-zero hex value of the length
1272 while ((OldAlignment
& 0x0F) == 0x00) {
1273 OldAlignment
= RShiftU64 (OldAlignment
, 4);
1278 // Adjust the alignment to even, quad or double quad boundary
1280 if (NewAlignment
== PCI_BAR_EVEN_ALIGN
) {
1281 if (OldAlignment
& 0x01) {
1282 OldAlignment
= OldAlignment
+ 2 - (OldAlignment
& 0x01);
1284 } else if (NewAlignment
== PCI_BAR_SQUAD_ALIGN
) {
1285 if (OldAlignment
& 0x03) {
1286 OldAlignment
= OldAlignment
+ 4 - (OldAlignment
& 0x03);
1288 } else if (NewAlignment
== PCI_BAR_DQUAD_ALIGN
) {
1289 if (OldAlignment
& 0x07) {
1290 OldAlignment
= OldAlignment
+ 8 - (OldAlignment
& 0x07);
1295 // Update the old value
1297 NewAlignment
= LShiftU64 (OldAlignment
, ShiftBit
) - 1;
1298 *Alignment
= NewAlignment
;
1306 @param PciIoDevice Pci device instance
1307 @param Offset bar offset
1308 @param BarIndex bar index
1310 @return next bar offset.
1314 IN PCI_IO_DEVICE
*PciIoDevice
,
1320 UINT32 OriginalValue
;
1329 Status
= BarExisted (
1336 if (EFI_ERROR (Status
)) {
1337 PciIoDevice
->PciBar
[BarIndex
].BaseAddress
= 0;
1338 PciIoDevice
->PciBar
[BarIndex
].Length
= 0;
1339 PciIoDevice
->PciBar
[BarIndex
].Alignment
= 0;
1342 // Some devices don't fully comply to PCI spec 2.2. So be to scan all the BARs anyway
1344 PciIoDevice
->PciBar
[BarIndex
].Offset
= (UINT8
) Offset
;
1348 PciIoDevice
->PciBar
[BarIndex
].Offset
= (UINT8
) Offset
;
1355 if (Value
& 0xFFFF0000) {
1359 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypeIo32
;
1360 PciIoDevice
->PciBar
[BarIndex
].Length
= ((~(Value
& Mask
)) + 1);
1361 PciIoDevice
->PciBar
[BarIndex
].Alignment
= PciIoDevice
->PciBar
[BarIndex
].Length
- 1;
1367 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypeIo16
;
1368 PciIoDevice
->PciBar
[BarIndex
].Length
= 0x0000FFFF & ((~(Value
& Mask
)) + 1);
1369 PciIoDevice
->PciBar
[BarIndex
].Alignment
= PciIoDevice
->PciBar
[BarIndex
].Length
- 1;
1373 // Workaround. Some platforms inplement IO bar with 0 length
1374 // Need to treat it as no-bar
1376 if (PciIoDevice
->PciBar
[BarIndex
].Length
== 0) {
1377 PciIoDevice
->PciBar
[BarIndex
].BarType
= (PCI_BAR_TYPE
) 0;
1380 PciIoDevice
->PciBar
[BarIndex
].Prefetchable
= FALSE
;
1381 PciIoDevice
->PciBar
[BarIndex
].BaseAddress
= OriginalValue
& Mask
;
1387 PciIoDevice
->PciBar
[BarIndex
].BaseAddress
= OriginalValue
& Mask
;
1389 switch (Value
& 0x07) {
1392 //memory space; anywhere in 32 bit address space
1396 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypePMem32
;
1398 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypeMem32
;
1401 PciIoDevice
->PciBar
[BarIndex
].Length
= (~(Value
& Mask
)) + 1;
1402 PciIoDevice
->PciBar
[BarIndex
].Alignment
= PciIoDevice
->PciBar
[BarIndex
].Length
- 1;
1407 // memory space; anywhere in 64 bit address space
1411 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypePMem64
;
1413 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypeMem64
;
1417 // According to PCI 2.2,if the bar indicates a memory 64 decoding, next bar
1418 // is regarded as an extension for the first bar. As a result
1419 // the sizing will be conducted on combined 64 bit value
1420 // Here just store the masked first 32bit value for future size
1423 PciIoDevice
->PciBar
[BarIndex
].Length
= Value
& Mask
;
1424 PciIoDevice
->PciBar
[BarIndex
].Alignment
= PciIoDevice
->PciBar
[BarIndex
].Length
- 1;
1427 // Increment the offset to point to next DWORD
1431 Status
= BarExisted (
1438 if (EFI_ERROR (Status
)) {
1443 // Fix the length to support some spefic 64 bit BAR
1447 for (Data
= Value
; Data
!= 0; Data
>>= 1) {
1450 Value
|= ((UINT32
)(-1) << Index
);
1453 // Calculate the size of 64bit bar
1455 PciIoDevice
->PciBar
[BarIndex
].BaseAddress
|= LShiftU64 ((UINT64
) OriginalValue
, 32);
1457 PciIoDevice
->PciBar
[BarIndex
].Length
= PciIoDevice
->PciBar
[BarIndex
].Length
| LShiftU64 ((UINT64
) Value
, 32);
1458 PciIoDevice
->PciBar
[BarIndex
].Length
= (~(PciIoDevice
->PciBar
[BarIndex
].Length
)) + 1;
1459 PciIoDevice
->PciBar
[BarIndex
].Alignment
= PciIoDevice
->PciBar
[BarIndex
].Length
- 1;
1467 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypeUnknown
;
1468 PciIoDevice
->PciBar
[BarIndex
].Length
= (~(Value
& Mask
)) + 1;
1469 PciIoDevice
->PciBar
[BarIndex
].Alignment
= PciIoDevice
->PciBar
[BarIndex
].Length
- 1;
1476 // Check the length again so as to keep compatible with some special bars
1478 if (PciIoDevice
->PciBar
[BarIndex
].Length
== 0) {
1479 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypeUnknown
;
1480 PciIoDevice
->PciBar
[BarIndex
].BaseAddress
= 0;
1481 PciIoDevice
->PciBar
[BarIndex
].Alignment
= 0;
1485 // Increment number of bar
1491 This routine is used to initialize the bar of a PCI device
1492 It can be called typically when a device is going to be rejected
1494 @param PciIoDevice Pci device instance
1497 InitializePciDevice (
1498 IN PCI_IO_DEVICE
*PciIoDevice
1501 EFI_PCI_IO_PROTOCOL
*PciIo
;
1504 PciIo
= &(PciIoDevice
->PciIo
);
1507 // Put all the resource apertures
1508 // Resource base is set to all ones so as to indicate its resource
1509 // has not been alloacted
1511 for (Offset
= 0x10; Offset
<= 0x24; Offset
+= sizeof (UINT32
)) {
1512 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, Offset
, 1, &gAllOne
);
1519 Init PPB for bridge device
1521 @param PciIoDevice Pci device instance
1525 IN PCI_IO_DEVICE
*PciIoDevice
1528 EFI_PCI_IO_PROTOCOL
*PciIo
;
1530 PciIo
= &(PciIoDevice
->PciIo
);
1533 // Put all the resource apertures including IO16
1534 // Io32, pMem32, pMem64 to quiescent state
1535 // Resource base all ones, Resource limit all zeros
1537 PciIoWrite (PciIo
, EfiPciIoWidthUint8
, 0x1C, 1, &gAllOne
);
1538 PciIoWrite (PciIo
, EfiPciIoWidthUint8
, 0x1D, 1, &gAllZero
);
1540 PciIoWrite (PciIo
, EfiPciIoWidthUint16
, 0x20, 1, &gAllOne
);
1541 PciIoWrite (PciIo
, EfiPciIoWidthUint16
, 0x22, 1, &gAllZero
);
1543 PciIoWrite (PciIo
, EfiPciIoWidthUint16
, 0x24, 1, &gAllOne
);
1544 PciIoWrite (PciIo
, EfiPciIoWidthUint16
, 0x26, 1, &gAllZero
);
1546 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x28, 1, &gAllOne
);
1547 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x2C, 1, &gAllZero
);
1550 // don't support use io32 as for now
1552 PciIoWrite (PciIo
, EfiPciIoWidthUint16
, 0x30, 1, &gAllOne
);
1553 PciIoWrite (PciIo
, EfiPciIoWidthUint16
, 0x32, 1, &gAllZero
);
1556 // Force Interrupt line to zero for cards that come up randomly
1558 PciIoWrite (PciIo
, EfiPciIoWidthUint8
, 0x3C, 1, &gAllZero
);
1564 Init private data for Hotplug bridge device
1566 @param PciIoDevice hotplug bridge device
1570 IN PCI_IO_DEVICE
*PciIoDevice
1573 EFI_PCI_IO_PROTOCOL
*PciIo
;
1575 PciIo
= &(PciIoDevice
->PciIo
);
1578 // Put all the resource apertures including IO16
1579 // Io32, pMem32, pMem64 to quiescent state(
1580 // Resource base all ones, Resource limit all zeros
1582 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x1c, 1, &gAllOne
);
1583 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x20, 1, &gAllZero
);
1585 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x24, 1, &gAllOne
);
1586 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x28, 1, &gAllZero
);
1588 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x2c, 1, &gAllOne
);
1589 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x30, 1, &gAllZero
);
1591 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x34, 1, &gAllOne
);
1592 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x38, 1, &gAllZero
);
1595 // Force Interrupt line to zero for cards that come up randomly
1597 PciIoWrite (PciIo
, EfiPciIoWidthUint8
, 0x3C, 1, &gAllZero
);
1602 Create and initiliaze general PCI I/O device instance for
1603 PCI device/bridge device/hotplug bridge device.
1605 @param PciRootBridgeIo Pointer to instance of EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
1606 @param Pci Pci bar block
1607 @param Bus device Bus NO.
1608 @param Device device device NO.
1609 @param Func device func NO.
1611 @return instance of PCI device
1615 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
,
1624 PCI_IO_DEVICE
*PciIoDevice
;
1628 Status
= gBS
->AllocatePool (
1629 EfiBootServicesData
,
1630 sizeof (PCI_IO_DEVICE
),
1631 (VOID
**) &PciIoDevice
1634 if (EFI_ERROR (Status
)) {
1638 ZeroMem (PciIoDevice
, sizeof (PCI_IO_DEVICE
));
1640 PciIoDevice
->Signature
= PCI_IO_DEVICE_SIGNATURE
;
1641 PciIoDevice
->Handle
= NULL
;
1642 PciIoDevice
->PciRootBridgeIo
= PciRootBridgeIo
;
1643 PciIoDevice
->DevicePath
= NULL
;
1644 PciIoDevice
->BusNumber
= Bus
;
1645 PciIoDevice
->DeviceNumber
= Device
;
1646 PciIoDevice
->FunctionNumber
= Func
;
1647 PciIoDevice
->Decodes
= 0;
1648 if (gFullEnumeration
) {
1649 PciIoDevice
->Allocated
= FALSE
;
1651 PciIoDevice
->Allocated
= TRUE
;
1654 PciIoDevice
->Registered
= FALSE
;
1655 PciIoDevice
->Attributes
= 0;
1656 PciIoDevice
->Supports
= 0;
1657 PciIoDevice
->BusOverride
= FALSE
;
1658 PciIoDevice
->AllOpRomProcessed
= FALSE
;
1660 PciIoDevice
->IsPciExp
= FALSE
;
1662 CopyMem (&(PciIoDevice
->Pci
), Pci
, sizeof (PCI_TYPE01
));
1665 // Initialize the PCI I/O instance structure
1668 Status
= InitializePciIoInstance (PciIoDevice
);
1669 Status
= InitializePciDriverOverrideInstance (PciIoDevice
);
1671 if (EFI_ERROR (Status
)) {
1672 gBS
->FreePool (PciIoDevice
);
1677 // Initialize the reserved resource list
1679 InitializeListHead (&PciIoDevice
->ReservedResourceList
);
1682 // Initialize the driver list
1684 InitializeListHead (&PciIoDevice
->OptionRomDriverList
);
1687 // Initialize the child list
1689 InitializeListHead (&PciIoDevice
->ChildList
);
1695 This routine is used to enumerate entire pci bus system
1697 It is only called on the second start on the same Root Bridge.
1699 @param Controller Parent bridge handler
1701 @return status of operation.
1704 PciEnumeratorLight (
1705 IN EFI_HANDLE Controller
1710 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
1711 PCI_IO_DEVICE
*RootBridgeDev
;
1714 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Descriptors
;
1717 MaxBus
= PCI_MAX_BUS
;
1721 // If this root bridge has been already enumerated, then return successfully
1723 if (GetRootBridgeByHandle (Controller
) != NULL
) {
1728 // Open pci root bridge io protocol
1730 Status
= gBS
->OpenProtocol (
1732 &gEfiPciRootBridgeIoProtocolGuid
,
1733 (VOID
**) &PciRootBridgeIo
,
1734 gPciBusDriverBinding
.DriverBindingHandle
,
1736 EFI_OPEN_PROTOCOL_BY_DRIVER
1738 if (EFI_ERROR (Status
) && Status
!= EFI_ALREADY_STARTED
) {
1742 Status
= PciRootBridgeIo
->Configuration (PciRootBridgeIo
, (VOID
**) &Descriptors
);
1744 if (EFI_ERROR (Status
)) {
1748 while (PciGetBusRange (&Descriptors
, &MinBus
, &MaxBus
, NULL
) == EFI_SUCCESS
) {
1751 // Create a device node for root bridge device with a NULL host bridge controller handle
1753 RootBridgeDev
= CreateRootBridge (Controller
);
1755 if (!RootBridgeDev
) {
1761 // Record the root bridge io protocol
1763 RootBridgeDev
->PciRootBridgeIo
= PciRootBridgeIo
;
1765 Status
= PciPciDeviceInfoCollector (
1770 if (!EFI_ERROR (Status
)) {
1773 // Remove those PCI devices which are rejected when full enumeration
1775 RemoveRejectedPciDevices (RootBridgeDev
->Handle
, RootBridgeDev
);
1778 // Process option rom light
1780 ProcessOptionRomLight (RootBridgeDev
);
1783 // Determine attributes for all devices under this root bridge
1785 DetermineDeviceAttribute (RootBridgeDev
);
1788 // If successfully, insert the node into device pool
1790 InsertRootBridge (RootBridgeDev
);
1794 // If unsuccessly, destroy the entire node
1796 DestroyRootBridge (RootBridgeDev
);
1808 @param Descriptors A pointer to the address space descriptor.
1809 @param MinBus The min bus.
1810 @param MaxBus The max bus.
1811 @param BusRange The bus range.
1813 @retval EFI_SUCCESS Success operation.
1814 @retval EFI_NOT_FOUND can not find the specific bus.
1818 IN EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
**Descriptors
,
1821 OUT UINT16
*BusRange
1825 while ((*Descriptors
)->Desc
!= ACPI_END_TAG_DESCRIPTOR
) {
1826 if ((*Descriptors
)->ResType
== ACPI_ADDRESS_SPACE_TYPE_BUS
) {
1827 if (MinBus
!= NULL
) {
1828 *MinBus
= (UINT16
) (*Descriptors
)->AddrRangeMin
;
1831 if (MaxBus
!= NULL
) {
1832 *MaxBus
= (UINT16
) (*Descriptors
)->AddrRangeMax
;
1835 if (BusRange
!= NULL
) {
1836 *BusRange
= (UINT16
) (*Descriptors
)->AddrLen
;
1845 return EFI_NOT_FOUND
;
1849 StartManagingRootBridge (
1850 IN PCI_IO_DEVICE
*RootBridgeDev
1853 EFI_HANDLE RootBridgeHandle
;
1855 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
1858 // Get the root bridge handle
1860 RootBridgeHandle
= RootBridgeDev
->Handle
;
1861 PciRootBridgeIo
= NULL
;
1864 // Get the pci root bridge io protocol
1866 Status
= gBS
->OpenProtocol (
1868 &gEfiPciRootBridgeIoProtocolGuid
,
1869 (VOID
**) &PciRootBridgeIo
,
1870 gPciBusDriverBinding
.DriverBindingHandle
,
1872 EFI_OPEN_PROTOCOL_BY_DRIVER
1875 if (EFI_ERROR (Status
) && Status
!= EFI_ALREADY_STARTED
) {
1880 // Store the PciRootBridgeIo protocol into root bridge private data
1882 RootBridgeDev
->PciRootBridgeIo
= PciRootBridgeIo
;
1889 This routine can be used to check whether a PCI device should be rejected when light enumeration
1891 @param PciIoDevice Pci device instance
1893 @retval TRUE This device should be rejected
1894 @retval FALSE This device shouldn't be rejected
1898 IsPciDeviceRejected (
1899 IN PCI_IO_DEVICE
*PciIoDevice
1909 // PPB should be skip!
1911 if (IS_PCI_BRIDGE (&PciIoDevice
->Pci
)) {
1915 if (IS_CARDBUS_BRIDGE (&PciIoDevice
->Pci
)) {
1917 // Only test base registers for P2C
1919 for (BarOffset
= 0x1C; BarOffset
<= 0x38; BarOffset
+= 2 * sizeof (UINT32
)) {
1921 Mask
= (BarOffset
< 0x2C) ? 0xFFFFF000 : 0xFFFFFFFC;
1922 Status
= BarExisted (PciIoDevice
, BarOffset
, &TestValue
, &OldValue
);
1923 if (EFI_ERROR (Status
)) {
1927 TestValue
= TestValue
& Mask
;
1928 if ((TestValue
!= 0) && (TestValue
== (OldValue
& Mask
))) {
1930 // The bar isn't programed, so it should be rejected
1939 for (BarOffset
= 0x14; BarOffset
<= 0x24; BarOffset
+= sizeof (UINT32
)) {
1943 Status
= BarExisted (PciIoDevice
, BarOffset
, &TestValue
, &OldValue
);
1944 if (EFI_ERROR (Status
)) {
1948 if (TestValue
& 0x01) {
1955 TestValue
= TestValue
& Mask
;
1956 if ((TestValue
!= 0) && (TestValue
== (OldValue
& Mask
))) {
1967 TestValue
= TestValue
& Mask
;
1969 if ((TestValue
& 0x07) == 0x04) {
1974 BarOffset
+= sizeof (UINT32
);
1975 if ((TestValue
!= 0) && (TestValue
== (OldValue
& Mask
))) {
1978 // Test its high 32-Bit BAR
1981 Status
= BarExisted (PciIoDevice
, BarOffset
, &TestValue
, &OldValue
);
1982 if (TestValue
== OldValue
) {
1992 if ((TestValue
!= 0) && (TestValue
== (OldValue
& Mask
))) {
2003 Reset and all bus number from specific bridge.
2005 @param Bridge Parent specific bridge
2006 @param StartBusNumber start bus number
2009 ResetAllPpbBusNumber (
2010 IN PCI_IO_DEVICE
*Bridge
,
2011 IN UINT8 StartBusNumber
2021 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
2023 PciRootBridgeIo
= Bridge
->PciRootBridgeIo
;
2025 for (Device
= 0; Device
<= PCI_MAX_DEVICE
; Device
++) {
2026 for (Func
= 0; Func
<= PCI_MAX_FUNC
; Func
++) {
2029 // Check to see whether a pci device is present
2031 Status
= PciDevicePresent (
2039 if (!EFI_ERROR (Status
) && (IS_PCI_BRIDGE (&Pci
))) {
2042 Address
= EFI_PCI_ADDRESS (StartBusNumber
, Device
, Func
, 0x18);
2043 Status
= PciRootBridgeIoRead (
2051 SecondaryBus
= (UINT8
)(Register
>> 8);
2053 if (SecondaryBus
!= 0) {
2054 ResetAllPpbBusNumber (Bridge
, SecondaryBus
);
2058 // Reset register 18h, 19h, 1Ah on PCI Bridge
2060 Register
&= 0xFF000000;
2061 Status
= PciRootBridgeIoWrite (
2071 if (Func
== 0 && !IS_PCI_MULTI_FUNC (&Pci
)) {
2073 // Skip sub functions, this is not a multi function device
2075 Func
= PCI_MAX_FUNC
;