2 Provides the basic interfaces to abstract a PCI Host Bridge Resource Allocation
4 Copyright (c) 2008 - 2012, 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 appeture
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_APPETURE mResAppeture
[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 &mResAppeture
[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 EfiPciHostBridgeBeginBusAllocation
:
286 // No specific action is required here, can perform any chipset specific programing
288 HostBridgeInstance
->CanRestarted
= FALSE
;
292 case EfiPciHostBridgeEndBusAllocation
:
294 // No specific action is required here, can perform any chipset specific programing
296 //HostBridgeInstance->CanRestarted = FALSE;
300 case EfiPciHostBridgeBeginResourceAllocation
:
302 // No specific action is required here, can perform any chipset specific programing
304 //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
;
477 case EfiPciHostBridgeEndResourceAllocation
:
478 HostBridgeInstance
->CanRestarted
= FALSE
;
482 return EFI_INVALID_PARAMETER
;
489 Return the device handle of the next PCI root bridge that is associated with this Host Bridge.
491 This function is called multiple times to retrieve the device handles of all the PCI root bridges that
492 are associated with this PCI host bridge. Each PCI host bridge is associated with one or more PCI
493 root bridges. On each call, the handle that was returned by the previous call is passed into the
494 interface, and on output the interface returns the device handle of the next PCI root bridge. The
495 caller can use the handle to obtain the instance of the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
496 for that root bridge. When there are no more PCI root bridges to report, the interface returns
497 EFI_NOT_FOUND. A PCI enumerator must enumerate the PCI root bridges in the order that they
498 are returned by this function.
499 For D945 implementation, there is only one root bridge in PCI host bridge.
501 @param[in] This The instance pointer of EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
502 @param[in, out] RootBridgeHandle Returns the device handle of the next PCI root bridge.
504 @retval EFI_SUCCESS If parameter RootBridgeHandle = NULL, then return the first Rootbridge handle of the
505 specific Host bridge and return EFI_SUCCESS.
506 @retval EFI_NOT_FOUND Can not find the any more root bridge in specific host bridge.
507 @retval EFI_INVALID_PARAMETER RootBridgeHandle is not an EFI_HANDLE that was
508 returned on a previous call to GetNextRootBridge().
513 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
514 IN OUT EFI_HANDLE
*RootBridgeHandle
517 BOOLEAN NoRootBridge
;
519 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
520 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
523 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
524 List
= HostBridgeInstance
->Head
.ForwardLink
;
527 while (List
!= &HostBridgeInstance
->Head
) {
528 NoRootBridge
= FALSE
;
529 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
530 if (*RootBridgeHandle
== NULL
) {
532 // Return the first Root Bridge Handle of the Host Bridge
534 *RootBridgeHandle
= RootBridgeInstance
->Handle
;
537 if (*RootBridgeHandle
== RootBridgeInstance
->Handle
) {
541 List
= List
->ForwardLink
;
542 if (List
!=&HostBridgeInstance
->Head
) {
543 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
544 *RootBridgeHandle
= RootBridgeInstance
->Handle
;
547 return EFI_NOT_FOUND
;
552 List
= List
->ForwardLink
;
556 return EFI_NOT_FOUND
;
558 return EFI_INVALID_PARAMETER
;
563 Returns the allocation attributes of a PCI root bridge.
565 The function returns the allocation attributes of a specific PCI root bridge. The attributes can vary
566 from one PCI root bridge to another. These attributes are different from the decode-related
567 attributes that are returned by the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.GetAttributes() member function. The
568 RootBridgeHandle parameter is used to specify the instance of the PCI root bridge. The device
569 handles of all the root bridges that are associated with this host bridge must be obtained by calling
570 GetNextRootBridge(). The attributes are static in the sense that they do not change during or
571 after the enumeration process. The hardware may provide mechanisms to change the attributes on
572 the fly, but such changes must be completed before EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL is
573 installed. The permitted values of EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ATTRIBUTES are defined in
574 "Related Definitions" below. The caller uses these attributes to combine multiple resource requests.
575 For example, if the flag EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM is set, the PCI bus enumerator needs to
576 include requests for the prefetchable memory in the nonprefetchable memory pool and not request any
578 Attribute Description
579 ------------------------------------ ----------------------------------------------------------------------
580 EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM If this bit is set, then the PCI root bridge does not support separate
581 windows for nonprefetchable and prefetchable memory. A PCI bus
582 driver needs to include requests for prefetchable memory in the
583 nonprefetchable memory pool.
585 EFI_PCI_HOST_BRIDGE_MEM64_DECODE If this bit is set, then the PCI root bridge supports 64-bit memory
586 windows. If this bit is not set, the PCI bus driver needs to include
587 requests for a 64-bit memory address in the corresponding 32-bit
590 @param[in] This The instance pointer of EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
591 @param[in] RootBridgeHandle The device handle of the PCI root bridge in which the caller is interested. Type
592 EFI_HANDLE is defined in InstallProtocolInterface() in the UEFI 2.0 Specification.
593 @param[out] Attributes The pointer to attribte of root bridge, it is output parameter
595 @retval EFI_INVALID_PARAMETER Attribute pointer is NULL
596 @retval EFI_INVALID_PARAMETER RootBridgehandle is invalid.
597 @retval EFI_SUCCESS Success to get attribute of interested root bridge.
603 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
604 IN EFI_HANDLE RootBridgeHandle
,
605 OUT UINT64
*Attributes
609 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
610 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
612 if (Attributes
== NULL
) {
613 return EFI_INVALID_PARAMETER
;
616 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
617 List
= HostBridgeInstance
->Head
.ForwardLink
;
619 while (List
!= &HostBridgeInstance
->Head
) {
620 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
621 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
622 *Attributes
= RootBridgeInstance
->RootBridgeAttrib
;
625 List
= List
->ForwardLink
;
629 // RootBridgeHandle is not an EFI_HANDLE
630 // that was returned on a previous call to GetNextRootBridge()
632 return EFI_INVALID_PARAMETER
;
636 Sets up the specified PCI root bridge for the bus enumeration process.
638 This member function sets up the root bridge for bus enumeration and returns the PCI bus range
639 over which the search should be performed in ACPI 2.0 resource descriptor format.
641 @param[in] This The EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ PROTOCOL instance.
642 @param[in] RootBridgeHandle The PCI Root Bridge to be set up.
643 @param[out] Configuration Pointer to the pointer to the PCI bus resource descriptor.
645 @retval EFI_INVALID_PARAMETER Invalid Root bridge's handle
646 @retval EFI_OUT_OF_RESOURCES Fail to allocate ACPI resource descriptor tag.
647 @retval EFI_SUCCESS Sucess to allocate ACPI resource descriptor.
653 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
654 IN EFI_HANDLE RootBridgeHandle
,
655 OUT VOID
**Configuration
659 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
660 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
666 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
667 List
= HostBridgeInstance
->Head
.ForwardLink
;
669 while (List
!= &HostBridgeInstance
->Head
) {
670 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
671 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
673 // Set up the Root Bridge for Bus Enumeration
675 BusStart
= RootBridgeInstance
->BusBase
;
676 BusEnd
= RootBridgeInstance
->BusLimit
;
678 // Program the Hardware(if needed) if error return EFI_DEVICE_ERROR
681 Buffer
= AllocatePool (sizeof(EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) + sizeof(EFI_ACPI_END_TAG_DESCRIPTOR
));
682 if (Buffer
== NULL
) {
683 return EFI_OUT_OF_RESOURCES
;
686 Temp
= (UINT8
*)Buffer
;
688 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->Desc
= 0x8A;
689 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->Len
= 0x2B;
690 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->ResType
= 2;
691 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->GenFlag
= 0;
692 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->SpecificFlag
= 0;
693 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->AddrSpaceGranularity
= 0;
694 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->AddrRangeMin
= BusStart
;
695 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->AddrRangeMax
= 0;
696 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->AddrTranslationOffset
= 0;
697 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->AddrLen
= BusEnd
- BusStart
+ 1;
699 Temp
= Temp
+ sizeof(EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
);
700 ((EFI_ACPI_END_TAG_DESCRIPTOR
*)Temp
)->Desc
= 0x79;
701 ((EFI_ACPI_END_TAG_DESCRIPTOR
*)Temp
)->Checksum
= 0x0;
703 *Configuration
= Buffer
;
706 List
= List
->ForwardLink
;
709 return EFI_INVALID_PARAMETER
;
713 Programs the PCI root bridge hardware so that it decodes the specified PCI bus range.
715 This member function programs the specified PCI root bridge to decode the bus range that is
716 specified by the input parameter Configuration.
717 The bus range information is specified in terms of the ACPI 2.0 resource descriptor format.
719 @param[in] This The EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ PROTOCOL instance
720 @param[in] RootBridgeHandle The PCI Root Bridge whose bus range is to be programmed
721 @param[in] Configuration The pointer to the PCI bus resource descriptor
723 @retval EFI_INVALID_PARAMETER RootBridgeHandle is not a valid root bridge handle.
724 @retval EFI_INVALID_PARAMETER Configuration is NULL.
725 @retval EFI_INVALID_PARAMETER Configuration does not point to a valid ACPI 2.0 resource descriptor.
726 @retval EFI_INVALID_PARAMETER Configuration does not include a valid ACPI 2.0 bus resource descriptor.
727 @retval EFI_INVALID_PARAMETER Configuration includes valid ACPI 2.0 resource descriptors other than
729 @retval EFI_INVALID_PARAMETER Configuration contains one or more invalid ACPI resource descriptors.
730 @retval EFI_INVALID_PARAMETER "Address Range Minimum" is invalid for this root bridge.
731 @retval EFI_INVALID_PARAMETER "Address Range Length" is invalid for this root bridge.
732 @retval EFI_DEVICE_ERROR Programming failed due to a hardware error.
733 @retval EFI_SUCCESS The bus range for the PCI root bridge was programmed.
739 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
740 IN EFI_HANDLE RootBridgeHandle
,
741 IN VOID
*Configuration
745 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
746 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
752 if (Configuration
== NULL
) {
753 return EFI_INVALID_PARAMETER
;
759 // Check the Configuration is valid
761 if(*Ptr
!= ACPI_ADDRESS_SPACE_DESCRIPTOR
) {
762 return EFI_INVALID_PARAMETER
;
765 if (((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Ptr
)->ResType
!= 2) {
766 return EFI_INVALID_PARAMETER
;
769 Ptr
+= sizeof(EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
);
770 if (*Ptr
!= ACPI_END_TAG_DESCRIPTOR
) {
771 return EFI_INVALID_PARAMETER
;
774 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
775 List
= HostBridgeInstance
->Head
.ForwardLink
;
779 while (List
!= &HostBridgeInstance
->Head
) {
780 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
781 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
782 BusStart
= (UINTN
)((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Ptr
)->AddrRangeMin
;
783 BusLen
= (UINTN
)((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Ptr
)->AddrLen
;
784 BusEnd
= BusStart
+ BusLen
- 1;
786 if (BusStart
> BusEnd
) {
787 return EFI_INVALID_PARAMETER
;
790 if ((BusStart
< RootBridgeInstance
->BusBase
) || (BusEnd
> RootBridgeInstance
->BusLimit
)) {
791 return EFI_INVALID_PARAMETER
;
795 // Update the Bus Range
797 RootBridgeInstance
->ResAllocNode
[TypeBus
].Base
= BusStart
;
798 RootBridgeInstance
->ResAllocNode
[TypeBus
].Length
= BusLen
;
799 RootBridgeInstance
->ResAllocNode
[TypeBus
].Status
= ResAllocated
;
802 // Program the Root Bridge Hardware
808 List
= List
->ForwardLink
;
811 return EFI_INVALID_PARAMETER
;
816 Submits the I/O and memory resource requirements for the specified PCI root bridge.
818 This function is used to submit all the I/O and memory resources that are required by the specified
819 PCI root bridge. The input parameter Configuration is used to specify the following:
820 - The various types of resources that are required
821 - The associated lengths in terms of ACPI 2.0 resource descriptor format
823 @param[in] This Pointer to the EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL instance.
824 @param[in] RootBridgeHandle The PCI root bridge whose I/O and memory resource requirements are being submitted.
825 @param[in] Configuration The pointer to the PCI I/O and PCI memory resource descriptor.
827 @retval EFI_SUCCESS The I/O and memory resource requests for a PCI root bridge were accepted.
828 @retval EFI_INVALID_PARAMETER RootBridgeHandle is not a valid root bridge handle.
829 @retval EFI_INVALID_PARAMETER Configuration is NULL.
830 @retval EFI_INVALID_PARAMETER Configuration does not point to a valid ACPI 2.0 resource descriptor.
831 @retval EFI_INVALID_PARAMETER Configuration includes requests for one or more resource types that are
832 not supported by this PCI root bridge. This error will happen if the caller
833 did not combine resources according to Attributes that were returned by
834 GetAllocAttributes().
835 @retval EFI_INVALID_PARAMETER Address Range Maximum" is invalid.
836 @retval EFI_INVALID_PARAMETER "Address Range Length" is invalid for this PCI root bridge.
837 @retval EFI_INVALID_PARAMETER "Address Space Granularity" is invalid for this PCI root bridge.
843 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
844 IN EFI_HANDLE RootBridgeHandle
,
845 IN VOID
*Configuration
849 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
850 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
852 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Ptr
;
857 // Check the input parameter: Configuration
859 if (Configuration
== NULL
) {
860 return EFI_INVALID_PARAMETER
;
863 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
864 List
= HostBridgeInstance
->Head
.ForwardLink
;
866 Temp
= (UINT8
*)Configuration
;
867 while ( *Temp
== 0x8A) {
868 Temp
+= sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) ;
871 return EFI_INVALID_PARAMETER
;
874 Temp
= (UINT8
*)Configuration
;
875 while (List
!= &HostBridgeInstance
->Head
) {
876 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
877 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
878 while ( *Temp
== 0x8A) {
879 Ptr
= (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Temp
;
882 // Check Address Length
884 if (Ptr
->AddrLen
> 0xffffffff) {
885 return EFI_INVALID_PARAMETER
;
889 // Check address range alignment
891 if (Ptr
->AddrRangeMax
>= 0xffffffff || Ptr
->AddrRangeMax
!= (GetPowerOfTwo64 (Ptr
->AddrRangeMax
+ 1) - 1)) {
892 return EFI_INVALID_PARAMETER
;
895 switch (Ptr
->ResType
) {
900 // Check invalid Address Sapce Granularity
902 if (Ptr
->AddrSpaceGranularity
!= 32) {
903 return EFI_INVALID_PARAMETER
;
907 // check the memory resource request is supported by PCI root bridge
909 if (RootBridgeInstance
->RootBridgeAttrib
== EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM
&&
910 Ptr
->SpecificFlag
== 0x06) {
911 return EFI_INVALID_PARAMETER
;
914 AddrLen
= Ptr
->AddrLen
;
915 Alignment
= Ptr
->AddrRangeMax
;
916 if (Ptr
->AddrSpaceGranularity
== 32) {
917 if (Ptr
->SpecificFlag
== 0x06) {
921 RootBridgeInstance
->ResAllocNode
[TypePMem32
].Status
= ResSubmitted
;
923 RootBridgeInstance
->ResAllocNode
[TypeMem32
].Length
= AddrLen
;
924 RootBridgeInstance
->ResAllocNode
[TypeMem32
].Alignment
= Alignment
;
925 RootBridgeInstance
->ResAllocNode
[TypeMem32
].Status
= ResRequested
;
926 HostBridgeInstance
->ResourceSubmited
= TRUE
;
930 if (Ptr
->AddrSpaceGranularity
== 64) {
931 if (Ptr
->SpecificFlag
== 0x06) {
932 RootBridgeInstance
->ResAllocNode
[TypePMem64
].Status
= ResSubmitted
;
934 RootBridgeInstance
->ResAllocNode
[TypeMem64
].Status
= ResSubmitted
;
940 AddrLen
= (UINTN
) Ptr
->AddrLen
;
941 Alignment
= (UINTN
) Ptr
->AddrRangeMax
;
942 RootBridgeInstance
->ResAllocNode
[TypeIo
].Length
= AddrLen
;
943 RootBridgeInstance
->ResAllocNode
[TypeIo
].Alignment
= Alignment
;
944 RootBridgeInstance
->ResAllocNode
[TypeIo
].Status
= ResRequested
;
945 HostBridgeInstance
->ResourceSubmited
= TRUE
;
952 Temp
+= sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) ;
958 List
= List
->ForwardLink
;
961 return EFI_INVALID_PARAMETER
;
965 Returns the proposed resource settings for the specified PCI root bridge.
967 This member function returns the proposed resource settings for the specified PCI root bridge. The
968 proposed resource settings are prepared when NotifyPhase() is called with a Phase of
969 EfiPciHostBridgeAllocateResources. The output parameter Configuration
970 specifies the following:
971 - The various types of resources, excluding bus resources, that are allocated
972 - The associated lengths in terms of ACPI 2.0 resource descriptor format
974 @param[in] This Pointer to the EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL instance.
975 @param[in] RootBridgeHandle The PCI root bridge handle. Type EFI_HANDLE is defined in InstallProtocolInterface() in the UEFI 2.0 Specification.
976 @param[out] Configuration The pointer to the pointer to the PCI I/O and memory resource descriptor.
978 @retval EFI_SUCCESS The requested parameters were returned.
979 @retval EFI_INVALID_PARAMETER RootBridgeHandle is not a valid root bridge handle.
980 @retval EFI_DEVICE_ERROR Programming failed due to a hardware error.
981 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
986 GetProposedResources(
987 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
988 IN EFI_HANDLE RootBridgeHandle
,
989 OUT VOID
**Configuration
993 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
994 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
999 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Ptr
;
1005 // Get the Host Bridge Instance from the resource allocation protocol
1007 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
1008 List
= HostBridgeInstance
->Head
.ForwardLink
;
1011 // Enumerate the root bridges in this host bridge
1013 while (List
!= &HostBridgeInstance
->Head
) {
1014 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
1015 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
1016 for (Index
= 0; Index
< TypeBus
; Index
++) {
1017 if (RootBridgeInstance
->ResAllocNode
[Index
].Status
!= ResNone
) {
1023 return EFI_INVALID_PARAMETER
;
1026 Buffer
= AllocateZeroPool (Number
* sizeof(EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) + sizeof(EFI_ACPI_END_TAG_DESCRIPTOR
));
1027 if (Buffer
== NULL
) {
1028 return EFI_OUT_OF_RESOURCES
;
1032 for (Index
= 0; Index
< TypeBus
; Index
++) {
1033 if (RootBridgeInstance
->ResAllocNode
[Index
].Status
!= ResNone
) {
1034 Ptr
= (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Temp
;
1035 ResStatus
= RootBridgeInstance
->ResAllocNode
[Index
].Status
;
1047 Ptr
->SpecificFlag
= 0;
1048 Ptr
->AddrRangeMin
= RootBridgeInstance
->ResAllocNode
[Index
].Base
;
1049 Ptr
->AddrRangeMax
= 0;
1050 Ptr
->AddrTranslationOffset
= \
1051 (ResStatus
== ResAllocated
) ? EFI_RESOURCE_SATISFIED
: EFI_RESOURCE_LESS
;
1052 Ptr
->AddrLen
= RootBridgeInstance
->ResAllocNode
[Index
].Length
;
1063 Ptr
->SpecificFlag
= 0;
1064 Ptr
->AddrSpaceGranularity
= 32;
1065 Ptr
->AddrRangeMin
= RootBridgeInstance
->ResAllocNode
[Index
].Base
;
1066 Ptr
->AddrRangeMax
= 0;
1067 Ptr
->AddrTranslationOffset
= \
1068 (ResStatus
== ResAllocated
) ? EFI_RESOURCE_SATISFIED
: EFI_RESOURCE_LESS
;
1069 Ptr
->AddrLen
= RootBridgeInstance
->ResAllocNode
[Index
].Length
;
1074 // Prefetch memory 32
1080 Ptr
->SpecificFlag
= 6;
1081 Ptr
->AddrSpaceGranularity
= 32;
1082 Ptr
->AddrRangeMin
= 0;
1083 Ptr
->AddrRangeMax
= 0;
1084 Ptr
->AddrTranslationOffset
= EFI_RESOURCE_NONEXISTENT
;
1096 Ptr
->SpecificFlag
= 0;
1097 Ptr
->AddrSpaceGranularity
= 64;
1098 Ptr
->AddrRangeMin
= 0;
1099 Ptr
->AddrRangeMax
= 0;
1100 Ptr
->AddrTranslationOffset
= EFI_RESOURCE_NONEXISTENT
;
1106 // Prefetch memory 64
1112 Ptr
->SpecificFlag
= 6;
1113 Ptr
->AddrSpaceGranularity
= 64;
1114 Ptr
->AddrRangeMin
= 0;
1115 Ptr
->AddrRangeMax
= 0;
1116 Ptr
->AddrTranslationOffset
= EFI_RESOURCE_NONEXISTENT
;
1121 Temp
+= sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
);
1125 ((EFI_ACPI_END_TAG_DESCRIPTOR
*)Temp
)->Desc
= 0x79;
1126 ((EFI_ACPI_END_TAG_DESCRIPTOR
*)Temp
)->Checksum
= 0x0;
1128 *Configuration
= Buffer
;
1133 List
= List
->ForwardLink
;
1136 return EFI_INVALID_PARAMETER
;
1140 Provides the hooks from the PCI bus driver to every PCI controller (device/function) at various
1141 stages of the PCI enumeration process that allow the host bridge driver to preinitialize individual
1142 PCI controllers before enumeration.
1144 This function is called during the PCI enumeration process. No specific action is expected from this
1145 member function. It allows the host bridge driver to preinitialize individual PCI controllers before
1148 @param This Pointer to the EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL instance.
1149 @param RootBridgeHandle The associated PCI root bridge handle. Type EFI_HANDLE is defined in
1150 InstallProtocolInterface() in the UEFI 2.0 Specification.
1151 @param PciAddress The address of the PCI device on the PCI bus. This address can be passed to the
1152 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL member functions to access the PCI
1153 configuration space of the device. See Table 12-1 in the UEFI 2.0 Specification for
1154 the definition of EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS.
1155 @param Phase The phase of the PCI device enumeration.
1157 @retval EFI_SUCCESS The requested parameters were returned.
1158 @retval EFI_INVALID_PARAMETER RootBridgeHandle is not a valid root bridge handle.
1159 @retval EFI_INVALID_PARAMETER Phase is not a valid phase that is defined in
1160 EFI_PCI_CONTROLLER_RESOURCE_ALLOCATION_PHASE.
1161 @retval EFI_DEVICE_ERROR Programming failed due to a hardware error. The PCI enumerator should
1162 not enumerate this device, including its child devices if it is a PCI-to-PCI
1168 PreprocessController (
1169 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
1170 IN EFI_HANDLE RootBridgeHandle
,
1171 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS PciAddress
,
1172 IN EFI_PCI_CONTROLLER_RESOURCE_ALLOCATION_PHASE Phase
1175 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
1176 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
1179 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
1180 List
= HostBridgeInstance
->Head
.ForwardLink
;
1183 // Enumerate the root bridges in this host bridge
1185 while (List
!= &HostBridgeInstance
->Head
) {
1186 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
1187 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
1190 List
= List
->ForwardLink
;
1192 if (List
== &HostBridgeInstance
->Head
) {
1193 return EFI_INVALID_PARAMETER
;
1196 if ((UINT32
)Phase
> EfiPciBeforeResourceCollection
) {
1197 return EFI_INVALID_PARAMETER
;