2 Provides the basic interfaces to abstract a PCI Host Bridge Resource
5 Copyright (C) 2015, Red Hat, Inc.
6 Copyright (c) 2008 - 2013, Intel Corporation. All rights reserved.<BR>
8 This program and the accompanying materials are licensed and made available
9 under the terms and conditions of the BSD License which accompanies this
10 distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include "PciHostBridge.h"
21 // Hard code: Root Bridge Number within the host bridge
22 // Root Bridge's attribute
23 // Root Bridge's device path
24 // Root Bridge's resource aperture
26 UINTN RootBridgeNumber
= 1;
28 UINT64 RootBridgeAttribute
[1] = {
29 EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM
32 EFI_PCI_ROOT_BRIDGE_DEVICE_PATH mEfiPciRootBridgeDevicePath
[1] = {
39 (UINT8
) (sizeof(ACPI_HID_DEVICE_PATH
)),
40 (UINT8
) ((sizeof(ACPI_HID_DEVICE_PATH
)) >> 8)
49 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
51 END_DEVICE_PATH_LENGTH
,
58 PCI_ROOT_BRIDGE_RESOURCE_APERTURE mResAperture
[1] = {
59 {0, 0xff, 0x80000000, 0xffffffff, 0, 0xffff}
62 EFI_HANDLE mDriverImageHandle
;
64 PCI_HOST_BRIDGE_INSTANCE mPciHostBridgeInstanceTemplate
= {
65 PCI_HOST_BRIDGE_SIGNATURE
, // Signature
66 NULL
, // HostBridgeHandle
67 0, // RootBridgeNumber
69 FALSE
, // ResourceSubiteed
88 Entry point of this driver
90 @param ImageHandle Handle of driver image
91 @param SystemTable Point to EFI_SYSTEM_TABLE
93 @retval EFI_OUT_OF_RESOURCES Can not allocate memory resource
94 @retval EFI_DEVICE_ERROR Can not install the protocol instance
95 @retval EFI_SUCCESS Success to initialize the Pci host bridge.
99 InitializePciHostBridge (
100 IN EFI_HANDLE ImageHandle
,
101 IN EFI_SYSTEM_TABLE
*SystemTable
106 PCI_HOST_BRIDGE_INSTANCE
*HostBridge
;
107 PCI_ROOT_BRIDGE_INSTANCE
*PrivateData
;
109 mDriverImageHandle
= ImageHandle
;
112 // Create Host Bridge Device Handle
114 HostBridge
= AllocateCopyPool (sizeof(PCI_HOST_BRIDGE_INSTANCE
),
115 &mPciHostBridgeInstanceTemplate
);
116 if (HostBridge
== NULL
) {
117 return EFI_OUT_OF_RESOURCES
;
120 HostBridge
->RootBridgeNumber
= RootBridgeNumber
;
121 InitializeListHead (&HostBridge
->Head
);
123 Status
= gBS
->InstallMultipleProtocolInterfaces (
124 &HostBridge
->HostBridgeHandle
,
125 &gEfiPciHostBridgeResourceAllocationProtocolGuid
,
126 &HostBridge
->ResAlloc
,
129 if (EFI_ERROR (Status
)) {
130 FreePool (HostBridge
);
131 return EFI_DEVICE_ERROR
;
135 // Create Root Bridge Device Handle in this Host Bridge
138 for (Loop2
= 0; Loop2
< HostBridge
->RootBridgeNumber
; Loop2
++) {
139 PrivateData
= AllocateZeroPool (sizeof(PCI_ROOT_BRIDGE_INSTANCE
));
140 if (PrivateData
== NULL
) {
141 return EFI_OUT_OF_RESOURCES
;
144 PrivateData
->Signature
= PCI_ROOT_BRIDGE_SIGNATURE
;
145 PrivateData
->DevicePath
=
146 (EFI_DEVICE_PATH_PROTOCOL
*)&mEfiPciRootBridgeDevicePath
[Loop2
];
148 RootBridgeConstructor (
150 HostBridge
->HostBridgeHandle
,
151 RootBridgeAttribute
[Loop2
],
155 Status
= gBS
->InstallMultipleProtocolInterfaces(
156 &PrivateData
->Handle
,
157 &gEfiDevicePathProtocolGuid
,
158 PrivateData
->DevicePath
,
159 &gEfiPciRootBridgeIoProtocolGuid
,
163 if (EFI_ERROR (Status
)) {
164 FreePool(PrivateData
);
165 return EFI_DEVICE_ERROR
;
168 InsertTailList (&HostBridge
->Head
, &PrivateData
->Link
);
176 These are the notifications from the PCI bus driver that it is about to enter
177 a certain phase of the PCI enumeration process.
179 This member function can be used to notify the host bridge driver to perform
180 specific actions, including any chipset-specific initialization, so that the
181 chipset is ready to enter the next phase. Eight notification points are
182 defined at this time. See belows:
184 EfiPciHostBridgeBeginEnumeration Resets the host bridge PCI apertures
185 and internal data structures. The PCI
186 enumerator should issue this
187 notification before starting a fresh
188 enumeration process. Enumeration
189 cannot be restarted after sending any
190 other notification such as
191 EfiPciHostBridgeBeginBusAllocation.
193 EfiPciHostBridgeBeginBusAllocation The bus allocation phase is about to
194 begin. No specific action is required
195 here. This notification can be used to
196 perform any chipset-specific
199 EfiPciHostBridgeEndBusAllocation The bus allocation and bus programming
200 phase is complete. No specific action
201 is required here. This notification
202 can be used to perform any
203 chipset-specific programming.
205 EfiPciHostBridgeBeginResourceAllocation
206 The resource allocation phase is about
207 to begin. No specific action is
208 required here. This notification can
209 be used to perform any
210 chipset-specific programming.
212 EfiPciHostBridgeAllocateResources Allocates resources per previously
213 submitted requests for all the PCI
214 root bridges. These resource settings
215 are returned on the next call to
216 GetProposedResources(). Before calling
217 NotifyPhase() with a Phase of
218 EfiPciHostBridgeAllocateResource, the
219 PCI bus enumerator is responsible for
220 gathering I/O and memory requests for
221 all the PCI root bridges and
222 submitting these requests using
223 SubmitResources(). This function pads
224 the resource amount to suit the root
225 bridge hardware, takes care of
226 dependencies between the PCI root
227 bridges, and calls the Global
228 Coherency Domain (GCD) with the
229 allocation request. In the case of
230 padding, the allocated range could be
231 bigger than what was requested.
233 EfiPciHostBridgeSetResources Programs the host bridge hardware to
234 decode previously allocated resources
235 (proposed resources) for all the PCI
236 root bridges. After the hardware is
237 programmed, reassigning resources will
238 not be supported. The bus settings are
241 EfiPciHostBridgeFreeResources Deallocates resources that were
242 previously allocated for all the PCI
243 root bridges and resets the I/O and
244 memory apertures to their initial
245 state. The bus settings are not
246 affected. If the request to allocate
247 resources fails, the PCI enumerator
248 can use this notification to
249 deallocate previous resources, adjust
250 the requests, and retry allocation.
252 EfiPciHostBridgeEndResourceAllocation The resource allocation phase is
253 completed. No specific action is
254 required here. This notification can
255 be used to perform any chipsetspecific
258 @param[in] This The instance pointer of
259 EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
261 @param[in] Phase The phase during enumeration
263 @retval EFI_NOT_READY This phase cannot be entered at this time. For
264 example, this error is valid for a Phase of
265 EfiPciHostBridgeAllocateResources if
266 SubmitResources() has not been called for one
267 or more PCI root bridges before this call
269 @retval EFI_DEVICE_ERROR Programming failed due to a hardware error.
270 This error is valid for a Phase of
271 EfiPciHostBridgeSetResources.
273 @retval EFI_INVALID_PARAMETER Invalid phase parameter
275 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
276 lack of resources. This error is valid for a
277 Phase of EfiPciHostBridgeAllocateResources if
278 the previously submitted resource requests
279 cannot be fulfilled or were only partially
282 @retval EFI_SUCCESS The notification was accepted without any
288 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
289 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PHASE Phase
292 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
293 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
294 PCI_RESOURCE_TYPE Index
;
296 EFI_PHYSICAL_ADDRESS BaseAddress
;
298 UINTN BitsOfAlignment
;
300 EFI_STATUS ReturnStatus
;
302 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
306 case EfiPciHostBridgeBeginEnumeration
:
307 if (HostBridgeInstance
->CanRestarted
) {
309 // Reset the Each Root Bridge
311 List
= HostBridgeInstance
->Head
.ForwardLink
;
313 while (List
!= &HostBridgeInstance
->Head
) {
314 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
315 for (Index
= TypeIo
; Index
< TypeMax
; Index
++) {
316 RootBridgeInstance
->ResAllocNode
[Index
].Type
= Index
;
317 RootBridgeInstance
->ResAllocNode
[Index
].Base
= 0;
318 RootBridgeInstance
->ResAllocNode
[Index
].Length
= 0;
319 RootBridgeInstance
->ResAllocNode
[Index
].Status
= ResNone
;
322 List
= List
->ForwardLink
;
325 HostBridgeInstance
->ResourceSubmited
= FALSE
;
326 HostBridgeInstance
->CanRestarted
= TRUE
;
331 return EFI_NOT_READY
;
335 case EfiPciHostBridgeEndEnumeration
:
338 case EfiPciHostBridgeBeginBusAllocation
:
340 // No specific action is required here, can perform any chipset specific
343 HostBridgeInstance
->CanRestarted
= FALSE
;
346 case EfiPciHostBridgeEndBusAllocation
:
348 // No specific action is required here, can perform any chipset specific
351 //HostBridgeInstance->CanRestarted = FALSE;
354 case EfiPciHostBridgeBeginResourceAllocation
:
356 // No specific action is required here, can perform any chipset specific
359 //HostBridgeInstance->CanRestarted = FALSE;
362 case EfiPciHostBridgeAllocateResources
:
363 ReturnStatus
= EFI_SUCCESS
;
364 if (HostBridgeInstance
->ResourceSubmited
) {
366 // Take care of the resource dependencies between the root bridges
368 List
= HostBridgeInstance
->Head
.ForwardLink
;
370 while (List
!= &HostBridgeInstance
->Head
) {
371 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
372 for (Index
= TypeIo
; Index
< TypeBus
; Index
++) {
373 if (RootBridgeInstance
->ResAllocNode
[Index
].Status
!= ResNone
) {
375 AddrLen
= RootBridgeInstance
->ResAllocNode
[Index
].Length
;
378 // Get the number of '1' in Alignment.
381 (UINTN
)(HighBitSet64 (
382 RootBridgeInstance
->ResAllocNode
[Index
].Alignment
389 // It is impossible for this chipset to align 0xFFFF for IO16
392 if (BitsOfAlignment
>= 16) {
396 Status
= gDS
->AllocateIoSpace (
397 EfiGcdAllocateAnySearchBottomUp
,
406 if (!EFI_ERROR (Status
)) {
407 RootBridgeInstance
->ResAllocNode
[Index
].Base
=
409 RootBridgeInstance
->ResAllocNode
[Index
].Status
=
412 ReturnStatus
= Status
;
413 if (Status
!= EFI_OUT_OF_RESOURCES
) {
414 RootBridgeInstance
->ResAllocNode
[Index
].Length
= 0;
423 // It is impossible for this chipset to align 0xFFFFFFFF for
428 if (BitsOfAlignment
>= 32) {
432 Status
= gDS
->AllocateMemorySpace (
433 EfiGcdAllocateAnySearchBottomUp
,
434 EfiGcdMemoryTypeMemoryMappedIo
,
442 if (!EFI_ERROR (Status
)) {
443 // We were able to allocate the PCI memory
444 RootBridgeInstance
->ResAllocNode
[Index
].Base
=
446 RootBridgeInstance
->ResAllocNode
[Index
].Status
=
450 // Not able to allocate enough PCI memory
451 ReturnStatus
= Status
;
453 if (Status
!= EFI_OUT_OF_RESOURCES
) {
454 RootBridgeInstance
->ResAllocNode
[Index
].Length
= 0;
463 ReturnStatus
= EFI_ABORTED
;
472 List
= List
->ForwardLink
;
478 return EFI_NOT_READY
;
482 case EfiPciHostBridgeSetResources
:
485 case EfiPciHostBridgeFreeResources
:
486 ReturnStatus
= EFI_SUCCESS
;
487 List
= HostBridgeInstance
->Head
.ForwardLink
;
488 while (List
!= &HostBridgeInstance
->Head
) {
489 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
490 for (Index
= TypeIo
; Index
< TypeBus
; Index
++) {
491 if (RootBridgeInstance
->ResAllocNode
[Index
].Status
== ResAllocated
) {
492 AddrLen
= RootBridgeInstance
->ResAllocNode
[Index
].Length
;
493 BaseAddress
= RootBridgeInstance
->ResAllocNode
[Index
].Base
;
497 Status
= gDS
->FreeIoSpace (BaseAddress
, AddrLen
);
498 if (EFI_ERROR (Status
)) {
499 ReturnStatus
= Status
;
504 Status
= gDS
->FreeMemorySpace (BaseAddress
, AddrLen
);
505 if (EFI_ERROR (Status
)) {
506 ReturnStatus
= Status
;
524 RootBridgeInstance
->ResAllocNode
[Index
].Type
= Index
;
525 RootBridgeInstance
->ResAllocNode
[Index
].Base
= 0;
526 RootBridgeInstance
->ResAllocNode
[Index
].Length
= 0;
527 RootBridgeInstance
->ResAllocNode
[Index
].Status
= ResNone
;
531 List
= List
->ForwardLink
;
534 HostBridgeInstance
->ResourceSubmited
= FALSE
;
535 HostBridgeInstance
->CanRestarted
= TRUE
;
538 case EfiPciHostBridgeEndResourceAllocation
:
539 HostBridgeInstance
->CanRestarted
= FALSE
;
543 return EFI_INVALID_PARAMETER
;
550 Return the device handle of the next PCI root bridge that is associated with
553 This function is called multiple times to retrieve the device handles of all
554 the PCI root bridges that are associated with this PCI host bridge. Each PCI
555 host bridge is associated with one or more PCI root bridges. On each call,
556 the handle that was returned by the previous call is passed into the
557 interface, and on output the interface returns the device handle of the next
558 PCI root bridge. The caller can use the handle to obtain the instance of the
559 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL for that root bridge. When there are no more
560 PCI root bridges to report, the interface returns EFI_NOT_FOUND. A PCI
561 enumerator must enumerate the PCI root bridges in the order that they are
562 returned by this function.
564 For D945 implementation, there is only one root bridge in PCI host bridge.
566 @param[in] This The instance pointer of
567 EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
569 @param[in, out] RootBridgeHandle Returns the device handle of the next PCI
572 @retval EFI_SUCCESS If parameter RootBridgeHandle = NULL, then
573 return the first Rootbridge handle of the
574 specific Host bridge and return EFI_SUCCESS.
576 @retval EFI_NOT_FOUND Can not find the any more root bridge in
577 specific host bridge.
579 @retval EFI_INVALID_PARAMETER RootBridgeHandle is not an EFI_HANDLE that was
580 returned on a previous call to
586 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
587 IN OUT EFI_HANDLE
*RootBridgeHandle
590 BOOLEAN NoRootBridge
;
592 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
593 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
596 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
597 List
= HostBridgeInstance
->Head
.ForwardLink
;
600 while (List
!= &HostBridgeInstance
->Head
) {
601 NoRootBridge
= FALSE
;
602 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
603 if (*RootBridgeHandle
== NULL
) {
605 // Return the first Root Bridge Handle of the Host Bridge
607 *RootBridgeHandle
= RootBridgeInstance
->Handle
;
610 if (*RootBridgeHandle
== RootBridgeInstance
->Handle
) {
614 List
= List
->ForwardLink
;
615 if (List
!=&HostBridgeInstance
->Head
) {
616 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
617 *RootBridgeHandle
= RootBridgeInstance
->Handle
;
620 return EFI_NOT_FOUND
;
625 List
= List
->ForwardLink
;
629 return EFI_NOT_FOUND
;
631 return EFI_INVALID_PARAMETER
;
636 Returns the allocation attributes of a PCI root bridge.
638 The function returns the allocation attributes of a specific PCI root bridge.
639 The attributes can vary from one PCI root bridge to another. These attributes
640 are different from the decode-related attributes that are returned by the
641 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.GetAttributes() member function. The
642 RootBridgeHandle parameter is used to specify the instance of the PCI root
643 bridge. The device handles of all the root bridges that are associated with
644 this host bridge must be obtained by calling GetNextRootBridge(). The
645 attributes are static in the sense that they do not change during or after
646 the enumeration process. The hardware may provide mechanisms to change the
647 attributes on the fly, but such changes must be completed before
648 EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL is installed. The permitted
649 values of EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ATTRIBUTES are defined in
650 "Related Definitions" below. The caller uses these attributes to combine
651 multiple resource requests.
653 For example, if the flag EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM is set, the PCI
654 bus enumerator needs to include requests for the prefetchable memory in the
655 nonprefetchable memory pool and not request any prefetchable memory.
657 Attribute Description
658 ------------------------------------ ---------------------------------------
659 EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM If this bit is set, then the PCI root
660 bridge does not support separate
661 windows for nonprefetchable and
662 prefetchable memory. A PCI bus driver
663 needs to include requests for
664 prefetchable memory in the
665 nonprefetchable memory pool.
667 EFI_PCI_HOST_BRIDGE_MEM64_DECODE If this bit is set, then the PCI root
668 bridge supports 64-bit memory windows.
669 If this bit is not set, the PCI bus
670 driver needs to include requests for a
671 64-bit memory address in the
672 corresponding 32-bit memory pool.
674 @param[in] This The instance pointer of
675 EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
677 @param[in] RootBridgeHandle The device handle of the PCI root bridge in
678 which the caller is interested. Type
679 EFI_HANDLE is defined in
680 InstallProtocolInterface() in the UEFI 2.0
683 @param[out] Attributes The pointer to attribte of root bridge, it is
686 @retval EFI_INVALID_PARAMETER Attribute pointer is NULL
688 @retval EFI_INVALID_PARAMETER RootBridgehandle is invalid.
690 @retval EFI_SUCCESS Success to get attribute of interested root
696 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
697 IN EFI_HANDLE RootBridgeHandle
,
698 OUT UINT64
*Attributes
702 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
703 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
705 if (Attributes
== NULL
) {
706 return EFI_INVALID_PARAMETER
;
709 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
710 List
= HostBridgeInstance
->Head
.ForwardLink
;
712 while (List
!= &HostBridgeInstance
->Head
) {
713 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
714 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
715 *Attributes
= RootBridgeInstance
->RootBridgeAttrib
;
718 List
= List
->ForwardLink
;
722 // RootBridgeHandle is not an EFI_HANDLE
723 // that was returned on a previous call to GetNextRootBridge()
725 return EFI_INVALID_PARAMETER
;
729 Sets up the specified PCI root bridge for the bus enumeration process.
731 This member function sets up the root bridge for bus enumeration and returns
732 the PCI bus range over which the search should be performed in ACPI 2.0
733 resource descriptor format.
736 EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
739 @param[in] RootBridgeHandle The PCI Root Bridge to be set up.
741 @param[out] Configuration Pointer to the pointer to the PCI bus resource
744 @retval EFI_INVALID_PARAMETER Invalid Root bridge's handle
746 @retval EFI_OUT_OF_RESOURCES Fail to allocate ACPI resource descriptor tag.
748 @retval EFI_SUCCESS Sucess to allocate ACPI resource descriptor.
753 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
754 IN EFI_HANDLE RootBridgeHandle
,
755 OUT VOID
**Configuration
759 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
760 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
766 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
767 List
= HostBridgeInstance
->Head
.ForwardLink
;
769 while (List
!= &HostBridgeInstance
->Head
) {
770 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
771 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
773 // Set up the Root Bridge for Bus Enumeration
775 BusStart
= RootBridgeInstance
->BusBase
;
776 BusEnd
= RootBridgeInstance
->BusLimit
;
778 // Program the Hardware(if needed) if error return EFI_DEVICE_ERROR
781 Buffer
= AllocatePool (
782 sizeof(EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) +
783 sizeof(EFI_ACPI_END_TAG_DESCRIPTOR
)
785 if (Buffer
== NULL
) {
786 return EFI_OUT_OF_RESOURCES
;
789 Temp
= (UINT8
*)Buffer
;
791 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->Desc
= 0x8A;
792 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->Len
= 0x2B;
793 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->ResType
= 2;
794 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->GenFlag
= 0;
795 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->SpecificFlag
= 0;
796 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->AddrSpaceGranularity
= 0;
797 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->AddrRangeMin
= BusStart
;
798 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->AddrRangeMax
= 0;
799 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->AddrTranslationOffset
= 0;
800 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->AddrLen
=
801 BusEnd
- BusStart
+ 1;
803 Temp
= Temp
+ sizeof(EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
);
804 ((EFI_ACPI_END_TAG_DESCRIPTOR
*)Temp
)->Desc
= 0x79;
805 ((EFI_ACPI_END_TAG_DESCRIPTOR
*)Temp
)->Checksum
= 0x0;
807 *Configuration
= Buffer
;
810 List
= List
->ForwardLink
;
813 return EFI_INVALID_PARAMETER
;
817 Programs the PCI root bridge hardware so that it decodes the specified PCI
820 This member function programs the specified PCI root bridge to decode the bus
821 range that is specified by the input parameter Configuration.
822 The bus range information is specified in terms of the ACPI 2.0 resource
826 EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
829 @param[in] RootBridgeHandle The PCI Root Bridge whose bus range is to be
832 @param[in] Configuration The pointer to the PCI bus resource descriptor
834 @retval EFI_INVALID_PARAMETER RootBridgeHandle is not a valid root bridge
837 @retval EFI_INVALID_PARAMETER Configuration is NULL.
839 @retval EFI_INVALID_PARAMETER Configuration does not point to a valid ACPI
840 2.0 resource descriptor.
842 @retval EFI_INVALID_PARAMETER Configuration does not include a valid ACPI
843 2.0 bus resource descriptor.
845 @retval EFI_INVALID_PARAMETER Configuration includes valid ACPI 2.0 resource
846 descriptors other than bus descriptors.
848 @retval EFI_INVALID_PARAMETER Configuration contains one or more invalid
849 ACPI resource descriptors.
851 @retval EFI_INVALID_PARAMETER "Address Range Minimum" is invalid for this
854 @retval EFI_INVALID_PARAMETER "Address Range Length" is invalid for this
857 @retval EFI_DEVICE_ERROR Programming failed due to a hardware error.
859 @retval EFI_SUCCESS The bus range for the PCI root bridge was
865 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
866 IN EFI_HANDLE RootBridgeHandle
,
867 IN VOID
*Configuration
871 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
872 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
878 if (Configuration
== NULL
) {
879 return EFI_INVALID_PARAMETER
;
885 // Check the Configuration is valid
887 if(*Ptr
!= ACPI_ADDRESS_SPACE_DESCRIPTOR
) {
888 return EFI_INVALID_PARAMETER
;
891 if (((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Ptr
)->ResType
!= 2) {
892 return EFI_INVALID_PARAMETER
;
895 Ptr
+= sizeof(EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
);
896 if (*Ptr
!= ACPI_END_TAG_DESCRIPTOR
) {
897 return EFI_INVALID_PARAMETER
;
900 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
901 List
= HostBridgeInstance
->Head
.ForwardLink
;
905 while (List
!= &HostBridgeInstance
->Head
) {
906 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
907 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
908 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Desc
;
910 Desc
= (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Ptr
;
911 BusStart
= (UINTN
)Desc
->AddrRangeMin
;
912 BusLen
= (UINTN
)Desc
->AddrLen
;
913 BusEnd
= BusStart
+ BusLen
- 1;
915 if (BusStart
> BusEnd
) {
916 return EFI_INVALID_PARAMETER
;
919 if ((BusStart
< RootBridgeInstance
->BusBase
) ||
920 (BusEnd
> RootBridgeInstance
->BusLimit
)) {
921 return EFI_INVALID_PARAMETER
;
925 // Update the Bus Range
927 RootBridgeInstance
->ResAllocNode
[TypeBus
].Base
= BusStart
;
928 RootBridgeInstance
->ResAllocNode
[TypeBus
].Length
= BusLen
;
929 RootBridgeInstance
->ResAllocNode
[TypeBus
].Status
= ResAllocated
;
932 // Program the Root Bridge Hardware
938 List
= List
->ForwardLink
;
941 return EFI_INVALID_PARAMETER
;
946 Submits the I/O and memory resource requirements for the specified PCI root
949 This function is used to submit all the I/O and memory resources that are
950 required by the specified PCI root bridge. The input parameter Configuration
951 is used to specify the following:
952 - The various types of resources that are required
953 - The associated lengths in terms of ACPI 2.0 resource descriptor format
955 @param[in] This Pointer to the
956 EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
959 @param[in] RootBridgeHandle The PCI root bridge whose I/O and memory
960 resource requirements are being submitted.
962 @param[in] Configuration The pointer to the PCI I/O and PCI memory
965 @retval EFI_SUCCESS The I/O and memory resource requests for a PCI
966 root bridge were accepted.
968 @retval EFI_INVALID_PARAMETER RootBridgeHandle is not a valid root bridge
971 @retval EFI_INVALID_PARAMETER Configuration is NULL.
973 @retval EFI_INVALID_PARAMETER Configuration does not point to a valid ACPI
974 2.0 resource descriptor.
976 @retval EFI_INVALID_PARAMETER Configuration includes requests for one or
977 more resource types that are not supported by
978 this PCI root bridge. This error will happen
979 if the caller did not combine resources
980 according to Attributes that were returned by
981 GetAllocAttributes().
983 @retval EFI_INVALID_PARAMETER Address Range Maximum" is invalid.
985 @retval EFI_INVALID_PARAMETER "Address Range Length" is invalid for this PCI
988 @retval EFI_INVALID_PARAMETER "Address Space Granularity" is invalid for
989 this PCI root bridge.
994 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
995 IN EFI_HANDLE RootBridgeHandle
,
996 IN VOID
*Configuration
1000 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
1001 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
1003 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Ptr
;
1008 // Check the input parameter: Configuration
1010 if (Configuration
== NULL
) {
1011 return EFI_INVALID_PARAMETER
;
1014 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
1015 List
= HostBridgeInstance
->Head
.ForwardLink
;
1017 Temp
= (UINT8
*)Configuration
;
1018 while ( *Temp
== 0x8A) {
1019 Temp
+= sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) ;
1021 if (*Temp
!= 0x79) {
1022 return EFI_INVALID_PARAMETER
;
1025 Temp
= (UINT8
*)Configuration
;
1026 while (List
!= &HostBridgeInstance
->Head
) {
1027 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
1028 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
1029 while ( *Temp
== 0x8A) {
1030 Ptr
= (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Temp
;
1033 // Check Address Length
1035 if (Ptr
->AddrLen
> 0xffffffff) {
1036 return EFI_INVALID_PARAMETER
;
1040 // Check address range alignment
1042 if (Ptr
->AddrRangeMax
>= 0xffffffff ||
1043 Ptr
->AddrRangeMax
!= (GetPowerOfTwo64 (
1044 Ptr
->AddrRangeMax
+ 1) - 1)) {
1045 return EFI_INVALID_PARAMETER
;
1048 switch (Ptr
->ResType
) {
1053 // Check invalid Address Sapce Granularity
1055 if (Ptr
->AddrSpaceGranularity
!= 32) {
1056 return EFI_INVALID_PARAMETER
;
1060 // check the memory resource request is supported by PCI root bridge
1062 if (RootBridgeInstance
->RootBridgeAttrib
==
1063 EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM
&&
1064 Ptr
->SpecificFlag
== 0x06) {
1065 return EFI_INVALID_PARAMETER
;
1068 AddrLen
= Ptr
->AddrLen
;
1069 Alignment
= Ptr
->AddrRangeMax
;
1070 if (Ptr
->AddrSpaceGranularity
== 32) {
1071 if (Ptr
->SpecificFlag
== 0x06) {
1075 RootBridgeInstance
->ResAllocNode
[TypePMem32
].Status
=
1078 RootBridgeInstance
->ResAllocNode
[TypeMem32
].Length
= AddrLen
;
1079 RootBridgeInstance
->ResAllocNode
[TypeMem32
].Alignment
=
1081 RootBridgeInstance
->ResAllocNode
[TypeMem32
].Status
=
1083 HostBridgeInstance
->ResourceSubmited
= TRUE
;
1087 if (Ptr
->AddrSpaceGranularity
== 64) {
1088 if (Ptr
->SpecificFlag
== 0x06) {
1089 RootBridgeInstance
->ResAllocNode
[TypePMem64
].Status
=
1092 RootBridgeInstance
->ResAllocNode
[TypeMem64
].Status
=
1099 AddrLen
= (UINTN
) Ptr
->AddrLen
;
1100 Alignment
= (UINTN
) Ptr
->AddrRangeMax
;
1101 RootBridgeInstance
->ResAllocNode
[TypeIo
].Length
= AddrLen
;
1102 RootBridgeInstance
->ResAllocNode
[TypeIo
].Alignment
= Alignment
;
1103 RootBridgeInstance
->ResAllocNode
[TypeIo
].Status
= ResRequested
;
1104 HostBridgeInstance
->ResourceSubmited
= TRUE
;
1111 Temp
+= sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) ;
1117 List
= List
->ForwardLink
;
1120 return EFI_INVALID_PARAMETER
;
1124 Returns the proposed resource settings for the specified PCI root bridge.
1126 This member function returns the proposed resource settings for the
1127 specified PCI root bridge. The proposed resource settings are prepared when
1128 NotifyPhase() is called with a Phase of EfiPciHostBridgeAllocateResources.
1129 The output parameter Configuration specifies the following:
1130 - The various types of resources, excluding bus resources, that are
1132 - The associated lengths in terms of ACPI 2.0 resource descriptor format
1134 @param[in] This Pointer to the
1135 EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
1138 @param[in] RootBridgeHandle The PCI root bridge handle. Type EFI_HANDLE is
1139 defined in InstallProtocolInterface() in the
1140 UEFI 2.0 Specification.
1142 @param[out] Configuration The pointer to the pointer to the PCI I/O and
1143 memory resource descriptor.
1145 @retval EFI_SUCCESS The requested parameters were returned.
1147 @retval EFI_INVALID_PARAMETER RootBridgeHandle is not a valid root bridge
1150 @retval EFI_DEVICE_ERROR Programming failed due to a hardware error.
1152 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
1157 GetProposedResources(
1158 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
1159 IN EFI_HANDLE RootBridgeHandle
,
1160 OUT VOID
**Configuration
1164 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
1165 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
1170 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Ptr
;
1176 // Get the Host Bridge Instance from the resource allocation protocol
1178 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
1179 List
= HostBridgeInstance
->Head
.ForwardLink
;
1182 // Enumerate the root bridges in this host bridge
1184 while (List
!= &HostBridgeInstance
->Head
) {
1185 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
1186 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
1187 for (Index
= 0; Index
< TypeBus
; Index
++) {
1188 if (RootBridgeInstance
->ResAllocNode
[Index
].Status
!= ResNone
) {
1194 return EFI_INVALID_PARAMETER
;
1197 Buffer
= AllocateZeroPool (
1198 Number
* sizeof(EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) +
1199 sizeof(EFI_ACPI_END_TAG_DESCRIPTOR
)
1201 if (Buffer
== NULL
) {
1202 return EFI_OUT_OF_RESOURCES
;
1206 for (Index
= 0; Index
< TypeBus
; Index
++) {
1207 if (RootBridgeInstance
->ResAllocNode
[Index
].Status
!= ResNone
) {
1208 Ptr
= (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Temp
;
1209 ResStatus
= RootBridgeInstance
->ResAllocNode
[Index
].Status
;
1221 Ptr
->SpecificFlag
= 0;
1222 Ptr
->AddrRangeMin
= RootBridgeInstance
->ResAllocNode
[Index
].Base
;
1223 Ptr
->AddrRangeMax
= 0;
1224 Ptr
->AddrTranslationOffset
= (ResStatus
== ResAllocated
) ?
1225 EFI_RESOURCE_SATISFIED
:
1227 Ptr
->AddrLen
= RootBridgeInstance
->ResAllocNode
[Index
].Length
;
1238 Ptr
->SpecificFlag
= 0;
1239 Ptr
->AddrSpaceGranularity
= 32;
1240 Ptr
->AddrRangeMin
= RootBridgeInstance
->ResAllocNode
[Index
].Base
;
1241 Ptr
->AddrRangeMax
= 0;
1242 Ptr
->AddrTranslationOffset
= (ResStatus
== ResAllocated
) ?
1243 EFI_RESOURCE_SATISFIED
:
1245 Ptr
->AddrLen
= RootBridgeInstance
->ResAllocNode
[Index
].Length
;
1250 // Prefetch memory 32
1256 Ptr
->SpecificFlag
= 6;
1257 Ptr
->AddrSpaceGranularity
= 32;
1258 Ptr
->AddrRangeMin
= 0;
1259 Ptr
->AddrRangeMax
= 0;
1260 Ptr
->AddrTranslationOffset
= EFI_RESOURCE_NONEXISTENT
;
1272 Ptr
->SpecificFlag
= 0;
1273 Ptr
->AddrSpaceGranularity
= 64;
1274 Ptr
->AddrRangeMin
= 0;
1275 Ptr
->AddrRangeMax
= 0;
1276 Ptr
->AddrTranslationOffset
= EFI_RESOURCE_NONEXISTENT
;
1282 // Prefetch memory 64
1288 Ptr
->SpecificFlag
= 6;
1289 Ptr
->AddrSpaceGranularity
= 64;
1290 Ptr
->AddrRangeMin
= 0;
1291 Ptr
->AddrRangeMax
= 0;
1292 Ptr
->AddrTranslationOffset
= EFI_RESOURCE_NONEXISTENT
;
1297 Temp
+= sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
);
1301 ((EFI_ACPI_END_TAG_DESCRIPTOR
*)Temp
)->Desc
= 0x79;
1302 ((EFI_ACPI_END_TAG_DESCRIPTOR
*)Temp
)->Checksum
= 0x0;
1304 *Configuration
= Buffer
;
1309 List
= List
->ForwardLink
;
1312 return EFI_INVALID_PARAMETER
;
1316 Provides the hooks from the PCI bus driver to every PCI controller
1317 (device/function) at various stages of the PCI enumeration process that allow
1318 the host bridge driver to preinitialize individual PCI controllers before
1321 This function is called during the PCI enumeration process. No specific
1322 action is expected from this member function. It allows the host bridge
1323 driver to preinitialize individual PCI controllers before enumeration.
1325 @param This Pointer to the
1326 EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
1329 @param RootBridgeHandle The associated PCI root bridge handle. Type
1330 EFI_HANDLE is defined in InstallProtocolInterface()
1331 in the UEFI 2.0 Specification.
1333 @param PciAddress The address of the PCI device on the PCI bus. This
1334 address can be passed to the
1335 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL member functions to
1336 access the PCI configuration space of the device.
1337 See Table 12-1 in the UEFI 2.0 Specification for the
1339 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS.
1341 @param Phase The phase of the PCI device enumeration.
1343 @retval EFI_SUCCESS The requested parameters were returned.
1345 @retval EFI_INVALID_PARAMETER RootBridgeHandle is not a valid root bridge
1348 @retval EFI_INVALID_PARAMETER Phase is not a valid phase that is defined
1350 EFI_PCI_CONTROLLER_RESOURCE_ALLOCATION_PHASE.
1352 @retval EFI_DEVICE_ERROR Programming failed due to a hardware error.
1353 The PCI enumerator should not enumerate this
1354 device, including its child devices if it is
1355 a PCI-to-PCI bridge.
1359 PreprocessController (
1360 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
1361 IN EFI_HANDLE RootBridgeHandle
,
1362 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS PciAddress
,
1363 IN EFI_PCI_CONTROLLER_RESOURCE_ALLOCATION_PHASE Phase
1366 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
1367 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
1370 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
1371 List
= HostBridgeInstance
->Head
.ForwardLink
;
1374 // Enumerate the root bridges in this host bridge
1376 while (List
!= &HostBridgeInstance
->Head
) {
1377 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
1378 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
1381 List
= List
->ForwardLink
;
1383 if (List
== &HostBridgeInstance
->Head
) {
1384 return EFI_INVALID_PARAMETER
;
1387 if ((UINT32
)Phase
> EfiPciBeforeResourceCollection
) {
1388 return EFI_INVALID_PARAMETER
;