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 UpdatePciInfo (PciIoDevice
);
299 if (PciIoDevice
->DevicePath
== NULL
) {
300 return EFI_OUT_OF_RESOURCES
;
304 // Detect this function has option rom
306 if (gFullEnumeration
) {
308 if (!IS_CARDBUS_BRIDGE (Pci
)) {
310 GetOpRomInfo (PciIoDevice
);
314 ResetPowerManagementFeature (PciIoDevice
);
319 // Insert it into a global tree for future reference
321 InsertPciDevice (Bridge
, PciIoDevice
);
324 // Determine PCI device attributes
327 if (PciDevice
!= NULL
) {
328 *PciDevice
= PciIoDevice
;
336 IN PCI_IO_DEVICE
*Bridge
,
353 // TODO: Bridge - add argument and description to function comment
354 // TODO: Pci - add argument and description to function comment
355 // TODO: Bus - add argument and description to function comment
356 // TODO: Device - add argument and description to function comment
357 // TODO: Func - add argument and description to function comment
361 PCI_IO_DEVICE
*PciIoDevice
;
362 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
364 PciRootBridgeIo
= Bridge
->PciRootBridgeIo
;
365 PciIoDevice
= CreatePciIoDevice (
378 // Create a device path for this PCI device and store it into its private data
380 CreatePciDevicePath (
386 // If it is a full enumeration, disconnect the device in advance
388 if (gFullEnumeration
) {
390 PciDisableCommandRegister (PciIoDevice
, EFI_PCI_COMMAND_BITS_OWNED
);
395 // Start to parse the bars
397 for (Offset
= 0x10, BarIndex
= 0; Offset
<= 0x24; BarIndex
++) {
398 Offset
= PciParseBar (PciIoDevice
, Offset
, BarIndex
);
406 IN PCI_IO_DEVICE
*Bridge
,
423 // TODO: Bridge - add argument and description to function comment
424 // TODO: Pci - add argument and description to function comment
425 // TODO: Bus - add argument and description to function comment
426 // TODO: Device - add argument and description to function comment
427 // TODO: Func - add argument and description to function comment
429 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
430 PCI_IO_DEVICE
*PciIoDevice
;
433 EFI_PCI_IO_PROTOCOL
*PciIo
;
436 PciRootBridgeIo
= Bridge
->PciRootBridgeIo
;
437 PciIoDevice
= CreatePciIoDevice (
450 // Create a device path for this PCI device and store it into its private data
452 CreatePciDevicePath (
457 if (gFullEnumeration
) {
458 PciDisableCommandRegister (PciIoDevice
, EFI_PCI_COMMAND_BITS_OWNED
);
461 // Initalize the bridge control register
463 PciDisableBridgeControlRegister (PciIoDevice
, EFI_PCI_BRIDGE_CONTROL_BITS_OWNED
);
468 // PPB can have two BARs
470 if (PciParseBar (PciIoDevice
, 0x10, PPB_BAR_0
) == 0x14) {
474 PciParseBar (PciIoDevice
, 0x14, PPB_BAR_1
);
477 PciIo
= &PciIoDevice
->PciIo
;
480 // Test whether it support 32 decode or not
482 PciIoRead (PciIo
, EfiPciIoWidthUint8
, 0x1C, 1, &Temp
);
483 PciIoWrite (PciIo
, EfiPciIoWidthUint8
, 0x1C, 1, &gAllOne
);
484 PciIoRead (PciIo
, EfiPciIoWidthUint8
, 0x1C, 1, &Value
);
485 PciIoWrite (PciIo
, EfiPciIoWidthUint8
, 0x1C, 1, &Temp
);
489 PciIoDevice
->Decodes
|= EFI_BRIDGE_IO32_DECODE_SUPPORTED
;
491 PciIoDevice
->Decodes
|= EFI_BRIDGE_IO16_DECODE_SUPPORTED
;
495 Status
= BarExisted (
503 // test if it supports 64 memory or not
505 if (!EFI_ERROR (Status
)) {
507 Status
= BarExisted (
514 if (!EFI_ERROR (Status
)) {
515 PciIoDevice
->Decodes
|= EFI_BRIDGE_PMEM32_DECODE_SUPPORTED
;
516 PciIoDevice
->Decodes
|= EFI_BRIDGE_PMEM64_DECODE_SUPPORTED
;
518 PciIoDevice
->Decodes
|= EFI_BRIDGE_PMEM32_DECODE_SUPPORTED
;
523 // Memory 32 code is required for ppb
525 PciIoDevice
->Decodes
|= EFI_BRIDGE_MEM32_DECODE_SUPPORTED
;
527 GetResourcePaddingPpb (PciIoDevice
);
534 IN PCI_IO_DEVICE
*Bridge
,
551 // TODO: Bridge - add argument and description to function comment
552 // TODO: Pci - add argument and description to function comment
553 // TODO: Bus - add argument and description to function comment
554 // TODO: Device - add argument and description to function comment
555 // TODO: Func - add argument and description to function comment
557 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
558 PCI_IO_DEVICE
*PciIoDevice
;
560 PciRootBridgeIo
= Bridge
->PciRootBridgeIo
;
561 PciIoDevice
= CreatePciIoDevice (
574 // Create a device path for this PCI device and store it into its private data
576 CreatePciDevicePath (
581 if (gFullEnumeration
) {
582 PciDisableCommandRegister (PciIoDevice
, EFI_PCI_COMMAND_BITS_OWNED
);
585 // Initalize the bridge control register
587 PciDisableBridgeControlRegister (PciIoDevice
, EFI_PCCARD_BRIDGE_CONTROL_BITS_OWNED
);
591 // P2C only has one bar that is in 0x10
593 PciParseBar (PciIoDevice
, 0x10, P2C_BAR_0
);
596 // Read PciBar information from the bar register
598 GetBackPcCardBar (PciIoDevice
);
599 PciIoDevice
->Decodes
= EFI_BRIDGE_MEM32_DECODE_SUPPORTED
|
600 EFI_BRIDGE_PMEM32_DECODE_SUPPORTED
|
601 EFI_BRIDGE_IO32_DECODE_SUPPORTED
;
606 EFI_DEVICE_PATH_PROTOCOL
*
607 CreatePciDevicePath (
608 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
,
609 IN PCI_IO_DEVICE
*PciIoDevice
622 // TODO: ParentDevicePath - add argument and description to function comment
623 // TODO: PciIoDevice - add argument and description to function comment
626 PCI_DEVICE_PATH PciNode
;
629 // Create PCI device path
631 PciNode
.Header
.Type
= HARDWARE_DEVICE_PATH
;
632 PciNode
.Header
.SubType
= HW_PCI_DP
;
633 SetDevicePathNodeLength (&PciNode
.Header
, sizeof (PciNode
));
635 PciNode
.Device
= PciIoDevice
->DeviceNumber
;
636 PciNode
.Function
= PciIoDevice
->FunctionNumber
;
637 PciIoDevice
->DevicePath
= AppendDevicePathNode (ParentDevicePath
, &PciNode
.Header
);
639 return PciIoDevice
->DevicePath
;
644 IN PCI_IO_DEVICE
*PciIoDevice
,
646 OUT UINT32
*BarLengthValue
,
647 OUT UINT32
*OriginalBarValue
653 Check the bar is existed or not.
657 PciIoDevice - A pointer to the PCI_IO_DEVICE.
659 BarLengthValue - The bar length value.
660 OriginalBarValue - The original bar value.
664 EFI_NOT_FOUND - The bar don't exist.
665 EFI_SUCCESS - The bar exist.
669 EFI_PCI_IO_PROTOCOL
*PciIo
;
670 UINT32 OriginalValue
;
674 PciIo
= &PciIoDevice
->PciIo
;
677 // Preserve the original value
680 PciIoRead (PciIo
, EfiPciIoWidthUint32
, (UINT8
) Offset
, 1, &OriginalValue
);
683 // Raise TPL to high level to disable timer interrupt while the BAR is probed
685 OldTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
687 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, (UINT8
) Offset
, 1, &gAllOne
);
688 PciIoRead (PciIo
, EfiPciIoWidthUint32
, (UINT8
) Offset
, 1, &Value
);
691 // Write back the original value
693 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, (UINT8
) Offset
, 1, &OriginalValue
);
696 // Restore TPL to its original level
698 gBS
->RestoreTPL (OldTpl
);
700 if (BarLengthValue
!= NULL
) {
701 *BarLengthValue
= Value
;
704 if (OriginalBarValue
!= NULL
) {
705 *OriginalBarValue
= OriginalValue
;
709 return EFI_NOT_FOUND
;
716 PciTestSupportedAttribute (
717 IN PCI_IO_DEVICE
*PciIoDevice
,
719 IN UINT16
*BridgeControl
,
720 IN UINT16
*OldCommand
,
721 IN UINT16
*OldBridgeControl
734 // TODO: PciIoDevice - add argument and description to function comment
735 // TODO: Command - add argument and description to function comment
736 // TODO: BridgeControl - add argument and description to function comment
737 // TODO: OldCommand - add argument and description to function comment
738 // TODO: OldBridgeControl - add argument and description to function comment
739 // TODO: EFI_SUCCESS - add return value to function comment
744 // Preserve the original value
746 PciReadCommandRegister (PciIoDevice
, OldCommand
);
749 // Raise TPL to high level to disable timer interrupt while the BAR is probed
751 OldTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
753 PciSetCommandRegister (PciIoDevice
, *Command
);
754 PciReadCommandRegister (PciIoDevice
, Command
);
757 // Write back the original value
759 PciSetCommandRegister (PciIoDevice
, *OldCommand
);
762 // Restore TPL to its original level
764 gBS
->RestoreTPL (OldTpl
);
766 if (IS_PCI_BRIDGE (&PciIoDevice
->Pci
) || IS_CARDBUS_BRIDGE (&PciIoDevice
->Pci
)) {
769 // Preserve the original value
771 PciReadBridgeControlRegister (PciIoDevice
, OldBridgeControl
);
774 // Raise TPL to high level to disable timer interrupt while the BAR is probed
776 OldTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
778 PciSetBridgeControlRegister (PciIoDevice
, *BridgeControl
);
779 PciReadBridgeControlRegister (PciIoDevice
, BridgeControl
);
782 // Write back the original value
784 PciSetBridgeControlRegister (PciIoDevice
, *OldBridgeControl
);
787 // Restore TPL to its original level
789 gBS
->RestoreTPL (OldTpl
);
792 *OldBridgeControl
= 0;
800 PciSetDeviceAttribute (
801 IN PCI_IO_DEVICE
*PciIoDevice
,
803 IN UINT16 BridgeControl
,
809 Set the supported or current attributes of a PCI device
812 PciIoDevice - Structure pointer for PCI device.
813 Command - Command register value.
814 BridgeControl - Bridge control value for PPB or P2C.
815 Option - Make a choice of EFI_SET_SUPPORTS or EFI_SET_ATTRIBUTES.
832 EFI_SUCCESS Always success
841 if (Command
& EFI_PCI_COMMAND_IO_SPACE
) {
842 Attributes
|= EFI_PCI_IO_ATTRIBUTE_IO
;
845 if (Command
& EFI_PCI_COMMAND_MEMORY_SPACE
) {
846 Attributes
|= EFI_PCI_IO_ATTRIBUTE_MEMORY
;
849 if (Command
& EFI_PCI_COMMAND_BUS_MASTER
) {
850 Attributes
|= EFI_PCI_IO_ATTRIBUTE_BUS_MASTER
;
853 if (Command
& EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
) {
854 Attributes
|= EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO
;
857 if (BridgeControl
& EFI_PCI_BRIDGE_CONTROL_ISA
) {
858 Attributes
|= EFI_PCI_IO_ATTRIBUTE_ISA_IO
;
861 if (BridgeControl
& EFI_PCI_BRIDGE_CONTROL_VGA
) {
862 Attributes
|= EFI_PCI_IO_ATTRIBUTE_VGA_IO
;
863 Attributes
|= EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY
;
864 Attributes
|= EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO
;
867 if (BridgeControl
& EFI_PCI_BRIDGE_CONTROL_VGA_16
) {
868 Attributes
|= EFI_PCI_IO_ATTRIBUTE_VGA_IO_16
;
869 Attributes
|= EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16
;
872 if (Option
== EFI_SET_SUPPORTS
) {
874 Attributes
|= EFI_PCI_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE
|
875 EFI_PCI_IO_ATTRIBUTE_MEMORY_CACHED
|
876 EFI_PCI_IO_ATTRIBUTE_MEMORY_DISABLE
|
877 EFI_PCI_IO_ATTRIBUTE_EMBEDDED_DEVICE
|
878 EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM
|
879 EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE
;
881 if (Attributes
& EFI_PCI_IO_ATTRIBUTE_IO
) {
882 Attributes
|= EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO
;
883 Attributes
|= EFI_PCI_IO_ATTRIBUTE_ISA_IO
;
886 if (IS_PCI_BRIDGE (&PciIoDevice
->Pci
) || IS_CARDBUS_BRIDGE (&PciIoDevice
->Pci
)) {
888 // For bridge, it should support IDE attributes
890 Attributes
|= EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO
;
891 Attributes
|= EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO
;
894 if (IS_PCI_IDE (&PciIoDevice
->Pci
)) {
895 Attributes
|= EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO
;
896 Attributes
|= EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO
;
899 if (IS_PCI_VGA (&PciIoDevice
->Pci
)) {
900 Attributes
|= EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY
;
901 Attributes
|= EFI_PCI_IO_ATTRIBUTE_VGA_IO
;
905 PciIoDevice
->Supports
= Attributes
;
906 PciIoDevice
->Supports
&= ( (PciIoDevice
->Parent
->Supports
) | \
907 EFI_PCI_IO_ATTRIBUTE_IO
| EFI_PCI_IO_ATTRIBUTE_MEMORY
| \
908 EFI_PCI_IO_ATTRIBUTE_BUS_MASTER
);
911 PciIoDevice
->Attributes
= Attributes
;
918 GetFastBackToBackSupport (
919 IN PCI_IO_DEVICE
*PciIoDevice
,
926 Determine if the device can support Fast Back to Back attribute
935 // TODO: PciIoDevice - add argument and description to function comment
936 // TODO: StatusIndex - add argument and description to function comment
937 // TODO: EFI_UNSUPPORTED - add return value to function comment
938 // TODO: EFI_SUCCESS - add return value to function comment
939 // TODO: EFI_UNSUPPORTED - add return value to function comment
941 EFI_PCI_IO_PROTOCOL
*PciIo
;
943 UINT32 StatusRegister
;
946 // Read the status register
948 PciIo
= &PciIoDevice
->PciIo
;
949 Status
= PciIoRead (PciIo
, EfiPciIoWidthUint16
, StatusIndex
, 1, &StatusRegister
);
950 if (EFI_ERROR (Status
)) {
951 return EFI_UNSUPPORTED
;
955 // Check the Fast B2B bit
957 if (StatusRegister
& EFI_PCI_FAST_BACK_TO_BACK_CAPABLE
) {
960 return EFI_UNSUPPORTED
;
967 ProcessOptionRomLight (
968 IN PCI_IO_DEVICE
*PciIoDevice
974 Process the option ROM for all the children of the specified parent PCI device.
975 It can only be used after the first full Option ROM process.
984 // TODO: PciIoDevice - add argument and description to function comment
985 // TODO: EFI_SUCCESS - add return value to function comment
988 LIST_ENTRY
*CurrentLink
;
991 // For RootBridge, PPB , P2C, go recursively to traverse all its children
993 CurrentLink
= PciIoDevice
->ChildList
.ForwardLink
;
994 while (CurrentLink
&& CurrentLink
!= &PciIoDevice
->ChildList
) {
996 Temp
= PCI_IO_DEVICE_FROM_LINK (CurrentLink
);
998 if (!IsListEmpty (&Temp
->ChildList
)) {
999 ProcessOptionRomLight (Temp
);
1002 PciRomGetImageMapping (Temp
);
1005 // The OpRom has already been processed in the first round
1007 Temp
->AllOpRomProcessed
= TRUE
;
1009 CurrentLink
= CurrentLink
->ForwardLink
;
1016 DetermineDeviceAttribute (
1017 IN PCI_IO_DEVICE
*PciIoDevice
1021 Routine Description:
1023 Determine the related attributes of all devices under a Root Bridge
1032 // TODO: PciIoDevice - add argument and description to function comment
1033 // TODO: EFI_SUCCESS - add return value to function comment
1036 UINT16 BridgeControl
;
1038 UINT16 OldBridgeControl
;
1039 BOOLEAN FastB2BSupport
;
1043 EFI_PCI_IO_PROTOCOL *PciIo;
1045 PCI_IO_DEVICE
*Temp
;
1046 LIST_ENTRY
*CurrentLink
;
1050 // For Root Bridge, just copy it by RootBridgeIo proctocol
1051 // so as to keep consistent with the actual attribute
1053 if (!PciIoDevice
->Parent
) {
1054 Status
= PciIoDevice
->PciRootBridgeIo
->GetAttributes (
1055 PciIoDevice
->PciRootBridgeIo
,
1056 &PciIoDevice
->Supports
,
1057 &PciIoDevice
->Attributes
1059 if (EFI_ERROR (Status
)) {
1065 // Set the attributes to be checked for common PCI devices and PPB or P2C
1066 // Since some devices only support part of them, it is better to set the
1067 // attribute according to its command or bridge control register
1069 Command
= EFI_PCI_COMMAND_IO_SPACE
|
1070 EFI_PCI_COMMAND_MEMORY_SPACE
|
1071 EFI_PCI_COMMAND_BUS_MASTER
|
1072 EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
;
1074 BridgeControl
= EFI_PCI_BRIDGE_CONTROL_ISA
| EFI_PCI_BRIDGE_CONTROL_VGA
| EFI_PCI_BRIDGE_CONTROL_VGA_16
;
1077 // Test whether the device can support attributes above
1079 PciTestSupportedAttribute (PciIoDevice
, &Command
, &BridgeControl
, &OldCommand
, &OldBridgeControl
);
1082 // Set the supported attributes for specified PCI device
1084 PciSetDeviceAttribute (PciIoDevice
, Command
, BridgeControl
, EFI_SET_SUPPORTS
);
1087 // Set the current attributes for specified PCI device
1089 PciSetDeviceAttribute (PciIoDevice
, OldCommand
, OldBridgeControl
, EFI_SET_ATTRIBUTES
);
1092 // Enable other supported attributes but not defined in PCI_IO_PROTOCOL
1094 PciEnableCommandRegister (PciIoDevice
, EFI_PCI_COMMAND_MEMORY_WRITE_AND_INVALIDATE
);
1097 // Enable IDE native mode
1100 if (IS_PCI_IDE(&PciIoDevice->Pci)) {
1102 PciIo = &PciIoDevice->PciIo;
1113 // Set native mode if it can be supported
1115 IdePI |= (((IdePI & 0x0F) >> 1) & 0x05);
1129 FastB2BSupport
= TRUE
;
1132 // P2C can not support FB2B on the secondary side
1134 if (IS_CARDBUS_BRIDGE (&PciIoDevice
->Pci
)) {
1135 FastB2BSupport
= FALSE
;
1139 // For RootBridge, PPB , P2C, go recursively to traverse all its children
1141 CurrentLink
= PciIoDevice
->ChildList
.ForwardLink
;
1142 while (CurrentLink
&& CurrentLink
!= &PciIoDevice
->ChildList
) {
1144 Temp
= PCI_IO_DEVICE_FROM_LINK (CurrentLink
);
1145 Status
= DetermineDeviceAttribute (Temp
);
1146 if (EFI_ERROR (Status
)) {
1150 // Detect Fast Bact to Bact support for the device under the bridge
1152 Status
= GetFastBackToBackSupport (Temp
, PCI_PRIMARY_STATUS_OFFSET
);
1153 if (FastB2BSupport
&& EFI_ERROR (Status
)) {
1154 FastB2BSupport
= FALSE
;
1157 CurrentLink
= CurrentLink
->ForwardLink
;
1160 // Set or clear Fast Back to Back bit for the whole bridge
1162 if (!IsListEmpty (&PciIoDevice
->ChildList
)) {
1164 if (IS_PCI_BRIDGE (&PciIoDevice
->Pci
)) {
1166 Status
= GetFastBackToBackSupport (PciIoDevice
, PCI_BRIDGE_STATUS_REGISTER_OFFSET
);
1168 if (EFI_ERROR (Status
) || (!FastB2BSupport
)) {
1169 FastB2BSupport
= FALSE
;
1170 PciDisableBridgeControlRegister (PciIoDevice
, EFI_PCI_BRIDGE_CONTROL_FAST_BACK_TO_BACK
);
1172 PciEnableBridgeControlRegister (PciIoDevice
, EFI_PCI_BRIDGE_CONTROL_FAST_BACK_TO_BACK
);
1176 CurrentLink
= PciIoDevice
->ChildList
.ForwardLink
;
1177 while (CurrentLink
&& CurrentLink
!= &PciIoDevice
->ChildList
) {
1178 Temp
= PCI_IO_DEVICE_FROM_LINK (CurrentLink
);
1179 if (FastB2BSupport
) {
1180 PciEnableCommandRegister (Temp
, EFI_PCI_COMMAND_FAST_BACK_TO_BACK
);
1182 PciDisableCommandRegister (Temp
, EFI_PCI_COMMAND_FAST_BACK_TO_BACK
);
1185 CurrentLink
= CurrentLink
->ForwardLink
;
1189 // End for IsListEmpty
1196 IN PCI_IO_DEVICE
*PciIoDevice
1200 Routine Description:
1202 This routine is used to update the bar information for those incompatible PCI device
1211 // TODO: PciIoDevice - add argument and description to function comment
1212 // TODO: EFI_UNSUPPORTED - add return value to function comment
1218 EFI_PCI_DEVICE_INFO PciDeviceInfo
;
1219 VOID
*Configuration
;
1220 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Ptr
;
1222 Configuration
= NULL
;
1223 Status
= EFI_SUCCESS
;
1225 if (gEfiIncompatiblePciDeviceSupport
== NULL
) {
1227 // It can only be supported after the Incompatible PCI Device
1228 // Support Protocol has been installed
1230 Status
= gBS
->LocateProtocol (
1231 &gEfiIncompatiblePciDeviceSupportProtocolGuid
,
1233 (VOID
**) &gEfiIncompatiblePciDeviceSupport
1236 if (Status
== EFI_SUCCESS
) {
1238 // Check whether the device belongs to incompatible devices from protocol or not
1239 // If it is , then get its special requirement in the ACPI table
1241 Status
= gEfiIncompatiblePciDeviceSupport
->CheckDevice (
1242 gEfiIncompatiblePciDeviceSupport
,
1243 PciIoDevice
->Pci
.Hdr
.VendorId
,
1244 PciIoDevice
->Pci
.Hdr
.DeviceId
,
1245 PciIoDevice
->Pci
.Hdr
.RevisionID
,
1246 PciIoDevice
->Pci
.Device
.SubsystemVendorID
,
1247 PciIoDevice
->Pci
.Device
.SubsystemID
,
1253 if (EFI_ERROR (Status
)) {
1255 // Check whether the device belongs to incompatible devices from library or not
1256 // If it is , then get its special requirement in the ACPI table
1258 if (PcdGet8 (PcdPciIncompatibleDeviceSupportMask
) & PCI_INCOMPATIBLE_ACPI_RESOURCE_SUPPORT
) {
1259 PciDeviceInfo
.VendorID
= PciIoDevice
->Pci
.Hdr
.VendorId
;
1260 PciDeviceInfo
.DeviceID
= PciIoDevice
->Pci
.Hdr
.DeviceId
;
1261 PciDeviceInfo
.RevisionID
= PciIoDevice
->Pci
.Hdr
.RevisionID
;
1262 PciDeviceInfo
.SubsystemVendorID
= PciIoDevice
->Pci
.Device
.SubsystemVendorID
;
1263 PciDeviceInfo
.SubsystemID
= PciIoDevice
->Pci
.Device
.SubsystemID
;
1265 Status
= PciResourceUpdateCheck (&PciDeviceInfo
, &Configuration
);
1269 if (EFI_ERROR (Status
)) {
1270 return EFI_UNSUPPORTED
;
1274 // Update PCI device information from the ACPI table
1276 Ptr
= (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Configuration
;
1278 while (Ptr
->Desc
!= ACPI_END_TAG_DESCRIPTOR
) {
1280 if (Ptr
->Desc
!= ACPI_ADDRESS_SPACE_DESCRIPTOR
) {
1282 // The format is not support
1287 BarIndex
= (UINTN
) Ptr
->AddrTranslationOffset
;
1288 BarEndIndex
= BarIndex
;
1291 // Update all the bars in the device
1293 if (BarIndex
== PCI_BAR_ALL
) {
1295 BarEndIndex
= PCI_MAX_BAR
- 1;
1298 if (BarIndex
>= PCI_MAX_BAR
) {
1303 for (; BarIndex
<= BarEndIndex
; BarIndex
++) {
1305 switch (Ptr
->ResType
) {
1306 case ACPI_ADDRESS_SPACE_TYPE_MEM
:
1309 // Make sure the bar is memory type
1311 if (CheckBarType (PciIoDevice
, (UINT8
) BarIndex
, PciBarTypeMem
)) {
1316 case ACPI_ADDRESS_SPACE_TYPE_IO
:
1319 // Make sure the bar is IO type
1321 if (CheckBarType (PciIoDevice
, (UINT8
) BarIndex
, PciBarTypeIo
)) {
1330 // Update the new alignment for the device
1332 SetNewAlign (&(PciIoDevice
->PciBar
[BarIndex
].Alignment
), Ptr
->AddrRangeMax
);
1335 // Update the new length for the device
1337 if (Ptr
->AddrLen
!= PCI_BAR_NOCHANGE
) {
1338 PciIoDevice
->PciBar
[BarIndex
].Length
= Ptr
->AddrLen
;
1346 gBS
->FreePool (Configuration
);
1353 IN UINT64
*Alignment
,
1354 IN UINT64 NewAlignment
1358 Routine Description:
1360 This routine will update the alignment with the new alignment
1369 // TODO: Alignment - add argument and description to function comment
1370 // TODO: NewAlignment - add argument and description to function comment
1372 UINT64 OldAlignment
;
1376 // The new alignment is the same as the original,
1379 if (NewAlignment
== PCI_BAR_OLD_ALIGN
) {
1383 // Check the validity of the parameter
1385 if (NewAlignment
!= PCI_BAR_EVEN_ALIGN
&&
1386 NewAlignment
!= PCI_BAR_SQUAD_ALIGN
&&
1387 NewAlignment
!= PCI_BAR_DQUAD_ALIGN
) {
1388 *Alignment
= NewAlignment
;
1392 OldAlignment
= (*Alignment
) + 1;
1396 // Get the first non-zero hex value of the length
1398 while ((OldAlignment
& 0x0F) == 0x00) {
1399 OldAlignment
= RShiftU64 (OldAlignment
, 4);
1404 // Adjust the alignment to even, quad or double quad boundary
1406 if (NewAlignment
== PCI_BAR_EVEN_ALIGN
) {
1407 if (OldAlignment
& 0x01) {
1408 OldAlignment
= OldAlignment
+ 2 - (OldAlignment
& 0x01);
1410 } else if (NewAlignment
== PCI_BAR_SQUAD_ALIGN
) {
1411 if (OldAlignment
& 0x03) {
1412 OldAlignment
= OldAlignment
+ 4 - (OldAlignment
& 0x03);
1414 } else if (NewAlignment
== PCI_BAR_DQUAD_ALIGN
) {
1415 if (OldAlignment
& 0x07) {
1416 OldAlignment
= OldAlignment
+ 8 - (OldAlignment
& 0x07);
1421 // Update the old value
1423 NewAlignment
= LShiftU64 (OldAlignment
, ShiftBit
) - 1;
1424 *Alignment
= NewAlignment
;
1431 IN PCI_IO_DEVICE
*PciIoDevice
,
1437 Routine Description:
1446 // TODO: PciIoDevice - add argument and description to function comment
1447 // TODO: Offset - add argument and description to function comment
1448 // TODO: BarIndex - add argument and description to function comment
1451 UINT32 OriginalValue
;
1460 Status
= BarExisted (
1467 if (EFI_ERROR (Status
)) {
1468 PciIoDevice
->PciBar
[BarIndex
].BaseAddress
= 0;
1469 PciIoDevice
->PciBar
[BarIndex
].Length
= 0;
1470 PciIoDevice
->PciBar
[BarIndex
].Alignment
= 0;
1473 // Some devices don't fully comply to PCI spec 2.2. So be to scan all the BARs anyway
1475 PciIoDevice
->PciBar
[BarIndex
].Offset
= (UINT8
) Offset
;
1479 PciIoDevice
->PciBar
[BarIndex
].Offset
= (UINT8
) Offset
;
1486 if (Value
& 0xFFFF0000) {
1490 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypeIo32
;
1491 PciIoDevice
->PciBar
[BarIndex
].Length
= ((~(Value
& Mask
)) + 1);
1492 PciIoDevice
->PciBar
[BarIndex
].Alignment
= PciIoDevice
->PciBar
[BarIndex
].Length
- 1;
1498 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypeIo16
;
1499 PciIoDevice
->PciBar
[BarIndex
].Length
= 0x0000FFFF & ((~(Value
& Mask
)) + 1);
1500 PciIoDevice
->PciBar
[BarIndex
].Alignment
= PciIoDevice
->PciBar
[BarIndex
].Length
- 1;
1504 // Workaround. Some platforms inplement IO bar with 0 length
1505 // Need to treat it as no-bar
1507 if (PciIoDevice
->PciBar
[BarIndex
].Length
== 0) {
1508 PciIoDevice
->PciBar
[BarIndex
].BarType
= (PCI_BAR_TYPE
) 0;
1511 PciIoDevice
->PciBar
[BarIndex
].Prefetchable
= FALSE
;
1512 PciIoDevice
->PciBar
[BarIndex
].BaseAddress
= OriginalValue
& Mask
;
1518 PciIoDevice
->PciBar
[BarIndex
].BaseAddress
= OriginalValue
& Mask
;
1520 switch (Value
& 0x07) {
1523 //memory space; anywhere in 32 bit address space
1527 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypePMem32
;
1529 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypeMem32
;
1532 PciIoDevice
->PciBar
[BarIndex
].Length
= (~(Value
& Mask
)) + 1;
1533 PciIoDevice
->PciBar
[BarIndex
].Alignment
= PciIoDevice
->PciBar
[BarIndex
].Length
- 1;
1538 // memory space; anywhere in 64 bit address space
1542 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypePMem64
;
1544 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypeMem64
;
1548 // According to PCI 2.2,if the bar indicates a memory 64 decoding, next bar
1549 // is regarded as an extension for the first bar. As a result
1550 // the sizing will be conducted on combined 64 bit value
1551 // Here just store the masked first 32bit value for future size
1554 PciIoDevice
->PciBar
[BarIndex
].Length
= Value
& Mask
;
1555 PciIoDevice
->PciBar
[BarIndex
].Alignment
= PciIoDevice
->PciBar
[BarIndex
].Length
- 1;
1558 // Increment the offset to point to next DWORD
1562 Status
= BarExisted (
1569 if (EFI_ERROR (Status
)) {
1574 // Fix the length to support some spefic 64 bit BAR
1578 for (Data
= Value
; Data
!= 0; Data
>>= 1) {
1581 Value
|= ((UINT32
)(-1) << Index
);
1584 // Calculate the size of 64bit bar
1586 PciIoDevice
->PciBar
[BarIndex
].BaseAddress
|= LShiftU64 ((UINT64
) OriginalValue
, 32);
1588 PciIoDevice
->PciBar
[BarIndex
].Length
= PciIoDevice
->PciBar
[BarIndex
].Length
| LShiftU64 ((UINT64
) Value
, 32);
1589 PciIoDevice
->PciBar
[BarIndex
].Length
= (~(PciIoDevice
->PciBar
[BarIndex
].Length
)) + 1;
1590 PciIoDevice
->PciBar
[BarIndex
].Alignment
= PciIoDevice
->PciBar
[BarIndex
].Length
- 1;
1598 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypeUnknown
;
1599 PciIoDevice
->PciBar
[BarIndex
].Length
= (~(Value
& Mask
)) + 1;
1600 PciIoDevice
->PciBar
[BarIndex
].Alignment
= PciIoDevice
->PciBar
[BarIndex
].Length
- 1;
1607 // Check the length again so as to keep compatible with some special bars
1609 if (PciIoDevice
->PciBar
[BarIndex
].Length
== 0) {
1610 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypeUnknown
;
1611 PciIoDevice
->PciBar
[BarIndex
].BaseAddress
= 0;
1612 PciIoDevice
->PciBar
[BarIndex
].Alignment
= 0;
1616 // Increment number of bar
1622 InitializePciDevice (
1623 IN PCI_IO_DEVICE
*PciIoDevice
1627 Routine Description:
1629 This routine is used to initialize the bar of a PCI device
1630 It can be called typically when a device is going to be rejected
1639 // TODO: PciIoDevice - add argument and description to function comment
1640 // TODO: EFI_SUCCESS - add return value to function comment
1642 EFI_PCI_IO_PROTOCOL
*PciIo
;
1645 PciIo
= &(PciIoDevice
->PciIo
);
1648 // Put all the resource apertures
1649 // Resource base is set to all ones so as to indicate its resource
1650 // has not been alloacted
1652 for (Offset
= 0x10; Offset
<= 0x24; Offset
+= sizeof (UINT32
)) {
1653 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, Offset
, 1, &gAllOne
);
1661 IN PCI_IO_DEVICE
*PciIoDevice
1665 Routine Description:
1674 // TODO: PciIoDevice - add argument and description to function comment
1675 // TODO: EFI_SUCCESS - add return value to function comment
1677 EFI_PCI_IO_PROTOCOL
*PciIo
;
1679 PciIo
= &(PciIoDevice
->PciIo
);
1682 // Put all the resource apertures including IO16
1683 // Io32, pMem32, pMem64 to quiescent state
1684 // Resource base all ones, Resource limit all zeros
1686 PciIoWrite (PciIo
, EfiPciIoWidthUint8
, 0x1C, 1, &gAllOne
);
1687 PciIoWrite (PciIo
, EfiPciIoWidthUint8
, 0x1D, 1, &gAllZero
);
1689 PciIoWrite (PciIo
, EfiPciIoWidthUint16
, 0x20, 1, &gAllOne
);
1690 PciIoWrite (PciIo
, EfiPciIoWidthUint16
, 0x22, 1, &gAllZero
);
1692 PciIoWrite (PciIo
, EfiPciIoWidthUint16
, 0x24, 1, &gAllOne
);
1693 PciIoWrite (PciIo
, EfiPciIoWidthUint16
, 0x26, 1, &gAllZero
);
1695 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x28, 1, &gAllOne
);
1696 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x2C, 1, &gAllZero
);
1699 // don't support use io32 as for now
1701 PciIoWrite (PciIo
, EfiPciIoWidthUint16
, 0x30, 1, &gAllOne
);
1702 PciIoWrite (PciIo
, EfiPciIoWidthUint16
, 0x32, 1, &gAllZero
);
1705 // Force Interrupt line to zero for cards that come up randomly
1707 PciIoWrite (PciIo
, EfiPciIoWidthUint8
, 0x3C, 1, &gAllZero
);
1714 IN PCI_IO_DEVICE
*PciIoDevice
1718 Routine Description:
1727 // TODO: PciIoDevice - add argument and description to function comment
1728 // TODO: EFI_SUCCESS - add return value to function comment
1730 EFI_PCI_IO_PROTOCOL
*PciIo
;
1732 PciIo
= &(PciIoDevice
->PciIo
);
1735 // Put all the resource apertures including IO16
1736 // Io32, pMem32, pMem64 to quiescent state(
1737 // Resource base all ones, Resource limit all zeros
1739 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x1c, 1, &gAllOne
);
1740 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x20, 1, &gAllZero
);
1742 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x24, 1, &gAllOne
);
1743 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x28, 1, &gAllZero
);
1745 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x2c, 1, &gAllOne
);
1746 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x30, 1, &gAllZero
);
1748 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x34, 1, &gAllOne
);
1749 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x38, 1, &gAllZero
);
1752 // Force Interrupt line to zero for cards that come up randomly
1754 PciIoWrite (PciIo
, EfiPciIoWidthUint8
, 0x3C, 1, &gAllZero
);
1760 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
,
1768 Routine Description:
1777 // TODO: PciRootBridgeIo - add argument and description to function comment
1778 // TODO: Pci - add argument and description to function comment
1779 // TODO: Bus - add argument and description to function comment
1780 // TODO: Device - add argument and description to function comment
1781 // TODO: Func - add argument and description to function comment
1785 PCI_IO_DEVICE
*PciIoDevice
;
1789 Status
= gBS
->AllocatePool (
1790 EfiBootServicesData
,
1791 sizeof (PCI_IO_DEVICE
),
1792 (VOID
**) &PciIoDevice
1795 if (EFI_ERROR (Status
)) {
1799 ZeroMem (PciIoDevice
, sizeof (PCI_IO_DEVICE
));
1801 PciIoDevice
->Signature
= PCI_IO_DEVICE_SIGNATURE
;
1802 PciIoDevice
->Handle
= NULL
;
1803 PciIoDevice
->PciRootBridgeIo
= PciRootBridgeIo
;
1804 PciIoDevice
->DevicePath
= NULL
;
1805 PciIoDevice
->BusNumber
= Bus
;
1806 PciIoDevice
->DeviceNumber
= Device
;
1807 PciIoDevice
->FunctionNumber
= Func
;
1808 PciIoDevice
->Decodes
= 0;
1809 if (gFullEnumeration
) {
1810 PciIoDevice
->Allocated
= FALSE
;
1812 PciIoDevice
->Allocated
= TRUE
;
1815 PciIoDevice
->Registered
= FALSE
;
1816 PciIoDevice
->Attributes
= 0;
1817 PciIoDevice
->Supports
= 0;
1818 PciIoDevice
->BusOverride
= FALSE
;
1819 PciIoDevice
->AllOpRomProcessed
= FALSE
;
1821 PciIoDevice
->IsPciExp
= FALSE
;
1823 CopyMem (&(PciIoDevice
->Pci
), Pci
, sizeof (PCI_TYPE01
));
1826 // Initialize the PCI I/O instance structure
1829 Status
= InitializePciIoInstance (PciIoDevice
);
1830 Status
= InitializePciDriverOverrideInstance (PciIoDevice
);
1832 if (EFI_ERROR (Status
)) {
1833 gBS
->FreePool (PciIoDevice
);
1838 // Initialize the reserved resource list
1840 InitializeListHead (&PciIoDevice
->ReservedResourceList
);
1843 // Initialize the driver list
1845 InitializeListHead (&PciIoDevice
->OptionRomDriverList
);
1848 // Initialize the child list
1850 InitializeListHead (&PciIoDevice
->ChildList
);
1856 PciEnumeratorLight (
1857 IN EFI_HANDLE Controller
1861 Routine Description:
1863 This routine is used to enumerate entire pci bus system
1865 It is only called on the second start on the same Root Bridge.
1874 // TODO: Controller - add argument and description to function comment
1875 // TODO: EFI_SUCCESS - add return value to function comment
1876 // TODO: EFI_SUCCESS - add return value to function comment
1880 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
1881 PCI_IO_DEVICE
*RootBridgeDev
;
1884 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Descriptors
;
1887 MaxBus
= PCI_MAX_BUS
;
1891 // If this root bridge has been already enumerated, then return successfully
1893 if (GetRootBridgeByHandle (Controller
) != NULL
) {
1898 // Open pci root bridge io protocol
1900 Status
= gBS
->OpenProtocol (
1902 &gEfiPciRootBridgeIoProtocolGuid
,
1903 (VOID
**) &PciRootBridgeIo
,
1904 gPciBusDriverBinding
.DriverBindingHandle
,
1906 EFI_OPEN_PROTOCOL_BY_DRIVER
1908 if (EFI_ERROR (Status
) && Status
!= EFI_ALREADY_STARTED
) {
1912 Status
= PciRootBridgeIo
->Configuration (PciRootBridgeIo
, (VOID
**) &Descriptors
);
1914 if (EFI_ERROR (Status
)) {
1918 while (PciGetBusRange (&Descriptors
, &MinBus
, &MaxBus
, NULL
) == EFI_SUCCESS
) {
1921 // Create a device node for root bridge device with a NULL host bridge controller handle
1923 RootBridgeDev
= CreateRootBridge (Controller
);
1925 if (!RootBridgeDev
) {
1931 // Record the root bridge io protocol
1933 RootBridgeDev
->PciRootBridgeIo
= PciRootBridgeIo
;
1935 Status
= PciPciDeviceInfoCollector (
1940 if (!EFI_ERROR (Status
)) {
1943 // Remove those PCI devices which are rejected when full enumeration
1945 RemoveRejectedPciDevices (RootBridgeDev
->Handle
, RootBridgeDev
);
1948 // Process option rom light
1950 ProcessOptionRomLight (RootBridgeDev
);
1953 // Determine attributes for all devices under this root bridge
1955 DetermineDeviceAttribute (RootBridgeDev
);
1958 // If successfully, insert the node into device pool
1960 InsertRootBridge (RootBridgeDev
);
1964 // If unsuccessly, destroy the entire node
1966 DestroyRootBridge (RootBridgeDev
);
1977 IN EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
**Descriptors
,
1980 OUT UINT16
*BusRange
1984 Routine Description:
1990 Descriptors - A pointer to the address space descriptor.
1991 MinBus - The min bus.
1992 MaxBus - The max bus.
1993 BusRange - The bus range.
2000 // TODO: EFI_SUCCESS - add return value to function comment
2001 // TODO: EFI_NOT_FOUND - add return value to function comment
2004 while ((*Descriptors
)->Desc
!= ACPI_END_TAG_DESCRIPTOR
) {
2005 if ((*Descriptors
)->ResType
== ACPI_ADDRESS_SPACE_TYPE_BUS
) {
2006 if (MinBus
!= NULL
) {
2007 *MinBus
= (UINT16
) (*Descriptors
)->AddrRangeMin
;
2010 if (MaxBus
!= NULL
) {
2011 *MaxBus
= (UINT16
) (*Descriptors
)->AddrRangeMax
;
2014 if (BusRange
!= NULL
) {
2015 *BusRange
= (UINT16
) (*Descriptors
)->AddrLen
;
2024 return EFI_NOT_FOUND
;
2028 StartManagingRootBridge (
2029 IN PCI_IO_DEVICE
*RootBridgeDev
2033 Routine Description:
2043 // TODO: RootBridgeDev - add argument and description to function comment
2044 // TODO: EFI_SUCCESS - add return value to function comment
2046 EFI_HANDLE RootBridgeHandle
;
2048 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
2051 // Get the root bridge handle
2053 RootBridgeHandle
= RootBridgeDev
->Handle
;
2054 PciRootBridgeIo
= NULL
;
2057 // Get the pci root bridge io protocol
2059 Status
= gBS
->OpenProtocol (
2061 &gEfiPciRootBridgeIoProtocolGuid
,
2062 (VOID
**) &PciRootBridgeIo
,
2063 gPciBusDriverBinding
.DriverBindingHandle
,
2065 EFI_OPEN_PROTOCOL_BY_DRIVER
2068 if (EFI_ERROR (Status
) && Status
!= EFI_ALREADY_STARTED
) {
2073 // Store the PciRootBridgeIo protocol into root bridge private data
2075 RootBridgeDev
->PciRootBridgeIo
= PciRootBridgeIo
;
2082 IsPciDeviceRejected (
2083 IN PCI_IO_DEVICE
*PciIoDevice
2087 Routine Description:
2089 This routine can be used to check whether a PCI device should be rejected when light enumeration
2095 TRUE This device should be rejected
2096 FALSE This device shouldn't be rejected
2099 // TODO: PciIoDevice - add argument and description to function comment
2108 // PPB should be skip!
2110 if (IS_PCI_BRIDGE (&PciIoDevice
->Pci
)) {
2114 if (IS_CARDBUS_BRIDGE (&PciIoDevice
->Pci
)) {
2116 // Only test base registers for P2C
2118 for (BarOffset
= 0x1C; BarOffset
<= 0x38; BarOffset
+= 2 * sizeof (UINT32
)) {
2120 Mask
= (BarOffset
< 0x2C) ? 0xFFFFF000 : 0xFFFFFFFC;
2121 Status
= BarExisted (PciIoDevice
, BarOffset
, &TestValue
, &OldValue
);
2122 if (EFI_ERROR (Status
)) {
2126 TestValue
= TestValue
& Mask
;
2127 if ((TestValue
!= 0) && (TestValue
== (OldValue
& Mask
))) {
2129 // The bar isn't programed, so it should be rejected
2138 for (BarOffset
= 0x14; BarOffset
<= 0x24; BarOffset
+= sizeof (UINT32
)) {
2142 Status
= BarExisted (PciIoDevice
, BarOffset
, &TestValue
, &OldValue
);
2143 if (EFI_ERROR (Status
)) {
2147 if (TestValue
& 0x01) {
2154 TestValue
= TestValue
& Mask
;
2155 if ((TestValue
!= 0) && (TestValue
== (OldValue
& Mask
))) {
2166 TestValue
= TestValue
& Mask
;
2168 if ((TestValue
& 0x07) == 0x04) {
2173 BarOffset
+= sizeof (UINT32
);
2174 if ((TestValue
!= 0) && (TestValue
== (OldValue
& Mask
))) {
2177 // Test its high 32-Bit BAR
2180 Status
= BarExisted (PciIoDevice
, BarOffset
, &TestValue
, &OldValue
);
2181 if (TestValue
== OldValue
) {
2191 if ((TestValue
!= 0) && (TestValue
== (OldValue
& Mask
))) {
2202 ResetAllPpbBusNumber (
2203 IN PCI_IO_DEVICE
*Bridge
,
2204 IN UINT8 StartBusNumber
2208 Routine Description:
2210 TODO: Add function description
2214 Bridge - TODO: add argument description
2215 StartBusNumber - TODO: add argument description
2219 EFI_SUCCESS - TODO: Add description for return value
2230 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
2232 PciRootBridgeIo
= Bridge
->PciRootBridgeIo
;
2234 for (Device
= 0; Device
<= PCI_MAX_DEVICE
; Device
++) {
2235 for (Func
= 0; Func
<= PCI_MAX_FUNC
; Func
++) {
2238 // Check to see whether a pci device is present
2240 Status
= PciDevicePresent (
2248 if (!EFI_ERROR (Status
) && (IS_PCI_BRIDGE (&Pci
))) {
2251 Address
= EFI_PCI_ADDRESS (StartBusNumber
, Device
, Func
, 0x18);
2252 Status
= PciRootBridgeIoRead (
2260 SecondaryBus
= (UINT8
)(Register
>> 8);
2262 if (SecondaryBus
!= 0) {
2263 ResetAllPpbBusNumber (Bridge
, SecondaryBus
);
2267 // Reset register 18h, 19h, 1Ah on PCI Bridge
2269 Register
&= 0xFF000000;
2270 Status
= PciRootBridgeIoWrite (
2280 if (Func
== 0 && !IS_PCI_MULTI_FUNC (&Pci
)) {
2282 // Skip sub functions, this is not a multi function device
2284 Func
= PCI_MAX_FUNC
;