/** @file
PCI resouces support functions implemntation for PCI Bus module.
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "PciBus.h"
//
// The default policy for the PCI bus driver is NOT to reserve I/O ranges for both ISA aliases and VGA aliases.
//
/**
The function is used to skip VGA range.
@param Start Returned start address including VGA range.
@param Length The length of VGA range.
**/
)
{
//
// For legacy VGA, bit 10 to bit 15 is not decoded
//
Mask = 0x3FF;
if (LimitOffset >= VGABASE1) {
}
}
/**
This function is used to skip ISA aliasing aperture.
@param Start Returned start address including ISA aliasing aperture.
@param Length The length of ISA aliasing aperture.
**/
)
{
//
// For legacy ISA, bit 10 to bit 15 is not decoded
//
Mask = 0x3FF;
if (LimitOffset >= ISABASE) {
}
}
/**
This function inserts a resource node into the resource list.
The resource list is sorted in descend order.
@param Bridge PCI resource node for bridge.
@param ResNode Resource node want to be inserted.
**/
)
{
break;
break;
}
}
}
}
/**
This routine is used to merge two different resource trees in need of
resoure degradation.
For example, if an upstream PPB doesn't support,
prefetchable memory decoding, the PCI bus driver will choose to call this function
to merge prefectchable memory resource list into normal memory list.
If the TypeMerge is TRUE, Res resource type is changed to the type of destination resource
type.
If Dst is NULL or Res is NULL, ASSERT ().
@param Dst Point to destination resource tree.
@param Res Point to source resource tree.
@param TypeMerge If the TypeMerge is TRUE, Res resource type is changed to the type of
destination resource type.
**/
)
{
if (TypeMerge) {
}
}
}
/**
This function is used to calculate the IO16 aperture
for a bridge.
@param Bridge PCI resource node for bridge.
**/
)
{
if (!mPolicyDetermined) {
//
// Check PciPlatform policy
//
PciPolicy = 0;
if (gPciPlatformProtocol != NULL) {
);
}
);
}
if ((PciPolicy & EFI_RESERVE_ISA_IO_ALIAS) != 0) {
}
if ((PciPolicy & EFI_RESERVE_VGA_IO_ALIAS) != 0) {
}
}
}
Aperture = 0;
return ;
}
//
// Assume the bridge is aligned
//
//
// Consider the aperture alignment
//
if (Offset != 0) {
}
//
// IsaEnable and VGAEnable can not be implemented now.
// If both of them are enabled, then the IO resource would
// become too limited to meet the requirement of most of devices.
//
if (mReserveIsaAliases || mReserveVgaAliases) {
//
//
if (mReserveIsaAliases) {
&Aperture,
);
if (Offset != 0) {
}
} else if (mReserveVgaAliases) {
&Aperture,
);
if (Offset != 0) {
}
}
}
}
//
// Increment aperture by the length of node
//
}
//
// At last, adjust the aperture with the bridge's
// alignment
//
if (Offset != 0) {
}
//
// At last, adjust the bridge's alignment to the first child's alignment
// if the bridge has at least one child
//
}
}
}
/**
This function is used to calculate the resource aperture
for a given bridge device.
@param Bridge PCI resouce node for given bridge device.
**/
)
{
Aperture = 0;
return ;
}
return ;
}
//
// Assume the bridge is aligned
//
//
// Apply padding resource if available
//
if (Offset != 0) {
}
//
// Recode current aperture as a offset
// this offset will be used in future real allocation
//
//
// Increment aperture by the length of node
//
//
// Consider the aperture alignment
//
}
//
// At last, adjust the aperture with the bridge's
// alignment
//
if (Offset != 0) {
}
//
// If the bridge has already padded the resource and the
// amount of padded resource is larger, then keep the
// padded resource
//
}
//
// At last, adjust the bridge's alignment to the first child's alignment
// if the bridge has at least one child
//
}
}
}
/**
@param PciDev Pci device instance.
@param IoNode Resource info node for IO .
@param Mem32Node Resource info node for 32-bit memory.
@param PMem32Node Resource info node for 32-bit Prefetchable Memory.
@param Mem64Node Resource info node for 64-bit memory.
@param PMem64Node Resource info node for 64-bit Prefetchable Memory.
**/
)
{
case PciBarTypeMem32:
);
);
break;
case PciBarTypeMem64:
);
);
break;
case PciBarTypePMem64:
);
);
break;
case PciBarTypePMem32:
);
);
break;
case PciBarTypeIo16:
case PciBarTypeIo32:
);
);
break;
case PciBarTypeUnknown:
break;
default:
break;
}
}
//
// Add VF resource
//
case PciBarTypeMem32:
);
);
break;
case PciBarTypeMem64:
);
);
break;
case PciBarTypePMem64:
);
);
break;
case PciBarTypePMem32:
);
);
break;
case PciBarTypeIo16:
case PciBarTypeIo32:
break;
case PciBarTypeUnknown:
break;
default:
break;
}
}
// If there is no resource requested from this device,
// then we indicate this device has been allocated naturally.
//
if (!ResourceRequested) {
}
}
/**
This function is used to create a resource node.
@param PciDev Pci device instance.
@param Alignment Alignment of resource.
@param Bar Bar index.
@param ResUsage Resource usage.
@return PCI resource node created for given PCI device.
NULL means PCI resource node is not created.
**/
)
{
return NULL;
}
return Node;
}
/**
This function is used to create a IOV VF resource node.
@param PciDev Pci device instance.
@param Alignment Alignment of resource.
@param Bar Bar index.
@param ResUsage Resource usage.
@return PCI resource node created for given VF PCI device.
NULL means PCI resource node is not created.
**/
)
{
return Node;
}
return Node;
}
/**
This function is used to extract resource request from
device node list.
@param Bridge Pci device instance.
@param IoNode Resource info node for IO.
@param Mem32Node Resource info node for 32-bit memory.
@param PMem32Node Resource info node for 32-bit Prefetchable Memory.
@param Mem64Node Resource info node for 64-bit memory.
@param PMem64Node Resource info node for 64-bit Prefetchable Memory.
**/
)
{
//
// Create resource nodes for this device by scanning the
// Bar array in the device private data
// If the upstream bridge doesn't support this device,
// no any resource node will be created for this device
//
Temp,
);
//
// If the device has children, create a bridge resource node for this PPB
// Note: For PPB, memory aperture is aligned with 1MB and IO aperture
// is aligned with 4KB (smaller alignments may be supported).
//
Temp,
0,
);
Temp,
0,
0xFFFFF,
);
Temp,
0,
0xFFFFF,
);
Temp,
0,
0xFFFFF,
);
Temp,
0,
0xFFFFF,
);
//
// Recursively create resouce map on this bridge
//
Temp,
);
if (ResourceRequestExisted (IoBridge)) {
);
} else {
}
//
// If there is node under this resource bridge,
// then calculate bridge's aperture of this type
// and insert it into the respective resource tree.
// If no, delete this resource bridge
//
if (ResourceRequestExisted (Mem32Bridge)) {
);
} else {
Mem32Bridge = NULL;
}
//
// If there is node under this resource bridge,
// then calculate bridge's aperture of this type
// and insert it into the respective resource tree.
// If no, delete this resource bridge
//
if (ResourceRequestExisted (PMem32Bridge)) {
);
} else {
PMem32Bridge = NULL;
}
//
// If there is node under this resource bridge,
// then calculate bridge's aperture of this type
// and insert it into the respective resource tree.
// If no, delete this resource bridge
//
if (ResourceRequestExisted (Mem64Bridge)) {
);
} else {
Mem64Bridge = NULL;
}
//
// If there is node under this resource bridge,
// then calculate bridge's aperture of this type
// and insert it into the respective resource tree.
// If no, delete this resource bridge
//
if (ResourceRequestExisted (PMem64Bridge)) {
);
} else {
PMem64Bridge = NULL;
}
}
//
// If it is P2C, apply hard coded resource padding
//
Temp,
);
}
}
//
// To do some platform specific resource padding ...
//
);
//
// Degrade resource if necessary
//
);
//
// Calculate resource aperture for this bridge device
//
}
/**
This function is used to do the resource padding for a specific platform.
@param PciDev Pci device instance.
@param IoNode Resource info node for IO.
@param Mem32Node Resource info node for 32-bit memory.
@param PMem32Node Resource info node for 32-bit Prefetchable Memory.
@param Mem64Node Resource info node for 64-bit memory.
@param PMem64Node Resource info node for 64-bit Prefetchable Memory.
**/
)
{
//
// Create padding resource node
//
);
}
}
/**
This function is used to degrade resource if the upstream bridge
doesn't support certain resource. Degradation path is
PMEM64 -> MEM64 -> MEM32
PMEM64 -> PMEM32 -> MEM32
IO32 -> IO16.
@param Bridge Pci device instance.
@param Mem32Node Resource info node for 32-bit memory.
@param PMem32Node Resource info node for 32-bit Prefetchable Memory.
@param Mem64Node Resource info node for 64-bit memory.
@param PMem64Node Resource info node for 64-bit Prefetchable Memory.
**/
)
{
//
// requests in case that if a legacy option ROM image can not access 64-bit resources.
//
}
}
}
}
}
}
}
}
//
// If firmware is in 32-bit mode,
//
if (sizeof (UINTN) <= 4) {
);
);
} else {
//
// if the bridge does not support MEM64, degrade MEM64 to MEM32
//
);
}
//
// if the bridge does not support PMEM64, degrade PMEM64 to PMEM32
//
);
}
//
// if both PMEM64 and PMEM32 requests from child devices, which can not be satisfied
// by a P2P bridge simultaneously, keep PMEM64 and degrade PMEM32 to MEM32.
//
);
}
}
//
// If bridge doesn't support Pmem32
// degrade it to mem32
//
);
}
//
// if root bridge supports combined Pmem Mem decoding
// merge these two type of resource
//
);
//
// No need to check if to degrade MEM64 after merge, because
// if there are PMEM64 still here, 64-bit decode should be supported
// by the root bride.
//
);
}
}
/**
Test whether bridge device support decode resource.
@param Bridge Bridge device instance.
@param Decode Decode type according to resource type.
@return TRUE The bridge device support decode resource.
@return FALSE The bridge device don't support decode resource.
**/
)
{
return TRUE;
}
return FALSE;
}
/**
This function is used to program the resource allocated
for each resource node under specified bridge.
@param Base Base address of resource to be progammed.
@param Bridge PCI resource node for the bridge device.
@retval EFI_SUCCESS Successfully to program all resouces
on given PCI bridge device.
@retval EFI_OUT_OF_RESOURCES Base is all one.
**/
)
{
return EFI_OUT_OF_RESOURCES;
}
//
// Program the PCI Card Bus device
//
} else {
//
// Program the PCI device BAR
//
}
} else {
//
// Program the PCI devices under this bridge
//
return Status;
}
}
}
return EFI_SUCCESS;
}
/**
Program Bar register for PCI device.
@param Base Base address for PCI device resource to be progammed.
@param Node Point to resoure node structure.
**/
)
{
//
// Check VF BAR
//
return;
}
Address = 0;
//
// Indicate pci bus driver has allocated
// resource for this device
// It might be a temporary solution here since
// pci device could have multiple bar
//
case PciBarTypeIo16:
case PciBarTypeIo32:
case PciBarTypeMem32:
case PciBarTypePMem32:
1,
);
break;
case PciBarTypeMem64:
case PciBarTypePMem64:
1,
);
1,
);
break;
default:
break;
}
}
/**
Program IOV VF Bar register for PCI device.
@param Base Base address for PCI device resource to be progammed.
@param Node Point to resoure node structure.
**/
)
{
Address = 0;
//
// Indicate pci bus driver has allocated
// resource for this device
// It might be a temporary solution here since
// pci device could have multiple bar
//
case PciBarTypeMem32:
case PciBarTypePMem32:
1,
);
break;
case PciBarTypeMem64:
case PciBarTypePMem64:
1,
);
1,
);
break;
case PciBarTypeIo16:
case PciBarTypeIo32:
break;
default:
break;
}
return EFI_SUCCESS;
}
/**
Program PCI-PCI bridge apperture.
@param Base Base address for resource.
@param Node Point to resoure node structure.
**/
)
{
Address = 0;
//
// If no device resource of this PPB, return anyway
// Apperture is set default in the initialization code
//
//
// For padding resource node, just ignore when programming
//
return ;
}
//
// Indicate the PPB resource has been allocated
//
case PPB_BAR_0:
case PPB_BAR_1:
1,
);
break;
case PPB_IO_RANGE:
0x1C,
1,
);
Address32 >>= 8;
0x30,
1,
);
0x1D,
1,
);
Address32 >>= 8;
0x32,
1,
);
break;
case PPB_MEM32_RANGE:
0x20,
1,
);
0x22,
1,
);
break;
case PPB_PMEM32_RANGE:
case PPB_PMEM64_RANGE:
0x24,
1,
);
0x26,
1,
);
0x28,
1,
);
0x2C,
1,
);
break;
default:
break;
}
}
/**
Program parent bridge for Option Rom.
@param PciDevice Pci deivce instance.
@param OptionRomBase Base address for Optiona Rom.
@param Enable Enable or disable PCI memory.
**/
)
{
//
// For root bridge, just return.
//
break;
}
//
// Program PPB to only open a single <= 16MB apperture
//
if (Enable) {
} else {
}
}
}
/**
Test whether resource exists for a bridge.
@param Bridge Point to resource node for a bridge.
@retval TRUE There is resource on the given bridge.
@retval FALSE There isn't resource on the given bridge.
**/
)
{
return TRUE;
}
}
return FALSE;
}
/**
Initialize resource pool structure.
@param ResourcePool Point to resource pool structure. This pool
is reset to all zero when returned.
@param ResourceType Type of resource.
**/
)
{
}
/**
Destory given resource tree.
@param Bridge PCI resource root node of resource tree.
**/
)
{
}
}
}
/**
Insert resource padding for P2C.
@param PciDev Pci device instance.
@param IoNode Resource info node for IO.
@param Mem32Node Resource info node for 32-bit memory.
@param PMem32Node Resource info node for 32-bit Prefetchable Memory.
@param Mem64Node Resource info node for 64-bit memory.
@param PMem64Node Resource info node for 64-bit Prefetchable Memory.
**/
)
{
//
// Bar 1 denodes memory range 0
//
0x2000000,
0x1ffffff,
1,
);
);
//
// Bar 2 denodes memory range1
//
0x2000000,
0x1ffffff,
2,
);
);
//
// Bar 3 denodes io range 0
//
0x100,
0xff,
3,
);
);
//
// Bar 4 denodes io range 0
//
0x100,
0xff,
4,
);
);
}
/**
Program PCI Card device register for given resource node.
@param Base Base address of PCI Card device to be programmed.
@param Node Given resource node.
**/
)
{
Address = 0;
//
// Indicate pci bus driver has allocated
// resource for this device
// It might be a temporary solution here since
// pci device could have multiple bar
//
case P2C_BAR_0:
1,
);
break;
case P2C_MEM_1:
1,
);
1,
);
//
// Set non-prefetchable bit
//
1,
);
1,
);
} else {
//
// Set pre-fetchable bit
//
1,
);
1,
);
}
break;
case P2C_MEM_2:
1,
);
1,
);
//
// Set non-prefetchable bit
//
1,
);
1,
);
} else {
//
// Set pre-fetchable bit
//
1,
);
1,
);
}
break;
case P2C_IO_1:
1,
);
1,
);
break;
case P2C_IO_2:
1,
);
1,
);
break;
default:
break;
}
}
/**
Create padding resource node.
@param PciDev Pci device instance.
@param IoNode Resource info node for IO.
@param Mem32Node Resource info node for 32-bit memory.
@param PMem32Node Resource info node for 32-bit Prefetchable Memory.
@param Mem64Node Resource info node for 64-bit memory.
@param PMem64Node Resource info node for 64-bit Prefetchable Memory.
**/
)
{
DummyBarIndex = 0;
);
);
}
Ptr++;
continue;
}
//
// prefechable
//
);
);
}
Ptr++;
continue;
}
//
// Non-prefechable
//
if (Ptr->SpecificFlag == 0) {
);
);
}
Ptr++;
continue;
}
}
//
// prefechable
//
);
);
}
Ptr++;
continue;
}
//
// Non-prefechable
//
if (Ptr->SpecificFlag == 0) {
);
);
}
Ptr++;
continue;
}
}
}
Ptr++;
}
}
/**
Get padding resource for PCI-PCI bridge.
@param PciIoDevice PCI-PCI bridge device instance.
@note Feature flag PcdPciBusHotplugDeviceSupport determines
whether need to pad resource for them.
**/
)
{
}
}
}