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
84 SetLinuxPciProbeOnlyProperty (
85 IN FDT_CLIENT_PROTOCOL
*FdtClient
92 if (!FeaturePcdGet (PcdPureAcpiBoot
)) {
94 // Set the /chosen/linux,pci-probe-only property to 1, so that the PCI
95 // setup we will perform in the firmware is honored by the Linux OS,
96 // rather than torn down and done from scratch. This is generally a more
97 // sensible approach, and aligns with what ACPI based OSes do typically.
99 // In case we are exposing an emulated VGA PCI device to the guest, which
100 // may subsequently get exposed via the Graphics Output protocol and
101 // driven as an efifb by Linux, we need this setting to prevent the
102 // framebuffer from becoming unresponsive.
104 Status
= FdtClient
->GetOrInsertChosenNode (FdtClient
, &Node
);
106 if (!EFI_ERROR (Status
)) {
107 Tmp
= SwapBytes32 (1);
108 Status
= FdtClient
->SetNodeProperty (FdtClient
, Node
,
109 "linux,pci-probe-only", &Tmp
, sizeof (Tmp
));
111 if (EFI_ERROR (Status
)) {
113 "Failed to set /chosen/linux,pci-probe-only property\n"));
119 // We expect the "ranges" property of "pci-host-ecam-generic" to consist of
120 // records like this.
128 } DTB_PCI_HOST_RANGE_RECORD
;
131 #define DTB_PCI_HOST_RANGE_RELOCATABLE BIT31
132 #define DTB_PCI_HOST_RANGE_PREFETCHABLE BIT30
133 #define DTB_PCI_HOST_RANGE_ALIASED BIT29
134 #define DTB_PCI_HOST_RANGE_MMIO32 BIT25
135 #define DTB_PCI_HOST_RANGE_MMIO64 (BIT25 | BIT24)
136 #define DTB_PCI_HOST_RANGE_IO BIT24
137 #define DTB_PCI_HOST_RANGE_TYPEMASK (BIT31 | BIT30 | BIT29 | BIT25 | BIT24)
144 OUT UINT64
*IoTranslation
,
145 OUT UINT64
*MmioBase
,
146 OUT UINT64
*MmioSize
,
147 OUT UINT64
*MmioTranslation
,
152 FDT_CLIENT_PROTOCOL
*FdtClient
;
154 UINT64 ConfigBase
, ConfigSize
;
161 // The following output arguments are initialized only in
162 // order to suppress '-Werror=maybe-uninitialized' warnings
163 // *incorrectly* emitted by some gcc versions.
168 *MmioTranslation
= 0;
173 // *IoSize and *MmioSize are initialized to zero because the logic below
174 // requires it. However, since they are also affected by the issue reported
175 // above, they are initialized early.
180 Status
= gBS
->LocateProtocol (&gFdtClientProtocolGuid
, NULL
,
181 (VOID
**)&FdtClient
);
182 ASSERT_EFI_ERROR (Status
);
184 Status
= FdtClient
->FindCompatibleNode (FdtClient
, "pci-host-ecam-generic",
186 if (EFI_ERROR (Status
)) {
188 "%a: No 'pci-host-ecam-generic' compatible DT node found\n",
190 return EFI_NOT_FOUND
;
197 // A DT can legally describe multiple PCI host bridges, but we are not
198 // equipped to deal with that. So assert that there is only one.
200 Status
= FdtClient
->FindNextCompatibleNode (FdtClient
,
201 "pci-host-ecam-generic", Node
, &Tmp
);
202 ASSERT (Status
== EFI_NOT_FOUND
);
205 Status
= FdtClient
->GetNodeProperty (FdtClient
, Node
, "reg", &Prop
, &Len
);
206 if (EFI_ERROR (Status
) || Len
!= 2 * sizeof (UINT64
)) {
207 DEBUG ((EFI_D_ERROR
, "%a: 'reg' property not found or invalid\n",
209 return EFI_PROTOCOL_ERROR
;
213 // Fetch the ECAM window.
215 ConfigBase
= SwapBytes64 (((CONST UINT64
*)Prop
)[0]);
216 ConfigSize
= SwapBytes64 (((CONST UINT64
*)Prop
)[1]);
219 // Fetch the bus range (note: inclusive).
221 Status
= FdtClient
->GetNodeProperty (FdtClient
, Node
, "bus-range", &Prop
,
223 if (EFI_ERROR (Status
) || Len
!= 2 * sizeof (UINT32
)) {
224 DEBUG ((EFI_D_ERROR
, "%a: 'bus-range' not found or invalid\n",
226 return EFI_PROTOCOL_ERROR
;
228 *BusMin
= SwapBytes32 (((CONST UINT32
*)Prop
)[0]);
229 *BusMax
= SwapBytes32 (((CONST UINT32
*)Prop
)[1]);
232 // Sanity check: the config space must accommodate all 4K register bytes of
233 // all 8 functions of all 32 devices of all buses.
235 if (*BusMax
< *BusMin
|| *BusMax
- *BusMin
== MAX_UINT32
||
236 DivU64x32 (ConfigSize
, SIZE_4KB
* 8 * 32) < *BusMax
- *BusMin
+ 1) {
237 DEBUG ((EFI_D_ERROR
, "%a: invalid 'bus-range' and/or 'reg'\n",
239 return EFI_PROTOCOL_ERROR
;
243 // Iterate over "ranges".
245 Status
= FdtClient
->GetNodeProperty (FdtClient
, Node
, "ranges", &Prop
, &Len
);
246 if (EFI_ERROR (Status
) || Len
== 0 ||
247 Len
% sizeof (DTB_PCI_HOST_RANGE_RECORD
) != 0) {
248 DEBUG ((EFI_D_ERROR
, "%a: 'ranges' not found or invalid\n", __FUNCTION__
));
249 return EFI_PROTOCOL_ERROR
;
252 for (RecordIdx
= 0; RecordIdx
< Len
/ sizeof (DTB_PCI_HOST_RANGE_RECORD
);
254 CONST DTB_PCI_HOST_RANGE_RECORD
*Record
;
256 Record
= (CONST DTB_PCI_HOST_RANGE_RECORD
*)Prop
+ RecordIdx
;
257 switch (SwapBytes32 (Record
->Type
) & DTB_PCI_HOST_RANGE_TYPEMASK
) {
258 case DTB_PCI_HOST_RANGE_IO
:
259 *IoBase
= SwapBytes64 (Record
->ChildBase
);
260 *IoSize
= SwapBytes64 (Record
->Size
);
261 *IoTranslation
= SwapBytes64 (Record
->CpuBase
) - *IoBase
;
264 case DTB_PCI_HOST_RANGE_MMIO32
:
265 *MmioBase
= SwapBytes64 (Record
->ChildBase
);
266 *MmioSize
= SwapBytes64 (Record
->Size
);
267 *MmioTranslation
= SwapBytes64 (Record
->CpuBase
) - *MmioBase
;
269 if (*MmioBase
> MAX_UINT32
|| *MmioSize
> MAX_UINT32
||
270 *MmioBase
+ *MmioSize
> SIZE_4GB
) {
271 DEBUG ((EFI_D_ERROR
, "%a: MMIO32 space invalid\n", __FUNCTION__
));
272 return EFI_PROTOCOL_ERROR
;
275 if (*MmioTranslation
!= 0) {
276 DEBUG ((EFI_D_ERROR
, "%a: unsupported nonzero MMIO32 translation "
277 "0x%Lx\n", __FUNCTION__
, *MmioTranslation
));
278 return EFI_UNSUPPORTED
;
284 if (*IoSize
== 0 || *MmioSize
== 0) {
285 DEBUG ((EFI_D_ERROR
, "%a: %a space empty\n", __FUNCTION__
,
286 (*IoSize
== 0) ? "IO" : "MMIO32"));
287 return EFI_PROTOCOL_ERROR
;
291 // The dynamic PCD PcdPciExpressBaseAddress should have already been set,
292 // and should match the value we found in the DT node.
294 ASSERT (PcdGet64 (PcdPciExpressBaseAddress
) == ConfigBase
);
296 SetLinuxPciProbeOnlyProperty (FdtClient
);
298 DEBUG ((EFI_D_INFO
, "%a: Config[0x%Lx+0x%Lx) Bus[0x%x..0x%x] "
299 "Io[0x%Lx+0x%Lx)@0x%Lx Mem[0x%Lx+0x%Lx)@0x%Lx\n", __FUNCTION__
, ConfigBase
,
300 ConfigSize
, *BusMin
, *BusMax
, *IoBase
, *IoSize
, *IoTranslation
, *MmioBase
,
301 *MmioSize
, *MmioTranslation
));
307 Entry point of this driver
309 @param ImageHandle Handle of driver image
310 @param SystemTable Point to EFI_SYSTEM_TABLE
312 @retval EFI_ABORTED PCI host bridge not present
313 @retval EFI_OUT_OF_RESOURCES Can not allocate memory resource
314 @retval EFI_DEVICE_ERROR Can not install the protocol instance
315 @retval EFI_SUCCESS Success to initialize the Pci host bridge.
319 InitializePciHostBridge (
320 IN EFI_HANDLE ImageHandle
,
321 IN EFI_SYSTEM_TABLE
*SystemTable
324 UINT64 MmioAttributes
;
328 PCI_HOST_BRIDGE_INSTANCE
*HostBridge
;
329 PCI_ROOT_BRIDGE_INSTANCE
*PrivateData
;
330 UINT64 IoBase
, IoSize
, IoTranslation
;
331 UINT64 MmioBase
, MmioSize
, MmioTranslation
;
332 UINT32 BusMin
, BusMax
;
334 if (PcdGet64 (PcdPciExpressBaseAddress
) == 0) {
335 DEBUG ((EFI_D_INFO
, "%a: PCI host bridge not present\n", __FUNCTION__
));
339 Status
= ProcessPciHost (&IoBase
, &IoSize
, &IoTranslation
, &MmioBase
,
340 &MmioSize
, &MmioTranslation
, &BusMin
, &BusMax
);
341 if (EFI_ERROR (Status
)) {
345 mDriverImageHandle
= ImageHandle
;
347 mResAperture
[0][0].BusBase
= BusMin
;
348 mResAperture
[0][0].BusLimit
= BusMax
;
350 mResAperture
[0][0].MemBase
= MmioBase
;
351 mResAperture
[0][0].MemLimit
= MmioBase
+ MmioSize
- 1;
353 mResAperture
[0][0].IoBase
= IoBase
;
354 mResAperture
[0][0].IoLimit
= IoBase
+ IoSize
- 1;
355 mResAperture
[0][0].IoTranslation
= IoTranslation
;
358 // Add IO and MMIO memory space, so that resources can be allocated in the
359 // EfiPciHostBridgeAllocateResources phase.
361 Status
= gDS
->AddIoSpace (
366 ASSERT_EFI_ERROR (Status
);
368 MmioAttributes
= FeaturePcdGet (PcdKludgeMapPciMmioAsCached
) ?
369 EFI_MEMORY_WB
: EFI_MEMORY_UC
;
371 Status
= gDS
->AddMemorySpace (
372 EfiGcdMemoryTypeMemoryMappedIo
,
377 if (EFI_ERROR (Status
)) {
378 DEBUG ((EFI_D_ERROR
, "%a: AddMemorySpace: %r\n", __FUNCTION__
, Status
));
382 Status
= gDS
->SetMemorySpaceAttributes (
387 if (EFI_ERROR (Status
)) {
388 DEBUG ((EFI_D_ERROR
, "%a: SetMemorySpaceAttributes: %r\n", __FUNCTION__
,
394 // Create Host Bridge Device Handle
396 for (Loop1
= 0; Loop1
< HOST_BRIDGE_NUMBER
; Loop1
++) {
397 HostBridge
= AllocateCopyPool (sizeof(PCI_HOST_BRIDGE_INSTANCE
), &mPciHostBridgeInstanceTemplate
);
398 if (HostBridge
== NULL
) {
399 return EFI_OUT_OF_RESOURCES
;
402 HostBridge
->RootBridgeNumber
= RootBridgeNumber
[Loop1
];
403 InitializeListHead (&HostBridge
->Head
);
405 Status
= gBS
->InstallMultipleProtocolInterfaces (
406 &HostBridge
->HostBridgeHandle
,
407 &gEfiPciHostBridgeResourceAllocationProtocolGuid
, &HostBridge
->ResAlloc
,
410 if (EFI_ERROR (Status
)) {
411 FreePool (HostBridge
);
412 return EFI_DEVICE_ERROR
;
416 // Create Root Bridge Device Handle in this Host Bridge
419 for (Loop2
= 0; Loop2
< HostBridge
->RootBridgeNumber
; Loop2
++) {
420 PrivateData
= AllocateZeroPool (sizeof(PCI_ROOT_BRIDGE_INSTANCE
));
421 if (PrivateData
== NULL
) {
422 return EFI_OUT_OF_RESOURCES
;
425 PrivateData
->Signature
= PCI_ROOT_BRIDGE_SIGNATURE
;
426 PrivateData
->DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*)&mEfiPciRootBridgeDevicePath
[Loop1
][Loop2
];
428 RootBridgeConstructor (
430 HostBridge
->HostBridgeHandle
,
431 RootBridgeAttribute
[Loop1
][Loop2
],
432 &mResAperture
[Loop1
][Loop2
]
435 Status
= gBS
->InstallMultipleProtocolInterfaces(
436 &PrivateData
->Handle
,
437 &gEfiDevicePathProtocolGuid
, PrivateData
->DevicePath
,
438 &gEfiPciRootBridgeIoProtocolGuid
, &PrivateData
->Io
,
441 if (EFI_ERROR (Status
)) {
442 FreePool(PrivateData
);
443 return EFI_DEVICE_ERROR
;
446 InsertTailList (&HostBridge
->Head
, &PrivateData
->Link
);
455 These are the notifications from the PCI bus driver that it is about to enter a certain
456 phase of the PCI enumeration process.
458 This member function can be used to notify the host bridge driver to perform specific actions,
459 including any chipset-specific initialization, so that the chipset is ready to enter the next phase.
460 Eight notification points are defined at this time. See belows:
461 EfiPciHostBridgeBeginEnumeration Resets the host bridge PCI apertures and internal data
462 structures. The PCI enumerator should issue this notification
463 before starting a fresh enumeration process. Enumeration cannot
464 be restarted after sending any other notification such as
465 EfiPciHostBridgeBeginBusAllocation.
466 EfiPciHostBridgeBeginBusAllocation The bus allocation phase is about to begin. No specific action is
467 required here. This notification can be used to perform any
468 chipset-specific programming.
469 EfiPciHostBridgeEndBusAllocation The bus allocation and bus programming phase is complete. No
470 specific action is required here. This notification can be used to
471 perform any chipset-specific programming.
472 EfiPciHostBridgeBeginResourceAllocation
473 The resource allocation phase is about to begin. No specific
474 action is required here. This notification can be used to perform
475 any chipset-specific programming.
476 EfiPciHostBridgeAllocateResources Allocates resources per previously submitted requests for all the PCI
477 root bridges. These resource settings are returned on the next call to
478 GetProposedResources(). Before calling NotifyPhase() with a Phase of
479 EfiPciHostBridgeAllocateResource, the PCI bus enumerator is responsible
480 for gathering I/O and memory requests for
481 all the PCI root bridges and submitting these requests using
482 SubmitResources(). This function pads the resource amount
483 to suit the root bridge hardware, takes care of dependencies between
484 the PCI root bridges, and calls the Global Coherency Domain (GCD)
485 with the allocation request. In the case of padding, the allocated range
486 could be bigger than what was requested.
487 EfiPciHostBridgeSetResources Programs the host bridge hardware to decode previously allocated
488 resources (proposed resources) for all the PCI root bridges. After the
489 hardware is programmed, reassigning resources will not be supported.
490 The bus settings are not affected.
491 EfiPciHostBridgeFreeResources Deallocates resources that were previously allocated for all the PCI
492 root bridges and resets the I/O and memory apertures to their initial
493 state. The bus settings are not affected. If the request to allocate
494 resources fails, the PCI enumerator can use this notification to
495 deallocate previous resources, adjust the requests, and retry
497 EfiPciHostBridgeEndResourceAllocation The resource allocation phase is completed. No specific action is
498 required here. This notification can be used to perform any chipsetspecific
501 @param[in] This The instance pointer of EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
502 @param[in] Phase The phase during enumeration
504 @retval EFI_NOT_READY This phase cannot be entered at this time. For example, this error
505 is valid for a Phase of EfiPciHostBridgeAllocateResources if
506 SubmitResources() has not been called for one or more
507 PCI root bridges before this call
508 @retval EFI_DEVICE_ERROR Programming failed due to a hardware error. This error is valid
509 for a Phase of EfiPciHostBridgeSetResources.
510 @retval EFI_INVALID_PARAMETER Invalid phase parameter
511 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
512 This error is valid for a Phase of EfiPciHostBridgeAllocateResources if the
513 previously submitted resource requests cannot be fulfilled or
514 were only partially fulfilled.
515 @retval EFI_SUCCESS The notification was accepted without any errors.
521 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
522 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PHASE Phase
525 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
526 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
527 PCI_RESOURCE_TYPE Index
;
529 EFI_PHYSICAL_ADDRESS BaseAddress
;
531 UINTN BitsOfAlignment
;
533 EFI_STATUS ReturnStatus
;
535 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
539 case EfiPciHostBridgeBeginEnumeration
:
540 if (HostBridgeInstance
->CanRestarted
) {
542 // Reset the Each Root Bridge
544 List
= HostBridgeInstance
->Head
.ForwardLink
;
546 while (List
!= &HostBridgeInstance
->Head
) {
547 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
548 for (Index
= TypeIo
; Index
< TypeMax
; Index
++) {
549 RootBridgeInstance
->ResAllocNode
[Index
].Type
= Index
;
550 RootBridgeInstance
->ResAllocNode
[Index
].Base
= 0;
551 RootBridgeInstance
->ResAllocNode
[Index
].Length
= 0;
552 RootBridgeInstance
->ResAllocNode
[Index
].Status
= ResNone
;
555 List
= List
->ForwardLink
;
558 HostBridgeInstance
->ResourceSubmited
= FALSE
;
559 HostBridgeInstance
->CanRestarted
= TRUE
;
564 return EFI_NOT_READY
;
568 case EfiPciHostBridgeEndEnumeration
:
571 case EfiPciHostBridgeBeginBusAllocation
:
573 // No specific action is required here, can perform any chipset specific programing
575 HostBridgeInstance
->CanRestarted
= FALSE
;
578 case EfiPciHostBridgeEndBusAllocation
:
580 // No specific action is required here, can perform any chipset specific programing
582 //HostBridgeInstance->CanRestarted = FALSE;
585 case EfiPciHostBridgeBeginResourceAllocation
:
587 // No specific action is required here, can perform any chipset specific programing
589 //HostBridgeInstance->CanRestarted = FALSE;
592 case EfiPciHostBridgeAllocateResources
:
593 ReturnStatus
= EFI_SUCCESS
;
594 if (HostBridgeInstance
->ResourceSubmited
) {
596 // Take care of the resource dependencies between the root bridges
598 List
= HostBridgeInstance
->Head
.ForwardLink
;
600 while (List
!= &HostBridgeInstance
->Head
) {
601 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
602 for (Index
= TypeIo
; Index
< TypeBus
; Index
++) {
603 if (RootBridgeInstance
->ResAllocNode
[Index
].Status
!= ResNone
) {
605 AddrLen
= RootBridgeInstance
->ResAllocNode
[Index
].Length
;
608 // Get the number of '1' in Alignment.
610 BitsOfAlignment
= (UINTN
) (HighBitSet64 (RootBridgeInstance
->ResAllocNode
[Index
].Alignment
) + 1);
616 // It is impossible for this chipset to align 0xFFFF for IO16
619 if (BitsOfAlignment
>= 16) {
623 BaseAddress
= mResAperture
[0][0].IoLimit
;
624 Status
= gDS
->AllocateIoSpace (
625 EfiGcdAllocateMaxAddressSearchTopDown
,
634 if (!EFI_ERROR (Status
)) {
635 RootBridgeInstance
->ResAllocNode
[Index
].Base
= (UINTN
)BaseAddress
;
636 RootBridgeInstance
->ResAllocNode
[Index
].Status
= ResAllocated
;
638 ReturnStatus
= Status
;
639 if (Status
!= EFI_OUT_OF_RESOURCES
) {
640 RootBridgeInstance
->ResAllocNode
[Index
].Length
= 0;
649 // It is impossible for this chipset to align 0xFFFFFFFF for Mem32
653 if (BitsOfAlignment
>= 32) {
657 BaseAddress
= mResAperture
[0][0].MemLimit
;
658 Status
= gDS
->AllocateMemorySpace (
659 EfiGcdAllocateMaxAddressSearchTopDown
,
660 EfiGcdMemoryTypeMemoryMappedIo
,
668 if (!EFI_ERROR (Status
)) {
669 // We were able to allocate the PCI memory
670 RootBridgeInstance
->ResAllocNode
[Index
].Base
= (UINTN
)BaseAddress
;
671 RootBridgeInstance
->ResAllocNode
[Index
].Status
= ResAllocated
;
674 // Not able to allocate enough PCI memory
675 ReturnStatus
= Status
;
677 if (Status
!= EFI_OUT_OF_RESOURCES
) {
678 RootBridgeInstance
->ResAllocNode
[Index
].Length
= 0;
687 ReturnStatus
= EFI_ABORTED
;
696 List
= List
->ForwardLink
;
701 return EFI_NOT_READY
;
704 case EfiPciHostBridgeSetResources
:
707 case EfiPciHostBridgeFreeResources
:
708 ReturnStatus
= EFI_SUCCESS
;
709 List
= HostBridgeInstance
->Head
.ForwardLink
;
710 while (List
!= &HostBridgeInstance
->Head
) {
711 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
712 for (Index
= TypeIo
; Index
< TypeBus
; Index
++) {
713 if (RootBridgeInstance
->ResAllocNode
[Index
].Status
== ResAllocated
) {
714 AddrLen
= RootBridgeInstance
->ResAllocNode
[Index
].Length
;
715 BaseAddress
= RootBridgeInstance
->ResAllocNode
[Index
].Base
;
719 Status
= gDS
->FreeIoSpace (BaseAddress
, AddrLen
);
720 if (EFI_ERROR (Status
)) {
721 ReturnStatus
= Status
;
726 Status
= gDS
->FreeMemorySpace (BaseAddress
, AddrLen
);
727 if (EFI_ERROR (Status
)) {
728 ReturnStatus
= Status
;
746 RootBridgeInstance
->ResAllocNode
[Index
].Type
= Index
;
747 RootBridgeInstance
->ResAllocNode
[Index
].Base
= 0;
748 RootBridgeInstance
->ResAllocNode
[Index
].Length
= 0;
749 RootBridgeInstance
->ResAllocNode
[Index
].Status
= ResNone
;
753 List
= List
->ForwardLink
;
756 HostBridgeInstance
->ResourceSubmited
= FALSE
;
757 HostBridgeInstance
->CanRestarted
= TRUE
;
760 case EfiPciHostBridgeEndResourceAllocation
:
761 HostBridgeInstance
->CanRestarted
= FALSE
;
765 return EFI_INVALID_PARAMETER
;
772 Return the device handle of the next PCI root bridge that is associated with this Host Bridge.
774 This function is called multiple times to retrieve the device handles of all the PCI root bridges that
775 are associated with this PCI host bridge. Each PCI host bridge is associated with one or more PCI
776 root bridges. On each call, the handle that was returned by the previous call is passed into the
777 interface, and on output the interface returns the device handle of the next PCI root bridge. The
778 caller can use the handle to obtain the instance of the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
779 for that root bridge. When there are no more PCI root bridges to report, the interface returns
780 EFI_NOT_FOUND. A PCI enumerator must enumerate the PCI root bridges in the order that they
781 are returned by this function.
782 For D945 implementation, there is only one root bridge in PCI host bridge.
784 @param[in] This The instance pointer of EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
785 @param[in, out] RootBridgeHandle Returns the device handle of the next PCI root bridge.
787 @retval EFI_SUCCESS If parameter RootBridgeHandle = NULL, then return the first Rootbridge handle of the
788 specific Host bridge and return EFI_SUCCESS.
789 @retval EFI_NOT_FOUND Can not find the any more root bridge in specific host bridge.
790 @retval EFI_INVALID_PARAMETER RootBridgeHandle is not an EFI_HANDLE that was
791 returned on a previous call to GetNextRootBridge().
796 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
797 IN OUT EFI_HANDLE
*RootBridgeHandle
800 BOOLEAN NoRootBridge
;
802 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
803 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
806 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
807 List
= HostBridgeInstance
->Head
.ForwardLink
;
810 while (List
!= &HostBridgeInstance
->Head
) {
811 NoRootBridge
= FALSE
;
812 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
813 if (*RootBridgeHandle
== NULL
) {
815 // Return the first Root Bridge Handle of the Host Bridge
817 *RootBridgeHandle
= RootBridgeInstance
->Handle
;
820 if (*RootBridgeHandle
== RootBridgeInstance
->Handle
) {
824 List
= List
->ForwardLink
;
825 if (List
!=&HostBridgeInstance
->Head
) {
826 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
827 *RootBridgeHandle
= RootBridgeInstance
->Handle
;
830 return EFI_NOT_FOUND
;
835 List
= List
->ForwardLink
;
839 return EFI_NOT_FOUND
;
841 return EFI_INVALID_PARAMETER
;
846 Returns the allocation attributes of a PCI root bridge.
848 The function returns the allocation attributes of a specific PCI root bridge. The attributes can vary
849 from one PCI root bridge to another. These attributes are different from the decode-related
850 attributes that are returned by the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.GetAttributes() member function. The
851 RootBridgeHandle parameter is used to specify the instance of the PCI root bridge. The device
852 handles of all the root bridges that are associated with this host bridge must be obtained by calling
853 GetNextRootBridge(). The attributes are static in the sense that they do not change during or
854 after the enumeration process. The hardware may provide mechanisms to change the attributes on
855 the fly, but such changes must be completed before EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL is
856 installed. The permitted values of EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ATTRIBUTES are defined in
857 "Related Definitions" below. The caller uses these attributes to combine multiple resource requests.
858 For example, if the flag EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM is set, the PCI bus enumerator needs to
859 include requests for the prefetchable memory in the nonprefetchable memory pool and not request any
861 Attribute Description
862 ------------------------------------ ----------------------------------------------------------------------
863 EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM If this bit is set, then the PCI root bridge does not support separate
864 windows for nonprefetchable and prefetchable memory. A PCI bus
865 driver needs to include requests for prefetchable memory in the
866 nonprefetchable memory pool.
868 EFI_PCI_HOST_BRIDGE_MEM64_DECODE If this bit is set, then the PCI root bridge supports 64-bit memory
869 windows. If this bit is not set, the PCI bus driver needs to include
870 requests for a 64-bit memory address in the corresponding 32-bit
873 @param[in] This The instance pointer of EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
874 @param[in] RootBridgeHandle The device handle of the PCI root bridge in which the caller is interested. Type
875 EFI_HANDLE is defined in InstallProtocolInterface() in the UEFI 2.0 Specification.
876 @param[out] Attributes The pointer to attribte of root bridge, it is output parameter
878 @retval EFI_INVALID_PARAMETER Attribute pointer is NULL
879 @retval EFI_INVALID_PARAMETER RootBridgehandle is invalid.
880 @retval EFI_SUCCESS Success to get attribute of interested root bridge.
886 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
887 IN EFI_HANDLE RootBridgeHandle
,
888 OUT UINT64
*Attributes
892 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
893 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
895 if (Attributes
== NULL
) {
896 return EFI_INVALID_PARAMETER
;
899 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
900 List
= HostBridgeInstance
->Head
.ForwardLink
;
902 while (List
!= &HostBridgeInstance
->Head
) {
903 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
904 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
905 *Attributes
= RootBridgeInstance
->RootBridgeAttrib
;
908 List
= List
->ForwardLink
;
912 // RootBridgeHandle is not an EFI_HANDLE
913 // that was returned on a previous call to GetNextRootBridge()
915 return EFI_INVALID_PARAMETER
;
919 Sets up the specified PCI root bridge for the bus enumeration process.
921 This member function sets up the root bridge for bus enumeration and returns the PCI bus range
922 over which the search should be performed in ACPI 2.0 resource descriptor format.
924 @param[in] This The EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ PROTOCOL instance.
925 @param[in] RootBridgeHandle The PCI Root Bridge to be set up.
926 @param[out] Configuration Pointer to the pointer to the PCI bus resource descriptor.
928 @retval EFI_INVALID_PARAMETER Invalid Root bridge's handle
929 @retval EFI_OUT_OF_RESOURCES Fail to allocate ACPI resource descriptor tag.
930 @retval EFI_SUCCESS Sucess to allocate ACPI resource descriptor.
936 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
937 IN EFI_HANDLE RootBridgeHandle
,
938 OUT VOID
**Configuration
942 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
943 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
949 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
950 List
= HostBridgeInstance
->Head
.ForwardLink
;
952 while (List
!= &HostBridgeInstance
->Head
) {
953 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
954 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
956 // Set up the Root Bridge for Bus Enumeration
958 BusStart
= RootBridgeInstance
->BusBase
;
959 BusEnd
= RootBridgeInstance
->BusLimit
;
961 // Program the Hardware(if needed) if error return EFI_DEVICE_ERROR
964 Buffer
= AllocatePool (sizeof(EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) + sizeof(EFI_ACPI_END_TAG_DESCRIPTOR
));
965 if (Buffer
== NULL
) {
966 return EFI_OUT_OF_RESOURCES
;
969 Temp
= (UINT8
*)Buffer
;
971 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->Desc
= 0x8A;
972 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->Len
= 0x2B;
973 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->ResType
= 2;
974 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->GenFlag
= 0;
975 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->SpecificFlag
= 0;
976 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->AddrSpaceGranularity
= 0;
977 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->AddrRangeMin
= BusStart
;
978 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->AddrRangeMax
= 0;
979 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->AddrTranslationOffset
= 0;
980 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->AddrLen
= BusEnd
- BusStart
+ 1;
982 Temp
= Temp
+ sizeof(EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
);
983 ((EFI_ACPI_END_TAG_DESCRIPTOR
*)Temp
)->Desc
= 0x79;
984 ((EFI_ACPI_END_TAG_DESCRIPTOR
*)Temp
)->Checksum
= 0x0;
986 *Configuration
= Buffer
;
989 List
= List
->ForwardLink
;
992 return EFI_INVALID_PARAMETER
;
996 Programs the PCI root bridge hardware so that it decodes the specified PCI bus range.
998 This member function programs the specified PCI root bridge to decode the bus range that is
999 specified by the input parameter Configuration.
1000 The bus range information is specified in terms of the ACPI 2.0 resource descriptor format.
1002 @param[in] This The EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ PROTOCOL instance
1003 @param[in] RootBridgeHandle The PCI Root Bridge whose bus range is to be programmed
1004 @param[in] Configuration The pointer to the PCI bus resource descriptor
1006 @retval EFI_INVALID_PARAMETER RootBridgeHandle is not a valid root bridge handle.
1007 @retval EFI_INVALID_PARAMETER Configuration is NULL.
1008 @retval EFI_INVALID_PARAMETER Configuration does not point to a valid ACPI 2.0 resource descriptor.
1009 @retval EFI_INVALID_PARAMETER Configuration does not include a valid ACPI 2.0 bus resource descriptor.
1010 @retval EFI_INVALID_PARAMETER Configuration includes valid ACPI 2.0 resource descriptors other than
1012 @retval EFI_INVALID_PARAMETER Configuration contains one or more invalid ACPI resource descriptors.
1013 @retval EFI_INVALID_PARAMETER "Address Range Minimum" is invalid for this root bridge.
1014 @retval EFI_INVALID_PARAMETER "Address Range Length" is invalid for this root bridge.
1015 @retval EFI_DEVICE_ERROR Programming failed due to a hardware error.
1016 @retval EFI_SUCCESS The bus range for the PCI root bridge was programmed.
1022 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
1023 IN EFI_HANDLE RootBridgeHandle
,
1024 IN VOID
*Configuration
1028 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
1029 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
1035 if (Configuration
== NULL
) {
1036 return EFI_INVALID_PARAMETER
;
1039 Ptr
= Configuration
;
1042 // Check the Configuration is valid
1044 if(*Ptr
!= ACPI_ADDRESS_SPACE_DESCRIPTOR
) {
1045 return EFI_INVALID_PARAMETER
;
1048 if (((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Ptr
)->ResType
!= 2) {
1049 return EFI_INVALID_PARAMETER
;
1052 Ptr
+= sizeof(EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
);
1053 if (*Ptr
!= ACPI_END_TAG_DESCRIPTOR
) {
1054 return EFI_INVALID_PARAMETER
;
1057 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
1058 List
= HostBridgeInstance
->Head
.ForwardLink
;
1060 Ptr
= Configuration
;
1062 while (List
!= &HostBridgeInstance
->Head
) {
1063 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
1064 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
1065 BusStart
= (UINTN
)((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Ptr
)->AddrRangeMin
;
1066 BusLen
= (UINTN
)((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Ptr
)->AddrLen
;
1067 BusEnd
= BusStart
+ BusLen
- 1;
1069 if (BusStart
> BusEnd
) {
1070 return EFI_INVALID_PARAMETER
;
1073 if ((BusStart
< RootBridgeInstance
->BusBase
) || (BusEnd
> RootBridgeInstance
->BusLimit
)) {
1074 return EFI_INVALID_PARAMETER
;
1078 // Update the Bus Range
1080 RootBridgeInstance
->ResAllocNode
[TypeBus
].Base
= BusStart
;
1081 RootBridgeInstance
->ResAllocNode
[TypeBus
].Length
= BusLen
;
1082 RootBridgeInstance
->ResAllocNode
[TypeBus
].Status
= ResAllocated
;
1085 // Program the Root Bridge Hardware
1091 List
= List
->ForwardLink
;
1094 return EFI_INVALID_PARAMETER
;
1099 Submits the I/O and memory resource requirements for the specified PCI root bridge.
1101 This function is used to submit all the I/O and memory resources that are required by the specified
1102 PCI root bridge. The input parameter Configuration is used to specify the following:
1103 - The various types of resources that are required
1104 - The associated lengths in terms of ACPI 2.0 resource descriptor format
1106 @param[in] This Pointer to the EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL instance.
1107 @param[in] RootBridgeHandle The PCI root bridge whose I/O and memory resource requirements are being submitted.
1108 @param[in] Configuration The pointer to the PCI I/O and PCI memory resource descriptor.
1110 @retval EFI_SUCCESS The I/O and memory resource requests for a PCI root bridge were accepted.
1111 @retval EFI_INVALID_PARAMETER RootBridgeHandle is not a valid root bridge handle.
1112 @retval EFI_INVALID_PARAMETER Configuration is NULL.
1113 @retval EFI_INVALID_PARAMETER Configuration does not point to a valid ACPI 2.0 resource descriptor.
1114 @retval EFI_INVALID_PARAMETER Configuration includes requests for one or more resource types that are
1115 not supported by this PCI root bridge. This error will happen if the caller
1116 did not combine resources according to Attributes that were returned by
1117 GetAllocAttributes().
1118 @retval EFI_INVALID_PARAMETER Address Range Maximum" is invalid.
1119 @retval EFI_INVALID_PARAMETER "Address Range Length" is invalid for this PCI root bridge.
1120 @retval EFI_INVALID_PARAMETER "Address Space Granularity" is invalid for this PCI root bridge.
1126 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
1127 IN EFI_HANDLE RootBridgeHandle
,
1128 IN VOID
*Configuration
1132 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
1133 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
1135 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Ptr
;
1140 // Check the input parameter: Configuration
1142 if (Configuration
== NULL
) {
1143 return EFI_INVALID_PARAMETER
;
1146 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
1147 List
= HostBridgeInstance
->Head
.ForwardLink
;
1149 Temp
= (UINT8
*)Configuration
;
1150 while ( *Temp
== 0x8A) {
1151 Temp
+= sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) ;
1153 if (*Temp
!= 0x79) {
1154 return EFI_INVALID_PARAMETER
;
1157 Temp
= (UINT8
*)Configuration
;
1158 while (List
!= &HostBridgeInstance
->Head
) {
1159 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
1160 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
1163 Temp
+= sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
)
1165 Ptr
= (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Temp
;
1168 // Check Address Length
1170 if (Ptr
->AddrLen
== 0) {
1171 HostBridgeInstance
->ResourceSubmited
= TRUE
;
1174 if (Ptr
->AddrLen
> 0xffffffff) {
1175 return EFI_INVALID_PARAMETER
;
1179 // Check address range alignment
1181 if (Ptr
->AddrRangeMax
>= 0xffffffff || Ptr
->AddrRangeMax
!= (GetPowerOfTwo64 (Ptr
->AddrRangeMax
+ 1) - 1)) {
1182 return EFI_INVALID_PARAMETER
;
1185 switch (Ptr
->ResType
) {
1190 // Check invalid Address Sapce Granularity
1192 if (Ptr
->AddrSpaceGranularity
!= 32) {
1193 return EFI_INVALID_PARAMETER
;
1197 // check the memory resource request is supported by PCI root bridge
1199 if (RootBridgeInstance
->RootBridgeAttrib
== EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM
&&
1200 Ptr
->SpecificFlag
== 0x06) {
1201 return EFI_INVALID_PARAMETER
;
1204 AddrLen
= Ptr
->AddrLen
;
1205 Alignment
= Ptr
->AddrRangeMax
;
1206 if (Ptr
->AddrSpaceGranularity
== 32) {
1207 if (Ptr
->SpecificFlag
== 0x06) {
1211 RootBridgeInstance
->ResAllocNode
[TypePMem32
].Status
= ResSubmitted
;
1213 RootBridgeInstance
->ResAllocNode
[TypeMem32
].Length
= AddrLen
;
1214 RootBridgeInstance
->ResAllocNode
[TypeMem32
].Alignment
= Alignment
;
1215 RootBridgeInstance
->ResAllocNode
[TypeMem32
].Status
= ResRequested
;
1216 HostBridgeInstance
->ResourceSubmited
= TRUE
;
1220 if (Ptr
->AddrSpaceGranularity
== 64) {
1221 if (Ptr
->SpecificFlag
== 0x06) {
1222 RootBridgeInstance
->ResAllocNode
[TypePMem64
].Status
= ResSubmitted
;
1224 RootBridgeInstance
->ResAllocNode
[TypeMem64
].Status
= ResSubmitted
;
1230 AddrLen
= (UINTN
) Ptr
->AddrLen
;
1231 Alignment
= (UINTN
) Ptr
->AddrRangeMax
;
1232 RootBridgeInstance
->ResAllocNode
[TypeIo
].Length
= AddrLen
;
1233 RootBridgeInstance
->ResAllocNode
[TypeIo
].Alignment
= Alignment
;
1234 RootBridgeInstance
->ResAllocNode
[TypeIo
].Status
= ResRequested
;
1235 HostBridgeInstance
->ResourceSubmited
= TRUE
;
1246 List
= List
->ForwardLink
;
1249 return EFI_INVALID_PARAMETER
;
1253 Returns the proposed resource settings for the specified PCI root bridge.
1255 This member function returns the proposed resource settings for the specified PCI root bridge. The
1256 proposed resource settings are prepared when NotifyPhase() is called with a Phase of
1257 EfiPciHostBridgeAllocateResources. The output parameter Configuration
1258 specifies the following:
1259 - The various types of resources, excluding bus resources, that are allocated
1260 - The associated lengths in terms of ACPI 2.0 resource descriptor format
1262 @param[in] This Pointer to the EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL instance.
1263 @param[in] RootBridgeHandle The PCI root bridge handle. Type EFI_HANDLE is defined in InstallProtocolInterface() in the UEFI 2.0 Specification.
1264 @param[out] Configuration The pointer to the pointer to the PCI I/O and memory resource descriptor.
1266 @retval EFI_SUCCESS The requested parameters were returned.
1267 @retval EFI_INVALID_PARAMETER RootBridgeHandle is not a valid root bridge handle.
1268 @retval EFI_DEVICE_ERROR Programming failed due to a hardware error.
1269 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
1274 GetProposedResources(
1275 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
1276 IN EFI_HANDLE RootBridgeHandle
,
1277 OUT VOID
**Configuration
1281 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
1282 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
1287 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Ptr
;
1293 // Get the Host Bridge Instance from the resource allocation protocol
1295 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
1296 List
= HostBridgeInstance
->Head
.ForwardLink
;
1299 // Enumerate the root bridges in this host bridge
1301 while (List
!= &HostBridgeInstance
->Head
) {
1302 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
1303 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
1304 for (Index
= 0; Index
< TypeBus
; Index
++) {
1305 if (RootBridgeInstance
->ResAllocNode
[Index
].Status
!= ResNone
) {
1311 EFI_ACPI_END_TAG_DESCRIPTOR
*End
;
1313 End
= AllocateZeroPool (sizeof *End
);
1315 return EFI_OUT_OF_RESOURCES
;
1317 End
->Desc
= ACPI_END_TAG_DESCRIPTOR
;
1318 *Configuration
= End
;
1322 Buffer
= AllocateZeroPool (Number
* sizeof(EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) + sizeof(EFI_ACPI_END_TAG_DESCRIPTOR
));
1323 if (Buffer
== NULL
) {
1324 return EFI_OUT_OF_RESOURCES
;
1328 for (Index
= 0; Index
< TypeBus
; Index
++) {
1329 if (RootBridgeInstance
->ResAllocNode
[Index
].Status
!= ResNone
) {
1330 Ptr
= (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Temp
;
1331 ResStatus
= RootBridgeInstance
->ResAllocNode
[Index
].Status
;
1343 Ptr
->SpecificFlag
= 0;
1344 Ptr
->AddrRangeMin
= RootBridgeInstance
->ResAllocNode
[Index
].Base
;
1345 Ptr
->AddrRangeMax
= 0;
1346 Ptr
->AddrTranslationOffset
= \
1347 (ResStatus
== ResAllocated
) ? EFI_RESOURCE_SATISFIED
: EFI_RESOURCE_LESS
;
1348 Ptr
->AddrLen
= RootBridgeInstance
->ResAllocNode
[Index
].Length
;
1359 Ptr
->SpecificFlag
= 0;
1360 Ptr
->AddrSpaceGranularity
= 32;
1361 Ptr
->AddrRangeMin
= RootBridgeInstance
->ResAllocNode
[Index
].Base
;
1362 Ptr
->AddrRangeMax
= 0;
1363 Ptr
->AddrTranslationOffset
= \
1364 (ResStatus
== ResAllocated
) ? EFI_RESOURCE_SATISFIED
: EFI_RESOURCE_LESS
;
1365 Ptr
->AddrLen
= RootBridgeInstance
->ResAllocNode
[Index
].Length
;
1370 // Prefetch memory 32
1376 Ptr
->SpecificFlag
= 6;
1377 Ptr
->AddrSpaceGranularity
= 32;
1378 Ptr
->AddrRangeMin
= 0;
1379 Ptr
->AddrRangeMax
= 0;
1380 Ptr
->AddrTranslationOffset
= EFI_RESOURCE_NONEXISTENT
;
1392 Ptr
->SpecificFlag
= 0;
1393 Ptr
->AddrSpaceGranularity
= 64;
1394 Ptr
->AddrRangeMin
= 0;
1395 Ptr
->AddrRangeMax
= 0;
1396 Ptr
->AddrTranslationOffset
= EFI_RESOURCE_NONEXISTENT
;
1402 // Prefetch memory 64
1408 Ptr
->SpecificFlag
= 6;
1409 Ptr
->AddrSpaceGranularity
= 64;
1410 Ptr
->AddrRangeMin
= 0;
1411 Ptr
->AddrRangeMax
= 0;
1412 Ptr
->AddrTranslationOffset
= EFI_RESOURCE_NONEXISTENT
;
1417 Temp
+= sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
);
1421 ((EFI_ACPI_END_TAG_DESCRIPTOR
*)Temp
)->Desc
= 0x79;
1422 ((EFI_ACPI_END_TAG_DESCRIPTOR
*)Temp
)->Checksum
= 0x0;
1424 *Configuration
= Buffer
;
1429 List
= List
->ForwardLink
;
1432 return EFI_INVALID_PARAMETER
;
1436 Provides the hooks from the PCI bus driver to every PCI controller (device/function) at various
1437 stages of the PCI enumeration process that allow the host bridge driver to preinitialize individual
1438 PCI controllers before enumeration.
1440 This function is called during the PCI enumeration process. No specific action is expected from this
1441 member function. It allows the host bridge driver to preinitialize individual PCI controllers before
1444 @param This Pointer to the EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL instance.
1445 @param RootBridgeHandle The associated PCI root bridge handle. Type EFI_HANDLE is defined in
1446 InstallProtocolInterface() in the UEFI 2.0 Specification.
1447 @param PciAddress The address of the PCI device on the PCI bus. This address can be passed to the
1448 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL member functions to access the PCI
1449 configuration space of the device. See Table 12-1 in the UEFI 2.0 Specification for
1450 the definition of EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS.
1451 @param Phase The phase of the PCI device enumeration.
1453 @retval EFI_SUCCESS The requested parameters were returned.
1454 @retval EFI_INVALID_PARAMETER RootBridgeHandle is not a valid root bridge handle.
1455 @retval EFI_INVALID_PARAMETER Phase is not a valid phase that is defined in
1456 EFI_PCI_CONTROLLER_RESOURCE_ALLOCATION_PHASE.
1457 @retval EFI_DEVICE_ERROR Programming failed due to a hardware error. The PCI enumerator should
1458 not enumerate this device, including its child devices if it is a PCI-to-PCI
1464 PreprocessController (
1465 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
1466 IN EFI_HANDLE RootBridgeHandle
,
1467 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS PciAddress
,
1468 IN EFI_PCI_CONTROLLER_RESOURCE_ALLOCATION_PHASE Phase
1471 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
1472 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
1475 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
1476 List
= HostBridgeInstance
->Head
.ForwardLink
;
1479 // Enumerate the root bridges in this host bridge
1481 while (List
!= &HostBridgeInstance
->Head
) {
1482 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
1483 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
1486 List
= List
->ForwardLink
;
1488 if (List
== &HostBridgeInstance
->Head
) {
1489 return EFI_INVALID_PARAMETER
;
1492 if ((UINT32
)Phase
> EfiPciBeforeResourceCollection
) {
1493 return EFI_INVALID_PARAMETER
;