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