-/*++\r
+/** @file\r
+ PCI Hot Plug support functions implementation for PCI Bus module..\r
\r
-Copyright (c) 2006 - 2007, Intel Corporation\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
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
-Module Name:\r
+**/\r
\r
- PciHotPlugSupport.c\r
+#include "PciBus.h"\r
\r
-Abstract:\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
+ Event notification function to set Hot Plug controller status.\r
\r
-Revision History\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
+ @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
PciHPCInitialized (\r
IN EFI_EVENT Event,\r
IN VOID *Context\r
)\r
-/*++\r
-\r
-Routine Description:\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
- None\r
-\r
---*/\r
-// TODO: Event - add argument and description to function comment\r
-// TODO: Context - add argument and description to function comment\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 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
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath1,\r
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath2\r
)\r
-/*++\r
-\r
-Routine Description:\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
- None\r
-\r
---*/\r
-// TODO: DevicePath1 - add argument and description to function comment\r
-// TODO: DevicePath2 - add argument and description to function comment\r
{\r
UINTN Size1;\r
UINTN Size2;\r
return FALSE;\r
}\r
\r
- if (CompareMem (DevicePath1, DevicePath2, Size1)) {\r
+ if (CompareMem (DevicePath1, DevicePath2, Size1) != 0) {\r
return FALSE;\r
}\r
\r
return TRUE;\r
}\r
\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
VOID\r
)\r
-/*++\r
-\r
-Routine Description:\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
- None\r
-\r
---*/\r
-// TODO: EFI_UNSUPPORTED - add return value to function comment\r
-// TODO: EFI_OUT_OF_RESOURCES - add return value to function comment\r
-// TODO: EFI_SUCCESS - add return value to function comment\r
{\r
EFI_STATUS Status;\r
EFI_HPC_LOCATION *HpcList;\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
return EFI_SUCCESS;\r
}\r
\r
-BOOLEAN\r
-IsRootPciHotPlugBus (\r
- IN EFI_DEVICE_PATH_PROTOCOL *HpbDevicePath,\r
- OUT UINTN *HpIndex\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-Arguments:\r
+/**\r
+ Test whether device path is for root pci hot plug bus.\r
\r
- HpcDevicePath - A pointer to the EFI_DEVICE_PATH_PROTOCOL.\r
- HpIndex - A pointer to the Index.\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
-Returns:\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
- None\r
-\r
---*/\r
-// TODO: HpbDevicePath - add argument and description to function comment\r
+**/\r
+BOOLEAN\r
+IsRootPciHotPlugBus (\r
+ IN EFI_DEVICE_PATH_PROTOCOL *HpbDevicePath,\r
+ OUT UINTN *HpIndex OPTIONAL\r
+ )\r
{\r
UINTN Index;\r
\r
return FALSE;\r
}\r
\r
+/**\r
+ Test whether device path is for root pci hot plug controller.\r
+\r
+ @param HpcDevicePath 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
IN EFI_DEVICE_PATH_PROTOCOL *HpcDevicePath,\r
OUT UINTN *HpIndex\r
)\r
-/*++\r
-\r
-Routine Description:\r
-\r
-Arguments:\r
-\r
- HpcDevicePath - A pointer to the EFI_DEVICE_PATH_PROTOCOL.\r
- HpIndex - A pointer to the Index.\r
-\r
-Returns:\r
-\r
- None\r
-\r
---*/\r
{\r
UINTN Index;\r
\r
return FALSE;\r
}\r
\r
+/**\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
-\r
-Routine Description:\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
- None\r
-\r
---*/\r
-// TODO: HpIndex - add argument and description to function comment\r
-// TODO: Event - add argument and description to function comment\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
return Status;\r
}\r
\r
+/**\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
IN UINTN TimeoutInMicroSeconds\r
)\r
-/*++\r
-\r
-Routine Description:\r
-\r
-Arguments:\r
- TimeoutInMicroSeconds - microseconds to wait for all root hpc's initialization\r
-\r
-Returns:\r
- EFI_SUCCESS - All root hpc's initialization is finished before the timeout\r
- EFI_TIMEOUT - Time out\r
-\r
---*/\r
-// TODO: TimeoutInMilliSeconds - add argument and description to function comment\r
-// TODO: EFI_SUCCESS - add return value to function comment\r
-// TODO: EFI_TIMEOUT - add return value to function comment\r
{\r
UINT32 Delay;\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
Delay--;\r
\r
- } while (Delay);\r
+ } while (Delay > 0);\r
\r
return EFI_TIMEOUT;\r
}\r
\r
-EFI_STATUS\r
-IsSHPC (\r
- PCI_IO_DEVICE *PciIoDevice\r
- )\r
-/*++\r
+/**\r
+ Check whether PCI-PCI bridge has PCI Hot Plug capability register block.\r
\r
-Routine Description:\r
+ @param PciIoDevice A Pointer to the PCI-PCI bridge.\r
\r
-Arguments:\r
+ @retval TRUE PCI device is HPC.\r
+ @retval FALSE PCI device is not HPC.\r
\r
-Returns:\r
-\r
- None\r
-\r
---*/\r
-// TODO: PciIoDevice - add argument and description to function comment\r
-// TODO: EFI_NOT_FOUND - add return value 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
+**/\r
+BOOLEAN\r
+IsSHPC (\r
+ IN PCI_IO_DEVICE *PciIoDevice\r
+ )\r
{\r
\r
EFI_STATUS Status;\r
UINT8 Offset;\r
\r
- if (!PciIoDevice) {\r
- return EFI_NOT_FOUND;\r
+ if (PciIoDevice == NULL) {\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
-EFI_STATUS\r
-GetResourcePaddingForHpb (\r
- IN PCI_IO_DEVICE *PciIoDevice\r
- )\r
-/*++\r
+/**\r
+ Get resource padding if the specified PCI bridge is a hot plug bus.\r
\r
-Routine Description:\r
+ @param PciIoDevice PCI bridge instance.\r
\r
-Arguments:\r
-\r
-Returns:\r
-\r
- None\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
+**/\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) && (State & EFI_HPC_STATE_INITIALIZED)) {\r
+ if ((State & EFI_HPC_STATE_ENABLED) != 0 && (State & EFI_HPC_STATE_INITIALIZED) != 0) {\r
PciIoDevice->ResourcePaddingDescriptors = Descriptors;\r
PciIoDevice->PaddingAttributes = Attributes;\r
}\r
\r
- return EFI_SUCCESS;\r
+ return;\r
}\r
-\r
- return EFI_NOT_FOUND;\r
}\r
\r
-EFI_STATUS\r
-IsPciHotPlugBus (\r
- PCI_IO_DEVICE *PciIoDevice\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-Arguments:\r
+/**\r
+ Test whether PCI device is hot plug bus.\r
\r
-Returns:\r
+ @param PciIoDevice PCI device instance.\r
\r
- None\r
+ @retval TRUE PCI device is a hot plug bus.\r
+ @retval FALSE PCI device is not a hot plug bus.\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_SUCCESS - add return value to function comment\r
-// TODO: EFI_NOT_FOUND - add return value to function comment\r
+**/\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