2 Provides the basic interfaces to abstract a PCI Host Bridge Resource Allocation
4 Copyright (c) 2008 - 2010, 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] = {
31 (UINT8
) (sizeof(ACPI_HID_DEVICE_PATH
)),
32 (UINT8
) ((sizeof(ACPI_HID_DEVICE_PATH
)) >> 8),
36 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
37 END_DEVICE_PATH_LENGTH
,
42 PCI_ROOT_BRIDGE_RESOURCE_APPETURE mResAppeture
[1][1] = {
43 {0, 0xff, 0x80000000, 0xffffffff, 0, 0xffff}
46 EFI_HANDLE mDriverImageHandle
;
48 PCI_HOST_BRIDGE_INSTANCE mPciHostBridgeInstanceTemplate
= {
49 PCI_HOST_BRIDGE_SIGNATURE
, // Signature
50 NULL
, // HostBridgeHandle
51 0, // RootBridgeNumber
53 FALSE
, // ResourceSubiteed
72 Entry point of this driver
74 @param ImageHandle Handle of driver image
75 @param SystemTable Point to EFI_SYSTEM_TABLE
77 @retval EFI_OUT_OF_RESOURCES Can not allocate memory resource
78 @retval EFI_DEVICE_ERROR Can not install the protocol instance
79 @retval EFI_SUCCESS Success to initialize the Pci host bridge.
83 InitializePciHostBridge (
84 IN EFI_HANDLE ImageHandle
,
85 IN EFI_SYSTEM_TABLE
*SystemTable
91 PCI_HOST_BRIDGE_INSTANCE
*HostBridge
;
92 PCI_ROOT_BRIDGE_INSTANCE
*PrivateData
;
94 mDriverImageHandle
= ImageHandle
;
97 // Create Host Bridge Device Handle
99 for (Loop1
= 0; Loop1
< HOST_BRIDGE_NUMBER
; Loop1
++) {
100 HostBridge
= AllocateCopyPool (sizeof(PCI_HOST_BRIDGE_INSTANCE
), &mPciHostBridgeInstanceTemplate
);
101 if (HostBridge
== NULL
) {
102 return EFI_OUT_OF_RESOURCES
;
105 HostBridge
->RootBridgeNumber
= RootBridgeNumber
[Loop1
];
106 InitializeListHead (&HostBridge
->Head
);
108 Status
= gBS
->InstallMultipleProtocolInterfaces (
109 &HostBridge
->HostBridgeHandle
,
110 &gEfiPciHostBridgeResourceAllocationProtocolGuid
, &HostBridge
->ResAlloc
,
113 if (EFI_ERROR (Status
)) {
114 FreePool (HostBridge
);
115 return EFI_DEVICE_ERROR
;
119 // Create Root Bridge Device Handle in this Host Bridge
122 for (Loop2
= 0; Loop2
< HostBridge
->RootBridgeNumber
; Loop2
++) {
123 PrivateData
= AllocateZeroPool (sizeof(PCI_ROOT_BRIDGE_INSTANCE
));
124 if (PrivateData
== NULL
) {
125 return EFI_OUT_OF_RESOURCES
;
128 PrivateData
->Signature
= PCI_ROOT_BRIDGE_SIGNATURE
;
129 PrivateData
->DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*)&mEfiPciRootBridgeDevicePath
[Loop1
][Loop2
];
131 RootBridgeConstructor (
133 HostBridge
->HostBridgeHandle
,
134 RootBridgeAttribute
[Loop1
][Loop2
],
135 &mResAppeture
[Loop1
][Loop2
]
138 Status
= gBS
->InstallMultipleProtocolInterfaces(
139 &PrivateData
->Handle
,
140 &gEfiDevicePathProtocolGuid
, PrivateData
->DevicePath
,
141 &gEfiPciRootBridgeIoProtocolGuid
, &PrivateData
->Io
,
144 if (EFI_ERROR (Status
)) {
145 FreePool(PrivateData
);
146 return EFI_DEVICE_ERROR
;
149 InsertTailList (&HostBridge
->Head
, &PrivateData
->Link
);
158 These are the notifications from the PCI bus driver that it is about to enter a certain
159 phase of the PCI enumeration process.
161 This member function can be used to notify the host bridge driver to perform specific actions,
162 including any chipset-specific initialization, so that the chipset is ready to enter the next phase.
163 Eight notification points are defined at this time. See belows:
164 EfiPciHostBridgeBeginEnumeration Resets the host bridge PCI apertures and internal data
165 structures. The PCI enumerator should issue this notification
166 before starting a fresh enumeration process. Enumeration cannot
167 be restarted after sending any other notification such as
168 EfiPciHostBridgeBeginBusAllocation.
169 EfiPciHostBridgeBeginBusAllocation The bus allocation phase is about to begin. No specific action is
170 required here. This notification can be used to perform any
171 chipset-specific programming.
172 EfiPciHostBridgeEndBusAllocation The bus allocation and bus programming phase is complete. No
173 specific action is required here. This notification can be used to
174 perform any chipset-specific programming.
175 EfiPciHostBridgeBeginResourceAllocation
176 The resource allocation phase is about to begin. No specific
177 action is required here. This notification can be used to perform
178 any chipset-specific programming.
179 EfiPciHostBridgeAllocateResources Allocates resources per previously submitted requests for all the PCI
180 root bridges. These resource settings are returned on the next call to
181 GetProposedResources(). Before calling NotifyPhase() with a Phase of
182 EfiPciHostBridgeAllocateResource, the PCI bus enumerator is responsible
183 for gathering I/O and memory requests for
184 all the PCI root bridges and submitting these requests using
185 SubmitResources(). This function pads the resource amount
186 to suit the root bridge hardware, takes care of dependencies between
187 the PCI root bridges, and calls the Global Coherency Domain (GCD)
188 with the allocation request. In the case of padding, the allocated range
189 could be bigger than what was requested.
190 EfiPciHostBridgeSetResources Programs the host bridge hardware to decode previously allocated
191 resources (proposed resources) for all the PCI root bridges. After the
192 hardware is programmed, reassigning resources will not be supported.
193 The bus settings are not affected.
194 EfiPciHostBridgeFreeResources Deallocates resources that were previously allocated for all the PCI
195 root bridges and resets the I/O and memory apertures to their initial
196 state. The bus settings are not affected. If the request to allocate
197 resources fails, the PCI enumerator can use this notification to
198 deallocate previous resources, adjust the requests, and retry
200 EfiPciHostBridgeEndResourceAllocation The resource allocation phase is completed. No specific action is
201 required here. This notification can be used to perform any chipsetspecific
204 @param[in] This The instance pointer of EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
205 @param[in] Phase The phase during enumeration
207 @retval EFI_NOT_READY This phase cannot be entered at this time. For example, this error
208 is valid for a Phase of EfiPciHostBridgeAllocateResources if
209 SubmitResources() has not been called for one or more
210 PCI root bridges before this call
211 @retval EFI_DEVICE_ERROR Programming failed due to a hardware error. This error is valid
212 for a Phase of EfiPciHostBridgeSetResources.
213 @retval EFI_INVALID_PARAMETER Invalid phase parameter
214 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
215 This error is valid for a Phase of EfiPciHostBridgeAllocateResources if the
216 previously submitted resource requests cannot be fulfilled or
217 were only partially fulfilled.
218 @retval EFI_SUCCESS The notification was accepted without any errors.
224 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
225 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PHASE Phase
228 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
229 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
230 PCI_RESOURCE_TYPE Index
;
232 EFI_PHYSICAL_ADDRESS BaseAddress
;
234 UINTN BitsOfAlignment
;
236 EFI_STATUS ReturnStatus
;
238 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
242 case EfiPciHostBridgeBeginEnumeration
:
243 if (HostBridgeInstance
->CanRestarted
) {
245 // Reset the Each Root Bridge
247 List
= HostBridgeInstance
->Head
.ForwardLink
;
249 while (List
!= &HostBridgeInstance
->Head
) {
250 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
251 for (Index
= TypeIo
; Index
< TypeMax
; Index
++) {
252 RootBridgeInstance
->ResAllocNode
[Index
].Type
= Index
;
253 RootBridgeInstance
->ResAllocNode
[Index
].Base
= 0;
254 RootBridgeInstance
->ResAllocNode
[Index
].Length
= 0;
255 RootBridgeInstance
->ResAllocNode
[Index
].Status
= ResNone
;
258 List
= List
->ForwardLink
;
261 HostBridgeInstance
->ResourceSubmited
= FALSE
;
262 HostBridgeInstance
->CanRestarted
= TRUE
;
267 return EFI_NOT_READY
;
271 case EfiPciHostBridgeBeginBusAllocation
:
273 // No specific action is required here, can perform any chipset specific programing
275 HostBridgeInstance
->CanRestarted
= FALSE
;
279 case EfiPciHostBridgeEndBusAllocation
:
281 // No specific action is required here, can perform any chipset specific programing
283 //HostBridgeInstance->CanRestarted = FALSE;
287 case EfiPciHostBridgeBeginResourceAllocation
:
289 // No specific action is required here, can perform any chipset specific programing
291 //HostBridgeInstance->CanRestarted = FALSE;
295 case EfiPciHostBridgeAllocateResources
:
296 ReturnStatus
= EFI_SUCCESS
;
297 if (HostBridgeInstance
->ResourceSubmited
) {
299 // Take care of the resource dependencies between the root bridges
301 List
= HostBridgeInstance
->Head
.ForwardLink
;
303 while (List
!= &HostBridgeInstance
->Head
) {
304 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
305 for (Index
= TypeIo
; Index
< TypeBus
; Index
++) {
306 if (RootBridgeInstance
->ResAllocNode
[Index
].Status
!= ResNone
) {
308 AddrLen
= RootBridgeInstance
->ResAllocNode
[Index
].Length
;
311 // Get the number of '1' in Alignment.
313 BitsOfAlignment
= (UINTN
) (HighBitSet64 (RootBridgeInstance
->ResAllocNode
[Index
].Alignment
) + 1);
319 // It is impossible for this chipset to align 0xFFFF for IO16
322 if (BitsOfAlignment
>= 16) {
326 Status
= gDS
->AllocateIoSpace (
327 EfiGcdAllocateAnySearchBottomUp
,
336 if (!EFI_ERROR (Status
)) {
337 RootBridgeInstance
->ResAllocNode
[Index
].Base
= (UINTN
)BaseAddress
;
338 RootBridgeInstance
->ResAllocNode
[Index
].Status
= ResAllocated
;
340 ReturnStatus
= Status
;
341 if (Status
!= EFI_OUT_OF_RESOURCES
) {
342 RootBridgeInstance
->ResAllocNode
[Index
].Length
= 0;
351 // It is impossible for this chipset to align 0xFFFFFFFF for Mem32
355 if (BitsOfAlignment
>= 32) {
359 Status
= gDS
->AllocateMemorySpace (
360 EfiGcdAllocateAnySearchBottomUp
,
361 EfiGcdMemoryTypeMemoryMappedIo
,
369 if (!EFI_ERROR (Status
)) {
370 // We were able to allocate the PCI memory
371 RootBridgeInstance
->ResAllocNode
[Index
].Base
= (UINTN
)BaseAddress
;
372 RootBridgeInstance
->ResAllocNode
[Index
].Status
= ResAllocated
;
375 // Not able to allocate enough PCI memory
376 ReturnStatus
= Status
;
378 if (Status
!= EFI_OUT_OF_RESOURCES
) {
379 RootBridgeInstance
->ResAllocNode
[Index
].Length
= 0;
388 ReturnStatus
= EFI_ABORTED
;
397 List
= List
->ForwardLink
;
403 return EFI_NOT_READY
;
407 case EfiPciHostBridgeSetResources
:
410 case EfiPciHostBridgeFreeResources
:
411 ReturnStatus
= EFI_SUCCESS
;
412 List
= HostBridgeInstance
->Head
.ForwardLink
;
413 while (List
!= &HostBridgeInstance
->Head
) {
414 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
415 for (Index
= TypeIo
; Index
< TypeBus
; Index
++) {
416 if (RootBridgeInstance
->ResAllocNode
[Index
].Status
== ResAllocated
) {
417 AddrLen
= RootBridgeInstance
->ResAllocNode
[Index
].Length
;
418 BaseAddress
= RootBridgeInstance
->ResAllocNode
[Index
].Base
;
422 Status
= gDS
->FreeIoSpace (BaseAddress
, AddrLen
);
423 if (EFI_ERROR (Status
)) {
424 ReturnStatus
= Status
;
429 Status
= gDS
->FreeMemorySpace (BaseAddress
, AddrLen
);
430 if (EFI_ERROR (Status
)) {
431 ReturnStatus
= Status
;
449 RootBridgeInstance
->ResAllocNode
[Index
].Type
= Index
;
450 RootBridgeInstance
->ResAllocNode
[Index
].Base
= 0;
451 RootBridgeInstance
->ResAllocNode
[Index
].Length
= 0;
452 RootBridgeInstance
->ResAllocNode
[Index
].Status
= ResNone
;
456 List
= List
->ForwardLink
;
459 HostBridgeInstance
->ResourceSubmited
= FALSE
;
460 HostBridgeInstance
->CanRestarted
= TRUE
;
464 case EfiPciHostBridgeEndResourceAllocation
:
465 HostBridgeInstance
->CanRestarted
= FALSE
;
469 return EFI_INVALID_PARAMETER
;
476 Return the device handle of the next PCI root bridge that is associated with this Host Bridge.
478 This function is called multiple times to retrieve the device handles of all the PCI root bridges that
479 are associated with this PCI host bridge. Each PCI host bridge is associated with one or more PCI
480 root bridges. On each call, the handle that was returned by the previous call is passed into the
481 interface, and on output the interface returns the device handle of the next PCI root bridge. The
482 caller can use the handle to obtain the instance of the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
483 for that root bridge. When there are no more PCI root bridges to report, the interface returns
484 EFI_NOT_FOUND. A PCI enumerator must enumerate the PCI root bridges in the order that they
485 are returned by this function.
486 For D945 implementation, there is only one root bridge in PCI host bridge.
488 @param[in] This The instance pointer of EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
489 @param[in, out] RootBridgeHandle Returns the device handle of the next PCI root bridge.
491 @retval EFI_SUCCESS If parameter RootBridgeHandle = NULL, then return the first Rootbridge handle of the
492 specific Host bridge and return EFI_SUCCESS.
493 @retval EFI_NOT_FOUND Can not find the any more root bridge in specific host bridge.
494 @retval EFI_INVALID_PARAMETER RootBridgeHandle is not an EFI_HANDLE that was
495 returned on a previous call to GetNextRootBridge().
500 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
501 IN OUT EFI_HANDLE
*RootBridgeHandle
504 BOOLEAN NoRootBridge
;
506 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
507 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
510 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
511 List
= HostBridgeInstance
->Head
.ForwardLink
;
514 while (List
!= &HostBridgeInstance
->Head
) {
515 NoRootBridge
= FALSE
;
516 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
517 if (*RootBridgeHandle
== NULL
) {
519 // Return the first Root Bridge Handle of the Host Bridge
521 *RootBridgeHandle
= RootBridgeInstance
->Handle
;
524 if (*RootBridgeHandle
== RootBridgeInstance
->Handle
) {
528 List
= List
->ForwardLink
;
529 if (List
!=&HostBridgeInstance
->Head
) {
530 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
531 *RootBridgeHandle
= RootBridgeInstance
->Handle
;
534 return EFI_NOT_FOUND
;
539 List
= List
->ForwardLink
;
543 return EFI_NOT_FOUND
;
545 return EFI_INVALID_PARAMETER
;
550 Returns the allocation attributes of a PCI root bridge.
552 The function returns the allocation attributes of a specific PCI root bridge. The attributes can vary
553 from one PCI root bridge to another. These attributes are different from the decode-related
554 attributes that are returned by the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.GetAttributes() member function. The
555 RootBridgeHandle parameter is used to specify the instance of the PCI root bridge. The device
556 handles of all the root bridges that are associated with this host bridge must be obtained by calling
557 GetNextRootBridge(). The attributes are static in the sense that they do not change during or
558 after the enumeration process. The hardware may provide mechanisms to change the attributes on
559 the fly, but such changes must be completed before EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL is
560 installed. The permitted values of EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ATTRIBUTES are defined in
561 "Related Definitions" below. The caller uses these attributes to combine multiple resource requests.
562 For example, if the flag EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM is set, the PCI bus enumerator needs to
563 include requests for the prefetchable memory in the nonprefetchable memory pool and not request any
565 Attribute Description
566 ------------------------------------ ----------------------------------------------------------------------
567 EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM If this bit is set, then the PCI root bridge does not support separate
568 windows for nonprefetchable and prefetchable memory. A PCI bus
569 driver needs to include requests for prefetchable memory in the
570 nonprefetchable memory pool.
572 EFI_PCI_HOST_BRIDGE_MEM64_DECODE If this bit is set, then the PCI root bridge supports 64-bit memory
573 windows. If this bit is not set, the PCI bus driver needs to include
574 requests for a 64-bit memory address in the corresponding 32-bit
577 @param[in] This The instance pointer of EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
578 @param[in] RootBridgeHandle The device handle of the PCI root bridge in which the caller is interested. Type
579 EFI_HANDLE is defined in InstallProtocolInterface() in the UEFI 2.0 Specification.
580 @param[out] Attributes The pointer to attribte of root bridge, it is output parameter
582 @retval EFI_INVALID_PARAMETER Attribute pointer is NULL
583 @retval EFI_INVALID_PARAMETER RootBridgehandle is invalid.
584 @retval EFI_SUCCESS Success to get attribute of interested root bridge.
590 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
591 IN EFI_HANDLE RootBridgeHandle
,
592 OUT UINT64
*Attributes
596 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
597 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
599 if (Attributes
== NULL
) {
600 return EFI_INVALID_PARAMETER
;
603 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
604 List
= HostBridgeInstance
->Head
.ForwardLink
;
606 while (List
!= &HostBridgeInstance
->Head
) {
607 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
608 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
609 *Attributes
= RootBridgeInstance
->RootBridgeAttrib
;
612 List
= List
->ForwardLink
;
616 // RootBridgeHandle is not an EFI_HANDLE
617 // that was returned on a previous call to GetNextRootBridge()
619 return EFI_INVALID_PARAMETER
;
623 Sets up the specified PCI root bridge for the bus enumeration process.
625 This member function sets up the root bridge for bus enumeration and returns the PCI bus range
626 over which the search should be performed in ACPI 2.0 resource descriptor format.
628 @param[in] This The EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ PROTOCOL instance.
629 @param[in] RootBridgeHandle The PCI Root Bridge to be set up.
630 @param[out] Configuration Pointer to the pointer to the PCI bus resource descriptor.
632 @retval EFI_INVALID_PARAMETER Invalid Root bridge's handle
633 @retval EFI_OUT_OF_RESOURCES Fail to allocate ACPI resource descriptor tag.
634 @retval EFI_SUCCESS Sucess to allocate ACPI resource descriptor.
640 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
641 IN EFI_HANDLE RootBridgeHandle
,
642 OUT VOID
**Configuration
646 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
647 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
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
) {
660 // Set up the Root Bridge for Bus Enumeration
662 BusStart
= RootBridgeInstance
->BusBase
;
663 BusEnd
= RootBridgeInstance
->BusLimit
;
665 // Program the Hardware(if needed) if error return EFI_DEVICE_ERROR
668 Buffer
= AllocatePool (sizeof(EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) + sizeof(EFI_ACPI_END_TAG_DESCRIPTOR
));
669 if (Buffer
== NULL
) {
670 return EFI_OUT_OF_RESOURCES
;
673 Temp
= (UINT8
*)Buffer
;
675 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->Desc
= 0x8A;
676 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->Len
= 0x2B;
677 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->ResType
= 2;
678 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->GenFlag
= 0;
679 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->SpecificFlag
= 0;
680 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->AddrSpaceGranularity
= 0;
681 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->AddrRangeMin
= BusStart
;
682 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->AddrRangeMax
= 0;
683 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->AddrTranslationOffset
= 0;
684 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Temp
)->AddrLen
= BusEnd
- BusStart
+ 1;
686 Temp
= Temp
+ sizeof(EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
);
687 ((EFI_ACPI_END_TAG_DESCRIPTOR
*)Temp
)->Desc
= 0x79;
688 ((EFI_ACPI_END_TAG_DESCRIPTOR
*)Temp
)->Checksum
= 0x0;
690 *Configuration
= Buffer
;
693 List
= List
->ForwardLink
;
696 return EFI_INVALID_PARAMETER
;
700 Programs the PCI root bridge hardware so that it decodes the specified PCI bus range.
702 This member function programs the specified PCI root bridge to decode the bus range that is
703 specified by the input parameter Configuration.
704 The bus range information is specified in terms of the ACPI 2.0 resource descriptor format.
706 @param[in] This The EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ PROTOCOL instance
707 @param[in] RootBridgeHandle The PCI Root Bridge whose bus range is to be programmed
708 @param[in] Configuration The pointer to the PCI bus resource descriptor
710 @retval EFI_INVALID_PARAMETER RootBridgeHandle is not a valid root bridge handle.
711 @retval EFI_INVALID_PARAMETER Configuration is NULL.
712 @retval EFI_INVALID_PARAMETER Configuration does not point to a valid ACPI 2.0 resource descriptor.
713 @retval EFI_INVALID_PARAMETER Configuration does not include a valid ACPI 2.0 bus resource descriptor.
714 @retval EFI_INVALID_PARAMETER Configuration includes valid ACPI 2.0 resource descriptors other than
716 @retval EFI_INVALID_PARAMETER Configuration contains one or more invalid ACPI resource descriptors.
717 @retval EFI_INVALID_PARAMETER "Address Range Minimum" is invalid for this root bridge.
718 @retval EFI_INVALID_PARAMETER "Address Range Length" is invalid for this root bridge.
719 @retval EFI_DEVICE_ERROR Programming failed due to a hardware error.
720 @retval EFI_SUCCESS The bus range for the PCI root bridge was programmed.
726 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
727 IN EFI_HANDLE RootBridgeHandle
,
728 IN VOID
*Configuration
732 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
733 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
739 if (Configuration
== NULL
) {
740 return EFI_INVALID_PARAMETER
;
746 // Check the Configuration is valid
748 if(*Ptr
!= ACPI_ADDRESS_SPACE_DESCRIPTOR
) {
749 return EFI_INVALID_PARAMETER
;
752 if (((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Ptr
)->ResType
!= 2) {
753 return EFI_INVALID_PARAMETER
;
756 Ptr
+= sizeof(EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
);
757 if (*Ptr
!= ACPI_END_TAG_DESCRIPTOR
) {
758 return EFI_INVALID_PARAMETER
;
761 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
762 List
= HostBridgeInstance
->Head
.ForwardLink
;
766 while (List
!= &HostBridgeInstance
->Head
) {
767 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
768 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
769 BusStart
= (UINTN
)((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Ptr
)->AddrRangeMin
;
770 BusLen
= (UINTN
)((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*)Ptr
)->AddrLen
;
771 BusEnd
= BusStart
+ BusLen
- 1;
773 if (BusStart
> BusEnd
) {
774 return EFI_INVALID_PARAMETER
;
777 if ((BusStart
< RootBridgeInstance
->BusBase
) || (BusEnd
> RootBridgeInstance
->BusLimit
)) {
778 return EFI_INVALID_PARAMETER
;
782 // Update the Bus Range
784 RootBridgeInstance
->ResAllocNode
[TypeBus
].Base
= BusStart
;
785 RootBridgeInstance
->ResAllocNode
[TypeBus
].Length
= BusLen
;
786 RootBridgeInstance
->ResAllocNode
[TypeBus
].Status
= ResAllocated
;
789 // Program the Root Bridge Hardware
795 List
= List
->ForwardLink
;
798 return EFI_INVALID_PARAMETER
;
803 Submits the I/O and memory resource requirements for the specified PCI root bridge.
805 This function is used to submit all the I/O and memory resources that are required by the specified
806 PCI root bridge. The input parameter Configuration is used to specify the following:
807 - The various types of resources that are required
808 - The associated lengths in terms of ACPI 2.0 resource descriptor format
810 @param[in] This Pointer to the EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL instance.
811 @param[in] RootBridgeHandle The PCI root bridge whose I/O and memory resource requirements are being submitted.
812 @param[in] Configuration The pointer to the PCI I/O and PCI memory resource descriptor.
814 @retval EFI_SUCCESS The I/O and memory resource requests for a PCI root bridge were accepted.
815 @retval EFI_INVALID_PARAMETER RootBridgeHandle is not a valid root bridge handle.
816 @retval EFI_INVALID_PARAMETER Configuration is NULL.
817 @retval EFI_INVALID_PARAMETER Configuration does not point to a valid ACPI 2.0 resource descriptor.
818 @retval EFI_INVALID_PARAMETER Configuration includes requests for one or more resource types that are
819 not supported by this PCI root bridge. This error will happen if the caller
820 did not combine resources according to Attributes that were returned by
821 GetAllocAttributes().
822 @retval EFI_INVALID_PARAMETER Address Range Maximum" is invalid.
823 @retval EFI_INVALID_PARAMETER "Address Range Length" is invalid for this PCI root bridge.
824 @retval EFI_INVALID_PARAMETER "Address Space Granularity" is invalid for this PCI root bridge.
830 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
831 IN EFI_HANDLE RootBridgeHandle
,
832 IN VOID
*Configuration
836 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
837 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
839 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Ptr
;
844 // Check the input parameter: Configuration
846 if (Configuration
== NULL
) {
847 return EFI_INVALID_PARAMETER
;
850 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
851 List
= HostBridgeInstance
->Head
.ForwardLink
;
853 Temp
= (UINT8
*)Configuration
;
854 while ( *Temp
== 0x8A) {
855 Temp
+= sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) ;
858 return EFI_INVALID_PARAMETER
;
861 Temp
= (UINT8
*)Configuration
;
862 while (List
!= &HostBridgeInstance
->Head
) {
863 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
864 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
865 while ( *Temp
== 0x8A) {
866 Ptr
= (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Temp
;
869 // Check Address Length
871 if (Ptr
->AddrLen
> 0xffffffff) {
872 return EFI_INVALID_PARAMETER
;
876 // Check address range alignment
878 if (Ptr
->AddrRangeMax
>= 0xffffffff || Ptr
->AddrRangeMax
!= (GetPowerOfTwo64 (Ptr
->AddrRangeMax
+ 1) - 1)) {
879 return EFI_INVALID_PARAMETER
;
882 switch (Ptr
->ResType
) {
887 // Check invalid Address Sapce Granularity
889 if (Ptr
->AddrSpaceGranularity
!= 32) {
890 return EFI_INVALID_PARAMETER
;
894 // check the memory resource request is supported by PCI root bridge
896 if (RootBridgeInstance
->RootBridgeAttrib
== EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM
&&
897 Ptr
->SpecificFlag
== 0x06) {
898 return EFI_INVALID_PARAMETER
;
901 AddrLen
= Ptr
->AddrLen
;
902 Alignment
= Ptr
->AddrRangeMax
;
903 if (Ptr
->AddrSpaceGranularity
== 32) {
904 if (Ptr
->SpecificFlag
== 0x06) {
908 RootBridgeInstance
->ResAllocNode
[TypePMem32
].Status
= ResSubmitted
;
910 RootBridgeInstance
->ResAllocNode
[TypeMem32
].Length
= AddrLen
;
911 RootBridgeInstance
->ResAllocNode
[TypeMem32
].Alignment
= Alignment
;
912 RootBridgeInstance
->ResAllocNode
[TypeMem32
].Status
= ResRequested
;
913 HostBridgeInstance
->ResourceSubmited
= TRUE
;
917 if (Ptr
->AddrSpaceGranularity
== 64) {
918 if (Ptr
->SpecificFlag
== 0x06) {
919 RootBridgeInstance
->ResAllocNode
[TypePMem64
].Status
= ResSubmitted
;
921 RootBridgeInstance
->ResAllocNode
[TypeMem64
].Status
= ResSubmitted
;
927 AddrLen
= (UINTN
) Ptr
->AddrLen
;
928 Alignment
= (UINTN
) Ptr
->AddrRangeMax
;
929 RootBridgeInstance
->ResAllocNode
[TypeIo
].Length
= AddrLen
;
930 RootBridgeInstance
->ResAllocNode
[TypeIo
].Alignment
= Alignment
;
931 RootBridgeInstance
->ResAllocNode
[TypeIo
].Status
= ResRequested
;
932 HostBridgeInstance
->ResourceSubmited
= TRUE
;
939 Temp
+= sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) ;
945 List
= List
->ForwardLink
;
948 return EFI_INVALID_PARAMETER
;
952 Returns the proposed resource settings for the specified PCI root bridge.
954 This member function returns the proposed resource settings for the specified PCI root bridge. The
955 proposed resource settings are prepared when NotifyPhase() is called with a Phase of
956 EfiPciHostBridgeAllocateResources. The output parameter Configuration
957 specifies the following:
958 - The various types of resources, excluding bus resources, that are allocated
959 - The associated lengths in terms of ACPI 2.0 resource descriptor format
961 @param[in] This Pointer to the EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL instance.
962 @param[in] RootBridgeHandle The PCI root bridge handle. Type EFI_HANDLE is defined in InstallProtocolInterface() in the UEFI 2.0 Specification.
963 @param[out] Configuration The pointer to the pointer to the PCI I/O and memory resource descriptor.
965 @retval EFI_SUCCESS The requested parameters were returned.
966 @retval EFI_INVALID_PARAMETER RootBridgeHandle is not a valid root bridge handle.
967 @retval EFI_DEVICE_ERROR Programming failed due to a hardware error.
968 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
973 GetProposedResources(
974 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
975 IN EFI_HANDLE RootBridgeHandle
,
976 OUT VOID
**Configuration
980 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
981 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
986 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Ptr
;
992 // Get the Host Bridge Instance from the resource allocation protocol
994 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
995 List
= HostBridgeInstance
->Head
.ForwardLink
;
998 // Enumerate the root bridges in this host bridge
1000 while (List
!= &HostBridgeInstance
->Head
) {
1001 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
1002 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
1003 for (Index
= 0; Index
< TypeBus
; Index
++) {
1004 if (RootBridgeInstance
->ResAllocNode
[Index
].Status
!= ResNone
) {
1010 return EFI_INVALID_PARAMETER
;
1013 Buffer
= AllocateZeroPool (Number
* sizeof(EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) + sizeof(EFI_ACPI_END_TAG_DESCRIPTOR
));
1014 if (Buffer
== NULL
) {
1015 return EFI_OUT_OF_RESOURCES
;
1019 for (Index
= 0; Index
< TypeBus
; Index
++) {
1020 if (RootBridgeInstance
->ResAllocNode
[Index
].Status
!= ResNone
) {
1021 Ptr
= (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Temp
;
1022 ResStatus
= RootBridgeInstance
->ResAllocNode
[Index
].Status
;
1034 Ptr
->SpecificFlag
= 0;
1035 Ptr
->AddrRangeMin
= RootBridgeInstance
->ResAllocNode
[Index
].Base
;
1036 Ptr
->AddrRangeMax
= 0;
1037 Ptr
->AddrTranslationOffset
= \
1038 (ResStatus
== ResAllocated
) ? EFI_RESOURCE_SATISFIED
: EFI_RESOURCE_LESS
;
1039 Ptr
->AddrLen
= RootBridgeInstance
->ResAllocNode
[Index
].Length
;
1050 Ptr
->SpecificFlag
= 0;
1051 Ptr
->AddrSpaceGranularity
= 32;
1052 Ptr
->AddrRangeMin
= RootBridgeInstance
->ResAllocNode
[Index
].Base
;
1053 Ptr
->AddrRangeMax
= 0;
1054 Ptr
->AddrTranslationOffset
= \
1055 (ResStatus
== ResAllocated
) ? EFI_RESOURCE_SATISFIED
: EFI_RESOURCE_LESS
;
1056 Ptr
->AddrLen
= RootBridgeInstance
->ResAllocNode
[Index
].Length
;
1061 // Prefetch memory 32
1067 Ptr
->SpecificFlag
= 6;
1068 Ptr
->AddrSpaceGranularity
= 32;
1069 Ptr
->AddrRangeMin
= 0;
1070 Ptr
->AddrRangeMax
= 0;
1071 Ptr
->AddrTranslationOffset
= EFI_RESOURCE_NONEXISTENT
;
1083 Ptr
->SpecificFlag
= 0;
1084 Ptr
->AddrSpaceGranularity
= 64;
1085 Ptr
->AddrRangeMin
= 0;
1086 Ptr
->AddrRangeMax
= 0;
1087 Ptr
->AddrTranslationOffset
= EFI_RESOURCE_NONEXISTENT
;
1093 // Prefetch memory 64
1099 Ptr
->SpecificFlag
= 6;
1100 Ptr
->AddrSpaceGranularity
= 64;
1101 Ptr
->AddrRangeMin
= 0;
1102 Ptr
->AddrRangeMax
= 0;
1103 Ptr
->AddrTranslationOffset
= EFI_RESOURCE_NONEXISTENT
;
1108 Temp
+= sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
);
1112 ((EFI_ACPI_END_TAG_DESCRIPTOR
*)Temp
)->Desc
= 0x79;
1113 ((EFI_ACPI_END_TAG_DESCRIPTOR
*)Temp
)->Checksum
= 0x0;
1115 *Configuration
= Buffer
;
1120 List
= List
->ForwardLink
;
1123 return EFI_INVALID_PARAMETER
;
1127 Provides the hooks from the PCI bus driver to every PCI controller (device/function) at various
1128 stages of the PCI enumeration process that allow the host bridge driver to preinitialize individual
1129 PCI controllers before enumeration.
1131 This function is called during the PCI enumeration process. No specific action is expected from this
1132 member function. It allows the host bridge driver to preinitialize individual PCI controllers before
1135 @param This Pointer to the EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL instance.
1136 @param RootBridgeHandle The associated PCI root bridge handle. Type EFI_HANDLE is defined in
1137 InstallProtocolInterface() in the UEFI 2.0 Specification.
1138 @param PciAddress The address of the PCI device on the PCI bus. This address can be passed to the
1139 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL member functions to access the PCI
1140 configuration space of the device. See Table 12-1 in the UEFI 2.0 Specification for
1141 the definition of EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS.
1142 @param Phase The phase of the PCI device enumeration.
1144 @retval EFI_SUCCESS The requested parameters were returned.
1145 @retval EFI_INVALID_PARAMETER RootBridgeHandle is not a valid root bridge handle.
1146 @retval EFI_INVALID_PARAMETER Phase is not a valid phase that is defined in
1147 EFI_PCI_CONTROLLER_RESOURCE_ALLOCATION_PHASE.
1148 @retval EFI_DEVICE_ERROR Programming failed due to a hardware error. The PCI enumerator should
1149 not enumerate this device, including its child devices if it is a PCI-to-PCI
1155 PreprocessController (
1156 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
1157 IN EFI_HANDLE RootBridgeHandle
,
1158 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS PciAddress
,
1159 IN EFI_PCI_CONTROLLER_RESOURCE_ALLOCATION_PHASE Phase
1162 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
1163 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
1166 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
1167 List
= HostBridgeInstance
->Head
.ForwardLink
;
1170 // Enumerate the root bridges in this host bridge
1172 while (List
!= &HostBridgeInstance
->Head
) {
1173 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
1174 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
1177 List
= List
->ForwardLink
;
1179 if (List
== &HostBridgeInstance
->Head
) {
1180 return EFI_INVALID_PARAMETER
;
1183 if (Phase
< EfiPciBeforeChildBusEnumeration
|| Phase
> EfiPciBeforeResourceCollection
) {
1184 return EFI_INVALID_PARAMETER
;