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"
22 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
,
32 This routine is used to check whether the pci device is present
41 // TODO: PciRootBridgeIo - add argument and description to function comment
42 // TODO: Pci - add argument and description to function comment
43 // TODO: Bus - add argument and description to function comment
44 // TODO: Device - add argument and description to function comment
45 // TODO: Func - add argument and description to function comment
46 // TODO: EFI_SUCCESS - add return value to function comment
47 // TODO: EFI_NOT_FOUND - add return value to function comment
53 // Create PCI address map in terms of Bus, Device and Func
55 Address
= EFI_PCI_ADDRESS (Bus
, Device
, Func
, 0);
58 // Read the Vendor Id register
60 Status
= PciRootBridgeIoRead (
69 if (!EFI_ERROR (Status
) && (Pci
->Hdr
).VendorId
!= 0xffff) {
72 // Read the entire config header for the device
75 Status
= PciRootBridgeIoRead (
80 sizeof (PCI_TYPE00
) / sizeof (UINT32
),
91 PciPciDeviceInfoCollector (
92 IN PCI_IO_DEVICE
*Bridge
,
106 // TODO: Bridge - add argument and description to function comment
107 // TODO: StartBusNumber - add argument and description to function comment
108 // TODO: EFI_SUCCESS - add return value to function comment
115 PCI_IO_DEVICE
*PciIoDevice
;
116 EFI_PCI_IO_PROTOCOL
*PciIo
;
118 Status
= EFI_SUCCESS
;
121 for (Device
= 0; Device
<= PCI_MAX_DEVICE
; Device
++) {
123 for (Func
= 0; Func
<= PCI_MAX_FUNC
; Func
++) {
126 // Check to see whether PCI device is present
129 Status
= PciDevicePresent (
130 Bridge
->PciRootBridgeIo
,
132 (UINT8
) StartBusNumber
,
137 if (!EFI_ERROR (Status
)) {
140 // Call back to host bridge function
142 PreprocessController (Bridge
, (UINT8
) StartBusNumber
, Device
, Func
, EfiPciBeforeResourceCollection
);
145 // Collect all the information about the PCI device discovered
147 Status
= PciSearchDevice (
150 (UINT8
) StartBusNumber
,
157 // Recursively scan PCI busses on the other side of PCI-PCI bridges
161 if (!EFI_ERROR (Status
) && (IS_PCI_BRIDGE (&Pci
) || IS_CARDBUS_BRIDGE (&Pci
))) {
164 // If it is PPB, we need to get the secondary bus to continue the enumeration
166 PciIo
= &(PciIoDevice
->PciIo
);
168 Status
= PciIoRead (PciIo
, EfiPciIoWidthUint8
, 0x19, 1, &SecBus
);
170 if (EFI_ERROR (Status
)) {
175 // Get resource padding for PPB
177 GetResourcePaddingPpb (PciIoDevice
);
180 // Deep enumerate the next level bus
182 Status
= PciPciDeviceInfoCollector (
189 if (Func
== 0 && !IS_PCI_MULTI_FUNC (&Pci
)) {
192 // Skip sub functions, this is not a multi function device
206 IN PCI_IO_DEVICE
*Bridge
,
211 OUT PCI_IO_DEVICE
**PciDevice
217 Search required device.
221 Bridge - A pointer to the PCI_IO_DEVICE.
222 Pci - A pointer to the PCI_TYPE00.
224 Device - Device number.
225 Func - Function number.
226 PciDevice - The Required pci device.
233 // TODO: EFI_OUT_OF_RESOURCES - add return value to function comment
234 // TODO: EFI_OUT_OF_RESOURCES - add return value to function comment
235 // TODO: EFI_SUCCESS - add return value to function comment
237 PCI_IO_DEVICE
*PciIoDevice
;
241 if (!IS_PCI_BRIDGE (Pci
)) {
243 if (IS_CARDBUS_BRIDGE (Pci
)) {
244 PciIoDevice
= GatherP2CInfo (
251 if ((PciIoDevice
!= NULL
) && gFullEnumeration
) {
252 InitializeP2C (PciIoDevice
);
257 // Create private data for Pci Device
259 PciIoDevice
= GatherDeviceInfo (
272 // Create private data for PPB
274 PciIoDevice
= GatherPpbInfo (
283 // Special initialization for PPB including making the PPB quiet
285 if ((PciIoDevice
!= NULL
) && gFullEnumeration
) {
286 InitializePpb (PciIoDevice
);
291 return EFI_OUT_OF_RESOURCES
;
295 // Update the bar information for this PCI device so as to support some specific device
297 if (PcdGet8 (PcdPciIncompatibleDeviceSupportMask
) & PCI_INCOMPATIBLE_ACPI_RESOURCE_SUPPORT
) {
298 UpdatePciInfo (PciIoDevice
);
301 if (PciIoDevice
->DevicePath
== NULL
) {
302 return EFI_OUT_OF_RESOURCES
;
306 // Detect this function has option rom
308 if (gFullEnumeration
) {
310 if (!IS_CARDBUS_BRIDGE (Pci
)) {
312 GetOpRomInfo (PciIoDevice
);
316 ResetPowerManagementFeature (PciIoDevice
);
321 // Insert it into a global tree for future reference
323 InsertPciDevice (Bridge
, PciIoDevice
);
326 // Determine PCI device attributes
329 if (PciDevice
!= NULL
) {
330 *PciDevice
= PciIoDevice
;
338 IN PCI_IO_DEVICE
*Bridge
,
355 // TODO: Bridge - add argument and description to function comment
356 // TODO: Pci - add argument and description to function comment
357 // TODO: Bus - add argument and description to function comment
358 // TODO: Device - add argument and description to function comment
359 // TODO: Func - add argument and description to function comment
363 PCI_IO_DEVICE
*PciIoDevice
;
364 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
366 PciRootBridgeIo
= Bridge
->PciRootBridgeIo
;
367 PciIoDevice
= CreatePciIoDevice (
380 // Create a device path for this PCI device and store it into its private data
382 CreatePciDevicePath (
388 // If it is a full enumeration, disconnect the device in advance
390 if (gFullEnumeration
) {
392 PciDisableCommandRegister (PciIoDevice
, EFI_PCI_COMMAND_BITS_OWNED
);
397 // Start to parse the bars
399 for (Offset
= 0x10, BarIndex
= 0; Offset
<= 0x24; BarIndex
++) {
400 Offset
= PciParseBar (PciIoDevice
, Offset
, BarIndex
);
408 IN PCI_IO_DEVICE
*Bridge
,
425 // TODO: Bridge - add argument and description to function comment
426 // TODO: Pci - add argument and description to function comment
427 // TODO: Bus - add argument and description to function comment
428 // TODO: Device - add argument and description to function comment
429 // TODO: Func - add argument and description to function comment
431 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
432 PCI_IO_DEVICE
*PciIoDevice
;
435 EFI_PCI_IO_PROTOCOL
*PciIo
;
438 PciRootBridgeIo
= Bridge
->PciRootBridgeIo
;
439 PciIoDevice
= CreatePciIoDevice (
452 // Create a device path for this PCI device and store it into its private data
454 CreatePciDevicePath (
459 if (gFullEnumeration
) {
460 PciDisableCommandRegister (PciIoDevice
, EFI_PCI_COMMAND_BITS_OWNED
);
463 // Initalize the bridge control register
465 PciDisableBridgeControlRegister (PciIoDevice
, EFI_PCI_BRIDGE_CONTROL_BITS_OWNED
);
470 // PPB can have two BARs
472 if (PciParseBar (PciIoDevice
, 0x10, PPB_BAR_0
) == 0x14) {
476 PciParseBar (PciIoDevice
, 0x14, PPB_BAR_1
);
479 PciIo
= &PciIoDevice
->PciIo
;
482 // Test whether it support 32 decode or not
484 PciIoRead (PciIo
, EfiPciIoWidthUint8
, 0x1C, 1, &Temp
);
485 PciIoWrite (PciIo
, EfiPciIoWidthUint8
, 0x1C, 1, &gAllOne
);
486 PciIoRead (PciIo
, EfiPciIoWidthUint8
, 0x1C, 1, &Value
);
487 PciIoWrite (PciIo
, EfiPciIoWidthUint8
, 0x1C, 1, &Temp
);
491 PciIoDevice
->Decodes
|= EFI_BRIDGE_IO32_DECODE_SUPPORTED
;
493 PciIoDevice
->Decodes
|= EFI_BRIDGE_IO16_DECODE_SUPPORTED
;
497 Status
= BarExisted (
505 // test if it supports 64 memory or not
507 if (!EFI_ERROR (Status
)) {
509 Status
= BarExisted (
516 if (!EFI_ERROR (Status
)) {
517 PciIoDevice
->Decodes
|= EFI_BRIDGE_PMEM32_DECODE_SUPPORTED
;
518 PciIoDevice
->Decodes
|= EFI_BRIDGE_PMEM64_DECODE_SUPPORTED
;
520 PciIoDevice
->Decodes
|= EFI_BRIDGE_PMEM32_DECODE_SUPPORTED
;
525 // Memory 32 code is required for ppb
527 PciIoDevice
->Decodes
|= EFI_BRIDGE_MEM32_DECODE_SUPPORTED
;
529 GetResourcePaddingPpb (PciIoDevice
);
536 IN PCI_IO_DEVICE
*Bridge
,
553 // TODO: Bridge - add argument and description to function comment
554 // TODO: Pci - add argument and description to function comment
555 // TODO: Bus - add argument and description to function comment
556 // TODO: Device - add argument and description to function comment
557 // TODO: Func - add argument and description to function comment
559 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
560 PCI_IO_DEVICE
*PciIoDevice
;
562 PciRootBridgeIo
= Bridge
->PciRootBridgeIo
;
563 PciIoDevice
= CreatePciIoDevice (
576 // Create a device path for this PCI device and store it into its private data
578 CreatePciDevicePath (
583 if (gFullEnumeration
) {
584 PciDisableCommandRegister (PciIoDevice
, EFI_PCI_COMMAND_BITS_OWNED
);
587 // Initalize the bridge control register
589 PciDisableBridgeControlRegister (PciIoDevice
, EFI_PCCARD_BRIDGE_CONTROL_BITS_OWNED
);
593 // P2C only has one bar that is in 0x10
595 PciParseBar (PciIoDevice
, 0x10, P2C_BAR_0
);
598 // Read PciBar information from the bar register
600 GetBackPcCardBar (PciIoDevice
);
601 PciIoDevice
->Decodes
= EFI_BRIDGE_MEM32_DECODE_SUPPORTED
|
602 EFI_BRIDGE_PMEM32_DECODE_SUPPORTED
|
603 EFI_BRIDGE_IO32_DECODE_SUPPORTED
;
608 EFI_DEVICE_PATH_PROTOCOL
*
609 CreatePciDevicePath (
610 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
,
611 IN PCI_IO_DEVICE
*PciIoDevice
624 // TODO: ParentDevicePath - add argument and description to function comment
625 // TODO: PciIoDevice - add argument and description to function comment
628 PCI_DEVICE_PATH PciNode
;
631 // Create PCI device path
633 PciNode
.Header
.Type
= HARDWARE_DEVICE_PATH
;
634 PciNode
.Header
.SubType
= HW_PCI_DP
;
635 SetDevicePathNodeLength (&PciNode
.Header
, sizeof (PciNode
));
637 PciNode
.Device
= PciIoDevice
->DeviceNumber
;
638 PciNode
.Function
= PciIoDevice
->FunctionNumber
;
639 PciIoDevice
->DevicePath
= AppendDevicePathNode (ParentDevicePath
, &PciNode
.Header
);
641 return PciIoDevice
->DevicePath
;
646 IN PCI_IO_DEVICE
*PciIoDevice
,
648 OUT UINT32
*BarLengthValue
,
649 OUT UINT32
*OriginalBarValue
655 Check the bar is existed or not.
659 PciIoDevice - A pointer to the PCI_IO_DEVICE.
661 BarLengthValue - The bar length value.
662 OriginalBarValue - The original bar value.
666 EFI_NOT_FOUND - The bar don't exist.
667 EFI_SUCCESS - The bar exist.
671 EFI_PCI_IO_PROTOCOL
*PciIo
;
672 UINT32 OriginalValue
;
676 PciIo
= &PciIoDevice
->PciIo
;
679 // Preserve the original value
682 PciIoRead (PciIo
, EfiPciIoWidthUint32
, (UINT8
) Offset
, 1, &OriginalValue
);
685 // Raise TPL to high level to disable timer interrupt while the BAR is probed
687 OldTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
689 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, (UINT8
) Offset
, 1, &gAllOne
);
690 PciIoRead (PciIo
, EfiPciIoWidthUint32
, (UINT8
) Offset
, 1, &Value
);
693 // Write back the original value
695 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, (UINT8
) Offset
, 1, &OriginalValue
);
698 // Restore TPL to its original level
700 gBS
->RestoreTPL (OldTpl
);
702 if (BarLengthValue
!= NULL
) {
703 *BarLengthValue
= Value
;
706 if (OriginalBarValue
!= NULL
) {
707 *OriginalBarValue
= OriginalValue
;
711 return EFI_NOT_FOUND
;
718 PciTestSupportedAttribute (
719 IN PCI_IO_DEVICE
*PciIoDevice
,
721 IN UINT16
*BridgeControl
,
722 IN UINT16
*OldCommand
,
723 IN UINT16
*OldBridgeControl
736 // TODO: PciIoDevice - add argument and description to function comment
737 // TODO: Command - add argument and description to function comment
738 // TODO: BridgeControl - add argument and description to function comment
739 // TODO: OldCommand - add argument and description to function comment
740 // TODO: OldBridgeControl - add argument and description to function comment
741 // TODO: EFI_SUCCESS - add return value to function comment
746 // Preserve the original value
748 PciReadCommandRegister (PciIoDevice
, OldCommand
);
751 // Raise TPL to high level to disable timer interrupt while the BAR is probed
753 OldTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
755 PciSetCommandRegister (PciIoDevice
, *Command
);
756 PciReadCommandRegister (PciIoDevice
, Command
);
759 // Write back the original value
761 PciSetCommandRegister (PciIoDevice
, *OldCommand
);
764 // Restore TPL to its original level
766 gBS
->RestoreTPL (OldTpl
);
768 if (IS_PCI_BRIDGE (&PciIoDevice
->Pci
) || IS_CARDBUS_BRIDGE (&PciIoDevice
->Pci
)) {
771 // Preserve the original value
773 PciReadBridgeControlRegister (PciIoDevice
, OldBridgeControl
);
776 // Raise TPL to high level to disable timer interrupt while the BAR is probed
778 OldTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
780 PciSetBridgeControlRegister (PciIoDevice
, *BridgeControl
);
781 PciReadBridgeControlRegister (PciIoDevice
, BridgeControl
);
784 // Write back the original value
786 PciSetBridgeControlRegister (PciIoDevice
, *OldBridgeControl
);
789 // Restore TPL to its original level
791 gBS
->RestoreTPL (OldTpl
);
794 *OldBridgeControl
= 0;
802 PciSetDeviceAttribute (
803 IN PCI_IO_DEVICE
*PciIoDevice
,
805 IN UINT16 BridgeControl
,
811 Set the supported or current attributes of a PCI device
814 PciIoDevice - Structure pointer for PCI device.
815 Command - Command register value.
816 BridgeControl - Bridge control value for PPB or P2C.
817 Option - Make a choice of EFI_SET_SUPPORTS or EFI_SET_ATTRIBUTES.
834 EFI_SUCCESS Always success
843 if (Command
& EFI_PCI_COMMAND_IO_SPACE
) {
844 Attributes
|= EFI_PCI_IO_ATTRIBUTE_IO
;
847 if (Command
& EFI_PCI_COMMAND_MEMORY_SPACE
) {
848 Attributes
|= EFI_PCI_IO_ATTRIBUTE_MEMORY
;
851 if (Command
& EFI_PCI_COMMAND_BUS_MASTER
) {
852 Attributes
|= EFI_PCI_IO_ATTRIBUTE_BUS_MASTER
;
855 if (Command
& EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
) {
856 Attributes
|= EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO
;
859 if (BridgeControl
& EFI_PCI_BRIDGE_CONTROL_ISA
) {
860 Attributes
|= EFI_PCI_IO_ATTRIBUTE_ISA_IO
;
863 if (BridgeControl
& EFI_PCI_BRIDGE_CONTROL_VGA
) {
864 Attributes
|= EFI_PCI_IO_ATTRIBUTE_VGA_IO
;
865 Attributes
|= EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY
;
866 Attributes
|= EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO
;
869 if (BridgeControl
& EFI_PCI_BRIDGE_CONTROL_VGA_16
) {
870 Attributes
|= EFI_PCI_IO_ATTRIBUTE_VGA_IO_16
;
871 Attributes
|= EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16
;
874 if (Option
== EFI_SET_SUPPORTS
) {
876 Attributes
|= EFI_PCI_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE
|
877 EFI_PCI_IO_ATTRIBUTE_MEMORY_CACHED
|
878 EFI_PCI_IO_ATTRIBUTE_MEMORY_DISABLE
|
879 EFI_PCI_IO_ATTRIBUTE_EMBEDDED_DEVICE
|
880 EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM
|
881 EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE
;
883 if (Attributes
& EFI_PCI_IO_ATTRIBUTE_IO
) {
884 Attributes
|= EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO
;
885 Attributes
|= EFI_PCI_IO_ATTRIBUTE_ISA_IO
;
888 if (IS_PCI_BRIDGE (&PciIoDevice
->Pci
) || IS_CARDBUS_BRIDGE (&PciIoDevice
->Pci
)) {
890 // For bridge, it should support IDE attributes
892 Attributes
|= EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO
;
893 Attributes
|= EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO
;
896 if (IS_PCI_IDE (&PciIoDevice
->Pci
)) {
897 Attributes
|= EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO
;
898 Attributes
|= EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO
;
901 if (IS_PCI_VGA (&PciIoDevice
->Pci
)) {
902 Attributes
|= EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY
;
903 Attributes
|= EFI_PCI_IO_ATTRIBUTE_VGA_IO
;
907 PciIoDevice
->Supports
= Attributes
;
908 PciIoDevice
->Supports
&= ( (PciIoDevice
->Parent
->Supports
) | \
909 EFI_PCI_IO_ATTRIBUTE_IO
| EFI_PCI_IO_ATTRIBUTE_MEMORY
| \
910 EFI_PCI_IO_ATTRIBUTE_BUS_MASTER
);
913 PciIoDevice
->Attributes
= Attributes
;
920 GetFastBackToBackSupport (
921 IN PCI_IO_DEVICE
*PciIoDevice
,
928 Determine if the device can support Fast Back to Back attribute
937 // TODO: PciIoDevice - add argument and description to function comment
938 // TODO: StatusIndex - add argument and description to function comment
939 // TODO: EFI_UNSUPPORTED - add return value to function comment
940 // TODO: EFI_SUCCESS - add return value to function comment
941 // TODO: EFI_UNSUPPORTED - add return value to function comment
943 EFI_PCI_IO_PROTOCOL
*PciIo
;
945 UINT32 StatusRegister
;
948 // Read the status register
950 PciIo
= &PciIoDevice
->PciIo
;
951 Status
= PciIoRead (PciIo
, EfiPciIoWidthUint16
, StatusIndex
, 1, &StatusRegister
);
952 if (EFI_ERROR (Status
)) {
953 return EFI_UNSUPPORTED
;
957 // Check the Fast B2B bit
959 if (StatusRegister
& EFI_PCI_FAST_BACK_TO_BACK_CAPABLE
) {
962 return EFI_UNSUPPORTED
;
969 ProcessOptionRomLight (
970 IN PCI_IO_DEVICE
*PciIoDevice
976 Process the option ROM for all the children of the specified parent PCI device.
977 It can only be used after the first full Option ROM process.
986 // TODO: PciIoDevice - add argument and description to function comment
987 // TODO: EFI_SUCCESS - add return value to function comment
990 LIST_ENTRY
*CurrentLink
;
993 // For RootBridge, PPB , P2C, go recursively to traverse all its children
995 CurrentLink
= PciIoDevice
->ChildList
.ForwardLink
;
996 while (CurrentLink
&& CurrentLink
!= &PciIoDevice
->ChildList
) {
998 Temp
= PCI_IO_DEVICE_FROM_LINK (CurrentLink
);
1000 if (!IsListEmpty (&Temp
->ChildList
)) {
1001 ProcessOptionRomLight (Temp
);
1004 PciRomGetImageMapping (Temp
);
1005 CurrentLink
= CurrentLink
->ForwardLink
;
1012 DetermineDeviceAttribute (
1013 IN PCI_IO_DEVICE
*PciIoDevice
1017 Routine Description:
1019 Determine the related attributes of all devices under a Root Bridge
1028 // TODO: PciIoDevice - add argument and description to function comment
1029 // TODO: EFI_SUCCESS - add return value to function comment
1032 UINT16 BridgeControl
;
1034 UINT16 OldBridgeControl
;
1035 BOOLEAN FastB2BSupport
;
1039 EFI_PCI_IO_PROTOCOL *PciIo;
1041 PCI_IO_DEVICE
*Temp
;
1042 LIST_ENTRY
*CurrentLink
;
1046 // For Root Bridge, just copy it by RootBridgeIo proctocol
1047 // so as to keep consistent with the actual attribute
1049 if (!PciIoDevice
->Parent
) {
1050 Status
= PciIoDevice
->PciRootBridgeIo
->GetAttributes (
1051 PciIoDevice
->PciRootBridgeIo
,
1052 &PciIoDevice
->Supports
,
1053 &PciIoDevice
->Attributes
1055 if (EFI_ERROR (Status
)) {
1061 // Set the attributes to be checked for common PCI devices and PPB or P2C
1062 // Since some devices only support part of them, it is better to set the
1063 // attribute according to its command or bridge control register
1065 Command
= EFI_PCI_COMMAND_IO_SPACE
|
1066 EFI_PCI_COMMAND_MEMORY_SPACE
|
1067 EFI_PCI_COMMAND_BUS_MASTER
|
1068 EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
;
1070 BridgeControl
= EFI_PCI_BRIDGE_CONTROL_ISA
| EFI_PCI_BRIDGE_CONTROL_VGA
| EFI_PCI_BRIDGE_CONTROL_VGA_16
;
1073 // Test whether the device can support attributes above
1075 PciTestSupportedAttribute (PciIoDevice
, &Command
, &BridgeControl
, &OldCommand
, &OldBridgeControl
);
1078 // Set the supported attributes for specified PCI device
1080 PciSetDeviceAttribute (PciIoDevice
, Command
, BridgeControl
, EFI_SET_SUPPORTS
);
1083 // Set the current attributes for specified PCI device
1085 PciSetDeviceAttribute (PciIoDevice
, OldCommand
, OldBridgeControl
, EFI_SET_ATTRIBUTES
);
1088 // Enable other supported attributes but not defined in PCI_IO_PROTOCOL
1090 PciEnableCommandRegister (PciIoDevice
, EFI_PCI_COMMAND_MEMORY_WRITE_AND_INVALIDATE
);
1093 // Enable IDE native mode
1096 if (IS_PCI_IDE(&PciIoDevice->Pci)) {
1098 PciIo = &PciIoDevice->PciIo;
1109 // Set native mode if it can be supported
1111 IdePI |= (((IdePI & 0x0F) >> 1) & 0x05);
1125 FastB2BSupport
= TRUE
;
1128 // P2C can not support FB2B on the secondary side
1130 if (IS_CARDBUS_BRIDGE (&PciIoDevice
->Pci
)) {
1131 FastB2BSupport
= FALSE
;
1135 // For RootBridge, PPB , P2C, go recursively to traverse all its children
1137 CurrentLink
= PciIoDevice
->ChildList
.ForwardLink
;
1138 while (CurrentLink
&& CurrentLink
!= &PciIoDevice
->ChildList
) {
1140 Temp
= PCI_IO_DEVICE_FROM_LINK (CurrentLink
);
1141 Status
= DetermineDeviceAttribute (Temp
);
1142 if (EFI_ERROR (Status
)) {
1146 // Detect Fast Bact to Bact support for the device under the bridge
1148 Status
= GetFastBackToBackSupport (Temp
, PCI_PRIMARY_STATUS_OFFSET
);
1149 if (FastB2BSupport
&& EFI_ERROR (Status
)) {
1150 FastB2BSupport
= FALSE
;
1153 CurrentLink
= CurrentLink
->ForwardLink
;
1156 // Set or clear Fast Back to Back bit for the whole bridge
1158 if (!IsListEmpty (&PciIoDevice
->ChildList
)) {
1160 if (IS_PCI_BRIDGE (&PciIoDevice
->Pci
)) {
1162 Status
= GetFastBackToBackSupport (PciIoDevice
, PCI_BRIDGE_STATUS_REGISTER_OFFSET
);
1164 if (EFI_ERROR (Status
) || (!FastB2BSupport
)) {
1165 FastB2BSupport
= FALSE
;
1166 PciDisableBridgeControlRegister (PciIoDevice
, EFI_PCI_BRIDGE_CONTROL_FAST_BACK_TO_BACK
);
1168 PciEnableBridgeControlRegister (PciIoDevice
, EFI_PCI_BRIDGE_CONTROL_FAST_BACK_TO_BACK
);
1172 CurrentLink
= PciIoDevice
->ChildList
.ForwardLink
;
1173 while (CurrentLink
&& CurrentLink
!= &PciIoDevice
->ChildList
) {
1174 Temp
= PCI_IO_DEVICE_FROM_LINK (CurrentLink
);
1175 if (FastB2BSupport
) {
1176 PciEnableCommandRegister (Temp
, EFI_PCI_COMMAND_FAST_BACK_TO_BACK
);
1178 PciDisableCommandRegister (Temp
, EFI_PCI_COMMAND_FAST_BACK_TO_BACK
);
1181 CurrentLink
= CurrentLink
->ForwardLink
;
1185 // End for IsListEmpty
1192 IN PCI_IO_DEVICE
*PciIoDevice
1196 Routine Description:
1198 This routine is used to update the bar information for those incompatible PCI device
1207 // TODO: PciIoDevice - add argument and description to function comment
1208 // TODO: EFI_UNSUPPORTED - add return value to function comment
1214 EFI_PCI_DEVICE_INFO PciDeviceInfo
;
1215 VOID
*Configuration
;
1216 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Ptr
;
1218 Configuration
= NULL
;
1221 // Check whether the device belongs to incompatible devices or not
1222 // If it is , then get its special requirement in the ACPI table
1224 PciDeviceInfo
.VendorID
= PciIoDevice
->Pci
.Hdr
.VendorId
;
1225 PciDeviceInfo
.DeviceID
= PciIoDevice
->Pci
.Hdr
.DeviceId
;
1226 PciDeviceInfo
.RevisionID
= PciIoDevice
->Pci
.Hdr
.RevisionID
;
1227 PciDeviceInfo
.SubsystemVendorID
= PciIoDevice
->Pci
.Device
.SubsystemVendorID
;
1228 PciDeviceInfo
.SubsystemID
= PciIoDevice
->Pci
.Device
.SubsystemID
;
1230 Status
= PciResourceUpdateCheck (&PciDeviceInfo
, &Configuration
);
1232 if (EFI_ERROR (Status
)) {
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 gBS
->FreePool (Configuration
);
1316 IN UINT64
*Alignment
,
1317 IN UINT64 NewAlignment
1321 Routine Description:
1323 This routine will update the alignment with the new alignment
1332 // TODO: Alignment - add argument and description to function comment
1333 // TODO: NewAlignment - add argument and description to function comment
1335 UINT64 OldAlignment
;
1339 // The new alignment is the same as the original,
1342 if (NewAlignment
== PCI_BAR_OLD_ALIGN
) {
1346 // Check the validity of the parameter
1348 if (NewAlignment
!= PCI_BAR_EVEN_ALIGN
&&
1349 NewAlignment
!= PCI_BAR_SQUAD_ALIGN
&&
1350 NewAlignment
!= PCI_BAR_DQUAD_ALIGN
) {
1351 *Alignment
= NewAlignment
;
1355 OldAlignment
= (*Alignment
) + 1;
1359 // Get the first non-zero hex value of the length
1361 while ((OldAlignment
& 0x0F) == 0x00) {
1362 OldAlignment
= RShiftU64 (OldAlignment
, 4);
1367 // Adjust the alignment to even, quad or double quad boundary
1369 if (NewAlignment
== PCI_BAR_EVEN_ALIGN
) {
1370 if (OldAlignment
& 0x01) {
1371 OldAlignment
= OldAlignment
+ 2 - (OldAlignment
& 0x01);
1373 } else if (NewAlignment
== PCI_BAR_SQUAD_ALIGN
) {
1374 if (OldAlignment
& 0x03) {
1375 OldAlignment
= OldAlignment
+ 4 - (OldAlignment
& 0x03);
1377 } else if (NewAlignment
== PCI_BAR_DQUAD_ALIGN
) {
1378 if (OldAlignment
& 0x07) {
1379 OldAlignment
= OldAlignment
+ 8 - (OldAlignment
& 0x07);
1384 // Update the old value
1386 NewAlignment
= LShiftU64 (OldAlignment
, ShiftBit
) - 1;
1387 *Alignment
= NewAlignment
;
1394 IN PCI_IO_DEVICE
*PciIoDevice
,
1400 Routine Description:
1409 // TODO: PciIoDevice - add argument and description to function comment
1410 // TODO: Offset - add argument and description to function comment
1411 // TODO: BarIndex - add argument and description to function comment
1414 UINT32 OriginalValue
;
1423 Status
= BarExisted (
1430 if (EFI_ERROR (Status
)) {
1431 PciIoDevice
->PciBar
[BarIndex
].BaseAddress
= 0;
1432 PciIoDevice
->PciBar
[BarIndex
].Length
= 0;
1433 PciIoDevice
->PciBar
[BarIndex
].Alignment
= 0;
1436 // Some devices don't fully comply to PCI spec 2.2. So be to scan all the BARs anyway
1438 PciIoDevice
->PciBar
[BarIndex
].Offset
= (UINT8
) Offset
;
1442 PciIoDevice
->PciBar
[BarIndex
].Offset
= (UINT8
) Offset
;
1449 if (Value
& 0xFFFF0000) {
1453 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypeIo32
;
1454 PciIoDevice
->PciBar
[BarIndex
].Length
= ((~(Value
& Mask
)) + 1);
1455 PciIoDevice
->PciBar
[BarIndex
].Alignment
= PciIoDevice
->PciBar
[BarIndex
].Length
- 1;
1461 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypeIo16
;
1462 PciIoDevice
->PciBar
[BarIndex
].Length
= 0x0000FFFF & ((~(Value
& Mask
)) + 1);
1463 PciIoDevice
->PciBar
[BarIndex
].Alignment
= PciIoDevice
->PciBar
[BarIndex
].Length
- 1;
1467 // Workaround. Some platforms inplement IO bar with 0 length
1468 // Need to treat it as no-bar
1470 if (PciIoDevice
->PciBar
[BarIndex
].Length
== 0) {
1471 PciIoDevice
->PciBar
[BarIndex
].BarType
= (PCI_BAR_TYPE
) 0;
1474 PciIoDevice
->PciBar
[BarIndex
].Prefetchable
= FALSE
;
1475 PciIoDevice
->PciBar
[BarIndex
].BaseAddress
= OriginalValue
& Mask
;
1481 PciIoDevice
->PciBar
[BarIndex
].BaseAddress
= OriginalValue
& Mask
;
1483 switch (Value
& 0x07) {
1486 //memory space; anywhere in 32 bit address space
1490 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypePMem32
;
1492 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypeMem32
;
1495 PciIoDevice
->PciBar
[BarIndex
].Length
= (~(Value
& Mask
)) + 1;
1496 PciIoDevice
->PciBar
[BarIndex
].Alignment
= PciIoDevice
->PciBar
[BarIndex
].Length
- 1;
1501 // memory space; anywhere in 64 bit address space
1505 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypePMem64
;
1507 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypeMem64
;
1511 // According to PCI 2.2,if the bar indicates a memory 64 decoding, next bar
1512 // is regarded as an extension for the first bar. As a result
1513 // the sizing will be conducted on combined 64 bit value
1514 // Here just store the masked first 32bit value for future size
1517 PciIoDevice
->PciBar
[BarIndex
].Length
= Value
& Mask
;
1518 PciIoDevice
->PciBar
[BarIndex
].Alignment
= PciIoDevice
->PciBar
[BarIndex
].Length
- 1;
1521 // Increment the offset to point to next DWORD
1525 Status
= BarExisted (
1532 if (EFI_ERROR (Status
)) {
1537 // Fix the length to support some spefic 64 bit BAR
1541 for (Data
= Value
; Data
!= 0; Data
>>= 1) {
1544 Value
|= ((UINT32
)(-1) << Index
);
1547 // Calculate the size of 64bit bar
1549 PciIoDevice
->PciBar
[BarIndex
].BaseAddress
|= LShiftU64 ((UINT64
) OriginalValue
, 32);
1551 PciIoDevice
->PciBar
[BarIndex
].Length
= PciIoDevice
->PciBar
[BarIndex
].Length
| LShiftU64 ((UINT64
) Value
, 32);
1552 PciIoDevice
->PciBar
[BarIndex
].Length
= (~(PciIoDevice
->PciBar
[BarIndex
].Length
)) + 1;
1553 PciIoDevice
->PciBar
[BarIndex
].Alignment
= PciIoDevice
->PciBar
[BarIndex
].Length
- 1;
1561 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypeUnknown
;
1562 PciIoDevice
->PciBar
[BarIndex
].Length
= (~(Value
& Mask
)) + 1;
1563 PciIoDevice
->PciBar
[BarIndex
].Alignment
= PciIoDevice
->PciBar
[BarIndex
].Length
- 1;
1570 // Check the length again so as to keep compatible with some special bars
1572 if (PciIoDevice
->PciBar
[BarIndex
].Length
== 0) {
1573 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypeUnknown
;
1574 PciIoDevice
->PciBar
[BarIndex
].BaseAddress
= 0;
1575 PciIoDevice
->PciBar
[BarIndex
].Alignment
= 0;
1579 // Increment number of bar
1585 InitializePciDevice (
1586 IN PCI_IO_DEVICE
*PciIoDevice
1590 Routine Description:
1592 This routine is used to initialize the bar of a PCI device
1593 It can be called typically when a device is going to be rejected
1602 // TODO: PciIoDevice - add argument and description to function comment
1603 // TODO: EFI_SUCCESS - add return value to function comment
1605 EFI_PCI_IO_PROTOCOL
*PciIo
;
1608 PciIo
= &(PciIoDevice
->PciIo
);
1611 // Put all the resource apertures
1612 // Resource base is set to all ones so as to indicate its resource
1613 // has not been alloacted
1615 for (Offset
= 0x10; Offset
<= 0x24; Offset
+= sizeof (UINT32
)) {
1616 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, Offset
, 1, &gAllOne
);
1624 IN PCI_IO_DEVICE
*PciIoDevice
1628 Routine Description:
1637 // TODO: PciIoDevice - add argument and description to function comment
1638 // TODO: EFI_SUCCESS - add return value to function comment
1640 EFI_PCI_IO_PROTOCOL
*PciIo
;
1642 PciIo
= &(PciIoDevice
->PciIo
);
1645 // Put all the resource apertures including IO16
1646 // Io32, pMem32, pMem64 to quiescent state
1647 // Resource base all ones, Resource limit all zeros
1649 PciIoWrite (PciIo
, EfiPciIoWidthUint8
, 0x1C, 1, &gAllOne
);
1650 PciIoWrite (PciIo
, EfiPciIoWidthUint8
, 0x1D, 1, &gAllZero
);
1652 PciIoWrite (PciIo
, EfiPciIoWidthUint16
, 0x20, 1, &gAllOne
);
1653 PciIoWrite (PciIo
, EfiPciIoWidthUint16
, 0x22, 1, &gAllZero
);
1655 PciIoWrite (PciIo
, EfiPciIoWidthUint16
, 0x24, 1, &gAllOne
);
1656 PciIoWrite (PciIo
, EfiPciIoWidthUint16
, 0x26, 1, &gAllZero
);
1658 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x28, 1, &gAllOne
);
1659 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x2C, 1, &gAllZero
);
1662 // don't support use io32 as for now
1664 PciIoWrite (PciIo
, EfiPciIoWidthUint16
, 0x30, 1, &gAllOne
);
1665 PciIoWrite (PciIo
, EfiPciIoWidthUint16
, 0x32, 1, &gAllZero
);
1668 // Force Interrupt line to zero for cards that come up randomly
1670 PciIoWrite (PciIo
, EfiPciIoWidthUint8
, 0x3C, 1, &gAllZero
);
1677 IN PCI_IO_DEVICE
*PciIoDevice
1681 Routine Description:
1690 // TODO: PciIoDevice - add argument and description to function comment
1691 // TODO: EFI_SUCCESS - add return value to function comment
1693 EFI_PCI_IO_PROTOCOL
*PciIo
;
1695 PciIo
= &(PciIoDevice
->PciIo
);
1698 // Put all the resource apertures including IO16
1699 // Io32, pMem32, pMem64 to quiescent state(
1700 // Resource base all ones, Resource limit all zeros
1702 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x1c, 1, &gAllOne
);
1703 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x20, 1, &gAllZero
);
1705 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x24, 1, &gAllOne
);
1706 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x28, 1, &gAllZero
);
1708 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x2c, 1, &gAllOne
);
1709 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x30, 1, &gAllZero
);
1711 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x34, 1, &gAllOne
);
1712 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x38, 1, &gAllZero
);
1715 // Force Interrupt line to zero for cards that come up randomly
1717 PciIoWrite (PciIo
, EfiPciIoWidthUint8
, 0x3C, 1, &gAllZero
);
1723 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
,
1731 Routine Description:
1740 // TODO: PciRootBridgeIo - add argument and description to function comment
1741 // TODO: Pci - add argument and description to function comment
1742 // TODO: Bus - add argument and description to function comment
1743 // TODO: Device - add argument and description to function comment
1744 // TODO: Func - add argument and description to function comment
1748 PCI_IO_DEVICE
*PciIoDevice
;
1752 Status
= gBS
->AllocatePool (
1753 EfiBootServicesData
,
1754 sizeof (PCI_IO_DEVICE
),
1755 (VOID
**) &PciIoDevice
1758 if (EFI_ERROR (Status
)) {
1762 ZeroMem (PciIoDevice
, sizeof (PCI_IO_DEVICE
));
1764 PciIoDevice
->Signature
= PCI_IO_DEVICE_SIGNATURE
;
1765 PciIoDevice
->Handle
= NULL
;
1766 PciIoDevice
->PciRootBridgeIo
= PciRootBridgeIo
;
1767 PciIoDevice
->DevicePath
= NULL
;
1768 PciIoDevice
->BusNumber
= Bus
;
1769 PciIoDevice
->DeviceNumber
= Device
;
1770 PciIoDevice
->FunctionNumber
= Func
;
1771 PciIoDevice
->Decodes
= 0;
1772 if (gFullEnumeration
) {
1773 PciIoDevice
->Allocated
= FALSE
;
1775 PciIoDevice
->Allocated
= TRUE
;
1778 PciIoDevice
->Registered
= FALSE
;
1779 PciIoDevice
->Attributes
= 0;
1780 PciIoDevice
->Supports
= 0;
1781 PciIoDevice
->BusOverride
= FALSE
;
1782 PciIoDevice
->AllOpRomProcessed
= FALSE
;
1784 PciIoDevice
->IsPciExp
= FALSE
;
1786 CopyMem (&(PciIoDevice
->Pci
), Pci
, sizeof (PCI_TYPE01
));
1789 // Initialize the PCI I/O instance structure
1792 Status
= InitializePciIoInstance (PciIoDevice
);
1793 Status
= InitializePciDriverOverrideInstance (PciIoDevice
);
1795 if (EFI_ERROR (Status
)) {
1796 gBS
->FreePool (PciIoDevice
);
1801 // Initialize the reserved resource list
1803 InitializeListHead (&PciIoDevice
->ReservedResourceList
);
1806 // Initialize the driver list
1808 InitializeListHead (&PciIoDevice
->OptionRomDriverList
);
1811 // Initialize the child list
1813 InitializeListHead (&PciIoDevice
->ChildList
);
1819 PciEnumeratorLight (
1820 IN EFI_HANDLE Controller
1824 Routine Description:
1826 This routine is used to enumerate entire pci bus system
1836 // TODO: Controller - add argument and description to function comment
1837 // TODO: EFI_SUCCESS - add return value to function comment
1838 // TODO: EFI_SUCCESS - add return value to function comment
1842 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
1843 PCI_IO_DEVICE
*RootBridgeDev
;
1846 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Descriptors
;
1849 MaxBus
= PCI_MAX_BUS
;
1853 // If this host bridge has been already enumerated, then return successfully
1855 if (RootBridgeExisted (Controller
)) {
1860 // Open pci root bridge io protocol
1862 Status
= gBS
->OpenProtocol (
1864 &gEfiPciRootBridgeIoProtocolGuid
,
1865 (VOID
**) &PciRootBridgeIo
,
1866 gPciBusDriverBinding
.DriverBindingHandle
,
1868 EFI_OPEN_PROTOCOL_BY_DRIVER
1870 if (EFI_ERROR (Status
) && Status
!= EFI_ALREADY_STARTED
) {
1874 Status
= PciRootBridgeIo
->Configuration (PciRootBridgeIo
, (VOID
**) &Descriptors
);
1876 if (EFI_ERROR (Status
)) {
1880 while (PciGetBusRange (&Descriptors
, &MinBus
, &MaxBus
, NULL
) == EFI_SUCCESS
) {
1883 // Create a device node for root bridge device with a NULL host bridge controller handle
1885 RootBridgeDev
= CreateRootBridge (Controller
);
1887 if (!RootBridgeDev
) {
1893 // Record the root bridge io protocol
1895 RootBridgeDev
->PciRootBridgeIo
= PciRootBridgeIo
;
1897 Status
= PciPciDeviceInfoCollector (
1902 if (!EFI_ERROR (Status
)) {
1905 // Remove those PCI devices which are rejected when full enumeration
1907 RemoveRejectedPciDevices (RootBridgeDev
->Handle
, RootBridgeDev
);
1910 // Process option rom light
1912 ProcessOptionRomLight (RootBridgeDev
);
1915 // Determine attributes for all devices under this root bridge
1917 DetermineDeviceAttribute (RootBridgeDev
);
1920 // If successfully, insert the node into device pool
1922 InsertRootBridge (RootBridgeDev
);
1926 // If unsuccessly, destroy the entire node
1928 DestroyRootBridge (RootBridgeDev
);
1939 IN EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
**Descriptors
,
1942 OUT UINT16
*BusRange
1946 Routine Description:
1952 Descriptors - A pointer to the address space descriptor.
1953 MinBus - The min bus.
1954 MaxBus - The max bus.
1955 BusRange - The bus range.
1962 // TODO: EFI_SUCCESS - add return value to function comment
1963 // TODO: EFI_NOT_FOUND - add return value to function comment
1966 while ((*Descriptors
)->Desc
!= ACPI_END_TAG_DESCRIPTOR
) {
1967 if ((*Descriptors
)->ResType
== ACPI_ADDRESS_SPACE_TYPE_BUS
) {
1968 if (MinBus
!= NULL
) {
1969 *MinBus
= (UINT16
) (*Descriptors
)->AddrRangeMin
;
1972 if (MaxBus
!= NULL
) {
1973 *MaxBus
= (UINT16
) (*Descriptors
)->AddrRangeMax
;
1976 if (BusRange
!= NULL
) {
1977 *BusRange
= (UINT16
) (*Descriptors
)->AddrLen
;
1986 return EFI_NOT_FOUND
;
1990 StartManagingRootBridge (
1991 IN PCI_IO_DEVICE
*RootBridgeDev
1995 Routine Description:
2005 // TODO: RootBridgeDev - add argument and description to function comment
2006 // TODO: EFI_SUCCESS - add return value to function comment
2008 EFI_HANDLE RootBridgeHandle
;
2010 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
2013 // Get the root bridge handle
2015 RootBridgeHandle
= RootBridgeDev
->Handle
;
2016 PciRootBridgeIo
= NULL
;
2019 // Get the pci root bridge io protocol
2021 Status
= gBS
->OpenProtocol (
2023 &gEfiPciRootBridgeIoProtocolGuid
,
2024 (VOID
**) &PciRootBridgeIo
,
2025 gPciBusDriverBinding
.DriverBindingHandle
,
2027 EFI_OPEN_PROTOCOL_BY_DRIVER
2030 if (EFI_ERROR (Status
) && Status
!= EFI_ALREADY_STARTED
) {
2035 // Store the PciRootBridgeIo protocol into root bridge private data
2037 RootBridgeDev
->PciRootBridgeIo
= PciRootBridgeIo
;
2044 IsPciDeviceRejected (
2045 IN PCI_IO_DEVICE
*PciIoDevice
2049 Routine Description:
2051 This routine can be used to check whether a PCI device should be rejected when light enumeration
2057 TRUE This device should be rejected
2058 FALSE This device shouldn't be rejected
2061 // TODO: PciIoDevice - add argument and description to function comment
2070 // PPB should be skip!
2072 if (IS_PCI_BRIDGE (&PciIoDevice
->Pci
)) {
2076 if (IS_CARDBUS_BRIDGE (&PciIoDevice
->Pci
)) {
2078 // Only test base registers for P2C
2080 for (BarOffset
= 0x1C; BarOffset
<= 0x38; BarOffset
+= 2 * sizeof (UINT32
)) {
2082 Mask
= (BarOffset
< 0x2C) ? 0xFFFFF000 : 0xFFFFFFFC;
2083 Status
= BarExisted (PciIoDevice
, BarOffset
, &TestValue
, &OldValue
);
2084 if (EFI_ERROR (Status
)) {
2088 TestValue
= TestValue
& Mask
;
2089 if ((TestValue
!= 0) && (TestValue
== (OldValue
& Mask
))) {
2091 // The bar isn't programed, so it should be rejected
2100 for (BarOffset
= 0x14; BarOffset
<= 0x24; BarOffset
+= sizeof (UINT32
)) {
2104 Status
= BarExisted (PciIoDevice
, BarOffset
, &TestValue
, &OldValue
);
2105 if (EFI_ERROR (Status
)) {
2109 if (TestValue
& 0x01) {
2116 TestValue
= TestValue
& Mask
;
2117 if ((TestValue
!= 0) && (TestValue
== (OldValue
& Mask
))) {
2128 TestValue
= TestValue
& Mask
;
2130 if ((TestValue
& 0x07) == 0x04) {
2135 BarOffset
+= sizeof (UINT32
);
2136 if ((TestValue
!= 0) && (TestValue
== (OldValue
& Mask
))) {
2139 // Test its high 32-Bit BAR
2142 Status
= BarExisted (PciIoDevice
, BarOffset
, &TestValue
, &OldValue
);
2143 if (TestValue
== OldValue
) {
2153 if ((TestValue
!= 0) && (TestValue
== (OldValue
& Mask
))) {
2164 ResetAllPpbBusNumber (
2165 IN PCI_IO_DEVICE
*Bridge
,
2166 IN UINT8 StartBusNumber
2170 Routine Description:
2172 TODO: Add function description
2176 Bridge - TODO: add argument description
2177 StartBusNumber - TODO: add argument description
2181 EFI_SUCCESS - TODO: Add description for return value
2192 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
2194 PciRootBridgeIo
= Bridge
->PciRootBridgeIo
;
2196 for (Device
= 0; Device
<= PCI_MAX_DEVICE
; Device
++) {
2197 for (Func
= 0; Func
<= PCI_MAX_FUNC
; Func
++) {
2200 // Check to see whether a pci device is present
2202 Status
= PciDevicePresent (
2210 if (!EFI_ERROR (Status
) && (IS_PCI_BRIDGE (&Pci
))) {
2213 Address
= EFI_PCI_ADDRESS (StartBusNumber
, Device
, Func
, 0x18);
2214 Status
= PciRootBridgeIoRead (
2222 SecondaryBus
= (UINT8
)(Register
>> 8);
2224 if (SecondaryBus
!= 0) {
2225 ResetAllPpbBusNumber (Bridge
, SecondaryBus
);
2229 // Reset register 18h, 19h, 1Ah on PCI Bridge
2231 Register
&= 0xFF000000;
2232 Status
= PciRootBridgeIoWrite (
2242 if (Func
== 0 && !IS_PCI_MULTI_FUNC (&Pci
)) {
2244 // Skip sub functions, this is not a multi function device
2246 Func
= PCI_MAX_FUNC
;