3 Copyright (c) 2006 - 2009, 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 "PciEnumerator.h"
17 #include "PciOptionRomSupport.h"
20 This routine is used to enumerate entire pci bus system
23 @param Controller Parent controller handle.
25 @return Status of enumerating.
29 IN EFI_HANDLE Controller
33 EFI_HANDLE HostBridgeHandle
;
35 EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*PciResAlloc
;
36 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
39 // If PCI bus has already done the full enumeration, never do it again
41 if (!gFullEnumeration
) {
42 return PciEnumeratorLight (Controller
);
46 // Get the rootbridge Io protocol to find the host bridge handle
48 Status
= gBS
->OpenProtocol (
50 &gEfiPciRootBridgeIoProtocolGuid
,
51 (VOID
**) &PciRootBridgeIo
,
52 gPciBusDriverBinding
.DriverBindingHandle
,
54 EFI_OPEN_PROTOCOL_GET_PROTOCOL
57 if (EFI_ERROR (Status
)) {
62 // Get the host bridge handle
64 HostBridgeHandle
= PciRootBridgeIo
->ParentHandle
;
67 // Get the pci host bridge resource allocation protocol
69 Status
= gBS
->OpenProtocol (
71 &gEfiPciHostBridgeResourceAllocationProtocolGuid
,
72 (VOID
**) &PciResAlloc
,
73 gPciBusDriverBinding
.DriverBindingHandle
,
75 EFI_OPEN_PROTOCOL_GET_PROTOCOL
78 if (EFI_ERROR (Status
)) {
83 // Notify the pci bus enumeration is about to begin
85 NotifyPhase (PciResAlloc
, EfiPciHostBridgeBeginEnumeration
);
88 // Start the bus allocation phase
90 Status
= PciHostBridgeEnumerator (PciResAlloc
);
92 if (EFI_ERROR (Status
)) {
97 // Submit the resource request
99 Status
= PciHostBridgeResourceAllocator (PciResAlloc
);
101 if (EFI_ERROR (Status
)) {
108 Status
= PciHostBridgeP2CProcess (PciResAlloc
);
110 if (EFI_ERROR (Status
)) {
115 // Process attributes for devices on this host bridge
117 Status
= PciHostBridgeDeviceAttribute (PciResAlloc
);
118 if (EFI_ERROR (Status
)) {
122 gFullEnumeration
= FALSE
;
128 Enumerate PCI root bridge
130 @param PciResAlloc Pointer to protocol instance of EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL.
131 @param RootBridgeDev Instance of root bridge device.
133 @retval EFI_SUCCESS Success to enumerate root bridge.
134 @retval Others Fail to enumerate root bridge.
138 PciRootBridgeEnumerator (
139 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*PciResAlloc
,
140 IN PCI_IO_DEVICE
*RootBridgeDev
144 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Configuration
;
146 UINT8 StartBusNumber
;
147 UINT8 PaddedBusRange
;
148 EFI_HANDLE RootBridgeHandle
;
155 // Get the root bridge handle
157 RootBridgeHandle
= RootBridgeDev
->Handle
;
159 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
161 EFI_IO_BUS_PCI
| EFI_IOB_PCI_PC_BUS_ENUM
,
162 RootBridgeDev
->DevicePath
166 // Get the Bus information
168 Status
= PciResAlloc
->StartBusEnumeration (
171 (VOID
**) &Configuration
174 if (EFI_ERROR (Status
)) {
179 // Get the bus number to start with
181 StartBusNumber
= (UINT8
) (Configuration
->AddrRangeMin
);
182 PaddedBusRange
= (UINT8
) (Configuration
->AddrRangeMax
);
185 // Initialize the subordinate bus number
187 SubBusNumber
= StartBusNumber
;
190 // Reset all assigned PCI bus number
192 ResetAllPpbBusNumber (
200 Status
= PciScanBus (
202 (UINT8
) (Configuration
->AddrRangeMin
),
207 if (EFI_ERROR (Status
)) {
213 // Assign max bus number scanned
215 Configuration
->AddrLen
= SubBusNumber
- StartBusNumber
+ 1 + PaddedBusRange
;
220 Status
= PciResAlloc
->SetBusNumbers (
226 gBS
->FreePool (Configuration
);
228 if (EFI_ERROR (Status
)) {
236 This routine is used to process option rom on a certain root bridge
238 @param Bridge Given parent's root bridge
239 @param RomBase Base address of ROM driver loaded from
240 @param MaxLength Max rom size
242 @retval EFI_SUCCESS Success to process option rom image.
246 IN PCI_IO_DEVICE
*Bridge
,
251 LIST_ENTRY
*CurrentLink
;
255 // Go through bridges to reach all devices
257 CurrentLink
= Bridge
->ChildList
.ForwardLink
;
258 while (CurrentLink
!= NULL
&& CurrentLink
!= &Bridge
->ChildList
) {
259 Temp
= PCI_IO_DEVICE_FROM_LINK (CurrentLink
);
260 if (!IsListEmpty (&Temp
->ChildList
)) {
263 // Go further to process the option rom under this bridge
265 ProcessOptionRom (Temp
, RomBase
, MaxLength
);
268 if (Temp
->RomSize
!= 0 && Temp
->RomSize
<= MaxLength
) {
271 // Load and process the option rom
273 LoadOpRomImage (Temp
, RomBase
);
276 CurrentLink
= CurrentLink
->ForwardLink
;
283 This routine is used to assign bus number to the given PCI bus system
285 @param Bridge Parent root bridge instance.
286 @param StartBusNumber Number of beginning.
287 @param SubBusNumber the number of sub bus.
289 @retval EFI_SUCCESS Success to assign bus number.
293 IN PCI_IO_DEVICE
*Bridge
,
294 IN UINT8 StartBusNumber
,
295 OUT UINT8
*SubBusNumber
306 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
308 PciRootBridgeIo
= Bridge
->PciRootBridgeIo
;
313 *SubBusNumber
= StartBusNumber
;
316 // First check to see whether the parent is ppb
318 for (Device
= 0; Device
<= PCI_MAX_DEVICE
; Device
++) {
319 for (Func
= 0; Func
<= PCI_MAX_FUNC
; Func
++) {
322 // Check to see whether a pci device is present
325 Status
= PciDevicePresent (
333 if (!EFI_ERROR (Status
) &&
334 (IS_PCI_BRIDGE (&Pci
) || IS_CARDBUS_BRIDGE (&Pci
))) {
337 // Reserved one bus for cardbus bridge
339 SecondBus
= ++(*SubBusNumber
);
341 Register
= (UINT16
) ((SecondBus
<< 8) | (UINT16
) StartBusNumber
);
343 Address
= EFI_PCI_ADDRESS (StartBusNumber
, Device
, Func
, 0x18);
345 Status
= PciRootBridgeIoWrite (
355 // Initialize SubBusNumber to SecondBus
357 Address
= EFI_PCI_ADDRESS (StartBusNumber
, Device
, Func
, 0x1A);
358 Status
= PciRootBridgeIoWrite (
367 // If it is PPB, resursively search down this bridge
369 if (IS_PCI_BRIDGE (&Pci
)) {
372 Status
= PciRootBridgeIoWrite (
381 Status
= PciAssignBusNumber (
387 if (EFI_ERROR (Status
)) {
388 return EFI_DEVICE_ERROR
;
393 // Set the current maximum bus number under the PPB
396 Address
= EFI_PCI_ADDRESS (StartBusNumber
, Device
, Func
, 0x1A);
398 Status
= PciRootBridgeIoWrite (
409 if (Func
== 0 && !IS_PCI_MULTI_FUNC (&Pci
)) {
412 // Skip sub functions, this is not a multi function device
424 This routine is used to determine the root bridge attribute by interfacing
425 the host bridge resource allocation protocol.
427 @param PciResAlloc Protocol instance of EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
428 @param RootBridgeDev Root bridge instance
430 @retval EFI_SUCCESS Success to get root bridge's attribute
431 @retval Others Fail to get attribute
434 DetermineRootBridgeAttributes (
435 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*PciResAlloc
,
436 IN PCI_IO_DEVICE
*RootBridgeDev
441 EFI_HANDLE RootBridgeHandle
;
444 RootBridgeHandle
= RootBridgeDev
->Handle
;
447 // Get root bridge attribute by calling into pci host bridge resource allocation protocol
449 Status
= PciResAlloc
->GetAllocAttributes (
455 if (EFI_ERROR (Status
)) {
460 // Here is the point where PCI bus driver calls HOST bridge allocation protocol
461 // Currently we hardcoded for ea815
464 if ((Attributes
& EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM
) != 0) {
465 RootBridgeDev
->Decodes
|= EFI_BRIDGE_PMEM_MEM_COMBINE_SUPPORTED
;
468 if ((Attributes
& EFI_PCI_HOST_BRIDGE_MEM64_DECODE
) != 0) {
469 RootBridgeDev
->Decodes
|= EFI_BRIDGE_PMEM64_DECODE_SUPPORTED
;
472 RootBridgeDev
->Decodes
|= EFI_BRIDGE_MEM32_DECODE_SUPPORTED
;
473 RootBridgeDev
->Decodes
|= EFI_BRIDGE_PMEM32_DECODE_SUPPORTED
;
474 RootBridgeDev
->Decodes
|= EFI_BRIDGE_IO16_DECODE_SUPPORTED
;
480 Get Max Option Rom size on this bridge
482 @param Bridge Bridge device instance.
483 @return Max size of option rom.
486 GetMaxOptionRomSize (
487 IN PCI_IO_DEVICE
*Bridge
490 LIST_ENTRY
*CurrentLink
;
492 UINT64 MaxOptionRomSize
;
493 UINT64 TempOptionRomSize
;
495 MaxOptionRomSize
= 0;
498 // Go through bridges to reach all devices
500 CurrentLink
= Bridge
->ChildList
.ForwardLink
;
501 while (CurrentLink
!= NULL
&& CurrentLink
!= &Bridge
->ChildList
) {
502 Temp
= PCI_IO_DEVICE_FROM_LINK (CurrentLink
);
503 if (!IsListEmpty (&Temp
->ChildList
)) {
506 // Get max option rom size under this bridge
508 TempOptionRomSize
= GetMaxOptionRomSize (Temp
);
511 // Compare with the option rom size of the bridge
512 // Get the larger one
514 if (Temp
->RomSize
> TempOptionRomSize
) {
515 TempOptionRomSize
= Temp
->RomSize
;
521 // For devices get the rom size directly
523 TempOptionRomSize
= Temp
->RomSize
;
527 // Get the largest rom size on this bridge
529 if (TempOptionRomSize
> MaxOptionRomSize
) {
530 MaxOptionRomSize
= TempOptionRomSize
;
533 CurrentLink
= CurrentLink
->ForwardLink
;
536 return MaxOptionRomSize
;
540 Process attributes of devices on this host bridge
542 @param PciResAlloc Protocol instance of EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL.
544 @retval EFI_NOT_FOUND Can not find the specific root bridge device.
545 @retval EFI_SUCCESS Success Process attribute.
546 @retval Others Can not determine the root bridge device's attribute.
549 PciHostBridgeDeviceAttribute (
550 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*PciResAlloc
553 EFI_HANDLE RootBridgeHandle
;
554 PCI_IO_DEVICE
*RootBridgeDev
;
557 RootBridgeHandle
= NULL
;
559 while (PciResAlloc
->GetNextRootBridge (PciResAlloc
, &RootBridgeHandle
) == EFI_SUCCESS
) {
562 // Get RootBridg Device by handle
564 RootBridgeDev
= GetRootBridgeByHandle (RootBridgeHandle
);
566 if (RootBridgeDev
== NULL
) {
567 return EFI_NOT_FOUND
;
571 // Set the attributes for devcies behind the Root Bridge
573 Status
= DetermineDeviceAttribute (RootBridgeDev
);
574 if (EFI_ERROR (Status
)) {
584 Get resource allocation status from the ACPI pointer
586 @param AcpiConfig Point to Acpi configuration table
587 @param IoResStatus Return the status of I/O resource
588 @param Mem32ResStatus Return the status of 32-bit Memory resource
589 @param PMem32ResStatus Return the status of 32-bit PMemory resource
590 @param Mem64ResStatus Return the status of 64-bit Memory resource
591 @param PMem64ResStatus Return the status of 64-bit PMemory resource
593 @retval EFI_SUCCESS Success to get resource allocation status from ACPI configuration table.
596 GetResourceAllocationStatus (
598 OUT UINT64
*IoResStatus
,
599 OUT UINT64
*Mem32ResStatus
,
600 OUT UINT64
*PMem32ResStatus
,
601 OUT UINT64
*Mem64ResStatus
,
602 OUT UINT64
*PMem64ResStatus
608 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*ACPIAddressDesc
;
610 Temp
= (UINT8
*) AcpiConfig
;
612 while (*Temp
== ACPI_ADDRESS_SPACE_DESCRIPTOR
) {
614 ACPIAddressDesc
= (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Temp
;
615 ResStatus
= ACPIAddressDesc
->AddrTranslationOffset
;
617 switch (ACPIAddressDesc
->ResType
) {
619 if (ACPIAddressDesc
->AddrSpaceGranularity
== 32) {
620 if (ACPIAddressDesc
->SpecificFlag
== 0x06) {
624 *PMem32ResStatus
= ResStatus
;
629 *Mem32ResStatus
= ResStatus
;
633 if (ACPIAddressDesc
->AddrSpaceGranularity
== 64) {
634 if (ACPIAddressDesc
->SpecificFlag
== 0x06) {
638 *PMem64ResStatus
= ResStatus
;
643 *Mem64ResStatus
= ResStatus
;
653 *IoResStatus
= ResStatus
;
660 Temp
+= sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
);
667 Remove a PCI device from device pool and mark its bar
669 @param PciDevice Instance of Pci device.
671 @retval EFI_SUCCESS Success Operation.
672 @retval EFI_ABORTED Pci device is a root bridge.
676 IN PCI_IO_DEVICE
*PciDevice
679 PCI_IO_DEVICE
*Bridge
;
681 LIST_ENTRY
*CurrentLink
;
684 // Remove the padding resource from a bridge
686 if ( IS_PCI_BRIDGE(&PciDevice
->Pci
) && \
687 PciDevice
->ResourcePaddingDescriptors
!= NULL
) {
688 gBS
->FreePool (PciDevice
->ResourcePaddingDescriptors
);
689 PciDevice
->ResourcePaddingDescriptors
= NULL
;
696 if (IS_PCI_BRIDGE (&PciDevice
->Pci
) || (PciDevice
->Parent
== NULL
)) {
700 if (IS_CARDBUS_BRIDGE (&PciDevice
->Pci
)) {
702 // Get the root bridge device
705 while (Bridge
->Parent
!= NULL
) {
706 Bridge
= Bridge
->Parent
;
709 RemoveAllPciDeviceOnBridge (Bridge
->Handle
, PciDevice
);
714 InitializeP2C (PciDevice
);
720 Bridge
= PciDevice
->Parent
;
721 CurrentLink
= Bridge
->ChildList
.ForwardLink
;
722 while (CurrentLink
!= NULL
&& CurrentLink
!= &Bridge
->ChildList
) {
723 Temp
= PCI_IO_DEVICE_FROM_LINK (CurrentLink
);
724 if (Temp
== PciDevice
) {
725 InitializePciDevice (Temp
);
726 RemoveEntryList (CurrentLink
);
727 FreePciDevice (Temp
);
731 CurrentLink
= CurrentLink
->ForwardLink
;
738 Determine whethter a PCI device can be rejected.
740 @param PciResNode Pointer to Pci resource node instance.
742 @return whethter a PCI device can be rejected.
746 IN PCI_RESOURCE_NODE
*PciResNode
751 Temp
= PciResNode
->PciDev
;
754 // Ensure the device is present
761 // PPB and RB should go ahead
763 if (IS_PCI_BRIDGE (&Temp
->Pci
) || (Temp
->Parent
== NULL
)) {
768 // Skip device on Bus0
770 if ((Temp
->Parent
!= NULL
) && (Temp
->BusNumber
== 0)) {
777 if (IS_PCI_VGA (&Temp
->Pci
)) {
785 Compare two resource node and get the larger resource consumer
787 @param PciResNode1 resource node 1 want to be compared
788 @param PciResNode2 resource node 2 want to be compared
790 @return Larger resource consumer.
793 GetLargerConsumerDevice (
794 IN PCI_RESOURCE_NODE
*PciResNode1
,
795 IN PCI_RESOURCE_NODE
*PciResNode2
798 if (PciResNode2
== NULL
) {
802 if ((IS_PCI_BRIDGE(&(PciResNode2
->PciDev
->Pci
)) || (PciResNode2
->PciDev
->Parent
== NULL
)) \
803 && (PciResNode2
->ResourceUsage
!= PciResUsagePadding
) )
808 if (PciResNode1
== NULL
) {
812 if ((PciResNode1
->Length
) > (PciResNode2
->Length
)) {
822 Get the max resource consumer in the host resource pool.
824 @param ResPool Pointer to resource pool node.
826 @return the max resource consumer in the host resource pool.
829 GetMaxResourceConsumerDevice (
830 IN PCI_RESOURCE_NODE
*ResPool
833 PCI_RESOURCE_NODE
*Temp
;
834 LIST_ENTRY
*CurrentLink
;
835 PCI_RESOURCE_NODE
*PciResNode
;
836 PCI_RESOURCE_NODE
*PPBResNode
;
840 CurrentLink
= ResPool
->ChildList
.ForwardLink
;
841 while (CurrentLink
!= NULL
&& CurrentLink
!= &ResPool
->ChildList
) {
843 Temp
= RESOURCE_NODE_FROM_LINK (CurrentLink
);
845 if (!IsRejectiveDevice (Temp
)) {
846 CurrentLink
= CurrentLink
->ForwardLink
;
850 if ((IS_PCI_BRIDGE (&(Temp
->PciDev
->Pci
)) || (Temp
->PciDev
->Parent
== NULL
)) \
851 && (Temp
->ResourceUsage
!= PciResUsagePadding
))
853 PPBResNode
= GetMaxResourceConsumerDevice (Temp
);
854 PciResNode
= GetLargerConsumerDevice (PciResNode
, PPBResNode
);
856 PciResNode
= GetLargerConsumerDevice (PciResNode
, Temp
);
859 CurrentLink
= CurrentLink
->ForwardLink
;
866 Adjust host bridge allocation so as to reduce resource requirement
868 @param IoPool Pointer to instance of I/O resource Node.
869 @param Mem32Pool Pointer to instance of 32-bit memory resource Node.
870 @param PMem32Pool Pointer to instance of 32-bit Pmemory resource node.
871 @param Mem64Pool Pointer to instance of 64-bit memory resource node.
872 @param PMem64Pool Pointer to instance of 64-bit Pmemory resource node.
873 @param IoResStatus Status of I/O resource Node.
874 @param Mem32ResStatus Status of 32-bit memory resource Node.
875 @param PMem32ResStatus Status of 32-bit Pmemory resource node.
876 @param Mem64ResStatus Status of 64-bit memory resource node.
877 @param PMem64ResStatus Status of 64-bit Pmemory resource node.
880 PciHostBridgeAdjustAllocation (
881 IN PCI_RESOURCE_NODE
*IoPool
,
882 IN PCI_RESOURCE_NODE
*Mem32Pool
,
883 IN PCI_RESOURCE_NODE
*PMem32Pool
,
884 IN PCI_RESOURCE_NODE
*Mem64Pool
,
885 IN PCI_RESOURCE_NODE
*PMem64Pool
,
886 IN UINT64 IoResStatus
,
887 IN UINT64 Mem32ResStatus
,
888 IN UINT64 PMem32ResStatus
,
889 IN UINT64 Mem64ResStatus
,
890 IN UINT64 PMem64ResStatus
893 BOOLEAN AllocationAjusted
;
894 PCI_RESOURCE_NODE
*PciResNode
;
895 PCI_RESOURCE_NODE
*ResPool
[5];
896 PCI_IO_DEVICE
*RemovedPciDev
[5];
898 UINTN RemovedPciDevNum
;
902 EFI_RESOURCE_ALLOC_FAILURE_ERROR_DATA_PAYLOAD AllocFailExtendedData
;
905 ZeroMem (RemovedPciDev
, 5 * sizeof (PCI_IO_DEVICE
*));
906 RemovedPciDevNum
= 0;
909 ResPool
[1] = Mem32Pool
;
910 ResPool
[2] = PMem32Pool
;
911 ResPool
[3] = Mem64Pool
;
912 ResPool
[4] = PMem64Pool
;
914 ResStatus
[0] = IoResStatus
;
915 ResStatus
[1] = Mem32ResStatus
;
916 ResStatus
[2] = PMem32ResStatus
;
917 ResStatus
[3] = Mem64ResStatus
;
918 ResStatus
[4] = PMem64ResStatus
;
920 AllocationAjusted
= FALSE
;
922 for (ResType
= 0; ResType
< 5; ResType
++) {
924 if (ResStatus
[ResType
] == EFI_RESOURCE_SATISFIED
) {
928 if (ResStatus
[ResType
] == EFI_RESOURCE_NOT_SATISFIED
) {
930 // Hostbridge hasn't this resource type
936 // Hostbridge hasn't enough resource
938 PciResNode
= GetMaxResourceConsumerDevice (ResPool
[ResType
]);
939 if (PciResNode
== NULL
) {
944 // Check if the device has been removed before
946 for (DevIndex
= 0; DevIndex
< RemovedPciDevNum
; DevIndex
++) {
947 if (PciResNode
->PciDev
== RemovedPciDev
[DevIndex
]) {
952 if (DevIndex
!= RemovedPciDevNum
) {
957 // Remove the device if it isn't in the array
959 Status
= RejectPciDevice (PciResNode
->PciDev
);
960 if (Status
== EFI_SUCCESS
) {
963 // Raise the EFI_IOB_EC_RESOURCE_CONFLICT status code
966 // Have no way to get ReqRes, AllocRes & Bar here
968 ZeroMem (&AllocFailExtendedData
, sizeof (AllocFailExtendedData
));
969 AllocFailExtendedData
.DevicePathSize
= sizeof (EFI_DEVICE_PATH_PROTOCOL
);
970 AllocFailExtendedData
.DevicePath
= (UINT8
*) PciResNode
->PciDev
->DevicePath
;
971 AllocFailExtendedData
.Bar
= PciResNode
->Bar
;
973 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
975 EFI_IO_BUS_PCI
| EFI_IOB_EC_RESOURCE_CONFLICT
,
976 (VOID
*) &AllocFailExtendedData
,
977 sizeof (AllocFailExtendedData
)
981 // Add it to the array and indicate at least a device has been rejected
983 RemovedPciDev
[RemovedPciDevNum
++] = PciResNode
->PciDev
;
984 AllocationAjusted
= TRUE
;
991 if (AllocationAjusted
) {
999 Summary requests for all resource type, and contruct ACPI resource
1002 @param Bridge detecting bridge
1003 @param IoNode Pointer to instance of I/O resource Node
1004 @param Mem32Node Pointer to instance of 32-bit memory resource Node
1005 @param PMem32Node Pointer to instance of 32-bit Pmemory resource node
1006 @param Mem64Node Pointer to instance of 64-bit memory resource node
1007 @param PMem64Node Pointer to instance of 64-bit Pmemory resource node
1008 @param Config Output buffer holding new constructed APCI resource requestor
1011 ConstructAcpiResourceRequestor (
1012 IN PCI_IO_DEVICE
*Bridge
,
1013 IN PCI_RESOURCE_NODE
*IoNode
,
1014 IN PCI_RESOURCE_NODE
*Mem32Node
,
1015 IN PCI_RESOURCE_NODE
*PMem32Node
,
1016 IN PCI_RESOURCE_NODE
*Mem64Node
,
1017 IN PCI_RESOURCE_NODE
*PMem64Node
,
1023 UINT8
*Configuration
;
1024 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Ptr
;
1025 EFI_ACPI_END_TAG_DESCRIPTOR
*PtrEnd
;
1033 // if there is io request, add to the io aperture
1035 if (ResourceRequestExisted (IoNode
)) {
1041 // if there is mem32 request, add to the mem32 aperture
1043 if (ResourceRequestExisted (Mem32Node
)) {
1049 // if there is pmem32 request, add to the pmem32 aperture
1051 if (ResourceRequestExisted (PMem32Node
)) {
1057 // if there is mem64 request, add to the mem64 aperture
1059 if (ResourceRequestExisted (Mem64Node
)) {
1065 // if there is pmem64 request, add to the pmem64 aperture
1067 if (ResourceRequestExisted (PMem64Node
)) {
1072 if (NumConfig
!= 0) {
1075 // If there is at least one type of resource request,
1076 // allocate a acpi resource node
1078 Configuration
= AllocatePool (sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) * NumConfig
+ sizeof (EFI_ACPI_END_TAG_DESCRIPTOR
));
1079 if (Configuration
== NULL
) {
1080 return EFI_OUT_OF_RESOURCES
;
1085 sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) * NumConfig
+ sizeof (EFI_ACPI_END_TAG_DESCRIPTOR
)
1088 Ptr
= (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Configuration
;
1091 // Deal with io aperture
1093 if ((Aperture
& 0x01) != 0) {
1094 Ptr
->Desc
= ACPI_ADDRESS_SPACE_DESCRIPTOR
;
1095 Ptr
->Len
= sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) - 3;
1099 Ptr
->ResType
= ACPI_ADDRESS_SPACE_TYPE_IO
;
1103 Ptr
->SpecificFlag
= 1;
1104 Ptr
->AddrLen
= IoNode
->Length
;
1105 Ptr
->AddrRangeMax
= IoNode
->Alignment
;
1110 // Deal with mem32 aperture
1112 if ((Aperture
& 0x02) != 0) {
1113 Ptr
->Desc
= ACPI_ADDRESS_SPACE_DESCRIPTOR
;
1114 Ptr
->Len
= sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) - 3;
1118 Ptr
->ResType
= ACPI_ADDRESS_SPACE_TYPE_MEM
;
1122 Ptr
->SpecificFlag
= 0;
1126 Ptr
->AddrSpaceGranularity
= 32;
1127 Ptr
->AddrLen
= Mem32Node
->Length
;
1128 Ptr
->AddrRangeMax
= Mem32Node
->Alignment
;
1134 // Deal with Pmem32 aperture
1136 if ((Aperture
& 0x04) != 0) {
1137 Ptr
->Desc
= ACPI_ADDRESS_SPACE_DESCRIPTOR
;
1138 Ptr
->Len
= sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) - 3;
1142 Ptr
->ResType
= ACPI_ADDRESS_SPACE_TYPE_MEM
;
1146 Ptr
->SpecificFlag
= 0x6;
1150 Ptr
->AddrSpaceGranularity
= 32;
1151 Ptr
->AddrLen
= PMem32Node
->Length
;
1152 Ptr
->AddrRangeMax
= PMem32Node
->Alignment
;
1157 // Deal with mem64 aperture
1159 if ((Aperture
& 0x08) != 0) {
1160 Ptr
->Desc
= ACPI_ADDRESS_SPACE_DESCRIPTOR
;
1161 Ptr
->Len
= sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) - 3;
1165 Ptr
->ResType
= ACPI_ADDRESS_SPACE_TYPE_MEM
;
1169 Ptr
->SpecificFlag
= 0;
1173 Ptr
->AddrSpaceGranularity
= 64;
1174 Ptr
->AddrLen
= Mem64Node
->Length
;
1175 Ptr
->AddrRangeMax
= Mem64Node
->Alignment
;
1180 // Deal with Pmem64 aperture
1182 if ((Aperture
& 0x10) != 0) {
1183 Ptr
->Desc
= ACPI_ADDRESS_SPACE_DESCRIPTOR
;
1184 Ptr
->Len
= sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) - 3;
1188 Ptr
->ResType
= ACPI_ADDRESS_SPACE_TYPE_MEM
;
1192 Ptr
->SpecificFlag
= 0x06;
1196 Ptr
->AddrSpaceGranularity
= 64;
1197 Ptr
->AddrLen
= PMem64Node
->Length
;
1198 Ptr
->AddrRangeMax
= PMem64Node
->Alignment
;
1206 PtrEnd
= (EFI_ACPI_END_TAG_DESCRIPTOR
*) Ptr
;
1208 PtrEnd
->Desc
= ACPI_END_TAG_DESCRIPTOR
;
1209 PtrEnd
->Checksum
= 0;
1214 // If there is no resource request
1216 Configuration
= AllocatePool (sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) + sizeof (EFI_ACPI_END_TAG_DESCRIPTOR
));
1217 if (Configuration
== NULL
) {
1218 return EFI_OUT_OF_RESOURCES
;
1221 ZeroMem (Configuration
, sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) + sizeof (EFI_ACPI_END_TAG_DESCRIPTOR
));
1223 Ptr
= (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) (Configuration
);
1224 Ptr
->Desc
= ACPI_ADDRESS_SPACE_DESCRIPTOR
;
1226 PtrEnd
= (EFI_ACPI_END_TAG_DESCRIPTOR
*) (Ptr
+ 1);
1227 PtrEnd
->Desc
= ACPI_END_TAG_DESCRIPTOR
;
1228 PtrEnd
->Checksum
= 0;
1231 *Config
= Configuration
;
1237 Get resource base from an acpi configuration descriptor.
1239 @param Config an acpi configuration descriptor.
1240 @param IoBase output of I/O resource base address.
1241 @param Mem32Base output of 32-bit memory base address.
1242 @param PMem32Base output of 32-bit pmemory base address.
1243 @param Mem64Base output of 64-bit memory base address.
1244 @param PMem64Base output of 64-bit pmemory base address.
1246 @return EFI_SUCCESS Get resource base address successfully.
1253 OUT UINT64
*Mem32Base
,
1254 OUT UINT64
*PMem32Base
,
1255 OUT UINT64
*Mem64Base
,
1256 OUT UINT64
*PMem64Base
1260 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Ptr
;
1263 ASSERT (Config
!= NULL
);
1265 *IoBase
= 0xFFFFFFFFFFFFFFFFULL
;
1266 *Mem32Base
= 0xFFFFFFFFFFFFFFFFULL
;
1267 *PMem32Base
= 0xFFFFFFFFFFFFFFFFULL
;
1268 *Mem64Base
= 0xFFFFFFFFFFFFFFFFULL
;
1269 *PMem64Base
= 0xFFFFFFFFFFFFFFFFULL
;
1271 Temp
= (UINT8
*) Config
;
1273 while (*Temp
== ACPI_ADDRESS_SPACE_DESCRIPTOR
) {
1275 Ptr
= (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Temp
;
1276 ResStatus
= Ptr
->AddrTranslationOffset
;
1278 if (ResStatus
== EFI_RESOURCE_SATISFIED
) {
1280 switch (Ptr
->ResType
) {
1283 // Memory type aperture
1288 // Check to see the granularity
1290 if (Ptr
->AddrSpaceGranularity
== 32) {
1291 if ((Ptr
->SpecificFlag
& 0x06) != 0) {
1292 *PMem32Base
= Ptr
->AddrRangeMin
;
1294 *Mem32Base
= Ptr
->AddrRangeMin
;
1298 if (Ptr
->AddrSpaceGranularity
== 64) {
1299 if ((Ptr
->SpecificFlag
& 0x06) != 0) {
1300 *PMem64Base
= Ptr
->AddrRangeMin
;
1302 *Mem64Base
= Ptr
->AddrRangeMin
;
1312 *IoBase
= Ptr
->AddrRangeMin
;
1326 Temp
+= sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
);
1333 Enumerate pci bridge, allocate resource and determine attribute
1334 for devices on this bridge
1336 @param BridgeDev Pointer to instance of bridge device.
1338 @retval EFI_SUCCESS Success operation.
1339 @retval Others Fail to enumerate.
1342 PciBridgeEnumerator (
1343 IN PCI_IO_DEVICE
*BridgeDev
1347 UINT8 StartBusNumber
;
1348 EFI_PCI_IO_PROTOCOL
*PciIo
;
1353 PciIo
= &(BridgeDev
->PciIo
);
1354 Status
= PciIoRead (PciIo
, EfiPciIoWidthUint8
, 0x19, 1, &StartBusNumber
);
1356 if (EFI_ERROR (Status
)) {
1360 Status
= PciAssignBusNumber (
1366 if (EFI_ERROR (Status
)) {
1370 Status
= PciPciDeviceInfoCollector (BridgeDev
, StartBusNumber
);
1372 if (EFI_ERROR (Status
)) {
1376 Status
= PciBridgeResourceAllocator (BridgeDev
);
1378 if (EFI_ERROR (Status
)) {
1382 Status
= DetermineDeviceAttribute (BridgeDev
);
1384 if (EFI_ERROR (Status
)) {
1393 Allocate all kinds of resource for bridge
1395 @param Bridge Pointer to bridge instance.
1397 @retval EFI_SUCCESS Success operation.
1398 @retval Others Fail to allocate resource for bridge.
1401 PciBridgeResourceAllocator (
1402 IN PCI_IO_DEVICE
*Bridge
1405 PCI_RESOURCE_NODE
*IoBridge
;
1406 PCI_RESOURCE_NODE
*Mem32Bridge
;
1407 PCI_RESOURCE_NODE
*PMem32Bridge
;
1408 PCI_RESOURCE_NODE
*Mem64Bridge
;
1409 PCI_RESOURCE_NODE
*PMem64Bridge
;
1417 IoBridge
= CreateResourceNode (
1426 Mem32Bridge
= CreateResourceNode (
1435 PMem32Bridge
= CreateResourceNode (
1444 Mem64Bridge
= CreateResourceNode (
1453 PMem64Bridge
= CreateResourceNode (
1463 // Create resourcemap by going through all the devices subject to this root bridge
1465 Status
= CreateResourceMap (
1474 if (EFI_ERROR (Status
)) {
1478 Status
= GetResourceBaseFromBridge (
1487 if (EFI_ERROR (Status
)) {
1492 // Program IO resources
1500 // Program Mem32 resources
1508 // Program PMem32 resources
1516 // Program Mem64 resources
1524 // Program PMem64 resources
1531 DestroyResourceTree (IoBridge
);
1532 DestroyResourceTree (Mem32Bridge
);
1533 DestroyResourceTree (PMem32Bridge
);
1534 DestroyResourceTree (PMem64Bridge
);
1535 DestroyResourceTree (Mem64Bridge
);
1537 gBS
->FreePool (IoBridge
);
1538 gBS
->FreePool (Mem32Bridge
);
1539 gBS
->FreePool (PMem32Bridge
);
1540 gBS
->FreePool (PMem64Bridge
);
1541 gBS
->FreePool (Mem64Bridge
);
1547 Get resource base address for a pci bridge device
1549 @param Bridge Given Pci driver instance.
1550 @param IoBase output for base address of I/O type resource.
1551 @param Mem32Base output for base address of 32-bit memory type resource.
1552 @param PMem32Base output for base address of 32-bit Pmemory type resource.
1553 @param Mem64Base output for base address of 64-bit memory type resource.
1554 @param PMem64Base output for base address of 64-bit Pmemory type resource.
1556 @retval EFI_SUCCESS Succes to get resource base address.
1559 GetResourceBaseFromBridge (
1560 IN PCI_IO_DEVICE
*Bridge
,
1562 OUT UINT64
*Mem32Base
,
1563 OUT UINT64
*PMem32Base
,
1564 OUT UINT64
*Mem64Base
,
1565 OUT UINT64
*PMem64Base
1568 if (!Bridge
->Allocated
) {
1569 return EFI_OUT_OF_RESOURCES
;
1573 *Mem32Base
= gAllOne
;
1574 *PMem32Base
= gAllOne
;
1575 *Mem64Base
= gAllOne
;
1576 *PMem64Base
= gAllOne
;
1578 if (IS_PCI_BRIDGE (&Bridge
->Pci
)) {
1580 if (Bridge
->PciBar
[PPB_IO_RANGE
].Length
> 0) {
1581 *IoBase
= Bridge
->PciBar
[PPB_IO_RANGE
].BaseAddress
;
1584 if (Bridge
->PciBar
[PPB_MEM32_RANGE
].Length
> 0) {
1585 *Mem32Base
= Bridge
->PciBar
[PPB_MEM32_RANGE
].BaseAddress
;
1588 if (Bridge
->PciBar
[PPB_PMEM32_RANGE
].Length
> 0) {
1589 *PMem32Base
= Bridge
->PciBar
[PPB_PMEM32_RANGE
].BaseAddress
;
1592 if (Bridge
->PciBar
[PPB_PMEM64_RANGE
].Length
> 0) {
1593 *PMem64Base
= Bridge
->PciBar
[PPB_PMEM64_RANGE
].BaseAddress
;
1595 *PMem64Base
= gAllOne
;
1600 if (IS_CARDBUS_BRIDGE (&Bridge
->Pci
)) {
1601 if (Bridge
->PciBar
[P2C_IO_1
].Length
> 0) {
1602 *IoBase
= Bridge
->PciBar
[P2C_IO_1
].BaseAddress
;
1604 if (Bridge
->PciBar
[P2C_IO_2
].Length
> 0) {
1605 *IoBase
= Bridge
->PciBar
[P2C_IO_2
].BaseAddress
;
1609 if (Bridge
->PciBar
[P2C_MEM_1
].Length
> 0) {
1610 if (Bridge
->PciBar
[P2C_MEM_1
].BarType
== PciBarTypePMem32
) {
1611 *PMem32Base
= Bridge
->PciBar
[P2C_MEM_1
].BaseAddress
;
1614 if (Bridge
->PciBar
[P2C_MEM_1
].BarType
== PciBarTypeMem32
) {
1615 *Mem32Base
= Bridge
->PciBar
[P2C_MEM_1
].BaseAddress
;
1619 if (Bridge
->PciBar
[P2C_MEM_2
].Length
> 0) {
1620 if (Bridge
->PciBar
[P2C_MEM_2
].BarType
== PciBarTypePMem32
) {
1621 *PMem32Base
= Bridge
->PciBar
[P2C_MEM_2
].BaseAddress
;
1624 if (Bridge
->PciBar
[P2C_MEM_2
].BarType
== PciBarTypeMem32
) {
1625 *Mem32Base
= Bridge
->PciBar
[P2C_MEM_2
].BaseAddress
;
1634 These are the notifications from the PCI bus driver that it is about to enter a certain
1635 phase of the PCI enumeration process.
1637 This member function can be used to notify the host bridge driver to perform specific actions,
1638 including any chipset-specific initialization, so that the chipset is ready to enter the next phase.
1639 Eight notification points are defined at this time. See belows:
1640 EfiPciHostBridgeBeginEnumeration - Resets the host bridge PCI apertures and internal data
1641 structures. The PCI enumerator should issue this notification
1642 before starting a fresh enumeration process. Enumeration cannot
1643 be restarted after sending any other notification such as
1644 EfiPciHostBridgeBeginBusAllocation.
1645 EfiPciHostBridgeBeginBusAllocation - The bus allocation phase is about to begin. No specific action is
1646 required here. This notification can be used to perform any
1647 chipset-specific programming.
1648 EfiPciHostBridgeEndBusAllocation - The bus allocation and bus programming phase is complete. No
1649 specific action is required here. This notification can be used to
1650 perform any chipset-specific programming.
1651 EfiPciHostBridgeBeginResourceAllocation - The resource allocation phase is about to begin. No specific
1652 action is required here. This notification can be used to perform
1653 any chipset-specific programming.
1654 EfiPciHostBridgeAllocateResources - Allocates resources per previously submitted requests for all the PCI
1655 root bridges. These resource settings are returned on the next call to
1656 GetProposedResources(). Before calling NotifyPhase() with a Phase of
1657 EfiPciHostBridgeAllocateResource, the PCI bus enumerator is responsible for gathering I/O and memory requests for
1658 all the PCI root bridges and submitting these requests using
1659 SubmitResources(). This function pads the resource amount
1660 to suit the root bridge hardware, takes care of dependencies between
1661 the PCI root bridges, and calls the Global Coherency Domain (GCD)
1662 with the allocation request. In the case of padding, the allocated range
1663 could be bigger than what was requested.
1664 EfiPciHostBridgeSetResources - Programs the host bridge hardware to decode previously allocated
1665 resources (proposed resources) for all the PCI root bridges. After the
1666 hardware is programmed, reassigning resources will not be supported.
1667 The bus settings are not affected.
1668 EfiPciHostBridgeFreeResources - Deallocates resources that were previously allocated for all the PCI
1669 root bridges and resets the I/O and memory apertures to their initial
1670 state. The bus settings are not affected. If the request to allocate
1671 resources fails, the PCI enumerator can use this notification to
1672 deallocate previous resources, adjust the requests, and retry
1674 EfiPciHostBridgeEndResourceAllocation- The resource allocation phase is completed. No specific action is
1675 required here. This notification can be used to perform any chipsetspecific
1678 @param[in] PciResAlloc The instance pointer of EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
1679 @param[in] Phase The phase during enumeration
1681 @retval EFI_NOT_READY This phase cannot be entered at this time. For example, this error
1682 is valid for a Phase of EfiPciHostBridgeAllocateResources if
1683 SubmitResources() has not been called for one or more
1684 PCI root bridges before this call
1685 @retval EFI_DEVICE_ERROR Programming failed due to a hardware error. This error is valid
1686 for a Phase of EfiPciHostBridgeSetResources.
1687 @retval EFI_INVALID_PARAMETER Invalid phase parameter
1688 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
1689 This error is valid for a Phase of EfiPciHostBridgeAllocateResources if the
1690 previously submitted resource requests cannot be fulfilled or
1691 were only partially fulfilled.
1692 @retval EFI_SUCCESS The notification was accepted without any errors.
1697 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*PciResAlloc
,
1698 EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PHASE Phase
1701 EFI_HANDLE HostBridgeHandle
;
1702 EFI_HANDLE RootBridgeHandle
;
1703 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
1706 HostBridgeHandle
= NULL
;
1707 RootBridgeHandle
= NULL
;
1708 if (gPciPlatformProtocol
!= NULL
) {
1710 // Get Host Bridge Handle.
1712 PciResAlloc
->GetNextRootBridge (PciResAlloc
, &RootBridgeHandle
);
1715 // Get the rootbridge Io protocol to find the host bridge handle
1717 Status
= gBS
->HandleProtocol (
1719 &gEfiPciRootBridgeIoProtocolGuid
,
1720 (VOID
**) &PciRootBridgeIo
1723 if (EFI_ERROR (Status
)) {
1724 return EFI_NOT_FOUND
;
1727 HostBridgeHandle
= PciRootBridgeIo
->ParentHandle
;
1730 // Call PlatformPci::PlatformNotify() if the protocol is present.
1732 gPciPlatformProtocol
->PlatformNotify (
1733 gPciPlatformProtocol
,
1740 Status
= PciResAlloc
->NotifyPhase (
1745 if (gPciPlatformProtocol
!= NULL
) {
1747 // Call PlatformPci::PlatformNotify() if the protocol is present.
1749 gPciPlatformProtocol
->PlatformNotify (
1750 gPciPlatformProtocol
,
1762 Provides the hooks from the PCI bus driver to every PCI controller (device/function) at various
1763 stages of the PCI enumeration process that allow the host bridge driver to preinitialize individual
1764 PCI controllers before enumeration.
1766 This function is called during the PCI enumeration process. No specific action is expected from this
1767 member function. It allows the host bridge driver to preinitialize individual PCI controllers before
1770 @param Bridge Pointer to the EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL instance.
1771 @param Bus The bus number of the pci device.
1772 @param Device The device number of the pci device.
1773 @param Func The function number of the pci device.
1774 @param Phase The phase of the PCI device enumeration.
1776 @retval EFI_SUCCESS The requested parameters were returned.
1777 @retval EFI_INVALID_PARAMETER RootBridgeHandle is not a valid root bridge handle.
1778 @retval EFI_INVALID_PARAMETER Phase is not a valid phase that is defined in
1779 EFI_PCI_CONTROLLER_RESOURCE_ALLOCATION_PHASE.
1780 @retval EFI_DEVICE_ERROR Programming failed due to a hardware error. The PCI enumerator should
1781 not enumerate this device, including its child devices if it is a PCI-to-PCI
1786 PreprocessController (
1787 IN PCI_IO_DEVICE
*Bridge
,
1791 IN EFI_PCI_CONTROLLER_RESOURCE_ALLOCATION_PHASE Phase
1794 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS RootBridgePciAddress
;
1795 EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*PciResAlloc
;
1796 EFI_HANDLE RootBridgeHandle
;
1797 EFI_HANDLE HostBridgeHandle
;
1801 // Get the host bridge handle
1803 HostBridgeHandle
= Bridge
->PciRootBridgeIo
->ParentHandle
;
1806 // Get the pci host bridge resource allocation protocol
1808 Status
= gBS
->OpenProtocol (
1810 &gEfiPciHostBridgeResourceAllocationProtocolGuid
,
1811 (VOID
**) &PciResAlloc
,
1814 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1817 if (EFI_ERROR (Status
)) {
1818 return EFI_UNSUPPORTED
;
1822 // Get Root Brige Handle
1824 while (Bridge
->Parent
!= NULL
) {
1825 Bridge
= Bridge
->Parent
;
1828 RootBridgeHandle
= Bridge
->Handle
;
1830 RootBridgePciAddress
.Register
= 0;
1831 RootBridgePciAddress
.Function
= Func
;
1832 RootBridgePciAddress
.Device
= Device
;
1833 RootBridgePciAddress
.Bus
= Bus
;
1834 RootBridgePciAddress
.ExtendedRegister
= 0;
1836 if (gPciPlatformProtocol
!= NULL
) {
1838 // Call PlatformPci::PrepController() if the protocol is present.
1840 gPciPlatformProtocol
->PlatformPrepController (
1841 gPciPlatformProtocol
,
1844 RootBridgePciAddress
,
1850 Status
= PciResAlloc
->PreprocessController (
1853 RootBridgePciAddress
,
1857 if (gPciPlatformProtocol
!= NULL
) {
1859 // Call PlatformPci::PrepController() if the protocol is present.
1861 gPciPlatformProtocol
->PlatformPrepController (
1862 gPciPlatformProtocol
,
1865 RootBridgePciAddress
,
1875 Hot plug request notify.
1877 @param This - A pointer to the hot plug request protocol.
1878 @param Operation - The operation.
1879 @param Controller - A pointer to the controller.
1880 @param RemainingDevicePath - A pointer to the device path.
1881 @param NumberOfChildren - A the number of child handle in the ChildHandleBuffer.
1882 @param ChildHandleBuffer - A pointer to the array contain the child handle.
1884 @retval EFI_NOT_FOUND Can not find bridge according to controller handle.
1885 @retval EFI_SUCCESS Success operating.
1889 PciHotPlugRequestNotify (
1890 IN EFI_PCI_HOTPLUG_REQUEST_PROTOCOL
* This
,
1891 IN EFI_PCI_HOTPLUG_OPERATION Operation
,
1892 IN EFI_HANDLE Controller
,
1893 IN EFI_DEVICE_PATH_PROTOCOL
* RemainingDevicePath OPTIONAL
,
1894 IN OUT UINT8
*NumberOfChildren
,
1895 IN OUT EFI_HANDLE
* ChildHandleBuffer
1898 PCI_IO_DEVICE
*Bridge
;
1899 PCI_IO_DEVICE
*Temp
;
1900 EFI_PCI_IO_PROTOCOL
*PciIo
;
1902 EFI_HANDLE RootBridgeHandle
;
1905 Status
= gBS
->OpenProtocol (
1907 &gEfiPciIoProtocolGuid
,
1909 gPciBusDriverBinding
.DriverBindingHandle
,
1911 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1914 if (EFI_ERROR (Status
)) {
1915 return EFI_NOT_FOUND
;
1918 Bridge
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (PciIo
);
1921 // Get root bridge handle
1924 while (Temp
->Parent
!= NULL
) {
1925 Temp
= Temp
->Parent
;
1928 RootBridgeHandle
= Temp
->Handle
;
1930 if (Operation
== EfiPciHotPlugRequestAdd
) {
1932 if (NumberOfChildren
!= NULL
) {
1933 *NumberOfChildren
= 0;
1936 if (IsListEmpty (&Bridge
->ChildList
)) {
1938 Status
= PciBridgeEnumerator (Bridge
);
1940 if (EFI_ERROR (Status
)) {
1945 Status
= StartPciDevicesOnBridge (
1948 RemainingDevicePath
,
1956 if (Operation
== EfiPciHotplugRequestRemove
) {
1958 if (*NumberOfChildren
== 0) {
1960 // Remove all devices on the bridge
1962 Status
= RemoveAllPciDeviceOnBridge (RootBridgeHandle
, Bridge
);
1967 for (Index
= 0; Index
< *NumberOfChildren
; Index
++) {
1969 // De register all the pci device
1971 Status
= DeRegisterPciDevice (RootBridgeHandle
, ChildHandleBuffer
[Index
]);
1973 if (EFI_ERROR (Status
)) {
1988 Search hostbridge according to given handle
1990 @param RootBridgeHandle - Host bridge handle.
1993 @return FALSE Not found.
1996 SearchHostBridgeHandle (
1997 IN EFI_HANDLE RootBridgeHandle
2000 EFI_HANDLE HostBridgeHandle
;
2001 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
2006 // Get the rootbridge Io protocol to find the host bridge handle
2008 Status
= gBS
->OpenProtocol (
2010 &gEfiPciRootBridgeIoProtocolGuid
,
2011 (VOID
**) &PciRootBridgeIo
,
2012 gPciBusDriverBinding
.DriverBindingHandle
,
2014 EFI_OPEN_PROTOCOL_GET_PROTOCOL
2017 if (EFI_ERROR (Status
)) {
2021 HostBridgeHandle
= PciRootBridgeIo
->ParentHandle
;
2022 for (Index
= 0; Index
< gPciHostBridgeNumber
; Index
++) {
2023 if (HostBridgeHandle
== gPciHostBrigeHandles
[Index
]) {
2032 Add host bridge handle to global variable for enumating.
2034 @param HostBridgeHandle host bridge handle.
2037 AddHostBridgeEnumerator (
2038 IN EFI_HANDLE HostBridgeHandle
2043 if (HostBridgeHandle
== NULL
) {
2047 for (Index
= 0; Index
< gPciHostBridgeNumber
; Index
++) {
2048 if (HostBridgeHandle
== gPciHostBrigeHandles
[Index
]) {
2053 if (Index
< PCI_MAX_HOST_BRIDGE_NUM
) {
2054 gPciHostBrigeHandles
[Index
] = HostBridgeHandle
;
2055 gPciHostBridgeNumber
++;