Code scrub for PCI Bus module and PciIncompatibleDeviceSupportLib module.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8662 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
vanjeff
2009-06-25 13:47:45 +00:00
parent 745ed9b412
commit 8e8227d1a3
33 changed files with 3495 additions and 4074 deletions

View File

@@ -1,31 +1,31 @@
/** @file
This module provide support function for hot plug device.
Copyright (c) 2006, Intel Corporation
All rights reserved. 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
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
PCI Hot Plug support functions implementation for PCI Bus module..
Copyright (c) 2006 - 2009, Intel Corporation
All rights reserved. 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
http://opensource.org/licenses/bsd-license.php
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"
#include "PciHotPlugSupport.h"
EFI_PCI_HOT_PLUG_INIT_PROTOCOL *gPciHotPlugInit;
EFI_HPC_LOCATION *gPciRootHpcPool;
UINTN gPciRootHpcCount;
ROOT_HPC_DATA *gPciRootHpcData;
EFI_PCI_HOT_PLUG_INIT_PROTOCOL *gPciHotPlugInit = NULL;
EFI_HPC_LOCATION *gPciRootHpcPool = NULL;
UINTN gPciRootHpcCount = 0;
ROOT_HPC_DATA *gPciRootHpcData = NULL;
/**
Init HPC private data.
@param Event event object
@param Context HPC private data.
Event notification function to set Hot Plug controller status.
@param Event The event that invoke this function.
@param Context The calling context, pointer to ROOT_HPC_DATA.
**/
VOID
EFIAPI
@@ -34,21 +34,21 @@ PciHPCInitialized (
IN VOID *Context
)
{
ROOT_HPC_DATA *HpcData;
ROOT_HPC_DATA *HpcData;
HpcData = (ROOT_HPC_DATA *) Context;
HpcData->Initialized = TRUE;
}
/**
Compare two device path
@param DevicePath1 the first device path want to be compared.
@param DevicePath2 the first device path want to be compared.
@retval TRUE equal.
@retval FALSE different.
Compare two device pathes to check if they are exactly same.
@param DevicePath1 A pointer to the first device path data structure.
@param DevicePath2 A pointer to the second device path data structure.
@retval TRUE They are same.
@retval FALSE They are not same.
**/
BOOLEAN
EfiCompareDevicePath (
@@ -74,8 +74,17 @@ EfiCompareDevicePath (
}
/**
Init hot plug support and root hot plug private data.
Check hot plug support and initialize root hot plug private data.
If Hot Plug is supported by the platform, call PCI Hot Plug Init protocol
to get PCI Hot Plug controller's information and constructor the root hot plug
private data structure.
@retval EFI_SUCCESS They are same.
@retval EFI_UNSUPPORTED No PCI Hot Plug controler on the platform.
@retval EFI_OUT_OF_RESOURCES No memory to constructor root hot plug private
data structure.
**/
EFI_STATUS
InitializeHotPlugSupport (
@@ -92,13 +101,8 @@ InitializeHotPlugSupport (
// hot plug controller supported on the platform
// the PCI Bus driver is running on. HotPlug Support
// is an optional feature, so absence of the protocol
// won't incur the penalty
// won't incur the penalty.
//
gPciHotPlugInit = NULL;
gPciRootHpcPool = NULL;
gPciRootHpcCount = 0;
gPciRootHpcData = NULL;
Status = gBS->LocateProtocol (
&gEfiPciHotPlugInitProtocolGuid,
NULL,
@@ -129,18 +133,20 @@ InitializeHotPlugSupport (
}
/**
Test whether device path is for root pci hot plug bus
@param HpbDevicePath tested device path.
@param HpIndex Return the index of root hot plug in global array.
@retval TRUE device path is for root pci hot plug.
@retval FALSE device path is not for root pci hot plug.
Test whether device path is for root pci hot plug bus.
@param HpbDevicePath A pointer to device path data structure to be tested.
@param HpIndex If HpIndex is not NULL, return the index of root hot
plug in global array when TRUE is retuned.
@retval TRUE The device path is for root pci hot plug bus.
@retval FALSE The device path is not for root pci hot plug bus.
**/
BOOLEAN
IsRootPciHotPlugBus (
IN EFI_DEVICE_PATH_PROTOCOL *HpbDevicePath,
OUT UINTN *HpIndex
IN EFI_DEVICE_PATH_PROTOCOL *HpbDevicePath,
OUT UINTN *HpIndex OPTIONAL
)
{
UINTN Index;
@@ -161,13 +167,15 @@ IsRootPciHotPlugBus (
}
/**
Test whether device path is for root pci hot plug controller
@param HpcDevicePath tested device path.
@param HpIndex Return the index of root hot plug in global array.
@retval TRUE device path is for root pci hot plug controller.
@retval FALSE device path is not for root pci hot plug controller.
Test whether device path is for root pci hot plug controller.
@param HpbDevicePath A pointer to device path data structure to be tested.
@param HpIndex If HpIndex is not NULL, return the index of root hot
plug in global array when TRUE is retuned.
@retval TRUE The device path is for root pci hot plug controller.
@retval FALSE The device path is not for root pci hot plug controller.
**/
BOOLEAN
IsRootPciHotPlugController (
@@ -193,23 +201,24 @@ IsRootPciHotPlugController (
}
/**
Wrapper for creating event object for HPC
@param HpIndex index of hot plug device in global array.
@param Event event object.
@return status of create event invoken.
Creating event object for PCI Hot Plug controller.
@param HpIndex Index of hot plug device in global array.
@param Event The retuned event that invoke this function.
@return Status of create event invoken.
**/
EFI_STATUS
CreateEventForHpc (
IN UINTN HpIndex,
IN UINTN HpIndex,
OUT EFI_EVENT *Event
)
{
EFI_STATUS Status;
Status = gBS->CreateEvent (
EVT_NOTIFY_SIGNAL,
EVT_NOTIFY_SIGNAL,
TPL_CALLBACK,
PciHPCInitialized,
gPciRootHpcData + HpIndex,
@@ -224,9 +233,13 @@ CreateEventForHpc (
}
/**
Wait for all root HPC initialized.
@param TimeoutInMicroSeconds microseconds to wait for all root hpc's initialization.
Wait for all root PCI Hot Plug controller finished initializing.
@param TimeoutInMicroSeconds Microseconds to wait for all root HPCs' initialization.
@retval EFI_SUCCESS All HPCs initialization finished.
@retval EFI_TIMEOUT Not ALL HPCs initialization finished in Microseconds.
**/
EFI_STATUS
AllRootHPCInitialized (
@@ -237,8 +250,8 @@ AllRootHPCInitialized (
UINTN Index;
Delay = (UINT32) ((TimeoutInMicroSeconds / 30) + 1);
do {
do {
for (Index = 0; Index < gPciRootHpcCount; Index++) {
if (!gPciRootHpcData[Index].Initialized) {
@@ -251,7 +264,7 @@ AllRootHPCInitialized (
}
//
// Stall for 30 us
// Stall for 30 microseconds..
//
gBS->Stall (30);
@@ -263,16 +276,17 @@ AllRootHPCInitialized (
}
/**
Check HPC capability register block
@param PciIoDevice PCI device instance.
@retval EFI_SUCCESS PCI device is HPC.
@retval EFI_NOT_FOUND PCI device is not HPC.
Check whether PCI-PCI bridge has PCI Hot Plug capability register block.
@param PciIoDevice A Pointer to the PCI-PCI bridge.
@retval TRUE PCI device is HPC.
@retval FALSE PCI device is not HPC.
**/
EFI_STATUS
BOOLEAN
IsSHPC (
PCI_IO_DEVICE *PciIoDevice
IN PCI_IO_DEVICE *PciIoDevice
)
{
@@ -280,7 +294,7 @@ IsSHPC (
UINT8 Offset;
if (PciIoDevice == NULL) {
return EFI_NOT_FOUND;
return FALSE;
}
Offset = 0;
@@ -292,42 +306,26 @@ IsSHPC (
);
//
// If the PPB has the hot plug controller build-in,
// If the PCI-PCI bridge has the hot plug controller build-in,
// then return TRUE;
//
if (!EFI_ERROR (Status)) {
return EFI_SUCCESS;
return TRUE;
}
return EFI_NOT_FOUND;
return FALSE;
}
/**
Get resource padding for hot plug bus
@param PciIoDevice PCI device instance
@retval EFI_SUCCESS success get padding and set it into PCI device instance
@retval EFI_NOT_FOUND PCI device is not a hot plug bus.
Get resource padding if the specified PCI bridge is a hot plug bus.
@param PciIoDevice PCI bridge instance.
**/
EFI_STATUS
VOID
GetResourcePaddingForHpb (
IN PCI_IO_DEVICE *PciIoDevice
IN PCI_IO_DEVICE *PciIoDevice
)
/**
Routine Description:
Arguments:
Returns:
None
**/
// TODO: PciIoDevice - add argument and description to function comment
// TODO: EFI_SUCCESS - add return value to function comment
// TODO: EFI_NOT_FOUND - add return value to function comment
{
EFI_STATUS Status;
EFI_HPC_STATE State;
@@ -335,9 +333,10 @@ Returns:
EFI_HPC_PADDING_ATTRIBUTES Attributes;
EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptors;
Status = IsPciHotPlugBus (PciIoDevice);
if (!EFI_ERROR (Status)) {
if (IsPciHotPlugBus (PciIoDevice)) {
//
// If PCI-PCI bridge device is PCI Hot Plug bus.
//
PciAddress = EFI_PCI_ADDRESS (PciIoDevice->BusNumber, PciIoDevice->DeviceNumber, PciIoDevice->FunctionNumber, 0);
Status = gPciHotPlugInit->GetResourcePadding (
gPciHotPlugInit,
@@ -349,7 +348,7 @@ Returns:
);
if (EFI_ERROR (Status)) {
return Status;
return;
}
if ((State & EFI_HPC_STATE_ENABLED) != 0 && (State & EFI_HPC_STATE_INITIALIZED) != 0) {
@@ -357,47 +356,39 @@ Returns:
PciIoDevice->PaddingAttributes = Attributes;
}
return EFI_SUCCESS;
return;
}
return EFI_NOT_FOUND;
}
/**
Test whether PCI device is hot plug bus.
@param PciIoDevice PCI device instance.
@retval EFI_SUCCESS PCI device is hot plug bus.
@retval EFI_NOT_FOUND PCI device is not hot plug bus.
@retval TRUE PCI device is a hot plug bus.
@retval FALSE PCI device is not a hot plug bus.
**/
EFI_STATUS
BOOLEAN
IsPciHotPlugBus (
PCI_IO_DEVICE *PciIoDevice
)
{
BOOLEAN Result;
EFI_STATUS Status;
Status = IsSHPC (PciIoDevice);
//
// If the PPB has the hot plug controller build-in,
// then return TRUE;
//
if (!EFI_ERROR (Status)) {
return EFI_SUCCESS;
if (IsSHPC (PciIoDevice)) {
//
// If the PPB has the hot plug controller build-in,
// then return TRUE;
//
return TRUE;
}
//
// Otherwise, see if it is a Root HPC
//
Result = IsRootPciHotPlugBus (PciIoDevice->DevicePath, NULL);
if (Result) {
return EFI_SUCCESS;
if(IsRootPciHotPlugBus (PciIoDevice->DevicePath, NULL)) {
return TRUE;
}
return EFI_NOT_FOUND;
return FALSE;
}