2 Provides the basic interfaces to abstract a PCI Host Bridge Resource Allocation
4 Copyright (c) 2008 - 2013, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials are
6 licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "PciHostBridge.h"
18 // Hard code: Root Bridge Number within the host bridge
19 // Root Bridge's attribute
20 // Root Bridge's device path
21 // Root Bridge's resource aperture
23 UINTN RootBridgeNumber
[1] = { 1 };
25 UINT64 RootBridgeAttribute
[1][1] = { { EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM
} };
27 EFI_PCI_ROOT_BRIDGE_DEVICE_PATH mEfiPciRootBridgeDevicePath
[1][1] = {
35 (UINT8
) (sizeof(ACPI_HID_DEVICE_PATH
)),
36 (UINT8
) ((sizeof(ACPI_HID_DEVICE_PATH
)) >> 8)
45 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
47 END_DEVICE_PATH_LENGTH
,
55 PCI_ROOT_BRIDGE_RESOURCE_APERTURE mResAperture
[1][1] = {
56 {{0, 0xff, 0x80000000, 0xffffffff, 0, 0xffff}}
59 EFI_HANDLE mDriverImageHandle
;
61 PCI_HOST_BRIDGE_INSTANCE mPciHostBridgeInstanceTemplate
= {
62 PCI_HOST_BRIDGE_SIGNATURE
, // Signature
63 NULL
, // HostBridgeHandle
64 0, // RootBridgeNumber
66 FALSE
, // ResourceSubiteed
85 Entry point of this driver
87 @param ImageHandle Handle of driver image
88 @param SystemTable Point to EFI_SYSTEM_TABLE
90 @retval EFI_OUT_OF_RESOURCES Can not allocate memory resource
91 @retval EFI_DEVICE_ERROR Can not install the protocol instance
92 @retval EFI_SUCCESS Success to initialize the Pci host bridge.
96 InitializePciHostBridge (
97 IN EFI_HANDLE ImageHandle
,
98 IN EFI_SYSTEM_TABLE
*SystemTable
104 PCI_HOST_BRIDGE_INSTANCE
*HostBridge
;
105 PCI_ROOT_BRIDGE_INSTANCE
*PrivateData
;
107 mDriverImageHandle
= ImageHandle
;
110 // Create Host Bridge Device Handle
112 for (Loop1
= 0; Loop1
< HOST_BRIDGE_NUMBER
; Loop1
++) {
113 HostBridge
= AllocateCopyPool (sizeof(PCI_HOST_BRIDGE_INSTANCE
), &mPciHostBridgeInstanceTemplate
);
114 if (HostBridge
== NULL
) {
115 return EFI_OUT_OF_RESOURCES
;
118 HostBridge
->RootBridgeNumber
= RootBridgeNumber
[Loop1
];
119 InitializeListHead (&HostBridge
->Head
);
121 Status
= gBS
->InstallMultipleProtocolInterfaces (
122 &HostBridge
->HostBridgeHandle
,
123 &gEfiPciHostBridgeResourceAllocationProtocolGuid
, &HostBridge
->ResAlloc
,
126 if (EFI_ERROR (Status
)) {
127 FreePool (HostBridge
);
128 return EFI_DEVICE_ERROR
;
132 // Create Root Bridge Device Handle in this Host Bridge
135 for (Loop2
= 0; Loop2
< HostBridge
->RootBridgeNumber
; Loop2
++) {
136 PrivateData
= AllocateZeroPool (sizeof(PCI_ROOT_BRIDGE_INSTANCE
));
137 if (PrivateData
== NULL
) {
138 return EFI_OUT_OF_RESOURCES
;
141 PrivateData
->Signature
= PCI_ROOT_BRIDGE_SIGNATURE
;
142 PrivateData
->DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*)&mEfiPciRootBridgeDevicePath
[Loop1
][Loop2
];
144 RootBridgeConstructor (
146 HostBridge
->HostBridgeHandle
,
147 RootBridgeAttribute
[Loop1
][Loop2
],
148 &mResAperture
[Loop1
][Loop2
]
151 Status
= gBS
->InstallMultipleProtocolInterfaces(
152 &PrivateData
->Handle
,
153 &gEfiDevicePathProtocolGuid
, PrivateData
->DevicePath
,
154 &gEfiPciRootBridgeIoProtocolGuid
, &PrivateData
->Io
,
157 if (EFI_ERROR (Status
)) {
158 FreePool(PrivateData
);
159 return EFI_DEVICE_ERROR
;
162 InsertTailList (&HostBridge
->Head
, &PrivateData
->Link
);
171 These are the notifications from the PCI bus driver that it is about to enter a certain
172 phase of the PCI enumeration process.
174 This member function can be used to notify the host bridge driver to perform specific actions,
175 including any chipset-specific initialization, so that the chipset is ready to enter the next phase.
176 Eight notification points are defined at this time. See belows:
177 EfiPciHostBridgeBeginEnumeration Resets the host bridge PCI apertures and internal data
178 structures. The PCI enumerator should issue this notification
179 before starting a fresh enumeration process. Enumeration cannot
180 be restarted after sending any other notification such as
181 EfiPciHostBridgeBeginBusAllocation.
182 EfiPciHostBridgeBeginBusAllocation The bus allocation phase is about to begin. No specific action is
183 required here. This notification can be used to perform any
184 chipset-specific programming.
185 EfiPciHostBridgeEndBusAllocation The bus allocation and bus programming phase is complete. No
186 specific action is required here. This notification can be used to
187 perform any chipset-specific programming.
188 EfiPciHostBridgeBeginResourceAllocation
189 The resource allocation phase is about to begin. No specific
190 action is required here. This notification can be used to perform
191 any chipset-specific programming.
192 EfiPciHostBridgeAllocateResources Allocates resources per previously submitted requests for all the PCI
193 root bridges. These resource settings are returned on the next call to
194 GetProposedResources(). Before calling NotifyPhase() with a Phase of
195 EfiPciHostBridgeAllocateResource, the PCI bus enumerator is responsible
196 for gathering I/O and memory requests for
197 all the PCI root bridges and submitting these requests using
198 SubmitResources(). This function pads the resource amount
199 to suit the root bridge hardware, takes care of dependencies between
200 the PCI root bridges, and calls the Global Coherency Domain (GCD)
201 with the allocation request. In the case of padding, the allocated range
202 could be bigger than what was requested.
203 EfiPciHostBridgeSetResources Programs the host bridge hardware to decode previously allocated
204 resources (proposed resources) for all the PCI root bridges. After the
205 hardware is programmed, reassigning resources will not be supported.
206 The bus settings are not affected.
207 EfiPciHostBridgeFreeResources Deallocates resources that were previously allocated for all the PCI
208 root bridges and resets the I/O and memory apertures to their initial
209 state. The bus settings are not affected. If the request to allocate
210 resources fails, the PCI enumerator can use this notification to
211 deallocate previous resources, adjust the requests, and retry
213 EfiPciHostBridgeEndResourceAllocation The resource allocation phase is completed. No specific action is
214 required here. This notification can be used to perform any chipsetspecific
217 @param[in] This The instance pointer of EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
218 @param[in] Phase The phase during enumeration
220 @retval EFI_NOT_READY This phase cannot be entered at this time. For example, this error
221 is valid for a Phase of EfiPciHostBridgeAllocateResources if
222 SubmitResources() has not been called for one or more
223 PCI root bridges before this call
224 @retval EFI_DEVICE_ERROR Programming failed due to a hardware error. This error is valid
225 for a Phase of EfiPciHostBridgeSetResources.
226 @retval EFI_INVALID_PARAMETER Invalid phase parameter
227 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
228 This error is valid for a Phase of EfiPciHostBridgeAllocateResources if the
229 previously submitted resource requests cannot be fulfilled or
230 were only partially fulfilled.
231 @retval EFI_SUCCESS The notification was accepted without any errors.
237 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
238 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PHASE Phase
241 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
242 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
243 PCI_RESOURCE_TYPE Index
;
245 EFI_PHYSICAL_ADDRESS BaseAddress
;
247 UINTN BitsOfAlignment
;
249 EFI_STATUS ReturnStatus
;
251 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
255 case EfiPciHostBridgeBeginEnumeration
:
256 if (HostBridgeInstance
->CanRestarted
) {
258 // Reset the Each Root Bridge
260 List
= HostBridgeInstance
->Head
.ForwardLink
;
262 while (List
!= &HostBridgeInstance
->Head
) {
263 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
264 for (Index
= TypeIo
; Index
< TypeMax
; Index
++) {
265 RootBridgeInstance
->ResAllocNode
[Index
].Type
= Index
;
266 RootBridgeInstance
->ResAllocNode
[Index
].Base
= 0;
267 RootBridgeInstance
->ResAllocNode
[Index
].Length
= 0;
268 RootBridgeInstance
->ResAllocNode
[Index
].Status
= ResNone
;
271 List
= List
->ForwardLink
;
274 HostBridgeInstance
->ResourceSubmited
= FALSE
;
275 HostBridgeInstance
->CanRestarted
= TRUE
;
280 return EFI_NOT_READY
;
284 case EfiPciHostBridgeEndEnumeration
:
287 case EfiPciHostBridgeBeginBusAllocation
:
289 // No specific action is required here, can perform any chipset specific programing
291 HostBridgeInstance
->CanRestarted
= FALSE
;
294 case EfiPciHostBridgeEndBusAllocation
:
296 // No specific action is required here, can perform any chipset specific programing
298 //HostBridgeInstance->CanRestarted = FALSE;
301 case EfiPciHostBridgeBeginResourceAllocation
:
303 // No specific action is required here, can perform any chipset specific programing
305 //HostBridgeInstance->CanRestarted = FALSE;
308 case EfiPciHostBridgeAllocateResources
:
309 ReturnStatus
= EFI_SUCCESS
;
310 if (HostBridgeInstance
->ResourceSubmited
) {
312 // Take care of the resource dependencies between the root bridges
314 List
= HostBridgeInstance
->Head
.ForwardLink
;
316 while (List
!= &HostBridgeInstance
->Head
) {
317 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
318 for (Index
= TypeIo
; Index
< TypeBus
; Index
++) {
319 if (RootBridgeInstance
->ResAllocNode
[Index
].Status
!= ResNone
) {
321 AddrLen
= RootBridgeInstance
->ResAllocNode
[Index
].Length
;
324 // Get the number of '1' in Alignment.
326 BitsOfAlignment
= (UINTN
) (HighBitSet64 (RootBridgeInstance
->ResAllocNode
[Index
].Alignment
) + 1);
332 // It is impossible for this chipset to align 0xFFFF for IO16
335 if (BitsOfAlignment
>= 16) {
339 Status
= gDS
->AllocateIoSpace (
340 EfiGcdAllocateAnySearchBottomUp
,
349 if (!EFI_ERROR (Status
)) {
350 RootBridgeInstance
->ResAllocNode
[Index
].Base
= (UINTN
)BaseAddress
;
351 RootBridgeInstance
->ResAllocNode
[Index
].Status
= ResAllocated
;
353 ReturnStatus
= Status
;
354 if (Status
!= EFI_OUT_OF_RESOURCES
) {
355 RootBridgeInstance
->ResAllocNode
[Index
].Length
= 0;
364 // It is impossible for this chipset to align 0xFFFFFFFF for Mem32
368 if (BitsOfAlignment
>= 32) {
372 Status
= gDS
->AllocateMemorySpace (
373 EfiGcdAllocateAnySearchBottomUp
,
374 EfiGcdMemoryTypeMemoryMappedIo
,
382 if (!EFI_ERROR (Status
)) {
383 // We were able to allocate the PCI memory
384 RootBridgeInstance
->ResAllocNode
[Index
].Base
= (UINTN
)BaseAddress
;
385 RootBridgeInstance
->ResAllocNode
[Index
].Status
= ResAllocated
;
388 // Not able to allocate enough PCI memory
389 ReturnStatus
= Status
;
391 if (Status
!= EFI_OUT_OF_RESOURCES
) {
392 RootBridgeInstance
->ResAllocNode
[Index
].Length
= 0;
401 ReturnStatus
= EFI_ABORTED
;
410 List
= List
->ForwardLink
;
416 return EFI_NOT_READY
;
420 case EfiPciHostBridgeSetResources
:
423 case EfiPciHostBridgeFreeResources
:
424 ReturnStatus
= EFI_SUCCESS
;
425 List
= HostBridgeInstance
->Head
.ForwardLink
;
426 while (List
!= &HostBridgeInstance
->Head
) {
427 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
428 for (Index
= TypeIo
; Index
< TypeBus
; Index
++) {
429 if (RootBridgeInstance
->ResAllocNode
[Index
].Status
== ResAllocated
) {
430 AddrLen
= RootBridgeInstance
->ResAllocNode
[Index
].Length
;
431 BaseAddress
= RootBridgeInstance
->ResAllocNode
[Index
].Base
;
435 Status
= gDS
->FreeIoSpace (BaseAddress
, AddrLen
);
436 if (EFI_ERROR (Status
)) {
437 ReturnStatus
= Status
;
442 Status
= gDS
->FreeMemorySpace (BaseAddress
, AddrLen
);
443 if (EFI_ERROR (Status
)) {
444 ReturnStatus
= Status
;
462 RootBridgeInstance
->ResAllocNode
[Index
].Type
= Index
;
463 RootBridgeInstance
->ResAllocNode
[Index
].Base
= 0;
464 RootBridgeInstance
->ResAllocNode
[Index
].Length
= 0;
465 RootBridgeInstance
->ResAllocNode
[Index
].Status
= ResNone
;
469 List
= List
->ForwardLink
;
472 HostBridgeInstance
->ResourceSubmited
= FALSE
;
473 HostBridgeInstance
->CanRestarted
= TRUE
;
476 case EfiPciHostBridgeEndResourceAllocation
:
477 HostBridgeInstance
->CanRestarted
= FALSE
;
481 return EFI_INVALID_PARAMETER
;
488 Return the device handle of the next PCI root bridge that is associated with this Host Bridge.
490 This function is called multiple times to retrieve the device handles of all the PCI root bridges that
491 are associated with this PCI host bridge. Each PCI host bridge is associated with one or more PCI
492 root bridges. On each call, the handle that was returned by the previous call is passed into the
493 interface, and on output the interface returns the device handle of the next PCI root bridge. The
494 caller can use the handle to obtain the instance of the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
495 for that root bridge. When there are no more PCI root bridges to report, the interface returns
496 EFI_NOT_FOUND. A PCI enumerator must enumerate the PCI root bridges in the order that they
497 are returned by this function.
498 For D945 implementation, there is only one root bridge in PCI host bridge.
500 @param[in] This The instance pointer of EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
501 @param[in, out] RootBridgeHandle Returns the device handle of the next PCI root bridge.
503 @retval EFI_SUCCESS If parameter RootBridgeHandle = NULL, then return the first Rootbridge handle of the
504 specific Host bridge and return EFI_SUCCESS.
505 @retval EFI_NOT_FOUND Can not find the any more root bridge in specific host bridge.
506 @retval EFI_INVALID_PARAMETER RootBridgeHandle is not an EFI_HANDLE that was
507 returned on a previous call to GetNextRootBridge().
512 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
513 IN OUT EFI_HANDLE
*RootBridgeHandle
516 BOOLEAN NoRootBridge
;
518 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
519 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
522 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
523 List
= HostBridgeInstance
->Head
.ForwardLink
;
526 while (List
!= &HostBridgeInstance
->Head
) {
527 NoRootBridge
= FALSE
;
528 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
529 if (*RootBridgeHandle
== NULL
) {
531 // Return the first Root Bridge Handle of the Host Bridge
533 *RootBridgeHandle
= RootBridgeInstance
->Handle
;
536 if (*RootBridgeHandle
== RootBridgeInstance
->Handle
) {
540 List
= List
->ForwardLink
;
541 if (List
!=&HostBridgeInstance
->Head
) {
542 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
543 *RootBridgeHandle
= RootBridgeInstance
->Handle
;
546 return EFI_NOT_FOUND
;
551 List
= List
->ForwardLink
;
555 return EFI_NOT_FOUND
;
557 return EFI_INVALID_PARAMETER
;
562 Returns the allocation attributes of a PCI root bridge.
564 The function returns the allocation attributes of a specific PCI root bridge. The attributes can vary
565 from one PCI root bridge to another. These attributes are different from the decode-related
566 attributes that are returned by the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.GetAttributes() member function. The
567 RootBridgeHandle parameter is used to specify the instance of the PCI root bridge. The device
568 handles of all the root bridges that are associated with this host bridge must be obtained by calling
569 GetNextRootBridge(). The attributes are static in the sense that they do not change during or
570 after the enumeration process. The hardware may provide mechanisms to change the attributes on
571 the fly, but such changes must be completed before EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL is
572 installed. The permitted values of EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ATTRIBUTES are defined in
573 "Related Definitions" below. The caller uses these attributes to combine multiple resource requests.
574 For example, if the flag EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM is set, the PCI bus enumerator needs to
575 include requests for the prefetchable memory in the nonprefetchable memory pool and not request any
577 Attribute Description
578 ------------------------------------ ----------------------------------------------------------------------
579 EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM If this bit is set, then the PCI root bridge does not support separate
580 windows for nonprefetchable and prefetchable memory. A PCI bus
581 driver needs to include requests for prefetchable memory in the
582 nonprefetchable memory pool.
584 EFI_PCI_HOST_BRIDGE_MEM64_DECODE If this bit is set, then the PCI root bridge supports 64-bit memory
585 windows. If this bit is not set, the PCI bus driver needs to include
586 requests for a 64-bit memory address in the corresponding 32-bit
589 @param[in] This The instance pointer of EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
590 @param[in] RootBridgeHandle The device handle of the PCI root bridge in which the caller is interested. Type
591 EFI_HANDLE is defined in InstallProtocolInterface() in the UEFI 2.0 Specification.
592 @param[out] Attributes The pointer to attribte of root bridge, it is output parameter
594 @retval EFI_INVALID_PARAMETER Attribute pointer is NULL
595 @retval EFI_INVALID_PARAMETER RootBridgehandle is invalid.
596 @retval EFI_SUCCESS Success to get attribute of interested root bridge.
602 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
603 IN EFI_HANDLE RootBridgeHandle
,
604 OUT UINT64
*Attributes
608 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
609 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
611 if (Attributes
== NULL
) {
612 return EFI_INVALID_PARAMETER
;
615 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
616 List
= HostBridgeInstance
->Head
.ForwardLink
;
618 while (List
!= &HostBridgeInstance
->Head
) {
619 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
620 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
621 *Attributes
= RootBridgeInstance
->RootBridgeAttrib
;
624 List
= List
->ForwardLink
;
628 // RootBridgeHandle is not an EFI_HANDLE
629 // that was returned on a previous call to GetNextRootBridge()
631 return EFI_INVALID_PARAMETER
;
635 Sets up the specified PCI root bridge for the bus enumeration process.
637 This member function sets up the root bridge for bus enumeration and returns the PCI bus range
638 over which the search should be performed in ACPI 2.0 resource descriptor format.
640 @param[in] This The EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ PROTOCOL instance.
641 @param[in] RootBridgeHandle The PCI Root Bridge to be set up.
642 @param[out] Configuration Pointer to the pointer to the PCI bus resource descriptor.
644 @retval EFI_INVALID_PARAMETER Invalid Root bridge's handle
645 @retval EFI_OUT_OF_RESOURCES Fail to allocate ACPI resource descriptor tag.
646 @retval EFI_SUCCESS Sucess to allocate ACPI resource descriptor.
652 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
653 IN EFI_HANDLE RootBridgeHandle
,
654 OUT VOID
**Configuration
658 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
659 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
665 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
666 List
= HostBridgeInstance
->Head
.ForwardLink
;
668 while (List
!= &HostBridgeInstance
->Head
) {
669 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
670 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
672 // Set up the Root Bridge for Bus Enumeration
674 BusStart
= RootBridgeInstance
->BusBase
;
675 BusEnd
= RootBridgeInstance
->BusLimit
;
677 // Program the Hardware(if needed) if error return EFI_DEVICE_ERROR
680 Buffer
= AllocatePool (sizeof(EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) + sizeof(EFI_ACPI_END_TAG_DESCRIPTOR
));
681 if (Buffer
== NULL
) {
682 return EFI_OUT_OF_RESOURCES
;
685 Temp
= (UINT8
*)Buffer
;
687 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->Desc
= 0x8A;
688 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->Len
= 0x2B;
689 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->ResType
= 2;
690 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->GenFlag
= 0;
691 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->SpecificFlag
= 0;
692 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->AddrSpaceGranularity
= 0;
693 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->AddrRangeMin
= BusStart
;
694 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->AddrRangeMax
= 0;
695 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->AddrTranslationOffset
= 0;
696 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->AddrLen
= BusEnd
- BusStart
+ 1;
698 Temp
= Temp
+ sizeof(EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
);
699 ((EFI_ACPI_END_TAG_DESCRIPTOR
*)Temp
)->Desc
= 0x79;
700 ((EFI_ACPI_END_TAG_DESCRIPTOR
*)Temp
)->Checksum
= 0x0;
702 *Configuration
= Buffer
;
705 List
= List
->ForwardLink
;
708 return EFI_INVALID_PARAMETER
;
712 Programs the PCI root bridge hardware so that it decodes the specified PCI bus range.
714 This member function programs the specified PCI root bridge to decode the bus range that is
715 specified by the input parameter Configuration.
716 The bus range information is specified in terms of the ACPI 2.0 resource descriptor format.
718 @param[in] This The EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ PROTOCOL instance
719 @param[in] RootBridgeHandle The PCI Root Bridge whose bus range is to be programmed
720 @param[in] Configuration The pointer to the PCI bus resource descriptor
722 @retval EFI_INVALID_PARAMETER RootBridgeHandle is not a valid root bridge handle.
723 @retval EFI_INVALID_PARAMETER Configuration is NULL.
724 @retval EFI_INVALID_PARAMETER Configuration does not point to a valid ACPI 2.0 resource descriptor.
725 @retval EFI_INVALID_PARAMETER Configuration does not include a valid ACPI 2.0 bus resource descriptor.
726 @retval EFI_INVALID_PARAMETER Configuration includes valid ACPI 2.0 resource descriptors other than
728 @retval EFI_INVALID_PARAMETER Configuration contains one or more invalid ACPI resource descriptors.
729 @retval EFI_INVALID_PARAMETER "Address Range Minimum" is invalid for this root bridge.
730 @retval EFI_INVALID_PARAMETER "Address Range Length" is invalid for this root bridge.
731 @retval EFI_DEVICE_ERROR Programming failed due to a hardware error.
732 @retval EFI_SUCCESS The bus range for the PCI root bridge was programmed.
738 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
739 IN EFI_HANDLE RootBridgeHandle
,
740 IN VOID
*Configuration
744 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
745 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
751 if (Configuration
== NULL
) {
752 return EFI_INVALID_PARAMETER
;
758 // Check the Configuration is valid
760 if(*Ptr
!= ACPI_ADDRESS_SPACE_DESCRIPTOR
) {
761 return EFI_INVALID_PARAMETER
;
764 if (((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Ptr
)->ResType
!= 2) {
765 return EFI_INVALID_PARAMETER
;
768 Ptr
+= sizeof(EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
);
769 if (*Ptr
!= ACPI_END_TAG_DESCRIPTOR
) {
770 return EFI_INVALID_PARAMETER
;
773 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
774 List
= HostBridgeInstance
->Head
.ForwardLink
;
778 while (List
!= &HostBridgeInstance
->Head
) {
779 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
780 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
781 BusStart
= (UINTN
)((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Ptr
)->AddrRangeMin
;
782 BusLen
= (UINTN
)((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Ptr
)->AddrLen
;
783 BusEnd
= BusStart
+ BusLen
- 1;
785 if (BusStart
> BusEnd
) {
786 return EFI_INVALID_PARAMETER
;
789 if ((BusStart
< RootBridgeInstance
->BusBase
) || (BusEnd
> RootBridgeInstance
->BusLimit
)) {
790 return EFI_INVALID_PARAMETER
;
794 // Update the Bus Range
796 RootBridgeInstance
->ResAllocNode
[TypeBus
].Base
= BusStart
;
797 RootBridgeInstance
->ResAllocNode
[TypeBus
].Length
= BusLen
;
798 RootBridgeInstance
->ResAllocNode
[TypeBus
].Status
= ResAllocated
;
801 // Program the Root Bridge Hardware
807 List
= List
->ForwardLink
;
810 return EFI_INVALID_PARAMETER
;
815 Submits the I/O and memory resource requirements for the specified PCI root bridge.
817 This function is used to submit all the I/O and memory resources that are required by the specified
818 PCI root bridge. The input parameter Configuration is used to specify the following:
819 - The various types of resources that are required
820 - The associated lengths in terms of ACPI 2.0 resource descriptor format
822 @param[in] This Pointer to the EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL instance.
823 @param[in] RootBridgeHandle The PCI root bridge whose I/O and memory resource requirements are being submitted.
824 @param[in] Configuration The pointer to the PCI I/O and PCI memory resource descriptor.
826 @retval EFI_SUCCESS The I/O and memory resource requests for a PCI root bridge were accepted.
827 @retval EFI_INVALID_PARAMETER RootBridgeHandle is not a valid root bridge handle.
828 @retval EFI_INVALID_PARAMETER Configuration is NULL.
829 @retval EFI_INVALID_PARAMETER Configuration does not point to a valid ACPI 2.0 resource descriptor.
830 @retval EFI_INVALID_PARAMETER Configuration includes requests for one or more resource types that are
831 not supported by this PCI root bridge. This error will happen if the caller
832 did not combine resources according to Attributes that were returned by
833 GetAllocAttributes().
834 @retval EFI_INVALID_PARAMETER Address Range Maximum" is invalid.
835 @retval EFI_INVALID_PARAMETER "Address Range Length" is invalid for this PCI root bridge.
836 @retval EFI_INVALID_PARAMETER "Address Space Granularity" is invalid for this PCI root bridge.
842 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
843 IN EFI_HANDLE RootBridgeHandle
,
844 IN VOID
*Configuration
848 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
849 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
851 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Ptr
;
856 // Check the input parameter: Configuration
858 if (Configuration
== NULL
) {
859 return EFI_INVALID_PARAMETER
;
862 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
863 List
= HostBridgeInstance
->Head
.ForwardLink
;
865 Temp
= (UINT8
*)Configuration
;
866 while ( *Temp
== 0x8A) {
867 Temp
+= sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) ;
870 return EFI_INVALID_PARAMETER
;
873 Temp
= (UINT8
*)Configuration
;
874 while (List
!= &HostBridgeInstance
->Head
) {
875 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
876 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
877 while ( *Temp
== 0x8A) {
878 Ptr
= (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Temp
;
881 // Check Address Length
883 if (Ptr
->AddrLen
> 0xffffffff) {
884 return EFI_INVALID_PARAMETER
;
888 // Check address range alignment
890 if (Ptr
->AddrRangeMax
>= 0xffffffff || Ptr
->AddrRangeMax
!= (GetPowerOfTwo64 (Ptr
->AddrRangeMax
+ 1) - 1)) {
891 return EFI_INVALID_PARAMETER
;
894 switch (Ptr
->ResType
) {
899 // Check invalid Address Sapce Granularity
901 if (Ptr
->AddrSpaceGranularity
!= 32) {
902 return EFI_INVALID_PARAMETER
;
906 // check the memory resource request is supported by PCI root bridge
908 if (RootBridgeInstance
->RootBridgeAttrib
== EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM
&&
909 Ptr
->SpecificFlag
== 0x06) {
910 return EFI_INVALID_PARAMETER
;
913 AddrLen
= Ptr
->AddrLen
;
914 Alignment
= Ptr
->AddrRangeMax
;
915 if (Ptr
->AddrSpaceGranularity
== 32) {
916 if (Ptr
->SpecificFlag
== 0x06) {
920 RootBridgeInstance
->ResAllocNode
[TypePMem32
].Status
= ResSubmitted
;
922 RootBridgeInstance
->ResAllocNode
[TypeMem32
].Length
= AddrLen
;
923 RootBridgeInstance
->ResAllocNode
[TypeMem32
].Alignment
= Alignment
;
924 RootBridgeInstance
->ResAllocNode
[TypeMem32
].Status
= ResRequested
;
925 HostBridgeInstance
->ResourceSubmited
= TRUE
;
929 if (Ptr
->AddrSpaceGranularity
== 64) {
930 if (Ptr
->SpecificFlag
== 0x06) {
931 RootBridgeInstance
->ResAllocNode
[TypePMem64
].Status
= ResSubmitted
;
933 RootBridgeInstance
->ResAllocNode
[TypeMem64
].Status
= ResSubmitted
;
939 AddrLen
= (UINTN
) Ptr
->AddrLen
;
940 Alignment
= (UINTN
) Ptr
->AddrRangeMax
;
941 RootBridgeInstance
->ResAllocNode
[TypeIo
].Length
= AddrLen
;
942 RootBridgeInstance
->ResAllocNode
[TypeIo
].Alignment
= Alignment
;
943 RootBridgeInstance
->ResAllocNode
[TypeIo
].Status
= ResRequested
;
944 HostBridgeInstance
->ResourceSubmited
= TRUE
;
951 Temp
+= sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) ;
957 List
= List
->ForwardLink
;
960 return EFI_INVALID_PARAMETER
;
964 Returns the proposed resource settings for the specified PCI root bridge.
966 This member function returns the proposed resource settings for the specified PCI root bridge. The
967 proposed resource settings are prepared when NotifyPhase() is called with a Phase of
968 EfiPciHostBridgeAllocateResources. The output parameter Configuration
969 specifies the following:
970 - The various types of resources, excluding bus resources, that are allocated
971 - The associated lengths in terms of ACPI 2.0 resource descriptor format
973 @param[in] This Pointer to the EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL instance.
974 @param[in] RootBridgeHandle The PCI root bridge handle. Type EFI_HANDLE is defined in InstallProtocolInterface() in the UEFI 2.0 Specification.
975 @param[out] Configuration The pointer to the pointer to the PCI I/O and memory resource descriptor.
977 @retval EFI_SUCCESS The requested parameters were returned.
978 @retval EFI_INVALID_PARAMETER RootBridgeHandle is not a valid root bridge handle.
979 @retval EFI_DEVICE_ERROR Programming failed due to a hardware error.
980 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
985 GetProposedResources(
986 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
987 IN EFI_HANDLE RootBridgeHandle
,
988 OUT VOID
**Configuration
992 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
993 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
998 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Ptr
;
1004 // Get the Host Bridge Instance from the resource allocation protocol
1006 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
1007 List
= HostBridgeInstance
->Head
.ForwardLink
;
1010 // Enumerate the root bridges in this host bridge
1012 while (List
!= &HostBridgeInstance
->Head
) {
1013 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
1014 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
1015 for (Index
= 0; Index
< TypeBus
; Index
++) {
1016 if (RootBridgeInstance
->ResAllocNode
[Index
].Status
!= ResNone
) {
1022 return EFI_INVALID_PARAMETER
;
1025 Buffer
= AllocateZeroPool (Number
* sizeof(EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) + sizeof(EFI_ACPI_END_TAG_DESCRIPTOR
));
1026 if (Buffer
== NULL
) {
1027 return EFI_OUT_OF_RESOURCES
;
1031 for (Index
= 0; Index
< TypeBus
; Index
++) {
1032 if (RootBridgeInstance
->ResAllocNode
[Index
].Status
!= ResNone
) {
1033 Ptr
= (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Temp
;
1034 ResStatus
= RootBridgeInstance
->ResAllocNode
[Index
].Status
;
1046 Ptr
->SpecificFlag
= 0;
1047 Ptr
->AddrRangeMin
= RootBridgeInstance
->ResAllocNode
[Index
].Base
;
1048 Ptr
->AddrRangeMax
= 0;
1049 Ptr
->AddrTranslationOffset
= \
1050 (ResStatus
== ResAllocated
) ? EFI_RESOURCE_SATISFIED
: EFI_RESOURCE_LESS
;
1051 Ptr
->AddrLen
= RootBridgeInstance
->ResAllocNode
[Index
].Length
;
1062 Ptr
->SpecificFlag
= 0;
1063 Ptr
->AddrSpaceGranularity
= 32;
1064 Ptr
->AddrRangeMin
= RootBridgeInstance
->ResAllocNode
[Index
].Base
;
1065 Ptr
->AddrRangeMax
= 0;
1066 Ptr
->AddrTranslationOffset
= \
1067 (ResStatus
== ResAllocated
) ? EFI_RESOURCE_SATISFIED
: EFI_RESOURCE_LESS
;
1068 Ptr
->AddrLen
= RootBridgeInstance
->ResAllocNode
[Index
].Length
;
1073 // Prefetch memory 32
1079 Ptr
->SpecificFlag
= 6;
1080 Ptr
->AddrSpaceGranularity
= 32;
1081 Ptr
->AddrRangeMin
= 0;
1082 Ptr
->AddrRangeMax
= 0;
1083 Ptr
->AddrTranslationOffset
= EFI_RESOURCE_NONEXISTENT
;
1095 Ptr
->SpecificFlag
= 0;
1096 Ptr
->AddrSpaceGranularity
= 64;
1097 Ptr
->AddrRangeMin
= 0;
1098 Ptr
->AddrRangeMax
= 0;
1099 Ptr
->AddrTranslationOffset
= EFI_RESOURCE_NONEXISTENT
;
1105 // Prefetch memory 64
1111 Ptr
->SpecificFlag
= 6;
1112 Ptr
->AddrSpaceGranularity
= 64;
1113 Ptr
->AddrRangeMin
= 0;
1114 Ptr
->AddrRangeMax
= 0;
1115 Ptr
->AddrTranslationOffset
= EFI_RESOURCE_NONEXISTENT
;
1120 Temp
+= sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
);
1124 ((EFI_ACPI_END_TAG_DESCRIPTOR
*)Temp
)->Desc
= 0x79;
1125 ((EFI_ACPI_END_TAG_DESCRIPTOR
*)Temp
)->Checksum
= 0x0;
1127 *Configuration
= Buffer
;
1132 List
= List
->ForwardLink
;
1135 return EFI_INVALID_PARAMETER
;
1139 Provides the hooks from the PCI bus driver to every PCI controller (device/function) at various
1140 stages of the PCI enumeration process that allow the host bridge driver to preinitialize individual
1141 PCI controllers before enumeration.
1143 This function is called during the PCI enumeration process. No specific action is expected from this
1144 member function. It allows the host bridge driver to preinitialize individual PCI controllers before
1147 @param This Pointer to the EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL instance.
1148 @param RootBridgeHandle The associated PCI root bridge handle. Type EFI_HANDLE is defined in
1149 InstallProtocolInterface() in the UEFI 2.0 Specification.
1150 @param PciAddress The address of the PCI device on the PCI bus. This address can be passed to the
1151 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL member functions to access the PCI
1152 configuration space of the device. See Table 12-1 in the UEFI 2.0 Specification for
1153 the definition of EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS.
1154 @param Phase The phase of the PCI device enumeration.
1156 @retval EFI_SUCCESS The requested parameters were returned.
1157 @retval EFI_INVALID_PARAMETER RootBridgeHandle is not a valid root bridge handle.
1158 @retval EFI_INVALID_PARAMETER Phase is not a valid phase that is defined in
1159 EFI_PCI_CONTROLLER_RESOURCE_ALLOCATION_PHASE.
1160 @retval EFI_DEVICE_ERROR Programming failed due to a hardware error. The PCI enumerator should
1161 not enumerate this device, including its child devices if it is a PCI-to-PCI
1167 PreprocessController (
1168 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
1169 IN EFI_HANDLE RootBridgeHandle
,
1170 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS PciAddress
,
1171 IN EFI_PCI_CONTROLLER_RESOURCE_ALLOCATION_PHASE Phase
1174 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
1175 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
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
) {
1189 List
= List
->ForwardLink
;
1191 if (List
== &HostBridgeInstance
->Head
) {
1192 return EFI_INVALID_PARAMETER
;
1195 if ((UINT32
)Phase
> EfiPciBeforeResourceCollection
) {
1196 return EFI_INVALID_PARAMETER
;