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 STATIC PCI_ROOT_BRIDGE_RESOURCE_APERTURE mResAperture
[1][1];
57 EFI_HANDLE mDriverImageHandle
;
59 PCI_HOST_BRIDGE_INSTANCE mPciHostBridgeInstanceTemplate
= {
60 PCI_HOST_BRIDGE_SIGNATURE
, // Signature
61 NULL
, // HostBridgeHandle
62 0, // RootBridgeNumber
64 FALSE
, // ResourceSubiteed
83 Entry point of this driver
85 @param ImageHandle Handle of driver image
86 @param SystemTable Point to EFI_SYSTEM_TABLE
88 @retval EFI_ABORTED PCI host bridge not present
89 @retval EFI_OUT_OF_RESOURCES Can not allocate memory resource
90 @retval EFI_DEVICE_ERROR Can not install the protocol instance
91 @retval EFI_SUCCESS Success to initialize the Pci host bridge.
95 InitializePciHostBridge (
96 IN EFI_HANDLE ImageHandle
,
97 IN EFI_SYSTEM_TABLE
*SystemTable
103 PCI_HOST_BRIDGE_INSTANCE
*HostBridge
;
104 PCI_ROOT_BRIDGE_INSTANCE
*PrivateData
;
106 if (PcdGet64 (PcdPciExpressBaseAddress
) == 0) {
107 DEBUG ((EFI_D_INFO
, "%a: PCI host bridge not present\n", __FUNCTION__
));
111 mDriverImageHandle
= ImageHandle
;
113 mResAperture
[0][0].BusBase
= PcdGet32 (PcdPciBusMin
);
114 mResAperture
[0][0].BusLimit
= PcdGet32 (PcdPciBusMax
);
116 mResAperture
[0][0].MemBase
= PcdGet32 (PcdPciMmio32Base
);
117 mResAperture
[0][0].MemLimit
= (UINT64
)PcdGet32 (PcdPciMmio32Base
) +
118 PcdGet32 (PcdPciMmio32Size
) - 1;
120 mResAperture
[0][0].IoBase
= PcdGet64 (PcdPciIoBase
);
121 mResAperture
[0][0].IoLimit
= PcdGet64 (PcdPciIoBase
) +
122 PcdGet64 (PcdPciIoSize
) - 1;
123 mResAperture
[0][0].IoTranslation
= PcdGet64 (PcdPciIoTranslation
);
126 // Add IO and MMIO memory space, so that resources can be allocated in the
127 // EfiPciHostBridgeAllocateResources phase.
129 Status
= gDS
->AddIoSpace (
131 PcdGet64 (PcdPciIoBase
),
132 PcdGet64 (PcdPciIoSize
)
134 ASSERT_EFI_ERROR (Status
);
136 Status
= gDS
->AddMemorySpace (
137 EfiGcdMemoryTypeMemoryMappedIo
,
138 PcdGet32 (PcdPciMmio32Base
),
139 PcdGet32 (PcdPciMmio32Size
),
142 if (EFI_ERROR (Status
)) {
143 DEBUG ((EFI_D_ERROR
, "%a: AddMemorySpace: %r\n", __FUNCTION__
, Status
));
148 // Create Host Bridge Device Handle
150 for (Loop1
= 0; Loop1
< HOST_BRIDGE_NUMBER
; Loop1
++) {
151 HostBridge
= AllocateCopyPool (sizeof(PCI_HOST_BRIDGE_INSTANCE
), &mPciHostBridgeInstanceTemplate
);
152 if (HostBridge
== NULL
) {
153 return EFI_OUT_OF_RESOURCES
;
156 HostBridge
->RootBridgeNumber
= RootBridgeNumber
[Loop1
];
157 InitializeListHead (&HostBridge
->Head
);
159 Status
= gBS
->InstallMultipleProtocolInterfaces (
160 &HostBridge
->HostBridgeHandle
,
161 &gEfiPciHostBridgeResourceAllocationProtocolGuid
, &HostBridge
->ResAlloc
,
164 if (EFI_ERROR (Status
)) {
165 FreePool (HostBridge
);
166 return EFI_DEVICE_ERROR
;
170 // Create Root Bridge Device Handle in this Host Bridge
173 for (Loop2
= 0; Loop2
< HostBridge
->RootBridgeNumber
; Loop2
++) {
174 PrivateData
= AllocateZeroPool (sizeof(PCI_ROOT_BRIDGE_INSTANCE
));
175 if (PrivateData
== NULL
) {
176 return EFI_OUT_OF_RESOURCES
;
179 PrivateData
->Signature
= PCI_ROOT_BRIDGE_SIGNATURE
;
180 PrivateData
->DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*)&mEfiPciRootBridgeDevicePath
[Loop1
][Loop2
];
182 RootBridgeConstructor (
184 HostBridge
->HostBridgeHandle
,
185 RootBridgeAttribute
[Loop1
][Loop2
],
186 &mResAperture
[Loop1
][Loop2
]
189 Status
= gBS
->InstallMultipleProtocolInterfaces(
190 &PrivateData
->Handle
,
191 &gEfiDevicePathProtocolGuid
, PrivateData
->DevicePath
,
192 &gEfiPciRootBridgeIoProtocolGuid
, &PrivateData
->Io
,
195 if (EFI_ERROR (Status
)) {
196 FreePool(PrivateData
);
197 return EFI_DEVICE_ERROR
;
200 InsertTailList (&HostBridge
->Head
, &PrivateData
->Link
);
209 These are the notifications from the PCI bus driver that it is about to enter a certain
210 phase of the PCI enumeration process.
212 This member function can be used to notify the host bridge driver to perform specific actions,
213 including any chipset-specific initialization, so that the chipset is ready to enter the next phase.
214 Eight notification points are defined at this time. See belows:
215 EfiPciHostBridgeBeginEnumeration Resets the host bridge PCI apertures and internal data
216 structures. The PCI enumerator should issue this notification
217 before starting a fresh enumeration process. Enumeration cannot
218 be restarted after sending any other notification such as
219 EfiPciHostBridgeBeginBusAllocation.
220 EfiPciHostBridgeBeginBusAllocation The bus allocation phase is about to begin. No specific action is
221 required here. This notification can be used to perform any
222 chipset-specific programming.
223 EfiPciHostBridgeEndBusAllocation The bus allocation and bus programming phase is complete. No
224 specific action is required here. This notification can be used to
225 perform any chipset-specific programming.
226 EfiPciHostBridgeBeginResourceAllocation
227 The resource allocation phase is about to begin. No specific
228 action is required here. This notification can be used to perform
229 any chipset-specific programming.
230 EfiPciHostBridgeAllocateResources Allocates resources per previously submitted requests for all the PCI
231 root bridges. These resource settings are returned on the next call to
232 GetProposedResources(). Before calling NotifyPhase() with a Phase of
233 EfiPciHostBridgeAllocateResource, the PCI bus enumerator is responsible
234 for gathering I/O and memory requests for
235 all the PCI root bridges and submitting these requests using
236 SubmitResources(). This function pads the resource amount
237 to suit the root bridge hardware, takes care of dependencies between
238 the PCI root bridges, and calls the Global Coherency Domain (GCD)
239 with the allocation request. In the case of padding, the allocated range
240 could be bigger than what was requested.
241 EfiPciHostBridgeSetResources Programs the host bridge hardware to decode previously allocated
242 resources (proposed resources) for all the PCI root bridges. After the
243 hardware is programmed, reassigning resources will not be supported.
244 The bus settings are not affected.
245 EfiPciHostBridgeFreeResources Deallocates resources that were previously allocated for all the PCI
246 root bridges and resets the I/O and memory apertures to their initial
247 state. The bus settings are not affected. If the request to allocate
248 resources fails, the PCI enumerator can use this notification to
249 deallocate previous resources, adjust the requests, and retry
251 EfiPciHostBridgeEndResourceAllocation The resource allocation phase is completed. No specific action is
252 required here. This notification can be used to perform any chipsetspecific
255 @param[in] This The instance pointer of EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
256 @param[in] Phase The phase during enumeration
258 @retval EFI_NOT_READY This phase cannot be entered at this time. For example, this error
259 is valid for a Phase of EfiPciHostBridgeAllocateResources if
260 SubmitResources() has not been called for one or more
261 PCI root bridges before this call
262 @retval EFI_DEVICE_ERROR Programming failed due to a hardware error. This error is valid
263 for a Phase of EfiPciHostBridgeSetResources.
264 @retval EFI_INVALID_PARAMETER Invalid phase parameter
265 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
266 This error is valid for a Phase of EfiPciHostBridgeAllocateResources if the
267 previously submitted resource requests cannot be fulfilled or
268 were only partially fulfilled.
269 @retval EFI_SUCCESS The notification was accepted without any errors.
275 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
276 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PHASE Phase
279 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
280 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
281 PCI_RESOURCE_TYPE Index
;
283 EFI_PHYSICAL_ADDRESS BaseAddress
;
285 UINTN BitsOfAlignment
;
287 EFI_STATUS ReturnStatus
;
289 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
293 case EfiPciHostBridgeBeginEnumeration
:
294 if (HostBridgeInstance
->CanRestarted
) {
296 // Reset the Each Root Bridge
298 List
= HostBridgeInstance
->Head
.ForwardLink
;
300 while (List
!= &HostBridgeInstance
->Head
) {
301 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
302 for (Index
= TypeIo
; Index
< TypeMax
; Index
++) {
303 RootBridgeInstance
->ResAllocNode
[Index
].Type
= Index
;
304 RootBridgeInstance
->ResAllocNode
[Index
].Base
= 0;
305 RootBridgeInstance
->ResAllocNode
[Index
].Length
= 0;
306 RootBridgeInstance
->ResAllocNode
[Index
].Status
= ResNone
;
309 List
= List
->ForwardLink
;
312 HostBridgeInstance
->ResourceSubmited
= FALSE
;
313 HostBridgeInstance
->CanRestarted
= TRUE
;
318 return EFI_NOT_READY
;
322 case EfiPciHostBridgeEndEnumeration
:
325 case EfiPciHostBridgeBeginBusAllocation
:
327 // No specific action is required here, can perform any chipset specific programing
329 HostBridgeInstance
->CanRestarted
= FALSE
;
332 case EfiPciHostBridgeEndBusAllocation
:
334 // No specific action is required here, can perform any chipset specific programing
336 //HostBridgeInstance->CanRestarted = FALSE;
339 case EfiPciHostBridgeBeginResourceAllocation
:
341 // No specific action is required here, can perform any chipset specific programing
343 //HostBridgeInstance->CanRestarted = FALSE;
346 case EfiPciHostBridgeAllocateResources
:
347 ReturnStatus
= EFI_SUCCESS
;
348 if (HostBridgeInstance
->ResourceSubmited
) {
350 // Take care of the resource dependencies between the root bridges
352 List
= HostBridgeInstance
->Head
.ForwardLink
;
354 while (List
!= &HostBridgeInstance
->Head
) {
355 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
356 for (Index
= TypeIo
; Index
< TypeBus
; Index
++) {
357 if (RootBridgeInstance
->ResAllocNode
[Index
].Status
!= ResNone
) {
359 AddrLen
= RootBridgeInstance
->ResAllocNode
[Index
].Length
;
362 // Get the number of '1' in Alignment.
364 BitsOfAlignment
= (UINTN
) (HighBitSet64 (RootBridgeInstance
->ResAllocNode
[Index
].Alignment
) + 1);
370 // It is impossible for this chipset to align 0xFFFF for IO16
373 if (BitsOfAlignment
>= 16) {
377 Status
= gDS
->AllocateIoSpace (
378 EfiGcdAllocateAnySearchBottomUp
,
387 if (!EFI_ERROR (Status
)) {
388 RootBridgeInstance
->ResAllocNode
[Index
].Base
= (UINTN
)BaseAddress
;
389 RootBridgeInstance
->ResAllocNode
[Index
].Status
= ResAllocated
;
391 ReturnStatus
= Status
;
392 if (Status
!= EFI_OUT_OF_RESOURCES
) {
393 RootBridgeInstance
->ResAllocNode
[Index
].Length
= 0;
402 // It is impossible for this chipset to align 0xFFFFFFFF for Mem32
406 if (BitsOfAlignment
>= 32) {
410 Status
= gDS
->AllocateMemorySpace (
411 EfiGcdAllocateAnySearchBottomUp
,
412 EfiGcdMemoryTypeMemoryMappedIo
,
420 if (!EFI_ERROR (Status
)) {
421 // We were able to allocate the PCI memory
422 RootBridgeInstance
->ResAllocNode
[Index
].Base
= (UINTN
)BaseAddress
;
423 RootBridgeInstance
->ResAllocNode
[Index
].Status
= ResAllocated
;
426 // Not able to allocate enough PCI memory
427 ReturnStatus
= Status
;
429 if (Status
!= EFI_OUT_OF_RESOURCES
) {
430 RootBridgeInstance
->ResAllocNode
[Index
].Length
= 0;
439 ReturnStatus
= EFI_ABORTED
;
448 List
= List
->ForwardLink
;
454 return EFI_NOT_READY
;
458 case EfiPciHostBridgeSetResources
:
461 case EfiPciHostBridgeFreeResources
:
462 ReturnStatus
= EFI_SUCCESS
;
463 List
= HostBridgeInstance
->Head
.ForwardLink
;
464 while (List
!= &HostBridgeInstance
->Head
) {
465 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
466 for (Index
= TypeIo
; Index
< TypeBus
; Index
++) {
467 if (RootBridgeInstance
->ResAllocNode
[Index
].Status
== ResAllocated
) {
468 AddrLen
= RootBridgeInstance
->ResAllocNode
[Index
].Length
;
469 BaseAddress
= RootBridgeInstance
->ResAllocNode
[Index
].Base
;
473 Status
= gDS
->FreeIoSpace (BaseAddress
, AddrLen
);
474 if (EFI_ERROR (Status
)) {
475 ReturnStatus
= Status
;
480 Status
= gDS
->FreeMemorySpace (BaseAddress
, AddrLen
);
481 if (EFI_ERROR (Status
)) {
482 ReturnStatus
= Status
;
500 RootBridgeInstance
->ResAllocNode
[Index
].Type
= Index
;
501 RootBridgeInstance
->ResAllocNode
[Index
].Base
= 0;
502 RootBridgeInstance
->ResAllocNode
[Index
].Length
= 0;
503 RootBridgeInstance
->ResAllocNode
[Index
].Status
= ResNone
;
507 List
= List
->ForwardLink
;
510 HostBridgeInstance
->ResourceSubmited
= FALSE
;
511 HostBridgeInstance
->CanRestarted
= TRUE
;
514 case EfiPciHostBridgeEndResourceAllocation
:
515 HostBridgeInstance
->CanRestarted
= FALSE
;
519 return EFI_INVALID_PARAMETER
;
526 Return the device handle of the next PCI root bridge that is associated with this Host Bridge.
528 This function is called multiple times to retrieve the device handles of all the PCI root bridges that
529 are associated with this PCI host bridge. Each PCI host bridge is associated with one or more PCI
530 root bridges. On each call, the handle that was returned by the previous call is passed into the
531 interface, and on output the interface returns the device handle of the next PCI root bridge. The
532 caller can use the handle to obtain the instance of the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
533 for that root bridge. When there are no more PCI root bridges to report, the interface returns
534 EFI_NOT_FOUND. A PCI enumerator must enumerate the PCI root bridges in the order that they
535 are returned by this function.
536 For D945 implementation, there is only one root bridge in PCI host bridge.
538 @param[in] This The instance pointer of EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
539 @param[in, out] RootBridgeHandle Returns the device handle of the next PCI root bridge.
541 @retval EFI_SUCCESS If parameter RootBridgeHandle = NULL, then return the first Rootbridge handle of the
542 specific Host bridge and return EFI_SUCCESS.
543 @retval EFI_NOT_FOUND Can not find the any more root bridge in specific host bridge.
544 @retval EFI_INVALID_PARAMETER RootBridgeHandle is not an EFI_HANDLE that was
545 returned on a previous call to GetNextRootBridge().
550 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
551 IN OUT EFI_HANDLE
*RootBridgeHandle
554 BOOLEAN NoRootBridge
;
556 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
557 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
560 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
561 List
= HostBridgeInstance
->Head
.ForwardLink
;
564 while (List
!= &HostBridgeInstance
->Head
) {
565 NoRootBridge
= FALSE
;
566 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
567 if (*RootBridgeHandle
== NULL
) {
569 // Return the first Root Bridge Handle of the Host Bridge
571 *RootBridgeHandle
= RootBridgeInstance
->Handle
;
574 if (*RootBridgeHandle
== RootBridgeInstance
->Handle
) {
578 List
= List
->ForwardLink
;
579 if (List
!=&HostBridgeInstance
->Head
) {
580 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
581 *RootBridgeHandle
= RootBridgeInstance
->Handle
;
584 return EFI_NOT_FOUND
;
589 List
= List
->ForwardLink
;
593 return EFI_NOT_FOUND
;
595 return EFI_INVALID_PARAMETER
;
600 Returns the allocation attributes of a PCI root bridge.
602 The function returns the allocation attributes of a specific PCI root bridge. The attributes can vary
603 from one PCI root bridge to another. These attributes are different from the decode-related
604 attributes that are returned by the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.GetAttributes() member function. The
605 RootBridgeHandle parameter is used to specify the instance of the PCI root bridge. The device
606 handles of all the root bridges that are associated with this host bridge must be obtained by calling
607 GetNextRootBridge(). The attributes are static in the sense that they do not change during or
608 after the enumeration process. The hardware may provide mechanisms to change the attributes on
609 the fly, but such changes must be completed before EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL is
610 installed. The permitted values of EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ATTRIBUTES are defined in
611 "Related Definitions" below. The caller uses these attributes to combine multiple resource requests.
612 For example, if the flag EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM is set, the PCI bus enumerator needs to
613 include requests for the prefetchable memory in the nonprefetchable memory pool and not request any
615 Attribute Description
616 ------------------------------------ ----------------------------------------------------------------------
617 EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM If this bit is set, then the PCI root bridge does not support separate
618 windows for nonprefetchable and prefetchable memory. A PCI bus
619 driver needs to include requests for prefetchable memory in the
620 nonprefetchable memory pool.
622 EFI_PCI_HOST_BRIDGE_MEM64_DECODE If this bit is set, then the PCI root bridge supports 64-bit memory
623 windows. If this bit is not set, the PCI bus driver needs to include
624 requests for a 64-bit memory address in the corresponding 32-bit
627 @param[in] This The instance pointer of EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
628 @param[in] RootBridgeHandle The device handle of the PCI root bridge in which the caller is interested. Type
629 EFI_HANDLE is defined in InstallProtocolInterface() in the UEFI 2.0 Specification.
630 @param[out] Attributes The pointer to attribte of root bridge, it is output parameter
632 @retval EFI_INVALID_PARAMETER Attribute pointer is NULL
633 @retval EFI_INVALID_PARAMETER RootBridgehandle is invalid.
634 @retval EFI_SUCCESS Success to get attribute of interested root bridge.
640 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
641 IN EFI_HANDLE RootBridgeHandle
,
642 OUT UINT64
*Attributes
646 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
647 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
649 if (Attributes
== NULL
) {
650 return EFI_INVALID_PARAMETER
;
653 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
654 List
= HostBridgeInstance
->Head
.ForwardLink
;
656 while (List
!= &HostBridgeInstance
->Head
) {
657 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
658 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
659 *Attributes
= RootBridgeInstance
->RootBridgeAttrib
;
662 List
= List
->ForwardLink
;
666 // RootBridgeHandle is not an EFI_HANDLE
667 // that was returned on a previous call to GetNextRootBridge()
669 return EFI_INVALID_PARAMETER
;
673 Sets up the specified PCI root bridge for the bus enumeration process.
675 This member function sets up the root bridge for bus enumeration and returns the PCI bus range
676 over which the search should be performed in ACPI 2.0 resource descriptor format.
678 @param[in] This The EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ PROTOCOL instance.
679 @param[in] RootBridgeHandle The PCI Root Bridge to be set up.
680 @param[out] Configuration Pointer to the pointer to the PCI bus resource descriptor.
682 @retval EFI_INVALID_PARAMETER Invalid Root bridge's handle
683 @retval EFI_OUT_OF_RESOURCES Fail to allocate ACPI resource descriptor tag.
684 @retval EFI_SUCCESS Sucess to allocate ACPI resource descriptor.
690 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
691 IN EFI_HANDLE RootBridgeHandle
,
692 OUT VOID
**Configuration
696 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
697 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
703 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
704 List
= HostBridgeInstance
->Head
.ForwardLink
;
706 while (List
!= &HostBridgeInstance
->Head
) {
707 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
708 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
710 // Set up the Root Bridge for Bus Enumeration
712 BusStart
= RootBridgeInstance
->BusBase
;
713 BusEnd
= RootBridgeInstance
->BusLimit
;
715 // Program the Hardware(if needed) if error return EFI_DEVICE_ERROR
718 Buffer
= AllocatePool (sizeof(EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) + sizeof(EFI_ACPI_END_TAG_DESCRIPTOR
));
719 if (Buffer
== NULL
) {
720 return EFI_OUT_OF_RESOURCES
;
723 Temp
= (UINT8
*)Buffer
;
725 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->Desc
= 0x8A;
726 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->Len
= 0x2B;
727 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->ResType
= 2;
728 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->GenFlag
= 0;
729 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->SpecificFlag
= 0;
730 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->AddrSpaceGranularity
= 0;
731 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->AddrRangeMin
= BusStart
;
732 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->AddrRangeMax
= 0;
733 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->AddrTranslationOffset
= 0;
734 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->AddrLen
= BusEnd
- BusStart
+ 1;
736 Temp
= Temp
+ sizeof(EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
);
737 ((EFI_ACPI_END_TAG_DESCRIPTOR
*)Temp
)->Desc
= 0x79;
738 ((EFI_ACPI_END_TAG_DESCRIPTOR
*)Temp
)->Checksum
= 0x0;
740 *Configuration
= Buffer
;
743 List
= List
->ForwardLink
;
746 return EFI_INVALID_PARAMETER
;
750 Programs the PCI root bridge hardware so that it decodes the specified PCI bus range.
752 This member function programs the specified PCI root bridge to decode the bus range that is
753 specified by the input parameter Configuration.
754 The bus range information is specified in terms of the ACPI 2.0 resource descriptor format.
756 @param[in] This The EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ PROTOCOL instance
757 @param[in] RootBridgeHandle The PCI Root Bridge whose bus range is to be programmed
758 @param[in] Configuration The pointer to the PCI bus resource descriptor
760 @retval EFI_INVALID_PARAMETER RootBridgeHandle is not a valid root bridge handle.
761 @retval EFI_INVALID_PARAMETER Configuration is NULL.
762 @retval EFI_INVALID_PARAMETER Configuration does not point to a valid ACPI 2.0 resource descriptor.
763 @retval EFI_INVALID_PARAMETER Configuration does not include a valid ACPI 2.0 bus resource descriptor.
764 @retval EFI_INVALID_PARAMETER Configuration includes valid ACPI 2.0 resource descriptors other than
766 @retval EFI_INVALID_PARAMETER Configuration contains one or more invalid ACPI resource descriptors.
767 @retval EFI_INVALID_PARAMETER "Address Range Minimum" is invalid for this root bridge.
768 @retval EFI_INVALID_PARAMETER "Address Range Length" is invalid for this root bridge.
769 @retval EFI_DEVICE_ERROR Programming failed due to a hardware error.
770 @retval EFI_SUCCESS The bus range for the PCI root bridge was programmed.
776 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
777 IN EFI_HANDLE RootBridgeHandle
,
778 IN VOID
*Configuration
782 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
783 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
789 if (Configuration
== NULL
) {
790 return EFI_INVALID_PARAMETER
;
796 // Check the Configuration is valid
798 if(*Ptr
!= ACPI_ADDRESS_SPACE_DESCRIPTOR
) {
799 return EFI_INVALID_PARAMETER
;
802 if (((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Ptr
)->ResType
!= 2) {
803 return EFI_INVALID_PARAMETER
;
806 Ptr
+= sizeof(EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
);
807 if (*Ptr
!= ACPI_END_TAG_DESCRIPTOR
) {
808 return EFI_INVALID_PARAMETER
;
811 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
812 List
= HostBridgeInstance
->Head
.ForwardLink
;
816 while (List
!= &HostBridgeInstance
->Head
) {
817 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
818 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
819 BusStart
= (UINTN
)((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Ptr
)->AddrRangeMin
;
820 BusLen
= (UINTN
)((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Ptr
)->AddrLen
;
821 BusEnd
= BusStart
+ BusLen
- 1;
823 if (BusStart
> BusEnd
) {
824 return EFI_INVALID_PARAMETER
;
827 if ((BusStart
< RootBridgeInstance
->BusBase
) || (BusEnd
> RootBridgeInstance
->BusLimit
)) {
828 return EFI_INVALID_PARAMETER
;
832 // Update the Bus Range
834 RootBridgeInstance
->ResAllocNode
[TypeBus
].Base
= BusStart
;
835 RootBridgeInstance
->ResAllocNode
[TypeBus
].Length
= BusLen
;
836 RootBridgeInstance
->ResAllocNode
[TypeBus
].Status
= ResAllocated
;
839 // Program the Root Bridge Hardware
845 List
= List
->ForwardLink
;
848 return EFI_INVALID_PARAMETER
;
853 Submits the I/O and memory resource requirements for the specified PCI root bridge.
855 This function is used to submit all the I/O and memory resources that are required by the specified
856 PCI root bridge. The input parameter Configuration is used to specify the following:
857 - The various types of resources that are required
858 - The associated lengths in terms of ACPI 2.0 resource descriptor format
860 @param[in] This Pointer to the EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL instance.
861 @param[in] RootBridgeHandle The PCI root bridge whose I/O and memory resource requirements are being submitted.
862 @param[in] Configuration The pointer to the PCI I/O and PCI memory resource descriptor.
864 @retval EFI_SUCCESS The I/O and memory resource requests for a PCI root bridge were accepted.
865 @retval EFI_INVALID_PARAMETER RootBridgeHandle is not a valid root bridge handle.
866 @retval EFI_INVALID_PARAMETER Configuration is NULL.
867 @retval EFI_INVALID_PARAMETER Configuration does not point to a valid ACPI 2.0 resource descriptor.
868 @retval EFI_INVALID_PARAMETER Configuration includes requests for one or more resource types that are
869 not supported by this PCI root bridge. This error will happen if the caller
870 did not combine resources according to Attributes that were returned by
871 GetAllocAttributes().
872 @retval EFI_INVALID_PARAMETER Address Range Maximum" is invalid.
873 @retval EFI_INVALID_PARAMETER "Address Range Length" is invalid for this PCI root bridge.
874 @retval EFI_INVALID_PARAMETER "Address Space Granularity" is invalid for this PCI root bridge.
880 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
881 IN EFI_HANDLE RootBridgeHandle
,
882 IN VOID
*Configuration
886 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
887 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
889 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Ptr
;
894 // Check the input parameter: Configuration
896 if (Configuration
== NULL
) {
897 return EFI_INVALID_PARAMETER
;
900 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
901 List
= HostBridgeInstance
->Head
.ForwardLink
;
903 Temp
= (UINT8
*)Configuration
;
904 while ( *Temp
== 0x8A) {
905 Temp
+= sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) ;
908 return EFI_INVALID_PARAMETER
;
911 Temp
= (UINT8
*)Configuration
;
912 while (List
!= &HostBridgeInstance
->Head
) {
913 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
914 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
915 while ( *Temp
== 0x8A) {
916 Ptr
= (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Temp
;
919 // Check Address Length
921 if (Ptr
->AddrLen
> 0xffffffff) {
922 return EFI_INVALID_PARAMETER
;
926 // Check address range alignment
928 if (Ptr
->AddrRangeMax
>= 0xffffffff || Ptr
->AddrRangeMax
!= (GetPowerOfTwo64 (Ptr
->AddrRangeMax
+ 1) - 1)) {
929 return EFI_INVALID_PARAMETER
;
932 switch (Ptr
->ResType
) {
937 // Check invalid Address Sapce Granularity
939 if (Ptr
->AddrSpaceGranularity
!= 32) {
940 return EFI_INVALID_PARAMETER
;
944 // check the memory resource request is supported by PCI root bridge
946 if (RootBridgeInstance
->RootBridgeAttrib
== EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM
&&
947 Ptr
->SpecificFlag
== 0x06) {
948 return EFI_INVALID_PARAMETER
;
951 AddrLen
= Ptr
->AddrLen
;
952 Alignment
= Ptr
->AddrRangeMax
;
953 if (Ptr
->AddrSpaceGranularity
== 32) {
954 if (Ptr
->SpecificFlag
== 0x06) {
958 RootBridgeInstance
->ResAllocNode
[TypePMem32
].Status
= ResSubmitted
;
960 RootBridgeInstance
->ResAllocNode
[TypeMem32
].Length
= AddrLen
;
961 RootBridgeInstance
->ResAllocNode
[TypeMem32
].Alignment
= Alignment
;
962 RootBridgeInstance
->ResAllocNode
[TypeMem32
].Status
= ResRequested
;
963 HostBridgeInstance
->ResourceSubmited
= TRUE
;
967 if (Ptr
->AddrSpaceGranularity
== 64) {
968 if (Ptr
->SpecificFlag
== 0x06) {
969 RootBridgeInstance
->ResAllocNode
[TypePMem64
].Status
= ResSubmitted
;
971 RootBridgeInstance
->ResAllocNode
[TypeMem64
].Status
= ResSubmitted
;
977 AddrLen
= (UINTN
) Ptr
->AddrLen
;
978 Alignment
= (UINTN
) Ptr
->AddrRangeMax
;
979 RootBridgeInstance
->ResAllocNode
[TypeIo
].Length
= AddrLen
;
980 RootBridgeInstance
->ResAllocNode
[TypeIo
].Alignment
= Alignment
;
981 RootBridgeInstance
->ResAllocNode
[TypeIo
].Status
= ResRequested
;
982 HostBridgeInstance
->ResourceSubmited
= TRUE
;
989 Temp
+= sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) ;
995 List
= List
->ForwardLink
;
998 return EFI_INVALID_PARAMETER
;
1002 Returns the proposed resource settings for the specified PCI root bridge.
1004 This member function returns the proposed resource settings for the specified PCI root bridge. The
1005 proposed resource settings are prepared when NotifyPhase() is called with a Phase of
1006 EfiPciHostBridgeAllocateResources. The output parameter Configuration
1007 specifies the following:
1008 - The various types of resources, excluding bus resources, that are allocated
1009 - The associated lengths in terms of ACPI 2.0 resource descriptor format
1011 @param[in] This Pointer to the EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL instance.
1012 @param[in] RootBridgeHandle The PCI root bridge handle. Type EFI_HANDLE is defined in InstallProtocolInterface() in the UEFI 2.0 Specification.
1013 @param[out] Configuration The pointer to the pointer to the PCI I/O and memory resource descriptor.
1015 @retval EFI_SUCCESS The requested parameters were returned.
1016 @retval EFI_INVALID_PARAMETER RootBridgeHandle is not a valid root bridge handle.
1017 @retval EFI_DEVICE_ERROR Programming failed due to a hardware error.
1018 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
1023 GetProposedResources(
1024 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
1025 IN EFI_HANDLE RootBridgeHandle
,
1026 OUT VOID
**Configuration
1030 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
1031 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
1036 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Ptr
;
1042 // Get the Host Bridge Instance from the resource allocation protocol
1044 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
1045 List
= HostBridgeInstance
->Head
.ForwardLink
;
1048 // Enumerate the root bridges in this host bridge
1050 while (List
!= &HostBridgeInstance
->Head
) {
1051 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
1052 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
1053 for (Index
= 0; Index
< TypeBus
; Index
++) {
1054 if (RootBridgeInstance
->ResAllocNode
[Index
].Status
!= ResNone
) {
1060 return EFI_INVALID_PARAMETER
;
1063 Buffer
= AllocateZeroPool (Number
* sizeof(EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) + sizeof(EFI_ACPI_END_TAG_DESCRIPTOR
));
1064 if (Buffer
== NULL
) {
1065 return EFI_OUT_OF_RESOURCES
;
1069 for (Index
= 0; Index
< TypeBus
; Index
++) {
1070 if (RootBridgeInstance
->ResAllocNode
[Index
].Status
!= ResNone
) {
1071 Ptr
= (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Temp
;
1072 ResStatus
= RootBridgeInstance
->ResAllocNode
[Index
].Status
;
1084 Ptr
->SpecificFlag
= 0;
1085 Ptr
->AddrRangeMin
= RootBridgeInstance
->ResAllocNode
[Index
].Base
;
1086 Ptr
->AddrRangeMax
= 0;
1087 Ptr
->AddrTranslationOffset
= \
1088 (ResStatus
== ResAllocated
) ? EFI_RESOURCE_SATISFIED
: EFI_RESOURCE_LESS
;
1089 Ptr
->AddrLen
= RootBridgeInstance
->ResAllocNode
[Index
].Length
;
1100 Ptr
->SpecificFlag
= 0;
1101 Ptr
->AddrSpaceGranularity
= 32;
1102 Ptr
->AddrRangeMin
= RootBridgeInstance
->ResAllocNode
[Index
].Base
;
1103 Ptr
->AddrRangeMax
= 0;
1104 Ptr
->AddrTranslationOffset
= \
1105 (ResStatus
== ResAllocated
) ? EFI_RESOURCE_SATISFIED
: EFI_RESOURCE_LESS
;
1106 Ptr
->AddrLen
= RootBridgeInstance
->ResAllocNode
[Index
].Length
;
1111 // Prefetch memory 32
1117 Ptr
->SpecificFlag
= 6;
1118 Ptr
->AddrSpaceGranularity
= 32;
1119 Ptr
->AddrRangeMin
= 0;
1120 Ptr
->AddrRangeMax
= 0;
1121 Ptr
->AddrTranslationOffset
= EFI_RESOURCE_NONEXISTENT
;
1133 Ptr
->SpecificFlag
= 0;
1134 Ptr
->AddrSpaceGranularity
= 64;
1135 Ptr
->AddrRangeMin
= 0;
1136 Ptr
->AddrRangeMax
= 0;
1137 Ptr
->AddrTranslationOffset
= EFI_RESOURCE_NONEXISTENT
;
1143 // Prefetch memory 64
1149 Ptr
->SpecificFlag
= 6;
1150 Ptr
->AddrSpaceGranularity
= 64;
1151 Ptr
->AddrRangeMin
= 0;
1152 Ptr
->AddrRangeMax
= 0;
1153 Ptr
->AddrTranslationOffset
= EFI_RESOURCE_NONEXISTENT
;
1158 Temp
+= sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
);
1162 ((EFI_ACPI_END_TAG_DESCRIPTOR
*)Temp
)->Desc
= 0x79;
1163 ((EFI_ACPI_END_TAG_DESCRIPTOR
*)Temp
)->Checksum
= 0x0;
1165 *Configuration
= Buffer
;
1170 List
= List
->ForwardLink
;
1173 return EFI_INVALID_PARAMETER
;
1177 Provides the hooks from the PCI bus driver to every PCI controller (device/function) at various
1178 stages of the PCI enumeration process that allow the host bridge driver to preinitialize individual
1179 PCI controllers before enumeration.
1181 This function is called during the PCI enumeration process. No specific action is expected from this
1182 member function. It allows the host bridge driver to preinitialize individual PCI controllers before
1185 @param This Pointer to the EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL instance.
1186 @param RootBridgeHandle The associated PCI root bridge handle. Type EFI_HANDLE is defined in
1187 InstallProtocolInterface() in the UEFI 2.0 Specification.
1188 @param PciAddress The address of the PCI device on the PCI bus. This address can be passed to the
1189 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL member functions to access the PCI
1190 configuration space of the device. See Table 12-1 in the UEFI 2.0 Specification for
1191 the definition of EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS.
1192 @param Phase The phase of the PCI device enumeration.
1194 @retval EFI_SUCCESS The requested parameters were returned.
1195 @retval EFI_INVALID_PARAMETER RootBridgeHandle is not a valid root bridge handle.
1196 @retval EFI_INVALID_PARAMETER Phase is not a valid phase that is defined in
1197 EFI_PCI_CONTROLLER_RESOURCE_ALLOCATION_PHASE.
1198 @retval EFI_DEVICE_ERROR Programming failed due to a hardware error. The PCI enumerator should
1199 not enumerate this device, including its child devices if it is a PCI-to-PCI
1205 PreprocessController (
1206 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
1207 IN EFI_HANDLE RootBridgeHandle
,
1208 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS PciAddress
,
1209 IN EFI_PCI_CONTROLLER_RESOURCE_ALLOCATION_PHASE Phase
1212 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
1213 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
1216 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
1217 List
= HostBridgeInstance
->Head
.ForwardLink
;
1220 // Enumerate the root bridges in this host bridge
1222 while (List
!= &HostBridgeInstance
->Head
) {
1223 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
1224 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
1227 List
= List
->ForwardLink
;
1229 if (List
== &HostBridgeInstance
->Head
) {
1230 return EFI_INVALID_PARAMETER
;
1233 if ((UINT32
)Phase
> EfiPciBeforeResourceCollection
) {
1234 return EFI_INVALID_PARAMETER
;