2 Pci Host Bridge driver for a simple IIO. There is only one PCI Root Bridge in the system.
3 Provides the basic interfaces to abstract a PCI Host Bridge Resource Allocation.
5 Copyright (c) 2013-2015 Intel Corporation.
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include "PciHostBridge.h"
19 #include <IntelQNCRegs.h>
22 // We can hardcode the following for a Simple IIO -
23 // Root Bridge Count within the host bridge
24 // Root Bridge's device path
25 // Root Bridge's resource appeture
27 EFI_PCI_ROOT_BRIDGE_DEVICE_PATH mEfiPciRootBridgeDevicePath
[ROOT_BRIDGE_COUNT
] = {
34 (UINT8
) (sizeof (ACPI_HID_DEVICE_PATH
)),
35 (UINT8
) ((sizeof (ACPI_HID_DEVICE_PATH
)) >> 8)
43 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
45 END_DEVICE_PATH_LENGTH
,
52 EFI_HANDLE mDriverImageHandle
;
53 PCI_ROOT_BRIDGE_RESOURCE_APERTURE
*mResAperture
;
60 InitializePciHostBridge (
61 IN EFI_HANDLE ImageHandle
,
62 IN EFI_SYSTEM_TABLE
*SystemTable
68 Entry point of this driver.
72 ImageHandle - Image handle of this driver.
73 SystemTable - Pointer to standard EFI system table.
77 EFI_SUCCESS - Succeed.
78 EFI_DEVICE_ERROR - Fail to install PCI_ROOT_BRIDGE_IO protocol.
83 UINTN TotalRootBridgeFound
;
84 PCI_HOST_BRIDGE_INSTANCE
*HostBridge
;
85 PCI_ROOT_BRIDGE_INSTANCE
*PrivateData
;
86 UINT64 AllocAttributes
;
87 EFI_PHYSICAL_ADDRESS BaseAddress
;
91 mDriverImageHandle
= ImageHandle
;
94 // Most systems in the world including complex servers
95 // have only one Host Bridge. Create Host Bridge Device Handle
97 Status
= gBS
->AllocatePool(EfiBootServicesData
, sizeof(PCI_HOST_BRIDGE_INSTANCE
), (VOID
**) &HostBridge
);
98 ASSERT_EFI_ERROR (Status
);
99 ZeroMem (HostBridge
, sizeof (PCI_HOST_BRIDGE_INSTANCE
));
101 HostBridge
->Signature
= PCI_HOST_BRIDGE_SIGNATURE
;
102 HostBridge
->RootBridgeCount
= 1;
103 HostBridge
->ResourceSubmited
= FALSE
;
104 HostBridge
->CanRestarted
= TRUE
;
106 // InitializeListHead (&HostBridge->Head);
108 HostBridge
->ResAlloc
.NotifyPhase
= NotifyPhase
;
109 HostBridge
->ResAlloc
.GetNextRootBridge
= GetNextRootBridge
;
110 HostBridge
->ResAlloc
.GetAllocAttributes
= GetAttributes
;
111 HostBridge
->ResAlloc
.StartBusEnumeration
= StartBusEnumeration
;
112 HostBridge
->ResAlloc
.SetBusNumbers
= SetBusNumbers
;
113 HostBridge
->ResAlloc
.SubmitResources
= SubmitResources
;
114 HostBridge
->ResAlloc
.GetProposedResources
= GetProposedResources
;
115 HostBridge
->ResAlloc
.PreprocessController
= PreprocessController
;
117 Status
= gBS
->InstallProtocolInterface (
118 &HostBridge
->HostBridgeHandle
,
119 &gEfiPciHostBridgeResourceAllocationProtocolGuid
,
120 EFI_NATIVE_INTERFACE
,
121 &HostBridge
->ResAlloc
123 if (EFI_ERROR (Status
)) {
124 gBS
->FreePool (HostBridge
);
125 return EFI_DEVICE_ERROR
;
128 Status
= gBS
->AllocatePool (EfiBootServicesData
,
129 HostBridge
->RootBridgeCount
* sizeof(PCI_ROOT_BRIDGE_RESOURCE_APERTURE
),
130 (VOID
**) &mResAperture
);
131 ASSERT_EFI_ERROR (Status
);
132 ZeroMem (mResAperture
, HostBridge
->RootBridgeCount
* sizeof(PCI_ROOT_BRIDGE_RESOURCE_APERTURE
));
134 DEBUG ((EFI_D_INFO
, "Address of resource Aperture: %x\n", mResAperture
));
137 // Create Root Bridge Device Handle in this Host Bridge
139 InitializeListHead (&HostBridge
->Head
);
141 TotalRootBridgeFound
= 0;
143 Status
= gBS
->AllocatePool ( EfiBootServicesData
,sizeof (PCI_ROOT_BRIDGE_INSTANCE
), (VOID
**) &PrivateData
);
144 ASSERT_EFI_ERROR (Status
);
145 ZeroMem (PrivateData
, sizeof (PCI_ROOT_BRIDGE_INSTANCE
));
147 PrivateData
->Signature
= PCI_ROOT_BRIDGE_SIGNATURE
;
148 PrivateData
->DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) &mEfiPciRootBridgeDevicePath
[TotalRootBridgeFound
];
149 AllocAttributes
= GetAllocAttributes (TotalRootBridgeFound
);
151 SimpleIioRootBridgeConstructor (
153 HostBridge
->HostBridgeHandle
,
154 &(mResAperture
[TotalRootBridgeFound
]),
158 // Update Root Bridge with UDS resource information
160 PrivateData
->Aperture
.BusBase
= QNC_PCI_HOST_BRIDGE_RESOURCE_APPETURE_BUSBASE
;
161 PrivateData
->Aperture
.BusLimit
= QNC_PCI_HOST_BRIDGE_RESOURCE_APPETURE_BUSLIMIT
;
162 PrivateData
->Aperture
.Mem32Base
= PcdGet32 (PcdPciHostBridgeMemory32Base
);
163 PrivateData
->Aperture
.Mem32Limit
= PcdGet32 (PcdPciHostBridgeMemory32Base
) + (PcdGet32 (PcdPciHostBridgeMemory32Size
) - 1);
164 PrivateData
->Aperture
.IoBase
= PcdGet16 (PcdPciHostBridgeIoBase
);
165 PrivateData
->Aperture
.IoLimit
= PcdGet16 (PcdPciHostBridgeIoBase
) + (PcdGet16 (PcdPciHostBridgeIoSize
) - 1);
167 DEBUG ((EFI_D_INFO
, "PCI Host Bridge BusBase: %x\n", QNC_PCI_HOST_BRIDGE_RESOURCE_APPETURE_BUSBASE
));
168 DEBUG ((EFI_D_INFO
, "PCI Host Bridge BusLimit: %x\n", QNC_PCI_HOST_BRIDGE_RESOURCE_APPETURE_BUSLIMIT
));
169 DEBUG ((EFI_D_INFO
, "PCI Host Bridge PciResourceMem32Base: %x\n", PcdGet32 (PcdPciHostBridgeMemory32Base
)));
170 DEBUG ((EFI_D_INFO
, "PCI Host Bridge PciResourceMem32Limit: %x\n", PcdGet32 (PcdPciHostBridgeMemory32Base
) + (PcdGet32 (PcdPciHostBridgeMemory32Size
) - 1)));
171 DEBUG ((EFI_D_INFO
, "PCI Host Bridge PciResourceMem64Base: %lX\n", PcdGet64 (PcdPciHostBridgeMemory64Base
)));
172 DEBUG ((EFI_D_INFO
, "PCI Host Bridge PciResourceMem64Limit: %lX\n", PcdGet64 (PcdPciHostBridgeMemory64Base
) + (PcdGet64 (PcdPciHostBridgeMemory64Size
) - 1)));
173 DEBUG ((EFI_D_INFO
, "PCI Host Bridge PciResourceIoBase: %x\n", PcdGet16 (PcdPciHostBridgeIoBase
)));
174 DEBUG ((EFI_D_INFO
, "PCI Host Bridge PciResourceIoLimit: %x\n", PcdGet16 (PcdPciHostBridgeIoBase
) + (PcdGet16 (PcdPciHostBridgeIoSize
) - 1)));
176 PrivateData
->Handle
= NULL
;
177 Status
= gBS
->InstallMultipleProtocolInterfaces (
178 &PrivateData
->Handle
,
179 &gEfiDevicePathProtocolGuid
,
180 PrivateData
->DevicePath
,
181 &gEfiPciRootBridgeIoProtocolGuid
,
185 ASSERT_EFI_ERROR (Status
);
187 InsertTailList (&HostBridge
->Head
, &PrivateData
->Link
);
188 TotalRootBridgeFound
++; // This is a valid rootbridge so imcrement total root bridges found
191 // Add PCIE base into Runtime memory so that it can be reported in E820 table
193 Status
= gDS
->AddMemorySpace (
194 EfiGcdMemoryTypeMemoryMappedIo
,
195 PcdGet64 (PcdPciExpressBaseAddress
),
196 PcdGet64 (PcdPciExpressSize
),
197 EFI_MEMORY_RUNTIME
| EFI_MEMORY_UC
199 ASSERT_EFI_ERROR(Status
);
201 BaseAddress
= PcdGet64 (PcdPciExpressBaseAddress
);
203 Status
= gDS
->AllocateMemorySpace (
204 EfiGcdAllocateAddress
,
205 EfiGcdMemoryTypeMemoryMappedIo
,
207 PcdGet64 (PcdPciExpressSize
),
212 ASSERT_EFI_ERROR(Status
);
214 Status
= gDS
->SetMemorySpaceAttributes (
215 PcdGet64 (PcdPciExpressBaseAddress
),
216 PcdGet64 (PcdPciExpressSize
),
219 ASSERT_EFI_ERROR (Status
);
221 if (PcdGet16 (PcdPciHostBridgeIoSize
) > 0) {
223 // At present, we use up the first 4k for fixed ranges like
224 // ICH GPIO, ACPI and ISA devices. The first 4k is not
225 // tracked through GCD. It should be.
227 Status
= gDS
->AddIoSpace (
229 PcdGet16(PcdPciHostBridgeIoBase
),
230 PcdGet16(PcdPciHostBridgeIoSize
)
232 ASSERT_EFI_ERROR (Status
);
235 if (PcdGet32(PcdPciHostBridgeMemory32Size
) > 0) {
237 // Shouldn't the capabilities be UC?
239 Status
= gDS
->AddMemorySpace (
240 EfiGcdMemoryTypeMemoryMappedIo
,
241 PcdGet32(PcdPciHostBridgeMemory32Base
),
242 PcdGet32(PcdPciHostBridgeMemory32Size
),
245 ASSERT_EFI_ERROR (Status
);
254 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
255 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PHASE Phase
261 Enter a certain phase of the PCI enumeration process.
265 This - The EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL instance.
266 Phase - The phase during enumeration.
270 EFI_SUCCESS - Succeed.
271 EFI_INVALID_PARAMETER - Wrong phase parameter passed in.
272 EFI_NOT_READY - Resources have not been submitted yet.
276 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
277 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
278 PCI_RESOURCE_TYPE Index
;
279 EFI_LIST_ENTRY
*List
;
280 EFI_PHYSICAL_ADDRESS BaseAddress
;
282 UINTN BitsOfAlignment
;
285 EFI_STATUS ReturnStatus
;
286 PCI_RESOURCE_TYPE Index1
;
287 PCI_RESOURCE_TYPE Index2
;
288 BOOLEAN ResNodeHandled
[TypeMax
];
291 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
294 case EfiPciHostBridgeBeginEnumeration
:
295 if (HostBridgeInstance
->CanRestarted
) {
299 List
= HostBridgeInstance
->Head
.ForwardLink
;
301 while (List
!= &HostBridgeInstance
->Head
) {
302 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
303 for (Index
= TypeIo
; Index
< TypeMax
; Index
++) {
304 RootBridgeInstance
->ResAllocNode
[Index
].Type
= Index
;
305 RootBridgeInstance
->ResAllocNode
[Index
].Base
= 0;
306 RootBridgeInstance
->ResAllocNode
[Index
].Length
= 0;
307 RootBridgeInstance
->ResAllocNode
[Index
].Status
= ResNone
;
310 List
= List
->ForwardLink
;
313 HostBridgeInstance
->ResourceSubmited
= FALSE
;
314 HostBridgeInstance
->CanRestarted
= TRUE
;
319 return EFI_NOT_READY
;
323 case EfiPciHostBridgeEndEnumeration
:
327 case EfiPciHostBridgeBeginBusAllocation
:
329 // No specific action is required here, can perform any chipset specific programing
331 HostBridgeInstance
->CanRestarted
= FALSE
;
335 case EfiPciHostBridgeEndBusAllocation
:
337 // No specific action is required here, can perform any chipset specific programing
339 // HostBridgeInstance->CanRestarted = FALSE;
344 case EfiPciHostBridgeBeginResourceAllocation
:
346 // No specific action is required here, can perform any chipset specific programing
348 // HostBridgeInstance->CanRestarted = FALSE;
353 case EfiPciHostBridgeAllocateResources
:
354 ReturnStatus
= EFI_SUCCESS
;
355 if (HostBridgeInstance
->ResourceSubmited
) {
356 List
= HostBridgeInstance
->Head
.ForwardLink
;
357 while (List
!= &HostBridgeInstance
->Head
) {
358 for (Index1
= TypeIo
; Index1
< TypeBus
; Index1
++) {
359 ResNodeHandled
[Index1
] = FALSE
;
362 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
363 DEBUG ((EFI_D_INFO
, "Address of RootBridgeInstance: %x)\n", RootBridgeInstance
));
364 DEBUG ((EFI_D_INFO
, " Signature: %x\n", RootBridgeInstance
->Signature
));
365 DEBUG ((EFI_D_INFO
, " Bus Number Assigned: %x\n", RootBridgeInstance
->BusNumberAssigned
));
366 DEBUG ((EFI_D_INFO
, " Bus Scan Count: %x\n", RootBridgeInstance
->BusScanCount
));
368 for (Index1
= TypeIo
; Index1
< TypeBus
; Index1
++) {
369 if (RootBridgeInstance
->ResAllocNode
[Index1
].Status
== ResNone
) {
370 ResNodeHandled
[Index1
] = TRUE
;
373 // Allocate the resource node with max alignment at first
377 for (Index2
= TypeIo
; Index2
< TypeBus
; Index2
++) {
378 if (ResNodeHandled
[Index2
]) {
381 if (MaxAlignment
<= RootBridgeInstance
->ResAllocNode
[Index2
].Alignment
) {
382 MaxAlignment
= RootBridgeInstance
->ResAllocNode
[Index2
].Alignment
;
387 if (Index
< TypeMax
) {
388 ResNodeHandled
[Index
] = TRUE
;
393 Alignment
= RootBridgeInstance
->ResAllocNode
[Index
].Alignment
;
396 // Get the number of '1' in Alignment.
398 for (BitsOfAlignment
= 0; Alignment
!= 0; BitsOfAlignment
++) {
399 Alignment
= RShiftU64 (Alignment
, 1);
402 AddrLen
= RootBridgeInstance
->ResAllocNode
[Index
].Length
;
403 Alignment
= RootBridgeInstance
->ResAllocNode
[Index
].Alignment
;
405 DEBUG ((EFI_D_INFO
, "\n\nResource Type to assign : %x\n", Index
));
406 DEBUG ((EFI_D_INFO
, " Length to allocate: %x\n", RootBridgeInstance
->ResAllocNode
[Index
].Length
));
407 DEBUG ((EFI_D_INFO
, " Aligment: %x\n", Alignment
));
411 if (RootBridgeInstance
->Aperture
.IoBase
< RootBridgeInstance
->Aperture
.IoLimit
) {
413 // It is impossible for 0xFFFF Alignment for IO16
415 if (BitsOfAlignment
>= 16)
418 BaseAddress
= RootBridgeInstance
->Aperture
.IoBase
;
421 // Have to make sure Aligment is handled seeing we are doing direct address allocation
423 if ((BaseAddress
& ~(Alignment
)) != BaseAddress
)
424 BaseAddress
= ((BaseAddress
+ Alignment
) & ~(Alignment
));
426 while((BaseAddress
+ AddrLen
) <= RootBridgeInstance
->Aperture
.IoLimit
+ 1) {
428 Status
= gDS
->AllocateIoSpace ( EfiGcdAllocateAddress
, EfiGcdIoTypeIo
, BitsOfAlignment
,
429 AddrLen
, &BaseAddress
, mDriverImageHandle
, NULL
);
431 if (!EFI_ERROR (Status
)) {
432 RootBridgeInstance
->ResAllocNode
[Index
].Base
= (UINT64
) BaseAddress
;
433 RootBridgeInstance
->ResAllocNode
[Index
].Status
= ResAllocated
;
437 BaseAddress
+= (Alignment
+ 1);
443 if (RootBridgeInstance
->ResAllocNode
[Index
].Status
!= ResAllocated
) {
445 // No Room at the Inn for this resources request
447 ReturnStatus
= EFI_OUT_OF_RESOURCES
;
453 if (RootBridgeInstance
->Aperture
.Mem32Base
< RootBridgeInstance
->Aperture
.Mem32Limit
) {
455 BaseAddress
= RootBridgeInstance
->Aperture
.Mem32Base
;
457 // Have to make sure Aligment is handled seeing we are doing direct address allocation
459 if ((BaseAddress
& ~(Alignment
)) != BaseAddress
)
460 BaseAddress
= ((BaseAddress
+ Alignment
) & ~(Alignment
));
462 while((BaseAddress
+ AddrLen
) <= RootBridgeInstance
->Aperture
.Mem32Limit
+ 1) {
464 Status
= gDS
->AllocateMemorySpace ( EfiGcdAllocateAddress
, EfiGcdMemoryTypeMemoryMappedIo
,
465 BitsOfAlignment
, AddrLen
, &BaseAddress
, mDriverImageHandle
, NULL
);
467 if (!EFI_ERROR (Status
)) {
468 RootBridgeInstance
->ResAllocNode
[Index
].Base
= (UINT64
) BaseAddress
;
469 RootBridgeInstance
->ResAllocNode
[Index
].Status
= ResAllocated
;
473 BaseAddress
+= (Alignment
+ 1);
478 if (RootBridgeInstance
->ResAllocNode
[Index
].Status
!= ResAllocated
) {
480 // No Room at the Inn for this resources request
482 ReturnStatus
= EFI_OUT_OF_RESOURCES
;
489 if (RootBridgeInstance
->Aperture
.Mem32Base
< RootBridgeInstance
->Aperture
.Mem32Limit
) {
491 BaseAddress
= RootBridgeInstance
->Aperture
.Mem32Limit
+ 1;
492 BaseAddress
-= AddrLen
;
495 // Have to make sure Aligment is handled seeing we are doing direct address allocation
497 if ((BaseAddress
& ~(Alignment
)) != BaseAddress
)
498 BaseAddress
= ((BaseAddress
) & ~(Alignment
));
500 while(RootBridgeInstance
->Aperture
.Mem32Base
<= BaseAddress
) {
502 DEBUG ((EFI_D_INFO
, " Attempting %x allocation at 0x%lx .....", Index
, BaseAddress
));
503 Status
= gDS
->AllocateMemorySpace ( EfiGcdAllocateAddress
, EfiGcdMemoryTypeMemoryMappedIo
,
504 BitsOfAlignment
, AddrLen
, &BaseAddress
, mDriverImageHandle
, NULL
);
506 if (!EFI_ERROR (Status
)) {
507 RootBridgeInstance
->ResAllocNode
[Index
].Base
= (UINT64
) BaseAddress
;
508 RootBridgeInstance
->ResAllocNode
[Index
].Status
= ResAllocated
;
509 DEBUG ((EFI_D_INFO
, "... Passed!!\n"));
510 goto TypePMem32Found
;
512 DEBUG ((EFI_D_INFO
, "... Failed!!\n"));
513 BaseAddress
-= (Alignment
+ 1);
518 if (RootBridgeInstance
->ResAllocNode
[Index
].Status
!= ResAllocated
) {
520 // No Room at the Inn for this resources request
522 ReturnStatus
= EFI_OUT_OF_RESOURCES
;
529 if (RootBridgeInstance
->ResAllocNode
[Index
].Status
!= ResAllocated
) {
531 // If 64-bit resourcing is not available, then try as PMem32
533 goto StartTypePMem32
;
540 } // End switch (Index)
542 DEBUG ((EFI_D_INFO
, "Resource Type Assigned: %x\n", Index
));
543 if (RootBridgeInstance
->ResAllocNode
[Index
].Status
== ResAllocated
) {
544 DEBUG ((EFI_D_INFO
, " Base Address Assigned: %x\n", RootBridgeInstance
->ResAllocNode
[Index
].Base
));
545 DEBUG ((EFI_D_INFO
, " Length Assigned: %x\n", RootBridgeInstance
->ResAllocNode
[Index
].Length
));
547 DEBUG ((DEBUG_ERROR
, " Resource Allocation failed! There was no room at the inn\n"));
553 List
= List
->ForwardLink
;
556 if (ReturnStatus
== EFI_OUT_OF_RESOURCES
) {
557 DEBUG ((DEBUG_ERROR
, "Resource allocation Failed. Continue booting the system.\n"));
561 // Set resource to zero for nodes where allocation fails
563 List
= HostBridgeInstance
->Head
.ForwardLink
;
564 while (List
!= &HostBridgeInstance
->Head
) {
565 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
566 for (Index
= TypeIo
; Index
< TypeBus
; Index
++) {
567 if (RootBridgeInstance
->ResAllocNode
[Index
].Status
!= ResAllocated
) {
568 RootBridgeInstance
->ResAllocNode
[Index
].Length
= 0;
571 List
= List
->ForwardLink
;
575 return EFI_NOT_READY
;
578 // HostBridgeInstance->CanRestarted = FALSE;
582 case EfiPciHostBridgeSetResources
:
584 // HostBridgeInstance->CanRestarted = FALSE;
588 case EfiPciHostBridgeFreeResources
:
590 // HostBridgeInstance->CanRestarted = FALSE;
592 ReturnStatus
= EFI_SUCCESS
;
593 List
= HostBridgeInstance
->Head
.ForwardLink
;
594 while (List
!= &HostBridgeInstance
->Head
) {
595 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
596 for (Index
= TypeIo
; Index
< TypeBus
; Index
++) {
597 if (RootBridgeInstance
->ResAllocNode
[Index
].Status
== ResAllocated
) {
598 AddrLen
= RootBridgeInstance
->ResAllocNode
[Index
].Length
;
599 BaseAddress
= (EFI_PHYSICAL_ADDRESS
) RootBridgeInstance
->ResAllocNode
[Index
].Base
;
602 Status
= gDS
->FreeIoSpace (BaseAddress
, AddrLen
);
603 if (EFI_ERROR (Status
)) {
604 ReturnStatus
= Status
;
609 Status
= gDS
->FreeMemorySpace (BaseAddress
, AddrLen
);
610 if (EFI_ERROR (Status
)) {
611 ReturnStatus
= Status
;
622 Status
= gDS
->FreeMemorySpace (BaseAddress
, AddrLen
);
623 if (EFI_ERROR (Status
)) {
624 ReturnStatus
= Status
;
630 } // end switch (Index)
632 RootBridgeInstance
->ResAllocNode
[Index
].Type
= Index
;
633 RootBridgeInstance
->ResAllocNode
[Index
].Base
= 0;
634 RootBridgeInstance
->ResAllocNode
[Index
].Length
= 0;
635 RootBridgeInstance
->ResAllocNode
[Index
].Status
= ResNone
;
639 List
= List
->ForwardLink
;
642 HostBridgeInstance
->ResourceSubmited
= FALSE
;
643 HostBridgeInstance
->CanRestarted
= TRUE
;
647 case EfiPciHostBridgeEndResourceAllocation
:
649 // Resource enumeration is done. Perform any activities that
650 // must wait until that time.
655 return EFI_INVALID_PARAMETER
;
656 } // End switch (Phase)
664 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
665 IN OUT EFI_HANDLE
*RootBridgeHandle
670 Return the device handle of the next PCI root bridge that is associated with
675 This - The EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ PROTOCOL instance.
676 RootBridgeHandle - Returns the device handle of the next PCI Root Bridge.
677 On input, it holds the RootBridgeHandle returned by the most
678 recent call to GetNextRootBridge().The handle for the first
679 PCI Root Bridge is returned if RootBridgeHandle is NULL on input.
683 EFI_SUCCESS - Succeed.
684 EFI_NOT_FOUND - Next PCI root bridge not found.
685 EFI_INVALID_PARAMETER - Wrong parameter passed in.
689 BOOLEAN NoRootBridge
;
690 EFI_LIST_ENTRY
*List
;
691 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
692 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
695 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
696 List
= HostBridgeInstance
->Head
.ForwardLink
;
698 while (List
!= &HostBridgeInstance
->Head
) {
699 NoRootBridge
= FALSE
;
700 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
701 if (*RootBridgeHandle
== NULL
) {
703 // Return the first Root Bridge Handle of the Host Bridge
705 *RootBridgeHandle
= RootBridgeInstance
->Handle
;
708 if (*RootBridgeHandle
== RootBridgeInstance
->Handle
) {
712 List
= List
->ForwardLink
;
713 if (List
!= &HostBridgeInstance
->Head
) {
714 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
715 *RootBridgeHandle
= RootBridgeInstance
->Handle
;
718 return EFI_NOT_FOUND
;
723 List
= List
->ForwardLink
;
730 return EFI_NOT_FOUND
;
732 return EFI_INVALID_PARAMETER
;
739 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
740 IN EFI_HANDLE RootBridgeHandle
,
741 OUT UINT64
*Attributes
746 Returns the attributes of a PCI Root Bridge.
750 This - The EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ PROTOCOL instance.
751 RootBridgeHandle - The device handle of the PCI Root Bridge
752 that the caller is interested in.
753 Attributes - The pointer to attributes of the PCI Root Bridge.
757 EFI_SUCCESS - Succeed.
758 EFI_INVALID_PARAMETER - Attributes parameter passed in is NULL or
759 RootBridgeHandle is not an EFI_HANDLE
760 that was returned on a previous call to
765 EFI_LIST_ENTRY
*List
;
766 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
767 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
769 if (Attributes
== NULL
) {
770 return EFI_INVALID_PARAMETER
;
773 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
774 List
= HostBridgeInstance
->Head
.ForwardLink
;
776 while (List
!= &HostBridgeInstance
->Head
) {
777 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
778 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
779 *Attributes
= RootBridgeInstance
->RootBridgeAllocAttrib
;
783 List
= List
->ForwardLink
;
786 // RootBridgeHandle is not an EFI_HANDLE
787 // that was returned on a previous call to GetNextRootBridge()
789 return EFI_INVALID_PARAMETER
;
794 StartBusEnumeration (
795 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
796 IN EFI_HANDLE RootBridgeHandle
,
797 OUT VOID
**Configuration
802 This is the request from the PCI enumerator to set up
803 the specified PCI Root Bridge for bus enumeration process.
807 This - The EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ PROTOCOL instance.
808 RootBridgeHandle - The PCI Root Bridge to be set up.
809 Configuration - Pointer to the pointer to the PCI bus resource descriptor.
813 EFI_SUCCESS - Succeed.
814 EFI_OUT_OF_RESOURCES - Not enough pool to be allocated.
815 EFI_INVALID_PARAMETER - RootBridgeHandle is not a valid handle.
819 EFI_LIST_ENTRY
*List
;
820 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
821 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
829 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
830 List
= HostBridgeInstance
->Head
.ForwardLink
;
832 while (List
!= &HostBridgeInstance
->Head
) {
833 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
834 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
836 // Set up the Root Bridge for Bus Enumeration
838 BusStart
= RootBridgeInstance
->Aperture
.BusBase
;
839 BusEnd
= RootBridgeInstance
->Aperture
.BusLimit
;
840 BusReserve
= RootBridgeInstance
->Aperture
.BusReserve
;
842 // Program the Hardware(if needed) if error return EFI_DEVICE_ERROR
844 Status
= gBS
->AllocatePool (
846 sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) + sizeof (EFI_ACPI_END_TAG_DESCRIPTOR
),
849 if (EFI_ERROR (Status
)) {
850 return EFI_OUT_OF_RESOURCES
;
853 Temp
= (UINT8
*) Buffer
;
855 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Temp
)->Desc
= ACPI_ADDRESS_SPACE_DESCRIPTOR
;
856 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Temp
)->Len
= 0x2B;
857 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Temp
)->ResType
= ACPI_ADDRESS_SPACE_TYPE_BUS
;
858 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Temp
)->GenFlag
= 0;
859 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Temp
)->SpecificFlag
= 0;
860 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Temp
)->AddrSpaceGranularity
= 0;
861 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Temp
)->AddrRangeMin
= BusStart
;
862 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Temp
)->AddrRangeMax
= BusReserve
;
863 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Temp
)->AddrTranslationOffset
= 0;
864 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Temp
)->AddrLen
= BusEnd
- BusStart
+ 1;
866 Temp
= Temp
+ sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
);
867 ((EFI_ACPI_END_TAG_DESCRIPTOR
*) Temp
)->Desc
= ACPI_END_TAG_DESCRIPTOR
;
868 ((EFI_ACPI_END_TAG_DESCRIPTOR
*) Temp
)->Checksum
= 0x0;
870 *Configuration
= Buffer
;
874 List
= List
->ForwardLink
;
877 return EFI_INVALID_PARAMETER
;
883 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
884 IN EFI_HANDLE RootBridgeHandle
,
885 IN VOID
*Configuration
890 This function programs the PCI Root Bridge hardware so that
891 it decodes the specified PCI bus range.
895 This - The EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ PROTOCOL instance.
896 RootBridgeHandle - The PCI Root Bridge whose bus range is to be programmed.
897 Configuration - The pointer to the PCI bus resource descriptor.
901 EFI_SUCCESS - Succeed.
902 EFI_INVALID_PARAMETER - Wrong parameters passed in.
906 EFI_LIST_ENTRY
*List
;
907 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
908 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
914 if (Configuration
== NULL
) {
915 return EFI_INVALID_PARAMETER
;
921 // Check the Configuration is valid
923 if (*Ptr
!= ACPI_ADDRESS_SPACE_DESCRIPTOR
) {
924 return EFI_INVALID_PARAMETER
;
927 if (((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Ptr
)->ResType
!= ACPI_ADDRESS_SPACE_TYPE_BUS
) {
928 return EFI_INVALID_PARAMETER
;
931 Ptr
+= sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
);
932 if (*Ptr
!= ACPI_END_TAG_DESCRIPTOR
) {
933 return EFI_INVALID_PARAMETER
;
936 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
937 List
= HostBridgeInstance
->Head
.ForwardLink
;
941 while (List
!= &HostBridgeInstance
->Head
) {
942 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
943 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
944 BusStart
= (UINTN
) ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Ptr
)->AddrRangeMin
;
945 BusLen
= (UINTN
) ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Ptr
)->AddrLen
;
946 BusEnd
= BusStart
+ BusLen
- 1;
948 if (BusStart
> BusEnd
) {
949 return EFI_INVALID_PARAMETER
;
952 if ((BusStart
< RootBridgeInstance
->Aperture
.BusBase
) || (BusEnd
> RootBridgeInstance
->Aperture
.BusLimit
)) {
953 return EFI_INVALID_PARAMETER
;
956 // Update the Bus Range
958 RootBridgeInstance
->ResAllocNode
[TypeBus
].Base
= BusStart
;
959 RootBridgeInstance
->ResAllocNode
[TypeBus
].Length
= BusLen
;
960 RootBridgeInstance
->ResAllocNode
[TypeBus
].Status
= ResAllocated
;
961 RootBridgeInstance
->BusScanCount
++;
962 if (RootBridgeInstance
->BusScanCount
> 0) {
964 // Only care about the 2nd PCI bus scanning
966 RootBridgeInstance
->BusNumberAssigned
= TRUE
;
972 List
= List
->ForwardLink
;
975 return EFI_INVALID_PARAMETER
;
981 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
982 IN EFI_HANDLE RootBridgeHandle
,
983 IN VOID
*Configuration
989 Submits the I/O and memory resource requirements for the specified PCI Root Bridge.
992 This - The EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ PROTOCOL instance.
993 RootBridgeHandle - The PCI Root Bridge whose I/O and memory resource requirements.
995 Configuration - The pointer to the PCI I/O and PCI memory resource descriptor.
999 EFI_SUCCESS - Succeed.
1000 EFI_INVALID_PARAMETER - Wrong parameters passed in.
1004 EFI_LIST_ENTRY
*List
;
1005 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
1006 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
1008 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*ptr
;
1014 // Check the input parameter: Configuration
1016 if (Configuration
== NULL
) {
1017 return EFI_INVALID_PARAMETER
;
1020 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
1021 List
= HostBridgeInstance
->Head
.ForwardLink
;
1023 Temp
= (UINT8
*) Configuration
;
1024 while (List
!= &HostBridgeInstance
->Head
) {
1025 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
1026 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
1028 // Check the resource descriptors.
1029 // If the Configuration includes one or more invalid resource descriptors, all the resource
1030 // descriptors are ignored and the function returns EFI_INVALID_PARAMETER.
1032 while (*Temp
== ACPI_ADDRESS_SPACE_DESCRIPTOR
) {
1033 ptr
= (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Temp
;
1034 DEBUG ((EFI_D_INFO
, " ptr->ResType:%x \n",ptr
->ResType
));
1035 DEBUG ((EFI_D_INFO
, " ptr->AddrLen:0x%lx AddrRangeMin:0x%lx AddrRangeMax:0x%lx\n\n",ptr
->AddrLen
,ptr
->AddrRangeMin
,ptr
->AddrRangeMax
));
1037 switch (ptr
->ResType
) {
1038 case ACPI_ADDRESS_SPACE_TYPE_MEM
:
1039 if (ptr
->AddrSpaceGranularity
!= 32 && ptr
->AddrSpaceGranularity
!= 64) {
1040 return EFI_INVALID_PARAMETER
;
1042 if (ptr
->AddrSpaceGranularity
== 32 && ptr
->AddrLen
> 0xffffffff) {
1043 return EFI_INVALID_PARAMETER
;
1046 // If the PCI root bridge does not support separate windows for nonprefetchable and
1047 // prefetchable memory, then the PCI bus driver needs to include requests for
1048 // prefetchable memory in the nonprefetchable memory pool.
1050 if ((RootBridgeInstance
->RootBridgeAllocAttrib
& EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM
) != 0 &&
1051 ((ptr
->SpecificFlag
& (BIT2
| BIT1
)) != 0)) {
1052 return EFI_INVALID_PARAMETER
;
1054 case ACPI_ADDRESS_SPACE_TYPE_IO
:
1056 // Check aligment, it should be of the form 2^n-1
1058 Value
= Power2MaxMemory (ptr
->AddrRangeMax
+ 1);
1059 if (Value
!= (ptr
->AddrRangeMax
+ 1)) {
1061 return EFI_INVALID_PARAMETER
;
1064 case ACPI_ADDRESS_SPACE_TYPE_BUS
:
1066 return EFI_INVALID_PARAMETER
;
1068 Temp
+= sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) ;
1070 if (*Temp
!= ACPI_END_TAG_DESCRIPTOR
) {
1071 return EFI_INVALID_PARAMETER
;
1074 Temp
= (UINT8
*) Configuration
;
1075 while (*Temp
== ACPI_ADDRESS_SPACE_DESCRIPTOR
) {
1076 ptr
= (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Temp
;
1078 switch (ptr
->ResType
) {
1079 case ACPI_ADDRESS_SPACE_TYPE_MEM
:
1080 AddrLen
= (UINT64
) ptr
->AddrLen
;
1081 Alignment
= (UINT64
) ptr
->AddrRangeMax
;
1082 if (ptr
->AddrSpaceGranularity
== 32) {
1083 if (ptr
->SpecificFlag
== 0x06) {
1087 RootBridgeInstance
->ResAllocNode
[TypePMem32
].Status
= ResSubmitted
;
1089 RootBridgeInstance
->ResAllocNode
[TypeMem32
].Length
= AddrLen
;
1090 RootBridgeInstance
->ResAllocNode
[TypeMem32
].Alignment
= Alignment
;
1091 RootBridgeInstance
->ResAllocNode
[TypeMem32
].Status
= ResRequested
;
1092 HostBridgeInstance
->ResourceSubmited
= TRUE
;
1096 if (ptr
->AddrSpaceGranularity
== 64) {
1097 if (ptr
->SpecificFlag
== 0x06) {
1098 RootBridgeInstance
->ResAllocNode
[TypePMem64
].Status
= ResSubmitted
;
1100 RootBridgeInstance
->ResAllocNode
[TypeMem64
].Length
= AddrLen
;
1101 RootBridgeInstance
->ResAllocNode
[TypeMem64
].Alignment
= Alignment
;
1102 RootBridgeInstance
->ResAllocNode
[TypeMem64
].Status
= ResSubmitted
;
1103 HostBridgeInstance
->ResourceSubmited
= TRUE
;
1108 case ACPI_ADDRESS_SPACE_TYPE_IO
:
1109 AddrLen
= (UINT64
) ptr
->AddrLen
;
1110 Alignment
= (UINT64
) ptr
->AddrRangeMax
;
1111 RootBridgeInstance
->ResAllocNode
[TypeIo
].Length
= AddrLen
;
1112 RootBridgeInstance
->ResAllocNode
[TypeIo
].Alignment
= Alignment
;
1113 RootBridgeInstance
->ResAllocNode
[TypeIo
].Status
= ResRequested
;
1114 HostBridgeInstance
->ResourceSubmited
= TRUE
;
1121 Temp
+= sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
);
1127 List
= List
->ForwardLink
;
1130 return EFI_INVALID_PARAMETER
;
1135 GetProposedResources (
1136 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
1137 IN EFI_HANDLE RootBridgeHandle
,
1138 OUT VOID
**Configuration
1142 Routine Description:
1143 This function returns the proposed resource settings for the specified
1148 This - The EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ PROTOCOL instance.
1149 RootBridgeHandle - The PCI Root Bridge handle.
1150 Configuration - The pointer to the pointer to the PCI I/O
1151 and memory resource descriptor.
1155 EFI_SUCCESS - Succeed.
1156 EFI_OUT_OF_RESOURCES - Not enough pool to be allocated.
1157 EFI_INVALID_PARAMETER - RootBridgeHandle is not a valid handle.
1161 EFI_LIST_ENTRY
*List
;
1162 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
1163 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
1168 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*ptr
;
1175 // Get the Host Bridge Instance from the resource allocation protocol
1177 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
1178 List
= HostBridgeInstance
->Head
.ForwardLink
;
1181 // Enumerate the root bridges in this host bridge
1183 while (List
!= &HostBridgeInstance
->Head
) {
1184 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
1185 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
1186 for (Index
= 0; Index
< TypeBus
; Index
++) {
1187 if (RootBridgeInstance
->ResAllocNode
[Index
].Status
!= ResNone
) {
1193 Status
= gBS
->AllocatePool (
1194 EfiBootServicesData
,
1195 Number
* sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) + sizeof (EFI_ACPI_END_TAG_DESCRIPTOR
),
1199 if (EFI_ERROR (Status
)) {
1200 return EFI_OUT_OF_RESOURCES
;
1203 ZeroMem (Buffer
, sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) * Number
+ sizeof (EFI_ACPI_END_TAG_DESCRIPTOR
));
1206 ASSERT (Buffer
!= NULL
);
1208 for (Index
= 0; Index
< TypeBus
; Index
++) {
1209 if (RootBridgeInstance
->ResAllocNode
[Index
].Status
!= ResNone
) {
1210 ptr
= (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Temp
;
1211 ResStatus
= RootBridgeInstance
->ResAllocNode
[Index
].Status
;
1223 ptr
->SpecificFlag
= 0;
1224 ptr
->AddrRangeMin
= RootBridgeInstance
->ResAllocNode
[Index
].Base
;
1225 ptr
->AddrRangeMax
= 0;
1226 ptr
->AddrTranslationOffset
= (ResStatus
== ResAllocated
) ? EFI_RESOURCE_SATISFIED
: EFI_RESOURCE_LESS
;
1227 ptr
->AddrLen
= RootBridgeInstance
->ResAllocNode
[Index
].Length
;
1238 ptr
->SpecificFlag
= 0;
1239 ptr
->AddrSpaceGranularity
= 32;
1240 ptr
->AddrRangeMin
= RootBridgeInstance
->ResAllocNode
[Index
].Base
;
1241 ptr
->AddrRangeMax
= 0;
1242 ptr
->AddrTranslationOffset
= (ResStatus
== ResAllocated
) ? EFI_RESOURCE_SATISFIED
: EFI_RESOURCE_LESS
;
1243 ptr
->AddrLen
= RootBridgeInstance
->ResAllocNode
[Index
].Length
;
1248 // Prefetch memory 32
1254 ptr
->SpecificFlag
= 6;
1255 ptr
->AddrSpaceGranularity
= 32;
1256 ptr
->AddrRangeMin
= 0;
1257 ptr
->AddrRangeMax
= 0;
1258 ptr
->AddrTranslationOffset
= EFI_RESOURCE_NONEXISTENT
;
1270 ptr
->SpecificFlag
= 0;
1271 ptr
->AddrSpaceGranularity
= 64;
1272 ptr
->AddrRangeMin
= RootBridgeInstance
->ResAllocNode
[Index
].Base
;
1273 ptr
->AddrRangeMax
= 0;
1274 ptr
->AddrTranslationOffset
= (ResStatus
== ResAllocated
) ? EFI_RESOURCE_SATISFIED
: EFI_RESOURCE_LESS
;
1275 ptr
->AddrLen
= RootBridgeInstance
->ResAllocNode
[Index
].Length
;
1280 // Prefetch memory 64
1286 ptr
->SpecificFlag
= 6;
1287 ptr
->AddrSpaceGranularity
= 64;
1288 ptr
->AddrRangeMin
= 0;
1289 ptr
->AddrRangeMax
= 0;
1290 ptr
->AddrTranslationOffset
= EFI_RESOURCE_NONEXISTENT
;
1295 Temp
+= sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
);
1299 ((EFI_ACPI_END_TAG_DESCRIPTOR
*) Temp
)->Desc
= 0x79;
1300 ((EFI_ACPI_END_TAG_DESCRIPTOR
*) Temp
)->Checksum
= 0x0;
1302 *Configuration
= Buffer
;
1307 List
= List
->ForwardLink
;
1310 return EFI_INVALID_PARAMETER
;
1315 PreprocessController (
1316 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
*This
,
1317 IN EFI_HANDLE RootBridgeHandle
,
1318 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS PciAddress
,
1319 IN EFI_PCI_CONTROLLER_RESOURCE_ALLOCATION_PHASE Phase
1323 Routine Description:
1324 This function is called for all the PCI controllers that the PCI
1325 bus driver finds. Can be used to Preprogram the controller.
1329 This - The EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ PROTOCOL instance.
1330 RootBridgeHandle - The PCI Root Bridge handle.
1331 PciAddress - Address of the controller on the PCI bus.
1332 Phase - The Phase during resource allocation.
1336 EFI_SUCCESS - Succeed.
1337 EFI_INVALID_PARAMETER - RootBridgeHandle is not a valid handle.
1341 BOOLEAN RootBridgeFound
;
1342 EFI_LIST_ENTRY
*List
;
1343 PCI_HOST_BRIDGE_INSTANCE
*HostBridgeInstance
;
1344 PCI_ROOT_BRIDGE_INSTANCE
*RootBridgeInstance
;
1346 if (RootBridgeHandle
== NULL
) {
1347 return EFI_INVALID_PARAMETER
;
1350 RootBridgeFound
= FALSE
;
1351 HostBridgeInstance
= INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This
);
1352 List
= HostBridgeInstance
->Head
.ForwardLink
;
1354 while (List
!= &HostBridgeInstance
->Head
) {
1355 RootBridgeInstance
= DRIVER_INSTANCE_FROM_LIST_ENTRY (List
);
1357 if (RootBridgeHandle
== RootBridgeInstance
->Handle
) {
1358 RootBridgeFound
= TRUE
;
1364 List
= List
->ForwardLink
;
1367 if (RootBridgeFound
== FALSE
) {
1368 return EFI_INVALID_PARAMETER
;
1376 IN UINT64 MemoryLength
1380 Routine Description:
1382 Calculate maximum memory length that can be fit to a mtrr.
1386 MemoryLength - Input memory length.
1390 Returned Maximum length.
1396 if (RShiftU64 (MemoryLength
, 32)) {
1397 Result
= LShiftU64 ((UINT64
) GetPowerOfTwo64 ((UINT32
) RShiftU64 (MemoryLength
, 32)), 32);
1399 Result
= (UINT64
) GetPowerOfTwo64 ((UINT32
) MemoryLength
);