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
);
1003 CurrentLink
= CurrentLink
->ForwardLink
;
1010 DetermineDeviceAttribute (
1011 IN PCI_IO_DEVICE
*PciIoDevice
1015 Routine Description:
1017 Determine the related attributes of all devices under a Root Bridge
1026 // TODO: PciIoDevice - add argument and description to function comment
1027 // TODO: EFI_SUCCESS - add return value to function comment
1030 UINT16 BridgeControl
;
1032 UINT16 OldBridgeControl
;
1033 BOOLEAN FastB2BSupport
;
1037 EFI_PCI_IO_PROTOCOL *PciIo;
1039 PCI_IO_DEVICE
*Temp
;
1040 LIST_ENTRY
*CurrentLink
;
1044 // For Root Bridge, just copy it by RootBridgeIo proctocol
1045 // so as to keep consistent with the actual attribute
1047 if (!PciIoDevice
->Parent
) {
1048 Status
= PciIoDevice
->PciRootBridgeIo
->GetAttributes (
1049 PciIoDevice
->PciRootBridgeIo
,
1050 &PciIoDevice
->Supports
,
1051 &PciIoDevice
->Attributes
1053 if (EFI_ERROR (Status
)) {
1059 // Set the attributes to be checked for common PCI devices and PPB or P2C
1060 // Since some devices only support part of them, it is better to set the
1061 // attribute according to its command or bridge control register
1063 Command
= EFI_PCI_COMMAND_IO_SPACE
|
1064 EFI_PCI_COMMAND_MEMORY_SPACE
|
1065 EFI_PCI_COMMAND_BUS_MASTER
|
1066 EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
;
1068 BridgeControl
= EFI_PCI_BRIDGE_CONTROL_ISA
| EFI_PCI_BRIDGE_CONTROL_VGA
| EFI_PCI_BRIDGE_CONTROL_VGA_16
;
1071 // Test whether the device can support attributes above
1073 PciTestSupportedAttribute (PciIoDevice
, &Command
, &BridgeControl
, &OldCommand
, &OldBridgeControl
);
1076 // Set the supported attributes for specified PCI device
1078 PciSetDeviceAttribute (PciIoDevice
, Command
, BridgeControl
, EFI_SET_SUPPORTS
);
1081 // Set the current attributes for specified PCI device
1083 PciSetDeviceAttribute (PciIoDevice
, OldCommand
, OldBridgeControl
, EFI_SET_ATTRIBUTES
);
1086 // Enable other supported attributes but not defined in PCI_IO_PROTOCOL
1088 PciEnableCommandRegister (PciIoDevice
, EFI_PCI_COMMAND_MEMORY_WRITE_AND_INVALIDATE
);
1091 // Enable IDE native mode
1094 if (IS_PCI_IDE(&PciIoDevice->Pci)) {
1096 PciIo = &PciIoDevice->PciIo;
1107 // Set native mode if it can be supported
1109 IdePI |= (((IdePI & 0x0F) >> 1) & 0x05);
1123 FastB2BSupport
= TRUE
;
1126 // P2C can not support FB2B on the secondary side
1128 if (IS_CARDBUS_BRIDGE (&PciIoDevice
->Pci
)) {
1129 FastB2BSupport
= FALSE
;
1133 // For RootBridge, PPB , P2C, go recursively to traverse all its children
1135 CurrentLink
= PciIoDevice
->ChildList
.ForwardLink
;
1136 while (CurrentLink
&& CurrentLink
!= &PciIoDevice
->ChildList
) {
1138 Temp
= PCI_IO_DEVICE_FROM_LINK (CurrentLink
);
1139 Status
= DetermineDeviceAttribute (Temp
);
1140 if (EFI_ERROR (Status
)) {
1144 // Detect Fast Bact to Bact support for the device under the bridge
1146 Status
= GetFastBackToBackSupport (Temp
, PCI_PRIMARY_STATUS_OFFSET
);
1147 if (FastB2BSupport
&& EFI_ERROR (Status
)) {
1148 FastB2BSupport
= FALSE
;
1151 CurrentLink
= CurrentLink
->ForwardLink
;
1154 // Set or clear Fast Back to Back bit for the whole bridge
1156 if (!IsListEmpty (&PciIoDevice
->ChildList
)) {
1158 if (IS_PCI_BRIDGE (&PciIoDevice
->Pci
)) {
1160 Status
= GetFastBackToBackSupport (PciIoDevice
, PCI_BRIDGE_STATUS_REGISTER_OFFSET
);
1162 if (EFI_ERROR (Status
) || (!FastB2BSupport
)) {
1163 FastB2BSupport
= FALSE
;
1164 PciDisableBridgeControlRegister (PciIoDevice
, EFI_PCI_BRIDGE_CONTROL_FAST_BACK_TO_BACK
);
1166 PciEnableBridgeControlRegister (PciIoDevice
, EFI_PCI_BRIDGE_CONTROL_FAST_BACK_TO_BACK
);
1170 CurrentLink
= PciIoDevice
->ChildList
.ForwardLink
;
1171 while (CurrentLink
&& CurrentLink
!= &PciIoDevice
->ChildList
) {
1172 Temp
= PCI_IO_DEVICE_FROM_LINK (CurrentLink
);
1173 if (FastB2BSupport
) {
1174 PciEnableCommandRegister (Temp
, EFI_PCI_COMMAND_FAST_BACK_TO_BACK
);
1176 PciDisableCommandRegister (Temp
, EFI_PCI_COMMAND_FAST_BACK_TO_BACK
);
1179 CurrentLink
= CurrentLink
->ForwardLink
;
1183 // End for IsListEmpty
1190 IN PCI_IO_DEVICE
*PciIoDevice
1194 Routine Description:
1196 This routine is used to update the bar information for those incompatible PCI device
1205 // TODO: PciIoDevice - add argument and description to function comment
1206 // TODO: EFI_UNSUPPORTED - add return value to function comment
1212 EFI_PCI_DEVICE_INFO PciDeviceInfo
;
1213 VOID
*Configuration
;
1214 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Ptr
;
1216 Configuration
= NULL
;
1217 Status
= EFI_SUCCESS
;
1219 if (gEfiIncompatiblePciDeviceSupport
== NULL
) {
1221 // It can only be supported after the Incompatible PCI Device
1222 // Support Protocol has been installed
1224 Status
= gBS
->LocateProtocol (
1225 &gEfiIncompatiblePciDeviceSupportProtocolGuid
,
1227 (VOID
**) &gEfiIncompatiblePciDeviceSupport
1230 if (Status
== EFI_SUCCESS
) {
1232 // Check whether the device belongs to incompatible devices from protocol or not
1233 // If it is , then get its special requirement in the ACPI table
1235 Status
= gEfiIncompatiblePciDeviceSupport
->CheckDevice (
1236 gEfiIncompatiblePciDeviceSupport
,
1237 PciIoDevice
->Pci
.Hdr
.VendorId
,
1238 PciIoDevice
->Pci
.Hdr
.DeviceId
,
1239 PciIoDevice
->Pci
.Hdr
.RevisionID
,
1240 PciIoDevice
->Pci
.Device
.SubsystemVendorID
,
1241 PciIoDevice
->Pci
.Device
.SubsystemID
,
1247 if (EFI_ERROR (Status
)) {
1249 // Check whether the device belongs to incompatible devices from library or not
1250 // If it is , then get its special requirement in the ACPI table
1252 if (PcdGet8 (PcdPciIncompatibleDeviceSupportMask
) & PCI_INCOMPATIBLE_ACPI_RESOURCE_SUPPORT
) {
1253 PciDeviceInfo
.VendorID
= PciIoDevice
->Pci
.Hdr
.VendorId
;
1254 PciDeviceInfo
.DeviceID
= PciIoDevice
->Pci
.Hdr
.DeviceId
;
1255 PciDeviceInfo
.RevisionID
= PciIoDevice
->Pci
.Hdr
.RevisionID
;
1256 PciDeviceInfo
.SubsystemVendorID
= PciIoDevice
->Pci
.Device
.SubsystemVendorID
;
1257 PciDeviceInfo
.SubsystemID
= PciIoDevice
->Pci
.Device
.SubsystemID
;
1259 Status
= PciResourceUpdateCheck (&PciDeviceInfo
, &Configuration
);
1263 if (EFI_ERROR (Status
)) {
1264 return EFI_UNSUPPORTED
;
1268 // Update PCI device information from the ACPI table
1270 Ptr
= (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Configuration
;
1272 while (Ptr
->Desc
!= ACPI_END_TAG_DESCRIPTOR
) {
1274 if (Ptr
->Desc
!= ACPI_ADDRESS_SPACE_DESCRIPTOR
) {
1276 // The format is not support
1281 BarIndex
= (UINTN
) Ptr
->AddrTranslationOffset
;
1282 BarEndIndex
= BarIndex
;
1285 // Update all the bars in the device
1287 if (BarIndex
== PCI_BAR_ALL
) {
1289 BarEndIndex
= PCI_MAX_BAR
- 1;
1292 if (BarIndex
>= PCI_MAX_BAR
) {
1297 for (; BarIndex
<= BarEndIndex
; BarIndex
++) {
1299 switch (Ptr
->ResType
) {
1300 case ACPI_ADDRESS_SPACE_TYPE_MEM
:
1303 // Make sure the bar is memory type
1305 if (CheckBarType (PciIoDevice
, (UINT8
) BarIndex
, PciBarTypeMem
)) {
1310 case ACPI_ADDRESS_SPACE_TYPE_IO
:
1313 // Make sure the bar is IO type
1315 if (CheckBarType (PciIoDevice
, (UINT8
) BarIndex
, PciBarTypeIo
)) {
1324 // Update the new alignment for the device
1326 SetNewAlign (&(PciIoDevice
->PciBar
[BarIndex
].Alignment
), Ptr
->AddrRangeMax
);
1329 // Update the new length for the device
1331 if (Ptr
->AddrLen
!= PCI_BAR_NOCHANGE
) {
1332 PciIoDevice
->PciBar
[BarIndex
].Length
= Ptr
->AddrLen
;
1340 gBS
->FreePool (Configuration
);
1347 IN UINT64
*Alignment
,
1348 IN UINT64 NewAlignment
1352 Routine Description:
1354 This routine will update the alignment with the new alignment
1363 // TODO: Alignment - add argument and description to function comment
1364 // TODO: NewAlignment - add argument and description to function comment
1366 UINT64 OldAlignment
;
1370 // The new alignment is the same as the original,
1373 if (NewAlignment
== PCI_BAR_OLD_ALIGN
) {
1377 // Check the validity of the parameter
1379 if (NewAlignment
!= PCI_BAR_EVEN_ALIGN
&&
1380 NewAlignment
!= PCI_BAR_SQUAD_ALIGN
&&
1381 NewAlignment
!= PCI_BAR_DQUAD_ALIGN
) {
1382 *Alignment
= NewAlignment
;
1386 OldAlignment
= (*Alignment
) + 1;
1390 // Get the first non-zero hex value of the length
1392 while ((OldAlignment
& 0x0F) == 0x00) {
1393 OldAlignment
= RShiftU64 (OldAlignment
, 4);
1398 // Adjust the alignment to even, quad or double quad boundary
1400 if (NewAlignment
== PCI_BAR_EVEN_ALIGN
) {
1401 if (OldAlignment
& 0x01) {
1402 OldAlignment
= OldAlignment
+ 2 - (OldAlignment
& 0x01);
1404 } else if (NewAlignment
== PCI_BAR_SQUAD_ALIGN
) {
1405 if (OldAlignment
& 0x03) {
1406 OldAlignment
= OldAlignment
+ 4 - (OldAlignment
& 0x03);
1408 } else if (NewAlignment
== PCI_BAR_DQUAD_ALIGN
) {
1409 if (OldAlignment
& 0x07) {
1410 OldAlignment
= OldAlignment
+ 8 - (OldAlignment
& 0x07);
1415 // Update the old value
1417 NewAlignment
= LShiftU64 (OldAlignment
, ShiftBit
) - 1;
1418 *Alignment
= NewAlignment
;
1425 IN PCI_IO_DEVICE
*PciIoDevice
,
1431 Routine Description:
1440 // TODO: PciIoDevice - add argument and description to function comment
1441 // TODO: Offset - add argument and description to function comment
1442 // TODO: BarIndex - add argument and description to function comment
1445 UINT32 OriginalValue
;
1454 Status
= BarExisted (
1461 if (EFI_ERROR (Status
)) {
1462 PciIoDevice
->PciBar
[BarIndex
].BaseAddress
= 0;
1463 PciIoDevice
->PciBar
[BarIndex
].Length
= 0;
1464 PciIoDevice
->PciBar
[BarIndex
].Alignment
= 0;
1467 // Some devices don't fully comply to PCI spec 2.2. So be to scan all the BARs anyway
1469 PciIoDevice
->PciBar
[BarIndex
].Offset
= (UINT8
) Offset
;
1473 PciIoDevice
->PciBar
[BarIndex
].Offset
= (UINT8
) Offset
;
1480 if (Value
& 0xFFFF0000) {
1484 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypeIo32
;
1485 PciIoDevice
->PciBar
[BarIndex
].Length
= ((~(Value
& Mask
)) + 1);
1486 PciIoDevice
->PciBar
[BarIndex
].Alignment
= PciIoDevice
->PciBar
[BarIndex
].Length
- 1;
1492 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypeIo16
;
1493 PciIoDevice
->PciBar
[BarIndex
].Length
= 0x0000FFFF & ((~(Value
& Mask
)) + 1);
1494 PciIoDevice
->PciBar
[BarIndex
].Alignment
= PciIoDevice
->PciBar
[BarIndex
].Length
- 1;
1498 // Workaround. Some platforms inplement IO bar with 0 length
1499 // Need to treat it as no-bar
1501 if (PciIoDevice
->PciBar
[BarIndex
].Length
== 0) {
1502 PciIoDevice
->PciBar
[BarIndex
].BarType
= (PCI_BAR_TYPE
) 0;
1505 PciIoDevice
->PciBar
[BarIndex
].Prefetchable
= FALSE
;
1506 PciIoDevice
->PciBar
[BarIndex
].BaseAddress
= OriginalValue
& Mask
;
1512 PciIoDevice
->PciBar
[BarIndex
].BaseAddress
= OriginalValue
& Mask
;
1514 switch (Value
& 0x07) {
1517 //memory space; anywhere in 32 bit address space
1521 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypePMem32
;
1523 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypeMem32
;
1526 PciIoDevice
->PciBar
[BarIndex
].Length
= (~(Value
& Mask
)) + 1;
1527 PciIoDevice
->PciBar
[BarIndex
].Alignment
= PciIoDevice
->PciBar
[BarIndex
].Length
- 1;
1532 // memory space; anywhere in 64 bit address space
1536 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypePMem64
;
1538 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypeMem64
;
1542 // According to PCI 2.2,if the bar indicates a memory 64 decoding, next bar
1543 // is regarded as an extension for the first bar. As a result
1544 // the sizing will be conducted on combined 64 bit value
1545 // Here just store the masked first 32bit value for future size
1548 PciIoDevice
->PciBar
[BarIndex
].Length
= Value
& Mask
;
1549 PciIoDevice
->PciBar
[BarIndex
].Alignment
= PciIoDevice
->PciBar
[BarIndex
].Length
- 1;
1552 // Increment the offset to point to next DWORD
1556 Status
= BarExisted (
1563 if (EFI_ERROR (Status
)) {
1568 // Fix the length to support some spefic 64 bit BAR
1572 for (Data
= Value
; Data
!= 0; Data
>>= 1) {
1575 Value
|= ((UINT32
)(-1) << Index
);
1578 // Calculate the size of 64bit bar
1580 PciIoDevice
->PciBar
[BarIndex
].BaseAddress
|= LShiftU64 ((UINT64
) OriginalValue
, 32);
1582 PciIoDevice
->PciBar
[BarIndex
].Length
= PciIoDevice
->PciBar
[BarIndex
].Length
| LShiftU64 ((UINT64
) Value
, 32);
1583 PciIoDevice
->PciBar
[BarIndex
].Length
= (~(PciIoDevice
->PciBar
[BarIndex
].Length
)) + 1;
1584 PciIoDevice
->PciBar
[BarIndex
].Alignment
= PciIoDevice
->PciBar
[BarIndex
].Length
- 1;
1592 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypeUnknown
;
1593 PciIoDevice
->PciBar
[BarIndex
].Length
= (~(Value
& Mask
)) + 1;
1594 PciIoDevice
->PciBar
[BarIndex
].Alignment
= PciIoDevice
->PciBar
[BarIndex
].Length
- 1;
1601 // Check the length again so as to keep compatible with some special bars
1603 if (PciIoDevice
->PciBar
[BarIndex
].Length
== 0) {
1604 PciIoDevice
->PciBar
[BarIndex
].BarType
= PciBarTypeUnknown
;
1605 PciIoDevice
->PciBar
[BarIndex
].BaseAddress
= 0;
1606 PciIoDevice
->PciBar
[BarIndex
].Alignment
= 0;
1610 // Increment number of bar
1616 InitializePciDevice (
1617 IN PCI_IO_DEVICE
*PciIoDevice
1621 Routine Description:
1623 This routine is used to initialize the bar of a PCI device
1624 It can be called typically when a device is going to be rejected
1633 // TODO: PciIoDevice - add argument and description to function comment
1634 // TODO: EFI_SUCCESS - add return value to function comment
1636 EFI_PCI_IO_PROTOCOL
*PciIo
;
1639 PciIo
= &(PciIoDevice
->PciIo
);
1642 // Put all the resource apertures
1643 // Resource base is set to all ones so as to indicate its resource
1644 // has not been alloacted
1646 for (Offset
= 0x10; Offset
<= 0x24; Offset
+= sizeof (UINT32
)) {
1647 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, Offset
, 1, &gAllOne
);
1655 IN PCI_IO_DEVICE
*PciIoDevice
1659 Routine Description:
1668 // TODO: PciIoDevice - add argument and description to function comment
1669 // TODO: EFI_SUCCESS - add return value to function comment
1671 EFI_PCI_IO_PROTOCOL
*PciIo
;
1673 PciIo
= &(PciIoDevice
->PciIo
);
1676 // Put all the resource apertures including IO16
1677 // Io32, pMem32, pMem64 to quiescent state
1678 // Resource base all ones, Resource limit all zeros
1680 PciIoWrite (PciIo
, EfiPciIoWidthUint8
, 0x1C, 1, &gAllOne
);
1681 PciIoWrite (PciIo
, EfiPciIoWidthUint8
, 0x1D, 1, &gAllZero
);
1683 PciIoWrite (PciIo
, EfiPciIoWidthUint16
, 0x20, 1, &gAllOne
);
1684 PciIoWrite (PciIo
, EfiPciIoWidthUint16
, 0x22, 1, &gAllZero
);
1686 PciIoWrite (PciIo
, EfiPciIoWidthUint16
, 0x24, 1, &gAllOne
);
1687 PciIoWrite (PciIo
, EfiPciIoWidthUint16
, 0x26, 1, &gAllZero
);
1689 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x28, 1, &gAllOne
);
1690 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x2C, 1, &gAllZero
);
1693 // don't support use io32 as for now
1695 PciIoWrite (PciIo
, EfiPciIoWidthUint16
, 0x30, 1, &gAllOne
);
1696 PciIoWrite (PciIo
, EfiPciIoWidthUint16
, 0x32, 1, &gAllZero
);
1699 // Force Interrupt line to zero for cards that come up randomly
1701 PciIoWrite (PciIo
, EfiPciIoWidthUint8
, 0x3C, 1, &gAllZero
);
1708 IN PCI_IO_DEVICE
*PciIoDevice
1712 Routine Description:
1721 // TODO: PciIoDevice - add argument and description to function comment
1722 // TODO: EFI_SUCCESS - add return value to function comment
1724 EFI_PCI_IO_PROTOCOL
*PciIo
;
1726 PciIo
= &(PciIoDevice
->PciIo
);
1729 // Put all the resource apertures including IO16
1730 // Io32, pMem32, pMem64 to quiescent state(
1731 // Resource base all ones, Resource limit all zeros
1733 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x1c, 1, &gAllOne
);
1734 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x20, 1, &gAllZero
);
1736 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x24, 1, &gAllOne
);
1737 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x28, 1, &gAllZero
);
1739 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x2c, 1, &gAllOne
);
1740 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x30, 1, &gAllZero
);
1742 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x34, 1, &gAllOne
);
1743 PciIoWrite (PciIo
, EfiPciIoWidthUint32
, 0x38, 1, &gAllZero
);
1746 // Force Interrupt line to zero for cards that come up randomly
1748 PciIoWrite (PciIo
, EfiPciIoWidthUint8
, 0x3C, 1, &gAllZero
);
1754 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
,
1762 Routine Description:
1771 // TODO: PciRootBridgeIo - add argument and description to function comment
1772 // TODO: Pci - add argument and description to function comment
1773 // TODO: Bus - add argument and description to function comment
1774 // TODO: Device - add argument and description to function comment
1775 // TODO: Func - add argument and description to function comment
1779 PCI_IO_DEVICE
*PciIoDevice
;
1783 Status
= gBS
->AllocatePool (
1784 EfiBootServicesData
,
1785 sizeof (PCI_IO_DEVICE
),
1786 (VOID
**) &PciIoDevice
1789 if (EFI_ERROR (Status
)) {
1793 ZeroMem (PciIoDevice
, sizeof (PCI_IO_DEVICE
));
1795 PciIoDevice
->Signature
= PCI_IO_DEVICE_SIGNATURE
;
1796 PciIoDevice
->Handle
= NULL
;
1797 PciIoDevice
->PciRootBridgeIo
= PciRootBridgeIo
;
1798 PciIoDevice
->DevicePath
= NULL
;
1799 PciIoDevice
->BusNumber
= Bus
;
1800 PciIoDevice
->DeviceNumber
= Device
;
1801 PciIoDevice
->FunctionNumber
= Func
;
1802 PciIoDevice
->Decodes
= 0;
1803 if (gFullEnumeration
) {
1804 PciIoDevice
->Allocated
= FALSE
;
1806 PciIoDevice
->Allocated
= TRUE
;
1809 PciIoDevice
->Registered
= FALSE
;
1810 PciIoDevice
->Attributes
= 0;
1811 PciIoDevice
->Supports
= 0;
1812 PciIoDevice
->BusOverride
= FALSE
;
1813 PciIoDevice
->AllOpRomProcessed
= FALSE
;
1815 PciIoDevice
->IsPciExp
= FALSE
;
1817 CopyMem (&(PciIoDevice
->Pci
), Pci
, sizeof (PCI_TYPE01
));
1820 // Initialize the PCI I/O instance structure
1823 Status
= InitializePciIoInstance (PciIoDevice
);
1824 Status
= InitializePciDriverOverrideInstance (PciIoDevice
);
1826 if (EFI_ERROR (Status
)) {
1827 gBS
->FreePool (PciIoDevice
);
1832 // Initialize the reserved resource list
1834 InitializeListHead (&PciIoDevice
->ReservedResourceList
);
1837 // Initialize the driver list
1839 InitializeListHead (&PciIoDevice
->OptionRomDriverList
);
1842 // Initialize the child list
1844 InitializeListHead (&PciIoDevice
->ChildList
);
1850 PciEnumeratorLight (
1851 IN EFI_HANDLE Controller
1855 Routine Description:
1857 This routine is used to enumerate entire pci bus system
1867 // TODO: Controller - add argument and description to function comment
1868 // TODO: EFI_SUCCESS - add return value to function comment
1869 // TODO: EFI_SUCCESS - add return value to function comment
1873 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
1874 PCI_IO_DEVICE
*RootBridgeDev
;
1877 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Descriptors
;
1880 MaxBus
= PCI_MAX_BUS
;
1884 // If this host bridge has been already enumerated, then return successfully
1886 if (RootBridgeExisted (Controller
)) {
1891 // Open pci root bridge io protocol
1893 Status
= gBS
->OpenProtocol (
1895 &gEfiPciRootBridgeIoProtocolGuid
,
1896 (VOID
**) &PciRootBridgeIo
,
1897 gPciBusDriverBinding
.DriverBindingHandle
,
1899 EFI_OPEN_PROTOCOL_BY_DRIVER
1901 if (EFI_ERROR (Status
) && Status
!= EFI_ALREADY_STARTED
) {
1905 Status
= PciRootBridgeIo
->Configuration (PciRootBridgeIo
, (VOID
**) &Descriptors
);
1907 if (EFI_ERROR (Status
)) {
1911 while (PciGetBusRange (&Descriptors
, &MinBus
, &MaxBus
, NULL
) == EFI_SUCCESS
) {
1914 // Create a device node for root bridge device with a NULL host bridge controller handle
1916 RootBridgeDev
= CreateRootBridge (Controller
);
1918 if (!RootBridgeDev
) {
1924 // Record the root bridge io protocol
1926 RootBridgeDev
->PciRootBridgeIo
= PciRootBridgeIo
;
1928 Status
= PciPciDeviceInfoCollector (
1933 if (!EFI_ERROR (Status
)) {
1936 // Remove those PCI devices which are rejected when full enumeration
1938 RemoveRejectedPciDevices (RootBridgeDev
->Handle
, RootBridgeDev
);
1941 // Process option rom light
1943 ProcessOptionRomLight (RootBridgeDev
);
1946 // Determine attributes for all devices under this root bridge
1948 DetermineDeviceAttribute (RootBridgeDev
);
1951 // If successfully, insert the node into device pool
1953 InsertRootBridge (RootBridgeDev
);
1957 // If unsuccessly, destroy the entire node
1959 DestroyRootBridge (RootBridgeDev
);
1970 IN EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
**Descriptors
,
1973 OUT UINT16
*BusRange
1977 Routine Description:
1983 Descriptors - A pointer to the address space descriptor.
1984 MinBus - The min bus.
1985 MaxBus - The max bus.
1986 BusRange - The bus range.
1993 // TODO: EFI_SUCCESS - add return value to function comment
1994 // TODO: EFI_NOT_FOUND - add return value to function comment
1997 while ((*Descriptors
)->Desc
!= ACPI_END_TAG_DESCRIPTOR
) {
1998 if ((*Descriptors
)->ResType
== ACPI_ADDRESS_SPACE_TYPE_BUS
) {
1999 if (MinBus
!= NULL
) {
2000 *MinBus
= (UINT16
) (*Descriptors
)->AddrRangeMin
;
2003 if (MaxBus
!= NULL
) {
2004 *MaxBus
= (UINT16
) (*Descriptors
)->AddrRangeMax
;
2007 if (BusRange
!= NULL
) {
2008 *BusRange
= (UINT16
) (*Descriptors
)->AddrLen
;
2017 return EFI_NOT_FOUND
;
2021 StartManagingRootBridge (
2022 IN PCI_IO_DEVICE
*RootBridgeDev
2026 Routine Description:
2036 // TODO: RootBridgeDev - add argument and description to function comment
2037 // TODO: EFI_SUCCESS - add return value to function comment
2039 EFI_HANDLE RootBridgeHandle
;
2041 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
2044 // Get the root bridge handle
2046 RootBridgeHandle
= RootBridgeDev
->Handle
;
2047 PciRootBridgeIo
= NULL
;
2050 // Get the pci root bridge io protocol
2052 Status
= gBS
->OpenProtocol (
2054 &gEfiPciRootBridgeIoProtocolGuid
,
2055 (VOID
**) &PciRootBridgeIo
,
2056 gPciBusDriverBinding
.DriverBindingHandle
,
2058 EFI_OPEN_PROTOCOL_BY_DRIVER
2061 if (EFI_ERROR (Status
) && Status
!= EFI_ALREADY_STARTED
) {
2066 // Store the PciRootBridgeIo protocol into root bridge private data
2068 RootBridgeDev
->PciRootBridgeIo
= PciRootBridgeIo
;
2075 IsPciDeviceRejected (
2076 IN PCI_IO_DEVICE
*PciIoDevice
2080 Routine Description:
2082 This routine can be used to check whether a PCI device should be rejected when light enumeration
2088 TRUE This device should be rejected
2089 FALSE This device shouldn't be rejected
2092 // TODO: PciIoDevice - add argument and description to function comment
2101 // PPB should be skip!
2103 if (IS_PCI_BRIDGE (&PciIoDevice
->Pci
)) {
2107 if (IS_CARDBUS_BRIDGE (&PciIoDevice
->Pci
)) {
2109 // Only test base registers for P2C
2111 for (BarOffset
= 0x1C; BarOffset
<= 0x38; BarOffset
+= 2 * sizeof (UINT32
)) {
2113 Mask
= (BarOffset
< 0x2C) ? 0xFFFFF000 : 0xFFFFFFFC;
2114 Status
= BarExisted (PciIoDevice
, BarOffset
, &TestValue
, &OldValue
);
2115 if (EFI_ERROR (Status
)) {
2119 TestValue
= TestValue
& Mask
;
2120 if ((TestValue
!= 0) && (TestValue
== (OldValue
& Mask
))) {
2122 // The bar isn't programed, so it should be rejected
2131 for (BarOffset
= 0x14; BarOffset
<= 0x24; BarOffset
+= sizeof (UINT32
)) {
2135 Status
= BarExisted (PciIoDevice
, BarOffset
, &TestValue
, &OldValue
);
2136 if (EFI_ERROR (Status
)) {
2140 if (TestValue
& 0x01) {
2147 TestValue
= TestValue
& Mask
;
2148 if ((TestValue
!= 0) && (TestValue
== (OldValue
& Mask
))) {
2159 TestValue
= TestValue
& Mask
;
2161 if ((TestValue
& 0x07) == 0x04) {
2166 BarOffset
+= sizeof (UINT32
);
2167 if ((TestValue
!= 0) && (TestValue
== (OldValue
& Mask
))) {
2170 // Test its high 32-Bit BAR
2173 Status
= BarExisted (PciIoDevice
, BarOffset
, &TestValue
, &OldValue
);
2174 if (TestValue
== OldValue
) {
2184 if ((TestValue
!= 0) && (TestValue
== (OldValue
& Mask
))) {
2195 ResetAllPpbBusNumber (
2196 IN PCI_IO_DEVICE
*Bridge
,
2197 IN UINT8 StartBusNumber
2201 Routine Description:
2203 TODO: Add function description
2207 Bridge - TODO: add argument description
2208 StartBusNumber - TODO: add argument description
2212 EFI_SUCCESS - TODO: Add description for return value
2223 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
2225 PciRootBridgeIo
= Bridge
->PciRootBridgeIo
;
2227 for (Device
= 0; Device
<= PCI_MAX_DEVICE
; Device
++) {
2228 for (Func
= 0; Func
<= PCI_MAX_FUNC
; Func
++) {
2231 // Check to see whether a pci device is present
2233 Status
= PciDevicePresent (
2241 if (!EFI_ERROR (Status
) && (IS_PCI_BRIDGE (&Pci
))) {
2244 Address
= EFI_PCI_ADDRESS (StartBusNumber
, Device
, Func
, 0x18);
2245 Status
= PciRootBridgeIoRead (
2253 SecondaryBus
= (UINT8
)(Register
>> 8);
2255 if (SecondaryBus
!= 0) {
2256 ResetAllPpbBusNumber (Bridge
, SecondaryBus
);
2260 // Reset register 18h, 19h, 1Ah on PCI Bridge
2262 Register
&= 0xFF000000;
2263 Status
= PciRootBridgeIoWrite (
2273 if (Func
== 0 && !IS_PCI_MULTI_FUNC (&Pci
)) {
2275 // Skip sub functions, this is not a multi function device
2277 Func
= PCI_MAX_FUNC
;