2 PCI emumeration support functions implementation for PCI Bus module.
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 routine is used to check whether the pci device is present.
20 @param PciRootBridgeIo Pointer to instance of EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
21 @param Pci Output buffer for PCI device configuration space.
22 @param Bus PCI bus NO.
23 @param Device PCI device NO.
24 @param Func PCI Func NO.
26 @retval EFI_NOT_FOUND PCI device not present.
27 @retval EFI_SUCCESS PCI device is found.
32 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
,
43 // Create PCI address map in terms of Bus, Device and Func
45 Address
= EFI_PCI_ADDRESS (Bus
, Device
, Func
, 0);
48 // Read the Vendor ID register
50 Status
= PciRootBridgeIo
->Pci
.Read (
58 if (!EFI_ERROR (Status
) && (Pci
->Hdr
).VendorId
!= 0xffff) {
60 // Read the entire config header for the device
62 Status
= PciRootBridgeIo
->Pci
.Read (
66 sizeof (PCI_TYPE00
) / sizeof (UINT32
),
77 Collect all the resource information under this root bridge.
79 A database that records all the information about pci device subject to this
80 root bridge will then be created.
82 @param Bridge Parent bridge instance.
83 @param StartBusNumber Bus number of begining.
85 @retval EFI_SUCCESS PCI device is found.
86 @retval other Some error occurred when reading PCI bridge information.
90 PciPciDeviceInfoCollector (
91 IN PCI_IO_DEVICE
*Bridge
,
92 IN UINT8 StartBusNumber
100 PCI_IO_DEVICE
*PciIoDevice
;
101 EFI_PCI_IO_PROTOCOL
*PciIo
;
103 Status
= EFI_SUCCESS
;
106 for (Device
= 0; Device
<= PCI_MAX_DEVICE
; Device
++) {
108 for (Func
= 0; Func
<= PCI_MAX_FUNC
; Func
++) {
111 // Check to see whether PCI device is present
113 Status
= PciDevicePresent (
114 Bridge
->PciRootBridgeIo
,
116 (UINT8
) StartBusNumber
,
120 if (!EFI_ERROR (Status
)) {
123 // Call back to host bridge function
125 PreprocessController (Bridge
, (UINT8
) StartBusNumber
, Device
, Func
, EfiPciBeforeResourceCollection
);
128 // Collect all the information about the PCI device discovered
130 Status
= PciSearchDevice (
133 (UINT8
) StartBusNumber
,
140 // Recursively scan PCI busses on the other side of PCI-PCI bridges
143 if (!EFI_ERROR (Status
) && (IS_PCI_BRIDGE (&Pci
) || IS_CARDBUS_BRIDGE (&Pci
))) {
146 // If it is PPB, we need to get the secondary bus to continue the enumeration
148 PciIo
= &(PciIoDevice
->PciIo
);
150 Status
= PciIo
->Pci
.Read (PciIo
, EfiPciIoWidthUint8
, PCI_BRIDGE_SECONDARY_BUS_REGISTER_OFFSET
, 1, &SecBus
);
152 if (EFI_ERROR (Status
)) {
157 // Get resource padding for PPB
159 GetResourcePaddingPpb (PciIoDevice
);
162 // Deep enumerate the next level bus
164 Status
= PciPciDeviceInfoCollector (
171 if (Func
== 0 && !IS_PCI_MULTI_FUNC (&Pci
)) {
174 // Skip sub functions, this is not a multi function device
187 Seach required device and create PCI device instance.
189 @param Bridge Parent bridge instance.
190 @param Pci Input PCI device information block.
191 @param Bus PCI bus NO.
192 @param Device PCI device NO.
193 @param Func PCI func NO.
194 @param PciDevice Output of searched PCI device instance.
196 @retval EFI_SUCCESS Successfully created PCI device instance.
197 @retval EFI_OUT_OF_RESOURCES Cannot get PCI device information.
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
);
263 if (PciIoDevice
== NULL
) {
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 device instance for PCI device.
310 @param Bridge Parent bridge instance.
311 @param Pci Input PCI device information block.
312 @param Bus PCI device Bus NO.
313 @param Device PCI device Device NO.
314 @param Func PCI device's func NO.
316 @return Created PCI device instance.
321 IN PCI_IO_DEVICE
*Bridge
,
330 PCI_IO_DEVICE
*PciIoDevice
;
332 PciIoDevice
= CreatePciIoDevice (
340 if (PciIoDevice
== NULL
) {
345 // Create a device path for this PCI device and store it into its private data
347 CreatePciDevicePath (
353 // If it is a full enumeration, disconnect the device in advance
355 if (gFullEnumeration
) {
357 PCI_DISABLE_COMMAND_REGISTER (PciIoDevice
, EFI_PCI_COMMAND_BITS_OWNED
);
362 // Start to parse the bars
364 for (Offset
= 0x10, BarIndex
= 0; Offset
<= 0x24 && BarIndex
< PCI_MAX_BAR
; BarIndex
++) {
365 Offset
= PciParseBar (PciIoDevice
, Offset
, BarIndex
);
369 // Parse the SR-IOV VF bars
371 if (PcdGetBool (PcdSrIovSupport
) && PciIoDevice
->SrIovCapabilityOffset
!= 0) {
372 for (Offset
= PciIoDevice
->SrIovCapabilityOffset
+ EFI_PCIE_CAPABILITY_ID_SRIOV_BAR0
, BarIndex
= 0;
373 Offset
<= PciIoDevice
->SrIovCapabilityOffset
+ EFI_PCIE_CAPABILITY_ID_SRIOV_BAR5
;
376 ASSERT (BarIndex
< PCI_MAX_BAR
);
377 Offset
= PciIovParseVfBar (PciIoDevice
, Offset
, BarIndex
);
384 Create PCI device instance for PCI-PCI bridge.
386 @param Bridge Parent bridge instance.
387 @param Pci Input PCI device information block.
388 @param Bus PCI device Bus NO.
389 @param Device PCI device Device NO.
390 @param Func PCI device's func NO.
392 @return Created PCI device instance.
397 IN PCI_IO_DEVICE
*Bridge
,
404 PCI_IO_DEVICE
*PciIoDevice
;
407 EFI_PCI_IO_PROTOCOL
*PciIo
;
410 PciIoDevice
= CreatePciIoDevice (
418 if (PciIoDevice
== NULL
) {
423 // Create a device path for this PCI device and store it into its private data
425 CreatePciDevicePath (
430 if (gFullEnumeration
) {
431 PCI_DISABLE_COMMAND_REGISTER (PciIoDevice
, EFI_PCI_COMMAND_BITS_OWNED
);
434 // Initalize the bridge control register
436 PCI_DISABLE_BRIDGE_CONTROL_REGISTER (PciIoDevice
, EFI_PCI_BRIDGE_CONTROL_BITS_OWNED
);
441 // PPB can have two BARs
443 if (PciParseBar (PciIoDevice
, 0x10, PPB_BAR_0
) == 0x14) {
447 PciParseBar (PciIoDevice
, 0x14, PPB_BAR_1
);
450 PciIo
= &PciIoDevice
->PciIo
;
453 // Test whether it support 32 decode or not
455 PciIo
->Pci
.Read (PciIo
, EfiPciIoWidthUint8
, 0x1C, 1, &Temp
);
456 PciIo
->Pci
.Write (PciIo
, EfiPciIoWidthUint8
, 0x1C, 1, &gAllOne
);
457 PciIo
->Pci
.Read (PciIo
, EfiPciIoWidthUint8
, 0x1C, 1, &Value
);
458 PciIo
->Pci
.Write (PciIo
, EfiPciIoWidthUint8
, 0x1C, 1, &Temp
);
461 if ((Value
& 0x01) != 0) {
462 PciIoDevice
->Decodes
|= EFI_BRIDGE_IO32_DECODE_SUPPORTED
;
464 PciIoDevice
->Decodes
|= EFI_BRIDGE_IO16_DECODE_SUPPORTED
;
469 // if PcdPciBridgeIoAlignmentProbe is TRUE, PCI bus driver probes
470 // PCI bridge supporting non-stardard I/O window alignment less than 4K.
473 PciIoDevice
->BridgeIoAlignment
= 0xFFF;
474 if (FeaturePcdGet (PcdPciBridgeIoAlignmentProbe
)) {
476 // Check any bits of bit 3-1 of I/O Base Register are writable.
477 // if so, it is assumed non-stardard I/O window alignment is supported by this bridge.
478 // Per spec, bit 3-1 of I/O Base Register are reserved bits, so its content can't be assumed.
480 Value
= (UINT8
)(Temp
^ (BIT3
| BIT2
| BIT1
));
481 PciIo
->Pci
.Write (PciIo
, EfiPciIoWidthUint8
, 0x1C, 1, &Value
);
482 PciIo
->Pci
.Read (PciIo
, EfiPciIoWidthUint8
, 0x1C, 1, &Value
);
483 PciIo
->Pci
.Write (PciIo
, EfiPciIoWidthUint8
, 0x1C, 1, &Temp
);
484 Value
= (UINT8
)((Value
^ Temp
) & (BIT3
| BIT2
| BIT1
));
487 PciIoDevice
->BridgeIoAlignment
= 0x7FF;
490 PciIoDevice
->BridgeIoAlignment
= 0x3FF;
492 case BIT3
| BIT2
| BIT1
:
493 PciIoDevice
->BridgeIoAlignment
= 0x1FF;
498 Status
= BarExisted (
506 // Test if it supports 64 memory or not
508 if (!EFI_ERROR (Status
)) {
510 Status
= BarExisted (
517 if (!EFI_ERROR (Status
)) {
518 PciIoDevice
->Decodes
|= EFI_BRIDGE_PMEM32_DECODE_SUPPORTED
;
519 PciIoDevice
->Decodes
|= EFI_BRIDGE_PMEM64_DECODE_SUPPORTED
;
521 PciIoDevice
->Decodes
|= EFI_BRIDGE_PMEM32_DECODE_SUPPORTED
;
526 // Memory 32 code is required for ppb
528 PciIoDevice
->Decodes
|= EFI_BRIDGE_MEM32_DECODE_SUPPORTED
;
530 GetResourcePaddingPpb (PciIoDevice
);
537 Create PCI device instance for PCI Card bridge device.
539 @param Bridge Parent bridge instance.
540 @param Pci Input PCI device information block.
541 @param Bus PCI device Bus NO.
542 @param Device PCI device Device NO.
543 @param Func PCI device's func NO.
545 @return Created PCI device instance.
550 IN PCI_IO_DEVICE
*Bridge
,
557 PCI_IO_DEVICE
*PciIoDevice
;
559 PciIoDevice
= CreatePciIoDevice (
567 if (PciIoDevice
== NULL
) {
572 // Create a device path for this PCI device and store it into its private data
574 CreatePciDevicePath (
579 if (gFullEnumeration
) {
580 PCI_DISABLE_COMMAND_REGISTER (PciIoDevice
, EFI_PCI_COMMAND_BITS_OWNED
);
583 // Initalize the bridge control register
585 PCI_DISABLE_BRIDGE_CONTROL_REGISTER (PciIoDevice
, EFI_PCCARD_BRIDGE_CONTROL_BITS_OWNED
);
589 // P2C only has one bar that is in 0x10
591 PciParseBar (PciIoDevice
, 0x10, P2C_BAR_0
);
594 // Read PciBar information from the bar register
596 GetBackPcCardBar (PciIoDevice
);
597 PciIoDevice
->Decodes
= EFI_BRIDGE_MEM32_DECODE_SUPPORTED
|
598 EFI_BRIDGE_PMEM32_DECODE_SUPPORTED
|
599 EFI_BRIDGE_IO32_DECODE_SUPPORTED
;
605 Create device path for pci deivce.
607 @param ParentDevicePath Parent bridge's path.
608 @param PciIoDevice Pci device instance.
610 @return Device path protocol instance for specific pci device.
613 EFI_DEVICE_PATH_PROTOCOL
*
614 CreatePciDevicePath (
615 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
,
616 IN PCI_IO_DEVICE
*PciIoDevice
620 PCI_DEVICE_PATH PciNode
;
623 // Create PCI device path
625 PciNode
.Header
.Type
= HARDWARE_DEVICE_PATH
;
626 PciNode
.Header
.SubType
= HW_PCI_DP
;
627 SetDevicePathNodeLength (&PciNode
.Header
, sizeof (PciNode
));
629 PciNode
.Device
= PciIoDevice
->DeviceNumber
;
630 PciNode
.Function
= PciIoDevice
->FunctionNumber
;
631 PciIoDevice
->DevicePath
= AppendDevicePathNode (ParentDevicePath
, &PciNode
.Header
);
633 return PciIoDevice
->DevicePath
;
637 Check whether the PCI IOV VF bar is existed or not.
639 @param PciIoDevice A pointer to the PCI_IO_DEVICE.
640 @param Offset The offset.
641 @param BarLengthValue The bar length value returned.
642 @param OriginalBarValue The original bar value returned.
644 @retval EFI_NOT_FOUND The bar doesn't exist.
645 @retval EFI_SUCCESS The bar exist.
650 IN PCI_IO_DEVICE
*PciIoDevice
,
652 OUT UINT32
*BarLengthValue
,
653 OUT UINT32
*OriginalBarValue
656 EFI_PCI_IO_PROTOCOL
*PciIo
;
657 UINT32 OriginalValue
;
662 // Ensure it is called properly
664 ASSERT (PciIoDevice
->SrIovCapabilityOffset
!= 0);
665 if (PciIoDevice
->SrIovCapabilityOffset
== 0) {
666 return EFI_NOT_FOUND
;
669 PciIo
= &PciIoDevice
->PciIo
;
672 // Preserve the original value
675 PciIo
->Pci
.Read (PciIo
, EfiPciIoWidthUint32
, (UINT32
)Offset
, 1, &OriginalValue
);
678 // Raise TPL to high level to disable timer interrupt while the BAR is probed
680 OldTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
682 PciIo
->Pci
.Write (PciIo
, EfiPciIoWidthUint32
, (UINT32
)Offset
, 1, &gAllOne
);
683 PciIo
->Pci
.Read (PciIo
, EfiPciIoWidthUint32
, (UINT32
)Offset
, 1, &Value
);
686 // Write back the original value
688 PciIo
->Pci
.Write (PciIo
, EfiPciIoWidthUint32
, (UINT32
)Offset
, 1, &OriginalValue
);
691 // Restore TPL to its original level
693 gBS
->RestoreTPL (OldTpl
);
695 if (BarLengthValue
!= NULL
) {
696 *BarLengthValue
= Value
;
699 if (OriginalBarValue
!= NULL
) {
700 *OriginalBarValue
= OriginalValue
;
704 return EFI_NOT_FOUND
;
711 Check whether the bar is existed or not.
713 @param PciIoDevice A pointer to the PCI_IO_DEVICE.
714 @param Offset The offset.
715 @param BarLengthValue The bar length value returned.
716 @param OriginalBarValue The original bar value returned.
718 @retval EFI_NOT_FOUND The bar doesn't exist.
719 @retval EFI_SUCCESS The bar exist.
724 IN PCI_IO_DEVICE
*PciIoDevice
,
726 OUT UINT32
*BarLengthValue
,
727 OUT UINT32
*OriginalBarValue
730 EFI_PCI_IO_PROTOCOL
*PciIo
;
731 UINT32 OriginalValue
;
735 PciIo
= &PciIoDevice
->PciIo
;
738 // Preserve the original value
740 PciIo
->Pci
.Read (PciIo
, EfiPciIoWidthUint32
, (UINT8
) Offset
, 1, &OriginalValue
);
743 // Raise TPL to high level to disable timer interrupt while the BAR is probed
745 OldTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
747 PciIo
->Pci
.Write (PciIo
, EfiPciIoWidthUint32
, (UINT8
) Offset
, 1, &gAllOne
);
748 PciIo
->Pci
.Read (PciIo
, EfiPciIoWidthUint32
, (UINT8
) Offset
, 1, &Value
);
751 // Write back the original value
753 PciIo
->Pci
.Write (PciIo
, EfiPciIoWidthUint32
, (UINT8
) Offset
, 1, &OriginalValue
);
756 // Restore TPL to its original level
758 gBS
->RestoreTPL (OldTpl
);
760 if (BarLengthValue
!= NULL
) {
761 *BarLengthValue
= Value
;
764 if (OriginalBarValue
!= NULL
) {
765 *OriginalBarValue
= OriginalValue
;
769 return EFI_NOT_FOUND
;
776 Test whether the device can support given attributes.
778 @param PciIoDevice Pci device instance.
779 @param Command Input command register value, and
780 returned supported register value.
781 @param BridgeControl Inout bridge control value for PPB or P2C, and
782 returned supported bridge control value.
783 @param OldCommand Returned and stored old command register offset.
784 @param OldBridgeControl Returned and stored old Bridge control value for PPB or P2C.
788 PciTestSupportedAttribute (
789 IN PCI_IO_DEVICE
*PciIoDevice
,
790 IN OUT UINT16
*Command
,
791 IN OUT UINT16
*BridgeControl
,
792 OUT UINT16
*OldCommand
,
793 OUT UINT16
*OldBridgeControl
799 // Preserve the original value
801 PCI_READ_COMMAND_REGISTER (PciIoDevice
, OldCommand
);
804 // Raise TPL to high level to disable timer interrupt while the BAR is probed
806 OldTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
808 PCI_SET_COMMAND_REGISTER (PciIoDevice
, *Command
);
809 PCI_READ_COMMAND_REGISTER (PciIoDevice
, Command
);
812 // Write back the original value
814 PCI_SET_COMMAND_REGISTER (PciIoDevice
, *OldCommand
);
817 // Restore TPL to its original level
819 gBS
->RestoreTPL (OldTpl
);
821 if (IS_PCI_BRIDGE (&PciIoDevice
->Pci
) || IS_CARDBUS_BRIDGE (&PciIoDevice
->Pci
)) {
824 // Preserve the original value
826 PCI_READ_BRIDGE_CONTROL_REGISTER (PciIoDevice
, OldBridgeControl
);
829 // Raise TPL to high level to disable timer interrupt while the BAR is probed
831 OldTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
833 PCI_SET_BRIDGE_CONTROL_REGISTER (PciIoDevice
, *BridgeControl
);
834 PCI_READ_BRIDGE_CONTROL_REGISTER (PciIoDevice
, BridgeControl
);
837 // Write back the original value
839 PCI_SET_BRIDGE_CONTROL_REGISTER (PciIoDevice
, *OldBridgeControl
);
842 // Restore TPL to its original level
844 gBS
->RestoreTPL (OldTpl
);
847 *OldBridgeControl
= 0;
853 Set the supported or current attributes of a PCI device.
855 @param PciIoDevice Structure pointer for PCI device.
856 @param Command Command register value.
857 @param BridgeControl Bridge control value for PPB or P2C.
858 @param Option Make a choice of EFI_SET_SUPPORTS or EFI_SET_ATTRIBUTES.
862 PciSetDeviceAttribute (
863 IN PCI_IO_DEVICE
*PciIoDevice
,
865 IN UINT16 BridgeControl
,
873 if ((Command
& EFI_PCI_COMMAND_IO_SPACE
) != 0) {
874 Attributes
|= EFI_PCI_IO_ATTRIBUTE_IO
;
877 if ((Command
& EFI_PCI_COMMAND_MEMORY_SPACE
) != 0) {
878 Attributes
|= EFI_PCI_IO_ATTRIBUTE_MEMORY
;
881 if ((Command
& EFI_PCI_COMMAND_BUS_MASTER
) != 0) {
882 Attributes
|= EFI_PCI_IO_ATTRIBUTE_BUS_MASTER
;
885 if ((Command
& EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
) != 0) {
886 Attributes
|= EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO
;
889 if ((BridgeControl
& EFI_PCI_BRIDGE_CONTROL_ISA
) != 0) {
890 Attributes
|= EFI_PCI_IO_ATTRIBUTE_ISA_IO
;
893 if ((BridgeControl
& EFI_PCI_BRIDGE_CONTROL_VGA
) != 0) {
894 Attributes
|= EFI_PCI_IO_ATTRIBUTE_VGA_IO
;
895 Attributes
|= EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY
;
896 Attributes
|= EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO
;
899 if ((BridgeControl
& EFI_PCI_BRIDGE_CONTROL_VGA_16
) != 0) {
900 Attributes
|= EFI_PCI_IO_ATTRIBUTE_VGA_IO_16
;
901 Attributes
|= EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16
;
904 if (Option
== EFI_SET_SUPPORTS
) {
906 Attributes
|= EFI_PCI_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE
|
907 EFI_PCI_IO_ATTRIBUTE_MEMORY_CACHED
|
908 EFI_PCI_IO_ATTRIBUTE_MEMORY_DISABLE
|
909 EFI_PCI_IO_ATTRIBUTE_EMBEDDED_DEVICE
|
910 EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM
|
911 EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE
;
913 if (IS_PCI_LPC (&PciIoDevice
->Pci
)) {
914 Attributes
|= EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO
;
915 Attributes
|= (mReserveIsaAliases
? EFI_PCI_IO_ATTRIBUTE_ISA_IO
: \
916 EFI_PCI_IO_ATTRIBUTE_ISA_IO_16
);
919 if (IS_PCI_BRIDGE (&PciIoDevice
->Pci
) || IS_CARDBUS_BRIDGE (&PciIoDevice
->Pci
)) {
921 // For bridge, it should support IDE attributes
923 Attributes
|= EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO
;
924 Attributes
|= EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO
;
926 if (mReserveVgaAliases
) {
927 Attributes
&= ~(UINT64
)(EFI_PCI_IO_ATTRIBUTE_VGA_IO_16
| \
928 EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16
);
930 Attributes
&= ~(UINT64
)(EFI_PCI_IO_ATTRIBUTE_VGA_IO
| \
931 EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO
);
935 if (IS_PCI_IDE (&PciIoDevice
->Pci
)) {
936 Attributes
|= EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO
;
937 Attributes
|= EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO
;
940 if (IS_PCI_VGA (&PciIoDevice
->Pci
)) {
941 Attributes
|= EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY
;
942 Attributes
|= (mReserveVgaAliases
? EFI_PCI_IO_ATTRIBUTE_VGA_IO
: \
943 EFI_PCI_IO_ATTRIBUTE_VGA_IO_16
);
947 PciIoDevice
->Supports
= Attributes
;
948 PciIoDevice
->Supports
&= ( (PciIoDevice
->Parent
->Supports
) | \
949 EFI_PCI_IO_ATTRIBUTE_IO
| EFI_PCI_IO_ATTRIBUTE_MEMORY
| \
950 EFI_PCI_IO_ATTRIBUTE_BUS_MASTER
);
954 // When this attribute is clear, the RomImage and RomSize fields in the PCI IO were
955 // initialized based on the PCI option ROM found through the ROM BAR of the PCI controller.
956 // When this attribute is set, the PCI option ROM described by the RomImage and RomSize
957 // fields is not from the the ROM BAR of the PCI controller.
959 if (!PciIoDevice
->EmbeddedRom
) {
960 Attributes
|= EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM
;
962 PciIoDevice
->Attributes
= Attributes
;
967 Determine if the device can support Fast Back to Back attribute.
969 @param PciIoDevice Pci device instance.
970 @param StatusIndex Status register value.
972 @retval EFI_SUCCESS This device support Fast Back to Back attribute.
973 @retval EFI_UNSUPPORTED This device doesn't support Fast Back to Back attribute.
977 GetFastBackToBackSupport (
978 IN PCI_IO_DEVICE
*PciIoDevice
,
982 EFI_PCI_IO_PROTOCOL
*PciIo
;
984 UINT32 StatusRegister
;
987 // Read the status register
989 PciIo
= &PciIoDevice
->PciIo
;
990 Status
= PciIo
->Pci
.Read (PciIo
, EfiPciIoWidthUint16
, StatusIndex
, 1, &StatusRegister
);
991 if (EFI_ERROR (Status
)) {
992 return EFI_UNSUPPORTED
;
996 // Check the Fast B2B bit
998 if ((StatusRegister
& EFI_PCI_FAST_BACK_TO_BACK_CAPABLE
) != 0) {
1001 return EFI_UNSUPPORTED
;
1006 Process the option ROM for all the children of the specified parent PCI device.
1007 It can only be used after the first full Option ROM process.
1009 @param PciIoDevice Pci device instance.
1013 ProcessOptionRomLight (
1014 IN PCI_IO_DEVICE
*PciIoDevice
1017 PCI_IO_DEVICE
*Temp
;
1018 LIST_ENTRY
*CurrentLink
;
1021 // For RootBridge, PPB , P2C, go recursively to traverse all its children
1023 CurrentLink
= PciIoDevice
->ChildList
.ForwardLink
;
1024 while (CurrentLink
!= NULL
&& CurrentLink
!= &PciIoDevice
->ChildList
) {
1026 Temp
= PCI_IO_DEVICE_FROM_LINK (CurrentLink
);
1028 if (!IsListEmpty (&Temp
->ChildList
)) {
1029 ProcessOptionRomLight (Temp
);
1032 PciRomGetImageMapping (Temp
);
1035 // The OpRom has already been processed in the first round
1037 Temp
->AllOpRomProcessed
= TRUE
;
1039 CurrentLink
= CurrentLink
->ForwardLink
;
1044 Determine the related attributes of all devices under a Root Bridge.
1046 @param PciIoDevice PCI device instance.
1050 DetermineDeviceAttribute (
1051 IN PCI_IO_DEVICE
*PciIoDevice
1055 UINT16 BridgeControl
;
1057 UINT16 OldBridgeControl
;
1058 BOOLEAN FastB2BSupport
;
1059 PCI_IO_DEVICE
*Temp
;
1060 LIST_ENTRY
*CurrentLink
;
1064 // For Root Bridge, just copy it by RootBridgeIo proctocol
1065 // so as to keep consistent with the actual attribute
1067 if (PciIoDevice
->Parent
== NULL
) {
1068 Status
= PciIoDevice
->PciRootBridgeIo
->GetAttributes (
1069 PciIoDevice
->PciRootBridgeIo
,
1070 &PciIoDevice
->Supports
,
1071 &PciIoDevice
->Attributes
1073 if (EFI_ERROR (Status
)) {
1076 PciIoDevice
->Supports
|= (EFI_PCI_IO_ATTRIBUTE_EMBEDDED_DEVICE
|
1077 EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM
);
1082 // Set the attributes to be checked for common PCI devices and PPB or P2C
1083 // Since some devices only support part of them, it is better to set the
1084 // attribute according to its command or bridge control register
1086 Command
= EFI_PCI_COMMAND_IO_SPACE
|
1087 EFI_PCI_COMMAND_MEMORY_SPACE
|
1088 EFI_PCI_COMMAND_BUS_MASTER
|
1089 EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
;
1091 BridgeControl
= EFI_PCI_BRIDGE_CONTROL_ISA
| EFI_PCI_BRIDGE_CONTROL_VGA
| EFI_PCI_BRIDGE_CONTROL_VGA_16
;
1094 // Test whether the device can support attributes above
1096 PciTestSupportedAttribute (PciIoDevice
, &Command
, &BridgeControl
, &OldCommand
, &OldBridgeControl
);
1099 // Set the supported attributes for specified PCI device
1101 PciSetDeviceAttribute (PciIoDevice
, Command
, BridgeControl
, EFI_SET_SUPPORTS
);
1104 // Set the current attributes for specified PCI device
1106 PciSetDeviceAttribute (PciIoDevice
, OldCommand
, OldBridgeControl
, EFI_SET_ATTRIBUTES
);
1109 // Enable other supported attributes but not defined in PCI_IO_PROTOCOL
1111 PCI_ENABLE_COMMAND_REGISTER (PciIoDevice
, EFI_PCI_COMMAND_MEMORY_WRITE_AND_INVALIDATE
);
1114 FastB2BSupport
= TRUE
;
1117 // P2C can not support FB2B on the secondary side
1119 if (IS_CARDBUS_BRIDGE (&PciIoDevice
->Pci
)) {
1120 FastB2BSupport
= FALSE
;
1124 // For RootBridge, PPB , P2C, go recursively to traverse all its children
1126 CurrentLink
= PciIoDevice
->ChildList
.ForwardLink
;
1127 while (CurrentLink
!= NULL
&& CurrentLink
!= &PciIoDevice
->ChildList
) {
1129 Temp
= PCI_IO_DEVICE_FROM_LINK (CurrentLink
);
1130 Status
= DetermineDeviceAttribute (Temp
);
1131 if (EFI_ERROR (Status
)) {
1135 // Detect Fast Bact to Bact support for the device under the bridge
1137 Status
= GetFastBackToBackSupport (Temp
, PCI_PRIMARY_STATUS_OFFSET
);
1138 if (FastB2BSupport
&& EFI_ERROR (Status
)) {
1139 FastB2BSupport
= FALSE
;
1142 CurrentLink
= CurrentLink
->ForwardLink
;
1145 // Set or clear Fast Back to Back bit for the whole bridge
1147 if (!IsListEmpty (&PciIoDevice
->ChildList
)) {
1149 if (IS_PCI_BRIDGE (&PciIoDevice
->Pci
)) {
1151 Status
= GetFastBackToBackSupport (PciIoDevice
, PCI_BRIDGE_STATUS_REGISTER_OFFSET
);
1153 if (EFI_ERROR (Status
) || (!FastB2BSupport
)) {
1154 FastB2BSupport
= FALSE
;
1155 PCI_DISABLE_BRIDGE_CONTROL_REGISTER (PciIoDevice
, EFI_PCI_BRIDGE_CONTROL_FAST_BACK_TO_BACK
);
1157 PCI_ENABLE_BRIDGE_CONTROL_REGISTER (PciIoDevice
, EFI_PCI_BRIDGE_CONTROL_FAST_BACK_TO_BACK
);
1161 CurrentLink
= PciIoDevice
->ChildList
.ForwardLink
;
1162 while (CurrentLink
!= NULL
&& CurrentLink
!= &PciIoDevice
->ChildList
) {
1163 Temp
= PCI_IO_DEVICE_FROM_LINK (CurrentLink
);
1164 if (FastB2BSupport
) {
1165 PCI_ENABLE_COMMAND_REGISTER (Temp
, EFI_PCI_COMMAND_FAST_BACK_TO_BACK
);
1167 PCI_DISABLE_COMMAND_REGISTER (Temp
, EFI_PCI_COMMAND_FAST_BACK_TO_BACK
);
1170 CurrentLink
= CurrentLink
->ForwardLink
;
1174 // End for IsListEmpty
1180 This routine is used to update the bar information for those incompatible PCI device.
1182 @param PciIoDevice Input Pci device instance. Output Pci device instance with updated
1185 @retval EFI_SUCCESS Successfully updated bar information.
1186 @retval EFI_UNSUPPORTED Given PCI device doesn't belong to incompatible PCI device list.
1191 IN OUT PCI_IO_DEVICE
*PciIoDevice
1198 VOID
*Configuration
;
1199 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Ptr
;
1201 Configuration
= NULL
;
1202 Status
= EFI_SUCCESS
;
1204 if (gEfiIncompatiblePciDeviceSupport
== NULL
) {
1206 // It can only be supported after the Incompatible PCI Device
1207 // Support Protocol has been installed
1209 Status
= gBS
->LocateProtocol (
1210 &gEfiIncompatiblePciDeviceSupportProtocolGuid
,
1212 (VOID
**) &gEfiIncompatiblePciDeviceSupport
1215 if (Status
== EFI_SUCCESS
) {
1217 // Check whether the device belongs to incompatible devices from protocol or not
1218 // If it is , then get its special requirement in the ACPI table
1220 Status
= gEfiIncompatiblePciDeviceSupport
->CheckDevice (
1221 gEfiIncompatiblePciDeviceSupport
,
1222 PciIoDevice
->Pci
.Hdr
.VendorId
,
1223 PciIoDevice
->Pci
.Hdr
.DeviceId
,
1224 PciIoDevice
->Pci
.Hdr
.RevisionID
,
1225 PciIoDevice
->Pci
.Device
.SubsystemVendorID
,
1226 PciIoDevice
->Pci
.Device
.SubsystemID
,
1232 if (EFI_ERROR (Status
) || Configuration
== NULL
) {
1233 return EFI_UNSUPPORTED
;
1237 // Update PCI device information from the ACPI table
1239 Ptr
= (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Configuration
;
1241 while (Ptr
->Desc
!= ACPI_END_TAG_DESCRIPTOR
) {
1243 if (Ptr
->Desc
!= ACPI_ADDRESS_SPACE_DESCRIPTOR
) {
1245 // The format is not support
1250 BarIndex
= (UINTN
) Ptr
->AddrTranslationOffset
;
1251 BarEndIndex
= BarIndex
;
1254 // Update all the bars in the device
1256 if (BarIndex
== PCI_BAR_ALL
) {
1258 BarEndIndex
= PCI_MAX_BAR
- 1;
1261 if (BarIndex
> PCI_MAX_BAR
) {
1266 for (; BarIndex
<= BarEndIndex
; BarIndex
++) {
1268 switch (Ptr
->ResType
) {
1269 case ACPI_ADDRESS_SPACE_TYPE_MEM
:
1272 // Make sure the bar is memory type
1274 if (CheckBarType (PciIoDevice
, (UINT8
) BarIndex
, PciBarTypeMem
)) {
1279 case ACPI_ADDRESS_SPACE_TYPE_IO
:
1282 // Make sure the bar is IO type
1284 if (CheckBarType (PciIoDevice
, (UINT8
) BarIndex
, PciBarTypeIo
)) {
1293 // Update the new alignment for the device
1295 SetNewAlign (&(PciIoDevice
->PciBar
[BarIndex
].Alignment
), Ptr
->AddrRangeMax
);
1298 // Update the new length for the device
1300 if (Ptr
->AddrLen
!= PCI_BAR_NOCHANGE
) {
1301 PciIoDevice
->PciBar
[BarIndex
].Length
= Ptr
->AddrLen
;
1309 FreePool (Configuration
);
1315 This routine will update the alignment with the new alignment.
1317 @param Alignment Input Old alignment. Output updated alignment.
1318 @param NewAlignment New alignment.
1323 IN OUT UINT64
*Alignment
,
1324 IN UINT64 NewAlignment
1327 UINT64 OldAlignment
;
1331 // The new alignment is the same as the original,
1334 if (NewAlignment
== PCI_BAR_OLD_ALIGN
) {
1338 // Check the validity of the parameter
1340 if (NewAlignment
!= PCI_BAR_EVEN_ALIGN
&&
1341 NewAlignment
!= PCI_BAR_SQUAD_ALIGN
&&
1342 NewAlignment
!= PCI_BAR_DQUAD_ALIGN
) {
1343 *Alignment
= NewAlignment
;
1347 OldAlignment
= (*Alignment
) + 1;
1351 // Get the first non-zero hex value of the length
1353 while ((OldAlignment
& 0x0F) == 0x00) {
1354 OldAlignment
= RShiftU64 (OldAlignment
, 4);
1359 // Adjust the alignment to even, quad or double quad boundary
1361 if (NewAlignment
== PCI_BAR_EVEN_ALIGN
) {
1362 if ((OldAlignment
& 0x01) != 0) {
1363 OldAlignment
= OldAlignment
+ 2 - (OldAlignment
& 0x01);
1365 } else if (NewAlignment
== PCI_BAR_SQUAD_ALIGN
) {
1366 if ((OldAlignment
& 0x03) != 0) {
1367 OldAlignment
= OldAlignment
+ 4 - (OldAlignment
& 0x03);
1369 } else if (NewAlignment
== PCI_BAR_DQUAD_ALIGN
) {
1370 if ((OldAlignment
& 0x07) != 0) {
1371 OldAlignment
= OldAlignment
+ 8 - (OldAlignment
& 0x07);
1376 // Update the old value
1378 NewAlignment
= LShiftU64 (OldAlignment
, ShiftBit
) - 1;
1379 *Alignment
= NewAlignment
;
1385 Parse PCI IOV VF bar information and fill them into PCI device instance.
1387 @param PciIoDevice Pci device instance.
1388 @param Offset Bar offset.
1389 @param BarIndex Bar index.
1391 @return Next bar offset.
1396 IN PCI_IO_DEVICE
*PciIoDevice
,
1402 UINT32 OriginalValue
;
1409 // Ensure it is called properly
1411 ASSERT (PciIoDevice
->SrIovCapabilityOffset
!= 0);
1412 if (PciIoDevice
->SrIovCapabilityOffset
== 0) {
1419 Status
= VfBarExisted (
1426 if (EFI_ERROR (Status
)) {
1427 PciIoDevice
->VfPciBar
[BarIndex
].BaseAddress
= 0;
1428 PciIoDevice
->VfPciBar
[BarIndex
].Length
= 0;
1429 PciIoDevice
->VfPciBar
[BarIndex
].Alignment
= 0;
1432 // Scan all the BARs anyway
1434 PciIoDevice
->VfPciBar
[BarIndex
].Offset
= (UINT16
) Offset
;
1438 PciIoDevice
->VfPciBar
[BarIndex
].Offset
= (UINT16
) Offset
;
1439 if ((Value
& 0x01) != 0) {
1441 // Device I/Os. Impossible
1450 PciIoDevice
->VfPciBar
[BarIndex
].BaseAddress
= OriginalValue
& Mask
;
1452 switch (Value
& 0x07) {
1455 //memory space; anywhere in 32 bit address space
1458 if ((Value
& 0x08) != 0) {
1459 PciIoDevice
->VfPciBar
[BarIndex
].BarType
= PciBarTypePMem32
;
1461 PciIoDevice
->VfPciBar
[BarIndex
].BarType
= PciBarTypeMem32
;
1464 PciIoDevice
->VfPciBar
[BarIndex
].Length
= (~(Value
& Mask
)) + 1;
1465 PciIoDevice
->VfPciBar
[BarIndex
].Alignment
= PciIoDevice
->VfPciBar
[BarIndex
].Length
- 1;
1470 PciIoDevice
->VfPciBar
[BarIndex
].Length
= MultU64x32 (PciIoDevice
->VfPciBar
[BarIndex
].Length
, PciIoDevice
->InitialVFs
);
1474 if (PciIoDevice
->VfPciBar
[BarIndex
].Alignment
< PciIoDevice
->SystemPageSize
- 1) {
1475 PciIoDevice
->VfPciBar
[BarIndex
].Alignment
= PciIoDevice
->SystemPageSize
- 1;
1481 // memory space; anywhere in 64 bit address space
1484 if ((Value
& 0x08) != 0) {
1485 PciIoDevice
->VfPciBar
[BarIndex
].BarType
= PciBarTypePMem64
;
1487 PciIoDevice
->VfPciBar
[BarIndex
].BarType
= PciBarTypeMem64
;
1491 // According to PCI 2.2,if the bar indicates a memory 64 decoding, next bar
1492 // is regarded as an extension for the first bar. As a result
1493 // the sizing will be conducted on combined 64 bit value
1494 // Here just store the masked first 32bit value for future size
1497 PciIoDevice
->VfPciBar
[BarIndex
].Length
= Value
& Mask
;
1498 PciIoDevice
->VfPciBar
[BarIndex
].Alignment
= PciIoDevice
->VfPciBar
[BarIndex
].Length
- 1;
1500 if (PciIoDevice
->VfPciBar
[BarIndex
].Alignment
< PciIoDevice
->SystemPageSize
- 1) {
1501 PciIoDevice
->VfPciBar
[BarIndex
].Alignment
= PciIoDevice
->SystemPageSize
- 1;
1505 // Increment the offset to point to next DWORD
1509 Status
= VfBarExisted (
1516 if (EFI_ERROR (Status
)) {
1521 // Fix the length to support some spefic 64 bit BAR
1525 for (Data
= Value
; Data
!= 0; Data
>>= 1) {
1528 Value
|= ((UINT32
)(-1) << Index
);
1531 // Calculate the size of 64bit bar
1533 PciIoDevice
->VfPciBar
[BarIndex
].BaseAddress
|= LShiftU64 ((UINT64
) OriginalValue
, 32);
1535 PciIoDevice
->VfPciBar
[BarIndex
].Length
= PciIoDevice
->VfPciBar
[BarIndex
].Length
| LShiftU64 ((UINT64
) Value
, 32);
1536 PciIoDevice
->VfPciBar
[BarIndex
].Length
= (~(PciIoDevice
->VfPciBar
[BarIndex
].Length
)) + 1;
1537 PciIoDevice
->VfPciBar
[BarIndex
].Alignment
= PciIoDevice
->VfPciBar
[BarIndex
].Length
- 1;
1542 PciIoDevice
->VfPciBar
[BarIndex
].Length
= MultU64x32 (PciIoDevice
->VfPciBar
[BarIndex
].Length
, PciIoDevice
->InitialVFs
);
1546 if (PciIoDevice
->VfPciBar
[BarIndex
].Alignment
< PciIoDevice
->SystemPageSize
- 1) {
1547 PciIoDevice
->VfPciBar
[BarIndex
].Alignment
= PciIoDevice
->SystemPageSize
- 1;
1556 PciIoDevice
->VfPciBar
[BarIndex
].BarType
= PciBarTypeUnknown
;
1557 PciIoDevice
->VfPciBar
[BarIndex
].Length
= (~(Value
& Mask
)) + 1;
1558 PciIoDevice
->VfPciBar
[BarIndex
].Alignment
= PciIoDevice
->VfPciBar
[BarIndex
].Length
- 1;
1560 if (PciIoDevice
->VfPciBar
[BarIndex
].Alignment
< PciIoDevice
->SystemPageSize
- 1) {
1561 PciIoDevice
->VfPciBar
[BarIndex
].Alignment
= PciIoDevice
->SystemPageSize
- 1;
1569 // Check the length again so as to keep compatible with some special bars
1571 if (PciIoDevice
->VfPciBar
[BarIndex
].Length
== 0) {
1572 PciIoDevice
->VfPciBar
[BarIndex
].BarType
= PciBarTypeUnknown
;
1573 PciIoDevice
->VfPciBar
[BarIndex
].BaseAddress
= 0;
1574 PciIoDevice
->VfPciBar
[BarIndex
].Alignment
= 0;
1578 // Increment number of bar
1584 Parse PCI bar information and fill them into PCI device instance.
1586 @param PciIoDevice Pci device instance.
1587 @param Offset Bar offset.
1588 @param BarIndex Bar index.
1590 @return Next bar offset.
1595 IN PCI_IO_DEVICE
*PciIoDevice
,
1601 UINT32 OriginalValue
;
1610 Status
= BarExisted (
1617 if (EFI_ERROR (Status
)) {
1618 PciIoDevice
->PciBar
[BarIndex
].BaseAddress
= 0;
1619 PciIoDevice
->PciBar
[BarIndex
].Length
= 0;
1620 PciIoDevice
->PciBar
[BarIndex
].Alignment
= 0;
1623 // Some devices don't fully comply to PCI spec 2.2. So be to scan all the BARs anyway
1625 PciIoDevice
->PciBar
[BarIndex
].Offset
= (UINT8
) Offset
;
1629 PciIoDevice
->PciBar
[BarIndex
].Offset
= (UINT8
) Offset
;
1630 if ((Value
& 0x01) != 0) {
1636 if ((Value
& 0xFFFF0000) != 0) {
1640 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypeIo32
;
1641 PciIoDevice
->PciBar
[BarIndex
].Length
= ((~(Value
& Mask
)) + 1);
1642 PciIoDevice
->PciBar
[BarIndex
].Alignment
= PciIoDevice
->PciBar
[BarIndex
].Length
- 1;
1648 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypeIo16
;
1649 PciIoDevice
->PciBar
[BarIndex
].Length
= 0x0000FFFF & ((~(Value
& Mask
)) + 1);
1650 PciIoDevice
->PciBar
[BarIndex
].Alignment
= PciIoDevice
->PciBar
[BarIndex
].Length
- 1;
1654 // Workaround. Some platforms inplement IO bar with 0 length
1655 // Need to treat it as no-bar
1657 if (PciIoDevice
->PciBar
[BarIndex
].Length
== 0) {
1658 PciIoDevice
->PciBar
[BarIndex
].BarType
= (PCI_BAR_TYPE
) 0;
1661 PciIoDevice
->PciBar
[BarIndex
].Prefetchable
= FALSE
;
1662 PciIoDevice
->PciBar
[BarIndex
].BaseAddress
= OriginalValue
& Mask
;
1668 PciIoDevice
->PciBar
[BarIndex
].BaseAddress
= OriginalValue
& Mask
;
1670 switch (Value
& 0x07) {
1673 //memory space; anywhere in 32 bit address space
1676 if ((Value
& 0x08) != 0) {
1677 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypePMem32
;
1679 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypeMem32
;
1682 PciIoDevice
->PciBar
[BarIndex
].Length
= (~(Value
& Mask
)) + 1;
1683 if (PciIoDevice
->PciBar
[BarIndex
].Length
< (SIZE_4KB
)) {
1685 // Force minimum 4KByte alignment for Virtualization technology for Directed I/O
1687 PciIoDevice
->PciBar
[BarIndex
].Alignment
= (SIZE_4KB
- 1);
1689 PciIoDevice
->PciBar
[BarIndex
].Alignment
= PciIoDevice
->PciBar
[BarIndex
].Length
- 1;
1694 // memory space; anywhere in 64 bit address space
1697 if ((Value
& 0x08) != 0) {
1698 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypePMem64
;
1700 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypeMem64
;
1704 // According to PCI 2.2,if the bar indicates a memory 64 decoding, next bar
1705 // is regarded as an extension for the first bar. As a result
1706 // the sizing will be conducted on combined 64 bit value
1707 // Here just store the masked first 32bit value for future size
1710 PciIoDevice
->PciBar
[BarIndex
].Length
= Value
& Mask
;
1711 PciIoDevice
->PciBar
[BarIndex
].Alignment
= PciIoDevice
->PciBar
[BarIndex
].Length
- 1;
1714 // Increment the offset to point to next DWORD
1718 Status
= BarExisted (
1725 if (EFI_ERROR (Status
)) {
1727 // the high 32 bit does not claim any BAR, we need to re-check the low 32 bit BAR again
1729 if (PciIoDevice
->PciBar
[BarIndex
].Length
== 0) {
1731 // some device implement MMIO bar with 0 length, need to treat it as no-bar
1733 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypeUnknown
;
1739 // Fix the length to support some spefic 64 bit BAR
1743 for (Data
= Value
; Data
!= 0; Data
>>= 1) {
1746 Value
|= ((UINT32
)(-1) << Index
);
1749 // Calculate the size of 64bit bar
1751 PciIoDevice
->PciBar
[BarIndex
].BaseAddress
|= LShiftU64 ((UINT64
) OriginalValue
, 32);
1753 PciIoDevice
->PciBar
[BarIndex
].Length
= PciIoDevice
->PciBar
[BarIndex
].Length
| LShiftU64 ((UINT64
) Value
, 32);
1754 PciIoDevice
->PciBar
[BarIndex
].Length
= (~(PciIoDevice
->PciBar
[BarIndex
].Length
)) + 1;
1755 if (PciIoDevice
->PciBar
[BarIndex
].Length
< (SIZE_4KB
)) {
1757 // Force minimum 4KByte alignment for Virtualization technology for Directed I/O
1759 PciIoDevice
->PciBar
[BarIndex
].Alignment
= (SIZE_4KB
- 1);
1761 PciIoDevice
->PciBar
[BarIndex
].Alignment
= PciIoDevice
->PciBar
[BarIndex
].Length
- 1;
1770 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypeUnknown
;
1771 PciIoDevice
->PciBar
[BarIndex
].Length
= (~(Value
& Mask
)) + 1;
1772 if (PciIoDevice
->PciBar
[BarIndex
].Length
< (SIZE_4KB
)) {
1774 // Force minimum 4KByte alignment for Virtualization technology for Directed I/O
1776 PciIoDevice
->PciBar
[BarIndex
].Alignment
= (SIZE_4KB
- 1);
1778 PciIoDevice
->PciBar
[BarIndex
].Alignment
= PciIoDevice
->PciBar
[BarIndex
].Length
- 1;
1785 // Check the length again so as to keep compatible with some special bars
1787 if (PciIoDevice
->PciBar
[BarIndex
].Length
== 0) {
1788 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypeUnknown
;
1789 PciIoDevice
->PciBar
[BarIndex
].BaseAddress
= 0;
1790 PciIoDevice
->PciBar
[BarIndex
].Alignment
= 0;
1794 // Increment number of bar
1800 This routine is used to initialize the bar of a PCI device.
1802 @param PciIoDevice Pci device instance.
1804 @note It can be called typically when a device is going to be rejected.
1808 InitializePciDevice (
1809 IN PCI_IO_DEVICE
*PciIoDevice
1812 EFI_PCI_IO_PROTOCOL
*PciIo
;
1815 PciIo
= &(PciIoDevice
->PciIo
);
1818 // Put all the resource apertures
1819 // Resource base is set to all ones so as to indicate its resource
1820 // has not been alloacted
1822 for (Offset
= 0x10; Offset
<= 0x24; Offset
+= sizeof (UINT32
)) {
1823 PciIo
->Pci
.Write (PciIo
, EfiPciIoWidthUint32
, Offset
, 1, &gAllOne
);
1828 This routine is used to initialize the bar of a PCI-PCI Bridge device.
1830 @param PciIoDevice PCI-PCI bridge device instance.
1835 IN PCI_IO_DEVICE
*PciIoDevice
1838 EFI_PCI_IO_PROTOCOL
*PciIo
;
1840 PciIo
= &(PciIoDevice
->PciIo
);
1843 // Put all the resource apertures including IO16
1844 // Io32, pMem32, pMem64 to quiescent state
1845 // Resource base all ones, Resource limit all zeros
1847 PciIo
->Pci
.Write (PciIo
, EfiPciIoWidthUint8
, 0x1C, 1, &gAllOne
);
1848 PciIo
->Pci
.Write (PciIo
, EfiPciIoWidthUint8
, 0x1D, 1, &gAllZero
);
1850 PciIo
->Pci
.Write (PciIo
, EfiPciIoWidthUint16
, 0x20, 1, &gAllOne
);
1851 PciIo
->Pci
.Write (PciIo
, EfiPciIoWidthUint16
, 0x22, 1, &gAllZero
);
1853 PciIo
->Pci
.Write (PciIo
, EfiPciIoWidthUint16
, 0x24, 1, &gAllOne
);
1854 PciIo
->Pci
.Write (PciIo
, EfiPciIoWidthUint16
, 0x26, 1, &gAllZero
);
1856 PciIo
->Pci
.Write (PciIo
, EfiPciIoWidthUint32
, 0x28, 1, &gAllOne
);
1857 PciIo
->Pci
.Write (PciIo
, EfiPciIoWidthUint32
, 0x2C, 1, &gAllZero
);
1860 // Don't support use io32 as for now
1862 PciIo
->Pci
.Write (PciIo
, EfiPciIoWidthUint16
, 0x30, 1, &gAllOne
);
1863 PciIo
->Pci
.Write (PciIo
, EfiPciIoWidthUint16
, 0x32, 1, &gAllZero
);
1866 // Force Interrupt line to zero for cards that come up randomly
1868 PciIo
->Pci
.Write (PciIo
, EfiPciIoWidthUint8
, 0x3C, 1, &gAllZero
);
1872 This routine is used to initialize the bar of a PCI Card Bridge device.
1874 @param PciIoDevice PCI Card bridge device.
1879 IN PCI_IO_DEVICE
*PciIoDevice
1882 EFI_PCI_IO_PROTOCOL
*PciIo
;
1884 PciIo
= &(PciIoDevice
->PciIo
);
1887 // Put all the resource apertures including IO16
1888 // Io32, pMem32, pMem64 to quiescent state(
1889 // Resource base all ones, Resource limit all zeros
1891 PciIo
->Pci
.Write (PciIo
, EfiPciIoWidthUint32
, 0x1c, 1, &gAllOne
);
1892 PciIo
->Pci
.Write (PciIo
, EfiPciIoWidthUint32
, 0x20, 1, &gAllZero
);
1894 PciIo
->Pci
.Write (PciIo
, EfiPciIoWidthUint32
, 0x24, 1, &gAllOne
);
1895 PciIo
->Pci
.Write (PciIo
, EfiPciIoWidthUint32
, 0x28, 1, &gAllZero
);
1897 PciIo
->Pci
.Write (PciIo
, EfiPciIoWidthUint32
, 0x2c, 1, &gAllOne
);
1898 PciIo
->Pci
.Write (PciIo
, EfiPciIoWidthUint32
, 0x30, 1, &gAllZero
);
1900 PciIo
->Pci
.Write (PciIo
, EfiPciIoWidthUint32
, 0x34, 1, &gAllOne
);
1901 PciIo
->Pci
.Write (PciIo
, EfiPciIoWidthUint32
, 0x38, 1, &gAllZero
);
1904 // Force Interrupt line to zero for cards that come up randomly
1906 PciIo
->Pci
.Write (PciIo
, EfiPciIoWidthUint8
, 0x3C, 1, &gAllZero
);
1910 Create and initiliaze general PCI I/O device instance for
1911 PCI device/bridge device/hotplug bridge device.
1913 @param PciRootBridgeIo Pointer to instance of EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
1914 @param Pci Input Pci information block.
1915 @param Bus Device Bus NO.
1916 @param Device Device device NO.
1917 @param Func Device func NO.
1919 @return Instance of PCI device. NULL means no instance created.
1924 IN PCI_IO_DEVICE
*Bridge
,
1931 PCI_IO_DEVICE
*PciIoDevice
;
1932 EFI_PCI_IO_PROTOCOL
*PciIo
;
1935 PciIoDevice
= AllocateZeroPool (sizeof (PCI_IO_DEVICE
));
1936 if (PciIoDevice
== NULL
) {
1940 PciIoDevice
->Signature
= PCI_IO_DEVICE_SIGNATURE
;
1941 PciIoDevice
->Handle
= NULL
;
1942 PciIoDevice
->PciRootBridgeIo
= Bridge
->PciRootBridgeIo
;
1943 PciIoDevice
->DevicePath
= NULL
;
1944 PciIoDevice
->BusNumber
= Bus
;
1945 PciIoDevice
->DeviceNumber
= Device
;
1946 PciIoDevice
->FunctionNumber
= Func
;
1947 PciIoDevice
->Decodes
= 0;
1949 if (gFullEnumeration
) {
1950 PciIoDevice
->Allocated
= FALSE
;
1952 PciIoDevice
->Allocated
= TRUE
;
1955 PciIoDevice
->Registered
= FALSE
;
1956 PciIoDevice
->Attributes
= 0;
1957 PciIoDevice
->Supports
= 0;
1958 PciIoDevice
->BusOverride
= FALSE
;
1959 PciIoDevice
->AllOpRomProcessed
= FALSE
;
1961 PciIoDevice
->IsPciExp
= FALSE
;
1963 CopyMem (&(PciIoDevice
->Pci
), Pci
, sizeof (PCI_TYPE01
));
1966 // Initialize the PCI I/O instance structure
1968 InitializePciIoInstance (PciIoDevice
);
1969 InitializePciDriverOverrideInstance (PciIoDevice
);
1970 InitializePciLoadFile2 (PciIoDevice
);
1971 PciIo
= &PciIoDevice
->PciIo
;
1974 // Detect if PCI Express Device
1976 PciIoDevice
->PciExpressCapabilityOffset
= 0;
1977 Status
= LocateCapabilityRegBlock (
1979 EFI_PCI_CAPABILITY_ID_PCIEXP
,
1980 &PciIoDevice
->PciExpressCapabilityOffset
,
1983 if (!EFI_ERROR (Status
)) {
1984 PciIoDevice
->IsPciExp
= TRUE
;
1987 if (PcdGetBool (PcdAriSupport
)) {
1989 // Check if the device is an ARI device.
1991 Status
= LocatePciExpressCapabilityRegBlock (
1993 EFI_PCIE_CAPABILITY_ID_ARI
,
1994 &PciIoDevice
->AriCapabilityOffset
,
1997 if (!EFI_ERROR (Status
)) {
1999 // We need to enable ARI feature before calculate BusReservation,
2000 // because FirstVFOffset and VFStride may change after that.
2002 EFI_PCI_IO_PROTOCOL
*ParentPciIo
;
2006 // Check if its parent supports ARI forwarding.
2008 ParentPciIo
= &Bridge
->PciIo
;
2009 ParentPciIo
->Pci
.Read (
2011 EfiPciIoWidthUint32
,
2012 Bridge
->PciExpressCapabilityOffset
+ EFI_PCIE_CAPABILITY_DEVICE_CAPABILITIES_2_OFFSET
,
2016 if ((Data32
& EFI_PCIE_CAPABILITY_DEVICE_CAPABILITIES_2_ARI_FORWARDING
) != 0) {
2018 // ARI forward support in bridge, so enable it.
2020 ParentPciIo
->Pci
.Read (
2022 EfiPciIoWidthUint32
,
2023 Bridge
->PciExpressCapabilityOffset
+ EFI_PCIE_CAPABILITY_DEVICE_CONTROL_2_OFFSET
,
2027 if ((Data32
& EFI_PCIE_CAPABILITY_DEVICE_CONTROL_2_ARI_FORWARDING
) == 0) {
2028 Data32
|= EFI_PCIE_CAPABILITY_DEVICE_CONTROL_2_ARI_FORWARDING
;
2029 ParentPciIo
->Pci
.Write (
2031 EfiPciIoWidthUint32
,
2032 Bridge
->PciExpressCapabilityOffset
+ EFI_PCIE_CAPABILITY_DEVICE_CONTROL_2_OFFSET
,
2038 "PCI B%x.D%x.F%x - ARI forwarding enabled\n",
2039 (UINTN
)Bridge
->BusNumber
,
2040 (UINTN
)Bridge
->DeviceNumber
,
2041 (UINTN
)Bridge
->FunctionNumber
2048 "PCI ARI B%x.D%x.F%x - ARI Cap offset - 0x%x\n",
2052 (UINTN
)PciIoDevice
->AriCapabilityOffset
2058 // Initialization for SR-IOV
2061 if (PcdGetBool (PcdSrIovSupport
)) {
2062 Status
= LocatePciExpressCapabilityRegBlock (
2064 EFI_PCIE_CAPABILITY_ID_SRIOV
,
2065 &PciIoDevice
->SrIovCapabilityOffset
,
2068 if (!EFI_ERROR (Status
)) {
2070 UINT16 FirstVFOffset
;
2076 // If the SR-IOV device is an ARI device, then Set ARI Capable Hierarchy for the device.
2078 if (PcdGetBool (PcdAriSupport
) && PciIoDevice
->AriCapabilityOffset
!= 0) {
2081 EfiPciIoWidthUint16
,
2082 PciIoDevice
->SrIovCapabilityOffset
+ EFI_PCIE_CAPABILITY_ID_SRIOV_CONTROL
,
2086 Data16
|= EFI_PCIE_CAPABILITY_ID_SRIOV_CONTROL_ARI_HIERARCHY
;
2089 EfiPciIoWidthUint16
,
2090 PciIoDevice
->SrIovCapabilityOffset
+ EFI_PCIE_CAPABILITY_ID_SRIOV_CONTROL
,
2097 // Calculate SystemPageSize
2102 EfiPciIoWidthUint32
,
2103 PciIoDevice
->SrIovCapabilityOffset
+ EFI_PCIE_CAPABILITY_ID_SRIOV_SUPPORTED_PAGE_SIZE
,
2105 &PciIoDevice
->SystemPageSize
2109 "PCI SR-IOV B%x.D%x.F%x - SupportedPageSize - 0x%x\n",
2113 PciIoDevice
->SystemPageSize
2116 PciIoDevice
->SystemPageSize
= (PcdGet32 (PcdSrIovSystemPageSize
) & PciIoDevice
->SystemPageSize
);
2117 ASSERT (PciIoDevice
->SystemPageSize
!= 0);
2121 EfiPciIoWidthUint32
,
2122 PciIoDevice
->SrIovCapabilityOffset
+ EFI_PCIE_CAPABILITY_ID_SRIOV_SYSTEM_PAGE_SIZE
,
2124 &PciIoDevice
->SystemPageSize
2128 "PCI SR-IOV B%x.D%x.F%x - SystemPageSize - 0x%x\n",
2132 PciIoDevice
->SystemPageSize
2135 // Adjust SystemPageSize for Alignment usage later
2137 PciIoDevice
->SystemPageSize
<<= 12;
2140 // Calculate BusReservation for PCI IOV
2144 // Read First FirstVFOffset, InitialVFs, and VFStride
2148 EfiPciIoWidthUint16
,
2149 PciIoDevice
->SrIovCapabilityOffset
+ EFI_PCIE_CAPABILITY_ID_SRIOV_FIRSTVF
,
2155 "PCI SR-IOV B%x.D%x.F%x - FirstVFOffset - 0x%x\n",
2159 (UINTN
)FirstVFOffset
2164 EfiPciIoWidthUint16
,
2165 PciIoDevice
->SrIovCapabilityOffset
+ EFI_PCIE_CAPABILITY_ID_SRIOV_INITIALVFS
,
2167 &PciIoDevice
->InitialVFs
2171 "PCI SR-IOV B%x.D%x.F%x - InitialVFs - 0x%x\n",
2175 (UINTN
)PciIoDevice
->InitialVFs
2180 EfiPciIoWidthUint16
,
2181 PciIoDevice
->SrIovCapabilityOffset
+ EFI_PCIE_CAPABILITY_ID_SRIOV_VFSTRIDE
,
2187 "PCI SR-IOV B%x.D%x.F%x - VFStride - 0x%x\n",
2197 PFRid
= EFI_PCI_RID(Bus
, Device
, Func
);
2198 LastVF
= PFRid
+ FirstVFOffset
+ (PciIoDevice
->InitialVFs
- 1) * VFStride
;
2201 // Calculate ReservedBusNum for this PF
2203 PciIoDevice
->ReservedBusNum
= (UINT16
)(EFI_PCI_BUS_OF_RID (LastVF
) - Bus
+ 1);
2206 "PCI SR-IOV B%x.D%x.F%x - reserved bus number - 0x%x\n",
2210 (UINTN
)PciIoDevice
->ReservedBusNum
2215 "PCI SR-IOV B%x.D%x.F%x - SRIOV Cap offset - 0x%x\n",
2219 (UINTN
)PciIoDevice
->SrIovCapabilityOffset
2224 if (PcdGetBool (PcdMrIovSupport
)) {
2225 Status
= LocatePciExpressCapabilityRegBlock (
2227 EFI_PCIE_CAPABILITY_ID_MRIOV
,
2228 &PciIoDevice
->MrIovCapabilityOffset
,
2231 if (!EFI_ERROR (Status
)) {
2234 "PCI MR-IOV B%x.D%x.F%x - MRIOV Cap offset - 0x%x\n",
2238 (UINTN
)PciIoDevice
->MrIovCapabilityOffset
2244 // Initialize the reserved resource list
2246 InitializeListHead (&PciIoDevice
->ReservedResourceList
);
2249 // Initialize the driver list
2251 InitializeListHead (&PciIoDevice
->OptionRomDriverList
);
2254 // Initialize the child list
2256 InitializeListHead (&PciIoDevice
->ChildList
);
2262 This routine is used to enumerate entire pci bus system
2263 in a given platform.
2265 It is only called on the second start on the same Root Bridge.
2267 @param Controller Parent bridge handler.
2269 @retval EFI_SUCCESS PCI enumeration finished successfully.
2270 @retval other Some error occurred when enumerating the pci bus system.
2274 PciEnumeratorLight (
2275 IN EFI_HANDLE Controller
2280 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
2281 PCI_IO_DEVICE
*RootBridgeDev
;
2284 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Descriptors
;
2287 MaxBus
= PCI_MAX_BUS
;
2291 // If this root bridge has been already enumerated, then return successfully
2293 if (GetRootBridgeByHandle (Controller
) != NULL
) {
2298 // Open pci root bridge io protocol
2300 Status
= gBS
->OpenProtocol (
2302 &gEfiPciRootBridgeIoProtocolGuid
,
2303 (VOID
**) &PciRootBridgeIo
,
2304 gPciBusDriverBinding
.DriverBindingHandle
,
2306 EFI_OPEN_PROTOCOL_BY_DRIVER
2308 if (EFI_ERROR (Status
) && Status
!= EFI_ALREADY_STARTED
) {
2312 Status
= PciRootBridgeIo
->Configuration (PciRootBridgeIo
, (VOID
**) &Descriptors
);
2314 if (EFI_ERROR (Status
)) {
2318 while (PciGetBusRange (&Descriptors
, &MinBus
, &MaxBus
, NULL
) == EFI_SUCCESS
) {
2321 // Create a device node for root bridge device with a NULL host bridge controller handle
2323 RootBridgeDev
= CreateRootBridge (Controller
);
2325 if (RootBridgeDev
== NULL
) {
2331 // Record the root bridgeio protocol
2333 RootBridgeDev
->PciRootBridgeIo
= PciRootBridgeIo
;
2335 Status
= PciPciDeviceInfoCollector (
2340 if (!EFI_ERROR (Status
)) {
2343 // Remove those PCI devices which are rejected when full enumeration
2345 RemoveRejectedPciDevices (RootBridgeDev
->Handle
, RootBridgeDev
);
2348 // Process option rom light
2350 ProcessOptionRomLight (RootBridgeDev
);
2353 // Determine attributes for all devices under this root bridge
2355 DetermineDeviceAttribute (RootBridgeDev
);
2358 // If successfully, insert the node into device pool
2360 InsertRootBridge (RootBridgeDev
);
2364 // If unsuccessly, destroy the entire node
2366 DestroyRootBridge (RootBridgeDev
);
2376 Get bus range from PCI resource descriptor list.
2378 @param Descriptors A pointer to the address space descriptor.
2379 @param MinBus The min bus returned.
2380 @param MaxBus The max bus returned.
2381 @param BusRange The bus range returned.
2383 @retval EFI_SUCCESS Successfully got bus range.
2384 @retval EFI_NOT_FOUND Can not find the specific bus.
2389 IN EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
**Descriptors
,
2392 OUT UINT16
*BusRange
2395 while ((*Descriptors
)->Desc
!= ACPI_END_TAG_DESCRIPTOR
) {
2396 if ((*Descriptors
)->ResType
== ACPI_ADDRESS_SPACE_TYPE_BUS
) {
2397 if (MinBus
!= NULL
) {
2398 *MinBus
= (UINT16
) (*Descriptors
)->AddrRangeMin
;
2401 if (MaxBus
!= NULL
) {
2402 *MaxBus
= (UINT16
) (*Descriptors
)->AddrRangeMax
;
2405 if (BusRange
!= NULL
) {
2406 *BusRange
= (UINT16
) (*Descriptors
)->AddrLen
;
2415 return EFI_NOT_FOUND
;
2419 This routine can be used to start the root bridge.
2421 @param RootBridgeDev Pci device instance.
2423 @retval EFI_SUCCESS This device started.
2424 @retval other Failed to get PCI Root Bridge I/O protocol.
2428 StartManagingRootBridge (
2429 IN PCI_IO_DEVICE
*RootBridgeDev
2432 EFI_HANDLE RootBridgeHandle
;
2434 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
2437 // Get the root bridge handle
2439 RootBridgeHandle
= RootBridgeDev
->Handle
;
2440 PciRootBridgeIo
= NULL
;
2443 // Get the pci root bridge io protocol
2445 Status
= gBS
->OpenProtocol (
2447 &gEfiPciRootBridgeIoProtocolGuid
,
2448 (VOID
**) &PciRootBridgeIo
,
2449 gPciBusDriverBinding
.DriverBindingHandle
,
2451 EFI_OPEN_PROTOCOL_BY_DRIVER
2454 if (EFI_ERROR (Status
) && Status
!= EFI_ALREADY_STARTED
) {
2459 // Store the PciRootBridgeIo protocol into root bridge private data
2461 RootBridgeDev
->PciRootBridgeIo
= PciRootBridgeIo
;
2468 This routine can be used to check whether a PCI device should be rejected when light enumeration.
2470 @param PciIoDevice Pci device instance.
2472 @retval TRUE This device should be rejected.
2473 @retval FALSE This device shouldn't be rejected.
2477 IsPciDeviceRejected (
2478 IN PCI_IO_DEVICE
*PciIoDevice
2488 // PPB should be skip!
2490 if (IS_PCI_BRIDGE (&PciIoDevice
->Pci
)) {
2494 if (IS_CARDBUS_BRIDGE (&PciIoDevice
->Pci
)) {
2496 // Only test base registers for P2C
2498 for (BarOffset
= 0x1C; BarOffset
<= 0x38; BarOffset
+= 2 * sizeof (UINT32
)) {
2500 Mask
= (BarOffset
< 0x2C) ? 0xFFFFF000 : 0xFFFFFFFC;
2501 Status
= BarExisted (PciIoDevice
, BarOffset
, &TestValue
, &OldValue
);
2502 if (EFI_ERROR (Status
)) {
2506 TestValue
= TestValue
& Mask
;
2507 if ((TestValue
!= 0) && (TestValue
== (OldValue
& Mask
))) {
2509 // The bar isn't programed, so it should be rejected
2518 for (BarOffset
= 0x14; BarOffset
<= 0x24; BarOffset
+= sizeof (UINT32
)) {
2522 Status
= BarExisted (PciIoDevice
, BarOffset
, &TestValue
, &OldValue
);
2523 if (EFI_ERROR (Status
)) {
2527 if ((TestValue
& 0x01) != 0) {
2533 TestValue
= TestValue
& Mask
;
2534 if ((TestValue
!= 0) && (TestValue
== (OldValue
& Mask
))) {
2544 TestValue
= TestValue
& Mask
;
2546 if ((TestValue
& 0x07) == 0x04) {
2551 BarOffset
+= sizeof (UINT32
);
2552 if ((TestValue
!= 0) && (TestValue
== (OldValue
& Mask
))) {
2555 // Test its high 32-Bit BAR
2557 Status
= BarExisted (PciIoDevice
, BarOffset
, &TestValue
, &OldValue
);
2558 if (TestValue
== OldValue
) {
2568 if ((TestValue
!= 0) && (TestValue
== (OldValue
& Mask
))) {
2579 Reset all bus number from specific bridge.
2581 @param Bridge Parent specific bridge.
2582 @param StartBusNumber Start bus number.
2586 ResetAllPpbBusNumber (
2587 IN PCI_IO_DEVICE
*Bridge
,
2588 IN UINT8 StartBusNumber
2598 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
2600 PciRootBridgeIo
= Bridge
->PciRootBridgeIo
;
2602 for (Device
= 0; Device
<= PCI_MAX_DEVICE
; Device
++) {
2603 for (Func
= 0; Func
<= PCI_MAX_FUNC
; Func
++) {
2606 // Check to see whether a pci device is present
2608 Status
= PciDevicePresent (
2616 if (!EFI_ERROR (Status
) && (IS_PCI_BRIDGE (&Pci
))) {
2619 Address
= EFI_PCI_ADDRESS (StartBusNumber
, Device
, Func
, 0x18);
2620 Status
= PciRootBridgeIo
->Pci
.Read (
2627 SecondaryBus
= (UINT8
)(Register
>> 8);
2629 if (SecondaryBus
!= 0) {
2630 ResetAllPpbBusNumber (Bridge
, SecondaryBus
);
2634 // Reset register 18h, 19h, 1Ah on PCI Bridge
2636 Register
&= 0xFF000000;
2637 Status
= PciRootBridgeIo
->Pci
.Write (
2646 if (Func
== 0 && !IS_PCI_MULTI_FUNC (&Pci
)) {
2648 // Skip sub functions, this is not a multi function device
2650 Func
= PCI_MAX_FUNC
;